From de8f24ea083384bb66b32ec105dc4743c5663cdf Mon Sep 17 00:00:00 2001 From: beck <> Date: Wed, 29 Sep 1999 04:37:45 +0000 Subject: OpenSSL 0.9.4 merge --- src/lib/libcrypto/Attic/Makefile | 308 +- src/lib/libcrypto/Makefile.ssl | 140 +- src/lib/libcrypto/asn1/Makefile.ssl | 1038 ++++- src/lib/libcrypto/asn1/a_bitstr.c | 78 +- src/lib/libcrypto/asn1/a_bmp.c | 19 +- src/lib/libcrypto/asn1/a_bool.c | 15 +- src/lib/libcrypto/asn1/a_bytes.c | 44 +- src/lib/libcrypto/asn1/a_d2i_fp.c | 18 +- src/lib/libcrypto/asn1/a_digest.c | 14 +- src/lib/libcrypto/asn1/a_dup.c | 7 +- src/lib/libcrypto/asn1/a_enum.c | 326 ++ src/lib/libcrypto/asn1/a_gentm.c | 224 + src/lib/libcrypto/asn1/a_hdr.c | 27 +- src/lib/libcrypto/asn1/a_i2d_fp.c | 14 +- src/lib/libcrypto/asn1/a_int.c | 215 +- src/lib/libcrypto/asn1/a_meth.c | 8 +- src/lib/libcrypto/asn1/a_object.c | 139 +- src/lib/libcrypto/asn1/a_octet.c | 17 +- src/lib/libcrypto/asn1/a_print.c | 70 +- src/lib/libcrypto/asn1/a_set.c | 112 +- src/lib/libcrypto/asn1/a_sign.c | 28 +- src/lib/libcrypto/asn1/a_time.c | 123 + src/lib/libcrypto/asn1/a_type.c | 91 +- src/lib/libcrypto/asn1/a_utctm.c | 98 +- src/lib/libcrypto/asn1/a_utf8.c | 83 + src/lib/libcrypto/asn1/a_verify.c | 23 +- src/lib/libcrypto/asn1/a_vis.c | 83 + src/lib/libcrypto/asn1/asn1.err | 182 - src/lib/libcrypto/asn1/asn1.h | 606 +-- src/lib/libcrypto/asn1/asn1_err.c | 357 +- src/lib/libcrypto/asn1/asn1_lib.c | 121 +- src/lib/libcrypto/asn1/asn1_mac.h | 355 +- src/lib/libcrypto/asn1/asn1_par.c | 84 +- src/lib/libcrypto/asn1/asn_pack.c | 145 + src/lib/libcrypto/asn1/d2i_dhp.c | 23 +- src/lib/libcrypto/asn1/d2i_dsap.c | 25 +- src/lib/libcrypto/asn1/d2i_pr.c | 17 +- src/lib/libcrypto/asn1/d2i_pu.c | 17 +- src/lib/libcrypto/asn1/d2i_r_pr.c | 24 +- src/lib/libcrypto/asn1/d2i_r_pu.c | 23 +- src/lib/libcrypto/asn1/d2i_s_pr.c | 24 +- src/lib/libcrypto/asn1/d2i_s_pu.c | 25 +- src/lib/libcrypto/asn1/evp_asn1.c | 38 +- src/lib/libcrypto/asn1/f.c | 4 +- src/lib/libcrypto/asn1/f_enum.c | 207 + src/lib/libcrypto/asn1/f_int.c | 25 +- src/lib/libcrypto/asn1/f_string.c | 26 +- src/lib/libcrypto/asn1/i2d_dhp.c | 24 +- src/lib/libcrypto/asn1/i2d_dsap.c | 16 +- src/lib/libcrypto/asn1/i2d_pr.c | 10 +- src/lib/libcrypto/asn1/i2d_pu.c | 10 +- src/lib/libcrypto/asn1/i2d_r_pr.c | 19 +- src/lib/libcrypto/asn1/i2d_r_pu.c | 20 +- src/lib/libcrypto/asn1/i2d_s_pr.c | 19 +- src/lib/libcrypto/asn1/i2d_s_pu.c | 22 +- src/lib/libcrypto/asn1/n_pkey.c | 66 +- src/lib/libcrypto/asn1/nsseq.c | 118 + src/lib/libcrypto/asn1/p5_pbe.c | 156 + src/lib/libcrypto/asn1/p5_pbev2.c | 274 ++ src/lib/libcrypto/asn1/p7_dgst.c | 25 +- src/lib/libcrypto/asn1/p7_enc.c | 25 +- src/lib/libcrypto/asn1/p7_enc_c.c | 28 +- src/lib/libcrypto/asn1/p7_evp.c | 38 +- src/lib/libcrypto/asn1/p7_i_s.c | 25 +- src/lib/libcrypto/asn1/p7_lib.c | 42 +- src/lib/libcrypto/asn1/p7_recip.c | 29 +- src/lib/libcrypto/asn1/p7_s_e.c | 81 +- src/lib/libcrypto/asn1/p7_signd.c | 69 +- src/lib/libcrypto/asn1/p7_signi.c | 51 +- src/lib/libcrypto/asn1/p8_pkey.c | 129 + src/lib/libcrypto/asn1/pkcs8.c | 23 +- src/lib/libcrypto/asn1/t_crl.c | 166 + src/lib/libcrypto/asn1/t_pkey.c | 71 +- src/lib/libcrypto/asn1/t_req.c | 36 +- src/lib/libcrypto/asn1/t_x509.c | 150 +- src/lib/libcrypto/asn1/x_algor.c | 28 +- src/lib/libcrypto/asn1/x_attrib.c | 59 +- src/lib/libcrypto/asn1/x_cinf.c | 56 +- src/lib/libcrypto/asn1/x_crl.c | 175 +- src/lib/libcrypto/asn1/x_exten.c | 28 +- src/lib/libcrypto/asn1/x_info.c | 14 +- src/lib/libcrypto/asn1/x_name.c | 96 +- src/lib/libcrypto/asn1/x_pkey.c | 27 +- src/lib/libcrypto/asn1/x_pubkey.c | 44 +- src/lib/libcrypto/asn1/x_req.c | 61 +- src/lib/libcrypto/asn1/x_sig.c | 23 +- src/lib/libcrypto/asn1/x_spki.c | 43 +- src/lib/libcrypto/asn1/x_val.c | 43 +- src/lib/libcrypto/asn1/x_x509.c | 33 +- src/lib/libcrypto/bf/Makefile.ssl | 45 +- src/lib/libcrypto/bf/Makefile.uni | 20 +- src/lib/libcrypto/bf/asm/bf-586.pl | 4 +- src/lib/libcrypto/bf/asm/bf-686.pl | 1 - src/lib/libcrypto/bf/asm/bx86unix.cpp | 976 ----- src/lib/libcrypto/bf/bf_cbc.c | 11 +- src/lib/libcrypto/bf/bf_cfb64.c | 12 +- src/lib/libcrypto/bf/bf_ecb.c | 14 +- src/lib/libcrypto/bf/bf_enc.c | 93 +- src/lib/libcrypto/bf/bf_locl.h | 219 + src/lib/libcrypto/bf/bf_locl.org | 242 -- src/lib/libcrypto/bf/bf_ofb64.c | 11 +- src/lib/libcrypto/bf/bf_opts.c | 61 +- src/lib/libcrypto/bf/bf_skey.c | 7 +- src/lib/libcrypto/bf/bfs.cpp | 2 +- src/lib/libcrypto/bf/bfspeed.c | 59 +- src/lib/libcrypto/bf/bftest.c | 46 +- src/lib/libcrypto/bf/blowfish.h | 45 +- src/lib/libcrypto/bio/Makefile.ssl | 170 +- src/lib/libcrypto/bio/b_dump.c | 13 +- src/lib/libcrypto/bio/b_print.c | 19 +- src/lib/libcrypto/bio/b_sock.c | 319 +- src/lib/libcrypto/bio/bf_buff.c | 49 +- src/lib/libcrypto/bio/bf_nbio.c | 50 +- src/lib/libcrypto/bio/bf_null.c | 48 +- src/lib/libcrypto/bio/bio.err | 46 - src/lib/libcrypto/bio/bio.h | 343 +- src/lib/libcrypto/bio/bio_cb.c | 13 +- src/lib/libcrypto/bio/bio_err.c | 131 +- src/lib/libcrypto/bio/bio_lib.c | 147 +- src/lib/libcrypto/bio/bss_acpt.c | 132 +- src/lib/libcrypto/bio/bss_bio.c | 588 +++ src/lib/libcrypto/bio/bss_conn.c | 146 +- src/lib/libcrypto/bio/bss_file.c | 60 +- src/lib/libcrypto/bio/bss_log.c | 232 + src/lib/libcrypto/bio/bss_mem.c | 59 +- src/lib/libcrypto/bio/bss_null.c | 46 +- src/lib/libcrypto/bio/bss_rtcp.c | 56 +- src/lib/libcrypto/bio/bss_sock.c | 118 +- src/lib/libcrypto/bn/Makefile.ssl | 215 +- src/lib/libcrypto/bn/asm/alpha.s | 1860 +++++++- src/lib/libcrypto/bn/asm/alpha.s.works | 533 +++ src/lib/libcrypto/bn/asm/bn-586.pl | 84 +- src/lib/libcrypto/bn/asm/bn-alpha.pl | 571 +++ src/lib/libcrypto/bn/asm/bn-win32.asm | 1441 ++++++- src/lib/libcrypto/bn/asm/bn86unix.cpp | 752 ---- src/lib/libcrypto/bn/asm/ca.pl | 33 + src/lib/libcrypto/bn/asm/co-586.pl | 286 ++ src/lib/libcrypto/bn/asm/co-alpha.pl | 116 + src/lib/libcrypto/bn/asm/mips1.s | 539 +++ src/lib/libcrypto/bn/asm/mips3.s | 2138 +++++++++ src/lib/libcrypto/bn/asm/sparc.s | 462 -- src/lib/libcrypto/bn/asm/sparcv8.S | 1458 +++++++ src/lib/libcrypto/bn/asm/sparcv8plus.S | 1535 +++++++ src/lib/libcrypto/bn/asm/vms.mar | 6695 +++++++++++++++++++++++++++++ src/lib/libcrypto/bn/asm/x86.pl | 28 + src/lib/libcrypto/bn/asm/x86w16.asm | 6 +- src/lib/libcrypto/bn/asm/x86w32.asm | 34 +- src/lib/libcrypto/bn/bn.err | 27 - src/lib/libcrypto/bn/bn.h | 467 ++ src/lib/libcrypto/bn/bn.mul | 19 + src/lib/libcrypto/bn/bn.org | 502 --- src/lib/libcrypto/bn/bn_add.c | 194 +- src/lib/libcrypto/bn/bn_asm.c | 802 ++++ src/lib/libcrypto/bn/bn_blind.c | 43 +- src/lib/libcrypto/bn/bn_comba.c | 345 ++ src/lib/libcrypto/bn/bn_div.c | 180 +- src/lib/libcrypto/bn/bn_err.c | 123 +- src/lib/libcrypto/bn/bn_exp.c | 210 +- src/lib/libcrypto/bn/bn_exp2.c | 195 + src/lib/libcrypto/bn/bn_gcd.c | 53 +- src/lib/libcrypto/bn/bn_lcl.h | 107 +- src/lib/libcrypto/bn/bn_lib.c | 492 ++- src/lib/libcrypto/bn/bn_m.c | 169 - src/lib/libcrypto/bn/bn_mod.c | 97 - src/lib/libcrypto/bn/bn_mont.c | 441 +- src/lib/libcrypto/bn/bn_mpi.c | 11 +- src/lib/libcrypto/bn/bn_mul.c | 753 +++- src/lib/libcrypto/bn/bn_mulw.c | 366 -- src/lib/libcrypto/bn/bn_opts.c | 324 ++ src/lib/libcrypto/bn/bn_prime.c | 126 +- src/lib/libcrypto/bn/bn_prime.pl | 2 +- src/lib/libcrypto/bn/bn_print.c | 30 +- src/lib/libcrypto/bn/bn_rand.c | 10 +- src/lib/libcrypto/bn/bn_recp.c | 178 +- src/lib/libcrypto/bn/bn_shift.c | 18 +- src/lib/libcrypto/bn/bn_sqr.c | 205 +- src/lib/libcrypto/bn/bn_sub.c | 180 - src/lib/libcrypto/bn/bn_word.c | 30 +- src/lib/libcrypto/bn/bnspeed.c | 67 +- src/lib/libcrypto/bn/bntest.c | 621 ++- src/lib/libcrypto/bn/comba.pl | 285 ++ src/lib/libcrypto/bn/d.c | 72 + src/lib/libcrypto/bn/exp.c | 60 + src/lib/libcrypto/bn/expspeed.c | 55 +- src/lib/libcrypto/bn/exptest.c | 60 +- src/lib/libcrypto/bn/new | 23 + src/lib/libcrypto/bn/test.c | 241 ++ src/lib/libcrypto/bn/todo | 3 + src/lib/libcrypto/bn/vms-helper.c | 66 + src/lib/libcrypto/buffer/Makefile.ssl | 44 +- src/lib/libcrypto/buffer/buf_err.c | 123 +- src/lib/libcrypto/buffer/buffer.c | 25 +- src/lib/libcrypto/buffer/buffer.err | 9 - src/lib/libcrypto/buffer/buffer.h | 21 +- src/lib/libcrypto/cast/Makefile.ssl | 51 +- src/lib/libcrypto/cast/Makefile.uni | 3 +- src/lib/libcrypto/cast/asm/c-win32.asm | 117 +- src/lib/libcrypto/cast/asm/cast-586.pl | 267 +- src/lib/libcrypto/cast/asm/cx86unix.cpp | 1010 ----- src/lib/libcrypto/cast/c_cfb64.c | 25 +- src/lib/libcrypto/cast/c_ecb.c | 14 +- src/lib/libcrypto/cast/c_enc.c | 43 +- src/lib/libcrypto/cast/c_ofb64.c | 16 +- src/lib/libcrypto/cast/c_skey.c | 11 +- src/lib/libcrypto/cast/cast.h | 36 +- src/lib/libcrypto/cast/cast_lcl.h | 20 +- src/lib/libcrypto/cast/cast_s.h | 16 +- src/lib/libcrypto/cast/cast_spd.c | 59 +- src/lib/libcrypto/cast/castopts.c | 61 +- src/lib/libcrypto/cast/casts.cpp | 2 +- src/lib/libcrypto/cast/casttest.c | 183 +- src/lib/libcrypto/conf/Makefile.ssl | 49 +- src/lib/libcrypto/conf/cnf_save.c | 7 +- src/lib/libcrypto/conf/conf.c | 211 +- src/lib/libcrypto/conf/conf.err | 12 - src/lib/libcrypto/conf/conf.h | 32 +- src/lib/libcrypto/conf/conf_err.c | 120 +- src/lib/libcrypto/conf/conf_lcl.h | 14 + src/lib/libcrypto/conf/keysets.pl | 2 +- src/lib/libcrypto/conf/test.c | 5 +- src/lib/libcrypto/cpt_err.c | 122 +- src/lib/libcrypto/cryptall.h | 110 - src/lib/libcrypto/cryptlib.c | 85 +- src/lib/libcrypto/cryptlib.h | 34 +- src/lib/libcrypto/crypto-lib.com | 1218 ++++++ src/lib/libcrypto/crypto.c | 575 --- src/lib/libcrypto/crypto.err | 8 - src/lib/libcrypto/crypto.h | 188 +- src/lib/libcrypto/cversion.c | 39 +- src/lib/libcrypto/date.h | 1 - src/lib/libcrypto/des/Makefile.ssl | 126 +- src/lib/libcrypto/des/Makefile.uni | 20 +- src/lib/libcrypto/des/VERSION | 1 + src/lib/libcrypto/des/asm/crypt586.pl | 4 +- src/lib/libcrypto/des/asm/des-586.pl | 4 +- src/lib/libcrypto/des/asm/des686.pl | 2 +- src/lib/libcrypto/des/asm/desboth.pl | 8 +- src/lib/libcrypto/des/asm/dx86unix.cpp | 3202 -------------- src/lib/libcrypto/des/asm/yx86unix.cpp | 976 ----- src/lib/libcrypto/des/cbc3_enc.c | 12 +- src/lib/libcrypto/des/cbc_cksm.c | 16 +- src/lib/libcrypto/des/cbc_enc.c | 78 +- src/lib/libcrypto/des/cfb64ede.c | 36 +- src/lib/libcrypto/des/cfb64enc.c | 27 +- src/lib/libcrypto/des/cfb_enc.c | 14 +- src/lib/libcrypto/des/des-lib.com | 1003 +++++ src/lib/libcrypto/des/des.c | 121 +- src/lib/libcrypto/des/des.h | 249 ++ src/lib/libcrypto/des/des.org | 301 -- src/lib/libcrypto/des/des.pl | 2 +- src/lib/libcrypto/des/des3s.cpp | 2 +- src/lib/libcrypto/des/des_enc.c | 140 +- src/lib/libcrypto/des/des_locl.h | 408 ++ src/lib/libcrypto/des/des_locl.org | 516 --- src/lib/libcrypto/des/des_opts.c | 62 +- src/lib/libcrypto/des/des_ver.h | 5 +- src/lib/libcrypto/des/dess.cpp | 2 +- src/lib/libcrypto/des/destest.c | 295 +- src/lib/libcrypto/des/ecb3_enc.c | 15 +- src/lib/libcrypto/des/ecb_enc.c | 24 +- src/lib/libcrypto/des/ede_cbcm_enc.c | 197 + src/lib/libcrypto/des/ede_enc.c | 190 - src/lib/libcrypto/des/enc_read.c | 84 +- src/lib/libcrypto/des/enc_writ.c | 62 +- src/lib/libcrypto/des/fcrypt_b.c | 9 +- src/lib/libcrypto/des/ncbc_enc.c | 41 +- src/lib/libcrypto/des/ofb64ede.c | 27 +- src/lib/libcrypto/des/ofb64enc.c | 22 +- src/lib/libcrypto/des/ofb_enc.c | 13 +- src/lib/libcrypto/des/pcbc_enc.c | 18 +- src/lib/libcrypto/des/qud_cksm.c | 16 +- src/lib/libcrypto/des/rand_key.c | 22 +- src/lib/libcrypto/des/ranlib.sh | 23 - src/lib/libcrypto/des/read2pwd.c | 12 +- src/lib/libcrypto/des/read_pwd.c | 145 +- src/lib/libcrypto/des/rpc_enc.c | 23 +- src/lib/libcrypto/des/rpw.c | 10 +- src/lib/libcrypto/des/set_key.c | 36 +- src/lib/libcrypto/des/shifts.pl | 2 +- src/lib/libcrypto/des/speed.c | 77 +- src/lib/libcrypto/des/spr.h | 2 +- src/lib/libcrypto/des/str2key.c | 34 +- src/lib/libcrypto/des/supp.c | 8 +- src/lib/libcrypto/des/testdes.pl | 2 +- src/lib/libcrypto/des/vms.com | 90 - src/lib/libcrypto/des/xcbc_enc.c | 56 +- src/lib/libcrypto/dh/Makefile.ssl | 66 +- src/lib/libcrypto/dh/dh.err | 12 - src/lib/libcrypto/dh/dh.h | 44 +- src/lib/libcrypto/dh/dh_check.c | 8 +- src/lib/libcrypto/dh/dh_err.c | 118 +- src/lib/libcrypto/dh/dh_gen.c | 18 +- src/lib/libcrypto/dh/dh_key.c | 52 +- src/lib/libcrypto/dh/dh_lib.c | 19 +- src/lib/libcrypto/dh/dhtest.c | 36 +- src/lib/libcrypto/dh/p1024.c | 8 +- src/lib/libcrypto/dh/p192.c | 8 +- src/lib/libcrypto/dh/p512.c | 8 +- src/lib/libcrypto/dsa/Makefile.ssl | 91 +- src/lib/libcrypto/dsa/dsa.err | 15 - src/lib/libcrypto/dsa/dsa.h | 80 +- src/lib/libcrypto/dsa/dsa_asn1.c | 96 + src/lib/libcrypto/dsa/dsa_err.c | 123 +- src/lib/libcrypto/dsa/dsa_gen.c | 109 +- src/lib/libcrypto/dsa/dsa_key.c | 14 +- src/lib/libcrypto/dsa/dsa_lib.c | 59 +- src/lib/libcrypto/dsa/dsa_sign.c | 152 +- src/lib/libcrypto/dsa/dsa_vrf.c | 140 +- src/lib/libcrypto/dsa/dsagen.c | 5 +- src/lib/libcrypto/dsa/dsatest.c | 52 +- src/lib/libcrypto/ebcdic.h | 17 + src/lib/libcrypto/err/Makefile.ssl | 60 +- src/lib/libcrypto/err/err.c | 185 +- src/lib/libcrypto/err/err.h | 82 +- src/lib/libcrypto/err/err_all.c | 34 +- src/lib/libcrypto/err/err_code.pl | 105 - src/lib/libcrypto/err/err_genc.pl | 198 - src/lib/libcrypto/err/err_prn.c | 20 +- src/lib/libcrypto/err/error.err | 13 - src/lib/libcrypto/err/openssl.ec | 71 + src/lib/libcrypto/err/ssleay.ec | 57 - src/lib/libcrypto/evp/Makefile.ssl | 1034 ++++- src/lib/libcrypto/evp/bio_b64.c | 39 +- src/lib/libcrypto/evp/bio_enc.c | 58 +- src/lib/libcrypto/evp/bio_md.c | 48 +- src/lib/libcrypto/evp/bio_ok.c | 552 +++ src/lib/libcrypto/evp/c_all.c | 77 +- src/lib/libcrypto/evp/digest.c | 29 +- src/lib/libcrypto/evp/e_cbc_3d.c | 64 +- src/lib/libcrypto/evp/e_cbc_bf.c | 31 +- src/lib/libcrypto/evp/e_cbc_c.c | 28 +- src/lib/libcrypto/evp/e_cbc_d.c | 40 +- src/lib/libcrypto/evp/e_cbc_i.c | 28 +- src/lib/libcrypto/evp/e_cbc_r2.c | 122 +- src/lib/libcrypto/evp/e_cbc_r5.c | 26 +- src/lib/libcrypto/evp/e_cfb_3d.c | 69 +- src/lib/libcrypto/evp/e_cfb_bf.c | 29 +- src/lib/libcrypto/evp/e_cfb_c.c | 26 +- src/lib/libcrypto/evp/e_cfb_d.c | 34 +- src/lib/libcrypto/evp/e_cfb_i.c | 26 +- src/lib/libcrypto/evp/e_cfb_r2.c | 30 +- src/lib/libcrypto/evp/e_cfb_r5.c | 26 +- src/lib/libcrypto/evp/e_dsa.c | 6 +- src/lib/libcrypto/evp/e_ecb_3d.c | 67 +- src/lib/libcrypto/evp/e_ecb_bf.c | 29 +- src/lib/libcrypto/evp/e_ecb_c.c | 26 +- src/lib/libcrypto/evp/e_ecb_d.c | 48 +- src/lib/libcrypto/evp/e_ecb_i.c | 26 +- src/lib/libcrypto/evp/e_ecb_r2.c | 30 +- src/lib/libcrypto/evp/e_ecb_r5.c | 26 +- src/lib/libcrypto/evp/e_null.c | 26 +- src/lib/libcrypto/evp/e_ofb_3d.c | 65 +- src/lib/libcrypto/evp/e_ofb_bf.c | 29 +- src/lib/libcrypto/evp/e_ofb_c.c | 26 +- src/lib/libcrypto/evp/e_ofb_d.c | 41 +- src/lib/libcrypto/evp/e_ofb_i.c | 26 +- src/lib/libcrypto/evp/e_ofb_r2.c | 30 +- src/lib/libcrypto/evp/e_ofb_r5.c | 26 +- src/lib/libcrypto/evp/e_rc4.c | 28 +- src/lib/libcrypto/evp/e_xcbc_d.c | 42 +- src/lib/libcrypto/evp/encode.c | 57 +- src/lib/libcrypto/evp/evp.err | 24 - src/lib/libcrypto/evp/evp.h | 347 +- src/lib/libcrypto/evp/evp_enc.c | 71 +- src/lib/libcrypto/evp/evp_err.c | 144 +- src/lib/libcrypto/evp/evp_key.c | 31 +- src/lib/libcrypto/evp/evp_lib.c | 51 +- src/lib/libcrypto/evp/evp_pbe.c | 134 + src/lib/libcrypto/evp/evp_pkey.c | 298 ++ src/lib/libcrypto/evp/m_dss.c | 11 +- src/lib/libcrypto/evp/m_dss1.c | 10 +- src/lib/libcrypto/evp/m_md2.c | 11 +- src/lib/libcrypto/evp/m_md5.c | 10 +- src/lib/libcrypto/evp/m_mdc2.c | 10 +- src/lib/libcrypto/evp/m_null.c | 10 +- src/lib/libcrypto/evp/m_ripemd.c | 11 +- src/lib/libcrypto/evp/m_sha.c | 11 +- src/lib/libcrypto/evp/m_sha1.c | 10 +- src/lib/libcrypto/evp/names.c | 239 +- src/lib/libcrypto/evp/p5_crpt.c | 146 + src/lib/libcrypto/evp/p5_crpt2.c | 247 ++ src/lib/libcrypto/evp/p_dec.c | 23 +- src/lib/libcrypto/evp/p_enc.c | 23 +- src/lib/libcrypto/evp/p_lib.c | 53 +- src/lib/libcrypto/evp/p_open.c | 22 +- src/lib/libcrypto/evp/p_seal.c | 27 +- src/lib/libcrypto/evp/p_sign.c | 25 +- src/lib/libcrypto/evp/p_verify.c | 15 +- src/lib/libcrypto/evp/pk_lib.c | 82 - src/lib/libcrypto/ex_data.c | 57 +- src/lib/libcrypto/hmac/Makefile.ssl | 44 +- src/lib/libcrypto/hmac/hmac.c | 33 +- src/lib/libcrypto/hmac/hmac.h | 28 +- src/lib/libcrypto/hmac/hmactest.c | 34 +- src/lib/libcrypto/idea/Makefile.ssl | 40 +- src/lib/libcrypto/idea/idea.h | 99 + src/lib/libcrypto/install.com | 128 + src/lib/libcrypto/lhash/Makefile.ssl | 38 +- src/lib/libcrypto/lhash/lh_stats.c | 38 +- src/lib/libcrypto/lhash/lh_test.c | 2 +- src/lib/libcrypto/lhash/lhash.c | 97 +- src/lib/libcrypto/lhash/lhash.h | 33 +- src/lib/libcrypto/lhash/num.pl | 2 +- src/lib/libcrypto/libvms.com | 31 - src/lib/libcrypto/md2/Makefile.ssl | 40 +- src/lib/libcrypto/md2/md2.c | 20 +- src/lib/libcrypto/md2/md2.h | 91 + src/lib/libcrypto/md2/md2.org | 106 - src/lib/libcrypto/md2/md2_dgst.c | 28 +- src/lib/libcrypto/md2/md2_one.c | 23 +- src/lib/libcrypto/md2/md2test.c | 27 +- src/lib/libcrypto/md32_common.h | 594 +++ src/lib/libcrypto/md5/Makefile.ssl | 58 +- src/lib/libcrypto/md5/Makefile.uni | 3 +- src/lib/libcrypto/md5/asm/m5-win32.asm | 55 +- src/lib/libcrypto/md5/asm/md5-586.pl | 40 +- src/lib/libcrypto/md5/asm/md5-sparcv9.S | 1029 +++++ src/lib/libcrypto/md5/asm/mx86unix.cpp | 730 ---- src/lib/libcrypto/md5/md5.c | 18 +- src/lib/libcrypto/md5/md5.h | 51 +- src/lib/libcrypto/md5/md5_dgst.c | 395 +- src/lib/libcrypto/md5/md5_locl.h | 160 +- src/lib/libcrypto/md5/md5_one.c | 28 +- src/lib/libcrypto/md5/md5s.cpp | 2 +- src/lib/libcrypto/md5/md5test.c | 23 +- src/lib/libcrypto/mdc2/Makefile.ssl | 39 +- src/lib/libcrypto/mdc2/mdc2.h | 16 +- src/lib/libcrypto/mem.c | 228 +- src/lib/libcrypto/objects/Makefile.ssl | 66 +- src/lib/libcrypto/objects/o_names.c | 243 ++ src/lib/libcrypto/objects/obj_dat.c | 269 +- src/lib/libcrypto/objects/obj_dat.h | 656 --- src/lib/libcrypto/objects/obj_dat.pl | 4 +- src/lib/libcrypto/objects/obj_err.c | 118 +- src/lib/libcrypto/objects/obj_lib.c | 32 +- src/lib/libcrypto/objects/objects.err | 12 - src/lib/libcrypto/objects/objects.h | 316 +- src/lib/libcrypto/opensslconf.h.in | 142 + src/lib/libcrypto/opensslv.h | 21 + src/lib/libcrypto/pem/Makefile.ssl | 162 +- src/lib/libcrypto/pem/ctx_size.c | 122 - src/lib/libcrypto/pem/pem.err | 38 - src/lib/libcrypto/pem/pem.h | 551 +-- src/lib/libcrypto/pem/pem.org | 562 --- src/lib/libcrypto/pem/pem2.h | 60 + src/lib/libcrypto/pem/pem_all.c | 429 +- src/lib/libcrypto/pem/pem_err.c | 121 +- src/lib/libcrypto/pem/pem_info.c | 60 +- src/lib/libcrypto/pem/pem_lib.c | 273 +- src/lib/libcrypto/pem/pem_seal.c | 41 +- src/lib/libcrypto/pem/pem_sign.c | 27 +- src/lib/libcrypto/perlasm/alpha.pl | 434 ++ src/lib/libcrypto/perlasm/cbc.pl | 2 +- src/lib/libcrypto/perlasm/x86asm.pl | 11 +- src/lib/libcrypto/perlasm/x86ms.pl | 12 +- src/lib/libcrypto/perlasm/x86nasm.pl | 342 ++ src/lib/libcrypto/perlasm/x86unix.pl | 42 +- src/lib/libcrypto/pkcs7/Makefile.ssl | 97 +- src/lib/libcrypto/pkcs7/bio_ber.c | 450 ++ src/lib/libcrypto/pkcs7/dec.c | 246 ++ src/lib/libcrypto/pkcs7/des.pem | 15 + src/lib/libcrypto/pkcs7/enc.c | 79 +- src/lib/libcrypto/pkcs7/es1.pem | 66 + src/lib/libcrypto/pkcs7/example.c | 327 ++ src/lib/libcrypto/pkcs7/example.h | 57 + src/lib/libcrypto/pkcs7/info.pem | 57 + src/lib/libcrypto/pkcs7/infokey.pem | 9 + src/lib/libcrypto/pkcs7/mf.p7 | 18 - src/lib/libcrypto/pkcs7/p7.tst | 33 - src/lib/libcrypto/pkcs7/pk7_dgst.c | 10 +- src/lib/libcrypto/pkcs7/pk7_doit.c | 718 +++- src/lib/libcrypto/pkcs7/pk7_enc.c | 10 +- src/lib/libcrypto/pkcs7/pk7_lib.c | 156 +- src/lib/libcrypto/pkcs7/pkcs7.err | 26 - src/lib/libcrypto/pkcs7/pkcs7.h | 196 +- src/lib/libcrypto/pkcs7/pkcs7err.c | 129 +- src/lib/libcrypto/pkcs7/sign.c | 21 +- src/lib/libcrypto/pkcs7/verify.c | 55 +- src/lib/libcrypto/rand/Makefile.ssl | 41 +- src/lib/libcrypto/rand/md_rand.c | 102 +- src/lib/libcrypto/rand/rand.h | 31 +- src/lib/libcrypto/rand/rand_lib.c | 98 + src/lib/libcrypto/rand/randfile.c | 39 +- src/lib/libcrypto/rand/randtest.c | 20 +- src/lib/libcrypto/ranlib.sh | 23 - src/lib/libcrypto/rc2/Makefile.ssl | 40 +- src/lib/libcrypto/rc2/Makefile.uni | 3 +- src/lib/libcrypto/rc2/rc2.h | 99 + src/lib/libcrypto/rc2/rc2.org | 118 - src/lib/libcrypto/rc2/rc2_cbc.c | 19 +- src/lib/libcrypto/rc2/rc2_ecb.c | 12 +- src/lib/libcrypto/rc2/rc2_skey.c | 8 +- src/lib/libcrypto/rc2/rc2cfb64.c | 12 +- src/lib/libcrypto/rc2/rc2ofb64.c | 11 +- src/lib/libcrypto/rc2/rc2speed.c | 59 +- src/lib/libcrypto/rc2/rc2test.c | 27 +- src/lib/libcrypto/rc2/tab.c | 86 + src/lib/libcrypto/rc4/Makefile.ssl | 41 +- src/lib/libcrypto/rc4/Makefile.uni | 3 +- src/lib/libcrypto/rc4/asm/rc4-586.pl | 2 +- src/lib/libcrypto/rc4/asm/rx86unix.cpp | 358 -- src/lib/libcrypto/rc4/rc4.c | 6 +- src/lib/libcrypto/rc4/rc4.h | 88 + src/lib/libcrypto/rc4/rc4.org | 103 - src/lib/libcrypto/rc4/rc4_enc.c | 10 +- src/lib/libcrypto/rc4/rc4_locl.h | 4 + src/lib/libcrypto/rc4/rc4_locl.org | 70 - src/lib/libcrypto/rc4/rc4_skey.c | 12 +- src/lib/libcrypto/rc4/rc4s.cpp | 2 +- src/lib/libcrypto/rc4/rc4speed.c | 59 +- src/lib/libcrypto/rc4/rc4test.c | 16 +- src/lib/libcrypto/rc5/Makefile.ssl | 41 +- src/lib/libcrypto/rc5/Makefile.uni | 3 +- src/lib/libcrypto/rc5/asm/r586unix.cpp | 628 --- src/lib/libcrypto/rc5/asm/rc5-586.pl | 2 +- src/lib/libcrypto/rc5/rc5.h | 17 +- src/lib/libcrypto/ripemd/Makefile.ssl | 39 +- src/lib/libcrypto/ripemd/Makefile.uni | 2 +- src/lib/libcrypto/ripemd/asm/rips.cpp | 2 +- src/lib/libcrypto/ripemd/asm/rm86unix.cpp | 2016 --------- src/lib/libcrypto/ripemd/asm/rmd-586.pl | 4 +- src/lib/libcrypto/ripemd/ripemd.h | 13 +- src/lib/libcrypto/ripemd/rmd160.c | 18 +- src/lib/libcrypto/ripemd/rmd_dgst.c | 38 +- src/lib/libcrypto/ripemd/rmd_locl.h | 6 +- src/lib/libcrypto/ripemd/rmd_one.c | 6 +- src/lib/libcrypto/ripemd/rmdtest.c | 31 +- src/lib/libcrypto/rsa/Makefile.ssl | 134 +- src/lib/libcrypto/rsa/rsa.err | 45 - src/lib/libcrypto/rsa/rsa.h | 203 +- src/lib/libcrypto/rsa/rsa_chk.c | 184 + src/lib/libcrypto/rsa/rsa_eay.c | 164 +- src/lib/libcrypto/rsa/rsa_err.c | 133 +- src/lib/libcrypto/rsa/rsa_gen.c | 14 +- src/lib/libcrypto/rsa/rsa_lib.c | 167 +- src/lib/libcrypto/rsa/rsa_none.c | 47 +- src/lib/libcrypto/rsa/rsa_oaep.c | 162 + src/lib/libcrypto/rsa/rsa_oaep_test.c | 309 ++ src/lib/libcrypto/rsa/rsa_pk1.c | 53 +- src/lib/libcrypto/rsa/rsa_saos.c | 27 +- src/lib/libcrypto/rsa/rsa_sign.c | 28 +- src/lib/libcrypto/rsa/rsa_ssl.c | 22 +- src/lib/libcrypto/sha/Makefile.ssl | 42 +- src/lib/libcrypto/sha/Makefile.uni | 2 +- src/lib/libcrypto/sha/asm/sha1-586.pl | 4 +- src/lib/libcrypto/sha/asm/sx86unix.cpp | 1948 --------- src/lib/libcrypto/sha/sha.c | 19 +- src/lib/libcrypto/sha/sha.h | 58 +- src/lib/libcrypto/sha/sha1.c | 18 +- src/lib/libcrypto/sha/sha1_one.c | 9 +- src/lib/libcrypto/sha/sha1dgst.c | 244 +- src/lib/libcrypto/sha/sha1s.cpp | 2 +- src/lib/libcrypto/sha/sha1test.c | 35 +- src/lib/libcrypto/sha/sha_dgst.c | 250 +- src/lib/libcrypto/sha/sha_locl.h | 78 +- src/lib/libcrypto/sha/sha_one.c | 9 +- src/lib/libcrypto/sha/sha_sgst.c | 246 -- src/lib/libcrypto/sha/shatest.c | 35 +- src/lib/libcrypto/stack/Makefile.ssl | 37 +- src/lib/libcrypto/stack/safestack.h | 129 + src/lib/libcrypto/stack/stack.c | 108 +- src/lib/libcrypto/stack/stack.h | 33 +- src/lib/libcrypto/threads/mttest.c | 119 +- src/lib/libcrypto/threads/th-lock.c | 79 +- src/lib/libcrypto/tmdiff.c | 106 +- src/lib/libcrypto/tmdiff.h | 81 + src/lib/libcrypto/txt_db/Makefile.ssl | 36 +- src/lib/libcrypto/txt_db/txt_db.c | 39 +- src/lib/libcrypto/txt_db/txt_db.h | 16 +- src/lib/libcrypto/util/add_cr.pl | 2 +- src/lib/libcrypto/util/ck_errf.pl | 3 +- src/lib/libcrypto/util/clean-depend.pl | 38 + src/lib/libcrypto/util/deleof.pl | 2 +- src/lib/libcrypto/util/do_ms.sh | 8 +- src/lib/libcrypto/util/domd | 11 + src/lib/libcrypto/util/err-ins.pl | 2 +- src/lib/libcrypto/util/files.pl | 2 +- src/lib/libcrypto/util/libeay.num | 789 +++- src/lib/libcrypto/util/mk1mf.pl | 316 +- src/lib/libcrypto/util/mkdef.pl | 444 +- src/lib/libcrypto/util/mkdir-p.pl | 33 + src/lib/libcrypto/util/mkerr.pl | 503 +++ src/lib/libcrypto/util/mkfiles.pl | 110 + src/lib/libcrypto/util/mklink.pl | 55 + src/lib/libcrypto/util/mklink.sh | 35 - src/lib/libcrypto/util/perlpath.pl | 9 +- src/lib/libcrypto/util/pl/BC-16.pl | 14 +- src/lib/libcrypto/util/pl/BC-32.pl | 153 +- src/lib/libcrypto/util/pl/Mingw32.pl | 79 + src/lib/libcrypto/util/pl/Mingw32f.pl | 73 + src/lib/libcrypto/util/pl/VC-16.pl | 14 +- src/lib/libcrypto/util/pl/VC-32.pl | 33 +- src/lib/libcrypto/util/pl/linux.pl | 16 +- src/lib/libcrypto/util/pl/ultrix.pl | 38 + src/lib/libcrypto/util/pl/unix.pl | 23 +- src/lib/libcrypto/util/point.sh | 4 +- src/lib/libcrypto/util/ranlib.sh | 23 - src/lib/libcrypto/util/sep_lib.sh | 3 - src/lib/libcrypto/util/sp-diff.pl | 2 +- src/lib/libcrypto/util/src-dep.pl | 2 +- src/lib/libcrypto/util/ssldir.pl | 52 - src/lib/libcrypto/util/ssleay.num | 61 + src/lib/libcrypto/util/tab_num.pl | 2 +- src/lib/libcrypto/util/up_ver.pl | 79 - src/lib/libcrypto/util/x86asm.sh | 4 +- src/lib/libcrypto/x509/Makefile.ssl | 374 +- src/lib/libcrypto/x509/attrib | 38 - src/lib/libcrypto/x509/by_dir.c | 57 +- src/lib/libcrypto/x509/by_file.c | 41 +- src/lib/libcrypto/x509/v3_net.c | 87 - src/lib/libcrypto/x509/v3_x509.c | 253 -- src/lib/libcrypto/x509/x509.doc | 27 - src/lib/libcrypto/x509/x509.err | 46 - src/lib/libcrypto/x509/x509.h | 627 +-- src/lib/libcrypto/x509/x509_cmp.c | 138 +- src/lib/libcrypto/x509/x509_d2.c | 13 +- src/lib/libcrypto/x509/x509_def.c | 16 +- src/lib/libcrypto/x509/x509_err.c | 136 +- src/lib/libcrypto/x509/x509_ext.c | 106 +- src/lib/libcrypto/x509/x509_lu.c | 139 +- src/lib/libcrypto/x509/x509_obj.c | 72 +- src/lib/libcrypto/x509/x509_r2x.c | 34 +- src/lib/libcrypto/x509/x509_req.c | 27 +- src/lib/libcrypto/x509/x509_set.c | 36 +- src/lib/libcrypto/x509/x509_txt.c | 18 +- src/lib/libcrypto/x509/x509_v3.c | 225 +- src/lib/libcrypto/x509/x509_vfy.c | 221 +- src/lib/libcrypto/x509/x509_vfy.h | 168 +- src/lib/libcrypto/x509/x509name.c | 137 +- src/lib/libcrypto/x509/x509pack.c | 157 - src/lib/libcrypto/x509/x509rset.c | 20 +- src/lib/libcrypto/x509/x509type.c | 13 +- src/lib/libcrypto/x509/x509v3.doc | 24 - src/lib/libcrypto/x509/x_all.c | 272 +- src/lib/libcrypto/x509v3/Makefile.ssl | 432 ++ src/lib/libcrypto/x509v3/README | 4 + src/lib/libcrypto/x509v3/format | 92 - src/lib/libcrypto/x509v3/header | 6 - src/lib/libcrypto/x509v3/v3_akey.c | 249 ++ src/lib/libcrypto/x509v3/v3_alt.c | 402 ++ src/lib/libcrypto/x509v3/v3_bcons.c | 164 + src/lib/libcrypto/x509v3/v3_bitst.c | 147 + src/lib/libcrypto/x509v3/v3_conf.c | 366 ++ src/lib/libcrypto/x509v3/v3_cpols.c | 655 +++ src/lib/libcrypto/x509v3/v3_crld.c | 283 ++ src/lib/libcrypto/x509v3/v3_enum.c | 103 + src/lib/libcrypto/x509v3/v3_extku.c | 150 + src/lib/libcrypto/x509v3/v3_genn.c | 237 + src/lib/libcrypto/x509v3/v3_ia5.c | 116 + src/lib/libcrypto/x509v3/v3_int.c | 79 + src/lib/libcrypto/x509v3/v3_ku.c | 318 -- src/lib/libcrypto/x509v3/v3_lib.c | 177 + src/lib/libcrypto/x509v3/v3_pku.c | 151 + src/lib/libcrypto/x509v3/v3_prn.c | 135 + src/lib/libcrypto/x509v3/v3_skey.c | 156 + src/lib/libcrypto/x509v3/v3_sxnet.c | 340 ++ src/lib/libcrypto/x509v3/v3_utl.c | 418 ++ src/lib/libcrypto/x509v3/v3conf.c | 128 + src/lib/libcrypto/x509v3/v3err.c | 171 + src/lib/libcrypto/x509v3/v3prin.c | 101 + src/lib/libcrypto/x509v3/x509v3.h | 607 ++- 661 files changed, 60139 insertions(+), 36094 deletions(-) create mode 100644 src/lib/libcrypto/asn1/a_enum.c create mode 100644 src/lib/libcrypto/asn1/a_gentm.c create mode 100644 src/lib/libcrypto/asn1/a_time.c create mode 100644 src/lib/libcrypto/asn1/a_utf8.c create mode 100644 src/lib/libcrypto/asn1/a_vis.c delete mode 100644 src/lib/libcrypto/asn1/asn1.err create mode 100644 src/lib/libcrypto/asn1/asn_pack.c create mode 100644 src/lib/libcrypto/asn1/f_enum.c create mode 100644 src/lib/libcrypto/asn1/nsseq.c create mode 100644 src/lib/libcrypto/asn1/p5_pbe.c create mode 100644 src/lib/libcrypto/asn1/p5_pbev2.c create mode 100644 src/lib/libcrypto/asn1/p8_pkey.c create mode 100644 src/lib/libcrypto/asn1/t_crl.c delete mode 100644 src/lib/libcrypto/bf/asm/bx86unix.cpp create mode 100644 src/lib/libcrypto/bf/bf_locl.h delete mode 100644 src/lib/libcrypto/bf/bf_locl.org delete mode 100644 src/lib/libcrypto/bio/bio.err create mode 100644 src/lib/libcrypto/bio/bss_bio.c create mode 100644 src/lib/libcrypto/bio/bss_log.c create mode 100644 src/lib/libcrypto/bn/asm/alpha.s.works create mode 100644 src/lib/libcrypto/bn/asm/bn-alpha.pl delete mode 100644 src/lib/libcrypto/bn/asm/bn86unix.cpp create mode 100644 src/lib/libcrypto/bn/asm/ca.pl create mode 100644 src/lib/libcrypto/bn/asm/co-586.pl create mode 100644 src/lib/libcrypto/bn/asm/co-alpha.pl create mode 100644 src/lib/libcrypto/bn/asm/mips1.s create mode 100644 src/lib/libcrypto/bn/asm/mips3.s delete mode 100644 src/lib/libcrypto/bn/asm/sparc.s create mode 100644 src/lib/libcrypto/bn/asm/sparcv8.S create mode 100644 src/lib/libcrypto/bn/asm/sparcv8plus.S create mode 100644 src/lib/libcrypto/bn/asm/vms.mar create mode 100644 src/lib/libcrypto/bn/asm/x86.pl delete mode 100644 src/lib/libcrypto/bn/bn.err create mode 100644 src/lib/libcrypto/bn/bn.h create mode 100644 src/lib/libcrypto/bn/bn.mul delete mode 100644 src/lib/libcrypto/bn/bn.org create mode 100644 src/lib/libcrypto/bn/bn_asm.c create mode 100644 src/lib/libcrypto/bn/bn_comba.c create mode 100644 src/lib/libcrypto/bn/bn_exp2.c delete mode 100644 src/lib/libcrypto/bn/bn_m.c delete mode 100644 src/lib/libcrypto/bn/bn_mod.c delete mode 100644 src/lib/libcrypto/bn/bn_mulw.c create mode 100644 src/lib/libcrypto/bn/bn_opts.c delete mode 100644 src/lib/libcrypto/bn/bn_sub.c create mode 100644 src/lib/libcrypto/bn/comba.pl create mode 100644 src/lib/libcrypto/bn/d.c create mode 100644 src/lib/libcrypto/bn/exp.c create mode 100644 src/lib/libcrypto/bn/new create mode 100644 src/lib/libcrypto/bn/test.c create mode 100644 src/lib/libcrypto/bn/todo create mode 100644 src/lib/libcrypto/bn/vms-helper.c delete mode 100644 src/lib/libcrypto/buffer/buffer.err delete mode 100644 src/lib/libcrypto/cast/asm/cx86unix.cpp delete mode 100644 src/lib/libcrypto/conf/conf.err delete mode 100644 src/lib/libcrypto/cryptall.h create mode 100644 src/lib/libcrypto/crypto-lib.com delete mode 100644 src/lib/libcrypto/crypto.c delete mode 100644 src/lib/libcrypto/crypto.err delete mode 100644 src/lib/libcrypto/date.h delete mode 100644 src/lib/libcrypto/des/asm/dx86unix.cpp delete mode 100644 src/lib/libcrypto/des/asm/yx86unix.cpp create mode 100644 src/lib/libcrypto/des/des-lib.com create mode 100644 src/lib/libcrypto/des/des.h delete mode 100644 src/lib/libcrypto/des/des.org create mode 100644 src/lib/libcrypto/des/des_locl.h delete mode 100644 src/lib/libcrypto/des/des_locl.org create mode 100644 src/lib/libcrypto/des/ede_cbcm_enc.c delete mode 100644 src/lib/libcrypto/des/ede_enc.c delete mode 100644 src/lib/libcrypto/des/ranlib.sh delete mode 100644 src/lib/libcrypto/des/vms.com delete mode 100644 src/lib/libcrypto/dh/dh.err delete mode 100644 src/lib/libcrypto/dsa/dsa.err create mode 100644 src/lib/libcrypto/dsa/dsa_asn1.c create mode 100644 src/lib/libcrypto/ebcdic.h delete mode 100644 src/lib/libcrypto/err/err_code.pl delete mode 100644 src/lib/libcrypto/err/err_genc.pl delete mode 100644 src/lib/libcrypto/err/error.err create mode 100644 src/lib/libcrypto/err/openssl.ec delete mode 100644 src/lib/libcrypto/err/ssleay.ec create mode 100644 src/lib/libcrypto/evp/bio_ok.c delete mode 100644 src/lib/libcrypto/evp/evp.err create mode 100644 src/lib/libcrypto/evp/evp_pbe.c create mode 100644 src/lib/libcrypto/evp/evp_pkey.c create mode 100644 src/lib/libcrypto/evp/p5_crpt.c create mode 100644 src/lib/libcrypto/evp/p5_crpt2.c delete mode 100644 src/lib/libcrypto/evp/pk_lib.c create mode 100644 src/lib/libcrypto/idea/idea.h create mode 100644 src/lib/libcrypto/install.com delete mode 100644 src/lib/libcrypto/libvms.com create mode 100644 src/lib/libcrypto/md2/md2.h delete mode 100644 src/lib/libcrypto/md2/md2.org create mode 100644 src/lib/libcrypto/md32_common.h create mode 100644 src/lib/libcrypto/md5/asm/md5-sparcv9.S delete mode 100644 src/lib/libcrypto/md5/asm/mx86unix.cpp create mode 100644 src/lib/libcrypto/objects/o_names.c delete mode 100644 src/lib/libcrypto/objects/obj_dat.h delete mode 100644 src/lib/libcrypto/objects/objects.err create mode 100644 src/lib/libcrypto/opensslconf.h.in create mode 100644 src/lib/libcrypto/opensslv.h delete mode 100644 src/lib/libcrypto/pem/ctx_size.c delete mode 100644 src/lib/libcrypto/pem/pem.err delete mode 100644 src/lib/libcrypto/pem/pem.org create mode 100644 src/lib/libcrypto/pem/pem2.h create mode 100644 src/lib/libcrypto/perlasm/alpha.pl create mode 100644 src/lib/libcrypto/perlasm/x86nasm.pl create mode 100644 src/lib/libcrypto/pkcs7/bio_ber.c create mode 100644 src/lib/libcrypto/pkcs7/dec.c create mode 100644 src/lib/libcrypto/pkcs7/des.pem create mode 100644 src/lib/libcrypto/pkcs7/es1.pem create mode 100644 src/lib/libcrypto/pkcs7/example.c create mode 100644 src/lib/libcrypto/pkcs7/example.h create mode 100644 src/lib/libcrypto/pkcs7/info.pem create mode 100644 src/lib/libcrypto/pkcs7/infokey.pem delete mode 100644 src/lib/libcrypto/pkcs7/mf.p7 delete mode 100644 src/lib/libcrypto/pkcs7/p7.tst delete mode 100644 src/lib/libcrypto/pkcs7/pkcs7.err create mode 100644 src/lib/libcrypto/rand/rand_lib.c delete mode 100644 src/lib/libcrypto/ranlib.sh create mode 100644 src/lib/libcrypto/rc2/rc2.h delete mode 100644 src/lib/libcrypto/rc2/rc2.org create mode 100644 src/lib/libcrypto/rc2/tab.c delete mode 100644 src/lib/libcrypto/rc4/asm/rx86unix.cpp create mode 100644 src/lib/libcrypto/rc4/rc4.h delete mode 100644 src/lib/libcrypto/rc4/rc4.org create mode 100644 src/lib/libcrypto/rc4/rc4_locl.h delete mode 100644 src/lib/libcrypto/rc4/rc4_locl.org delete mode 100644 src/lib/libcrypto/rc5/asm/r586unix.cpp delete mode 100644 src/lib/libcrypto/ripemd/asm/rm86unix.cpp delete mode 100644 src/lib/libcrypto/rsa/rsa.err create mode 100644 src/lib/libcrypto/rsa/rsa_chk.c create mode 100644 src/lib/libcrypto/rsa/rsa_oaep.c create mode 100644 src/lib/libcrypto/rsa/rsa_oaep_test.c delete mode 100644 src/lib/libcrypto/sha/asm/sx86unix.cpp delete mode 100644 src/lib/libcrypto/sha/sha_sgst.c create mode 100644 src/lib/libcrypto/stack/safestack.h create mode 100644 src/lib/libcrypto/tmdiff.h create mode 100644 src/lib/libcrypto/util/clean-depend.pl create mode 100644 src/lib/libcrypto/util/domd create mode 100644 src/lib/libcrypto/util/mkdir-p.pl create mode 100644 src/lib/libcrypto/util/mkerr.pl create mode 100644 src/lib/libcrypto/util/mkfiles.pl create mode 100644 src/lib/libcrypto/util/mklink.pl delete mode 100644 src/lib/libcrypto/util/mklink.sh create mode 100644 src/lib/libcrypto/util/pl/Mingw32.pl create mode 100644 src/lib/libcrypto/util/pl/Mingw32f.pl create mode 100644 src/lib/libcrypto/util/pl/ultrix.pl delete mode 100644 src/lib/libcrypto/util/ranlib.sh delete mode 100644 src/lib/libcrypto/util/ssldir.pl delete mode 100644 src/lib/libcrypto/util/up_ver.pl delete mode 100644 src/lib/libcrypto/x509/attrib delete mode 100644 src/lib/libcrypto/x509/v3_net.c delete mode 100644 src/lib/libcrypto/x509/v3_x509.c delete mode 100644 src/lib/libcrypto/x509/x509.doc delete mode 100644 src/lib/libcrypto/x509/x509.err delete mode 100644 src/lib/libcrypto/x509/x509pack.c delete mode 100644 src/lib/libcrypto/x509/x509v3.doc create mode 100644 src/lib/libcrypto/x509v3/Makefile.ssl create mode 100644 src/lib/libcrypto/x509v3/README delete mode 100644 src/lib/libcrypto/x509v3/format delete mode 100644 src/lib/libcrypto/x509v3/header create mode 100644 src/lib/libcrypto/x509v3/v3_akey.c create mode 100644 src/lib/libcrypto/x509v3/v3_alt.c create mode 100644 src/lib/libcrypto/x509v3/v3_bcons.c create mode 100644 src/lib/libcrypto/x509v3/v3_bitst.c create mode 100644 src/lib/libcrypto/x509v3/v3_conf.c create mode 100644 src/lib/libcrypto/x509v3/v3_cpols.c create mode 100644 src/lib/libcrypto/x509v3/v3_crld.c create mode 100644 src/lib/libcrypto/x509v3/v3_enum.c create mode 100644 src/lib/libcrypto/x509v3/v3_extku.c create mode 100644 src/lib/libcrypto/x509v3/v3_genn.c create mode 100644 src/lib/libcrypto/x509v3/v3_ia5.c create mode 100644 src/lib/libcrypto/x509v3/v3_int.c delete mode 100644 src/lib/libcrypto/x509v3/v3_ku.c create mode 100644 src/lib/libcrypto/x509v3/v3_lib.c create mode 100644 src/lib/libcrypto/x509v3/v3_pku.c create mode 100644 src/lib/libcrypto/x509v3/v3_prn.c create mode 100644 src/lib/libcrypto/x509v3/v3_skey.c create mode 100644 src/lib/libcrypto/x509v3/v3_sxnet.c create mode 100644 src/lib/libcrypto/x509v3/v3_utl.c create mode 100644 src/lib/libcrypto/x509v3/v3conf.c create mode 100644 src/lib/libcrypto/x509v3/v3err.c create mode 100644 src/lib/libcrypto/x509v3/v3prin.c (limited to 'src/lib/libcrypto') diff --git a/src/lib/libcrypto/Attic/Makefile b/src/lib/libcrypto/Attic/Makefile index eb49323ad5..37aaac1528 100644 --- a/src/lib/libcrypto/Attic/Makefile +++ b/src/lib/libcrypto/Attic/Makefile @@ -1,133 +1,179 @@ -LIB= crypto -CFLAGS+= -DNO_IDEA -DTERMIOS -DL_ENDIAN -DANSI_SOURCE -CFLAGS+= -I${.CURDIR}/../include -SRCS+= cryptlib.c mem.c cversion.c ex_data.c cpt_err.c -CFLAGS+= -I${.CURDIR}/md2 -SRCS+= md2_dgst.c md2_one.c -CFLAGS+= -I${.CURDIR}/md5 -SRCS+= md5_dgst.c md5_one.c -CFLAGS+= -I${.CURDIR}/sha -SRCS+= sha_dgst.c sha1dgst.c sha_one.c sha1_one.c -CFLAGS+= -I${.CURDIR}/mdc2 -SRCS+= mdc2dgst.c mdc2_one.c -CFLAGS+= -I${.CURDIR}/hmac -SRCS+= hmac.c -CFLAGS+= -I${.CURDIR}/ripemd -SRCS+= rmd_dgst.c rmd_one.c -CFLAGS+= -I${.CURDIR}/des -SRCS+= set_key.c ecb_enc.c cbc_enc.c ecb3_enc.c -SRCS+= cfb64enc.c cfb64ede.c cfb_enc.c ofb64ede.c -SRCS+= enc_read.c enc_writ.c ofb64enc.c ofb_enc.c -SRCS+= str2key.c pcbc_enc.c qud_cksm.c rand_key.c -SRCS+= read2pwd.c fcrypt.c xcbc_enc.c read_pwd.c -SRCS+= rpc_enc.c cbc_cksm.c supp.c -CFLAGS+= -I${.CURDIR}/rc2 -SRCS+= rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c -SRCS+= rc2ofb64.c -CFLAGS+= -I${.CURDIR}/rc4 -SRCS+= rc4_skey.c -CFLAGS+= -I${.CURDIR}/rc5 -SRCS+= rc5_skey.c rc5_ecb.c rc5cfb64.c rc5cfb64.c -SRCS+= rc5ofb64.c -CFLAGS+= -I${.CURDIR}/idea -SRCS+= i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c -SRCS+= i_skey.c -CFLAGS+= -I${.CURDIR}/bf -SRCS+= bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c -CFLAGS+= -I${.CURDIR}/cast -SRCS+= c_skey.c c_ecb.c c_cfb64.c c_ofb64.c -CFLAGS+= -I${.CURDIR}/bn -SRCS+= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c -SRCS+= bn_mul.c bn_print.c bn_rand.c bn_shift.c bn_sub.c -SRCS+= bn_word.c bn_blind.c bn_gcd.c bn_prime.c bn_err.c -SRCS+= bn_sqr.c bn_recp.c bn_mont.c bn_mpi.c -CFLAGS+= -I${.CURDIR}/rsa -SRCS+= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c -SRCS+= rsa_saos.c rsa_err.c rsa_pk1.c rsa_ssl.c -SRCS+= rsa_none.c -CFLAGS+= -I${.CURDIR}/dsa -SRCS+= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c -SRCS+= dsa_sign.c dsa_err.c -CFLAGS+= -I${.CURDIR}/dh -SRCS+= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c -CFLAGS+= -I${.CURDIR}/buffer -SRCS+= buffer.c buf_err.c -CFLAGS+= -I${.CURDIR}/bio -SRCS+= bio_lib.c bio_cb.c bio_err.c bss_mem.c -SRCS+= bss_null.c bss_fd.c bss_file.c bss_sock.c -SRCS+= bss_conn.c bf_null.c bf_buff.c -SRCS+= b_print.c b_dump.c b_sock.c bss_acpt.c -SRCS+= bf_nbio.c -CFLAGS+= -I${.CURDIR}/stack -SRCS+= stack.c -CFLAGS+= -I${.CURDIR}/lhash -SRCS+= lhash.c lh_stats.c -CFLAGS+= -I${.CURDIR}/rand -SRCS+= md_rand.c randfile.c -CFLAGS+= -I${.CURDIR}/err -SRCS+= err.c err_all.c err_prn.c -CFLAGS+= -I${.CURDIR}/objects -SRCS+= obj_dat.c obj_lib.c obj_err.c -CFLAGS+= -I${.CURDIR}/evp -SRCS+= encode.c digest.c evp_enc.c evp_key.c -SRCS+= e_ecb_d.c e_cbc_d.c e_cfb_d.c e_ofb_d.c -SRCS+= e_ecb_i.c e_cbc_i.c e_cfb_i.c e_ofb_i.c -SRCS+= e_ecb_3d.c e_cbc_3d.c e_rc4.c names.c -SRCS+= e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c e_ecb_r2.c -SRCS+= e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c e_ecb_bf.c -SRCS+= e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c e_ecb_c.c -SRCS+= e_cbc_c.c e_cfb_c.c e_ofb_c.c e_ecb_r5.c -SRCS+= e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c m_null.c -SRCS+= m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c -SRCS+= m_dss1.c m_mdc2.c m_ripemd.c p_open.c -SRCS+= p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c -SRCS+= p_dec.c bio_md.c bio_b64.c bio_enc.c -SRCS+= evp_err.c e_null.c c_all.c evp_lib.c -CFLAGS+= -I${.CURDIR}/pem -SRCS+= pem_sign.c pem_seal.c pem_info.c pem_lib.c -SRCS+= pem_all.c pem_err.c -CFLAGS+= -I${.CURDIR}/asn1 -SRCS+= a_object.c a_bitstr.c a_utctm.c a_int.c -SRCS+= a_octet.c a_print.c a_type.c a_set.c -SRCS+= a_dup.c a_d2i_fp.c a_i2d_fp.c a_sign.c -SRCS+= a_digest.c a_verify.c x_algor.c x_val.c -SRCS+= x_pubkey.c x_sig.c x_req.c x_attrib.c -SRCS+= x_name.c x_cinf.c x_x509.c x_crl.c -SRCS+= x_info.c x_spki.c d2i_r_pr.c i2d_r_pr.c -SRCS+= d2i_r_pu.c i2d_r_pu.c d2i_s_pr.c i2d_s_pr.c -SRCS+= d2i_s_pu.c i2d_s_pu.c d2i_pu.c d2i_pr.c -SRCS+= i2d_pu.c i2d_pr.c t_req.c t_x509.c -SRCS+= t_pkey.c p7_i_s.c p7_signi.c p7_signd.c -SRCS+= p7_recip.c p7_enc_c.c p7_evp.c p7_dgst.c -SRCS+= p7_s_e.c p7_enc.c p7_lib.c f_int.c -SRCS+= f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c -SRCS+= d2i_dsap.c n_pkey.c a_hdr.c x_pkey.c -SRCS+= a_bool.c x_exten.c asn1_par.c asn1_lib.c -SRCS+= asn1_err.c a_meth.c a_bytes.c evp_asn1.c -CFLAGS+= -I${.CURDIR}/x509 -SRCS+= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c -SRCS+= x509_obj.c x509_req.c x509_vfy.c x509_set.c -SRCS+= x509rset.c x509_err.c x509name.c x509_v3.c -SRCS+= x509_ext.c x509pack.c x509type.c x509_lu.c -SRCS+= x_all.c x509_txt.c by_file.c by_dir.c -SRCS+= v3_net.c v3_x509.c -CFLAGS+= -I${.CURDIR}/conf -SRCS+= conf.c conf_err.c -CFLAGS+= -I${.CURDIR}/txt_db -SRCS+= txt_db.c -CFLAGS+= -I${.CURDIR}/pkcs7 -SRCS+= pk7_lib.c pkcs7err.c pk7_doit.c - -.PATH: ${.CURDIR}/md2 ${.CURDIR}/md5 ${.CURDIR}/sha ${.CURDIR}/mdc2 \ - ${.CURDIR}/hmac ${.CURDIR}/ripemd ${.CURDIR}/des ${.CURDIR}/rc2 \ - ${.CURDIR}/rc4 ${.CURDIR}/rc5 ${.CURDIR}/idea ${.CURDIR}/bf \ - ${.CURDIR}/cast ${.CURDIR}/bn ${.CURDIR}/rsa ${.CURDIR}/dsa \ - ${.CURDIR}/dh ${.CURDIR}/buffer ${.CURDIR}/bio ${.CURDIR}/stack \ - ${.CURDIR}/lhash ${.CURDIR}/rand ${.CURDIR}/err ${.CURDIR}/objects \ - ${.CURDIR}/evp ${.CURDIR}/pem ${.CURDIR}/asn1 ${.CURDIR}/asn1 \ - ${.CURDIR}/x509 ${.CURDIR}/conf txt_db/txt_db.c ${.CURDIR}/pkcs7 \ - ${.CURDIR}/txt_db - -.include +# +# SSLeay/crypto/Makefile +# +DIR= crypto +TOP= .. +CC= cc +INCLUDE= -I. -I../include +INCLUDES= -I.. -I../../include +CFLAG= -g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl +INSTALLTOP= /usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) +MAKEFILE= Makefile.ssl +RM= rm -f +AR= ar r +PEX_LIBS= +EX_LIBS= + +CFLAGS= $(INCLUDE) $(CFLAG) + + +LIBS= + +SDIRS= md2 md5 sha mdc2 hmac ripemd \ + des rc2 rc4 rc5 idea bf cast \ + bn rsa dsa dh \ + buffer bio stack lhash rand err objects \ + evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp + +GENERAL=Makefile README crypto-lib.com install.com + +LIB= $(TOP)/libcrypto.a +LIBSRC= cryptlib.c mem.c cversion.c ex_data.c tmdiff.c cpt_err.c +LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o tmdiff.o cpt_err.o + +SRC= $(LIBSRC) + +EXHEADER= crypto.h tmdiff.h opensslv.h opensslconf.h ebcdic.h +HEADER= cryptlib.h buildinf.h $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + @(cd ..; $(MAKE) DIRS=$(DIR) all) + +all: buildinf.h lib subdirs + +buildinf.h: ../Makefile.ssl + ( echo "#ifndef MK1MF_BUILD"; \ + echo " /* auto-generated by crypto/Makefile.ssl for crypto/cversion.c */"; \ + echo " #define CFLAGS \"$(CC) $(CFLAG)\""; \ + echo " #define PLATFORM \"$(PLATFORM)\""; \ + echo " #define DATE \"`date`\""; \ + echo "#endif" ) >buildinf.h + +subdirs: + @for i in $(SDIRS) ;\ + do \ + (cd $$i && echo "making all in crypto/$$i..." && \ + $(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}' all ) || exit 1; \ + done; + +files: + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + @for i in $(SDIRS) ;\ + do \ + (cd $$i; echo "making 'files' in crypto/$$i..."; \ + $(MAKE) PERL='${PERL}' files ); \ + done; + +links: + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @for i in $(SDIRS); do \ + (cd $$i; echo "making links in crypto/$$i..."; \ + $(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}' PERL='${PERL}' links ); \ + done; + +lib: $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + $(RANLIB) $(LIB) + @touch lib + +libs: + @for i in $(SDIRS) ;\ + do \ + (cd $$i; echo "making libs in crypto/$$i..."; \ + $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \ + done; + +tests: + @for i in $(SDIRS) ;\ + do \ + (cd $$i; echo "making tests in crypto/$$i..."; \ + $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' tests ); \ + done; + +install: + @for i in $(EXHEADER) ;\ + do \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ + done; + @for i in $(SDIRS) ;\ + do \ + (cd $$i; echo "making install in crypto/$$i..."; \ + $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \ + done; + +lint: + @for i in $(SDIRS) ;\ + do \ + (cd $$i; echo "making lint in crypto/$$i..."; \ + $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' lint ); \ + done; + +depend: + if [ ! -e buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist + $(MAKEDEPEND) $(INCLUDE) $(DEPFLAG) $(PROGS) $(LIBSRC) + if [ ! -s buildinf.h ]; then rm buildinf.h; fi + @for i in $(SDIRS) ;\ + do \ + (cd $$i; echo "making depend in crypto/$$i..."; \ + $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' DEPFLAG='${DEPFLAG}' depend ); \ + done; + +clean: + rm -f buildinf.h *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + @for i in $(SDIRS) ;\ + do \ + (cd $$i; echo "making clean in crypto/$$i..."; \ + $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' clean ); \ + done; + +dclean: + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + @for i in $(SDIRS) ;\ + do \ + (cd $$i; echo "making dclean in crypto/$$i..."; \ + $(MAKE) PERL='${PERL}' CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \ + done; + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +cpt_err.o: ../include/openssl/crypto.h ../include/openssl/err.h +cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/stack.h +cryptlib.o: ../include/openssl/bio.h ../include/openssl/buffer.h +cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +cryptlib.o: ../include/openssl/e_os2.h ../include/openssl/err.h +cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +cryptlib.o: ../include/openssl/stack.h cryptlib.h +cversion.o: ../include/openssl/bio.h ../include/openssl/buffer.h +cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +cversion.o: ../include/openssl/e_os2.h ../include/openssl/err.h +cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +cversion.o: ../include/openssl/stack.h buildinf.h cryptlib.h +ex_data.o: ../include/openssl/bio.h ../include/openssl/buffer.h +ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +ex_data.o: ../include/openssl/e_os2.h ../include/openssl/err.h +ex_data.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h +ex_data.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h +mem.o: ../include/openssl/bio.h ../include/openssl/buffer.h +mem.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +mem.o: ../include/openssl/e_os2.h ../include/openssl/err.h +mem.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h +mem.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h +tmdiff.o: ../include/openssl/bio.h ../include/openssl/buffer.h +tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +tmdiff.o: ../include/openssl/e_os2.h ../include/openssl/err.h +tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +tmdiff.o: ../include/openssl/stack.h ../include/openssl/tmdiff.h cryptlib.h diff --git a/src/lib/libcrypto/Makefile.ssl b/src/lib/libcrypto/Makefile.ssl index efdbba38ac..37aaac1528 100644 --- a/src/lib/libcrypto/Makefile.ssl +++ b/src/lib/libcrypto/Makefile.ssl @@ -8,24 +8,20 @@ CC= cc INCLUDE= -I. -I../include INCLUDES= -I.. -I../../include CFLAG= -g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP= /usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl -RM= /bin/rm -f +RM= rm -f AR= ar r -MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl -MAKEFILE= Makefile.ssl - PEX_LIBS= EX_LIBS= -CFLAGS= $(INCLUDE) $(CFLAG) -DCFLAGS=" \"$(CC) $(CFLAG)\" " +CFLAGS= $(INCLUDE) $(CFLAG) -ERR=crypto -ERRC=cpt_err LIBS= @@ -33,129 +29,151 @@ SDIRS= md2 md5 sha mdc2 hmac ripemd \ des rc2 rc4 rc5 idea bf cast \ bn rsa dsa dh \ buffer bio stack lhash rand err objects \ - evp pem x509 \ - asn1 conf txt_db pkcs7 + evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp -GENERAL=Makefile README +GENERAL=Makefile README crypto-lib.com install.com LIB= $(TOP)/libcrypto.a -LIBSRC= cryptlib.c mem.c cversion.c ex_data.c $(ERRC).c -LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o $(ERRC).o +LIBSRC= cryptlib.c mem.c cversion.c ex_data.c tmdiff.c cpt_err.c +LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o tmdiff.o cpt_err.o SRC= $(LIBSRC) -EXHEADER= crypto.h cryptall.h -HEADER= cryptlib.h date.h $(EXHEADER) +EXHEADER= crypto.h tmdiff.h opensslv.h opensslconf.h ebcdic.h +HEADER= cryptlib.h buildinf.h $(EXHEADER) ALL= $(GENERAL) $(SRC) $(HEADER) top: @(cd ..; $(MAKE) DIRS=$(DIR) all) -all: date.h lib subdirs +all: buildinf.h lib subdirs -date.h: ../Makefile.ssl ../VERSION - echo "#define DATE \"`date`\"" >date.h +buildinf.h: ../Makefile.ssl + ( echo "#ifndef MK1MF_BUILD"; \ + echo " /* auto-generated by crypto/Makefile.ssl for crypto/cversion.c */"; \ + echo " #define CFLAGS \"$(CC) $(CFLAG)\""; \ + echo " #define PLATFORM \"$(PLATFORM)\""; \ + echo " #define DATE \"`date`\""; \ + echo "#endif" ) >buildinf.h subdirs: @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making all in $$i..."; \ - $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' 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}' all ); \ + (cd $$i && echo "making all in crypto/$$i..." && \ + $(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}' all ) || exit 1; \ done; files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making 'files' in $$i..."; \ - $(MAKE) files ); \ + (cd $$i; echo "making 'files' in crypto/$$i..."; \ + $(MAKE) PERL='${PERL}' files ); \ done; links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../include $(HEADER) ; - $(TOP)/util/mklink.sh ../test $(TEST) ; - $(TOP)/util/mklink.sh ../apps $(APPS) ; - $(TOP)/util/point.sh Makefile.ssl Makefile; - @for i in $(SDIRS) ;\ - do \ - (cd $$i; echo "making links in $$i..."; \ - $(MAKE) links ); \ + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @for i in $(SDIRS); do \ + (cd $$i; echo "making links in crypto/$$i..."; \ + $(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}' PERL='${PERL}' links ); \ done; lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib libs: @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making libs in $$i..."; \ - $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \ + (cd $$i; echo "making libs in crypto/$$i..."; \ + $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \ done; tests: @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making tests in $$i..."; \ + (cd $$i; echo "making tests in crypto/$$i..."; \ $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' tests ); \ done; install: @for i in $(EXHEADER) ;\ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making install in $$i..."; \ - $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \ + (cd $$i; echo "making install in crypto/$$i..."; \ + $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \ done; lint: @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making lint in $$i..."; \ + (cd $$i; echo "making lint in crypto/$$i..."; \ $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' lint ); \ done; depend: - $(MAKEDEPEND) $(INCLUDE) $(PROGS) $(LIBSRC) + if [ ! -e buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist + $(MAKEDEPEND) $(INCLUDE) $(DEPFLAG) $(PROGS) $(LIBSRC) + if [ ! -s buildinf.h ]; then rm buildinf.h; fi @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making depend in $$i..."; \ - $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' MAKEDEPEND='${MAKEDEPEND}' depend ); \ + (cd $$i; echo "making depend in crypto/$$i..."; \ + $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' DEPFLAG='${DEPFLAG}' depend ); \ done; clean: - /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + rm -f buildinf.h *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making clean in $$i..."; \ + (cd $$i; echo "making clean in crypto/$$i..."; \ $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' clean ); \ done; dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) @for i in $(SDIRS) ;\ do \ - (cd $$i; echo "making dclean in $$i..."; \ - $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \ - done; - -errors: - perl ./err/err_code.pl -conf err/ssleay.ec *.c */*.c ../ssl/*.c ../rsaref/*.c - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl err/err_genc.pl -s $(ERR).h $(ERRC).c - @for i in $(SDIRS) ;\ - do \ - (cd $$i; echo "making errors in $$i..."; \ - $(MAKE) errors ); \ + (cd $$i; echo "making dclean in crypto/$$i..."; \ + $(MAKE) PERL='${PERL}' CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \ done; # DO NOT DELETE THIS LINE -- make depend depends on it. + +cpt_err.o: ../include/openssl/crypto.h ../include/openssl/err.h +cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/stack.h +cryptlib.o: ../include/openssl/bio.h ../include/openssl/buffer.h +cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +cryptlib.o: ../include/openssl/e_os2.h ../include/openssl/err.h +cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +cryptlib.o: ../include/openssl/stack.h cryptlib.h +cversion.o: ../include/openssl/bio.h ../include/openssl/buffer.h +cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +cversion.o: ../include/openssl/e_os2.h ../include/openssl/err.h +cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +cversion.o: ../include/openssl/stack.h buildinf.h cryptlib.h +ex_data.o: ../include/openssl/bio.h ../include/openssl/buffer.h +ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +ex_data.o: ../include/openssl/e_os2.h ../include/openssl/err.h +ex_data.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h +ex_data.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h +mem.o: ../include/openssl/bio.h ../include/openssl/buffer.h +mem.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +mem.o: ../include/openssl/e_os2.h ../include/openssl/err.h +mem.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h +mem.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h +tmdiff.o: ../include/openssl/bio.h ../include/openssl/buffer.h +tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os.h +tmdiff.o: ../include/openssl/e_os2.h ../include/openssl/err.h +tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h +tmdiff.o: ../include/openssl/stack.h ../include/openssl/tmdiff.h cryptlib.h diff --git a/src/lib/libcrypto/asn1/Makefile.ssl b/src/lib/libcrypto/asn1/Makefile.ssl index 30751bd156..541d1dac4a 100644 --- a/src/lib/libcrypto/asn1/Makefile.ssl +++ b/src/lib/libcrypto/asn1/Makefile.ssl @@ -7,51 +7,51 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=asn1 -ERRC=asn1_err GENERAL=Makefile README TEST= APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \ - a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \ - a_sign.c a_digest.c a_verify.c \ +LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \ + a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \ + a_enum.c a_vis.c a_utf8.c a_sign.c a_digest.c a_verify.c \ x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \ - x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c \ + x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c nsseq.c \ d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \ d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \ d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\ - t_req.c t_x509.c t_pkey.c \ + t_req.c t_x509.c t_crl.c t_pkey.c \ p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \ p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \ f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \ - a_hdr.c x_pkey.c a_bool.c x_exten.c \ - asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c \ - evp_asn1.c -LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_int.o a_octet.o a_print.o \ - a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \ - a_sign.o a_digest.o a_verify.o \ + f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c \ + asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c \ + evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c +LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \ + a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \ + a_enum.o a_vis.o a_utf8.o a_sign.o a_digest.o a_verify.o \ x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \ - x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o \ + x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o nsseq.o \ d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \ d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \ d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \ - t_req.o t_x509.o t_pkey.o \ + t_req.o t_x509.o t_crl.o t_pkey.o \ p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \ p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \ f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \ - a_hdr.o x_pkey.o a_bool.o x_exten.o \ - asn1_par.o asn1_lib.o $(ERRC).o a_meth.o a_bytes.o \ - evp_asn1.o + f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o \ + asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o \ + evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o SRC= $(LIBSRC) @@ -75,24 +75,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -104,17 +103,988 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c # DO NOT DELETE THIS LINE -- make depend depends on it. + +a_bitstr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_bitstr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_bitstr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_bitstr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_bitstr.o: ../../include/openssl/opensslconf.h +a_bitstr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_bitstr.o: ../../include/openssl/stack.h ../cryptlib.h +a_bmp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_bmp.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_bmp.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_bmp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_bmp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_bmp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_bmp.o: ../cryptlib.h +a_bool.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_bool.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_bool.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_bool.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_bool.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_bool.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_bool.o: ../cryptlib.h +a_bytes.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +a_bytes.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +a_bytes.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +a_bytes.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_bytes.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +a_bytes.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_bytes.o: ../../include/openssl/stack.h ../cryptlib.h +a_d2i_fp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +a_d2i_fp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +a_d2i_fp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +a_d2i_fp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_d2i_fp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +a_d2i_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_d2i_fp.o: ../../include/openssl/stack.h ../cryptlib.h +a_digest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_digest.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +a_digest.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +a_digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +a_digest.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +a_digest.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h +a_digest.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +a_digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +a_digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +a_digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +a_digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +a_digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +a_digest.o: ../../include/openssl/stack.h ../cryptlib.h +a_dup.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +a_dup.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +a_dup.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +a_dup.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_dup.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +a_dup.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_dup.o: ../../include/openssl/stack.h ../cryptlib.h +a_enum.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_enum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_enum.o: ../cryptlib.h +a_gentm.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_gentm.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_gentm.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_gentm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_gentm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_gentm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_gentm.o: ../cryptlib.h +a_hdr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +a_hdr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +a_hdr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +a_hdr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_hdr.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +a_hdr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_hdr.o: ../../include/openssl/stack.h ../cryptlib.h +a_i2d_fp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +a_i2d_fp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +a_i2d_fp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +a_i2d_fp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_i2d_fp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +a_i2d_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_i2d_fp.o: ../../include/openssl/stack.h ../cryptlib.h +a_int.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_int.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_int.o: ../cryptlib.h +a_meth.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_meth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_meth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_meth.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_meth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_meth.o: ../cryptlib.h +a_object.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_object.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_object.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_object.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_object.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +a_object.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_object.o: ../../include/openssl/stack.h ../cryptlib.h +a_octet.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_octet.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_octet.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_octet.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_octet.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_octet.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_octet.o: ../cryptlib.h +a_print.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_print.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_print.o: ../cryptlib.h +a_set.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +a_set.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +a_set.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +a_set.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_set.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +a_set.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_set.o: ../../include/openssl/stack.h ../cryptlib.h +a_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +a_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +a_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +a_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +a_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h +a_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +a_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +a_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +a_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +a_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +a_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +a_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +a_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +a_sign.o: ../cryptlib.h +a_time.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_time.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_time.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_time.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_time.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_time.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_time.o: ../cryptlib.h +a_type.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +a_type.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +a_type.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +a_type.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_type.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +a_type.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +a_type.o: ../../include/openssl/stack.h ../cryptlib.h +a_utctm.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_utctm.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_utctm.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_utctm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_utctm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_utctm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_utctm.o: ../cryptlib.h +a_utf8.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_utf8.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_utf8.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_utf8.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_utf8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_utf8.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_utf8.o: ../cryptlib.h +a_verify.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_verify.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +a_verify.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +a_verify.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +a_verify.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +a_verify.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +a_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h +a_verify.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +a_verify.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +a_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +a_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +a_verify.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +a_verify.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +a_verify.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +a_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +a_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +a_verify.o: ../cryptlib.h +a_vis.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +a_vis.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +a_vis.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +a_vis.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +a_vis.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +a_vis.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +a_vis.o: ../cryptlib.h +asn1_err.o: ../../include/openssl/asn1.h ../../include/openssl/bn.h +asn1_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +asn1_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +asn1_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +asn1_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +asn1_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +asn1_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +asn1_lib.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +asn1_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +asn1_lib.o: ../../include/openssl/stack.h ../cryptlib.h +asn1_par.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +asn1_par.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +asn1_par.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +asn1_par.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +asn1_par.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +asn1_par.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +asn1_par.o: ../../include/openssl/stack.h ../cryptlib.h +asn_pack.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +asn_pack.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +asn_pack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +asn_pack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +asn_pack.o: ../../include/openssl/opensslconf.h +asn_pack.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +asn_pack.o: ../../include/openssl/stack.h ../cryptlib.h +d2i_dhp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +d2i_dhp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +d2i_dhp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +d2i_dhp.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h +d2i_dhp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +d2i_dhp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +d2i_dhp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +d2i_dhp.o: ../../include/openssl/stack.h ../cryptlib.h +d2i_dsap.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +d2i_dsap.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +d2i_dsap.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +d2i_dsap.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +d2i_dsap.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +d2i_dsap.o: ../../include/openssl/err.h ../../include/openssl/objects.h +d2i_dsap.o: ../../include/openssl/opensslconf.h +d2i_dsap.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +d2i_dsap.o: ../../include/openssl/stack.h ../cryptlib.h +d2i_pr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +d2i_pr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +d2i_pr.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +d2i_pr.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +d2i_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +d2i_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +d2i_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h +d2i_pr.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +d2i_pr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +d2i_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +d2i_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +d2i_pr.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +d2i_pr.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +d2i_pr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +d2i_pr.o: ../../include/openssl/stack.h ../cryptlib.h +d2i_pu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +d2i_pu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +d2i_pu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +d2i_pu.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +d2i_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +d2i_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +d2i_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h +d2i_pu.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +d2i_pu.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +d2i_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +d2i_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +d2i_pu.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +d2i_pu.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +d2i_pu.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +d2i_pu.o: ../../include/openssl/stack.h ../cryptlib.h +d2i_r_pr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +d2i_r_pr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +d2i_r_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +d2i_r_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +d2i_r_pr.o: ../../include/openssl/err.h ../../include/openssl/objects.h +d2i_r_pr.o: ../../include/openssl/opensslconf.h +d2i_r_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h +d2i_r_pr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +d2i_r_pr.o: ../cryptlib.h +d2i_r_pu.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +d2i_r_pu.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +d2i_r_pu.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +d2i_r_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +d2i_r_pu.o: ../../include/openssl/err.h ../../include/openssl/objects.h +d2i_r_pu.o: ../../include/openssl/opensslconf.h +d2i_r_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h +d2i_r_pu.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +d2i_r_pu.o: ../cryptlib.h +d2i_s_pr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +d2i_s_pr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +d2i_s_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +d2i_s_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +d2i_s_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +d2i_s_pr.o: ../../include/openssl/err.h ../../include/openssl/objects.h +d2i_s_pr.o: ../../include/openssl/opensslconf.h +d2i_s_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +d2i_s_pr.o: ../../include/openssl/stack.h ../cryptlib.h +d2i_s_pu.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +d2i_s_pu.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +d2i_s_pu.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +d2i_s_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +d2i_s_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +d2i_s_pu.o: ../../include/openssl/err.h ../../include/openssl/objects.h +d2i_s_pu.o: ../../include/openssl/opensslconf.h +d2i_s_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +d2i_s_pu.o: ../../include/openssl/stack.h ../cryptlib.h +evp_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +evp_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +evp_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +evp_asn1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +evp_asn1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +evp_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +evp_asn1.o: ../../include/openssl/stack.h ../cryptlib.h +f_enum.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +f_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +f_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +f_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +f_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +f_enum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +f_enum.o: ../cryptlib.h +f_int.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +f_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +f_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +f_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +f_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +f_int.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +f_int.o: ../cryptlib.h +f_string.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +f_string.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +f_string.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +f_string.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +f_string.o: ../../include/openssl/opensslconf.h +f_string.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +f_string.o: ../../include/openssl/stack.h ../cryptlib.h +i2d_dhp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +i2d_dhp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +i2d_dhp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +i2d_dhp.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h +i2d_dhp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +i2d_dhp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +i2d_dhp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +i2d_dhp.o: ../cryptlib.h +i2d_dsap.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +i2d_dsap.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +i2d_dsap.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +i2d_dsap.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +i2d_dsap.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +i2d_dsap.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +i2d_dsap.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +i2d_dsap.o: ../../include/openssl/stack.h ../cryptlib.h +i2d_pr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +i2d_pr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +i2d_pr.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +i2d_pr.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +i2d_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +i2d_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +i2d_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h +i2d_pr.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +i2d_pr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +i2d_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +i2d_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +i2d_pr.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +i2d_pr.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +i2d_pr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +i2d_pr.o: ../../include/openssl/stack.h ../cryptlib.h +i2d_pu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +i2d_pu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +i2d_pu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +i2d_pu.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +i2d_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +i2d_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +i2d_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h +i2d_pu.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +i2d_pu.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +i2d_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +i2d_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +i2d_pu.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +i2d_pu.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +i2d_pu.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +i2d_pu.o: ../../include/openssl/stack.h ../cryptlib.h +i2d_r_pr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +i2d_r_pr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +i2d_r_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +i2d_r_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +i2d_r_pr.o: ../../include/openssl/err.h ../../include/openssl/objects.h +i2d_r_pr.o: ../../include/openssl/opensslconf.h +i2d_r_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h +i2d_r_pr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +i2d_r_pr.o: ../cryptlib.h +i2d_r_pu.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +i2d_r_pu.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +i2d_r_pu.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +i2d_r_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +i2d_r_pu.o: ../../include/openssl/err.h ../../include/openssl/objects.h +i2d_r_pu.o: ../../include/openssl/opensslconf.h +i2d_r_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h +i2d_r_pu.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +i2d_r_pu.o: ../cryptlib.h +i2d_s_pr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +i2d_s_pr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +i2d_s_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +i2d_s_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +i2d_s_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +i2d_s_pr.o: ../../include/openssl/err.h ../../include/openssl/objects.h +i2d_s_pr.o: ../../include/openssl/opensslconf.h +i2d_s_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +i2d_s_pr.o: ../../include/openssl/stack.h ../cryptlib.h +i2d_s_pu.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +i2d_s_pu.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +i2d_s_pu.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +i2d_s_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +i2d_s_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +i2d_s_pu.o: ../../include/openssl/err.h ../../include/openssl/objects.h +i2d_s_pu.o: ../../include/openssl/opensslconf.h +i2d_s_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +i2d_s_pu.o: ../../include/openssl/stack.h ../cryptlib.h +n_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +n_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +n_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +n_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +n_pkey.o: ../../include/openssl/des.h ../../include/openssl/dh.h +n_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +n_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +n_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +n_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +n_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +n_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +n_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +n_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +n_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +n_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +n_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +n_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +nsseq.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +nsseq.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +nsseq.o: ../../include/openssl/bn.h ../../include/openssl/cast.h +nsseq.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +nsseq.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +nsseq.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +nsseq.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +nsseq.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +nsseq.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +nsseq.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +nsseq.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +nsseq.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +nsseq.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +nsseq.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +nsseq.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +nsseq.o: ../../include/openssl/x509_vfy.h +p5_pbe.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p5_pbe.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p5_pbe.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p5_pbe.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p5_pbe.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p5_pbe.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p5_pbe.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p5_pbe.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p5_pbe.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p5_pbe.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p5_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p5_pbe.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h +p5_pbe.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p5_pbe.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p5_pbe.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p5_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p5_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p5_pbe.o: ../cryptlib.h +p5_pbev2.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p5_pbev2.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p5_pbev2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p5_pbev2.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p5_pbev2.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p5_pbev2.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p5_pbev2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p5_pbev2.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p5_pbev2.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p5_pbev2.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p5_pbev2.o: ../../include/openssl/opensslconf.h +p5_pbev2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p5_pbev2.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h +p5_pbev2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p5_pbev2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p5_pbev2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p5_pbev2.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p5_pbev2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p7_dgst.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_dgst.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_dgst.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_dgst.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_dgst.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_dgst.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_dgst.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_dgst.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_dgst.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_dgst.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p7_dgst.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +p7_dgst.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p7_dgst.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p7_dgst.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p7_dgst.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p7_dgst.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p7_enc.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_enc.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_enc.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_enc.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_enc.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_enc.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_enc.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_enc.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_enc.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p7_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +p7_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p7_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p7_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p7_enc.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p7_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p7_enc_c.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_enc_c.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_enc_c.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_enc_c.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_enc_c.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_enc_c.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_enc_c.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_enc_c.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_enc_c.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_enc_c.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_enc_c.o: ../../include/openssl/opensslconf.h +p7_enc_c.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p7_enc_c.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p7_enc_c.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p7_enc_c.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p7_enc_c.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p7_enc_c.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p7_enc_c.o: ../cryptlib.h +p7_evp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_evp.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_evp.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_evp.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_evp.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_evp.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_evp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_evp.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_evp.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_evp.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_evp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p7_evp.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +p7_evp.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p7_evp.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p7_evp.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p7_evp.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p7_evp.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p7_i_s.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_i_s.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_i_s.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_i_s.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_i_s.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_i_s.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_i_s.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_i_s.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_i_s.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_i_s.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_i_s.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p7_i_s.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +p7_i_s.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p7_i_s.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p7_i_s.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p7_i_s.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p7_i_s.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p7_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_lib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_lib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_lib.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_lib.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p7_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +p7_lib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p7_lib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p7_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p7_lib.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p7_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p7_recip.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_recip.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_recip.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_recip.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_recip.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_recip.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_recip.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_recip.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_recip.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_recip.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_recip.o: ../../include/openssl/opensslconf.h +p7_recip.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p7_recip.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p7_recip.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p7_recip.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p7_recip.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p7_recip.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p7_recip.o: ../cryptlib.h +p7_s_e.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_s_e.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_s_e.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_s_e.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_s_e.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_s_e.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_s_e.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_s_e.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_s_e.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_s_e.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_s_e.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p7_s_e.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +p7_s_e.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p7_s_e.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p7_s_e.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p7_s_e.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p7_s_e.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p7_signd.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_signd.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_signd.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_signd.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_signd.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_signd.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_signd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_signd.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_signd.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_signd.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_signd.o: ../../include/openssl/opensslconf.h +p7_signd.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p7_signd.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p7_signd.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p7_signd.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p7_signd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p7_signd.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p7_signd.o: ../cryptlib.h +p7_signi.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p7_signi.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p7_signi.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p7_signi.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p7_signi.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p7_signi.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p7_signi.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p7_signi.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p7_signi.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p7_signi.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p7_signi.o: ../../include/openssl/opensslconf.h +p7_signi.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p7_signi.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p7_signi.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p7_signi.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p7_signi.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p7_signi.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p7_signi.o: ../cryptlib.h +p8_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p8_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p8_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p8_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p8_pkey.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p8_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p8_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p8_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p8_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p8_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p8_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p8_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +p8_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p8_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p8_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p8_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p8_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +t_crl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +t_crl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +t_crl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +t_crl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +t_crl.o: ../../include/openssl/des.h ../../include/openssl/dh.h +t_crl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +t_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +t_crl.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +t_crl.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +t_crl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +t_crl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +t_crl.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +t_crl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +t_crl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +t_crl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +t_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +t_crl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +t_crl.o: ../../include/openssl/x509v3.h ../cryptlib.h +t_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +t_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +t_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +t_pkey.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +t_pkey.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +t_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h +t_pkey.o: ../../include/openssl/stack.h ../cryptlib.h +t_req.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +t_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +t_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +t_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +t_req.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +t_req.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +t_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h +t_req.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +t_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +t_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +t_req.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +t_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +t_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +t_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +t_req.o: ../cryptlib.h +t_x509.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +t_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +t_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +t_x509.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +t_x509.o: ../../include/openssl/des.h ../../include/openssl/dh.h +t_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +t_x509.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +t_x509.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +t_x509.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +t_x509.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +t_x509.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +t_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +t_x509.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +t_x509.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +t_x509.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +t_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +t_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h +x_algor.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_algor.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_algor.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_algor.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_algor.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_algor.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_algor.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_algor.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_algor.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_algor.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_algor.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_algor.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_algor.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_algor.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_algor.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_algor.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_algor.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_attrib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_attrib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_attrib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_attrib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_attrib.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_attrib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_attrib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_attrib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_attrib.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_attrib.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_attrib.o: ../../include/openssl/opensslconf.h +x_attrib.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x_attrib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x_attrib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x_attrib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x_attrib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x_attrib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x_attrib.o: ../cryptlib.h +x_cinf.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_cinf.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_cinf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_cinf.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_cinf.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_cinf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_cinf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_cinf.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_cinf.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_cinf.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_cinf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_cinf.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_cinf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_cinf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_cinf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_cinf.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_cinf.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_crl.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_crl.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_crl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_crl.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_crl.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_crl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_crl.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_crl.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_crl.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_crl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_crl.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_crl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_crl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_crl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_crl.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_crl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_exten.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_exten.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_exten.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_exten.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_exten.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_exten.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_exten.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_exten.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_exten.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_exten.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_exten.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_exten.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_exten.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_exten.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_exten.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_exten.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_exten.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_info.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_info.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_info.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_info.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_info.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_info.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_info.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_info.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_info.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_info.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_info.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_info.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_info.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_info.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_info.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_name.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_name.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_name.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_name.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_name.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_name.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_name.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_name.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_name.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_name.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_name.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_name.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_name.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_name.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_name.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_name.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_name.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_pkey.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_pubkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_pubkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_pubkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_pubkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_pubkey.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_pubkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_pubkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_pubkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_pubkey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_pubkey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_pubkey.o: ../../include/openssl/opensslconf.h +x_pubkey.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x_pubkey.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x_pubkey.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x_pubkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x_pubkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x_pubkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x_pubkey.o: ../cryptlib.h +x_req.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_req.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_req.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_req.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_req.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_req.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_req.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_req.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_req.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_req.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_req.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_req.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_req.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_req.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_req.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_sig.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_sig.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_sig.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_sig.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_sig.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_sig.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_sig.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_sig.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_sig.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_sig.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_sig.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_sig.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_sig.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_sig.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_sig.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_sig.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_sig.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_spki.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_spki.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_spki.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_spki.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_spki.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_spki.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_spki.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_spki.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_spki.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_spki.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_spki.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_val.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_val.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_val.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_val.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_val.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_val.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_val.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_val.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_val.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_val.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_val.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_val.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_val.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_val.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_val.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_val.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_val.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x_x509.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +x_x509.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +x_x509.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +x_x509.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x_x509.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +x_x509.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +x_x509.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +x_x509.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x_x509.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x_x509.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x_x509.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x_x509.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x_x509.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 2c10120651..38ea802be8 100644 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ b/src/lib/libcrypto/asn1/a_bitstr.c @@ -58,45 +58,60 @@ #include #include "cryptlib.h" -#include "asn1.h" +#include -/* ASN1err(ASN1_F_ASN1_STRING_NEW,ASN1_R_STRING_TOO_SHORT); - * ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,ASN1_R_EXPECTING_A_BIT_STRING); - */ - -int i2d_ASN1_BIT_STRING(a,pp) -ASN1_BIT_STRING *a; -unsigned char **pp; +int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) { - int ret,j,r,bits; + int ret,j,r,bits,len; unsigned char *p,*d; if (a == NULL) return(0); - /* our bit strings are always a multiple of 8 :-) */ - bits=0; - ret=1+a->length; + len=a->length; + + if (len > 0) + { + if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) + { + bits=(int)a->flags&0x07; + } + else + { + for ( ; len > 0; len--) + { + if (a->data[len-1]) break; + } + j=a->data[len-1]; + if (j & 0x01) bits=0; + else if (j & 0x02) bits=1; + else if (j & 0x04) bits=2; + else if (j & 0x08) bits=3; + else if (j & 0x10) bits=4; + else if (j & 0x20) bits=5; + else if (j & 0x40) bits=6; + else if (j & 0x80) bits=7; + else bits=0; /* should not happen */ + } + } + else + bits=0; + ret=1+len; r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING); if (pp == NULL) return(r); p= *pp; ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL); - if (bits == 0) - j=0; - else j=8-bits; - *(p++)=(unsigned char)j; + *(p++)=(unsigned char)bits; d=a->data; - memcpy(p,d,a->length); - p+=a->length; - if (a->length > 0) p[-1]&=(0xff< 0) p[-1]&=(0xff<flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */ + ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ + if (len-- > 1) /* using one because of the bits left byte */ { s=(unsigned char *)Malloc((int)len); @@ -158,10 +179,7 @@ err: /* These next 2 functions from Goetz Babin-Ebell */ -int ASN1_BIT_STRING_set_bit(a,n,value) -ASN1_BIT_STRING *a; -int n; -int value; +int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) { int w,v,iv; unsigned char *c; @@ -170,6 +188,8 @@ int value; v=1<<(7-(n&0x07)); iv= ~v; + a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ + if (a == NULL) return(0); if ((a->length < (w+1)) || (a->data == NULL)) { @@ -189,9 +209,7 @@ int value; return(1); } -int ASN1_BIT_STRING_get_bit(a,n) -ASN1_BIT_STRING *a; -int n; +int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) { int w,v; diff --git a/src/lib/libcrypto/asn1/a_bmp.c b/src/lib/libcrypto/asn1/a_bmp.c index 774502b1fc..6075871984 100644 --- a/src/lib/libcrypto/asn1/a_bmp.c +++ b/src/lib/libcrypto/asn1/a_bmp.c @@ -58,31 +58,24 @@ #include #include "cryptlib.h" -#include "asn1.h" +#include -/* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER); - */ - -int i2d_ASN1_BMPSTRING(a, pp) -ASN1_BMPSTRING *a; -unsigned char **pp; +int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp) { return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL)); } -ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(a, pp, length) -ASN1_BMPSTRING **a; -unsigned char **pp; -long length; +ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp, + long length) { ASN1_BMPSTRING *ret=NULL; ret=(ASN1_BMPSTRING *)d2i_ASN1_bytes((ASN1_STRING **)a, - pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL); + pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL); if (ret == NULL) { - ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ASN1_R_ERROR_STACK); + ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ERR_R_NESTED_ASN1_ERROR); return(NULL); } return(ret); diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c index 41a95aa278..18fa61840b 100644 --- a/src/lib/libcrypto/asn1/a_bool.c +++ b/src/lib/libcrypto/asn1/a_bool.c @@ -58,15 +58,9 @@ #include #include "cryptlib.h" -#include "asn1.h" +#include -/* ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,ASN1_R_EXPECTING_A_BOOLEAN); - * ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,ASN1_R_BOOLEAN_IS_WRONG_LENGTH); - */ - -int i2d_ASN1_BOOLEAN(a,pp) -int a; -unsigned char **pp; +int i2d_ASN1_BOOLEAN(int a, unsigned char **pp) { int r; unsigned char *p; @@ -81,10 +75,7 @@ unsigned char **pp; return(r); } -int d2i_ASN1_BOOLEAN(a, pp, length) -int *a; -unsigned char **pp; -long length; +int d2i_ASN1_BOOLEAN(int *a, unsigned char **pp, long length) { int ret= -1; unsigned char *p; diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c index 14168d61ad..e452e03b88 100644 --- a/src/lib/libcrypto/asn1/a_bytes.c +++ b/src/lib/libcrypto/asn1/a_bytes.c @@ -58,38 +58,24 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" - -/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK); - * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_ERROR_STACK); - * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_WRONG_TYPE); - * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG); - */ +#include static unsigned long tag2bit[32]={ 0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */ B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */ B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */ -B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 12-15 */ +B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */ 0, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0, 0,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, }; -#ifndef NOPROTO static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c); -#else -static int asn1_collate_primative(); -#endif - -/* type is a 'bitmap' of acceptable string types to be accepted. +/* type is a 'bitmap' of acceptable string types. */ -ASN1_STRING *d2i_ASN1_type_bytes(a, pp, length, type) -ASN1_STRING **a; -unsigned char **pp; -long length; -int type; +ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp, + long length, int type) { ASN1_STRING *ret=NULL; unsigned char *p,*s; @@ -152,11 +138,7 @@ err: return(NULL); } -int i2d_ASN1_bytes(a, pp, tag, xclass) -ASN1_STRING *a; -unsigned char **pp; -int tag; -int xclass; +int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) { int ret,r,constructed; unsigned char *p; @@ -182,12 +164,8 @@ int xclass; return(r); } -ASN1_STRING *d2i_ASN1_bytes(a, pp, length, Ptag, Pclass) -ASN1_STRING **a; -unsigned char **pp; -long length; -int Ptag; -int Pclass; +ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length, + int Ptag, int Pclass) { ASN1_STRING *ret=NULL; unsigned char *p,*s; @@ -279,9 +257,7 @@ err: * them into the one struture that is then returned */ /* There have been a few bug fixes for this function from * Paul Keogh , many thanks to him */ -static int asn1_collate_primative(a,c) -ASN1_STRING *a; -ASN1_CTX *c; +static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c) { ASN1_STRING *os=NULL; BUF_MEM b; @@ -338,7 +314,7 @@ ASN1_CTX *c; if (os != NULL) ASN1_STRING_free(os); return(1); err: - ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,c->error); + ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error); if (os != NULL) ASN1_STRING_free(os); if (b.data != NULL) Free(b.data); return(0); diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c index d952836a91..a49d1cb289 100644 --- a/src/lib/libcrypto/asn1/a_d2i_fp.c +++ b/src/lib/libcrypto/asn1/a_d2i_fp.c @@ -58,17 +58,14 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "asn1_mac.h" +#include +#include #define HEADER_SIZE 8 #ifndef NO_FP_API -char *ASN1_d2i_fp(xnew,d2i,in,x) -char *(*xnew)(); -char *(*d2i)(); -FILE *in; -unsigned char **x; +char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in, + unsigned char **x) { BIO *b; char *ret; @@ -85,11 +82,8 @@ unsigned char **x; } #endif -char *ASN1_d2i_bio(xnew,d2i,in,x) -char *(*xnew)(); -char *(*d2i)(); -BIO *in; -unsigned char **x; +char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in, + unsigned char **x) { BUF_MEM *b; unsigned char *p; diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c index 8ddb65b0dc..8c45add557 100644 --- a/src/lib/libcrypto/asn1/a_digest.c +++ b/src/lib/libcrypto/asn1/a_digest.c @@ -62,16 +62,12 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "x509.h" -#include "buffer.h" +#include +#include +#include -int ASN1_digest(i2d,type,data,md,len) -int (*i2d)(); -EVP_MD *type; -char *data; -unsigned char *md; -unsigned int *len; +int ASN1_digest(int (*i2d)(), EVP_MD *type, char *data, unsigned char *md, + unsigned int *len) { EVP_MD_CTX ctx; int i; diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c index 961b4cb069..c0a8709f3b 100644 --- a/src/lib/libcrypto/asn1/a_dup.c +++ b/src/lib/libcrypto/asn1/a_dup.c @@ -58,14 +58,11 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" +#include #define READ_CHUNK 2048 -char *ASN1_dup(i2d,d2i,x) -int (*i2d)(); -char *(*d2i)(); -char *x; +char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x) { unsigned char *b,*p; long i; diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c new file mode 100644 index 0000000000..9239ecc439 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_enum.c @@ -0,0 +1,326 @@ +/* crypto/asn1/a_enum.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include + +/* + * Code for ENUMERATED type: identical to INTEGER apart from a different tag. + * for comments on encoding see a_int.c + */ + +int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp) + { + int pad=0,ret,r,i,t; + unsigned char *p,*n,pb=0; + + if ((a == NULL) || (a->data == NULL)) return(0); + t=a->type; + if (a->length == 0) + ret=1; + else + { + ret=a->length; + i=a->data[0]; + if ((t == V_ASN1_ENUMERATED) && (i > 127)) { + pad=1; + pb=0; + } else if(t == V_ASN1_NEG_ENUMERATED) { + if(i>128) { + pad=1; + pb=0xFF; + } else if(i == 128) { + for(i = 1; i < a->length; i++) if(a->data[i]) { + pad=1; + pb=0xFF; + break; + } + } + } + ret+=pad; + } + r=ASN1_object_size(0,ret,V_ASN1_ENUMERATED); + if (pp == NULL) return(r); + p= *pp; + + ASN1_put_object(&p,0,ret,V_ASN1_ENUMERATED,V_ASN1_UNIVERSAL); + if (pad) *(p++)=pb; + if (a->length == 0) + *(p++)=0; + else if (t == V_ASN1_ENUMERATED) + { + memcpy(p,a->data,(unsigned int)a->length); + p+=a->length; + } + else { + /* Begin at the end of the encoding */ + n=a->data + a->length - 1; + p += a->length - 1; + i = a->length; + /* Copy zeros to destination as long as source is zero */ + while(!*n) { + *(p--) = 0; + n--; + i--; + } + /* Complement and increment next octet */ + *(p--) = ((*(n--)) ^ 0xff) + 1; + i--; + /* Complement any octets left */ + for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; + p += a->length; + } + + *pp=p; + return(r); + } + +ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp, + long length) + { + ASN1_ENUMERATED *ret=NULL; + unsigned char *p,*to,*s; + long len; + int inf,tag,xclass; + int i; + + if ((a == NULL) || ((*a) == NULL)) + { + if ((ret=ASN1_ENUMERATED_new()) == NULL) return(NULL); + ret->type=V_ASN1_ENUMERATED; + } + else + ret=(*a); + + p= *pp; + inf=ASN1_get_object(&p,&len,&tag,&xclass,length); + if (inf & 0x80) + { + i=ASN1_R_BAD_OBJECT_HEADER; + goto err; + } + + if (tag != V_ASN1_ENUMERATED) + { + i=ASN1_R_EXPECTING_AN_ENUMERATED; + goto err; + } + + /* We must Malloc stuff, even for 0 bytes otherwise it + * signifies a missing NULL parameter. */ + s=(unsigned char *)Malloc((int)len+1); + if (s == NULL) + { + i=ERR_R_MALLOC_FAILURE; + goto err; + } + to=s; + if (*p & 0x80) /* a negative number */ + { + ret->type=V_ASN1_NEG_ENUMERATED; + if ((*p == 0xff) && (len != 1)) { + p++; + len--; + } + i = len; + p += i - 1; + to += i - 1; + while((!*p) && i) { + *(to--) = 0; + i--; + p--; + } + if(!i) { + *s = 1; + s[len] = 0; + p += len; + len++; + } else { + *(to--) = (*(p--) ^ 0xff) + 1; + i--; + for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; + p += len; + } + } else { + ret->type=V_ASN1_ENUMERATED; + if ((*p == 0) && (len != 1)) + { + p++; + len--; + } + memcpy(s,p,(int)len); + p+=len; + } + + if (ret->data != NULL) Free((char *)ret->data); + ret->data=s; + ret->length=(int)len; + if (a != NULL) (*a)=ret; + *pp=p; + return(ret); +err: + ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) + ASN1_ENUMERATED_free(ret); + return(NULL); + } + +int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) + { + int i,j,k; + unsigned char buf[sizeof(long)+1]; + long d; + + a->type=V_ASN1_ENUMERATED; + if (a->length < (sizeof(long)+1)) + { + if (a->data != NULL) + Free((char *)a->data); + if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL) + memset((char *)a->data,0,sizeof(long)+1); + } + if (a->data == NULL) + { + ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); + return(0); + } + d=v; + if (d < 0) + { + d= -d; + a->type=V_ASN1_NEG_ENUMERATED; + } + + for (i=0; i>=8; + } + j=0; + for (k=i-1; k >=0; k--) + a->data[j++]=buf[k]; + a->length=j; + return(1); + } + +long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) + { + int neg=0,i; + long r=0; + + if (a == NULL) return(0L); + i=a->type; + if (i == V_ASN1_NEG_ENUMERATED) + neg=1; + else if (i != V_ASN1_ENUMERATED) + return(0); + + if (a->length > sizeof(long)) + { + /* hmm... a bit ugly */ + return(0xffffffffL); + } + if (a->data == NULL) + return(0); + + for (i=0; ilength; i++) + { + r<<=8; + r|=(unsigned char)a->data[i]; + } + if (neg) r= -r; + return(r); + } + +ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) + { + ASN1_ENUMERATED *ret; + int len,j; + + if (ai == NULL) + ret=ASN1_ENUMERATED_new(); + else + ret=ai; + if (ret == NULL) + { + ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); + goto err; + } + if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED; + else ret->type=V_ASN1_ENUMERATED; + j=BN_num_bits(bn); + len=((j == 0)?0:((j/8)+1)); + ret->data=(unsigned char *)Malloc(len+4); + ret->length=BN_bn2bin(bn,ret->data); + return(ret); +err: + if (ret != ai) ASN1_ENUMERATED_free(ret); + return(NULL); + } + +BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) + { + BIGNUM *ret; + + if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) + ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); + if(ai->type == V_ASN1_NEG_ENUMERATED) bn->neg = 1; + return(ret); + } diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c new file mode 100644 index 0000000000..226474f057 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_gentm.c @@ -0,0 +1,224 @@ +/* crypto/asn1/a_gentm.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* GENERALIZEDTIME implementation, written by Steve Henson. Based on UTCTIME */ + +#include +#include +#include "cryptlib.h" +#include + +int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) + { +#ifdef CHARSET_EBCDIC + /* KLUDGE! We convert to ascii before writing DER */ + int len; + char tmp[24]; + ASN1_STRING tmpstr = *(ASN1_STRING *)a; + + len = tmpstr.length; + ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len); + tmpstr.data = tmp; + + a = (ASN1_GENERALIZEDTIME *) &tmpstr; +#endif + return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, + V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); + } + + +ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, + unsigned char **pp, long length) + { + ASN1_GENERALIZEDTIME *ret=NULL; + + ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, + V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); + if (ret == NULL) + { + ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); + return(NULL); + } +#ifdef CHARSET_EBCDIC + ascii2ebcdic(ret->data, ret->data, ret->length); +#endif + if (!ASN1_GENERALIZEDTIME_check(ret)) + { + ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT); + goto err; + } + + return(ret); +err: + if ((ret != NULL) && ((a == NULL) || (*a != ret))) + ASN1_GENERALIZEDTIME_free(ret); + return(NULL); + } + +int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) + { + static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; + static int max[9]={99, 99,12,31,23,59,59,12,59}; + char *a; + int n,i,l,o; + + if (d->type != V_ASN1_GENERALIZEDTIME) return(0); + l=d->length; + a=(char *)d->data; + o=0; + /* GENERALIZEDTIME is similar to UTCTIME except the year is + * represented as YYYY. This stuff treats everything as a two digit + * field so make first two fields 00 to 99 + */ + if (l < 13) goto err; + for (i=0; i<7; i++) + { + if ((i == 6) && ((a[o] == 'Z') || + (a[o] == '+') || (a[o] == '-'))) + { i++; break; } + if ((a[o] < '0') || (a[o] > '9')) goto err; + n= a[o]-'0'; + if (++o > l) goto err; + + if ((a[o] < '0') || (a[o] > '9')) goto err; + n=(n*10)+ a[o]-'0'; + if (++o > l) goto err; + + if ((n < min[i]) || (n > max[i])) goto err; + } + if (a[o] == 'Z') + o++; + else if ((a[o] == '+') || (a[o] == '-')) + { + o++; + if (o+4 > l) goto err; + for (i=7; i<9; i++) + { + if ((a[o] < '0') || (a[o] > '9')) goto err; + n= a[o]-'0'; + o++; + if ((a[o] < '0') || (a[o] > '9')) goto err; + n=(n*10)+ a[o]-'0'; + if ((n < min[i]) || (n > max[i])) goto err; + o++; + } + } + return(o == l); +err: + return(0); + } + +int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str) + { + ASN1_GENERALIZEDTIME t; + + t.type=V_ASN1_GENERALIZEDTIME; + t.length=strlen(str); + t.data=(unsigned char *)str; + if (ASN1_GENERALIZEDTIME_check(&t)) + { + if (s != NULL) + { + ASN1_STRING_set((ASN1_STRING *)s, + (unsigned char *)str,t.length); + } + return(1); + } + else + return(0); + } + +ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, + time_t t) + { + char *p; + struct tm *ts; +#if defined(THREADS) && !defined(WIN32) + struct tm data; +#endif + + if (s == NULL) + s=ASN1_GENERALIZEDTIME_new(); + if (s == NULL) + return(NULL); + +#if defined(THREADS) && !defined(WIN32) + gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */ + ts=&data; +#else + ts=gmtime(&t); +#endif + p=(char *)s->data; + if ((p == NULL) || (s->length < 16)) + { + p=Malloc(20); + if (p == NULL) return(NULL); + if (s->data != NULL) + Free(s->data); + s->data=(unsigned char *)p; + } + + sprintf(p,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, + ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); + s->length=strlen(p); + s->type=V_ASN1_GENERALIZEDTIME; +#ifdef CHARSET_EBCDIC_not + ebcdic2ascii(s->data, s->data, s->length); +#endif + return(s); + } diff --git a/src/lib/libcrypto/asn1/a_hdr.c b/src/lib/libcrypto/asn1/a_hdr.c index 4fb7a5fa75..1171d36443 100644 --- a/src/lib/libcrypto/asn1/a_hdr.c +++ b/src/lib/libcrypto/asn1/a_hdr.c @@ -58,19 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "asn1.h" +#include +#include -/* - * ASN1err(ASN1_F_D2I_ASN1_HEADER,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT); - * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT); - * ASN1err(ASN1_F_ASN1_HEADER_NEW,ASN1_R_BAD_GET_OBJECT); - */ - -int i2d_ASN1_HEADER(a,pp) -ASN1_HEADER *a; -unsigned char **pp; +int i2d_ASN1_HEADER(ASN1_HEADER *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -85,10 +76,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -ASN1_HEADER *d2i_ASN1_HEADER(a,pp,length) -ASN1_HEADER **a; -unsigned char **pp; -long length; +ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new); @@ -107,9 +96,10 @@ long length; M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER); } -ASN1_HEADER *ASN1_HEADER_new() +ASN1_HEADER *ASN1_HEADER_new(void) { ASN1_HEADER *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,ASN1_HEADER); M_ASN1_New(ret->header,ASN1_OCTET_STRING_new); @@ -119,8 +109,7 @@ ASN1_HEADER *ASN1_HEADER_new() M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW); } -void ASN1_HEADER_free(a) -ASN1_HEADER *a; +void ASN1_HEADER_free(ASN1_HEADER *a) { if (a == NULL) return; ASN1_OCTET_STRING_free(a->header); diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c index 66c3df68d5..6bd845443c 100644 --- a/src/lib/libcrypto/asn1/a_i2d_fp.c +++ b/src/lib/libcrypto/asn1/a_i2d_fp.c @@ -58,14 +58,11 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "asn1_mac.h" +#include +#include #ifndef NO_FP_API -int ASN1_i2d_fp(i2d,out,x) -int (*i2d)(); -FILE *out; -unsigned char *x; +int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x) { BIO *b; int ret; @@ -82,10 +79,7 @@ unsigned char *x; } #endif -int ASN1_i2d_bio(i2d,out,x) -int (*i2d)(); -BIO *out; -unsigned char *x; +int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x) { char *b; unsigned char *p; diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c index df79cf99bb..d05436378b 100644 --- a/src/lib/libcrypto/asn1/a_int.c +++ b/src/lib/libcrypto/asn1/a_int.c @@ -58,17 +58,37 @@ #include #include "cryptlib.h" -#include "asn1.h" +#include -/* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER); +/* + * This converts an ASN1 INTEGER into its DER encoding. + * The internal representation is an ASN1_STRING whose data is a big endian + * representation of the value, ignoring the sign. The sign is determined by + * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative. + * + * Positive integers are no problem: they are almost the same as the DER + * encoding, except if the first byte is >= 0x80 we need to add a zero pad. + * + * Negative integers are a bit trickier... + * The DER representation of negative integers is in 2s complement form. + * The internal form is converted by complementing each octet and finally + * adding one to the result. This can be done less messily with a little trick. + * If the internal form has trailing zeroes then they will become FF by the + * complement and 0 by the add one (due to carry) so just copy as many trailing + * zeros to the destination as there are in the source. The carry will add one + * to the last none zero octet: so complement this octet and add one and finally + * complement any left over until you get to the start of the string. + * + * Padding is a little trickier too. If the first bytes is > 0x80 then we pad + * with 0xff. However if the first byte is 0x80 and one of the following bytes + * is non-zero we pad with 0xff. The reason for this distinction is that 0x80 + * followed by optional zeros isn't padded. */ -int i2d_ASN1_INTEGER(a,pp) -ASN1_INTEGER *a; -unsigned char **pp; +int i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) { int pad=0,ret,r,i,t; - unsigned char *p,*pt,*n,pb=0; + unsigned char *p,*n,pb=0; if ((a == NULL) || (a->data == NULL)) return(0); t=a->type; @@ -78,16 +98,25 @@ unsigned char **pp; { ret=a->length; i=a->data[0]; - if ((t == V_ASN1_INTEGER) && (i > 127)) - { + if ((t == V_ASN1_INTEGER) && (i > 127)) { pad=1; pb=0; + } else if(t == V_ASN1_NEG_INTEGER) { + if(i>128) { + pad=1; + pb=0xFF; + } else if(i == 128) { + /* + * Special case: if any other bytes non zero we pad: + * otherwise we don't. + */ + for(i = 1; i < a->length; i++) if(a->data[i]) { + pad=1; + pb=0xFF; + break; + } } - else if ((t == V_ASN1_NEG_INTEGER) && (i>128)) - { - pad=1; - pb=0xFF; - } + } ret+=pad; } r=ASN1_object_size(0,ret,V_ASN1_INTEGER); @@ -96,33 +125,35 @@ unsigned char **pp; ASN1_put_object(&p,0,ret,V_ASN1_INTEGER,V_ASN1_UNIVERSAL); if (pad) *(p++)=pb; - if (a->length == 0) - *(p++)=0; - else if (t == V_ASN1_INTEGER) - { - memcpy(p,a->data,(unsigned int)a->length); - p+=a->length; - } - else - { - n=a->data; - pt=p; - for (i=a->length; i>0; i--) - *(p++)= (*(n++)^0xFF)+1; - if (!pad) *pt|=0x80; + if (a->length == 0) *(p++)=0; + else if (t == V_ASN1_INTEGER) memcpy(p,a->data,(unsigned int)a->length); + else { + /* Begin at the end of the encoding */ + n=a->data + a->length - 1; + p += a->length - 1; + i = a->length; + /* Copy zeros to destination as long as source is zero */ + while(!*n) { + *(p--) = 0; + n--; + i--; } + /* Complement and increment next octet */ + *(p--) = ((*(n--)) ^ 0xff) + 1; + i--; + /* Complement any octets left */ + for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; + } - *pp=p; + *pp+=r; return(r); } -ASN1_INTEGER *d2i_ASN1_INTEGER(a, pp, length) -ASN1_INTEGER **a; -unsigned char **pp; -long length; +ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp, + long length) { ASN1_INTEGER *ret=NULL; - unsigned char *p,*to,*s; + unsigned char *p,*to,*s, *pend; long len; int inf,tag,xclass; int i; @@ -137,6 +168,7 @@ long length; p= *pp; inf=ASN1_get_object(&p,&len,&tag,&xclass,length); + pend = p + len; if (inf & 0x80) { i=ASN1_R_BAD_OBJECT_HEADER; @@ -161,16 +193,102 @@ long length; if (*p & 0x80) /* a negative number */ { ret->type=V_ASN1_NEG_INTEGER; - if (*p == 0xff) + if ((*p == 0xff) && (len != 1)) { + p++; + len--; + } + i = len; + p += i - 1; + to += i - 1; + while((!*p) && i) { + *(to--) = 0; + i--; + p--; + } + /* Special case: if all zeros then the number will be of + * the form FF followed by n zero bytes: this corresponds to + * 1 followed by n zero bytes. We've already written n zeros + * so we just append an extra one and set the first byte to + * a 1. This is treated separately because it is the only case + * where the number of bytes is larger than len. + */ + if(!i) { + *s = 1; + s[len] = 0; + len++; + } else { + *(to--) = (*(p--) ^ 0xff) + 1; + i--; + for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; + } + } else { + ret->type=V_ASN1_INTEGER; + if ((*p == 0) && (len != 1)) { p++; len--; } - for (i=(int)len; i>0; i--) - *(to++)= (*(p++)^0xFF)+1; + memcpy(s,p,(int)len); + } + + if (ret->data != NULL) Free((char *)ret->data); + ret->data=s; + ret->length=(int)len; + if (a != NULL) (*a)=ret; + *pp=pend; + return(ret); +err: + ASN1err(ASN1_F_D2I_ASN1_INTEGER,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) + ASN1_INTEGER_free(ret); + return(NULL); + } + +/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of + * ASN1 integers: some broken software can encode a positive INTEGER + * with its MSB set as negative (it doesn't add a padding zero). + */ + +ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp, + long length) + { + ASN1_INTEGER *ret=NULL; + unsigned char *p,*to,*s; + long len; + int inf,tag,xclass; + int i; + + if ((a == NULL) || ((*a) == NULL)) + { + if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL); + ret->type=V_ASN1_INTEGER; } else + ret=(*a); + + p= *pp; + inf=ASN1_get_object(&p,&len,&tag,&xclass,length); + if (inf & 0x80) + { + i=ASN1_R_BAD_OBJECT_HEADER; + goto err; + } + + if (tag != V_ASN1_INTEGER) { + i=ASN1_R_EXPECTING_AN_INTEGER; + goto err; + } + + /* We must Malloc stuff, even for 0 bytes otherwise it + * signifies a missing NULL parameter. */ + s=(unsigned char *)Malloc((int)len+1); + if (s == NULL) + { + i=ERR_R_MALLOC_FAILURE; + goto err; + } + to=s; ret->type=V_ASN1_INTEGER; if ((*p == 0) && (len != 1)) { @@ -179,7 +297,6 @@ long length; } memcpy(s,p,(int)len); p+=len; - } if (ret->data != NULL) Free((char *)ret->data); ret->data=s; @@ -188,15 +305,13 @@ long length; *pp=p; return(ret); err: - ASN1err(ASN1_F_D2I_ASN1_INTEGER,i); + ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i); if ((ret != NULL) && ((a == NULL) || (*a != ret))) ASN1_INTEGER_free(ret); return(NULL); } -int ASN1_INTEGER_set(a,v) -ASN1_INTEGER *a; -long v; +int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) { int i,j,k; unsigned char buf[sizeof(long)+1]; @@ -229,15 +344,13 @@ long v; d>>=8; } j=0; - if (v < 0) a->data[j++]=0; for (k=i-1; k >=0; k--) a->data[j++]=buf[k]; a->length=j; return(1); } -long ASN1_INTEGER_get(a) -ASN1_INTEGER *a; +long ASN1_INTEGER_get(ASN1_INTEGER *a) { int neg=0,i; long r=0; @@ -266,9 +379,7 @@ ASN1_INTEGER *a; return(r); } -ASN1_INTEGER *BN_to_ASN1_INTEGER(bn,ai) -BIGNUM *bn; -ASN1_INTEGER *ai; +ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai) { ASN1_INTEGER *ret; int len,j; @@ -279,10 +390,11 @@ ASN1_INTEGER *ai; ret=ai; if (ret == NULL) { - ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ASN1_R_ERROR_STACK); + ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); goto err; } - ret->type=V_ASN1_INTEGER; + if(bn->neg) ret->type = V_ASN1_NEG_INTEGER; + else ret->type=V_ASN1_INTEGER; j=BN_num_bits(bn); len=((j == 0)?0:((j/8)+1)); ret->data=(unsigned char *)Malloc(len+4); @@ -293,13 +405,12 @@ err: return(NULL); } -BIGNUM *ASN1_INTEGER_to_BN(ai,bn) -ASN1_INTEGER *ai; -BIGNUM *bn; +BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn) { BIGNUM *ret; if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB); + if(ai->type == V_ASN1_NEG_INTEGER) bn->neg = 1; return(ret); } diff --git a/src/lib/libcrypto/asn1/a_meth.c b/src/lib/libcrypto/asn1/a_meth.c index 513625c305..63158e9cab 100644 --- a/src/lib/libcrypto/asn1/a_meth.c +++ b/src/lib/libcrypto/asn1/a_meth.c @@ -58,8 +58,8 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "x509.h" +#include +#include static ASN1_METHOD ia5string_meth={ (int (*)()) i2d_ASN1_IA5STRING, @@ -73,12 +73,12 @@ static ASN1_METHOD bit_string_meth={ (char *(*)()) ASN1_STRING_new, (void (*)()) ASN1_STRING_free}; -ASN1_METHOD *ASN1_IA5STRING_asn1_meth() +ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void) { return(&ia5string_meth); } -ASN1_METHOD *ASN1_BIT_STRING_asn1_meth() +ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void) { return(&bit_string_meth); } diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index 5a7eeef8d8..b94b418ee8 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c @@ -58,18 +58,11 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "asn1.h" -#include "objects.h" +#include +#include +#include -/* ASN1err(ASN1_F_ASN1_OBJECT_NEW,ASN1_R_EXPECTING_AN_OBJECT); - * ASN1err(ASN1_F_D2I_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); - * ASN1err(ASN1_F_I2T_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER); - */ - -int i2d_ASN1_OBJECT(a, pp) -ASN1_OBJECT *a; -unsigned char **pp; +int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) { unsigned char *p; @@ -87,14 +80,11 @@ unsigned char **pp; return(a->length); } -int a2d_ASN1_OBJECT(out,olen,buf,num) -unsigned char *out; -int olen; -char *buf; -int num; +int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) { int i,first,len=0,c; - char tmp[24],*p; + char tmp[24]; + const char *p; unsigned long l; if (num == 0) @@ -180,85 +170,12 @@ err: return(0); } -int i2t_ASN1_OBJECT(buf,buf_len,a) -char *buf; -int buf_len; -ASN1_OBJECT *a; - { - int i,idx=0,n=0,len,nid; - unsigned long l; - unsigned char *p; - char *s; - char tbuf[32]; - - if (buf_len <= 0) return(0); - - if ((a == NULL) || (a->data == NULL)) - { - buf[0]='\0'; - return(0); - } - - nid=OBJ_obj2nid(a); - if (nid == NID_undef) - { - len=a->length; - p=a->data; - - idx=0; - l=0; - while (idx < a->length) - { - l|=(p[idx]&0x7f); - if (!(p[idx] & 0x80)) break; - l<<=7L; - idx++; - } - idx++; - i=(int)(l/40); - if (i > 2) i=2; - l-=(long)(i*40); - - sprintf(tbuf,"%d.%ld",i,l); - i=strlen(tbuf); - strncpy(buf,tbuf,buf_len); - buf_len-=i; - buf+=i; - n+=i; - - l=0; - for (; idx 0) - strncpy(buf,tbuf,buf_len); - buf_len-=i; - buf+=i; - n+=i; - l=0; - } - l<<=7L; - } - } - else - { - s=(char *)OBJ_nid2ln(nid); - if (s == NULL) - s=(char *)OBJ_nid2sn(nid); - strncpy(buf,s,buf_len); - n=strlen(s); - } - buf[buf_len-1]='\0'; - return(n); - } +int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) +{ + return OBJ_obj2txt(buf, buf_len, a, 0); +} -int i2a_ASN1_OBJECT(bp,a) -BIO *bp; -ASN1_OBJECT *a; +int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) { char buf[80]; int i; @@ -271,10 +188,8 @@ ASN1_OBJECT *a; return(i); } -ASN1_OBJECT *d2i_ASN1_OBJECT(a, pp, length) -ASN1_OBJECT **a; -unsigned char **pp; -long length; +ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, + long length) { ASN1_OBJECT *ret=NULL; unsigned char *p; @@ -330,7 +245,7 @@ err: return(NULL); } -ASN1_OBJECT *ASN1_OBJECT_new() +ASN1_OBJECT *ASN1_OBJECT_new(void) { ASN1_OBJECT *ret; @@ -349,14 +264,15 @@ ASN1_OBJECT *ASN1_OBJECT_new() return(ret); } -void ASN1_OBJECT_free(a) -ASN1_OBJECT *a; +void ASN1_OBJECT_free(ASN1_OBJECT *a) { if (a == NULL) return; if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) { - if (a->sn != NULL) Free(a->sn); - if (a->ln != NULL) Free(a->ln); +#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause mempory leaks */ + if (a->sn != NULL) Free((void *)a->sn); + if (a->ln != NULL) Free((void *)a->ln); +#endif a->sn=a->ln=NULL; } if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) @@ -366,14 +282,11 @@ ASN1_OBJECT *a; a->length=0; } if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) - Free((char *)a); + Free(a); } -ASN1_OBJECT *ASN1_OBJECT_create(nid,data,len,sn,ln) -int nid; -unsigned char *data; -int len; -char *sn,*ln; +ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, + char *sn, char *ln) { ASN1_OBJECT o; @@ -382,8 +295,10 @@ char *sn,*ln; o.data=data; o.nid=nid; o.length=len; - o.flags=ASN1_OBJECT_FLAG_DYNAMIC| - ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA; + o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| + ASN1_OBJECT_FLAG_DYNAMIC_DATA; return(OBJ_dup(&o)); } +IMPLEMENT_STACK_OF(ASN1_OBJECT) +IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c index be3f172a8c..7659a13bd3 100644 --- a/src/lib/libcrypto/asn1/a_octet.c +++ b/src/lib/libcrypto/asn1/a_octet.c @@ -58,23 +58,16 @@ #include #include "cryptlib.h" -#include "asn1.h" +#include -/* ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ASN1_R_EXPECTING_AN_OCTET_STRING); - */ - -int i2d_ASN1_OCTET_STRING(a, pp) -ASN1_OCTET_STRING *a; -unsigned char **pp; +int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp) { return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL)); } -ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(a, pp, length) -ASN1_OCTET_STRING **a; -unsigned char **pp; -long length; +ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, + unsigned char **pp, long length) { ASN1_OCTET_STRING *ret=NULL; @@ -82,7 +75,7 @@ long length; pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL); if (ret == NULL) { - ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ASN1_R_ERROR_STACK); + ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ERR_R_NESTED_ASN1_ERROR); return(NULL); } return(ret); diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c index 3023361dee..cdec7a1561 100644 --- a/src/lib/libcrypto/asn1/a_print.c +++ b/src/lib/libcrypto/asn1/a_print.c @@ -58,49 +58,32 @@ #include #include "cryptlib.h" -#include "asn1.h" +#include -/* ASN1err(ASN1_F_D2I_ASN1_PRINT_TYPE,ASN1_R_WRONG_PRINTABLE_TYPE); - * ASN1err(ASN1_F_D2I_ASN1_PRINT_TYPE,ASN1_R_TAG_VALUE_TOO_HIGH); - */ - -int i2d_ASN1_IA5STRING(a,pp) -ASN1_IA5STRING *a; -unsigned char **pp; +int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **pp) { return(M_i2d_ASN1_IA5STRING(a,pp)); } -ASN1_IA5STRING *d2i_ASN1_IA5STRING(a,pp,l) -ASN1_IA5STRING **a; -unsigned char **pp; -long l; +ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, unsigned char **pp, + long l) { return(M_d2i_ASN1_IA5STRING(a,pp,l)); } -ASN1_T61STRING *d2i_ASN1_T61STRING(a,pp,l) -ASN1_T61STRING **a; -unsigned char **pp; -long l; +ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, unsigned char **pp, + long l) { return(M_d2i_ASN1_T61STRING(a,pp,l)); } -ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(a,pp,l) -ASN1_PRINTABLESTRING **a; -unsigned char **pp; -long l; - { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,l)); } +ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, + unsigned char **pp, long l) + { return(M_d2i_ASN1_PRINTABLESTRING(a,pp, + l)); } -int i2d_ASN1_PRINTABLE(a,pp) -ASN1_STRING *a; -unsigned char **pp; +int i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **pp) { return(M_i2d_ASN1_PRINTABLE(a,pp)); } -ASN1_STRING *d2i_ASN1_PRINTABLE(a,pp,l) -ASN1_STRING **a; -unsigned char **pp; -long l; +ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, unsigned char **pp, + long l) { return(M_d2i_ASN1_PRINTABLE(a,pp,l)); } -int ASN1_PRINTABLE_type(s,len) -unsigned char *s; -int len; +int ASN1_PRINTABLE_type(unsigned char *s, int len) { int c; int ia5=0; @@ -112,6 +95,7 @@ int len; while ((*s) && (len-- != 0)) { c= *(s++); +#ifndef CHARSET_EBCDIC if (!( ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || (c == ' ') || @@ -125,14 +109,20 @@ int len; ia5=1; if (c&0x80) t61=1; +#else + if (!isalnum(c) && (c != ' ') && + strchr("'()+,-./:=?", c) == NULL) + ia5=1; + if (os_toascii[c] & 0x80) + t61=1; +#endif } if (t61) return(V_ASN1_T61STRING); if (ia5) return(V_ASN1_IA5STRING); return(V_ASN1_PRINTABLESTRING); } -int ASN1_UNIVERSALSTRING_to_string(s) -ASN1_UNIVERSALSTRING *s; +int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) { int i; unsigned char *p; @@ -159,3 +149,17 @@ ASN1_UNIVERSALSTRING *s; return(1); } + +int i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **pp) + { return(M_i2d_DIRECTORYSTRING(a,pp)); } + +ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp, + long l) + { return(M_d2i_DIRECTORYSTRING(a,pp,l)); } + +int i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **pp) + { return(M_i2d_DISPLAYTEXT(a,pp)); } + +ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, + long l) + { return(M_d2i_DISPLAYTEXT(a,pp,l)); } diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c index 17c49946cf..c2481e7597 100644 --- a/src/lib/libcrypto/asn1/a_set.c +++ b/src/lib/libcrypto/asn1/a_set.c @@ -58,21 +58,40 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" +#include -/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ERR_R_MALLOC_FAILURE); +typedef struct + { + unsigned char *pbData; + int cbData; + } MYBLOB; + +/* SetBlobCmp + * This function compares two elements of SET_OF block */ +static int SetBlobCmp(const void *elem1, const void *elem2 ) + { + const MYBLOB *b1 = (const MYBLOB *)elem1; + const MYBLOB *b2 = (const MYBLOB *)elem2; + int r; + + r = memcmp(b1->pbData, b2->pbData, + b1->cbData < b2->cbData ? b1->cbData : b2->cbData); + if(r != 0) + return r; + return b1->cbData-b2->cbData; + } -int i2d_ASN1_SET(a,pp,func,ex_tag,ex_class) -STACK *a; -unsigned char **pp; -int (*func)(); -int ex_tag; -int ex_class; +/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */ +int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag, + int ex_class, int is_set) { int ret=0,r; int i; unsigned char *p; + unsigned char *pStart, *pTempMem; + MYBLOB *rgSetBlob; + int totSize; if (a == NULL) return(0); for (i=sk_num(a)-1; i>=0; i--) @@ -82,20 +101,58 @@ int ex_class; p= *pp; ASN1_put_object(&p,1,ret,ex_tag,ex_class); - for (i=0; i #include "cryptlib.h" -#include "bn.h" -#include "evp.h" -#include "x509.h" -#include "objects.h" -#include "buffer.h" -#include "pem.h" +#include +#include +#include +#include +#include -int ASN1_sign(i2d,algor1,algor2,signature,data,pkey,type) -int (*i2d)(); -X509_ALGOR *algor1; -X509_ALGOR *algor2; -ASN1_BIT_STRING *signature; -char *data; -EVP_PKEY *pkey; -EVP_MD *type; +int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2, + ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey, + const EVP_MD *type) { EVP_MD_CTX ctx; unsigned char *p,*buf_in=NULL,*buf_out=NULL; @@ -136,7 +130,11 @@ EVP_MD *type; signature->data=buf_out; buf_out=NULL; signature->length=outl; - + /* In the interests of compatability, I'll make sure that + * the bit string has a 'not-used bits' value of 0 + */ + signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); + signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; err: memset(&ctx,0,sizeof(ctx)); if (buf_in != NULL) diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c new file mode 100644 index 0000000000..c1690a5694 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_time.c @@ -0,0 +1,123 @@ +/* crypto/asn1/a_time.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + +/* This is an implementation of the ASN1 Time structure which is: + * Time ::= CHOICE { + * utcTime UTCTime, + * generalTime GeneralizedTime } + * written by Steve Henson. + */ + +#include +#include +#include "cryptlib.h" +#include + +int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) + { +#ifdef CHARSET_EBCDIC + /* KLUDGE! We convert to ascii before writing DER */ + char tmp[24]; + ASN1_STRING tmpstr; + + if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) { + int len; + + tmpstr = *(ASN1_STRING *)a; + len = tmpstr.length; + ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len); + tmpstr.data = tmp; + a = (ASN1_GENERALIZEDTIME *) &tmpstr; + } +#endif + if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) + return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, + a->type ,V_ASN1_UNIVERSAL)); + ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); + return -1; + } + + +ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **a, unsigned char **pp, long length) + { + unsigned char tag; + tag = **pp & ~V_ASN1_CONSTRUCTED; + if(tag == (V_ASN1_UTCTIME|V_ASN1_UNIVERSAL)) + return d2i_ASN1_UTCTIME(a, pp, length); + if(tag == (V_ASN1_GENERALIZEDTIME|V_ASN1_UNIVERSAL)) + return d2i_ASN1_GENERALIZEDTIME(a, pp, length); + ASN1err(ASN1_F_D2I_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); + return(NULL); + } + + +ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) + { + struct tm *ts; +#if defined(THREADS) && !defined(WIN32) + struct tm data; +#endif + +#if defined(THREADS) && !defined(WIN32) + gmtime_r(&t,&data); + ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */ +#else + ts=gmtime(&t); +#endif + if((ts->tm_year >= 50) && (ts->tm_year < 150)) + return ASN1_UTCTIME_set(s, t); + return ASN1_GENERALIZEDTIME_set(s,t); + } diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c index 7c0004084c..3f2ecee5c2 100644 --- a/src/lib/libcrypto/asn1/a_type.c +++ b/src/lib/libcrypto/asn1/a_type.c @@ -58,23 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" +#include -/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK); - * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_ERROR_STACK); - * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_WRONG_TAG); - * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG); - */ - -#ifndef NOPROTO static void ASN1_TYPE_component_free(ASN1_TYPE *a); -#else -static void ASN1_TYPE_component_free(); -#endif - -int i2d_ASN1_TYPE(a,pp) -ASN1_TYPE *a; -unsigned char **pp; +int i2d_ASN1_TYPE(ASN1_TYPE *a, unsigned char **pp) { int r=0; @@ -91,6 +78,10 @@ unsigned char **pp; case V_ASN1_NEG_INTEGER: r=i2d_ASN1_INTEGER(a->value.integer,pp); break; + case V_ASN1_ENUMERATED: + case V_ASN1_NEG_ENUMERATED: + r=i2d_ASN1_ENUMERATED(a->value.enumerated,pp); + break; case V_ASN1_BIT_STRING: r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp); break; @@ -115,12 +106,21 @@ unsigned char **pp; case V_ASN1_UNIVERSALSTRING: r=M_i2d_ASN1_UNIVERSALSTRING(a->value.universalstring,pp); break; + case V_ASN1_UTF8STRING: + r=M_i2d_ASN1_UTF8STRING(a->value.utf8string,pp); + break; + case V_ASN1_VISIBLESTRING: + r=M_i2d_ASN1_VISIBLESTRING(a->value.visiblestring,pp); + break; case V_ASN1_BMPSTRING: r=M_i2d_ASN1_BMPSTRING(a->value.bmpstring,pp); break; case V_ASN1_UTCTIME: r=i2d_ASN1_UTCTIME(a->value.utctime,pp); break; + case V_ASN1_GENERALIZEDTIME: + r=i2d_ASN1_GENERALIZEDTIME(a->value.generalizedtime,pp); + break; case V_ASN1_SET: case V_ASN1_SEQUENCE: if (a->value.set == NULL) @@ -139,10 +139,7 @@ unsigned char **pp; return(r); } -ASN1_TYPE *d2i_ASN1_TYPE(a,pp,length) -ASN1_TYPE **a; -unsigned char **pp; -long length; +ASN1_TYPE *d2i_ASN1_TYPE(ASN1_TYPE **a, unsigned char **pp, long length) { ASN1_TYPE *ret=NULL; unsigned char *q,*p,*max; @@ -176,6 +173,11 @@ long length; d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL) goto err; break; + case V_ASN1_ENUMERATED: + if ((ret->value.enumerated= + d2i_ASN1_ENUMERATED(NULL,&p,max-p)) == NULL) + goto err; + break; case V_ASN1_BIT_STRING: if ((ret->value.bit_string= d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL) @@ -186,6 +188,16 @@ long length; d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL) goto err; break; + case V_ASN1_VISIBLESTRING: + if ((ret->value.visiblestring= + d2i_ASN1_VISIBLESTRING(NULL,&p,max-p)) == NULL) + goto err; + break; + case V_ASN1_UTF8STRING: + if ((ret->value.utf8string= + d2i_ASN1_UTF8STRING(NULL,&p,max-p)) == NULL) + goto err; + break; case V_ASN1_OBJECT: if ((ret->value.object= d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL) @@ -226,6 +238,11 @@ long length; d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL) goto err; break; + case V_ASN1_GENERALIZEDTIME: + if ((ret->value.generalizedtime= + d2i_ASN1_GENERALIZEDTIME(NULL,&p,max-p)) == NULL) + goto err; + break; case V_ASN1_SET: case V_ASN1_SEQUENCE: /* Sets and sequences are left complete */ @@ -249,9 +266,10 @@ err: return(NULL); } -ASN1_TYPE *ASN1_TYPE_new() +ASN1_TYPE *ASN1_TYPE_new(void) { ASN1_TYPE *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,ASN1_TYPE); ret->type= -1; @@ -260,16 +278,14 @@ ASN1_TYPE *ASN1_TYPE_new() M_ASN1_New_Error(ASN1_F_ASN1_TYPE_NEW); } -void ASN1_TYPE_free(a) -ASN1_TYPE *a; +void ASN1_TYPE_free(ASN1_TYPE *a) { if (a == NULL) return; ASN1_TYPE_component_free(a); Free((char *)(char *)a); } -int ASN1_TYPE_get(a) -ASN1_TYPE *a; +int ASN1_TYPE_get(ASN1_TYPE *a) { if (a->value.ptr != NULL) return(a->type); @@ -277,10 +293,7 @@ ASN1_TYPE *a; return(0); } -void ASN1_TYPE_set(a,type,value) -ASN1_TYPE *a; -int type; -char *value; +void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) { if (a->value.ptr != NULL) ASN1_TYPE_component_free(a); @@ -288,8 +301,7 @@ char *value; a->value.ptr=value; } -static void ASN1_TYPE_component_free(a) -ASN1_TYPE *a; +static void ASN1_TYPE_component_free(ASN1_TYPE *a) { if (a == NULL) return; @@ -302,16 +314,25 @@ ASN1_TYPE *a; break; case V_ASN1_INTEGER: case V_ASN1_NEG_INTEGER: + case V_ASN1_ENUMERATED: + case V_ASN1_NEG_ENUMERATED: case V_ASN1_BIT_STRING: case V_ASN1_OCTET_STRING: + case V_ASN1_SEQUENCE: + case V_ASN1_SET: + case V_ASN1_NUMERICSTRING: case V_ASN1_PRINTABLESTRING: case V_ASN1_T61STRING: + case V_ASN1_VIDEOTEXSTRING: case V_ASN1_IA5STRING: - case V_ASN1_UNIVERSALSTRING: - case V_ASN1_GENERALSTRING: case V_ASN1_UTCTIME: - case V_ASN1_SET: - case V_ASN1_SEQUENCE: + case V_ASN1_GENERALIZEDTIME: + case V_ASN1_GRAPHICSTRING: + case V_ASN1_VISIBLESTRING: + case V_ASN1_GENERALSTRING: + case V_ASN1_UNIVERSALSTRING: + case V_ASN1_BMPSTRING: + case V_ASN1_UTF8STRING: ASN1_STRING_free((ASN1_STRING *)a->value.ptr); break; default: @@ -323,3 +344,5 @@ ASN1_TYPE *a; } } +IMPLEMENT_STACK_OF(ASN1_TYPE) +IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c index 17a7abbb67..688199fdd2 100644 --- a/src/lib/libcrypto/asn1/a_utctm.c +++ b/src/lib/libcrypto/asn1/a_utctm.c @@ -58,26 +58,35 @@ #include #include +#ifdef VMS +#include +#include +#include +#endif #include "cryptlib.h" -#include "asn1.h" - -/* ASN1err(ASN1_F_ASN1_UTCTIME_NEW,ASN1_R_UTCTIME_TOO_LONG); - * ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_EXPECTING_A_UTCTIME); - */ +#include -int i2d_ASN1_UTCTIME(a,pp) -ASN1_UTCTIME *a; -unsigned char **pp; +int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp) { +#ifndef CHARSET_EBCDIC return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); +#else + /* KLUDGE! We convert to ascii before writing DER */ + int len; + char tmp[24]; + ASN1_STRING x = *(ASN1_STRING *)a; + + len = x.length; + ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len); + x.data = tmp; + return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); +#endif } -ASN1_UTCTIME *d2i_ASN1_UTCTIME(a, pp, length) -ASN1_UTCTIME **a; -unsigned char **pp; -long length; +ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp, + long length) { ASN1_UTCTIME *ret=NULL; @@ -85,9 +94,12 @@ long length; V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); if (ret == NULL) { - ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_ERROR_STACK); + ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR); return(NULL); } +#ifdef CHARSET_EBCDIC + ascii2ebcdic(ret->data, ret->data, ret->length); +#endif if (!ASN1_UTCTIME_check(ret)) { ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); @@ -101,8 +113,7 @@ err: return(NULL); } -int ASN1_UTCTIME_check(d) -ASN1_UTCTIME *d; +int ASN1_UTCTIME_check(ASN1_UTCTIME *d) { static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; static int max[8]={99,12,31,23,59,59,12,59}; @@ -152,9 +163,7 @@ err: return(0); } -int ASN1_UTCTIME_set_string(s,str) -ASN1_UTCTIME *s; -char *str; +int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str) { ASN1_UTCTIME t; @@ -174,13 +183,11 @@ char *str; return(0); } -ASN1_UTCTIME *ASN1_UTCTIME_set(s, t) -ASN1_UTCTIME *s; -time_t t; +ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) { char *p; struct tm *ts; -#if defined(THREADS) +#if defined(THREADS) && !defined(WIN32) struct tm data; #endif @@ -189,10 +196,48 @@ time_t t; if (s == NULL) return(NULL); -#if defined(THREADS) - ts=(struct tm *)gmtime_r(&t,&data); +#if defined(THREADS) && !defined(WIN32) + gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */ + ts=&data; #else - ts=(struct tm *)gmtime(&t); + ts=gmtime(&t); +#endif +#ifdef VMS + if (ts == NULL) + { + static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL"); + static $DESCRIPTOR(lognam,"SYS$TIMEZONE_DIFFERENTIAL"); + char result[256]; + unsigned int reslen = 0; + struct { + short buflen; + short code; + void *bufaddr; + unsigned int *reslen; + } itemlist[] = { + { 0, LNM$_STRING, 0, 0 }, + { 0, 0, 0, 0 }, + }; + int status; + + /* Get the value for SYS$TIMEZONE_DIFFERENTIAL */ + itemlist[0].buflen = sizeof(result); + itemlist[0].bufaddr = result; + itemlist[0].reslen = &reslen; + status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist); + if (!(status & 1)) + return NULL; + result[reslen] = '\0'; + + /* Get the numerical value of the equivalence string */ + status = atoi(result); + + /* and use it to move time to GMT */ + t -= status; + + /* then convert the result to the time structure */ + ts=(struct tm *)localtime(&t); + } #endif p=(char *)s->data; if ((p == NULL) || (s->length < 14)) @@ -208,5 +253,8 @@ time_t t; ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); s->length=strlen(p); s->type=V_ASN1_UTCTIME; +#ifdef CHARSET_EBCDIC_not + ebcdic2ascii(s->data, s->data, s->length); +#endif return(s); } diff --git a/src/lib/libcrypto/asn1/a_utf8.c b/src/lib/libcrypto/asn1/a_utf8.c new file mode 100644 index 0000000000..4a8a92e9e4 --- /dev/null +++ b/src/lib/libcrypto/asn1/a_utf8.c @@ -0,0 +1,83 @@ +/* crypto/asn1/a_utf8.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include + +int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **pp) + { + return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, + V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL)); + } + +ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, unsigned char **pp, + long length) + { + ASN1_UTF8STRING *ret=NULL; + + ret=(ASN1_UTF8STRING *)d2i_ASN1_bytes((ASN1_STRING **)a, + pp,length,V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL); + if (ret == NULL) + { + ASN1err(ASN1_F_D2I_ASN1_UTF8STRING,ERR_R_NESTED_ASN1_ERROR); + return(NULL); + } + return(ret); + } + diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c index 03fc63dbef..6383d2c698 100644 --- a/src/lib/libcrypto/asn1/a_verify.c +++ b/src/lib/libcrypto/asn1/a_verify.c @@ -62,22 +62,17 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "x509.h" -#include "objects.h" -#include "buffer.h" -#include "evp.h" -#include "pem.h" +#include +#include +#include +#include +#include -int ASN1_verify(i2d,a,signature,data,pkey) -int (*i2d)(); -X509_ALGOR *a; -ASN1_BIT_STRING *signature; -char *data; -EVP_PKEY *pkey; +int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature, + char *data, EVP_PKEY *pkey) { EVP_MD_CTX ctx; - EVP_MD *type; + const EVP_MD *type; unsigned char *p,*buf_in=NULL; int ret= -1,i,inl; @@ -90,7 +85,7 @@ EVP_PKEY *pkey; } inl=i2d(data,NULL); - buf_in=(unsigned char *)Malloc((unsigned int)inl); + buf_in=Malloc((unsigned int)inl); if (buf_in == NULL) { ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE); diff --git a/src/lib/libcrypto/asn1/a_vis.c b/src/lib/libcrypto/asn1/a_vis.c new file mode 100644 index 0000000000..2072be780d --- /dev/null +++ b/src/lib/libcrypto/asn1/a_vis.c @@ -0,0 +1,83 @@ +/* crypto/asn1/a_vis.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include + +int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a, unsigned char **pp) + { + return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, + V_ASN1_VISIBLESTRING,V_ASN1_UNIVERSAL)); + } + +ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a, + unsigned char **pp, long length) + { + ASN1_VISIBLESTRING *ret=NULL; + + ret=(ASN1_VISIBLESTRING *)d2i_ASN1_bytes((ASN1_STRING **)a, + pp,length,V_ASN1_VISIBLESTRING,V_ASN1_UNIVERSAL); + if (ret == NULL) + { + ASN1err(ASN1_F_D2I_ASN1_VISIBLESTRING,ERR_R_NESTED_ASN1_ERROR); + return(NULL); + } + return(ret); + } + diff --git a/src/lib/libcrypto/asn1/asn1.err b/src/lib/libcrypto/asn1/asn1.err deleted file mode 100644 index c8b7011488..0000000000 --- a/src/lib/libcrypto/asn1/asn1.err +++ /dev/null @@ -1,182 +0,0 @@ -/* Error codes for the ASN1 functions. */ - -/* Function codes. */ -#define ASN1_F_A2D_ASN1_OBJECT 100 -#define ASN1_F_A2I_ASN1_INTEGER 101 -#define ASN1_F_A2I_ASN1_STRING 102 -#define ASN1_F_ASN1_COLLATE_PRIMATIVE 103 -#define ASN1_F_ASN1_D2I_BIO 104 -#define ASN1_F_ASN1_D2I_FP 105 -#define ASN1_F_ASN1_DUP 106 -#define ASN1_F_ASN1_GET_OBJECT 107 -#define ASN1_F_ASN1_HEADER_NEW 108 -#define ASN1_F_ASN1_I2D_BIO 109 -#define ASN1_F_ASN1_I2D_FP 110 -#define ASN1_F_ASN1_INTEGER_SET 111 -#define ASN1_F_ASN1_INTEGER_TO_BN 112 -#define ASN1_F_ASN1_OBJECT_NEW 113 -#define ASN1_F_ASN1_SIGN 114 -#define ASN1_F_ASN1_STRING_NEW 115 -#define ASN1_F_ASN1_STRING_TYPE_NEW 116 -#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117 -#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118 -#define ASN1_F_ASN1_TYPE_NEW 119 -#define ASN1_F_ASN1_UTCTIME_NEW 120 -#define ASN1_F_ASN1_VERIFY 121 -#define ASN1_F_BN_TO_ASN1_INTEGER 122 -#define ASN1_F_D2I_ASN1_BIT_STRING 123 -#define ASN1_F_D2I_ASN1_BMPSTRING 124 -#define ASN1_F_D2I_ASN1_BOOLEAN 125 -#define ASN1_F_D2I_ASN1_BYTES 126 -#define ASN1_F_D2I_ASN1_HEADER 127 -#define ASN1_F_D2I_ASN1_INTEGER 128 -#define ASN1_F_D2I_ASN1_OBJECT 129 -#define ASN1_F_D2I_ASN1_OCTET_STRING 130 -#define ASN1_F_D2I_ASN1_PRINT_TYPE 131 -#define ASN1_F_D2I_ASN1_SET 132 -#define ASN1_F_D2I_ASN1_TYPE 133 -#define ASN1_F_D2I_ASN1_TYPE_BYTES 134 -#define ASN1_F_D2I_ASN1_UTCTIME 135 -#define ASN1_F_D2I_DHPARAMS 136 -#define ASN1_F_D2I_DSAPARAMS 137 -#define ASN1_F_D2I_DSAPRIVATEKEY 138 -#define ASN1_F_D2I_DSAPUBLICKEY 139 -#define ASN1_F_D2I_NETSCAPE_PKEY 140 -#define ASN1_F_D2I_NETSCAPE_RSA 141 -#define ASN1_F_D2I_NETSCAPE_RSA_2 142 -#define ASN1_F_D2I_NETSCAPE_SPKAC 143 -#define ASN1_F_D2I_NETSCAPE_SPKI 144 -#define ASN1_F_D2I_PKCS7 145 -#define ASN1_F_D2I_PKCS7_DIGEST 146 -#define ASN1_F_D2I_PKCS7_ENCRYPT 147 -#define ASN1_F_D2I_PKCS7_ENC_CONTENT 148 -#define ASN1_F_D2I_PKCS7_ENVELOPE 149 -#define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150 -#define ASN1_F_D2I_PKCS7_RECIP_INFO 151 -#define ASN1_F_D2I_PKCS7_SIGNED 152 -#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153 -#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154 -#define ASN1_F_D2I_PRIVATEKEY 155 -#define ASN1_F_D2I_PUBLICKEY 156 -#define ASN1_F_D2I_RSAPRIVATEKEY 157 -#define ASN1_F_D2I_RSAPUBLICKEY 158 -#define ASN1_F_D2I_X509 159 -#define ASN1_F_D2I_X509_ALGOR 160 -#define ASN1_F_D2I_X509_ATTRIBUTE 161 -#define ASN1_F_D2I_X509_CINF 162 -#define ASN1_F_D2I_X509_CRL 163 -#define ASN1_F_D2I_X509_CRL_INFO 164 -#define ASN1_F_D2I_X509_EXTENSION 165 -#define ASN1_F_D2I_X509_KEY 166 -#define ASN1_F_D2I_X509_NAME 167 -#define ASN1_F_D2I_X509_NAME_ENTRY 168 -#define ASN1_F_D2I_X509_PKEY 169 -#define ASN1_F_D2I_X509_PUBKEY 170 -#define ASN1_F_D2I_X509_REQ 171 -#define ASN1_F_D2I_X509_REQ_INFO 172 -#define ASN1_F_D2I_X509_REVOKED 173 -#define ASN1_F_D2I_X509_SIG 174 -#define ASN1_F_D2I_X509_VAL 175 -#define ASN1_F_I2D_ASN1_HEADER 176 -#define ASN1_F_I2D_DHPARAMS 177 -#define ASN1_F_I2D_DSAPARAMS 178 -#define ASN1_F_I2D_DSAPRIVATEKEY 179 -#define ASN1_F_I2D_DSAPUBLICKEY 180 -#define ASN1_F_I2D_NETSCAPE_RSA 181 -#define ASN1_F_I2D_PKCS7 182 -#define ASN1_F_I2D_PRIVATEKEY 183 -#define ASN1_F_I2D_PUBLICKEY 184 -#define ASN1_F_I2D_RSAPRIVATEKEY 185 -#define ASN1_F_I2D_RSAPUBLICKEY 186 -#define ASN1_F_I2D_X509_ATTRIBUTE 187 -#define ASN1_F_I2T_ASN1_OBJECT 188 -#define ASN1_F_NETSCAPE_PKEY_NEW 189 -#define ASN1_F_NETSCAPE_SPKAC_NEW 190 -#define ASN1_F_NETSCAPE_SPKI_NEW 191 -#define ASN1_F_PKCS7_DIGEST_NEW 192 -#define ASN1_F_PKCS7_ENCRYPT_NEW 193 -#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194 -#define ASN1_F_PKCS7_ENVELOPE_NEW 195 -#define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196 -#define ASN1_F_PKCS7_NEW 197 -#define ASN1_F_PKCS7_RECIP_INFO_NEW 198 -#define ASN1_F_PKCS7_SIGNED_NEW 199 -#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200 -#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201 -#define ASN1_F_X509_ALGOR_NEW 202 -#define ASN1_F_X509_ATTRIBUTE_NEW 203 -#define ASN1_F_X509_CINF_NEW 204 -#define ASN1_F_X509_CRL_INFO_NEW 205 -#define ASN1_F_X509_CRL_NEW 206 -#define ASN1_F_X509_DHPARAMS_NEW 207 -#define ASN1_F_X509_EXTENSION_NEW 208 -#define ASN1_F_X509_INFO_NEW 209 -#define ASN1_F_X509_KEY_NEW 210 -#define ASN1_F_X509_NAME_ENTRY_NEW 211 -#define ASN1_F_X509_NAME_NEW 212 -#define ASN1_F_X509_NEW 213 -#define ASN1_F_X509_PKEY_NEW 214 -#define ASN1_F_X509_PUBKEY_NEW 215 -#define ASN1_F_X509_REQ_INFO_NEW 216 -#define ASN1_F_X509_REQ_NEW 217 -#define ASN1_F_X509_REVOKED_NEW 218 -#define ASN1_F_X509_SIG_NEW 219 -#define ASN1_F_X509_VAL_FREE 220 -#define ASN1_F_X509_VAL_NEW 221 - -/* Reason codes. */ -#define ASN1_R_BAD_CLASS 100 -#define ASN1_R_BAD_GET_OBJECT 101 -#define ASN1_R_BAD_OBJECT_HEADER 102 -#define ASN1_R_BAD_PASSWORD_READ 103 -#define ASN1_R_BAD_PKCS7_CONTENT 104 -#define ASN1_R_BAD_PKCS7_TYPE 105 -#define ASN1_R_BAD_TAG 106 -#define ASN1_R_BAD_TYPE 107 -#define ASN1_R_BN_LIB 108 -#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109 -#define ASN1_R_BUFFER_TOO_SMALL 110 -#define ASN1_R_DATA_IS_WRONG 111 -#define ASN1_R_DECODING_ERROR 112 -#define ASN1_R_ERROR_STACK 113 -#define ASN1_R_EXPECTING_AN_INTEGER 114 -#define ASN1_R_EXPECTING_AN_OBJECT 115 -#define ASN1_R_EXPECTING_AN_OCTET_STRING 116 -#define ASN1_R_EXPECTING_A_BIT_STRING 117 -#define ASN1_R_EXPECTING_A_BOOLEAN 118 -#define ASN1_R_EXPECTING_A_SEQUENCE 119 -#define ASN1_R_EXPECTING_A_UTCTIME 120 -#define ASN1_R_FIRST_NUM_TOO_LARGE 121 -#define ASN1_R_HEADER_TOO_LONG 122 -#define ASN1_R_INVALID_DIGIT 123 -#define ASN1_R_INVALID_SEPARATOR 124 -#define ASN1_R_INVALID_TIME_FORMAT 125 -#define ASN1_R_IV_TOO_LARGE 126 -#define ASN1_R_LENGTH_ERROR 127 -#define ASN1_R_LENGTH_MISMATCH 128 -#define ASN1_R_MISSING_EOS 129 -#define ASN1_R_MISSING_SECOND_NUMBER 130 -#define ASN1_R_NON_HEX_CHARACTERS 131 -#define ASN1_R_NOT_ENOUGH_DATA 132 -#define ASN1_R_ODD_NUMBER_OF_CHARS 133 -#define ASN1_R_PARSING 134 -#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135 -#define ASN1_R_SECOND_NUMBER_TOO_LARGE 136 -#define ASN1_R_SHORT_LINE 137 -#define ASN1_R_STRING_TOO_SHORT 138 -#define ASN1_R_TAG_VALUE_TOO_HIGH 139 -#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140 -#define ASN1_R_TOO_LONG 141 -#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142 -#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143 -#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144 -#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145 -#define ASN1_R_UNKNOWN_OBJECT_TYPE 146 -#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147 -#define ASN1_R_UNSUPPORTED_CIPHER 148 -#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149 -#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150 -#define ASN1_R_UTCTIME_TOO_LONG 151 -#define ASN1_R_WRONG_PRINTABLE_TYPE 152 -#define ASN1_R_WRONG_TAG 153 -#define ASN1_R_WRONG_TYPE 154 diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index 9793db365d..5c2d8999bc 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h @@ -64,8 +64,9 @@ extern "C" { #endif #include -#include "bn.h" -#include "stack.h" +#include +#include +#include #define V_ASN1_UNIVERSAL 0x00 #define V_ASN1_APPLICATION 0x40 @@ -73,6 +74,7 @@ extern "C" { #define V_ASN1_PRIVATE 0xc0 #define V_ASN1_CONSTRUCTED 0x20 +#define V_ASN1_PRIMITIVE_TAG 0x1f #define V_ASN1_PRIMATIVE_TAG 0x1f #define V_ASN1_APP_CHOOSE -2 /* let the recipent choose */ @@ -89,7 +91,9 @@ extern "C" { #define V_ASN1_OBJECT_DESCRIPTOR 7 #define V_ASN1_EXTERNAL 8 #define V_ASN1_REAL 9 -#define V_ASN1_ENUMERATED 10 /* microsoft weirdness */ +#define V_ASN1_ENUMERATED 10 +#define V_ASN1_NEG_ENUMERATED (10+0x100) +#define V_ASN1_UTF8STRING 12 #define V_ASN1_SEQUENCE 16 #define V_ASN1_SET 17 #define V_ASN1_NUMERICSTRING 18 /**/ @@ -111,111 +115,46 @@ extern "C" { #define B_ASN1_NUMERICSTRING 0x0001 #define B_ASN1_PRINTABLESTRING 0x0002 #define B_ASN1_T61STRING 0x0004 +#define B_ASN1_TELETEXSTRING 0x0008 #define B_ASN1_VIDEOTEXSTRING 0x0008 #define B_ASN1_IA5STRING 0x0010 #define B_ASN1_GRAPHICSTRING 0x0020 #define B_ASN1_ISO64STRING 0x0040 +#define B_ASN1_VISIBLESTRING 0x0040 #define B_ASN1_GENERALSTRING 0x0080 #define B_ASN1_UNIVERSALSTRING 0x0100 #define B_ASN1_OCTET_STRING 0x0200 #define B_ASN1_BIT_STRING 0x0400 #define B_ASN1_BMPSTRING 0x0800 #define B_ASN1_UNKNOWN 0x1000 - -#ifndef DEBUG - -#define ASN1_INTEGER ASN1_STRING -#define ASN1_BIT_STRING ASN1_STRING -#define ASN1_OCTET_STRING ASN1_STRING -#define ASN1_PRINTABLESTRING ASN1_STRING -#define ASN1_T61STRING ASN1_STRING -#define ASN1_IA5STRING ASN1_STRING -#define ASN1_UTCTIME ASN1_STRING -#define ASN1_GENERALIZEDTIME ASN1_STRING -#define ASN1_GENERALSTRING ASN1_STRING -#define ASN1_UNIVERSALSTRING ASN1_STRING -#define ASN1_BMPSTRING ASN1_STRING - -#else - -typedef struct asn1_integer_st - { - int length; - int type; - unsigned char *data; - } ASN1_INTEGER; - -typedef struct asn1_bit_string_st - { - int length; - int type; - unsigned char *data; - } ASN1_BIT_STRING; - -typedef struct asn1_octet_string_st - { - int length; - int type; - unsigned char *data; - } ASN1_OCTET_STRING; - -typedef struct asn1_printablestring_st - { - int length; - int type; - unsigned char *data; - } ASN1_PRINTABLESTRING; - -typedef struct asn1_t61string_st - { - int length; - int type; - unsigned char *data; - } ASN1_T61STRING; - -typedef struct asn1_ia5string_st - { - int length; - int type; - unsigned char *data; - } ASN1_IA5STRING; - -typedef struct asn1_generalstring_st - { - int length; - int type; - unsigned char *data; - } ASN1_GENERALSTRING; - -typedef struct asn1_universalstring_st - { - int length; - int type; - unsigned char *data; - } ASN1_UNIVERSALSTRING; - -typedef struct asn1_bmpstring_st - { - int length; - int type; - unsigned char *data; - } ASN1_BMPSTRING; - -typedef struct asn1_utctime_st - { - int length; - int type; - unsigned char *data; - } ASN1_UTCTIME; - -typedef struct asn1_generalizedtime_st - { - int length; - int type; - unsigned char *data; - } ASN1_GENERALIZEDTIME; - -#endif +#define B_ASN1_UTF8STRING 0x2000 + +#define DECLARE_ASN1_SET_OF(type) \ +int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \ + int (*func)(type *,unsigned char **), int ex_tag, \ + int ex_class, int is_set); \ +STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \ + long length, \ + type *(*func)(type **, \ + unsigned char **,long), \ + void (*free_func)(type *), \ + int ex_tag,int ex_class); + +#define IMPLEMENT_ASN1_SET_OF(type) \ +int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \ + int (*func)(type *,unsigned char **), int ex_tag, \ + int ex_class, int is_set) \ + { return i2d_ASN1_SET((STACK *)a,pp,func,ex_tag,ex_class,is_set); } \ +STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \ + long length, \ + type *(*func)(type **, \ + unsigned char **,long), \ + void (*free_func)(type *), \ + int ex_tag,int ex_class) \ + { return (STACK_OF(type) *)d2i_ASN1_SET((STACK **)a,pp,length, \ + (char *(*)())func, \ + (void (*)())free_func, \ + ex_tag,ex_class); } typedef struct asn1_ctx_st { @@ -229,6 +168,7 @@ typedef struct asn1_ctx_st unsigned char *max; /* largest value of p alowed */ unsigned char *q;/* temporary variable */ unsigned char **pp;/* variable */ + int line; /* used in error processing */ } ASN1_CTX; /* These are used internally in the ASN1_OBJECT to keep track of @@ -239,21 +179,61 @@ typedef struct asn1_ctx_st #define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */ typedef struct asn1_object_st { - char *sn,*ln; + const char *sn,*ln; int nid; int length; unsigned char *data; int flags; /* Should we free this one */ } ASN1_OBJECT; +#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */ /* This is the base type that holds just about everything :-) */ typedef struct asn1_string_st { int length; int type; unsigned char *data; + /* The value of the following field depends on the type being + * held. It is mostly being used for BIT_STRING so if the + * input data has a non-zero 'unused bits' value, it will be + * handled correctly */ + long flags; } ASN1_STRING; +#ifndef DEBUG +#define ASN1_INTEGER ASN1_STRING +#define ASN1_ENUMERATED ASN1_STRING +#define ASN1_BIT_STRING ASN1_STRING +#define ASN1_OCTET_STRING ASN1_STRING +#define ASN1_PRINTABLESTRING ASN1_STRING +#define ASN1_T61STRING ASN1_STRING +#define ASN1_IA5STRING ASN1_STRING +#define ASN1_UTCTIME ASN1_STRING +#define ASN1_GENERALIZEDTIME ASN1_STRING +#define ASN1_TIME ASN1_STRING +#define ASN1_GENERALSTRING ASN1_STRING +#define ASN1_UNIVERSALSTRING ASN1_STRING +#define ASN1_BMPSTRING ASN1_STRING +#define ASN1_VISIBLESTRING ASN1_STRING +#define ASN1_UTF8STRING ASN1_STRING +#else +typedef struct asn1_string_st ASN1_INTEGER; +typedef struct asn1_string_st ASN1_ENUMERATED; +typedef struct asn1_string_st ASN1_BIT_STRING; +typedef struct asn1_string_st ASN1_OCTET_STRING; +typedef struct asn1_string_st ASN1_PRINTABLESTRING; +typedef struct asn1_string_st ASN1_T61STRING; +typedef struct asn1_string_st ASN1_IA5STRING; +typedef struct asn1_string_st ASN1_GENERALSTRING; +typedef struct asn1_string_st ASN1_UNIVERSALSTRING; +typedef struct asn1_string_st ASN1_BMPSTRING; +typedef struct asn1_string_st ASN1_UTCTIME; +typedef struct asn1_string_st ASN1_TIME; +typedef struct asn1_string_st ASN1_GENERALIZEDTIME; +typedef struct asn1_string_st ASN1_VISIBLESTRING; +typedef struct asn1_string_st ASN1_UTF8STRING; +#endif + typedef struct asn1_type_st { int type; @@ -262,6 +242,7 @@ typedef struct asn1_type_st ASN1_STRING * asn1_string; ASN1_OBJECT * object; ASN1_INTEGER * integer; + ASN1_ENUMERATED * enumerated; ASN1_BIT_STRING * bit_string; ASN1_OCTET_STRING * octet_string; ASN1_PRINTABLESTRING * printablestring; @@ -272,6 +253,8 @@ typedef struct asn1_type_st ASN1_UNIVERSALSTRING * universalstring; ASN1_UTCTIME * utctime; ASN1_GENERALIZEDTIME * generalizedtime; + ASN1_VISIBLESTRING * visiblestring; + ASN1_UTF8STRING * utf8string; /* set and sequence are left complete and still * contain the set or sequence bytes */ ASN1_STRING * set; @@ -279,6 +262,9 @@ typedef struct asn1_type_st } value; } ASN1_TYPE; +DECLARE_STACK_OF(ASN1_TYPE) +DECLARE_ASN1_SET_OF(ASN1_TYPE) + typedef struct asn1_method_st { int (*i2d)(); @@ -322,6 +308,17 @@ typedef struct asn1_header_st /* i2d_ASN1_INTEGER() is a function */ /* d2i_ASN1_INTEGER() is a function */ +#define ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\ + ASN1_STRING_type_new(V_ASN1_ENUMERATED) +#define ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a) +#define ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\ + (ASN1_STRING *)a,(ASN1_STRING *)b) +/* ASN1_ENUMERATED_set() is a function, also see BN_to_ASN1_ENUMERATED() */ +/* ASN1_ENUMERATED_get() is a function, also see ASN1_ENUMERATED_to_BN() */ +/* i2d_ASN1_ENUMERATED() is a function */ +/* d2i_ASN1_ENUMERATED() is a function */ + #define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\ ASN1_STRING_type_new(V_ASN1_OCTET_STRING) #define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) @@ -350,7 +347,29 @@ typedef struct asn1_header_st B_ASN1_BMPSTRING|\ B_ASN1_UNKNOWN) -#define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING_STRING *)\ +#define DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) +#define DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ + pp,a->type,V_ASN1_UNIVERSAL) +#define M_d2i_DIRECTORYSTRING(a,pp,l) \ + d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ + B_ASN1_PRINTABLESTRING| \ + B_ASN1_TELETEXSTRING|\ + B_ASN1_BMPSTRING|\ + B_ASN1_UNIVERSALSTRING|\ + B_ASN1_UTF8STRING) + +#define DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) +#define DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ + pp,a->type,V_ASN1_UNIVERSAL) +#define M_d2i_DISPLAYTEXT(a,pp,l) \ + d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ + B_ASN1_VISIBLESTRING| \ + B_ASN1_BMPSTRING|\ + B_ASN1_UTF8STRING) + +#define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\ ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) #define ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) #define M_i2d_ASN1_PRINTABLESTRING(a,pp) \ @@ -373,6 +392,8 @@ typedef struct asn1_header_st #define ASN1_IA5STRING_new() (ASN1_IA5STRING *)\ ASN1_STRING_type_new(V_ASN1_IA5STRING) #define ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define ASN1_IA5STRING_dup(a) \ + (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a) #define M_i2d_ASN1_IA5STRING(a,pp) \ i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\ V_ASN1_UNIVERSAL) @@ -392,12 +413,22 @@ typedef struct asn1_header_st #define ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\ ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME) #define ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) -#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup(\ +#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\ (ASN1_STRING *)a) -/* DOES NOT EXIST YET i2d_ASN1_GENERALIZEDTIME() is a function */ -/* DOES NOT EXIST YET d2i_ASN1_GENERALIZEDTIME() is a function */ -/* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_set() is a function */ -/* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_check() is a function */ +/* i2d_ASN1_GENERALIZEDTIME() is a function */ +/* d2i_ASN1_GENERALIZEDTIME() is a function */ +/* ASN1_GENERALIZEDTIME_set() is a function */ +/* ASN1_GENERALIZEDTIME_check() is a function */ + +#define ASN1_TIME_new() (ASN1_TIME *)\ + ASN1_STRING_type_new(V_ASN1_UTCTIME) +#define ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a) + +/* i2d_ASN1_TIME() is a function */ +/* d2i_ASN1_TIME() is a function */ +/* ASN1_TIME_set() is a function */ +/* ASN1_TIME_check() is a function */ #define ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\ ASN1_STRING_type_new(V_ASN1_GENERALSTRING) @@ -429,13 +460,36 @@ typedef struct asn1_header_st (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\ ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING) -#ifndef NOPROTO +#define ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\ + ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) +#define ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_VISIBLESTRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \ + (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING) + +#define ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\ + ASN1_STRING_type_new(V_ASN1_UTF8STRING) +#define ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) +#define M_i2d_ASN1_UTF8STRING(a,pp) \ + i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\ + V_ASN1_UNIVERSAL) +#define M_d2i_ASN1_UTF8STRING(a,pp,l) \ + (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\ + ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING) + + /* for the is_set parameter to i2d_ASN1_SET */ +#define IS_SEQUENCE 0 +#define IS_SET 1 + ASN1_TYPE * ASN1_TYPE_new(void ); void ASN1_TYPE_free(ASN1_TYPE *a); int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp); ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length); int ASN1_TYPE_get(ASN1_TYPE *a); -void ASN1_TYPE_set(ASN1_TYPE *a, int type, char *value); +void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value); ASN1_OBJECT * ASN1_OBJECT_new(void ); void ASN1_OBJECT_free(ASN1_OBJECT *a); @@ -443,12 +497,17 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp); ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp, long length); +DECLARE_STACK_OF(ASN1_OBJECT) +DECLARE_ASN1_SET_OF(ASN1_OBJECT) + ASN1_STRING * ASN1_STRING_new(void ); void ASN1_STRING_free(ASN1_STRING *a); ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a); ASN1_STRING * ASN1_STRING_type_new(int type ); int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b); -int ASN1_STRING_set(ASN1_STRING *str,unsigned char *data, int len); + /* Since this is used to store all sorts of things, via macros, for now, make + its data void * */ +int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp); ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp, @@ -463,21 +522,50 @@ int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length); int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp, long length); +ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp, + long length); + +int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp); +ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp, + long length); int ASN1_UTCTIME_check(ASN1_UTCTIME *a); ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t); int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str); +int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a); +ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t); +int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str); + int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp); ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, unsigned char **pp,long length); +int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp); +ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a, + unsigned char **pp,long length); + +int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp); +ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, + unsigned char **pp,long length); + +int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp); +ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp, + long length); + int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp); ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, unsigned char **pp, long l); ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, unsigned char **pp, long l); +int i2d_DIRECTORYSTRING(ASN1_STRING *a,unsigned char **pp); +ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp, + long length); + +int i2d_DISPLAYTEXT(ASN1_STRING *a,unsigned char **pp); +ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, long length); + ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, unsigned char **pp, long l); int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp); @@ -488,21 +576,32 @@ int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp); ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp, long length); +int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp); +ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp, + long length); + +int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp); +ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length); +ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t); + int i2d_ASN1_SET(STACK *a, unsigned char **pp, - int (*func)(), int ex_tag, int ex_class); + int (*func)(), int ex_tag, int ex_class, int is_set); STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length, - char *(*func)(), int ex_tag, int ex_class); + char *(*func)(), void (*free_func)(), + int ex_tag, int ex_class); #ifdef HEADER_BIO_H int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size); +int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a); +int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size); int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a); int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size); int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type); #endif int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a); -int a2d_ASN1_OBJECT(unsigned char *out,int olen, char *buf, int num); +int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num); ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len, char *sn, char *ln); @@ -511,6 +610,11 @@ long ASN1_INTEGER_get(ASN1_INTEGER *a); ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai); BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn); +int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); +long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a); +ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai); +BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn); + /* General */ /* given a string, return the correct type, max is the maximum length */ int ASN1_PRINTABLE_type(unsigned char *s, int max); @@ -545,6 +649,8 @@ int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x); char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x); int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x); int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a); +int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a); +int ASN1_TIME_print(BIO *fp,ASN1_TIME *a); int ASN1_STRING_print(BIO *bp,ASN1_STRING *v); int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent); #endif @@ -574,111 +680,32 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, unsigned char *data, int max_len); -#else - -ASN1_TYPE * ASN1_TYPE_new(); -void ASN1_TYPE_free(); -int i2d_ASN1_TYPE(); -ASN1_TYPE * d2i_ASN1_TYPE(); -int ASN1_TYPE_get(); -void ASN1_TYPE_set(); - -ASN1_OBJECT * ASN1_OBJECT_new(); -void ASN1_OBJECT_free(); -int i2d_ASN1_OBJECT(); -ASN1_OBJECT * d2i_ASN1_OBJECT(); -ASN1_STRING * ASN1_STRING_new(); -void ASN1_STRING_free(); -ASN1_STRING * ASN1_STRING_dup(); -ASN1_STRING * ASN1_STRING_type_new(); -int ASN1_STRING_cmp(); -int ASN1_STRING_set(); -int i2d_ASN1_BIT_STRING(); -ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(); -int ASN1_BIT_STRING_set_bit(); -int ASN1_BIT_STRING_get_bit(); -int i2d_ASN1_BOOLEAN(); -int d2i_ASN1_BOOLEAN(); -int i2d_ASN1_INTEGER(); -ASN1_INTEGER *d2i_ASN1_INTEGER(); -int ASN1_UTCTIME_check(); -ASN1_UTCTIME *ASN1_UTCTIME_set(); -int ASN1_UTCTIME_set_string(); -int i2d_ASN1_OCTET_STRING(); -ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(); -int i2d_ASN1_PRINTABLE(); -ASN1_STRING *d2i_ASN1_PRINTABLE(); -ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(); -ASN1_T61STRING *d2i_ASN1_T61STRING(); -int i2d_ASN1_IA5STRING(); -ASN1_IA5STRING *d2i_ASN1_IA5STRING(); -int i2d_ASN1_UTCTIME(); -ASN1_UTCTIME * d2i_ASN1_UTCTIME(); -int i2d_ASN1_SET(); -STACK * d2i_ASN1_SET(); -int a2d_ASN1_OBJECT(); -ASN1_OBJECT *ASN1_OBJECT_create(); -int ASN1_INTEGER_set(); -long ASN1_INTEGER_get(); -ASN1_INTEGER *BN_to_ASN1_INTEGER(); -BIGNUM *ASN1_INTEGER_to_BN(); -int ASN1_PRINTABLE_type(); -int i2d_ASN1_bytes(); -ASN1_STRING *d2i_ASN1_bytes(); -ASN1_STRING *d2i_ASN1_type_bytes(); -int asn1_Finish(); -int ASN1_get_object(); -int ASN1_check_infinite_end(); -void ASN1_put_object(); -int ASN1_object_size(); -char *ASN1_dup(); -#ifndef NO_FP_API -char *ASN1_d2i_fp(); -int ASN1_i2d_fp(); -#endif - -char *ASN1_d2i_bio(); -int ASN1_i2d_bio(); -int ASN1_UTCTIME_print(); -int ASN1_STRING_print(); -int ASN1_parse(); -int i2a_ASN1_INTEGER(); -int a2i_ASN1_INTEGER(); -int i2a_ASN1_OBJECT(); -int i2t_ASN1_OBJECT(); -int a2i_ASN1_STRING(); -int i2a_ASN1_STRING(); - -int i2d_ASN1_HEADER(); -ASN1_HEADER *d2i_ASN1_HEADER(); -ASN1_HEADER *ASN1_HEADER_new(); -void ASN1_HEADER_free(); -void ERR_load_ASN1_strings(); -ASN1_METHOD *X509_asn1_meth(); -ASN1_METHOD *RSAPrivateKey_asn1_meth(); -ASN1_METHOD *ASN1_IA5STRING_asn1_meth(); -ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(); - -int ASN1_UNIVERSALSTRING_to_string(); - -int ASN1_TYPE_set_octetstring(); -int ASN1_TYPE_get_octetstring(); -int ASN1_TYPE_set_int_octetstring(); -int ASN1_TYPE_get_int_octetstring(); - -#endif +STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(), + void (*free_func)() ); +unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf, + int *len ); +void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)()); +ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct); /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the ASN1 functions. */ /* Function codes. */ #define ASN1_F_A2D_ASN1_OBJECT 100 +#define ASN1_F_A2I_ASN1_ENUMERATED 236 #define ASN1_F_A2I_ASN1_INTEGER 101 #define ASN1_F_A2I_ASN1_STRING 102 -#define ASN1_F_ASN1_COLLATE_PRIMATIVE 103 +#define ASN1_F_ASN1_COLLATE_PRIMITIVE 103 #define ASN1_F_ASN1_D2I_BIO 104 #define ASN1_F_ASN1_D2I_FP 105 #define ASN1_F_ASN1_DUP 106 +#define ASN1_F_ASN1_ENUMERATED_SET 232 +#define ASN1_F_ASN1_ENUMERATED_TO_BN 233 +#define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222 #define ASN1_F_ASN1_GET_OBJECT 107 #define ASN1_F_ASN1_HEADER_NEW 108 #define ASN1_F_ASN1_I2D_BIO 109 @@ -686,37 +713,65 @@ int ASN1_TYPE_get_int_octetstring(); #define ASN1_F_ASN1_INTEGER_SET 111 #define ASN1_F_ASN1_INTEGER_TO_BN 112 #define ASN1_F_ASN1_OBJECT_NEW 113 +#define ASN1_F_ASN1_PACK_STRING 245 +#define ASN1_F_ASN1_PBE_SET 253 +#define ASN1_F_ASN1_SEQ_PACK 246 +#define ASN1_F_ASN1_SEQ_UNPACK 247 #define ASN1_F_ASN1_SIGN 114 #define ASN1_F_ASN1_STRING_NEW 115 #define ASN1_F_ASN1_STRING_TYPE_NEW 116 #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117 #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118 #define ASN1_F_ASN1_TYPE_NEW 119 +#define ASN1_F_ASN1_UNPACK_STRING 248 #define ASN1_F_ASN1_UTCTIME_NEW 120 #define ASN1_F_ASN1_VERIFY 121 +#define ASN1_F_AUTHORITY_KEYID_NEW 237 +#define ASN1_F_BASIC_CONSTRAINTS_NEW 226 +#define ASN1_F_BN_TO_ASN1_ENUMERATED 234 #define ASN1_F_BN_TO_ASN1_INTEGER 122 #define ASN1_F_D2I_ASN1_BIT_STRING 123 #define ASN1_F_D2I_ASN1_BMPSTRING 124 #define ASN1_F_D2I_ASN1_BOOLEAN 125 #define ASN1_F_D2I_ASN1_BYTES 126 +#define ASN1_F_D2I_ASN1_ENUMERATED 235 +#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223 #define ASN1_F_D2I_ASN1_HEADER 127 #define ASN1_F_D2I_ASN1_INTEGER 128 #define ASN1_F_D2I_ASN1_OBJECT 129 #define ASN1_F_D2I_ASN1_OCTET_STRING 130 #define ASN1_F_D2I_ASN1_PRINT_TYPE 131 #define ASN1_F_D2I_ASN1_SET 132 +#define ASN1_F_D2I_ASN1_TIME 224 #define ASN1_F_D2I_ASN1_TYPE 133 #define ASN1_F_D2I_ASN1_TYPE_BYTES 134 +#define ASN1_F_D2I_ASN1_UINTEGER 280 #define ASN1_F_D2I_ASN1_UTCTIME 135 +#define ASN1_F_D2I_ASN1_UTF8STRING 266 +#define ASN1_F_D2I_ASN1_VISIBLESTRING 267 +#define ASN1_F_D2I_AUTHORITY_KEYID 238 +#define ASN1_F_D2I_BASIC_CONSTRAINTS 227 #define ASN1_F_D2I_DHPARAMS 136 +#define ASN1_F_D2I_DIST_POINT 276 +#define ASN1_F_D2I_DIST_POINT_NAME 277 #define ASN1_F_D2I_DSAPARAMS 137 #define ASN1_F_D2I_DSAPRIVATEKEY 138 #define ASN1_F_D2I_DSAPUBLICKEY 139 +#define ASN1_F_D2I_GENERAL_NAME 230 +#define ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE 228 #define ASN1_F_D2I_NETSCAPE_PKEY 140 #define ASN1_F_D2I_NETSCAPE_RSA 141 #define ASN1_F_D2I_NETSCAPE_RSA_2 142 #define ASN1_F_D2I_NETSCAPE_SPKAC 143 #define ASN1_F_D2I_NETSCAPE_SPKI 144 +#define ASN1_F_D2I_NOTICEREF 268 +#define ASN1_F_D2I_PBE2PARAM 262 +#define ASN1_F_D2I_PBEPARAM 249 +#define ASN1_F_D2I_PBKDF2PARAM 263 +#define ASN1_F_D2I_PKCS12 254 +#define ASN1_F_D2I_PKCS12_BAGS 255 +#define ASN1_F_D2I_PKCS12_MAC_DATA 256 +#define ASN1_F_D2I_PKCS12_SAFEBAG 257 #define ASN1_F_D2I_PKCS7 145 #define ASN1_F_D2I_PKCS7_DIGEST 146 #define ASN1_F_D2I_PKCS7_ENCRYPT 147 @@ -727,10 +782,17 @@ int ASN1_TYPE_get_int_octetstring(); #define ASN1_F_D2I_PKCS7_SIGNED 152 #define ASN1_F_D2I_PKCS7_SIGNER_INFO 153 #define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154 +#define ASN1_F_D2I_PKCS8_PRIV_KEY_INFO 250 +#define ASN1_F_D2I_PKEY_USAGE_PERIOD 239 +#define ASN1_F_D2I_POLICYINFO 269 +#define ASN1_F_D2I_POLICYQUALINFO 270 #define ASN1_F_D2I_PRIVATEKEY 155 #define ASN1_F_D2I_PUBLICKEY 156 #define ASN1_F_D2I_RSAPRIVATEKEY 157 #define ASN1_F_D2I_RSAPUBLICKEY 158 +#define ASN1_F_D2I_SXNET 241 +#define ASN1_F_D2I_SXNETID 243 +#define ASN1_F_D2I_USERNOTICE 271 #define ASN1_F_D2I_X509 159 #define ASN1_F_D2I_X509_ALGOR 160 #define ASN1_F_D2I_X509_ATTRIBUTE 161 @@ -748,7 +810,11 @@ int ASN1_TYPE_get_int_octetstring(); #define ASN1_F_D2I_X509_REVOKED 173 #define ASN1_F_D2I_X509_SIG 174 #define ASN1_F_D2I_X509_VAL 175 +#define ASN1_F_DIST_POINT_NAME_NEW 278 +#define ASN1_F_DIST_POINT_NEW 279 +#define ASN1_F_GENERAL_NAME_NEW 231 #define ASN1_F_I2D_ASN1_HEADER 176 +#define ASN1_F_I2D_ASN1_TIME 225 #define ASN1_F_I2D_DHPARAMS 177 #define ASN1_F_I2D_DSAPARAMS 178 #define ASN1_F_I2D_DSAPRIVATEKEY 179 @@ -761,9 +827,19 @@ int ASN1_TYPE_get_int_octetstring(); #define ASN1_F_I2D_RSAPUBLICKEY 186 #define ASN1_F_I2D_X509_ATTRIBUTE 187 #define ASN1_F_I2T_ASN1_OBJECT 188 +#define ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW 229 #define ASN1_F_NETSCAPE_PKEY_NEW 189 #define ASN1_F_NETSCAPE_SPKAC_NEW 190 #define ASN1_F_NETSCAPE_SPKI_NEW 191 +#define ASN1_F_NOTICEREF_NEW 272 +#define ASN1_F_PBE2PARAM_NEW 264 +#define ASN1_F_PBEPARAM_NEW 251 +#define ASN1_F_PBKDF2PARAM_NEW 265 +#define ASN1_F_PKCS12_BAGS_NEW 258 +#define ASN1_F_PKCS12_MAC_DATA_NEW 259 +#define ASN1_F_PKCS12_NEW 260 +#define ASN1_F_PKCS12_SAFEBAG_NEW 261 +#define ASN1_F_PKCS5_PBE2_SET 281 #define ASN1_F_PKCS7_DIGEST_NEW 192 #define ASN1_F_PKCS7_ENCRYPT_NEW 193 #define ASN1_F_PKCS7_ENC_CONTENT_NEW 194 @@ -774,6 +850,13 @@ int ASN1_TYPE_get_int_octetstring(); #define ASN1_F_PKCS7_SIGNED_NEW 199 #define ASN1_F_PKCS7_SIGNER_INFO_NEW 200 #define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201 +#define ASN1_F_PKCS8_PRIV_KEY_INFO_NEW 252 +#define ASN1_F_PKEY_USAGE_PERIOD_NEW 240 +#define ASN1_F_POLICYINFO_NEW 273 +#define ASN1_F_POLICYQUALINFO_NEW 274 +#define ASN1_F_SXNETID_NEW 244 +#define ASN1_F_SXNET_NEW 242 +#define ASN1_F_USERNOTICE_NEW 275 #define ASN1_F_X509_ALGOR_NEW 202 #define ASN1_F_X509_ATTRIBUTE_NEW 203 #define ASN1_F_X509_CINF_NEW 204 @@ -797,61 +880,64 @@ int ASN1_TYPE_get_int_octetstring(); /* Reason codes. */ #define ASN1_R_BAD_CLASS 100 -#define ASN1_R_BAD_GET_OBJECT 101 -#define ASN1_R_BAD_OBJECT_HEADER 102 -#define ASN1_R_BAD_PASSWORD_READ 103 -#define ASN1_R_BAD_PKCS7_CONTENT 104 -#define ASN1_R_BAD_PKCS7_TYPE 105 -#define ASN1_R_BAD_TAG 106 -#define ASN1_R_BAD_TYPE 107 -#define ASN1_R_BN_LIB 108 -#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109 -#define ASN1_R_BUFFER_TOO_SMALL 110 -#define ASN1_R_DATA_IS_WRONG 111 -#define ASN1_R_DECODING_ERROR 112 -#define ASN1_R_ERROR_STACK 113 -#define ASN1_R_EXPECTING_AN_INTEGER 114 -#define ASN1_R_EXPECTING_AN_OBJECT 115 -#define ASN1_R_EXPECTING_AN_OCTET_STRING 116 -#define ASN1_R_EXPECTING_A_BIT_STRING 117 -#define ASN1_R_EXPECTING_A_BOOLEAN 118 -#define ASN1_R_EXPECTING_A_SEQUENCE 119 -#define ASN1_R_EXPECTING_A_UTCTIME 120 -#define ASN1_R_FIRST_NUM_TOO_LARGE 121 -#define ASN1_R_HEADER_TOO_LONG 122 -#define ASN1_R_INVALID_DIGIT 123 -#define ASN1_R_INVALID_SEPARATOR 124 -#define ASN1_R_INVALID_TIME_FORMAT 125 -#define ASN1_R_IV_TOO_LARGE 126 -#define ASN1_R_LENGTH_ERROR 127 -#define ASN1_R_LENGTH_MISMATCH 128 -#define ASN1_R_MISSING_EOS 129 -#define ASN1_R_MISSING_SECOND_NUMBER 130 -#define ASN1_R_NON_HEX_CHARACTERS 131 -#define ASN1_R_NOT_ENOUGH_DATA 132 -#define ASN1_R_ODD_NUMBER_OF_CHARS 133 -#define ASN1_R_PARSING 134 -#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135 -#define ASN1_R_SECOND_NUMBER_TOO_LARGE 136 -#define ASN1_R_SHORT_LINE 137 -#define ASN1_R_STRING_TOO_SHORT 138 -#define ASN1_R_TAG_VALUE_TOO_HIGH 139 -#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140 -#define ASN1_R_TOO_LONG 141 -#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142 -#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143 -#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144 -#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145 -#define ASN1_R_UNKNOWN_OBJECT_TYPE 146 -#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147 -#define ASN1_R_UNSUPPORTED_CIPHER 148 -#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149 -#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150 -#define ASN1_R_UTCTIME_TOO_LONG 151 -#define ASN1_R_WRONG_PRINTABLE_TYPE 152 -#define ASN1_R_WRONG_TAG 153 -#define ASN1_R_WRONG_TYPE 154 - +#define ASN1_R_BAD_OBJECT_HEADER 101 +#define ASN1_R_BAD_PASSWORD_READ 102 +#define ASN1_R_BAD_PKCS7_CONTENT 103 +#define ASN1_R_BAD_PKCS7_TYPE 104 +#define ASN1_R_BAD_TAG 105 +#define ASN1_R_BAD_TYPE 106 +#define ASN1_R_BN_LIB 107 +#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108 +#define ASN1_R_BUFFER_TOO_SMALL 109 +#define ASN1_R_DATA_IS_WRONG 110 +#define ASN1_R_DECODE_ERROR 155 +#define ASN1_R_DECODING_ERROR 111 +#define ASN1_R_ENCODE_ERROR 156 +#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112 +#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 157 +#define ASN1_R_EXPECTING_AN_ENUMERATED 154 +#define ASN1_R_EXPECTING_AN_INTEGER 113 +#define ASN1_R_EXPECTING_AN_OBJECT 114 +#define ASN1_R_EXPECTING_AN_OCTET_STRING 115 +#define ASN1_R_EXPECTING_A_BIT_STRING 116 +#define ASN1_R_EXPECTING_A_BOOLEAN 117 +#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151 +#define ASN1_R_EXPECTING_A_TIME 152 +#define ASN1_R_EXPECTING_A_UTCTIME 118 +#define ASN1_R_FIRST_NUM_TOO_LARGE 119 +#define ASN1_R_GENERALIZEDTIME_TOO_LONG 153 +#define ASN1_R_HEADER_TOO_LONG 120 +#define ASN1_R_INVALID_DIGIT 121 +#define ASN1_R_INVALID_SEPARATOR 122 +#define ASN1_R_INVALID_TIME_FORMAT 123 +#define ASN1_R_IV_TOO_LARGE 124 +#define ASN1_R_LENGTH_ERROR 125 +#define ASN1_R_MISSING_SECOND_NUMBER 126 +#define ASN1_R_NON_HEX_CHARACTERS 127 +#define ASN1_R_NOT_ENOUGH_DATA 128 +#define ASN1_R_ODD_NUMBER_OF_CHARS 129 +#define ASN1_R_PARSING 130 +#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131 +#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132 +#define ASN1_R_SHORT_LINE 133 +#define ASN1_R_STRING_TOO_SHORT 134 +#define ASN1_R_TAG_VALUE_TOO_HIGH 135 +#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136 +#define ASN1_R_TOO_LONG 137 +#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138 +#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139 +#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140 +#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141 +#define ASN1_R_UNKNOWN_OBJECT_TYPE 142 +#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143 +#define ASN1_R_UNSUPPORTED_CIPHER 144 +#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 145 +#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 146 +#define ASN1_R_UTCTIME_TOO_LONG 147 +#define ASN1_R_WRONG_PRINTABLE_TYPE 148 +#define ASN1_R_WRONG_TAG 149 +#define ASN1_R_WRONG_TYPE 150 + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c index 03c2858e7d..16755a0b05 100644 --- a/src/lib/libcrypto/asn1/asn1_err.c +++ b/src/lib/libcrypto/asn1/asn1_err.c @@ -1,75 +1,81 @@ -/* lib/asn1/asn1_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/asn1/asn1_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "asn1.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR static ERR_STRING_DATA ASN1_str_functs[]= { {ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"}, +{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"}, {ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"}, {ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"}, -{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMATIVE,0), "ASN1_COLLATE_PRIMATIVE"}, +{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"}, {ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"}, {ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"}, {ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"}, +{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"}, +{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"}, +{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_NEW"}, {ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"}, {ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"}, {ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"}, @@ -77,121 +83,176 @@ static ERR_STRING_DATA ASN1_str_functs[]= {ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"}, {ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"}, {ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"}, -{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_SIGN"}, +{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"}, +{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"}, +{ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"}, +{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"}, +{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"}, {ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"}, {ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"}, {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"}, {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"}, {ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"}, +{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"}, {ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"}, -{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_VERIFY"}, +{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"}, +{ERR_PACK(0,ASN1_F_AUTHORITY_KEYID_NEW,0), "AUTHORITY_KEYID_new"}, +{ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_new"}, +{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"}, {ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"}, -{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "D2I_ASN1_BMPSTRING"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_ENUMERATED,0), "d2i_ASN1_ENUMERATED"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_TIME,0), "d2i_ASN1_TIME"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_UINTEGER,0), "d2i_ASN1_UINTEGER"}, {ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"}, -{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "D2I_DHPARAMS"}, -{ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "D2I_DSAPARAMS"}, -{ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "D2I_DSAPRIVATEKEY"}, -{ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "D2I_DSAPUBLICKEY"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_UTF8STRING,0), "d2i_ASN1_UTF8STRING"}, +{ERR_PACK(0,ASN1_F_D2I_ASN1_VISIBLESTRING,0), "d2i_ASN1_VISIBLESTRING"}, +{ERR_PACK(0,ASN1_F_D2I_AUTHORITY_KEYID,0), "d2i_AUTHORITY_KEYID"}, +{ERR_PACK(0,ASN1_F_D2I_BASIC_CONSTRAINTS,0), "d2i_BASIC_CONSTRAINTS"}, +{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "d2i_DHparams"}, +{ERR_PACK(0,ASN1_F_D2I_DIST_POINT,0), "d2i_DIST_POINT"}, +{ERR_PACK(0,ASN1_F_D2I_DIST_POINT_NAME,0), "d2i_DIST_POINT_NAME"}, +{ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "d2i_DSAparams"}, +{ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "d2i_DSAPrivateKey"}, +{ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "d2i_DSAPublicKey"}, +{ERR_PACK(0,ASN1_F_D2I_GENERAL_NAME,0), "d2i_GENERAL_NAME"}, +{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE,0), "d2i_NETSCAPE_CERT_SEQUENCE"}, {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_PKEY,0), "D2I_NETSCAPE_PKEY"}, -{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "D2I_NETSCAPE_RSA"}, -{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "D2I_NETSCAPE_RSA_2"}, -{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "D2I_NETSCAPE_SPKAC"}, -{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "D2I_NETSCAPE_SPKI"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "D2I_PKCS7"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "D2I_PKCS7_DIGEST"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "D2I_PKCS7_ENCRYPT"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "D2I_PKCS7_ENC_CONTENT"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "D2I_PKCS7_ENVELOPE"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "D2I_PKCS7_ISSUER_AND_SERIAL"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "D2I_PKCS7_RECIP_INFO"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "D2I_PKCS7_SIGNED"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "D2I_PKCS7_SIGNER_INFO"}, -{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "D2I_PKCS7_SIGN_ENVELOPE"}, -{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "D2I_PRIVATEKEY"}, -{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "D2I_PUBLICKEY"}, -{ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "D2I_RSAPRIVATEKEY"}, -{ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "D2I_RSAPUBLICKEY"}, -{ERR_PACK(0,ASN1_F_D2I_X509,0), "D2I_X509"}, -{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "D2I_X509_ALGOR"}, -{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "D2I_X509_ATTRIBUTE"}, -{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "D2I_X509_CINF"}, -{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "D2I_X509_CRL"}, -{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "D2I_X509_CRL_INFO"}, -{ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "D2I_X509_EXTENSION"}, +{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "d2i_Netscape_RSA"}, +{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "d2i_Netscape_RSA_2"}, +{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "d2i_NETSCAPE_SPKAC"}, +{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "d2i_NETSCAPE_SPKI"}, +{ERR_PACK(0,ASN1_F_D2I_NOTICEREF,0), "d2i_NOTICEREF"}, +{ERR_PACK(0,ASN1_F_D2I_PBE2PARAM,0), "d2i_PBE2PARAM"}, +{ERR_PACK(0,ASN1_F_D2I_PBEPARAM,0), "d2i_PBEPARAM"}, +{ERR_PACK(0,ASN1_F_D2I_PBKDF2PARAM,0), "d2i_PBKDF2PARAM"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS12,0), "d2i_PKCS12"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS12_BAGS,0), "d2i_PKCS12_BAGS"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS12_MAC_DATA,0), "d2i_PKCS12_MAC_DATA"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS12_SAFEBAG,0), "d2i_PKCS12_SAFEBAG"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "d2i_PKCS7"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "d2i_PKCS7_DIGEST"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "d2i_PKCS7_ENCRYPT"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "d2i_PKCS7_ENC_CONTENT"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "d2i_PKCS7_ENVELOPE"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "d2i_PKCS7_ISSUER_AND_SERIAL"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "d2i_PKCS7_RECIP_INFO"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "d2i_PKCS7_SIGNED"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "d2i_PKCS7_SIGNER_INFO"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "d2i_PKCS7_SIGN_ENVELOPE"}, +{ERR_PACK(0,ASN1_F_D2I_PKCS8_PRIV_KEY_INFO,0), "d2i_PKCS8_PRIV_KEY_INFO"}, +{ERR_PACK(0,ASN1_F_D2I_PKEY_USAGE_PERIOD,0), "d2i_PKEY_USAGE_PERIOD"}, +{ERR_PACK(0,ASN1_F_D2I_POLICYINFO,0), "d2i_POLICYINFO"}, +{ERR_PACK(0,ASN1_F_D2I_POLICYQUALINFO,0), "d2i_POLICYQUALINFO"}, +{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"}, +{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"}, +{ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "d2i_RSAPrivateKey"}, +{ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "d2i_RSAPublicKey"}, +{ERR_PACK(0,ASN1_F_D2I_SXNET,0), "d2i_SXNET"}, +{ERR_PACK(0,ASN1_F_D2I_SXNETID,0), "d2i_SXNETID"}, +{ERR_PACK(0,ASN1_F_D2I_USERNOTICE,0), "d2i_USERNOTICE"}, +{ERR_PACK(0,ASN1_F_D2I_X509,0), "d2i_X509"}, +{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "d2i_X509_ALGOR"}, +{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "d2i_X509_ATTRIBUTE"}, +{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "d2i_X509_CINF"}, +{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "d2i_X509_CRL"}, +{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "d2i_X509_CRL_INFO"}, +{ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "d2i_X509_EXTENSION"}, {ERR_PACK(0,ASN1_F_D2I_X509_KEY,0), "D2I_X509_KEY"}, -{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "D2I_X509_NAME"}, -{ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "D2I_X509_NAME_ENTRY"}, -{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "D2I_X509_PKEY"}, -{ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "D2I_X509_PUBKEY"}, -{ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "D2I_X509_REQ"}, -{ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "D2I_X509_REQ_INFO"}, -{ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "D2I_X509_REVOKED"}, -{ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "D2I_X509_SIG"}, -{ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "D2I_X509_VAL"}, +{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "d2i_X509_NAME"}, +{ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "d2i_X509_NAME_ENTRY"}, +{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"}, +{ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "d2i_X509_PUBKEY"}, +{ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "d2i_X509_REQ"}, +{ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "d2i_X509_REQ_INFO"}, +{ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "d2i_X509_REVOKED"}, +{ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "d2i_X509_SIG"}, +{ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "d2i_X509_VAL"}, +{ERR_PACK(0,ASN1_F_DIST_POINT_NAME_NEW,0), "DIST_POINT_NAME_new"}, +{ERR_PACK(0,ASN1_F_DIST_POINT_NEW,0), "DIST_POINT_new"}, +{ERR_PACK(0,ASN1_F_GENERAL_NAME_NEW,0), "GENERAL_NAME_new"}, {ERR_PACK(0,ASN1_F_I2D_ASN1_HEADER,0), "i2d_ASN1_HEADER"}, -{ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "I2D_DHPARAMS"}, -{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "I2D_DSAPARAMS"}, -{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "I2D_DSAPRIVATEKEY"}, -{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "I2D_DSAPUBLICKEY"}, -{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "I2D_NETSCAPE_RSA"}, -{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "I2D_PKCS7"}, -{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "I2D_PRIVATEKEY"}, -{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "I2D_PUBLICKEY"}, -{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "I2D_RSAPRIVATEKEY"}, -{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "I2D_RSAPUBLICKEY"}, -{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "I2D_X509_ATTRIBUTE"}, +{ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "i2d_ASN1_TIME"}, +{ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "i2d_DHparams"}, +{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "i2d_DSAparams"}, +{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "i2d_DSAPrivateKey"}, +{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "i2d_DSAPublicKey"}, +{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"}, +{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "i2d_PKCS7"}, +{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"}, +{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"}, +{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "i2d_RSAPrivateKey"}, +{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "i2d_RSAPublicKey"}, +{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "i2d_X509_ATTRIBUTE"}, {ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"}, +{ERR_PACK(0,ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW,0), "NETSCAPE_CERT_SEQUENCE_new"}, {ERR_PACK(0,ASN1_F_NETSCAPE_PKEY_NEW,0), "NETSCAPE_PKEY_NEW"}, -{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_NEW"}, -{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_NEW"}, -{ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_NEW"}, -{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_NEW"}, -{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_NEW"}, -{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_NEW"}, -{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_NEW"}, -{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_NEW"}, +{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_new"}, +{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_new"}, +{ERR_PACK(0,ASN1_F_NOTICEREF_NEW,0), "NOTICEREF_new"}, +{ERR_PACK(0,ASN1_F_PBE2PARAM_NEW,0), "PBE2PARAM_new"}, +{ERR_PACK(0,ASN1_F_PBEPARAM_NEW,0), "PBEPARAM_new"}, +{ERR_PACK(0,ASN1_F_PBKDF2PARAM_NEW,0), "PBKDF2PARAM_new"}, +{ERR_PACK(0,ASN1_F_PKCS12_BAGS_NEW,0), "PKCS12_BAGS_new"}, +{ERR_PACK(0,ASN1_F_PKCS12_MAC_DATA_NEW,0), "PKCS12_MAC_DATA_new"}, +{ERR_PACK(0,ASN1_F_PKCS12_NEW,0), "PKCS12_new"}, +{ERR_PACK(0,ASN1_F_PKCS12_SAFEBAG_NEW,0), "PKCS12_SAFEBAG_new"}, +{ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"}, +{ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_new"}, +{ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_new"}, +{ERR_PACK(0,ASN1_F_PKCS8_PRIV_KEY_INFO_NEW,0), "PKCS8_PRIV_KEY_INFO_new"}, +{ERR_PACK(0,ASN1_F_PKEY_USAGE_PERIOD_NEW,0), "PKEY_USAGE_PERIOD_new"}, +{ERR_PACK(0,ASN1_F_POLICYINFO_NEW,0), "POLICYINFO_new"}, +{ERR_PACK(0,ASN1_F_POLICYQUALINFO_NEW,0), "POLICYQUALINFO_new"}, +{ERR_PACK(0,ASN1_F_SXNETID_NEW,0), "SXNETID_new"}, +{ERR_PACK(0,ASN1_F_SXNET_NEW,0), "SXNET_new"}, +{ERR_PACK(0,ASN1_F_USERNOTICE_NEW,0), "USERNOTICE_new"}, +{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_new"}, +{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_new"}, +{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_new"}, +{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_new"}, +{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_new"}, {ERR_PACK(0,ASN1_F_X509_DHPARAMS_NEW,0), "X509_DHPARAMS_NEW"}, -{ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_NEW"}, -{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_NEW"}, +{ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_new"}, +{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_new"}, {ERR_PACK(0,ASN1_F_X509_KEY_NEW,0), "X509_KEY_NEW"}, -{ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_NEW"}, -{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_NEW"}, -{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_NEW"}, -{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_NEW"}, -{ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_NEW"}, -{ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_NEW"}, -{ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_NEW"}, -{ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_NEW"}, -{ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_NEW"}, -{ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_FREE"}, -{ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_NEW"}, -{0,NULL}, +{ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_new"}, +{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_new"}, +{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_new"}, +{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_new"}, +{ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_new"}, +{ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_new"}, +{ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_new"}, +{ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_new"}, +{ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_new"}, +{ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_free"}, +{ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_new"}, +{0,NULL} }; static ERR_STRING_DATA ASN1_str_reasons[]= { {ASN1_R_BAD_CLASS ,"bad class"}, -{ASN1_R_BAD_GET_OBJECT ,"bad get object"}, {ASN1_R_BAD_OBJECT_HEADER ,"bad object header"}, {ASN1_R_BAD_PASSWORD_READ ,"bad password read"}, {ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"}, @@ -202,24 +263,28 @@ static ERR_STRING_DATA ASN1_str_reasons[]= {ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"}, {ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"}, {ASN1_R_DATA_IS_WRONG ,"data is wrong"}, +{ASN1_R_DECODE_ERROR ,"decode error"}, {ASN1_R_DECODING_ERROR ,"decoding error"}, -{ASN1_R_ERROR_STACK ,"error stack"}, +{ASN1_R_ENCODE_ERROR ,"encode error"}, +{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"}, +{ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"}, +{ASN1_R_EXPECTING_AN_ENUMERATED ,"expecting an enumerated"}, {ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"}, {ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"}, {ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"}, {ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"}, {ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"}, -{ASN1_R_EXPECTING_A_SEQUENCE ,"expecting a sequence"}, +{ASN1_R_EXPECTING_A_GENERALIZEDTIME ,"expecting a generalizedtime"}, +{ASN1_R_EXPECTING_A_TIME ,"expecting a time"}, {ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"}, {ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"}, +{ASN1_R_GENERALIZEDTIME_TOO_LONG ,"generalizedtime too long"}, {ASN1_R_HEADER_TOO_LONG ,"header too long"}, {ASN1_R_INVALID_DIGIT ,"invalid digit"}, {ASN1_R_INVALID_SEPARATOR ,"invalid separator"}, {ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"}, {ASN1_R_IV_TOO_LARGE ,"iv too large"}, {ASN1_R_LENGTH_ERROR ,"length error"}, -{ASN1_R_LENGTH_MISMATCH ,"length mismatch"}, -{ASN1_R_MISSING_EOS ,"missing eos"}, {ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"}, {ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"}, {ASN1_R_NOT_ENOUGH_DATA ,"not enough data"}, @@ -245,17 +310,17 @@ static ERR_STRING_DATA ASN1_str_reasons[]= {ASN1_R_WRONG_PRINTABLE_TYPE ,"wrong printable type"}, {ASN1_R_WRONG_TAG ,"wrong tag"}, {ASN1_R_WRONG_TYPE ,"wrong type"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_ASN1_strings() +void ERR_load_ASN1_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs); diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c index ff30b25836..95e54ed626 100644 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ b/src/lib/libcrypto/asn1/asn1_lib.c @@ -58,22 +58,14 @@ #include #include "cryptlib.h" -#include "asn1.h" -#include "asn1_mac.h" +#include +#include -#ifndef NOPROTO static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max); static void asn1_put_length(unsigned char **pp, int length); -#else -static int asn1_get_length(); -static void asn1_put_length(); -#endif - -char *ASN1_version="ASN1 part of SSLeay 0.9.0b 29-Jun-1998"; +const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT; -int ASN1_check_infinite_end(p,len) -unsigned char **p; -long len; +int ASN1_check_infinite_end(unsigned char **p, long len) { /* If there is 0 or 1 byte left, the length check should pick * things up */ @@ -88,12 +80,8 @@ long len; } -int ASN1_get_object(pp, plength, ptag, pclass, omax) -unsigned char **pp; -long *plength; -int *ptag; -int *pclass; -long omax; +int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, + long omax) { int i,ret; long l; @@ -104,8 +92,8 @@ long omax; if (!max) goto err; ret=(*p&V_ASN1_CONSTRUCTED); xclass=(*p&V_ASN1_PRIVATE); - i= *p&V_ASN1_PRIMATIVE_TAG; - if (i == V_ASN1_PRIMATIVE_TAG) + i= *p&V_ASN1_PRIMITIVE_TAG; + if (i == V_ASN1_PRIMITIVE_TAG) { /* high-tag */ p++; if (--max == 0) goto err; @@ -130,11 +118,13 @@ long omax; *pclass=xclass; if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; -#ifdef undef - fprintf(stderr,"p=%d + *plength=%d > omax=%d + *pp=%d (%d > %d)\n", - p,*plength,omax,*pp,(p+ *plength),omax+ *pp); +#if 0 + fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", + (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), + (int)(omax+ *pp)); #endif +#if 0 if ((p+ *plength) > (omax+ *pp)) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); @@ -142,18 +132,15 @@ long omax; * the values are set correctly */ ret|=0x80; } +#endif *pp=p; - return(ret+inf); + return(ret|inf); err: ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); return(0x80); } -static int asn1_get_length(pp,inf,rl,max) -unsigned char **pp; -int *inf; -long *rl; -int max; +static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) { unsigned char *p= *pp; long ret=0; @@ -190,12 +177,8 @@ int max; /* class 0 is constructed * constructed == 2 for indefinitle length constructed */ -void ASN1_put_object(pp,constructed,length,tag,xclass) -unsigned char **pp; -int constructed; -int length; -int tag; -int xclass; +void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, + int xclass) { unsigned char *p= *pp; int i; @@ -203,10 +186,10 @@ int xclass; i=(constructed)?V_ASN1_CONSTRUCTED:0; i|=(xclass&V_ASN1_PRIVATE); if (tag < 31) - *(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG); + *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); else { - *(p++)=i|V_ASN1_PRIMATIVE_TAG; + *(p++)=i|V_ASN1_PRIMITIVE_TAG; while (tag > 0x7f) { *(p++)=(tag&0x7f)|0x80; @@ -221,9 +204,7 @@ int xclass; *pp=p; } -static void asn1_put_length(pp, length) -unsigned char **pp; -int length; +static void asn1_put_length(unsigned char **pp, int length) { unsigned char *p= *pp; int i,l; @@ -246,10 +227,7 @@ int length; *pp=p; } -int ASN1_object_size(constructed, length, tag) -int constructed; -int length; -int tag; +int ASN1_object_size(int constructed, int length, int tag) { int ret; @@ -277,29 +255,26 @@ int tag; return(ret); } -int asn1_Finish(c) -ASN1_CTX *c; +int asn1_Finish(ASN1_CTX *c) { if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) { if (!ASN1_check_infinite_end(&c->p,c->slen)) { - c->error=ASN1_R_MISSING_EOS; + c->error=ERR_R_MISSING_ASN1_EOS; return(0); } } if ( ((c->slen != 0) && !(c->inf & 1)) || ((c->slen < 0) && (c->inf & 1))) { - c->error=ASN1_R_LENGTH_MISMATCH; + c->error=ERR_R_ASN1_LENGTH_MISMATCH; return(0); } return(1); } -int asn1_GetSequence(c,length) -ASN1_CTX *c; -long *length; +int asn1_GetSequence(ASN1_CTX *c, long *length) { unsigned char *q; @@ -308,18 +283,18 @@ long *length; *length); if (c->inf & 0x80) { - c->error=ASN1_R_BAD_GET_OBJECT; + c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; return(0); } if (c->tag != V_ASN1_SEQUENCE) { - c->error=ASN1_R_EXPECTING_A_SEQUENCE; + c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; return(0); } (*length)-=(c->p-q); if (c->max && (*length < 0)) { - c->error=ASN1_R_LENGTH_MISMATCH; + c->error=ERR_R_ASN1_LENGTH_MISMATCH; return(0); } if (c->inf == (1|V_ASN1_CONSTRUCTED)) @@ -328,8 +303,7 @@ long *length; return(1); } -ASN1_STRING *ASN1_STRING_dup(str) -ASN1_STRING *str; +ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str) { ASN1_STRING *ret; @@ -341,34 +315,33 @@ ASN1_STRING *str; ASN1_STRING_free(ret); return(NULL); } + ret->flags = str->flags; return(ret); } -int ASN1_STRING_set(str,data,len) -ASN1_STRING *str; -unsigned char *data; -int len; +int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) { - char *c; + unsigned char *c; + const char *data=_data; if (len < 0) { if (data == NULL) return(0); else - len=strlen((char *)data); + len=strlen(data); } if ((str->length < len) || (str->data == NULL)) { - c=(char *)str->data; + c=str->data; if (c == NULL) - str->data=(unsigned char *)Malloc(len+1); + str->data=Malloc(len+1); else - str->data=(unsigned char *)Realloc(c,len+1); + str->data=Realloc(c,len+1); if (str->data == NULL) { - str->data=(unsigned char *)c; + str->data=c; return(0); } } @@ -382,14 +355,13 @@ int len; return(1); } -ASN1_STRING *ASN1_STRING_new() +ASN1_STRING *ASN1_STRING_new(void) { return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); } -ASN1_STRING *ASN1_STRING_type_new(type) -int type; +ASN1_STRING *ASN1_STRING_type_new(int type) { ASN1_STRING *ret; @@ -402,19 +374,18 @@ int type; ret->length=0; ret->type=type; ret->data=NULL; + ret->flags=0; return(ret); } -void ASN1_STRING_free(a) -ASN1_STRING *a; +void ASN1_STRING_free(ASN1_STRING *a) { if (a == NULL) return; if (a->data != NULL) Free((char *)a->data); Free((char *)a); } -int ASN1_STRING_cmp(a,b) -ASN1_STRING *a,*b; +int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b) { int i; @@ -431,9 +402,7 @@ ASN1_STRING *a,*b; return(i); } -void asn1_add_error(address,offset) -unsigned char *address; -int offset; +void asn1_add_error(unsigned char *address, int offset) { char buf1[16],buf2[16]; diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h index 4fba70e4bb..93f9c5193c 100644 --- a/src/lib/libcrypto/asn1/asn1_mac.h +++ b/src/lib/libcrypto/asn1/asn1_mac.h @@ -63,18 +63,25 @@ extern "C" { #endif -#include "asn1.h" -#include "x509.h" -#include "pkcs7.h" +#include + +#ifndef ASN1_MAC_ERR_LIB +#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1 +#endif + +#define ASN1_MAC_H_err(f,r,line) \ + ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),ERR_file_name,(line)) #define M_ASN1_D2I_vars(a,type,func) \ ASN1_CTX c; \ type ret=NULL; \ \ c.pp=pp; \ - c.error=ASN1_R_ERROR_STACK; \ + c.q= *pp; \ + c.error=ERR_R_NESTED_ASN1_ERROR; \ if ((a == NULL) || ((*a) == NULL)) \ - { if ((ret=(type)func()) == NULL) goto err; } \ + { if ((ret=(type)func()) == NULL) \ + { c.line=__LINE__; goto err; } } \ else ret=(*a); #define M_ASN1_D2I_Init() \ @@ -82,7 +89,8 @@ extern "C" { c.max=(length == 0)?0:(c.p+length); #define M_ASN1_D2I_Finish_2(a) \ - if (!asn1_Finish(&c)) goto err; \ + if (!asn1_Finish(&c)) \ + { c.line=__LINE__; goto err; } \ *pp=c.p; \ if (a != NULL) (*a)=ret; \ return(ret); @@ -90,21 +98,31 @@ extern "C" { #define M_ASN1_D2I_Finish(a,func,e) \ M_ASN1_D2I_Finish_2(a); \ err:\ - ASN1err((e),c.error); \ + ASN1_MAC_H_err((e),c.error,c.line); \ asn1_add_error(*pp,(int)(c.q- *pp)); \ if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ return(NULL) #define M_ASN1_D2I_start_sequence() \ - if (!asn1_GetSequence(&c,&length)) goto err; + if (!asn1_GetSequence(&c,&length)) \ + { c.line=__LINE__; goto err; } #define M_ASN1_D2I_end_sequence() \ (((c.inf&1) == 0)?(c.slen <= 0): \ (c.eos=ASN1_check_infinite_end(&c.p,c.slen))) +/* Don't use this with d2i_ASN1_BOOLEAN() */ #define M_ASN1_D2I_get(b,func) \ c.q=c.p; \ - if (func(&(b),&c.p,c.slen) == NULL) goto err; \ + if (func(&(b),&c.p,c.slen) == NULL) \ + {c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +/* use this instead () */ +#define M_ASN1_D2I_get_int(b,func) \ + c.q=c.p; \ + if (func(&(b),&c.p,c.slen) < 0) \ + {c.line=__LINE__; goto err; } \ c.slen-=(c.p-c.q); #define M_ASN1_D2I_get_opt(b,func,type) \ @@ -114,49 +132,118 @@ err:\ M_ASN1_D2I_get(b,func); \ } +#define M_ASN1_D2I_get_imp(b,func, type) \ + M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \ + c.q=c.p; \ + if (func(&(b),&c.p,c.slen) == NULL) \ + {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \ + c.slen-=(c.p-c.q);\ + M_ASN1_next_prev=_tmp; + #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ { \ - unsigned char tmp; \ - tmp=M_ASN1_next; \ - M_ASN1_next=(tmp& ~V_ASN1_PRIMATIVE_TAG)|type; \ - M_ASN1_D2I_get(b,func); \ - M_ASN1_next_prev=tmp; \ + unsigned char _tmp = M_ASN1_next; \ + M_ASN1_D2I_get_imp(b,func, type);\ } -#define M_ASN1_D2I_get_set(r,func) \ - M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SET,V_ASN1_UNIVERSAL); +#define M_ASN1_D2I_get_set(r,func,free_func) \ + M_ASN1_D2I_get_imp_set(r,func,free_func, \ + V_ASN1_SET,V_ASN1_UNIVERSAL); + +#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \ + M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \ + V_ASN1_SET,V_ASN1_UNIVERSAL); + +#define M_ASN1_D2I_get_set_opt(r,func,free_func) \ + if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ + V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ + { M_ASN1_D2I_get_set(r,func,free_func); } + +#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \ + if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ + V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ + { M_ASN1_D2I_get_set_type(type,r,func,free_func); } + +#define M_ASN1_I2D_len_SET_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_len_SET(a,f); + +#define M_ASN1_I2D_put_SET_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_put_SET(a,f); + +#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_put_SEQUENCE(a,f); + +#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + M_ASN1_I2D_put_SEQUENCE_type(type,a,f); + +#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \ + if ((c.slen != 0) && \ + (M_ASN1_next == \ + (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ + { \ + M_ASN1_D2I_get_imp_set(b,func,free_func,\ + tag,V_ASN1_CONTEXT_SPECIFIC); \ + } -#define M_ASN1_D2I_get_IMP_set_opt(b,func,tag) \ +#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \ if ((c.slen != 0) && \ (M_ASN1_next == \ (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ { \ - M_ASN1_D2I_get_imp_set(b,func,tag,V_ASN1_CONTEXT_SPECIFIC); \ + M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\ + tag,V_ASN1_CONTEXT_SPECIFIC); \ } -#define M_ASN1_D2I_get_seq(r,func) \ - M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); +#define M_ASN1_D2I_get_seq(r,func,free_func) \ + M_ASN1_D2I_get_imp_set(r,func,free_func,\ + V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + +#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \ + M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ + V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) -#define M_ASN1_D2I_get_seq_opt(r,func) \ +#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \ if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ - { M_ASN1_D2I_get_seq(r,func); } + { M_ASN1_D2I_get_seq(r,func,free_func); } -#define M_ASN1_D2I_get_IMP_set(r,func,x) \ - M_ASN1_D2I_get_imp_set(r,func,x,V_ASN1_CONTEXT_SPECIFIC); +#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \ + if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ + V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ + { M_ASN1_D2I_get_seq_type(type,r,func,free_func); } + +#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \ + M_ASN1_D2I_get_imp_set(r,func,free_func,\ + x,V_ASN1_CONTEXT_SPECIFIC); -#define M_ASN1_D2I_get_imp_set(r,func,a,b) \ +#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ + M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ + x,V_ASN1_CONTEXT_SPECIFIC); + +#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ c.q=c.p; \ - if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,a,b) == NULL) \ - goto err; \ + if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ + (void (*)())free_func,a,b) == NULL) \ + { c.line=__LINE__; goto err; } \ + c.slen-=(c.p-c.q); + +#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \ + c.q=c.p; \ + if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\ + free_func,a,b) == NULL) \ + { c.line=__LINE__; goto err; } \ c.slen-=(c.p-c.q); #define M_ASN1_D2I_get_set_strings(r,func,a,b) \ c.q=c.p; \ if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ - goto err; \ + { c.line=__LINE__; goto err; } \ c.slen-=(c.p-c.q); #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ @@ -169,13 +256,22 @@ err:\ c.q=c.p; \ Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ if (Tinf & 0x80) \ - { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \ + { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ + c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ + Tlen = c.slen - (c.p - c.q) - 2; \ if (func(&(r),&c.p,Tlen) == NULL) \ - goto err; \ + { c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ + Tlen = c.slen - (c.p - c.q); \ + if(!ASN1_check_infinite_end(&c.p, Tlen)) \ + { c.error=ERR_R_MISSING_ASN1_EOS; \ + c.line=__LINE__; goto err; } \ + }\ c.slen-=(c.p-c.q); \ } -#define M_ASN1_D2I_get_EXP_set_opt(r,func,tag,b) \ +#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \ if ((c.slen != 0) && (M_ASN1_next == \ (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ { \ @@ -185,24 +281,61 @@ err:\ c.q=c.p; \ Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ if (Tinf & 0x80) \ - { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \ + { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ + c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ + Tlen = c.slen - (c.p - c.q) - 2; \ if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ + (void (*)())free_func, \ b,V_ASN1_UNIVERSAL) == NULL) \ - goto err; \ + { c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ + Tlen = c.slen - (c.p - c.q); \ + if(!ASN1_check_infinite_end(&c.p, Tlen)) \ + { c.error=ERR_R_MISSING_ASN1_EOS; \ + c.line=__LINE__; goto err; } \ + }\ + c.slen-=(c.p-c.q); \ + } + +#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \ + if ((c.slen != 0) && (M_ASN1_next == \ + (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ + { \ + int Tinf,Ttag,Tclass; \ + long Tlen; \ + \ + c.q=c.p; \ + Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ + if (Tinf & 0x80) \ + { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ + c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ + Tlen = c.slen - (c.p - c.q) - 2; \ + if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \ + free_func,b,V_ASN1_UNIVERSAL) == NULL) \ + { c.line=__LINE__; goto err; } \ + if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ + Tlen = c.slen - (c.p - c.q); \ + if(!ASN1_check_infinite_end(&c.p, Tlen)) \ + { c.error=ERR_R_MISSING_ASN1_EOS; \ + c.line=__LINE__; goto err; } \ + }\ c.slen-=(c.p-c.q); \ } /* New macros */ #define M_ASN1_New_Malloc(ret,type) \ - if ((ret=(type *)Malloc(sizeof(type))) == NULL) goto err2; + if ((ret=(type *)Malloc(sizeof(type))) == NULL) \ + { c.line=__LINE__; goto err2; } #define M_ASN1_New(arg,func) \ if (((arg)=func()) == NULL) return(NULL) #define M_ASN1_New_Error(a) \ -/* err: ASN1err((a),ASN1_R_ERROR_STACK); \ +/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \ return(NULL);*/ \ - err2: ASN1err((a),ERR_R_MALLOC_FAILURE); \ + err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \ return(NULL) @@ -220,21 +353,59 @@ err:\ #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) #define M_ASN1_I2D_len_SET(a,f) \ - ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL); + ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); -#define M_ASN1_I2D_len_SEQ(a,f) \ - ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); +#define M_ASN1_I2D_len_SET_type(type,a,f) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \ + V_ASN1_UNIVERSAL,IS_SET); -#define M_ASN1_I2D_len_SEQ_opt(a,f) \ +#define M_ASN1_I2D_len_SEQUENCE(a,f) \ + ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ + IS_SEQUENCE); + +#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \ + V_ASN1_UNIVERSAL,IS_SEQUENCE) + +#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \ if ((a != NULL) && (sk_num(a) != 0)) \ - M_ASN1_I2D_len_SEQ(a,f); + M_ASN1_I2D_len_SEQUENCE(a,f); + +#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + M_ASN1_I2D_len_SEQUENCE_type(type,a,f); -#define M_ASN1_I2D_len_IMP_set(a,f,x) \ - ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC); +#define M_ASN1_I2D_len_IMP_SET(a,f,x) \ + ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET); -#define M_ASN1_I2D_len_IMP_set_opt(a,f,x) \ +#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ + V_ASN1_CONTEXT_SPECIFIC,IS_SET); + +#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \ if ((a != NULL) && (sk_num(a) != 0)) \ - ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC); + ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SET); + +#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ + V_ASN1_CONTEXT_SPECIFIC,IS_SET); + +#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \ + ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); + +#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); + +#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ + V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ if (a != NULL)\ @@ -243,10 +414,27 @@ err:\ ret+=ASN1_object_size(1,v,mtag); \ } -#define M_ASN1_I2D_len_EXP_set_opt(a,f,mtag,tag,v) \ +#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_num(a) != 0))\ + { \ + v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ + ret+=ASN1_object_size(1,v,mtag); \ + } + +#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ if ((a != NULL) && (sk_num(a) != 0))\ { \ - v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL); \ + v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \ + IS_SEQUENCE); \ + ret+=ASN1_object_size(1,v,mtag); \ + } + +#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_##type##_num(a) != 0))\ + { \ + v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \ + V_ASN1_UNIVERSAL, \ + IS_SEQUENCE); \ ret+=ASN1_object_size(1,v,mtag); \ } @@ -262,20 +450,48 @@ err:\ } #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ - V_ASN1_UNIVERSAL) -#define M_ASN1_I2D_put_IMP_set(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ - V_ASN1_CONTEXT_SPECIFIC) - -#define M_ASN1_I2D_put_SEQ(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ - V_ASN1_UNIVERSAL) + V_ASN1_UNIVERSAL,IS_SET) +#define M_ASN1_I2D_put_SET_type(type,a,f) \ + i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET) +#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ + V_ASN1_CONTEXT_SPECIFIC,IS_SET) +#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ + i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) +#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ + V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE) + +#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ + V_ASN1_UNIVERSAL,IS_SEQUENCE) + +#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \ + i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ + IS_SEQUENCE) + +#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + M_ASN1_I2D_put_SEQUENCE(a,f); -#define M_ASN1_I2D_put_SEQ_opt(a,f) \ +#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \ if ((a != NULL) && (sk_num(a) != 0)) \ - M_ASN1_I2D_put_SEQ(a,f); + { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SET); } + +#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ + V_ASN1_CONTEXT_SPECIFIC, \ + IS_SET); } -#define M_ASN1_I2D_put_IMP_set_opt(a,f,x) \ +#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \ if ((a != NULL) && (sk_num(a) != 0)) \ - { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC); } + { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); } + +#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ + V_ASN1_CONTEXT_SPECIFIC, \ + IS_SEQUENCE); } #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ if (a != NULL) \ @@ -284,11 +500,26 @@ err:\ f(a,&p); \ } -#define M_ASN1_I2D_put_EXP_set_opt(a,f,mtag,tag,v) \ +#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \ if ((a != NULL) && (sk_num(a) != 0)) \ { \ ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ - i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL); \ + i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ + } + +#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_num(a) != 0)) \ + { \ + ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ + i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \ + } + +#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ + if ((a != NULL) && (sk_##type##_num(a) != 0)) \ + { \ + ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ + i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \ + IS_SEQUENCE); \ } #define M_ASN1_I2D_seq_total() \ @@ -306,14 +537,8 @@ err:\ #define M_ASN1_I2D_finish() *pp=p; \ return(r); -#ifndef NOPROTO int asn1_GetSequence(ASN1_CTX *c, long *length); void asn1_add_error(unsigned char *address,int offset); -#else -int asn1_GetSequence(); -void asn1_add_error(); -#endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c index 3906227d21..86886606ef 100644 --- a/src/lib/libcrypto/asn1/asn1_par.c +++ b/src/lib/libcrypto/asn1/asn1_par.c @@ -58,30 +58,21 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include -#ifndef NOPROTO static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, int indent); static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset, int depth, int indent); -#else -static int asn1_print_info(); -static int asn1_parse2(); -#endif - -static int asn1_print_info(bp, tag, xclass, constructed,indent) -BIO *bp; -int tag; -int xclass; -int constructed; -int indent; +static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, + int indent) { - static char *fmt="%-18s"; - static char *fmt2="%2d %-15s"; - char *p,str[128],*p2=NULL; + static const char fmt[]="%-18s"; + static const char fmt2[]="%2d %-15s"; + char str[128]; + const char *p,*p2=NULL; if (constructed & V_ASN1_CONSTRUCTED) p="cons: "; @@ -108,6 +99,8 @@ int indent; p="BOOLEAN"; else if (tag == V_ASN1_INTEGER) p="INTEGER"; + else if (tag == V_ASN1_ENUMERATED) + p="ENUMERATED"; else if (tag == V_ASN1_BIT_STRING) p="BIT STRING"; else if (tag == V_ASN1_OCTET_STRING) @@ -138,8 +131,8 @@ int indent; p="GENERALIZEDTIME"; else if (tag == V_ASN1_GRAPHICSTRING) p="GRAPHICSTRING"; - else if (tag == V_ASN1_ISO64STRING) - p="ISO64STRING"; + else if (tag == V_ASN1_VISIBLESTRING) + p="VISIBLESTRING"; else if (tag == V_ASN1_GENERALSTRING) p="GENERALSTRING"; else if (tag == V_ASN1_UNIVERSALSTRING) @@ -162,22 +155,13 @@ err: return(0); } -int ASN1_parse(bp, pp, len, indent) -BIO *bp; -unsigned char *pp; -long len; -int indent; +int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent) { return(asn1_parse2(bp,&pp,len,0,0,indent)); } -static int asn1_parse2(bp, pp, length, offset, depth, indent) -BIO *bp; -unsigned char **pp; -long length; -int offset; -int depth; -int indent; +static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset, + int depth, int indent) { unsigned char *p,*ep,*tot,*op,*opp; long len; @@ -266,7 +250,9 @@ int indent; if ( (tag == V_ASN1_PRINTABLESTRING) || (tag == V_ASN1_T61STRING) || (tag == V_ASN1_IA5STRING) || - (tag == V_ASN1_UTCTIME)) + (tag == V_ASN1_VISIBLESTRING) || + (tag == V_ASN1_UTCTIME) || + (tag == V_ASN1_GENERALIZEDTIME)) { if (BIO_write(bp,":",1) <= 0) goto end; if ((len > 0) && @@ -370,6 +356,38 @@ int indent; } ASN1_INTEGER_free(bs); } + else if (tag == V_ASN1_ENUMERATED) + { + ASN1_ENUMERATED *bs; + int i; + + opp=op; + bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); + if (bs != NULL) + { + if (BIO_write(bp,":",1) <= 0) goto end; + if (bs->type == V_ASN1_NEG_ENUMERATED) + if (BIO_write(bp,"-",1) <= 0) + goto end; + for (i=0; ilength; i++) + { + if (BIO_printf(bp,"%02X", + bs->data[i]) <= 0) + goto end; + } + if (bs->length == 0) + { + if (BIO_write(bp,"00",2) <= 0) + goto end; + } + } + else + { + if (BIO_write(bp,"BAD ENUMERATED",11) <= 0) + goto end; + } + ASN1_ENUMERATED_free(bs); + } if (!nl) { diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c new file mode 100644 index 0000000000..662a2626a1 --- /dev/null +++ b/src/lib/libcrypto/asn1/asn_pack.c @@ -0,0 +1,145 @@ +/* asn_pack.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include + +/* ASN1 packing and unpacking functions */ + +/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */ + +STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(), + void (*free_func)()) +{ + STACK *sk; + unsigned char *pbuf; + pbuf = buf; + if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func, + V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL))) + ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR); + return sk; +} + +/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a + * Malloc'ed buffer + */ + +unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf, + int *len) +{ + int safelen; + unsigned char *safe, *p; + if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE, + V_ASN1_UNIVERSAL, IS_SEQUENCE))) { + ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR); + return NULL; + } + if (!(safe = Malloc (safelen))) { + ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE); + return NULL; + } + p = safe; + i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, + IS_SEQUENCE); + if (len) *len = safelen; + if (buf) *buf = safe; + return safe; +} + +/* Extract an ASN1 object from an ASN1_STRING */ + +void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)()) +{ + unsigned char *p; + char *ret; + + p = oct->data; + if(!(ret = d2i(NULL, &p, oct->length))) + ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR); + return ret; +} + +/* Pack an ASN1 object into an ASN1_STRING */ + +ASN1_STRING *ASN1_pack_string (void *obj, int (*i2d)(), ASN1_STRING **oct) +{ + unsigned char *p; + ASN1_STRING *octmp; + + if (!oct || !*oct) { + if (!(octmp = ASN1_STRING_new ())) { + ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); + return NULL; + } + if (oct) *oct = octmp; + } else octmp = *oct; + + if (!(octmp->length = i2d(obj, NULL))) { + ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR); + return NULL; + } + if (!(p = Malloc (octmp->length))) { + ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); + return NULL; + } + octmp->data = p; + i2d (obj, &p); + return octmp; +} + diff --git a/src/lib/libcrypto/asn1/d2i_dhp.c b/src/lib/libcrypto/asn1/d2i_dhp.c index 616a308100..a077211a4c 100644 --- a/src/lib/libcrypto/asn1/d2i_dhp.c +++ b/src/lib/libcrypto/asn1/d2i_dhp.c @@ -56,24 +56,17 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DH #include #include "cryptlib.h" -#include "bn.h" -#include "dh.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_DHPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ - -DH *d2i_DHparams(a,pp,length) -DH **a; -unsigned char **pp; -long length; +DH *d2i_DHparams(DH **a, unsigned char **pp, long length) { - int i=ASN1_R_ERROR_STACK; + int i=ERR_R_NESTED_ASN1_ERROR; ASN1_INTEGER *bs=NULL; long v=0; M_ASN1_D2I_vars(a,DH *,DH_new); @@ -105,4 +98,4 @@ err: if (bs != NULL) ASN1_BIT_STRING_free(bs); return(NULL); } - +#endif diff --git a/src/lib/libcrypto/asn1/d2i_dsap.c b/src/lib/libcrypto/asn1/d2i_dsap.c index 2c8ac7bbcf..cdd7136f51 100644 --- a/src/lib/libcrypto/asn1/d2i_dsap.c +++ b/src/lib/libcrypto/asn1/d2i_dsap.c @@ -56,24 +56,21 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DSA #include #include "cryptlib.h" -#include "bn.h" -#include "dsa.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_DSAPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ +#ifdef NEG_PUBKEY_BUG +#define d2i_ASN1_INTEGER d2i_ASN1_UINTEGER +#endif -DSA *d2i_DSAparams(a,pp,length) -DSA **a; -unsigned char **pp; -long length; +DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length) { - int i=ASN1_R_ERROR_STACK; + int i=ERR_R_NESTED_ASN1_ERROR; ASN1_INTEGER *bs=NULL; M_ASN1_D2I_vars(a,DSA *,DSA_new); @@ -98,4 +95,4 @@ err: if (bs != NULL) ASN1_BIT_STRING_free(bs); return(NULL); } - +#endif diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c index b9eaa9629b..f3d1aa6240 100644 --- a/src/lib/libcrypto/asn1/d2i_pr.c +++ b/src/lib/libcrypto/asn1/d2i_pr.c @@ -58,16 +58,13 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include +#include -EVP_PKEY *d2i_PrivateKey(type,a,pp,length) -int type; -EVP_PKEY **a; -unsigned char **pp; -long length; +EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp, + long length) { EVP_PKEY *ret; @@ -106,7 +103,7 @@ long length; default: ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); goto err; - break; + /* break; */ } if (a != NULL) (*a)=ret; return(ret); diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c index 5d6192f1e5..e0d203cef7 100644 --- a/src/lib/libcrypto/asn1/d2i_pu.c +++ b/src/lib/libcrypto/asn1/d2i_pu.c @@ -58,16 +58,13 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include +#include -EVP_PKEY *d2i_PublicKey(type,a,pp,length) -int type; -EVP_PKEY **a; -unsigned char **pp; -long length; +EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp, + long length) { EVP_PKEY *ret; @@ -106,7 +103,7 @@ long length; default: ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); goto err; - break; + /* break; */ } if (a != NULL) (*a)=ret; return(ret); diff --git a/src/lib/libcrypto/asn1/d2i_r_pr.c b/src/lib/libcrypto/asn1/d2i_r_pr.c index 0c53aa94bf..18f11b6f5e 100644 --- a/src/lib/libcrypto/asn1/d2i_r_pr.c +++ b/src/lib/libcrypto/asn1/d2i_r_pr.c @@ -56,18 +56,13 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RSA #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "objects.h" -#include "asn1_mac.h" - -/* - * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_PARSING); - */ +#include +#include +#include +#include static ASN1_METHOD method={ (int (*)()) i2d_RSAPrivateKey, @@ -75,15 +70,12 @@ static ASN1_METHOD method={ (char *(*)())RSA_new, (void (*)()) RSA_free}; -ASN1_METHOD *RSAPrivateKey_asn1_meth() +ASN1_METHOD *RSAPrivateKey_asn1_meth(void) { return(&method); } -RSA *d2i_RSAPrivateKey(a,pp,length) -RSA **a; -unsigned char **pp; -long length; +RSA *d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length) { int i=ASN1_R_PARSING; ASN1_INTEGER *bs=NULL; @@ -126,4 +118,4 @@ err: if (bs != NULL) ASN1_INTEGER_free(bs); return(NULL); } - +#endif diff --git a/src/lib/libcrypto/asn1/d2i_r_pu.c b/src/lib/libcrypto/asn1/d2i_r_pu.c index 778b792b1e..c4ae58b594 100644 --- a/src/lib/libcrypto/asn1/d2i_r_pu.c +++ b/src/lib/libcrypto/asn1/d2i_r_pu.c @@ -56,22 +56,19 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RSA #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ +#ifdef NEG_PUBKEY_BUG +#define d2i_ASN1_INTEGER d2i_ASN1_UINTEGER +#endif -RSA *d2i_RSAPublicKey(a,pp,length) -RSA **a; -unsigned char **pp; -long length; +RSA *d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length) { int i=ASN1_R_PARSING; ASN1_INTEGER *bs=NULL; @@ -97,4 +94,4 @@ err: if (bs != NULL) ASN1_INTEGER_free(bs); return(NULL); } - +#endif diff --git a/src/lib/libcrypto/asn1/d2i_s_pr.c b/src/lib/libcrypto/asn1/d2i_s_pr.c index 32ff8ba4b3..050e1cc5fb 100644 --- a/src/lib/libcrypto/asn1/d2i_s_pr.c +++ b/src/lib/libcrypto/asn1/d2i_s_pr.c @@ -56,25 +56,17 @@ * [including the GNU Public Licence.] */ -/* Origional version from Steven Schoch */ +/* Original version from Steven Schoch */ +#ifndef NO_DSA #include #include "cryptlib.h" -#include "bn.h" -#include "dsa.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_PARSING); - */ - -DSA *d2i_DSAPrivateKey(a,pp,length) -DSA **a; -unsigned char **pp; -long length; +DSA *d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length) { int i=ASN1_R_PARSING; ASN1_INTEGER *bs=NULL; @@ -110,4 +102,4 @@ err: if (bs != NULL) ASN1_INTEGER_free(bs); return(NULL); } - +#endif diff --git a/src/lib/libcrypto/asn1/d2i_s_pu.c b/src/lib/libcrypto/asn1/d2i_s_pu.c index 1002f41cd8..94ea1c313b 100644 --- a/src/lib/libcrypto/asn1/d2i_s_pu.c +++ b/src/lib/libcrypto/asn1/d2i_s_pu.c @@ -56,24 +56,21 @@ * [including the GNU Public Licence.] */ -/* Origional version from Steven Schoch */ +/* Original version from Steven Schoch */ +#ifndef NO_DSA #include #include "cryptlib.h" -#include "bn.h" -#include "dsa.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_DSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ +#ifdef NEG_PUBKEY_BUG +#define d2i_ASN1_INTEGER d2i_ASN1_UINTEGER +#endif -DSA *d2i_DSAPublicKey(a,pp,length) -DSA **a; -unsigned char **pp; -long length; +DSA *d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length) { int i=ASN1_R_PARSING; ASN1_INTEGER *bs=NULL; @@ -121,4 +118,4 @@ err: if (bs != NULL) ASN1_INTEGER_free(bs); return(NULL); } - +#endif diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c index ebe34a3362..41ced49c19 100644 --- a/src/lib/libcrypto/asn1/evp_asn1.c +++ b/src/lib/libcrypto/asn1/evp_asn1.c @@ -58,26 +58,22 @@ #include #include "cryptlib.h" -#include "asn1.h" -#include "asn1_mac.h" +#include +#include -int ASN1_TYPE_set_octetstring(a,data,len) -ASN1_TYPE *a; -unsigned char *data; -int len; +int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) { ASN1_STRING *os; if ((os=ASN1_OCTET_STRING_new()) == NULL) return(0); if (!ASN1_OCTET_STRING_set(os,data,len)) return(0); - ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,(char *)os); + ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); return(1); } -int ASN1_TYPE_get_octetstring(a,data,max_len) -ASN1_TYPE *a; -unsigned char *data; -int max_len; /* for returned value */ +/* int max_len: for returned value */ +int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, + int max_len) { int ret,num; unsigned char *p; @@ -97,11 +93,8 @@ int max_len; /* for returned value */ return(ret); } -int ASN1_TYPE_set_int_octetstring(a,num,data,len) -ASN1_TYPE *a; -long num; -unsigned char *data; -int len; +int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, + int len) { int n,size; ASN1_OCTET_STRING os,*osp; @@ -131,16 +124,15 @@ int len; i2d_ASN1_INTEGER(&in,&p); M_i2d_ASN1_OCTET_STRING(&os,&p); - ASN1_TYPE_set(a,V_ASN1_SEQUENCE,(char *)osp); + ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); return(1); } -/* we return the actual length... */ -int ASN1_TYPE_get_int_octetstring(a,num,data,max_len) -ASN1_TYPE *a; -long *num; -unsigned char *data; -int max_len; /* for returned value */ +/* we return the actual length..., num may be missing, in which + * case, set it to zero */ +/* int max_len: for returned value */ +int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, + int max_len) { int ret= -1,n; ASN1_INTEGER *ai=NULL; diff --git a/src/lib/libcrypto/asn1/f.c b/src/lib/libcrypto/asn1/f.c index 2ab3a262ac..82bccdfd51 100644 --- a/src/lib/libcrypto/asn1/f.c +++ b/src/lib/libcrypto/asn1/f.c @@ -56,8 +56,8 @@ * [including the GNU Public Licence.] */ #include -#include "asn1.h" -#include "err.h" +#include +#include main() { diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c new file mode 100644 index 0000000000..3bcceecdb8 --- /dev/null +++ b/src/lib/libcrypto/asn1/f_enum.c @@ -0,0 +1,207 @@ +/* crypto/asn1/f_enum.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include +#include + +/* Based on a_int.c: equivalent ENUMERATED functions */ + +int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) + { + int i,n=0; + static const char *h="0123456789ABCDEF"; + char buf[2]; + + if (a == NULL) return(0); + + if (a->length == 0) + { + if (BIO_write(bp,"00",2) != 2) goto err; + n=2; + } + else + { + for (i=0; ilength; i++) + { + if ((i != 0) && (i%35 == 0)) + { + if (BIO_write(bp,"\\\n",2) != 2) goto err; + n+=2; + } + buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; + buf[1]=h[((unsigned char)a->data[i] )&0x0f]; + if (BIO_write(bp,buf,2) != 2) goto err; + n+=2; + } + } + return(n); +err: + return(-1); + } + +int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) + { + int ret=0; + int i,j,k,m,n,again,bufsize; + unsigned char *s=NULL,*sp; + unsigned char *bufp; + int num=0,slen=0,first=1; + + bs->type=V_ASN1_ENUMERATED; + + bufsize=BIO_gets(bp,buf,size); + for (;;) + { + if (bufsize < 1) goto err_sl; + i=bufsize; + if (buf[i-1] == '\n') buf[--i]='\0'; + if (i == 0) goto err_sl; + if (buf[i-1] == '\r') buf[--i]='\0'; + if (i == 0) goto err_sl; + again=(buf[i-1] == '\\'); + + for (j=0; j= '0') && (buf[j] <= '9')) || + ((buf[j] >= 'a') && (buf[j] <= 'f')) || + ((buf[j] >= 'A') && (buf[j] <= 'F')))) + { + i=j; + break; + } + } + buf[i]='\0'; + /* We have now cleared all the crap off the end of the + * line */ + if (i < 2) goto err_sl; + + bufp=(unsigned char *)buf; + if (first) + { + first=0; + if ((bufp[0] == '0') && (buf[1] == '0')) + { + bufp+=2; + i-=2; + } + } + k=0; + i-=again; + if (i%2 != 0) + { + ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); + goto err; + } + i/=2; + if (num+i > slen) + { + if (s == NULL) + sp=(unsigned char *)Malloc( + (unsigned int)num+i*2); + else + sp=(unsigned char *)Realloc(s, + (unsigned int)num+i*2); + if (sp == NULL) + { + ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); + if (s != NULL) Free((char *)s); + goto err; + } + s=sp; + slen=num+i*2; + } + for (j=0; j= '0') && (m <= '9')) + m-='0'; + else if ((m >= 'a') && (m <= 'f')) + m=m-'a'+10; + else if ((m >= 'A') && (m <= 'F')) + m=m-'A'+10; + else + { + ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); + goto err; + } + s[num+j]<<=4; + s[num+j]|=m; + } + } + num+=i; + if (again) + bufsize=BIO_gets(bp,buf,size); + else + break; + } + bs->length=num; + bs->data=s; + ret=1; +err: + if (0) + { +err_sl: + ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); + } + return(ret); + } + diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c index 4817c45cb7..55560dd814 100644 --- a/src/lib/libcrypto/asn1/f_int.c +++ b/src/lib/libcrypto/asn1/f_int.c @@ -58,15 +58,13 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "x509.h" +#include +#include -int i2a_ASN1_INTEGER(bp, a) -BIO *bp; -ASN1_INTEGER *a; +int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) { int i,n=0; - static char *h="0123456789ABCDEF"; + static const char *h="0123456789ABCDEF"; char buf[2]; if (a == NULL) return(0); @@ -96,11 +94,7 @@ err: return(-1); } -int a2i_ASN1_INTEGER(bp,bs,buf,size) -BIO *bp; -ASN1_INTEGER *bs; -char *buf; -int size; +int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) { int ret=0; int i,j,k,m,n,again,bufsize; @@ -123,9 +117,18 @@ int size; for (j=0; j= '0') && (buf[j] <= '9')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) || ((buf[j] >= 'A') && (buf[j] <= 'F')))) +#else + /* This #ifdef is not strictly necessary, since + * the characters A...F a...f 0...9 are contiguous + * (yes, even in EBCDIC - but not the whole alphabet). + * Nevertheless, isxdigit() is faster. + */ + if (!isxdigit(buf[j])) +#endif { i=j; break; diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c index ab2837824e..5d0cf5a46d 100644 --- a/src/lib/libcrypto/asn1/f_string.c +++ b/src/lib/libcrypto/asn1/f_string.c @@ -58,16 +58,13 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "x509.h" +#include +#include -int i2a_ASN1_STRING(bp, a, type) -BIO *bp; -ASN1_STRING *a; -int type; +int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) { int i,n=0; - static char *h="0123456789ABCDEF"; + static const char *h="0123456789ABCDEF"; char buf[2]; if (a == NULL) return(0); @@ -97,11 +94,7 @@ err: return(-1); } -int a2i_ASN1_STRING(bp,bs,buf,size) -BIO *bp; -ASN1_STRING *bs; -char *buf; -int size; +int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) { int ret=0; int i,j,k,m,n,again,bufsize; @@ -130,9 +123,18 @@ int size; for (j=i-1; j>0; j--) { +#ifndef CHARSET_EBCDIC if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || ((buf[j] >= 'a') && (buf[j] <= 'f')) || ((buf[j] >= 'A') && (buf[j] <= 'F')))) +#else + /* This #ifdef is not strictly necessary, since + * the characters A...F a...f 0...9 are contiguous + * (yes, even in EBCDIC - but not the whole alphabet). + * Nevertheless, isxdigit() is faster. + */ + if (!isxdigit(buf[j])) +#endif { i=j; break; diff --git a/src/lib/libcrypto/asn1/i2d_dhp.c b/src/lib/libcrypto/asn1/i2d_dhp.c index a454025ce3..fdda4ec41b 100644 --- a/src/lib/libcrypto/asn1/i2d_dhp.c +++ b/src/lib/libcrypto/asn1/i2d_dhp.c @@ -56,20 +56,14 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DH #include #include "cryptlib.h" -#include "bn.h" -#include "asn1_mac.h" -#include "dh.h" +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_DHPARAMS_NEW,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_DHparams(a,pp) -DH *a; -unsigned char **pp; +int i2d_DHparams(DH *a, unsigned char **pp) { BIGNUM *num[3]; ASN1_INTEGER bs; @@ -100,7 +94,12 @@ unsigned char **pp; } t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); - if (pp == NULL) return(t); + if (pp == NULL) + { + if (num[2] != NULL) + BN_free(num[2]); + return(t); + } p= *pp; ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); @@ -126,3 +125,4 @@ err: *pp=p; return(ret); } +#endif diff --git a/src/lib/libcrypto/asn1/i2d_dsap.c b/src/lib/libcrypto/asn1/i2d_dsap.c index 94ecff1525..f36f0da4e2 100644 --- a/src/lib/libcrypto/asn1/i2d_dsap.c +++ b/src/lib/libcrypto/asn1/i2d_dsap.c @@ -56,19 +56,14 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DSA #include #include "cryptlib.h" -#include "bn.h" -#include "asn1_mac.h" -#include "dsa.h" +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_DSAparams(a,pp) -DSA *a; -unsigned char **pp; +int i2d_DSAparams(DSA *a, unsigned char **pp) { BIGNUM *num[3]; ASN1_INTEGER bs; @@ -118,4 +113,5 @@ err: *pp=p; return(ret); } +#endif diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c index b6b821d73c..71d6910204 100644 --- a/src/lib/libcrypto/asn1/i2d_pr.c +++ b/src/lib/libcrypto/asn1/i2d_pr.c @@ -58,13 +58,11 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "evp.h" -#include "objects.h" +#include +#include +#include -int i2d_PrivateKey(a,pp) -EVP_PKEY *a; -unsigned char **pp; +int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) { #ifndef NO_RSA if (a->type == EVP_PKEY_RSA) diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c index 1b854252b7..8f73d37d03 100644 --- a/src/lib/libcrypto/asn1/i2d_pu.c +++ b/src/lib/libcrypto/asn1/i2d_pu.c @@ -58,13 +58,11 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "evp.h" -#include "objects.h" +#include +#include +#include -int i2d_PublicKey(a,pp) -EVP_PKEY *a; -unsigned char **pp; +int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) { switch (a->type) { diff --git a/src/lib/libcrypto/asn1/i2d_r_pr.c b/src/lib/libcrypto/asn1/i2d_r_pr.c index aadbb92d8e..27e6844a7f 100644 --- a/src/lib/libcrypto/asn1/i2d_r_pr.c +++ b/src/lib/libcrypto/asn1/i2d_r_pr.c @@ -56,21 +56,15 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RSA #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ - -int i2d_RSAPrivateKey(a,pp) -RSA *a; -unsigned char **pp; +int i2d_RSAPrivateKey(RSA *a, unsigned char **pp) { BIGNUM *num[9]; unsigned char data[1]; @@ -129,4 +123,5 @@ unsigned char **pp; *pp=p; return(t); } +#endif diff --git a/src/lib/libcrypto/asn1/i2d_r_pu.c b/src/lib/libcrypto/asn1/i2d_r_pu.c index 3c54f6709d..6d01bfa8b5 100644 --- a/src/lib/libcrypto/asn1/i2d_r_pu.c +++ b/src/lib/libcrypto/asn1/i2d_r_pu.c @@ -56,21 +56,15 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RSA #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ - -int i2d_RSAPublicKey(a,pp) -RSA *a; -unsigned char **pp; +int i2d_RSAPublicKey(RSA *a, unsigned char **pp) { BIGNUM *num[2]; ASN1_INTEGER bs; @@ -115,4 +109,4 @@ unsigned char **pp; *pp=p; return(t); } - +#endif diff --git a/src/lib/libcrypto/asn1/i2d_s_pr.c b/src/lib/libcrypto/asn1/i2d_s_pr.c index 6e95305548..5d3dcdf197 100644 --- a/src/lib/libcrypto/asn1/i2d_s_pr.c +++ b/src/lib/libcrypto/asn1/i2d_s_pr.c @@ -56,20 +56,15 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DSA #include #include "cryptlib.h" -#include "bn.h" -#include "dsa.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ - -int i2d_DSAPrivateKey(a,pp) -DSA *a; -unsigned char **pp; +int i2d_DSAPrivateKey(DSA *a, unsigned char **pp) { BIGNUM *num[6]; unsigned char data[1]; @@ -125,4 +120,4 @@ unsigned char **pp; *pp=p; return(t); } - +#endif diff --git a/src/lib/libcrypto/asn1/i2d_s_pu.c b/src/lib/libcrypto/asn1/i2d_s_pu.c index 5cf2877069..18f790f746 100644 --- a/src/lib/libcrypto/asn1/i2d_s_pu.c +++ b/src/lib/libcrypto/asn1/i2d_s_pu.c @@ -56,20 +56,15 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DSA #include #include "cryptlib.h" -#include "bn.h" -#include "dsa.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include +#include -/* - * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ - -int i2d_DSAPublicKey(a,pp) -DSA *a; -unsigned char **pp; +int i2d_DSAPublicKey(DSA *a, unsigned char **pp) { BIGNUM *num[4]; ASN1_INTEGER bs; @@ -128,6 +123,7 @@ unsigned char **pp; } Free((char *)bs.data); *pp=p; - return(t); + if(all) return(t); + else return(tot); } - +#endif diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c index 5110c91bec..cdc0d8b7c4 100644 --- a/src/lib/libcrypto/asn1/n_pkey.c +++ b/src/lib/libcrypto/asn1/n_pkey.c @@ -56,13 +56,14 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RSA #include #include "cryptlib.h" -#include "rsa.h" -#include "objects.h" -#include "asn1_mac.h" -#include "evp.h" -#include "x509.h" +#include +#include +#include +#include +#include #ifndef NO_RC4 @@ -74,28 +75,12 @@ typedef struct netscape_pkey_st ASN1_OCTET_STRING *private_key; } NETSCAPE_PKEY; -/* - * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR); - * ASN1err(ASN1_F_D2I_NETSCAPE_PKEY,ASN1_R_DECODING_ERROR); - * ASN1err(ASN1_F_NETSCAPE_PKEY_NEW,ASN1_R_DECODING_ERROR); - */ -#ifndef NOPROTO static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp); static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a,unsigned char **pp, long length); static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void); static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *); -#else -static int i2d_NETSCAPE_PKEY(); -static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(); -static NETSCAPE_PKEY *NETSCAPE_PKEY_new(); -static void NETSCAPE_PKEY_free(); -#endif -int i2d_Netscape_RSA(a,pp,cb) -RSA *a; -unsigned char **pp; -int (*cb)(); +int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)()) { int i,j,l[6]; NETSCAPE_PKEY *pkey; @@ -138,7 +123,9 @@ int (*cb)(); l[2]=i2d_X509_ALGOR(alg,NULL); l[3]=ASN1_object_size(1,l[2]+l[1],V_ASN1_SEQUENCE); +#ifndef CONST_STRICT os.data=(unsigned char *)"private-key"; +#endif os.length=11; l[4]=i2d_ASN1_OCTET_STRING(&os,NULL); @@ -195,18 +182,14 @@ int (*cb)(); i2d_ASN1_OCTET_STRING(&os2,&p); ret=l[5]; err: - if (os2.data != NULL) Free((char *)os2.data); + if (os2.data != NULL) Free(os2.data); if (alg != NULL) X509_ALGOR_free(alg); if (pkey != NULL) NETSCAPE_PKEY_free(pkey); r=r; return(ret); } -RSA *d2i_Netscape_RSA(a,pp,length,cb) -RSA **a; -unsigned char **pp; -long length; -int (*cb)(); +RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)()) { RSA *ret=NULL; ASN1_OCTET_STRING *os=NULL; @@ -233,11 +216,8 @@ int (*cb)(); M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA); } -RSA *d2i_Netscape_RSA_2(a,pp,length,cb) -RSA **a; -unsigned char **pp; -long length; -int (*cb)(); +RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length, + int (*cb)()) { NETSCAPE_PKEY *pkey=NULL; RSA *ret=NULL; @@ -249,7 +229,7 @@ int (*cb)(); ASN1_OCTET_STRING *os=NULL; ASN1_CTX c; - c.error=ASN1_R_ERROR_STACK; + c.error=ERR_R_NESTED_ASN1_ERROR; c.pp=pp; M_ASN1_D2I_Init(); @@ -304,9 +284,7 @@ err: return(ret); } -static int i2d_NETSCAPE_PKEY(a,pp) -NETSCAPE_PKEY *a; -unsigned char **pp; +static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -324,10 +302,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(a,pp,length) -NETSCAPE_PKEY **a; -unsigned char **pp; -long length; +static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new); @@ -339,9 +315,10 @@ long length; M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY); } -static NETSCAPE_PKEY *NETSCAPE_PKEY_new() +static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void) { NETSCAPE_PKEY *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,NETSCAPE_PKEY); M_ASN1_New(ret->version,ASN1_INTEGER_new); @@ -351,8 +328,7 @@ static NETSCAPE_PKEY *NETSCAPE_PKEY_new() M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW); } -static void NETSCAPE_PKEY_free(a) -NETSCAPE_PKEY *a; +static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); @@ -362,4 +338,4 @@ NETSCAPE_PKEY *a; } #endif /* NO_RC4 */ - +#endif diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c new file mode 100644 index 0000000000..417d024b81 --- /dev/null +++ b/src/lib/libcrypto/asn1/nsseq.c @@ -0,0 +1,118 @@ +/* nsseq.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include +#include +#include +#include +#include + +/* Netscape certificate sequence structure */ + +int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp) +{ + int v = 0; + M_ASN1_I2D_vars(a); + M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT); + M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0, + V_ASN1_SEQUENCE,v); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT); + M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0, + V_ASN1_SEQUENCE,v); + + M_ASN1_I2D_finish(); +} + +NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void) +{ + NETSCAPE_CERT_SEQUENCE *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, NETSCAPE_CERT_SEQUENCE); + /* Note hardcoded object type */ + ret->type = OBJ_nid2obj(NID_netscape_cert_sequence); + ret->certs = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW); +} + +NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, + unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,NETSCAPE_CERT_SEQUENCE *, + NETSCAPE_CERT_SEQUENCE_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT); + M_ASN1_D2I_get_EXP_set_opt_type(X509,ret->certs,d2i_X509,X509_free,0, + V_ASN1_SEQUENCE); + M_ASN1_D2I_Finish(a, NETSCAPE_CERT_SEQUENCE_free, + ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE); +} + +void NETSCAPE_CERT_SEQUENCE_free (NETSCAPE_CERT_SEQUENCE *a) +{ + if (a == NULL) return; + ASN1_OBJECT_free(a->type); + if(a->certs) + sk_X509_pop_free(a->certs, X509_free); + Free (a); +} diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c new file mode 100644 index 0000000000..b831836e7b --- /dev/null +++ b/src/lib/libcrypto/asn1/p5_pbe.c @@ -0,0 +1,156 @@ +/* p5_pbe.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include +#include + +/* PKCS#5 password based encryption structure */ + +int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + M_ASN1_I2D_len (a->salt, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER); + + M_ASN1_I2D_seq_total (); + + M_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER); + M_ASN1_I2D_finish(); +} + +PBEPARAM *PBEPARAM_new(void) +{ + PBEPARAM *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PBEPARAM); + M_ASN1_New(ret->iter,ASN1_INTEGER_new); + M_ASN1_New(ret->salt,ASN1_OCTET_STRING_new); + return (ret); + M_ASN1_New_Error(ASN1_F_PBEPARAM_NEW); +} + +PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,PBEPARAM *,PBEPARAM_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->salt, d2i_ASN1_OCTET_STRING); + M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER); + M_ASN1_D2I_Finish(a, PBEPARAM_free, ASN1_F_D2I_PBEPARAM); +} + +void PBEPARAM_free (PBEPARAM *a) +{ + if(a==NULL) return; + ASN1_OCTET_STRING_free(a->salt); + ASN1_INTEGER_free (a->iter); + Free ((char *)a); +} + +/* Return an algorithm identifier for a PKCS#5 PBE algorithm */ + +X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, + int saltlen) +{ + PBEPARAM *pbe; + ASN1_OBJECT *al; + X509_ALGOR *algor; + ASN1_TYPE *astype; + + if (!(pbe = PBEPARAM_new ())) { + ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); + return NULL; + } + if(iter <= 0) iter = PKCS5_DEFAULT_ITER; + ASN1_INTEGER_set (pbe->iter, iter); + if (!saltlen) saltlen = PKCS5_SALT_LEN; + if (!(pbe->salt->data = Malloc (saltlen))) { + ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); + return NULL; + } + pbe->salt->length = saltlen; + if (salt) memcpy (pbe->salt->data, salt, saltlen); + else RAND_bytes (pbe->salt->data, saltlen); + + if (!(astype = ASN1_TYPE_new())) { + ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); + return NULL; + } + + astype->type = V_ASN1_SEQUENCE; + if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) { + ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); + return NULL; + } + PBEPARAM_free (pbe); + + al = OBJ_nid2obj(alg); /* never need to free al */ + if (!(algor = X509_ALGOR_new())) { + ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); + return NULL; + } + ASN1_OBJECT_free(algor->algorithm); + algor->algorithm = al; + algor->parameter = astype; + + return (algor); +} diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c new file mode 100644 index 0000000000..09f4bf6112 --- /dev/null +++ b/src/lib/libcrypto/asn1/p5_pbev2.c @@ -0,0 +1,274 @@ +/* p5_pbev2.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include +#include + +/* PKCS#5 v2.0 password based encryption structures */ + +int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + M_ASN1_I2D_len (a->keyfunc, i2d_X509_ALGOR); + M_ASN1_I2D_len (a->encryption, i2d_X509_ALGOR); + + M_ASN1_I2D_seq_total (); + + M_ASN1_I2D_put (a->keyfunc, i2d_X509_ALGOR); + M_ASN1_I2D_put (a->encryption, i2d_X509_ALGOR); + + M_ASN1_I2D_finish(); +} + +PBE2PARAM *PBE2PARAM_new(void) +{ + PBE2PARAM *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PBE2PARAM); + M_ASN1_New(ret->keyfunc,X509_ALGOR_new); + M_ASN1_New(ret->encryption,X509_ALGOR_new); + return (ret); + M_ASN1_New_Error(ASN1_F_PBE2PARAM_NEW); +} + +PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,PBE2PARAM *,PBE2PARAM_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->keyfunc, d2i_X509_ALGOR); + M_ASN1_D2I_get (ret->encryption, d2i_X509_ALGOR); + M_ASN1_D2I_Finish(a, PBE2PARAM_free, ASN1_F_D2I_PBE2PARAM); +} + +void PBE2PARAM_free (PBE2PARAM *a) +{ + if(a==NULL) return; + X509_ALGOR_free(a->keyfunc); + X509_ALGOR_free(a->encryption); + Free ((char *)a); +} + +int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + M_ASN1_I2D_len (a->salt, i2d_ASN1_TYPE); + M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER); + M_ASN1_I2D_len (a->keylength, i2d_ASN1_INTEGER); + M_ASN1_I2D_len (a->prf, i2d_X509_ALGOR); + + M_ASN1_I2D_seq_total (); + + M_ASN1_I2D_put (a->salt, i2d_ASN1_TYPE); + M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER); + M_ASN1_I2D_put (a->keylength, i2d_ASN1_INTEGER); + M_ASN1_I2D_put (a->prf, i2d_X509_ALGOR); + + M_ASN1_I2D_finish(); +} + +PBKDF2PARAM *PBKDF2PARAM_new(void) +{ + PBKDF2PARAM *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PBKDF2PARAM); + M_ASN1_New(ret->salt, ASN1_TYPE_new); + M_ASN1_New(ret->iter, ASN1_INTEGER_new); + ret->keylength = NULL; + ret->prf = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_PBKDF2PARAM_NEW); +} + +PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, + long length) +{ + M_ASN1_D2I_vars(a,PBKDF2PARAM *,PBKDF2PARAM_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->salt, d2i_ASN1_TYPE); + M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER); + M_ASN1_D2I_get_opt (ret->keylength, d2i_ASN1_INTEGER, V_ASN1_INTEGER); + M_ASN1_D2I_get_opt (ret->prf, d2i_X509_ALGOR, V_ASN1_SEQUENCE); + M_ASN1_D2I_Finish(a, PBKDF2PARAM_free, ASN1_F_D2I_PBKDF2PARAM); +} + +void PBKDF2PARAM_free (PBKDF2PARAM *a) +{ + if(a==NULL) return; + ASN1_TYPE_free(a->salt); + ASN1_INTEGER_free(a->iter); + ASN1_INTEGER_free(a->keylength); + X509_ALGOR_free(a->prf); + Free ((char *)a); +} + +/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm: + * yes I know this is horrible! + */ + +X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, + unsigned char *salt, int saltlen) +{ + X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL; + int alg_nid; + EVP_CIPHER_CTX ctx; + unsigned char iv[EVP_MAX_IV_LENGTH]; + PBKDF2PARAM *kdf = NULL; + PBE2PARAM *pbe2 = NULL; + ASN1_OCTET_STRING *osalt = NULL; + + if(!(pbe2 = PBE2PARAM_new())) goto merr; + + /* Setup the AlgorithmIdentifier for the encryption scheme */ + scheme = pbe2->encryption; + + alg_nid = EVP_CIPHER_type(cipher); + + scheme->algorithm = OBJ_nid2obj(alg_nid); + if(!(scheme->parameter = ASN1_TYPE_new())) goto merr; + + /* Create random IV */ + RAND_bytes(iv, EVP_CIPHER_iv_length(cipher)); + + /* Dummy cipherinit to just setup the IV */ + EVP_CipherInit(&ctx, cipher, NULL, iv, 0); + if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) { + ASN1err(ASN1_F_PKCS5_PBE2_SET, + ASN1_R_ERROR_SETTING_CIPHER_PARAMS); + goto err; + } + EVP_CIPHER_CTX_cleanup(&ctx); + + if(!(kdf = PBKDF2PARAM_new())) goto merr; + if(!(osalt = ASN1_OCTET_STRING_new())) goto merr; + + if (!saltlen) saltlen = PKCS5_SALT_LEN; + if (!(osalt->data = Malloc (saltlen))) goto merr; + osalt->length = saltlen; + if (salt) memcpy (osalt->data, salt, saltlen); + else RAND_bytes (osalt->data, saltlen); + + if(iter <= 0) iter = PKCS5_DEFAULT_ITER; + if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr; + + /* Now include salt in kdf structure */ + kdf->salt->value.octet_string = osalt; + kdf->salt->type = V_ASN1_OCTET_STRING; + osalt = NULL; + + /* If its RC2 then we'd better setup the key length */ + + if(alg_nid == NID_rc2_cbc) { + if(!(kdf->keylength = ASN1_INTEGER_new())) goto merr; + if(!ASN1_INTEGER_set (kdf->keylength, + EVP_CIPHER_key_length(cipher))) goto merr; + } + + /* prf can stay NULL because we are using hmacWithSHA1 */ + + /* Now setup the PBE2PARAM keyfunc structure */ + + pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2); + + /* Encode PBKDF2PARAM into parameter of pbe2 */ + + if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr; + + if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM, + &pbe2->keyfunc->parameter->value.sequence)) goto merr; + pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE; + + PBKDF2PARAM_free(kdf); + kdf = NULL; + + /* Now set up top level AlgorithmIdentifier */ + + if(!(ret = X509_ALGOR_new())) goto merr; + if(!(ret->parameter = ASN1_TYPE_new())) goto merr; + + ret->algorithm = OBJ_nid2obj(NID_pbes2); + + /* Encode PBE2PARAM into parameter */ + + if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM, + &ret->parameter->value.sequence)) goto merr; + ret->parameter->type = V_ASN1_SEQUENCE; + + PBE2PARAM_free(pbe2); + pbe2 = NULL; + + return ret; + + merr: + ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE); + + err: + PBE2PARAM_free(pbe2); + /* Note 'scheme' is freed as part of pbe2 */ + ASN1_OCTET_STRING_free(osalt); + PBKDF2PARAM_free(kdf); + X509_ALGOR_free(kalg); + X509_ALGOR_free(ret); + + return NULL; + +} diff --git a/src/lib/libcrypto/asn1/p7_dgst.c b/src/lib/libcrypto/asn1/p7_dgst.c index f71ed8eb1d..62783a2b8d 100644 --- a/src/lib/libcrypto/asn1/p7_dgst.c +++ b/src/lib/libcrypto/asn1/p7_dgst.c @@ -58,17 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_DIGEST_NEW,ASN1_R_MISSING_EOS); - * ASN1err(ASN1_F_D2I_PKCS7_DIGEST,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_DIGEST(a,pp) -PKCS7_DIGEST *a; -unsigned char **pp; +int i2d_PKCS7_DIGEST(PKCS7_DIGEST *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -87,10 +80,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -PKCS7_DIGEST *d2i_PKCS7_DIGEST(a,pp,length) -PKCS7_DIGEST **a; -unsigned char **pp; -long length; +PKCS7_DIGEST *d2i_PKCS7_DIGEST(PKCS7_DIGEST **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,PKCS7_DIGEST *,PKCS7_DIGEST_new); @@ -104,9 +95,10 @@ long length; M_ASN1_D2I_Finish(a,PKCS7_DIGEST_free,ASN1_F_D2I_PKCS7_DIGEST); } -PKCS7_DIGEST *PKCS7_DIGEST_new() +PKCS7_DIGEST *PKCS7_DIGEST_new(void) { PKCS7_DIGEST *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_DIGEST); M_ASN1_New(ret->version,ASN1_INTEGER_new); @@ -117,8 +109,7 @@ PKCS7_DIGEST *PKCS7_DIGEST_new() M_ASN1_New_Error(ASN1_F_PKCS7_DIGEST_NEW); } -void PKCS7_DIGEST_free(a) -PKCS7_DIGEST *a; +void PKCS7_DIGEST_free(PKCS7_DIGEST *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); diff --git a/src/lib/libcrypto/asn1/p7_enc.c b/src/lib/libcrypto/asn1/p7_enc.c index 874dd78389..4741126587 100644 --- a/src/lib/libcrypto/asn1/p7_enc.c +++ b/src/lib/libcrypto/asn1/p7_enc.c @@ -58,17 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_ENCRYPT_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_ENCRYPT,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_ENCRYPT(a,pp) -PKCS7_ENCRYPT *a; -unsigned char **pp; +int i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -83,10 +76,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(a,pp,length) -PKCS7_ENCRYPT **a; -unsigned char **pp; -long length; +PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,PKCS7_ENCRYPT *,PKCS7_ENCRYPT_new); @@ -98,9 +89,10 @@ long length; M_ASN1_D2I_Finish(a,PKCS7_ENCRYPT_free,ASN1_F_D2I_PKCS7_ENCRYPT); } -PKCS7_ENCRYPT *PKCS7_ENCRYPT_new() +PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void) { PKCS7_ENCRYPT *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_ENCRYPT); M_ASN1_New(ret->version,ASN1_INTEGER_new); @@ -109,8 +101,7 @@ PKCS7_ENCRYPT *PKCS7_ENCRYPT_new() M_ASN1_New_Error(ASN1_F_PKCS7_ENCRYPT_NEW); } -void PKCS7_ENCRYPT_free(a) -PKCS7_ENCRYPT *a; +void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); diff --git a/src/lib/libcrypto/asn1/p7_enc_c.c b/src/lib/libcrypto/asn1/p7_enc_c.c index 2860d3e925..a832737a38 100644 --- a/src/lib/libcrypto/asn1/p7_enc_c.c +++ b/src/lib/libcrypto/asn1/p7_enc_c.c @@ -58,17 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_ENC_CONTENT_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_ENC_CONTENT,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_ENC_CONTENT(a,pp) -PKCS7_ENC_CONTENT *a; -unsigned char **pp; +int i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -85,10 +78,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(a,pp,length) -PKCS7_ENC_CONTENT **a; -unsigned char **pp; -long length; +PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT **a, + unsigned char **pp, long length) { M_ASN1_D2I_vars(a,PKCS7_ENC_CONTENT *,PKCS7_ENC_CONTENT_new); @@ -103,20 +94,21 @@ long length; ASN1_F_D2I_PKCS7_ENC_CONTENT); } -PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new() +PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(void) { PKCS7_ENC_CONTENT *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_ENC_CONTENT); - M_ASN1_New(ret->content_type,ASN1_OBJECT_new); + /* M_ASN1_New(ret->content_type,ASN1_OBJECT_new); */ + ret->content_type=OBJ_nid2obj(NID_pkcs7_encrypted); M_ASN1_New(ret->algorithm,X509_ALGOR_new); ret->enc_data=NULL; return(ret); M_ASN1_New_Error(ASN1_F_PKCS7_ENC_CONTENT_NEW); } -void PKCS7_ENC_CONTENT_free(a) -PKCS7_ENC_CONTENT *a; +void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a) { if (a == NULL) return; ASN1_OBJECT_free(a->content_type); diff --git a/src/lib/libcrypto/asn1/p7_evp.c b/src/lib/libcrypto/asn1/p7_evp.c index 4db0a7fe62..b2b3d50dcd 100644 --- a/src/lib/libcrypto/asn1/p7_evp.c +++ b/src/lib/libcrypto/asn1/p7_evp.c @@ -58,67 +58,61 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_ENVELOPE,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_ENVELOPE(a,pp) -PKCS7_ENVELOPE *a; -unsigned char **pp; +int i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE *a, unsigned char **pp) { M_ASN1_I2D_vars(a); M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); - M_ASN1_I2D_len_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); + M_ASN1_I2D_len_SET_type(PKCS7_RECIP_INFO,a->recipientinfo, + i2d_PKCS7_RECIP_INFO); M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); M_ASN1_I2D_seq_total(); M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); - M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); + M_ASN1_I2D_put_SET_type(PKCS7_RECIP_INFO,a->recipientinfo, + i2d_PKCS7_RECIP_INFO); M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); M_ASN1_I2D_finish(); } -PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(a,pp,length) -PKCS7_ENVELOPE **a; -unsigned char **pp; -long length; +PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,PKCS7_ENVELOPE *,PKCS7_ENVELOPE_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); - M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); + M_ASN1_D2I_get_set_type(PKCS7_RECIP_INFO,ret->recipientinfo, + d2i_PKCS7_RECIP_INFO,PKCS7_RECIP_INFO_free); M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); M_ASN1_D2I_Finish(a,PKCS7_ENVELOPE_free,ASN1_F_D2I_PKCS7_ENVELOPE); } -PKCS7_ENVELOPE *PKCS7_ENVELOPE_new() +PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void) { PKCS7_ENVELOPE *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_ENVELOPE); M_ASN1_New(ret->version,ASN1_INTEGER_new); - M_ASN1_New(ret->recipientinfo,sk_new_null); + M_ASN1_New(ret->recipientinfo,sk_PKCS7_RECIP_INFO_new_null); M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); return(ret); M_ASN1_New_Error(ASN1_F_PKCS7_ENVELOPE_NEW); } -void PKCS7_ENVELOPE_free(a) -PKCS7_ENVELOPE *a; +void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); - sk_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); + sk_PKCS7_RECIP_INFO_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); PKCS7_ENC_CONTENT_free(a->enc_data); Free((char *)a); } diff --git a/src/lib/libcrypto/asn1/p7_i_s.c b/src/lib/libcrypto/asn1/p7_i_s.c index 9b00c556d9..7d4b457e01 100644 --- a/src/lib/libcrypto/asn1/p7_i_s.c +++ b/src/lib/libcrypto/asn1/p7_i_s.c @@ -58,17 +58,11 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_ISSUER_AND_SERIAL(a,pp) -PKCS7_ISSUER_AND_SERIAL *a; -unsigned char **pp; +int i2d_PKCS7_ISSUER_AND_SERIAL(PKCS7_ISSUER_AND_SERIAL *a, + unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -83,10 +77,7 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(a,pp,length) -PKCS7_ISSUER_AND_SERIAL **a; -unsigned char **pp; -long length; +PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(PKCS7_ISSUER_AND_SERIAL **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,PKCS7_ISSUER_AND_SERIAL *,PKCS7_ISSUER_AND_SERIAL_new); @@ -98,9 +89,10 @@ long length; ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL); } -PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new() +PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void) { PKCS7_ISSUER_AND_SERIAL *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_ISSUER_AND_SERIAL); M_ASN1_New(ret->issuer,X509_NAME_new); @@ -109,8 +101,7 @@ PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new() M_ASN1_New_Error(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW); } -void PKCS7_ISSUER_AND_SERIAL_free(a) -PKCS7_ISSUER_AND_SERIAL *a; +void PKCS7_ISSUER_AND_SERIAL_free(PKCS7_ISSUER_AND_SERIAL *a) { if (a == NULL) return; X509_NAME_free(a->issuer); diff --git a/src/lib/libcrypto/asn1/p7_lib.c b/src/lib/libcrypto/asn1/p7_lib.c index 2134e0974a..846be17158 100644 --- a/src/lib/libcrypto/asn1/p7_lib.c +++ b/src/lib/libcrypto/asn1/p7_lib.c @@ -58,17 +58,11 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "objects.h" +#include +#include +#include -/* ASN1err(ASN1_F_D2I_PKCS7,ASN1_R_BAD_PKCS7_CONTENT); - * ASN1err(ASN1_F_I2D_PKCS7,ASN1_R_BAD_PKCS7_TYPE); - * ASN1err(ASN1_F_PKCS7_NEW,ASN1_R_BAD_PKCS7_TYPE); - */ - -int i2d_PKCS7(a,pp) -PKCS7 *a; -unsigned char **pp; +int i2d_PKCS7(PKCS7 *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -150,10 +144,7 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -PKCS7 *d2i_PKCS7(a,pp,length) -PKCS7 **a; -unsigned char **pp; -long length; +PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new); @@ -179,6 +170,7 @@ long length; V_ASN1_CONTEXT_SPECIFIC|0)) { c.error=ASN1_R_BAD_PKCS7_CONTENT; + c.line=__LINE__; goto err; } @@ -187,7 +179,7 @@ long length; c.q=c.p; Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass, (c.inf & 1)?(length+ *pp-c.q):c.slen); - if (Tinf & 0x80) goto err; + if (Tinf & 0x80) { c.line=__LINE__; goto err; } c.slen-=(c.p-c.q); switch (OBJ_obj2nid(ret->type)) @@ -215,14 +207,16 @@ long length; break; default: c.error=ASN1_R_BAD_PKCS7_TYPE; + c.line=__LINE__; goto err; - break; + /* break; */ } if (Tinf == (1|V_ASN1_CONSTRUCTED)) { if (!ASN1_check_infinite_end(&c.p,c.slen)) { - c.error=ASN1_R_MISSING_EOS; + c.error=ERR_R_MISSING_ASN1_EOS; + c.line=__LINE__; goto err; } } @@ -233,12 +227,13 @@ long length; M_ASN1_D2I_Finish(a,PKCS7_free,ASN1_F_D2I_PKCS7); } -PKCS7 *PKCS7_new() +PKCS7 *PKCS7_new(void) { PKCS7 *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7); - ret->type=ASN1_OBJECT_new(); + ret->type=OBJ_nid2obj(NID_undef); ret->asn1=NULL; ret->length=0; ret->detached=0; @@ -247,8 +242,7 @@ PKCS7 *PKCS7_new() M_ASN1_New_Error(ASN1_F_PKCS7_NEW); } -void PKCS7_free(a) -PKCS7 *a; +void PKCS7_free(PKCS7 *a) { if (a == NULL) return; @@ -260,9 +254,11 @@ PKCS7 *a; Free((char *)(char *)a); } -void PKCS7_content_free(a) -PKCS7 *a; +void PKCS7_content_free(PKCS7 *a) { + if(a == NULL) + return; + if (a->asn1 != NULL) Free((char *)a->asn1); if (a->d.ptr != NULL) diff --git a/src/lib/libcrypto/asn1/p7_recip.c b/src/lib/libcrypto/asn1/p7_recip.c index f02233f5a8..9fda4f20d4 100644 --- a/src/lib/libcrypto/asn1/p7_recip.c +++ b/src/lib/libcrypto/asn1/p7_recip.c @@ -58,17 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_RECIP_INFO_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_RECIP_INFO,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_RECIP_INFO(a,pp) -PKCS7_RECIP_INFO *a; -unsigned char **pp; +int i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -87,10 +80,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(a,pp,length) -PKCS7_RECIP_INFO **a; -unsigned char **pp; -long length; +PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO **a, + unsigned char **pp, long length) { M_ASN1_D2I_vars(a,PKCS7_RECIP_INFO *,PKCS7_RECIP_INFO_new); @@ -104,9 +95,10 @@ long length; M_ASN1_D2I_Finish(a,PKCS7_RECIP_INFO_free,ASN1_F_D2I_PKCS7_RECIP_INFO); } -PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new() +PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void) { PKCS7_RECIP_INFO *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_RECIP_INFO); M_ASN1_New(ret->version,ASN1_INTEGER_new); @@ -118,8 +110,7 @@ PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new() M_ASN1_New_Error(ASN1_F_PKCS7_RECIP_INFO_NEW); } -void PKCS7_RECIP_INFO_free(a) -PKCS7_RECIP_INFO *a; +void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); @@ -127,6 +118,8 @@ PKCS7_RECIP_INFO *a; X509_ALGOR_free(a->key_enc_algor); ASN1_OCTET_STRING_free(a->enc_key); if (a->cert != NULL) X509_free(a->cert); - Free((char *)a); + Free(a); } +IMPLEMENT_STACK_OF(PKCS7_RECIP_INFO) +IMPLEMENT_ASN1_SET_OF(PKCS7_RECIP_INFO) diff --git a/src/lib/libcrypto/asn1/p7_s_e.c b/src/lib/libcrypto/asn1/p7_s_e.c index d344211456..90946695c9 100644 --- a/src/lib/libcrypto/asn1/p7_s_e.c +++ b/src/lib/libcrypto/asn1/p7_s_e.c @@ -58,89 +58,88 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_SIGN_ENVELOPE(a,pp) -PKCS7_SIGN_ENVELOPE *a; -unsigned char **pp; +int i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE *a, unsigned char **pp) { M_ASN1_I2D_vars(a); M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); - M_ASN1_I2D_len_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); - M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); + M_ASN1_I2D_len_SET_type(PKCS7_RECIP_INFO,a->recipientinfo, + i2d_PKCS7_RECIP_INFO); + M_ASN1_I2D_len_SET_type(X509_ALGOR,a->md_algs,i2d_X509_ALGOR); M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); - M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); - M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); - M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); + M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(X509,a->cert,i2d_X509,0); + M_ASN1_I2D_len_IMP_SET_opt_type(X509_CRL,a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_len_SET_type(PKCS7_SIGNER_INFO,a->signer_info, + i2d_PKCS7_SIGNER_INFO); M_ASN1_I2D_seq_total(); M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); - M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); - M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); + M_ASN1_I2D_put_SET_type(PKCS7_RECIP_INFO,a->recipientinfo, + i2d_PKCS7_RECIP_INFO); + M_ASN1_I2D_put_SET_type(X509_ALGOR,a->md_algs,i2d_X509_ALGOR); M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); - M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); - M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); - M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); + M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(X509,a->cert,i2d_X509,0); + M_ASN1_I2D_put_IMP_SET_opt_type(X509_CRL,a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_put_SET_type(PKCS7_SIGNER_INFO,a->signer_info, + i2d_PKCS7_SIGNER_INFO); M_ASN1_I2D_finish(); } -PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(a,pp,length) -PKCS7_SIGN_ENVELOPE **a; -unsigned char **pp; -long length; +PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE **a, + unsigned char **pp, long length) { M_ASN1_D2I_vars(a,PKCS7_SIGN_ENVELOPE *,PKCS7_SIGN_ENVELOPE_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); - M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); - M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); + M_ASN1_D2I_get_set_type(PKCS7_RECIP_INFO,ret->recipientinfo, + d2i_PKCS7_RECIP_INFO,PKCS7_RECIP_INFO_free); + M_ASN1_D2I_get_set_type(X509_ALGOR,ret->md_algs,d2i_X509_ALGOR, + X509_ALGOR_free); M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); - M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); - M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); - M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); + M_ASN1_D2I_get_IMP_set_opt_type(X509,ret->cert,d2i_X509,X509_free,0); + M_ASN1_D2I_get_IMP_set_opt_type(X509_CRL,ret->crl,d2i_X509_CRL, + X509_CRL_free,1); + M_ASN1_D2I_get_set_type(PKCS7_SIGNER_INFO,ret->signer_info, + d2i_PKCS7_SIGNER_INFO,PKCS7_SIGNER_INFO_free); M_ASN1_D2I_Finish(a,PKCS7_SIGN_ENVELOPE_free, ASN1_F_D2I_PKCS7_SIGN_ENVELOPE); } -PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new() +PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void) { PKCS7_SIGN_ENVELOPE *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_SIGN_ENVELOPE); M_ASN1_New(ret->version,ASN1_INTEGER_new); - M_ASN1_New(ret->recipientinfo,sk_new_null); - M_ASN1_New(ret->md_algs,sk_new_null); + M_ASN1_New(ret->recipientinfo,sk_PKCS7_RECIP_INFO_new_null); + M_ASN1_New(ret->md_algs,sk_X509_ALGOR_new_null); M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); ret->cert=NULL; ret->crl=NULL; - M_ASN1_New(ret->signer_info,sk_new_null); + M_ASN1_New(ret->signer_info,sk_PKCS7_SIGNER_INFO_new_null); return(ret); M_ASN1_New_Error(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW); } -void PKCS7_SIGN_ENVELOPE_free(a) -PKCS7_SIGN_ENVELOPE *a; +void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); - sk_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); - sk_pop_free(a->md_algs,X509_ALGOR_free); + sk_PKCS7_RECIP_INFO_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); + sk_X509_ALGOR_pop_free(a->md_algs,X509_ALGOR_free); PKCS7_ENC_CONTENT_free(a->enc_data); - sk_pop_free(a->cert,X509_free); - sk_pop_free(a->crl,X509_CRL_free); - sk_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); - Free((char *)a); + sk_X509_pop_free(a->cert,X509_free); + sk_X509_CRL_pop_free(a->crl,X509_CRL_free); + sk_PKCS7_SIGNER_INFO_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); + Free(a); } diff --git a/src/lib/libcrypto/asn1/p7_signd.c b/src/lib/libcrypto/asn1/p7_signd.c index 40f9a44fa8..74f0f522e1 100644 --- a/src/lib/libcrypto/asn1/p7_signd.c +++ b/src/lib/libcrypto/asn1/p7_signd.c @@ -58,83 +58,78 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_SIGNED_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_SIGNED,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_SIGNED(a,pp) -PKCS7_SIGNED *a; -unsigned char **pp; +int i2d_PKCS7_SIGNED(PKCS7_SIGNED *a, unsigned char **pp) { M_ASN1_I2D_vars(a); M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); - M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); + M_ASN1_I2D_len_SET_type(X509_ALGOR,a->md_algs,i2d_X509_ALGOR); M_ASN1_I2D_len(a->contents,i2d_PKCS7); - M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); - M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); - M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); + M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(X509,a->cert,i2d_X509,0); + M_ASN1_I2D_len_IMP_SET_opt_type(X509_CRL,a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_len_SET_type(PKCS7_SIGNER_INFO,a->signer_info, + i2d_PKCS7_SIGNER_INFO); M_ASN1_I2D_seq_total(); M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); - M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); + M_ASN1_I2D_put_SET_type(X509_ALGOR,a->md_algs,i2d_X509_ALGOR); M_ASN1_I2D_put(a->contents,i2d_PKCS7); - M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); - M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); - M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); + M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(X509,a->cert,i2d_X509,0); + M_ASN1_I2D_put_IMP_SET_opt_type(X509_CRL,a->crl,i2d_X509_CRL,1); + M_ASN1_I2D_put_SET_type(PKCS7_SIGNER_INFO,a->signer_info, + i2d_PKCS7_SIGNER_INFO); M_ASN1_I2D_finish(); } -PKCS7_SIGNED *d2i_PKCS7_SIGNED(a,pp,length) -PKCS7_SIGNED **a; -unsigned char **pp; -long length; +PKCS7_SIGNED *d2i_PKCS7_SIGNED(PKCS7_SIGNED **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,PKCS7_SIGNED *,PKCS7_SIGNED_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); - M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); + M_ASN1_D2I_get_set_type(X509_ALGOR,ret->md_algs,d2i_X509_ALGOR, + X509_ALGOR_free); M_ASN1_D2I_get(ret->contents,d2i_PKCS7); - M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); - M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); - M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); + M_ASN1_D2I_get_IMP_set_opt_type(X509,ret->cert,d2i_X509,X509_free,0); + M_ASN1_D2I_get_IMP_set_opt_type(X509_CRL,ret->crl,d2i_X509_CRL, + X509_CRL_free,1); + M_ASN1_D2I_get_set_type(PKCS7_SIGNER_INFO,ret->signer_info, + d2i_PKCS7_SIGNER_INFO,PKCS7_SIGNER_INFO_free); M_ASN1_D2I_Finish(a,PKCS7_SIGNED_free,ASN1_F_D2I_PKCS7_SIGNED); } -PKCS7_SIGNED *PKCS7_SIGNED_new() +PKCS7_SIGNED *PKCS7_SIGNED_new(void) { PKCS7_SIGNED *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_SIGNED); M_ASN1_New(ret->version,ASN1_INTEGER_new); - M_ASN1_New(ret->md_algs,sk_new_null); + M_ASN1_New(ret->md_algs,sk_X509_ALGOR_new_null); M_ASN1_New(ret->contents,PKCS7_new); ret->cert=NULL; ret->crl=NULL; - M_ASN1_New(ret->signer_info,sk_new_null); + M_ASN1_New(ret->signer_info,sk_PKCS7_SIGNER_INFO_new_null); return(ret); M_ASN1_New_Error(ASN1_F_PKCS7_SIGNED_NEW); } -void PKCS7_SIGNED_free(a) -PKCS7_SIGNED *a; +void PKCS7_SIGNED_free(PKCS7_SIGNED *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); - sk_pop_free(a->md_algs,X509_ALGOR_free); + sk_X509_ALGOR_pop_free(a->md_algs,X509_ALGOR_free); PKCS7_free(a->contents); - sk_pop_free(a->cert,X509_free); - sk_pop_free(a->crl,X509_CRL_free); - sk_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); - Free((char *)a); + sk_X509_pop_free(a->cert,X509_free); + sk_X509_CRL_pop_free(a->crl,X509_CRL_free); + sk_PKCS7_SIGNER_INFO_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); + Free(a); } - diff --git a/src/lib/libcrypto/asn1/p7_signi.c b/src/lib/libcrypto/asn1/p7_signi.c index 0da92169fc..21132ef4dd 100644 --- a/src/lib/libcrypto/asn1/p7_signi.c +++ b/src/lib/libcrypto/asn1/p7_signi.c @@ -58,45 +58,40 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include -/* - * ASN1err(ASN1_F_PKCS7_SIGNER_INFO_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_PKCS7_SIGNER_INFO,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_PKCS7_SIGNER_INFO(a,pp) -PKCS7_SIGNER_INFO *a; -unsigned char **pp; +int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a, unsigned char **pp) { M_ASN1_I2D_vars(a); M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); M_ASN1_I2D_len(a->digest_alg,i2d_X509_ALGOR); - M_ASN1_I2D_len_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->auth_attr, + i2d_X509_ATTRIBUTE,0); M_ASN1_I2D_len(a->digest_enc_alg,i2d_X509_ALGOR); M_ASN1_I2D_len(a->enc_digest,i2d_ASN1_OCTET_STRING); - M_ASN1_I2D_len_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); + M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->unauth_attr, + i2d_X509_ATTRIBUTE,1); M_ASN1_I2D_seq_total(); M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); M_ASN1_I2D_put(a->digest_alg,i2d_X509_ALGOR); - M_ASN1_I2D_put_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->auth_attr, + i2d_X509_ATTRIBUTE,0); M_ASN1_I2D_put(a->digest_enc_alg,i2d_X509_ALGOR); M_ASN1_I2D_put(a->enc_digest,i2d_ASN1_OCTET_STRING); - M_ASN1_I2D_put_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); + M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->unauth_attr, + i2d_X509_ATTRIBUTE,1); M_ASN1_I2D_finish(); } -PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(a,pp,length) -PKCS7_SIGNER_INFO **a; -unsigned char **pp; -long length; +PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a, + unsigned char **pp, long length) { M_ASN1_D2I_vars(a,PKCS7_SIGNER_INFO *,PKCS7_SIGNER_INFO_new); @@ -105,18 +100,23 @@ long length; M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL); M_ASN1_D2I_get(ret->digest_alg,d2i_X509_ALGOR); - M_ASN1_D2I_get_IMP_set_opt(ret->auth_attr,d2i_X509_ATTRIBUTE,0); + M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE,ret->auth_attr, + d2i_X509_ATTRIBUTE,X509_ATTRIBUTE_free, + 0); M_ASN1_D2I_get(ret->digest_enc_alg,d2i_X509_ALGOR); M_ASN1_D2I_get(ret->enc_digest,d2i_ASN1_OCTET_STRING); - M_ASN1_D2I_get_IMP_set_opt(ret->unauth_attr,d2i_X509_ATTRIBUTE,1); + M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE,ret->unauth_attr, + d2i_X509_ATTRIBUTE, + X509_ATTRIBUTE_free,1); M_ASN1_D2I_Finish(a,PKCS7_SIGNER_INFO_free, ASN1_F_D2I_PKCS7_SIGNER_INFO); } -PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new() +PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void) { PKCS7_SIGNER_INFO *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,PKCS7_SIGNER_INFO); M_ASN1_New(ret->version,ASN1_INTEGER_new); @@ -131,19 +131,20 @@ PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new() M_ASN1_New_Error(ASN1_F_PKCS7_SIGNER_INFO_NEW); } -void PKCS7_SIGNER_INFO_free(a) -PKCS7_SIGNER_INFO *a; +void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial); X509_ALGOR_free(a->digest_alg); - sk_pop_free(a->auth_attr,X509_ATTRIBUTE_free); + sk_X509_ATTRIBUTE_pop_free(a->auth_attr,X509_ATTRIBUTE_free); X509_ALGOR_free(a->digest_enc_alg); ASN1_OCTET_STRING_free(a->enc_digest); - sk_pop_free(a->unauth_attr,X509_ATTRIBUTE_free); + sk_X509_ATTRIBUTE_pop_free(a->unauth_attr,X509_ATTRIBUTE_free); if (a->pkey != NULL) EVP_PKEY_free(a->pkey); Free((char *)a); } +IMPLEMENT_STACK_OF(PKCS7_SIGNER_INFO) +IMPLEMENT_ASN1_SET_OF(PKCS7_SIGNER_INFO) diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c new file mode 100644 index 0000000000..aa9a4f6c96 --- /dev/null +++ b/src/lib/libcrypto/asn1/p8_pkey.c @@ -0,0 +1,129 @@ +/* p8_pkey.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include + +int i2d_PKCS8_PRIV_KEY_INFO (PKCS8_PRIV_KEY_INFO *a, unsigned char **pp) +{ + + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER); + M_ASN1_I2D_len (a->pkeyalg, i2d_X509_ALGOR); + M_ASN1_I2D_len (a->pkey, i2d_ASN1_TYPE); + M_ASN1_I2D_len_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes, + i2d_X509_ATTRIBUTE, 0); + + M_ASN1_I2D_seq_total (); + + M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER); + M_ASN1_I2D_put (a->pkeyalg, i2d_X509_ALGOR); + M_ASN1_I2D_put (a->pkey, i2d_ASN1_TYPE); + M_ASN1_I2D_put_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes, + i2d_X509_ATTRIBUTE, 0); + + M_ASN1_I2D_finish(); +} + +PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void) +{ + PKCS8_PRIV_KEY_INFO *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PKCS8_PRIV_KEY_INFO); + M_ASN1_New (ret->version, ASN1_INTEGER_new); + M_ASN1_New (ret->pkeyalg, X509_ALGOR_new); + M_ASN1_New (ret->pkey, ASN1_TYPE_new); + ret->attributes = NULL; + ret->broken = PKCS8_OK; + return (ret); + M_ASN1_New_Error(ASN1_F_PKCS8_PRIV_KEY_INFO_NEW); +} + +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a, + unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,PKCS8_PRIV_KEY_INFO *,PKCS8_PRIV_KEY_INFO_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER); + M_ASN1_D2I_get (ret->pkeyalg, d2i_X509_ALGOR); + M_ASN1_D2I_get (ret->pkey, d2i_ASN1_TYPE); + M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes, + d2i_X509_ATTRIBUTE, + X509_ATTRIBUTE_free, 0); + if (ASN1_TYPE_get(ret->pkey) == V_ASN1_SEQUENCE) + ret->broken = PKCS8_NO_OCTET; + M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO); +} + +void PKCS8_PRIV_KEY_INFO_free (PKCS8_PRIV_KEY_INFO *a) +{ + if (a == NULL) return; + ASN1_INTEGER_free (a->version); + X509_ALGOR_free(a->pkeyalg); + /* Clear sensitive data */ + if (a->pkey->value.octet_string) + memset (a->pkey->value.octet_string->data, + 0, a->pkey->value.octet_string->length); + ASN1_TYPE_free (a->pkey); + sk_X509_ATTRIBUTE_pop_free (a->attributes, X509_ATTRIBUTE_free); + Free (a); +} diff --git a/src/lib/libcrypto/asn1/pkcs8.c b/src/lib/libcrypto/asn1/pkcs8.c index 03fdadd51a..29c4ea6a29 100644 --- a/src/lib/libcrypto/asn1/pkcs8.c +++ b/src/lib/libcrypto/asn1/pkcs8.c @@ -58,17 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "objects.h" +#include +#include -/* - * ASN1err(ASN1_F_D2I_X509_KEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_KEY_NEW,ASN1_R_BAD_GET_OBJECT); - */ - -int i2d_X509_KEY(a,pp) -X509 *a; -unsigned char **pp; +int i2d_X509_KEY(X509 *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -85,10 +78,7 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -X509 *d2i_X509_KEY(a,pp,length) -X509 **a; -unsigned char **pp; -long length; +X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,X509 *,X509_new); @@ -100,7 +90,7 @@ long length; M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); } -X509 *X509_KEY_new() +X509 *X509_KEY_new(void) { X509_KEY *ret=NULL; @@ -114,8 +104,7 @@ X509 *X509_KEY_new() M_ASN1_New_Error(ASN1_F_X509_NEW); } -void X509_KEY_free(a) -X509 *a; +void X509_KEY_free(X509 *a) { int i; diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c new file mode 100644 index 0000000000..c2e447ce6f --- /dev/null +++ b/src/lib/libcrypto/asn1/t_crl.c @@ -0,0 +1,166 @@ +/* t_crl.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include +#include +#include +#include + +static void ext_print(BIO *out, X509_EXTENSION *ex); +#ifndef NO_FP_API +int X509_CRL_print_fp(FILE *fp, X509_CRL *x) + { + BIO *b; + int ret; + + if ((b=BIO_new(BIO_s_file())) == NULL) + { + X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB); + return(0); + } + BIO_set_fp(b,fp,BIO_NOCLOSE); + ret=X509_CRL_print(b, x); + BIO_free(b); + return(ret); + } +#endif + +int X509_CRL_print(BIO *out, X509_CRL *x) +{ + char buf[256]; + unsigned char *s; + STACK_OF(X509_REVOKED) *rev; + X509_REVOKED *r; + long l; + int i, j, n; + + BIO_printf(out, "Certificate Revocation List (CRL):\n"); + l = X509_CRL_get_version(x); + BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l); + i = OBJ_obj2nid(x->sig_alg->algorithm); + BIO_printf(out, "%8sSignature Algorithm: %s\n", "", + (i == NID_undef) ? "NONE" : OBJ_nid2ln(i)); + X509_NAME_oneline(X509_CRL_get_issuer(x),buf,256); + BIO_printf(out,"%8sIssuer: %s\n","",buf); + BIO_printf(out,"%8sLast Update: ",""); + ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x)); + BIO_printf(out,"\n%8sNext Update: ",""); + if (X509_CRL_get_nextUpdate(x)) + ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x)); + else BIO_printf(out,"NONE"); + BIO_printf(out,"\n"); + + n=X509_CRL_get_ext_count(x); + if (n > 0) { + BIO_printf(out,"%8sCRL extensions:\n",""); + for (i=0; iserialNumber); + BIO_printf(out,"\n Revocation Date: ",""); + ASN1_TIME_print(out,r->revocationDate); + BIO_printf(out,"\n"); + for(j = 0; j < X509_REVOKED_get_ext_count(r); j++) + ext_print(out, X509_REVOKED_get_ext(r, j)); + } + + i=OBJ_obj2nid(x->sig_alg->algorithm); + BIO_printf(out," Signature Algorithm: %s", + (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); + + s = x->signature->data; + n = x->signature->length; + for (i=0; ivalue); + } + BIO_write(out,"\n",1); +} diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c index bc518d59a2..0dc6e30c3d 100644 --- a/src/lib/libcrypto/asn1/t_pkey.c +++ b/src/lib/libcrypto/asn1/t_pkey.c @@ -58,35 +58,23 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "bn.h" +#include +#include #ifndef NO_RSA -#include "rsa.h" +#include #endif #ifndef NO_DH -#include "dh.h" +#include #endif #ifndef NO_DSA -#include "dsa.h" +#include #endif -/* DHerr(DH_F_DHPARAMS_PRINT,ERR_R_MALLOC_FAILURE); - * DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE); - */ - -#ifndef NOPROTO -static int print(BIO *fp,char *str,BIGNUM *num, +static int print(BIO *fp,const char *str,BIGNUM *num, unsigned char *buf,int off); -#else -static int print(); -#endif - #ifndef NO_RSA #ifndef NO_FP_API -int RSA_print_fp(fp,x,off) -FILE *fp; -RSA *x; -int off; +int RSA_print_fp(FILE *fp, RSA *x, int off) { BIO *b; int ret; @@ -103,12 +91,10 @@ int off; } #endif -int RSA_print(bp,x,off) -BIO *bp; -RSA *x; -int off; +int RSA_print(BIO *bp, RSA *x, int off) { - char str[128],*s; + char str[128]; + const char *s; unsigned char *m=NULL; int i,ret=0; @@ -154,10 +140,7 @@ err: #ifndef NO_DSA #ifndef NO_FP_API -int DSA_print_fp(fp,x,off) -FILE *fp; -DSA *x; -int off; +int DSA_print_fp(FILE *fp, DSA *x, int off) { BIO *b; int ret; @@ -174,10 +157,7 @@ int off; } #endif -int DSA_print(bp,x,off) -BIO *bp; -DSA *x; -int off; +int DSA_print(BIO *bp, DSA *x, int off) { char str[128]; unsigned char *m=NULL; @@ -229,15 +209,12 @@ err: } #endif /* !NO_DSA */ -static int print(bp,number,num,buf,off) -BIO *bp; -char *number; -BIGNUM *num; -unsigned char *buf; -int off; +static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf, + int off) { int n,i; - char str[128],*neg; + char str[128]; + const char *neg; if (num == NULL) return(1); neg=(num->neg)?"-":""; @@ -284,9 +261,7 @@ int off; #ifndef NO_DH #ifndef NO_FP_API -int DHparams_print_fp(fp,x) -FILE *fp; -DH *x; +int DHparams_print_fp(FILE *fp, DH *x) { BIO *b; int ret; @@ -303,9 +278,7 @@ DH *x; } #endif -int DHparams_print(bp,x) -BIO *bp; -DH *x; +int DHparams_print(BIO *bp, DH *x) { unsigned char *m=NULL; int reason=ERR_R_BUF_LIB,i,ret=0; @@ -341,9 +314,7 @@ err: #ifndef NO_DSA #ifndef NO_FP_API -int DSAparams_print_fp(fp,x) -FILE *fp; -DSA *x; +int DSAparams_print_fp(FILE *fp, DSA *x) { BIO *b; int ret; @@ -360,9 +331,7 @@ DSA *x; } #endif -int DSAparams_print(bp,x) -BIO *bp; -DSA *x; +int DSAparams_print(BIO *bp, DSA *x) { unsigned char *m=NULL; int reason=ERR_R_BUF_LIB,i,ret=0; diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c index 7df749a48f..bdd749436a 100644 --- a/src/lib/libcrypto/asn1/t_req.c +++ b/src/lib/libcrypto/asn1/t_req.c @@ -58,15 +58,13 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "bn.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include +#include #ifndef NO_FP_API -int X509_REQ_print_fp(fp,x) -FILE *fp; -X509_REQ *x; +int X509_REQ_print_fp(FILE *fp, X509_REQ *x) { BIO *b; int ret; @@ -83,16 +81,15 @@ X509_REQ *x; } #endif -int X509_REQ_print(bp,x) -BIO *bp; -X509_REQ *x; +int X509_REQ_print(BIO *bp, X509_REQ *x) { unsigned long l; int i,n; - char *s,*neg; + char *s; + const char *neg; X509_REQ_INFO *ri; EVP_PKEY *pkey; - STACK *sk; + STACK_OF(X509_ATTRIBUTE) *sk; char str[128]; ri=x->req_info; @@ -138,12 +135,14 @@ X509_REQ *x; #endif BIO_printf(bp,"%12sUnknown Public Key:\n",""); + EVP_PKEY_free(pkey); + /* may not be */ sprintf(str,"%8sAttributes:\n",""); if (BIO_puts(bp,str) <= 0) goto err; sk=x->req_info->attributes; - if ((sk == NULL) || (sk_num(sk) == 0)) + if ((sk == NULL) || (sk_X509_ATTRIBUTE_num(sk) == 0)) { if (!x->req_info->req_kludge) { @@ -153,7 +152,7 @@ X509_REQ *x; } else { - for (i=0; iobject)) > 0) - + { if (a->set) { ii=0; - count=sk_num(a->value.set); + count=sk_ASN1_TYPE_num(a->value.set); get_next: - at=(ASN1_TYPE *)sk_value(a->value.set,ii); + at=sk_ASN1_TYPE_value(a->value.set,ii); type=at->type; bs=at->value.asn1_string; } @@ -181,6 +180,7 @@ get_next: type=t->type; bs=t->value.bit_string; } + } for (j=25-j; j>0; j--) if (BIO_write(bp," ",1) != 1) goto err; if (BIO_puts(bp,":") <= 0) goto err; diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c index b10fbbb992..42f4d498cf 100644 --- a/src/lib/libcrypto/asn1/t_x509.c +++ b/src/lib/libcrypto/asn1/t_x509.c @@ -58,21 +58,20 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "bn.h" +#include +#include #ifndef NO_RSA -#include "rsa.h" +#include #endif #ifndef NO_DSA -#include "dsa.h" +#include #endif -#include "objects.h" -#include "x509.h" +#include +#include +#include #ifndef NO_FP_API -int X509_print_fp(fp,x) -FILE *fp; -X509 *x; +int X509_print_fp(FILE *fp, X509 *x) { BIO *b; int ret; @@ -89,9 +88,7 @@ X509 *x; } #endif -int X509_print(bp,x) -BIO *bp; -X509 *x; +int X509_print(BIO *bp, X509 *x) { long l; int ret=0,i,j,n; @@ -99,7 +96,7 @@ X509 *x; X509_CINF *ci; ASN1_INTEGER *bs; EVP_PKEY *pkey=NULL; - char *neg; + const char *neg; X509_EXTENSION *ex; ASN1_STRING *str=NULL; @@ -146,9 +143,9 @@ X509 *x; if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err; if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err; if (BIO_write(bp," Not Before: ",24) <= 0) goto err; - if (!ASN1_UTCTIME_print(bp,X509_get_notBefore(x))) goto err; + if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; - if (!ASN1_UTCTIME_print(bp,X509_get_notAfter(x))) goto err; + if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err; if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err; if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0) @@ -158,6 +155,12 @@ X509 *x; (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err; pkey=X509_get_pubkey(x); + if (pkey == NULL) + { + BIO_printf(bp,"%12sUnable to load Public Key\n",""); + ERR_print_errors(bp); + } + else #ifndef NO_RSA if (pkey->type == EVP_PKEY_RSA) { @@ -175,7 +178,9 @@ X509 *x; } else #endif - BIO_printf(bp,"%12sDSA Public Key:\n",""); + BIO_printf(bp,"%12sUnknown Public Key:\n",""); + + EVP_PKEY_free(pkey); n=X509_get_ext_count(x); if (n > 0) @@ -183,7 +188,9 @@ X509 *x; BIO_printf(bp,"%8sX509v3 extensions:\n",""); for (i=0; idata, - str->length) <= 0) - goto err; - } - else if (data_type == V_ASN1_BIT_STRING) - { - BIO_printf(bp,"0x"); - for (j=0; jlength; j++) - { - BIO_printf(bp,"%02X", - str->data[j]); - } - } - } - else + if(!X509V3_EXT_print(bp, ex, 0, 16)) { + BIO_printf(bp, "%16s", ""); ASN1_OCTET_STRING_print(bp,ex->value); } if (BIO_write(bp,"\n",1) <= 0) goto err; @@ -253,9 +230,7 @@ err: return(ret); } -int ASN1_STRING_print(bp,v) -BIO *bp; -ASN1_STRING *v; +int ASN1_STRING_print(BIO *bp, ASN1_STRING *v) { int i,n; char buf[80],*p;; @@ -284,15 +259,59 @@ ASN1_STRING *v; return(1); } -int ASN1_UTCTIME_print(bp,tm) -BIO *bp; -ASN1_UTCTIME *tm; +int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm) +{ + if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm); + if(tm->type == V_ASN1_GENERALIZEDTIME) + return ASN1_GENERALIZEDTIME_print(bp, tm); + BIO_write(bp,"Bad time value",14); + return(0); +} + +static const char *mon[12]= + { + "Jan","Feb","Mar","Apr","May","Jun", + "Jul","Aug","Sep","Oct","Nov","Dec" + }; + +int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm) + { + char *v; + int gmt=0; + int i; + int y=0,M=0,d=0,h=0,m=0,s=0; + + i=tm->length; + v=(char *)tm->data; + + if (i < 12) goto err; + if (v[i-1] == 'Z') gmt=1; + for (i=0; i<12; i++) + if ((v[i] > '9') || (v[i] < '0')) goto err; + y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0'); + M= (v[4]-'0')*10+(v[5]-'0'); + if ((M > 12) || (M < 1)) goto err; + d= (v[6]-'0')*10+(v[7]-'0'); + h= (v[8]-'0')*10+(v[9]-'0'); + m= (v[10]-'0')*10+(v[11]-'0'); + if ( (v[12] >= '0') && (v[12] <= '9') && + (v[13] >= '0') && (v[13] <= '9')) + s= (v[12]-'0')*10+(v[13]-'0'); + + if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s", + mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0) + return(0); + else + return(1); +err: + BIO_write(bp,"Bad time value",14); + return(0); + } + +int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm) { char *v; int gmt=0; - static char *mon[12]={ - "Jan","Feb","Mar","Apr","May","Jun", - "Jul","Aug","Sep","Oct","Nov","Dec"}; int i; int y=0,M=0,d=0,h=0,m=0,s=0; @@ -324,10 +343,7 @@ err: return(0); } -int X509_NAME_print(bp,name,obase) -BIO *bp; -X509_NAME *name; -int obase; +int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) { char *s,*c; int ret=0,l,ll,i,first=1; @@ -342,6 +358,7 @@ int obase; c=s; for (;;) { +#ifndef CHARSET_EBCDIC if ( ((*s == '/') && ((s[1] >= 'A') && (s[1] <= 'Z') && ( (s[2] == '=') || @@ -349,6 +366,15 @@ int obase; (s[3] == '=')) ))) || (*s == '\0')) +#else + if ( ((*s == '/') && + (isupper(s[1]) && ( + (s[2] == '=') || + (isupper(s[2]) && + (s[3] == '=')) + ))) || + (*s == '\0')) +#endif { if ((l <= 0) && !first) { diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c index 0ed2c87b64..b2c20d139f 100644 --- a/src/lib/libcrypto/asn1/x_algor.c +++ b/src/lib/libcrypto/asn1/x_algor.c @@ -58,17 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" +#include +#include -/* - * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_ALGOR_NEW,ASN1_R_EXPECTING_A_SEQUENCE); - * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_X509_ALGOR(a,pp) -X509_ALGOR *a; -unsigned char **pp; +int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -84,10 +77,7 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -X509_ALGOR *d2i_X509_ALGOR(a,pp,length) -X509_ALGOR **a; -unsigned char **pp; -long length; +X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,X509_ALGOR *,X509_ALGOR_new); @@ -104,19 +94,19 @@ long length; M_ASN1_D2I_Finish(a,X509_ALGOR_free,ASN1_F_D2I_X509_ALGOR); } -X509_ALGOR *X509_ALGOR_new() +X509_ALGOR *X509_ALGOR_new(void) { X509_ALGOR *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_ALGOR); - M_ASN1_New(ret->algorithm,ASN1_OBJECT_new); + ret->algorithm=OBJ_nid2obj(NID_undef); ret->parameter=NULL; return(ret); M_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW); } -void X509_ALGOR_free(a) -X509_ALGOR *a; +void X509_ALGOR_free(X509_ALGOR *a) { if (a == NULL) return; ASN1_OBJECT_free(a->algorithm); @@ -124,3 +114,5 @@ X509_ALGOR *a; Free((char *)a); } +IMPLEMENT_STACK_OF(X509_ALGOR) +IMPLEMENT_ASN1_SET_OF(X509_ALGOR) diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c index e52ced8627..a1cbebf5a5 100644 --- a/src/lib/libcrypto/asn1/x_attrib.c +++ b/src/lib/libcrypto/asn1/x_attrib.c @@ -58,19 +58,12 @@ #include #include "cryptlib.h" -#include "objects.h" -#include "asn1_mac.h" - -/* - * ASN1err(ASN1_F_D2I_X509_ATTRIBUTE,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_ATTRIBUTE_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - * ASN1err(ASN1_F_I2D_X509_ATTRIBUTE,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ +#include +#include +#include /* sequence */ -int i2d_X509_ATTRIBUTE(a,pp) -X509_ATTRIBUTE *a; -unsigned char **pp; +int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **pp) { int k=0; int r=0,ret=0; @@ -92,18 +85,16 @@ unsigned char **pp; ret+=i2d_ASN1_OBJECT(a->object,p); if (a->set) - ret+=i2d_ASN1_SET(a->value.set,p,i2d_ASN1_TYPE, - V_ASN1_SET,V_ASN1_UNIVERSAL); + ret+=i2d_ASN1_SET_OF_ASN1_TYPE(a->value.set,p,i2d_ASN1_TYPE, + V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); else ret+=i2d_ASN1_TYPE(a->value.single,p); if (k++) return(r); } } -X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(a,pp,length) -X509_ATTRIBUTE **a; -unsigned char **pp; -long length; +X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,X509_ATTRIBUTE *,X509_ATTRIBUTE_new); @@ -115,7 +106,8 @@ long length; (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET))) { ret->set=1; - M_ASN1_D2I_get_set(ret->value.set,d2i_ASN1_TYPE); + M_ASN1_D2I_get_set_type(ASN1_TYPE,ret->value.set,d2i_ASN1_TYPE, + ASN1_TYPE_free); } else { @@ -126,25 +118,46 @@ long length; M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE); } -X509_ATTRIBUTE *X509_ATTRIBUTE_new() +X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) + { + X509_ATTRIBUTE *ret=NULL; + ASN1_TYPE *val=NULL; + + if ((ret=X509_ATTRIBUTE_new()) == NULL) + return(NULL); + ret->object=OBJ_nid2obj(nid); + ret->set=1; + if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err; + if ((val=ASN1_TYPE_new()) == NULL) goto err; + if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err; + + ASN1_TYPE_set(val,atrtype,value); + return(ret); +err: + if (ret != NULL) X509_ATTRIBUTE_free(ret); + if (val != NULL) ASN1_TYPE_free(val); + return(NULL); + } + +X509_ATTRIBUTE *X509_ATTRIBUTE_new(void) { X509_ATTRIBUTE *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_ATTRIBUTE); - M_ASN1_New(ret->object,ASN1_OBJECT_new); + ret->object=OBJ_nid2obj(NID_undef); ret->set=0; ret->value.ptr=NULL; return(ret); M_ASN1_New_Error(ASN1_F_X509_ATTRIBUTE_NEW); } -void X509_ATTRIBUTE_free(a) -X509_ATTRIBUTE *a; +void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a) { if (a == NULL) return; ASN1_OBJECT_free(a->object); if (a->set) - sk_pop_free(a->value.set,ASN1_TYPE_free); + sk_ASN1_TYPE_pop_free(a->value.set,ASN1_TYPE_free); else ASN1_TYPE_free(a->value.single); Free((char *)a); diff --git a/src/lib/libcrypto/asn1/x_cinf.c b/src/lib/libcrypto/asn1/x_cinf.c index 4fc2cc9f6e..fe1b18a90f 100644 --- a/src/lib/libcrypto/asn1/x_cinf.c +++ b/src/lib/libcrypto/asn1/x_cinf.c @@ -58,16 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" +#include +#include -/* - * ASN1err(ASN1_F_D2I_X509_CINF,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_CINF_NEW,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_X509_CINF(a,pp) -X509_CINF *a; -unsigned char **pp; +int i2d_X509_CINF(X509_CINF *a, unsigned char **pp) { int v1=0,v2=0; M_ASN1_I2D_vars(a); @@ -81,7 +75,9 @@ unsigned char **pp; M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY); M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING); M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING); - M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); + M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions, + i2d_X509_EXTENSION,3, + V_ASN1_SEQUENCE,v2); M_ASN1_I2D_seq_total(); @@ -94,15 +90,14 @@ unsigned char **pp; M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY); M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1); M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2); - M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); + M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions, + i2d_X509_EXTENSION,3, + V_ASN1_SEQUENCE,v2); M_ASN1_I2D_finish(); } -X509_CINF *d2i_X509_CINF(a,pp,length) -X509_CINF **a; -unsigned char **pp; -long length; +X509_CINF *d2i_X509_CINF(X509_CINF **a, unsigned char **pp, long length) { int ver=0; M_ASN1_D2I_vars(a,X509_CINF *,X509_CINF_new); @@ -140,28 +135,38 @@ long length; if (ret->subjectUID != NULL) { ASN1_BIT_STRING_free(ret->subjectUID); - ret->issuerUID=NULL; + ret->subjectUID=NULL; } M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1, V_ASN1_BIT_STRING); M_ASN1_D2I_get_IMP_opt(ret->subjectUID,d2i_ASN1_BIT_STRING, 2, V_ASN1_BIT_STRING); } +/* Note: some broken certificates include extensions but don't set + * the version number properly. By bypassing this check they can + * be parsed. + */ + +#ifdef VERSION_EXT_CHECK if (ver >= 2) /* version 3 extensions */ +#endif { if (ret->extensions != NULL) - while (sk_num(ret->extensions)) - X509_EXTENSION_free((X509_EXTENSION *) - sk_pop(ret->extensions)); - M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION,3, - V_ASN1_SEQUENCE); + while (sk_X509_EXTENSION_num(ret->extensions)) + X509_EXTENSION_free( + sk_X509_EXTENSION_pop(ret->extensions)); + M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions, + d2i_X509_EXTENSION, + X509_EXTENSION_free,3, + V_ASN1_SEQUENCE); } M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF); } -X509_CINF *X509_CINF_new() +X509_CINF *X509_CINF_new(void) { X509_CINF *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_CINF); ret->version=NULL; @@ -178,8 +183,7 @@ X509_CINF *X509_CINF_new() M_ASN1_New_Error(ASN1_F_X509_CINF_NEW); } -void X509_CINF_free(a) -X509_CINF *a; +void X509_CINF_free(X509_CINF *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); @@ -191,7 +195,7 @@ X509_CINF *a; X509_PUBKEY_free(a->key); ASN1_BIT_STRING_free(a->issuerUID); ASN1_BIT_STRING_free(a->subjectUID); - sk_pop_free(a->extensions,X509_EXTENSION_free); - Free((char *)a); + sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free); + Free(a); } diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c index 13acdab427..cd46bbebc2 100644 --- a/src/lib/libcrypto/asn1/x_crl.c +++ b/src/lib/libcrypto/asn1/x_crl.c @@ -58,83 +58,69 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" - -/* - * ASN1err(ASN1_F_D2I_X509_CRL,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_X509_CRL_INFO,ASN1_R_EXPECTING_A_SEQUENCE); - * ASN1err(ASN1_F_D2I_X509_REVOKED,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_CRL_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_CRL_INFO_NEW,ASN1_R_EXPECTING_A_SEQUENCE); - * ASN1err(ASN1_F_X509_REVOKED_NEW,ASN1_R_LENGTH_MISMATCH); - */ +#include +#include -#ifndef NOPROTO static int X509_REVOKED_cmp(X509_REVOKED **a,X509_REVOKED **b); static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b); -#else -static int X509_REVOKED_cmp(); -static int X509_REVOKED_seq_cmp(); -#endif - -int i2d_X509_REVOKED(a,pp) -X509_REVOKED *a; -unsigned char **pp; +int i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **pp) { M_ASN1_I2D_vars(a); M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER); - M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_UTCTIME); - M_ASN1_I2D_len_SEQ_opt(a->extensions,i2d_X509_EXTENSION); + M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_TIME); + M_ASN1_I2D_len_SEQUENCE_opt_type(X509_EXTENSION,a->extensions, + i2d_X509_EXTENSION); M_ASN1_I2D_seq_total(); M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER); - M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_UTCTIME); - M_ASN1_I2D_put_SEQ_opt(a->extensions,i2d_X509_EXTENSION); + M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_TIME); + M_ASN1_I2D_put_SEQUENCE_opt_type(X509_EXTENSION,a->extensions, + i2d_X509_EXTENSION); M_ASN1_I2D_finish(); } -X509_REVOKED *d2i_X509_REVOKED(a,pp,length) -X509_REVOKED **a; -unsigned char **pp; -long length; +X509_REVOKED *d2i_X509_REVOKED(X509_REVOKED **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER); - M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_UTCTIME); - M_ASN1_D2I_get_seq_opt(ret->extensions,d2i_X509_EXTENSION); + M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_TIME); + M_ASN1_D2I_get_seq_opt_type(X509_EXTENSION,ret->extensions, + d2i_X509_EXTENSION,X509_EXTENSION_free); M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED); } -int i2d_X509_CRL_INFO(a,pp) -X509_CRL_INFO *a; -unsigned char **pp; +int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp) { int v1=0; long l=0; + int (*old_cmp)(X509_REVOKED **,X509_REVOKED **); M_ASN1_I2D_vars(a); + + old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp); + sk_X509_REVOKED_sort(a->revoked); + sk_X509_REVOKED_set_cmp_func(a->revoked,old_cmp); - if (sk_num(a->revoked) != 0) - qsort((char *)a->revoked->data,sk_num(a->revoked), - sizeof(X509_REVOKED *),(int (*)(P_CC_CC))X509_REVOKED_seq_cmp); if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0)) { M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); } M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR); M_ASN1_I2D_len(a->issuer,i2d_X509_NAME); - M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_UTCTIME); + M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_TIME); if (a->nextUpdate != NULL) - { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_UTCTIME); } - M_ASN1_I2D_len_SEQ_opt(a->revoked,i2d_X509_REVOKED); - M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, - V_ASN1_SEQUENCE,v1); + { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_TIME); } + M_ASN1_I2D_len_SEQUENCE_opt_type(X509_REVOKED,a->revoked, + i2d_X509_REVOKED); + M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions, + i2d_X509_EXTENSION,0, + V_ASN1_SEQUENCE,v1); M_ASN1_I2D_seq_total(); @@ -147,17 +133,17 @@ unsigned char **pp; M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME); if (a->nextUpdate != NULL) { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); } - M_ASN1_I2D_put_SEQ_opt(a->revoked,i2d_X509_REVOKED); - M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, - V_ASN1_SEQUENCE,v1); + M_ASN1_I2D_put_SEQUENCE_opt_type(X509_REVOKED,a->revoked, + i2d_X509_REVOKED); + M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions, + i2d_X509_EXTENSION,0, + V_ASN1_SEQUENCE,v1); M_ASN1_I2D_finish(); } -X509_CRL_INFO *d2i_X509_CRL_INFO(a,pp,length) -X509_CRL_INFO **a; -unsigned char **pp; -long length; +X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, unsigned char **pp, + long length) { int i,ver=0; M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new); @@ -176,20 +162,31 @@ long length; } M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); - M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_UTCTIME); - M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME,V_ASN1_UTCTIME); + M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_TIME); + /* Manually handle the OPTIONAL ASN1_TIME stuff */ + if(c.slen != 0 + && ( (M_ASN1_next & ~V_ASN1_CONSTRUCTED) == + (V_ASN1_UNIVERSAL|V_ASN1_UTCTIME) + || (M_ASN1_next & ~V_ASN1_CONSTRUCTED) == + (V_ASN1_UNIVERSAL|V_ASN1_GENERALIZEDTIME) ) ) { + M_ASN1_D2I_get(ret->nextUpdate,d2i_ASN1_TIME); + } + if(!ret->nextUpdate) + M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME, + V_ASN1_GENERALIZEDTIME); if (ret->revoked != NULL) { - while (sk_num(ret->revoked)) - X509_REVOKED_free((X509_REVOKED *)sk_pop(ret->revoked)); + while (sk_X509_REVOKED_num(ret->revoked)) + X509_REVOKED_free(sk_X509_REVOKED_pop(ret->revoked)); } - M_ASN1_D2I_get_seq_opt(ret->revoked,d2i_X509_REVOKED); + M_ASN1_D2I_get_seq_opt_type(X509_REVOKED,ret->revoked,d2i_X509_REVOKED, + X509_REVOKED_free); if (ret->revoked != NULL) { - for (i=0; irevoked); i++) + for (i=0; irevoked); i++) { - ((X509_REVOKED *)sk_value(ret->revoked,i))->sequence=i; + sk_X509_REVOKED_value(ret->revoked,i)->sequence=i; } } @@ -197,21 +194,21 @@ long length; { if (ret->extensions != NULL) { - while (sk_num(ret->extensions)) - X509_EXTENSION_free((X509_EXTENSION *) - sk_pop(ret->extensions)); + while (sk_X509_EXTENSION_num(ret->extensions)) + X509_EXTENSION_free( + sk_X509_EXTENSION_pop(ret->extensions)); } - M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION, - 0,V_ASN1_SEQUENCE); + M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions, + d2i_X509_EXTENSION, + X509_EXTENSION_free,0, + V_ASN1_SEQUENCE); } M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO); } -int i2d_X509_CRL(a,pp) -X509_CRL *a; -unsigned char **pp; +int i2d_X509_CRL(X509_CRL *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -228,10 +225,7 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -X509_CRL *d2i_X509_CRL(a,pp,length) -X509_CRL **a; -unsigned char **pp; -long length; +X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new); @@ -245,9 +239,10 @@ long length; } -X509_REVOKED *X509_REVOKED_new() +X509_REVOKED *X509_REVOKED_new(void) { X509_REVOKED *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_REVOKED); M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); @@ -257,9 +252,10 @@ X509_REVOKED *X509_REVOKED_new() M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW); } -X509_CRL_INFO *X509_CRL_INFO_new() +X509_CRL_INFO *X509_CRL_INFO_new(void) { X509_CRL_INFO *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_CRL_INFO); ret->version=NULL; @@ -267,16 +263,17 @@ X509_CRL_INFO *X509_CRL_INFO_new() M_ASN1_New(ret->issuer,X509_NAME_new); M_ASN1_New(ret->lastUpdate,ASN1_UTCTIME_new); ret->nextUpdate=NULL; - M_ASN1_New(ret->revoked,sk_new_null); - M_ASN1_New(ret->extensions,sk_new_null); - ret->revoked->comp=(int (*)())X509_REVOKED_cmp; + M_ASN1_New(ret->revoked,sk_X509_REVOKED_new_null); + M_ASN1_New(ret->extensions,sk_X509_EXTENSION_new_null); + sk_X509_REVOKED_set_cmp_func(ret->revoked,X509_REVOKED_cmp); return(ret); M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW); } -X509_CRL *X509_CRL_new() +X509_CRL *X509_CRL_new(void) { X509_CRL *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_CRL); ret->references=1; @@ -287,18 +284,16 @@ X509_CRL *X509_CRL_new() M_ASN1_New_Error(ASN1_F_X509_CRL_NEW); } -void X509_REVOKED_free(a) -X509_REVOKED *a; +void X509_REVOKED_free(X509_REVOKED *a) { if (a == NULL) return; ASN1_INTEGER_free(a->serialNumber); ASN1_UTCTIME_free(a->revocationDate); - sk_pop_free(a->extensions,X509_EXTENSION_free); - Free((char *)a); + sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free); + Free(a); } -void X509_CRL_INFO_free(a) -X509_CRL_INFO *a; +void X509_CRL_INFO_free(X509_CRL_INFO *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); @@ -307,13 +302,12 @@ X509_CRL_INFO *a; ASN1_UTCTIME_free(a->lastUpdate); if (a->nextUpdate) ASN1_UTCTIME_free(a->nextUpdate); - sk_pop_free(a->revoked,X509_REVOKED_free); - sk_pop_free(a->extensions,X509_EXTENSION_free); - Free((char *)a); + sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free); + sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free); + Free(a); } -void X509_CRL_free(a) -X509_CRL *a; +void X509_CRL_free(X509_CRL *a) { int i; @@ -335,19 +329,22 @@ X509_CRL *a; X509_CRL_INFO_free(a->crl); X509_ALGOR_free(a->sig_alg); ASN1_BIT_STRING_free(a->signature); - Free((char *)a); + Free(a); } -static int X509_REVOKED_cmp(a,b) -X509_REVOKED **a,**b; +static int X509_REVOKED_cmp(X509_REVOKED **a, X509_REVOKED **b) { return(ASN1_STRING_cmp( (ASN1_STRING *)(*a)->serialNumber, (ASN1_STRING *)(*b)->serialNumber)); } -static int X509_REVOKED_seq_cmp(a,b) -X509_REVOKED **a,**b; +static int X509_REVOKED_seq_cmp(X509_REVOKED **a, X509_REVOKED **b) { return((*a)->sequence-(*b)->sequence); } + +IMPLEMENT_STACK_OF(X509_REVOKED) +IMPLEMENT_ASN1_SET_OF(X509_REVOKED) +IMPLEMENT_STACK_OF(X509_CRL) +IMPLEMENT_ASN1_SET_OF(X509_CRL) diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c index 54ffe2f00b..d5f9e1df9e 100644 --- a/src/lib/libcrypto/asn1/x_exten.c +++ b/src/lib/libcrypto/asn1/x_exten.c @@ -58,17 +58,11 @@ #include #include "cryptlib.h" -#include "objects.h" -#include "asn1_mac.h" +#include +#include +#include -/* - * ASN1err(ASN1_F_D2I_X509_EXTENSION,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_EXTENSION_NEW,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_X509_EXTENSION(a,pp) -X509_EXTENSION *a; -unsigned char **pp; +int i2d_X509_EXTENSION(X509_EXTENSION *a, unsigned char **pp) { int k=0; int r=0,ret=0; @@ -96,10 +90,8 @@ unsigned char **pp; } } -X509_EXTENSION *d2i_X509_EXTENSION(a,pp,length) -X509_EXTENSION **a; -unsigned char **pp; -long length; +X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a, unsigned char **pp, + long length) { int i; M_ASN1_D2I_vars(a,X509_EXTENSION *,X509_EXTENSION_new); @@ -127,12 +119,13 @@ long length; M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION); } -X509_EXTENSION *X509_EXTENSION_new() +X509_EXTENSION *X509_EXTENSION_new(void) { X509_EXTENSION *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_EXTENSION); - M_ASN1_New(ret->object,ASN1_OBJECT_new); + ret->object=OBJ_nid2obj(NID_undef); M_ASN1_New(ret->value,ASN1_OCTET_STRING_new); ret->critical=0; ret->netscape_hack=0; @@ -143,8 +136,7 @@ X509_EXTENSION *X509_EXTENSION_new() M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW); } -void X509_EXTENSION_free(a) -X509_EXTENSION *a; +void X509_EXTENSION_free(X509_EXTENSION *a) { if (a == NULL) return; if ((a->argp != NULL) && (a->ex_free != NULL)) diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c index b55f0ce77a..99ce011f07 100644 --- a/src/lib/libcrypto/asn1/x_info.c +++ b/src/lib/libcrypto/asn1/x_info.c @@ -58,11 +58,11 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include +#include -X509_INFO *X509_INFO_new() +X509_INFO *X509_INFO_new(void) { X509_INFO *ret=NULL; @@ -84,8 +84,7 @@ X509_INFO *X509_INFO_new() return(ret); } -void X509_INFO_free(x) -X509_INFO *x; +void X509_INFO_free(X509_INFO *x) { int i; @@ -109,3 +108,6 @@ X509_INFO *x; if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); Free((char *)x); } + +IMPLEMENT_STACK_OF(X509_INFO) + diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c index 28b9c34b58..b09fba33fb 100644 --- a/src/lib/libcrypto/asn1/x_name.c +++ b/src/lib/libcrypto/asn1/x_name.c @@ -58,25 +58,12 @@ #include #include "cryptlib.h" -#include "objects.h" -#include "asn1_mac.h" - -/* - * ASN1err(ASN1_F_D2I_X509_NAME,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_NAME_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - * ASN1err(ASN1_F_D2I_X509_NAME_ENTRY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_NAME_ENTRY_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); - */ +#include +#include +#include -#ifndef NOPROTO static int i2d_X509_NAME_entries(X509_NAME *a); -#else -static int i2d_X509_NAME_entries(); -#endif - -int i2d_X509_NAME_ENTRY(a,pp) -X509_NAME_ENTRY *a; -unsigned char **pp; +int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -91,10 +78,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(a,pp,length) -X509_NAME_ENTRY **a; -unsigned char **pp; -long length; +X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,X509_NAME_ENTRY *,X509_NAME_ENTRY_new); @@ -106,9 +91,7 @@ long length; M_ASN1_D2I_Finish(a,X509_NAME_ENTRY_free,ASN1_F_D2I_X509_NAME_ENTRY); } -int i2d_X509_NAME(a,pp) -X509_NAME *a; -unsigned char **pp; +int i2d_X509_NAME(X509_NAME *a, unsigned char **pp) { int ret; @@ -128,11 +111,10 @@ unsigned char **pp; return(ret); } -static int i2d_X509_NAME_entries(a) -X509_NAME *a; +static int i2d_X509_NAME_entries(X509_NAME *a) { X509_NAME_ENTRY *ne,*fe=NULL; - STACK *sk; + STACK_OF(X509_NAME_ENTRY) *sk; BUF_MEM *buf=NULL; int set=0,r,ret=0; int i; @@ -140,9 +122,9 @@ X509_NAME *a; int size=0; sk=a->entries; - for (i=0; iset) { set=ne->set; @@ -190,10 +172,7 @@ err: return(-1); } -X509_NAME *d2i_X509_NAME(a,pp,length) -X509_NAME **a; -unsigned char **pp; -long length; +X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length) { int set=0,i; int idx=0; @@ -201,11 +180,11 @@ long length; M_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new); orig= *pp; - if (sk_num(ret->entries) > 0) + if (sk_X509_NAME_ENTRY_num(ret->entries) > 0) { - while (sk_num(ret->entries) > 0) - X509_NAME_ENTRY_free((X509_NAME_ENTRY *) - sk_pop(ret->entries)); + while (sk_X509_NAME_ENTRY_num(ret->entries) > 0) + X509_NAME_ENTRY_free( + sk_X509_NAME_ENTRY_pop(ret->entries)); } M_ASN1_D2I_Init(); @@ -213,11 +192,12 @@ long length; for (;;) { if (M_ASN1_D2I_end_sequence()) break; - M_ASN1_D2I_get_set(ret->entries,d2i_X509_NAME_ENTRY); - for (; idx < sk_num(ret->entries); idx++) + M_ASN1_D2I_get_set_type(X509_NAME_ENTRY,ret->entries, + d2i_X509_NAME_ENTRY, + X509_NAME_ENTRY_free); + for (; idx < sk_X509_NAME_ENTRY_num(ret->entries); idx++) { - ((X509_NAME_ENTRY *)sk_value(ret->entries,idx))->set= - set; + sk_X509_NAME_ENTRY_value(ret->entries,idx)->set=set; } set++; } @@ -231,21 +211,24 @@ long length; M_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME); } -X509_NAME *X509_NAME_new() +X509_NAME *X509_NAME_new(void) { X509_NAME *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_NAME); - if ((ret->entries=sk_new(NULL)) == NULL) goto err2; + if ((ret->entries=sk_X509_NAME_ENTRY_new(NULL)) == NULL) + { c.line=__LINE__; goto err2; } M_ASN1_New(ret->bytes,BUF_MEM_new); ret->modified=1; return(ret); M_ASN1_New_Error(ASN1_F_X509_NAME_NEW); } -X509_NAME_ENTRY *X509_NAME_ENTRY_new() +X509_NAME_ENTRY *X509_NAME_ENTRY_new(void) { X509_NAME_ENTRY *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_NAME_ENTRY); /* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/ @@ -256,26 +239,25 @@ X509_NAME_ENTRY *X509_NAME_ENTRY_new() M_ASN1_New_Error(ASN1_F_X509_NAME_ENTRY_NEW); } -void X509_NAME_free(a) -X509_NAME *a; +void X509_NAME_free(X509_NAME *a) { + if(a == NULL) + return; + BUF_MEM_free(a->bytes); - sk_pop_free(a->entries,X509_NAME_ENTRY_free); - Free((char *)a); + sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free); + Free(a); } -void X509_NAME_ENTRY_free(a) -X509_NAME_ENTRY *a; +void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a) { if (a == NULL) return; ASN1_OBJECT_free(a->object); ASN1_BIT_STRING_free(a->value); - Free((char *)a); + Free(a); } -int X509_NAME_set(xn,name) -X509_NAME **xn; -X509_NAME *name; +int X509_NAME_set(X509_NAME **xn, X509_NAME *name) { X509_NAME *in; @@ -293,3 +275,5 @@ X509_NAME *name; return(*xn != NULL); } +IMPLEMENT_STACK_OF(X509_NAME_ENTRY) +IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY) diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c index 1d4d926129..b0057eb212 100644 --- a/src/lib/libcrypto/asn1/x_pkey.c +++ b/src/lib/libcrypto/asn1/x_pkey.c @@ -58,25 +58,18 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "asn1_mac.h" - -/* ASN1err(ASN1_F_D2I_X509_PKEY,ASN1_R_UNSUPPORTED_CIPHER); */ -/* ASN1err(ASN1_F_X509_PKEY_NEW,ASN1_R_IV_TOO_LARGE); */ +#include +#include +#include +#include /* need to implement */ -int i2d_X509_PKEY(a,pp) -X509_PKEY *a; -unsigned char **pp; +int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) { return(0); } -X509_PKEY *d2i_X509_PKEY(a,pp,length) -X509_PKEY **a; -unsigned char **pp; -long length; +X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, unsigned char **pp, long length) { int i; M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); @@ -91,6 +84,7 @@ long length; if (ret->cipher.cipher == NULL) { c.error=ASN1_R_UNSUPPORTED_CIPHER; + c.line=__LINE__; goto err; } if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) @@ -99,6 +93,7 @@ long length; if (i > EVP_MAX_IV_LENGTH) { c.error=ASN1_R_IV_TOO_LARGE; + c.line=__LINE__; goto err; } memcpy(ret->cipher.iv, @@ -109,9 +104,10 @@ long length; M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); } -X509_PKEY *X509_PKEY_new() +X509_PKEY *X509_PKEY_new(void) { X509_PKEY *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_PKEY); ret->version=0; @@ -128,8 +124,7 @@ X509_PKEY *X509_PKEY_new() M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); } -void X509_PKEY_free(x) -X509_PKEY *x; +void X509_PKEY_free(X509_PKEY *x) { int i; diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c index a309cf74a7..4ac32c59dd 100644 --- a/src/lib/libcrypto/asn1/x_pubkey.c +++ b/src/lib/libcrypto/asn1/x_pubkey.c @@ -58,16 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" +#include +#include -/* - * ASN1err(ASN1_F_D2I_X509_PUBKEY,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_PUBKEY_NEW,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_X509_PUBKEY(a,pp) -X509_PUBKEY *a; -unsigned char **pp; +int i2d_X509_PUBKEY(X509_PUBKEY *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -82,10 +76,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -X509_PUBKEY *d2i_X509_PUBKEY(a,pp,length) -X509_PUBKEY **a; -unsigned char **pp; -long length; +X509_PUBKEY *d2i_X509_PUBKEY(X509_PUBKEY **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,X509_PUBKEY *,X509_PUBKEY_new); @@ -101,9 +93,10 @@ long length; M_ASN1_D2I_Finish(a,X509_PUBKEY_free,ASN1_F_D2I_X509_PUBKEY); } -X509_PUBKEY *X509_PUBKEY_new() +X509_PUBKEY *X509_PUBKEY_new(void) { X509_PUBKEY *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_PUBKEY); M_ASN1_New(ret->algor,X509_ALGOR_new); @@ -113,8 +106,7 @@ X509_PUBKEY *X509_PUBKEY_new() M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW); } -void X509_PUBKEY_free(a) -X509_PUBKEY *a; +void X509_PUBKEY_free(X509_PUBKEY *a) { if (a == NULL) return; X509_ALGOR_free(a->algor); @@ -123,9 +115,7 @@ X509_PUBKEY *a; Free((char *)a); } -int X509_PUBKEY_set(x,pkey) -X509_PUBKEY **x; -EVP_PKEY *pkey; +int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) { int ok=0; X509_PUBKEY *pk; @@ -182,11 +172,15 @@ EVP_PKEY *pkey; goto err; } - i=i2d_PublicKey(pkey,NULL); + if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err; if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err; p=s; i2d_PublicKey(pkey,&p); if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err; + /* Set number of unused bits to zero */ + pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); + pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; + Free(s); CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); @@ -204,8 +198,7 @@ err: return(ok); } -EVP_PKEY *X509_PUBKEY_get(key) -X509_PUBKEY *key; +EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) { EVP_PKEY *ret=NULL; long j; @@ -217,7 +210,11 @@ X509_PUBKEY *key; if (key == NULL) goto err; - if (key->pkey != NULL) return(key->pkey); + if (key->pkey != NULL) + { + CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY); + return(key->pkey); + } if (key->public_key == NULL) goto err; @@ -247,6 +244,7 @@ X509_PUBKEY *key; } #endif key->pkey=ret; + CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY); return(ret); err: if (ret != NULL) diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c index ff0be13d37..9b1d6abe64 100644 --- a/src/lib/libcrypto/asn1/x_req.c +++ b/src/lib/libcrypto/asn1/x_req.c @@ -58,19 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" -#include "x509.h" - -/* - * ASN1err(ASN1_F_D2I_X509_REQ,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_X509_REQ_INFO,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_REQ_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_REQ_INFO_NEW,ASN1_R_LENGTH_MISMATCH); - */ +#include +#include -int i2d_X509_REQ_INFO(a,pp) -X509_REQ_INFO *a; -unsigned char **pp; +int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -87,11 +78,12 @@ unsigned char **pp; */ if (a->req_kludge) { - M_ASN1_I2D_len_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,i2d_X509_ATTRIBUTE,0); } else { - M_ASN1_I2D_len_IMP_set(a->attributes, i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_len_IMP_SET_type(X509_ATTRIBUTE,a->attributes, + i2d_X509_ATTRIBUTE,0); } M_ASN1_I2D_seq_total(); @@ -107,20 +99,20 @@ unsigned char **pp; */ if (a->req_kludge) { - M_ASN1_I2D_put_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes, + i2d_X509_ATTRIBUTE,0); } else { - M_ASN1_I2D_put_IMP_set(a->attributes,i2d_X509_ATTRIBUTE,0); + M_ASN1_I2D_put_IMP_SET_type(X509_ATTRIBUTE,a->attributes, + i2d_X509_ATTRIBUTE,0); } M_ASN1_I2D_finish(); } -X509_REQ_INFO *d2i_X509_REQ_INFO(a,pp,length) -X509_REQ_INFO **a; -unsigned char **pp; -long length; +X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,X509_REQ_INFO *,X509_REQ_INFO_new); @@ -141,40 +133,40 @@ long length; ret->req_kludge=1; else { - M_ASN1_D2I_get_IMP_set(ret->attributes,d2i_X509_ATTRIBUTE,0); + M_ASN1_D2I_get_IMP_set_type(X509_ATTRIBUTE,ret->attributes, + d2i_X509_ATTRIBUTE, + X509_ATTRIBUTE_free,0); } M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO); } -X509_REQ_INFO *X509_REQ_INFO_new() +X509_REQ_INFO *X509_REQ_INFO_new(void) { X509_REQ_INFO *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_REQ_INFO); M_ASN1_New(ret->version,ASN1_INTEGER_new); M_ASN1_New(ret->subject,X509_NAME_new); M_ASN1_New(ret->pubkey,X509_PUBKEY_new); - M_ASN1_New(ret->attributes,sk_new_null); + M_ASN1_New(ret->attributes,sk_X509_ATTRIBUTE_new_null); ret->req_kludge=0; return(ret); M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW); } -void X509_REQ_INFO_free(a) -X509_REQ_INFO *a; +void X509_REQ_INFO_free(X509_REQ_INFO *a) { if (a == NULL) return; ASN1_INTEGER_free(a->version); X509_NAME_free(a->subject); X509_PUBKEY_free(a->pubkey); - sk_pop_free(a->attributes,X509_ATTRIBUTE_free); + sk_X509_ATTRIBUTE_pop_free(a->attributes,X509_ATTRIBUTE_free); Free((char *)a); } -int i2d_X509_REQ(a,pp) -X509_REQ *a; -unsigned char **pp; +int i2d_X509_REQ(X509_REQ *a, unsigned char **pp) { M_ASN1_I2D_vars(a); M_ASN1_I2D_len(a->req_info, i2d_X509_REQ_INFO); @@ -190,10 +182,7 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -X509_REQ *d2i_X509_REQ(a,pp,length) -X509_REQ **a; -unsigned char **pp; -long length; +X509_REQ *d2i_X509_REQ(X509_REQ **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,X509_REQ *,X509_REQ_new); @@ -205,9 +194,10 @@ long length; M_ASN1_D2I_Finish(a,X509_REQ_free,ASN1_F_D2I_X509_REQ); } -X509_REQ *X509_REQ_new() +X509_REQ *X509_REQ_new(void) { X509_REQ *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_REQ); ret->references=1; @@ -218,8 +208,7 @@ X509_REQ *X509_REQ_new() M_ASN1_New_Error(ASN1_F_X509_REQ_NEW); } -void X509_REQ_free(a) -X509_REQ *a; +void X509_REQ_free(X509_REQ *a) { int i; diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c index f0a2e4c27a..c2782d1b9c 100644 --- a/src/lib/libcrypto/asn1/x_sig.c +++ b/src/lib/libcrypto/asn1/x_sig.c @@ -58,16 +58,10 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" +#include +#include -/* - * ASN1err(ASN1_F_D2I_X509_SIG,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_SIG_NEW,ASN1_R_LENGTH_MISMATCH); - */ - -int i2d_X509_SIG(a,pp) -X509_SIG *a; -unsigned char **pp; +int i2d_X509_SIG(X509_SIG *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -82,10 +76,7 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -X509_SIG *d2i_X509_SIG(a,pp,length) -X509_SIG **a; -unsigned char **pp; -long length; +X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new); @@ -96,9 +87,10 @@ long length; M_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG); } -X509_SIG *X509_SIG_new() +X509_SIG *X509_SIG_new(void) { X509_SIG *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_SIG); M_ASN1_New(ret->algor,X509_ALGOR_new); @@ -107,8 +99,7 @@ X509_SIG *X509_SIG_new() M_ASN1_New_Error(ASN1_F_X509_SIG_NEW); } -void X509_SIG_free(a) -X509_SIG *a; +void X509_SIG_free(X509_SIG *a) { if (a == NULL) return; X509_ALGOR_free(a->algor); diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c index 4a80df44b8..43e0023839 100644 --- a/src/lib/libcrypto/asn1/x_spki.c +++ b/src/lib/libcrypto/asn1/x_spki.c @@ -62,19 +62,10 @@ #include #include "cryptlib.h" -#include "x509.h" -#include "asn1_mac.h" - -/* - * ASN1err(ASN1_F_D2I_NETSCAPE_SPKAC,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_NETSCAPE_SPKAC_NEW,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_D2I_NETSCAPE_SPKI,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_NETSCAPE_SPKI_NEW,ASN1_R_LENGTH_MISMATCH); - */ +#include +#include -int i2d_NETSCAPE_SPKAC(a,pp) -NETSCAPE_SPKAC *a; -unsigned char **pp; +int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -89,10 +80,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(a,pp,length) -NETSCAPE_SPKAC **a; -unsigned char **pp; -long length; +NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,NETSCAPE_SPKAC *,NETSCAPE_SPKAC_new); @@ -103,9 +92,10 @@ long length; M_ASN1_D2I_Finish(a,NETSCAPE_SPKAC_free,ASN1_F_D2I_NETSCAPE_SPKAC); } -NETSCAPE_SPKAC *NETSCAPE_SPKAC_new() +NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void) { NETSCAPE_SPKAC *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC); M_ASN1_New(ret->pubkey,X509_PUBKEY_new); @@ -114,8 +104,7 @@ NETSCAPE_SPKAC *NETSCAPE_SPKAC_new() M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW); } -void NETSCAPE_SPKAC_free(a) -NETSCAPE_SPKAC *a; +void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a) { if (a == NULL) return; X509_PUBKEY_free(a->pubkey); @@ -123,9 +112,7 @@ NETSCAPE_SPKAC *a; Free((char *)a); } -int i2d_NETSCAPE_SPKI(a,pp) -NETSCAPE_SPKI *a; -unsigned char **pp; +int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -142,10 +129,8 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(a,pp,length) -NETSCAPE_SPKI **a; -unsigned char **pp; -long length; +NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a, unsigned char **pp, + long length) { M_ASN1_D2I_vars(a,NETSCAPE_SPKI *,NETSCAPE_SPKI_new); @@ -157,9 +142,10 @@ long length; M_ASN1_D2I_Finish(a,NETSCAPE_SPKI_free,ASN1_F_D2I_NETSCAPE_SPKI); } -NETSCAPE_SPKI *NETSCAPE_SPKI_new() +NETSCAPE_SPKI *NETSCAPE_SPKI_new(void) { NETSCAPE_SPKI *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,NETSCAPE_SPKI); M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new); @@ -169,8 +155,7 @@ NETSCAPE_SPKI *NETSCAPE_SPKI_new() M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW); } -void NETSCAPE_SPKI_free(a) -NETSCAPE_SPKI *a; +void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a) { if (a == NULL) return; NETSCAPE_SPKAC_free(a->spkac); diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c index a9c390f88c..84d6f7ca4d 100644 --- a/src/lib/libcrypto/asn1/x_val.c +++ b/src/lib/libcrypto/asn1/x_val.c @@ -58,61 +58,52 @@ #include #include "cryptlib.h" -#include "asn1_mac.h" +#include +#include -/* ASN1err(ASN1_F_X509_VAL_NEW,ERR_R_MALLOC_FAILURE); - * ASN1err(ASN1_F_X509_VAL_FREE,ERR_R_MALLOC_FAILURE); - * ASN1err(ASN1_F_D2I_X509_VAL,ERR_R_MALLOC_FAILURE); - */ - -int i2d_X509_VAL(a,pp) -X509_VAL *a; -unsigned char **pp; +int i2d_X509_VAL(X509_VAL *a, unsigned char **pp) { M_ASN1_I2D_vars(a); - M_ASN1_I2D_len(a->notBefore,i2d_ASN1_UTCTIME); - M_ASN1_I2D_len(a->notAfter,i2d_ASN1_UTCTIME); + M_ASN1_I2D_len(a->notBefore,i2d_ASN1_TIME); + M_ASN1_I2D_len(a->notAfter,i2d_ASN1_TIME); M_ASN1_I2D_seq_total(); - M_ASN1_I2D_put(a->notBefore,i2d_ASN1_UTCTIME); - M_ASN1_I2D_put(a->notAfter,i2d_ASN1_UTCTIME); + M_ASN1_I2D_put(a->notBefore,i2d_ASN1_TIME); + M_ASN1_I2D_put(a->notAfter,i2d_ASN1_TIME); M_ASN1_I2D_finish(); } -X509_VAL *d2i_X509_VAL(a,pp,length) -X509_VAL **a; -unsigned char **pp; -long length; +X509_VAL *d2i_X509_VAL(X509_VAL **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,X509_VAL *,X509_VAL_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); - M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_UTCTIME); - M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_UTCTIME); + M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_TIME); + M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_TIME); M_ASN1_D2I_Finish(a,X509_VAL_free,ASN1_F_D2I_X509_VAL); } -X509_VAL *X509_VAL_new() +X509_VAL *X509_VAL_new(void) { X509_VAL *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_VAL); - M_ASN1_New(ret->notBefore,ASN1_UTCTIME_new); - M_ASN1_New(ret->notAfter,ASN1_UTCTIME_new); + M_ASN1_New(ret->notBefore,ASN1_TIME_new); + M_ASN1_New(ret->notAfter,ASN1_TIME_new); return(ret); M_ASN1_New_Error(ASN1_F_X509_VAL_NEW); } -void X509_VAL_free(a) -X509_VAL *a; +void X509_VAL_free(X509_VAL *a) { if (a == NULL) return; - ASN1_UTCTIME_free(a->notBefore); - ASN1_UTCTIME_free(a->notAfter); + ASN1_TIME_free(a->notBefore); + ASN1_TIME_free(a->notAfter); Free((char *)a); } diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c index bc466ce0f6..7abf6b2a6b 100644 --- a/src/lib/libcrypto/asn1/x_x509.c +++ b/src/lib/libcrypto/asn1/x_x509.c @@ -58,13 +58,9 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "asn1_mac.h" - -/* - * ASN1err(ASN1_F_D2I_X509,ASN1_R_LENGTH_MISMATCH); - * ASN1err(ASN1_F_X509_NEW,ASN1_R_BAD_GET_OBJECT); - */ +#include +#include +#include static ASN1_METHOD meth={ (int (*)()) i2d_X509, @@ -72,14 +68,12 @@ static ASN1_METHOD meth={ (char *(*)())X509_new, (void (*)()) X509_free}; -ASN1_METHOD *X509_asn1_meth() +ASN1_METHOD *X509_asn1_meth(void) { return(&meth); } -int i2d_X509(a,pp) -X509 *a; -unsigned char **pp; +int i2d_X509(X509 *a, unsigned char **pp) { M_ASN1_I2D_vars(a); @@ -96,10 +90,7 @@ unsigned char **pp; M_ASN1_I2D_finish(); } -X509 *d2i_X509(a,pp,length) -X509 **a; -unsigned char **pp; -long length; +X509 *d2i_X509(X509 **a, unsigned char **pp, long length) { M_ASN1_D2I_vars(a,X509 *,X509_new); @@ -108,15 +99,16 @@ long length; M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF); M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); -if (ret->name != NULL) Free(ret->name); -ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); + if (ret->name != NULL) Free(ret->name); + ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); } -X509 *X509_new() +X509 *X509_new(void) { X509 *ret=NULL; + ASN1_CTX c; M_ASN1_New_Malloc(ret,X509); ret->references=1; @@ -129,8 +121,7 @@ X509 *X509_new() M_ASN1_New_Error(ASN1_F_X509_NEW); } -void X509_free(a) -X509 *a; +void X509_free(X509 *a) { int i; @@ -149,9 +140,11 @@ X509 *a; } #endif + /* CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); */ X509_CINF_free(a->cert_info); X509_ALGOR_free(a->sig_alg); ASN1_BIT_STRING_free(a->signature); + if (a->name != NULL) Free(a->name); Free((char *)a); } diff --git a/src/lib/libcrypto/bf/Makefile.ssl b/src/lib/libcrypto/bf/Makefile.ssl index 236671f238..18bddda0db 100644 --- a/src/lib/libcrypto/bf/Makefile.ssl +++ b/src/lib/libcrypto/bf/Makefile.ssl @@ -8,9 +8,11 @@ CC= cc CPP= $(CC) -E INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -42,7 +44,7 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf @@ -61,27 +63,25 @@ asm/bx86-out.o: asm/bx86unix.cpp # bsdi asm/bx86bsdi.o: asm/bx86unix.cpp - $(CPP) -DBSDI asm/bx86unix.cpp | as -o asm/bx86bsdi.o + $(CPP) -DBSDI asm/bx86unix.cpp | sed 's/ :/:/' | as -o asm/bx86bsdi.o asm/bx86unix.cpp: - (cd asm; perl bf-586.pl cpp >bx86unix.cpp) + (cd asm; $(PERL) bf-586.pl cpp $(PROCESSOR) >bx86unix.cpp) files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/point.sh ../../doc/blowfish.doc blowfish.doc ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -93,15 +93,24 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f asm/bx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +bf_cfb64.o: ../../include/openssl/blowfish.h +bf_cfb64.o: ../../include/openssl/opensslconf.h bf_locl.h +bf_ecb.o: ../../include/openssl/blowfish.h ../../include/openssl/opensslconf.h +bf_ecb.o: ../../include/openssl/opensslv.h bf_locl.h +bf_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/opensslconf.h +bf_enc.o: bf_locl.h +bf_ofb64.o: ../../include/openssl/blowfish.h +bf_ofb64.o: ../../include/openssl/opensslconf.h bf_locl.h +bf_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/opensslconf.h +bf_skey.o: bf_locl.h bf_pi.h diff --git a/src/lib/libcrypto/bf/Makefile.uni b/src/lib/libcrypto/bf/Makefile.uni index 9ba5b0c854..f67e5ca23b 100644 --- a/src/lib/libcrypto/bf/Makefile.uni +++ b/src/lib/libcrypto/bf/Makefile.uni @@ -29,6 +29,7 @@ CFLAG= -O3 -fomit-frame-pointer CFLAGS=$(OPTS) $(CFLAG) CPP=$(CC) -E AS=as +RANLIB=ranlib # Assember version of bf_encrypt(). BF_ENC=bf_enc.o # normal C version @@ -105,9 +106,7 @@ test: all $(BLIB): $(LIBOBJ) /bin/rm -f $(BLIB) ar cr $(BLIB) $(LIBOBJ) - -if test -s /bin/ranlib; then /bin/ranlib $(BLIB); \ - else if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(BLIB); \ - else exit 0; fi; fi + $(RANLIB) $(BLIB) bftest: bftest.o $(BLIB) $(CC) $(CFLAGS) -o bftest bftest.o $(BLIB) @@ -142,25 +141,14 @@ install: $(BLIB) if test $(INSTALLTOP); then \ echo SSL style install; \ cp $(BLIB) $(INSTALLTOP)/lib; \ - if test -s /bin/ranlib; then \ - /bin/ranlib $(INSTALLTOP)/lib/$(BLIB); \ - else \ - if test -s /usr/bin/ranlib; then \ - /usr/bin/ranlib $(INSTALLTOP)/lib/$(BLIB); \ - fi; fi; \ + $(RANLIB) $(BLIB); \ chmod 644 $(INSTALLTOP)/lib/$(BLIB); \ cp blowfish.h $(INSTALLTOP)/include; \ chmod 644 $(INSTALLTOP)/include/blowfish.h; \ else \ echo Standalone install; \ cp $(BLIB) $(LIBDIR)/$(BLIB); \ - if test -s /bin/ranlib; then \ - /bin/ranlib $(LIBDIR)/$(BLIB); \ - else \ - if test -s /usr/bin/ranlib; then \ - /usr/bin/ranlib $(LIBDIR)/$(BLIB); \ - fi; \ - fi; \ + $(RANLIB) $(BLIB); \ chmod 644 $(LIBDIR)/$(BLIB); \ cp blowfish.h $(INCDIR)/blowfish.h; \ chmod 644 $(INCDIR)/blowfish.h; \ diff --git a/src/lib/libcrypto/bf/asm/bf-586.pl b/src/lib/libcrypto/bf/asm/bf-586.pl index 5c7ab14ab0..b556642c94 100644 --- a/src/lib/libcrypto/bf/asm/bf-586.pl +++ b/src/lib/libcrypto/bf/asm/bf-586.pl @@ -1,10 +1,10 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl push(@INC,"perlasm","../../perlasm"); require "x86asm.pl"; require "cbc.pl"; -&asm_init($ARGV[0],"bf-586.pl"); +&asm_init($ARGV[0],"bf-586.pl",$ARGV[$#ARGV] eq "386"); $BF_ROUNDS=16; $BF_OFF=($BF_ROUNDS+2)*4; diff --git a/src/lib/libcrypto/bf/asm/bf-686.pl b/src/lib/libcrypto/bf/asm/bf-686.pl index bed303d786..8e4c25f598 100644 --- a/src/lib/libcrypto/bf/asm/bf-686.pl +++ b/src/lib/libcrypto/bf/asm/bf-686.pl @@ -1,4 +1,3 @@ -#!/usr/bin/perl #!/usr/local/bin/perl push(@INC,"perlasm","../../perlasm"); diff --git a/src/lib/libcrypto/bf/asm/bx86unix.cpp b/src/lib/libcrypto/bf/asm/bx86unix.cpp deleted file mode 100644 index cdaa269378..0000000000 --- a/src/lib/libcrypto/bf/asm/bx86unix.cpp +++ /dev/null @@ -1,976 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define BF_encrypt _BF_encrypt -#define BF_decrypt _BF_decrypt -#define BF_cbc_encrypt _BF_cbc_encrypt - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by bf-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "bf-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl BF_encrypt - TYPE(BF_encrypt,@function) -BF_encrypt: - - pushl %ebp - pushl %ebx - movl 12(%esp), %ebx - movl 16(%esp), %ebp - pushl %esi - pushl %edi - /* Load the 2 words */ - movl (%ebx), %edi - movl 4(%ebx), %esi - xorl %eax, %eax - movl (%ebp), %ebx - xorl %ecx, %ecx - xorl %ebx, %edi - - /* Round 0 */ - movl 4(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 1 */ - movl 8(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 2 */ - movl 12(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 3 */ - movl 16(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 4 */ - movl 20(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 5 */ - movl 24(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 6 */ - movl 28(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 7 */ - movl 32(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 8 */ - movl 36(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 9 */ - movl 40(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 10 */ - movl 44(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 11 */ - movl 48(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 12 */ - movl 52(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 13 */ - movl 56(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 14 */ - movl 60(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 15 */ - movl 64(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - /* Load parameter 0 (16) enc=1 */ - movl 20(%esp), %eax - xorl %ebx, %edi - movl 68(%ebp), %edx - xorl %edx, %esi - movl %edi, 4(%eax) - movl %esi, (%eax) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.BF_encrypt_end: - SIZE(BF_encrypt,.BF_encrypt_end-BF_encrypt) -.ident "BF_encrypt" -.text - .align ALIGN -.globl BF_decrypt - TYPE(BF_decrypt,@function) -BF_decrypt: - - pushl %ebp - pushl %ebx - movl 12(%esp), %ebx - movl 16(%esp), %ebp - pushl %esi - pushl %edi - /* Load the 2 words */ - movl (%ebx), %edi - movl 4(%ebx), %esi - xorl %eax, %eax - movl 68(%ebp), %ebx - xorl %ecx, %ecx - xorl %ebx, %edi - - /* Round 16 */ - movl 64(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 15 */ - movl 60(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 14 */ - movl 56(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 13 */ - movl 52(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 12 */ - movl 48(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 11 */ - movl 44(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 10 */ - movl 40(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 9 */ - movl 36(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 8 */ - movl 32(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 7 */ - movl 28(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 6 */ - movl 24(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 5 */ - movl 20(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 4 */ - movl 16(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 3 */ - movl 12(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %edi - - /* Round 2 */ - movl 8(%ebp), %edx - movl %edi, %ebx - xorl %edx, %esi - shrl $16, %ebx - movl %edi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - xorl %eax, %eax - xorl %ebx, %esi - - /* Round 1 */ - movl 4(%ebp), %edx - movl %esi, %ebx - xorl %edx, %edi - shrl $16, %ebx - movl %esi, %edx - movb %bh, %al - andl $255, %ebx - movb %dh, %cl - andl $255, %edx - movl 72(%ebp,%eax,4),%eax - movl 1096(%ebp,%ebx,4),%ebx - addl %eax, %ebx - movl 2120(%ebp,%ecx,4),%eax - xorl %eax, %ebx - movl 3144(%ebp,%edx,4),%edx - addl %edx, %ebx - /* Load parameter 0 (1) enc=0 */ - movl 20(%esp), %eax - xorl %ebx, %edi - movl (%ebp), %edx - xorl %edx, %esi - movl %edi, 4(%eax) - movl %esi, (%eax) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.BF_decrypt_end: - SIZE(BF_decrypt,.BF_decrypt_end-BF_decrypt) -.ident "BF_decrypt" -.text - .align ALIGN -.globl BF_cbc_encrypt - TYPE(BF_cbc_encrypt,@function) -BF_cbc_encrypt: - - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - movl 28(%esp), %ebp - /* getting iv ptr from parameter 4 */ - movl 36(%esp), %ebx - movl (%ebx), %esi - movl 4(%ebx), %edi - pushl %edi - pushl %esi - pushl %edi - pushl %esi - movl %esp, %ebx - movl 36(%esp), %esi - movl 40(%esp), %edi - /* getting encrypt flag from parameter 5 */ - movl 56(%esp), %ecx - /* get and push parameter 3 */ - movl 48(%esp), %eax - pushl %eax - pushl %ebx - cmpl $0, %ecx - jz .L000decrypt - andl $4294967288, %ebp - movl 8(%esp), %eax - movl 12(%esp), %ebx - jz .L001encrypt_finish -.L002encrypt_loop: - movl (%esi), %ecx - movl 4(%esi), %edx - xorl %ecx, %eax - xorl %edx, %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call BF_encrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, (%edi) - movl %ebx, 4(%edi) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L002encrypt_loop -.L001encrypt_finish: - movl 52(%esp), %ebp - andl $7, %ebp - jz .L003finish - xorl %ecx, %ecx - xorl %edx, %edx - movl .L004cbc_enc_jmp_table(,%ebp,4),%ebp - jmp *%ebp -.L005ej7: - movb 6(%esi), %dh - sall $8, %edx -.L006ej6: - movb 5(%esi), %dh -.L007ej5: - movb 4(%esi), %dl -.L008ej4: - movl (%esi), %ecx - jmp .L009ejend -.L010ej3: - movb 2(%esi), %ch - sall $8, %ecx -.L011ej2: - movb 1(%esi), %ch -.L012ej1: - movb (%esi), %cl -.L009ejend: - xorl %ecx, %eax - xorl %edx, %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call BF_encrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, (%edi) - movl %ebx, 4(%edi) - jmp .L003finish -.align ALIGN -.L000decrypt: - andl $4294967288, %ebp - movl 16(%esp), %eax - movl 20(%esp), %ebx - jz .L013decrypt_finish -.L014decrypt_loop: - movl (%esi), %eax - movl 4(%esi), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call BF_decrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl 16(%esp), %ecx - movl 20(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx - movl %ecx, (%edi) - movl %edx, 4(%edi) - movl %eax, 16(%esp) - movl %ebx, 20(%esp) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L014decrypt_loop -.L013decrypt_finish: - movl 52(%esp), %ebp - andl $7, %ebp - jz .L003finish - movl (%esi), %eax - movl 4(%esi), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call BF_decrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl 16(%esp), %ecx - movl 20(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx -.L015dj7: - rorl $16, %edx - movb %dl, 6(%edi) - shrl $16, %edx -.L016dj6: - movb %dh, 5(%edi) -.L017dj5: - movb %dl, 4(%edi) -.L018dj4: - movl %ecx, (%edi) - jmp .L019djend -.L020dj3: - rorl $16, %ecx - movb %cl, 2(%edi) - sall $16, %ecx -.L021dj2: - movb %ch, 1(%esi) -.L022dj1: - movb %cl, (%esi) -.L019djend: - jmp .L003finish -.align ALIGN -.L003finish: - movl 60(%esp), %ecx - addl $24, %esp - movl %eax, (%ecx) - movl %ebx, 4(%ecx) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.align ALIGN -.L004cbc_enc_jmp_table: - .long 0 - .long .L012ej1 - .long .L011ej2 - .long .L010ej3 - .long .L008ej4 - .long .L007ej5 - .long .L006ej6 - .long .L005ej7 -.align ALIGN -.L023cbc_dec_jmp_table: - .long 0 - .long .L022dj1 - .long .L021dj2 - .long .L020dj3 - .long .L018dj4 - .long .L017dj5 - .long .L016dj6 - .long .L015dj7 -.BF_cbc_encrypt_end: - SIZE(BF_cbc_encrypt,.BF_cbc_encrypt_end-BF_cbc_encrypt) -.ident "desasm.pl" diff --git a/src/lib/libcrypto/bf/bf_cbc.c b/src/lib/libcrypto/bf/bf_cbc.c index e0fa9ad763..95d1cdcdf9 100644 --- a/src/lib/libcrypto/bf/bf_cbc.c +++ b/src/lib/libcrypto/bf/bf_cbc.c @@ -56,16 +56,11 @@ * [including the GNU Public Licence.] */ -#include "blowfish.h" +#include #include "bf_locl.h" -void BF_cbc_encrypt(in, out, length, ks, iv, encrypt) -unsigned char *in; -unsigned char *out; -long length; -BF_KEY *ks; -unsigned char *iv; -int encrypt; +void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, + BF_KEY *ks, unsigned char *iv, int encrypt) { register BF_LONG tin0,tin1; register BF_LONG tout0,tout1,xor0,xor1; diff --git a/src/lib/libcrypto/bf/bf_cfb64.c b/src/lib/libcrypto/bf/bf_cfb64.c index f9c66e7ced..1fb8905f49 100644 --- a/src/lib/libcrypto/bf/bf_cfb64.c +++ b/src/lib/libcrypto/bf/bf_cfb64.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "blowfish.h" +#include #include "bf_locl.h" /* The input and output encrypted as though 64bit cfb mode is being @@ -64,14 +64,8 @@ * 64bit block we have used is contained in *num; */ -void BF_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) -unsigned char *in; -unsigned char *out; -long length; -BF_KEY *schedule; -unsigned char *ivec; -int *num; -int encrypt; +void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, + BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt) { register BF_LONG v0,v1,t; register int n= *num; diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c index 6d16360bd9..9f8a24cdff 100644 --- a/src/lib/libcrypto/bf/bf_ecb.c +++ b/src/lib/libcrypto/bf/bf_ecb.c @@ -56,17 +56,18 @@ * [including the GNU Public Licence.] */ -#include "blowfish.h" +#include #include "bf_locl.h" +#include /* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) */ -char *BF_version="BlowFish part of SSLeay 0.9.0b 29-Jun-1998"; +const char *BF_version="BlowFish" OPENSSL_VERSION_PTEXT; -char *BF_options() +const char *BF_options(void) { #ifdef BF_PTR return("blowfish(ptr)"); @@ -77,11 +78,8 @@ char *BF_options() #endif } -void BF_ecb_encrypt(in, out, ks, encrypt) -unsigned char *in; -unsigned char *out; -BF_KEY *ks; -int encrypt; +void BF_ecb_encrypt(unsigned char *in, unsigned char *out, BF_KEY *ks, + int encrypt) { BF_LONG l,d[2]; diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c index 66a8604c59..ee01834561 100644 --- a/src/lib/libcrypto/bf/bf_enc.c +++ b/src/lib/libcrypto/bf/bf_enc.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "blowfish.h" +#include #include "bf_locl.h" /* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' @@ -65,14 +65,13 @@ */ #if (BF_ROUNDS != 16) && (BF_ROUNDS != 20) -If you set BF_ROUNDS to some value other than 16 or 20, you will have +#error If you set BF_ROUNDS to some value other than 16 or 20, you will have \ to modify the code. #endif -void BF_encrypt(data,key) -BF_LONG *data; -BF_KEY *key; +void BF_encrypt(BF_LONG *data, BF_KEY *key) { +#ifndef BF_PTR2 register BF_LONG l,r,*p,*s; p=key->P; @@ -107,14 +106,48 @@ BF_KEY *key; data[1]=l&0xffffffffL; data[0]=r&0xffffffffL; +#else + register BF_LONG l,r,t,*k; + + l=data[0]; + r=data[1]; + k=(BF_LONG*)key; + + l^=k[0]; + BF_ENC(r,l,k, 1); + BF_ENC(l,r,k, 2); + BF_ENC(r,l,k, 3); + BF_ENC(l,r,k, 4); + BF_ENC(r,l,k, 5); + BF_ENC(l,r,k, 6); + BF_ENC(r,l,k, 7); + BF_ENC(l,r,k, 8); + BF_ENC(r,l,k, 9); + BF_ENC(l,r,k,10); + BF_ENC(r,l,k,11); + BF_ENC(l,r,k,12); + BF_ENC(r,l,k,13); + BF_ENC(l,r,k,14); + BF_ENC(r,l,k,15); + BF_ENC(l,r,k,16); +#if BF_ROUNDS == 20 + BF_ENC(r,l,k,17); + BF_ENC(l,r,k,18); + BF_ENC(r,l,k,19); + BF_ENC(l,r,k,20); +#endif + r^=k[BF_ROUNDS+1]; + + data[1]=l&0xffffffffL; + data[0]=r&0xffffffffL; +#endif } #ifndef BF_DEFAULT_OPTIONS -void BF_decrypt(data,key) -BF_LONG *data; -BF_KEY *key; +void BF_decrypt(BF_LONG *data, BF_KEY *key) { +#ifndef BF_PTR2 register BF_LONG l,r,*p,*s; p=key->P; @@ -149,15 +182,45 @@ BF_KEY *key; data[1]=l&0xffffffffL; data[0]=r&0xffffffffL; +#else + register BF_LONG l,r,t,*k; + + l=data[0]; + r=data[1]; + k=(BF_LONG *)key; + + l^=k[BF_ROUNDS+1]; +#if BF_ROUNDS == 20 + BF_ENC(r,l,k,20); + BF_ENC(l,r,k,19); + BF_ENC(r,l,k,18); + BF_ENC(l,r,k,17); +#endif + BF_ENC(r,l,k,16); + BF_ENC(l,r,k,15); + BF_ENC(r,l,k,14); + BF_ENC(l,r,k,13); + BF_ENC(r,l,k,12); + BF_ENC(l,r,k,11); + BF_ENC(r,l,k,10); + BF_ENC(l,r,k, 9); + BF_ENC(r,l,k, 8); + BF_ENC(l,r,k, 7); + BF_ENC(r,l,k, 6); + BF_ENC(l,r,k, 5); + BF_ENC(r,l,k, 4); + BF_ENC(l,r,k, 3); + BF_ENC(r,l,k, 2); + BF_ENC(l,r,k, 1); + r^=k[0]; + + data[1]=l&0xffffffffL; + data[0]=r&0xffffffffL; +#endif } -void BF_cbc_encrypt(in, out, length, ks, iv, encrypt) -unsigned char *in; -unsigned char *out; -long length; -BF_KEY *ks; -unsigned char *iv; -int encrypt; +void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length, + BF_KEY *ks, unsigned char *iv, int encrypt) { register BF_LONG tin0,tin1; register BF_LONG tout0,tout1,xor0,xor1; diff --git a/src/lib/libcrypto/bf/bf_locl.h b/src/lib/libcrypto/bf/bf_locl.h new file mode 100644 index 0000000000..05756b5d3b --- /dev/null +++ b/src/lib/libcrypto/bf/bf_locl.h @@ -0,0 +1,219 @@ +/* crypto/bf/bf_locl.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_BF_LOCL_H +#define HEADER_BF_LOCL_H +#include /* BF_PTR, BF_PTR2 */ + +#undef c2l +#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ + l|=((unsigned long)(*((c)++)))<< 8L, \ + l|=((unsigned long)(*((c)++)))<<16L, \ + l|=((unsigned long)(*((c)++)))<<24L) + +/* NOTE - c is not incremented as per c2l */ +#undef c2ln +#define c2ln(c,l1,l2,n) { \ + c+=n; \ + l1=l2=0; \ + switch (n) { \ + case 8: l2 =((unsigned long)(*(--(c))))<<24L; \ + case 7: l2|=((unsigned long)(*(--(c))))<<16L; \ + case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \ + case 5: l2|=((unsigned long)(*(--(c)))); \ + case 4: l1 =((unsigned long)(*(--(c))))<<24L; \ + case 3: l1|=((unsigned long)(*(--(c))))<<16L; \ + case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \ + case 1: l1|=((unsigned long)(*(--(c)))); \ + } \ + } + +#undef l2c +#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ + *((c)++)=(unsigned char)(((l)>>24L)&0xff)) + +/* NOTE - c is not incremented as per l2c */ +#undef l2cn +#define l2cn(l1,l2,c,n) { \ + c+=n; \ + switch (n) { \ + case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ + case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ + case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ + case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ + case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ + case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ + case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ + case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ + } \ + } + +/* NOTE - c is not incremented as per n2l */ +#define n2ln(c,l1,l2,n) { \ + c+=n; \ + l1=l2=0; \ + switch (n) { \ + case 8: l2 =((unsigned long)(*(--(c)))) ; \ + case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ + case 6: l2|=((unsigned long)(*(--(c))))<<16; \ + case 5: l2|=((unsigned long)(*(--(c))))<<24; \ + case 4: l1 =((unsigned long)(*(--(c)))) ; \ + case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ + case 2: l1|=((unsigned long)(*(--(c))))<<16; \ + case 1: l1|=((unsigned long)(*(--(c))))<<24; \ + } \ + } + +/* NOTE - c is not incremented as per l2n */ +#define l2nn(l1,l2,c,n) { \ + c+=n; \ + switch (n) { \ + case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ + case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ + case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ + case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ + case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ + case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ + case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ + case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ + } \ + } + +#undef n2l +#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \ + l|=((unsigned long)(*((c)++)))<<16L, \ + l|=((unsigned long)(*((c)++)))<< 8L, \ + l|=((unsigned long)(*((c)++)))) + +#undef l2n +#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ + *((c)++)=(unsigned char)(((l) )&0xff)) + +/* This is actually a big endian algorithm, the most significate byte + * is used to lookup array 0 */ + +#if defined(BF_PTR2) + +/* + * This is basically a special Intel version. Point is that Intel + * doesn't have many registers, but offers a reach choice of addressing + * modes. So we spare some registers by directly traversing BF_KEY + * structure and hiring the most decorated addressing mode. The code + * generated by EGCS is *perfectly* competitive with assembler + * implementation! + */ +#define BF_ENC(LL,R,KEY,Pi) (\ + LL^=KEY[Pi], \ + t= KEY[BF_ROUNDS+2 + 0 + ((R>>24)&0xFF)], \ + t+= KEY[BF_ROUNDS+2 + 256 + ((R>>16)&0xFF)], \ + t^= KEY[BF_ROUNDS+2 + 512 + ((R>>8 )&0xFF)], \ + t+= KEY[BF_ROUNDS+2 + 768 + ((R )&0xFF)], \ + LL^=t \ + ) + +#elif defined(BF_PTR) + +#ifndef BF_LONG_LOG2 +#define BF_LONG_LOG2 2 /* default to BF_LONG being 32 bits */ +#endif +#define BF_M (0xFF<>BF_i)&BF_M gets folded into a single instruction, namely + * rlwinm. So let'em double-check if their compiler does it. + */ + +#define BF_ENC(LL,R,S,P) ( \ + LL^=P, \ + LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \ + *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \ + *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \ + *(BF_LONG *)((unsigned char *)&(S[768])+((R<>24)&0xff)] + \ + S[0x0100+((int)(R>>16)&0xff)])^ \ + S[0x0200+((int)(R>> 8)&0xff)])+ \ + S[0x0300+((int)(R )&0xff)])&0xffffffffL \ + ) +#endif + +#endif diff --git a/src/lib/libcrypto/bf/bf_locl.org b/src/lib/libcrypto/bf/bf_locl.org deleted file mode 100644 index a5663de8ca..0000000000 --- a/src/lib/libcrypto/bf/bf_locl.org +++ /dev/null @@ -1,242 +0,0 @@ -/* crypto/bf/bf_locl.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify bf_locl.org since bf_locl.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - -/* Special defines which change the way the code is built depending on the - CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find - even newer MIPS CPU's, but at the moment one size fits all for - optimization options. Older Sparc's work better with only UNROLL, but - there's no way to tell at compile time what it is you're running on */ - -#if defined( sun ) /* Newer Sparc's */ -# define BF_PTR -#elif defined( __ultrix ) /* Older MIPS */ -# define BF_PTR -#elif defined( __osf1__ ) /* Alpha */ - /* None */ -#elif defined ( _AIX ) /* RS6000 */ - /* Unknown */ -#elif defined( __hpux ) /* HP-PA */ - /* None */ -#elif defined( __aux ) /* 68K */ - /* Unknown */ -#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */ - /* Unknown */ -#elif defined( __sgi ) /* Newer MIPS */ -# define BF_PTR -#elif defined( i386 ) /* x86 boxes, should be gcc */ -#elif defined( _MSC_VER ) /* x86 boxes, Visual C */ -#endif /* Systems-specific speed defines */ - -#undef c2l -#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ - l|=((unsigned long)(*((c)++)))<< 8L, \ - l|=((unsigned long)(*((c)++)))<<16L, \ - l|=((unsigned long)(*((c)++)))<<24L) - -/* NOTE - c is not incremented as per c2l */ -#undef c2ln -#define c2ln(c,l1,l2,n) { \ - c+=n; \ - l1=l2=0; \ - switch (n) { \ - case 8: l2 =((unsigned long)(*(--(c))))<<24L; \ - case 7: l2|=((unsigned long)(*(--(c))))<<16L; \ - case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \ - case 5: l2|=((unsigned long)(*(--(c)))); \ - case 4: l1 =((unsigned long)(*(--(c))))<<24L; \ - case 3: l1|=((unsigned long)(*(--(c))))<<16L; \ - case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \ - case 1: l1|=((unsigned long)(*(--(c)))); \ - } \ - } - -#undef l2c -#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ - *((c)++)=(unsigned char)(((l)>>24L)&0xff)) - -/* NOTE - c is not incremented as per l2c */ -#undef l2cn -#define l2cn(l1,l2,c,n) { \ - c+=n; \ - switch (n) { \ - case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ - case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ - case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ - case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ - case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ - case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ - case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ - case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ - } \ - } - -/* NOTE - c is not incremented as per n2l */ -#define n2ln(c,l1,l2,n) { \ - c+=n; \ - l1=l2=0; \ - switch (n) { \ - case 8: l2 =((unsigned long)(*(--(c)))) ; \ - case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ - case 6: l2|=((unsigned long)(*(--(c))))<<16; \ - case 5: l2|=((unsigned long)(*(--(c))))<<24; \ - case 4: l1 =((unsigned long)(*(--(c)))) ; \ - case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ - case 2: l1|=((unsigned long)(*(--(c))))<<16; \ - case 1: l1|=((unsigned long)(*(--(c))))<<24; \ - } \ - } - -/* NOTE - c is not incremented as per l2n */ -#define l2nn(l1,l2,c,n) { \ - c+=n; \ - switch (n) { \ - case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ - case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ - case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ - case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ - case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ - case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ - case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ - case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ - } \ - } - -#undef n2l -#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \ - l|=((unsigned long)(*((c)++)))<<16L, \ - l|=((unsigned long)(*((c)++)))<< 8L, \ - l|=((unsigned long)(*((c)++)))) - -#undef l2n -#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ - *((c)++)=(unsigned char)(((l) )&0xff)) - -/* This is actually a big endian algorithm, the most significate byte - * is used to lookup array 0 */ - -/* use BF_PTR2 for intel boxes, - * BF_PTR for sparc and MIPS/SGI - * use nothing for Alpha and HP. - */ -#if !defined(BF_PTR) && !defined(BF_PTR2) -#undef BF_PTR -#endif - -#define BF_M 0x3fc -#define BF_0 22L -#define BF_1 14L -#define BF_2 6L -#define BF_3 2L /* left shift */ - -#if defined(BF_PTR2) - -/* This is basically a special pentium verson */ -#define BF_ENC(LL,R,S,P) \ - { \ - BF_LONG t,u,v; \ - u=R>>BF_0; \ - v=R>>BF_1; \ - u&=BF_M; \ - v&=BF_M; \ - t= *(BF_LONG *)((unsigned char *)&(S[ 0])+u); \ - u=R>>BF_2; \ - t+= *(BF_LONG *)((unsigned char *)&(S[256])+v); \ - v=R<>BF_0)&BF_M))+ \ - *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \ - *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \ - *(BF_LONG *)((unsigned char *)&(S[768])+((R<>24L) ] + \ - S[0x0100+((int)(R>>16L)&0xff)])^ \ - S[0x0200+((int)(R>> 8L)&0xff)])+ \ - S[0x0300+((int)(R )&0xff)])&0xffffffffL; -#endif diff --git a/src/lib/libcrypto/bf/bf_ofb64.c b/src/lib/libcrypto/bf/bf_ofb64.c index 5d844ac760..8ceb8d9bda 100644 --- a/src/lib/libcrypto/bf/bf_ofb64.c +++ b/src/lib/libcrypto/bf/bf_ofb64.c @@ -56,20 +56,15 @@ * [including the GNU Public Licence.] */ -#include "blowfish.h" +#include #include "bf_locl.h" /* The input and output encrypted as though 64bit ofb mode is being * used. The extra state information to record how much of the * 64bit block we have used is contained in *num; */ -void BF_ofb64_encrypt(in, out, length, schedule, ivec, num) -unsigned char *in; -unsigned char *out; -long length; -BF_KEY *schedule; -unsigned char *ivec; -int *num; +void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, + BF_KEY *schedule, unsigned char *ivec, int *num) { register BF_LONG v0,v1,t; register int n= *num; diff --git a/src/lib/libcrypto/bf/bf_opts.c b/src/lib/libcrypto/bf/bf_opts.c index 5cfa60c537..5f330cc53c 100644 --- a/src/lib/libcrypto/bf/bf_opts.c +++ b/src/lib/libcrypto/bf/bf_opts.c @@ -59,19 +59,17 @@ /* define PART1, PART2, PART3 or PART4 to build only with a few of the options. * This is for machines with 64k code segment size restrictions. */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include -#ifndef MSDOS -#include -#else -#include -extern void exit(); -#endif + +#include +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include -#ifndef VMS #ifndef _IRIX #include #endif @@ -79,25 +77,26 @@ extern void exit(); #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "blowfish.h" +#include #define BF_DEFAULT_OPTIONS @@ -126,11 +125,7 @@ struct tms { #ifndef HZ # ifndef CLK_TCK # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ -# ifndef VMS -# define HZ 100.0 -# else /* VMS */ -# define HZ 100.0 -# endif +# define HZ 100.0 # else /* _BSD_CLK_TCK_ */ # define HZ ((double)_BSD_CLK_TCK_) # endif @@ -142,12 +137,7 @@ struct tms { #define BUFSIZE ((long)1024) long run=0; -#ifndef NOPROTO double Time_F(int s); -#else -double Time_F(); -#endif - #ifdef SIGALRM #if defined(__STDC__) || defined(sgi) #define SIGRETTYPE void @@ -155,14 +145,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -175,8 +159,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -237,9 +220,7 @@ int s; fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ tm[index]*8,1.0e6/tm[index]); -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; diff --git a/src/lib/libcrypto/bf/bf_skey.c b/src/lib/libcrypto/bf/bf_skey.c index 86574c0acc..eefa8e6f51 100644 --- a/src/lib/libcrypto/bf/bf_skey.c +++ b/src/lib/libcrypto/bf/bf_skey.c @@ -58,14 +58,11 @@ #include #include -#include "blowfish.h" +#include #include "bf_locl.h" #include "bf_pi.h" -void BF_set_key(key,len,data) -BF_KEY *key; -int len; -unsigned char *data; +void BF_set_key(BF_KEY *key, int len, unsigned char *data) { int i; BF_LONG *p,ri,in[2]; diff --git a/src/lib/libcrypto/bf/bfs.cpp b/src/lib/libcrypto/bf/bfs.cpp index 272ed2f978..d74c457760 100644 --- a/src/lib/libcrypto/bf/bfs.cpp +++ b/src/lib/libcrypto/bf/bfs.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include #include -#include "blowfish.h" +#include void main(int argc,char *argv[]) { diff --git a/src/lib/libcrypto/bf/bfspeed.c b/src/lib/libcrypto/bf/bfspeed.c index 640d820dd3..9b893e92cc 100644 --- a/src/lib/libcrypto/bf/bfspeed.c +++ b/src/lib/libcrypto/bf/bfspeed.c @@ -59,19 +59,17 @@ /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include -#ifndef MSDOS -#include -#else -#include -extern int exit(); -#endif + +#include +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include -#ifndef VMS #ifndef _IRIX #include #endif @@ -79,34 +77,31 @@ extern int exit(); #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "blowfish.h" +#include /* The following if from times(3) man page. It may need to be changed */ #ifndef HZ #ifndef CLK_TCK -#ifndef VMS -#define HZ 100.0 -#else /* VMS */ #define HZ 100.0 -#endif #else /* CLK_TCK */ #define HZ ((double)CLK_TCK) #endif @@ -115,12 +110,7 @@ struct tms { #define BUFSIZE ((long)1024) long run=0; -#ifndef NOPROTO double Time_F(int s); -#else -double Time_F(); -#endif - #ifdef SIGALRM #if defined(__STDC__) || defined(sgi) || defined(_AIX) #define SIGRETTYPE void @@ -128,14 +118,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -148,8 +132,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -185,9 +168,7 @@ int s; #endif } -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; diff --git a/src/lib/libcrypto/bf/bftest.c b/src/lib/libcrypto/bf/bftest.c index 9266cf813a..6ecd2609a9 100644 --- a/src/lib/libcrypto/bf/bftest.c +++ b/src/lib/libcrypto/bf/bftest.c @@ -62,7 +62,19 @@ #include #include #include -#include "blowfish.h" + +#ifdef NO_BF +int main(int argc, char *argv[]) +{ + printf("No BF support\n"); + return(0); +} +#else +#include + +#ifdef CHARSET_EBCDIC +#include +#endif char *bf_key[2]={ "abcdefghijklmnopqrstuvwxyz", @@ -252,17 +264,9 @@ unsigned char key_out[KEY_TEST_NUM][8]={ {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80}, }; -#ifndef NOPROTO static int test(void ); static int print_test_data(void ); -#else -static int test(); -static int print_test_data(); -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int ret; @@ -275,7 +279,7 @@ char *argv[]; return(0); } -static int print_test_data() +static int print_test_data(void) { unsigned int i,j; @@ -304,7 +308,7 @@ static int print_test_data() printf("c="); for (j=0; j<8; j++) printf("%02X",key_out[i][j]); - printf(" k[%2d]=",i+1); + printf(" k[%2u]=",i+1); for (j=0; j + */ +#else +#define BF_LONG unsigned int +#endif #define BF_ROUNDS 16 #define BF_BLOCK 8 @@ -81,7 +102,6 @@ typedef struct bf_key_st BF_LONG S[4*256]; } BF_KEY; -#ifndef NOPROTO void BF_set_key(BF_KEY *key, int len, unsigned char *data); void BF_ecb_encrypt(unsigned char *in,unsigned char *out,BF_KEY *key, @@ -94,20 +114,7 @@ void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, BF_KEY *schedule, unsigned char *ivec, int *num, int enc); void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, BF_KEY *schedule, unsigned char *ivec, int *num); -char *BF_options(void); - -#else - -void BF_set_key(); -void BF_ecb_encrypt(); -void BF_encrypt(); -void BF_decrypt(); -void BF_cbc_encrypt(); -void BF_cfb64_encrypt(); -void BF_ofb64_encrypt(); -char *BF_options(); - -#endif +const char *BF_options(void); #ifdef __cplusplus } diff --git a/src/lib/libcrypto/bio/Makefile.ssl b/src/lib/libcrypto/bio/Makefile.ssl index 42e11e1c94..f54c7ee1f0 100644 --- a/src/lib/libcrypto/bio/Makefile.ssl +++ b/src/lib/libcrypto/bio/Makefile.ssl @@ -7,36 +7,36 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=bio -ERRC=bio_err GENERAL=Makefile TEST= APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= bio_lib.c bio_cb.c $(ERRC).c \ +LIBSRC= bio_lib.c bio_cb.c bio_err.c \ bss_mem.c bss_null.c bss_fd.c \ bss_file.c bss_sock.c bss_conn.c \ bf_null.c bf_buff.c b_print.c b_dump.c \ - b_sock.c bss_acpt.c bf_nbio.c -LIBOBJ= bio_lib.o bio_cb.o $(ERRC).o \ + b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c +LIBOBJ= bio_lib.o bio_cb.o bio_err.o \ bss_mem.o bss_null.o bss_fd.o \ bss_file.o bss_sock.o bss_conn.o \ bf_null.o bf_buff.o b_print.o b_dump.o \ - b_sock.o bss_acpt.o bf_nbio.o + b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o SRC= $(LIBSRC) -EXHEADER= bio.h bss_file.c -HEADER= $(EXHEADER) +EXHEADER= bio.h +HEADER= bss_file.c $(EXHEADER) ALL= $(GENERAL) $(SRC) $(HEADER) @@ -47,24 +47,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: - @for i in $(EXHEADER) bss_file.c ; \ + @for i in $(EXHEADER); \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -76,17 +75,136 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +b_dump.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +b_dump.o: ../../include/openssl/stack.h ../cryptlib.h +b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +b_print.o: ../../include/openssl/stack.h ../cryptlib.h +b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +b_sock.o: ../../include/openssl/stack.h ../cryptlib.h +bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bf_buff.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bf_buff.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bf_buff.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bf_buff.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bf_buff.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bf_buff.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bf_buff.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +bf_buff.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +bf_buff.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +bf_buff.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +bf_buff.o: ../../include/openssl/stack.h ../cryptlib.h +bf_nbio.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bf_nbio.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bf_nbio.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bf_nbio.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bf_nbio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bf_nbio.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bf_nbio.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bf_nbio.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bf_nbio.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +bf_nbio.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +bf_nbio.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +bf_nbio.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +bf_nbio.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +bf_nbio.o: ../cryptlib.h +bf_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bf_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bf_null.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bf_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bf_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bf_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bf_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bf_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bf_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bf_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +bf_null.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +bf_null.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +bf_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +bf_null.o: ../../include/openssl/stack.h ../cryptlib.h +bio_cb.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bio_cb.o: ../../include/openssl/stack.h ../cryptlib.h +bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h +bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h +bio_err.o: ../../include/openssl/stack.h +bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bio_lib.o: ../../include/openssl/stack.h ../cryptlib.h +bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_acpt.o: ../../include/openssl/opensslconf.h +bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_acpt.o: ../cryptlib.h +bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h +bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h +bss_bio.o: ../../include/openssl/stack.h +bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_conn.o: ../../include/openssl/opensslconf.h +bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_conn.o: ../cryptlib.h +bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bss_fd.o: ../../include/openssl/stack.h ../cryptlib.h bss_sock.c +bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_file.o: ../../include/openssl/opensslconf.h +bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_file.o: ../cryptlib.h +bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bss_log.o: ../../include/openssl/stack.h ../cryptlib.h +bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +bss_mem.o: ../../include/openssl/stack.h ../cryptlib.h +bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_null.o: ../../include/openssl/opensslconf.h +bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_null.o: ../cryptlib.h +bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +bss_sock.o: ../../include/openssl/opensslconf.h +bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bss_sock.o: ../cryptlib.h diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c index db84ad3d47..a7cd828978 100644 --- a/src/lib/libcrypto/bio/b_dump.c +++ b/src/lib/libcrypto/bio/b_dump.c @@ -62,15 +62,12 @@ #include #include "cryptlib.h" -#include "bio.h" +#include #define TRUNCATE #define DUMP_WIDTH 16 -int BIO_dump(bio,s,len) -BIO *bio; -char *s; -int len; +int BIO_dump(BIO *bio, const char *s, int len) { int ret=0; char buf[160+1],tmp[20]; @@ -105,7 +102,13 @@ int len; if (((i*DUMP_WIDTH)+j)>=len) break; ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; +#ifndef CHARSET_EBCDIC sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); +#else + sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) + ? os_toebcdic[ch] + : '.'); +#endif strcat(buf,tmp); } strcat(buf,"\n"); diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index cdadeb839a..f448004298 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/lib/libcrypto/bio/b_print.c @@ -61,32 +61,27 @@ */ #include +#include #include "cryptlib.h" -#include "bio.h" +#include -int BIO_printf ( VAR_PLIST( BIO *, bio ) ) -VAR_ALIST +int BIO_printf (BIO *bio, ...) { - VAR_BDEFN(args, BIO *, bio); + va_list args; char *format; int ret; MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */ - VAR_INIT(args, BIO *, bio); - VAR_ARG(args, char *, format); + va_start(args, bio); + format=va_arg(args, char *); hugebuf[0]='\0'; -/* no-one uses _doprnt anymore and it appears to be broken under SunOS 4.1.4 */ -#if 0 && defined(sun) && !defined(VAR_ANSI) /**/ - _doprnt(hugebuf,format,args); -#else /* !sun */ vsprintf(hugebuf,format,args); -#endif /* sun */ ret=BIO_write(bio,hugebuf,strlen(hugebuf)); - VAR_END( args ); + va_end(args); return(ret); } diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index a45909527c..d29b29ff8b 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c @@ -63,9 +63,7 @@ #include #define USE_SOCKETS #include "cryptlib.h" -#include "bio.h" - -/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ +#include #ifdef WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ @@ -96,21 +94,14 @@ static struct ghbn_cache_st unsigned long order; } ghbn_cache[GHBN_NUM]; -#ifndef NOPROTO -static int get_ip(char *str,unsigned char *ip); +static int get_ip(const char *str,unsigned char *ip); static void ghbn_free(struct hostent *a); static struct hostent *ghbn_dup(struct hostent *a); -#else -static int get_ip(); -static void ghbn_free(); -static struct hostent *ghbn_dup(); -#endif - -int BIO_get_host_ip(str,ip) -char *str; -unsigned char *ip; +int BIO_get_host_ip(const char *str, unsigned char *ip) { int i; + int err = 1; + int locked = 0; struct hostent *he; i=get_ip(str,ip); @@ -118,37 +109,45 @@ unsigned char *ip; if (i < 0) { BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); - ERR_add_error_data(2,"host=",str); - return(0); + goto err; } - else - { /* do a gethostbyname */ - if (!BIO_sock_init()) return(0); - he=BIO_gethostbyname(str); - if (he == NULL) - { - BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); - ERR_add_error_data(2,"host=",str); - return(0); - } + /* do a gethostbyname */ + if (!BIO_sock_init()) + return(0); /* don't generate another error code here */ - /* cast to short because of win16 winsock definition */ - if ((short)he->h_addrtype != AF_INET) - { - BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); - ERR_add_error_data(2,"host=",str); - return(0); - } - for (i=0; i<4; i++) - ip[i]=he->h_addr_list[0][i]; + CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); + locked = 1; + he=BIO_gethostbyname(str); + if (he == NULL) + { + BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP); + goto err; } - return(1); + + /* cast to short because of win16 winsock definition */ + if ((short)he->h_addrtype != AF_INET) + { + BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); + goto err; + } + for (i=0; i<4; i++) + ip[i]=he->h_addr_list[0][i]; + err = 0; + + err: + if (locked) + CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); + if (err) + { + ERR_add_error_data(2,"host=",str); + return 0; + } + else + return 1; } -int BIO_get_port(str,port_ptr) -char *str; -short *port_ptr; +int BIO_get_port(const char *str, unsigned short *port_ptr) { int i; struct servent *s; @@ -163,8 +162,12 @@ short *port_ptr; *port_ptr=(unsigned short)i; else { - s=getservbyname(str,"tcp"); - if (s == NULL) + CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); + s=getservbyname(str,"tcp"); + if(s != NULL) + *port_ptr=ntohs((unsigned short)s->s_port); + CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); + if(s == NULL) { if (strcmp(str,"http") == 0) *port_ptr=80; @@ -190,31 +193,30 @@ short *port_ptr; ERR_add_error_data(3,"service='",str,"'"); return(0); } - return(1); } - *port_ptr=htons((unsigned short)s->s_port); } return(1); } -int BIO_sock_error(sock) -int sock; +int BIO_sock_error(int sock) { - int j,i,size; + int j,i; + int size; size=sizeof(int); - - i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,&size); + /* Note: under Windows the third parameter is of type (char *) + * whereas under other systems it is (void *) if you don't have + * a cast it will choke the compiler: if you do have a cast then + * you can either go for (char *) or (void *). + */ + i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size); if (i < 0) return(1); else return(j); } -long BIO_ghbn_ctrl(cmd,iarg,parg) -int cmd; -int iarg; -char *parg; +long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) { int i; char **p; @@ -223,13 +225,13 @@ char *parg; { case BIO_GHBN_CTRL_HITS: return(BIO_ghbn_hits); - break; + /* break; */ case BIO_GHBN_CTRL_MISSES: return(BIO_ghbn_miss); - break; + /* break; */ case BIO_GHBN_CTRL_CACHE_SIZE: return(GHBN_NUM); - break; + /* break; */ case BIO_GHBN_CTRL_GET_ENTRY: if ((iarg >= 0) && (iarg 0)) @@ -241,7 +243,7 @@ char *parg; return(1); } return(0); - break; + /* break; */ case BIO_GHBN_CTRL_FLUSH: for (i=0; ih_aliases[i] != NULL; i++) ; i++; - ret->h_aliases=(char **)malloc(sizeof(char *)*i); - memset(ret->h_aliases,0,sizeof(char *)*i); - if (ret == NULL) goto err; + ret->h_aliases = (char **)Malloc(i*sizeof(char *)); + if (ret->h_aliases == NULL) + goto err; + memset(ret->h_aliases, 0, i*sizeof(char *)); for (i=0; a->h_addr_list[i] != NULL; i++) ; i++; - ret->h_addr_list=(char **)malloc(sizeof(char *)*i); - memset(ret->h_addr_list,0,sizeof(char *)*i); - if (ret->h_addr_list == NULL) goto err; + ret->h_addr_list=(char **)Malloc(i*sizeof(char *)); + if (ret->h_addr_list == NULL) + goto err; + memset(ret->h_addr_list, 0, i*sizeof(char *)); j=strlen(a->h_name)+1; - if ((ret->h_name=malloc(j)) == NULL) goto err; - memcpy((char *)ret->h_name,a->h_name,j); + if ((ret->h_name=Malloc(j)) == NULL) goto err; + memcpy((char *)ret->h_name,a->h_name,j+1); for (i=0; a->h_aliases[i] != NULL; i++) { j=strlen(a->h_aliases[i])+1; - if ((ret->h_aliases[i]=malloc(j)) == NULL) goto err; - memcpy(ret->h_aliases[i],a->h_aliases[i],j); + if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err; + memcpy(ret->h_aliases[i],a->h_aliases[i],j+1); } ret->h_length=a->h_length; ret->h_addrtype=a->h_addrtype; for (i=0; a->h_addr_list[i] != NULL; i++) { - if ((ret->h_addr_list[i]=malloc(a->h_length)) == NULL) + if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL) goto err; memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); } - return(ret); + if (0) + { err: - if (ret != NULL) - ghbn_free(ret); - return(NULL); + if (ret != NULL) + ghbn_free(ret); + ret=NULL; + } + MemCheck_on(); + return(ret); } -static void ghbn_free(a) -struct hostent *a; +static void ghbn_free(struct hostent *a) { int i; + if(a == NULL) + return; + if (a->h_aliases != NULL) { for (i=0; a->h_aliases[i] != NULL; i++) - free(a->h_aliases[i]); - free(a->h_aliases); + Free(a->h_aliases[i]); + Free(a->h_aliases); } if (a->h_addr_list != NULL) { for (i=0; a->h_addr_list[i] != NULL; i++) - free(a->h_addr_list[i]); - free(a->h_addr_list); + Free(a->h_addr_list[i]); + Free(a->h_addr_list); } - if (a->h_name != NULL) free((char *)a->h_name); - free(a); + if (a->h_name != NULL) Free((char *)a->h_name); + Free(a); } -struct hostent *BIO_gethostbyname(name) -char *name; +struct hostent *BIO_gethostbyname(const char *name) { struct hostent *ret; int i,lowi=0,j; @@ -330,7 +339,12 @@ char *name; /* return(gethostbyname(name)); */ - CRYPTO_w_lock(CRYPTO_LOCK_BIO_GETHOSTBYNAME); +#if 0 /* It doesn't make sense to use locking here: The function interface + * is not thread-safe, because threads can never be sure when + * some other thread destroys the data they were given a pointer to. + */ + CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); +#endif j=strlen(name); if (j < 128) { @@ -356,15 +370,29 @@ char *name; BIO_ghbn_miss++; ret=gethostbyname(name); - if (ret == NULL) return(NULL); - if (j > 128) return(ret); /* too big to cache */ + if (ret == NULL) + goto end; + if (j > 128) /* too big to cache */ + { +#if 0 /* If we were trying to make this function thread-safe (which + * is bound to fail), we'd have to give up in this case + * (or allocate more memory). */ + ret = NULL; +#endif + goto end; + } /* else add to cache */ if (ghbn_cache[lowi].ent != NULL) - ghbn_free(ghbn_cache[lowi].ent); + ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */ + ghbn_cache[lowi].name[0] = '\0'; + if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL) + { + BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE); + goto end; + } strncpy(ghbn_cache[lowi].name,name,128); - ghbn_cache[lowi].ent=ghbn_dup(ret); ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits; } else @@ -373,11 +401,14 @@ char *name; ret= ghbn_cache[i].ent; ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; } - CRYPTO_w_unlock(CRYPTO_LOCK_BIO_GETHOSTBYNAME); +end: +#if 0 + CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); +#endif return(ret); } -int BIO_sock_init() +int BIO_sock_init(void) { #ifdef WINDOWS static struct WSAData wsa_state; @@ -403,7 +434,7 @@ int BIO_sock_init() return(1); } -void BIO_sock_cleanup() +void BIO_sock_cleanup(void) { #ifdef WINDOWS if (wsa_init_done) @@ -415,10 +446,9 @@ void BIO_sock_cleanup() #endif } -int BIO_socket_ioctl(fd,type,arg) -int fd; -long type; -unsigned long *arg; +#if !defined(VMS) || __VMS_VER >= 70000000 + +int BIO_socket_ioctl(int fd, long type, unsigned long *arg) { int i; @@ -427,12 +457,11 @@ unsigned long *arg; SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error()); return(i); } +#endif /* __VMS_VER */ /* The reason I have implemented this instead of using sscanf is because * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ -static int get_ip(str,ip) -char *str; -unsigned char ip[4]; +static int get_ip(const char *str, unsigned char ip[4]) { unsigned int tmp[4]; int num=0,c,ok=0; @@ -467,16 +496,17 @@ unsigned char ip[4]; return(1); } -int BIO_get_accept_socket(host) -char *host; +int BIO_get_accept_socket(char *host, int bind_mode) { int ret=0; - struct sockaddr_in server; - int s= -1; + struct sockaddr_in server,client; + int s= -1,cs; unsigned char ip[4]; - short port; - char *str,*h,*p,*e; + unsigned short port; + char *str,*e; + const char *h,*p; unsigned long l; + int err_num; if (!BIO_sock_init()) return(INVALID_SOCKET); @@ -508,7 +538,7 @@ char *host; memset((char *)&server,0,sizeof(server)); server.sin_family=AF_INET; - server.sin_port=htons((unsigned short)port); + server.sin_port=htons(port); if (strcmp(h,"*") == 0) server.sin_addr.s_addr=INADDR_ANY; @@ -517,12 +547,13 @@ char *host; if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET); l=(unsigned long) ((unsigned long)ip[0]<<24L)| - ((unsigned long)ip[0]<<16L)| - ((unsigned long)ip[0]<< 8L)| - ((unsigned long)ip[0]); + ((unsigned long)ip[1]<<16L)| + ((unsigned long)ip[2]<< 8L)| + ((unsigned long)ip[3]); server.sin_addr.s_addr=htonl(l); } +again: s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); if (s == INVALID_SOCKET) { @@ -531,9 +562,45 @@ char *host; BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET); goto err; } + +#ifdef SO_REUSEADDR + if (bind_mode == BIO_BIND_REUSEADDR) + { + int i=1; + + ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i)); + bind_mode=BIO_BIND_NORMAL; + } +#endif if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) { - SYSerr(SYS_F_BIND,get_last_socket_error()); +#ifdef SO_REUSEADDR + err_num=get_last_socket_error(); + if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) && + (err_num == EADDRINUSE)) + { + memcpy((char *)&client,(char *)&server,sizeof(server)); + if (strcmp(h,"*") == 0) + client.sin_addr.s_addr=htonl(0x7F000001); + cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); + if (cs != INVALID_SOCKET) + { + int ii; + ii=connect(cs,(struct sockaddr *)&client, + sizeof(client)); + closesocket(cs); + if (ii == INVALID_SOCKET) + { + bind_mode=BIO_BIND_REUSEADDR; + closesocket(s); + goto again; + } + /* else error */ + } + /* else error */ + } +#endif + SYSerr(SYS_F_BIND,err_num); ERR_add_error_data(3,"port='",host,"'"); BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET); goto err; @@ -550,30 +617,29 @@ err: if (str != NULL) Free(str); if ((ret == 0) && (s != INVALID_SOCKET)) { -#ifdef WINDOWS closesocket(s); -#else - close(s); -#endif s= INVALID_SOCKET; } return(s); } -int BIO_accept(sock,addr) -int sock; -char **addr; +int BIO_accept(int sock, char **addr) { int ret=INVALID_SOCKET; static struct sockaddr_in from; unsigned long l; - short port; + unsigned short port; int len; char *p; memset((char *)&from,0,sizeof(from)); len=sizeof(from); - ret=accept(sock,(struct sockaddr *)&from,&len); + /* Note: under VMS with SOCKETSHR the fourth parameter is currently + * of type (int *) whereas under other systems it is (void *) if + * you don't have a cast it will choke the compiler: if you do + * have a cast then you can either go for (int *) or (void *). + */ + ret=accept(sock,(struct sockaddr *)&from,(void *)&len); if (ret == INVALID_SOCKET) { SYSerr(SYS_F_ACCEPT,get_last_socket_error()); @@ -604,9 +670,7 @@ end: return(ret); } -int BIO_set_tcp_ndelay(s,on) -int s; -int on; +int BIO_set_tcp_ndelay(int s, int on) { int ret=0; #if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) @@ -626,3 +690,14 @@ int on; } #endif +int BIO_socket_nbio(int s, int mode) + { + int ret= -1; + unsigned long l; + + l=mode; +#ifdef FIONBIO + ret=BIO_socket_ioctl(s,FIONBIO,&l); +#endif + return(ret == 0); + } diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c index 7912b88473..acd8148138 100644 --- a/src/lib/libcrypto/bio/bf_buff.c +++ b/src/lib/libcrypto/bio/bf_buff.c @@ -59,10 +59,9 @@ #include #include #include "cryptlib.h" -#include "bio.h" -#include "evp.h" +#include +#include -#ifndef NOPROTO static int buffer_write(BIO *h,char *buf,int num); static int buffer_read(BIO *h,char *buf,int size); static int buffer_puts(BIO *h,char *str); @@ -70,16 +69,6 @@ static int buffer_gets(BIO *h,char *str,int size); static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int buffer_new(BIO *h); static int buffer_free(BIO *data); -#else -static int buffer_write(); -static int buffer_read(); -static int buffer_puts(); -static int buffer_gets(); -static long buffer_ctrl(); -static int buffer_new(); -static int buffer_free(); -#endif - #define DEFAULT_BUFFER_SIZE 1024 static BIO_METHOD methods_buffer= @@ -95,13 +84,12 @@ static BIO_METHOD methods_buffer= buffer_free, }; -BIO_METHOD *BIO_f_buffer() +BIO_METHOD *BIO_f_buffer(void) { return(&methods_buffer); } -static int buffer_new(bi) -BIO *bi; +static int buffer_new(BIO *bi) { BIO_F_BUFFER_CTX *ctx; @@ -124,8 +112,7 @@ BIO *bi; return(1); } -static int buffer_free(a) -BIO *a; +static int buffer_free(BIO *a) { BIO_F_BUFFER_CTX *b; @@ -140,10 +127,7 @@ BIO *a; return(1); } -static int buffer_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int buffer_read(BIO *b, char *out, int outl) { int i,num=0; BIO_F_BUFFER_CTX *ctx; @@ -209,10 +193,7 @@ start: goto start; } -static int buffer_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int buffer_write(BIO *b, char *in, int inl) { int i,num=0; BIO_F_BUFFER_CTX *ctx; @@ -285,11 +266,7 @@ start: goto start; } -static long buffer_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO *dbio; BIO_F_BUFFER_CTX *ctx; @@ -432,6 +409,7 @@ fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_ break; } } + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); break; case BIO_CTRL_DUP: dbio=(BIO *)ptr; @@ -449,10 +427,7 @@ malloc_error: return(0); } -static int buffer_gets(b,buf,size) -BIO *b; -char *buf; -int size; +static int buffer_gets(BIO *b, char *buf, int size) { BIO_F_BUFFER_CTX *ctx; int num=0,i,flag; @@ -503,9 +478,7 @@ int size; } } -static int buffer_puts(b,str) -BIO *b; -char *str; +static int buffer_puts(BIO *b, char *str) { return(BIO_write(b,str,strlen(str))); } diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c index 034b3024df..cbec2bae29 100644 --- a/src/lib/libcrypto/bio/bf_nbio.c +++ b/src/lib/libcrypto/bio/bf_nbio.c @@ -59,14 +59,13 @@ #include #include #include "cryptlib.h" -#include "rand.h" -#include "bio.h" -#include "evp.h" +#include +#include +#include /* BIO_put and BIO_get both add to the digest, * BIO_gets returns the digest */ -#ifndef NOPROTO static int nbiof_write(BIO *h,char *buf,int num); static int nbiof_read(BIO *h,char *buf,int size); static int nbiof_puts(BIO *h,char *str); @@ -74,16 +73,6 @@ static int nbiof_gets(BIO *h,char *str,int size); static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int nbiof_new(BIO *h); static int nbiof_free(BIO *data); -#else -static int nbiof_write(); -static int nbiof_read(); -static int nbiof_puts(); -static int nbiof_gets(); -static long nbiof_ctrl(); -static int nbiof_new(); -static int nbiof_free(); -#endif - typedef struct nbio_test_st { /* only set if we sent a 'should retry' error */ @@ -104,13 +93,12 @@ static BIO_METHOD methods_nbiof= nbiof_free, }; -BIO_METHOD *BIO_f_nbio_test() +BIO_METHOD *BIO_f_nbio_test(void) { return(&methods_nbiof); } -static int nbiof_new(bi) -BIO *bi; +static int nbiof_new(BIO *bi) { NBIO_TEST *nt; @@ -123,8 +111,7 @@ BIO *bi; return(1); } -static int nbiof_free(a) -BIO *a; +static int nbiof_free(BIO *a) { if (a == NULL) return(0); if (a->ptr != NULL) @@ -135,10 +122,7 @@ BIO *a; return(1); } -static int nbiof_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int nbiof_read(BIO *b, char *out, int outl) { NBIO_TEST *nt; int ret=0; @@ -173,10 +157,7 @@ int outl; return(ret); } -static int nbiof_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int nbiof_write(BIO *b, char *in, int inl) { NBIO_TEST *nt; int ret=0; @@ -221,11 +202,7 @@ int inl; return(ret); } -static long nbiof_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret; @@ -247,19 +224,14 @@ char *ptr; return(ret); } -static int nbiof_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int nbiof_gets(BIO *bp, char *buf, int size) { if (bp->next_bio == NULL) return(0); return(BIO_gets(bp->next_bio,buf,size)); } -static int nbiof_puts(bp,str) -BIO *bp; -char *str; +static int nbiof_puts(BIO *bp, char *str) { if (bp->next_bio == NULL) return(0); return(BIO_puts(bp->next_bio,str)); diff --git a/src/lib/libcrypto/bio/bf_null.c b/src/lib/libcrypto/bio/bf_null.c index a47a65741a..3254a55dce 100644 --- a/src/lib/libcrypto/bio/bf_null.c +++ b/src/lib/libcrypto/bio/bf_null.c @@ -59,13 +59,12 @@ #include #include #include "cryptlib.h" -#include "bio.h" -#include "evp.h" +#include +#include /* BIO_put and BIO_get both add to the digest, * BIO_gets returns the digest */ -#ifndef NOPROTO static int nullf_write(BIO *h,char *buf,int num); static int nullf_read(BIO *h,char *buf,int size); static int nullf_puts(BIO *h,char *str); @@ -73,16 +72,6 @@ static int nullf_gets(BIO *h,char *str,int size); static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int nullf_new(BIO *h); static int nullf_free(BIO *data); -#else -static int nullf_write(); -static int nullf_read(); -static int nullf_puts(); -static int nullf_gets(); -static long nullf_ctrl(); -static int nullf_new(); -static int nullf_free(); -#endif - static BIO_METHOD methods_nullf= { BIO_TYPE_NULL_FILTER, @@ -96,13 +85,12 @@ static BIO_METHOD methods_nullf= nullf_free, }; -BIO_METHOD *BIO_f_null() +BIO_METHOD *BIO_f_null(void) { return(&methods_nullf); } -static int nullf_new(bi) -BIO *bi; +static int nullf_new(BIO *bi) { bi->init=1; bi->ptr=NULL; @@ -110,8 +98,7 @@ BIO *bi; return(1); } -static int nullf_free(a) -BIO *a; +static int nullf_free(BIO *a) { if (a == NULL) return(0); /* a->ptr=NULL; @@ -120,10 +107,7 @@ BIO *a; return(1); } -static int nullf_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int nullf_read(BIO *b, char *out, int outl) { int ret=0; @@ -135,10 +119,7 @@ int outl; return(ret); } -static int nullf_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int nullf_write(BIO *b, char *in, int inl) { int ret=0; @@ -150,11 +131,7 @@ int inl; return(ret); } -static long nullf_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret; @@ -175,19 +152,14 @@ char *ptr; return(ret); } -static int nullf_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int nullf_gets(BIO *bp, char *buf, int size) { if (bp->next_bio == NULL) return(0); return(BIO_gets(bp->next_bio,buf,size)); } -static int nullf_puts(bp,str) -BIO *bp; -char *str; +static int nullf_puts(BIO *bp, char *str) { if (bp->next_bio == NULL) return(0); return(BIO_puts(bp->next_bio,str)); diff --git a/src/lib/libcrypto/bio/bio.err b/src/lib/libcrypto/bio/bio.err deleted file mode 100644 index 6e2f2b63ca..0000000000 --- a/src/lib/libcrypto/bio/bio.err +++ /dev/null @@ -1,46 +0,0 @@ -/* Error codes for the BIO functions. */ - -/* Function codes. */ -#define BIO_F_ACPT_STATE 100 -#define BIO_F_BIO_ACCEPT 101 -#define BIO_F_BIO_CTRL 102 -#define BIO_F_BIO_GETS 103 -#define BIO_F_BIO_GET_ACCEPT_SOCKET 104 -#define BIO_F_BIO_GET_HOST_IP 105 -#define BIO_F_BIO_GET_PORT 106 -#define BIO_F_BIO_NEW 107 -#define BIO_F_BIO_NEW_FILE 108 -#define BIO_F_BIO_PUTS 109 -#define BIO_F_BIO_READ 110 -#define BIO_F_BIO_SOCK_INIT 111 -#define BIO_F_BIO_WRITE 112 -#define BIO_F_BUFFER_CTRL 113 -#define BIO_F_CONN_STATE 114 -#define BIO_F_FILE_CTRL 115 -#define BIO_F_MEM_WRITE 116 -#define BIO_F_SSL_NEW 117 -#define BIO_F_WSASTARTUP 118 - -/* Reason codes. */ -#define BIO_R_ACCEPT_ERROR 100 -#define BIO_R_BAD_FOPEN_MODE 101 -#define BIO_R_BAD_HOSTNAME_LOOKUP 102 -#define BIO_R_CONNECT_ERROR 103 -#define BIO_R_ERROR_SETTING_NBIO 104 -#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 -#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 -#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 -#define BIO_R_INVALID_IP_ADDRESS 108 -#define BIO_R_KEEPALIVE 109 -#define BIO_R_NBIO_CONNECT_ERROR 110 -#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 -#define BIO_R_NO_HOSTHNAME_SPECIFIED 112 -#define BIO_R_NO_PORT_DEFINED 113 -#define BIO_R_NO_PORT_SPECIFIED 114 -#define BIO_R_NULL_PARAMETER 115 -#define BIO_R_UNABLE_TO_BIND_SOCKET 116 -#define BIO_R_UNABLE_TO_CREATE_SOCKET 117 -#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118 -#define BIO_R_UNINITALISED 119 -#define BIO_R_UNSUPPORTED_METHOD 120 -#define BIO_R_WSASTARTUP 121 diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h index 300b330e00..54bf622a3b 100644 --- a/src/lib/libcrypto/bio/bio.h +++ b/src/lib/libcrypto/bio/bio.h @@ -63,7 +63,9 @@ extern "C" { #endif -#include "crypto.h" +#include +#include +#include /* These are the 'types' of BIOs */ #define BIO_TYPE_NONE 0 @@ -84,6 +86,8 @@ extern "C" { #define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ #define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ #define BIO_TYPE_NULL_FILTER (17|0x0200) +#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ +#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ #define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ #define BIO_TYPE_FILTER 0x0200 @@ -202,7 +206,7 @@ extern "C" { typedef struct bio_method_st { int type; - char *name; + const char *name; int (*bwrite)(); int (*bread)(); int (*bputs)(); @@ -215,7 +219,7 @@ typedef struct bio_method_st typedef struct bio_method_st { int type; - char *name; + const char *name; int (_far *bwrite)(); int (_far *bread)(); int (_far *bputs)(); @@ -229,12 +233,8 @@ typedef struct bio_method_st typedef struct bio_st { BIO_METHOD *method; -#ifndef NOPROTO /* bio, mode, argp, argi, argl, ret */ - long (*callback)(struct bio_st *,int,char *,int, long,long); -#else - long (*callback)(); -#endif + long (*callback)(struct bio_st *,int,const char *,int, long,long); char *cb_arg; /* first argument for the callback */ int init; @@ -242,7 +242,7 @@ typedef struct bio_st int flags; /* extra storage */ int retry_reason; int num; - char *ptr; + void *ptr; struct bio_st *next_bio; /* used by filter BIOs */ struct bio_st *prev_bio; /* used by filter BIOs */ int references; @@ -276,7 +276,7 @@ typedef struct bio_f_buffer_ctx_struct #define BIO_CONN_S_OK 6 #define BIO_CONN_S_BLOCKED_CONNECT 7 #define BIO_CONN_S_NBIO 8 -#define BIO_CONN_get_param_hostname BIO_ctrl +/*#define BIO_CONN_get_param_hostname BIO_ctrl */ #define BIO_number_read(b) ((b)->num_read) #define BIO_number_written(b) ((b)->num_write) @@ -309,18 +309,28 @@ typedef struct bio_f_buffer_ctx_struct #define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 #define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 #define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 +#define BIO_C_FILE_SEEK 128 +#define BIO_C_GET_CIPHER_CTX 129 +#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ +#define BIO_C_SET_BIND_MODE 131 +#define BIO_C_GET_BIND_MODE 132 +#define BIO_C_FILE_TELL 133 +#define BIO_C_GET_SOCKS 134 +#define BIO_C_SET_SOCKS 135 + +#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ +#define BIO_C_GET_WRITE_BUF_SIZE 137 +#define BIO_C_MAKE_BIO_PAIR 138 +#define BIO_C_DESTROY_BIO_PAIR 139 +#define BIO_C_GET_WRITE_GUARANTEE 140 +#define BIO_C_GET_READ_REQUEST 141 +#define BIO_C_SHUTDOWN_WR 142 + #define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) #define BIO_get_app_data(s) BIO_get_ex_data(s,0) -int BIO_get_ex_num(BIO *bio); -int BIO_set_ex_data(BIO *bio,int idx,char *data); -char *BIO_get_ex_data(BIO *bio,int idx); -void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); -int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), - int (*dup_func)(), void (*free_func)()); - -/* BIO_s_connect_socket() */ +/* BIO_s_connect() and BIO_s_socks4a_connect() */ #define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) #define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) #define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) @@ -328,7 +338,8 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) #define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) #define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2) -#define BIO_get_conn_int port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) +#define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) + #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) @@ -339,6 +350,12 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) +#define BIO_BIND_NORMAL 0 +#define BIO_BIND_REUSEADDR_IF_UNUSED 1 +#define BIO_BIND_REUSEADDR 2 +#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) +#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) + #define BIO_do_connect(b) BIO_do_handshake(b) #define BIO_do_accept(b) BIO_do_handshake(b) #define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) @@ -364,12 +381,26 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) #define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) +#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) +#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) + +/* name is cast to lose const, but might be better to route through a function + so we can do it safely */ +#ifdef CONST_STRICT +/* If you are wondering why this isn't defined, its because CONST_STRICT is + * purely a compile-time kludge to allow const to be checked. + */ +int BIO_read_filename(BIO *b,const char *name); +#else #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ - BIO_CLOSE|BIO_FP_READ,name) + BIO_CLOSE|BIO_FP_READ,(char *)name) +#endif #define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ BIO_CLOSE|BIO_FP_WRITE,name) #define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ BIO_CLOSE|BIO_FP_APPEND,name) +#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ + BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) /* WARNING WARNING, this ups the reference count on the read bio of the * SSL structure. This is because the ssl read BIO is now pointed to by @@ -388,8 +419,11 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), /* defined in evp.h */ /* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ +#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) #define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) #define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) +#define BIO_set_mem_eof_return(b,v) \ + BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) /* For the BIO_f_buffer() type */ #define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) @@ -407,6 +441,9 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), #define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) #define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) #define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) +/* ...pending macros have inappropriate return type */ +size_t BIO_ctrl_pending(BIO *b); +size_t BIO_ctrl_wpending(BIO *b); #define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) #define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp) #define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb) @@ -414,11 +451,32 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), /* For the BIO_f_buffer() type */ #define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) +/* For BIO_s_bio() */ +#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) +#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) +#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) +#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) +/* macros with inappropriate type -- but ...pending macros use int too: */ +#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) +#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) +size_t BIO_ctrl_get_write_guarantee(BIO *b); +size_t BIO_ctrl_get_read_request(BIO *b); + + + #ifdef NO_STDIO #define NO_FP_API #endif -#ifndef NOPROTO + +/* These two aren't currently implemented */ +/* int BIO_get_ex_num(BIO *bio); */ +/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ +int BIO_set_ex_data(BIO *bio,int idx,char *data); +char *BIO_get_ex_data(BIO *bio,int idx); +int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), + int (*dup_func)(), void (*free_func)()); + # if defined(WIN16) && defined(_WINDLL) BIO_METHOD *BIO_s_file_internal(void); BIO *BIO_new_file_internal(char *filename, char *mode); @@ -428,39 +486,20 @@ BIO *BIO_new_fp_internal(FILE *stream, int close_flag); # define BIO_new_fp BIO_new_fp_internal # else /* FP_API */ BIO_METHOD *BIO_s_file(void ); -BIO *BIO_new_file(char *filename, char *mode); +BIO *BIO_new_file(const char *filename, const char *mode); BIO *BIO_new_fp(FILE *stream, int close_flag); # define BIO_s_file_internal BIO_s_file # define BIO_new_file_internal BIO_new_file # define BIO_new_fp_internal BIO_s_file # endif /* FP_API */ -#else -# if defined(WIN16) && defined(_WINDLL) -BIO_METHOD *BIO_s_file_internal(); -BIO *BIO_new_file_internal(); -BIO *BIO_new_fp_internal(); -# define BIO_s_file BIO_s_file_internal -# define BIO_new_file BIO_new_file_internal -# define BIO_new_fp BIO_new_fp_internal -# else /* FP_API */ -BIO_METHOD *BIO_s_file(); -BIO *BIO_new_file(); -BIO *BIO_new_fp(); -# define BIO_s_file_internal BIO_s_file -# define BIO_new_file_internal BIO_new_file -# define BIO_new_fp_internal BIO_s_file -# endif /* FP_API */ -#endif - -#ifndef NOPROTO BIO * BIO_new(BIO_METHOD *type); int BIO_set(BIO *a,BIO_METHOD *type); int BIO_free(BIO *a); -int BIO_read(BIO *b, char *data, int len); +int BIO_read(BIO *b, void *data, int len); int BIO_gets(BIO *bp,char *buf, int size); -int BIO_write(BIO *b, char *data, int len); -int BIO_puts(BIO *bp,char *buf); -long BIO_ctrl(BIO *bp,int cmd,long larg,char *parg); +int BIO_write(BIO *b, const char *data, int len); +int BIO_puts(BIO *bp,const char *buf); +long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); BIO * BIO_push(BIO *b,BIO *append); @@ -472,10 +511,10 @@ int BIO_get_retry_reason(BIO *bio); BIO * BIO_dup_chain(BIO *in); #ifndef WIN16 -long BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi, +long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, long argl,long ret); #else -long _far _loadds BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi, +long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, long argl,long ret); #endif @@ -484,23 +523,35 @@ BIO_METHOD *BIO_s_socket(void); BIO_METHOD *BIO_s_connect(void); BIO_METHOD *BIO_s_accept(void); BIO_METHOD *BIO_s_fd(void); +BIO_METHOD *BIO_s_log(void); +BIO_METHOD *BIO_s_bio(void); BIO_METHOD *BIO_s_null(void); BIO_METHOD *BIO_f_null(void); -BIO_METHOD *BIO_f_nbio_test(void); BIO_METHOD *BIO_f_buffer(void); +BIO_METHOD *BIO_f_nbio_test(void); +/* BIO_METHOD *BIO_f_ber(void); */ int BIO_sock_should_retry(int i); int BIO_sock_non_fatal_error(int error); int BIO_fd_should_retry(int i); int BIO_fd_non_fatal_error(int error); -int BIO_dump(BIO *b,char *bytes,int len); - -struct hostent *BIO_gethostbyname(char *name); +int BIO_dump(BIO *b,const char *bytes,int len); + +struct hostent *BIO_gethostbyname(const char *name); +/* We might want a thread-safe interface too: + * struct hostent *BIO_gethostbyname_r(const char *name, + * struct hostent *result, void *buffer, size_t buflen); + * or something similar (caller allocates a struct hostent, + * pointed to by "result", and additional buffer space for the various + * substructures; if the buffer does not suffice, NULL is returned + * and an appropriate error code is set). + */ int BIO_sock_error(int sock); int BIO_socket_ioctl(int fd, long type, unsigned long *arg); -int BIO_get_port(char *str, short *port_ptr); -int BIO_get_host_ip(char *str, unsigned char *ip); -int BIO_get_accept_socket(char *host_port); +int BIO_socket_nbio(int fd,int mode); +int BIO_get_port(const char *str, unsigned short *port_ptr); +int BIO_get_host_ip(const char *str, unsigned char *ip); +int BIO_get_accept_socket(char *host_port,int mode); int BIO_accept(int sock,char **ip_port); int BIO_sock_init(void ); void BIO_sock_cleanup(void); @@ -513,174 +564,78 @@ BIO *BIO_new_fd(int fd, int close_flag); BIO *BIO_new_connect(char *host_port); BIO *BIO_new_accept(char *host_port); +int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, + BIO **bio2, size_t writebuf2); +/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. + * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. + * Size 0 uses default value. + */ + void BIO_copy_next_retry(BIO *b); long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); -#else - -BIO * BIO_new(); -int BIO_set(); -int BIO_free(); -int BIO_read(); -int BIO_gets(); -int BIO_write(); -int BIO_puts(); -char * BIO_ptr_ctrl(); -long BIO_ctrl(); -long BIO_int_ctrl(); -BIO * BIO_push(); -BIO * BIO_pop(); -void BIO_free_all(); -BIO * BIO_find_type(); -BIO * BIO_get_retry_BIO(); -int BIO_get_retry_reason(); -BIO * BIO_dup_chain(); - -#ifndef WIN16 -long BIO_debug_callback(); -#else -long _far _loadds BIO_debug_callback(); -#endif - -BIO_METHOD *BIO_s_mem(); -BIO_METHOD *BIO_s_socket(); -BIO_METHOD *BIO_s_connect(); -BIO_METHOD *BIO_s_accept(); -BIO_METHOD *BIO_s_fd(); -BIO_METHOD *BIO_s_null(); -BIO_METHOD *BIO_f_null(); -BIO_METHOD *BIO_f_buffer(); -BIO_METHOD *BIO_f_nbio_test(); - -int BIO_sock_should_retry(); -int BIO_sock_non_fatal_error(); -int BIO_fd_should_retry(); -int BIO_fd_non_fatal_error(); -int BIO_dump(); - -struct hostent *BIO_gethostbyname(); -int BIO_sock_error(); -int BIO_socket_ioctl(); -int BIO_get_port(); -int BIO_get_host_ip(); -int BIO_get_accept_socket(); -int BIO_accept(); -int BIO_sock_init(); -void BIO_sock_cleanup(); -int BIO_set_tcp_ndelay(); - -void ERR_load_BIO_strings(); - -BIO *BIO_new_socket(); -BIO *BIO_new_fd(); -BIO *BIO_new_connect(); -BIO *BIO_new_accept(); - -void BIO_copy_next_retry(); - -int BIO_ghbn_ctrl(); - -#endif - -/* Tim Hudson's portable varargs stuff */ - -#ifndef NOPROTO -#define VAR_ANSI /* select ANSI version by default */ -#endif - -#ifdef VAR_ANSI -/* ANSI version of a "portable" macro set for variable length args */ -#ifndef __STDARG_H__ /**/ -#include -#endif /**/ - -#define VAR_PLIST(arg1type,arg1) arg1type arg1, ... -#define VAR_PLIST2(arg1type,arg1,arg2type,arg2) arg1type arg1,arg2type arg2,... -#define VAR_ALIST -#define VAR_BDEFN(args,arg1type,arg1) va_list args -#define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args -#define VAR_INIT(args,arg1type,arg1) va_start(args,arg1); -#define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args,arg2); -#define VAR_ARG(args,type,arg) arg=va_arg(args,type) -#define VAR_END(args) va_end(args); - -#else - -/* K&R version of a "portable" macro set for variable length args */ -#ifndef __VARARGS_H__ -#include -#endif - -#define VAR_PLIST(arg1type,arg1) va_alist -#define VAR_PLIST2(arg1type,arg1,arg2type,arg2) va_alist -#define VAR_ALIST va_dcl -#define VAR_BDEFN(args,arg1type,arg1) va_list args; arg1type arg1 -#define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args; \ - arg1type arg1; arg2type arg2 -#define VAR_INIT(args,arg1type,arg1) va_start(args); \ - arg1=va_arg(args,arg1type); -#define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args); \ - arg1=va_arg(args,arg1type); arg2=va_arg(args,arg2type); -#define VAR_ARG(args,type,arg) arg=va_arg(args,type) -#define VAR_END(args) va_end(args); - -#endif - -#ifndef NOPROTO -int BIO_printf( VAR_PLIST( BIO *, bio ) ); -#else -int BIO_printf(); -#endif +int BIO_printf(BIO *bio, ...); /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the BIO functions. */ /* Function codes. */ #define BIO_F_ACPT_STATE 100 #define BIO_F_BIO_ACCEPT 101 -#define BIO_F_BIO_CTRL 102 -#define BIO_F_BIO_GETS 103 -#define BIO_F_BIO_GET_ACCEPT_SOCKET 104 -#define BIO_F_BIO_GET_HOST_IP 105 -#define BIO_F_BIO_GET_PORT 106 -#define BIO_F_BIO_NEW 107 -#define BIO_F_BIO_NEW_FILE 108 -#define BIO_F_BIO_PUTS 109 -#define BIO_F_BIO_READ 110 -#define BIO_F_BIO_SOCK_INIT 111 -#define BIO_F_BIO_WRITE 112 -#define BIO_F_BUFFER_CTRL 113 -#define BIO_F_CONN_STATE 114 -#define BIO_F_FILE_CTRL 115 -#define BIO_F_MEM_WRITE 116 -#define BIO_F_SSL_NEW 117 -#define BIO_F_WSASTARTUP 118 +#define BIO_F_BIO_BER_GET_HEADER 102 +#define BIO_F_BIO_CTRL 103 +#define BIO_F_BIO_GETHOSTBYNAME 120 +#define BIO_F_BIO_GETS 104 +#define BIO_F_BIO_GET_ACCEPT_SOCKET 105 +#define BIO_F_BIO_GET_HOST_IP 106 +#define BIO_F_BIO_GET_PORT 107 +#define BIO_F_BIO_MAKE_PAIR 121 +#define BIO_F_BIO_NEW 108 +#define BIO_F_BIO_NEW_FILE 109 +#define BIO_F_BIO_PUTS 110 +#define BIO_F_BIO_READ 111 +#define BIO_F_BIO_SOCK_INIT 112 +#define BIO_F_BIO_WRITE 113 +#define BIO_F_BUFFER_CTRL 114 +#define BIO_F_CONN_STATE 115 +#define BIO_F_FILE_CTRL 116 +#define BIO_F_MEM_WRITE 117 +#define BIO_F_SSL_NEW 118 +#define BIO_F_WSASTARTUP 119 /* Reason codes. */ #define BIO_R_ACCEPT_ERROR 100 #define BIO_R_BAD_FOPEN_MODE 101 #define BIO_R_BAD_HOSTNAME_LOOKUP 102 +#define BIO_R_BROKEN_PIPE 124 #define BIO_R_CONNECT_ERROR 103 #define BIO_R_ERROR_SETTING_NBIO 104 #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 #define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 +#define BIO_R_INVALID_ARGUMENT 125 #define BIO_R_INVALID_IP_ADDRESS 108 +#define BIO_R_IN_USE 123 #define BIO_R_KEEPALIVE 109 #define BIO_R_NBIO_CONNECT_ERROR 110 #define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 -#define BIO_R_NO_HOSTHNAME_SPECIFIED 112 +#define BIO_R_NO_HOSTNAME_SPECIFIED 112 #define BIO_R_NO_PORT_DEFINED 113 #define BIO_R_NO_PORT_SPECIFIED 114 #define BIO_R_NULL_PARAMETER 115 -#define BIO_R_UNABLE_TO_BIND_SOCKET 116 -#define BIO_R_UNABLE_TO_CREATE_SOCKET 117 -#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118 -#define BIO_R_UNINITALISED 119 -#define BIO_R_UNSUPPORTED_METHOD 120 -#define BIO_R_WSASTARTUP 121 - +#define BIO_R_TAG_MISMATCH 116 +#define BIO_R_UNABLE_TO_BIND_SOCKET 117 +#define BIO_R_UNABLE_TO_CREATE_SOCKET 118 +#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 +#define BIO_R_UNINITIALIZED 120 +#define BIO_R_UNSUPPORTED_METHOD 121 +#define BIO_R_WSASTARTUP 122 + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c index bc6ed9eda1..37c7c22666 100644 --- a/src/lib/libcrypto/bio/bio_cb.c +++ b/src/lib/libcrypto/bio/bio_cb.c @@ -60,16 +60,11 @@ #include #include #include "cryptlib.h" -#include "bio.h" -#include "err.h" +#include +#include -long MS_CALLBACK BIO_debug_callback(bio,cmd,argp,argi,argl,ret) -BIO *bio; -int cmd; -char *argp; -int argi; -long argl; -long ret; +long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp, + int argi, long argl, long ret) { BIO *b; MS_STATIC char buf[256]; diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c index 37e14ca107..712d98a3a1 100644 --- a/src/lib/libcrypto/bio/bio_err.c +++ b/src/lib/libcrypto/bio/bio_err.c @@ -1,63 +1,65 @@ -/* lib/bio/bio_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/bio/bio_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "bio.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -65,11 +67,14 @@ static ERR_STRING_DATA BIO_str_functs[]= { {ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"}, {ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"}, +{ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"}, {ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"}, +{ERR_PACK(0,BIO_F_BIO_GETHOSTBYNAME,0), "BIO_gethostbyname"}, {ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"}, {ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"}, {ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"}, {ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"}, +{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"}, {ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"}, {ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"}, {ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"}, @@ -80,9 +85,9 @@ static ERR_STRING_DATA BIO_str_functs[]= {ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, {ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, {ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, -{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_NEW"}, +{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"}, {ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"}, -{0,NULL}, +{0,NULL} }; static ERR_STRING_DATA BIO_str_reasons[]= @@ -90,36 +95,40 @@ static ERR_STRING_DATA BIO_str_reasons[]= {BIO_R_ACCEPT_ERROR ,"accept error"}, {BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"}, {BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"}, +{BIO_R_BROKEN_PIPE ,"broken pipe"}, {BIO_R_CONNECT_ERROR ,"connect error"}, {BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"}, {BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"}, {BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"}, {BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"}, +{BIO_R_INVALID_ARGUMENT ,"invalid argument"}, {BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"}, +{BIO_R_IN_USE ,"in use"}, {BIO_R_KEEPALIVE ,"keepalive"}, {BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"}, {BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"}, -{BIO_R_NO_HOSTHNAME_SPECIFIED ,"no hosthname specified"}, +{BIO_R_NO_HOSTNAME_SPECIFIED ,"no hostname specified"}, {BIO_R_NO_PORT_DEFINED ,"no port defined"}, {BIO_R_NO_PORT_SPECIFIED ,"no port specified"}, {BIO_R_NULL_PARAMETER ,"null parameter"}, +{BIO_R_TAG_MISMATCH ,"tag mismatch"}, {BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"}, {BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"}, {BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, -{BIO_R_UNINITALISED ,"uninitalised"}, +{BIO_R_UNINITIALIZED ,"uninitialized"}, {BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, {BIO_R_WSASTARTUP ,"wsastartup"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_BIO_strings() +void ERR_load_BIO_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_BIO,BIO_str_functs); diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index 7a66b0892e..b72688ea90 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c @@ -58,16 +58,15 @@ #include #include -#include "crypto.h" +#include #include "cryptlib.h" -#include "bio.h" -#include "stack.h" +#include +#include static STACK *bio_meth=NULL; static int bio_meth_num=0; -BIO *BIO_new(method) -BIO_METHOD *method; +BIO *BIO_new(BIO_METHOD *method) { BIO *ret=NULL; @@ -85,9 +84,7 @@ BIO_METHOD *method; return(ret); } -int BIO_set(bio,method) -BIO *bio; -BIO_METHOD *method; +int BIO_set(BIO *bio, BIO_METHOD *method) { bio->method=method; bio->callback=NULL; @@ -110,8 +107,7 @@ BIO_METHOD *method; return(1); } -int BIO_free(a) -BIO *a; +int BIO_free(BIO *a) { int ret=0,i; @@ -121,7 +117,7 @@ BIO *a; #ifdef REF_PRINT REF_PRINT("BIO",a); #endif - if (i > 0) return(1); + if (i > 0) return(1); #ifdef REF_CHECK if (i < 0) { @@ -141,10 +137,7 @@ BIO *a; return(1); } -int BIO_read(b,out,outl) -BIO *b; -char *out; -int outl; +int BIO_read(BIO *b, void *out, int outl) { int i; long (*cb)(); @@ -162,11 +155,12 @@ int outl; if (!b->init) { - BIOerr(BIO_F_BIO_READ,BIO_R_UNINITALISED); + BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED); return(-2); } i=b->method->bread(b,out,outl); + if (i > 0) b->num_read+=(unsigned long)i; if (cb != NULL) @@ -175,10 +169,7 @@ int outl; return(i); } -int BIO_write(b,in,inl) -BIO *b; -char *in; -int inl; +int BIO_write(BIO *b, const char *in, int inl) { int i; long (*cb)(); @@ -199,22 +190,27 @@ int inl; if (!b->init) { - BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITALISED); + BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED); return(-2); } i=b->method->bwrite(b,in,inl); + if (i > 0) b->num_write+=(unsigned long)i; - if (cb != NULL) + /* This is evil and not thread safe. If the BIO has been freed, + * we must not call the callback. The only way to be able to + * determine this is the reference count which is now invalid since + * the memory has been free()ed. + */ + if (b->references <= 0) abort(); + if (cb != NULL) /* && (b->references >= 1)) */ i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, 0L,(long)i); return(i); } -int BIO_puts(b,in) -BIO *b; -char *in; +int BIO_puts(BIO *b, const char *in) { int i; long (*cb)(); @@ -233,7 +229,7 @@ char *in; if (!b->init) { - BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITALISED); + BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED); return(-2); } @@ -245,10 +241,7 @@ char *in; return(i); } -int BIO_gets(b,in,inl) -BIO *b; -char *in; -int inl; +int BIO_gets(BIO *b, char *in, int inl) { int i; long (*cb)(); @@ -267,7 +260,7 @@ int inl; if (!b->init) { - BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITALISED); + BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED); return(-2); } @@ -279,11 +272,7 @@ int inl; return(i); } -long BIO_int_ctrl(b,cmd,larg,iarg) -BIO *b; -int cmd; -long larg; -int iarg; +long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) { int i; @@ -291,10 +280,7 @@ int iarg; return(BIO_ctrl(b,cmd,larg,(char *)&i)); } -char *BIO_ptr_ctrl(b,cmd,larg) -BIO *b; -int cmd; -long larg; +char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) { char *p=NULL; @@ -304,11 +290,7 @@ long larg; return(p); } -long BIO_ctrl(b,cmd,larg,parg) -BIO *b; -int cmd; -long larg; -char *parg; +long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) { long ret; long (*cb)(); @@ -335,9 +317,22 @@ char *parg; return(ret); } +/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros + * do; but those macros have inappropriate return type, and for interfacing + * from other programming languages, C macros aren't much of a help anyway. */ +size_t BIO_ctrl_pending(BIO *bio) + { + return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); + } + +size_t BIO_ctrl_wpending(BIO *bio) + { + return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); + } + + /* put the 'bio' on the end of b's list of operators */ -BIO *BIO_push(b,bio) -BIO *b,*bio; +BIO *BIO_push(BIO *b, BIO *bio) { BIO *lb; @@ -354,8 +349,7 @@ BIO *b,*bio; } /* Remove the first and return the rest */ -BIO *BIO_pop(b) -BIO *b; +BIO *BIO_pop(BIO *b) { BIO *ret; @@ -373,9 +367,7 @@ BIO *b; return(ret); } -BIO *BIO_get_retry_BIO(bio,reason) -BIO *bio; -int *reason; +BIO *BIO_get_retry_BIO(BIO *bio, int *reason) { BIO *b,*last; @@ -391,15 +383,12 @@ int *reason; return(last); } -int BIO_get_retry_reason(bio) -BIO *bio; +int BIO_get_retry_reason(BIO *bio) { return(bio->retry_reason); } -BIO *BIO_find_type(bio,type) -BIO *bio; -int type; +BIO *BIO_find_type(BIO *bio, int type) { int mt,mask; @@ -421,8 +410,7 @@ int type; return(NULL); } -void BIO_free_all(bio) -BIO *bio; +void BIO_free_all(BIO *bio) { BIO *b; int ref; @@ -438,8 +426,7 @@ BIO *bio; } } -BIO *BIO_dup_chain(in) -BIO *in; +BIO *BIO_dup_chain(BIO *in) { BIO *ret=NULL,*eoc=NULL,*bio,*new; @@ -461,9 +448,9 @@ BIO *in; goto err; } - /* copy app data */ - if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) - goto err; + /* copy app data */ + if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) + goto err; if (ret == NULL) { @@ -483,36 +470,26 @@ err: return(NULL); } -void BIO_copy_next_retry(b) -BIO *b; +void BIO_copy_next_retry(BIO *b) { BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); b->retry_reason=b->next_bio->retry_reason; } -int BIO_get_ex_new_index(argl,argp,new_func,dup_func,free_func) -long argl; -char *argp; -int (*new_func)(); -int (*dup_func)(); -void (*free_func)(); - { - bio_meth_num++; - return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, - argl,argp,new_func,dup_func,free_func)); - } - -int BIO_set_ex_data(bio,idx,data) -BIO *bio; -int idx; -char *data; +int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), + int (*dup_func)(), void (*free_func)()) + { + bio_meth_num++; + return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, + argl,argp,new_func,dup_func,free_func)); + } + +int BIO_set_ex_data(BIO *bio, int idx, char *data) { return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); } -char *BIO_get_ex_data(bio,idx) -BIO *bio; -int idx; +char *BIO_get_ex_data(BIO *bio, int idx) { return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); } diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c index e49902fa9f..47af80f76d 100644 --- a/src/lib/libcrypto/bio/bss_acpt.c +++ b/src/lib/libcrypto/bio/bss_acpt.c @@ -62,9 +62,7 @@ #include #define USE_SOCKETS #include "cryptlib.h" -#include "bio.h" - -/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ +#include #ifdef WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ @@ -72,6 +70,11 @@ #define SOCKET_PROTOCOL IPPROTO_TCP #endif +#if (defined(VMS) && __VMS_VER < 70000000) +/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */ +#undef FIONBIO +#endif + typedef struct bio_accept_st { int state; @@ -82,39 +85,24 @@ typedef struct bio_accept_st char *addr; int nbio; + /* If 0, it means normal, if 1, do a connect on bind failure, + * and if there is no-one listening, bind with SO_REUSEADDR. + * If 2, always use SO_REUSEADDR. */ + int bind_mode; BIO *bio_chain; } BIO_ACCEPT; -#ifndef NOPROTO static int acpt_write(BIO *h,char *buf,int num); static int acpt_read(BIO *h,char *buf,int size); static int acpt_puts(BIO *h,char *str); static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int acpt_new(BIO *h); static int acpt_free(BIO *data); -#else -static int acpt_write(); -static int acpt_read(); -static int acpt_puts(); -static long acpt_ctrl(); -static int acpt_new(); -static int acpt_free(); -#endif - -#ifndef NOPROTO static int acpt_state(BIO *b, BIO_ACCEPT *c); static void acpt_close_socket(BIO *data); BIO_ACCEPT *BIO_ACCEPT_new(void ); void BIO_ACCEPT_free(BIO_ACCEPT *a); -#else - -static int acpt_state(); -static void acpt_close_socket(); -BIO_ACCEPT *BIO_ACCEPT_new(); -void BIO_ACCEPT_free(); -#endif - #define ACPT_S_BEFORE 1 #define ACPT_S_GET_ACCEPT_SOCKET 2 #define ACPT_S_OK 3 @@ -132,13 +120,12 @@ static BIO_METHOD methods_acceptp= acpt_free, }; -BIO_METHOD *BIO_s_accept() +BIO_METHOD *BIO_s_accept(void) { return(&methods_acceptp); } -static int acpt_new(bi) -BIO *bi; +static int acpt_new(BIO *bi) { BIO_ACCEPT *ba; @@ -153,7 +140,7 @@ BIO *bi; return(1); } -BIO_ACCEPT *BIO_ACCEPT_new() +BIO_ACCEPT *BIO_ACCEPT_new(void) { BIO_ACCEPT *ret; @@ -162,20 +149,22 @@ BIO_ACCEPT *BIO_ACCEPT_new() memset(ret,0,sizeof(BIO_ACCEPT)); ret->accept_sock=INVALID_SOCKET; + ret->bind_mode=BIO_BIND_NORMAL; return(ret); } -void BIO_ACCEPT_free(a) -BIO_ACCEPT *a; +void BIO_ACCEPT_free(BIO_ACCEPT *a) { + if(a == NULL) + return; + if (a->param_addr != NULL) Free(a->param_addr); if (a->addr != NULL) Free(a->addr); if (a->bio_chain != NULL) BIO_free(a->bio_chain); Free(a); } -static void acpt_close_socket(bio) -BIO *bio; +static void acpt_close_socket(BIO *bio) { BIO_ACCEPT *c; @@ -183,18 +172,13 @@ BIO *bio; if (c->accept_sock != INVALID_SOCKET) { shutdown(c->accept_sock,2); -# ifdef WINDOWS closesocket(c->accept_sock); -# else - close(c->accept_sock); -# endif c->accept_sock=INVALID_SOCKET; bio->num=INVALID_SOCKET; } } -static int acpt_free(a) -BIO *a; +static int acpt_free(BIO *a) { BIO_ACCEPT *data; @@ -212,12 +196,9 @@ BIO *a; return(1); } -static int acpt_state(b,c) -BIO *b; -BIO_ACCEPT *c; +static int acpt_state(BIO *b, BIO_ACCEPT *c) { BIO *bio=NULL,*dbio; - unsigned long l=1; int s= -1; int i; @@ -230,31 +211,24 @@ again: BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED); return(-1); } - s=BIO_get_accept_socket(c->param_addr); + s=BIO_get_accept_socket(c->param_addr,c->bind_mode); if (s == INVALID_SOCKET) return(-1); -#ifdef FIONBIO if (c->accept_nbio) { - i=BIO_socket_ioctl(b->num,FIONBIO,&l); - if (i < 0) + if (!BIO_socket_nbio(s,1)) { -#ifdef WINDOWS closesocket(s); -#else - close(s); -# endif BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); return(-1); } } -#endif c->accept_sock=s; b->num=s; c->state=ACPT_S_GET_ACCEPT_SOCKET; return(1); - break; + /* break; */ case ACPT_S_GET_ACCEPT_SOCKET: if (b->next_bio != NULL) { @@ -269,17 +243,14 @@ again: BIO_set_callback(bio,BIO_get_callback(b)); BIO_set_callback_arg(bio,BIO_get_callback_arg(b)); -#ifdef FIONBIO if (c->nbio) { - i=BIO_socket_ioctl(i,FIONBIO,&l); - if (i < 0) + if (!BIO_socket_nbio(i,1)) { BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); goto err; } } -#endif /* If the accept BIO has an bio_chain, we dup it and * put the new socket at the end. */ @@ -298,15 +269,9 @@ err: if (bio != NULL) BIO_free(bio); else if (s >= 0) - { -#ifdef WINDOWS closesocket(s); -#else - close(s); -# endif - } return(0); - break; + /* break; */ case ACPT_S_OK: if (b->next_bio == NULL) { @@ -314,23 +279,20 @@ err: goto again; } return(1); - break; + /* break; */ default: return(0); - break; + /* break; */ } } -static int acpt_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int acpt_read(BIO *b, char *out, int outl) { int ret=0; BIO_ACCEPT *data; - BIO_clear_retry_flags(b); + BIO_clear_retry_flags(b); data=(BIO_ACCEPT *)b->ptr; while (b->next_bio == NULL) @@ -344,10 +306,7 @@ int outl; return(ret); } -static int acpt_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int acpt_write(BIO *b, char *in, int inl) { int ret; BIO_ACCEPT *data; @@ -366,11 +325,7 @@ int inl; return(ret); } -static long acpt_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO *dbio; int *ip; @@ -417,13 +372,21 @@ char *ptr; case BIO_C_SET_NBIO: data->nbio=(int)num; break; + case BIO_C_SET_FD: + b->init=1; + b->num= *((int *)ptr); + data->accept_sock=b->num; + data->state=ACPT_S_GET_ACCEPT_SOCKET; + b->shutdown=(int)num; + b->init=1; + break; case BIO_C_GET_FD: if (b->init) { ip=(int *)ptr; if (ip != NULL) *ip=data->accept_sock; - ret=b->num; + ret=data->accept_sock; } else ret= -1; @@ -454,6 +417,12 @@ char *ptr; break; case BIO_CTRL_FLUSH: break; + case BIO_C_SET_BIND_MODE: + data->bind_mode=(int)num; + break; + case BIO_C_GET_BIND_MODE: + ret=(long)data->bind_mode; + break; case BIO_CTRL_DUP: dbio=(BIO *)ptr; /* if (data->param_port) EAY EAY @@ -470,9 +439,7 @@ char *ptr; return(ret); } -static int acpt_puts(bp,str) -BIO *bp; -char *str; +static int acpt_puts(BIO *bp, char *str) { int n,ret; @@ -481,8 +448,7 @@ char *str; return(ret); } -BIO *BIO_new_accept(str) -char *str; +BIO *BIO_new_accept(char *str) { BIO *ret; diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c new file mode 100644 index 0000000000..562e9d8de2 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_bio.c @@ -0,0 +1,588 @@ +/* crypto/bio/bss_bio.c -*- Mode: C; c-file-style: "eay" -*- */ + +/* Special method for a BIO where the other endpoint is also a BIO + * of this kind, handled by the same thread (i.e. the "peer" is actually + * ourselves, wearing a different hat). + * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces + * for which no specific BIO method is available. + * See ssl/ssltest.c for some hints on how this can be used. */ + +#ifndef BIO_PAIR_DEBUG +# undef NDEBUG /* avoid conflicting definitions */ +# define NDEBUG +#endif + +#include +#include +#include + +#include +#include +#include + +static int bio_new(BIO *bio); +static int bio_free(BIO *bio); +static int bio_read(BIO *bio, char *buf, int size); +static int bio_write(BIO *bio, char *buf, int num); +static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr); +static int bio_puts(BIO *bio, char *str); + +static int bio_make_pair(BIO *bio1, BIO *bio2); +static void bio_destroy_pair(BIO *bio); + +static BIO_METHOD methods_biop = +{ + BIO_TYPE_BIO, + "BIO pair", + bio_write, + bio_read, + bio_puts, + NULL /* no bio_gets */, + bio_ctrl, + bio_new, + bio_free +}; + +BIO_METHOD *BIO_s_bio(void) + { + return &methods_biop; + } + +struct bio_bio_st +{ + BIO *peer; /* NULL if buf == NULL. + * If peer != NULL, then peer->ptr is also a bio_bio_st, + * and its "peer" member points back to us. + * peer != NULL iff init != 0 in the BIO. */ + + /* This is for what we write (i.e. reading uses peer's struct): */ + int closed; /* valid iff peer != NULL */ + size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ + size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ + size_t size; + char *buf; /* "size" elements (if != NULL) */ + + size_t request; /* valid iff peer != NULL; 0 if len != 0, + * otherwise set by peer to number of bytes + * it (unsuccesfully) tried to read, + * never more than buffer space (size-len) warrants. */ +}; + +static int bio_new(BIO *bio) + { + struct bio_bio_st *b; + + b = Malloc(sizeof *b); + if (b == NULL) + return 0; + + b->peer = NULL; + b->size = 17*1024; /* enough for one TLS record (just a default) */ + b->buf = NULL; + + bio->ptr = b; + return 1; + } + + +static int bio_free(BIO *bio) + { + struct bio_bio_st *b; + + if (bio == NULL) + return 0; + b = bio->ptr; + + assert(b != NULL); + + if (b->peer) + bio_destroy_pair(bio); + + if (b->buf != NULL) + { + Free(b->buf); + } + + Free(b); + + return 1; + } + + + +static int bio_read(BIO *bio, char *buf, int size_) + { + size_t size = size_; + size_t rest; + struct bio_bio_st *b, *peer_b; + + BIO_clear_retry_flags(bio); + + if (!bio->init) + return 0; + + b = bio->ptr; + assert(b != NULL); + assert(b->peer != NULL); + peer_b = b->peer->ptr; + assert(peer_b != NULL); + assert(peer_b->buf != NULL); + + peer_b->request = 0; /* will be set in "retry_read" situation */ + + if (buf == NULL || size == 0) + return 0; + + if (peer_b->len == 0) + { + if (peer_b->closed) + return 0; /* writer has closed, and no data is left */ + else + { + BIO_set_retry_read(bio); /* buffer is empty */ + if (size <= peer_b->size) + peer_b->request = size; + else + /* don't ask for more than the peer can + * deliver in one write */ + peer_b->request = peer_b->size; + return -1; + } + } + + /* we can read */ + if (peer_b->len < size) + size = peer_b->len; + + /* now read "size" bytes */ + + rest = size; + + assert(rest > 0); + do /* one or two iterations */ + { + size_t chunk; + + assert(rest <= peer_b->len); + if (peer_b->offset + rest <= peer_b->size) + chunk = rest; + else + /* wrap around ring buffer */ + chunk = peer_b->size - peer_b->offset; + assert(peer_b->offset + chunk <= peer_b->size); + + memcpy(buf, peer_b->buf + peer_b->offset, chunk); + + peer_b->len -= chunk; + if (peer_b->len) + { + peer_b->offset += chunk; + assert(peer_b->offset <= peer_b->size); + if (peer_b->offset == peer_b->size) + peer_b->offset = 0; + buf += chunk; + } + else + { + /* buffer now empty, no need to advance "buf" */ + assert(chunk == rest); + peer_b->offset = 0; + } + rest -= chunk; + } + while (rest); + + return size; + } + +static int bio_write(BIO *bio, char *buf, int num_) + { + size_t num = num_; + size_t rest; + struct bio_bio_st *b; + + BIO_clear_retry_flags(bio); + + if (!bio->init || buf == NULL || num == 0) + return 0; + + b = bio->ptr; + assert(b != NULL); + assert(b->peer != NULL); + assert(b->buf != NULL); + + b->request = 0; + if (b->closed) + { + /* we already closed */ + BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); + return -1; + } + + assert(b->len <= b->size); + + if (b->len == b->size) + { + BIO_set_retry_write(bio); /* buffer is full */ + return -1; + } + + /* we can write */ + if (num > b->size - b->len) + num = b->size - b->len; + + /* now write "num" bytes */ + + rest = num; + + assert(rest > 0); + do /* one or two iterations */ + { + size_t write_offset; + size_t chunk; + + assert(b->len + rest <= b->size); + + write_offset = b->offset + b->len; + if (write_offset >= b->size) + write_offset -= b->size; + /* b->buf[write_offset] is the first byte we can write to. */ + + if (write_offset + rest <= b->size) + chunk = rest; + else + /* wrap around ring buffer */ + chunk = b->size - write_offset; + + memcpy(b->buf + write_offset, buf, chunk); + + b->len += chunk; + + assert(b->len <= b->size); + + rest -= chunk; + buf += chunk; + } + while (rest); + + return num; + } + + +static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) + { + long ret; + struct bio_bio_st *b = bio->ptr; + + assert(b != NULL); + + switch (cmd) + { + /* specific CTRL codes */ + + case BIO_C_SET_WRITE_BUF_SIZE: + if (b->peer) + { + BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); + ret = 0; + } + else if (num == 0) + { + BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); + ret = 0; + } + else + { + size_t new_size = num; + + if (b->size != new_size) + { + if (b->buf) + { + Free(b->buf); + b->buf = NULL; + } + b->size = new_size; + } + ret = 1; + } + break; + + case BIO_C_GET_WRITE_BUF_SIZE: + num = (long) b->size; + + case BIO_C_MAKE_BIO_PAIR: + { + BIO *other_bio = ptr; + + if (bio_make_pair(bio, other_bio)) + ret = 1; + else + ret = 0; + } + break; + + case BIO_C_DESTROY_BIO_PAIR: + /* Effects both BIOs in the pair -- call just once! + * Or let BIO_free(bio1); BIO_free(bio2); do the job. */ + bio_destroy_pair(bio); + ret = 1; + break; + + case BIO_C_GET_WRITE_GUARANTEE: + /* How many bytes can the caller feed to the next write + * withouth having to keep any? */ + if (b->peer == NULL || b->closed) + ret = 0; + else + ret = (long) b->size - b->len; + break; + + case BIO_C_GET_READ_REQUEST: + /* If the peer unsuccesfully tried to read, how many bytes + * were requested? (As with BIO_CTRL_PENDING, that number + * can usually be treated as boolean.) */ + ret = (long) b->request; + break; + + case BIO_C_SHUTDOWN_WR: + /* similar to shutdown(..., SHUT_WR) */ + b->closed = 1; + ret = 1; + break; + + + /* standard CTRL codes follow */ + + case BIO_CTRL_RESET: + if (b->buf != NULL) + { + b->len = 0; + b->offset = 0; + } + ret = 0; + break; + + case BIO_CTRL_GET_CLOSE: + ret = bio->shutdown; + break; + + case BIO_CTRL_SET_CLOSE: + bio->shutdown = (int) num; + ret = 1; + break; + + case BIO_CTRL_PENDING: + if (b->peer != NULL) + { + struct bio_bio_st *peer_b = b->peer->ptr; + + ret = (long) peer_b->len; + } + else + ret = 0; + break; + + case BIO_CTRL_WPENDING: + if (b->buf != NULL) + ret = (long) b->len; + else + ret = 0; + break; + + case BIO_CTRL_DUP: + /* See BIO_dup_chain for circumstances we have to expect. */ + { + BIO *other_bio = ptr; + struct bio_bio_st *other_b; + + assert(other_bio != NULL); + other_b = other_bio->ptr; + assert(other_b != NULL); + + assert(other_b->buf == NULL); /* other_bio is always fresh */ + + other_b->size = b->size; + } + + ret = 1; + break; + + case BIO_CTRL_FLUSH: + ret = 1; + break; + + case BIO_CTRL_EOF: + { + BIO *other_bio = ptr; + + if (other_bio) + { + struct bio_bio_st *other_b = other_bio->ptr; + + assert(other_b != NULL); + ret = other_b->len == 0 && other_b->closed; + } + else + ret = 1; + } + break; + + default: + ret = 0; + } + return ret; + } + +static int bio_puts(BIO *bio, char *str) + { + return bio_write(bio, str, strlen(str)); + } + + +static int bio_make_pair(BIO *bio1, BIO *bio2) + { + struct bio_bio_st *b1, *b2; + + assert(bio1 != NULL); + assert(bio2 != NULL); + + b1 = bio1->ptr; + b2 = bio2->ptr; + + if (b1->peer != NULL || b2->peer != NULL) + { + BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); + return 0; + } + + if (b1->buf == NULL) + { + b1->buf = Malloc(b1->size); + if (b1->buf == NULL) + { + BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); + return 0; + } + b1->len = 0; + b1->offset = 0; + } + + if (b2->buf == NULL) + { + b2->buf = Malloc(b2->size); + if (b2->buf == NULL) + { + BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); + return 0; + } + b2->len = 0; + b2->offset = 0; + } + + b1->peer = bio2; + b1->closed = 0; + b1->request = 0; + b2->peer = bio1; + b2->closed = 0; + b2->request = 0; + + bio1->init = 1; + bio2->init = 1; + + return 1; + } + +static void bio_destroy_pair(BIO *bio) + { + struct bio_bio_st *b = bio->ptr; + + if (b != NULL) + { + BIO *peer_bio = b->peer; + + if (peer_bio != NULL) + { + struct bio_bio_st *peer_b = peer_bio->ptr; + + assert(peer_b != NULL); + assert(peer_b->peer == bio); + + peer_b->peer = NULL; + peer_bio->init = 0; + assert(peer_b->buf != NULL); + peer_b->len = 0; + peer_b->offset = 0; + + b->peer = NULL; + bio->init = 0; + assert(b->buf != NULL); + b->len = 0; + b->offset = 0; + } + } + } + + +/* Exported convenience functions */ +int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, + BIO **bio2_p, size_t writebuf2) + { + BIO *bio1 = NULL, *bio2 = NULL; + long r; + int ret = 0; + + bio1 = BIO_new(BIO_s_bio()); + if (bio1 == NULL) + goto err; + bio2 = BIO_new(BIO_s_bio()); + if (bio2 == NULL) + goto err; + + if (writebuf1) + { + r = BIO_set_write_buf_size(bio1, writebuf1); + if (!r) + goto err; + } + if (writebuf2) + { + r = BIO_set_write_buf_size(bio2, writebuf2); + if (!r) + goto err; + } + + r = BIO_make_bio_pair(bio1, bio2); + if (!r) + goto err; + ret = 1; + + err: + if (ret == 0) + { + if (bio1) + { + BIO_free(bio1); + bio1 = NULL; + } + if (bio2) + { + BIO_free(bio2); + bio2 = NULL; + } + } + + *bio1_p = bio1; + *bio2_p = bio2; + return ret; + } + +size_t BIO_ctrl_get_write_guarantee(BIO *bio) + { + return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); + } + +size_t BIO_ctrl_get_read_request(BIO *bio) + { + return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); + } diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c index 6e547bf866..68c46e3d69 100644 --- a/src/lib/libcrypto/bio/bss_conn.c +++ b/src/lib/libcrypto/bio/bss_conn.c @@ -62,9 +62,7 @@ #include #define USE_SOCKETS #include "cryptlib.h" -#include "bio.h" - -/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */ +#include #ifdef WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ @@ -72,6 +70,12 @@ #define SOCKET_PROTOCOL IPPROTO_TCP #endif +#if (defined(VMS) && __VMS_VER < 70000000) +/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */ +#undef FIONBIO +#endif + + typedef struct bio_connect_st { int state; @@ -81,13 +85,12 @@ typedef struct bio_connect_st int nbio; unsigned char ip[4]; - short port; + unsigned short port; struct sockaddr_in them; /* int socket; this will be kept in bio->num so that it is * compatable with the bss_sock bio */ - int error; /* called when the connection is initially made * callback(BIO,state,ret); The callback should return @@ -95,38 +98,18 @@ typedef struct bio_connect_st int (*info_callback)(); } BIO_CONNECT; -#ifndef NOPROTO static int conn_write(BIO *h,char *buf,int num); static int conn_read(BIO *h,char *buf,int size); static int conn_puts(BIO *h,char *str); static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int conn_new(BIO *h); static int conn_free(BIO *data); -#else -static int conn_write(); -static int conn_read(); -static int conn_puts(); -static long conn_ctrl(); -static int conn_new(); -static int conn_free(); -#endif - -#ifndef NOPROTO static int conn_state(BIO *b, BIO_CONNECT *c); static void conn_close_socket(BIO *data); BIO_CONNECT *BIO_CONNECT_new(void ); void BIO_CONNECT_free(BIO_CONNECT *a); -#else - -static int conn_state(); -static void conn_close_socket(); -BIO_CONNECT *BIO_CONNECT_new(); -void BIO_CONNECT_free(); - -#endif - static BIO_METHOD methods_connectp= { BIO_TYPE_CONNECT, @@ -140,9 +123,7 @@ static BIO_METHOD methods_connectp= conn_free, }; -static int conn_state(b,c) -BIO *b; -BIO_CONNECT *c; +static int conn_state(BIO *b, BIO_CONNECT *c) { int ret= -1,i; unsigned long l; @@ -160,7 +141,7 @@ BIO_CONNECT *c; p=c->param_hostname; if (p == NULL) { - BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTHNAME_SPECIFIED); + BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED); goto exit_loop; } for ( ; *p != '\0'; p++) @@ -187,7 +168,7 @@ BIO_CONNECT *c; } } - if (p == NULL) + if (c->param_port == NULL) { BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); ERR_add_error_data(2,"host=",c->param_hostname); @@ -203,7 +184,12 @@ BIO_CONNECT *c; break; case BIO_CONN_S_GET_PORT: - if (BIO_get_port(c->param_port,&c->port) <= 0) + if (c->param_port == NULL) + { + abort(); + goto exit_loop; + } + else if (BIO_get_port(c->param_port,&c->port) <= 0) goto exit_loop; c->state=BIO_CONN_S_CREATE_SOCKET; break; @@ -235,12 +221,9 @@ BIO_CONNECT *c; break; case BIO_CONN_S_NBIO: -#ifdef FIONBIO if (c->nbio) { - l=1; - ret=BIO_socket_ioctl(b->num,FIONBIO,&l); - if (ret < 0) + if (!BIO_socket_nbio(b->num,1)) { BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); ERR_add_error_data(4,"host=", @@ -249,7 +232,6 @@ BIO_CONNECT *c; goto exit_loop; } } -#endif c->state=BIO_CONN_S_CONNECT; #ifdef SO_KEEPALIVE @@ -326,17 +308,15 @@ BIO_CONNECT *c; } } - if (1) - { + /* Loop does not exit */ exit_loop: - if (cb != NULL) - ret=cb((BIO *)b,c->state,ret); - } + if (cb != NULL) + ret=cb((BIO *)b,c->state,ret); end: return(ret); } -BIO_CONNECT *BIO_CONNECT_new() +BIO_CONNECT *BIO_CONNECT_new(void) { BIO_CONNECT *ret; @@ -353,13 +333,14 @@ BIO_CONNECT *BIO_CONNECT_new() ret->ip[3]=0; ret->port=0; memset((char *)&ret->them,0,sizeof(ret->them)); - ret->error=0; return(ret); } -void BIO_CONNECT_free(a) -BIO_CONNECT *a; +void BIO_CONNECT_free(BIO_CONNECT *a) { + if(a == NULL) + return; + if (a->param_hostname != NULL) Free(a->param_hostname); if (a->param_port != NULL) @@ -367,13 +348,12 @@ BIO_CONNECT *a; Free(a); } -BIO_METHOD *BIO_s_connect() +BIO_METHOD *BIO_s_connect(void) { return(&methods_connectp); } -static int conn_new(bi) -BIO *bi; +static int conn_new(BIO *bi) { bi->init=0; bi->num=INVALID_SOCKET; @@ -384,8 +364,7 @@ BIO *bi; return(1); } -static void conn_close_socket(bio) -BIO *bio; +static void conn_close_socket(BIO *bio) { BIO_CONNECT *c; @@ -395,17 +374,12 @@ BIO *bio; /* Only do a shutdown if things were established */ if (c->state == BIO_CONN_S_OK) shutdown(bio->num,2); -# ifdef WINDOWS closesocket(bio->num); -# else - close(bio->num); -# endif bio->num=INVALID_SOCKET; } } -static int conn_free(a) -BIO *a; +static int conn_free(BIO *a) { BIO_CONNECT *data; @@ -423,10 +397,7 @@ BIO *a; return(1); } -static int conn_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int conn_read(BIO *b, char *out, int outl) { int ret=0; BIO_CONNECT *data; @@ -442,11 +413,7 @@ int outl; if (out != NULL) { clear_socket_error(); -#if defined(WINDOWS) - ret=recv(b->num,out,outl,0); -#else - ret=read(b->num,out,outl); -#endif + ret=readsocket(b->num,out,outl); BIO_clear_retry_flags(b); if (ret <= 0) { @@ -457,10 +424,7 @@ int outl; return(ret); } -static int conn_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int conn_write(BIO *b, char *in, int inl) { int ret; BIO_CONNECT *data; @@ -473,11 +437,7 @@ int inl; } clear_socket_error(); -#if defined(WINDOWS) - ret=send(b->num,in,inl,0); -#else - ret=write(b->num,in,inl); -#endif + ret=writesocket(b->num,in,inl); BIO_clear_retry_flags(b); if (ret <= 0) { @@ -487,15 +447,11 @@ int inl; return(ret); } -static long conn_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long conn_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO *dbio; int *ip; - char **pptr; + const char **pptr; long ret=1; BIO_CONNECT *data; @@ -519,7 +475,7 @@ char *ptr; case BIO_C_GET_CONNECT: if (ptr != NULL) { - pptr=(char **)ptr; + pptr=(const char **)ptr; if (num == 0) { *pptr=data->param_hostname; @@ -559,9 +515,26 @@ char *ptr; data->param_port=BUF_strdup(ptr); } else if (num == 2) - memcpy(data->ip,ptr,4); + { + char buf[16]; + + sprintf(buf,"%d.%d.%d.%d", + ptr[0],ptr[1],ptr[2],ptr[3]); + if (data->param_hostname != NULL) + Free(data->param_hostname); + data->param_hostname=BUF_strdup(buf); + memcpy(&(data->ip[0]),ptr,4); + } else if (num == 3) + { + char buf[16]; + + sprintf(buf,"%d",*(int *)ptr); + if (data->param_port != NULL) + Free(data->param_port); + data->param_port=BUF_strdup(buf); data->port= *(int *)ptr; + } } break; case BIO_C_SET_NBIO: @@ -597,7 +570,7 @@ char *ptr; if (data->param_hostname) BIO_set_conn_hostname(dbio,data->param_hostname); BIO_set_nbio(dbio,data->nbio); - BIO_set_info_callback(dbio,data->info_callback); + (void)BIO_set_info_callback(dbio,data->info_callback); break; case BIO_CTRL_SET_CALLBACK: data->info_callback=(int (*)())ptr; @@ -617,9 +590,7 @@ char *ptr; return(ret); } -static int conn_puts(bp,str) -BIO *bp; -char *str; +static int conn_puts(BIO *bp, char *str) { int n,ret; @@ -628,8 +599,7 @@ char *str; return(ret); } -BIO *BIO_new_connect(str) -char *str; +BIO *BIO_new_connect(char *str) { BIO *ret; diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 1484cf849e..52c0c39df0 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c @@ -68,12 +68,11 @@ #include #include #include "cryptlib.h" -#include "bio.h" -#include "err.h" +#include +#include #if !defined(NO_STDIO) -#ifndef NOPROTO static int MS_CALLBACK file_write(BIO *h,char *buf,int num); static int MS_CALLBACK file_read(BIO *h,char *buf,int size); static int MS_CALLBACK file_puts(BIO *h,char *str); @@ -81,16 +80,6 @@ static int MS_CALLBACK file_gets(BIO *h,char *str,int size); static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int MS_CALLBACK file_new(BIO *h); static int MS_CALLBACK file_free(BIO *data); -#else -static int MS_CALLBACK file_write(); -static int MS_CALLBACK file_read(); -static int MS_CALLBACK file_puts(); -static int MS_CALLBACK file_gets(); -static long MS_CALLBACK file_ctrl(); -static int MS_CALLBACK file_new(); -static int MS_CALLBACK file_free(); -#endif - static BIO_METHOD methods_filep= { BIO_TYPE_FILE, @@ -104,9 +93,7 @@ static BIO_METHOD methods_filep= file_free, }; -BIO *BIO_new_file(filename,mode) -char *filename; -char *mode; +BIO *BIO_new_file(const char *filename, const char *mode) { BIO *ret; FILE *file; @@ -125,9 +112,7 @@ char *mode; return(ret); } -BIO *BIO_new_fp(stream,close_flag) -FILE *stream; -int close_flag; +BIO *BIO_new_fp(FILE *stream, int close_flag) { BIO *ret; @@ -138,13 +123,12 @@ int close_flag; return(ret); } -BIO_METHOD *BIO_s_file() +BIO_METHOD *BIO_s_file(void) { return(&methods_filep); } -static int MS_CALLBACK file_new(bi) -BIO *bi; +static int MS_CALLBACK file_new(BIO *bi) { bi->init=0; bi->num=0; @@ -152,8 +136,7 @@ BIO *bi; return(1); } -static int MS_CALLBACK file_free(a) -BIO *a; +static int MS_CALLBACK file_free(BIO *a) { if (a == NULL) return(0); if (a->shutdown) @@ -168,10 +151,7 @@ BIO *a; return(1); } -static int MS_CALLBACK file_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int MS_CALLBACK file_read(BIO *b, char *out, int outl) { int ret=0; @@ -182,10 +162,7 @@ int outl; return(ret); } -static int MS_CALLBACK file_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int MS_CALLBACK file_write(BIO *b, char *in, int inl) { int ret=0; @@ -201,11 +178,7 @@ int inl; return(ret); } -static long MS_CALLBACK file_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret=1; FILE *fp=(FILE *)b->ptr; @@ -214,18 +187,20 @@ char *ptr; switch (cmd) { + case BIO_C_FILE_SEEK: case BIO_CTRL_RESET: ret=(long)fseek(fp,num,0); break; case BIO_CTRL_EOF: ret=(long)feof(fp); break; + case BIO_C_FILE_TELL: case BIO_CTRL_INFO: ret=ftell(fp); break; case BIO_C_SET_FILE_PTR: file_free(b); - b->shutdown=(int)num; + b->shutdown=(int)num&BIO_CLOSE; b->ptr=(char *)ptr; b->init=1; #if defined(MSDOS) || defined(WINDOWS) @@ -307,10 +282,7 @@ char *ptr; return(ret); } -static int MS_CALLBACK file_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size) { int ret=0; @@ -321,9 +293,7 @@ int size; return(ret); } -static int MS_CALLBACK file_puts(bp,str) -BIO *bp; -char *str; +static int MS_CALLBACK file_puts(BIO *bp, char *str) { int n,ret; diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c new file mode 100644 index 0000000000..db82e757e7 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_log.c @@ -0,0 +1,232 @@ +/* crypto/bio/bss_log.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + Why BIO_s_log? + + BIO_s_log is useful for system daemons (or services under NT). + It is one-way BIO, it sends all stuff to syslogd (or event log + under NT). + +*/ + + +#include +#include + +#ifndef WIN32 +#ifdef __ultrix +#include +#else +#include +#endif +#endif + +#include "cryptlib.h" +#include +#include +#ifndef NO_SYSLOG + + +static int MS_CALLBACK slg_write(BIO *h,char *buf,int num); +static int MS_CALLBACK slg_puts(BIO *h,char *str); +static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2); +static int MS_CALLBACK slg_new(BIO *h); +static int MS_CALLBACK slg_free(BIO *data); +static int xopenlog(BIO* bp, const char* name, int level); +static int xcloselog(BIO* bp); + +static BIO_METHOD methods_slg= + { + BIO_TYPE_MEM,"syslog", + slg_write, + NULL, + slg_puts, + NULL, + slg_ctrl, + slg_new, + slg_free, + }; + +BIO_METHOD *BIO_s_log(void) + { + return(&methods_slg); + } + +static int MS_CALLBACK slg_new(BIO *bi) + { + bi->init=1; + bi->num=0; + bi->ptr=NULL; +#ifndef WIN32 + xopenlog(bi, "application", LOG_DAEMON); +#else + xopenlog(bi, "application", 0); +#endif + return(1); + } + +static int MS_CALLBACK slg_free(BIO *a) + { + if (a == NULL) return(0); + xcloselog(a); + return(1); + } + +static int MS_CALLBACK slg_write(BIO *b, char *in, int inl) + { + int ret= inl; + char* buf= in; + char* pp; +#if defined(WIN32) + LPTSTR lpszStrings[1]; + WORD evtype= EVENTLOG_ERROR_TYPE; +#else + int priority; +#endif + + if((buf= (char *)Malloc(inl+ 1)) == NULL){ + return(0); + } + strncpy(buf, in, inl); + buf[inl]= '\0'; +#if defined(WIN32) + if(strncmp(buf, "ERR ", 4) == 0){ + evtype= EVENTLOG_ERROR_TYPE; + pp= buf+ 4; + }else if(strncmp(buf, "WAR ", 4) == 0){ + evtype= EVENTLOG_WARNING_TYPE; + pp= buf+ 4; + }else if(strncmp(buf, "INF ", 4) == 0){ + evtype= EVENTLOG_INFORMATION_TYPE; + pp= buf+ 4; + }else{ + evtype= EVENTLOG_ERROR_TYPE; + pp= buf; + } + lpszStrings[0]= pp; + + if(b->ptr) + ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0, + lpszStrings, NULL); +#else + if(strncmp(buf, "ERR ", 4) == 0){ + priority= LOG_ERR; + pp= buf+ 4; + }else if(strncmp(buf, "WAR ", 4) == 0){ + priority= LOG_WARNING; + pp= buf+ 4; + }else if(strncmp(buf, "INF ", 4) == 0){ + priority= LOG_INFO; + pp= buf+ 4; + }else{ + priority= LOG_ERR; + pp= buf; + } + + syslog(priority, "%s", pp); +#endif + Free(buf); + return(ret); + } + +static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr) + { + switch (cmd) + { + case BIO_CTRL_SET: + xcloselog(b); + xopenlog(b, ptr, num); + break; + default: + break; + } + return(0); + } + +static int MS_CALLBACK slg_puts(BIO *bp, char *str) + { + int n,ret; + + n=strlen(str); + ret=slg_write(bp,str,n); + return(ret); + } + +static int xopenlog(BIO* bp, const char* name, int level) +{ +#if defined(WIN32) + if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){ + return(0); + } +#else + openlog(name, LOG_PID|LOG_CONS, level); +#endif + return(1); +} + +static int xcloselog(BIO* bp) +{ +#if defined(WIN32) + if(bp->ptr) + DeregisterEventSource((HANDLE)(bp->ptr)); + bp->ptr= NULL; +#else + closelog(); +#endif + return(1); +} + +#endif diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c index 40c4e39f02..7e749a503e 100644 --- a/src/lib/libcrypto/bio/bss_mem.c +++ b/src/lib/libcrypto/bio/bss_mem.c @@ -59,9 +59,8 @@ #include #include #include "cryptlib.h" -#include "bio.h" +#include -#ifndef NOPROTO static int mem_write(BIO *h,char *buf,int num); static int mem_read(BIO *h,char *buf,int size); static int mem_puts(BIO *h,char *str); @@ -69,16 +68,6 @@ static int mem_gets(BIO *h,char *str,int size); static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int mem_new(BIO *h); static int mem_free(BIO *data); -#else -static int mem_write(); -static int mem_read(); -static int mem_puts(); -static int mem_gets(); -static long mem_ctrl(); -static int mem_new(); -static int mem_free(); -#endif - static BIO_METHOD mem_method= { BIO_TYPE_MEM, @@ -92,13 +81,15 @@ static BIO_METHOD mem_method= mem_free, }; -BIO_METHOD *BIO_s_mem() +/* bio->num is used to hold the value to return on 'empty', if it is + * 0, should_retry is not set */ + +BIO_METHOD *BIO_s_mem(void) { return(&mem_method); } -static int mem_new(bi) -BIO *bi; +static int mem_new(BIO *bi) { BUF_MEM *b; @@ -106,13 +97,12 @@ BIO *bi; return(0); bi->shutdown=1; bi->init=1; - bi->num=0; + bi->num= -1; bi->ptr=(char *)b; return(1); } -static int mem_free(a) -BIO *a; +static int mem_free(BIO *a) { if (a == NULL) return(0); if (a->shutdown) @@ -126,10 +116,7 @@ BIO *a; return(1); } -static int mem_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int mem_read(BIO *b, char *out, int outl) { int ret= -1; BUF_MEM *bm; @@ -151,16 +138,14 @@ int outl; } else if (bm->length == 0) { - BIO_set_retry_read(b); - ret= -1; + if (b->num != 0) + BIO_set_retry_read(b); + ret= b->num; } return(ret); } -static int mem_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int mem_write(BIO *b, char *in, int inl) { int ret= -1; int blen; @@ -183,11 +168,7 @@ end: return(ret); } -static long mem_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long mem_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret=1; char **pptr; @@ -204,6 +185,9 @@ char *ptr; case BIO_CTRL_EOF: ret=(long)(bm->length == 0); break; + case BIO_C_SET_BUF_MEM_EOF_RETURN: + b->num=(int)num; + break; case BIO_CTRL_INFO: ret=(long)bm->length; if (ptr != NULL) @@ -250,10 +234,7 @@ char *ptr; return(ret); } -static int mem_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int mem_gets(BIO *bp, char *buf, int size) { int i,j; int ret= -1; @@ -283,9 +264,7 @@ int size; return(ret); } -static int mem_puts(bp,str) -BIO *bp; -char *str; +static int mem_puts(BIO *bp, char *str) { int n,ret; diff --git a/src/lib/libcrypto/bio/bss_null.c b/src/lib/libcrypto/bio/bss_null.c index 0791a2471a..d04be888e5 100644 --- a/src/lib/libcrypto/bio/bss_null.c +++ b/src/lib/libcrypto/bio/bss_null.c @@ -59,9 +59,8 @@ #include #include #include "cryptlib.h" -#include "bio.h" +#include -#ifndef NOPROTO static int null_write(BIO *h,char *buf,int num); static int null_read(BIO *h,char *buf,int size); static int null_puts(BIO *h,char *str); @@ -69,16 +68,6 @@ static int null_gets(BIO *h,char *str,int size); static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int null_new(BIO *h); static int null_free(BIO *data); -#else -static int null_write(); -static int null_read(); -static int null_puts(); -static int null_gets(); -static long null_ctrl(); -static int null_new(); -static int null_free(); -#endif - static BIO_METHOD null_method= { BIO_TYPE_NULL, @@ -92,13 +81,12 @@ static BIO_METHOD null_method= null_free, }; -BIO_METHOD *BIO_s_null() +BIO_METHOD *BIO_s_null(void) { return(&null_method); } -static int null_new(bi) -BIO *bi; +static int null_new(BIO *bi) { bi->init=1; bi->num=0; @@ -106,34 +94,23 @@ BIO *bi; return(1); } -static int null_free(a) -BIO *a; +static int null_free(BIO *a) { if (a == NULL) return(0); return(1); } -static int null_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int null_read(BIO *b, char *out, int outl) { return(0); } -static int null_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int null_write(BIO *b, char *in, int inl) { return(inl); } -static long null_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long null_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret=1; @@ -159,17 +136,12 @@ char *ptr; return(ret); } -static int null_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int null_gets(BIO *bp, char *buf, int size) { return(0); } -static int null_puts(bp,str) -BIO *bp; -char *str; +static int null_puts(BIO *bp, char *str) { if (str == NULL) return(0); return(strlen(str)); diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c index 6eb434dee8..2ef040057e 100644 --- a/src/lib/libcrypto/bio/bss_rtcp.c +++ b/src/lib/libcrypto/bio/bss_rtcp.c @@ -58,6 +58,7 @@ /* Written by David L. Jones * Date: 22-JUL-1996 + * Revised: 25-SEP-1997 Update for 0.8.1, BIO_CTRL_SET -> BIO_C_SET_FD */ /* VMS */ #include @@ -65,10 +66,11 @@ #include #include #include "cryptlib.h" -#include "bio.h" +#include #include /* VMS IO$_ definitions */ -extern int SYS$QIOW(); +#include + typedef unsigned short io_channel; /*************************************************************************/ struct io_status { short status, count; long flags; }; @@ -107,18 +109,24 @@ static BIO_METHOD rtcp_method= rtcp_free, }; -BIO_METHOD *BIO_s_rtcp() +BIO_METHOD *BIO_s_rtcp(void) { return(&rtcp_method); } /*****************************************************************************/ /* Decnet I/O routines. */ + +#ifdef __DECC +#pragma message save +#pragma message disable DOLLARID +#endif + static int get ( io_channel chan, char *buffer, int maxlen, int *length ) { int status; struct io_status iosb; - status = SYS$QIOW ( 0, chan, IO$_READVBLK, &iosb, 0, 0, + status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0, buffer, maxlen, 0, 0, 0, 0 ); if ( (status&1) == 1 ) status = iosb.status; if ( (status&1) == 1 ) *length = iosb.count; @@ -129,15 +137,19 @@ static int put ( io_channel chan, char *buffer, int length ) { int status; struct io_status iosb; - status = SYS$QIOW ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, + status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, buffer, length, 0, 0, 0, 0 ); if ( (status&1) == 1 ) status = iosb.status; return status; } + +#ifdef __DECC +#pragma message restore +#endif + /***************************************************************************/ -static int rtcp_new(bi) -BIO *bi; +static int rtcp_new(BIO *bi) { struct rpc_ctx *ctx; bi->init=1; @@ -150,8 +162,7 @@ BIO *bi; return(1); } -static int rtcp_free(a) -BIO *a; +static int rtcp_free(BIO *a) { if (a == NULL) return(0); if ( a->ptr ) Free ( a->ptr ); @@ -159,10 +170,7 @@ BIO *a; return(1); } -static int rtcp_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int rtcp_read(BIO *b, char *out, int outl) { int status, length; struct rpc_ctx *ctx; @@ -209,10 +217,7 @@ int outl; return length; } -static int rtcp_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int rtcp_write(BIO *b, char *in, int inl) { int status, i, segment, length; struct rpc_ctx *ctx; @@ -241,11 +246,7 @@ int inl; return(i); } -static long rtcp_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long rtcp_ctrl(BIO *b, int cmd, long num, char *ptr) { long ret=1; @@ -255,7 +256,7 @@ char *ptr; case BIO_CTRL_EOF: ret = 1; break; - case BIO_CTRL_SET: + case BIO_C_SET_FD: b->num = num; ret = 1; break; @@ -276,17 +277,12 @@ char *ptr; return(ret); } -static int rtcp_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int rtcp_gets(BIO *bp, char *buf, int size) { return(0); } -static int rtcp_puts(bp,str) -BIO *bp; -char *str; +static int rtcp_puts(BIO *bp, char *str) { int length; if (str == NULL) return(0); diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c index d907a2867b..d336b99fe8 100644 --- a/src/lib/libcrypto/bio/bss_sock.c +++ b/src/lib/libcrypto/bio/bss_sock.c @@ -62,10 +62,9 @@ #include #define USE_SOCKETS #include "cryptlib.h" -#include "bio.h" +#include #ifndef BIO_FD -#ifndef NOPROTO static int sock_write(BIO *h,char *buf,int num); static int sock_read(BIO *h,char *buf,int size); static int sock_puts(BIO *h,char *str); @@ -73,19 +72,8 @@ static long sock_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int sock_new(BIO *h); static int sock_free(BIO *data); int BIO_sock_should_retry(int s); -#else -static int sock_write(); -static int sock_read(); -static int sock_puts(); -static long sock_ctrl(); -static int sock_new(); -static int sock_free(); -int BIO_sock_should_retry(); -#endif - #else -#ifndef NOPROTO static int fd_write(BIO *h,char *buf,int num); static int fd_read(BIO *h,char *buf,int size); static int fd_puts(BIO *h,char *str); @@ -93,15 +81,6 @@ static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int fd_new(BIO *h); static int fd_free(BIO *data); int BIO_fd_should_retry(int s); -#else -static int fd_write(); -static int fd_read(); -static int fd_puts(); -static long fd_ctrl(); -static int fd_new(); -static int fd_free(); -int BIO_fd_should_retry(); -#endif #endif #ifndef BIO_FD @@ -118,7 +97,7 @@ static BIO_METHOD methods_sockp= sock_free, }; -BIO_METHOD *BIO_s_socket() +BIO_METHOD *BIO_s_socket(void) { return(&methods_sockp); } @@ -135,19 +114,17 @@ static BIO_METHOD methods_fdp= fd_free, }; -BIO_METHOD *BIO_s_fd() +BIO_METHOD *BIO_s_fd(void) { return(&methods_fdp); } #endif #ifndef BIO_FD -BIO *BIO_new_socket(fd,close_flag) +BIO *BIO_new_socket(int fd, int close_flag) #else -BIO *BIO_new_fd(fd,close_flag) +BIO *BIO_new_fd(int fd,int close_flag) #endif -int fd; -int close_flag; { BIO *ret; @@ -162,11 +139,10 @@ int close_flag; } #ifndef BIO_FD -static int sock_new(bi) +static int sock_new(BIO *bi) #else -static int fd_new(bi) +static int fd_new(BIO *bi) #endif -BIO *bi; { bi->init=0; bi->num=0; @@ -176,11 +152,10 @@ BIO *bi; } #ifndef BIO_FD -static int sock_free(a) +static int sock_free(BIO *a) #else -static int fd_free(a) +static int fd_free(BIO *a) #endif -BIO *a; { if (a == NULL) return(0); if (a->shutdown) @@ -189,11 +164,7 @@ BIO *a; { #ifndef BIO_FD shutdown(a->num,2); -# ifdef WINDOWS closesocket(a->num); -# else - close(a->num); -# endif #else /* BIO_FD */ close(a->num); #endif @@ -206,21 +177,18 @@ BIO *a; } #ifndef BIO_FD -static int sock_read(b,out,outl) +static int sock_read(BIO *b, char *out, int outl) #else -static int fd_read(b,out,outl) +static int fd_read(BIO *b, char *out,int outl) #endif -BIO *b; -char *out; -int outl; { int ret=0; if (out != NULL) { -#if defined(WINDOWS) && !defined(BIO_FD) +#ifndef BIO_FD clear_socket_error(); - ret=recv(b->num,out,outl,0); + ret=readsocket(b->num,out,outl); #else clear_sys_error(); ret=read(b->num,out,outl); @@ -240,19 +208,16 @@ int outl; } #ifndef BIO_FD -static int sock_write(b,in,inl) +static int sock_write(BIO *b, char *in, int inl) #else -static int fd_write(b,in,inl) +static int fd_write(BIO *b, char *in, int inl) #endif -BIO *b; -char *in; -int inl; { int ret; -#if defined(WINDOWS) && !defined(BIO_FD) +#ifndef BIO_FD clear_socket_error(); - ret=send(b->num,in,inl,0); + ret=writesocket(b->num,in,inl); #else clear_sys_error(); ret=write(b->num,in,inl); @@ -271,14 +236,10 @@ int inl; } #ifndef BIO_FD -static long sock_ctrl(b,cmd,num,ptr) +static long sock_ctrl(BIO *b, int cmd, long num, char *ptr) #else -static long fd_ctrl(b,cmd,num,ptr) +static long fd_ctrl(BIO *b, int cmd, long num, char *ptr) #endif -BIO *b; -int cmd; -long num; -char *ptr; { long ret=1; int *ip; @@ -286,14 +247,21 @@ char *ptr; switch (cmd) { case BIO_CTRL_RESET: + num=0; + case BIO_C_FILE_SEEK: #ifdef BIO_FD - ret=(long)lseek(b->num,0,0); + ret=(long)lseek(b->num,num,0); #else ret=0; #endif break; + case BIO_C_FILE_TELL: case BIO_CTRL_INFO: +#ifdef BIO_FD + ret=(long)lseek(b->num,0,1); +#else ret=0; +#endif break; case BIO_C_SET_FD: #ifndef BIO_FD @@ -329,7 +297,6 @@ char *ptr; case BIO_CTRL_FLUSH: ret=1; break; - break; default: ret=0; break; @@ -338,22 +305,17 @@ char *ptr; } #ifdef undef -static int sock_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int sock_gets(BIO *bp, char *buf,int size) { return(-1); } #endif #ifndef BIO_FD -static int sock_puts(bp,str) +static int sock_puts(BIO *bp, char *str) #else -static int fd_puts(bp,str) +static int fd_puts(BIO *bp, char *str) #endif -BIO *bp; -char *str; { int n,ret; @@ -367,23 +329,22 @@ char *str; } #ifndef BIO_FD -int BIO_sock_should_retry(i) +int BIO_sock_should_retry(int i) #else -int BIO_fd_should_retry(i) +int BIO_fd_should_retry(int i) #endif -int i; { int err; if ((i == 0) || (i == -1)) { -#if !defined(BIO_FD) && defined(WINDOWS) +#ifndef BIO_FD err=get_last_socket_error(); #else err=get_last_sys_error(); #endif -#if defined(WINDOWS) /* more microsoft stupidity */ +#if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ if ((i == -1) && (err == 0)) return(1); #endif @@ -398,11 +359,10 @@ int i; } #ifndef BIO_FD -int BIO_sock_non_fatal_error(err) +int BIO_sock_non_fatal_error(int err) #else -int BIO_fd_non_fatal_error(err) +int BIO_fd_non_fatal_error(int err) #endif -int err; { switch (err) { @@ -411,8 +371,10 @@ int err; case WSAEWOULDBLOCK: # endif -# if defined(WSAENOTCONN) +# if 0 /* This appears to always be an error */ +# if defined(WSAENOTCONN) case WSAENOTCONN: +# endif # endif #endif @@ -452,7 +414,7 @@ int err; case EALREADY: #endif return(1); - break; + /* break; */ default: break; } diff --git a/src/lib/libcrypto/bn/Makefile.ssl b/src/lib/libcrypto/bn/Makefile.ssl index 9809d26cbc..fcabb62452 100644 --- a/src/lib/libcrypto/bn/Makefile.ssl +++ b/src/lib/libcrypto/bn/Makefile.ssl @@ -7,35 +7,35 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r -BN_MULW= bn_mulw.o +BN_ASM= bn_asm.o # or use -#BN_MULW= bn86-elf.o +#BN_ASM= bn86-elf.o CFLAGS= $(INCLUDES) $(CFLAG) +ASFLAGS=$(CFLAGS) -ERR=bn -ERRC=bn_err GENERAL=Makefile TEST=bntest.c exptest.c APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c bn_mul.c \ - bn_print.c bn_rand.c bn_shift.c bn_sub.c bn_word.c bn_blind.c \ - bn_gcd.c bn_prime.c $(ERRC).c bn_sqr.c bn_mulw.c bn_recp.c bn_mont.c \ - bn_mpi.c - -LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_mod.o bn_mul.o \ - bn_print.o bn_rand.o bn_shift.o bn_sub.o bn_word.o bn_blind.o \ - bn_gcd.o bn_prime.o $(ERRC).o bn_sqr.o $(BN_MULW) bn_recp.o bn_mont.o \ - bn_mpi.o +LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mul.c \ + bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \ + bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c bn_recp.c bn_mont.c \ + bn_mpi.c bn_exp2.c +LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_mul.o \ + bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \ + bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) bn_recp.o bn_mont.o \ + bn_mpi.o bn_exp2.o SRC= $(LIBSRC) @@ -58,53 +58,90 @@ knuth.fast: bn_knuth.c lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf asm/bn86-elf.o: asm/bn86unix.cpp $(CPP) -DELF asm/bn86unix.cpp | as -o asm/bn86-elf.o +asm/co86-elf.o: asm/co86unix.cpp + $(CPP) -DELF asm/co86unix.cpp | as -o asm/co86-elf.o + # solaris asm/bn86-sol.o: asm/bn86unix.cpp $(CC) -E -DSOL asm/bn86unix.cpp | sed 's/^#.*//' > asm/bn86-sol.s as -o asm/bn86-sol.o asm/bn86-sol.s rm -f asm/bn86-sol.s +asm/co86-sol.o: asm/co86unix.cpp + $(CC) -E -DSOL asm/co86unix.cpp | sed 's/^#.*//' > asm/co86-sol.s + as -o asm/co86-sol.o asm/co86-sol.s + rm -f asm/co86-sol.s + # a.out asm/bn86-out.o: asm/bn86unix.cpp $(CPP) -DOUT asm/bn86unix.cpp | as -o asm/bn86-out.o +asm/co86-out.o: asm/co86unix.cpp + $(CPP) -DOUT asm/co86unix.cpp | as -o asm/co86-out.o + # bsdi asm/bn86bsdi.o: asm/bn86unix.cpp - $(CPP) -DBSDI asm/bn86unix.cpp | as -o asm/bn86bsdi.o + $(CPP) -DBSDI asm/bn86unix.cpp | sed 's/ :/:/' | as -o asm/bn86bsdi.o + +asm/co86bsdi.o: asm/co86unix.cpp + $(CPP) -DBSDI asm/co86unix.cpp | sed 's/ :/:/' | as -o asm/co86bsdi.o + +asm/bn86unix.cpp: asm/bn-586.pl + (cd asm; $(PERL) bn-586.pl cpp >bn86unix.cpp ) + +asm/co86unix.cpp: asm/co-586.pl + (cd asm; $(PERL) co-586.pl cpp >co86unix.cpp ) -asm/bn86unix.cpp: - (cd asm; perl bn-586.pl cpp >bn86unix.cpp ) +asm/sparcv8.o: asm/sparcv8.S + +asm/sparcv8plus.o: asm/sparcv8plus.S + +# Old GNU assembler doesn't understand V9 instructions, so we +# hire /usr/ccs/bin/as to do the job. Note that option is called +# *-gcc27, but even gcc 2>=8 users may experience similar problem +# if they didn't bother to upgrade GNU assembler. Such users should +# not choose this option, but be adviced to *remove* GNU assembler +# or upgrade it. +asm/sparcv8plus-gcc27.o: asm/sparcv8plus.S + $(CC) $(ASFLAGS) -E asm/sparcv8plus.S | \ + /usr/ccs/bin/as -xarch=v8plus - -o asm/sparcv8plus-gcc27.o + +# MIPS 64 bit assember +asm/mips3.o: asm/mips3.s + +# MIPS 32 bit assember +asm/mips1.o: asm/mips1.s + /usr/bin/as -O2 -o asm/mips1.o asm/mips1.s files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; exptest: - /bin/rm -f exptest + rm -f exptest gcc -I../../include -g2 -ggdb -o exptest exptest.c ../../libcrypto.a div: - /bin/rm -f a.out + rm -f a.out gcc -I.. -g div.c ../../libcrypto.a tags: @@ -116,18 +153,124 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff bn_mulw.s - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # special case .org - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f asm/co86unix.cpp asm/bn86unix.cpp *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff bn_asm.s # DO NOT DELETE THIS LINE -- make depend depends on it. + +bn_add.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_add.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_add.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_add.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_add.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_add.o: ../cryptlib.h bn_lcl.h +bn_asm.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_asm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_asm.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_asm.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_asm.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_asm.o: ../cryptlib.h bn_lcl.h +bn_blind.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_blind.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_blind.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_blind.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_blind.o: ../cryptlib.h bn_lcl.h +bn_div.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_div.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_div.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_div.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_div.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_div.o: ../cryptlib.h bn_lcl.h +bn_err.o: ../../include/openssl/bn.h ../../include/openssl/err.h +bn_err.o: ../../include/openssl/opensslconf.h +bn_exp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_exp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_exp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_exp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_exp.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_exp.o: ../cryptlib.h bn_lcl.h +bn_exp2.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_exp2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_exp2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_exp2.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_exp2.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_exp2.o: ../cryptlib.h bn_lcl.h +bn_gcd.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_gcd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_gcd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_gcd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_gcd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_gcd.o: ../cryptlib.h bn_lcl.h +bn_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_lib.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_lib.o: ../cryptlib.h bn_lcl.h +bn_mont.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_mont.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_mont.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_mont.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_mont.o: ../cryptlib.h bn_lcl.h +bn_mpi.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_mpi.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_mpi.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_mpi.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_mpi.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_mpi.o: ../cryptlib.h bn_lcl.h +bn_mul.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_mul.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_mul.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_mul.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_mul.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_mul.o: ../cryptlib.h bn_lcl.h +bn_prime.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_prime.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_prime.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_prime.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +bn_prime.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h bn_prime.h +bn_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_print.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_print.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_print.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_print.o: ../cryptlib.h bn_lcl.h +bn_rand.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_rand.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_rand.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_rand.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +bn_rand.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h +bn_recp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_recp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_recp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_recp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_recp.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_recp.o: ../cryptlib.h bn_lcl.h +bn_shift.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_shift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_shift.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_shift.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_shift.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_shift.o: ../cryptlib.h bn_lcl.h +bn_sqr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_sqr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_sqr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_sqr.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_sqr.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_sqr.o: ../cryptlib.h bn_lcl.h +bn_word.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +bn_word.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +bn_word.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bn_word.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +bn_word.o: ../cryptlib.h bn_lcl.h diff --git a/src/lib/libcrypto/bn/asm/alpha.s b/src/lib/libcrypto/bn/asm/alpha.s index 1d17b1d619..a351694ca2 100644 --- a/src/lib/libcrypto/bn/asm/alpha.s +++ b/src/lib/libcrypto/bn/asm/alpha.s @@ -1,8 +1,14 @@ # DEC Alpha assember - # The bn_div64 is actually gcc output but the other parts are hand done. + # The bn_div_words is actually gcc output but the other parts are hand done. # Thanks to tzeruch@ceddec.com for sending me the gcc output for - # bn_div64. - .file 1 "bn_mulw.c" + # bn_div_words. + # I've gone back and re-done most of routines. + # The key thing to remeber for the 164 CPU is that while a + # multiply operation takes 8 cycles, another one can only be issued + # after 4 cycles have elapsed. I've done modification to help + # improve this. Also, normally, a ld instruction will not be available + # for about 3 cycles. + .file 1 "bn_asm.c" .set noat gcc2_compiled.: __gnu_compiled_c: @@ -14,65 +20,91 @@ bn_mul_add_words: bn_mul_add_words..ng: .frame $30,0,$26,0 .prologue 0 - subq $18,2,$25 # num=-2 - bis $31,$31,$0 - blt $25,$42 .align 5 -$142: - subq $18,2,$18 # num-=2 - subq $25,2,$25 # num-=2 - - ldq $1,0($17) # a[0] - ldq $2,8($17) # a[1] - - mulq $19,$1,$3 # a[0]*w low part r3 - umulh $19,$1,$1 # a[0]*w high part r1 - mulq $19,$2,$4 # a[1]*w low part r4 - umulh $19,$2,$2 # a[1]*w high part r2 - - ldq $22,0($16) # r[0] r22 - ldq $23,8($16) # r[1] r23 - - addq $3,$22,$3 # a0 low part + r[0] - addq $4,$23,$4 # a1 low part + r[1] - cmpult $3,$22,$5 # overflow? - cmpult $4,$23,$6 # overflow? - addq $5,$1,$1 # high part + overflow - addq $6,$2,$2 # high part + overflow - - addq $3,$0,$3 # add c - cmpult $3,$0,$5 # overflow? - stq $3,0($16) - addq $5,$1,$0 # c=high part + overflow - - addq $4,$0,$4 # add c - cmpult $4,$0,$5 # overflow? - stq $4,8($16) - addq $5,$2,$0 # c=high part + overflow + subq $18,4,$18 + bis $31,$31,$0 + blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code + ldq $20,0($17) # 1 1 + ldq $1,0($16) # 1 1 + .align 3 +$42: + mulq $20,$19,$5 # 1 2 1 ###### + ldq $21,8($17) # 2 1 + ldq $2,8($16) # 2 1 + umulh $20,$19,$20 # 1 2 ###### + ldq $27,16($17) # 3 1 + ldq $3,16($16) # 3 1 + mulq $21,$19,$6 # 2 2 1 ###### + ldq $28,24($17) # 4 1 + addq $1,$5,$1 # 1 2 2 + ldq $4,24($16) # 4 1 + umulh $21,$19,$21 # 2 2 ###### + cmpult $1,$5,$22 # 1 2 3 1 + addq $20,$22,$20 # 1 3 1 + addq $1,$0,$1 # 1 2 3 1 + mulq $27,$19,$7 # 3 2 1 ###### + cmpult $1,$0,$0 # 1 2 3 2 + addq $2,$6,$2 # 2 2 2 + addq $20,$0,$0 # 1 3 2 + cmpult $2,$6,$23 # 2 2 3 1 + addq $21,$23,$21 # 2 3 1 + umulh $27,$19,$27 # 3 2 ###### + addq $2,$0,$2 # 2 2 3 1 + cmpult $2,$0,$0 # 2 2 3 2 + subq $18,4,$18 + mulq $28,$19,$8 # 4 2 1 ###### + addq $21,$0,$0 # 2 3 2 + addq $3,$7,$3 # 3 2 2 + addq $16,32,$16 + cmpult $3,$7,$24 # 3 2 3 1 + stq $1,-32($16) # 1 2 4 + umulh $28,$19,$28 # 4 2 ###### + addq $27,$24,$27 # 3 3 1 + addq $3,$0,$3 # 3 2 3 1 + stq $2,-24($16) # 2 2 4 + cmpult $3,$0,$0 # 3 2 3 2 + stq $3,-16($16) # 3 2 4 + addq $4,$8,$4 # 4 2 2 + addq $27,$0,$0 # 3 3 2 + cmpult $4,$8,$25 # 4 2 3 1 + addq $17,32,$17 + addq $28,$25,$28 # 4 3 1 + addq $4,$0,$4 # 4 2 3 1 + cmpult $4,$0,$0 # 4 2 3 2 + stq $4,-8($16) # 4 2 4 + addq $28,$0,$0 # 4 3 2 + blt $18,$43 - ble $18,$43 + ldq $20,0($17) # 1 1 + ldq $1,0($16) # 1 1 - addq $16,16,$16 - addq $17,16,$17 - blt $25,$42 + br $42 - br $31,$142 -$42: - ldq $1,0($17) # a[0] - umulh $19,$1,$3 # a[0]*w high part - mulq $19,$1,$1 # a[0]*w low part - ldq $2,0($16) # r[0] - addq $1,$2,$1 # low part + r[0] - cmpult $1,$2,$4 # overflow? - addq $4,$3,$3 # high part + overflow - addq $1,$0,$1 # add c - cmpult $1,$0,$4 # overflow? - addq $4,$3,$0 # c=high part + overflow - stq $1,0($16) + .align 4 +$45: + ldq $20,0($17) # 4 1 + ldq $1,0($16) # 4 1 + mulq $20,$19,$5 # 4 2 1 + subq $18,1,$18 + addq $16,8,$16 + addq $17,8,$17 + umulh $20,$19,$20 # 4 2 + addq $1,$5,$1 # 4 2 2 + cmpult $1,$5,$22 # 4 2 3 1 + addq $20,$22,$20 # 4 3 1 + addq $1,$0,$1 # 4 2 3 1 + cmpult $1,$0,$0 # 4 2 3 2 + addq $20,$0,$0 # 4 3 2 + stq $1,-8($16) # 4 2 4 + bgt $18,$45 + ret $31,($26),1 # else exit .align 4 $43: - ret $31,($26),1 + addq $18,4,$18 + bgt $18,$45 # goto tail code + ret $31,($26),1 # else exit + .end bn_mul_add_words .align 3 .globl bn_mul_words @@ -81,49 +113,75 @@ bn_mul_words: bn_mul_words..ng: .frame $30,0,$26,0 .prologue 0 - subq $18,2,$25 # num=-2 - bis $31,$31,$0 - blt $25,$242 .align 5 -$342: - subq $18,2,$18 # num-=2 - subq $25,2,$25 # num-=2 - - ldq $1,0($17) # a[0] - ldq $2,8($17) # a[1] - - mulq $19,$1,$3 # a[0]*w low part r3 - umulh $19,$1,$1 # a[0]*w high part r1 - mulq $19,$2,$4 # a[1]*w low part r4 - umulh $19,$2,$2 # a[1]*w high part r2 - - addq $3,$0,$3 # add c - cmpult $3,$0,$5 # overflow? - stq $3,0($16) - addq $5,$1,$0 # c=high part + overflow - - addq $4,$0,$4 # add c - cmpult $4,$0,$5 # overflow? - stq $4,8($16) - addq $5,$2,$0 # c=high part + overflow - - ble $18,$243 - - addq $16,16,$16 - addq $17,16,$17 - blt $25,$242 - - br $31,$342 -$242: - ldq $1,0($17) # a[0] - umulh $19,$1,$3 # a[0]*w high part - mulq $19,$1,$1 # a[0]*w low part - addq $1,$0,$1 # add c - cmpult $1,$0,$4 # overflow? - addq $4,$3,$0 # c=high part + overflow - stq $1,0($16) -$243: - ret $31,($26),1 + subq $18,4,$18 + bis $31,$31,$0 + blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code + ldq $20,0($17) # 1 1 + .align 3 +$142: + + mulq $20,$19,$5 # 1 2 1 ##### + ldq $21,8($17) # 2 1 + ldq $27,16($17) # 3 1 + umulh $20,$19,$20 # 1 2 ##### + ldq $28,24($17) # 4 1 + mulq $21,$19,$6 # 2 2 1 ##### + addq $5,$0,$5 # 1 2 3 1 + subq $18,4,$18 + cmpult $5,$0,$0 # 1 2 3 2 + umulh $21,$19,$21 # 2 2 ##### + addq $20,$0,$0 # 1 3 2 + addq $17,32,$17 + addq $6,$0,$6 # 2 2 3 1 + mulq $27,$19,$7 # 3 2 1 ##### + cmpult $6,$0,$0 # 2 2 3 2 + addq $21,$0,$0 # 2 3 2 + addq $16,32,$16 + umulh $27,$19,$27 # 3 2 ##### + stq $5,-32($16) # 1 2 4 + mulq $28,$19,$8 # 4 2 1 ##### + addq $7,$0,$7 # 3 2 3 1 + stq $6,-24($16) # 2 2 4 + cmpult $7,$0,$0 # 3 2 3 2 + umulh $28,$19,$28 # 4 2 ##### + addq $27,$0,$0 # 3 3 2 + stq $7,-16($16) # 3 2 4 + addq $8,$0,$8 # 4 2 3 1 + cmpult $8,$0,$0 # 4 2 3 2 + + addq $28,$0,$0 # 4 3 2 + + stq $8,-8($16) # 4 2 4 + + blt $18,$143 + + ldq $20,0($17) # 1 1 + + br $142 + + .align 4 +$145: + ldq $20,0($17) # 4 1 + mulq $20,$19,$5 # 4 2 1 + subq $18,1,$18 + umulh $20,$19,$20 # 4 2 + addq $5,$0,$5 # 4 2 3 1 + addq $16,8,$16 + cmpult $5,$0,$0 # 4 2 3 2 + addq $17,8,$17 + addq $20,$0,$0 # 4 3 2 + stq $5,-8($16) # 4 2 4 + + bgt $18,$145 + ret $31,($26),1 # else exit + + .align 4 +$143: + addq $18,4,$18 + bgt $18,$145 # goto tail code + ret $31,($26),1 # else exit + .end bn_mul_words .align 3 .globl bn_sqr_words @@ -132,44 +190,58 @@ bn_sqr_words: bn_sqr_words..ng: .frame $30,0,$26,0 .prologue 0 - - subq $18,2,$25 # num=-2 - blt $25,$442 - .align 5 -$542: - subq $18,2,$18 # num-=2 - subq $25,2,$25 # num-=2 - - ldq $1,0($17) # a[0] - ldq $4,8($17) # a[1] - mulq $1,$1,$2 # a[0]*w low part r2 - umulh $1,$1,$3 # a[0]*w high part r3 - mulq $4,$4,$5 # a[1]*w low part r5 - umulh $4,$4,$6 # a[1]*w high part r6 - - stq $2,0($16) # r[0] - stq $3,8($16) # r[1] - stq $5,16($16) # r[3] - stq $6,24($16) # r[4] + subq $18,4,$18 + blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code + ldq $20,0($17) # 1 1 + .align 3 +$542: + mulq $20,$20,$5 ###### + ldq $21,8($17) # 1 1 + subq $18,4 + umulh $20,$20,$1 ###### + ldq $27,16($17) # 1 1 + mulq $21,$21,$6 ###### + ldq $28,24($17) # 1 1 + stq $5,0($16) # r[0] + umulh $21,$21,$2 ###### + stq $1,8($16) # r[1] + mulq $27,$27,$7 ###### + stq $6,16($16) # r[0] + umulh $27,$27,$3 ###### + stq $2,24($16) # r[1] + mulq $28,$28,$8 ###### + stq $7,32($16) # r[0] + umulh $28,$28,$4 ###### + stq $3,40($16) # r[1] - ble $18,$443 + addq $16,64,$16 + addq $17,32,$17 + stq $8,-16($16) # r[0] + stq $4,-8($16) # r[1] - addq $16,32,$16 - addq $17,16,$17 - blt $25,$442 - br $31,$542 + blt $18,$543 + ldq $20,0($17) # 1 1 + br $542 $442: - ldq $1,0($17) # a[0] - mulq $1,$1,$2 # a[0]*w low part r2 - umulh $1,$1,$3 # a[0]*w high part r3 - stq $2,0($16) # r[0] - stq $3,8($16) # r[1] + ldq $20,0($17) # a[0] + mulq $20,$20,$5 # a[0]*w low part r2 + addq $16,16,$16 + addq $17,8,$17 + subq $18,1,$18 + umulh $20,$20,$1 # a[0]*w high part r3 + stq $5,-16($16) # r[0] + stq $1,-8($16) # r[1] + + bgt $18,$442 + ret $31,($26),1 # else exit .align 4 -$443: - ret $31,($26),1 +$543: + addq $18,4,$18 + bgt $18,$442 # goto tail code + ret $31,($26),1 # else exit .end bn_sqr_words .align 3 @@ -180,31 +252,74 @@ bn_add_words..ng: .frame $30,0,$26,0 .prologue 0 - bis $31,$31,$8 # carry = 0 - ble $19,$900 + subq $19,4,$19 + bis $31,$31,$0 # carry = 0 + blt $19,$900 + ldq $5,0($17) # a[0] + ldq $1,0($18) # b[1] + .align 3 $901: - ldq $0,0($17) # a[0] - ldq $1,0($18) # a[1] + addq $1,$5,$1 # r=a+b; + ldq $6,8($17) # a[1] + cmpult $1,$5,$22 # did we overflow? + ldq $2,8($18) # b[1] + addq $1,$0,$1 # c+= overflow + ldq $7,16($17) # a[2] + cmpult $1,$0,$0 # overflow? + ldq $3,16($18) # b[2] + addq $0,$22,$0 + ldq $8,24($17) # a[3] + addq $2,$6,$2 # r=a+b; + ldq $4,24($18) # b[3] + cmpult $2,$6,$23 # did we overflow? + addq $3,$7,$3 # r=a+b; + addq $2,$0,$2 # c+= overflow + cmpult $3,$7,$24 # did we overflow? + cmpult $2,$0,$0 # overflow? + addq $4,$8,$4 # r=a+b; + addq $0,$23,$0 + cmpult $4,$8,$25 # did we overflow? + addq $3,$0,$3 # c+= overflow + stq $1,0($16) # r[0]=c + cmpult $3,$0,$0 # overflow? + stq $2,8($16) # r[1]=c + addq $0,$24,$0 + stq $3,16($16) # r[2]=c + addq $4,$0,$4 # c+= overflow + subq $19,4,$19 # loop-- + cmpult $4,$0,$0 # overflow? + addq $17,32,$17 # a++ + addq $0,$25,$0 + stq $4,24($16) # r[3]=c + addq $18,32,$18 # b++ + addq $16,32,$16 # r++ - addq $0,$1,$3 # c=a+b; + blt $19,$900 + ldq $5,0($17) # a[0] + ldq $1,0($18) # b[1] + br $901 + .align 4 +$945: + ldq $5,0($17) # a[0] + ldq $1,0($18) # b[1] + addq $1,$5,$1 # r=a+b; + subq $19,1,$19 # loop-- + addq $1,$0,$1 # c+= overflow addq $17,8,$17 # a++ + cmpult $1,$5,$22 # did we overflow? + cmpult $1,$0,$0 # overflow? + addq $18,8,$18 # b++ + stq $1,0($16) # r[0]=c + addq $0,$22,$0 + addq $16,8,$16 # r++ - cmpult $3,$1,$7 # did we overflow? - addq $18,8,$18 # b++ - - addq $8,$3,$3 # c+=carry + bgt $19,$945 + ret $31,($26),1 # else exit - cmpult $3,$8,$8 # did we overflow? - stq $3,($16) # r[0]=c - - addq $7,$8,$8 # add into overflow - subq $19,1,$19 # loop-- - - addq $16,8,$16 # r++ - bgt $19,$901 $900: - bis $8,$8,$0 # return carry - ret $31,($26),1 + addq $19,4,$19 + bgt $19,$945 # goto tail code + ret $31,($26),1 # else exit .end bn_add_words # @@ -213,11 +328,11 @@ $900: # .text .align 3 - .globl bn_div64 - .ent bn_div64 -bn_div64: + .globl bn_div_words + .ent bn_div_words +bn_div_words: ldgp $29,0($27) -bn_div64..ng: +bn_div_words..ng: lda $30,-48($30) .frame $30,48,$26,0 stq $26,0($30) @@ -338,7 +453,1446 @@ $136: ldq $13,40($30) addq $30,48,$30 ret $31,($26),1 - .end bn_div64 - .ident "GCC: (GNU) 2.7.2.1" + .end bn_div_words + + .set noat + .text + .align 3 + .globl bn_sub_words + .ent bn_sub_words +bn_sub_words: +bn_sub_words..ng: + .frame $30,0,$26,0 + .prologue 0 + + subq $19, 4, $19 + bis $31, $31, $0 + blt $19, $100 + ldq $1, 0($17) + ldq $2, 0($18) +$101: + ldq $3, 8($17) + cmpult $1, $2, $4 + ldq $5, 8($18) + subq $1, $2, $1 + ldq $6, 16($17) + cmpult $1, $0, $2 + ldq $7, 16($18) + subq $1, $0, $23 + ldq $8, 24($17) + addq $2, $4, $0 + cmpult $3, $5, $24 + subq $3, $5, $3 + ldq $22, 24($18) + cmpult $3, $0, $5 + subq $3, $0, $25 + addq $5, $24, $0 + cmpult $6, $7, $27 + subq $6, $7, $6 + stq $23, 0($16) + cmpult $6, $0, $7 + subq $6, $0, $28 + addq $7, $27, $0 + cmpult $8, $22, $21 + subq $8, $22, $8 + stq $25, 8($16) + cmpult $8, $0, $22 + subq $8, $0, $20 + addq $22, $21, $0 + stq $28, 16($16) + subq $19, 4, $19 + stq $20, 24($16) + addq $17, 32, $17 + addq $18, 32, $18 + addq $16, 32, $16 + blt $19, $100 + ldq $1, 0($17) + ldq $2, 0($18) + br $101 +$102: + ldq $1, 0($17) + ldq $2, 0($18) + cmpult $1, $2, $27 + subq $1, $2, $1 + cmpult $1, $0, $2 + subq $1, $0, $1 + stq $1, 0($16) + addq $2, $27, $0 + addq $17, 8, $17 + addq $18, 8, $18 + addq $16, 8, $16 + subq $19, 1, $19 + bgt $19, $102 + ret $31,($26),1 +$100: + addq $19, 4, $19 + bgt $19, $102 +$103: + ret $31,($26),1 + .end bn_sub_words + .text + .align 3 + .globl bn_mul_comba4 + .ent bn_mul_comba4 +bn_mul_comba4: +bn_mul_comba4..ng: + .frame $30,0,$26,0 + .prologue 0 + ldq $0, 0($17) + ldq $1, 0($18) + ldq $2, 8($17) + ldq $3, 8($18) + ldq $4, 16($17) + ldq $5, 16($18) + ldq $6, 24($17) + ldq $7, 24($18) + bis $31, $31, $23 + mulq $0, $1, $8 + umulh $0, $1, $22 + stq $8, 0($16) + bis $31, $31, $8 + mulq $0, $3, $24 + umulh $0, $3, $25 + addq $22, $24, $22 + cmpult $22, $24, $27 + addq $27, $25, $25 + addq $23, $25, $23 + cmpult $23, $25, $28 + addq $8, $28, $8 + mulq $2, $1, $21 + umulh $2, $1, $20 + addq $22, $21, $22 + cmpult $22, $21, $19 + addq $19, $20, $20 + addq $23, $20, $23 + cmpult $23, $20, $17 + addq $8, $17, $8 + stq $22, 8($16) + bis $31, $31, $22 + mulq $2, $3, $18 + umulh $2, $3, $24 + addq $23, $18, $23 + cmpult $23, $18, $27 + addq $27, $24, $24 + addq $8, $24, $8 + cmpult $8, $24, $25 + addq $22, $25, $22 + mulq $0, $5, $28 + umulh $0, $5, $21 + addq $23, $28, $23 + cmpult $23, $28, $19 + addq $19, $21, $21 + addq $8, $21, $8 + cmpult $8, $21, $20 + addq $22, $20, $22 + mulq $4, $1, $17 + umulh $4, $1, $18 + addq $23, $17, $23 + cmpult $23, $17, $27 + addq $27, $18, $18 + addq $8, $18, $8 + cmpult $8, $18, $24 + addq $22, $24, $22 + stq $23, 16($16) + bis $31, $31, $23 + mulq $0, $7, $25 + umulh $0, $7, $28 + addq $8, $25, $8 + cmpult $8, $25, $19 + addq $19, $28, $28 + addq $22, $28, $22 + cmpult $22, $28, $21 + addq $23, $21, $23 + mulq $2, $5, $20 + umulh $2, $5, $17 + addq $8, $20, $8 + cmpult $8, $20, $27 + addq $27, $17, $17 + addq $22, $17, $22 + cmpult $22, $17, $18 + addq $23, $18, $23 + mulq $4, $3, $24 + umulh $4, $3, $25 + addq $8, $24, $8 + cmpult $8, $24, $19 + addq $19, $25, $25 + addq $22, $25, $22 + cmpult $22, $25, $28 + addq $23, $28, $23 + mulq $6, $1, $21 + umulh $6, $1, $0 + addq $8, $21, $8 + cmpult $8, $21, $20 + addq $20, $0, $0 + addq $22, $0, $22 + cmpult $22, $0, $27 + addq $23, $27, $23 + stq $8, 24($16) + bis $31, $31, $8 + mulq $2, $7, $17 + umulh $2, $7, $18 + addq $22, $17, $22 + cmpult $22, $17, $24 + addq $24, $18, $18 + addq $23, $18, $23 + cmpult $23, $18, $19 + addq $8, $19, $8 + mulq $4, $5, $25 + umulh $4, $5, $28 + addq $22, $25, $22 + cmpult $22, $25, $21 + addq $21, $28, $28 + addq $23, $28, $23 + cmpult $23, $28, $20 + addq $8, $20, $8 + mulq $6, $3, $0 + umulh $6, $3, $27 + addq $22, $0, $22 + cmpult $22, $0, $1 + addq $1, $27, $27 + addq $23, $27, $23 + cmpult $23, $27, $17 + addq $8, $17, $8 + stq $22, 32($16) + bis $31, $31, $22 + mulq $4, $7, $24 + umulh $4, $7, $18 + addq $23, $24, $23 + cmpult $23, $24, $19 + addq $19, $18, $18 + addq $8, $18, $8 + cmpult $8, $18, $2 + addq $22, $2, $22 + mulq $6, $5, $25 + umulh $6, $5, $21 + addq $23, $25, $23 + cmpult $23, $25, $28 + addq $28, $21, $21 + addq $8, $21, $8 + cmpult $8, $21, $20 + addq $22, $20, $22 + stq $23, 40($16) + bis $31, $31, $23 + mulq $6, $7, $0 + umulh $6, $7, $1 + addq $8, $0, $8 + cmpult $8, $0, $27 + addq $27, $1, $1 + addq $22, $1, $22 + cmpult $22, $1, $17 + addq $23, $17, $23 + stq $8, 48($16) + stq $22, 56($16) + ret $31,($26),1 + .end bn_mul_comba4 + .text + .align 3 + .globl bn_mul_comba8 + .ent bn_mul_comba8 +bn_mul_comba8: +bn_mul_comba8..ng: + .frame $30,0,$26,0 + .prologue 0 + + subq $30, 16, $30 + ldq $0, 0($17) + ldq $1, 0($18) + stq $9, 0($30) + stq $10, 8($30) + ldq $2, 8($17) + ldq $3, 8($18) + ldq $4, 16($17) + ldq $5, 16($18) + ldq $6, 24($17) + ldq $7, 24($18) + ldq $8, 8($17) + ldq $22, 8($18) + ldq $23, 8($17) + ldq $24, 8($18) + ldq $25, 8($17) + ldq $27, 8($18) + ldq $28, 8($17) + ldq $21, 8($18) + bis $31, $31, $9 + mulq $0, $1, $20 + umulh $0, $1, $19 + stq $20, 0($16) + bis $31, $31, $20 + mulq $0, $3, $10 + umulh $0, $3, $17 + addq $19, $10, $19 + cmpult $19, $10, $18 + addq $18, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $10 + addq $20, $10, $20 + mulq $2, $1, $18 + umulh $2, $1, $17 + addq $19, $18, $19 + cmpult $19, $18, $10 + addq $10, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $18 + addq $20, $18, $20 + stq $19, 8($16) + bis $31, $31, $19 + mulq $0, $5, $10 + umulh $0, $5, $17 + addq $9, $10, $9 + cmpult $9, $10, $18 + addq $18, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $10 + addq $19, $10, $19 + mulq $2, $3, $18 + umulh $2, $3, $17 + addq $9, $18, $9 + cmpult $9, $18, $10 + addq $10, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $18 + addq $19, $18, $19 + mulq $4, $1, $10 + umulh $4, $1, $17 + addq $9, $10, $9 + cmpult $9, $10, $18 + addq $18, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $10 + addq $19, $10, $19 + stq $9, 16($16) + bis $31, $31, $9 + mulq $0, $7, $18 + umulh $0, $7, $17 + addq $20, $18, $20 + cmpult $20, $18, $10 + addq $10, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $18 + addq $9, $18, $9 + mulq $2, $5, $10 + umulh $2, $5, $17 + addq $20, $10, $20 + cmpult $20, $10, $18 + addq $18, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $10 + addq $9, $10, $9 + mulq $4, $3, $18 + umulh $4, $3, $17 + addq $20, $18, $20 + cmpult $20, $18, $10 + addq $10, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $18 + addq $9, $18, $9 + mulq $6, $1, $10 + umulh $6, $1, $17 + addq $20, $10, $20 + cmpult $20, $10, $18 + addq $18, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $10 + addq $9, $10, $9 + stq $20, 24($16) + bis $31, $31, $20 + mulq $0, $22, $18 + umulh $0, $22, $17 + addq $19, $18, $19 + cmpult $19, $18, $10 + addq $10, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $18 + addq $20, $18, $20 + mulq $2, $7, $10 + umulh $2, $7, $17 + addq $19, $10, $19 + cmpult $19, $10, $18 + addq $18, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $10 + addq $20, $10, $20 + mulq $4, $5, $18 + umulh $4, $5, $17 + addq $19, $18, $19 + cmpult $19, $18, $10 + addq $10, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $18 + addq $20, $18, $20 + mulq $6, $3, $10 + umulh $6, $3, $17 + addq $19, $10, $19 + cmpult $19, $10, $18 + addq $18, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $10 + addq $20, $10, $20 + mulq $8, $1, $18 + umulh $8, $1, $17 + addq $19, $18, $19 + cmpult $19, $18, $10 + addq $10, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $18 + addq $20, $18, $20 + stq $19, 32($16) + bis $31, $31, $19 + mulq $0, $24, $10 + umulh $0, $24, $17 + addq $9, $10, $9 + cmpult $9, $10, $18 + addq $18, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $10 + addq $19, $10, $19 + mulq $2, $22, $18 + umulh $2, $22, $17 + addq $9, $18, $9 + cmpult $9, $18, $10 + addq $10, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $18 + addq $19, $18, $19 + mulq $4, $7, $10 + umulh $4, $7, $17 + addq $9, $10, $9 + cmpult $9, $10, $18 + addq $18, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $10 + addq $19, $10, $19 + mulq $6, $5, $18 + umulh $6, $5, $17 + addq $9, $18, $9 + cmpult $9, $18, $10 + addq $10, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $18 + addq $19, $18, $19 + mulq $8, $3, $10 + umulh $8, $3, $17 + addq $9, $10, $9 + cmpult $9, $10, $18 + addq $18, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $10 + addq $19, $10, $19 + mulq $23, $1, $18 + umulh $23, $1, $17 + addq $9, $18, $9 + cmpult $9, $18, $10 + addq $10, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $18 + addq $19, $18, $19 + stq $9, 40($16) + bis $31, $31, $9 + mulq $0, $27, $10 + umulh $0, $27, $17 + addq $20, $10, $20 + cmpult $20, $10, $18 + addq $18, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $10 + addq $9, $10, $9 + mulq $2, $24, $18 + umulh $2, $24, $17 + addq $20, $18, $20 + cmpult $20, $18, $10 + addq $10, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $18 + addq $9, $18, $9 + mulq $4, $22, $10 + umulh $4, $22, $17 + addq $20, $10, $20 + cmpult $20, $10, $18 + addq $18, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $10 + addq $9, $10, $9 + mulq $6, $7, $18 + umulh $6, $7, $17 + addq $20, $18, $20 + cmpult $20, $18, $10 + addq $10, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $18 + addq $9, $18, $9 + mulq $8, $5, $10 + umulh $8, $5, $17 + addq $20, $10, $20 + cmpult $20, $10, $18 + addq $18, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $10 + addq $9, $10, $9 + mulq $23, $3, $18 + umulh $23, $3, $17 + addq $20, $18, $20 + cmpult $20, $18, $10 + addq $10, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $18 + addq $9, $18, $9 + mulq $25, $1, $10 + umulh $25, $1, $17 + addq $20, $10, $20 + cmpult $20, $10, $18 + addq $18, $17, $17 + addq $19, $17, $19 + cmpult $19, $17, $10 + addq $9, $10, $9 + stq $20, 48($16) + bis $31, $31, $20 + mulq $0, $21, $18 + umulh $0, $21, $17 + addq $19, $18, $19 + cmpult $19, $18, $10 + addq $10, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $18 + addq $20, $18, $20 + mulq $2, $27, $10 + umulh $2, $27, $17 + addq $19, $10, $19 + cmpult $19, $10, $18 + addq $18, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $0 + addq $20, $0, $20 + mulq $4, $24, $10 + umulh $4, $24, $18 + addq $19, $10, $19 + cmpult $19, $10, $17 + addq $17, $18, $18 + addq $9, $18, $9 + cmpult $9, $18, $0 + addq $20, $0, $20 + mulq $6, $22, $10 + umulh $6, $22, $17 + addq $19, $10, $19 + cmpult $19, $10, $18 + addq $18, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $0 + addq $20, $0, $20 + mulq $8, $7, $10 + umulh $8, $7, $18 + addq $19, $10, $19 + cmpult $19, $10, $17 + addq $17, $18, $18 + addq $9, $18, $9 + cmpult $9, $18, $0 + addq $20, $0, $20 + mulq $23, $5, $10 + umulh $23, $5, $17 + addq $19, $10, $19 + cmpult $19, $10, $18 + addq $18, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $0 + addq $20, $0, $20 + mulq $25, $3, $10 + umulh $25, $3, $18 + addq $19, $10, $19 + cmpult $19, $10, $17 + addq $17, $18, $18 + addq $9, $18, $9 + cmpult $9, $18, $0 + addq $20, $0, $20 + mulq $28, $1, $10 + umulh $28, $1, $17 + addq $19, $10, $19 + cmpult $19, $10, $18 + addq $18, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $0 + addq $20, $0, $20 + stq $19, 56($16) + bis $31, $31, $19 + mulq $2, $21, $10 + umulh $2, $21, $18 + addq $9, $10, $9 + cmpult $9, $10, $17 + addq $17, $18, $18 + addq $20, $18, $20 + cmpult $20, $18, $0 + addq $19, $0, $19 + mulq $4, $27, $1 + umulh $4, $27, $10 + addq $9, $1, $9 + cmpult $9, $1, $17 + addq $17, $10, $10 + addq $20, $10, $20 + cmpult $20, $10, $18 + addq $19, $18, $19 + mulq $6, $24, $0 + umulh $6, $24, $2 + addq $9, $0, $9 + cmpult $9, $0, $1 + addq $1, $2, $2 + addq $20, $2, $20 + cmpult $20, $2, $17 + addq $19, $17, $19 + mulq $8, $22, $10 + umulh $8, $22, $18 + addq $9, $10, $9 + cmpult $9, $10, $0 + addq $0, $18, $18 + addq $20, $18, $20 + cmpult $20, $18, $1 + addq $19, $1, $19 + mulq $23, $7, $2 + umulh $23, $7, $17 + addq $9, $2, $9 + cmpult $9, $2, $10 + addq $10, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $0 + addq $19, $0, $19 + mulq $25, $5, $18 + umulh $25, $5, $1 + addq $9, $18, $9 + cmpult $9, $18, $2 + addq $2, $1, $1 + addq $20, $1, $20 + cmpult $20, $1, $10 + addq $19, $10, $19 + mulq $28, $3, $17 + umulh $28, $3, $0 + addq $9, $17, $9 + cmpult $9, $17, $18 + addq $18, $0, $0 + addq $20, $0, $20 + cmpult $20, $0, $2 + addq $19, $2, $19 + stq $9, 64($16) + bis $31, $31, $9 + mulq $4, $21, $1 + umulh $4, $21, $10 + addq $20, $1, $20 + cmpult $20, $1, $17 + addq $17, $10, $10 + addq $19, $10, $19 + cmpult $19, $10, $18 + addq $9, $18, $9 + mulq $6, $27, $0 + umulh $6, $27, $2 + addq $20, $0, $20 + cmpult $20, $0, $3 + addq $3, $2, $2 + addq $19, $2, $19 + cmpult $19, $2, $1 + addq $9, $1, $9 + mulq $8, $24, $17 + umulh $8, $24, $10 + addq $20, $17, $20 + cmpult $20, $17, $18 + addq $18, $10, $10 + addq $19, $10, $19 + cmpult $19, $10, $4 + addq $9, $4, $9 + mulq $23, $22, $0 + umulh $23, $22, $3 + addq $20, $0, $20 + cmpult $20, $0, $2 + addq $2, $3, $3 + addq $19, $3, $19 + cmpult $19, $3, $1 + addq $9, $1, $9 + mulq $25, $7, $17 + umulh $25, $7, $18 + addq $20, $17, $20 + cmpult $20, $17, $10 + addq $10, $18, $18 + addq $19, $18, $19 + cmpult $19, $18, $4 + addq $9, $4, $9 + mulq $28, $5, $0 + umulh $28, $5, $2 + addq $20, $0, $20 + cmpult $20, $0, $3 + addq $3, $2, $2 + addq $19, $2, $19 + cmpult $19, $2, $1 + addq $9, $1, $9 + stq $20, 72($16) + bis $31, $31, $20 + mulq $6, $21, $17 + umulh $6, $21, $10 + addq $19, $17, $19 + cmpult $19, $17, $18 + addq $18, $10, $10 + addq $9, $10, $9 + cmpult $9, $10, $4 + addq $20, $4, $20 + mulq $8, $27, $0 + umulh $8, $27, $3 + addq $19, $0, $19 + cmpult $19, $0, $2 + addq $2, $3, $3 + addq $9, $3, $9 + cmpult $9, $3, $1 + addq $20, $1, $20 + mulq $23, $24, $5 + umulh $23, $24, $17 + addq $19, $5, $19 + cmpult $19, $5, $18 + addq $18, $17, $17 + addq $9, $17, $9 + cmpult $9, $17, $10 + addq $20, $10, $20 + mulq $25, $22, $4 + umulh $25, $22, $6 + addq $19, $4, $19 + cmpult $19, $4, $0 + addq $0, $6, $6 + addq $9, $6, $9 + cmpult $9, $6, $2 + addq $20, $2, $20 + mulq $28, $7, $3 + umulh $28, $7, $1 + addq $19, $3, $19 + cmpult $19, $3, $5 + addq $5, $1, $1 + addq $9, $1, $9 + cmpult $9, $1, $18 + addq $20, $18, $20 + stq $19, 80($16) + bis $31, $31, $19 + mulq $8, $21, $17 + umulh $8, $21, $10 + addq $9, $17, $9 + cmpult $9, $17, $4 + addq $4, $10, $10 + addq $20, $10, $20 + cmpult $20, $10, $0 + addq $19, $0, $19 + mulq $23, $27, $6 + umulh $23, $27, $2 + addq $9, $6, $9 + cmpult $9, $6, $3 + addq $3, $2, $2 + addq $20, $2, $20 + cmpult $20, $2, $5 + addq $19, $5, $19 + mulq $25, $24, $1 + umulh $25, $24, $18 + addq $9, $1, $9 + cmpult $9, $1, $7 + addq $7, $18, $18 + addq $20, $18, $20 + cmpult $20, $18, $17 + addq $19, $17, $19 + mulq $28, $22, $4 + umulh $28, $22, $10 + addq $9, $4, $9 + cmpult $9, $4, $0 + addq $0, $10, $10 + addq $20, $10, $20 + cmpult $20, $10, $8 + addq $19, $8, $19 + stq $9, 88($16) + bis $31, $31, $9 + mulq $23, $21, $6 + umulh $23, $21, $3 + addq $20, $6, $20 + cmpult $20, $6, $2 + addq $2, $3, $3 + addq $19, $3, $19 + cmpult $19, $3, $5 + addq $9, $5, $9 + mulq $25, $27, $1 + umulh $25, $27, $7 + addq $20, $1, $20 + cmpult $20, $1, $18 + addq $18, $7, $7 + addq $19, $7, $19 + cmpult $19, $7, $17 + addq $9, $17, $9 + mulq $28, $24, $4 + umulh $28, $24, $0 + addq $20, $4, $20 + cmpult $20, $4, $10 + addq $10, $0, $0 + addq $19, $0, $19 + cmpult $19, $0, $8 + addq $9, $8, $9 + stq $20, 96($16) + bis $31, $31, $20 + mulq $25, $21, $22 + umulh $25, $21, $6 + addq $19, $22, $19 + cmpult $19, $22, $2 + addq $2, $6, $6 + addq $9, $6, $9 + cmpult $9, $6, $3 + addq $20, $3, $20 + mulq $28, $27, $5 + umulh $28, $27, $23 + addq $19, $5, $19 + cmpult $19, $5, $1 + addq $1, $23, $23 + addq $9, $23, $9 + cmpult $9, $23, $18 + addq $20, $18, $20 + stq $19, 104($16) + bis $31, $31, $19 + mulq $28, $21, $7 + umulh $28, $21, $17 + addq $9, $7, $9 + cmpult $9, $7, $4 + addq $4, $17, $17 + addq $20, $17, $20 + cmpult $20, $17, $10 + addq $19, $10, $19 + stq $9, 112($16) + stq $20, 120($16) + ldq $9, 0($30) + ldq $10, 8($30) + addq $30, 16, $30 + ret $31,($26),1 + .end bn_mul_comba8 + .text + .align 3 + .globl bn_sqr_comba4 + .ent bn_sqr_comba4 +bn_sqr_comba4: +bn_sqr_comba4..ng: + .frame $30,0,$26,0 + .prologue 0 + + ldq $0, 0($17) + ldq $1, 8($17) + ldq $2, 16($17) + ldq $3, 24($17) + bis $31, $31, $6 + mulq $0, $0, $4 + umulh $0, $0, $5 + stq $4, 0($16) + bis $31, $31, $4 + mulq $0, $1, $7 + umulh $0, $1, $8 + cmplt $7, $31, $22 + cmplt $8, $31, $23 + addq $7, $7, $7 + addq $8, $8, $8 + addq $8, $22, $8 + addq $4, $23, $4 + addq $5, $7, $5 + addq $6, $8, $6 + cmpult $5, $7, $24 + cmpult $6, $8, $25 + addq $6, $24, $6 + addq $4, $25, $4 + stq $5, 8($16) + bis $31, $31, $5 + mulq $1, $1, $27 + umulh $1, $1, $28 + addq $6, $27, $6 + addq $4, $28, $4 + cmpult $6, $27, $21 + cmpult $4, $28, $20 + addq $4, $21, $4 + addq $5, $20, $5 + mulq $2, $0, $19 + umulh $2, $0, $18 + cmplt $19, $31, $17 + cmplt $18, $31, $22 + addq $19, $19, $19 + addq $18, $18, $18 + addq $18, $17, $18 + addq $5, $22, $5 + addq $6, $19, $6 + addq $4, $18, $4 + cmpult $6, $19, $23 + cmpult $4, $18, $7 + addq $4, $23, $4 + addq $5, $7, $5 + stq $6, 16($16) + bis $31, $31, $6 + mulq $3, $0, $8 + umulh $3, $0, $24 + cmplt $8, $31, $25 + cmplt $24, $31, $27 + addq $8, $8, $8 + addq $24, $24, $24 + addq $24, $25, $24 + addq $6, $27, $6 + addq $4, $8, $4 + addq $5, $24, $5 + cmpult $4, $8, $28 + cmpult $5, $24, $21 + addq $5, $28, $5 + addq $6, $21, $6 + mulq $2, $1, $20 + umulh $2, $1, $17 + cmplt $20, $31, $22 + cmplt $17, $31, $19 + addq $20, $20, $20 + addq $17, $17, $17 + addq $17, $22, $17 + addq $6, $19, $6 + addq $4, $20, $4 + addq $5, $17, $5 + cmpult $4, $20, $18 + cmpult $5, $17, $23 + addq $5, $18, $5 + addq $6, $23, $6 + stq $4, 24($16) + bis $31, $31, $4 + mulq $2, $2, $7 + umulh $2, $2, $25 + addq $5, $7, $5 + addq $6, $25, $6 + cmpult $5, $7, $27 + cmpult $6, $25, $8 + addq $6, $27, $6 + addq $4, $8, $4 + mulq $3, $1, $24 + umulh $3, $1, $28 + cmplt $24, $31, $21 + cmplt $28, $31, $22 + addq $24, $24, $24 + addq $28, $28, $28 + addq $28, $21, $28 + addq $4, $22, $4 + addq $5, $24, $5 + addq $6, $28, $6 + cmpult $5, $24, $19 + cmpult $6, $28, $20 + addq $6, $19, $6 + addq $4, $20, $4 + stq $5, 32($16) + bis $31, $31, $5 + mulq $3, $2, $17 + umulh $3, $2, $18 + cmplt $17, $31, $23 + cmplt $18, $31, $7 + addq $17, $17, $17 + addq $18, $18, $18 + addq $18, $23, $18 + addq $5, $7, $5 + addq $6, $17, $6 + addq $4, $18, $4 + cmpult $6, $17, $25 + cmpult $4, $18, $27 + addq $4, $25, $4 + addq $5, $27, $5 + stq $6, 40($16) + bis $31, $31, $6 + mulq $3, $3, $8 + umulh $3, $3, $21 + addq $4, $8, $4 + addq $5, $21, $5 + cmpult $4, $8, $22 + cmpult $5, $21, $24 + addq $5, $22, $5 + addq $6, $24, $6 + stq $4, 48($16) + stq $5, 56($16) + ret $31,($26),1 + .end bn_sqr_comba4 + .text + .align 3 + .globl bn_sqr_comba8 + .ent bn_sqr_comba8 +bn_sqr_comba8: +bn_sqr_comba8..ng: + .frame $30,0,$26,0 + .prologue 0 + ldq $0, 0($17) + ldq $1, 8($17) + ldq $2, 16($17) + ldq $3, 24($17) + ldq $4, 32($17) + ldq $5, 40($17) + ldq $6, 48($17) + ldq $7, 56($17) + bis $31, $31, $23 + mulq $0, $0, $8 + umulh $0, $0, $22 + stq $8, 0($16) + bis $31, $31, $8 + mulq $1, $0, $24 + umulh $1, $0, $25 + cmplt $24, $31, $27 + cmplt $25, $31, $28 + addq $24, $24, $24 + addq $25, $25, $25 + addq $25, $27, $25 + addq $8, $28, $8 + addq $22, $24, $22 + addq $23, $25, $23 + cmpult $22, $24, $21 + cmpult $23, $25, $20 + addq $23, $21, $23 + addq $8, $20, $8 + stq $22, 8($16) + bis $31, $31, $22 + mulq $1, $1, $19 + umulh $1, $1, $18 + addq $23, $19, $23 + addq $8, $18, $8 + cmpult $23, $19, $17 + cmpult $8, $18, $27 + addq $8, $17, $8 + addq $22, $27, $22 + mulq $2, $0, $28 + umulh $2, $0, $24 + cmplt $28, $31, $25 + cmplt $24, $31, $21 + addq $28, $28, $28 + addq $24, $24, $24 + addq $24, $25, $24 + addq $22, $21, $22 + addq $23, $28, $23 + addq $8, $24, $8 + cmpult $23, $28, $20 + cmpult $8, $24, $19 + addq $8, $20, $8 + addq $22, $19, $22 + stq $23, 16($16) + bis $31, $31, $23 + mulq $2, $1, $18 + umulh $2, $1, $17 + cmplt $18, $31, $27 + cmplt $17, $31, $25 + addq $18, $18, $18 + addq $17, $17, $17 + addq $17, $27, $17 + addq $23, $25, $23 + addq $8, $18, $8 + addq $22, $17, $22 + cmpult $8, $18, $21 + cmpult $22, $17, $28 + addq $22, $21, $22 + addq $23, $28, $23 + mulq $3, $0, $24 + umulh $3, $0, $20 + cmplt $24, $31, $19 + cmplt $20, $31, $27 + addq $24, $24, $24 + addq $20, $20, $20 + addq $20, $19, $20 + addq $23, $27, $23 + addq $8, $24, $8 + addq $22, $20, $22 + cmpult $8, $24, $25 + cmpult $22, $20, $18 + addq $22, $25, $22 + addq $23, $18, $23 + stq $8, 24($16) + bis $31, $31, $8 + mulq $2, $2, $17 + umulh $2, $2, $21 + addq $22, $17, $22 + addq $23, $21, $23 + cmpult $22, $17, $28 + cmpult $23, $21, $19 + addq $23, $28, $23 + addq $8, $19, $8 + mulq $3, $1, $27 + umulh $3, $1, $24 + cmplt $27, $31, $20 + cmplt $24, $31, $25 + addq $27, $27, $27 + addq $24, $24, $24 + addq $24, $20, $24 + addq $8, $25, $8 + addq $22, $27, $22 + addq $23, $24, $23 + cmpult $22, $27, $18 + cmpult $23, $24, $17 + addq $23, $18, $23 + addq $8, $17, $8 + mulq $4, $0, $21 + umulh $4, $0, $28 + cmplt $21, $31, $19 + cmplt $28, $31, $20 + addq $21, $21, $21 + addq $28, $28, $28 + addq $28, $19, $28 + addq $8, $20, $8 + addq $22, $21, $22 + addq $23, $28, $23 + cmpult $22, $21, $25 + cmpult $23, $28, $27 + addq $23, $25, $23 + addq $8, $27, $8 + stq $22, 32($16) + bis $31, $31, $22 + mulq $3, $2, $24 + umulh $3, $2, $18 + cmplt $24, $31, $17 + cmplt $18, $31, $19 + addq $24, $24, $24 + addq $18, $18, $18 + addq $18, $17, $18 + addq $22, $19, $22 + addq $23, $24, $23 + addq $8, $18, $8 + cmpult $23, $24, $20 + cmpult $8, $18, $21 + addq $8, $20, $8 + addq $22, $21, $22 + mulq $4, $1, $28 + umulh $4, $1, $25 + cmplt $28, $31, $27 + cmplt $25, $31, $17 + addq $28, $28, $28 + addq $25, $25, $25 + addq $25, $27, $25 + addq $22, $17, $22 + addq $23, $28, $23 + addq $8, $25, $8 + cmpult $23, $28, $19 + cmpult $8, $25, $24 + addq $8, $19, $8 + addq $22, $24, $22 + mulq $5, $0, $18 + umulh $5, $0, $20 + cmplt $18, $31, $21 + cmplt $20, $31, $27 + addq $18, $18, $18 + addq $20, $20, $20 + addq $20, $21, $20 + addq $22, $27, $22 + addq $23, $18, $23 + addq $8, $20, $8 + cmpult $23, $18, $17 + cmpult $8, $20, $28 + addq $8, $17, $8 + addq $22, $28, $22 + stq $23, 40($16) + bis $31, $31, $23 + mulq $3, $3, $25 + umulh $3, $3, $19 + addq $8, $25, $8 + addq $22, $19, $22 + cmpult $8, $25, $24 + cmpult $22, $19, $21 + addq $22, $24, $22 + addq $23, $21, $23 + mulq $4, $2, $27 + umulh $4, $2, $18 + cmplt $27, $31, $20 + cmplt $18, $31, $17 + addq $27, $27, $27 + addq $18, $18, $18 + addq $18, $20, $18 + addq $23, $17, $23 + addq $8, $27, $8 + addq $22, $18, $22 + cmpult $8, $27, $28 + cmpult $22, $18, $25 + addq $22, $28, $22 + addq $23, $25, $23 + mulq $5, $1, $19 + umulh $5, $1, $24 + cmplt $19, $31, $21 + cmplt $24, $31, $20 + addq $19, $19, $19 + addq $24, $24, $24 + addq $24, $21, $24 + addq $23, $20, $23 + addq $8, $19, $8 + addq $22, $24, $22 + cmpult $8, $19, $17 + cmpult $22, $24, $27 + addq $22, $17, $22 + addq $23, $27, $23 + mulq $6, $0, $18 + umulh $6, $0, $28 + cmplt $18, $31, $25 + cmplt $28, $31, $21 + addq $18, $18, $18 + addq $28, $28, $28 + addq $28, $25, $28 + addq $23, $21, $23 + addq $8, $18, $8 + addq $22, $28, $22 + cmpult $8, $18, $20 + cmpult $22, $28, $19 + addq $22, $20, $22 + addq $23, $19, $23 + stq $8, 48($16) + bis $31, $31, $8 + mulq $4, $3, $24 + umulh $4, $3, $17 + cmplt $24, $31, $27 + cmplt $17, $31, $25 + addq $24, $24, $24 + addq $17, $17, $17 + addq $17, $27, $17 + addq $8, $25, $8 + addq $22, $24, $22 + addq $23, $17, $23 + cmpult $22, $24, $21 + cmpult $23, $17, $18 + addq $23, $21, $23 + addq $8, $18, $8 + mulq $5, $2, $28 + umulh $5, $2, $20 + cmplt $28, $31, $19 + cmplt $20, $31, $27 + addq $28, $28, $28 + addq $20, $20, $20 + addq $20, $19, $20 + addq $8, $27, $8 + addq $22, $28, $22 + addq $23, $20, $23 + cmpult $22, $28, $25 + cmpult $23, $20, $24 + addq $23, $25, $23 + addq $8, $24, $8 + mulq $6, $1, $17 + umulh $6, $1, $21 + cmplt $17, $31, $18 + cmplt $21, $31, $19 + addq $17, $17, $17 + addq $21, $21, $21 + addq $21, $18, $21 + addq $8, $19, $8 + addq $22, $17, $22 + addq $23, $21, $23 + cmpult $22, $17, $27 + cmpult $23, $21, $28 + addq $23, $27, $23 + addq $8, $28, $8 + mulq $7, $0, $20 + umulh $7, $0, $25 + cmplt $20, $31, $24 + cmplt $25, $31, $18 + addq $20, $20, $20 + addq $25, $25, $25 + addq $25, $24, $25 + addq $8, $18, $8 + addq $22, $20, $22 + addq $23, $25, $23 + cmpult $22, $20, $19 + cmpult $23, $25, $17 + addq $23, $19, $23 + addq $8, $17, $8 + stq $22, 56($16) + bis $31, $31, $22 + mulq $4, $4, $21 + umulh $4, $4, $27 + addq $23, $21, $23 + addq $8, $27, $8 + cmpult $23, $21, $28 + cmpult $8, $27, $24 + addq $8, $28, $8 + addq $22, $24, $22 + mulq $5, $3, $18 + umulh $5, $3, $20 + cmplt $18, $31, $25 + cmplt $20, $31, $19 + addq $18, $18, $18 + addq $20, $20, $20 + addq $20, $25, $20 + addq $22, $19, $22 + addq $23, $18, $23 + addq $8, $20, $8 + cmpult $23, $18, $17 + cmpult $8, $20, $21 + addq $8, $17, $8 + addq $22, $21, $22 + mulq $6, $2, $27 + umulh $6, $2, $28 + cmplt $27, $31, $24 + cmplt $28, $31, $25 + addq $27, $27, $27 + addq $28, $28, $28 + addq $28, $24, $28 + addq $22, $25, $22 + addq $23, $27, $23 + addq $8, $28, $8 + cmpult $23, $27, $19 + cmpult $8, $28, $18 + addq $8, $19, $8 + addq $22, $18, $22 + mulq $7, $1, $20 + umulh $7, $1, $17 + cmplt $20, $31, $21 + cmplt $17, $31, $24 + addq $20, $20, $20 + addq $17, $17, $17 + addq $17, $21, $17 + addq $22, $24, $22 + addq $23, $20, $23 + addq $8, $17, $8 + cmpult $23, $20, $25 + cmpult $8, $17, $27 + addq $8, $25, $8 + addq $22, $27, $22 + stq $23, 64($16) + bis $31, $31, $23 + mulq $5, $4, $28 + umulh $5, $4, $19 + cmplt $28, $31, $18 + cmplt $19, $31, $21 + addq $28, $28, $28 + addq $19, $19, $19 + addq $19, $18, $19 + addq $23, $21, $23 + addq $8, $28, $8 + addq $22, $19, $22 + cmpult $8, $28, $24 + cmpult $22, $19, $20 + addq $22, $24, $22 + addq $23, $20, $23 + mulq $6, $3, $17 + umulh $6, $3, $25 + cmplt $17, $31, $27 + cmplt $25, $31, $18 + addq $17, $17, $17 + addq $25, $25, $25 + addq $25, $27, $25 + addq $23, $18, $23 + addq $8, $17, $8 + addq $22, $25, $22 + cmpult $8, $17, $21 + cmpult $22, $25, $28 + addq $22, $21, $22 + addq $23, $28, $23 + mulq $7, $2, $19 + umulh $7, $2, $24 + cmplt $19, $31, $20 + cmplt $24, $31, $27 + addq $19, $19, $19 + addq $24, $24, $24 + addq $24, $20, $24 + addq $23, $27, $23 + addq $8, $19, $8 + addq $22, $24, $22 + cmpult $8, $19, $18 + cmpult $22, $24, $17 + addq $22, $18, $22 + addq $23, $17, $23 + stq $8, 72($16) + bis $31, $31, $8 + mulq $5, $5, $25 + umulh $5, $5, $21 + addq $22, $25, $22 + addq $23, $21, $23 + cmpult $22, $25, $28 + cmpult $23, $21, $20 + addq $23, $28, $23 + addq $8, $20, $8 + mulq $6, $4, $27 + umulh $6, $4, $19 + cmplt $27, $31, $24 + cmplt $19, $31, $18 + addq $27, $27, $27 + addq $19, $19, $19 + addq $19, $24, $19 + addq $8, $18, $8 + addq $22, $27, $22 + addq $23, $19, $23 + cmpult $22, $27, $17 + cmpult $23, $19, $25 + addq $23, $17, $23 + addq $8, $25, $8 + mulq $7, $3, $21 + umulh $7, $3, $28 + cmplt $21, $31, $20 + cmplt $28, $31, $24 + addq $21, $21, $21 + addq $28, $28, $28 + addq $28, $20, $28 + addq $8, $24, $8 + addq $22, $21, $22 + addq $23, $28, $23 + cmpult $22, $21, $18 + cmpult $23, $28, $27 + addq $23, $18, $23 + addq $8, $27, $8 + stq $22, 80($16) + bis $31, $31, $22 + mulq $6, $5, $19 + umulh $6, $5, $17 + cmplt $19, $31, $25 + cmplt $17, $31, $20 + addq $19, $19, $19 + addq $17, $17, $17 + addq $17, $25, $17 + addq $22, $20, $22 + addq $23, $19, $23 + addq $8, $17, $8 + cmpult $23, $19, $24 + cmpult $8, $17, $21 + addq $8, $24, $8 + addq $22, $21, $22 + mulq $7, $4, $28 + umulh $7, $4, $18 + cmplt $28, $31, $27 + cmplt $18, $31, $25 + addq $28, $28, $28 + addq $18, $18, $18 + addq $18, $27, $18 + addq $22, $25, $22 + addq $23, $28, $23 + addq $8, $18, $8 + cmpult $23, $28, $20 + cmpult $8, $18, $19 + addq $8, $20, $8 + addq $22, $19, $22 + stq $23, 88($16) + bis $31, $31, $23 + mulq $6, $6, $17 + umulh $6, $6, $24 + addq $8, $17, $8 + addq $22, $24, $22 + cmpult $8, $17, $21 + cmpult $22, $24, $27 + addq $22, $21, $22 + addq $23, $27, $23 + mulq $7, $5, $25 + umulh $7, $5, $28 + cmplt $25, $31, $18 + cmplt $28, $31, $20 + addq $25, $25, $25 + addq $28, $28, $28 + addq $28, $18, $28 + addq $23, $20, $23 + addq $8, $25, $8 + addq $22, $28, $22 + cmpult $8, $25, $19 + cmpult $22, $28, $17 + addq $22, $19, $22 + addq $23, $17, $23 + stq $8, 96($16) + bis $31, $31, $8 + mulq $7, $6, $24 + umulh $7, $6, $21 + cmplt $24, $31, $27 + cmplt $21, $31, $18 + addq $24, $24, $24 + addq $21, $21, $21 + addq $21, $27, $21 + addq $8, $18, $8 + addq $22, $24, $22 + addq $23, $21, $23 + cmpult $22, $24, $20 + cmpult $23, $21, $25 + addq $23, $20, $23 + addq $8, $25, $8 + stq $22, 104($16) + bis $31, $31, $22 + mulq $7, $7, $28 + umulh $7, $7, $19 + addq $23, $28, $23 + addq $8, $19, $8 + cmpult $23, $28, $17 + cmpult $8, $19, $27 + addq $8, $17, $8 + addq $22, $27, $22 + stq $23, 112($16) + stq $8, 120($16) + ret $31,($26),1 + .end bn_sqr_comba8 diff --git a/src/lib/libcrypto/bn/asm/alpha.s.works b/src/lib/libcrypto/bn/asm/alpha.s.works new file mode 100644 index 0000000000..ee6c587809 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/alpha.s.works @@ -0,0 +1,533 @@ + + # DEC Alpha assember + # The bn_div64 is actually gcc output but the other parts are hand done. + # Thanks to tzeruch@ceddec.com for sending me the gcc output for + # bn_div64. + # I've gone back and re-done most of routines. + # The key thing to remeber for the 164 CPU is that while a + # multiply operation takes 8 cycles, another one can only be issued + # after 4 cycles have elapsed. I've done modification to help + # improve this. Also, normally, a ld instruction will not be available + # for about 3 cycles. + .file 1 "bn_asm.c" + .set noat +gcc2_compiled.: +__gnu_compiled_c: + .text + .align 3 + .globl bn_mul_add_words + .ent bn_mul_add_words +bn_mul_add_words: +bn_mul_add_words..ng: + .frame $30,0,$26,0 + .prologue 0 + .align 5 + subq $18,4,$18 + bis $31,$31,$0 + blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code + ldq $20,0($17) # 1 1 + ldq $1,0($16) # 1 1 + .align 3 +$42: + mulq $20,$19,$5 # 1 2 1 ###### + ldq $21,8($17) # 2 1 + ldq $2,8($16) # 2 1 + umulh $20,$19,$20 # 1 2 ###### + ldq $27,16($17) # 3 1 + ldq $3,16($16) # 3 1 + mulq $21,$19,$6 # 2 2 1 ###### + ldq $28,24($17) # 4 1 + addq $1,$5,$1 # 1 2 2 + ldq $4,24($16) # 4 1 + umulh $21,$19,$21 # 2 2 ###### + cmpult $1,$5,$22 # 1 2 3 1 + addq $20,$22,$20 # 1 3 1 + addq $1,$0,$1 # 1 2 3 1 + mulq $27,$19,$7 # 3 2 1 ###### + cmpult $1,$0,$0 # 1 2 3 2 + addq $2,$6,$2 # 2 2 2 + addq $20,$0,$0 # 1 3 2 + cmpult $2,$6,$23 # 2 2 3 1 + addq $21,$23,$21 # 2 3 1 + umulh $27,$19,$27 # 3 2 ###### + addq $2,$0,$2 # 2 2 3 1 + cmpult $2,$0,$0 # 2 2 3 2 + subq $18,4,$18 + mulq $28,$19,$8 # 4 2 1 ###### + addq $21,$0,$0 # 2 3 2 + addq $3,$7,$3 # 3 2 2 + addq $16,32,$16 + cmpult $3,$7,$24 # 3 2 3 1 + stq $1,-32($16) # 1 2 4 + umulh $28,$19,$28 # 4 2 ###### + addq $27,$24,$27 # 3 3 1 + addq $3,$0,$3 # 3 2 3 1 + stq $2,-24($16) # 2 2 4 + cmpult $3,$0,$0 # 3 2 3 2 + stq $3,-16($16) # 3 2 4 + addq $4,$8,$4 # 4 2 2 + addq $27,$0,$0 # 3 3 2 + cmpult $4,$8,$25 # 4 2 3 1 + addq $17,32,$17 + addq $28,$25,$28 # 4 3 1 + addq $4,$0,$4 # 4 2 3 1 + cmpult $4,$0,$0 # 4 2 3 2 + stq $4,-8($16) # 4 2 4 + addq $28,$0,$0 # 4 3 2 + blt $18,$43 + + ldq $20,0($17) # 1 1 + ldq $1,0($16) # 1 1 + + br $42 + + .align 4 +$45: + ldq $20,0($17) # 4 1 + ldq $1,0($16) # 4 1 + mulq $20,$19,$5 # 4 2 1 + subq $18,1,$18 + addq $16,8,$16 + addq $17,8,$17 + umulh $20,$19,$20 # 4 2 + addq $1,$5,$1 # 4 2 2 + cmpult $1,$5,$22 # 4 2 3 1 + addq $20,$22,$20 # 4 3 1 + addq $1,$0,$1 # 4 2 3 1 + cmpult $1,$0,$0 # 4 2 3 2 + addq $20,$0,$0 # 4 3 2 + stq $1,-8($16) # 4 2 4 + bgt $18,$45 + ret $31,($26),1 # else exit + + .align 4 +$43: + addq $18,4,$18 + bgt $18,$45 # goto tail code + ret $31,($26),1 # else exit + + .end bn_mul_add_words + .align 3 + .globl bn_mul_words + .ent bn_mul_words +bn_mul_words: +bn_mul_words..ng: + .frame $30,0,$26,0 + .prologue 0 + .align 5 + subq $18,4,$18 + bis $31,$31,$0 + blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code + ldq $20,0($17) # 1 1 + .align 3 +$142: + + mulq $20,$19,$5 # 1 2 1 ##### + ldq $21,8($17) # 2 1 + ldq $27,16($17) # 3 1 + umulh $20,$19,$20 # 1 2 ##### + ldq $28,24($17) # 4 1 + mulq $21,$19,$6 # 2 2 1 ##### + addq $5,$0,$5 # 1 2 3 1 + subq $18,4,$18 + cmpult $5,$0,$0 # 1 2 3 2 + umulh $21,$19,$21 # 2 2 ##### + addq $20,$0,$0 # 1 3 2 + addq $17,32,$17 + addq $6,$0,$6 # 2 2 3 1 + mulq $27,$19,$7 # 3 2 1 ##### + cmpult $6,$0,$0 # 2 2 3 2 + addq $21,$0,$0 # 2 3 2 + addq $16,32,$16 + umulh $27,$19,$27 # 3 2 ##### + stq $5,-32($16) # 1 2 4 + mulq $28,$19,$8 # 4 2 1 ##### + addq $7,$0,$7 # 3 2 3 1 + stq $6,-24($16) # 2 2 4 + cmpult $7,$0,$0 # 3 2 3 2 + umulh $28,$19,$28 # 4 2 ##### + addq $27,$0,$0 # 3 3 2 + stq $7,-16($16) # 3 2 4 + addq $8,$0,$8 # 4 2 3 1 + cmpult $8,$0,$0 # 4 2 3 2 + + addq $28,$0,$0 # 4 3 2 + + stq $8,-8($16) # 4 2 4 + + blt $18,$143 + + ldq $20,0($17) # 1 1 + + br $142 + + .align 4 +$145: + ldq $20,0($17) # 4 1 + mulq $20,$19,$5 # 4 2 1 + subq $18,1,$18 + umulh $20,$19,$20 # 4 2 + addq $5,$0,$5 # 4 2 3 1 + addq $16,8,$16 + cmpult $5,$0,$0 # 4 2 3 2 + addq $17,8,$17 + addq $20,$0,$0 # 4 3 2 + stq $5,-8($16) # 4 2 4 + + bgt $18,$145 + ret $31,($26),1 # else exit + + .align 4 +$143: + addq $18,4,$18 + bgt $18,$145 # goto tail code + ret $31,($26),1 # else exit + + .end bn_mul_words + .align 3 + .globl bn_sqr_words + .ent bn_sqr_words +bn_sqr_words: +bn_sqr_words..ng: + .frame $30,0,$26,0 + .prologue 0 + + subq $18,4,$18 + blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code + ldq $20,0($17) # 1 1 + .align 3 +$542: + mulq $20,$20,$5 ###### + ldq $21,8($17) # 1 1 + subq $18,4 + umulh $20,$20,$1 ###### + ldq $27,16($17) # 1 1 + mulq $21,$21,$6 ###### + ldq $28,24($17) # 1 1 + stq $5,0($16) # r[0] + umulh $21,$21,$2 ###### + stq $1,8($16) # r[1] + mulq $27,$27,$7 ###### + stq $6,16($16) # r[0] + umulh $27,$27,$3 ###### + stq $2,24($16) # r[1] + mulq $28,$28,$8 ###### + stq $7,32($16) # r[0] + umulh $28,$28,$4 ###### + stq $3,40($16) # r[1] + + addq $16,64,$16 + addq $17,32,$17 + stq $8,-16($16) # r[0] + stq $4,-8($16) # r[1] + + blt $18,$543 + ldq $20,0($17) # 1 1 + br $542 + +$442: + ldq $20,0($17) # a[0] + mulq $20,$20,$5 # a[0]*w low part r2 + addq $16,16,$16 + addq $17,8,$17 + subq $18,1,$18 + umulh $20,$20,$1 # a[0]*w high part r3 + stq $5,-16($16) # r[0] + stq $1,-8($16) # r[1] + + bgt $18,$442 + ret $31,($26),1 # else exit + + .align 4 +$543: + addq $18,4,$18 + bgt $18,$442 # goto tail code + ret $31,($26),1 # else exit + .end bn_sqr_words + + .align 3 + .globl bn_add_words + .ent bn_add_words +bn_add_words: +bn_add_words..ng: + .frame $30,0,$26,0 + .prologue 0 + + subq $19,4,$19 + bis $31,$31,$0 # carry = 0 + blt $19,$900 + ldq $5,0($17) # a[0] + ldq $1,0($18) # b[1] + .align 3 +$901: + addq $1,$5,$1 # r=a+b; + ldq $6,8($17) # a[1] + cmpult $1,$5,$22 # did we overflow? + ldq $2,8($18) # b[1] + addq $1,$0,$1 # c+= overflow + ldq $7,16($17) # a[2] + cmpult $1,$0,$0 # overflow? + ldq $3,16($18) # b[2] + addq $0,$22,$0 + ldq $8,24($17) # a[3] + addq $2,$6,$2 # r=a+b; + ldq $4,24($18) # b[3] + cmpult $2,$6,$23 # did we overflow? + addq $3,$7,$3 # r=a+b; + addq $2,$0,$2 # c+= overflow + cmpult $3,$7,$24 # did we overflow? + cmpult $2,$0,$0 # overflow? + addq $4,$8,$4 # r=a+b; + addq $0,$23,$0 + cmpult $4,$8,$25 # did we overflow? + addq $3,$0,$3 # c+= overflow + stq $1,0($16) # r[0]=c + cmpult $3,$0,$0 # overflow? + stq $2,8($16) # r[1]=c + addq $0,$24,$0 + stq $3,16($16) # r[2]=c + addq $4,$0,$4 # c+= overflow + subq $19,4,$19 # loop-- + cmpult $4,$0,$0 # overflow? + addq $17,32,$17 # a++ + addq $0,$25,$0 + stq $4,24($16) # r[3]=c + addq $18,32,$18 # b++ + addq $16,32,$16 # r++ + + blt $19,$900 + ldq $5,0($17) # a[0] + ldq $1,0($18) # b[1] + br $901 + .align 4 +$945: + ldq $5,0($17) # a[0] + ldq $1,0($18) # b[1] + addq $1,$5,$1 # r=a+b; + subq $19,1,$19 # loop-- + addq $1,$0,$1 # c+= overflow + addq $17,8,$17 # a++ + cmpult $1,$5,$22 # did we overflow? + cmpult $1,$0,$0 # overflow? + addq $18,8,$18 # b++ + stq $1,0($16) # r[0]=c + addq $0,$22,$0 + addq $16,8,$16 # r++ + + bgt $19,$945 + ret $31,($26),1 # else exit + +$900: + addq $19,4,$19 + bgt $19,$945 # goto tail code + ret $31,($26),1 # else exit + .end bn_add_words + + # + # What follows was taken directly from the C compiler with a few + # hacks to redo the lables. + # +.text + .align 3 + .globl bn_div64 + .ent bn_div64 +bn_div64: + ldgp $29,0($27) +bn_div64..ng: + lda $30,-48($30) + .frame $30,48,$26,0 + stq $26,0($30) + stq $9,8($30) + stq $10,16($30) + stq $11,24($30) + stq $12,32($30) + stq $13,40($30) + .mask 0x4003e00,-48 + .prologue 1 + bis $16,$16,$9 + bis $17,$17,$10 + bis $18,$18,$11 + bis $31,$31,$13 + bis $31,2,$12 + bne $11,$119 + lda $0,-1 + br $31,$136 + .align 4 +$119: + bis $11,$11,$16 + jsr $26,BN_num_bits_word + ldgp $29,0($26) + subq $0,64,$1 + beq $1,$120 + bis $31,1,$1 + sll $1,$0,$1 + cmpule $9,$1,$1 + bne $1,$120 + # lda $16,_IO_stderr_ + # lda $17,$C32 + # bis $0,$0,$18 + # jsr $26,fprintf + # ldgp $29,0($26) + jsr $26,abort + ldgp $29,0($26) + .align 4 +$120: + bis $31,64,$3 + cmpult $9,$11,$2 + subq $3,$0,$1 + addl $1,$31,$0 + subq $9,$11,$1 + cmoveq $2,$1,$9 + beq $0,$122 + zapnot $0,15,$2 + subq $3,$0,$1 + sll $11,$2,$11 + sll $9,$2,$3 + srl $10,$1,$1 + sll $10,$2,$10 + bis $3,$1,$9 +$122: + srl $11,32,$5 + zapnot $11,15,$6 + lda $7,-1 + .align 5 +$123: + srl $9,32,$1 + subq $1,$5,$1 + bne $1,$126 + zapnot $7,15,$27 + br $31,$127 + .align 4 +$126: + bis $9,$9,$24 + bis $5,$5,$25 + divqu $24,$25,$27 +$127: + srl $10,32,$4 + .align 5 +$128: + mulq $27,$5,$1 + subq $9,$1,$3 + zapnot $3,240,$1 + bne $1,$129 + mulq $6,$27,$2 + sll $3,32,$1 + addq $1,$4,$1 + cmpule $2,$1,$2 + bne $2,$129 + subq $27,1,$27 + br $31,$128 + .align 4 +$129: + mulq $27,$6,$1 + mulq $27,$5,$4 + srl $1,32,$3 + sll $1,32,$1 + addq $4,$3,$4 + cmpult $10,$1,$2 + subq $10,$1,$10 + addq $2,$4,$2 + cmpult $9,$2,$1 + bis $2,$2,$4 + beq $1,$134 + addq $9,$11,$9 + subq $27,1,$27 +$134: + subl $12,1,$12 + subq $9,$4,$9 + beq $12,$124 + sll $27,32,$13 + sll $9,32,$2 + srl $10,32,$1 + sll $10,32,$10 + bis $2,$1,$9 + br $31,$123 + .align 4 +$124: + bis $13,$27,$0 +$136: + ldq $26,0($30) + ldq $9,8($30) + ldq $10,16($30) + ldq $11,24($30) + ldq $12,32($30) + ldq $13,40($30) + addq $30,48,$30 + ret $31,($26),1 + .end bn_div64 + + .set noat + .text + .align 3 + .globl bn_sub_words + .ent bn_sub_words +bn_sub_words: +bn_sub_words..ng: + .frame $30,0,$26,0 + .prologue 0 + + subq $19, 4, $19 + bis $31, $31, $0 + blt $19, $100 + ldq $1, 0($17) + ldq $2, 0($18) +$101: + ldq $3, 8($17) + cmpult $1, $2, $4 + ldq $5, 8($18) + subq $1, $2, $1 + ldq $6, 16($17) + cmpult $1, $0, $2 + ldq $7, 16($18) + subq $1, $0, $23 + ldq $8, 24($17) + addq $2, $4, $0 + cmpult $3, $5, $24 + subq $3, $5, $3 + ldq $22, 24($18) + cmpult $3, $0, $5 + subq $3, $0, $25 + addq $5, $24, $0 + cmpult $6, $7, $27 + subq $6, $7, $6 + stq $23, 0($16) + cmpult $6, $0, $7 + subq $6, $0, $28 + addq $7, $27, $0 + cmpult $8, $22, $21 + subq $8, $22, $8 + stq $25, 8($16) + cmpult $8, $0, $22 + subq $8, $0, $20 + addq $22, $21, $0 + stq $28, 16($16) + subq $19, 4, $19 + stq $20, 24($16) + addq $17, 32, $17 + addq $18, 32, $18 + addq $16, 32, $16 + blt $19, $100 + ldq $1, 0($17) + ldq $2, 0($18) + br $101 +$102: + ldq $1, 0($17) + ldq $2, 0($18) + cmpult $1, $2, $27 + subq $1, $2, $1 + cmpult $1, $0, $2 + subq $1, $0, $1 + stq $1, 0($16) + addq $2, $27, $0 + addq $17, 8, $17 + addq $18, 8, $18 + addq $16, 8, $16 + subq $19, 1, $19 + bgt $19, $102 + ret $31,($26),1 +$100: + addq $19, 4, $19 + bgt $19, $102 +$103: + ret $31,($26),1 + .end bn_sub_words diff --git a/src/lib/libcrypto/bn/asm/bn-586.pl b/src/lib/libcrypto/bn/asm/bn-586.pl index 19d425ee96..5191bed273 100644 --- a/src/lib/libcrypto/bn/asm/bn-586.pl +++ b/src/lib/libcrypto/bn/asm/bn-586.pl @@ -1,18 +1,16 @@ -#!/usr/bin/perl -# - #!/usr/local/bin/perl push(@INC,"perlasm","../../perlasm"); require "x86asm.pl"; -&asm_init($ARGV[0],"bn-586.pl"); +&asm_init($ARGV[0],$0); &bn_mul_add_words("bn_mul_add_words"); &bn_mul_words("bn_mul_words"); &bn_sqr_words("bn_sqr_words"); -&bn_div64("bn_div64"); +&bn_div_words("bn_div_words"); &bn_add_words("bn_add_words"); +&bn_sub_words("bn_sub_words"); &asm_finish(); @@ -228,7 +226,7 @@ sub bn_sqr_words &function_end($name); } -sub bn_div64 +sub bn_div_words { local($name)=@_; @@ -307,7 +305,79 @@ sub bn_add_words } &set_label("aw_end",0); - &mov("eax",$c); +# &mov("eax",$c); # $c is "eax" + + &function_end($name); + } + +sub bn_sub_words + { + local($name)=@_; + + &function_begin($name,""); + + &comment(""); + $a="esi"; + $b="edi"; + $c="eax"; + $r="ebx"; + $tmp1="ecx"; + $tmp2="edx"; + $num="ebp"; + + &mov($r,&wparam(0)); # get r + &mov($a,&wparam(1)); # get a + &mov($b,&wparam(2)); # get b + &mov($num,&wparam(3)); # get num + &xor($c,$c); # clear carry + &and($num,0xfffffff8); # num / 8 + + &jz(&label("aw_finish")); + + &set_label("aw_loop",0); + for ($i=0; $i<8; $i++) + { + &comment("Round $i"); + + &mov($tmp1,&DWP($i*4,$a,"",0)); # *a + &mov($tmp2,&DWP($i*4,$b,"",0)); # *b + &sub($tmp1,$c); + &mov($c,0); + &adc($c,$c); + &sub($tmp1,$tmp2); + &adc($c,0); + &mov(&DWP($i*4,$r,"",0),$tmp1); # *r + } + + &comment(""); + &add($a,32); + &add($b,32); + &add($r,32); + &sub($num,8); + &jnz(&label("aw_loop")); + + &set_label("aw_finish",0); + &mov($num,&wparam(3)); # get num + &and($num,7); + &jz(&label("aw_end")); + + for ($i=0; $i<7; $i++) + { + &comment("Tail Round $i"); + &mov($tmp1,&DWP($i*4,$a,"",0)); # *a + &mov($tmp2,&DWP($i*4,$b,"",0));# *b + &sub($tmp1,$c); + &mov($c,0); + &adc($c,$c); + &sub($tmp1,$tmp2); + &adc($c,0); + &dec($num) if ($i != 6); + &mov(&DWP($i*4,$r,"",0),$tmp1); # *a + &jz(&label("aw_end")) if ($i != 6); + } + &set_label("aw_end",0); + +# &mov("eax",$c); # $c is "eax" &function_end($name); } diff --git a/src/lib/libcrypto/bn/asm/bn-alpha.pl b/src/lib/libcrypto/bn/asm/bn-alpha.pl new file mode 100644 index 0000000000..302edf2376 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/bn-alpha.pl @@ -0,0 +1,571 @@ +#!/usr/local/bin/perl +# I have this in perl so I can use more usefull register names and then convert +# them into alpha registers. +# + +$d=&data(); +$d =~ s/CC/0/g; +$d =~ s/R1/1/g; +$d =~ s/R2/2/g; +$d =~ s/R3/3/g; +$d =~ s/R4/4/g; +$d =~ s/L1/5/g; +$d =~ s/L2/6/g; +$d =~ s/L3/7/g; +$d =~ s/L4/8/g; +$d =~ s/O1/22/g; +$d =~ s/O2/23/g; +$d =~ s/O3/24/g; +$d =~ s/O4/25/g; +$d =~ s/A1/20/g; +$d =~ s/A2/21/g; +$d =~ s/A3/27/g; +$d =~ s/A4/28/g; +if (0){ +} + +print $d; + +sub data + { + local($data)=<<'EOF'; + + # DEC Alpha assember + # The bn_div_words is actually gcc output but the other parts are hand done. + # Thanks to tzeruch@ceddec.com for sending me the gcc output for + # bn_div_words. + # I've gone back and re-done most of routines. + # The key thing to remeber for the 164 CPU is that while a + # multiply operation takes 8 cycles, another one can only be issued + # after 4 cycles have elapsed. I've done modification to help + # improve this. Also, normally, a ld instruction will not be available + # for about 3 cycles. + .file 1 "bn_asm.c" + .set noat +gcc2_compiled.: +__gnu_compiled_c: + .text + .align 3 + .globl bn_mul_add_words + .ent bn_mul_add_words +bn_mul_add_words: +bn_mul_add_words..ng: + .frame $30,0,$26,0 + .prologue 0 + .align 5 + subq $18,4,$18 + bis $31,$31,$CC + blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code + ldq $A1,0($17) # 1 1 + ldq $R1,0($16) # 1 1 + .align 3 +$42: + mulq $A1,$19,$L1 # 1 2 1 ###### + ldq $A2,8($17) # 2 1 + ldq $R2,8($16) # 2 1 + umulh $A1,$19,$A1 # 1 2 ###### + ldq $A3,16($17) # 3 1 + ldq $R3,16($16) # 3 1 + mulq $A2,$19,$L2 # 2 2 1 ###### + ldq $A4,24($17) # 4 1 + addq $R1,$L1,$R1 # 1 2 2 + ldq $R4,24($16) # 4 1 + umulh $A2,$19,$A2 # 2 2 ###### + cmpult $R1,$L1,$O1 # 1 2 3 1 + addq $A1,$O1,$A1 # 1 3 1 + addq $R1,$CC,$R1 # 1 2 3 1 + mulq $A3,$19,$L3 # 3 2 1 ###### + cmpult $R1,$CC,$CC # 1 2 3 2 + addq $R2,$L2,$R2 # 2 2 2 + addq $A1,$CC,$CC # 1 3 2 + cmpult $R2,$L2,$O2 # 2 2 3 1 + addq $A2,$O2,$A2 # 2 3 1 + umulh $A3,$19,$A3 # 3 2 ###### + addq $R2,$CC,$R2 # 2 2 3 1 + cmpult $R2,$CC,$CC # 2 2 3 2 + subq $18,4,$18 + mulq $A4,$19,$L4 # 4 2 1 ###### + addq $A2,$CC,$CC # 2 3 2 + addq $R3,$L3,$R3 # 3 2 2 + addq $16,32,$16 + cmpult $R3,$L3,$O3 # 3 2 3 1 + stq $R1,-32($16) # 1 2 4 + umulh $A4,$19,$A4 # 4 2 ###### + addq $A3,$O3,$A3 # 3 3 1 + addq $R3,$CC,$R3 # 3 2 3 1 + stq $R2,-24($16) # 2 2 4 + cmpult $R3,$CC,$CC # 3 2 3 2 + stq $R3,-16($16) # 3 2 4 + addq $R4,$L4,$R4 # 4 2 2 + addq $A3,$CC,$CC # 3 3 2 + cmpult $R4,$L4,$O4 # 4 2 3 1 + addq $17,32,$17 + addq $A4,$O4,$A4 # 4 3 1 + addq $R4,$CC,$R4 # 4 2 3 1 + cmpult $R4,$CC,$CC # 4 2 3 2 + stq $R4,-8($16) # 4 2 4 + addq $A4,$CC,$CC # 4 3 2 + blt $18,$43 + + ldq $A1,0($17) # 1 1 + ldq $R1,0($16) # 1 1 + + br $42 + + .align 4 +$45: + ldq $A1,0($17) # 4 1 + ldq $R1,0($16) # 4 1 + mulq $A1,$19,$L1 # 4 2 1 + subq $18,1,$18 + addq $16,8,$16 + addq $17,8,$17 + umulh $A1,$19,$A1 # 4 2 + addq $R1,$L1,$R1 # 4 2 2 + cmpult $R1,$L1,$O1 # 4 2 3 1 + addq $A1,$O1,$A1 # 4 3 1 + addq $R1,$CC,$R1 # 4 2 3 1 + cmpult $R1,$CC,$CC # 4 2 3 2 + addq $A1,$CC,$CC # 4 3 2 + stq $R1,-8($16) # 4 2 4 + bgt $18,$45 + ret $31,($26),1 # else exit + + .align 4 +$43: + addq $18,4,$18 + bgt $18,$45 # goto tail code + ret $31,($26),1 # else exit + + .end bn_mul_add_words + .align 3 + .globl bn_mul_words + .ent bn_mul_words +bn_mul_words: +bn_mul_words..ng: + .frame $30,0,$26,0 + .prologue 0 + .align 5 + subq $18,4,$18 + bis $31,$31,$CC + blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code + ldq $A1,0($17) # 1 1 + .align 3 +$142: + + mulq $A1,$19,$L1 # 1 2 1 ##### + ldq $A2,8($17) # 2 1 + ldq $A3,16($17) # 3 1 + umulh $A1,$19,$A1 # 1 2 ##### + ldq $A4,24($17) # 4 1 + mulq $A2,$19,$L2 # 2 2 1 ##### + addq $L1,$CC,$L1 # 1 2 3 1 + subq $18,4,$18 + cmpult $L1,$CC,$CC # 1 2 3 2 + umulh $A2,$19,$A2 # 2 2 ##### + addq $A1,$CC,$CC # 1 3 2 + addq $17,32,$17 + addq $L2,$CC,$L2 # 2 2 3 1 + mulq $A3,$19,$L3 # 3 2 1 ##### + cmpult $L2,$CC,$CC # 2 2 3 2 + addq $A2,$CC,$CC # 2 3 2 + addq $16,32,$16 + umulh $A3,$19,$A3 # 3 2 ##### + stq $L1,-32($16) # 1 2 4 + mulq $A4,$19,$L4 # 4 2 1 ##### + addq $L3,$CC,$L3 # 3 2 3 1 + stq $L2,-24($16) # 2 2 4 + cmpult $L3,$CC,$CC # 3 2 3 2 + umulh $A4,$19,$A4 # 4 2 ##### + addq $A3,$CC,$CC # 3 3 2 + stq $L3,-16($16) # 3 2 4 + addq $L4,$CC,$L4 # 4 2 3 1 + cmpult $L4,$CC,$CC # 4 2 3 2 + + addq $A4,$CC,$CC # 4 3 2 + + stq $L4,-8($16) # 4 2 4 + + blt $18,$143 + + ldq $A1,0($17) # 1 1 + + br $142 + + .align 4 +$145: + ldq $A1,0($17) # 4 1 + mulq $A1,$19,$L1 # 4 2 1 + subq $18,1,$18 + umulh $A1,$19,$A1 # 4 2 + addq $L1,$CC,$L1 # 4 2 3 1 + addq $16,8,$16 + cmpult $L1,$CC,$CC # 4 2 3 2 + addq $17,8,$17 + addq $A1,$CC,$CC # 4 3 2 + stq $L1,-8($16) # 4 2 4 + + bgt $18,$145 + ret $31,($26),1 # else exit + + .align 4 +$143: + addq $18,4,$18 + bgt $18,$145 # goto tail code + ret $31,($26),1 # else exit + + .end bn_mul_words + .align 3 + .globl bn_sqr_words + .ent bn_sqr_words +bn_sqr_words: +bn_sqr_words..ng: + .frame $30,0,$26,0 + .prologue 0 + + subq $18,4,$18 + blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code + ldq $A1,0($17) # 1 1 + .align 3 +$542: + mulq $A1,$A1,$L1 ###### + ldq $A2,8($17) # 1 1 + subq $18,4 + umulh $A1,$A1,$R1 ###### + ldq $A3,16($17) # 1 1 + mulq $A2,$A2,$L2 ###### + ldq $A4,24($17) # 1 1 + stq $L1,0($16) # r[0] + umulh $A2,$A2,$R2 ###### + stq $R1,8($16) # r[1] + mulq $A3,$A3,$L3 ###### + stq $L2,16($16) # r[0] + umulh $A3,$A3,$R3 ###### + stq $R2,24($16) # r[1] + mulq $A4,$A4,$L4 ###### + stq $L3,32($16) # r[0] + umulh $A4,$A4,$R4 ###### + stq $R3,40($16) # r[1] + + addq $16,64,$16 + addq $17,32,$17 + stq $L4,-16($16) # r[0] + stq $R4,-8($16) # r[1] + + blt $18,$543 + ldq $A1,0($17) # 1 1 + br $542 + +$442: + ldq $A1,0($17) # a[0] + mulq $A1,$A1,$L1 # a[0]*w low part r2 + addq $16,16,$16 + addq $17,8,$17 + subq $18,1,$18 + umulh $A1,$A1,$R1 # a[0]*w high part r3 + stq $L1,-16($16) # r[0] + stq $R1,-8($16) # r[1] + + bgt $18,$442 + ret $31,($26),1 # else exit + + .align 4 +$543: + addq $18,4,$18 + bgt $18,$442 # goto tail code + ret $31,($26),1 # else exit + .end bn_sqr_words + + .align 3 + .globl bn_add_words + .ent bn_add_words +bn_add_words: +bn_add_words..ng: + .frame $30,0,$26,0 + .prologue 0 + + subq $19,4,$19 + bis $31,$31,$CC # carry = 0 + blt $19,$900 + ldq $L1,0($17) # a[0] + ldq $R1,0($18) # b[1] + .align 3 +$901: + addq $R1,$L1,$R1 # r=a+b; + ldq $L2,8($17) # a[1] + cmpult $R1,$L1,$O1 # did we overflow? + ldq $R2,8($18) # b[1] + addq $R1,$CC,$R1 # c+= overflow + ldq $L3,16($17) # a[2] + cmpult $R1,$CC,$CC # overflow? + ldq $R3,16($18) # b[2] + addq $CC,$O1,$CC + ldq $L4,24($17) # a[3] + addq $R2,$L2,$R2 # r=a+b; + ldq $R4,24($18) # b[3] + cmpult $R2,$L2,$O2 # did we overflow? + addq $R3,$L3,$R3 # r=a+b; + addq $R2,$CC,$R2 # c+= overflow + cmpult $R3,$L3,$O3 # did we overflow? + cmpult $R2,$CC,$CC # overflow? + addq $R4,$L4,$R4 # r=a+b; + addq $CC,$O2,$CC + cmpult $R4,$L4,$O4 # did we overflow? + addq $R3,$CC,$R3 # c+= overflow + stq $R1,0($16) # r[0]=c + cmpult $R3,$CC,$CC # overflow? + stq $R2,8($16) # r[1]=c + addq $CC,$O3,$CC + stq $R3,16($16) # r[2]=c + addq $R4,$CC,$R4 # c+= overflow + subq $19,4,$19 # loop-- + cmpult $R4,$CC,$CC # overflow? + addq $17,32,$17 # a++ + addq $CC,$O4,$CC + stq $R4,24($16) # r[3]=c + addq $18,32,$18 # b++ + addq $16,32,$16 # r++ + + blt $19,$900 + ldq $L1,0($17) # a[0] + ldq $R1,0($18) # b[1] + br $901 + .align 4 +$945: + ldq $L1,0($17) # a[0] + ldq $R1,0($18) # b[1] + addq $R1,$L1,$R1 # r=a+b; + subq $19,1,$19 # loop-- + addq $R1,$CC,$R1 # c+= overflow + addq $17,8,$17 # a++ + cmpult $R1,$L1,$O1 # did we overflow? + cmpult $R1,$CC,$CC # overflow? + addq $18,8,$18 # b++ + stq $R1,0($16) # r[0]=c + addq $CC,$O1,$CC + addq $16,8,$16 # r++ + + bgt $19,$945 + ret $31,($26),1 # else exit + +$900: + addq $19,4,$19 + bgt $19,$945 # goto tail code + ret $31,($26),1 # else exit + .end bn_add_words + + .align 3 + .globl bn_sub_words + .ent bn_sub_words +bn_sub_words: +bn_sub_words..ng: + .frame $30,0,$26,0 + .prologue 0 + + subq $19,4,$19 + bis $31,$31,$CC # carry = 0 + br $800 + blt $19,$800 + ldq $L1,0($17) # a[0] + ldq $R1,0($18) # b[1] + .align 3 +$801: + addq $R1,$L1,$R1 # r=a+b; + ldq $L2,8($17) # a[1] + cmpult $R1,$L1,$O1 # did we overflow? + ldq $R2,8($18) # b[1] + addq $R1,$CC,$R1 # c+= overflow + ldq $L3,16($17) # a[2] + cmpult $R1,$CC,$CC # overflow? + ldq $R3,16($18) # b[2] + addq $CC,$O1,$CC + ldq $L4,24($17) # a[3] + addq $R2,$L2,$R2 # r=a+b; + ldq $R4,24($18) # b[3] + cmpult $R2,$L2,$O2 # did we overflow? + addq $R3,$L3,$R3 # r=a+b; + addq $R2,$CC,$R2 # c+= overflow + cmpult $R3,$L3,$O3 # did we overflow? + cmpult $R2,$CC,$CC # overflow? + addq $R4,$L4,$R4 # r=a+b; + addq $CC,$O2,$CC + cmpult $R4,$L4,$O4 # did we overflow? + addq $R3,$CC,$R3 # c+= overflow + stq $R1,0($16) # r[0]=c + cmpult $R3,$CC,$CC # overflow? + stq $R2,8($16) # r[1]=c + addq $CC,$O3,$CC + stq $R3,16($16) # r[2]=c + addq $R4,$CC,$R4 # c+= overflow + subq $19,4,$19 # loop-- + cmpult $R4,$CC,$CC # overflow? + addq $17,32,$17 # a++ + addq $CC,$O4,$CC + stq $R4,24($16) # r[3]=c + addq $18,32,$18 # b++ + addq $16,32,$16 # r++ + + blt $19,$800 + ldq $L1,0($17) # a[0] + ldq $R1,0($18) # b[1] + br $801 + .align 4 +$845: + ldq $L1,0($17) # a[0] + ldq $R1,0($18) # b[1] + cmpult $L1,$R1,$O1 # will we borrow? + subq $L1,$R1,$R1 # r=a-b; + subq $19,1,$19 # loop-- + cmpult $R1,$CC,$O2 # will we borrow? + subq $R1,$CC,$R1 # c+= overflow + addq $17,8,$17 # a++ + addq $18,8,$18 # b++ + stq $R1,0($16) # r[0]=c + addq $O2,$O1,$CC + addq $16,8,$16 # r++ + + bgt $19,$845 + ret $31,($26),1 # else exit + +$800: + addq $19,4,$19 + bgt $19,$845 # goto tail code + ret $31,($26),1 # else exit + .end bn_sub_words + + # + # What follows was taken directly from the C compiler with a few + # hacks to redo the lables. + # +.text + .align 3 + .globl bn_div_words + .ent bn_div_words +bn_div_words: + ldgp $29,0($27) +bn_div_words..ng: + lda $30,-48($30) + .frame $30,48,$26,0 + stq $26,0($30) + stq $9,8($30) + stq $10,16($30) + stq $11,24($30) + stq $12,32($30) + stq $13,40($30) + .mask 0x4003e00,-48 + .prologue 1 + bis $16,$16,$9 + bis $17,$17,$10 + bis $18,$18,$11 + bis $31,$31,$13 + bis $31,2,$12 + bne $11,$119 + lda $0,-1 + br $31,$136 + .align 4 +$119: + bis $11,$11,$16 + jsr $26,BN_num_bits_word + ldgp $29,0($26) + subq $0,64,$1 + beq $1,$120 + bis $31,1,$1 + sll $1,$0,$1 + cmpule $9,$1,$1 + bne $1,$120 + # lda $16,_IO_stderr_ + # lda $17,$C32 + # bis $0,$0,$18 + # jsr $26,fprintf + # ldgp $29,0($26) + jsr $26,abort + ldgp $29,0($26) + .align 4 +$120: + bis $31,64,$3 + cmpult $9,$11,$2 + subq $3,$0,$1 + addl $1,$31,$0 + subq $9,$11,$1 + cmoveq $2,$1,$9 + beq $0,$122 + zapnot $0,15,$2 + subq $3,$0,$1 + sll $11,$2,$11 + sll $9,$2,$3 + srl $10,$1,$1 + sll $10,$2,$10 + bis $3,$1,$9 +$122: + srl $11,32,$5 + zapnot $11,15,$6 + lda $7,-1 + .align 5 +$123: + srl $9,32,$1 + subq $1,$5,$1 + bne $1,$126 + zapnot $7,15,$27 + br $31,$127 + .align 4 +$126: + bis $9,$9,$24 + bis $5,$5,$25 + divqu $24,$25,$27 +$127: + srl $10,32,$4 + .align 5 +$128: + mulq $27,$5,$1 + subq $9,$1,$3 + zapnot $3,240,$1 + bne $1,$129 + mulq $6,$27,$2 + sll $3,32,$1 + addq $1,$4,$1 + cmpule $2,$1,$2 + bne $2,$129 + subq $27,1,$27 + br $31,$128 + .align 4 +$129: + mulq $27,$6,$1 + mulq $27,$5,$4 + srl $1,32,$3 + sll $1,32,$1 + addq $4,$3,$4 + cmpult $10,$1,$2 + subq $10,$1,$10 + addq $2,$4,$2 + cmpult $9,$2,$1 + bis $2,$2,$4 + beq $1,$134 + addq $9,$11,$9 + subq $27,1,$27 +$134: + subl $12,1,$12 + subq $9,$4,$9 + beq $12,$124 + sll $27,32,$13 + sll $9,32,$2 + srl $10,32,$1 + sll $10,32,$10 + bis $2,$1,$9 + br $31,$123 + .align 4 +$124: + bis $13,$27,$0 +$136: + ldq $26,0($30) + ldq $9,8($30) + ldq $10,16($30) + ldq $11,24($30) + ldq $12,32($30) + ldq $13,40($30) + addq $30,48,$30 + ret $31,($26),1 + .end bn_div_words +EOF + return($data); + } + diff --git a/src/lib/libcrypto/bn/asm/bn-win32.asm b/src/lib/libcrypto/bn/asm/bn-win32.asm index 017ea462b0..871bd88d77 100644 --- a/src/lib/libcrypto/bn/asm/bn-win32.asm +++ b/src/lib/libcrypto/bn/asm/bn-win32.asm @@ -485,9 +485,9 @@ $L010sw_end: _bn_sqr_words ENDP _TEXT ENDS _TEXT SEGMENT -PUBLIC _bn_div64 +PUBLIC _bn_div_words -_bn_div64 PROC NEAR +_bn_div_words PROC NEAR push ebp push ebx push esi @@ -501,7 +501,7 @@ _bn_div64 PROC NEAR pop ebx pop ebp ret -_bn_div64 ENDP +_bn_div_words ENDP _TEXT ENDS _TEXT SEGMENT PUBLIC _bn_add_words @@ -678,7 +678,6 @@ $L011aw_finish: adc eax, 0 mov DWORD PTR 24[ebx],ecx $L013aw_end: - mov eax, eax pop edi pop esi pop ebx @@ -686,4 +685,1438 @@ $L013aw_end: ret _bn_add_words ENDP _TEXT ENDS +_TEXT SEGMENT +PUBLIC _bn_sub_words + +_bn_sub_words PROC NEAR + push ebp + push ebx + push esi + push edi + ; + mov ebx, DWORD PTR 20[esp] + mov esi, DWORD PTR 24[esp] + mov edi, DWORD PTR 28[esp] + mov ebp, DWORD PTR 32[esp] + xor eax, eax + and ebp, 4294967288 + jz $L014aw_finish +L015aw_loop: + ; Round 0 + mov ecx, DWORD PTR [esi] + mov edx, DWORD PTR [edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR [ebx],ecx + ; Round 1 + mov ecx, DWORD PTR 4[esi] + mov edx, DWORD PTR 4[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR 4[ebx],ecx + ; Round 2 + mov ecx, DWORD PTR 8[esi] + mov edx, DWORD PTR 8[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR 8[ebx],ecx + ; Round 3 + mov ecx, DWORD PTR 12[esi] + mov edx, DWORD PTR 12[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR 12[ebx],ecx + ; Round 4 + mov ecx, DWORD PTR 16[esi] + mov edx, DWORD PTR 16[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR 16[ebx],ecx + ; Round 5 + mov ecx, DWORD PTR 20[esi] + mov edx, DWORD PTR 20[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR 20[ebx],ecx + ; Round 6 + mov ecx, DWORD PTR 24[esi] + mov edx, DWORD PTR 24[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR 24[ebx],ecx + ; Round 7 + mov ecx, DWORD PTR 28[esi] + mov edx, DWORD PTR 28[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR 28[ebx],ecx + ; + add esi, 32 + add edi, 32 + add ebx, 32 + sub ebp, 8 + jnz L015aw_loop +$L014aw_finish: + mov ebp, DWORD PTR 32[esp] + and ebp, 7 + jz $L016aw_end + ; Tail Round 0 + mov ecx, DWORD PTR [esi] + mov edx, DWORD PTR [edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + dec ebp + mov DWORD PTR [ebx],ecx + jz $L016aw_end + ; Tail Round 1 + mov ecx, DWORD PTR 4[esi] + mov edx, DWORD PTR 4[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + dec ebp + mov DWORD PTR 4[ebx],ecx + jz $L016aw_end + ; Tail Round 2 + mov ecx, DWORD PTR 8[esi] + mov edx, DWORD PTR 8[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + dec ebp + mov DWORD PTR 8[ebx],ecx + jz $L016aw_end + ; Tail Round 3 + mov ecx, DWORD PTR 12[esi] + mov edx, DWORD PTR 12[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + dec ebp + mov DWORD PTR 12[ebx],ecx + jz $L016aw_end + ; Tail Round 4 + mov ecx, DWORD PTR 16[esi] + mov edx, DWORD PTR 16[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + dec ebp + mov DWORD PTR 16[ebx],ecx + jz $L016aw_end + ; Tail Round 5 + mov ecx, DWORD PTR 20[esi] + mov edx, DWORD PTR 20[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + dec ebp + mov DWORD PTR 20[ebx],ecx + jz $L016aw_end + ; Tail Round 6 + mov ecx, DWORD PTR 24[esi] + mov edx, DWORD PTR 24[edi] + sub ecx, eax + mov eax, 0 + adc eax, eax + sub ecx, edx + adc eax, 0 + mov DWORD PTR 24[ebx],ecx +$L016aw_end: + pop edi + pop esi + pop ebx + pop ebp + ret +_bn_sub_words ENDP +_TEXT ENDS +_TEXT SEGMENT +PUBLIC _bn_mul_comba8 + +_bn_mul_comba8 PROC NEAR + push esi + mov esi, DWORD PTR 12[esp] + push edi + mov edi, DWORD PTR 20[esp] + push ebp + push ebx + xor ebx, ebx + mov eax, DWORD PTR [esi] + xor ecx, ecx + mov edx, DWORD PTR [edi] + ; ################## Calculate word 0 + xor ebp, ebp + ; mul a[0]*b[0] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esp] + adc ecx, edx + mov edx, DWORD PTR [edi] + adc ebp, 0 + mov DWORD PTR [eax],ebx + mov eax, DWORD PTR 4[esi] + ; saved r[0] + ; ################## Calculate word 1 + xor ebx, ebx + ; mul a[1]*b[0] + mul edx + add ecx, eax + mov eax, DWORD PTR [esi] + adc ebp, edx + mov edx, DWORD PTR 4[edi] + adc ebx, 0 + ; mul a[0]*b[1] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esp] + adc ebp, edx + mov edx, DWORD PTR [edi] + adc ebx, 0 + mov DWORD PTR 4[eax],ecx + mov eax, DWORD PTR 8[esi] + ; saved r[1] + ; ################## Calculate word 2 + xor ecx, ecx + ; mul a[2]*b[0] + mul edx + add ebp, eax + mov eax, DWORD PTR 4[esi] + adc ebx, edx + mov edx, DWORD PTR 4[edi] + adc ecx, 0 + ; mul a[1]*b[1] + mul edx + add ebp, eax + mov eax, DWORD PTR [esi] + adc ebx, edx + mov edx, DWORD PTR 8[edi] + adc ecx, 0 + ; mul a[0]*b[2] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esp] + adc ebx, edx + mov edx, DWORD PTR [edi] + adc ecx, 0 + mov DWORD PTR 8[eax],ebp + mov eax, DWORD PTR 12[esi] + ; saved r[2] + ; ################## Calculate word 3 + xor ebp, ebp + ; mul a[3]*b[0] + mul edx + add ebx, eax + mov eax, DWORD PTR 8[esi] + adc ecx, edx + mov edx, DWORD PTR 4[edi] + adc ebp, 0 + ; mul a[2]*b[1] + mul edx + add ebx, eax + mov eax, DWORD PTR 4[esi] + adc ecx, edx + mov edx, DWORD PTR 8[edi] + adc ebp, 0 + ; mul a[1]*b[2] + mul edx + add ebx, eax + mov eax, DWORD PTR [esi] + adc ecx, edx + mov edx, DWORD PTR 12[edi] + adc ebp, 0 + ; mul a[0]*b[3] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esp] + adc ecx, edx + mov edx, DWORD PTR [edi] + adc ebp, 0 + mov DWORD PTR 12[eax],ebx + mov eax, DWORD PTR 16[esi] + ; saved r[3] + ; ################## Calculate word 4 + xor ebx, ebx + ; mul a[4]*b[0] + mul edx + add ecx, eax + mov eax, DWORD PTR 12[esi] + adc ebp, edx + mov edx, DWORD PTR 4[edi] + adc ebx, 0 + ; mul a[3]*b[1] + mul edx + add ecx, eax + mov eax, DWORD PTR 8[esi] + adc ebp, edx + mov edx, DWORD PTR 8[edi] + adc ebx, 0 + ; mul a[2]*b[2] + mul edx + add ecx, eax + mov eax, DWORD PTR 4[esi] + adc ebp, edx + mov edx, DWORD PTR 12[edi] + adc ebx, 0 + ; mul a[1]*b[3] + mul edx + add ecx, eax + mov eax, DWORD PTR [esi] + adc ebp, edx + mov edx, DWORD PTR 16[edi] + adc ebx, 0 + ; mul a[0]*b[4] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esp] + adc ebp, edx + mov edx, DWORD PTR [edi] + adc ebx, 0 + mov DWORD PTR 16[eax],ecx + mov eax, DWORD PTR 20[esi] + ; saved r[4] + ; ################## Calculate word 5 + xor ecx, ecx + ; mul a[5]*b[0] + mul edx + add ebp, eax + mov eax, DWORD PTR 16[esi] + adc ebx, edx + mov edx, DWORD PTR 4[edi] + adc ecx, 0 + ; mul a[4]*b[1] + mul edx + add ebp, eax + mov eax, DWORD PTR 12[esi] + adc ebx, edx + mov edx, DWORD PTR 8[edi] + adc ecx, 0 + ; mul a[3]*b[2] + mul edx + add ebp, eax + mov eax, DWORD PTR 8[esi] + adc ebx, edx + mov edx, DWORD PTR 12[edi] + adc ecx, 0 + ; mul a[2]*b[3] + mul edx + add ebp, eax + mov eax, DWORD PTR 4[esi] + adc ebx, edx + mov edx, DWORD PTR 16[edi] + adc ecx, 0 + ; mul a[1]*b[4] + mul edx + add ebp, eax + mov eax, DWORD PTR [esi] + adc ebx, edx + mov edx, DWORD PTR 20[edi] + adc ecx, 0 + ; mul a[0]*b[5] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esp] + adc ebx, edx + mov edx, DWORD PTR [edi] + adc ecx, 0 + mov DWORD PTR 20[eax],ebp + mov eax, DWORD PTR 24[esi] + ; saved r[5] + ; ################## Calculate word 6 + xor ebp, ebp + ; mul a[6]*b[0] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esi] + adc ecx, edx + mov edx, DWORD PTR 4[edi] + adc ebp, 0 + ; mul a[5]*b[1] + mul edx + add ebx, eax + mov eax, DWORD PTR 16[esi] + adc ecx, edx + mov edx, DWORD PTR 8[edi] + adc ebp, 0 + ; mul a[4]*b[2] + mul edx + add ebx, eax + mov eax, DWORD PTR 12[esi] + adc ecx, edx + mov edx, DWORD PTR 12[edi] + adc ebp, 0 + ; mul a[3]*b[3] + mul edx + add ebx, eax + mov eax, DWORD PTR 8[esi] + adc ecx, edx + mov edx, DWORD PTR 16[edi] + adc ebp, 0 + ; mul a[2]*b[4] + mul edx + add ebx, eax + mov eax, DWORD PTR 4[esi] + adc ecx, edx + mov edx, DWORD PTR 20[edi] + adc ebp, 0 + ; mul a[1]*b[5] + mul edx + add ebx, eax + mov eax, DWORD PTR [esi] + adc ecx, edx + mov edx, DWORD PTR 24[edi] + adc ebp, 0 + ; mul a[0]*b[6] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esp] + adc ecx, edx + mov edx, DWORD PTR [edi] + adc ebp, 0 + mov DWORD PTR 24[eax],ebx + mov eax, DWORD PTR 28[esi] + ; saved r[6] + ; ################## Calculate word 7 + xor ebx, ebx + ; mul a[7]*b[0] + mul edx + add ecx, eax + mov eax, DWORD PTR 24[esi] + adc ebp, edx + mov edx, DWORD PTR 4[edi] + adc ebx, 0 + ; mul a[6]*b[1] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esi] + adc ebp, edx + mov edx, DWORD PTR 8[edi] + adc ebx, 0 + ; mul a[5]*b[2] + mul edx + add ecx, eax + mov eax, DWORD PTR 16[esi] + adc ebp, edx + mov edx, DWORD PTR 12[edi] + adc ebx, 0 + ; mul a[4]*b[3] + mul edx + add ecx, eax + mov eax, DWORD PTR 12[esi] + adc ebp, edx + mov edx, DWORD PTR 16[edi] + adc ebx, 0 + ; mul a[3]*b[4] + mul edx + add ecx, eax + mov eax, DWORD PTR 8[esi] + adc ebp, edx + mov edx, DWORD PTR 20[edi] + adc ebx, 0 + ; mul a[2]*b[5] + mul edx + add ecx, eax + mov eax, DWORD PTR 4[esi] + adc ebp, edx + mov edx, DWORD PTR 24[edi] + adc ebx, 0 + ; mul a[1]*b[6] + mul edx + add ecx, eax + mov eax, DWORD PTR [esi] + adc ebp, edx + mov edx, DWORD PTR 28[edi] + adc ebx, 0 + ; mul a[0]*b[7] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esp] + adc ebp, edx + mov edx, DWORD PTR 4[edi] + adc ebx, 0 + mov DWORD PTR 28[eax],ecx + mov eax, DWORD PTR 28[esi] + ; saved r[7] + ; ################## Calculate word 8 + xor ecx, ecx + ; mul a[7]*b[1] + mul edx + add ebp, eax + mov eax, DWORD PTR 24[esi] + adc ebx, edx + mov edx, DWORD PTR 8[edi] + adc ecx, 0 + ; mul a[6]*b[2] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esi] + adc ebx, edx + mov edx, DWORD PTR 12[edi] + adc ecx, 0 + ; mul a[5]*b[3] + mul edx + add ebp, eax + mov eax, DWORD PTR 16[esi] + adc ebx, edx + mov edx, DWORD PTR 16[edi] + adc ecx, 0 + ; mul a[4]*b[4] + mul edx + add ebp, eax + mov eax, DWORD PTR 12[esi] + adc ebx, edx + mov edx, DWORD PTR 20[edi] + adc ecx, 0 + ; mul a[3]*b[5] + mul edx + add ebp, eax + mov eax, DWORD PTR 8[esi] + adc ebx, edx + mov edx, DWORD PTR 24[edi] + adc ecx, 0 + ; mul a[2]*b[6] + mul edx + add ebp, eax + mov eax, DWORD PTR 4[esi] + adc ebx, edx + mov edx, DWORD PTR 28[edi] + adc ecx, 0 + ; mul a[1]*b[7] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esp] + adc ebx, edx + mov edx, DWORD PTR 8[edi] + adc ecx, 0 + mov DWORD PTR 32[eax],ebp + mov eax, DWORD PTR 28[esi] + ; saved r[8] + ; ################## Calculate word 9 + xor ebp, ebp + ; mul a[7]*b[2] + mul edx + add ebx, eax + mov eax, DWORD PTR 24[esi] + adc ecx, edx + mov edx, DWORD PTR 12[edi] + adc ebp, 0 + ; mul a[6]*b[3] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esi] + adc ecx, edx + mov edx, DWORD PTR 16[edi] + adc ebp, 0 + ; mul a[5]*b[4] + mul edx + add ebx, eax + mov eax, DWORD PTR 16[esi] + adc ecx, edx + mov edx, DWORD PTR 20[edi] + adc ebp, 0 + ; mul a[4]*b[5] + mul edx + add ebx, eax + mov eax, DWORD PTR 12[esi] + adc ecx, edx + mov edx, DWORD PTR 24[edi] + adc ebp, 0 + ; mul a[3]*b[6] + mul edx + add ebx, eax + mov eax, DWORD PTR 8[esi] + adc ecx, edx + mov edx, DWORD PTR 28[edi] + adc ebp, 0 + ; mul a[2]*b[7] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esp] + adc ecx, edx + mov edx, DWORD PTR 12[edi] + adc ebp, 0 + mov DWORD PTR 36[eax],ebx + mov eax, DWORD PTR 28[esi] + ; saved r[9] + ; ################## Calculate word 10 + xor ebx, ebx + ; mul a[7]*b[3] + mul edx + add ecx, eax + mov eax, DWORD PTR 24[esi] + adc ebp, edx + mov edx, DWORD PTR 16[edi] + adc ebx, 0 + ; mul a[6]*b[4] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esi] + adc ebp, edx + mov edx, DWORD PTR 20[edi] + adc ebx, 0 + ; mul a[5]*b[5] + mul edx + add ecx, eax + mov eax, DWORD PTR 16[esi] + adc ebp, edx + mov edx, DWORD PTR 24[edi] + adc ebx, 0 + ; mul a[4]*b[6] + mul edx + add ecx, eax + mov eax, DWORD PTR 12[esi] + adc ebp, edx + mov edx, DWORD PTR 28[edi] + adc ebx, 0 + ; mul a[3]*b[7] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esp] + adc ebp, edx + mov edx, DWORD PTR 16[edi] + adc ebx, 0 + mov DWORD PTR 40[eax],ecx + mov eax, DWORD PTR 28[esi] + ; saved r[10] + ; ################## Calculate word 11 + xor ecx, ecx + ; mul a[7]*b[4] + mul edx + add ebp, eax + mov eax, DWORD PTR 24[esi] + adc ebx, edx + mov edx, DWORD PTR 20[edi] + adc ecx, 0 + ; mul a[6]*b[5] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esi] + adc ebx, edx + mov edx, DWORD PTR 24[edi] + adc ecx, 0 + ; mul a[5]*b[6] + mul edx + add ebp, eax + mov eax, DWORD PTR 16[esi] + adc ebx, edx + mov edx, DWORD PTR 28[edi] + adc ecx, 0 + ; mul a[4]*b[7] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esp] + adc ebx, edx + mov edx, DWORD PTR 20[edi] + adc ecx, 0 + mov DWORD PTR 44[eax],ebp + mov eax, DWORD PTR 28[esi] + ; saved r[11] + ; ################## Calculate word 12 + xor ebp, ebp + ; mul a[7]*b[5] + mul edx + add ebx, eax + mov eax, DWORD PTR 24[esi] + adc ecx, edx + mov edx, DWORD PTR 24[edi] + adc ebp, 0 + ; mul a[6]*b[6] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esi] + adc ecx, edx + mov edx, DWORD PTR 28[edi] + adc ebp, 0 + ; mul a[5]*b[7] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esp] + adc ecx, edx + mov edx, DWORD PTR 24[edi] + adc ebp, 0 + mov DWORD PTR 48[eax],ebx + mov eax, DWORD PTR 28[esi] + ; saved r[12] + ; ################## Calculate word 13 + xor ebx, ebx + ; mul a[7]*b[6] + mul edx + add ecx, eax + mov eax, DWORD PTR 24[esi] + adc ebp, edx + mov edx, DWORD PTR 28[edi] + adc ebx, 0 + ; mul a[6]*b[7] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esp] + adc ebp, edx + mov edx, DWORD PTR 28[edi] + adc ebx, 0 + mov DWORD PTR 52[eax],ecx + mov eax, DWORD PTR 28[esi] + ; saved r[13] + ; ################## Calculate word 14 + xor ecx, ecx + ; mul a[7]*b[7] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esp] + adc ebx, edx + adc ecx, 0 + mov DWORD PTR 56[eax],ebp + ; saved r[14] + ; save r[15] + mov DWORD PTR 60[eax],ebx + pop ebx + pop ebp + pop edi + pop esi + ret +_bn_mul_comba8 ENDP +_TEXT ENDS +_TEXT SEGMENT +PUBLIC _bn_mul_comba4 + +_bn_mul_comba4 PROC NEAR + push esi + mov esi, DWORD PTR 12[esp] + push edi + mov edi, DWORD PTR 20[esp] + push ebp + push ebx + xor ebx, ebx + mov eax, DWORD PTR [esi] + xor ecx, ecx + mov edx, DWORD PTR [edi] + ; ################## Calculate word 0 + xor ebp, ebp + ; mul a[0]*b[0] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esp] + adc ecx, edx + mov edx, DWORD PTR [edi] + adc ebp, 0 + mov DWORD PTR [eax],ebx + mov eax, DWORD PTR 4[esi] + ; saved r[0] + ; ################## Calculate word 1 + xor ebx, ebx + ; mul a[1]*b[0] + mul edx + add ecx, eax + mov eax, DWORD PTR [esi] + adc ebp, edx + mov edx, DWORD PTR 4[edi] + adc ebx, 0 + ; mul a[0]*b[1] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esp] + adc ebp, edx + mov edx, DWORD PTR [edi] + adc ebx, 0 + mov DWORD PTR 4[eax],ecx + mov eax, DWORD PTR 8[esi] + ; saved r[1] + ; ################## Calculate word 2 + xor ecx, ecx + ; mul a[2]*b[0] + mul edx + add ebp, eax + mov eax, DWORD PTR 4[esi] + adc ebx, edx + mov edx, DWORD PTR 4[edi] + adc ecx, 0 + ; mul a[1]*b[1] + mul edx + add ebp, eax + mov eax, DWORD PTR [esi] + adc ebx, edx + mov edx, DWORD PTR 8[edi] + adc ecx, 0 + ; mul a[0]*b[2] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esp] + adc ebx, edx + mov edx, DWORD PTR [edi] + adc ecx, 0 + mov DWORD PTR 8[eax],ebp + mov eax, DWORD PTR 12[esi] + ; saved r[2] + ; ################## Calculate word 3 + xor ebp, ebp + ; mul a[3]*b[0] + mul edx + add ebx, eax + mov eax, DWORD PTR 8[esi] + adc ecx, edx + mov edx, DWORD PTR 4[edi] + adc ebp, 0 + ; mul a[2]*b[1] + mul edx + add ebx, eax + mov eax, DWORD PTR 4[esi] + adc ecx, edx + mov edx, DWORD PTR 8[edi] + adc ebp, 0 + ; mul a[1]*b[2] + mul edx + add ebx, eax + mov eax, DWORD PTR [esi] + adc ecx, edx + mov edx, DWORD PTR 12[edi] + adc ebp, 0 + ; mul a[0]*b[3] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esp] + adc ecx, edx + mov edx, DWORD PTR 4[edi] + adc ebp, 0 + mov DWORD PTR 12[eax],ebx + mov eax, DWORD PTR 12[esi] + ; saved r[3] + ; ################## Calculate word 4 + xor ebx, ebx + ; mul a[3]*b[1] + mul edx + add ecx, eax + mov eax, DWORD PTR 8[esi] + adc ebp, edx + mov edx, DWORD PTR 8[edi] + adc ebx, 0 + ; mul a[2]*b[2] + mul edx + add ecx, eax + mov eax, DWORD PTR 4[esi] + adc ebp, edx + mov edx, DWORD PTR 12[edi] + adc ebx, 0 + ; mul a[1]*b[3] + mul edx + add ecx, eax + mov eax, DWORD PTR 20[esp] + adc ebp, edx + mov edx, DWORD PTR 8[edi] + adc ebx, 0 + mov DWORD PTR 16[eax],ecx + mov eax, DWORD PTR 12[esi] + ; saved r[4] + ; ################## Calculate word 5 + xor ecx, ecx + ; mul a[3]*b[2] + mul edx + add ebp, eax + mov eax, DWORD PTR 8[esi] + adc ebx, edx + mov edx, DWORD PTR 12[edi] + adc ecx, 0 + ; mul a[2]*b[3] + mul edx + add ebp, eax + mov eax, DWORD PTR 20[esp] + adc ebx, edx + mov edx, DWORD PTR 12[edi] + adc ecx, 0 + mov DWORD PTR 20[eax],ebp + mov eax, DWORD PTR 12[esi] + ; saved r[5] + ; ################## Calculate word 6 + xor ebp, ebp + ; mul a[3]*b[3] + mul edx + add ebx, eax + mov eax, DWORD PTR 20[esp] + adc ecx, edx + adc ebp, 0 + mov DWORD PTR 24[eax],ebx + ; saved r[6] + ; save r[7] + mov DWORD PTR 28[eax],ecx + pop ebx + pop ebp + pop edi + pop esi + ret +_bn_mul_comba4 ENDP +_TEXT ENDS +_TEXT SEGMENT +PUBLIC _bn_sqr_comba8 + +_bn_sqr_comba8 PROC NEAR + push esi + push edi + push ebp + push ebx + mov edi, DWORD PTR 20[esp] + mov esi, DWORD PTR 24[esp] + xor ebx, ebx + xor ecx, ecx + mov eax, DWORD PTR [esi] + ; ############### Calculate word 0 + xor ebp, ebp + ; sqr a[0]*a[0] + mul eax + add ebx, eax + adc ecx, edx + mov edx, DWORD PTR [esi] + adc ebp, 0 + mov DWORD PTR [edi],ebx + mov eax, DWORD PTR 4[esi] + ; saved r[0] + ; ############### Calculate word 1 + xor ebx, ebx + ; sqr a[1]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 8[esi] + adc ebx, 0 + mov DWORD PTR 4[edi],ecx + mov edx, DWORD PTR [esi] + ; saved r[1] + ; ############### Calculate word 2 + xor ecx, ecx + ; sqr a[2]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 4[esi] + adc ecx, 0 + ; sqr a[1]*a[1] + mul eax + add ebp, eax + adc ebx, edx + mov edx, DWORD PTR [esi] + adc ecx, 0 + mov DWORD PTR 8[edi],ebp + mov eax, DWORD PTR 12[esi] + ; saved r[2] + ; ############### Calculate word 3 + xor ebp, ebp + ; sqr a[3]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 8[esi] + adc ebp, 0 + mov edx, DWORD PTR 4[esi] + ; sqr a[2]*a[1] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 16[esi] + adc ebp, 0 + mov DWORD PTR 12[edi],ebx + mov edx, DWORD PTR [esi] + ; saved r[3] + ; ############### Calculate word 4 + xor ebx, ebx + ; sqr a[4]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 12[esi] + adc ebx, 0 + mov edx, DWORD PTR 4[esi] + ; sqr a[3]*a[1] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 8[esi] + adc ebx, 0 + ; sqr a[2]*a[2] + mul eax + add ecx, eax + adc ebp, edx + mov edx, DWORD PTR [esi] + adc ebx, 0 + mov DWORD PTR 16[edi],ecx + mov eax, DWORD PTR 20[esi] + ; saved r[4] + ; ############### Calculate word 5 + xor ecx, ecx + ; sqr a[5]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 16[esi] + adc ecx, 0 + mov edx, DWORD PTR 4[esi] + ; sqr a[4]*a[1] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 12[esi] + adc ecx, 0 + mov edx, DWORD PTR 8[esi] + ; sqr a[3]*a[2] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 24[esi] + adc ecx, 0 + mov DWORD PTR 20[edi],ebp + mov edx, DWORD PTR [esi] + ; saved r[5] + ; ############### Calculate word 6 + xor ebp, ebp + ; sqr a[6]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 20[esi] + adc ebp, 0 + mov edx, DWORD PTR 4[esi] + ; sqr a[5]*a[1] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 16[esi] + adc ebp, 0 + mov edx, DWORD PTR 8[esi] + ; sqr a[4]*a[2] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 12[esi] + adc ebp, 0 + ; sqr a[3]*a[3] + mul eax + add ebx, eax + adc ecx, edx + mov edx, DWORD PTR [esi] + adc ebp, 0 + mov DWORD PTR 24[edi],ebx + mov eax, DWORD PTR 28[esi] + ; saved r[6] + ; ############### Calculate word 7 + xor ebx, ebx + ; sqr a[7]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 24[esi] + adc ebx, 0 + mov edx, DWORD PTR 4[esi] + ; sqr a[6]*a[1] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 20[esi] + adc ebx, 0 + mov edx, DWORD PTR 8[esi] + ; sqr a[5]*a[2] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 16[esi] + adc ebx, 0 + mov edx, DWORD PTR 12[esi] + ; sqr a[4]*a[3] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 28[esi] + adc ebx, 0 + mov DWORD PTR 28[edi],ecx + mov edx, DWORD PTR 4[esi] + ; saved r[7] + ; ############### Calculate word 8 + xor ecx, ecx + ; sqr a[7]*a[1] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 24[esi] + adc ecx, 0 + mov edx, DWORD PTR 8[esi] + ; sqr a[6]*a[2] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 20[esi] + adc ecx, 0 + mov edx, DWORD PTR 12[esi] + ; sqr a[5]*a[3] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 16[esi] + adc ecx, 0 + ; sqr a[4]*a[4] + mul eax + add ebp, eax + adc ebx, edx + mov edx, DWORD PTR 8[esi] + adc ecx, 0 + mov DWORD PTR 32[edi],ebp + mov eax, DWORD PTR 28[esi] + ; saved r[8] + ; ############### Calculate word 9 + xor ebp, ebp + ; sqr a[7]*a[2] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 24[esi] + adc ebp, 0 + mov edx, DWORD PTR 12[esi] + ; sqr a[6]*a[3] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 20[esi] + adc ebp, 0 + mov edx, DWORD PTR 16[esi] + ; sqr a[5]*a[4] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 28[esi] + adc ebp, 0 + mov DWORD PTR 36[edi],ebx + mov edx, DWORD PTR 12[esi] + ; saved r[9] + ; ############### Calculate word 10 + xor ebx, ebx + ; sqr a[7]*a[3] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 24[esi] + adc ebx, 0 + mov edx, DWORD PTR 16[esi] + ; sqr a[6]*a[4] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 20[esi] + adc ebx, 0 + ; sqr a[5]*a[5] + mul eax + add ecx, eax + adc ebp, edx + mov edx, DWORD PTR 16[esi] + adc ebx, 0 + mov DWORD PTR 40[edi],ecx + mov eax, DWORD PTR 28[esi] + ; saved r[10] + ; ############### Calculate word 11 + xor ecx, ecx + ; sqr a[7]*a[4] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 24[esi] + adc ecx, 0 + mov edx, DWORD PTR 20[esi] + ; sqr a[6]*a[5] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 28[esi] + adc ecx, 0 + mov DWORD PTR 44[edi],ebp + mov edx, DWORD PTR 20[esi] + ; saved r[11] + ; ############### Calculate word 12 + xor ebp, ebp + ; sqr a[7]*a[5] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 24[esi] + adc ebp, 0 + ; sqr a[6]*a[6] + mul eax + add ebx, eax + adc ecx, edx + mov edx, DWORD PTR 24[esi] + adc ebp, 0 + mov DWORD PTR 48[edi],ebx + mov eax, DWORD PTR 28[esi] + ; saved r[12] + ; ############### Calculate word 13 + xor ebx, ebx + ; sqr a[7]*a[6] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 28[esi] + adc ebx, 0 + mov DWORD PTR 52[edi],ecx + ; saved r[13] + ; ############### Calculate word 14 + xor ecx, ecx + ; sqr a[7]*a[7] + mul eax + add ebp, eax + adc ebx, edx + adc ecx, 0 + mov DWORD PTR 56[edi],ebp + ; saved r[14] + mov DWORD PTR 60[edi],ebx + pop ebx + pop ebp + pop edi + pop esi + ret +_bn_sqr_comba8 ENDP +_TEXT ENDS +_TEXT SEGMENT +PUBLIC _bn_sqr_comba4 + +_bn_sqr_comba4 PROC NEAR + push esi + push edi + push ebp + push ebx + mov edi, DWORD PTR 20[esp] + mov esi, DWORD PTR 24[esp] + xor ebx, ebx + xor ecx, ecx + mov eax, DWORD PTR [esi] + ; ############### Calculate word 0 + xor ebp, ebp + ; sqr a[0]*a[0] + mul eax + add ebx, eax + adc ecx, edx + mov edx, DWORD PTR [esi] + adc ebp, 0 + mov DWORD PTR [edi],ebx + mov eax, DWORD PTR 4[esi] + ; saved r[0] + ; ############### Calculate word 1 + xor ebx, ebx + ; sqr a[1]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 8[esi] + adc ebx, 0 + mov DWORD PTR 4[edi],ecx + mov edx, DWORD PTR [esi] + ; saved r[1] + ; ############### Calculate word 2 + xor ecx, ecx + ; sqr a[2]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 4[esi] + adc ecx, 0 + ; sqr a[1]*a[1] + mul eax + add ebp, eax + adc ebx, edx + mov edx, DWORD PTR [esi] + adc ecx, 0 + mov DWORD PTR 8[edi],ebp + mov eax, DWORD PTR 12[esi] + ; saved r[2] + ; ############### Calculate word 3 + xor ebp, ebp + ; sqr a[3]*a[0] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 8[esi] + adc ebp, 0 + mov edx, DWORD PTR 4[esi] + ; sqr a[2]*a[1] + mul edx + add eax, eax + adc edx, edx + adc ebp, 0 + add ebx, eax + adc ecx, edx + mov eax, DWORD PTR 12[esi] + adc ebp, 0 + mov DWORD PTR 12[edi],ebx + mov edx, DWORD PTR 4[esi] + ; saved r[3] + ; ############### Calculate word 4 + xor ebx, ebx + ; sqr a[3]*a[1] + mul edx + add eax, eax + adc edx, edx + adc ebx, 0 + add ecx, eax + adc ebp, edx + mov eax, DWORD PTR 8[esi] + adc ebx, 0 + ; sqr a[2]*a[2] + mul eax + add ecx, eax + adc ebp, edx + mov edx, DWORD PTR 8[esi] + adc ebx, 0 + mov DWORD PTR 16[edi],ecx + mov eax, DWORD PTR 12[esi] + ; saved r[4] + ; ############### Calculate word 5 + xor ecx, ecx + ; sqr a[3]*a[2] + mul edx + add eax, eax + adc edx, edx + adc ecx, 0 + add ebp, eax + adc ebx, edx + mov eax, DWORD PTR 12[esi] + adc ecx, 0 + mov DWORD PTR 20[edi],ebp + ; saved r[5] + ; ############### Calculate word 6 + xor ebp, ebp + ; sqr a[3]*a[3] + mul eax + add ebx, eax + adc ecx, edx + adc ebp, 0 + mov DWORD PTR 24[edi],ebx + ; saved r[6] + mov DWORD PTR 28[edi],ecx + pop ebx + pop ebp + pop edi + pop esi + ret +_bn_sqr_comba4 ENDP +_TEXT ENDS END diff --git a/src/lib/libcrypto/bn/asm/bn86unix.cpp b/src/lib/libcrypto/bn/asm/bn86unix.cpp deleted file mode 100644 index 64702201ea..0000000000 --- a/src/lib/libcrypto/bn/asm/bn86unix.cpp +++ /dev/null @@ -1,752 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define bn_mul_add_words _bn_mul_add_words -#define bn_mul_words _bn_mul_words -#define bn_sqr_words _bn_sqr_words -#define bn_div64 _bn_div64 -#define bn_add_words _bn_add_words - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by bn-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "bn-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl bn_mul_add_words - TYPE(bn_mul_add_words,@function) -bn_mul_add_words: - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - - - xorl %esi, %esi - movl 20(%esp), %edi - movl 28(%esp), %ecx - movl 24(%esp), %ebx - andl $4294967288, %ecx - movl 32(%esp), %ebp - pushl %ecx - jz .L000maw_finish -.L001maw_loop: - movl %ecx, (%esp) - /* Round 0 */ - movl (%ebx), %eax - mull %ebp - addl %esi, %eax - movl (%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, (%edi) - movl %edx, %esi - /* Round 4 */ - movl 4(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 4(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, 4(%edi) - movl %edx, %esi - /* Round 8 */ - movl 8(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 8(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, 8(%edi) - movl %edx, %esi - /* Round 12 */ - movl 12(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 12(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, 12(%edi) - movl %edx, %esi - /* Round 16 */ - movl 16(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 16(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, 16(%edi) - movl %edx, %esi - /* Round 20 */ - movl 20(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 20(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, 20(%edi) - movl %edx, %esi - /* Round 24 */ - movl 24(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 24(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, 24(%edi) - movl %edx, %esi - /* Round 28 */ - movl 28(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 28(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, 28(%edi) - movl %edx, %esi - - movl (%esp), %ecx - addl $32, %ebx - addl $32, %edi - subl $8, %ecx - jnz .L001maw_loop -.L000maw_finish: - movl 32(%esp), %ecx - andl $7, %ecx - jnz .L002maw_finish2 - jmp .L003maw_end -.align ALIGN -.L002maw_finish2: - /* Tail Round 0 */ - movl (%ebx), %eax - mull %ebp - addl %esi, %eax - movl (%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - decl %ecx - movl %eax, (%edi) - movl %edx, %esi - jz .L003maw_end - /* Tail Round 1 */ - movl 4(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 4(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - decl %ecx - movl %eax, 4(%edi) - movl %edx, %esi - jz .L003maw_end - /* Tail Round 2 */ - movl 8(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 8(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - decl %ecx - movl %eax, 8(%edi) - movl %edx, %esi - jz .L003maw_end - /* Tail Round 3 */ - movl 12(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 12(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - decl %ecx - movl %eax, 12(%edi) - movl %edx, %esi - jz .L003maw_end - /* Tail Round 4 */ - movl 16(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 16(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - decl %ecx - movl %eax, 16(%edi) - movl %edx, %esi - jz .L003maw_end - /* Tail Round 5 */ - movl 20(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 20(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - decl %ecx - movl %eax, 20(%edi) - movl %edx, %esi - jz .L003maw_end - /* Tail Round 6 */ - movl 24(%ebx), %eax - mull %ebp - addl %esi, %eax - movl 24(%edi), %esi - adcl $0, %edx - addl %esi, %eax - adcl $0, %edx - movl %eax, 24(%edi) - movl %edx, %esi -.L003maw_end: - movl %esi, %eax - popl %ecx - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.bn_mul_add_words_end: - SIZE(bn_mul_add_words,.bn_mul_add_words_end-bn_mul_add_words) -.ident "bn_mul_add_words" -.text - .align ALIGN -.globl bn_mul_words - TYPE(bn_mul_words,@function) -bn_mul_words: - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - - - xorl %esi, %esi - movl 20(%esp), %edi - movl 24(%esp), %ebx - movl 28(%esp), %ebp - movl 32(%esp), %ecx - andl $4294967288, %ebp - jz .L004mw_finish -.L005mw_loop: - /* Round 0 */ - movl (%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, (%edi) - movl %edx, %esi - /* Round 4 */ - movl 4(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 4(%edi) - movl %edx, %esi - /* Round 8 */ - movl 8(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 8(%edi) - movl %edx, %esi - /* Round 12 */ - movl 12(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 12(%edi) - movl %edx, %esi - /* Round 16 */ - movl 16(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 16(%edi) - movl %edx, %esi - /* Round 20 */ - movl 20(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 20(%edi) - movl %edx, %esi - /* Round 24 */ - movl 24(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 24(%edi) - movl %edx, %esi - /* Round 28 */ - movl 28(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 28(%edi) - movl %edx, %esi - - addl $32, %ebx - addl $32, %edi - subl $8, %ebp - jz .L004mw_finish - jmp .L005mw_loop -.L004mw_finish: - movl 28(%esp), %ebp - andl $7, %ebp - jnz .L006mw_finish2 - jmp .L007mw_end -.align ALIGN -.L006mw_finish2: - /* Tail Round 0 */ - movl (%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, (%edi) - movl %edx, %esi - decl %ebp - jz .L007mw_end - /* Tail Round 1 */ - movl 4(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 4(%edi) - movl %edx, %esi - decl %ebp - jz .L007mw_end - /* Tail Round 2 */ - movl 8(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 8(%edi) - movl %edx, %esi - decl %ebp - jz .L007mw_end - /* Tail Round 3 */ - movl 12(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 12(%edi) - movl %edx, %esi - decl %ebp - jz .L007mw_end - /* Tail Round 4 */ - movl 16(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 16(%edi) - movl %edx, %esi - decl %ebp - jz .L007mw_end - /* Tail Round 5 */ - movl 20(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 20(%edi) - movl %edx, %esi - decl %ebp - jz .L007mw_end - /* Tail Round 6 */ - movl 24(%ebx), %eax - mull %ecx - addl %esi, %eax - adcl $0, %edx - movl %eax, 24(%edi) - movl %edx, %esi -.L007mw_end: - movl %esi, %eax - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.bn_mul_words_end: - SIZE(bn_mul_words,.bn_mul_words_end-bn_mul_words) -.ident "bn_mul_words" -.text - .align ALIGN -.globl bn_sqr_words - TYPE(bn_sqr_words,@function) -bn_sqr_words: - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - - - movl 20(%esp), %esi - movl 24(%esp), %edi - movl 28(%esp), %ebx - andl $4294967288, %ebx - jz .L008sw_finish -.L009sw_loop: - /* Round 0 */ - movl (%edi), %eax - mull %eax - movl %eax, (%esi) - movl %edx, 4(%esi) - /* Round 4 */ - movl 4(%edi), %eax - mull %eax - movl %eax, 8(%esi) - movl %edx, 12(%esi) - /* Round 8 */ - movl 8(%edi), %eax - mull %eax - movl %eax, 16(%esi) - movl %edx, 20(%esi) - /* Round 12 */ - movl 12(%edi), %eax - mull %eax - movl %eax, 24(%esi) - movl %edx, 28(%esi) - /* Round 16 */ - movl 16(%edi), %eax - mull %eax - movl %eax, 32(%esi) - movl %edx, 36(%esi) - /* Round 20 */ - movl 20(%edi), %eax - mull %eax - movl %eax, 40(%esi) - movl %edx, 44(%esi) - /* Round 24 */ - movl 24(%edi), %eax - mull %eax - movl %eax, 48(%esi) - movl %edx, 52(%esi) - /* Round 28 */ - movl 28(%edi), %eax - mull %eax - movl %eax, 56(%esi) - movl %edx, 60(%esi) - - addl $32, %edi - addl $64, %esi - subl $8, %ebx - jnz .L009sw_loop -.L008sw_finish: - movl 28(%esp), %ebx - andl $7, %ebx - jz .L010sw_end - /* Tail Round 0 */ - movl (%edi), %eax - mull %eax - movl %eax, (%esi) - decl %ebx - movl %edx, 4(%esi) - jz .L010sw_end - /* Tail Round 1 */ - movl 4(%edi), %eax - mull %eax - movl %eax, 8(%esi) - decl %ebx - movl %edx, 12(%esi) - jz .L010sw_end - /* Tail Round 2 */ - movl 8(%edi), %eax - mull %eax - movl %eax, 16(%esi) - decl %ebx - movl %edx, 20(%esi) - jz .L010sw_end - /* Tail Round 3 */ - movl 12(%edi), %eax - mull %eax - movl %eax, 24(%esi) - decl %ebx - movl %edx, 28(%esi) - jz .L010sw_end - /* Tail Round 4 */ - movl 16(%edi), %eax - mull %eax - movl %eax, 32(%esi) - decl %ebx - movl %edx, 36(%esi) - jz .L010sw_end - /* Tail Round 5 */ - movl 20(%edi), %eax - mull %eax - movl %eax, 40(%esi) - decl %ebx - movl %edx, 44(%esi) - jz .L010sw_end - /* Tail Round 6 */ - movl 24(%edi), %eax - mull %eax - movl %eax, 48(%esi) - movl %edx, 52(%esi) -.L010sw_end: - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.bn_sqr_words_end: - SIZE(bn_sqr_words,.bn_sqr_words_end-bn_sqr_words) -.ident "bn_sqr_words" -.text - .align ALIGN -.globl bn_div64 - TYPE(bn_div64,@function) -bn_div64: - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - - movl 20(%esp), %edx - movl 24(%esp), %eax - movl 28(%esp), %ebx - divl %ebx - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.bn_div64_end: - SIZE(bn_div64,.bn_div64_end-bn_div64) -.ident "bn_div64" -.text - .align ALIGN -.globl bn_add_words - TYPE(bn_add_words,@function) -bn_add_words: - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - - - movl 20(%esp), %ebx - movl 24(%esp), %esi - movl 28(%esp), %edi - movl 32(%esp), %ebp - xorl %eax, %eax - andl $4294967288, %ebp - jz .L011aw_finish -.L012aw_loop: - /* Round 0 */ - movl (%esi), %ecx - movl (%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, (%ebx) - /* Round 1 */ - movl 4(%esi), %ecx - movl 4(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, 4(%ebx) - /* Round 2 */ - movl 8(%esi), %ecx - movl 8(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, 8(%ebx) - /* Round 3 */ - movl 12(%esi), %ecx - movl 12(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, 12(%ebx) - /* Round 4 */ - movl 16(%esi), %ecx - movl 16(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, 16(%ebx) - /* Round 5 */ - movl 20(%esi), %ecx - movl 20(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, 20(%ebx) - /* Round 6 */ - movl 24(%esi), %ecx - movl 24(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, 24(%ebx) - /* Round 7 */ - movl 28(%esi), %ecx - movl 28(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, 28(%ebx) - - addl $32, %esi - addl $32, %edi - addl $32, %ebx - subl $8, %ebp - jnz .L012aw_loop -.L011aw_finish: - movl 32(%esp), %ebp - andl $7, %ebp - jz .L013aw_end - /* Tail Round 0 */ - movl (%esi), %ecx - movl (%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - decl %ebp - movl %ecx, (%ebx) - jz .L013aw_end - /* Tail Round 1 */ - movl 4(%esi), %ecx - movl 4(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - decl %ebp - movl %ecx, 4(%ebx) - jz .L013aw_end - /* Tail Round 2 */ - movl 8(%esi), %ecx - movl 8(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - decl %ebp - movl %ecx, 8(%ebx) - jz .L013aw_end - /* Tail Round 3 */ - movl 12(%esi), %ecx - movl 12(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - decl %ebp - movl %ecx, 12(%ebx) - jz .L013aw_end - /* Tail Round 4 */ - movl 16(%esi), %ecx - movl 16(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - decl %ebp - movl %ecx, 16(%ebx) - jz .L013aw_end - /* Tail Round 5 */ - movl 20(%esi), %ecx - movl 20(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - decl %ebp - movl %ecx, 20(%ebx) - jz .L013aw_end - /* Tail Round 6 */ - movl 24(%esi), %ecx - movl 24(%edi), %edx - addl %eax, %ecx - movl $0, %eax - adcl %eax, %eax - addl %edx, %ecx - adcl $0, %eax - movl %ecx, 24(%ebx) -.L013aw_end: - movl %eax, %eax - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.bn_add_words_end: - SIZE(bn_add_words,.bn_add_words_end-bn_add_words) -.ident "bn_add_words" diff --git a/src/lib/libcrypto/bn/asm/ca.pl b/src/lib/libcrypto/bn/asm/ca.pl new file mode 100644 index 0000000000..c1ce67a6b4 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/ca.pl @@ -0,0 +1,33 @@ +#!/usr/local/bin/perl +# I have this in perl so I can use more usefull register names and then convert +# them into alpha registers. +# + +push(@INC,"perlasm","../../perlasm"); +require "alpha.pl"; +require "alpha/mul_add.pl"; +require "alpha/mul.pl"; +require "alpha/sqr.pl"; +require "alpha/add.pl"; +require "alpha/sub.pl"; +require "alpha/mul_c8.pl"; +require "alpha/mul_c4.pl"; +require "alpha/sqr_c4.pl"; +require "alpha/sqr_c8.pl"; +require "alpha/div.pl"; + +&asm_init($ARGV[0],$0); + +&bn_mul_words("bn_mul_words"); +&bn_sqr_words("bn_sqr_words"); +&bn_mul_add_words("bn_mul_add_words"); +&bn_add_words("bn_add_words"); +&bn_sub_words("bn_sub_words"); +&bn_div_words("bn_div_words"); +&bn_mul_comba8("bn_mul_comba8"); +&bn_mul_comba4("bn_mul_comba4"); +&bn_sqr_comba4("bn_sqr_comba4"); +&bn_sqr_comba8("bn_sqr_comba8"); + +&asm_finish(); + diff --git a/src/lib/libcrypto/bn/asm/co-586.pl b/src/lib/libcrypto/bn/asm/co-586.pl new file mode 100644 index 0000000000..5d962cb957 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/co-586.pl @@ -0,0 +1,286 @@ +#!/usr/local/bin/perl + +push(@INC,"perlasm","../../perlasm"); +require "x86asm.pl"; + +&asm_init($ARGV[0],$0); + +&bn_mul_comba("bn_mul_comba8",8); +&bn_mul_comba("bn_mul_comba4",4); +&bn_sqr_comba("bn_sqr_comba8",8); +&bn_sqr_comba("bn_sqr_comba4",4); + +&asm_finish(); + +sub mul_add_c + { + local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; + + # pos == -1 if eax and edx are pre-loaded, 0 to load from next + # words, and 1 if load return value + + &comment("mul a[$ai]*b[$bi]"); + + # "eax" and "edx" will always be pre-loaded. + # &mov("eax",&DWP($ai*4,$a,"",0)) ; + # &mov("edx",&DWP($bi*4,$b,"",0)); + + &mul("edx"); + &add($c0,"eax"); + &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a + &mov("eax",&wparam(0)) if $pos > 0; # load r[] + ### + &adc($c1,"edx"); + &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b + &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b + ### + &adc($c2,0); + # is pos > 1, it means it is the last loop + &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[]; + &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a + } + +sub sqr_add_c + { + local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; + + # pos == -1 if eax and edx are pre-loaded, 0 to load from next + # words, and 1 if load return value + + &comment("sqr a[$ai]*a[$bi]"); + + # "eax" and "edx" will always be pre-loaded. + # &mov("eax",&DWP($ai*4,$a,"",0)) ; + # &mov("edx",&DWP($bi*4,$b,"",0)); + + if ($ai == $bi) + { &mul("eax");} + else + { &mul("edx");} + &add($c0,"eax"); + &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a + ### + &adc($c1,"edx"); + &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb); + ### + &adc($c2,0); + # is pos > 1, it means it is the last loop + &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[]; + &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b + } + +sub sqr_add_c2 + { + local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_; + + # pos == -1 if eax and edx are pre-loaded, 0 to load from next + # words, and 1 if load return value + + &comment("sqr a[$ai]*a[$bi]"); + + # "eax" and "edx" will always be pre-loaded. + # &mov("eax",&DWP($ai*4,$a,"",0)) ; + # &mov("edx",&DWP($bi*4,$a,"",0)); + + if ($ai == $bi) + { &mul("eax");} + else + { &mul("edx");} + &add("eax","eax"); + ### + &adc("edx","edx"); + ### + &adc($c2,0); + &add($c0,"eax"); + &adc($c1,"edx"); + &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a + &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b + &adc($c2,0); + &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[]; + &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb); + ### + } + +sub bn_mul_comba + { + local($name,$num)=@_; + local($a,$b,$c0,$c1,$c2); + local($i,$as,$ae,$bs,$be,$ai,$bi); + local($tot,$end); + + &function_begin_B($name,""); + + $c0="ebx"; + $c1="ecx"; + $c2="ebp"; + $a="esi"; + $b="edi"; + + $as=0; + $ae=0; + $bs=0; + $be=0; + $tot=$num+$num-1; + + &push("esi"); + &mov($a,&wparam(1)); + &push("edi"); + &mov($b,&wparam(2)); + &push("ebp"); + &push("ebx"); + + &xor($c0,$c0); + &mov("eax",&DWP(0,$a,"",0)); # load the first word + &xor($c1,$c1); + &mov("edx",&DWP(0,$b,"",0)); # load the first second + + for ($i=0; $i<$tot; $i++) + { + $ai=$as; + $bi=$bs; + $end=$be+1; + + &comment("################## Calculate word $i"); + + for ($j=$bs; $j<$end; $j++) + { + &xor($c2,$c2) if ($j == $bs); + if (($j+1) == $end) + { + $v=1; + $v=2 if (($i+1) == $tot); + } + else + { $v=0; } + if (($j+1) != $end) + { + $na=($ai-1); + $nb=($bi+1); + } + else + { + $na=$as+($i < ($num-1)); + $nb=$bs+($i >= ($num-1)); + } +#printf STDERR "[$ai,$bi] -> [$na,$nb]\n"; + &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb); + if ($v) + { + &comment("saved r[$i]"); + # &mov("eax",&wparam(0)); + # &mov(&DWP($i*4,"eax","",0),$c0); + ($c0,$c1,$c2)=($c1,$c2,$c0); + } + $ai--; + $bi++; + } + $as++ if ($i < ($num-1)); + $ae++ if ($i >= ($num-1)); + + $bs++ if ($i >= ($num-1)); + $be++ if ($i < ($num-1)); + } + &comment("save r[$i]"); + # &mov("eax",&wparam(0)); + &mov(&DWP($i*4,"eax","",0),$c0); + + &pop("ebx"); + &pop("ebp"); + &pop("edi"); + &pop("esi"); + &ret(); + &function_end_B($name); + } + +sub bn_sqr_comba + { + local($name,$num)=@_; + local($r,$a,$c0,$c1,$c2)=@_; + local($i,$as,$ae,$bs,$be,$ai,$bi); + local($b,$tot,$end,$half); + + &function_begin_B($name,""); + + $c0="ebx"; + $c1="ecx"; + $c2="ebp"; + $a="esi"; + $r="edi"; + + &push("esi"); + &push("edi"); + &push("ebp"); + &push("ebx"); + &mov($r,&wparam(0)); + &mov($a,&wparam(1)); + &xor($c0,$c0); + &xor($c1,$c1); + &mov("eax",&DWP(0,$a,"",0)); # load the first word + + $as=0; + $ae=0; + $bs=0; + $be=0; + $tot=$num+$num-1; + + for ($i=0; $i<$tot; $i++) + { + $ai=$as; + $bi=$bs; + $end=$be+1; + + &comment("############### Calculate word $i"); + for ($j=$bs; $j<$end; $j++) + { + &xor($c2,$c2) if ($j == $bs); + if (($ai-1) < ($bi+1)) + { + $v=1; + $v=2 if ($i+1) == $tot; + } + else + { $v=0; } + if (!$v) + { + $na=$ai-1; + $nb=$bi+1; + } + else + { + $na=$as+($i < ($num-1)); + $nb=$bs+($i >= ($num-1)); + } + if ($ai == $bi) + { + &sqr_add_c($r,$a,$ai,$bi, + $c0,$c1,$c2,$v,$i,$na,$nb); + } + else + { + &sqr_add_c2($r,$a,$ai,$bi, + $c0,$c1,$c2,$v,$i,$na,$nb); + } + if ($v) + { + &comment("saved r[$i]"); + #&mov(&DWP($i*4,$r,"",0),$c0); + ($c0,$c1,$c2)=($c1,$c2,$c0); + last; + } + $ai--; + $bi++; + } + $as++ if ($i < ($num-1)); + $ae++ if ($i >= ($num-1)); + + $bs++ if ($i >= ($num-1)); + $be++ if ($i < ($num-1)); + } + &mov(&DWP($i*4,$r,"",0),$c0); + &pop("ebx"); + &pop("ebp"); + &pop("edi"); + &pop("esi"); + &ret(); + &function_end_B($name); + } diff --git a/src/lib/libcrypto/bn/asm/co-alpha.pl b/src/lib/libcrypto/bn/asm/co-alpha.pl new file mode 100644 index 0000000000..67dad3e3d5 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/co-alpha.pl @@ -0,0 +1,116 @@ +#!/usr/local/bin/perl +# I have this in perl so I can use more usefull register names and then convert +# them into alpha registers. +# + +push(@INC,"perlasm","../../perlasm"); +require "alpha.pl"; + +&asm_init($ARGV[0],$0); + +print &bn_sub_words("bn_sub_words"); + +&asm_finish(); + +sub bn_sub_words + { + local($name)=@_; + local($cc,$a,$b,$r); + + $cc="r0"; + $a0="r1"; $b0="r5"; $r0="r9"; $tmp="r13"; + $a1="r2"; $b1="r6"; $r1="r10"; $t1="r14"; + $a2="r3"; $b2="r7"; $r2="r11"; + $a3="r4"; $b3="r8"; $r3="r12"; $t3="r15"; + + $rp=&wparam(0); + $ap=&wparam(1); + $bp=&wparam(2); + $count=&wparam(3); + + &function_begin($name,""); + + &comment(""); + &sub($count,4,$count); + &mov("zero",$cc); + &blt($count,&label("finish")); + + &ld($a0,&QWPw(0,$ap)); + &ld($b0,&QWPw(0,$bp)); + +########################################################## + &set_label("loop"); + + &ld($a1,&QWPw(1,$ap)); + &cmpult($a0,$b0,$tmp); # will we borrow? + &ld($b1,&QWPw(1,$bp)); + &sub($a0,$b0,$a0); # do the subtract + &ld($a2,&QWPw(2,$ap)); + &cmpult($a0,$cc,$b0); # will we borrow? + &ld($b2,&QWPw(2,$bp)); + &sub($a0,$cc,$a0); # will we borrow? + &ld($a3,&QWPw(3,$ap)); + &add($b0,$tmp,$cc); # add the borrows + + &cmpult($a1,$b1,$t1); # will we borrow? + &sub($a1,$b1,$a1); # do the subtract + &ld($b3,&QWPw(3,$bp)); + &cmpult($a1,$cc,$b1); # will we borrow? + &sub($a1,$cc,$a1); # will we borrow? + &add($b1,$t1,$cc); # add the borrows + + &cmpult($a2,$b2,$tmp); # will we borrow? + &sub($a2,$b2,$a2); # do the subtract + &st($a0,&QWPw(0,$rp)); # save + &cmpult($a2,$cc,$b2); # will we borrow? + &sub($a2,$cc,$a2); # will we borrow? + &add($b2,$tmp,$cc); # add the borrows + + &cmpult($a3,$b3,$t3); # will we borrow? + &sub($a3,$b3,$a3); # do the subtract + &st($a1,&QWPw(1,$rp)); # save + &cmpult($a3,$cc,$b3); # will we borrow? + &sub($a3,$cc,$a3); # will we borrow? + &add($b3,$t3,$cc); # add the borrows + + &st($a2,&QWPw(2,$rp)); # save + &sub($count,4,$count); # count-=4 + &st($a3,&QWPw(3,$rp)); # save + &add($ap,4*$QWS,$ap); # count+=4 + &add($bp,4*$QWS,$bp); # count+=4 + &add($rp,4*$QWS,$rp); # count+=4 + + &blt($count,&label("finish")); + &ld($a0,&QWPw(0,$ap)); + &ld($b0,&QWPw(0,$bp)); + &br(&label("loop")); +################################################## + # Do the last 0..3 words + + &set_label("last_loop"); + + &ld($a0,&QWPw(0,$ap)); # get a + &ld($b0,&QWPw(0,$bp)); # get b + &cmpult($a0,$b0,$tmp); # will we borrow? + &sub($a0,$b0,$a0); # do the subtract + &cmpult($a0,$cc,$b0); # will we borrow? + &sub($a0,$cc,$a0); # will we borrow? + &st($a0,&QWPw(0,$rp)); # save + &add($b0,$tmp,$cc); # add the borrows + + &add($ap,$QWS,$ap); + &add($bp,$QWS,$bp); + &add($rp,$QWS,$rp); + &sub($count,1,$count); + &bgt($count,&label("last_loop")); + &function_end_A($name); + +###################################################### + &set_label("finish"); + &add($count,4,$count); + &bgt($count,&label("last_loop")); + + &set_label("end"); + &function_end($name); + } + diff --git a/src/lib/libcrypto/bn/asm/mips1.s b/src/lib/libcrypto/bn/asm/mips1.s new file mode 100644 index 0000000000..44fa1254c7 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/mips1.s @@ -0,0 +1,539 @@ +/* This assember is for R2000/R3000 machines, or higher ones that do + * no want to do any 64 bit arithmatic. + * Make sure that the SSLeay bignum library is compiled with + * THIRTY_TWO_BIT set. + * This must either be compiled with the system CC, or, if you use GNU gas, + * cc -E mips1.s|gas -o mips1.o + */ + .set reorder + .set noat + +#define R1 $1 +#define CC $2 +#define R2 $3 +#define R3 $8 +#define R4 $9 +#define L1 $10 +#define L2 $11 +#define L3 $12 +#define L4 $13 +#define H1 $14 +#define H2 $15 +#define H3 $24 +#define H4 $25 + +#define P1 $4 +#define P2 $5 +#define P3 $6 +#define P4 $7 + + .align 2 + .ent bn_mul_add_words + .globl bn_mul_add_words +.text +bn_mul_add_words: + .frame $sp,0,$31 + .mask 0x00000000,0 + .fmask 0x00000000,0 + + #blt P3,4,$lab34 + + subu R1,P3,4 + move CC,$0 + bltz R1,$lab34 +$lab2: + lw R1,0(P1) + lw L1,0(P2) + lw R2,4(P1) + lw L2,4(P2) + lw R3,8(P1) + lw L3,8(P2) + lw R4,12(P1) + lw L4,12(P2) + multu L1,P4 + addu R1,R1,CC + mflo L1 + sltu CC,R1,CC + addu R1,R1,L1 + mfhi H1 + sltu L1,R1,L1 + sw R1,0(P1) + addu CC,CC,L1 + multu L2,P4 + addu CC,H1,CC + mflo L2 + addu R2,R2,CC + sltu CC,R2,CC + mfhi H2 + addu R2,R2,L2 + addu P2,P2,16 + sltu L2,R2,L2 + sw R2,4(P1) + addu CC,CC,L2 + multu L3,P4 + addu CC,H2,CC + mflo L3 + addu R3,R3,CC + sltu CC,R3,CC + mfhi H3 + addu R3,R3,L3 + addu P1,P1,16 + sltu L3,R3,L3 + sw R3,-8(P1) + addu CC,CC,L3 + multu L4,P4 + addu CC,H3,CC + mflo L4 + addu R4,R4,CC + sltu CC,R4,CC + mfhi H4 + addu R4,R4,L4 + subu P3,P3,4 + sltu L4,R4,L4 + addu CC,CC,L4 + addu CC,H4,CC + + subu R1,P3,4 + sw R4,-4(P1) # delay slot + bgez R1,$lab2 + + bleu P3,0,$lab3 + .align 2 +$lab33: + lw L1,0(P2) + lw R1,0(P1) + multu L1,P4 + addu R1,R1,CC + sltu CC,R1,CC + addu P1,P1,4 + mflo L1 + mfhi H1 + addu R1,R1,L1 + addu P2,P2,4 + sltu L1,R1,L1 + subu P3,P3,1 + addu CC,CC,L1 + sw R1,-4(P1) + addu CC,H1,CC + bgtz P3,$lab33 + j $31 + .align 2 +$lab3: + j $31 + .align 2 +$lab34: + bgt P3,0,$lab33 + j $31 + .end bn_mul_add_words + + .align 2 + # Program Unit: bn_mul_words + .ent bn_mul_words + .globl bn_mul_words +.text +bn_mul_words: + .frame $sp,0,$31 + .mask 0x00000000,0 + .fmask 0x00000000,0 + + subu P3,P3,4 + move CC,$0 + bltz P3,$lab45 +$lab44: + lw L1,0(P2) + lw L2,4(P2) + lw L3,8(P2) + lw L4,12(P2) + multu L1,P4 + subu P3,P3,4 + mflo L1 + mfhi H1 + addu L1,L1,CC + multu L2,P4 + sltu CC,L1,CC + sw L1,0(P1) + addu CC,H1,CC + mflo L2 + mfhi H2 + addu L2,L2,CC + multu L3,P4 + sltu CC,L2,CC + sw L2,4(P1) + addu CC,H2,CC + mflo L3 + mfhi H3 + addu L3,L3,CC + multu L4,P4 + sltu CC,L3,CC + sw L3,8(P1) + addu CC,H3,CC + mflo L4 + mfhi H4 + addu L4,L4,CC + addu P1,P1,16 + sltu CC,L4,CC + addu P2,P2,16 + addu CC,H4,CC + sw L4,-4(P1) + + bgez P3,$lab44 + b $lab45 +$lab46: + lw L1,0(P2) + addu P1,P1,4 + multu L1,P4 + addu P2,P2,4 + mflo L1 + mfhi H1 + addu L1,L1,CC + subu P3,P3,1 + sltu CC,L1,CC + sw L1,-4(P1) + addu CC,H1,CC + bgtz P3,$lab46 + j $31 +$lab45: + addu P3,P3,4 + bgtz P3,$lab46 + j $31 + .align 2 + .end bn_mul_words + + # Program Unit: bn_sqr_words + .ent bn_sqr_words + .globl bn_sqr_words +.text +bn_sqr_words: + .frame $sp,0,$31 + .mask 0x00000000,0 + .fmask 0x00000000,0 + + subu P3,P3,4 + bltz P3,$lab55 +$lab54: + lw L1,0(P2) + lw L2,4(P2) + lw L3,8(P2) + lw L4,12(P2) + + multu L1,L1 + subu P3,P3,4 + mflo L1 + mfhi H1 + sw L1,0(P1) + sw H1,4(P1) + + multu L2,L2 + addu P1,P1,32 + mflo L2 + mfhi H2 + sw L2,-24(P1) + sw H2,-20(P1) + + multu L3,L3 + addu P2,P2,16 + mflo L3 + mfhi H3 + sw L3,-16(P1) + sw H3,-12(P1) + + multu L4,L4 + + mflo L4 + mfhi H4 + sw L4,-8(P1) + sw H4,-4(P1) + + bgtz P3,$lab54 + b $lab55 +$lab56: + lw L1,0(P2) + addu P1,P1,8 + multu L1,L1 + addu P2,P2,4 + subu P3,P3,1 + mflo L1 + mfhi H1 + sw L1,-8(P1) + sw H1,-4(P1) + + bgtz P3,$lab56 + j $31 +$lab55: + addu P3,P3,4 + bgtz P3,$lab56 + j $31 + .align 2 + .end bn_sqr_words + + # Program Unit: bn_add_words + .ent bn_add_words + .globl bn_add_words +.text +bn_add_words: # 0x590 + .frame $sp,0,$31 + .mask 0x00000000,0 + .fmask 0x00000000,0 + + subu P4,P4,4 + move CC,$0 + bltz P4,$lab65 +$lab64: + lw L1,0(P2) + lw R1,0(P3) + lw L2,4(P2) + lw R2,4(P3) + + addu L1,L1,CC + lw L3,8(P2) + sltu CC,L1,CC + addu L1,L1,R1 + sltu R1,L1,R1 + lw R3,8(P3) + addu CC,CC,R1 + lw L4,12(P2) + + addu L2,L2,CC + lw R4,12(P3) + sltu CC,L2,CC + addu L2,L2,R2 + sltu R2,L2,R2 + sw L1,0(P1) + addu CC,CC,R2 + addu P1,P1,16 + addu L3,L3,CC + sw L2,-12(P1) + + sltu CC,L3,CC + addu L3,L3,R3 + sltu R3,L3,R3 + addu P2,P2,16 + addu CC,CC,R3 + + addu L4,L4,CC + addu P3,P3,16 + sltu CC,L4,CC + addu L4,L4,R4 + subu P4,P4,4 + sltu R4,L4,R4 + sw L3,-8(P1) + addu CC,CC,R4 + sw L4,-4(P1) + + bgtz P4,$lab64 + b $lab65 +$lab66: + lw L1,0(P2) + lw R1,0(P3) + addu L1,L1,CC + addu P1,P1,4 + sltu CC,L1,CC + addu P2,P2,4 + addu P3,P3,4 + addu L1,L1,R1 + subu P4,P4,1 + sltu R1,L1,R1 + sw L1,-4(P1) + addu CC,CC,R1 + + bgtz P4,$lab66 + j $31 +$lab65: + addu P4,P4,4 + bgtz P4,$lab66 + j $31 + .end bn_add_words + + # Program Unit: bn_div64 + .set at + .set reorder + .text + .align 2 + .globl bn_div64 + # 321 { + .ent bn_div64 2 +bn_div64: + subu $sp, 64 + sw $31, 56($sp) + sw $16, 48($sp) + .mask 0x80010000, -56 + .frame $sp, 64, $31 + move $9, $4 + move $12, $5 + move $16, $6 + # 322 BN_ULONG dh,dl,q,ret=0,th,tl,t; + move $31, $0 + # 323 int i,count=2; + li $13, 2 + # 324 + # 325 if (d == 0) return(BN_MASK2); + bne $16, 0, $80 + li $2, -1 + b $93 +$80: + # 326 + # 327 i=BN_num_bits_word(d); + move $4, $16 + sw $31, 16($sp) + sw $9, 24($sp) + sw $12, 32($sp) + sw $13, 40($sp) + .livereg 0x800ff0e,0xfff + jal BN_num_bits_word + li $4, 32 + lw $31, 16($sp) + lw $9, 24($sp) + lw $12, 32($sp) + lw $13, 40($sp) + move $3, $2 + # 328 if ((i != BN_BITS2) && (h > (BN_ULONG)1<= d) h-=d; + bltu $9, $16, $82 + subu $9, $9, $16 +$82: + # 337 + # 338 if (i) + beq $3, 0, $83 + # 339 { + # 340 d<<=i; + sll $16, $16, $3 + # 341 h=(h<>(BN_BITS2-i)); + sll $24, $9, $3 + subu $25, $4, $3 + srl $14, $12, $25 + or $9, $24, $14 + # 342 l<<=i; + sll $12, $12, $3 + # 343 } +$83: + # 344 dh=(d&BN_MASK2h)>>BN_BITS4; + # 345 dl=(d&BN_MASK2l); + and $8, $16, -65536 + srl $8, $8, 16 + and $10, $16, 65535 + li $6, -65536 +$84: + # 346 for (;;) + # 347 { + # 348 if ((h>>BN_BITS4) == dh) + srl $15, $9, 16 + bne $8, $15, $85 + # 349 q=BN_MASK2l; + li $5, 65535 + b $86 +$85: + # 350 else + # 351 q=h/dh; + divu $5, $9, $8 +$86: + # 352 + # 353 for (;;) + # 354 { + # 355 t=(h-q*dh); + mul $4, $5, $8 + subu $2, $9, $4 + move $3, $2 + # 356 if ((t&BN_MASK2h) || + # 357 ((dl*q) <= ( + # 358 (t<>BN_BITS4)))) + and $25, $2, $6 + bne $25, $0, $87 + mul $24, $10, $5 + sll $14, $3, 16 + and $15, $12, $6 + srl $25, $15, 16 + addu $15, $14, $25 + bgtu $24, $15, $88 +$87: + # 360 break; + mul $3, $10, $5 + b $89 +$88: + # 361 q--; + addu $5, $5, -1 + # 362 } + b $86 +$89: + # 363 th=q*dh; + # 364 tl=q*dl; + # 365 t=(tl>>BN_BITS4); + # 366 tl=(tl<>BN_BITS4))&BN_MASK2; + sll $24, $9, 16 + srl $15, $12, 16 + or $9, $24, $15 + # 382 l=(l&BN_MASK2l)<" + +/* + * ==================================================================== + * Written by Andy Polyakov for the OpenSSL + * project. + * + * Rights for redistribution and usage in source and binary forms are + * granted according to the OpenSSL license. Warranty of any kind is + * disclaimed. + * ==================================================================== + */ + +/* + * This is my modest contributon to the OpenSSL project (see + * http://www.openssl.org/ for more information about it) and is + * a drop-in MIPS III/IV ISA replacement for crypto/bn/bn_asm.c + * module. For updates see http://fy.chalmers.se/~appro/hpe/. + * + * The module is designed to work with either of the "new" MIPS ABI(5), + * namely N32 or N64, offered by IRIX 6.x. It's not ment to work under + * IRIX 5.x not only because it doesn't support new ABIs but also + * because 5.x kernels put R4x00 CPU into 32-bit mode and all those + * 64-bit instructions (daddu, dmultu, etc.) found below gonna only + * cause illegal instruction exception:-( + * + * In addition the code depends on preprocessor flags set up by MIPSpro + * compiler driver (either as or cc) and therefore (probably?) can't be + * compiled by the GNU assembler. GNU C driver manages fine though... + * I mean as long as -mmips-as is specified or is the default option, + * because then it simply invokes /usr/bin/as which in turn takes + * perfect care of the preprocessor definitions. Another neat feature + * offered by the MIPSpro assembler is an optimization pass. This gave + * me the opportunity to have the code looking more regular as all those + * architecture dependent instruction rescheduling details were left to + * the assembler. Cool, huh? + * + * Performance improvement is astonishing! 'apps/openssl speed rsa dsa' + * goes way over 3 times faster! + * + * + */ +#include +#include + +#if _MIPS_ISA>=4 +#define MOVNZ(cond,dst,src) \ + movn dst,src,cond +#else +#define MOVNZ(cond,dst,src) \ + .set noreorder; \ + bnezl cond,.+8; \ + move dst,src; \ + .set reorder +#endif + +.text + +.set noat +.set reorder + +#define MINUS4 v1 + +.align 5 +LEAF(bn_mul_add_words) + .set noreorder + bgtzl a2,.L_bn_mul_add_words_proceed + ld t0,0(a1) + jr ra + move v0,zero + .set reorder + +.L_bn_mul_add_words_proceed: + li MINUS4,-4 + and ta0,a2,MINUS4 + move v0,zero + beqz ta0,.L_bn_mul_add_words_tail + +.L_bn_mul_add_words_loop: + dmultu t0,a3 + ld t1,0(a0) + ld t2,8(a1) + ld t3,8(a0) + ld ta0,16(a1) + ld ta1,16(a0) + daddu t1,v0 + sltu v0,t1,v0 /* All manuals say it "compares 32-bit + * values", but it seems to work fine + * even on 64-bit registers. */ + mflo AT + mfhi t0 + daddu t1,AT + daddu v0,t0 + sltu AT,t1,AT + sd t1,0(a0) + daddu v0,AT + + dmultu t2,a3 + ld ta2,24(a1) + ld ta3,24(a0) + daddu t3,v0 + sltu v0,t3,v0 + mflo AT + mfhi t2 + daddu t3,AT + daddu v0,t2 + sltu AT,t3,AT + sd t3,8(a0) + daddu v0,AT + + dmultu ta0,a3 + subu a2,4 + PTR_ADD a0,32 + PTR_ADD a1,32 + daddu ta1,v0 + sltu v0,ta1,v0 + mflo AT + mfhi ta0 + daddu ta1,AT + daddu v0,ta0 + sltu AT,ta1,AT + sd ta1,-16(a0) + daddu v0,AT + + + dmultu ta2,a3 + and ta0,a2,MINUS4 + daddu ta3,v0 + sltu v0,ta3,v0 + mflo AT + mfhi ta2 + daddu ta3,AT + daddu v0,ta2 + sltu AT,ta3,AT + sd ta3,-8(a0) + daddu v0,AT + .set noreorder + bgtzl ta0,.L_bn_mul_add_words_loop + ld t0,0(a1) + + bnezl a2,.L_bn_mul_add_words_tail + ld t0,0(a1) + .set reorder + +.L_bn_mul_add_words_return: + jr ra + +.L_bn_mul_add_words_tail: + dmultu t0,a3 + ld t1,0(a0) + subu a2,1 + daddu t1,v0 + sltu v0,t1,v0 + mflo AT + mfhi t0 + daddu t1,AT + daddu v0,t0 + sltu AT,t1,AT + sd t1,0(a0) + daddu v0,AT + beqz a2,.L_bn_mul_add_words_return + + ld t0,8(a1) + dmultu t0,a3 + ld t1,8(a0) + subu a2,1 + daddu t1,v0 + sltu v0,t1,v0 + mflo AT + mfhi t0 + daddu t1,AT + daddu v0,t0 + sltu AT,t1,AT + sd t1,8(a0) + daddu v0,AT + beqz a2,.L_bn_mul_add_words_return + + ld t0,16(a1) + dmultu t0,a3 + ld t1,16(a0) + daddu t1,v0 + sltu v0,t1,v0 + mflo AT + mfhi t0 + daddu t1,AT + daddu v0,t0 + sltu AT,t1,AT + sd t1,16(a0) + daddu v0,AT + jr ra +END(bn_mul_add_words) + +.align 5 +LEAF(bn_mul_words) + .set noreorder + bgtzl a2,.L_bn_mul_words_proceed + ld t0,0(a1) + jr ra + move v0,zero + .set reorder + +.L_bn_mul_words_proceed: + li MINUS4,-4 + and ta0,a2,MINUS4 + move v0,zero + beqz ta0,.L_bn_mul_words_tail + +.L_bn_mul_words_loop: + dmultu t0,a3 + ld t2,8(a1) + ld ta0,16(a1) + ld ta2,24(a1) + mflo AT + mfhi t0 + daddu v0,AT + sltu t1,v0,AT + sd v0,0(a0) + daddu v0,t1,t0 + + dmultu t2,a3 + subu a2,4 + PTR_ADD a0,32 + PTR_ADD a1,32 + mflo AT + mfhi t2 + daddu v0,AT + sltu t3,v0,AT + sd v0,-24(a0) + daddu v0,t3,t2 + + dmultu ta0,a3 + mflo AT + mfhi ta0 + daddu v0,AT + sltu ta1,v0,AT + sd v0,-16(a0) + daddu v0,ta1,ta0 + + + dmultu ta2,a3 + and ta0,a2,MINUS4 + mflo AT + mfhi ta2 + daddu v0,AT + sltu ta3,v0,AT + sd v0,-8(a0) + daddu v0,ta3,ta2 + .set noreorder + bgtzl ta0,.L_bn_mul_words_loop + ld t0,0(a1) + + bnezl a2,.L_bn_mul_words_tail + ld t0,0(a1) + .set reorder + +.L_bn_mul_words_return: + jr ra + +.L_bn_mul_words_tail: + dmultu t0,a3 + subu a2,1 + mflo AT + mfhi t0 + daddu v0,AT + sltu t1,v0,AT + sd v0,0(a0) + daddu v0,t1,t0 + beqz a2,.L_bn_mul_words_return + + ld t0,8(a1) + dmultu t0,a3 + subu a2,1 + mflo AT + mfhi t0 + daddu v0,AT + sltu t1,v0,AT + sd v0,8(a0) + daddu v0,t1,t0 + beqz a2,.L_bn_mul_words_return + + ld t0,16(a1) + dmultu t0,a3 + mflo AT + mfhi t0 + daddu v0,AT + sltu t1,v0,AT + sd v0,16(a0) + daddu v0,t1,t0 + jr ra +END(bn_mul_words) + +.align 5 +LEAF(bn_sqr_words) + .set noreorder + bgtzl a2,.L_bn_sqr_words_proceed + ld t0,0(a1) + jr ra + move v0,zero + .set reorder + +.L_bn_sqr_words_proceed: + li MINUS4,-4 + and ta0,a2,MINUS4 + move v0,zero + beqz ta0,.L_bn_sqr_words_tail + +.L_bn_sqr_words_loop: + dmultu t0,t0 + ld t2,8(a1) + ld ta0,16(a1) + ld ta2,24(a1) + mflo t1 + mfhi t0 + sd t1,0(a0) + sd t0,8(a0) + + dmultu t2,t2 + subu a2,4 + PTR_ADD a0,64 + PTR_ADD a1,32 + mflo t3 + mfhi t2 + sd t3,-48(a0) + sd t2,-40(a0) + + dmultu ta0,ta0 + mflo ta1 + mfhi ta0 + sd ta1,-32(a0) + sd ta0,-24(a0) + + + dmultu ta2,ta2 + and ta0,a2,MINUS4 + mflo ta3 + mfhi ta2 + sd ta3,-16(a0) + sd ta2,-8(a0) + + .set noreorder + bgtzl ta0,.L_bn_sqr_words_loop + ld t0,0(a1) + + bnezl a2,.L_bn_sqr_words_tail + ld t0,0(a1) + .set reorder + +.L_bn_sqr_words_return: + move v0,zero + jr ra + +.L_bn_sqr_words_tail: + dmultu t0,t0 + subu a2,1 + mflo t1 + mfhi t0 + sd t1,0(a0) + sd t0,8(a0) + beqz a2,.L_bn_sqr_words_return + + ld t0,8(a1) + dmultu t0,t0 + subu a2,1 + mflo t1 + mfhi t0 + sd t1,16(a0) + sd t0,24(a0) + beqz a2,.L_bn_sqr_words_return + + ld t0,16(a1) + dmultu t0,t0 + mflo t1 + mfhi t0 + sd t1,32(a0) + sd t0,40(a0) + jr ra +END(bn_sqr_words) + +.align 5 +LEAF(bn_add_words) + .set noreorder + bgtzl a3,.L_bn_add_words_proceed + ld t0,0(a1) + jr ra + move v0,zero + .set reorder + +.L_bn_add_words_proceed: + li MINUS4,-4 + and AT,a3,MINUS4 + move v0,zero + beqz AT,.L_bn_add_words_tail + +.L_bn_add_words_loop: + ld ta0,0(a2) + ld t1,8(a1) + ld ta1,8(a2) + ld t2,16(a1) + ld ta2,16(a2) + ld t3,24(a1) + ld ta3,24(a2) + daddu ta0,t0 + subu a3,4 + sltu t8,ta0,t0 + daddu t0,ta0,v0 + PTR_ADD a0,32 + sltu v0,t0,ta0 + sd t0,-32(a0) + daddu v0,t8 + + daddu ta1,t1 + PTR_ADD a1,32 + sltu t9,ta1,t1 + daddu t1,ta1,v0 + PTR_ADD a2,32 + sltu v0,t1,ta1 + sd t1,-24(a0) + daddu v0,t9 + + daddu ta2,t2 + and AT,a3,MINUS4 + sltu t8,ta2,t2 + daddu t2,ta2,v0 + sltu v0,t2,ta2 + sd t2,-16(a0) + daddu v0,t8 + + daddu ta3,t3 + sltu t9,ta3,t3 + daddu t3,ta3,v0 + sltu v0,t3,ta3 + sd t3,-8(a0) + daddu v0,t9 + + .set noreorder + bgtzl AT,.L_bn_add_words_loop + ld t0,0(a1) + + bnezl a3,.L_bn_add_words_tail + ld t0,0(a1) + .set reorder + +.L_bn_add_words_return: + jr ra + +.L_bn_add_words_tail: + ld ta0,0(a2) + daddu ta0,t0 + subu a3,1 + sltu t8,ta0,t0 + daddu t0,ta0,v0 + sltu v0,t0,ta0 + sd t0,0(a0) + daddu v0,t8 + beqz a3,.L_bn_add_words_return + + ld t1,8(a1) + ld ta1,8(a2) + daddu ta1,t1 + subu a3,1 + sltu t9,ta1,t1 + daddu t1,ta1,v0 + sltu v0,t1,ta1 + sd t1,8(a0) + daddu v0,t9 + beqz a3,.L_bn_add_words_return + + ld t2,16(a1) + ld ta2,16(a2) + daddu ta2,t2 + sltu t8,ta2,t2 + daddu t2,ta2,v0 + sltu v0,t2,ta2 + sd t2,16(a0) + daddu v0,t8 + jr ra +END(bn_add_words) + +.align 5 +LEAF(bn_sub_words) + .set noreorder + bgtzl a3,.L_bn_sub_words_proceed + ld t0,0(a1) + jr ra + move v0,zero + .set reorder + +.L_bn_sub_words_proceed: + li MINUS4,-4 + and AT,a3,MINUS4 + move v0,zero + beqz AT,.L_bn_sub_words_tail + +.L_bn_sub_words_loop: + ld ta0,0(a2) + ld t1,8(a1) + ld ta1,8(a2) + ld t2,16(a1) + ld ta2,16(a2) + ld t3,24(a1) + ld ta3,24(a2) + sltu t8,t0,ta0 + dsubu t0,ta0 + subu a3,4 + dsubu ta0,t0,v0 + and AT,a3,MINUS4 + sd ta0,0(a0) + MOVNZ (t0,v0,t8) + + sltu t9,t1,ta1 + dsubu t1,ta1 + PTR_ADD a0,32 + dsubu ta1,t1,v0 + PTR_ADD a1,32 + sd ta1,-24(a0) + MOVNZ (t1,v0,t9) + + + sltu t8,t2,ta2 + dsubu t2,ta2 + dsubu ta2,t2,v0 + PTR_ADD a2,32 + sd ta2,-16(a0) + MOVNZ (t2,v0,t8) + + sltu t9,t3,ta3 + dsubu t3,ta3 + dsubu ta3,t3,v0 + sd ta3,-8(a0) + MOVNZ (t3,v0,t9) + + .set noreorder + bgtzl AT,.L_bn_sub_words_loop + ld t0,0(a1) + + bnezl a3,.L_bn_sub_words_tail + ld t0,0(a1) + .set reorder + +.L_bn_sub_words_return: + jr ra + +.L_bn_sub_words_tail: + ld ta0,0(a2) + subu a3,1 + sltu t8,t0,ta0 + dsubu t0,ta0 + dsubu ta0,t0,v0 + MOVNZ (t0,v0,t8) + sd ta0,0(a0) + beqz a3,.L_bn_sub_words_return + + ld t1,8(a1) + subu a3,1 + ld ta1,8(a2) + sltu t9,t1,ta1 + dsubu t1,ta1 + dsubu ta1,t1,v0 + MOVNZ (t1,v0,t9) + sd ta1,8(a0) + beqz a3,.L_bn_sub_words_return + + ld t2,16(a1) + ld ta2,16(a2) + sltu t8,t2,ta2 + dsubu t2,ta2 + dsubu ta2,t2,v0 + MOVNZ (t2,v0,t8) + sd ta2,16(a0) + jr ra +END(bn_sub_words) + +#undef MINUS4 + +.align 5 +LEAF(bn_div_words) + .set noreorder + bnezl a2,.L_bn_div_words_proceed + move v1,zero + jr ra + li v0,-1 /* I'd rather signal div-by-zero + * which can be done with 'break 7' */ + +.L_bn_div_words_proceed: + bltz a2,.L_bn_div_words_body + move t9,v1 + dsll a2,1 + bgtz a2,.-4 + addu t9,1 + + .set reorder + negu t1,t9 + li t2,-1 + dsll t2,t1 + and t2,a0 + dsrl AT,a1,t1 + .set noreorder + bnezl t2,.+8 + break 6 /* signal overflow */ + .set reorder + dsll a0,t9 + dsll a1,t9 + or a0,AT + +#define QT ta0 +#define HH ta1 +#define DH v1 +.L_bn_div_words_body: + dsrl DH,a2,32 + sgeu AT,a0,a2 + .set noreorder + bnezl AT,.+8 + dsubu a0,a2 + .set reorder + + li QT,-1 + dsrl HH,a0,32 + dsrl QT,32 /* q=0xffffffff */ + beq DH,HH,.L_bn_div_words_skip_div1 + ddivu zero,a0,DH + mflo QT +.L_bn_div_words_skip_div1: + dmultu a2,QT + dsll t3,a0,32 + dsrl AT,a1,32 + or t3,AT + mflo t0 + mfhi t1 +.L_bn_div_words_inner_loop1: + sltu t2,t3,t0 + seq t8,HH,t1 + sltu AT,HH,t1 + and t2,t8 + or AT,t2 + .set noreorder + beqz AT,.L_bn_div_words_inner_loop1_done + sltu t2,t0,a2 + .set reorder + dsubu QT,1 + dsubu t0,a2 + dsubu t1,t2 + b .L_bn_div_words_inner_loop1 +.L_bn_div_words_inner_loop1_done: + + dsll a1,32 + dsubu a0,t3,t0 + dsll v0,QT,32 + + li QT,-1 + dsrl HH,a0,32 + dsrl QT,32 /* q=0xffffffff */ + beq DH,HH,.L_bn_div_words_skip_div2 + ddivu zero,a0,DH + mflo QT +.L_bn_div_words_skip_div2: + dmultu a2,QT + dsll t3,a0,32 + dsrl AT,a1,32 + or t3,AT + mflo t0 + mfhi t1 +.L_bn_div_words_inner_loop2: + sltu t2,t3,t0 + seq t8,HH,t1 + sltu AT,HH,t1 + and t2,t8 + or AT,t2 + .set noreorder + beqz AT,.L_bn_div_words_inner_loop2_done + sltu t2,t0,a2 + .set reorder + dsubu QT,1 + dsubu t0,a2 + dsubu t1,t2 + b .L_bn_div_words_inner_loop2 +.L_bn_div_words_inner_loop2_done: + + dsubu a0,t3,t0 + or v0,QT + dsrl v1,a0,t9 /* v1 contains remainder if anybody wants it */ + dsrl a2,t9 /* restore a2 */ + jr ra +#undef HH +#undef DH +#undef QT +END(bn_div_words) + +.align 5 +LEAF(bn_div_3_words) + .set reorder + move a3,a0 /* we know that bn_div_words doesn't + * touch a3, ta2, ta3 and preserves a2 + * so that we can save two arguments + * and return address in registers + * instead of stack:-) + */ + ld a0,(a3) + move ta2,a2 + move a2,a1 + ld a1,-8(a3) + move ta3,ra + move v1,zero + li v0,-1 + beq a0,a2,.L_bn_div_3_words_skip_div + jal bn_div_words + move ra,ta3 +.L_bn_div_3_words_skip_div: + dmultu ta2,v0 + ld t2,-16(a3) + mflo t0 + mfhi t1 +.L_bn_div_3_words_inner_loop: + sgeu AT,t2,t0 + seq t9,t1,v1 + sltu t8,t1,v1 + and AT,t9 + or AT,t8 + bnez AT,.L_bn_div_3_words_inner_loop_done + daddu v1,a2 + sltu t3,t0,ta2 + sltu AT,v1,a2 + dsubu v0,1 + dsubu t0,ta2 + dsubu t1,t3 + beqz AT,.L_bn_div_3_words_inner_loop +.L_bn_div_3_words_inner_loop_done: + jr ra +END(bn_div_3_words) + +#define a_0 t0 +#define a_1 t1 +#define a_2 t2 +#define a_3 t3 +#define b_0 ta0 +#define b_1 ta1 +#define b_2 ta2 +#define b_3 ta3 + +#define a_4 s0 +#define a_5 s2 +#define a_6 s4 +#define a_7 a1 /* once we load a[7] we don't need a anymore */ +#define b_4 s1 +#define b_5 s3 +#define b_6 s5 +#define b_7 a2 /* once we load b[7] we don't need b anymore */ + +#define t_1 t8 +#define t_2 t9 + +#define c_1 v0 +#define c_2 v1 +#define c_3 a3 + +#define FRAME_SIZE 48 + +.align 5 +LEAF(bn_mul_comba8) + .set noreorder + PTR_SUB sp,FRAME_SIZE + .frame sp,64,ra + .set reorder + ld a_0,0(a1) /* If compiled with -mips3 option on + * R5000 box assembler barks on this + * line with "shouldn't have mult/div + * as last instruction in bb (R10K + * bug)" warning. If anybody out there + * has a clue about how to circumvent + * this do send me a note. + * + */ + ld b_0,0(a2) + ld a_1,8(a1) + ld a_2,16(a1) + ld a_3,24(a1) + ld b_1,8(a2) + ld b_2,16(a2) + ld b_3,24(a2) + dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */ + sd s0,0(sp) + sd s1,8(sp) + sd s2,16(sp) + sd s3,24(sp) + sd s4,32(sp) + sd s5,40(sp) + mflo c_1 + mfhi c_2 + + dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */ + ld a_4,32(a1) + ld a_5,40(a1) + ld a_6,48(a1) + ld a_7,56(a1) + ld b_4,32(a2) + ld b_5,40(a2) + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu c_3,t_2,AT + dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */ + ld b_6,48(a2) + ld b_7,56(a2) + sd c_1,0(a0) /* r[0]=c1; */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + sd c_2,8(a0) /* r[1]=c2; */ + + dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,16(a0) /* r[2]=c3; */ + + dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,24(a0) /* r[3]=c1; */ + + dmultu a_4,b_0 /* mul_add_c(a[4],b[0],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_0,b_4 /* mul_add_c(a[0],b[4],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + sd c_2,32(a0) /* r[4]=c2; */ + + dmultu a_0,b_5 /* mul_add_c(a[0],b[5],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + dmultu a_1,b_4 /* mul_add_c(a[1],b[4],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_4,b_1 /* mul_add_c(a[4],b[1],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_5,b_0 /* mul_add_c(a[5],b[0],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,40(a0) /* r[5]=c3; */ + + dmultu a_6,b_0 /* mul_add_c(a[6],b[0],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + dmultu a_5,b_1 /* mul_add_c(a[5],b[1],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_4,b_2 /* mul_add_c(a[4],b[2],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_2,b_4 /* mul_add_c(a[2],b[4],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_1,b_5 /* mul_add_c(a[1],b[5],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_0,b_6 /* mul_add_c(a[0],b[6],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,48(a0) /* r[6]=c1; */ + + dmultu a_0,b_7 /* mul_add_c(a[0],b[7],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + dmultu a_1,b_6 /* mul_add_c(a[1],b[6],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + dmultu a_2,b_5 /* mul_add_c(a[2],b[5],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_3,b_4 /* mul_add_c(a[3],b[4],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_4,b_3 /* mul_add_c(a[4],b[3],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_5,b_2 /* mul_add_c(a[5],b[2],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_6,b_1 /* mul_add_c(a[6],b[1],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_7,b_0 /* mul_add_c(a[7],b[0],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + sd c_2,56(a0) /* r[7]=c2; */ + + dmultu a_7,b_1 /* mul_add_c(a[7],b[1],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + dmultu a_6,b_2 /* mul_add_c(a[6],b[2],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_5,b_3 /* mul_add_c(a[5],b[3],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_4,b_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_3,b_5 /* mul_add_c(a[3],b[5],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_2,b_6 /* mul_add_c(a[2],b[6],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_1,b_7 /* mul_add_c(a[1],b[7],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,64(a0) /* r[8]=c3; */ + + dmultu a_2,b_7 /* mul_add_c(a[2],b[7],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + dmultu a_3,b_6 /* mul_add_c(a[3],b[6],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_4,b_5 /* mul_add_c(a[4],b[5],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_5,b_4 /* mul_add_c(a[5],b[4],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_6,b_3 /* mul_add_c(a[6],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_7,b_2 /* mul_add_c(a[7],b[2],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,72(a0) /* r[9]=c1; */ + + dmultu a_7,b_3 /* mul_add_c(a[7],b[3],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + dmultu a_6,b_4 /* mul_add_c(a[6],b[4],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + dmultu a_5,b_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_4,b_6 /* mul_add_c(a[4],b[6],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_3,b_7 /* mul_add_c(a[3],b[7],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + sd c_2,80(a0) /* r[10]=c2; */ + + dmultu a_4,b_7 /* mul_add_c(a[4],b[7],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + dmultu a_5,b_6 /* mul_add_c(a[5],b[6],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_6,b_5 /* mul_add_c(a[6],b[5],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_7,b_4 /* mul_add_c(a[7],b[4],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,88(a0) /* r[11]=c3; */ + + dmultu a_7,b_5 /* mul_add_c(a[7],b[5],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + dmultu a_6,b_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_5,b_7 /* mul_add_c(a[5],b[7],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,96(a0) /* r[12]=c1; */ + + dmultu a_6,b_7 /* mul_add_c(a[6],b[7],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + dmultu a_7,b_6 /* mul_add_c(a[7],b[6],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + sd c_2,104(a0) /* r[13]=c2; */ + + dmultu a_7,b_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */ + ld s0,0(sp) + ld s1,8(sp) + ld s2,16(sp) + ld s3,24(sp) + ld s4,32(sp) + ld s5,40(sp) + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sd c_3,112(a0) /* r[14]=c3; */ + sd c_1,120(a0) /* r[15]=c1; */ + + PTR_ADD sp,FRAME_SIZE + + jr ra +END(bn_mul_comba8) + +.align 5 +LEAF(bn_mul_comba4) + .set reorder + ld a_0,0(a1) + ld b_0,0(a2) + ld a_1,8(a1) + ld a_2,16(a1) + dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */ + ld a_3,24(a1) + ld b_1,8(a2) + ld b_2,16(a2) + ld b_3,24(a2) + mflo c_1 + mfhi c_2 + sd c_1,0(a0) + + dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu c_3,t_2,AT + dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + sd c_2,8(a0) + + dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,16(a0) + + dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,24(a0) + + dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + sd c_2,32(a0) + + dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + sd c_3,40(a0) + + dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sd c_1,48(a0) + sd c_2,56(a0) + + jr ra +END(bn_mul_comba4) + +#undef a_4 +#undef a_5 +#undef a_6 +#undef a_7 +#define a_4 b_0 +#define a_5 b_1 +#define a_6 b_2 +#define a_7 b_3 + +.align 5 +LEAF(bn_sqr_comba8) + .set reorder + ld a_0,0(a1) + ld a_1,8(a1) + ld a_2,16(a1) + ld a_3,24(a1) + + dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */ + ld a_4,32(a1) + ld a_5,40(a1) + ld a_6,48(a1) + ld a_7,56(a1) + mflo c_1 + mfhi c_2 + sd c_1,0(a0) + + dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu c_3,t_2,AT + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + sd c_2,8(a0) + + dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,16(a0) + + dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_1,a_2 /* mul_add_c2(a[1],b[2],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + sltu AT,c_2,a2 + daddu c_3,AT + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,24(a0) + + dmultu a_4,a_0 /* mul_add_c2(a[4],b[0],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + sltu AT,c_3,a2 + daddu c_1,AT + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + sd c_2,32(a0) + + dmultu a_0,a_5 /* mul_add_c2(a[0],b[5],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_1,a_4 /* mul_add_c2(a[1],b[4],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + sltu AT,c_1,a2 + daddu c_2,AT + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + sltu AT,c_1,a2 + daddu c_2,AT + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,40(a0) + + dmultu a_6,a_0 /* mul_add_c2(a[6],b[0],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_5,a_1 /* mul_add_c2(a[5],b[1],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + sltu AT,c_2,a2 + daddu c_3,AT + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_4,a_2 /* mul_add_c2(a[4],b[2],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + sltu AT,c_2,a2 + daddu c_3,AT + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,48(a0) + + dmultu a_0,a_7 /* mul_add_c2(a[0],b[7],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + dmultu a_1,a_6 /* mul_add_c2(a[1],b[6],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + sltu AT,c_3,a2 + daddu c_1,AT + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_2,a_5 /* mul_add_c2(a[2],b[5],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + sltu AT,c_3,a2 + daddu c_1,AT + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_3,a_4 /* mul_add_c2(a[3],b[4],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + sltu AT,c_3,a2 + daddu c_1,AT + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + sd c_2,56(a0) + + dmultu a_7,a_1 /* mul_add_c2(a[7],b[1],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_6,a_2 /* mul_add_c2(a[6],b[2],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + sltu AT,c_1,a2 + daddu c_2,AT + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_5,a_3 /* mul_add_c2(a[5],b[3],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + sltu AT,c_1,a2 + daddu c_2,AT + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + dmultu a_4,a_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,64(a0) + + dmultu a_2,a_7 /* mul_add_c2(a[2],b[7],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_3,a_6 /* mul_add_c2(a[3],b[6],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + sltu AT,c_2,a2 + daddu c_3,AT + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + dmultu a_4,a_5 /* mul_add_c2(a[4],b[5],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + sltu AT,c_2,a2 + daddu c_3,AT + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,72(a0) + + dmultu a_7,a_3 /* mul_add_c2(a[7],b[3],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + dmultu a_6,a_4 /* mul_add_c2(a[6],b[4],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + sltu AT,c_3,a2 + daddu c_1,AT + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + dmultu a_5,a_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + sd c_2,80(a0) + + dmultu a_4,a_7 /* mul_add_c2(a[4],b[7],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_5,a_6 /* mul_add_c2(a[5],b[6],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + sltu AT,c_1,a2 + daddu c_2,AT + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,88(a0) + + dmultu a_7,a_5 /* mul_add_c2(a[7],b[5],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_6,a_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,96(a0) + + dmultu a_6,a_7 /* mul_add_c2(a[6],b[7],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + sd c_2,104(a0) + + dmultu a_7,a_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sd c_3,112(a0) + sd c_1,120(a0) + + jr ra +END(bn_sqr_comba8) + +.align 5 +LEAF(bn_sqr_comba4) + .set reorder + ld a_0,0(a1) + ld a_1,8(a1) + ld a_2,16(a1) + ld a_3,24(a1) + dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */ + mflo c_1 + mfhi c_2 + sd c_1,0(a0) + + dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu c_3,t_2,AT + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + sd c_2,8(a0) + + dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu AT,c_1,t_2 + daddu c_2,AT + sd c_3,16(a0) + + dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu c_3,c_2,t_2 + dmultu a_1,a_2 /* mul_add_c(a2[1],b[2],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu a2,t_2,AT + daddu c_2,a2 + sltu AT,c_2,a2 + daddu c_3,AT + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sltu AT,c_2,t_2 + daddu c_3,AT + sd c_1,24(a0) + + dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu a2,t_2,AT + daddu c_3,a2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu c_1,c_3,t_2 + dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */ + mflo t_1 + mfhi t_2 + daddu c_2,t_1 + sltu AT,c_2,t_1 + daddu t_2,AT + daddu c_3,t_2 + sltu AT,c_3,t_2 + daddu c_1,AT + sd c_2,32(a0) + + dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */ + mflo t_1 + mfhi t_2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu a2,t_2,AT + daddu c_1,a2 + daddu c_3,t_1 + sltu AT,c_3,t_1 + daddu t_2,AT + daddu c_1,t_2 + sltu c_2,c_1,t_2 + sd c_3,40(a0) + + dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */ + mflo t_1 + mfhi t_2 + daddu c_1,t_1 + sltu AT,c_1,t_1 + daddu t_2,AT + daddu c_2,t_2 + sd c_1,48(a0) + sd c_2,56(a0) + + jr ra +END(bn_sqr_comba4) diff --git a/src/lib/libcrypto/bn/asm/sparc.s b/src/lib/libcrypto/bn/asm/sparc.s deleted file mode 100644 index f9e533caa8..0000000000 --- a/src/lib/libcrypto/bn/asm/sparc.s +++ /dev/null @@ -1,462 +0,0 @@ - .file "bn_mulw.c" -gcc2_compiled.: -.section ".text" - .align 4 - .global bn_mul_add_words - .type bn_mul_add_words,#function - .proc 016 -bn_mul_add_words: - !#PROLOGUE# 0 - save %sp,-112,%sp - !#PROLOGUE# 1 - mov %i0,%o0 - mov %i1,%o2 - mov %i2,%g1 - mov %i3,%o1 - mov 0,%i4 - add %o0,12,%g4 - add %o2,12,%o7 -.LL2: - mov %i4,%i3 - mov 0,%i2 - ld [%o0],%g2 - mov %g2,%i1 - ld [%o2],%g2 - mov 0,%i0 - umul %o1,%g2,%g3 - rd %y,%g2 - addcc %g3,%i1,%g3 - addx %g2,%i0,%g2 - addcc %g3,%i3,%g3 - addx %g2,%i2,%g2 - st %g3,[%o0] - mov %g2,%i5 - mov 0,%i4 - addcc %g1,-1,%g1 - be .LL3 - mov %i5,%i4 - mov %i4,%i3 - mov 0,%i2 - ld [%g4-8],%g2 - mov %g2,%i1 - ld [%o7-8],%g2 - mov 0,%i0 - umul %o1,%g2,%g3 - rd %y,%g2 - addcc %g3,%i1,%g3 - addx %g2,%i0,%g2 - addcc %g3,%i3,%g3 - addx %g2,%i2,%g2 - st %g3,[%g4-8] - mov %g2,%i5 - mov 0,%i4 - addcc %g1,-1,%g1 - be .LL3 - mov %i5,%i4 - mov %i4,%i3 - mov 0,%i2 - ld [%g4-4],%g2 - mov %g2,%i1 - ld [%o7-4],%g2 - mov 0,%i0 - umul %o1,%g2,%g3 - rd %y,%g2 - addcc %g3,%i1,%g3 - addx %g2,%i0,%g2 - addcc %g3,%i3,%g3 - addx %g2,%i2,%g2 - st %g3,[%g4-4] - mov %g2,%i5 - mov 0,%i4 - addcc %g1,-1,%g1 - be .LL3 - mov %i5,%i4 - mov %i4,%i3 - mov 0,%i2 - ld [%g4],%g2 - mov %g2,%i1 - ld [%o7],%g2 - mov 0,%i0 - umul %o1,%g2,%g3 - rd %y,%g2 - addcc %g3,%i1,%g3 - addx %g2,%i0,%g2 - addcc %g3,%i3,%g3 - addx %g2,%i2,%g2 - st %g3,[%g4] - mov %g2,%i5 - mov 0,%i4 - addcc %g1,-1,%g1 - be .LL3 - mov %i5,%i4 - add %o7,16,%o7 - add %o2,16,%o2 - add %g4,16,%g4 - b .LL2 - add %o0,16,%o0 -.LL3: - ret - restore %g0,%i4,%o0 -.LLfe1: - .size bn_mul_add_words,.LLfe1-bn_mul_add_words - .align 4 - .global bn_mul_words - .type bn_mul_words,#function - .proc 016 -bn_mul_words: - !#PROLOGUE# 0 - save %sp,-112,%sp - !#PROLOGUE# 1 - mov %i0,%o7 - mov %i1,%o0 - mov %i2,%i4 - mov %i3,%g4 - mov 0,%i0 - add %o7,12,%g1 - add %o0,12,%i5 -.LL18: - mov %i0,%g3 - mov 0,%g2 - ld [%o0],%i2 - umul %g4,%i2,%i3 - rd %y,%i2 - addcc %i3,%g3,%i3 - addx %i2,%g2,%i2 - st %i3,[%o7] - mov %i2,%i1 - mov 0,%i0 - addcc %i4,-1,%i4 - be .LL19 - mov %i1,%i0 - mov %i0,%g3 - mov 0,%g2 - ld [%i5-8],%i2 - umul %g4,%i2,%i3 - rd %y,%i2 - addcc %i3,%g3,%i3 - addx %i2,%g2,%i2 - st %i3,[%g1-8] - mov %i2,%i1 - mov 0,%i0 - addcc %i4,-1,%i4 - be .LL19 - mov %i1,%i0 - mov %i0,%g3 - mov 0,%g2 - ld [%i5-4],%i2 - umul %g4,%i2,%i3 - rd %y,%i2 - addcc %i3,%g3,%i3 - addx %i2,%g2,%i2 - st %i3,[%g1-4] - mov %i2,%i1 - mov 0,%i0 - addcc %i4,-1,%i4 - be .LL19 - mov %i1,%i0 - mov %i0,%g3 - mov 0,%g2 - ld [%i5],%i2 - umul %g4,%i2,%i3 - rd %y,%i2 - addcc %i3,%g3,%i3 - addx %i2,%g2,%i2 - st %i3,[%g1] - mov %i2,%i1 - mov 0,%i0 - addcc %i4,-1,%i4 - be .LL19 - mov %i1,%i0 - add %i5,16,%i5 - add %o0,16,%o0 - add %g1,16,%g1 - b .LL18 - add %o7,16,%o7 -.LL19: - ret - restore -.LLfe2: - .size bn_mul_words,.LLfe2-bn_mul_words - .align 4 - .global bn_sqr_words - .type bn_sqr_words,#function - .proc 020 -bn_sqr_words: - !#PROLOGUE# 0 - !#PROLOGUE# 1 - mov %o0,%g4 - add %g4,28,%o3 - add %o1,12,%g1 -.LL34: - ld [%o1],%o0 - addcc %o2,-1,%o2 - umul %o0,%o0,%o5 - rd %y,%o4 - st %o5,[%g4] - mov %o4,%g3 - mov 0,%g2 - be .LL35 - st %g3,[%o3-24] - ld [%g1-8],%o0 - addcc %o2,-1,%o2 - umul %o0,%o0,%o5 - rd %y,%o4 - st %o5,[%o3-20] - mov %o4,%g3 - mov 0,%g2 - be .LL35 - st %g3,[%o3-16] - ld [%g1-4],%o0 - addcc %o2,-1,%o2 - umul %o0,%o0,%o5 - rd %y,%o4 - st %o5,[%o3-12] - mov %o4,%g3 - mov 0,%g2 - be .LL35 - st %g3,[%o3-8] - ld [%g1],%o0 - addcc %o2,-1,%o2 - umul %o0,%o0,%o5 - rd %y,%o4 - st %o5,[%o3-4] - mov %o4,%g3 - mov 0,%g2 - be .LL35 - st %g3,[%o3] - add %g1,16,%g1 - add %o1,16,%o1 - add %o3,32,%o3 - b .LL34 - add %g4,32,%g4 -.LL35: - retl - nop -.LLfe3: - .size bn_sqr_words,.LLfe3-bn_sqr_words - .align 4 - .global bn_add_words - .type bn_add_words,#function - .proc 016 -bn_add_words: - !#PROLOGUE# 0 - save %sp,-112,%sp - !#PROLOGUE# 1 - mov %i0,%o2 - mov %i1,%o3 - mov %i2,%o4 - mov %i3,%i5 - mov 0,%o0 - mov 0,%o1 - add %o2,12,%o7 - add %o4,12,%g4 - b .LL42 - add %o3,12,%g1 -.LL45: - add %i5,-1,%i5 - mov %i4,%g3 - ld [%g4-8],%i4 - mov 0,%g2 - mov %i4,%i1 - mov 0,%i0 - addcc %g3,%i1,%g3 - addx %g2,%i0,%g2 - addcc %o1,%g3,%o1 - addx %o0,%g2,%o0 - st %o1,[%o7-8] - mov %o0,%i3 - mov 0,%i2 - mov %i2,%o0 - mov %i3,%o1 - cmp %i5,0 - ble .LL43 - add %i5,-1,%i5 - ld [%g1-4],%i4 - mov %i4,%g3 - ld [%g4-4],%i4 - mov 0,%g2 - mov %i4,%i1 - mov 0,%i0 - addcc %g3,%i1,%g3 - addx %g2,%i0,%g2 - addcc %o1,%g3,%o1 - addx %o0,%g2,%o0 - st %o1,[%o7-4] - mov %o0,%i3 - mov 0,%i2 - mov %i2,%o0 - mov %i3,%o1 - cmp %i5,0 - ble .LL43 - add %i5,-1,%i5 - ld [%g1],%i4 - mov %i4,%g3 - ld [%g4],%i4 - mov 0,%g2 - mov %i4,%i1 - mov 0,%i0 - addcc %g3,%i1,%g3 - addx %g2,%i0,%g2 - addcc %o1,%g3,%o1 - addx %o0,%g2,%o0 - st %o1,[%o7] - mov %o0,%i3 - mov 0,%i2 - mov %i2,%o0 - mov %i3,%o1 - cmp %i5,0 - ble .LL43 - add %g1,16,%g1 - add %o3,16,%o3 - add %g4,16,%g4 - add %o4,16,%o4 - add %o7,16,%o7 - add %o2,16,%o2 -.LL42: - ld [%o3],%i4 - add %i5,-1,%i5 - mov %i4,%g3 - ld [%o4],%i4 - mov 0,%g2 - mov %i4,%i1 - mov 0,%i0 - addcc %g3,%i1,%g3 - addx %g2,%i0,%g2 - addcc %o1,%g3,%o1 - addx %o0,%g2,%o0 - st %o1,[%o2] - mov %o0,%i3 - mov 0,%i2 - mov %i2,%o0 - mov %i3,%o1 - cmp %i5,0 - bg,a .LL45 - ld [%g1-8],%i4 -.LL43: - ret - restore %g0,%o1,%o0 -.LLfe4: - .size bn_add_words,.LLfe4-bn_add_words -.section ".rodata" - .align 8 -.LLC0: - .asciz "Division would overflow (%d)\n" -.section ".text" - .align 4 - .global bn_div64 - .type bn_div64,#function - .proc 016 -bn_div64: - !#PROLOGUE# 0 - save %sp,-112,%sp - !#PROLOGUE# 1 - mov 0,%l1 - cmp %i2,0 - bne .LL51 - mov 2,%l0 - b .LL68 - mov -1,%i0 -.LL51: - call BN_num_bits_word,0 - mov %i2,%o0 - mov %o0,%o2 - cmp %o2,32 - be .LL52 - mov 1,%o0 - sll %o0,%o2,%o0 - cmp %i0,%o0 - bleu .LL69 - mov 32,%o0 - sethi %hi(__iob+32),%o0 - or %o0,%lo(__iob+32),%o0 - sethi %hi(.LLC0),%o1 - call fprintf,0 - or %o1,%lo(.LLC0),%o1 - call abort,0 - nop -.LL52: - mov 32,%o0 -.LL69: - cmp %i0,%i2 - blu .LL53 - sub %o0,%o2,%o2 - sub %i0,%i2,%i0 -.LL53: - cmp %o2,0 - be .LL54 - sll %i0,%o2,%o1 - sll %i2,%o2,%i2 - sub %o0,%o2,%o0 - srl %i1,%o0,%o0 - or %o1,%o0,%i0 - sll %i1,%o2,%i1 -.LL54: - srl %i2,16,%g2 - sethi %hi(65535),%o0 - or %o0,%lo(65535),%o1 - and %i2,%o1,%g3 - mov %o0,%g4 - sethi %hi(-65536),%o7 - mov %o1,%g1 -.LL55: - srl %i0,16,%o0 - cmp %o0,%g2 - be .LL59 - or %g4,%lo(65535),%o3 - wr %g0,%g0,%y - nop - nop - nop - udiv %i0,%g2,%o3 -.LL59: - and %i1,%o7,%o0 - srl %o0,16,%o5 - smul %o3,%g3,%o4 - smul %o3,%g2,%o2 -.LL60: - sub %i0,%o2,%o1 - andcc %o1,%o7,%g0 - bne .LL61 - sll %o1,16,%o0 - add %o0,%o5,%o0 - cmp %o4,%o0 - bleu .LL61 - sub %o4,%g3,%o4 - sub %o2,%g2,%o2 - b .LL60 - add %o3,-1,%o3 -.LL61: - smul %o3,%g2,%o2 - smul %o3,%g3,%o0 - srl %o0,16,%o1 - sll %o0,16,%o0 - and %o0,%o7,%o0 - cmp %i1,%o0 - bgeu .LL65 - add %o2,%o1,%o2 - add %o2,1,%o2 -.LL65: - cmp %i0,%o2 - bgeu .LL66 - sub %i1,%o0,%i1 - add %i0,%i2,%i0 - add %o3,-1,%o3 -.LL66: - addcc %l0,-1,%l0 - be .LL56 - sub %i0,%o2,%i0 - sll %o3,16,%l1 - sll %i0,16,%o0 - srl %i1,16,%o1 - or %o0,%o1,%i0 - and %i1,%g1,%o0 - b .LL55 - sll %o0,16,%i1 -.LL56: - or %l1,%o3,%i0 -.LL68: - ret - restore -.LLfe5: - .size bn_div64,.LLfe5-bn_div64 - .ident "GCC: (GNU) 2.7.2.3" diff --git a/src/lib/libcrypto/bn/asm/sparcv8.S b/src/lib/libcrypto/bn/asm/sparcv8.S new file mode 100644 index 0000000000..88c5dc480a --- /dev/null +++ b/src/lib/libcrypto/bn/asm/sparcv8.S @@ -0,0 +1,1458 @@ +.ident "sparcv8.s, Version 1.4" +.ident "SPARC v8 ISA artwork by Andy Polyakov " + +/* + * ==================================================================== + * Written by Andy Polyakov for the OpenSSL + * project. + * + * Rights for redistribution and usage in source and binary forms are + * granted according to the OpenSSL license. Warranty of any kind is + * disclaimed. + * ==================================================================== + */ + +/* + * This is my modest contributon to OpenSSL project (see + * http://www.openssl.org/ for more information about it) and is + * a drop-in SuperSPARC ISA replacement for crypto/bn/bn_asm.c + * module. For updates see http://fy.chalmers.se/~appro/hpe/. + * + * See bn_asm.sparc.v8plus.S for more details. + */ + +/* + * Revision history. + * + * 1.1 - new loop unrolling model(*); + * 1.2 - made gas friendly; + * 1.3 - fixed problem with /usr/ccs/lib/cpp; + * 1.4 - some retunes; + * + * (*) see bn_asm.sparc.v8plus.S for details + */ + +.section ".text",#alloc,#execinstr +.file "bn_asm.sparc.v8.S" + +.align 32 + +.global bn_mul_add_words +/* + * BN_ULONG bn_mul_add_words(rp,ap,num,w) + * BN_ULONG *rp,*ap; + * int num; + * BN_ULONG w; + */ +bn_mul_add_words: + cmp %o2,0 + bg,a .L_bn_mul_add_words_proceed + ld [%o1],%g2 + retl + clr %o0 + +.L_bn_mul_add_words_proceed: + andcc %o2,-4,%g0 + bz .L_bn_mul_add_words_tail + clr %o5 + +.L_bn_mul_add_words_loop: + ld [%o0],%o4 + ld [%o1+4],%g3 + umul %o3,%g2,%g2 + rd %y,%g1 + addcc %o4,%o5,%o4 + addx %g1,0,%g1 + addcc %o4,%g2,%o4 + st %o4,[%o0] + addx %g1,0,%o5 + + ld [%o0+4],%o4 + ld [%o1+8],%g2 + umul %o3,%g3,%g3 + dec 4,%o2 + rd %y,%g1 + addcc %o4,%o5,%o4 + addx %g1,0,%g1 + addcc %o4,%g3,%o4 + st %o4,[%o0+4] + addx %g1,0,%o5 + + ld [%o0+8],%o4 + ld [%o1+12],%g3 + umul %o3,%g2,%g2 + inc 16,%o1 + rd %y,%g1 + addcc %o4,%o5,%o4 + addx %g1,0,%g1 + addcc %o4,%g2,%o4 + st %o4,[%o0+8] + addx %g1,0,%o5 + + ld [%o0+12],%o4 + umul %o3,%g3,%g3 + inc 16,%o0 + rd %y,%g1 + addcc %o4,%o5,%o4 + addx %g1,0,%g1 + addcc %o4,%g3,%o4 + st %o4,[%o0-4] + addx %g1,0,%o5 + andcc %o2,-4,%g0 + bnz,a .L_bn_mul_add_words_loop + ld [%o1],%g2 + + tst %o2 + bnz,a .L_bn_mul_add_words_tail + ld [%o1],%g2 +.L_bn_mul_add_words_return: + retl + mov %o5,%o0 + nop + +.L_bn_mul_add_words_tail: + ld [%o0],%o4 + umul %o3,%g2,%g2 + addcc %o4,%o5,%o4 + rd %y,%g1 + addx %g1,0,%g1 + addcc %o4,%g2,%o4 + addx %g1,0,%o5 + deccc %o2 + bz .L_bn_mul_add_words_return + st %o4,[%o0] + + ld [%o1+4],%g2 + ld [%o0+4],%o4 + umul %o3,%g2,%g2 + rd %y,%g1 + addcc %o4,%o5,%o4 + addx %g1,0,%g1 + addcc %o4,%g2,%o4 + addx %g1,0,%o5 + deccc %o2 + bz .L_bn_mul_add_words_return + st %o4,[%o0+4] + + ld [%o1+8],%g2 + ld [%o0+8],%o4 + umul %o3,%g2,%g2 + rd %y,%g1 + addcc %o4,%o5,%o4 + addx %g1,0,%g1 + addcc %o4,%g2,%o4 + st %o4,[%o0+8] + retl + addx %g1,0,%o0 + +.type bn_mul_add_words,#function +.size bn_mul_add_words,(.-bn_mul_add_words) + +.align 32 + +.global bn_mul_words +/* + * BN_ULONG bn_mul_words(rp,ap,num,w) + * BN_ULONG *rp,*ap; + * int num; + * BN_ULONG w; + */ +bn_mul_words: + cmp %o2,0 + bg,a .L_bn_mul_words_proceeed + ld [%o1],%g2 + retl + clr %o0 + +.L_bn_mul_words_proceeed: + andcc %o2,-4,%g0 + bz .L_bn_mul_words_tail + clr %o5 + +.L_bn_mul_words_loop: + ld [%o1+4],%g3 + umul %o3,%g2,%g2 + addcc %g2,%o5,%g2 + rd %y,%g1 + addx %g1,0,%o5 + st %g2,[%o0] + + ld [%o1+8],%g2 + umul %o3,%g3,%g3 + addcc %g3,%o5,%g3 + rd %y,%g1 + dec 4,%o2 + addx %g1,0,%o5 + st %g3,[%o0+4] + + ld [%o1+12],%g3 + umul %o3,%g2,%g2 + addcc %g2,%o5,%g2 + rd %y,%g1 + inc 16,%o1 + st %g2,[%o0+8] + addx %g1,0,%o5 + + umul %o3,%g3,%g3 + addcc %g3,%o5,%g3 + rd %y,%g1 + inc 16,%o0 + addx %g1,0,%o5 + st %g3,[%o0-4] + andcc %o2,-4,%g0 + nop + bnz,a .L_bn_mul_words_loop + ld [%o1],%g2 + + tst %o2 + bnz,a .L_bn_mul_words_tail + ld [%o1],%g2 +.L_bn_mul_words_return: + retl + mov %o5,%o0 + nop + +.L_bn_mul_words_tail: + umul %o3,%g2,%g2 + addcc %g2,%o5,%g2 + rd %y,%g1 + addx %g1,0,%o5 + deccc %o2 + bz .L_bn_mul_words_return + st %g2,[%o0] + nop + + ld [%o1+4],%g2 + umul %o3,%g2,%g2 + addcc %g2,%o5,%g2 + rd %y,%g1 + addx %g1,0,%o5 + deccc %o2 + bz .L_bn_mul_words_return + st %g2,[%o0+4] + + ld [%o1+8],%g2 + umul %o3,%g2,%g2 + addcc %g2,%o5,%g2 + rd %y,%g1 + st %g2,[%o0+8] + retl + addx %g1,0,%o0 + +.type bn_mul_words,#function +.size bn_mul_words,(.-bn_mul_words) + +.align 32 +.global bn_sqr_words +/* + * void bn_sqr_words(r,a,n) + * BN_ULONG *r,*a; + * int n; + */ +bn_sqr_words: + cmp %o2,0 + bg,a .L_bn_sqr_words_proceeed + ld [%o1],%g2 + retl + clr %o0 + +.L_bn_sqr_words_proceeed: + andcc %o2,-4,%g0 + bz .L_bn_sqr_words_tail + clr %o5 + +.L_bn_sqr_words_loop: + ld [%o1+4],%g3 + umul %g2,%g2,%o4 + st %o4,[%o0] + rd %y,%o5 + st %o5,[%o0+4] + + ld [%o1+8],%g2 + umul %g3,%g3,%o4 + dec 4,%o2 + st %o4,[%o0+8] + rd %y,%o5 + st %o5,[%o0+12] + nop + + ld [%o1+12],%g3 + umul %g2,%g2,%o4 + st %o4,[%o0+16] + rd %y,%o5 + inc 16,%o1 + st %o5,[%o0+20] + + umul %g3,%g3,%o4 + inc 32,%o0 + st %o4,[%o0-8] + rd %y,%o5 + st %o5,[%o0-4] + andcc %o2,-4,%g2 + bnz,a .L_bn_sqr_words_loop + ld [%o1],%g2 + + tst %o2 + nop + bnz,a .L_bn_sqr_words_tail + ld [%o1],%g2 +.L_bn_sqr_words_return: + retl + clr %o0 + +.L_bn_sqr_words_tail: + umul %g2,%g2,%o4 + st %o4,[%o0] + deccc %o2 + rd %y,%o5 + bz .L_bn_sqr_words_return + st %o5,[%o0+4] + + ld [%o1+4],%g2 + umul %g2,%g2,%o4 + st %o4,[%o0+8] + deccc %o2 + rd %y,%o5 + nop + bz .L_bn_sqr_words_return + st %o5,[%o0+12] + + ld [%o1+8],%g2 + umul %g2,%g2,%o4 + st %o4,[%o0+16] + rd %y,%o5 + st %o5,[%o0+20] + retl + clr %o0 + +.type bn_sqr_words,#function +.size bn_sqr_words,(.-bn_sqr_words) + +.align 32 + +.global bn_div_words +/* + * BN_ULONG bn_div_words(h,l,d) + * BN_ULONG h,l,d; + */ +bn_div_words: + wr %o0,%y + udiv %o1,%o2,%o0 + retl + nop + +.type bn_div_words,#function +.size bn_div_words,(.-bn_div_words) + +.align 32 + +.global bn_add_words +/* + * BN_ULONG bn_add_words(rp,ap,bp,n) + * BN_ULONG *rp,*ap,*bp; + * int n; + */ +bn_add_words: + cmp %o3,0 + bg,a .L_bn_add_words_proceed + ld [%o1],%o4 + retl + clr %o0 + +.L_bn_add_words_proceed: + andcc %o3,-4,%g0 + bz .L_bn_add_words_tail + clr %g1 + ba .L_bn_add_words_warn_loop + addcc %g0,0,%g0 ! clear carry flag + +.L_bn_add_words_loop: + ld [%o1],%o4 +.L_bn_add_words_warn_loop: + ld [%o2],%o5 + ld [%o1+4],%g3 + ld [%o2+4],%g4 + dec 4,%o3 + addxcc %o5,%o4,%o5 + st %o5,[%o0] + + ld [%o1+8],%o4 + ld [%o2+8],%o5 + inc 16,%o1 + addxcc %g3,%g4,%g3 + st %g3,[%o0+4] + + ld [%o1-4],%g3 + ld [%o2+12],%g4 + inc 16,%o2 + addxcc %o5,%o4,%o5 + st %o5,[%o0+8] + + inc 16,%o0 + addxcc %g3,%g4,%g3 + st %g3,[%o0-4] + addx %g0,0,%g1 + andcc %o3,-4,%g0 + bnz,a .L_bn_add_words_loop + addcc %g1,-1,%g0 + + tst %o3 + bnz,a .L_bn_add_words_tail + ld [%o1],%o4 +.L_bn_add_words_return: + retl + mov %g1,%o0 + +.L_bn_add_words_tail: + addcc %g1,-1,%g0 + ld [%o2],%o5 + addxcc %o5,%o4,%o5 + addx %g0,0,%g1 + deccc %o3 + bz .L_bn_add_words_return + st %o5,[%o0] + + ld [%o1+4],%o4 + addcc %g1,-1,%g0 + ld [%o2+4],%o5 + addxcc %o5,%o4,%o5 + addx %g0,0,%g1 + deccc %o3 + bz .L_bn_add_words_return + st %o5,[%o0+4] + + ld [%o1+8],%o4 + addcc %g1,-1,%g0 + ld [%o2+8],%o5 + addxcc %o5,%o4,%o5 + st %o5,[%o0+8] + retl + addx %g0,0,%o0 + +.type bn_add_words,#function +.size bn_add_words,(.-bn_add_words) + +.align 32 + +.global bn_sub_words +/* + * BN_ULONG bn_sub_words(rp,ap,bp,n) + * BN_ULONG *rp,*ap,*bp; + * int n; + */ +bn_sub_words: + cmp %o3,0 + bg,a .L_bn_sub_words_proceed + ld [%o1],%o4 + retl + clr %o0 + +.L_bn_sub_words_proceed: + andcc %o3,-4,%g0 + bz .L_bn_sub_words_tail + clr %g1 + ba .L_bn_sub_words_warm_loop + addcc %g0,0,%g0 ! clear carry flag + +.L_bn_sub_words_loop: + ld [%o1],%o4 +.L_bn_sub_words_warm_loop: + ld [%o2],%o5 + ld [%o1+4],%g3 + ld [%o2+4],%g4 + dec 4,%o3 + subxcc %o4,%o5,%o5 + st %o5,[%o0] + + ld [%o1+8],%o4 + ld [%o2+8],%o5 + inc 16,%o1 + subxcc %g3,%g4,%g4 + st %g4,[%o0+4] + + ld [%o1-4],%g3 + ld [%o2+12],%g4 + inc 16,%o2 + subxcc %o4,%o5,%o5 + st %o5,[%o0+8] + + inc 16,%o0 + subxcc %g3,%g4,%g4 + st %g4,[%o0-4] + addx %g0,0,%g1 + andcc %o3,-4,%g0 + bnz,a .L_bn_sub_words_loop + addcc %g1,-1,%g0 + + tst %o3 + nop + bnz,a .L_bn_sub_words_tail + ld [%o1],%o4 +.L_bn_sub_words_return: + retl + mov %g1,%o0 + +.L_bn_sub_words_tail: + addcc %g1,-1,%g0 + ld [%o2],%o5 + subxcc %o4,%o5,%o5 + addx %g0,0,%g1 + deccc %o3 + bz .L_bn_sub_words_return + st %o5,[%o0] + nop + + ld [%o1+4],%o4 + addcc %g1,-1,%g0 + ld [%o2+4],%o5 + subxcc %o4,%o5,%o5 + addx %g0,0,%g1 + deccc %o3 + bz .L_bn_sub_words_return + st %o5,[%o0+4] + + ld [%o1+8],%o4 + addcc %g1,-1,%g0 + ld [%o2+8],%o5 + subxcc %o4,%o5,%o5 + st %o5,[%o0+8] + retl + addx %g0,0,%o0 + +.type bn_sub_words,#function +.size bn_sub_words,(.-bn_sub_words) + +#define FRAME_SIZE -96 + +/* + * Here is register usage map for *all* routines below. + */ +#define t_1 %o0 +#define t_2 %o1 +#define c_1 %o2 +#define c_2 %o3 +#define c_3 %o4 + +#define ap(I) [%i1+4*I] +#define bp(I) [%i2+4*I] +#define rp(I) [%i0+4*I] + +#define a_0 %l0 +#define a_1 %l1 +#define a_2 %l2 +#define a_3 %l3 +#define a_4 %l4 +#define a_5 %l5 +#define a_6 %l6 +#define a_7 %l7 + +#define b_0 %i3 +#define b_1 %i4 +#define b_2 %i5 +#define b_3 %o5 +#define b_4 %g1 +#define b_5 %g2 +#define b_6 %g3 +#define b_7 %g4 + +.align 32 +.global bn_mul_comba8 +/* + * void bn_mul_comba8(r,a,b) + * BN_ULONG *r,*a,*b; + */ +bn_mul_comba8: + save %sp,FRAME_SIZE,%sp + ld ap(0),a_0 + ld bp(0),b_0 + umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3); + ld bp(1),b_1 + rd %y,c_2 + st c_1,rp(0) !r[0]=c1; + + umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1); + ld ap(1),a_1 + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc %g0,t_2,c_3 != + addx %g0,%g0,c_1 + ld ap(2),a_2 + umul a_1,b_0,t_1 !mul_add_c(a[1],b[0],c2,c3,c1); + addcc c_2,t_1,c_2 != + rd %y,t_2 + addxcc c_3,t_2,c_3 + st c_2,rp(1) !r[1]=c2; + addx c_1,%g0,c_1 != + + umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx %g0,%g0,c_2 + ld bp(2),b_2 + umul a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + ld bp(3),b_3 + addx c_2,%g0,c_2 != + umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx c_2,%g0,c_2 + st c_3,rp(2) !r[2]=c3; + + umul a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx %g0,%g0,c_3 + umul a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + ld ap(3),a_3 + umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 != + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + ld ap(4),a_4 + umul a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!= + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + st c_1,rp(3) !r[3]=c1; + + umul a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx %g0,%g0,c_1 + umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1); + addcc c_2,t_1,c_2 != + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + umul a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 != + ld bp(4),b_4 + umul a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + ld bp(5),b_5 + umul a_0,b_4,t_1 !=!mul_add_c(a[0],b[4],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 != + st c_2,rp(4) !r[4]=c2; + + umul a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 + umul a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + umul a_2,b_3,t_1 !=!mul_add_c(a[2],b[3],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 != + umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx c_2,%g0,c_2 + ld ap(5),a_5 + umul a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + ld ap(6),a_6 + addx c_2,%g0,c_2 != + umul a_5,b_0,t_1 !mul_add_c(a[5],b[0],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx c_2,%g0,c_2 + st c_3,rp(5) !r[5]=c3; + + umul a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx %g0,%g0,c_3 + umul a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + umul a_4,b_2,t_1 !mul_add_c(a[4],b[2],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 != + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + umul a_2,b_4,t_1 !mul_add_c(a[2],b[4],c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + ld bp(6),b_6 + addx c_3,%g0,c_3 != + umul a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + ld bp(7),b_7 + umul a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + st c_1,rp(6) !r[6]=c1; + addx c_3,%g0,c_3 != + + umul a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 != + addx %g0,%g0,c_1 + umul a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + umul a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1); + addcc c_2,t_1,c_2 != + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + umul a_3,b_4,t_1 !=!mul_add_c(a[3],b[4],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 != + umul a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + ld ap(7),a_7 + umul a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 != + umul a_7,b_0,t_1 !mul_add_c(a[7],b[0],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + st c_2,rp(7) !r[7]=c2; + + umul a_7,b_1,t_1 !mul_add_c(a[7],b[1],c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 + umul a_6,b_2,t_1 !=!mul_add_c(a[6],b[2],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 != + umul a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx c_2,%g0,c_2 + umul a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + umul a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + umul a_2,b_6,t_1 !=!mul_add_c(a[2],b[6],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 != + umul a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 ! + addx c_2,%g0,c_2 + st c_3,rp(8) !r[8]=c3; + + umul a_2,b_7,t_1 !mul_add_c(a[2],b[7],c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx %g0,%g0,c_3 + umul a_3,b_6,t_1 !=!mul_add_c(a[3],b[6],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + umul a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + umul a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 != + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + umul a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + umul a_7,b_2,t_1 !=!mul_add_c(a[7],b[2],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + st c_1,rp(9) !r[9]=c1; + + umul a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx %g0,%g0,c_1 + umul a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1); + addcc c_2,t_1,c_2 != + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + umul a_5,b_5,t_1 !=!mul_add_c(a[5],b[5],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 != + umul a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + st c_2,rp(10) !r[10]=c2; + + umul a_4,b_7,t_1 !=!mul_add_c(a[4],b[7],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 != + umul a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx c_2,%g0,c_2 + umul a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + umul a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + st c_3,rp(11) !r[11]=c3; + addx c_2,%g0,c_2 != + + umul a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx %g0,%g0,c_3 + umul a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 != + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + umul a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + st c_1,rp(12) !r[12]=c1; + addx c_3,%g0,c_3 != + + umul a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 != + addx %g0,%g0,c_1 + umul a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + st c_2,rp(13) !r[13]=c2; + + umul a_7,b_7,t_1 !=!mul_add_c(a[7],b[7],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + nop != + st c_3,rp(14) !r[14]=c3; + st c_1,rp(15) !r[15]=c1; + + ret + restore %g0,%g0,%o0 + +.type bn_mul_comba8,#function +.size bn_mul_comba8,(.-bn_mul_comba8) + +.align 32 + +.global bn_mul_comba4 +/* + * void bn_mul_comba4(r,a,b) + * BN_ULONG *r,*a,*b; + */ +bn_mul_comba4: + save %sp,FRAME_SIZE,%sp + ld ap(0),a_0 + ld bp(0),b_0 + umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3); + ld bp(1),b_1 + rd %y,c_2 + st c_1,rp(0) !r[0]=c1; + + umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1); + ld ap(1),a_1 + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc %g0,t_2,c_3 + addx %g0,%g0,c_1 + ld ap(2),a_2 + umul a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 != + st c_2,rp(1) !r[1]=c2; + + umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 + ld bp(2),b_2 + umul a_1,b_1,t_1 !=!mul_add_c(a[1],b[1],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 != + ld bp(3),b_3 + umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + st c_3,rp(2) !r[2]=c3; + + umul a_0,b_3,t_1 !=!mul_add_c(a[0],b[3],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx %g0,%g0,c_3 != + umul a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + ld ap(3),a_3 + umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + umul a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + st c_1,rp(3) !r[3]=c1; + + umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx %g0,%g0,c_1 + umul a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1); + addcc c_2,t_1,c_2 != + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + umul a_1,b_3,t_1 !=!mul_add_c(a[1],b[3],c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 != + st c_2,rp(4) !r[4]=c2; + + umul a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 + umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + st c_3,rp(5) !r[5]=c3; + addx c_2,%g0,c_2 != + + umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + st c_1,rp(6) !r[6]=c1; + st c_2,rp(7) !r[7]=c2; + + ret + restore %g0,%g0,%o0 + +.type bn_mul_comba4,#function +.size bn_mul_comba4,(.-bn_mul_comba4) + +.align 32 + +.global bn_sqr_comba8 +bn_sqr_comba8: + save %sp,FRAME_SIZE,%sp + ld ap(0),a_0 + ld ap(1),a_1 + umul a_0,a_0,c_1 !=!sqr_add_c(a,0,c1,c2,c3); + rd %y,c_2 + st c_1,rp(0) !r[0]=c1; + + ld ap(2),a_2 + umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc %g0,t_2,c_3 + addx %g0,%g0,c_1 != + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 + st c_2,rp(1) !r[1]=c2; + addx c_1,%g0,c_1 != + + umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx %g0,%g0,c_2 + addcc c_3,t_1,c_3 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 != + ld ap(3),a_3 + umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + st c_3,rp(2) !r[2]=c3; + + umul a_0,a_3,t_1 !=!sqr_add_c2(a,3,0,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx %g0,%g0,c_3 != + addcc c_1,t_1,c_1 + addxcc c_2,t_2,c_2 + ld ap(4),a_4 + addx c_3,%g0,c_3 != + umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + addcc c_1,t_1,c_1 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + st c_1,rp(3) !r[3]=c1; + + umul a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx %g0,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + ld ap(5),a_5 + umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1); + addcc c_2,t_1,c_2 != + rd %y,t_2 + addxcc c_3,t_2,c_3 + st c_2,rp(4) !r[4]=c2; + addx c_1,%g0,c_1 != + + umul a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx %g0,%g0,c_2 + addcc c_3,t_1,c_3 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 != + umul a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + addx c_2,%g0,c_2 + addcc c_3,t_1,c_3 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 != + ld ap(6),a_6 + umul a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + addcc c_3,t_1,c_3 + addxcc c_1,t_2,c_1 != + addx c_2,%g0,c_2 + st c_3,rp(5) !r[5]=c3; + + umul a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx %g0,%g0,c_3 + addcc c_1,t_1,c_1 != + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + umul a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + addcc c_1,t_1,c_1 != + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + umul a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3); + addcc c_1,t_1,c_1 != + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + addcc c_1,t_1,c_1 != + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 + ld ap(7),a_7 + umul a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + st c_1,rp(6) !r[6]=c1; + + umul a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx %g0,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + st c_2,rp(7) !r[7]=c2; + + umul a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 + addcc c_3,t_1,c_3 != + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + umul a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + addcc c_3,t_1,c_3 != + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + umul a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + addcc c_3,t_1,c_3 != + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + umul a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + st c_3,rp(8) !r[8]=c3; + addx c_2,%g0,c_2 != + + umul a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx %g0,%g0,c_3 + addcc c_1,t_1,c_1 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + umul a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + addcc c_1,t_1,c_1 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + umul a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + addcc c_1,t_1,c_1 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + st c_1,rp(9) !r[9]=c1; + + umul a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx %g0,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + st c_2,rp(10) !r[10]=c2; + + umul a_4,a_7,t_1 !=!sqr_add_c2(a,7,4,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 != + addcc c_3,t_1,c_3 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 + umul a_5,a_6,t_1 !=!sqr_add_c2(a,6,5,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx c_2,%g0,c_2 != + addcc c_3,t_1,c_3 + addxcc c_1,t_2,c_1 + st c_3,rp(11) !r[11]=c3; + addx c_2,%g0,c_2 != + + umul a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx %g0,%g0,c_3 + addcc c_1,t_1,c_1 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + umul a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + st c_1,rp(12) !r[12]=c1; + + umul a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1); + addcc c_2,t_1,c_2 != + rd %y,t_2 + addxcc c_3,t_2,c_3 + addx %g0,%g0,c_1 + addcc c_2,t_1,c_2 != + addxcc c_3,t_2,c_3 + st c_2,rp(13) !r[13]=c2; + addx c_1,%g0,c_1 != + + umul a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 != + st c_3,rp(14) !r[14]=c3; + st c_1,rp(15) !r[15]=c1; + + ret + restore %g0,%g0,%o0 + +.type bn_sqr_comba8,#function +.size bn_sqr_comba8,(.-bn_sqr_comba8) + +.align 32 + +.global bn_sqr_comba4 +/* + * void bn_sqr_comba4(r,a) + * BN_ULONG *r,*a; + */ +bn_sqr_comba4: + save %sp,FRAME_SIZE,%sp + ld ap(0),a_0 + umul a_0,a_0,c_1 !sqr_add_c(a,0,c1,c2,c3); + ld ap(1),a_1 != + rd %y,c_2 + st c_1,rp(0) !r[0]=c1; + + ld ap(2),a_2 + umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 + addxcc %g0,t_2,c_3 + addx %g0,%g0,c_1 != + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 != + st c_2,rp(1) !r[1]=c2; + + umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 != + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 + addcc c_3,t_1,c_3 + addxcc c_1,t_2,c_1 != + addx c_2,%g0,c_2 + ld ap(3),a_3 + umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2); + addcc c_3,t_1,c_3 != + rd %y,t_2 + addxcc c_1,t_2,c_1 + st c_3,rp(2) !r[2]=c3; + addx c_2,%g0,c_2 != + + umul a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx %g0,%g0,c_3 + addcc c_1,t_1,c_1 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + addx c_3,%g0,c_3 + addcc c_1,t_1,c_1 + addxcc c_2,t_2,c_2 + addx c_3,%g0,c_3 != + st c_1,rp(3) !r[3]=c1; + + umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx %g0,%g0,c_1 + addcc c_2,t_1,c_2 + addxcc c_3,t_2,c_3 != + addx c_1,%g0,c_1 + umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1); + addcc c_2,t_1,c_2 + rd %y,t_2 != + addxcc c_3,t_2,c_3 + addx c_1,%g0,c_1 + st c_2,rp(4) !r[4]=c2; + + umul a_2,a_3,t_1 !=!sqr_add_c2(a,3,2,c3,c1,c2); + addcc c_3,t_1,c_3 + rd %y,t_2 + addxcc c_1,t_2,c_1 + addx %g0,%g0,c_2 != + addcc c_3,t_1,c_3 + addxcc c_1,t_2,c_1 + st c_3,rp(5) !r[5]=c3; + addx c_2,%g0,c_2 != + + umul a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3); + addcc c_1,t_1,c_1 + rd %y,t_2 + addxcc c_2,t_2,c_2 != + st c_1,rp(6) !r[6]=c1; + st c_2,rp(7) !r[7]=c2; + + ret + restore %g0,%g0,%o0 + +.type bn_sqr_comba4,#function +.size bn_sqr_comba4,(.-bn_sqr_comba4) + +.align 32 diff --git a/src/lib/libcrypto/bn/asm/sparcv8plus.S b/src/lib/libcrypto/bn/asm/sparcv8plus.S new file mode 100644 index 0000000000..0074dfdb75 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/sparcv8plus.S @@ -0,0 +1,1535 @@ +.ident "sparcv8plus.s, Version 1.4" +.ident "SPARC v9 ISA artwork by Andy Polyakov " + +/* + * ==================================================================== + * Written by Andy Polyakov for the OpenSSL + * project. + * + * Rights for redistribution and usage in source and binary forms are + * granted according to the OpenSSL license. Warranty of any kind is + * disclaimed. + * ==================================================================== + */ + +/* + * This is my modest contributon to OpenSSL project (see + * http://www.openssl.org/ for more information about it) and is + * a drop-in UltraSPARC ISA replacement for crypto/bn/bn_asm.c + * module. For updates see http://fy.chalmers.se/~appro/hpe/. + * + * Questions-n-answers. + * + * Q. How to compile? + * A. With SC4.x/SC5.x: + * + * cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o + * + * and with gcc: + * + * gcc -mcpu=ultrasparc -c bn_asm.sparc.v8plus.S -o bn_asm.o + * + * or if above fails (it does if you have gas installed): + * + * gcc -E bn_asm.sparc.v8plus.S | as -xarch=v8plus /dev/fd/0 -o bn_asm.o + * + * Quick-n-dirty way to fuse the module into the library. + * Provided that the library is already configured and built + * (in 0.9.2 case with no-asm option): + * + * # cd crypto/bn + * # cp /some/place/bn_asm.sparc.v8plus.S . + * # cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o + * # make + * # cd ../.. + * # make; make test + * + * Quick-n-dirty way to get rid of it: + * + * # cd crypto/bn + * # touch bn_asm.c + * # make + * # cd ../.. + * # make; make test + * + * Q. V8plus achitecture? What kind of beast is that? + * A. Well, it's rather a programming model than an architecture... + * It's actually v9-compliant, i.e. *any* UltraSPARC, CPU under + * special conditions, namely when kernel doesn't preserve upper + * 32 bits of otherwise 64-bit registers during a context switch. + * + * Q. Why just UltraSPARC? What about SuperSPARC? + * A. Original release did target UltraSPARC only. Now SuperSPARC + * version is provided along. Both version share bn_*comba[48] + * implementations (see comment later in code for explanation). + * But what's so special about this UltraSPARC implementation? + * Why didn't I let compiler do the job? Trouble is that most of + * available compilers (well, SC5.0 is the only exception) don't + * attempt to take advantage of UltraSPARC's 64-bitness under + * 32-bit kernels even though it's perfectly possible (see next + * question). + * + * Q. 64-bit registers under 32-bit kernels? Didn't you just say it + * doesn't work? + * A. You can't adress *all* registers as 64-bit wide:-( The catch is + * that you actually may rely upon %o0-%o5 and %g1-%g4 being fully + * preserved if you're in a leaf function, i.e. such never calling + * any other functions. All functions in this module are leaf and + * 10 registers is a handful. And as a matter of fact none-"comba" + * routines don't require even that much and I could even afford to + * not allocate own stack frame for 'em:-) + * + * Q. What about 64-bit kernels? + * A. What about 'em? Just kidding:-) Pure 64-bit version is currently + * under evaluation and development... + * + * Q. What about shared libraries? + * A. What about 'em? Kidding again:-) Code does *not* contain any + * code position dependencies and it's safe to include it into + * shared library as is. + * + * Q. How much faster does it go? + * A. Do you have a good benchmark? In either case below is what I + * experience with crypto/bn/expspeed.c test program: + * + * v8plus module on U10/300MHz against bn_asm.c compiled with: + * + * cc-5.0 -xarch=v8plus -xO5 -xdepend +7-12% + * cc-4.2 -xarch=v8plus -xO5 -xdepend +25-35% + * egcs-1.1.2 -mcpu=ultrasparc -O3 +35-45% + * + * v8 module on SS10/60MHz against bn_asm.c compiled with: + * + * cc-5.0 -xarch=v8 -xO5 -xdepend +7-10% + * cc-4.2 -xarch=v8 -xO5 -xdepend +10% + * egcs-1.1.2 -mv8 -O3 +35-45% + * + * As you can see it's damn hard to beat the new Sun C compiler + * and it's in first place GNU C users who will appreciate this + * assembler implementation:-) + */ + +/* + * Revision history. + * + * 1.0 - initial release; + * 1.1 - new loop unrolling model(*); + * - some more fine tuning; + * 1.2 - made gas friendly; + * - updates to documentation concerning v9; + * - new performance comparison matrix; + * 1.3 - fixed problem with /usr/ccs/lib/cpp; + * 1.4 - native V9 bn_*_comba[48] implementation (15% more efficient) + * resulting in slight overall performance kick; + * - some retunes; + * - support for GNU as added; + * + * (*) Originally unrolled loop looked like this: + * for (;;) { + * op(p+0); if (--n==0) break; + * op(p+1); if (--n==0) break; + * op(p+2); if (--n==0) break; + * op(p+3); if (--n==0) break; + * p+=4; + * } + * I unroll according to following: + * while (n&~3) { + * op(p+0); op(p+1); op(p+2); op(p+3); + * p+=4; n=-4; + * } + * if (n) { + * op(p+0); if (--n==0) return; + * op(p+2); if (--n==0) return; + * op(p+3); return; + * } + */ + +/* + * GNU assembler can't stand stuw:-( + */ +#define stuw st + +.section ".text",#alloc,#execinstr +.file "bn_asm.sparc.v8plus.S" + +.align 32 + +.global bn_mul_add_words +/* + * BN_ULONG bn_mul_add_words(rp,ap,num,w) + * BN_ULONG *rp,*ap; + * int num; + * BN_ULONG w; + */ +bn_mul_add_words: + brgz,a %o2,.L_bn_mul_add_words_proceed + lduw [%o1],%g2 + retl + clr %o0 + +.L_bn_mul_add_words_proceed: + srl %o3,%g0,%o3 ! clruw %o3 + andcc %o2,-4,%g0 + bz,pn %icc,.L_bn_mul_add_words_tail + clr %o5 + +.L_bn_mul_add_words_loop: ! wow! 32 aligned! + lduw [%o0],%g1 + lduw [%o1+4],%g3 + mulx %o3,%g2,%g2 + add %g1,%o5,%o4 + nop + add %o4,%g2,%o4 + stuw %o4,[%o0] + srlx %o4,32,%o5 + + lduw [%o0+4],%g1 + lduw [%o1+8],%g2 + mulx %o3,%g3,%g3 + add %g1,%o5,%o4 + dec 4,%o2 + add %o4,%g3,%o4 + stuw %o4,[%o0+4] + srlx %o4,32,%o5 + + lduw [%o0+8],%g1 + lduw [%o1+12],%g3 + mulx %o3,%g2,%g2 + add %g1,%o5,%o4 + inc 16,%o1 + add %o4,%g2,%o4 + stuw %o4,[%o0+8] + srlx %o4,32,%o5 + + lduw [%o0+12],%g1 + mulx %o3,%g3,%g3 + add %g1,%o5,%o4 + inc 16,%o0 + add %o4,%g3,%o4 + andcc %o2,-4,%g0 + stuw %o4,[%o0-4] + srlx %o4,32,%o5 + bnz,a,pt %icc,.L_bn_mul_add_words_loop + lduw [%o1],%g2 + + brnz,a,pn %o2,.L_bn_mul_add_words_tail + lduw [%o1],%g2 +.L_bn_mul_add_words_return: + retl + mov %o5,%o0 + +.L_bn_mul_add_words_tail: + lduw [%o0],%g1 + mulx %o3,%g2,%g2 + add %g1,%o5,%o4 + dec %o2 + add %o4,%g2,%o4 + srlx %o4,32,%o5 + brz,pt %o2,.L_bn_mul_add_words_return + stuw %o4,[%o0] + + lduw [%o1+4],%g2 + lduw [%o0+4],%g1 + mulx %o3,%g2,%g2 + add %g1,%o5,%o4 + dec %o2 + add %o4,%g2,%o4 + srlx %o4,32,%o5 + brz,pt %o2,.L_bn_mul_add_words_return + stuw %o4,[%o0+4] + + lduw [%o1+8],%g2 + lduw [%o0+8],%g1 + mulx %o3,%g2,%g2 + add %g1,%o5,%o4 + add %o4,%g2,%o4 + stuw %o4,[%o0+8] + retl + srlx %o4,32,%o0 + +.type bn_mul_add_words,#function +.size bn_mul_add_words,(.-bn_mul_add_words) + +.align 32 + +.global bn_mul_words +/* + * BN_ULONG bn_mul_words(rp,ap,num,w) + * BN_ULONG *rp,*ap; + * int num; + * BN_ULONG w; + */ +bn_mul_words: + brgz,a %o2,.L_bn_mul_words_proceeed + lduw [%o1],%g2 + retl + clr %o0 + +.L_bn_mul_words_proceeed: + srl %o3,%g0,%o3 ! clruw %o3 + andcc %o2,-4,%g0 + bz,pn %icc,.L_bn_mul_words_tail + clr %o5 + +.L_bn_mul_words_loop: ! wow! 32 aligned! + lduw [%o1+4],%g3 + mulx %o3,%g2,%g2 + add %g2,%o5,%o4 + nop + stuw %o4,[%o0] + srlx %o4,32,%o5 + + lduw [%o1+8],%g2 + mulx %o3,%g3,%g3 + add %g3,%o5,%o4 + dec 4,%o2 + stuw %o4,[%o0+4] + srlx %o4,32,%o5 + + lduw [%o1+12],%g3 + mulx %o3,%g2,%g2 + add %g2,%o5,%o4 + inc 16,%o1 + stuw %o4,[%o0+8] + srlx %o4,32,%o5 + + mulx %o3,%g3,%g3 + add %g3,%o5,%o4 + inc 16,%o0 + stuw %o4,[%o0-4] + srlx %o4,32,%o5 + andcc %o2,-4,%g0 + bnz,a,pt %icc,.L_bn_mul_words_loop + lduw [%o1],%g2 + nop + nop + + brnz,a,pn %o2,.L_bn_mul_words_tail + lduw [%o1],%g2 +.L_bn_mul_words_return: + retl + mov %o5,%o0 + +.L_bn_mul_words_tail: + mulx %o3,%g2,%g2 + add %g2,%o5,%o4 + dec %o2 + srlx %o4,32,%o5 + brz,pt %o2,.L_bn_mul_words_return + stuw %o4,[%o0] + + lduw [%o1+4],%g2 + mulx %o3,%g2,%g2 + add %g2,%o5,%o4 + dec %o2 + srlx %o4,32,%o5 + brz,pt %o2,.L_bn_mul_words_return + stuw %o4,[%o0+4] + + lduw [%o1+8],%g2 + mulx %o3,%g2,%g2 + add %g2,%o5,%o4 + stuw %o4,[%o0+8] + retl + srlx %o4,32,%o0 + +.type bn_mul_words,#function +.size bn_mul_words,(.-bn_mul_words) + +.align 32 +.global bn_sqr_words +/* + * void bn_sqr_words(r,a,n) + * BN_ULONG *r,*a; + * int n; + */ +bn_sqr_words: + brgz,a %o2,.L_bn_sqr_words_proceeed + lduw [%o1],%g2 + retl + clr %o0 + +.L_bn_sqr_words_proceeed: + andcc %o2,-4,%g0 + nop + bz,pn %icc,.L_bn_sqr_words_tail + nop + +.L_bn_sqr_words_loop: ! wow! 32 aligned! + lduw [%o1+4],%g3 + mulx %g2,%g2,%o4 + stuw %o4,[%o0] + srlx %o4,32,%o5 + stuw %o5,[%o0+4] + nop + + lduw [%o1+8],%g2 + mulx %g3,%g3,%o4 + dec 4,%o2 + stuw %o4,[%o0+8] + srlx %o4,32,%o5 + stuw %o5,[%o0+12] + + lduw [%o1+12],%g3 + mulx %g2,%g2,%o4 + srlx %o4,32,%o5 + stuw %o4,[%o0+16] + inc 16,%o1 + stuw %o5,[%o0+20] + + mulx %g3,%g3,%o4 + inc 32,%o0 + stuw %o4,[%o0-8] + srlx %o4,32,%o5 + andcc %o2,-4,%g2 + stuw %o5,[%o0-4] + bnz,a,pt %icc,.L_bn_sqr_words_loop + lduw [%o1],%g2 + nop + + brnz,a,pn %o2,.L_bn_sqr_words_tail + lduw [%o1],%g2 +.L_bn_sqr_words_return: + retl + clr %o0 + +.L_bn_sqr_words_tail: + mulx %g2,%g2,%o4 + dec %o2 + stuw %o4,[%o0] + srlx %o4,32,%o5 + brz,pt %o2,.L_bn_sqr_words_return + stuw %o5,[%o0+4] + + lduw [%o1+4],%g2 + mulx %g2,%g2,%o4 + dec %o2 + stuw %o4,[%o0+8] + srlx %o4,32,%o5 + brz,pt %o2,.L_bn_sqr_words_return + stuw %o5,[%o0+12] + + lduw [%o1+8],%g2 + mulx %g2,%g2,%o4 + srlx %o4,32,%o5 + stuw %o4,[%o0+16] + stuw %o5,[%o0+20] + retl + clr %o0 + +.type bn_sqr_words,#function +.size bn_sqr_words,(.-bn_sqr_words) + +.align 32 +.global bn_div_words +/* + * BN_ULONG bn_div_words(h,l,d) + * BN_ULONG h,l,d; + */ +bn_div_words: + sllx %o0,32,%o0 + or %o0,%o1,%o0 + udivx %o0,%o2,%o0 + retl + srl %o0,%g0,%o0 ! clruw %o0 + +.type bn_div_words,#function +.size bn_div_words,(.-bn_div_words) + +.align 32 + +.global bn_add_words +/* + * BN_ULONG bn_add_words(rp,ap,bp,n) + * BN_ULONG *rp,*ap,*bp; + * int n; + */ +bn_add_words: + brgz,a %o3,.L_bn_add_words_proceed + lduw [%o1],%o4 + retl + clr %o0 + +.L_bn_add_words_proceed: + andcc %o3,-4,%g0 + bz,pn %icc,.L_bn_add_words_tail + addcc %g0,0,%g0 ! clear carry flag + nop + +.L_bn_add_words_loop: ! wow! 32 aligned! + dec 4,%o3 + lduw [%o2],%o5 + lduw [%o1+4],%g1 + lduw [%o2+4],%g2 + lduw [%o1+8],%g3 + lduw [%o2+8],%g4 + addccc %o5,%o4,%o5 + stuw %o5,[%o0] + + lduw [%o1+12],%o4 + lduw [%o2+12],%o5 + inc 16,%o1 + addccc %g1,%g2,%g1 + stuw %g1,[%o0+4] + + inc 16,%o2 + addccc %g3,%g4,%g3 + stuw %g3,[%o0+8] + + inc 16,%o0 + addccc %o5,%o4,%o5 + stuw %o5,[%o0-4] + and %o3,-4,%g1 + brnz,a,pt %g1,.L_bn_add_words_loop + lduw [%o1],%o4 + + brnz,a,pn %o3,.L_bn_add_words_tail + lduw [%o1],%o4 +.L_bn_add_words_return: + clr %o0 + retl + movcs %icc,1,%o0 + nop + +.L_bn_add_words_tail: + lduw [%o2],%o5 + dec %o3 + addccc %o5,%o4,%o5 + brz,pt %o3,.L_bn_add_words_return + stuw %o5,[%o0] + + lduw [%o1+4],%o4 + lduw [%o2+4],%o5 + dec %o3 + addccc %o5,%o4,%o5 + brz,pt %o3,.L_bn_add_words_return + stuw %o5,[%o0+4] + + lduw [%o1+8],%o4 + lduw [%o2+8],%o5 + addccc %o5,%o4,%o5 + stuw %o5,[%o0+8] + clr %o0 + retl + movcs %icc,1,%o0 + +.type bn_add_words,#function +.size bn_add_words,(.-bn_add_words) + +.global bn_sub_words +/* + * BN_ULONG bn_sub_words(rp,ap,bp,n) + * BN_ULONG *rp,*ap,*bp; + * int n; + */ +bn_sub_words: + brgz,a %o3,.L_bn_sub_words_proceed + lduw [%o1],%o4 + retl + clr %o0 + +.L_bn_sub_words_proceed: + andcc %o3,-4,%g0 + bz,pn %icc,.L_bn_sub_words_tail + addcc %g0,0,%g0 ! clear carry flag + nop + +.L_bn_sub_words_loop: ! wow! 32 aligned! + dec 4,%o3 + lduw [%o2],%o5 + lduw [%o1+4],%g1 + lduw [%o2+4],%g2 + lduw [%o1+8],%g3 + lduw [%o2+8],%g4 + subccc %o4,%o5,%o5 + stuw %o5,[%o0] + + lduw [%o1+12],%o4 + lduw [%o2+12],%o5 + inc 16,%o1 + subccc %g1,%g2,%g2 + stuw %g2,[%o0+4] + + inc 16,%o2 + subccc %g3,%g4,%g4 + stuw %g4,[%o0+8] + + inc 16,%o0 + subccc %o4,%o5,%o5 + stuw %o5,[%o0-4] + and %o3,-4,%g1 + brnz,a,pt %g1,.L_bn_sub_words_loop + lduw [%o1],%o4 + + brnz,a,pn %o3,.L_bn_sub_words_tail + lduw [%o1],%o4 +.L_bn_sub_words_return: + clr %o0 + retl + movcs %icc,1,%o0 + nop + +.L_bn_sub_words_tail: ! wow! 32 aligned! + lduw [%o2],%o5 + dec %o3 + subccc %o4,%o5,%o5 + brz,pt %o3,.L_bn_sub_words_return + stuw %o5,[%o0] + + lduw [%o1+4],%o4 + lduw [%o2+4],%o5 + dec %o3 + subccc %o4,%o5,%o5 + brz,pt %o3,.L_bn_sub_words_return + stuw %o5,[%o0+4] + + lduw [%o1+8],%o4 + lduw [%o2+8],%o5 + subccc %o4,%o5,%o5 + stuw %o5,[%o0+8] + clr %o0 + retl + movcs %icc,1,%o0 + +.type bn_sub_words,#function +.size bn_sub_words,(.-bn_sub_words) + +/* + * Code below depends on the fact that upper parts of the %l0-%l7 + * and %i0-%i7 are zeroed by kernel after context switch. In + * previous versions this comment stated that "the trouble is that + * it's not feasible to implement the mumbo-jumbo in less V9 + * instructions:-(" which apparently isn't true thanks to + * 'bcs,a %xcc,.+8; inc %rd' pair. But the performance improvement + * results not from the shorter code, but from elimination of + * multicycle none-pairable 'rd %y,%rd' instructions. + * + * Andy. + */ + +#define FRAME_SIZE -96 + +/* + * Here is register usage map for *all* routines below. + */ +#define t_1 %o0 +#define t_2 %o1 +#define c_12 %o2 +#define c_3 %o3 + +#define ap(I) [%i1+4*I] +#define bp(I) [%i2+4*I] +#define rp(I) [%i0+4*I] + +#define a_0 %l0 +#define a_1 %l1 +#define a_2 %l2 +#define a_3 %l3 +#define a_4 %l4 +#define a_5 %l5 +#define a_6 %l6 +#define a_7 %l7 + +#define b_0 %i3 +#define b_1 %i4 +#define b_2 %i5 +#define b_3 %o4 +#define b_4 %o5 +#define b_5 %o7 +#define b_6 %g1 +#define b_7 %g4 + +.align 32 +.global bn_mul_comba8 +/* + * void bn_mul_comba8(r,a,b) + * BN_ULONG *r,*a,*b; + */ +bn_mul_comba8: + save %sp,FRAME_SIZE,%sp + mov 1,t_2 + lduw ap(0),a_0 + sllx t_2,32,t_2 + lduw bp(0),b_0 != + lduw bp(1),b_1 + mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3); + srlx t_1,32,c_12 + stuw t_1,rp(0) !=!r[0]=c1; + + lduw ap(1),a_1 + mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(2),a_2 + mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 != + stuw t_1,rp(1) !r[1]=c2; + or c_12,c_3,c_12 + + mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2); + addcc c_12,t_1,c_12 != + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw bp(2),b_2 != + mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + lduw bp(3),b_3 + mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(2) !r[2]=c3; + or c_12,c_3,c_12 != + + mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + lduw ap(3),a_3 + mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3); + addcc c_12,t_1,c_12 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(4),a_4 + mulx a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);!= + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 != + stuw t_1,rp(3) !r[3]=c1; + or c_12,c_3,c_12 + + mulx a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1); + addcc c_12,t_1,c_12 != + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_3,b_1,t_1 !=!mul_add_c(a[3],b[1],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw bp(4),b_4 != + mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + lduw bp(5),b_5 + mulx a_0,b_4,t_1 !mul_add_c(a[0],b[4],c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(4) !r[4]=c2; + or c_12,c_3,c_12 != + + mulx a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + lduw ap(5),a_5 + mulx a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2); + addcc c_12,t_1,c_12 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(6),a_6 + mulx a_5,b_0,t_1 !=!mul_add_c(a[5],b[0],c3,c1,c2); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 != + stuw t_1,rp(5) !r[5]=c3; + or c_12,c_3,c_12 + + mulx a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3); + addcc c_12,t_1,c_12 != + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_4,b_2,t_1 !=!mul_add_c(a[4],b[2],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_3,b_3,t_1 !=!mul_add_c(a[3],b[3],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_2,b_4,t_1 !=!mul_add_c(a[2],b[4],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw bp(6),b_6 != + mulx a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + lduw bp(7),b_7 + mulx a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(6) !r[6]=c1; + or c_12,c_3,c_12 != + + mulx a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_3,b_4,t_1 !mul_add_c(a[3],b[4],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + lduw ap(7),a_7 + mulx a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_7,b_0,t_1 !=!mul_add_c(a[7],b[0],c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 != + stuw t_1,rp(7) !r[7]=c2; + or c_12,c_3,c_12 + + mulx a_7,b_1,t_1 !=!mul_add_c(a[7],b[1],c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + mulx a_6,b_2,t_1 !mul_add_c(a[6],b[2],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + mulx a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + mulx a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + mulx a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + mulx a_2,b_6,t_1 !mul_add_c(a[2],b[6],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + mulx a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + srlx t_1,32,c_12 + stuw t_1,rp(8) !r[8]=c3; + or c_12,c_3,c_12 + + mulx a_2,b_7,t_1 !=!mul_add_c(a[2],b[7],c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + mulx a_3,b_6,t_1 !mul_add_c(a[3],b[6],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_7,b_2,t_1 !mul_add_c(a[7],b[2],c1,c2,c3); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(9) !r[9]=c1; + or c_12,c_3,c_12 != + + mulx a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_5,b_5,t_1 !mul_add_c(a[5],b[5],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(10) !r[10]=c2; + or c_12,c_3,c_12 != + + mulx a_4,b_7,t_1 !mul_add_c(a[4],b[7],c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(11) !r[11]=c3; + or c_12,c_3,c_12 != + + mulx a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(12) !r[12]=c1; + or c_12,c_3,c_12 != + + mulx a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + st t_1,rp(13) !r[13]=c2; + or c_12,c_3,c_12 != + + mulx a_7,b_7,t_1 !mul_add_c(a[7],b[7],c3,c1,c2); + addcc c_12,t_1,t_1 + srlx t_1,32,c_12 != + stuw t_1,rp(14) !r[14]=c3; + stuw c_12,rp(15) !r[15]=c1; + + ret + restore %g0,%g0,%o0 != + +.type bn_mul_comba8,#function +.size bn_mul_comba8,(.-bn_mul_comba8) + +.align 32 + +.global bn_mul_comba4 +/* + * void bn_mul_comba4(r,a,b) + * BN_ULONG *r,*a,*b; + */ +bn_mul_comba4: + save %sp,FRAME_SIZE,%sp + lduw ap(0),a_0 + mov 1,t_2 + lduw bp(0),b_0 + sllx t_2,32,t_2 != + lduw bp(1),b_1 + mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3); + srlx t_1,32,c_12 + stuw t_1,rp(0) !=!r[0]=c1; + + lduw ap(1),a_1 + mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(2),a_2 + mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 != + stuw t_1,rp(1) !r[1]=c2; + or c_12,c_3,c_12 + + mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2); + addcc c_12,t_1,c_12 != + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw bp(2),b_2 != + mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 != + lduw bp(3),b_3 + mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(2) !r[2]=c3; + or c_12,c_3,c_12 != + + mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + mulx a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 != + add c_3,t_2,c_3 + lduw ap(3),a_3 + mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3); + addcc c_12,t_1,c_12 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!= + addcc c_12,t_1,t_1 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(3) !=!r[3]=c1; + or c_12,c_3,c_12 + + mulx a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1); + addcc c_12,t_1,c_12 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1); + addcc c_12,t_1,t_1 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(4) !=!r[4]=c2; + or c_12,c_3,c_12 + + mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2); + addcc c_12,t_1,t_1 != + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(5) !=!r[5]=c3; + or c_12,c_3,c_12 + + mulx a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3); + addcc c_12,t_1,t_1 + srlx t_1,32,c_12 != + stuw t_1,rp(6) !r[6]=c1; + stuw c_12,rp(7) !r[7]=c2; + + ret + restore %g0,%g0,%o0 + +.type bn_mul_comba4,#function +.size bn_mul_comba4,(.-bn_mul_comba4) + +.align 32 + +.global bn_sqr_comba8 +bn_sqr_comba8: + save %sp,FRAME_SIZE,%sp + mov 1,t_2 + lduw ap(0),a_0 + sllx t_2,32,t_2 + lduw ap(1),a_1 + mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3); + srlx t_1,32,c_12 + stuw t_1,rp(0) !r[0]=c1; + + lduw ap(2),a_2 + mulx a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(1) !r[1]=c2; + or c_12,c_3,c_12 + + mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(3),a_3 + mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(2) !r[2]=c3; + or c_12,c_3,c_12 + + mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(4),a_4 + mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + st t_1,rp(3) !r[3]=c1; + or c_12,c_3,c_12 + + mulx a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(5),a_5 + mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(4) !r[4]=c2; + or c_12,c_3,c_12 + + mulx a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(6),a_6 + mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(5) !r[5]=c3; + or c_12,c_3,c_12 + + mulx a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(7),a_7 + mulx a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(6) !r[6]=c1; + or c_12,c_3,c_12 + + mulx a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(7) !r[7]=c2; + or c_12,c_3,c_12 + + mulx a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(8) !r[8]=c3; + or c_12,c_3,c_12 + + mulx a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(9) !r[9]=c1; + or c_12,c_3,c_12 + + mulx a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(10) !r[10]=c2; + or c_12,c_3,c_12 + + mulx a_4,a_7,t_1 !sqr_add_c2(a,7,4,c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_5,a_6,t_1 !sqr_add_c2(a,6,5,c3,c1,c2); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(11) !r[11]=c3; + or c_12,c_3,c_12 + + mulx a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(12) !r[12]=c1; + or c_12,c_3,c_12 + + mulx a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(13) !r[13]=c2; + or c_12,c_3,c_12 + + mulx a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2); + addcc c_12,t_1,t_1 + srlx t_1,32,c_12 + stuw t_1,rp(14) !r[14]=c3; + stuw c_12,rp(15) !r[15]=c1; + + ret + restore %g0,%g0,%o0 + +.type bn_sqr_comba8,#function +.size bn_sqr_comba8,(.-bn_sqr_comba8) + +.align 32 + +.global bn_sqr_comba4 +/* + * void bn_sqr_comba4(r,a) + * BN_ULONG *r,*a; + */ +bn_sqr_comba4: + save %sp,FRAME_SIZE,%sp + mov 1,t_2 + lduw ap(0),a_0 + sllx t_2,32,t_2 + lduw ap(1),a_1 + mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3); + srlx t_1,32,c_12 + stuw t_1,rp(0) !r[0]=c1; + + lduw ap(2),a_2 + mulx a_0,a_1,t_1 !sqr_add_c2(a,1,0,c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(1) !r[1]=c2; + or c_12,c_3,c_12 + + mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + lduw ap(3),a_3 + mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(2) !r[2]=c3; + or c_12,c_3,c_12 + + mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3); + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(3) !r[3]=c1; + or c_12,c_3,c_12 + + mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,c_12 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1); + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(4) !r[4]=c2; + or c_12,c_3,c_12 + + mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2); + addcc c_12,t_1,c_12 + clr c_3 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + addcc c_12,t_1,t_1 + bcs,a %xcc,.+8 + add c_3,t_2,c_3 + srlx t_1,32,c_12 + stuw t_1,rp(5) !r[5]=c3; + or c_12,c_3,c_12 + + mulx a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3); + addcc c_12,t_1,t_1 + srlx t_1,32,c_12 + stuw t_1,rp(6) !r[6]=c1; + stuw c_12,rp(7) !r[7]=c2; + + ret + restore %g0,%g0,%o0 + +.type bn_sqr_comba4,#function +.size bn_sqr_comba4,(.-bn_sqr_comba4) + +.align 32 diff --git a/src/lib/libcrypto/bn/asm/vms.mar b/src/lib/libcrypto/bn/asm/vms.mar new file mode 100644 index 0000000000..ac9d57d7b0 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/vms.mar @@ -0,0 +1,6695 @@ + .title vax_bn_mul_add_word unsigned multiply & add, 32*32+32+32=>64 +; +; w.j.m. 15-jan-1999 +; +; it's magic ... +; +; ULONG bn_mul_add_words(ULONG r[],ULONG a[],int n,ULONG w) { +; ULONG c = 0; +; int i; +; for(i = 0; i < n; i++) := r[i] + c + a[i] * w ; +; return c; +; } + +r=4 ;(AP) +a=8 ;(AP) +n=12 ;(AP) n by value (input) +w=16 ;(AP) w by value (input) + + + .psect code,nowrt + +.entry bn_mul_add_words,^m + + moval @r(ap),r2 + moval @a(ap),r3 + movl n(ap),r4 ; assumed >0 by C code + movl w(ap),r5 + clrl r6 ; c + +0$: + emul r5,(r3),(r2),r0 ; w, a[], r[] considered signed + + ; fixup for "negative" r[] + tstl (r2) + bgeq 10$ + incl r1 +10$: + + ; add in c + addl2 r6,r0 + adwc #0,r1 + + ; combined fixup for "negative" w, a[] + tstl r5 + bgeq 20$ + addl2 (r3),r1 +20$: + tstl (r3) + bgeq 30$ + addl2 r5,r1 +30$: + + movl r0,(r2)+ ; store lo result in r[] & advance + addl #4,r3 ; advance a[] + movl r1,r6 ; store hi result => c + + sobgtr r4,0$ + + movl r6,r0 ; return c + ret + + .title vax_bn_mul_word unsigned multiply & add, 32*32+32=>64 +; +; w.j.m. 15-jan-1999 +; +; it's magic ... +; +; ULONG bn_mul_words(ULONG r[],ULONG a[],int n,ULONG w) { +; ULONG c = 0; +; int i; +; for(i = 0; i < num; i++) := a[i] * w + c ; +; return(c); +; } + +r=4 ;(AP) +a=8 ;(AP) +n=12 ;(AP) n by value (input) +w=16 ;(AP) w by value (input) + + + .psect code,nowrt + +.entry bn_mul_words,^m + + moval @r(ap),r2 ; r2 -> r[] + moval @a(ap),r3 ; r3 -> a[] + movl n(ap),r4 ; r4 = loop count (assumed >0 by C code) + movl w(ap),r5 ; r5 = w + clrl r6 ; r6 = c + +0$: + ; := w * a[] + c + emul r5,(r3),r6,r0 ; w, a[], c considered signed + + ; fixup for "negative" c + tstl r6 ; c + bgeq 10$ + incl r1 +10$: + + ; combined fixup for "negative" w, a[] + tstl r5 ; w + bgeq 20$ + addl2 (r3),r1 ; a[] +20$: + tstl (r3) ; a[] + bgeq 30$ + addl2 r5,r1 ; w +30$: + + movl r0,(r2)+ ; store lo result in r[] & advance + addl #4,r3 ; advance a[] + movl r1,r6 ; store hi result => c + + sobgtr r4,0$ + + movl r6,r0 ; return c + ret + + .title vax_bn_sqr_words unsigned square, 32*32=>64 +; +; w.j.m. 15-jan-1999 +; +; it's magic ... +; +; void bn_sqr_words(ULONG r[],ULONG a[],int n) { +; int i; +; for(i = 0; i < n; i++) := a[i] * a[i] ; +; } + +r=4 ;(AP) +a=8 ;(AP) +n=12 ;(AP) n by value (input) + + + .psect code,nowrt + +.entry bn_sqr_words,^m + + moval @r(ap),r2 ; r2 -> r[] + moval @a(ap),r3 ; r3 -> a[] + movl n(ap),r4 ; r4 = n (assumed >0 by C code) + +0$: + movl (r3)+,r5 ; r5 = a[] & advance + + ; := a[] * a[] + emul r5,r5,#0,r0 ; a[] considered signed + + ; fixup for "negative" a[] + tstl r5 ; a[] + bgeq 30$ + addl2 r5,r1 ; a[] + addl2 r5,r1 ; a[] +30$: + + movl r0,(r2)+ ; store lo result in r[] & advance + movl r1,(r2)+ ; store hi result in r[] & advance + + sobgtr r4,0$ + + movl #1,r0 ; return SS$_NORMAL + ret + + .title (generated) + + .psect code,nowrt + +.entry BN_DIV_WORDS,^m + subl2 #4,sp + + clrl r9 + movl #2,r8 + + tstl 12(ap) + bneq noname.2 + mnegl #1,r10 + brw noname.3 + tstl r0 + nop +noname.2: + + pushl 12(ap) + calls #1,BN_NUM_BITS_WORD + movl r0,r7 + + cmpl r7,#32 + beql noname.4 + ashl r7,#1,r2 + cmpl 4(ap),r2 + blequ noname.4 + + pushl r7 + calls #1,BN_DIV_WORDS_ABORT +noname.4: + + subl3 r7,#32,r7 + + movl 12(ap),r2 + cmpl 4(ap),r2 + blssu noname.5 + subl2 r2,4(ap) +noname.5: + + tstl r7 + beql noname.6 + + ashl r7,r2,12(ap) + + ashl r7,4(ap),r4 + subl3 r7,#32,r3 + subl3 r3,#32,r2 + extzv r3,r2,8(ap),r2 + bisl3 r4,r2,4(ap) + + ashl r7,8(ap),8(ap) +noname.6: + + bicl3 #65535,12(ap),r2 + extzv #16,#16,r2,r5 + + bicl3 #-65536,12(ap),r6 + +noname.7: + + moval 4(ap),r2 + movzwl 2(r2),r0 + cmpl r0,r5 + bneq noname.8 + + movzwl #65535,r4 + brb noname.9 +noname.8: + + clrl r1 + movl (r2),r0 + movl r5,r2 + bgeq vcg.1 + cmpl r2,r0 + bgtru vcg.2 + incl r1 + brb vcg.2 + nop +vcg.1: + ediv r2,r0,r1,r0 +vcg.2: + movl r1,r4 +noname.9: + +noname.10: + + mull3 r5,r4,r0 + subl3 r0,4(ap),r3 + + bicl3 #65535,r3,r0 + bneq noname.13 + mull3 r6,r4,r2 + ashl #16,r3,r1 + bicl3 #65535,8(ap),r0 + extzv #16,#16,r0,r0 + addl2 r0,r1 + cmpl r2,r1 + bgtru noname.12 +noname.11: + + brb noname.13 + nop +noname.12: + + decl r4 + brb noname.10 +noname.13: + + mull3 r5,r4,r1 + + mull3 r6,r4,r0 + + extzv #16,#16,r0,r3 + + ashl #16,r0,r2 + bicl3 #65535,r2,r0 + + addl2 r3,r1 + + moval 8(ap),r3 + cmpl (r3),r0 + bgequ noname.15 + incl r1 +noname.15: + + subl2 r0,(r3) + + cmpl 4(ap),r1 + bgequ noname.16 + + addl2 12(ap),4(ap) + + decl r4 +noname.16: + + subl2 r1,4(ap) + + decl r8 + beql noname.18 +noname.17: + + ashl #16,r4,r9 + + ashl #16,4(ap),r2 + movzwl 2(r3),r0 + bisl2 r0,r2 + bicl3 #0,r2,4(ap) + + bicl3 #-65536,(r3),r0 + ashl #16,r0,(r3) + brw noname.7 + nop +noname.18: + + bisl2 r4,r9 + + movl r9,r10 + +noname.3: + movl r10,r0 + ret + tstl r0 + + + .psect code,nowrt + +.entry BN_ADD_WORDS,^m + + tstl 16(ap) + bgtr noname.21 + clrl r7 + brw noname.22 +noname.21: + + clrl r4 + + tstl r0 +noname.23: + + movl 8(ap),r6 + addl3 r4,(r6),r2 + + bicl2 #0,r2 + + clrl r0 + cmpl r2,r4 + bgequ vcg.3 + incl r0 +vcg.3: + movl r0,r4 + + movl 12(ap),r5 + addl3 (r5),r2,r1 + bicl2 #0,r1 + + clrl r0 + cmpl r1,r2 + bgequ vcg.4 + incl r0 +vcg.4: + addl2 r0,r4 + + movl 4(ap),r3 + movl r1,(r3) + + decl 16(ap) + bgtr gen.1 + brw noname.25 +gen.1: +noname.24: + + addl3 r4,4(r6),r2 + + bicl2 #0,r2 + + clrl r0 + cmpl r2,r4 + bgequ vcg.5 + incl r0 +vcg.5: + movl r0,r4 + + addl3 4(r5),r2,r1 + bicl2 #0,r1 + + clrl r0 + cmpl r1,r2 + bgequ vcg.6 + incl r0 +vcg.6: + addl2 r0,r4 + + movl r1,4(r3) + + decl 16(ap) + bleq noname.25 +noname.26: + + addl3 r4,8(r6),r2 + + bicl2 #0,r2 + + clrl r0 + cmpl r2,r4 + bgequ vcg.7 + incl r0 +vcg.7: + movl r0,r4 + + addl3 8(r5),r2,r1 + bicl2 #0,r1 + + clrl r0 + cmpl r1,r2 + bgequ vcg.8 + incl r0 +vcg.8: + addl2 r0,r4 + + movl r1,8(r3) + + decl 16(ap) + bleq noname.25 +noname.27: + + addl3 r4,12(r6),r2 + + bicl2 #0,r2 + + clrl r0 + cmpl r2,r4 + bgequ vcg.9 + incl r0 +vcg.9: + movl r0,r4 + + addl3 12(r5),r2,r1 + bicl2 #0,r1 + + clrl r0 + cmpl r1,r2 + bgequ vcg.10 + incl r0 +vcg.10: + addl2 r0,r4 + + movl r1,12(r3) + + decl 16(ap) + bleq noname.25 +noname.28: + + addl3 #16,r6,8(ap) + + addl3 #16,r5,12(ap) + + addl3 #16,r3,4(ap) + brw noname.23 + tstl r0 +noname.25: + + movl r4,r7 + +noname.22: + movl r7,r0 + ret + nop + + + +;r=4 ;(AP) +;a=8 ;(AP) +;b=12 ;(AP) +;n=16 ;(AP) n by value (input) + + .psect code,nowrt + +.entry BN_SUB_WORDS,^m + + clrl r6 + + tstl 16(ap) + bgtr noname.31 + clrl r7 + brw noname.32 + tstl r0 +noname.31: + +noname.33: + + movl 8(ap),r5 + movl (r5),r1 + movl 12(ap),r4 + movl (r4),r2 + + movl 4(ap),r3 + subl3 r2,r1,r0 + subl2 r6,r0 + bicl3 #0,r0,(r3) + + cmpl r1,r2 + beql noname.34 + clrl r0 + cmpl r1,r2 + bgequ vcg.11 + incl r0 +vcg.11: + movl r0,r6 +noname.34: + + decl 16(ap) + bgtr gen.2 + brw noname.36 +gen.2: +noname.35: + + movl 4(r5),r2 + movl 4(r4),r1 + + subl3 r1,r2,r0 + subl2 r6,r0 + bicl3 #0,r0,4(r3) + + cmpl r2,r1 + beql noname.37 + clrl r0 + cmpl r2,r1 + bgequ vcg.12 + incl r0 +vcg.12: + movl r0,r6 +noname.37: + + decl 16(ap) + bleq noname.36 +noname.38: + + movl 8(r5),r1 + movl 8(r4),r2 + + subl3 r2,r1,r0 + subl2 r6,r0 + bicl3 #0,r0,8(r3) + + cmpl r1,r2 + beql noname.39 + clrl r0 + cmpl r1,r2 + bgequ vcg.13 + incl r0 +vcg.13: + movl r0,r6 +noname.39: + + decl 16(ap) + bleq noname.36 +noname.40: + + movl 12(r5),r1 + movl 12(r4),r2 + + subl3 r2,r1,r0 + subl2 r6,r0 + bicl3 #0,r0,12(r3) + + cmpl r1,r2 + beql noname.41 + clrl r0 + cmpl r1,r2 + bgequ vcg.14 + incl r0 +vcg.14: + movl r0,r6 +noname.41: + + decl 16(ap) + bleq noname.36 +noname.42: + + addl3 #16,r5,8(ap) + + addl3 #16,r4,12(ap) + + addl3 #16,r3,4(ap) + brw noname.33 + tstl r0 +noname.36: + + movl r6,r7 + +noname.32: + movl r7,r0 + ret + nop + + + +;r=4 ;(AP) +;a=8 ;(AP) +;b=12 ;(AP) +;n=16 ;(AP) n by value (input) + + .psect code,nowrt + +.entry BN_MUL_COMBA8,^m + movab -924(sp),sp + clrq r8 + + clrl r10 + + movl 8(ap),r6 + movzwl 2(r6),r3 + movl 12(ap),r7 + bicl3 #-65536,(r7),r2 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,(r6),-12(fp) + bicl3 #-65536,r3,-16(fp) + mull3 r0,-12(fp),-4(fp) + mull2 r2,-12(fp) + mull3 r2,-16(fp),-8(fp) + mull2 r0,-16(fp) + addl3 -4(fp),-8(fp),r0 + bicl3 #0,r0,-4(fp) + cmpl -4(fp),-8(fp) + bgequ noname.45 + addl2 #65536,-16(fp) +noname.45: + movzwl -2(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-16(fp) + bicl3 #-65536,-4(fp),r0 + ashl #16,r0,-8(fp) + addl3 -8(fp),-12(fp),r0 + bicl3 #0,r0,-12(fp) + cmpl -12(fp),-8(fp) + bgequ noname.46 + incl -16(fp) +noname.46: + movl -12(fp),r1 + movl -16(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.47 + incl r2 +noname.47: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.48 + incl r10 +noname.48: + + movl 4(ap),r11 + movl r9,(r11) + + clrl r9 + + movzwl 2(r6),r2 + bicl3 #-65536,4(r7),r3 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,(r6),-28(fp) + bicl3 #-65536,r2,-32(fp) + mull3 r0,-28(fp),-20(fp) + mull2 r3,-28(fp) + mull3 r3,-32(fp),-24(fp) + mull2 r0,-32(fp) + addl3 -20(fp),-24(fp),r0 + bicl3 #0,r0,-20(fp) + cmpl -20(fp),-24(fp) + bgequ noname.49 + addl2 #65536,-32(fp) +noname.49: + movzwl -18(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-32(fp) + bicl3 #-65536,-20(fp),r0 + ashl #16,r0,-24(fp) + addl3 -24(fp),-28(fp),r0 + bicl3 #0,r0,-28(fp) + cmpl -28(fp),-24(fp) + bgequ noname.50 + incl -32(fp) +noname.50: + movl -28(fp),r1 + movl -32(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.51 + incl r2 +noname.51: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.52 + incl r9 +noname.52: + + movzwl 6(r6),r2 + bicl3 #-65536,(r7),r3 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-44(fp) + bicl3 #-65536,r2,-48(fp) + mull3 r0,-44(fp),-36(fp) + mull2 r3,-44(fp) + mull3 r3,-48(fp),-40(fp) + mull2 r0,-48(fp) + addl3 -36(fp),-40(fp),r0 + bicl3 #0,r0,-36(fp) + cmpl -36(fp),-40(fp) + bgequ noname.53 + addl2 #65536,-48(fp) +noname.53: + movzwl -34(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-48(fp) + bicl3 #-65536,-36(fp),r0 + ashl #16,r0,-40(fp) + addl3 -40(fp),-44(fp),r0 + bicl3 #0,r0,-44(fp) + cmpl -44(fp),-40(fp) + bgequ noname.54 + incl -48(fp) +noname.54: + movl -44(fp),r1 + movl -48(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.55 + incl r2 +noname.55: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.56 + incl r9 +noname.56: + + movl r8,4(r11) + + clrl r8 + + movzwl 10(r6),r2 + bicl3 #-65536,(r7),r3 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r6),-60(fp) + bicl3 #-65536,r2,-64(fp) + mull3 r0,-60(fp),-52(fp) + mull2 r3,-60(fp) + mull3 r3,-64(fp),-56(fp) + mull2 r0,-64(fp) + addl3 -52(fp),-56(fp),r0 + bicl3 #0,r0,-52(fp) + cmpl -52(fp),-56(fp) + bgequ noname.57 + addl2 #65536,-64(fp) +noname.57: + movzwl -50(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-64(fp) + bicl3 #-65536,-52(fp),r0 + ashl #16,r0,-56(fp) + addl3 -56(fp),-60(fp),r0 + bicl3 #0,r0,-60(fp) + cmpl -60(fp),-56(fp) + bgequ noname.58 + incl -64(fp) +noname.58: + movl -60(fp),r1 + movl -64(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.59 + incl r2 +noname.59: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.60 + incl r8 +noname.60: + + movzwl 6(r6),r2 + bicl3 #-65536,4(r7),r3 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-76(fp) + bicl3 #-65536,r2,-80(fp) + mull3 r0,-76(fp),-68(fp) + mull2 r3,-76(fp) + mull3 r3,-80(fp),-72(fp) + mull2 r0,-80(fp) + addl3 -68(fp),-72(fp),r0 + bicl3 #0,r0,-68(fp) + cmpl -68(fp),-72(fp) + bgequ noname.61 + addl2 #65536,-80(fp) +noname.61: + movzwl -66(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-80(fp) + bicl3 #-65536,-68(fp),r0 + ashl #16,r0,-72(fp) + addl3 -72(fp),-76(fp),r0 + bicl3 #0,r0,-76(fp) + cmpl -76(fp),-72(fp) + bgequ noname.62 + incl -80(fp) +noname.62: + movl -76(fp),r1 + movl -80(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.63 + incl r2 +noname.63: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.64 + incl r8 +noname.64: + + movzwl 2(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,(r6),-92(fp) + bicl3 #-65536,r2,-96(fp) + mull3 r0,-92(fp),-84(fp) + mull2 r3,-92(fp) + mull3 r3,-96(fp),-88(fp) + mull2 r0,-96(fp) + addl3 -84(fp),-88(fp),r0 + bicl3 #0,r0,-84(fp) + cmpl -84(fp),-88(fp) + bgequ noname.65 + addl2 #65536,-96(fp) +noname.65: + movzwl -82(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-96(fp) + bicl3 #-65536,-84(fp),r0 + ashl #16,r0,-88(fp) + addl3 -88(fp),-92(fp),r0 + bicl3 #0,r0,-92(fp) + cmpl -92(fp),-88(fp) + bgequ noname.66 + incl -96(fp) +noname.66: + movl -92(fp),r1 + movl -96(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.67 + incl r2 +noname.67: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.68 + incl r8 +noname.68: + + movl r10,8(r11) + + clrl r10 + + movzwl 2(r6),r2 + bicl3 #-65536,12(r7),r3 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,(r6),-108(fp) + bicl3 #-65536,r2,-112(fp) + mull3 r0,-108(fp),-100(fp) + mull2 r3,-108(fp) + mull3 r3,-112(fp),-104(fp) + mull2 r0,-112(fp) + addl3 -100(fp),-104(fp),r0 + bicl3 #0,r0,-100(fp) + cmpl -100(fp),-104(fp) + bgequ noname.69 + addl2 #65536,-112(fp) +noname.69: + movzwl -98(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-112(fp) + bicl3 #-65536,-100(fp),r0 + ashl #16,r0,-104(fp) + addl3 -104(fp),-108(fp),r0 + bicl3 #0,r0,-108(fp) + cmpl -108(fp),-104(fp) + bgequ noname.70 + incl -112(fp) +noname.70: + movl -108(fp),r1 + movl -112(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.71 + incl r2 +noname.71: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.72 + incl r10 +noname.72: + + movzwl 6(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-124(fp) + bicl3 #-65536,r2,-128(fp) + mull3 r0,-124(fp),-116(fp) + mull2 r3,-124(fp) + mull3 r3,-128(fp),-120(fp) + mull2 r0,-128(fp) + addl3 -116(fp),-120(fp),r0 + bicl3 #0,r0,-116(fp) + cmpl -116(fp),-120(fp) + bgequ noname.73 + addl2 #65536,-128(fp) +noname.73: + movzwl -114(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-128(fp) + bicl3 #-65536,-116(fp),r0 + ashl #16,r0,-120(fp) + addl3 -120(fp),-124(fp),r0 + bicl3 #0,r0,-124(fp) + cmpl -124(fp),-120(fp) + bgequ noname.74 + incl -128(fp) +noname.74: + movl -124(fp),r1 + movl -128(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.75 + incl r2 +noname.75: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.76 + incl r10 +noname.76: + + movzwl 10(r6),r2 + bicl3 #-65536,4(r7),r3 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r6),-140(fp) + bicl3 #-65536,r2,-144(fp) + mull3 r0,-140(fp),-132(fp) + mull2 r3,-140(fp) + mull3 r3,-144(fp),-136(fp) + mull2 r0,-144(fp) + addl3 -132(fp),-136(fp),r0 + bicl3 #0,r0,-132(fp) + cmpl -132(fp),-136(fp) + bgequ noname.77 + addl2 #65536,-144(fp) +noname.77: + movzwl -130(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-144(fp) + bicl3 #-65536,-132(fp),r0 + ashl #16,r0,-136(fp) + addl3 -136(fp),-140(fp),r0 + bicl3 #0,r0,-140(fp) + cmpl -140(fp),-136(fp) + bgequ noname.78 + incl -144(fp) +noname.78: + movl -140(fp),r1 + movl -144(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.79 + incl r2 +noname.79: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.80 + incl r10 +noname.80: + + movzwl 14(r6),r2 + bicl3 #-65536,(r7),r3 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-156(fp) + bicl3 #-65536,r2,-160(fp) + mull3 r0,-156(fp),-148(fp) + mull2 r3,-156(fp) + mull3 r3,-160(fp),-152(fp) + mull2 r0,-160(fp) + addl3 -148(fp),-152(fp),r0 + bicl3 #0,r0,-148(fp) + cmpl -148(fp),-152(fp) + bgequ noname.81 + addl2 #65536,-160(fp) +noname.81: + movzwl -146(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-160(fp) + bicl3 #-65536,-148(fp),r0 + ashl #16,r0,-152(fp) + addl3 -152(fp),-156(fp),r0 + bicl3 #0,r0,-156(fp) + cmpl -156(fp),-152(fp) + bgequ noname.82 + incl -160(fp) +noname.82: + movl -156(fp),r1 + movl -160(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.83 + incl r2 +noname.83: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.84 + incl r10 +noname.84: + + movl r9,12(r11) + + clrl r9 + + movzwl 18(r6),r2 + bicl3 #-65536,(r7),r3 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,16(r6),-172(fp) + bicl3 #-65536,r2,-176(fp) + mull3 r0,-172(fp),-164(fp) + mull2 r3,-172(fp) + mull3 r3,-176(fp),-168(fp) + mull2 r0,-176(fp) + addl3 -164(fp),-168(fp),r0 + bicl3 #0,r0,-164(fp) + cmpl -164(fp),-168(fp) + bgequ noname.85 + addl2 #65536,-176(fp) +noname.85: + movzwl -162(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-176(fp) + bicl3 #-65536,-164(fp),r0 + ashl #16,r0,-168(fp) + addl3 -168(fp),-172(fp),r0 + bicl3 #0,r0,-172(fp) + cmpl -172(fp),-168(fp) + bgequ noname.86 + incl -176(fp) +noname.86: + movl -172(fp),r1 + movl -176(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.87 + incl r2 +noname.87: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.88 + incl r9 +noname.88: + + movzwl 14(r6),r2 + bicl3 #-65536,4(r7),r3 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-188(fp) + bicl3 #-65536,r2,-192(fp) + mull3 r0,-188(fp),-180(fp) + mull2 r3,-188(fp) + mull3 r3,-192(fp),-184(fp) + mull2 r0,-192(fp) + addl3 -180(fp),-184(fp),r0 + bicl3 #0,r0,-180(fp) + cmpl -180(fp),-184(fp) + bgequ noname.89 + addl2 #65536,-192(fp) +noname.89: + movzwl -178(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-192(fp) + bicl3 #-65536,-180(fp),r0 + ashl #16,r0,-184(fp) + addl3 -184(fp),-188(fp),r0 + bicl3 #0,r0,-188(fp) + cmpl -188(fp),-184(fp) + bgequ noname.90 + incl -192(fp) +noname.90: + movl -188(fp),r1 + movl -192(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.91 + incl r2 +noname.91: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.92 + incl r9 +noname.92: + + movzwl 10(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r6),-204(fp) + bicl3 #-65536,r2,-208(fp) + mull3 r0,-204(fp),-196(fp) + mull2 r3,-204(fp) + mull3 r3,-208(fp),-200(fp) + mull2 r0,-208(fp) + addl3 -196(fp),-200(fp),r0 + bicl3 #0,r0,-196(fp) + cmpl -196(fp),-200(fp) + bgequ noname.93 + addl2 #65536,-208(fp) +noname.93: + movzwl -194(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-208(fp) + bicl3 #-65536,-196(fp),r0 + ashl #16,r0,-200(fp) + addl3 -200(fp),-204(fp),r0 + bicl3 #0,r0,-204(fp) + cmpl -204(fp),-200(fp) + bgequ noname.94 + incl -208(fp) +noname.94: + movl -204(fp),r1 + movl -208(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.95 + incl r2 +noname.95: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.96 + incl r9 +noname.96: + + movzwl 6(r6),r2 + bicl3 #-65536,12(r7),r3 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-220(fp) + bicl3 #-65536,r2,-224(fp) + mull3 r0,-220(fp),-212(fp) + mull2 r3,-220(fp) + mull3 r3,-224(fp),-216(fp) + mull2 r0,-224(fp) + addl3 -212(fp),-216(fp),r0 + bicl3 #0,r0,-212(fp) + cmpl -212(fp),-216(fp) + bgequ noname.97 + addl2 #65536,-224(fp) +noname.97: + movzwl -210(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-224(fp) + bicl3 #-65536,-212(fp),r0 + ashl #16,r0,-216(fp) + addl3 -216(fp),-220(fp),r0 + bicl3 #0,r0,-220(fp) + cmpl -220(fp),-216(fp) + bgequ noname.98 + incl -224(fp) +noname.98: + movl -220(fp),r1 + movl -224(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.99 + incl r2 +noname.99: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.100 + incl r9 +noname.100: + + movzwl 2(r6),r2 + bicl3 #-65536,16(r7),r3 + movzwl 18(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,(r6),-236(fp) + bicl3 #-65536,r2,-240(fp) + mull3 r0,-236(fp),-228(fp) + mull2 r3,-236(fp) + mull3 r3,-240(fp),-232(fp) + mull2 r0,-240(fp) + addl3 -228(fp),-232(fp),r0 + bicl3 #0,r0,-228(fp) + cmpl -228(fp),-232(fp) + bgequ noname.101 + addl2 #65536,-240(fp) +noname.101: + movzwl -226(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-240(fp) + bicl3 #-65536,-228(fp),r0 + ashl #16,r0,-232(fp) + addl3 -232(fp),-236(fp),r0 + bicl3 #0,r0,-236(fp) + cmpl -236(fp),-232(fp) + bgequ noname.102 + incl -240(fp) +noname.102: + movl -236(fp),r1 + movl -240(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.103 + incl r2 +noname.103: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.104 + incl r9 +noname.104: + + movl r8,16(r11) + + clrl r8 + + movzwl 2(r6),r2 + bicl3 #-65536,20(r7),r3 + movzwl 22(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,(r6),-252(fp) + bicl3 #-65536,r2,-256(fp) + mull3 r0,-252(fp),-244(fp) + mull2 r3,-252(fp) + mull3 r3,-256(fp),-248(fp) + mull2 r0,-256(fp) + addl3 -244(fp),-248(fp),r0 + bicl3 #0,r0,-244(fp) + cmpl -244(fp),-248(fp) + bgequ noname.105 + addl2 #65536,-256(fp) +noname.105: + movzwl -242(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-256(fp) + bicl3 #-65536,-244(fp),r0 + ashl #16,r0,-248(fp) + addl3 -248(fp),-252(fp),r0 + bicl3 #0,r0,-252(fp) + cmpl -252(fp),-248(fp) + bgequ noname.106 + incl -256(fp) +noname.106: + movl -252(fp),r1 + movl -256(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.107 + incl r2 +noname.107: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.108 + incl r8 +noname.108: + + movzwl 6(r6),r2 + bicl3 #-65536,16(r7),r3 + movzwl 18(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-268(fp) + bicl3 #-65536,r2,-272(fp) + mull3 r0,-268(fp),-260(fp) + mull2 r3,-268(fp) + mull3 r3,-272(fp),-264(fp) + mull2 r0,-272(fp) + addl3 -260(fp),-264(fp),r0 + bicl3 #0,r0,-260(fp) + cmpl -260(fp),-264(fp) + bgequ noname.109 + addl2 #65536,-272(fp) +noname.109: + movzwl -258(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-272(fp) + bicl3 #-65536,-260(fp),r0 + ashl #16,r0,-264(fp) + addl3 -264(fp),-268(fp),r0 + bicl3 #0,r0,-268(fp) + cmpl -268(fp),-264(fp) + bgequ noname.110 + incl -272(fp) +noname.110: + movl -268(fp),r1 + movl -272(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.111 + incl r2 +noname.111: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.112 + incl r8 +noname.112: + + movzwl 10(r6),r2 + bicl3 #-65536,12(r7),r3 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r6),-284(fp) + bicl3 #-65536,r2,-288(fp) + mull3 r0,-284(fp),-276(fp) + mull2 r3,-284(fp) + mull3 r3,-288(fp),-280(fp) + mull2 r0,-288(fp) + addl3 -276(fp),-280(fp),r0 + bicl3 #0,r0,-276(fp) + cmpl -276(fp),-280(fp) + bgequ noname.113 + addl2 #65536,-288(fp) +noname.113: + movzwl -274(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-288(fp) + bicl3 #-65536,-276(fp),r0 + ashl #16,r0,-280(fp) + addl3 -280(fp),-284(fp),r0 + bicl3 #0,r0,-284(fp) + cmpl -284(fp),-280(fp) + bgequ noname.114 + incl -288(fp) +noname.114: + movl -284(fp),r1 + movl -288(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.115 + incl r2 +noname.115: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.116 + incl r8 +noname.116: + + movzwl 14(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-300(fp) + bicl3 #-65536,r2,-304(fp) + mull3 r0,-300(fp),-292(fp) + mull2 r3,-300(fp) + mull3 r3,-304(fp),-296(fp) + mull2 r0,-304(fp) + addl3 -292(fp),-296(fp),r0 + bicl3 #0,r0,-292(fp) + cmpl -292(fp),-296(fp) + bgequ noname.117 + addl2 #65536,-304(fp) +noname.117: + movzwl -290(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-304(fp) + bicl3 #-65536,-292(fp),r0 + ashl #16,r0,-296(fp) + addl3 -296(fp),-300(fp),r0 + bicl3 #0,r0,-300(fp) + cmpl -300(fp),-296(fp) + bgequ noname.118 + incl -304(fp) +noname.118: + movl -300(fp),r1 + movl -304(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.119 + incl r2 +noname.119: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.120 + incl r8 +noname.120: + + movzwl 18(r6),r2 + bicl3 #-65536,4(r7),r3 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,16(r6),-316(fp) + bicl3 #-65536,r2,-320(fp) + mull3 r0,-316(fp),-308(fp) + mull2 r3,-316(fp) + mull3 r3,-320(fp),-312(fp) + mull2 r0,-320(fp) + addl3 -308(fp),-312(fp),r0 + bicl3 #0,r0,-308(fp) + cmpl -308(fp),-312(fp) + bgequ noname.121 + addl2 #65536,-320(fp) +noname.121: + movzwl -306(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-320(fp) + bicl3 #-65536,-308(fp),r0 + ashl #16,r0,-312(fp) + addl3 -312(fp),-316(fp),r0 + bicl3 #0,r0,-316(fp) + cmpl -316(fp),-312(fp) + bgequ noname.122 + incl -320(fp) +noname.122: + movl -316(fp),r1 + movl -320(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.123 + incl r2 + +noname.123: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.124 + incl r8 +noname.124: + + movzwl 22(r6),r2 + bicl3 #-65536,(r7),r3 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,20(r6),-332(fp) + bicl3 #-65536,r2,-336(fp) + mull3 r0,-332(fp),-324(fp) + mull2 r3,-332(fp) + mull3 r3,-336(fp),-328(fp) + mull2 r0,-336(fp) + addl3 -324(fp),-328(fp),r0 + bicl3 #0,r0,-324(fp) + cmpl -324(fp),-328(fp) + bgequ noname.125 + addl2 #65536,-336(fp) +noname.125: + movzwl -322(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-336(fp) + bicl3 #-65536,-324(fp),r0 + ashl #16,r0,-328(fp) + addl3 -328(fp),-332(fp),r0 + bicl3 #0,r0,-332(fp) + cmpl -332(fp),-328(fp) + bgequ noname.126 + incl -336(fp) +noname.126: + movl -332(fp),r1 + movl -336(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.127 + incl r2 +noname.127: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.128 + incl r8 +noname.128: + + movl r10,20(r11) + + clrl r10 + + movzwl 26(r6),r2 + bicl3 #-65536,(r7),r3 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,24(r6),-348(fp) + bicl3 #-65536,r2,-352(fp) + mull3 r0,-348(fp),-340(fp) + mull2 r3,-348(fp) + mull3 r3,-352(fp),-344(fp) + mull2 r0,-352(fp) + addl3 -340(fp),-344(fp),r0 + bicl3 #0,r0,-340(fp) + cmpl -340(fp),-344(fp) + bgequ noname.129 + addl2 #65536,-352(fp) +noname.129: + movzwl -338(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-352(fp) + bicl3 #-65536,-340(fp),r0 + ashl #16,r0,-344(fp) + addl3 -344(fp),-348(fp),r0 + bicl3 #0,r0,-348(fp) + cmpl -348(fp),-344(fp) + bgequ noname.130 + incl -352(fp) +noname.130: + movl -348(fp),r1 + movl -352(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.131 + incl r2 +noname.131: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.132 + incl r10 +noname.132: + + movzwl 22(r6),r2 + bicl3 #-65536,4(r7),r3 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,20(r6),-364(fp) + bicl3 #-65536,r2,-368(fp) + mull3 r0,-364(fp),-356(fp) + mull2 r3,-364(fp) + mull3 r3,-368(fp),-360(fp) + mull2 r0,-368(fp) + addl3 -356(fp),-360(fp),r0 + bicl3 #0,r0,-356(fp) + cmpl -356(fp),-360(fp) + bgequ noname.133 + addl2 #65536,-368(fp) +noname.133: + movzwl -354(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-368(fp) + bicl3 #-65536,-356(fp),r0 + ashl #16,r0,-360(fp) + addl3 -360(fp),-364(fp),r0 + bicl3 #0,r0,-364(fp) + cmpl -364(fp),-360(fp) + bgequ noname.134 + incl -368(fp) +noname.134: + movl -364(fp),r1 + movl -368(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.135 + incl r2 +noname.135: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.136 + incl r10 +noname.136: + + movzwl 18(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,16(r6),-380(fp) + bicl3 #-65536,r2,-384(fp) + mull3 r0,-380(fp),-372(fp) + mull2 r3,-380(fp) + mull3 r3,-384(fp),-376(fp) + mull2 r0,-384(fp) + addl3 -372(fp),-376(fp),r0 + bicl3 #0,r0,-372(fp) + cmpl -372(fp),-376(fp) + bgequ noname.137 + addl2 #65536,-384(fp) +noname.137: + movzwl -370(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-384(fp) + bicl3 #-65536,-372(fp),r0 + ashl #16,r0,-376(fp) + addl3 -376(fp),-380(fp),r0 + bicl3 #0,r0,-380(fp) + cmpl -380(fp),-376(fp) + bgequ noname.138 + incl -384(fp) +noname.138: + movl -380(fp),r1 + movl -384(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.139 + incl r2 +noname.139: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.140 + incl r10 +noname.140: + + movzwl 14(r6),r2 + bicl3 #-65536,12(r7),r3 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-396(fp) + bicl3 #-65536,r2,-400(fp) + mull3 r0,-396(fp),-388(fp) + mull2 r3,-396(fp) + mull3 r3,-400(fp),-392(fp) + mull2 r0,-400(fp) + addl3 -388(fp),-392(fp),r0 + bicl3 #0,r0,-388(fp) + cmpl -388(fp),-392(fp) + bgequ noname.141 + addl2 #65536,-400(fp) +noname.141: + movzwl -386(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-400(fp) + bicl3 #-65536,-388(fp),r0 + ashl #16,r0,-392(fp) + addl3 -392(fp),-396(fp),r0 + bicl3 #0,r0,-396(fp) + cmpl -396(fp),-392(fp) + bgequ noname.142 + incl -400(fp) +noname.142: + movl -396(fp),r1 + movl -400(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.143 + incl r2 +noname.143: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.144 + incl r10 +noname.144: + + movzwl 10(r6),r2 + bicl3 #-65536,16(r7),r3 + movzwl 18(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r6),-412(fp) + bicl3 #-65536,r2,-416(fp) + mull3 r0,-412(fp),-404(fp) + mull2 r3,-412(fp) + mull3 r3,-416(fp),-408(fp) + mull2 r0,-416(fp) + addl3 -404(fp),-408(fp),r0 + bicl3 #0,r0,-404(fp) + cmpl -404(fp),-408(fp) + bgequ noname.145 + addl2 #65536,-416(fp) +noname.145: + movzwl -402(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-416(fp) + bicl3 #-65536,-404(fp),r0 + ashl #16,r0,-408(fp) + addl3 -408(fp),-412(fp),r0 + bicl3 #0,r0,-412(fp) + cmpl -412(fp),-408(fp) + bgequ noname.146 + incl -416(fp) +noname.146: + movl -412(fp),r1 + movl -416(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.147 + incl r2 +noname.147: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.148 + incl r10 +noname.148: + + movzwl 6(r6),r2 + bicl3 #-65536,20(r7),r3 + movzwl 22(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-428(fp) + bicl3 #-65536,r2,-432(fp) + mull3 r0,-428(fp),-420(fp) + mull2 r3,-428(fp) + mull3 r3,-432(fp),-424(fp) + mull2 r0,-432(fp) + addl3 -420(fp),-424(fp),r0 + bicl3 #0,r0,-420(fp) + cmpl -420(fp),-424(fp) + bgequ noname.149 + addl2 #65536,-432(fp) +noname.149: + movzwl -418(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-432(fp) + bicl3 #-65536,-420(fp),r0 + ashl #16,r0,-424(fp) + addl3 -424(fp),-428(fp),r0 + bicl3 #0,r0,-428(fp) + cmpl -428(fp),-424(fp) + bgequ noname.150 + incl -432(fp) +noname.150: + movl -428(fp),r1 + movl -432(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.151 + incl r2 +noname.151: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.152 + incl r10 +noname.152: + + movzwl 2(r6),r2 + bicl3 #-65536,24(r7),r3 + movzwl 26(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,(r6),-444(fp) + bicl3 #-65536,r2,-448(fp) + mull3 r0,-444(fp),-436(fp) + mull2 r3,-444(fp) + mull3 r3,-448(fp),-440(fp) + mull2 r0,-448(fp) + addl3 -436(fp),-440(fp),r0 + bicl3 #0,r0,-436(fp) + cmpl -436(fp),-440(fp) + bgequ noname.153 + addl2 #65536,-448(fp) +noname.153: + movzwl -434(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-448(fp) + bicl3 #-65536,-436(fp),r0 + ashl #16,r0,-440(fp) + addl3 -440(fp),-444(fp),r0 + bicl3 #0,r0,-444(fp) + cmpl -444(fp),-440(fp) + bgequ noname.154 + incl -448(fp) +noname.154: + movl -444(fp),r1 + movl -448(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.155 + incl r2 +noname.155: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.156 + incl r10 +noname.156: + + movl r9,24(r11) + + clrl r9 + + movzwl 2(r6),r2 + bicl3 #-65536,28(r7),r3 + movzwl 30(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,(r6),-460(fp) + bicl3 #-65536,r2,-464(fp) + mull3 r0,-460(fp),-452(fp) + mull2 r3,-460(fp) + mull3 r3,-464(fp),-456(fp) + mull2 r0,-464(fp) + addl3 -452(fp),-456(fp),r0 + bicl3 #0,r0,-452(fp) + cmpl -452(fp),-456(fp) + bgequ noname.157 + addl2 #65536,-464(fp) +noname.157: + movzwl -450(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-464(fp) + bicl3 #-65536,-452(fp),r0 + ashl #16,r0,-456(fp) + addl3 -456(fp),-460(fp),r0 + bicl3 #0,r0,-460(fp) + cmpl -460(fp),-456(fp) + bgequ noname.158 + incl -464(fp) +noname.158: + movl -460(fp),r1 + movl -464(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.159 + incl r2 +noname.159: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.160 + incl r9 +noname.160: + + movzwl 6(r6),r2 + bicl3 #-65536,24(r7),r3 + movzwl 26(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-476(fp) + bicl3 #-65536,r2,-480(fp) + mull3 r0,-476(fp),-468(fp) + mull2 r3,-476(fp) + mull3 r3,-480(fp),-472(fp) + mull2 r0,-480(fp) + addl3 -468(fp),-472(fp),r0 + bicl3 #0,r0,-468(fp) + cmpl -468(fp),-472(fp) + bgequ noname.161 + addl2 #65536,-480(fp) +noname.161: + movzwl -466(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-480(fp) + bicl3 #-65536,-468(fp),r0 + ashl #16,r0,-472(fp) + addl3 -472(fp),-476(fp),r0 + bicl3 #0,r0,-476(fp) + cmpl -476(fp),-472(fp) + bgequ noname.162 + incl -480(fp) +noname.162: + movl -476(fp),r1 + movl -480(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.163 + incl r2 +noname.163: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.164 + incl r9 +noname.164: + + movzwl 10(r6),r2 + bicl3 #-65536,20(r7),r3 + movzwl 22(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r6),-492(fp) + bicl3 #-65536,r2,-496(fp) + mull3 r0,-492(fp),-484(fp) + mull2 r3,-492(fp) + mull3 r3,-496(fp),-488(fp) + mull2 r0,-496(fp) + addl3 -484(fp),-488(fp),r0 + bicl3 #0,r0,-484(fp) + cmpl -484(fp),-488(fp) + bgequ noname.165 + addl2 #65536,-496(fp) +noname.165: + movzwl -482(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-496(fp) + bicl3 #-65536,-484(fp),r0 + ashl #16,r0,-488(fp) + addl3 -488(fp),-492(fp),r0 + bicl3 #0,r0,-492(fp) + cmpl -492(fp),-488(fp) + bgequ noname.166 + incl -496(fp) +noname.166: + movl -492(fp),r1 + movl -496(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.167 + incl r2 +noname.167: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.168 + incl r9 +noname.168: + + movzwl 14(r6),r2 + bicl3 #-65536,16(r7),r3 + movzwl 18(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-508(fp) + bicl3 #-65536,r2,-512(fp) + mull3 r0,-508(fp),-500(fp) + mull2 r3,-508(fp) + mull3 r3,-512(fp),-504(fp) + mull2 r0,-512(fp) + addl3 -500(fp),-504(fp),r0 + bicl3 #0,r0,-500(fp) + cmpl -500(fp),-504(fp) + bgequ noname.169 + addl2 #65536,-512(fp) +noname.169: + movzwl -498(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-512(fp) + bicl3 #-65536,-500(fp),r0 + ashl #16,r0,-504(fp) + addl3 -504(fp),-508(fp),r0 + bicl3 #0,r0,-508(fp) + cmpl -508(fp),-504(fp) + bgequ noname.170 + incl -512(fp) +noname.170: + movl -508(fp),r1 + movl -512(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.171 + incl r2 +noname.171: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.172 + incl r9 +noname.172: + + movzwl 18(r6),r2 + bicl3 #-65536,12(r7),r3 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,16(r6),-524(fp) + bicl3 #-65536,r2,-528(fp) + mull3 r0,-524(fp),-516(fp) + mull2 r3,-524(fp) + mull3 r3,-528(fp),-520(fp) + mull2 r0,-528(fp) + addl3 -516(fp),-520(fp),r0 + bicl3 #0,r0,-516(fp) + cmpl -516(fp),-520(fp) + bgequ noname.173 + addl2 #65536,-528(fp) +noname.173: + movzwl -514(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-528(fp) + bicl3 #-65536,-516(fp),r0 + ashl #16,r0,-520(fp) + addl3 -520(fp),-524(fp),r0 + bicl3 #0,r0,-524(fp) + cmpl -524(fp),-520(fp) + bgequ noname.174 + incl -528(fp) +noname.174: + movl -524(fp),r1 + movl -528(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.175 + incl r2 +noname.175: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.176 + incl r9 +noname.176: + + movzwl 22(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,20(r6),-540(fp) + bicl3 #-65536,r2,-544(fp) + mull3 r0,-540(fp),-532(fp) + mull2 r3,-540(fp) + mull3 r3,-544(fp),-536(fp) + mull2 r0,-544(fp) + addl3 -532(fp),-536(fp),r0 + bicl3 #0,r0,-532(fp) + cmpl -532(fp),-536(fp) + bgequ noname.177 + addl2 #65536,-544(fp) +noname.177: + movzwl -530(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-544(fp) + bicl3 #-65536,-532(fp),r0 + ashl #16,r0,-536(fp) + addl3 -536(fp),-540(fp),r0 + bicl3 #0,r0,-540(fp) + cmpl -540(fp),-536(fp) + bgequ noname.178 + incl -544(fp) +noname.178: + movl -540(fp),r1 + movl -544(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.179 + incl r2 +noname.179: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.180 + incl r9 +noname.180: + + movzwl 26(r6),r2 + bicl3 #-65536,4(r7),r3 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,24(r6),-556(fp) + bicl3 #-65536,r2,-560(fp) + mull3 r0,-556(fp),-548(fp) + mull2 r3,-556(fp) + mull3 r3,-560(fp),-552(fp) + mull2 r0,-560(fp) + addl3 -548(fp),-552(fp),r0 + bicl3 #0,r0,-548(fp) + cmpl -548(fp),-552(fp) + bgequ noname.181 + addl2 #65536,-560(fp) +noname.181: + movzwl -546(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-560(fp) + bicl3 #-65536,-548(fp),r0 + ashl #16,r0,-552(fp) + addl3 -552(fp),-556(fp),r0 + bicl3 #0,r0,-556(fp) + cmpl -556(fp),-552(fp) + bgequ noname.182 + incl -560(fp) +noname.182: + movl -556(fp),r1 + movl -560(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.183 + incl r2 +noname.183: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.184 + incl r9 +noname.184: + + movzwl 30(r6),r2 + bicl3 #-65536,(r7),r3 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,28(r6),-572(fp) + bicl3 #-65536,r2,-576(fp) + mull3 r0,-572(fp),-564(fp) + mull2 r3,-572(fp) + mull3 r3,-576(fp),-568(fp) + mull2 r0,-576(fp) + addl3 -564(fp),-568(fp),r0 + bicl3 #0,r0,-564(fp) + cmpl -564(fp),-568(fp) + bgequ noname.185 + addl2 #65536,-576(fp) +noname.185: + movzwl -562(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-576(fp) + bicl3 #-65536,-564(fp),r0 + ashl #16,r0,-568(fp) + addl3 -568(fp),-572(fp),r0 + bicl3 #0,r0,-572(fp) + cmpl -572(fp),-568(fp) + bgequ noname.186 + incl -576(fp) +noname.186: + movl -572(fp),r1 + movl -576(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.187 + incl r2 +noname.187: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.188 + incl r9 +noname.188: + + movl r8,28(r11) + + clrl r8 + + movzwl 30(r6),r2 + bicl3 #-65536,4(r7),r3 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,28(r6),-588(fp) + bicl3 #-65536,r2,-592(fp) + mull3 r0,-588(fp),-580(fp) + mull2 r3,-588(fp) + mull3 r3,-592(fp),-584(fp) + mull2 r0,-592(fp) + addl3 -580(fp),-584(fp),r0 + bicl3 #0,r0,-580(fp) + cmpl -580(fp),-584(fp) + bgequ noname.189 + addl2 #65536,-592(fp) +noname.189: + movzwl -578(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-592(fp) + bicl3 #-65536,-580(fp),r0 + ashl #16,r0,-584(fp) + addl3 -584(fp),-588(fp),r0 + bicl3 #0,r0,-588(fp) + cmpl -588(fp),-584(fp) + bgequ noname.190 + incl -592(fp) +noname.190: + movl -588(fp),r1 + movl -592(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.191 + incl r2 +noname.191: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.192 + incl r8 +noname.192: + + movzwl 26(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,24(r6),-604(fp) + bicl3 #-65536,r2,-608(fp) + mull3 r0,-604(fp),-596(fp) + mull2 r3,-604(fp) + mull3 r3,-608(fp),-600(fp) + mull2 r0,-608(fp) + addl3 -596(fp),-600(fp),r0 + bicl3 #0,r0,-596(fp) + cmpl -596(fp),-600(fp) + bgequ noname.193 + addl2 #65536,-608(fp) +noname.193: + movzwl -594(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-608(fp) + bicl3 #-65536,-596(fp),r0 + ashl #16,r0,-600(fp) + addl3 -600(fp),-604(fp),r0 + bicl3 #0,r0,-604(fp) + cmpl -604(fp),-600(fp) + bgequ noname.194 + incl -608(fp) +noname.194: + movl -604(fp),r1 + movl -608(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.195 + incl r2 +noname.195: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.196 + incl r8 +noname.196: + + movzwl 22(r6),r2 + bicl3 #-65536,12(r7),r3 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,20(r6),-620(fp) + bicl3 #-65536,r2,-624(fp) + mull3 r0,-620(fp),-612(fp) + mull2 r3,-620(fp) + mull3 r3,-624(fp),-616(fp) + mull2 r0,-624(fp) + addl3 -612(fp),-616(fp),r0 + bicl3 #0,r0,-612(fp) + cmpl -612(fp),-616(fp) + bgequ noname.197 + addl2 #65536,-624(fp) +noname.197: + movzwl -610(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-624(fp) + bicl3 #-65536,-612(fp),r0 + ashl #16,r0,-616(fp) + addl3 -616(fp),-620(fp),r0 + bicl3 #0,r0,-620(fp) + cmpl -620(fp),-616(fp) + bgequ noname.198 + incl -624(fp) +noname.198: + movl -620(fp),r1 + movl -624(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.199 + incl r2 +noname.199: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.200 + incl r8 +noname.200: + + movzwl 18(r6),r2 + bicl3 #-65536,16(r7),r3 + movzwl 18(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,16(r6),-636(fp) + bicl3 #-65536,r2,-640(fp) + mull3 r0,-636(fp),-628(fp) + mull2 r3,-636(fp) + mull3 r3,-640(fp),-632(fp) + mull2 r0,-640(fp) + addl3 -628(fp),-632(fp),r0 + bicl3 #0,r0,-628(fp) + cmpl -628(fp),-632(fp) + bgequ noname.201 + addl2 #65536,-640(fp) +noname.201: + movzwl -626(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-640(fp) + bicl3 #-65536,-628(fp),r0 + ashl #16,r0,-632(fp) + addl3 -632(fp),-636(fp),r0 + bicl3 #0,r0,-636(fp) + cmpl -636(fp),-632(fp) + bgequ noname.202 + incl -640(fp) +noname.202: + movl -636(fp),r1 + movl -640(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.203 + incl r2 +noname.203: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.204 + incl r8 +noname.204: + + movzwl 14(r6),r2 + bicl3 #-65536,20(r7),r3 + movzwl 22(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-652(fp) + bicl3 #-65536,r2,-656(fp) + mull3 r0,-652(fp),-644(fp) + mull2 r3,-652(fp) + mull3 r3,-656(fp),-648(fp) + mull2 r0,-656(fp) + addl3 -644(fp),-648(fp),r0 + bicl3 #0,r0,-644(fp) + cmpl -644(fp),-648(fp) + bgequ noname.205 + addl2 #65536,-656(fp) +noname.205: + movzwl -642(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-656(fp) + bicl3 #-65536,-644(fp),r0 + ashl #16,r0,-648(fp) + addl3 -648(fp),-652(fp),r0 + bicl3 #0,r0,-652(fp) + cmpl -652(fp),-648(fp) + bgequ noname.206 + incl -656(fp) +noname.206: + movl -652(fp),r1 + movl -656(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.207 + incl r2 +noname.207: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.208 + incl r8 +noname.208: + + movzwl 10(r6),r2 + bicl3 #-65536,24(r7),r3 + movzwl 26(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r6),-668(fp) + bicl3 #-65536,r2,-672(fp) + mull3 r0,-668(fp),-660(fp) + mull2 r3,-668(fp) + mull3 r3,-672(fp),-664(fp) + mull2 r0,-672(fp) + addl3 -660(fp),-664(fp),r0 + bicl3 #0,r0,-660(fp) + cmpl -660(fp),-664(fp) + bgequ noname.209 + addl2 #65536,-672(fp) +noname.209: + movzwl -658(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-672(fp) + bicl3 #-65536,-660(fp),r0 + ashl #16,r0,-664(fp) + addl3 -664(fp),-668(fp),r0 + bicl3 #0,r0,-668(fp) + cmpl -668(fp),-664(fp) + bgequ noname.210 + incl -672(fp) +noname.210: + movl -668(fp),r1 + movl -672(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.211 + incl r2 +noname.211: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.212 + incl r8 +noname.212: + + movzwl 6(r6),r2 + bicl3 #-65536,28(r7),r3 + movzwl 30(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-684(fp) + bicl3 #-65536,r2,-688(fp) + mull3 r0,-684(fp),-676(fp) + mull2 r3,-684(fp) + mull3 r3,-688(fp),-680(fp) + mull2 r0,-688(fp) + addl3 -676(fp),-680(fp),r0 + bicl3 #0,r0,-676(fp) + cmpl -676(fp),-680(fp) + bgequ noname.213 + addl2 #65536,-688(fp) +noname.213: + movzwl -674(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-688(fp) + bicl3 #-65536,-676(fp),r0 + ashl #16,r0,-680(fp) + addl3 -680(fp),-684(fp),r0 + bicl3 #0,r0,-684(fp) + cmpl -684(fp),-680(fp) + bgequ noname.214 + incl -688(fp) +noname.214: + movl -684(fp),r1 + movl -688(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.215 + incl r2 +noname.215: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.216 + incl r8 +noname.216: + + movl r10,32(r11) + + clrl r10 + + movzwl 10(r6),r2 + bicl3 #-65536,28(r7),r3 + movzwl 30(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r6),-700(fp) + bicl3 #-65536,r2,-704(fp) + mull3 r0,-700(fp),-692(fp) + mull2 r3,-700(fp) + mull3 r3,-704(fp),-696(fp) + mull2 r0,-704(fp) + addl3 -692(fp),-696(fp),r0 + bicl3 #0,r0,-692(fp) + cmpl -692(fp),-696(fp) + bgequ noname.217 + addl2 #65536,-704(fp) +noname.217: + movzwl -690(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-704(fp) + bicl3 #-65536,-692(fp),r0 + ashl #16,r0,-696(fp) + addl3 -696(fp),-700(fp),r0 + bicl3 #0,r0,-700(fp) + cmpl -700(fp),-696(fp) + bgequ noname.218 + incl -704(fp) +noname.218: + movl -700(fp),r1 + movl -704(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.219 + incl r2 +noname.219: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.220 + incl r10 +noname.220: + + movzwl 14(r6),r2 + bicl3 #-65536,24(r7),r3 + movzwl 26(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-716(fp) + bicl3 #-65536,r2,-720(fp) + mull3 r0,-716(fp),-708(fp) + mull2 r3,-716(fp) + mull3 r3,-720(fp),-712(fp) + mull2 r0,-720(fp) + addl3 -708(fp),-712(fp),r0 + bicl3 #0,r0,-708(fp) + cmpl -708(fp),-712(fp) + bgequ noname.221 + addl2 #65536,-720(fp) +noname.221: + movzwl -706(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-720(fp) + bicl3 #-65536,-708(fp),r0 + ashl #16,r0,-712(fp) + addl3 -712(fp),-716(fp),r0 + bicl3 #0,r0,-716(fp) + cmpl -716(fp),-712(fp) + bgequ noname.222 + incl -720(fp) +noname.222: + movl -716(fp),r1 + movl -720(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.223 + incl r2 +noname.223: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.224 + incl r10 +noname.224: + + movzwl 18(r6),r2 + bicl3 #-65536,20(r7),r3 + movzwl 22(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,16(r6),-732(fp) + bicl3 #-65536,r2,-736(fp) + mull3 r0,-732(fp),-724(fp) + mull2 r3,-732(fp) + mull3 r3,-736(fp),-728(fp) + mull2 r0,-736(fp) + addl3 -724(fp),-728(fp),r0 + bicl3 #0,r0,-724(fp) + cmpl -724(fp),-728(fp) + bgequ noname.225 + addl2 #65536,-736(fp) +noname.225: + movzwl -722(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-736(fp) + bicl3 #-65536,-724(fp),r0 + ashl #16,r0,-728(fp) + addl3 -728(fp),-732(fp),r0 + bicl3 #0,r0,-732(fp) + cmpl -732(fp),-728(fp) + bgequ noname.226 + incl -736(fp) +noname.226: + movl -732(fp),r1 + movl -736(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.227 + incl r2 +noname.227: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.228 + incl r10 +noname.228: + + movzwl 22(r6),r2 + bicl3 #-65536,16(r7),r3 + movzwl 18(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,20(r6),-748(fp) + bicl3 #-65536,r2,-752(fp) + mull3 r0,-748(fp),-740(fp) + mull2 r3,-748(fp) + mull3 r3,-752(fp),-744(fp) + mull2 r0,-752(fp) + addl3 -740(fp),-744(fp),r0 + bicl3 #0,r0,-740(fp) + cmpl -740(fp),-744(fp) + bgequ noname.229 + addl2 #65536,-752(fp) +noname.229: + movzwl -738(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-752(fp) + bicl3 #-65536,-740(fp),r0 + ashl #16,r0,-744(fp) + addl3 -744(fp),-748(fp),r0 + bicl3 #0,r0,-748(fp) + cmpl -748(fp),-744(fp) + bgequ noname.230 + incl -752(fp) +noname.230: + movl -748(fp),r1 + movl -752(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.231 + incl r2 +noname.231: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.232 + incl r10 +noname.232: + + movzwl 26(r6),r2 + bicl3 #-65536,12(r7),r3 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,24(r6),-764(fp) + bicl3 #-65536,r2,-768(fp) + mull3 r0,-764(fp),-756(fp) + mull2 r3,-764(fp) + mull3 r3,-768(fp),-760(fp) + mull2 r0,-768(fp) + addl3 -756(fp),-760(fp),r0 + bicl3 #0,r0,-756(fp) + cmpl -756(fp),-760(fp) + bgequ noname.233 + addl2 #65536,-768(fp) +noname.233: + movzwl -754(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-768(fp) + bicl3 #-65536,-756(fp),r0 + ashl #16,r0,-760(fp) + addl3 -760(fp),-764(fp),r0 + bicl3 #0,r0,-764(fp) + cmpl -764(fp),-760(fp) + bgequ noname.234 + incl -768(fp) +noname.234: + movl -764(fp),r1 + movl -768(fp),r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.235 + incl r2 +noname.235: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.236 + incl r10 +noname.236: + + bicl3 #-65536,28(r6),r3 + movzwl 30(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,8(r7),r2 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-772(fp) + mull2 r2,r5 + mull3 r2,r4,-776(fp) + mull2 r0,r4 + addl3 -772(fp),-776(fp),r0 + bicl3 #0,r0,-772(fp) + cmpl -772(fp),-776(fp) + bgequ noname.237 + addl2 #65536,r4 +noname.237: + movzwl -770(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-772(fp),r0 + ashl #16,r0,-776(fp) + addl2 -776(fp),r5 + bicl2 #0,r5 + cmpl r5,-776(fp) + bgequ noname.238 + incl r4 +noname.238: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.239 + incl r2 +noname.239: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.240 + incl r10 +noname.240: + + movl r9,36(r11) + + clrl r9 + + bicl3 #-65536,28(r6),r3 + movzwl 30(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,12(r7),r2 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-780(fp) + mull2 r2,r5 + mull3 r2,r4,-784(fp) + mull2 r0,r4 + addl3 -780(fp),-784(fp),r0 + bicl3 #0,r0,-780(fp) + cmpl -780(fp),-784(fp) + bgequ noname.241 + addl2 #65536,r4 +noname.241: + movzwl -778(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-780(fp),r0 + ashl #16,r0,-784(fp) + addl2 -784(fp),r5 + bicl2 #0,r5 + cmpl r5,-784(fp) + bgequ noname.242 + incl r4 +noname.242: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.243 + incl r2 +noname.243: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.244 + incl r9 +noname.244: + + bicl3 #-65536,24(r6),r3 + movzwl 26(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,16(r7),r2 + movzwl 18(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-788(fp) + mull2 r2,r5 + mull3 r2,r4,-792(fp) + mull2 r0,r4 + addl3 -788(fp),-792(fp),r0 + bicl3 #0,r0,-788(fp) + cmpl -788(fp),-792(fp) + bgequ noname.245 + addl2 #65536,r4 +noname.245: + movzwl -786(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-788(fp),r0 + ashl #16,r0,-792(fp) + addl2 -792(fp),r5 + bicl2 #0,r5 + cmpl r5,-792(fp) + bgequ noname.246 + incl r4 +noname.246: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.247 + incl r2 +noname.247: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.248 + incl r9 +noname.248: + + bicl3 #-65536,20(r6),r3 + movzwl 22(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,20(r7),r2 + movzwl 22(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-796(fp) + mull2 r2,r5 + mull3 r2,r4,-800(fp) + mull2 r0,r4 + addl3 -796(fp),-800(fp),r0 + bicl3 #0,r0,-796(fp) + cmpl -796(fp),-800(fp) + bgequ noname.249 + addl2 #65536,r4 +noname.249: + movzwl -794(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-796(fp),r0 + ashl #16,r0,-800(fp) + addl2 -800(fp),r5 + bicl2 #0,r5 + cmpl r5,-800(fp) + bgequ noname.250 + incl r4 +noname.250: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.251 + incl r2 +noname.251: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.252 + incl r9 +noname.252: + + bicl3 #-65536,16(r6),r3 + movzwl 18(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,24(r7),r2 + movzwl 26(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-804(fp) + mull2 r2,r5 + mull3 r2,r4,-808(fp) + mull2 r0,r4 + addl3 -804(fp),-808(fp),r0 + bicl3 #0,r0,-804(fp) + cmpl -804(fp),-808(fp) + bgequ noname.253 + addl2 #65536,r4 +noname.253: + movzwl -802(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-804(fp),r0 + ashl #16,r0,-808(fp) + addl2 -808(fp),r5 + bicl2 #0,r5 + cmpl r5,-808(fp) + bgequ noname.254 + incl r4 +noname.254: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.255 + incl r2 +noname.255: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.256 + incl r9 +noname.256: + + bicl3 #-65536,12(r6),r3 + movzwl 14(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,28(r7),r2 + movzwl 30(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-812(fp) + mull2 r2,r5 + mull3 r2,r4,-816(fp) + mull2 r0,r4 + addl3 -812(fp),-816(fp),r0 + bicl3 #0,r0,-812(fp) + cmpl -812(fp),-816(fp) + bgequ noname.257 + addl2 #65536,r4 +noname.257: + movzwl -810(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-812(fp),r0 + ashl #16,r0,-816(fp) + addl2 -816(fp),r5 + bicl2 #0,r5 + cmpl r5,-816(fp) + bgequ noname.258 + incl r4 +noname.258: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.259 + incl r2 +noname.259: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.260 + incl r9 +noname.260: + + movl r8,40(r11) + + clrl r8 + + bicl3 #-65536,16(r6),r3 + movzwl 18(r6),r2 + bicl3 #-65536,28(r7),r1 + movzwl 30(r7),r0 + bicl2 #-65536,r0 + movl r3,r4 + bicl3 #-65536,r2,-828(fp) + mull3 r0,r4,-820(fp) + mull2 r1,r4 + mull3 r1,-828(fp),-824(fp) + mull2 r0,-828(fp) + addl3 -820(fp),-824(fp),r0 + bicl3 #0,r0,-820(fp) + cmpl -820(fp),-824(fp) + bgequ noname.261 + addl2 #65536,-828(fp) +noname.261: + movzwl -818(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-828(fp) + bicl3 #-65536,-820(fp),r0 + ashl #16,r0,-824(fp) + addl2 -824(fp),r4 + bicl2 #0,r4 + cmpl r4,-824(fp) + bgequ noname.262 + incl -828(fp) +noname.262: + movl r4,r1 + movl -828(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.263 + incl r2 +noname.263: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.264 + incl r8 +noname.264: + + movzwl 22(r6),r2 + bicl3 #-65536,24(r7),r3 + movzwl 26(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,20(r6),-840(fp) + bicl3 #-65536,r2,-844(fp) + mull3 r0,-840(fp),-832(fp) + mull2 r3,-840(fp) + mull3 r3,-844(fp),-836(fp) + mull2 r0,-844(fp) + addl3 -832(fp),-836(fp),r0 + bicl3 #0,r0,-832(fp) + cmpl -832(fp),-836(fp) + bgequ noname.265 + addl2 #65536,-844(fp) +noname.265: + movzwl -830(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-844(fp) + bicl3 #-65536,-832(fp),r0 + ashl #16,r0,-836(fp) + addl3 -836(fp),-840(fp),r0 + bicl3 #0,r0,-840(fp) + cmpl -840(fp),-836(fp) + bgequ noname.266 + incl -844(fp) +noname.266: + movl -840(fp),r1 + movl -844(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.267 + incl r2 +noname.267: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.268 + incl r8 +noname.268: + + bicl3 #-65536,24(r6),r3 + movzwl 26(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,20(r7),r2 + movzwl 22(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-848(fp) + mull2 r2,r5 + mull3 r2,r4,-852(fp) + mull2 r0,r4 + addl3 -848(fp),-852(fp),r0 + bicl3 #0,r0,-848(fp) + cmpl -848(fp),-852(fp) + bgequ noname.269 + addl2 #65536,r4 +noname.269: + movzwl -846(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-848(fp),r0 + ashl #16,r0,-852(fp) + addl2 -852(fp),r5 + bicl2 #0,r5 + cmpl r5,-852(fp) + bgequ noname.270 + incl r4 +noname.270: + movl r5,r1 + movl r4,r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.271 + incl r2 +noname.271: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.272 + incl r8 +noname.272: + + bicl3 #-65536,28(r6),r3 + movzwl 30(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,16(r7),r2 + movzwl 18(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-856(fp) + mull2 r2,r5 + mull3 r2,r4,-860(fp) + mull2 r0,r4 + addl3 -856(fp),-860(fp),r0 + bicl3 #0,r0,-856(fp) + cmpl -856(fp),-860(fp) + bgequ noname.273 + addl2 #65536,r4 +noname.273: + movzwl -854(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-856(fp),r0 + ashl #16,r0,-860(fp) + addl2 -860(fp),r5 + bicl2 #0,r5 + cmpl r5,-860(fp) + bgequ noname.274 + incl r4 +noname.274: + movl r5,r1 + movl r4,r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.275 + incl r2 +noname.275: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.276 + incl r8 +noname.276: + + movl r10,44(r11) + + clrl r10 + + bicl3 #-65536,28(r6),r3 + movzwl 30(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,20(r7),r2 + movzwl 22(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-864(fp) + mull2 r2,r5 + mull3 r2,r4,-868(fp) + mull2 r0,r4 + addl3 -864(fp),-868(fp),r0 + bicl3 #0,r0,-864(fp) + cmpl -864(fp),-868(fp) + bgequ noname.277 + addl2 #65536,r4 +noname.277: + movzwl -862(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-864(fp),r0 + ashl #16,r0,-868(fp) + addl2 -868(fp),r5 + bicl2 #0,r5 + cmpl r5,-868(fp) + bgequ noname.278 + incl r4 +noname.278: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.279 + incl r2 +noname.279: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.280 + incl r10 +noname.280: + + bicl3 #-65536,24(r6),r3 + movzwl 26(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,24(r7),r2 + movzwl 26(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-872(fp) + mull2 r2,r5 + mull3 r2,r4,-876(fp) + mull2 r0,r4 + addl3 -872(fp),-876(fp),r0 + bicl3 #0,r0,-872(fp) + cmpl -872(fp),-876(fp) + bgequ noname.281 + addl2 #65536,r4 +noname.281: + movzwl -870(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-872(fp),r0 + ashl #16,r0,-876(fp) + addl2 -876(fp),r5 + bicl2 #0,r5 + cmpl r5,-876(fp) + bgequ noname.282 + incl r4 +noname.282: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.283 + incl r2 +noname.283: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.284 + incl r10 +noname.284: + + bicl3 #-65536,20(r6),r3 + movzwl 22(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,28(r7),r2 + movzwl 30(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-880(fp) + mull2 r2,r5 + mull3 r2,r4,-884(fp) + mull2 r0,r4 + addl3 -880(fp),-884(fp),r0 + bicl3 #0,r0,-880(fp) + cmpl -880(fp),-884(fp) + bgequ noname.285 + addl2 #65536,r4 +noname.285: + movzwl -878(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-880(fp),r0 + ashl #16,r0,-884(fp) + addl2 -884(fp),r5 + bicl2 #0,r5 + cmpl r5,-884(fp) + bgequ noname.286 + incl r4 +noname.286: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.287 + incl r2 +noname.287: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.288 + incl r10 +noname.288: + + movl r9,48(r11) + + clrl r9 + + bicl3 #-65536,24(r6),r3 + movzwl 26(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,28(r7),r2 + movzwl 30(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-888(fp) + mull2 r2,r5 + mull3 r2,r4,-892(fp) + mull2 r0,r4 + addl3 -888(fp),-892(fp),r0 + bicl3 #0,r0,-888(fp) + cmpl -888(fp),-892(fp) + bgequ noname.289 + addl2 #65536,r4 +noname.289: + movzwl -886(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-888(fp),r0 + ashl #16,r0,-892(fp) + addl2 -892(fp),r5 + bicl2 #0,r5 + cmpl r5,-892(fp) + bgequ noname.290 + incl r4 +noname.290: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.291 + incl r2 +noname.291: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.292 + incl r9 +noname.292: + + movzwl 30(r6),r2 + bicl3 #-65536,24(r7),r3 + movzwl 26(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,28(r6),-904(fp) + bicl3 #-65536,r2,-908(fp) + mull3 r0,-904(fp),-896(fp) + mull2 r3,-904(fp) + mull3 r3,-908(fp),-900(fp) + mull2 r0,-908(fp) + addl3 -896(fp),-900(fp),r0 + bicl3 #0,r0,-896(fp) + cmpl -896(fp),-900(fp) + bgequ noname.293 + addl2 #65536,-908(fp) +noname.293: + movzwl -894(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-908(fp) + bicl3 #-65536,-896(fp),r0 + ashl #16,r0,-900(fp) + addl3 -900(fp),-904(fp),r0 + bicl3 #0,r0,-904(fp) + cmpl -904(fp),-900(fp) + bgequ noname.294 + incl -908(fp) +noname.294: + movl -904(fp),r1 + movl -908(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.295 + incl r2 +noname.295: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.296 + incl r9 +noname.296: + + movl r8,52(r11) + + clrl r8 + + movzwl 30(r6),r2 + bicl3 #-65536,28(r7),r3 + movzwl 30(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,28(r6),-920(fp) + bicl3 #-65536,r2,-924(fp) + mull3 r0,-920(fp),-912(fp) + mull2 r3,-920(fp) + mull3 r3,-924(fp),-916(fp) + mull2 r0,-924(fp) + addl3 -912(fp),-916(fp),r0 + bicl3 #0,r0,-912(fp) + cmpl -912(fp),-916(fp) + bgequ noname.297 + addl2 #65536,-924(fp) +noname.297: + movzwl -910(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-924(fp) + bicl3 #-65536,-912(fp),r0 + ashl #16,r0,-916(fp) + addl3 -916(fp),-920(fp),r0 + bicl3 #0,r0,-920(fp) + cmpl -920(fp),-916(fp) + bgequ noname.298 + incl -924(fp) +noname.298: + movl -920(fp),r1 + movl -924(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.299 + incl r2 +noname.299: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.300 + incl r8 +noname.300: + + movl r10,56(r11) + + movl r9,60(r11) + + ret + + + +;r=4 ;(AP) +;a=8 ;(AP) +;b=12 ;(AP) +;n=16 ;(AP) n by value (input) + + .psect code,nowrt + +.entry BN_MUL_COMBA4,^m + movab -156(sp),sp + + clrq r9 + + clrl r8 + + movl 8(ap),r6 + bicl3 #-65536,(r6),r3 + movzwl 2(r6),r2 + bicl2 #-65536,r2 + movl 12(ap),r7 + bicl3 #-65536,(r7),r1 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r2,r4 + mull3 r0,r5,-4(fp) + mull2 r1,r5 + mull3 r1,r4,-8(fp) + mull2 r0,r4 + addl3 -4(fp),-8(fp),r0 + bicl3 #0,r0,-4(fp) + cmpl -4(fp),-8(fp) + bgequ noname.303 + addl2 #65536,r4 +noname.303: + movzwl -2(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-4(fp),r0 + ashl #16,r0,-8(fp) + addl2 -8(fp),r5 + bicl2 #0,r5 + cmpl r5,-8(fp) + bgequ noname.304 + incl r4 +noname.304: + movl r5,r1 + movl r4,r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.305 + incl r2 +noname.305: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.306 + incl r8 +noname.306: + + movl 4(ap),r11 + movl r10,(r11) + + clrl r10 + + bicl3 #-65536,(r6),r3 + movzwl 2(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,4(r7),r2 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-12(fp) + mull2 r2,r5 + mull3 r2,r4,-16(fp) + mull2 r0,r4 + addl3 -12(fp),-16(fp),r0 + bicl3 #0,r0,-12(fp) + cmpl -12(fp),-16(fp) + bgequ noname.307 + addl2 #65536,r4 +noname.307: + movzwl -10(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-12(fp),r0 + ashl #16,r0,-16(fp) + addl2 -16(fp),r5 + bicl2 #0,r5 + cmpl r5,-16(fp) + bgequ noname.308 + incl r4 +noname.308: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.309 + incl r2 +noname.309: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.310 + incl r10 +noname.310: + + bicl3 #-65536,4(r6),r3 + movzwl 6(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,(r7),r2 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-20(fp) + mull2 r2,r5 + mull3 r2,r4,-24(fp) + mull2 r0,r4 + addl3 -20(fp),-24(fp),r0 + bicl3 #0,r0,-20(fp) + cmpl -20(fp),-24(fp) + bgequ noname.311 + addl2 #65536,r4 +noname.311: + movzwl -18(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-20(fp),r0 + ashl #16,r0,-24(fp) + addl2 -24(fp),r5 + bicl2 #0,r5 + cmpl r5,-24(fp) + bgequ noname.312 + incl r4 +noname.312: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.313 + incl r2 +noname.313: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.314 + incl r10 +noname.314: + + movl r9,4(r11) + + clrl r9 + + bicl3 #-65536,8(r6),r3 + movzwl 10(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,(r7),r2 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-28(fp) + mull2 r2,r5 + mull3 r2,r4,-32(fp) + mull2 r0,r4 + addl3 -28(fp),-32(fp),r0 + bicl3 #0,r0,-28(fp) + cmpl -28(fp),-32(fp) + bgequ noname.315 + addl2 #65536,r4 +noname.315: + movzwl -26(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-28(fp),r0 + ashl #16,r0,-32(fp) + addl2 -32(fp),r5 + bicl2 #0,r5 + cmpl r5,-32(fp) + bgequ noname.316 + incl r4 +noname.316: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.317 + incl r2 +noname.317: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.318 + incl r9 +noname.318: + + bicl3 #-65536,4(r6),r3 + movzwl 6(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,4(r7),r2 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-36(fp) + mull2 r2,r5 + mull3 r2,r4,-40(fp) + mull2 r0,r4 + addl3 -36(fp),-40(fp),r0 + bicl3 #0,r0,-36(fp) + cmpl -36(fp),-40(fp) + bgequ noname.319 + addl2 #65536,r4 +noname.319: + movzwl -34(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-36(fp),r0 + ashl #16,r0,-40(fp) + addl2 -40(fp),r5 + bicl2 #0,r5 + cmpl r5,-40(fp) + bgequ noname.320 + incl r4 +noname.320: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.321 + incl r2 +noname.321: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.322 + incl r9 +noname.322: + + bicl3 #-65536,(r6),r3 + movzwl 2(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,8(r7),r2 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-44(fp) + mull2 r2,r5 + mull3 r2,r4,-48(fp) + mull2 r0,r4 + addl3 -44(fp),-48(fp),r0 + bicl3 #0,r0,-44(fp) + cmpl -44(fp),-48(fp) + bgequ noname.323 + addl2 #65536,r4 +noname.323: + movzwl -42(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-44(fp),r0 + ashl #16,r0,-48(fp) + addl2 -48(fp),r5 + bicl2 #0,r5 + cmpl r5,-48(fp) + bgequ noname.324 + incl r4 +noname.324: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.325 + incl r2 +noname.325: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.326 + incl r9 +noname.326: + + movl r8,8(r11) + + clrl r8 + + bicl3 #-65536,(r6),r3 + movzwl 2(r6),r2 + bicl3 #-65536,12(r7),r1 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + movl r3,r4 + bicl3 #-65536,r2,-60(fp) + mull3 r0,r4,-52(fp) + mull2 r1,r4 + mull3 r1,-60(fp),-56(fp) + mull2 r0,-60(fp) + addl3 -52(fp),-56(fp),r0 + bicl3 #0,r0,-52(fp) + cmpl -52(fp),-56(fp) + bgequ noname.327 + addl2 #65536,-60(fp) +noname.327: + movzwl -50(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-60(fp) + bicl3 #-65536,-52(fp),r0 + ashl #16,r0,-56(fp) + addl2 -56(fp),r4 + bicl2 #0,r4 + cmpl r4,-56(fp) + bgequ noname.328 + incl -60(fp) +noname.328: + movl r4,r1 + movl -60(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.329 + incl r2 +noname.329: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.330 + incl r8 +noname.330: + + movzwl 6(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r6),-72(fp) + bicl3 #-65536,r2,-76(fp) + mull3 r0,-72(fp),-64(fp) + mull2 r3,-72(fp) + mull3 r3,-76(fp),-68(fp) + mull2 r0,-76(fp) + addl3 -64(fp),-68(fp),r0 + bicl3 #0,r0,-64(fp) + cmpl -64(fp),-68(fp) + bgequ noname.331 + addl2 #65536,-76(fp) +noname.331: + movzwl -62(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-76(fp) + bicl3 #-65536,-64(fp),r0 + ashl #16,r0,-68(fp) + addl3 -68(fp),-72(fp),r0 + bicl3 #0,r0,-72(fp) + cmpl -72(fp),-68(fp) + bgequ noname.332 + incl -76(fp) +noname.332: + movl -72(fp),r1 + movl -76(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.333 + incl r2 +noname.333: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.334 + incl r8 +noname.334: + + bicl3 #-65536,8(r6),r3 + movzwl 10(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,4(r7),r2 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-80(fp) + mull2 r2,r5 + mull3 r2,r4,-84(fp) + mull2 r0,r4 + addl3 -80(fp),-84(fp),r0 + bicl3 #0,r0,-80(fp) + cmpl -80(fp),-84(fp) + bgequ noname.335 + addl2 #65536,r4 +noname.335: + movzwl -78(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-80(fp),r0 + ashl #16,r0,-84(fp) + addl2 -84(fp),r5 + bicl2 #0,r5 + cmpl r5,-84(fp) + bgequ noname.336 + incl r4 +noname.336: + movl r5,r1 + movl r4,r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.337 + incl r2 +noname.337: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.338 + incl r8 +noname.338: + + bicl3 #-65536,12(r6),r3 + movzwl 14(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,(r7),r2 + movzwl 2(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-88(fp) + mull2 r2,r5 + mull3 r2,r4,-92(fp) + mull2 r0,r4 + addl3 -88(fp),-92(fp),r0 + bicl3 #0,r0,-88(fp) + cmpl -88(fp),-92(fp) + bgequ noname.339 + addl2 #65536,r4 +noname.339: + movzwl -86(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-88(fp),r0 + ashl #16,r0,-92(fp) + addl2 -92(fp),r5 + bicl2 #0,r5 + cmpl r5,-92(fp) + bgequ noname.340 + incl r4 +noname.340: + movl r5,r1 + movl r4,r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.341 + incl r2 +noname.341: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.342 + incl r8 +noname.342: + + movl r10,12(r11) + + clrl r10 + + bicl3 #-65536,12(r6),r3 + movzwl 14(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,4(r7),r2 + movzwl 6(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-96(fp) + mull2 r2,r5 + mull3 r2,r4,-100(fp) + mull2 r0,r4 + addl3 -96(fp),-100(fp),r0 + bicl3 #0,r0,-96(fp) + cmpl -96(fp),-100(fp) + bgequ noname.343 + addl2 #65536,r4 +noname.343: + movzwl -94(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-96(fp),r0 + ashl #16,r0,-100(fp) + addl2 -100(fp),r5 + bicl2 #0,r5 + cmpl r5,-100(fp) + bgequ noname.344 + incl r4 +noname.344: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.345 + incl r2 +noname.345: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.346 + incl r10 +noname.346: + + bicl3 #-65536,8(r6),r3 + movzwl 10(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,8(r7),r2 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-104(fp) + mull2 r2,r5 + mull3 r2,r4,-108(fp) + mull2 r0,r4 + addl3 -104(fp),-108(fp),r0 + bicl3 #0,r0,-104(fp) + cmpl -104(fp),-108(fp) + bgequ noname.347 + addl2 #65536,r4 +noname.347: + movzwl -102(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-104(fp),r0 + ashl #16,r0,-108(fp) + addl2 -108(fp),r5 + bicl2 #0,r5 + cmpl r5,-108(fp) + bgequ noname.348 + incl r4 +noname.348: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.349 + incl r2 +noname.349: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.350 + incl r10 +noname.350: + + bicl3 #-65536,4(r6),r3 + movzwl 6(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,12(r7),r2 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-112(fp) + mull2 r2,r5 + mull3 r2,r4,-116(fp) + mull2 r0,r4 + addl3 -112(fp),-116(fp),r0 + bicl3 #0,r0,-112(fp) + cmpl -112(fp),-116(fp) + bgequ noname.351 + addl2 #65536,r4 +noname.351: + movzwl -110(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-112(fp),r0 + ashl #16,r0,-116(fp) + addl2 -116(fp),r5 + bicl2 #0,r5 + cmpl r5,-116(fp) + bgequ noname.352 + incl r4 +noname.352: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.353 + incl r2 +noname.353: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.354 + incl r10 +noname.354: + + movl r9,16(r11) + + clrl r9 + + bicl3 #-65536,8(r6),r3 + movzwl 10(r6),r1 + bicl2 #-65536,r1 + bicl3 #-65536,12(r7),r2 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-120(fp) + mull2 r2,r5 + mull3 r2,r4,-124(fp) + mull2 r0,r4 + addl3 -120(fp),-124(fp),r0 + bicl3 #0,r0,-120(fp) + cmpl -120(fp),-124(fp) + bgequ noname.355 + addl2 #65536,r4 +noname.355: + movzwl -118(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-120(fp),r0 + ashl #16,r0,-124(fp) + addl2 -124(fp),r5 + bicl2 #0,r5 + cmpl r5,-124(fp) + bgequ noname.356 + incl r4 +noname.356: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.357 + incl r2 +noname.357: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.358 + incl r9 +noname.358: + + movzwl 14(r6),r2 + bicl3 #-65536,8(r7),r3 + movzwl 10(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-136(fp) + bicl3 #-65536,r2,-140(fp) + mull3 r0,-136(fp),-128(fp) + mull2 r3,-136(fp) + mull3 r3,-140(fp),-132(fp) + mull2 r0,-140(fp) + addl3 -128(fp),-132(fp),r0 + bicl3 #0,r0,-128(fp) + cmpl -128(fp),-132(fp) + bgequ noname.359 + addl2 #65536,-140(fp) +noname.359: + movzwl -126(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-140(fp) + bicl3 #-65536,-128(fp),r0 + ashl #16,r0,-132(fp) + addl3 -132(fp),-136(fp),r0 + bicl3 #0,r0,-136(fp) + cmpl -136(fp),-132(fp) + bgequ noname.360 + incl -140(fp) +noname.360: + movl -136(fp),r1 + movl -140(fp),r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.361 + incl r2 +noname.361: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.362 + incl r9 +noname.362: + + movl r8,20(r11) + + clrl r8 + + movzwl 14(r6),r2 + bicl3 #-65536,12(r7),r3 + movzwl 14(r7),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r6),-152(fp) + bicl3 #-65536,r2,-156(fp) + mull3 r0,-152(fp),-144(fp) + mull2 r3,-152(fp) + mull3 r3,-156(fp),-148(fp) + mull2 r0,-156(fp) + addl3 -144(fp),-148(fp),r0 + bicl3 #0,r0,-144(fp) + cmpl -144(fp),-148(fp) + bgequ noname.363 + addl2 #65536,-156(fp) +noname.363: + movzwl -142(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-156(fp) + bicl3 #-65536,-144(fp),r0 + ashl #16,r0,-148(fp) + addl3 -148(fp),-152(fp),r0 + bicl3 #0,r0,-152(fp) + cmpl -152(fp),-148(fp) + bgequ noname.364 + incl -156(fp) +noname.364: + movl -152(fp),r1 + movl -156(fp),r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.365 + incl r2 +noname.365: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.366 + incl r8 +noname.366: + + movl r10,24(r11) + + movl r9,28(r11) + + ret + + + +;r=4 ;(AP) +;a=8 ;(AP) +;b=12 ;(AP) +;n=16 ;(AP) n by value (input) + + .psect code,nowrt + +.entry BN_SQR_COMBA8,^m + movab -444(sp),sp + + clrq r8 + + clrl r7 + + movl 8(ap),r4 + movl (r4),r3 + bicl3 #-65536,r3,-4(fp) + extzv #16,#16,r3,r0 + bicl3 #-65536,r0,r3 + movl -4(fp),r0 + mull3 r0,r3,-8(fp) + mull3 r0,r0,-4(fp) + mull2 r3,r3 + bicl3 #32767,-8(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r3 + bicl3 #-65536,-8(fp),r0 + ashl #17,r0,-8(fp) + addl3 -4(fp),-8(fp),r0 + bicl3 #0,r0,-4(fp) + cmpl -4(fp),-8(fp) + bgequ noname.369 + incl r3 +noname.369: + movl -4(fp),r1 + movl r3,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.370 + incl r2 +noname.370: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.371 + incl r7 +noname.371: + + movl r9,@4(ap) + + clrl r9 + + movzwl 6(r4),r2 + bicl3 #-65536,(r4),r3 + movzwl 2(r4),r0 + bicl2 #-65536,r0 + bicl3 #-65536,4(r4),-20(fp) + bicl3 #-65536,r2,-24(fp) + mull3 r0,-20(fp),-12(fp) + mull2 r3,-20(fp) + mull3 r3,-24(fp),-16(fp) + mull2 r0,-24(fp) + addl3 -12(fp),-16(fp),r0 + bicl3 #0,r0,-12(fp) + cmpl -12(fp),-16(fp) + bgequ noname.372 + addl2 #65536,-24(fp) +noname.372: + movzwl -10(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-24(fp) + bicl3 #-65536,-12(fp),r0 + ashl #16,r0,-16(fp) + addl3 -16(fp),-20(fp),r0 + bicl3 #0,r0,-20(fp) + cmpl -20(fp),-16(fp) + bgequ noname.373 + incl -24(fp) +noname.373: + movl -20(fp),r3 + movl -24(fp),r2 + bbc #31,r2,noname.374 + incl r9 +noname.374: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.375 + incl r2 +noname.375: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.376 + incl r2 + bicl3 #0,r2,r0 + bneq noname.376 + incl r9 +noname.376: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.377 + incl r9 +noname.377: + + movl 4(ap),r0 + movl r8,4(r0) + + clrl r8 + + movl 8(ap),r4 + movl 4(r4),r3 + bicl3 #-65536,r3,-28(fp) + extzv #16,#16,r3,r0 + bicl3 #-65536,r0,r3 + movl -28(fp),r0 + mull3 r0,r3,-32(fp) + mull3 r0,r0,-28(fp) + mull2 r3,r3 + bicl3 #32767,-32(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r3 + bicl3 #-65536,-32(fp),r0 + ashl #17,r0,-32(fp) + addl3 -28(fp),-32(fp),r0 + bicl3 #0,r0,-28(fp) + cmpl -28(fp),-32(fp) + bgequ noname.378 + incl r3 +noname.378: + movl -28(fp),r1 + movl r3,r2 + addl2 r1,r7 + bicl2 #0,r7 + cmpl r7,r1 + bgequ noname.379 + incl r2 +noname.379: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.380 + incl r8 +noname.380: + + movzwl 10(r4),r2 + bicl3 #-65536,(r4),r3 + movzwl 2(r4),r0 + bicl2 #-65536,r0 + bicl3 #-65536,8(r4),-44(fp) + bicl3 #-65536,r2,-48(fp) + mull3 r0,-44(fp),-36(fp) + mull2 r3,-44(fp) + mull3 r3,-48(fp),-40(fp) + mull2 r0,-48(fp) + addl3 -36(fp),-40(fp),r0 + bicl3 #0,r0,-36(fp) + cmpl -36(fp),-40(fp) + bgequ noname.381 + addl2 #65536,-48(fp) +noname.381: + movzwl -34(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-48(fp) + bicl3 #-65536,-36(fp),r0 + ashl #16,r0,-40(fp) + addl3 -40(fp),-44(fp),r0 + bicl3 #0,r0,-44(fp) + cmpl -44(fp),-40(fp) + bgequ noname.382 + incl -48(fp) +noname.382: + movl -44(fp),r3 + movl -48(fp),r2 + bbc #31,r2,noname.383 + incl r8 +noname.383: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.384 + incl r2 +noname.384: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.385 + incl r2 + bicl3 #0,r2,r0 + bneq noname.385 + incl r8 +noname.385: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.386 + incl r8 +noname.386: + + movl 4(ap),r0 + movl r7,8(r0) + + clrl r7 + + movl 8(ap),r0 + movzwl 14(r0),r2 + bicl3 #-65536,(r0),r3 + movzwl 2(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,12(r0),-60(fp) + bicl3 #-65536,r2,-64(fp) + mull3 r1,-60(fp),-52(fp) + mull2 r3,-60(fp) + mull3 r3,-64(fp),-56(fp) + mull2 r1,-64(fp) + addl3 -52(fp),-56(fp),r0 + bicl3 #0,r0,-52(fp) + cmpl -52(fp),-56(fp) + bgequ noname.387 + addl2 #65536,-64(fp) +noname.387: + movzwl -50(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-64(fp) + bicl3 #-65536,-52(fp),r0 + ashl #16,r0,-56(fp) + addl3 -56(fp),-60(fp),r0 + bicl3 #0,r0,-60(fp) + cmpl -60(fp),-56(fp) + bgequ noname.388 + incl -64(fp) +noname.388: + movl -60(fp),r3 + movl -64(fp),r2 + bbc #31,r2,noname.389 + incl r7 +noname.389: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.390 + incl r2 +noname.390: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.391 + incl r2 + bicl3 #0,r2,r0 + bneq noname.391 + incl r7 +noname.391: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.392 + incl r7 +noname.392: + + movl 8(ap),r0 + movzwl 10(r0),r2 + bicl3 #-65536,4(r0),r3 + movzwl 6(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,8(r0),-76(fp) + bicl3 #-65536,r2,-80(fp) + mull3 r1,-76(fp),-68(fp) + mull2 r3,-76(fp) + mull3 r3,-80(fp),-72(fp) + mull2 r1,-80(fp) + addl3 -68(fp),-72(fp),r0 + bicl3 #0,r0,-68(fp) + cmpl -68(fp),-72(fp) + bgequ noname.393 + addl2 #65536,-80(fp) +noname.393: + movzwl -66(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-80(fp) + bicl3 #-65536,-68(fp),r0 + ashl #16,r0,-72(fp) + addl3 -72(fp),-76(fp),r0 + bicl3 #0,r0,-76(fp) + cmpl -76(fp),-72(fp) + bgequ noname.394 + incl -80(fp) +noname.394: + movl -76(fp),r3 + movl -80(fp),r2 + bbc #31,r2,noname.395 + incl r7 +noname.395: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.396 + incl r2 +noname.396: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.397 + incl r2 + bicl3 #0,r2,r0 + bneq noname.397 + incl r7 +noname.397: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.398 + incl r7 +noname.398: + + movl 4(ap),r0 + movl r9,12(r0) + + clrl r9 + + movl 8(ap),r2 + movl 8(r2),r4 + bicl3 #-65536,r4,-84(fp) + extzv #16,#16,r4,r0 + bicl3 #-65536,r0,r4 + movl -84(fp),r0 + mull3 r0,r4,-88(fp) + mull3 r0,r0,-84(fp) + mull2 r4,r4 + bicl3 #32767,-88(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r4 + bicl3 #-65536,-88(fp),r0 + ashl #17,r0,-88(fp) + addl3 -84(fp),-88(fp),r0 + bicl3 #0,r0,-84(fp) + cmpl -84(fp),-88(fp) + bgequ noname.399 + incl r4 +noname.399: + movl -84(fp),r1 + movl r4,r3 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.400 + incl r3 +noname.400: + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.401 + incl r9 +noname.401: + + movzwl 14(r2),r3 + bicl3 #-65536,4(r2),r1 + movzwl 6(r2),r0 + bicl2 #-65536,r0 + bicl3 #-65536,12(r2),-100(fp) + bicl3 #-65536,r3,-104(fp) + mull3 r0,-100(fp),-92(fp) + mull2 r1,-100(fp) + mull3 r1,-104(fp),-96(fp) + mull2 r0,-104(fp) + addl3 -92(fp),-96(fp),r0 + bicl3 #0,r0,-92(fp) + cmpl -92(fp),-96(fp) + bgequ noname.402 + addl2 #65536,-104(fp) +noname.402: + movzwl -90(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-104(fp) + bicl3 #-65536,-92(fp),r0 + ashl #16,r0,-96(fp) + addl3 -96(fp),-100(fp),r0 + bicl3 #0,r0,-100(fp) + cmpl -100(fp),-96(fp) + bgequ noname.403 + incl -104(fp) +noname.403: + movl -100(fp),r3 + movl -104(fp),r2 + bbc #31,r2,noname.404 + incl r9 +noname.404: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.405 + incl r2 +noname.405: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.406 + incl r2 + bicl3 #0,r2,r0 + bneq noname.406 + incl r9 +noname.406: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.407 + incl r9 +noname.407: + + movl 8(ap),r0 + movzwl 18(r0),r2 + bicl3 #-65536,(r0),r3 + movzwl 2(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,16(r0),-116(fp) + bicl3 #-65536,r2,-120(fp) + mull3 r1,-116(fp),-108(fp) + mull2 r3,-116(fp) + mull3 r3,-120(fp),-112(fp) + mull2 r1,-120(fp) + addl3 -108(fp),-112(fp),r0 + bicl3 #0,r0,-108(fp) + cmpl -108(fp),-112(fp) + bgequ noname.408 + addl2 #65536,-120(fp) +noname.408: + movzwl -106(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-120(fp) + bicl3 #-65536,-108(fp),r0 + ashl #16,r0,-112(fp) + addl3 -112(fp),-116(fp),r0 + bicl3 #0,r0,-116(fp) + cmpl -116(fp),-112(fp) + bgequ noname.409 + incl -120(fp) +noname.409: + movl -116(fp),r3 + movl -120(fp),r2 + bbc #31,r2,noname.410 + incl r9 +noname.410: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.411 + incl r2 +noname.411: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.412 + incl r2 + bicl3 #0,r2,r0 + bneq noname.412 + incl r9 +noname.412: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.413 + incl r9 +noname.413: + + movl 4(ap),r0 + movl r8,16(r0) + + clrl r8 + + movl 8(ap),r0 + movzwl 22(r0),r2 + bicl3 #-65536,(r0),r3 + movzwl 2(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,20(r0),-132(fp) + bicl3 #-65536,r2,-136(fp) + mull3 r1,-132(fp),-124(fp) + mull2 r3,-132(fp) + mull3 r3,-136(fp),-128(fp) + mull2 r1,-136(fp) + addl3 -124(fp),-128(fp),r0 + bicl3 #0,r0,-124(fp) + cmpl -124(fp),-128(fp) + bgequ noname.414 + addl2 #65536,-136(fp) +noname.414: + movzwl -122(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-136(fp) + bicl3 #-65536,-124(fp),r0 + ashl #16,r0,-128(fp) + addl3 -128(fp),-132(fp),r0 + bicl3 #0,r0,-132(fp) + cmpl -132(fp),-128(fp) + bgequ noname.415 + incl -136(fp) +noname.415: + movl -132(fp),r3 + movl -136(fp),r2 + bbc #31,r2,noname.416 + incl r8 +noname.416: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.417 + incl r2 +noname.417: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.418 + incl r2 + bicl3 #0,r2,r0 + bneq noname.418 + incl r8 +noname.418: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.419 + incl r8 +noname.419: + + movl 8(ap),r0 + movzwl 18(r0),r2 + bicl3 #-65536,4(r0),r3 + movzwl 6(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,16(r0),-148(fp) + bicl3 #-65536,r2,-152(fp) + mull3 r1,-148(fp),-140(fp) + mull2 r3,-148(fp) + mull3 r3,-152(fp),-144(fp) + mull2 r1,-152(fp) + addl3 -140(fp),-144(fp),r0 + bicl3 #0,r0,-140(fp) + cmpl -140(fp),-144(fp) + bgequ noname.420 + addl2 #65536,-152(fp) +noname.420: + movzwl -138(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-152(fp) + bicl3 #-65536,-140(fp),r0 + ashl #16,r0,-144(fp) + addl3 -144(fp),-148(fp),r0 + bicl3 #0,r0,-148(fp) + cmpl -148(fp),-144(fp) + bgequ noname.421 + incl -152(fp) +noname.421: + movl -148(fp),r3 + movl -152(fp),r2 + bbc #31,r2,noname.422 + incl r8 +noname.422: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.423 + incl r2 +noname.423: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.424 + incl r2 + bicl3 #0,r2,r0 + bneq noname.424 + incl r8 +noname.424: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.425 + incl r8 +noname.425: + + movl 8(ap),r0 + movzwl 14(r0),r2 + bicl3 #-65536,8(r0),r3 + movzwl 10(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,12(r0),-164(fp) + bicl3 #-65536,r2,-168(fp) + mull3 r1,-164(fp),-156(fp) + mull2 r3,-164(fp) + mull3 r3,-168(fp),-160(fp) + mull2 r1,-168(fp) + addl3 -156(fp),-160(fp),r0 + bicl3 #0,r0,-156(fp) + cmpl -156(fp),-160(fp) + bgequ noname.426 + addl2 #65536,-168(fp) +noname.426: + movzwl -154(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-168(fp) + bicl3 #-65536,-156(fp),r0 + ashl #16,r0,-160(fp) + addl3 -160(fp),-164(fp),r0 + bicl3 #0,r0,-164(fp) + cmpl -164(fp),-160(fp) + bgequ noname.427 + incl -168(fp) +noname.427: + movl -164(fp),r3 + movl -168(fp),r2 + bbc #31,r2,noname.428 + incl r8 +noname.428: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.429 + incl r2 +noname.429: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.430 + incl r2 + bicl3 #0,r2,r0 + bneq noname.430 + incl r8 +noname.430: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.431 + incl r8 +noname.431: + + movl 4(ap),r0 + movl r7,20(r0) + + clrl r7 + + movl 8(ap),r2 + movl 12(r2),r4 + bicl3 #-65536,r4,-172(fp) + extzv #16,#16,r4,r0 + bicl3 #-65536,r0,r4 + movl -172(fp),r0 + mull3 r0,r4,-176(fp) + mull3 r0,r0,-172(fp) + mull2 r4,r4 + bicl3 #32767,-176(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r4 + bicl3 #-65536,-176(fp),r0 + ashl #17,r0,-176(fp) + addl3 -172(fp),-176(fp),r0 + bicl3 #0,r0,-172(fp) + cmpl -172(fp),-176(fp) + bgequ noname.432 + incl r4 +noname.432: + movl -172(fp),r1 + movl r4,r3 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.433 + incl r3 +noname.433: + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.434 + incl r7 +noname.434: + + movzwl 18(r2),r3 + bicl3 #-65536,8(r2),r1 + movzwl 10(r2),r0 + bicl2 #-65536,r0 + bicl3 #-65536,16(r2),-188(fp) + bicl3 #-65536,r3,-192(fp) + mull3 r0,-188(fp),-180(fp) + mull2 r1,-188(fp) + mull3 r1,-192(fp),-184(fp) + mull2 r0,-192(fp) + addl3 -180(fp),-184(fp),r0 + bicl3 #0,r0,-180(fp) + cmpl -180(fp),-184(fp) + bgequ noname.435 + addl2 #65536,-192(fp) +noname.435: + movzwl -178(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-192(fp) + bicl3 #-65536,-180(fp),r0 + ashl #16,r0,-184(fp) + addl3 -184(fp),-188(fp),r0 + bicl3 #0,r0,-188(fp) + cmpl -188(fp),-184(fp) + bgequ noname.436 + incl -192(fp) +noname.436: + movl -188(fp),r3 + movl -192(fp),r2 + bbc #31,r2,noname.437 + incl r7 +noname.437: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.438 + incl r2 +noname.438: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.439 + incl r2 + bicl3 #0,r2,r0 + bneq noname.439 + incl r7 +noname.439: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.440 + incl r7 +noname.440: + + movl 8(ap),r0 + movzwl 22(r0),r2 + bicl3 #-65536,4(r0),r3 + movzwl 6(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,20(r0),-204(fp) + bicl3 #-65536,r2,-208(fp) + mull3 r1,-204(fp),-196(fp) + mull2 r3,-204(fp) + mull3 r3,-208(fp),-200(fp) + mull2 r1,-208(fp) + addl3 -196(fp),-200(fp),r0 + bicl3 #0,r0,-196(fp) + cmpl -196(fp),-200(fp) + bgequ noname.441 + addl2 #65536,-208(fp) +noname.441: + movzwl -194(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-208(fp) + bicl3 #-65536,-196(fp),r0 + ashl #16,r0,-200(fp) + addl3 -200(fp),-204(fp),r0 + bicl3 #0,r0,-204(fp) + cmpl -204(fp),-200(fp) + bgequ noname.442 + incl -208(fp) +noname.442: + movl -204(fp),r3 + movl -208(fp),r2 + bbc #31,r2,noname.443 + incl r7 +noname.443: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.444 + incl r2 +noname.444: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.445 + incl r2 + bicl3 #0,r2,r0 + bneq noname.445 + incl r7 +noname.445: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.446 + incl r7 +noname.446: + + movl 8(ap),r0 + movzwl 26(r0),r2 + bicl3 #-65536,(r0),r3 + movzwl 2(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,24(r0),-220(fp) + bicl3 #-65536,r2,-224(fp) + mull3 r1,-220(fp),-212(fp) + mull2 r3,-220(fp) + mull3 r3,-224(fp),-216(fp) + mull2 r1,-224(fp) + addl3 -212(fp),-216(fp),r0 + bicl3 #0,r0,-212(fp) + cmpl -212(fp),-216(fp) + bgequ noname.447 + addl2 #65536,-224(fp) +noname.447: + movzwl -210(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-224(fp) + bicl3 #-65536,-212(fp),r0 + ashl #16,r0,-216(fp) + addl3 -216(fp),-220(fp),r0 + bicl3 #0,r0,-220(fp) + cmpl -220(fp),-216(fp) + bgequ noname.448 + incl -224(fp) +noname.448: + movl -220(fp),r3 + movl -224(fp),r2 + bbc #31,r2,noname.449 + incl r7 +noname.449: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.450 + incl r2 +noname.450: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.451 + incl r2 + bicl3 #0,r2,r0 + bneq noname.451 + incl r7 +noname.451: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.452 + incl r7 +noname.452: + + movl 4(ap),r0 + movl r9,24(r0) + + clrl r9 + + movl 8(ap),r0 + movzwl 30(r0),r2 + bicl3 #-65536,(r0),r3 + movzwl 2(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,28(r0),-236(fp) + bicl3 #-65536,r2,-240(fp) + mull3 r1,-236(fp),-228(fp) + mull2 r3,-236(fp) + mull3 r3,-240(fp),-232(fp) + mull2 r1,-240(fp) + addl3 -228(fp),-232(fp),r0 + bicl3 #0,r0,-228(fp) + cmpl -228(fp),-232(fp) + bgequ noname.453 + addl2 #65536,-240(fp) +noname.453: + movzwl -226(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-240(fp) + bicl3 #-65536,-228(fp),r0 + ashl #16,r0,-232(fp) + addl3 -232(fp),-236(fp),r0 + bicl3 #0,r0,-236(fp) + cmpl -236(fp),-232(fp) + bgequ noname.454 + incl -240(fp) +noname.454: + movl -236(fp),r3 + movl -240(fp),r2 + bbc #31,r2,noname.455 + incl r9 +noname.455: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.456 + incl r2 +noname.456: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.457 + incl r2 + bicl3 #0,r2,r0 + bneq noname.457 + incl r9 +noname.457: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.458 + incl r9 +noname.458: + + movl 8(ap),r0 + movzwl 26(r0),r2 + bicl3 #-65536,4(r0),r3 + movzwl 6(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,24(r0),-252(fp) + bicl3 #-65536,r2,-256(fp) + mull3 r1,-252(fp),-244(fp) + mull2 r3,-252(fp) + mull3 r3,-256(fp),-248(fp) + mull2 r1,-256(fp) + addl3 -244(fp),-248(fp),r0 + bicl3 #0,r0,-244(fp) + cmpl -244(fp),-248(fp) + bgequ noname.459 + addl2 #65536,-256(fp) +noname.459: + movzwl -242(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-256(fp) + bicl3 #-65536,-244(fp),r0 + ashl #16,r0,-248(fp) + addl3 -248(fp),-252(fp),r0 + bicl3 #0,r0,-252(fp) + cmpl -252(fp),-248(fp) + bgequ noname.460 + incl -256(fp) +noname.460: + movl -252(fp),r3 + movl -256(fp),r2 + bbc #31,r2,noname.461 + incl r9 +noname.461: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.462 + incl r2 +noname.462: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.463 + incl r2 + bicl3 #0,r2,r0 + bneq noname.463 + incl r9 +noname.463: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.464 + incl r9 +noname.464: + + movl 8(ap),r0 + movzwl 22(r0),r2 + bicl3 #-65536,8(r0),r3 + movzwl 10(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,20(r0),-268(fp) + bicl3 #-65536,r2,-272(fp) + mull3 r1,-268(fp),-260(fp) + mull2 r3,-268(fp) + mull3 r3,-272(fp),-264(fp) + mull2 r1,-272(fp) + addl3 -260(fp),-264(fp),r0 + bicl3 #0,r0,-260(fp) + cmpl -260(fp),-264(fp) + bgequ noname.465 + addl2 #65536,-272(fp) +noname.465: + movzwl -258(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-272(fp) + bicl3 #-65536,-260(fp),r0 + ashl #16,r0,-264(fp) + addl3 -264(fp),-268(fp),r0 + bicl3 #0,r0,-268(fp) + cmpl -268(fp),-264(fp) + bgequ noname.466 + incl -272(fp) +noname.466: + movl -268(fp),r3 + movl -272(fp),r2 + bbc #31,r2,noname.467 + incl r9 +noname.467: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.468 + incl r2 +noname.468: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.469 + incl r2 + bicl3 #0,r2,r0 + bneq noname.469 + incl r9 +noname.469: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.470 + incl r9 +noname.470: + + movl 8(ap),r0 + movzwl 18(r0),r2 + bicl3 #-65536,12(r0),r3 + movzwl 14(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,16(r0),-284(fp) + bicl3 #-65536,r2,-288(fp) + mull3 r1,-284(fp),-276(fp) + mull2 r3,-284(fp) + mull3 r3,-288(fp),-280(fp) + mull2 r1,-288(fp) + addl3 -276(fp),-280(fp),r0 + bicl3 #0,r0,-276(fp) + cmpl -276(fp),-280(fp) + bgequ noname.471 + addl2 #65536,-288(fp) +noname.471: + movzwl -274(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-288(fp) + bicl3 #-65536,-276(fp),r0 + ashl #16,r0,-280(fp) + addl3 -280(fp),-284(fp),r0 + bicl3 #0,r0,-284(fp) + cmpl -284(fp),-280(fp) + bgequ noname.472 + incl -288(fp) +noname.472: + movl -284(fp),r3 + movl -288(fp),r2 + bbc #31,r2,noname.473 + incl r9 +noname.473: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.474 + incl r2 +noname.474: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.475 + incl r2 + bicl3 #0,r2,r0 + bneq noname.475 + incl r9 +noname.475: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.476 + incl r9 +noname.476: + + movl 4(ap),r0 + movl r8,28(r0) + + clrl r8 + + movl 8(ap),r3 + movl 16(r3),r4 + bicl3 #-65536,r4,r5 + extzv #16,#16,r4,r0 + bicl3 #-65536,r0,r4 + mull3 r5,r4,-292(fp) + mull2 r5,r5 + mull2 r4,r4 + bicl3 #32767,-292(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r4 + bicl3 #-65536,-292(fp),r0 + ashl #17,r0,-292(fp) + addl2 -292(fp),r5 + bicl2 #0,r5 + cmpl r5,-292(fp) + bgequ noname.477 + incl r4 +noname.477: + movl r5,r1 + movl r4,r2 + addl2 r1,r7 + bicl2 #0,r7 + cmpl r7,r1 + bgequ noname.478 + incl r2 +noname.478: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.479 + incl r8 +noname.479: + + bicl3 #-65536,20(r3),r4 + movzwl 22(r3),r1 + bicl2 #-65536,r1 + bicl3 #-65536,12(r3),r2 + movzwl 14(r3),r0 + bicl2 #-65536,r0 + movl r4,r6 + movl r1,r5 + mull3 r0,r6,-296(fp) + mull2 r2,r6 + mull3 r2,r5,-300(fp) + mull2 r0,r5 + addl3 -296(fp),-300(fp),r0 + bicl3 #0,r0,-296(fp) + cmpl -296(fp),-300(fp) + bgequ noname.480 + addl2 #65536,r5 +noname.480: + movzwl -294(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r5 + bicl3 #-65536,-296(fp),r0 + ashl #16,r0,-300(fp) + addl2 -300(fp),r6 + bicl2 #0,r6 + cmpl r6,-300(fp) + bgequ noname.481 + incl r5 +noname.481: + movl r6,r3 + movl r5,r2 + bbc #31,r2,noname.482 + incl r8 +noname.482: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.483 + incl r2 +noname.483: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.484 + incl r2 + bicl3 #0,r2,r0 + bneq noname.484 + incl r8 +noname.484: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.485 + incl r8 +noname.485: + + movl 8(ap),r0 + bicl3 #-65536,24(r0),r3 + movzwl 26(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,8(r0),r2 + movzwl 10(r0),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-304(fp) + mull2 r2,r5 + mull3 r2,r4,-308(fp) + mull2 r0,r4 + addl3 -304(fp),-308(fp),r0 + bicl3 #0,r0,-304(fp) + cmpl -304(fp),-308(fp) + bgequ noname.486 + addl2 #65536,r4 +noname.486: + movzwl -302(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-304(fp),r0 + ashl #16,r0,-308(fp) + addl2 -308(fp),r5 + bicl2 #0,r5 + cmpl r5,-308(fp) + bgequ noname.487 + incl r4 +noname.487: + movl r5,r3 + movl r4,r2 + bbc #31,r2,noname.488 + incl r8 +noname.488: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.489 + incl r2 +noname.489: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.490 + incl r2 + bicl3 #0,r2,r0 + bneq noname.490 + incl r8 +noname.490: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.491 + incl r8 +noname.491: + + movl 8(ap),r0 + bicl3 #-65536,28(r0),r3 + movzwl 30(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,4(r0),r2 + movzwl 6(r0),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-312(fp) + mull2 r2,r5 + mull3 r2,r4,-316(fp) + mull2 r0,r4 + addl3 -312(fp),-316(fp),r0 + bicl3 #0,r0,-312(fp) + cmpl -312(fp),-316(fp) + bgequ noname.492 + addl2 #65536,r4 +noname.492: + movzwl -310(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-312(fp),r0 + ashl #16,r0,-316(fp) + addl2 -316(fp),r5 + bicl2 #0,r5 + cmpl r5,-316(fp) + bgequ noname.493 + incl r4 +noname.493: + movl r5,r3 + movl r4,r2 + bbc #31,r2,noname.494 + incl r8 +noname.494: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.495 + incl r2 +noname.495: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.496 + incl r2 + bicl3 #0,r2,r0 + bneq noname.496 + incl r8 +noname.496: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.497 + incl r8 +noname.497: + + movl 4(ap),r0 + movl r7,32(r0) + + clrl r7 + + movl 8(ap),r0 + bicl3 #-65536,28(r0),r3 + movzwl 30(r0),r2 + bicl3 #-65536,8(r0),r1 + movzwl 10(r0),r0 + bicl2 #-65536,r0 + movl r3,r4 + bicl3 #-65536,r2,-328(fp) + mull3 r0,r4,-320(fp) + mull2 r1,r4 + mull3 r1,-328(fp),-324(fp) + mull2 r0,-328(fp) + addl3 -320(fp),-324(fp),r0 + bicl3 #0,r0,-320(fp) + cmpl -320(fp),-324(fp) + bgequ noname.498 + addl2 #65536,-328(fp) +noname.498: + movzwl -318(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-328(fp) + bicl3 #-65536,-320(fp),r0 + ashl #16,r0,-324(fp) + addl2 -324(fp),r4 + bicl2 #0,r4 + cmpl r4,-324(fp) + bgequ noname.499 + incl -328(fp) +noname.499: + movl r4,r3 + movl -328(fp),r2 + bbc #31,r2,noname.500 + incl r7 +noname.500: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.501 + incl r2 +noname.501: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.502 + incl r2 + bicl3 #0,r2,r0 + bneq noname.502 + incl r7 +noname.502: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.503 + incl r7 +noname.503: + + movl 8(ap),r0 + movzwl 26(r0),r2 + bicl3 #-65536,12(r0),r3 + movzwl 14(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,24(r0),-340(fp) + bicl3 #-65536,r2,-344(fp) + mull3 r1,-340(fp),-332(fp) + mull2 r3,-340(fp) + mull3 r3,-344(fp),-336(fp) + mull2 r1,-344(fp) + addl3 -332(fp),-336(fp),r0 + bicl3 #0,r0,-332(fp) + cmpl -332(fp),-336(fp) + bgequ noname.504 + addl2 #65536,-344(fp) +noname.504: + movzwl -330(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-344(fp) + bicl3 #-65536,-332(fp),r0 + ashl #16,r0,-336(fp) + addl3 -336(fp),-340(fp),r0 + bicl3 #0,r0,-340(fp) + cmpl -340(fp),-336(fp) + bgequ noname.505 + incl -344(fp) +noname.505: + movl -340(fp),r3 + movl -344(fp),r2 + bbc #31,r2,noname.506 + incl r7 +noname.506: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.507 + incl r2 +noname.507: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.508 + incl r2 + bicl3 #0,r2,r0 + bneq noname.508 + incl r7 +noname.508: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.509 + incl r7 +noname.509: + + movl 8(ap),r0 + movzwl 22(r0),r2 + bicl3 #-65536,16(r0),r3 + movzwl 18(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,20(r0),-356(fp) + bicl3 #-65536,r2,-360(fp) + mull3 r1,-356(fp),-348(fp) + mull2 r3,-356(fp) + mull3 r3,-360(fp),-352(fp) + mull2 r1,-360(fp) + addl3 -348(fp),-352(fp),r0 + bicl3 #0,r0,-348(fp) + cmpl -348(fp),-352(fp) + bgequ noname.510 + addl2 #65536,-360(fp) +noname.510: + movzwl -346(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-360(fp) + bicl3 #-65536,-348(fp),r0 + ashl #16,r0,-352(fp) + addl3 -352(fp),-356(fp),r0 + bicl3 #0,r0,-356(fp) + cmpl -356(fp),-352(fp) + bgequ noname.511 + incl -360(fp) +noname.511: + movl -356(fp),r3 + movl -360(fp),r2 + bbc #31,r2,noname.512 + incl r7 +noname.512: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.513 + incl r2 +noname.513: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.514 + incl r2 + bicl3 #0,r2,r0 + bneq noname.514 + incl r7 +noname.514: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.515 + incl r7 +noname.515: + + movl 4(ap),r0 + movl r9,36(r0) + + clrl r9 + + movl 8(ap),r3 + movl 20(r3),r4 + bicl3 #-65536,r4,-364(fp) + extzv #16,#16,r4,r0 + bicl3 #-65536,r0,r4 + movl -364(fp),r0 + mull3 r0,r4,-368(fp) + mull3 r0,r0,-364(fp) + mull2 r4,r4 + bicl3 #32767,-368(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r4 + bicl3 #-65536,-368(fp),r0 + ashl #17,r0,-368(fp) + addl3 -364(fp),-368(fp),r0 + bicl3 #0,r0,-364(fp) + cmpl -364(fp),-368(fp) + bgequ noname.516 + incl r4 +noname.516: + movl -364(fp),r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.517 + incl r2 +noname.517: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.518 + incl r9 +noname.518: + + bicl3 #-65536,24(r3),r4 + movzwl 26(r3),r1 + bicl2 #-65536,r1 + bicl3 #-65536,16(r3),r2 + movzwl 18(r3),r0 + bicl2 #-65536,r0 + movl r4,r6 + movl r1,r5 + mull3 r0,r6,-372(fp) + mull2 r2,r6 + mull3 r2,r5,-376(fp) + mull2 r0,r5 + addl3 -372(fp),-376(fp),r0 + bicl3 #0,r0,-372(fp) + cmpl -372(fp),-376(fp) + bgequ noname.519 + addl2 #65536,r5 +noname.519: + movzwl -370(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r5 + bicl3 #-65536,-372(fp),r0 + ashl #16,r0,-376(fp) + addl2 -376(fp),r6 + bicl2 #0,r6 + cmpl r6,-376(fp) + bgequ noname.520 + incl r5 +noname.520: + movl r6,r3 + movl r5,r2 + bbc #31,r2,noname.521 + incl r9 +noname.521: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.522 + incl r2 +noname.522: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.523 + incl r2 + bicl3 #0,r2,r0 + bneq noname.523 + incl r9 +noname.523: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.524 + incl r9 +noname.524: + + movl 8(ap),r0 + bicl3 #-65536,28(r0),r3 + movzwl 30(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,12(r0),r2 + movzwl 14(r0),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-380(fp) + mull2 r2,r5 + mull3 r2,r4,-384(fp) + mull2 r0,r4 + addl3 -380(fp),-384(fp),r0 + bicl3 #0,r0,-380(fp) + cmpl -380(fp),-384(fp) + bgequ noname.525 + addl2 #65536,r4 +noname.525: + movzwl -378(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-380(fp),r0 + ashl #16,r0,-384(fp) + addl2 -384(fp),r5 + bicl2 #0,r5 + cmpl r5,-384(fp) + bgequ noname.526 + incl r4 +noname.526: + movl r5,r3 + movl r4,r2 + bbc #31,r2,noname.527 + incl r9 +noname.527: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.528 + incl r2 +noname.528: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.529 + incl r2 + bicl3 #0,r2,r0 + bneq noname.529 + incl r9 +noname.529: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.530 + incl r9 +noname.530: + movl 4(ap),r0 + movl r8,40(r0) + + clrl r8 + + movl 8(ap),r0 + bicl3 #-65536,28(r0),r3 + movzwl 30(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,16(r0),r2 + movzwl 18(r0),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-388(fp) + mull2 r2,r5 + mull3 r2,r4,-392(fp) + mull2 r0,r4 + addl3 -388(fp),-392(fp),r0 + bicl3 #0,r0,-388(fp) + cmpl -388(fp),-392(fp) + bgequ noname.531 + addl2 #65536,r4 +noname.531: + movzwl -386(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-388(fp),r0 + ashl #16,r0,-392(fp) + addl2 -392(fp),r5 + bicl2 #0,r5 + cmpl r5,-392(fp) + bgequ noname.532 + incl r4 +noname.532: + movl r5,r3 + movl r4,r2 + bbc #31,r2,noname.533 + incl r8 +noname.533: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.534 + incl r2 +noname.534: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.535 + incl r2 + bicl3 #0,r2,r0 + bneq noname.535 + incl r8 +noname.535: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.536 + incl r8 +noname.536: + + movl 8(ap),r0 + bicl3 #-65536,24(r0),r3 + movzwl 26(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,20(r0),r2 + movzwl 22(r0),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-396(fp) + mull2 r2,r5 + mull3 r2,r4,-400(fp) + mull2 r0,r4 + addl3 -396(fp),-400(fp),r0 + bicl3 #0,r0,-396(fp) + cmpl -396(fp),-400(fp) + bgequ noname.537 + addl2 #65536,r4 +noname.537: + movzwl -394(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-396(fp),r0 + ashl #16,r0,-400(fp) + addl2 -400(fp),r5 + bicl2 #0,r5 + cmpl r5,-400(fp) + bgequ noname.538 + incl r4 +noname.538: + movl r5,r3 + movl r4,r2 + bbc #31,r2,noname.539 + incl r8 +noname.539: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.540 + incl r2 +noname.540: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r7 + bicl2 #0,r7 + cmpl r7,r3 + bgequ noname.541 + incl r2 + bicl3 #0,r2,r0 + bneq noname.541 + incl r8 +noname.541: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.542 + incl r8 +noname.542: + + movl 4(ap),r0 + movl r7,44(r0) + + clrl r7 + + movl 8(ap),r3 + movl 24(r3),r4 + bicl3 #-65536,r4,r5 + extzv #16,#16,r4,r0 + bicl3 #-65536,r0,r4 + mull3 r5,r4,-404(fp) + mull2 r5,r5 + mull2 r4,r4 + bicl3 #32767,-404(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r4 + bicl3 #-65536,-404(fp),r0 + ashl #17,r0,-404(fp) + addl2 -404(fp),r5 + bicl2 #0,r5 + cmpl r5,-404(fp) + bgequ noname.543 + incl r4 +noname.543: + movl r5,r1 + movl r4,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.544 + incl r2 +noname.544: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.545 + incl r7 +noname.545: + + movzwl 30(r3),r2 + bicl3 #-65536,20(r3),r1 + movzwl 22(r3),r0 + bicl2 #-65536,r0 + bicl3 #-65536,28(r3),-416(fp) + bicl3 #-65536,r2,-420(fp) + mull3 r0,-416(fp),-408(fp) + mull2 r1,-416(fp) + mull3 r1,-420(fp),-412(fp) + mull2 r0,-420(fp) + addl3 -408(fp),-412(fp),r0 + bicl3 #0,r0,-408(fp) + cmpl -408(fp),-412(fp) + bgequ noname.546 + addl2 #65536,-420(fp) +noname.546: + movzwl -406(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-420(fp) + bicl3 #-65536,-408(fp),r0 + ashl #16,r0,-412(fp) + addl3 -412(fp),-416(fp),r0 + bicl3 #0,r0,-416(fp) + cmpl -416(fp),-412(fp) + bgequ noname.547 + incl -420(fp) +noname.547: + movl -416(fp),r3 + movl -420(fp),r2 + bbc #31,r2,noname.548 + incl r7 +noname.548: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.549 + incl r2 +noname.549: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.550 + incl r2 + bicl3 #0,r2,r0 + bneq noname.550 + incl r7 +noname.550: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.551 + incl r7 +noname.551: + + movl 4(ap),r0 + movl r9,48(r0) + + clrl r9 + + movl 8(ap),r0 + movzwl 30(r0),r2 + bicl3 #-65536,24(r0),r3 + movzwl 26(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,28(r0),-432(fp) + bicl3 #-65536,r2,-436(fp) + mull3 r1,-432(fp),-424(fp) + mull2 r3,-432(fp) + mull3 r3,-436(fp),-428(fp) + mull2 r1,-436(fp) + addl3 -424(fp),-428(fp),r0 + bicl3 #0,r0,-424(fp) + cmpl -424(fp),-428(fp) + bgequ noname.552 + addl2 #65536,-436(fp) +noname.552: + movzwl -422(fp),r0 + bicl2 #-65536,r0 + addl2 r0,-436(fp) + bicl3 #-65536,-424(fp),r0 + ashl #16,r0,-428(fp) + addl3 -428(fp),-432(fp),r0 + bicl3 #0,r0,-432(fp) + cmpl -432(fp),-428(fp) + bgequ noname.553 + incl -436(fp) +noname.553: + movl -432(fp),r3 + movl -436(fp),r2 + bbc #31,r2,noname.554 + incl r9 +noname.554: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.555 + incl r2 +noname.555: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.556 + incl r2 + bicl3 #0,r2,r0 + bneq noname.556 + incl r9 +noname.556: + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.557 + incl r9 +noname.557: + + movl 4(ap),r4 + movl r8,52(r4) + + clrl r8 + + movl 8(ap),r0 + movl 28(r0),r3 + bicl3 #-65536,r3,-440(fp) + extzv #16,#16,r3,r0 + bicl3 #-65536,r0,r3 + movl -440(fp),r0 + mull3 r0,r3,-444(fp) + mull3 r0,r0,-440(fp) + mull2 r3,r3 + bicl3 #32767,-444(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r3 + bicl3 #-65536,-444(fp),r0 + ashl #17,r0,-444(fp) + addl3 -440(fp),-444(fp),r0 + bicl3 #0,r0,-440(fp) + cmpl -440(fp),-444(fp) + bgequ noname.558 + incl r3 +noname.558: + movl -440(fp),r1 + movl r3,r2 + addl2 r1,r7 + bicl2 #0,r7 + cmpl r7,r1 + bgequ noname.559 + incl r2 +noname.559: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.560 + incl r8 +noname.560: + + movl r7,56(r4) + + movl r9,60(r4) + + ret + + + +;r=4 ;(AP) +;a=8 ;(AP) +;b=12 ;(AP) +;n=16 ;(AP) n by value (input) + + .psect code,nowrt + +.entry BN_SQR_COMBA4,^m + subl2 #44,sp + + clrq r8 + + clrl r10 + + movl 8(ap),r5 + movl (r5),r3 + bicl3 #-65536,r3,r4 + extzv #16,#16,r3,r0 + bicl3 #-65536,r0,r3 + mull3 r4,r3,-4(fp) + mull2 r4,r4 + mull2 r3,r3 + bicl3 #32767,-4(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r3 + bicl3 #-65536,-4(fp),r0 + ashl #17,r0,-4(fp) + addl2 -4(fp),r4 + bicl2 #0,r4 + cmpl r4,-4(fp) + bgequ noname.563 + incl r3 +noname.563: + movl r4,r1 + movl r3,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.564 + incl r2 +noname.564: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.565 + incl r10 +noname.565: + + movl r9,@4(ap) + + clrl r9 + + bicl3 #-65536,4(r5),r3 + movzwl 6(r5),r1 + bicl2 #-65536,r1 + bicl3 #-65536,(r5),r2 + movzwl 2(r5),r0 + bicl2 #-65536,r0 + movl r3,r6 + movl r1,r4 + mull3 r0,r6,-8(fp) + mull2 r2,r6 + mull2 r4,r2 + mull2 r0,r4 + addl3 -8(fp),r2,r0 + bicl3 #0,r0,-8(fp) + cmpl -8(fp),r2 + bgequ noname.566 + addl2 #65536,r4 +noname.566: + movzwl -6(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-8(fp),r0 + ashl #16,r0,r1 + addl2 r1,r6 + bicl2 #0,r6 + cmpl r6,r1 + bgequ noname.567 + incl r4 +noname.567: + movl r6,r3 + movl r4,r2 + bbc #31,r2,noname.568 + incl r9 +noname.568: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.569 + incl r2 +noname.569: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.570 + incl r2 + bicl3 #0,r2,r0 + bneq noname.570 + incl r9 +noname.570: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.571 + incl r9 +noname.571: + + movl 4(ap),r0 + movl r8,4(r0) + + clrl r8 + + movl 8(ap),r4 + movl 4(r4),r3 + bicl3 #-65536,r3,r5 + extzv #16,#16,r3,r0 + bicl3 #-65536,r0,r3 + mull3 r5,r3,r1 + mull2 r5,r5 + mull2 r3,r3 + bicl3 #32767,r1,r0 + extzv #15,#17,r0,r0 + addl2 r0,r3 + bicl2 #-65536,r1 + ashl #17,r1,r1 + addl2 r1,r5 + bicl2 #0,r5 + cmpl r5,r1 + bgequ noname.572 + incl r3 +noname.572: + movl r5,r1 + movl r3,r2 + addl2 r1,r10 + bicl2 #0,r10 + cmpl r10,r1 + bgequ noname.573 + incl r2 +noname.573: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.574 + incl r8 +noname.574: + + bicl3 #-65536,8(r4),r3 + movzwl 10(r4),r1 + bicl2 #-65536,r1 + bicl3 #-65536,(r4),r2 + movzwl 2(r4),r0 + bicl2 #-65536,r0 + movl r3,r6 + movl r1,r5 + mull3 r0,r6,r7 + mull2 r2,r6 + mull2 r5,r2 + mull2 r0,r5 + addl2 r2,r7 + bicl2 #0,r7 + cmpl r7,r2 + bgequ noname.575 + addl2 #65536,r5 +noname.575: + extzv #16,#16,r7,r0 + bicl2 #-65536,r0 + addl2 r0,r5 + bicl3 #-65536,r7,r0 + ashl #16,r0,r1 + addl2 r1,r6 + bicl2 #0,r6 + cmpl r6,r1 + bgequ noname.576 + incl r5 +noname.576: + movl r6,r3 + movl r5,r2 + bbc #31,r2,noname.577 + incl r8 +noname.577: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.578 + incl r2 +noname.578: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r10 + bicl2 #0,r10 + cmpl r10,r3 + bgequ noname.579 + incl r2 + bicl3 #0,r2,r0 + bneq noname.579 + incl r8 +noname.579: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.580 + incl r8 +noname.580: + + movl 4(ap),r0 + movl r10,8(r0) + + clrl r10 + + movl 8(ap),r0 + bicl3 #-65536,12(r0),r3 + movzwl 14(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,(r0),r2 + movzwl 2(r0),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,r6 + mull2 r2,r5 + mull3 r2,r4,-12(fp) + mull2 r0,r4 + addl2 -12(fp),r6 + bicl2 #0,r6 + cmpl r6,-12(fp) + bgequ noname.581 + addl2 #65536,r4 +noname.581: + extzv #16,#16,r6,r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,r6,r0 + ashl #16,r0,-12(fp) + addl2 -12(fp),r5 + bicl2 #0,r5 + cmpl r5,-12(fp) + bgequ noname.582 + incl r4 +noname.582: + movl r5,r3 + movl r4,r2 + bbc #31,r2,noname.583 + incl r10 +noname.583: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.584 + incl r2 +noname.584: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.585 + incl r2 + bicl3 #0,r2,r0 + bneq noname.585 + incl r10 +noname.585: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.586 + incl r10 +noname.586: + + movl 8(ap),r0 + bicl3 #-65536,8(r0),r3 + movzwl 10(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,4(r0),r2 + movzwl 6(r0),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-16(fp) + mull2 r2,r5 + mull3 r2,r4,-20(fp) + mull2 r0,r4 + addl3 -16(fp),-20(fp),r0 + bicl3 #0,r0,-16(fp) + cmpl -16(fp),-20(fp) + bgequ noname.587 + addl2 #65536,r4 +noname.587: + movzwl -14(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-16(fp),r0 + ashl #16,r0,-20(fp) + addl2 -20(fp),r5 + bicl2 #0,r5 + cmpl r5,-20(fp) + bgequ noname.588 + incl r4 +noname.588: + movl r5,r3 + movl r4,r2 + bbc #31,r2,noname.589 + incl r10 +noname.589: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.590 + incl r2 +noname.590: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r9 + bicl2 #0,r9 + cmpl r9,r3 + bgequ noname.591 + incl r2 + bicl3 #0,r2,r0 + bneq noname.591 + incl r10 +noname.591: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.592 + incl r10 +noname.592: + movl 4(ap),r0 + movl r9,12(r0) + + clrl r9 + + movl 8(ap),r3 + movl 8(r3),r4 + bicl3 #-65536,r4,r5 + extzv #16,#16,r4,r0 + bicl3 #-65536,r0,r4 + mull3 r5,r4,-24(fp) + mull2 r5,r5 + mull2 r4,r4 + bicl3 #32767,-24(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r4 + bicl3 #-65536,-24(fp),r0 + ashl #17,r0,-24(fp) + addl2 -24(fp),r5 + bicl2 #0,r5 + cmpl r5,-24(fp) + bgequ noname.593 + incl r4 +noname.593: + movl r5,r1 + movl r4,r2 + addl2 r1,r8 + bicl2 #0,r8 + cmpl r8,r1 + bgequ noname.594 + incl r2 +noname.594: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.595 + incl r9 +noname.595: + + bicl3 #-65536,12(r3),r4 + movzwl 14(r3),r1 + bicl2 #-65536,r1 + bicl3 #-65536,4(r3),r2 + movzwl 6(r3),r0 + bicl2 #-65536,r0 + movl r4,r6 + movl r1,r5 + mull3 r0,r6,-28(fp) + mull2 r2,r6 + mull3 r2,r5,-32(fp) + mull2 r0,r5 + addl3 -28(fp),-32(fp),r0 + bicl3 #0,r0,-28(fp) + cmpl -28(fp),-32(fp) + bgequ noname.596 + addl2 #65536,r5 +noname.596: + movzwl -26(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r5 + bicl3 #-65536,-28(fp),r0 + ashl #16,r0,-32(fp) + addl2 -32(fp),r6 + bicl2 #0,r6 + cmpl r6,-32(fp) + bgequ noname.597 + incl r5 +noname.597: + movl r6,r3 + movl r5,r2 + bbc #31,r2,noname.598 + incl r9 +noname.598: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.599 + incl r2 +noname.599: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r8 + bicl2 #0,r8 + cmpl r8,r3 + bgequ noname.600 + incl r2 + bicl3 #0,r2,r0 + bneq noname.600 + incl r9 +noname.600: + addl2 r2,r10 + bicl2 #0,r10 + cmpl r10,r2 + bgequ noname.601 + incl r9 +noname.601: + + movl 4(ap),r0 + movl r8,16(r0) + + clrl r8 + + movl 8(ap),r0 + bicl3 #-65536,12(r0),r3 + movzwl 14(r0),r1 + bicl2 #-65536,r1 + bicl3 #-65536,8(r0),r2 + movzwl 10(r0),r0 + bicl2 #-65536,r0 + movl r3,r5 + movl r1,r4 + mull3 r0,r5,-36(fp) + mull2 r2,r5 + mull3 r2,r4,-40(fp) + mull2 r0,r4 + addl3 -36(fp),-40(fp),r0 + bicl3 #0,r0,-36(fp) + cmpl -36(fp),-40(fp) + bgequ noname.602 + addl2 #65536,r4 +noname.602: + movzwl -34(fp),r0 + bicl2 #-65536,r0 + addl2 r0,r4 + bicl3 #-65536,-36(fp),r0 + ashl #16,r0,-40(fp) + addl2 -40(fp),r5 + bicl2 #0,r5 + cmpl r5,-40(fp) + bgequ noname.603 + incl r4 +noname.603: + movl r5,r3 + movl r4,r2 + bbc #31,r2,noname.604 + incl r8 +noname.604: + addl2 r2,r2 + bicl2 #0,r2 + bbc #31,r3,noname.605 + incl r2 +noname.605: + addl2 r3,r3 + bicl2 #0,r3 + addl2 r3,r10 + bicl2 #0,r10 + cmpl r10,r3 + bgequ noname.606 + incl r2 + bicl3 #0,r2,r0 + bneq noname.606 + incl r8 +noname.606: + addl2 r2,r9 + bicl2 #0,r9 + cmpl r9,r2 + bgequ noname.607 + incl r8 +noname.607: + + movl 4(ap),r4 + movl r10,20(r4) + + clrl r10 + + movl 8(ap),r0 + movl 12(r0),r3 + bicl3 #-65536,r3,r5 + extzv #16,#16,r3,r0 + bicl3 #-65536,r0,r3 + mull3 r5,r3,-44(fp) + mull2 r5,r5 + mull2 r3,r3 + bicl3 #32767,-44(fp),r0 + extzv #15,#17,r0,r0 + addl2 r0,r3 + bicl3 #-65536,-44(fp),r0 + ashl #17,r0,-44(fp) + addl2 -44(fp),r5 + bicl2 #0,r5 + cmpl r5,-44(fp) + bgequ noname.608 + incl r3 +noname.608: + movl r5,r1 + movl r3,r2 + addl2 r1,r9 + bicl2 #0,r9 + cmpl r9,r1 + bgequ noname.609 + incl r2 +noname.609: + addl2 r2,r8 + bicl2 #0,r8 + cmpl r8,r2 + bgequ noname.610 + incl r10 +noname.610: + + movl r9,24(r4) + + movl r8,28(r4) + + ret + +; For now, the code below doesn't work, so I end this prematurely. +.end + + .title vax_bn_div64 division 64/32=>32 +; +; r.l. 16-jan-1998 +; +; unsigned int bn_div64(unsigned long h, unsigned long l, unsigned long d) +; return /d; +; + + .psect code,nowrt + +h=4 ;(AP) by value (input) +l=8 ;(AP) by value (input) +d=12 ;(AP) by value (input) + +.entry bn_div64,^m + + movl l(ap),r2 ; l + movl h(ap),r3 ; h + movl d(ap),r4 ; d + clrl r5 ; q + clrl r6 ; r + + ; Treat "negative" specially + tstl r3 + blss 30$ + + tstl r4 + beql 90$ + + ediv r4,r2,r5,r6 + bvs 666$ + + movl r5,r0 + ret + +30$: + ; The theory here is to do some harmless shifting and a little + ; bit of rounding (brackets are to designate when decimals are + ; cut off): + ; + ; result = 2 * [ ([/2] + [d/2]) / d ] + [ l / d ] + + movl #0,r7 + movl r3,r8 ; copy h + ashq #-1,r7,r7 ; [/2] => + bicl2 #^X80000000,r8 ; Remove "sign" + + movl r4,r9 ; copy d + ashl #-1,r9,r9 ; [d/2] => r9 + bicl2 #^X80000000,r9 ; Remove "sign" + + addl2 r9,r7 + adwc #0,r8 ; [/2] + [d/2] => + + ediv r4,r7,r5,r6 ; [ ([/2] + [d/2]) / d ] => + bvs 666$ + + movl #0,r6 + ashq #1,r5,r5 ; 2 * [ ([/2] + [d/2]) / d ] => r5 + + movl #0,r3 + ediv r4,r2,r8,r9 ; [ l / d ] => + + addl2 r8,r5 ; + bcs 666$ + + movl r5,r0 + ret + +90$: + movl #-1,r0 + ret + +666$: + + +.end diff --git a/src/lib/libcrypto/bn/asm/x86.pl b/src/lib/libcrypto/bn/asm/x86.pl new file mode 100644 index 0000000000..1bc4f1bb27 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/x86.pl @@ -0,0 +1,28 @@ +#!/usr/local/bin/perl + +push(@INC,"perlasm","../../perlasm"); +require "x86asm.pl"; + +require("x86/mul_add.pl"); +require("x86/mul.pl"); +require("x86/sqr.pl"); +require("x86/div.pl"); +require("x86/add.pl"); +require("x86/sub.pl"); +require("x86/comba.pl"); + +&asm_init($ARGV[0],$0); + +&bn_mul_add_words("bn_mul_add_words"); +&bn_mul_words("bn_mul_words"); +&bn_sqr_words("bn_sqr_words"); +&bn_div_words("bn_div_words"); +&bn_add_words("bn_add_words"); +&bn_sub_words("bn_sub_words"); +&bn_mul_comba("bn_mul_comba8",8); +&bn_mul_comba("bn_mul_comba4",4); +&bn_sqr_comba("bn_sqr_comba8",8); +&bn_sqr_comba("bn_sqr_comba4",4); + +&asm_finish(); + diff --git a/src/lib/libcrypto/bn/asm/x86w16.asm b/src/lib/libcrypto/bn/asm/x86w16.asm index 74a933a8cd..80a9ed6eef 100644 --- a/src/lib/libcrypto/bn/asm/x86w16.asm +++ b/src/lib/libcrypto/bn/asm/x86w16.asm @@ -6,11 +6,11 @@ F_TEXT SEGMENT WORD PUBLIC 'CODE' F_TEXT ENDS _DATA SEGMENT WORD PUBLIC 'DATA' _DATA ENDS -CONST SEGMENT WORD PUBLIC 'CONST' -CONST ENDS +_CONST SEGMENT WORD PUBLIC 'CONST' +_CONST ENDS _BSS SEGMENT WORD PUBLIC 'BSS' _BSS ENDS -DGROUP GROUP CONST, _BSS, _DATA +DGROUP GROUP _CONST, _BSS, _DATA ASSUME DS: DGROUP, SS: DGROUP F_TEXT SEGMENT ASSUME CS: F_TEXT diff --git a/src/lib/libcrypto/bn/asm/x86w32.asm b/src/lib/libcrypto/bn/asm/x86w32.asm index fc6f917714..957d71e3b1 100644 --- a/src/lib/libcrypto/bn/asm/x86w32.asm +++ b/src/lib/libcrypto/bn/asm/x86w32.asm @@ -6,11 +6,11 @@ F_TEXT SEGMENT WORD USE16 PUBLIC 'CODE' F_TEXT ENDS _DATA SEGMENT WORD USE16 PUBLIC 'DATA' _DATA ENDS -CONST SEGMENT WORD USE16 PUBLIC 'CONST' -CONST ENDS +_CONST SEGMENT WORD USE16 PUBLIC 'CONST' +_CONST ENDS _BSS SEGMENT WORD USE16 PUBLIC 'BSS' _BSS ENDS -DGROUP GROUP CONST, _BSS, _DATA +DGROUP GROUP _CONST, _BSS, _DATA ASSUME DS: DGROUP, SS: DGROUP F_TEXT SEGMENT ASSUME CS: F_TEXT @@ -89,7 +89,7 @@ $L555: mov bp,WORD PTR [bp+26] ; load num and bp,3 dec bp - js $L547 + js $L547m mov eax,ecx mul DWORD PTR es:[bx] ; w* *a @@ -100,7 +100,7 @@ $L555: mov DWORD PTR ds:[di],eax mov esi,edx dec bp - js $L547 ; Note that we are now testing for -1 + js $L547m ; Note that we are now testing for -1 ; mov eax,ecx mul DWORD PTR es:[bx+4] ; w* *a @@ -111,7 +111,7 @@ $L555: mov DWORD PTR ds:[di+4],eax mov esi,edx dec bp - js $L547 + js $L547m ; mov eax,ecx mul DWORD PTR es:[bx+8] ; w* *a @@ -121,7 +121,7 @@ $L555: adc edx,0 mov DWORD PTR ds:[di+8],eax mov esi,edx -$L547: +$L547m: mov eax,esi mov edx,esi shr edx,16 @@ -315,37 +315,35 @@ _bn_add_words PROC FAR ; ap = 22 ; rp = 18 xor esi,esi ;c=0; + mov bx,WORD PTR [bp+18] ; load low r mov si,WORD PTR [bp+22] ; load a mov es,WORD PTR [bp+24] ; load a mov di,WORD PTR [bp+26] ; load b mov ds,WORD PTR [bp+28] ; load b mov dx,WORD PTR [bp+30] ; load num - dec dx - js $L547 xor ecx,ecx + dec dx + js $L547a $L5477: - xor ebx,ebx mov eax,DWORD PTR es:[si] ; *a add eax,ecx - adc ebx,0 + mov ecx,0 + adc ecx,0 add si,4 ; a++ add eax,DWORD PTR ds:[di] ; + *b - mov ecx,ebx adc ecx,0 - add di,4 - mov bx,WORD PTR [bp+18] mov ds,WORD PTR [bp+20] + add di,4 mov DWORD PTR ds:[bx],eax - add bx,4 mov ds,WORD PTR [bp+28] - mov WORD PTR [bp+18],bx + add bx,4 dec dx - js $L547 ; Note that we are now testing for -1 + js $L547a ; Note that we are now testing for -1 jmp $L5477 ; -$L547: +$L547a: mov eax,ecx mov edx,ecx shr edx,16 diff --git a/src/lib/libcrypto/bn/bn.err b/src/lib/libcrypto/bn/bn.err deleted file mode 100644 index 7ccc247c41..0000000000 --- a/src/lib/libcrypto/bn/bn.err +++ /dev/null @@ -1,27 +0,0 @@ -/* Error codes for the BN functions. */ - -/* Function codes. */ -#define BN_F_BN_BLINDING_CONVERT 100 -#define BN_F_BN_BLINDING_INVERT 101 -#define BN_F_BN_BLINDING_NEW 102 -#define BN_F_BN_BLINDING_UPDATE 103 -#define BN_F_BN_BN2DEC 104 -#define BN_F_BN_BN2HEX 105 -#define BN_F_BN_CTX_NEW 106 -#define BN_F_BN_DIV 107 -#define BN_F_BN_EXPAND2 108 -#define BN_F_BN_MOD_EXP_MONT 109 -#define BN_F_BN_MOD_INVERSE 110 -#define BN_F_BN_MOD_MUL_RECIPROCAL 111 -#define BN_F_BN_MPI2BN 112 -#define BN_F_BN_NEW 113 -#define BN_F_BN_RAND 114 - -/* Reason codes. */ -#define BN_R_BAD_RECIPROCAL 100 -#define BN_R_CALLED_WITH_EVEN_MODULUS 101 -#define BN_R_DIV_BY_ZERO 102 -#define BN_R_ENCODING_ERROR 103 -#define BN_R_INVALID_LENGTH 104 -#define BN_R_NOT_INITALISED 105 -#define BN_R_NO_INVERSE 106 diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h new file mode 100644 index 0000000000..f935e1ca79 --- /dev/null +++ b/src/lib/libcrypto/bn/bn.h @@ -0,0 +1,467 @@ +/* crypto/bn/bn.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_BN_H +#define HEADER_BN_H + +#ifndef WIN16 +#include /* FILE */ +#endif +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef VMS +#undef BN_LLONG /* experimental, so far... */ +#endif + +#define BN_MUL_COMBA +#define BN_SQR_COMBA +#define BN_RECURSION +#define RECP_MUL_MOD +#define MONT_MUL_MOD + +/* This next option uses the C libraries (2 word)/(1 word) function. + * If it is not defined, I use my C version (which is slower). + * The reason for this flag is that when the particular C compiler + * library routine is used, and the library is linked with a different + * compiler, the library is missing. This mostly happens when the + * library is built with gcc and then linked using nornal cc. This would + * be a common occurance because gcc normally produces code that is + * 2 times faster than system compilers for the big number stuff. + * For machines with only one compiler (or shared libraries), this should + * be on. Again this in only really a problem on machines + * using "long long's", are 32bit, and are not using my assember code. */ +#if defined(MSDOS) || defined(WINDOWS) || defined(linux) +#define BN_DIV2W +#endif + +/* assuming long is 64bit - this is the DEC Alpha + * unsigned long long is only 64 bits :-(, don't define + * BN_LLONG for the DEC Alpha */ +#ifdef SIXTY_FOUR_BIT_LONG +#define BN_ULLONG unsigned long long +#define BN_ULONG unsigned long +#define BN_LONG long +#define BN_BITS 128 +#define BN_BYTES 8 +#define BN_BITS2 64 +#define BN_BITS4 32 +#define BN_MASK (0xffffffffffffffffffffffffffffffffLL) +#define BN_MASK2 (0xffffffffffffffffL) +#define BN_MASK2l (0xffffffffL) +#define BN_MASK2h (0xffffffff00000000L) +#define BN_MASK2h1 (0xffffffff80000000L) +#define BN_TBIT (0x8000000000000000L) +#define BN_DEC_CONV (10000000000000000000UL) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%019lu" +#define BN_DEC_NUM 19 +#endif + +/* This is where the long long data type is 64 bits, but long is 32. + * For machines where there are 64bit registers, this is the mode to use. + * IRIX, on R4000 and above should use this mode, along with the relevent + * assember code :-). Do NOT define BN_LLONG. + */ +#ifdef SIXTY_FOUR_BIT +#undef BN_LLONG +#undef BN_ULLONG +#define BN_ULONG unsigned long long +#define BN_LONG long long +#define BN_BITS 128 +#define BN_BYTES 8 +#define BN_BITS2 64 +#define BN_BITS4 32 +#define BN_MASK2 (0xffffffffffffffffLL) +#define BN_MASK2l (0xffffffffL) +#define BN_MASK2h (0xffffffff00000000LL) +#define BN_MASK2h1 (0xffffffff80000000LL) +#define BN_TBIT (0x8000000000000000LL) +#define BN_DEC_CONV (10000000000000000000LL) +#define BN_DEC_FMT1 "%llu" +#define BN_DEC_FMT2 "%019llu" +#define BN_DEC_NUM 19 +#endif + +#ifdef THIRTY_TWO_BIT +#if defined(WIN32) && !defined(__GNUC__) +#define BN_ULLONG unsigned _int64 +#else +#define BN_ULLONG unsigned long long +#endif +#define BN_ULONG unsigned long +#define BN_LONG long +#define BN_BITS 64 +#define BN_BYTES 4 +#define BN_BITS2 32 +#define BN_BITS4 16 +#ifdef WIN32 +/* VC++ doesn't like the LL suffix */ +#define BN_MASK (0xffffffffffffffffL) +#else +#define BN_MASK (0xffffffffffffffffLL) +#endif +#define BN_MASK2 (0xffffffffL) +#define BN_MASK2l (0xffff) +#define BN_MASK2h1 (0xffff8000L) +#define BN_MASK2h (0xffff0000L) +#define BN_TBIT (0x80000000L) +#define BN_DEC_CONV (1000000000L) +#define BN_DEC_FMT1 "%lu" +#define BN_DEC_FMT2 "%09lu" +#define BN_DEC_NUM 9 +#endif + +#ifdef SIXTEEN_BIT +#ifndef BN_DIV2W +#define BN_DIV2W +#endif +#define BN_ULLONG unsigned long +#define BN_ULONG unsigned short +#define BN_LONG short +#define BN_BITS 32 +#define BN_BYTES 2 +#define BN_BITS2 16 +#define BN_BITS4 8 +#define BN_MASK (0xffffffff) +#define BN_MASK2 (0xffff) +#define BN_MASK2l (0xff) +#define BN_MASK2h1 (0xff80) +#define BN_MASK2h (0xff00) +#define BN_TBIT (0x8000) +#define BN_DEC_CONV (100000) +#define BN_DEC_FMT1 "%u" +#define BN_DEC_FMT2 "%05u" +#define BN_DEC_NUM 5 +#endif + +#ifdef EIGHT_BIT +#ifndef BN_DIV2W +#define BN_DIV2W +#endif +#define BN_ULLONG unsigned short +#define BN_ULONG unsigned char +#define BN_LONG char +#define BN_BITS 16 +#define BN_BYTES 1 +#define BN_BITS2 8 +#define BN_BITS4 4 +#define BN_MASK (0xffff) +#define BN_MASK2 (0xff) +#define BN_MASK2l (0xf) +#define BN_MASK2h1 (0xf8) +#define BN_MASK2h (0xf0) +#define BN_TBIT (0x80) +#define BN_DEC_CONV (100) +#define BN_DEC_FMT1 "%u" +#define BN_DEC_FMT2 "%02u" +#define BN_DEC_NUM 2 +#endif + +#define BN_DEFAULT_BITS 1280 + +#ifdef BIGNUM +#undef BIGNUM +#endif + +#define BN_FLG_MALLOCED 0x01 +#define BN_FLG_STATIC_DATA 0x02 +#define BN_FLG_FREE 0x8000 /* used for debuging */ +#define BN_set_flags(b,n) ((b)->flags|=(n)) +#define BN_get_flags(b,n) ((b)->flags&(n)) + +typedef struct bignum_st + { + BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ + int top; /* Index of last used d +1. */ + /* The next are internal book keeping for bn_expand. */ + int max; /* Size of the d array. */ + int neg; /* one if the number is negative */ + int flags; + } BIGNUM; + +/* Used for temp variables */ +#define BN_CTX_NUM 12 +typedef struct bignum_ctx + { + int tos; + BIGNUM bn[BN_CTX_NUM+1]; + int flags; + } BN_CTX; + +typedef struct bn_blinding_st + { + int init; + BIGNUM *A; + BIGNUM *Ai; + BIGNUM *mod; /* just a reference */ + } BN_BLINDING; + +/* Used for montgomery multiplication */ +typedef struct bn_mont_ctx_st + { + int use_word; /* 0 for word form, 1 for long form */ + int ri; /* number of bits in R */ + BIGNUM RR; /* used to convert to montgomery form */ + BIGNUM N; /* The modulus */ + BIGNUM Ni; /* The inverse of N */ + BN_ULONG n0; /* word form of inverse, normally only one of + * Ni or n0 is defined */ + int flags; + } BN_MONT_CTX; + +/* Used for reciprocal division/mod functions + * It cannot be shared between threads + */ +typedef struct bn_recp_ctx_st + { + BIGNUM N; /* the divisor */ + BIGNUM Nr; /* the reciprocal */ + int num_bits; + int shift; + int flags; + } BN_RECP_CTX; + +#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ + r,a,&((mont)->RR),(mont),ctx) + +#define BN_prime_checks (5) + +#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) +#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) +#define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0)) +#define BN_is_one(a) (BN_is_word((a),1)) +#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) +#define BN_one(a) (BN_set_word((a),1)) +#define BN_zero(a) (BN_set_word((a),0)) + +/*#define BN_ascii2bn(a) BN_hex2bn(a) */ +/*#define BN_bn2ascii(a) BN_bn2hex(a) */ + +#define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\ + (n):bn_expand2((n),(b)/BN_BITS2+1)) +#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b))) + +#define bn_fix_top(a) \ + { \ + BN_ULONG *ftl; \ + if ((a)->top > 0) \ + { \ + for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ + if (*(ftl--)) break; \ + } \ + } + +BIGNUM *BN_value_one(void); +char * BN_options(void); +BN_CTX *BN_CTX_new(void); +void BN_CTX_init(BN_CTX *c); +void BN_CTX_free(BN_CTX *c); +int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); +int BN_num_bits(const BIGNUM *a); +int BN_num_bits_word(BN_ULONG); +BIGNUM *BN_new(void); +void BN_init(BIGNUM *); +void BN_clear_free(BIGNUM *a); +BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b); +BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret); +int BN_bn2bin(const BIGNUM *a, unsigned char *to); +BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret); +int BN_bn2mpi(const BIGNUM *a, unsigned char *to); +int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); +int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b); +int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx); +int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, + BN_CTX *ctx); +int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx); +int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx); +BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w); +int BN_mul_word(BIGNUM *a, BN_ULONG w); +int BN_add_word(BIGNUM *a, BN_ULONG w); +int BN_sub_word(BIGNUM *a, BN_ULONG w); +int BN_set_word(BIGNUM *a, BN_ULONG w); +BN_ULONG BN_get_word(BIGNUM *a); +int BN_cmp(const BIGNUM *a, const BIGNUM *b); +void BN_free(BIGNUM *a); +int BN_is_bit_set(const BIGNUM *a, int n); +int BN_lshift(BIGNUM *r, const BIGNUM *a, int n); +int BN_lshift1(BIGNUM *r, BIGNUM *a); +int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx); +int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, + const BIGNUM *m,BN_CTX *ctx); +int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); +int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2, + BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx); +int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, + BIGNUM *m,BN_CTX *ctx); +int BN_mask_bits(BIGNUM *a,int n); +int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx); +#ifndef WIN16 +int BN_print_fp(FILE *fp, BIGNUM *a); +#endif +#ifdef HEADER_BIO_H +int BN_print(BIO *fp, const BIGNUM *a); +#else +int BN_print(char *fp, const BIGNUM *a); +#endif +int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx); +int BN_rshift(BIGNUM *r, BIGNUM *a, int n); +int BN_rshift1(BIGNUM *r, BIGNUM *a); +void BN_clear(BIGNUM *a); +BIGNUM *bn_expand2(BIGNUM *b, int bits); +BIGNUM *BN_dup(const BIGNUM *a); +int BN_ucmp(const BIGNUM *a, const BIGNUM *b); +int BN_set_bit(BIGNUM *a, int n); +int BN_clear_bit(BIGNUM *a, int n); +char * BN_bn2hex(const BIGNUM *a); +char * BN_bn2dec(const BIGNUM *a); +int BN_hex2bn(BIGNUM **a, const char *str); +int BN_dec2bn(BIGNUM **a, const char *str); +int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx); +BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); +BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int strong,BIGNUM *add, + BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg); +int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,void *), + BN_CTX *ctx,void *cb_arg); +void ERR_load_BN_strings(void ); + +BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); +BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); +void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num); +BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d); +BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num); +BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num); + +BN_MONT_CTX *BN_MONT_CTX_new(void ); +void BN_MONT_CTX_init(BN_MONT_CTX *ctx); +int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont, + BN_CTX *ctx); +int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx); +void BN_MONT_CTX_free(BN_MONT_CTX *mont); +int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx); +BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from); + +BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod); +void BN_BLINDING_free(BN_BLINDING *b); +int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx); +int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx); +int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); + +void BN_set_params(int mul,int high,int low,int mont); +int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */ + +void BN_RECP_CTX_init(BN_RECP_CTX *recp); +BN_RECP_CTX *BN_RECP_CTX_new(void); +void BN_RECP_CTX_free(BN_RECP_CTX *recp); +int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx); +int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, + BN_RECP_CTX *recp,BN_CTX *ctx); +int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx); +int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, + BN_RECP_CTX *recp, BN_CTX *ctx); + + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +/* Error codes for the BN functions. */ + +/* Function codes. */ +#define BN_F_BN_BLINDING_CONVERT 100 +#define BN_F_BN_BLINDING_INVERT 101 +#define BN_F_BN_BLINDING_NEW 102 +#define BN_F_BN_BLINDING_UPDATE 103 +#define BN_F_BN_BN2DEC 104 +#define BN_F_BN_BN2HEX 105 +#define BN_F_BN_CTX_NEW 106 +#define BN_F_BN_DIV 107 +#define BN_F_BN_EXPAND2 108 +#define BN_F_BN_MOD_EXP_MONT 109 +#define BN_F_BN_MOD_INVERSE 110 +#define BN_F_BN_MOD_MUL_RECIPROCAL 111 +#define BN_F_BN_MPI2BN 112 +#define BN_F_BN_NEW 113 +#define BN_F_BN_RAND 114 +#define BN_F_BN_USUB 115 + +/* Reason codes. */ +#define BN_R_ARG2_LT_ARG3 100 +#define BN_R_BAD_RECIPROCAL 101 +#define BN_R_CALLED_WITH_EVEN_MODULUS 102 +#define BN_R_DIV_BY_ZERO 103 +#define BN_R_ENCODING_ERROR 104 +#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105 +#define BN_R_INVALID_LENGTH 106 +#define BN_R_NOT_INITIALIZED 107 +#define BN_R_NO_INVERSE 108 + +#ifdef __cplusplus +} +#endif +#endif + diff --git a/src/lib/libcrypto/bn/bn.mul b/src/lib/libcrypto/bn/bn.mul new file mode 100644 index 0000000000..9728870d38 --- /dev/null +++ b/src/lib/libcrypto/bn/bn.mul @@ -0,0 +1,19 @@ +We need + +* bn_mul_comba8 +* bn_mul_comba4 +* bn_mul_normal +* bn_mul_recursive + +* bn_sqr_comba8 +* bn_sqr_comba4 +bn_sqr_normal -> BN_sqr +* bn_sqr_recursive + +* bn_mul_low_recursive +* bn_mul_low_normal +* bn_mul_high + +* bn_mul_part_recursive # symetric but not power of 2 + +bn_mul_asymetric_recursive # uneven, but do the chop up. diff --git a/src/lib/libcrypto/bn/bn.org b/src/lib/libcrypto/bn/bn.org deleted file mode 100644 index 66dde285d6..0000000000 --- a/src/lib/libcrypto/bn/bn.org +++ /dev/null @@ -1,502 +0,0 @@ -/* crypto/bn/bn.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify bn.org since bn.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - -#ifndef HEADER_BN_H -#define HEADER_BN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#undef BN_LLONG - -#ifdef WIN32 -#define BN_LLONG /* This comment stops Configure mutilating things */ -#endif - -#define RECP_MUL_MOD -#define MONT_MUL_MOD - -/* This next option uses the C libraries (2 word)/(1 word) function. - * If it is not defined, I use my C version (which is slower). - * The reason for this flag is that when the particular C compiler - * library routine is used, and the library is linked with a different - * compiler, the library is missing. This mostly happens when the - * library is built with gcc and then linked using nornal cc. This would - * be a common occurance because gcc normally produces code that is - * 2 times faster than system compilers for the big number stuff. - * For machines with only one compiler (or shared libraries), this should - * be on. Again this in only really a problem on machines - * using "long long's", are 32bit, and are not using my assember code. */ -#if defined(MSDOS) || defined(WINDOWS) || defined(linux) -#define BN_DIV2W -#endif - -/* Only one for the following should be defined */ -/* The prime number generation stuff may not work when - * EIGHT_BIT but I don't care since I've only used this mode - * for debuging the bignum libraries */ -#undef SIXTY_FOUR_BIT_LONG -#undef SIXTY_FOUR_BIT -#define THIRTY_TWO_BIT -#undef SIXTEEN_BIT -#undef EIGHT_BIT - -/* assuming long is 64bit - this is the DEC Alpha - * unsigned long long is only 64 bits :-(, don't define - * BN_LLONG for the DEC Alpha */ -#ifdef SIXTY_FOUR_BIT_LONG -#define BN_ULLONG unsigned long long -#define BN_ULONG unsigned long -#define BN_LONG long -#define BN_BITS 128 -#define BN_BYTES 8 -#define BN_BITS2 64 -#define BN_BITS4 32 -#define BN_MASK2 (0xffffffffffffffffL) -#define BN_MASK2l (0xffffffffL) -#define BN_MASK2h (0xffffffff00000000L) -#define BN_MASK2h1 (0xffffffff80000000L) -#define BN_TBIT (0x8000000000000000L) -#define BN_DEC_CONV (10000000000000000000L) -#define BN_DEC_FMT1 "%lu" -#define BN_DEC_FMT2 "%019lu" -#define BN_DEC_NUM 19 -#endif - -#ifdef SIXTY_FOUR_BIT -#undef BN_LLONG -/* #define BN_ULLONG unsigned long long */ -#define BN_ULONG unsigned long long -#define BN_LONG long long -#define BN_BITS 128 -#define BN_BYTES 8 -#define BN_BITS2 64 -#define BN_BITS4 32 -#define BN_MASK2 (0xffffffffffffffffLL) -#define BN_MASK2l (0xffffffffL) -#define BN_MASK2h (0xffffffff00000000LL) -#define BN_MASK2h1 (0xffffffff80000000LL) -#define BN_TBIT (0x8000000000000000LL) -#define BN_DEC_CONV (10000000000000000000L) -#define BN_DEC_FMT1 "%lu" -#define BN_DEC_FMT2 "%019lu" -#define BN_DEC_NUM 19 -#endif - -#ifdef THIRTY_TWO_BIT -#ifdef WIN32 -#define BN_ULLONG unsigned _int64 -#else -#define BN_ULLONG unsigned long long -#endif -#define BN_ULONG unsigned long -#define BN_LONG long -#define BN_BITS 64 -#define BN_BYTES 4 -#define BN_BITS2 32 -#define BN_BITS4 16 -#define BN_MASK2 (0xffffffffL) -#define BN_MASK2l (0xffff) -#define BN_MASK2h1 (0xffff8000L) -#define BN_MASK2h (0xffff0000L) -#define BN_TBIT (0x80000000L) -#define BN_DEC_CONV (1000000000L) -#define BN_DEC_FMT1 "%lu" -#define BN_DEC_FMT2 "%09lu" -#define BN_DEC_NUM 9 -#endif - -#ifdef SIXTEEN_BIT -#ifndef BN_DIV2W -#define BN_DIV2W -#endif -#define BN_ULLONG unsigned long -#define BN_ULONG unsigned short -#define BN_LONG short -#define BN_BITS 32 -#define BN_BYTES 2 -#define BN_BITS2 16 -#define BN_BITS4 8 -#define BN_MASK2 (0xffff) -#define BN_MASK2l (0xff) -#define BN_MASK2h1 (0xff80) -#define BN_MASK2h (0xff00) -#define BN_TBIT (0x8000) -#define BN_DEC_CONV (100000) -#define BN_DEC_FMT1 "%u" -#define BN_DEC_FMT2 "%05u" -#define BN_DEC_NUM 5 -#endif - -#ifdef EIGHT_BIT -#ifndef BN_DIV2W -#define BN_DIV2W -#endif -#define BN_ULLONG unsigned short -#define BN_ULONG unsigned char -#define BN_LONG char -#define BN_BITS 16 -#define BN_BYTES 1 -#define BN_BITS2 8 -#define BN_BITS4 4 -#define BN_MASK2 (0xff) -#define BN_MASK2l (0xf) -#define BN_MASK2h1 (0xf8) -#define BN_MASK2h (0xf0) -#define BN_TBIT (0x80) -#define BN_DEC_CONV (100) -#define BN_DEC_FMT1 "%u" -#define BN_DEC_FMT2 "%02u" -#define BN_DEC_NUM 2 -#endif - -#define BN_DEFAULT_BITS 1280 - -#ifdef BIGNUM -#undef BIGNUM -#endif - -typedef struct bignum_st - { - BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ - int top; /* Index of last used d +1. */ - /* The next are internal book keeping for bn_expand. */ - int max; /* Size of the d array. */ - int neg; /* one if the number is negative */ - } BIGNUM; - -/* Used for temp variables */ -#define BN_CTX_NUM 12 -typedef struct bignum_ctx - { - int tos; - BIGNUM *bn[BN_CTX_NUM+1]; - } BN_CTX; - -typedef struct bn_blinding_st - { - int init; - BIGNUM *A; - BIGNUM *Ai; - BIGNUM *mod; /* just a reference */ - } BN_BLINDING; - -/* Used for montgomery multiplication */ -typedef struct bn_mont_ctx_st - { - int ri; /* number of bits in R */ - BIGNUM *RR; /* used to convert to montgomery form */ - BIGNUM *N; /* The modulus */ - BIGNUM *Ni; /* The inverse of N */ - BN_ULONG n0; /* word form of inverse, normally only one of - * Ni or n0 is defined */ - } BN_MONT_CTX; - -#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ - r,a,(mont)->RR,(mont),ctx) - -#define BN_prime_checks (5) - -#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) -#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) -#define BN_is_zero(a) (((a)->top <= 1) && ((a)->d[0] == (BN_ULONG)0)) -#define BN_is_one(a) (BN_is_word((a),1)) -#define BN_is_odd(a) ((a)->d[0] & 1) -#define BN_one(a) (BN_set_word((a),1)) -#define BN_zero(a) (BN_set_word((a),0)) - -#define BN_ascii2bn(a) BN_hex2bn(a) -#define BN_bn2ascii(a) BN_bn2hex(a) - -#define bn_fix_top(a) \ - { \ - BN_ULONG *fix_top_l; \ - for (fix_top_l= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ - if (*(fix_top_l--)) break; \ - } - -#define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?\ - (n):bn_expand2((n),(b)/BN_BITS2)) -#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b))) - - -#ifndef NOPROTO -BIGNUM *BN_value_one(void); -char * BN_options(void); -BN_CTX *BN_CTX_new(void); -void BN_CTX_free(BN_CTX *c); -int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); -int BN_num_bits(BIGNUM *a); -int BN_num_bits_word(BN_ULONG); -BIGNUM *BN_new(void); -void BN_clear_free(BIGNUM *a); -BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b); -BIGNUM *BN_bin2bn(unsigned char *s,int len,BIGNUM *ret); -int BN_bn2bin(BIGNUM *a, unsigned char *to); -BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret); -int BN_bn2mpi(BIGNUM *a, unsigned char *to); -int BN_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b); -void bn_qsub(BIGNUM *r, BIGNUM *a, BIGNUM *b); -void bn_qadd(BIGNUM *r, BIGNUM *a, BIGNUM *b); -int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b); -int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx); -int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx); -int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b); -int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx); -BN_ULONG BN_mod_word(BIGNUM *a, unsigned long w); -BN_ULONG BN_div_word(BIGNUM *a, unsigned long w); -int BN_mul_word(BIGNUM *a, unsigned long w); -int BN_add_word(BIGNUM *a, unsigned long w); -int BN_sub_word(BIGNUM *a, unsigned long w); -int BN_set_word(BIGNUM *a, unsigned long w); -unsigned long BN_get_word(BIGNUM *a); -int BN_cmp(BIGNUM *a, BIGNUM *b); -void BN_free(BIGNUM *a); -int BN_is_bit_set(BIGNUM *a, int n); -int BN_lshift(BIGNUM *r, BIGNUM *a, int n); -int BN_lshift1(BIGNUM *r, BIGNUM *a); -int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx); -int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx); -int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx, - BN_MONT_CTX *m_ctx); -int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx); -int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, - BIGNUM *m,BN_CTX *ctx); -int BN_mask_bits(BIGNUM *a,int n); -int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BIGNUM *m, - BIGNUM *i, int nb, BN_CTX *ctx); -int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m, - BN_CTX *ctx); -#ifndef WIN16 -int BN_print_fp(FILE *fp, BIGNUM *a); -#endif -#ifdef HEADER_BIO_H -int BN_print(BIO *fp, BIGNUM *a); -#else -int BN_print(char *fp, BIGNUM *a); -#endif -int BN_reciprocal(BIGNUM *r, BIGNUM *m, BN_CTX *ctx); -int BN_rshift(BIGNUM *r, BIGNUM *a, int n); -int BN_rshift1(BIGNUM *r, BIGNUM *a); -void BN_clear(BIGNUM *a); -BIGNUM *bn_expand2(BIGNUM *b, int bits); -BIGNUM *BN_dup(BIGNUM *a); -int BN_ucmp(BIGNUM *a, BIGNUM *b); -int BN_set_bit(BIGNUM *a, int n); -int BN_clear_bit(BIGNUM *a, int n); -char * BN_bn2hex(BIGNUM *a); -char * BN_bn2dec(BIGNUM *a); -int BN_hex2bn(BIGNUM **a,char *str); -int BN_dec2bn(BIGNUM **a,char *str); -int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx); -BIGNUM *BN_mod_inverse(BIGNUM *a, BIGNUM *n,BN_CTX *ctx); -BIGNUM *BN_generate_prime(int bits,int strong,BIGNUM *add, - BIGNUM *rem,void (*callback)(int,int,char *),char *cb_arg); -int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,char *), - BN_CTX *ctx,char *cb_arg); -void ERR_load_BN_strings(void ); - -BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); -BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); -void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num); -BN_ULONG bn_div64(BN_ULONG h, BN_ULONG l, BN_ULONG d); -BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num); - -BN_MONT_CTX *BN_MONT_CTX_new(void ); -int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont, - BN_CTX *ctx); -int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx); -void BN_MONT_CTX_free(BN_MONT_CTX *mont); -int BN_MONT_CTX_set(BN_MONT_CTX *mont,BIGNUM *modulus,BN_CTX *ctx); - -BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod); -void BN_BLINDING_free(BN_BLINDING *b); -int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx); -int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx); -int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); - -#else - -BIGNUM *BN_value_one(); -char * BN_options(); -BN_CTX *BN_CTX_new(); -void BN_CTX_free(); -int BN_rand(); -int BN_num_bits(); -int BN_num_bits_word(); -BIGNUM *BN_new(); -void BN_clear_free(); -BIGNUM *BN_copy(); -BIGNUM *BN_bin2bn(); -int BN_bn2bin(); -BIGNUM *BN_mpi2bn(); -int BN_bn2mpi(); -int BN_sub(); -void bn_qsub(); -void bn_qadd(); -int BN_add(); -int BN_mod(); -int BN_div(); -int BN_mul(); -int BN_sqr(); -BN_ULONG BN_mod_word(); -BN_ULONG BN_div_word(); -int BN_add_word(); -int BN_sub_word(); -int BN_mul_word(); -int BN_set_word(); -unsigned long BN_get_word(); -int BN_cmp(); -void BN_free(); -int BN_is_bit_set(); -int BN_lshift(); -int BN_lshift1(); -int BN_exp(); -int BN_mod_exp(); -int BN_mod_exp_mont(); -int BN_mod_exp_recp(); -int BN_mod_exp_simple(); -int BN_mask_bits(); -int BN_mod_mul_reciprocal(); -int BN_mod_mul(); -#ifndef WIN16 -int BN_print_fp(); -#endif -int BN_print(); -int BN_reciprocal(); -int BN_rshift(); -int BN_rshift1(); -void BN_clear(); -BIGNUM *bn_expand2(); -BIGNUM *BN_dup(); -int BN_ucmp(); -int BN_set_bit(); -int BN_clear_bit(); -char * BN_bn2hex(); -char * BN_bn2dec(); -int BN_hex2bn(); -int BN_dec2bn(); -int BN_gcd(); -BIGNUM *BN_mod_inverse(); -BIGNUM *BN_generate_prime(); -int BN_is_prime(); -void ERR_load_BN_strings(); - -BN_ULONG bn_mul_add_words(); -BN_ULONG bn_mul_words(); -void bn_sqr_words(); -BN_ULONG bn_div64(); -BN_ULONG bn_add_words(); - -int BN_mod_mul_montgomery(); -int BN_from_montgomery(); -BN_MONT_CTX *BN_MONT_CTX_new(); -void BN_MONT_CTX_free(); -int BN_MONT_CTX_set(); - -BN_BLINDING *BN_BLINDING_new(); -void BN_BLINDING_free(); -int BN_BLINDING_update(); -int BN_BLINDING_convert(); -int BN_BLINDING_invert(); - -#endif - -/* BEGIN ERROR CODES */ -/* Error codes for the BN functions. */ - -/* Function codes. */ -#define BN_F_BN_BLINDING_CONVERT 100 -#define BN_F_BN_BLINDING_INVERT 101 -#define BN_F_BN_BLINDING_NEW 102 -#define BN_F_BN_BLINDING_UPDATE 103 -#define BN_F_BN_BN2DEC 104 -#define BN_F_BN_BN2HEX 105 -#define BN_F_BN_CTX_NEW 106 -#define BN_F_BN_DIV 107 -#define BN_F_BN_EXPAND2 108 -#define BN_F_BN_MOD_EXP_MONT 109 -#define BN_F_BN_MOD_INVERSE 110 -#define BN_F_BN_MOD_MUL_RECIPROCAL 111 -#define BN_F_BN_MPI2BN 112 -#define BN_F_BN_NEW 113 -#define BN_F_BN_RAND 114 - -/* Reason codes. */ -#define BN_R_BAD_RECIPROCAL 100 -#define BN_R_CALLED_WITH_EVEN_MODULUS 101 -#define BN_R_DIV_BY_ZERO 102 -#define BN_R_ENCODING_ERROR 103 -#define BN_R_INVALID_LENGTH 104 -#define BN_R_NOT_INITALISED 105 -#define BN_R_NO_INVERSE 106 - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/src/lib/libcrypto/bn/bn_add.c b/src/lib/libcrypto/bn/bn_add.c index efb2e312e8..c5ab066c9e 100644 --- a/src/lib/libcrypto/bn/bn_add.c +++ b/src/lib/libcrypto/bn/bn_add.c @@ -61,14 +61,13 @@ #include "bn_lcl.h" /* r can == a or b */ -int BN_add(r, a, b) -BIGNUM *r; -BIGNUM *a; -BIGNUM *b; +int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b) { - int i; BIGNUM *tmp; + bn_check_top(a); + bn_check_top(b); + /* a + b a+b * a + -b a-b * -a + b b-a @@ -84,14 +83,12 @@ BIGNUM *b; if (BN_ucmp(a,b) < 0) { - if (bn_wexpand(r,b->top) == NULL) return(0); - bn_qsub(r,b,a); + if (!BN_usub(r,b,a)) return(0); r->neg=1; } else { - if (bn_wexpand(r,a->top) == NULL) return(0); - bn_qsub(r,a,b); + if (!BN_usub(r,a,b)) return(0); r->neg=0; } return(1); @@ -102,35 +99,32 @@ BIGNUM *b; else r->neg=0; - i=(a->top > b->top); - - if (i) - { - if (bn_wexpand(r,a->top+1) == NULL) return(0); - bn_qadd(r,a,b); - } - else - { - if (bn_wexpand(r,b->top+1) == NULL) return(0); - bn_qadd(r,b,a); - } + if (!BN_uadd(r,a,b)) return(0); return(1); } /* unsigned add of b to a, r must be large enough */ -void bn_qadd(r,a,b) -BIGNUM *r; -BIGNUM *a; -BIGNUM *b; +int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) { register int i; int max,min; BN_ULONG *ap,*bp,*rp,carry,t1; + const BIGNUM *tmp; + + bn_check_top(a); + bn_check_top(b); + if (a->top < b->top) + { tmp=a; a=b; b=tmp; } max=a->top; min=b->top; + + if (bn_wexpand(r,max+1) == NULL) + return(0); + r->top=max; + ap=a->d; bp=b->d; rp=r->d; @@ -160,8 +154,154 @@ BIGNUM *b; r->top++; } } - for (; itop < b->top) /* hmm... should not be happening */ + { + BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); + return(0); + } + + max=a->top; + min=b->top; + if (bn_wexpand(r,max) == NULL) return(0); + + ap=a->d; + bp=b->d; + rp=r->d; + +#if 1 + carry=0; + for (i=0; i t2) break; + } + } +#if 0 + memcpy(rp,ap,sizeof(*rp)*(max-i)); +#else + if (rp != ap) + { + for (;;) + { + if (i++ >= max) break; + rp[0]=ap[0]; + if (i++ >= max) break; + rp[1]=ap[1]; + if (i++ >= max) break; + rp[2]=ap[2]; + if (i++ >= max) break; + rp[3]=ap[3]; + rp+=4; + ap+=4; + } + } +#endif + + r->top=max; + bn_fix_top(r); + return(1); + } + +int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) + { + int max; + int add=0,neg=0; + const BIGNUM *tmp; + + bn_check_top(a); + bn_check_top(b); + + /* a - b a-b + * a - -b a+b + * -a - b -(a+b) + * -a - -b b-a + */ + if (a->neg) + { + if (b->neg) + { tmp=a; a=b; b=tmp; } + else + { add=1; neg=1; } + } + else + { + if (b->neg) { add=1; neg=0; } + } + + if (add) + { + if (!BN_uadd(r,a,b)) return(0); + r->neg=neg; + return(1); + } + + /* We are actually doing a - b :-) */ + + max=(a->top > b->top)?a->top:b->top; + if (bn_wexpand(r,max) == NULL) return(0); + if (BN_ucmp(a,b) < 0) + { + if (!BN_usub(r,b,a)) return(0); + r->neg=1; + } + else + { + if (!BN_usub(r,a,b)) return(0); + r->neg=0; + } + return(1); } diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c new file mode 100644 index 0000000000..4d3da16a0c --- /dev/null +++ b/src/lib/libcrypto/bn/bn_asm.c @@ -0,0 +1,802 @@ +/* crypto/bn/bn_asm.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include "cryptlib.h" +#include "bn_lcl.h" + +#ifdef BN_LLONG + +BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) + { + BN_ULONG c1=0; + + bn_check_num(num); + if (num <= 0) return(c1); + + for (;;) + { + mul_add(rp[0],ap[0],w,c1); + if (--num == 0) break; + mul_add(rp[1],ap[1],w,c1); + if (--num == 0) break; + mul_add(rp[2],ap[2],w,c1); + if (--num == 0) break; + mul_add(rp[3],ap[3],w,c1); + if (--num == 0) break; + ap+=4; + rp+=4; + } + + return(c1); + } + +BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) + { + BN_ULONG c1=0; + + bn_check_num(num); + if (num <= 0) return(c1); + + /* for (;;) */ + while (1) /* circumvent egcs-1.1.2 bug */ + { + mul(rp[0],ap[0],w,c1); + if (--num == 0) break; + mul(rp[1],ap[1],w,c1); + if (--num == 0) break; + mul(rp[2],ap[2],w,c1); + if (--num == 0) break; + mul(rp[3],ap[3],w,c1); + if (--num == 0) break; + ap+=4; + rp+=4; + } + return(c1); + } + +void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) + { + bn_check_num(n); + if (n <= 0) return; + for (;;) + { + BN_ULLONG t; + + t=(BN_ULLONG)(a[0])*(a[0]); + r[0]=Lw(t); r[1]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[1])*(a[1]); + r[2]=Lw(t); r[3]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[2])*(a[2]); + r[4]=Lw(t); r[5]=Hw(t); + if (--n == 0) break; + + t=(BN_ULLONG)(a[3])*(a[3]); + r[6]=Lw(t); r[7]=Hw(t); + if (--n == 0) break; + + a+=4; + r+=8; + } + } + +#else + +BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) + { + BN_ULONG c=0; + BN_ULONG bl,bh; + + bn_check_num(num); + if (num <= 0) return((BN_ULONG)0); + + bl=LBITS(w); + bh=HBITS(w); + + for (;;) + { + mul_add(rp[0],ap[0],bl,bh,c); + if (--num == 0) break; + mul_add(rp[1],ap[1],bl,bh,c); + if (--num == 0) break; + mul_add(rp[2],ap[2],bl,bh,c); + if (--num == 0) break; + mul_add(rp[3],ap[3],bl,bh,c); + if (--num == 0) break; + ap+=4; + rp+=4; + } + return(c); + } + +BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) + { + BN_ULONG carry=0; + BN_ULONG bl,bh; + + bn_check_num(num); + if (num <= 0) return((BN_ULONG)0); + + bl=LBITS(w); + bh=HBITS(w); + + for (;;) + { + mul(rp[0],ap[0],bl,bh,carry); + if (--num == 0) break; + mul(rp[1],ap[1],bl,bh,carry); + if (--num == 0) break; + mul(rp[2],ap[2],bl,bh,carry); + if (--num == 0) break; + mul(rp[3],ap[3],bl,bh,carry); + if (--num == 0) break; + ap+=4; + rp+=4; + } + return(carry); + } + +void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) + { + bn_check_num(n); + if (n <= 0) return; + for (;;) + { + sqr64(r[0],r[1],a[0]); + if (--n == 0) break; + + sqr64(r[2],r[3],a[1]); + if (--n == 0) break; + + sqr64(r[4],r[5],a[2]); + if (--n == 0) break; + + sqr64(r[6],r[7],a[3]); + if (--n == 0) break; + + a+=4; + r+=8; + } + } + +#endif + +#if defined(BN_LLONG) && defined(BN_DIV2W) + +BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d) + { + return((BN_ULONG)(((((BN_ULLONG)h)< (BN_ULONG)1<= d) h-=d; + + if (i) + { + d<<=i; + h=(h<>(BN_BITS2-i)); + l<<=i; + } + dh=(d&BN_MASK2h)>>BN_BITS4; + dl=(d&BN_MASK2l); + for (;;) + { + if ((h>>BN_BITS4) == dh) + q=BN_MASK2l; + else + q=h/dh; + + th=q*dh; + tl=dl*q; + for (;;) + { + t=h-th; + if ((t&BN_MASK2h) || + ((tl) <= ( + (t<>BN_BITS4)))) + break; + q--; + th-=dh; + tl-=dl; + } + t=(tl>>BN_BITS4); + tl=(tl<>BN_BITS4))&BN_MASK2; + l=(l&BN_MASK2l)<>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[1]+b[1]; + r[1]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[2]+b[2]; + r[2]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + ll+=(BN_ULLONG)a[3]+b[3]; + r[3]=(BN_ULONG)ll&BN_MASK2; + ll>>=BN_BITS2; + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } + return((BN_ULONG)ll); + } +#else +BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) + { + BN_ULONG c,l,t; + + bn_check_num(n); + if (n <= 0) return((BN_ULONG)0); + + c=0; + for (;;) + { + t=a[0]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[0])&BN_MASK2; + c+=(l < t); + r[0]=l; + if (--n <= 0) break; + + t=a[1]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[1])&BN_MASK2; + c+=(l < t); + r[1]=l; + if (--n <= 0) break; + + t=a[2]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[2])&BN_MASK2; + c+=(l < t); + r[2]=l; + if (--n <= 0) break; + + t=a[3]; + t=(t+c)&BN_MASK2; + c=(t < c); + l=(t+b[3])&BN_MASK2; + c+=(l < t); + r[3]=l; + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } + return((BN_ULONG)c); + } +#endif + +BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) + { + BN_ULONG t1,t2; + int c=0; + + bn_check_num(n); + if (n <= 0) return((BN_ULONG)0); + + for (;;) + { + t1=a[0]; t2=b[0]; + r[0]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[1]; t2=b[1]; + r[1]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[2]; t2=b[2]; + r[2]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + t1=a[3]; t2=b[3]; + r[3]=(t1-t2-c)&BN_MASK2; + if (t1 != t2) c=(t1 < t2); + if (--n <= 0) break; + + a+=4; + b+=4; + r+=4; + } + return(c); + } + +#ifdef BN_MUL_COMBA + +#undef bn_mul_comba8 +#undef bn_mul_comba4 +#undef bn_sqr_comba8 +#undef bn_sqr_comba4 + +#ifdef BN_LLONG +#define mul_add_c(a,b,c0,c1,c2) \ + t=(BN_ULLONG)a*b; \ + t1=(BN_ULONG)Lw(t); \ + t2=(BN_ULONG)Hw(t); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \ + t=(BN_ULLONG)a*b; \ + tt=(t+t)&BN_MASK; \ + if (tt < t) c2++; \ + t1=(BN_ULONG)Lw(tt); \ + t2=(BN_ULONG)Hw(tt); \ + c0=(c0+t1)&BN_MASK2; \ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \ + t=(BN_ULLONG)a[i]*a[i]; \ + t1=(BN_ULONG)Lw(t); \ + t2=(BN_ULONG)Hw(t); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#else +#define mul_add_c(a,b,c0,c1,c2) \ + t1=LBITS(a); t2=HBITS(a); \ + bl=LBITS(b); bh=HBITS(b); \ + mul64(t1,t2,bl,bh); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \ + t1=LBITS(a); t2=HBITS(a); \ + bl=LBITS(b); bh=HBITS(b); \ + mul64(t1,t2,bl,bh); \ + if (t2 & BN_TBIT) c2++; \ + t2=(t2+t2)&BN_MASK2; \ + if (t1 & BN_TBIT) t2++; \ + t1=(t1+t1)&BN_MASK2; \ + c0=(c0+t1)&BN_MASK2; \ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \ + sqr64(t1,t2,(a)[i]); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#endif + +void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + mul_add_c(a[0],b[0],c1,c2,c3); + r[0]=c1; + c1=0; + mul_add_c(a[0],b[1],c2,c3,c1); + mul_add_c(a[1],b[0],c2,c3,c1); + r[1]=c2; + c2=0; + mul_add_c(a[2],b[0],c3,c1,c2); + mul_add_c(a[1],b[1],c3,c1,c2); + mul_add_c(a[0],b[2],c3,c1,c2); + r[2]=c3; + c3=0; + mul_add_c(a[0],b[3],c1,c2,c3); + mul_add_c(a[1],b[2],c1,c2,c3); + mul_add_c(a[2],b[1],c1,c2,c3); + mul_add_c(a[3],b[0],c1,c2,c3); + r[3]=c1; + c1=0; + mul_add_c(a[4],b[0],c2,c3,c1); + mul_add_c(a[3],b[1],c2,c3,c1); + mul_add_c(a[2],b[2],c2,c3,c1); + mul_add_c(a[1],b[3],c2,c3,c1); + mul_add_c(a[0],b[4],c2,c3,c1); + r[4]=c2; + c2=0; + mul_add_c(a[0],b[5],c3,c1,c2); + mul_add_c(a[1],b[4],c3,c1,c2); + mul_add_c(a[2],b[3],c3,c1,c2); + mul_add_c(a[3],b[2],c3,c1,c2); + mul_add_c(a[4],b[1],c3,c1,c2); + mul_add_c(a[5],b[0],c3,c1,c2); + r[5]=c3; + c3=0; + mul_add_c(a[6],b[0],c1,c2,c3); + mul_add_c(a[5],b[1],c1,c2,c3); + mul_add_c(a[4],b[2],c1,c2,c3); + mul_add_c(a[3],b[3],c1,c2,c3); + mul_add_c(a[2],b[4],c1,c2,c3); + mul_add_c(a[1],b[5],c1,c2,c3); + mul_add_c(a[0],b[6],c1,c2,c3); + r[6]=c1; + c1=0; + mul_add_c(a[0],b[7],c2,c3,c1); + mul_add_c(a[1],b[6],c2,c3,c1); + mul_add_c(a[2],b[5],c2,c3,c1); + mul_add_c(a[3],b[4],c2,c3,c1); + mul_add_c(a[4],b[3],c2,c3,c1); + mul_add_c(a[5],b[2],c2,c3,c1); + mul_add_c(a[6],b[1],c2,c3,c1); + mul_add_c(a[7],b[0],c2,c3,c1); + r[7]=c2; + c2=0; + mul_add_c(a[7],b[1],c3,c1,c2); + mul_add_c(a[6],b[2],c3,c1,c2); + mul_add_c(a[5],b[3],c3,c1,c2); + mul_add_c(a[4],b[4],c3,c1,c2); + mul_add_c(a[3],b[5],c3,c1,c2); + mul_add_c(a[2],b[6],c3,c1,c2); + mul_add_c(a[1],b[7],c3,c1,c2); + r[8]=c3; + c3=0; + mul_add_c(a[2],b[7],c1,c2,c3); + mul_add_c(a[3],b[6],c1,c2,c3); + mul_add_c(a[4],b[5],c1,c2,c3); + mul_add_c(a[5],b[4],c1,c2,c3); + mul_add_c(a[6],b[3],c1,c2,c3); + mul_add_c(a[7],b[2],c1,c2,c3); + r[9]=c1; + c1=0; + mul_add_c(a[7],b[3],c2,c3,c1); + mul_add_c(a[6],b[4],c2,c3,c1); + mul_add_c(a[5],b[5],c2,c3,c1); + mul_add_c(a[4],b[6],c2,c3,c1); + mul_add_c(a[3],b[7],c2,c3,c1); + r[10]=c2; + c2=0; + mul_add_c(a[4],b[7],c3,c1,c2); + mul_add_c(a[5],b[6],c3,c1,c2); + mul_add_c(a[6],b[5],c3,c1,c2); + mul_add_c(a[7],b[4],c3,c1,c2); + r[11]=c3; + c3=0; + mul_add_c(a[7],b[5],c1,c2,c3); + mul_add_c(a[6],b[6],c1,c2,c3); + mul_add_c(a[5],b[7],c1,c2,c3); + r[12]=c1; + c1=0; + mul_add_c(a[6],b[7],c2,c3,c1); + mul_add_c(a[7],b[6],c2,c3,c1); + r[13]=c2; + c2=0; + mul_add_c(a[7],b[7],c3,c1,c2); + r[14]=c3; + r[15]=c1; + } + +void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + mul_add_c(a[0],b[0],c1,c2,c3); + r[0]=c1; + c1=0; + mul_add_c(a[0],b[1],c2,c3,c1); + mul_add_c(a[1],b[0],c2,c3,c1); + r[1]=c2; + c2=0; + mul_add_c(a[2],b[0],c3,c1,c2); + mul_add_c(a[1],b[1],c3,c1,c2); + mul_add_c(a[0],b[2],c3,c1,c2); + r[2]=c3; + c3=0; + mul_add_c(a[0],b[3],c1,c2,c3); + mul_add_c(a[1],b[2],c1,c2,c3); + mul_add_c(a[2],b[1],c1,c2,c3); + mul_add_c(a[3],b[0],c1,c2,c3); + r[3]=c1; + c1=0; + mul_add_c(a[3],b[1],c2,c3,c1); + mul_add_c(a[2],b[2],c2,c3,c1); + mul_add_c(a[1],b[3],c2,c3,c1); + r[4]=c2; + c2=0; + mul_add_c(a[2],b[3],c3,c1,c2); + mul_add_c(a[3],b[2],c3,c1,c2); + r[5]=c3; + c3=0; + mul_add_c(a[3],b[3],c1,c2,c3); + r[6]=c1; + r[7]=c2; + } + +void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a) + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + sqr_add_c(a,0,c1,c2,c3); + r[0]=c1; + c1=0; + sqr_add_c2(a,1,0,c2,c3,c1); + r[1]=c2; + c2=0; + sqr_add_c(a,1,c3,c1,c2); + sqr_add_c2(a,2,0,c3,c1,c2); + r[2]=c3; + c3=0; + sqr_add_c2(a,3,0,c1,c2,c3); + sqr_add_c2(a,2,1,c1,c2,c3); + r[3]=c1; + c1=0; + sqr_add_c(a,2,c2,c3,c1); + sqr_add_c2(a,3,1,c2,c3,c1); + sqr_add_c2(a,4,0,c2,c3,c1); + r[4]=c2; + c2=0; + sqr_add_c2(a,5,0,c3,c1,c2); + sqr_add_c2(a,4,1,c3,c1,c2); + sqr_add_c2(a,3,2,c3,c1,c2); + r[5]=c3; + c3=0; + sqr_add_c(a,3,c1,c2,c3); + sqr_add_c2(a,4,2,c1,c2,c3); + sqr_add_c2(a,5,1,c1,c2,c3); + sqr_add_c2(a,6,0,c1,c2,c3); + r[6]=c1; + c1=0; + sqr_add_c2(a,7,0,c2,c3,c1); + sqr_add_c2(a,6,1,c2,c3,c1); + sqr_add_c2(a,5,2,c2,c3,c1); + sqr_add_c2(a,4,3,c2,c3,c1); + r[7]=c2; + c2=0; + sqr_add_c(a,4,c3,c1,c2); + sqr_add_c2(a,5,3,c3,c1,c2); + sqr_add_c2(a,6,2,c3,c1,c2); + sqr_add_c2(a,7,1,c3,c1,c2); + r[8]=c3; + c3=0; + sqr_add_c2(a,7,2,c1,c2,c3); + sqr_add_c2(a,6,3,c1,c2,c3); + sqr_add_c2(a,5,4,c1,c2,c3); + r[9]=c1; + c1=0; + sqr_add_c(a,5,c2,c3,c1); + sqr_add_c2(a,6,4,c2,c3,c1); + sqr_add_c2(a,7,3,c2,c3,c1); + r[10]=c2; + c2=0; + sqr_add_c2(a,7,4,c3,c1,c2); + sqr_add_c2(a,6,5,c3,c1,c2); + r[11]=c3; + c3=0; + sqr_add_c(a,6,c1,c2,c3); + sqr_add_c2(a,7,5,c1,c2,c3); + r[12]=c1; + c1=0; + sqr_add_c2(a,7,6,c2,c3,c1); + r[13]=c2; + c2=0; + sqr_add_c(a,7,c3,c1,c2); + r[14]=c3; + r[15]=c1; + } + +void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a) + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + sqr_add_c(a,0,c1,c2,c3); + r[0]=c1; + c1=0; + sqr_add_c2(a,1,0,c2,c3,c1); + r[1]=c2; + c2=0; + sqr_add_c(a,1,c3,c1,c2); + sqr_add_c2(a,2,0,c3,c1,c2); + r[2]=c3; + c3=0; + sqr_add_c2(a,3,0,c1,c2,c3); + sqr_add_c2(a,2,1,c1,c2,c3); + r[3]=c1; + c1=0; + sqr_add_c(a,2,c2,c3,c1); + sqr_add_c2(a,3,1,c2,c3,c1); + r[4]=c2; + c2=0; + sqr_add_c2(a,3,2,c3,c1,c2); + r[5]=c3; + c3=0; + sqr_add_c(a,3,c1,c2,c3); + r[6]=c1; + r[7]=c2; + } +#else + +/* hmm... is it faster just to do a multiply? */ +#undef bn_sqr_comba4 +void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a) + { + BN_ULONG t[8]; + bn_sqr_normal(r,a,4,t); + } + +#undef bn_sqr_comba8 +void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a) + { + BN_ULONG t[16]; + bn_sqr_normal(r,a,8,t); + } + +void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) + { + r[4]=bn_mul_words( &(r[0]),a,4,b[0]); + r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]); + r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]); + r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]); + } + +void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) + { + r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]); + r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]); + r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]); + r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]); + r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]); + r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]); + r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]); + r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]); + } + +#endif /* BN_COMBA */ diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c index a7b34f0bf0..1b1bb06046 100644 --- a/src/lib/libcrypto/bn/bn_blind.c +++ b/src/lib/libcrypto/bn/bn_blind.c @@ -60,15 +60,18 @@ #include "cryptlib.h" #include "bn_lcl.h" -BN_BLINDING *BN_BLINDING_new(A,Ai,mod) -BIGNUM *A; -BIGNUM *Ai; -BIGNUM *mod; +BN_BLINDING *BN_BLINDING_new(BIGNUM *A, BIGNUM *Ai, BIGNUM *mod) { BN_BLINDING *ret=NULL; + bn_check_top(Ai); + bn_check_top(mod); + if ((ret=(BN_BLINDING *)Malloc(sizeof(BN_BLINDING))) == NULL) + { BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE); + return(NULL); + } memset(ret,0,sizeof(BN_BLINDING)); if ((ret->A=BN_new()) == NULL) goto err; if ((ret->Ai=BN_new()) == NULL) goto err; @@ -78,26 +81,26 @@ BIGNUM *mod; return(ret); err: if (ret != NULL) BN_BLINDING_free(ret); - return(ret); + return(NULL); } -void BN_BLINDING_free(r) -BN_BLINDING *r; +void BN_BLINDING_free(BN_BLINDING *r) { + if(r == NULL) + return; + if (r->A != NULL) BN_free(r->A ); if (r->Ai != NULL) BN_free(r->Ai); Free(r); } -int BN_BLINDING_update(b,ctx) -BN_BLINDING *b; -BN_CTX *ctx; +int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx) { int ret=0; if ((b->A == NULL) || (b->Ai == NULL)) { - BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITALISED); + BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED); goto err; } @@ -109,28 +112,26 @@ err: return(ret); } -int BN_BLINDING_convert(n,b,ctx) -BIGNUM *n; -BN_BLINDING *b; -BN_CTX *ctx; +int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx) { + bn_check_top(n); + if ((b->A == NULL) || (b->Ai == NULL)) { - BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITALISED); + BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITIALIZED); return(0); } return(BN_mod_mul(n,n,b->A,b->mod,ctx)); } -int BN_BLINDING_invert(n,b,ctx) -BIGNUM *n; -BN_BLINDING *b; -BN_CTX *ctx; +int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx) { int ret; + + bn_check_top(n); if ((b->A == NULL) || (b->Ai == NULL)) { - BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITALISED); + BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED); return(0); } if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0) diff --git a/src/lib/libcrypto/bn/bn_comba.c b/src/lib/libcrypto/bn/bn_comba.c new file mode 100644 index 0000000000..7ad09b4a6d --- /dev/null +++ b/src/lib/libcrypto/bn/bn_comba.c @@ -0,0 +1,345 @@ +/* crypto/bn/bn_comba.c */ +#include +#include "bn_lcl.h" +/* Auto generated from crypto/bn/comba.pl + */ + +#undef bn_mul_comba8 +#undef bn_mul_comba4 +#undef bn_sqr_comba8 +#undef bn_sqr_comba4 + +#ifdef BN_LLONG +#define mul_add_c(a,b,c0,c1,c2) \ + t=(BN_ULLONG)a*b; \ + t1=(BN_ULONG)Lw(t); \ + t2=(BN_ULONG)Hw(t); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \ + t=(BN_ULLONG)a*b; \ + tt=(t+t)&BN_MASK; \ + if (tt < t) c2++; \ + t1=(BN_ULONG)Lw(tt); \ + t2=(BN_ULONG)Hw(tt); \ + c0=(c0+t1)&BN_MASK2; \ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \ + t=(BN_ULLONG)a[i]*a[i]; \ + t1=(BN_ULONG)Lw(t); \ + t2=(BN_ULONG)Hw(t); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#else +#define mul_add_c(a,b,c0,c1,c2) \ + t1=LBITS(a); t2=HBITS(a); \ + bl=LBITS(b); bh=HBITS(b); \ + mul64(t1,t2,bl,bh); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \ + t1=LBITS(a); t2=HBITS(a); \ + bl=LBITS(b); bh=HBITS(b); \ + mul64(t1,t2,bl,bh); \ + if (t2 & BN_TBIT) c2++; \ + t2=(t2+t2)&BN_MASK2; \ + if (t1 & BN_TBIT) t2++; \ + t1=(t1+t1)&BN_MASK2; \ + c0=(c0+t1)&BN_MASK2; \ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \ + sqr64(t1,t2,(a)[i]); \ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#endif + +void bn_mul_comba88(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b); +void bn_mul_comba44(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b); +void bn_sqr_comba88(BN_ULONG *r,BN_ULONG *a); +void bn_sqr_comba44(BN_ULONG *r,BN_ULONG *a); + +void bn_mul_comba88(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + mul_add_c(a[0],b[0],c1,c2,c3); + r[0]=c1; + c1=0; + mul_add_c(a[0],b[1],c2,c3,c1); + mul_add_c(a[1],b[0],c2,c3,c1); + r[1]=c2; + c2=0; + mul_add_c(a[2],b[0],c3,c1,c2); + mul_add_c(a[1],b[1],c3,c1,c2); + mul_add_c(a[0],b[2],c3,c1,c2); + r[2]=c3; + c3=0; + mul_add_c(a[0],b[3],c1,c2,c3); + mul_add_c(a[1],b[2],c1,c2,c3); + mul_add_c(a[2],b[1],c1,c2,c3); + mul_add_c(a[3],b[0],c1,c2,c3); + r[3]=c1; + c1=0; + mul_add_c(a[4],b[0],c2,c3,c1); + mul_add_c(a[3],b[1],c2,c3,c1); + mul_add_c(a[2],b[2],c2,c3,c1); + mul_add_c(a[1],b[3],c2,c3,c1); + mul_add_c(a[0],b[4],c2,c3,c1); + r[4]=c2; + c2=0; + mul_add_c(a[0],b[5],c3,c1,c2); + mul_add_c(a[1],b[4],c3,c1,c2); + mul_add_c(a[2],b[3],c3,c1,c2); + mul_add_c(a[3],b[2],c3,c1,c2); + mul_add_c(a[4],b[1],c3,c1,c2); + mul_add_c(a[5],b[0],c3,c1,c2); + r[5]=c3; + c3=0; + mul_add_c(a[6],b[0],c1,c2,c3); + mul_add_c(a[5],b[1],c1,c2,c3); + mul_add_c(a[4],b[2],c1,c2,c3); + mul_add_c(a[3],b[3],c1,c2,c3); + mul_add_c(a[2],b[4],c1,c2,c3); + mul_add_c(a[1],b[5],c1,c2,c3); + mul_add_c(a[0],b[6],c1,c2,c3); + r[6]=c1; + c1=0; + mul_add_c(a[0],b[7],c2,c3,c1); + mul_add_c(a[1],b[6],c2,c3,c1); + mul_add_c(a[2],b[5],c2,c3,c1); + mul_add_c(a[3],b[4],c2,c3,c1); + mul_add_c(a[4],b[3],c2,c3,c1); + mul_add_c(a[5],b[2],c2,c3,c1); + mul_add_c(a[6],b[1],c2,c3,c1); + mul_add_c(a[7],b[0],c2,c3,c1); + r[7]=c2; + c2=0; + mul_add_c(a[7],b[1],c3,c1,c2); + mul_add_c(a[6],b[2],c3,c1,c2); + mul_add_c(a[5],b[3],c3,c1,c2); + mul_add_c(a[4],b[4],c3,c1,c2); + mul_add_c(a[3],b[5],c3,c1,c2); + mul_add_c(a[2],b[6],c3,c1,c2); + mul_add_c(a[1],b[7],c3,c1,c2); + r[8]=c3; + c3=0; + mul_add_c(a[2],b[7],c1,c2,c3); + mul_add_c(a[3],b[6],c1,c2,c3); + mul_add_c(a[4],b[5],c1,c2,c3); + mul_add_c(a[5],b[4],c1,c2,c3); + mul_add_c(a[6],b[3],c1,c2,c3); + mul_add_c(a[7],b[2],c1,c2,c3); + r[9]=c1; + c1=0; + mul_add_c(a[7],b[3],c2,c3,c1); + mul_add_c(a[6],b[4],c2,c3,c1); + mul_add_c(a[5],b[5],c2,c3,c1); + mul_add_c(a[4],b[6],c2,c3,c1); + mul_add_c(a[3],b[7],c2,c3,c1); + r[10]=c2; + c2=0; + mul_add_c(a[4],b[7],c3,c1,c2); + mul_add_c(a[5],b[6],c3,c1,c2); + mul_add_c(a[6],b[5],c3,c1,c2); + mul_add_c(a[7],b[4],c3,c1,c2); + r[11]=c3; + c3=0; + mul_add_c(a[7],b[5],c1,c2,c3); + mul_add_c(a[6],b[6],c1,c2,c3); + mul_add_c(a[5],b[7],c1,c2,c3); + r[12]=c1; + c1=0; + mul_add_c(a[6],b[7],c2,c3,c1); + mul_add_c(a[7],b[6],c2,c3,c1); + r[13]=c2; + c2=0; + mul_add_c(a[7],b[7],c3,c1,c2); + r[14]=c3; + r[15]=c1; + } + +void bn_mul_comba44(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + mul_add_c(a[0],b[0],c1,c2,c3); + r[0]=c1; + c1=0; + mul_add_c(a[0],b[1],c2,c3,c1); + mul_add_c(a[1],b[0],c2,c3,c1); + r[1]=c2; + c2=0; + mul_add_c(a[2],b[0],c3,c1,c2); + mul_add_c(a[1],b[1],c3,c1,c2); + mul_add_c(a[0],b[2],c3,c1,c2); + r[2]=c3; + c3=0; + mul_add_c(a[0],b[3],c1,c2,c3); + mul_add_c(a[1],b[2],c1,c2,c3); + mul_add_c(a[2],b[1],c1,c2,c3); + mul_add_c(a[3],b[0],c1,c2,c3); + r[3]=c1; + c1=0; + mul_add_c(a[3],b[1],c2,c3,c1); + mul_add_c(a[2],b[2],c2,c3,c1); + mul_add_c(a[1],b[3],c2,c3,c1); + r[4]=c2; + c2=0; + mul_add_c(a[2],b[3],c3,c1,c2); + mul_add_c(a[3],b[2],c3,c1,c2); + r[5]=c3; + c3=0; + mul_add_c(a[3],b[3],c1,c2,c3); + r[6]=c1; + r[7]=c2; + } + +void bn_sqr_comba88(BN_ULONG *r, BN_ULONG *a) + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + sqr_add_c(a,0,c1,c2,c3); + r[0]=c1; + c1=0; + sqr_add_c2(a,1,0,c2,c3,c1); + r[1]=c2; + c2=0; + sqr_add_c(a,1,c3,c1,c2); + sqr_add_c2(a,2,0,c3,c1,c2); + r[2]=c3; + c3=0; + sqr_add_c2(a,3,0,c1,c2,c3); + sqr_add_c2(a,2,1,c1,c2,c3); + r[3]=c1; + c1=0; + sqr_add_c(a,2,c2,c3,c1); + sqr_add_c2(a,3,1,c2,c3,c1); + sqr_add_c2(a,4,0,c2,c3,c1); + r[4]=c2; + c2=0; + sqr_add_c2(a,5,0,c3,c1,c2); + sqr_add_c2(a,4,1,c3,c1,c2); + sqr_add_c2(a,3,2,c3,c1,c2); + r[5]=c3; + c3=0; + sqr_add_c(a,3,c1,c2,c3); + sqr_add_c2(a,4,2,c1,c2,c3); + sqr_add_c2(a,5,1,c1,c2,c3); + sqr_add_c2(a,6,0,c1,c2,c3); + r[6]=c1; + c1=0; + sqr_add_c2(a,7,0,c2,c3,c1); + sqr_add_c2(a,6,1,c2,c3,c1); + sqr_add_c2(a,5,2,c2,c3,c1); + sqr_add_c2(a,4,3,c2,c3,c1); + r[7]=c2; + c2=0; + sqr_add_c(a,4,c3,c1,c2); + sqr_add_c2(a,5,3,c3,c1,c2); + sqr_add_c2(a,6,2,c3,c1,c2); + sqr_add_c2(a,7,1,c3,c1,c2); + r[8]=c3; + c3=0; + sqr_add_c2(a,7,2,c1,c2,c3); + sqr_add_c2(a,6,3,c1,c2,c3); + sqr_add_c2(a,5,4,c1,c2,c3); + r[9]=c1; + c1=0; + sqr_add_c(a,5,c2,c3,c1); + sqr_add_c2(a,6,4,c2,c3,c1); + sqr_add_c2(a,7,3,c2,c3,c1); + r[10]=c2; + c2=0; + sqr_add_c2(a,7,4,c3,c1,c2); + sqr_add_c2(a,6,5,c3,c1,c2); + r[11]=c3; + c3=0; + sqr_add_c(a,6,c1,c2,c3); + sqr_add_c2(a,7,5,c1,c2,c3); + r[12]=c1; + c1=0; + sqr_add_c2(a,7,6,c2,c3,c1); + r[13]=c2; + c2=0; + sqr_add_c(a,7,c3,c1,c2); + r[14]=c3; + r[15]=c1; + } + +void bn_sqr_comba44(BN_ULONG *r, BN_ULONG *a) + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + + c1=0; + c2=0; + c3=0; + sqr_add_c(a,0,c1,c2,c3); + r[0]=c1; + c1=0; + sqr_add_c2(a,1,0,c2,c3,c1); + r[1]=c2; + c2=0; + sqr_add_c(a,1,c3,c1,c2); + sqr_add_c2(a,2,0,c3,c1,c2); + r[2]=c3; + c3=0; + sqr_add_c2(a,3,0,c1,c2,c3); + sqr_add_c2(a,2,1,c1,c2,c3); + r[3]=c1; + c1=0; + sqr_add_c(a,2,c2,c3,c1); + sqr_add_c2(a,3,1,c2,c3,c1); + r[4]=c2; + c2=0; + sqr_add_c2(a,3,2,c3,c1,c2); + r[5]=c3; + c3=0; + sqr_add_c(a,3,c1,c2,c3); + r[6]=c1; + r[7]=c2; + } diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c index 2263bdc7da..150dd289a5 100644 --- a/src/lib/libcrypto/bn/bn_div.c +++ b/src/lib/libcrypto/bn/bn_div.c @@ -57,21 +57,19 @@ */ #include +#include #include "cryptlib.h" #include "bn_lcl.h" /* The old slow way */ #if 0 -int BN_div(dv, rem, m, d,ctx) -BIGNUM *dv; -BIGNUM *rem; -BIGNUM *m; -BIGNUM *d; -BN_CTX *ctx; +int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx) { int i,nm,nd; BIGNUM *D; + bn_check_top(m); + bn_check_top(d); if (BN_is_zero(d)) { BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); @@ -86,9 +84,9 @@ BN_CTX *ctx; return(1); } - D=ctx->bn[ctx->tos]; - if (dv == NULL) dv=ctx->bn[ctx->tos+1]; - if (rem == NULL) rem=ctx->bn[ctx->tos+2]; + D= &(ctx->bn[ctx->tos]); + if (dv == NULL) dv= &(ctx->bn[ctx->tos+1]); + if (rem == NULL) rem= &(ctx->bn[ctx->tos+2]); nd=BN_num_bits(d); nm=BN_num_bits(m); @@ -98,6 +96,7 @@ BN_CTX *ctx; /* The next 2 are needed so we can do a dv->d[0]|=1 later * since BN_lshift1 will only work once there is a value :-) */ BN_zero(dv); + bn_wexpand(dv,1); dv->top=1; if (!BN_lshift(D,D,nm-nd)) return(0); @@ -107,7 +106,7 @@ BN_CTX *ctx; if (BN_ucmp(rem,D) >= 0) { dv->d[0]|=1; - bn_qsub(rem,rem,D); + if (!BN_usub(rem,rem,D)) return(0); } /* CAN IMPROVE (and have now :=) */ if (!BN_rshift1(D,D)) return(0); @@ -119,12 +118,8 @@ BN_CTX *ctx; #else -int BN_div(dv, rm, num, divisor,ctx) -BIGNUM *dv; -BIGNUM *rm; -BIGNUM *num; -BIGNUM *divisor; -BN_CTX *ctx; +int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, + BN_CTX *ctx) { int norm_shift,i,j,loop; BIGNUM *tmp,wnum,*snum,*sdiv,*res; @@ -132,6 +127,9 @@ BN_CTX *ctx; BN_ULONG d0,d1; int num_n,div_n; + bn_check_top(num); + bn_check_top(divisor); + if (BN_is_zero(divisor)) { BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); @@ -146,12 +144,12 @@ BN_CTX *ctx; return(1); } - tmp=ctx->bn[ctx->tos]; + tmp= &(ctx->bn[ctx->tos]); tmp->neg=0; - snum=ctx->bn[ctx->tos+1]; - sdiv=ctx->bn[ctx->tos+2]; + snum= &(ctx->bn[ctx->tos+1]); + sdiv= &(ctx->bn[ctx->tos+2]); if (dv == NULL) - res=ctx->bn[ctx->tos+3]; + res= &(ctx->bn[ctx->tos+3]); else res=dv; /* First we normalise the numbers */ @@ -168,10 +166,10 @@ BN_CTX *ctx; /* Lets setup a 'window' into snum * This is the part that corresponds to the current * 'area' being divided */ + BN_init(&wnum); wnum.d= &(snum->d[loop]); wnum.top= div_n; - wnum.max= snum->max; /* a bit of a lie */ - wnum.neg= 0; + wnum.max= snum->max+1; /* a bit of a lie */ /* Get the top 2 words of sdiv */ /* i=sdiv->top; */ @@ -183,8 +181,8 @@ BN_CTX *ctx; /* Setup to 'res' */ res->neg= (num->neg^divisor->neg); - res->top=loop; if (!bn_wexpand(res,(loop+1))) goto err; + res->top=loop; resp= &(res->d[loop-1]); /* space for temp */ @@ -192,7 +190,7 @@ BN_CTX *ctx; if (BN_ucmp(&wnum,sdiv) >= 0) { - bn_qsub(&wnum,&wnum,sdiv); + if (!BN_usub(&wnum,&wnum,sdiv)) goto err; *resp=1; res->d[res->top-1]=1; } @@ -202,56 +200,98 @@ BN_CTX *ctx; for (i=0; i=2 +# if defined(__i386) + /* + * There were two reasons for implementing this template: + * - GNU C generates a call to a function (__udivdi3 to be exact) + * in reply to ((((BN_ULLONG)n0)< + */ +# define bn_div_words(n0,n1,d0) \ + ({ asm volatile ( \ + "divl %4" \ + : "=a"(q), "=d"(rem) \ + : "a"(n1), "d"(n0), "g"(d0) \ + : "cc"); \ + q; \ + }) +# define REMINDER_IS_ALREADY_CALCULATED +# endif /* __ */ +# endif /* __GNUC__ */ +#endif /* NO_ASM */ + BN_ULONG n0,n1,rem=0; - wnum.d--; wnum.top++; n0=wnump[0]; n1=wnump[-1]; if (n0 == d0) q=BN_MASK2; else - q=bn_div64(n0,n1,d0); +#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words) + q=((((BN_ULLONG)n0)<>BN_BITS2) || - (t2 <= ((BN_ULLONG)(rem< t1l) t3h++; - t3h=(t1h-t3h)&BN_MASK2; - - /*if ((t3>>BN_BITS2) || - (t2 <= ((t3<d,sdiv->d,div_n,q); tmp->d[div_n]=l0; for (j=div_n+1; j>0; j--) @@ -284,3 +324,35 @@ err: } #endif + +/* rem != m */ +int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) + { +#if 0 /* The old slow way */ + int i,nm,nd; + BIGNUM *dv; + + if (BN_ucmp(m,d) < 0) + return((BN_copy(rem,m) == NULL)?0:1); + + dv= &(ctx->bn[ctx->tos]); + + if (!BN_copy(rem,m)) return(0); + + nm=BN_num_bits(rem); + nd=BN_num_bits(d); + if (!BN_lshift(dv,d,nm-nd)) return(0); + for (i=nm-nd; i>=0; i--) + { + if (BN_cmp(rem,dv) >= 0) + { + if (!BN_sub(rem,rem,dv)) return(0); + } + if (!BN_rshift1(dv,dv)) return(0); + } + return(1); +#else + return(BN_div(NULL,rem,m,d,ctx)); +#endif + } + diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c index 029ae810d5..73e80774e5 100644 --- a/src/lib/libcrypto/bn/bn_err.c +++ b/src/lib/libcrypto/bn/bn_err.c @@ -1,63 +1,65 @@ -/* lib/bn/bn_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/bn/bn_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "bn.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -78,29 +80,32 @@ static ERR_STRING_DATA BN_str_functs[]= {ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"}, {ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"}, {ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"}, -{0,NULL}, +{ERR_PACK(0,BN_F_BN_USUB,0), "BN_usub"}, +{0,NULL} }; static ERR_STRING_DATA BN_str_reasons[]= { +{BN_R_ARG2_LT_ARG3 ,"arg2 lt arg3"}, {BN_R_BAD_RECIPROCAL ,"bad reciprocal"}, {BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"}, {BN_R_DIV_BY_ZERO ,"div by zero"}, {BN_R_ENCODING_ERROR ,"encoding error"}, +{BN_R_EXPAND_ON_STATIC_BIGNUM_DATA ,"expand on static bignum data"}, {BN_R_INVALID_LENGTH ,"invalid length"}, -{BN_R_NOT_INITALISED ,"not initalised"}, +{BN_R_NOT_INITIALIZED ,"not initialized"}, {BN_R_NO_INVERSE ,"no inverse"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_BN_strings() +void ERR_load_BN_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_BN,BN_str_functs); diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c index c056a5083f..2df1614ada 100644 --- a/src/lib/libcrypto/bn/bn_exp.c +++ b/src/lib/libcrypto/bn/bn_exp.c @@ -60,22 +60,23 @@ #include "cryptlib.h" #include "bn_lcl.h" +#define TABLE_SIZE 16 + /* slow but works */ -int BN_mod_mul(ret, a, b, m, ctx) -BIGNUM *ret; -BIGNUM *a; -BIGNUM *b; -BIGNUM *m; -BN_CTX *ctx; +int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx) { BIGNUM *t; int r=0; - t=ctx->bn[ctx->tos++]; + bn_check_top(a); + bn_check_top(b); + bn_check_top(m); + + t= &(ctx->bn[ctx->tos++]); if (a == b) { if (!BN_sqr(t,a,ctx)) goto err; } else - { if (!BN_mul(t,a,b)) goto err; } + { if (!BN_mul(t,a,b,ctx)) goto err; } if (!BN_mod(ret,t,m,ctx)) goto err; r=1; err: @@ -85,22 +86,20 @@ err: #if 0 /* this one works - simple but works */ -int BN_mod_exp(r,a,p,m,ctx) -BIGNUM *r,*a,*p,*m; -BN_CTX *ctx; +int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx) { int i,bits,ret=0; BIGNUM *v,*tmp; - v=ctx->bn[ctx->tos++]; - tmp=ctx->bn[ctx->tos++]; + v= &(ctx->bn[ctx->tos++]); + tmp= &(ctx->bn[ctx->tos++]); if (BN_copy(v,a) == NULL) goto err; bits=BN_num_bits(p); if (BN_is_odd(p)) { if (BN_copy(r,a) == NULL) goto err; } - else { if (BN_one(r)) goto err; } + else { if (!BN_one(r)) goto err; } for (i=1; ibn[ctx->tos++]; - tmp=ctx->bn[ctx->tos++]; + tos=ctx->tos; + v= &(ctx->bn[ctx->tos++]); + if ((r == a) || (r == p)) + rr= &(ctx->bn[ctx->tos++]); + else + rr=r; if (BN_copy(v,a) == NULL) goto err; bits=BN_num_bits(p); if (BN_is_odd(p)) - { if (BN_copy(r,a) == NULL) goto err; } - else { if (BN_one(r)) goto err; } + { if (BN_copy(rr,a) == NULL) goto err; } + else { if (!BN_one(rr)) goto err; } for (i=1; itos-=2; + ctx->tos=tos; + if (r != rr) BN_copy(r,rr); return(ret); } -int BN_mod_exp(r,a,p,m,ctx) -BIGNUM *r; -BIGNUM *a; -BIGNUM *p; -BIGNUM *m; -BN_CTX *ctx; +int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m, + BN_CTX *ctx) { int ret; + bn_check_top(a); + bn_check_top(p); + bn_check_top(m); + #ifdef MONT_MUL_MOD /* I have finally been able to take out this pre-condition of * the top bit being set. It was caused by an error in BN_div @@ -182,20 +184,16 @@ BN_CTX *ctx; } /* #ifdef RECP_MUL_MOD */ -int BN_mod_exp_recp(r,a,p,m,ctx) -BIGNUM *r; -BIGNUM *a; -BIGNUM *p; -BIGNUM *m; -BN_CTX *ctx; +int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx) { - int nb,i,j,bits,ret=0,wstart,wend,window,wvalue; - int start=1; - BIGNUM *d,*aa; - BIGNUM *val[16]; + int i,j,bits,ret=0,wstart,wend,window,wvalue; + int start=1,ts=0; + BIGNUM *aa; + BIGNUM val[TABLE_SIZE]; + BN_RECP_CTX recp; - d=ctx->bn[ctx->tos++]; - aa=ctx->bn[ctx->tos++]; + aa= &(ctx->bn[ctx->tos++]); bits=BN_num_bits(p); if (bits == 0) @@ -203,12 +201,14 @@ BN_CTX *ctx; BN_one(r); return(1); } - nb=BN_reciprocal(d,m,ctx); - if (nb == -1) goto err; + BN_RECP_CTX_init(&recp); + if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err; - val[0]=BN_new(); - if (!BN_mod(val[0],a,m,ctx)) goto err; /* 1 */ - if (!BN_mod_mul_reciprocal(aa,val[0],val[0],m,d,nb,ctx)) + BN_init(&(val[0])); + ts=1; + + if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */ + if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx)) goto err; /* 2 */ if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ @@ -223,12 +223,11 @@ BN_CTX *ctx; j=1<<(window-1); for (i=1; i>1],m,d,nb,ctx)) + if (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx)) goto err; /* move the 'window' down further */ @@ -290,35 +289,36 @@ BN_CTX *ctx; } ret=1; err: - ctx->tos-=2; - for (i=0; i<16; i++) - if (val[i] != NULL) BN_clear_free(val[i]); + ctx->tos--; + for (i=0; id[0] & 1)) { BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); return(0); } - d=ctx->bn[ctx->tos++]; + d= &(ctx->bn[ctx->tos++]); + r= &(ctx->bn[ctx->tos++]); bits=BN_num_bits(p); if (bits == 0) { @@ -339,22 +339,23 @@ BN_MONT_CTX *in_mont; if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; } - val[0]=BN_new(); + BN_init(&val[0]); + ts=1; if (BN_ucmp(a,m) >= 0) { - BN_mod(val[0],a,m,ctx); - aa=val[0]; + BN_mod(&(val[0]),a,m,ctx); + aa= &(val[0]); } else aa=a; - if (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err; /* 1 */ - if (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err; /* 2 */ + if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */ + if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */ if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */ window=1; - else if (bits > 250) + else if (bits >= 256) window=5; /* max size of window */ - else if (bits >= 120) + else if (bits >= 128) window=4; else window=3; @@ -362,12 +363,11 @@ BN_MONT_CTX *in_mont; j=1<<(window-1); for (i=1; i>1],mont,ctx)) + if (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx)) goto err; /* move the 'window' down further */ @@ -428,31 +428,27 @@ BN_MONT_CTX *in_mont; start=0; if (wstart < 0) break; } - BN_from_montgomery(r,r,mont,ctx); + BN_from_montgomery(rr,r,mont,ctx); ret=1; err: if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); - ctx->tos--; - for (i=0; itos-=2; + for (i=0; ibn[ctx->tos++]; + d= &(ctx->bn[ctx->tos++]); bits=BN_num_bits(p); if (bits == 0) @@ -461,9 +457,10 @@ BN_CTX *ctx; return(1); } - val[0]=BN_new(); - if (!BN_mod(val[0],a,m,ctx)) goto err; /* 1 */ - if (!BN_mod_mul(d,val[0],val[0],m,ctx)) + BN_init(&(val[0])); + ts=1; + if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */ + if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx)) goto err; /* 2 */ if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ @@ -478,12 +475,11 @@ BN_CTX *ctx; j=1<<(window-1); for (i=1; i>1],m,ctx)) + if (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx)) goto err; /* move the 'window' down further */ @@ -546,8 +542,8 @@ BN_CTX *ctx; ret=1; err: ctx->tos--; - for (i=0; i<16; i++) - if (val[i] != NULL) BN_clear_free(val[i]); + for (i=0; i +#include "cryptlib.h" +#include "bn_lcl.h" + +/* I've done some timing with different table sizes. + * The main hassle is that even with bits set at 3, this requires + * 63 BIGNUMs to store the pre-calculated values. + * 512 1024 + * bits=1 75.4% 79.4% + * bits=2 61.2% 62.4% + * bits=3 61.3% 59.3% + * The lack of speed improvment is also a function of the pre-calculation + * which could be removed. + */ +#define EXP2_TABLE_BITS 2 /* 1 2 3 4 5 */ +#define EXP2_TABLE_SIZE 4 /* 2 4 8 16 32 */ + +int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2, + BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) + { + int i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue; + int start=1,ts=0,x,y; + BIGNUM *d,*aa1,*aa2,*r; + BIGNUM val[EXP2_TABLE_SIZE][EXP2_TABLE_SIZE]; + BN_MONT_CTX *mont=NULL; + + bn_check_top(a1); + bn_check_top(p1); + bn_check_top(a2); + bn_check_top(p2); + bn_check_top(m); + + if (!(m->d[0] & 1)) + { + BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); + return(0); + } + d= &(ctx->bn[ctx->tos++]); + r= &(ctx->bn[ctx->tos++]); + bits1=BN_num_bits(p1); + bits2=BN_num_bits(p2); + if ((bits1 == 0) && (bits2 == 0)) + { + BN_one(r); + return(1); + } + bits=(bits1 > bits2)?bits1:bits2; + + /* If this is not done, things will break in the montgomery + * part */ + + if (in_mont != NULL) + mont=in_mont; + else + { + if ((mont=BN_MONT_CTX_new()) == NULL) goto err; + if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; + } + + BN_init(&(val[0][0])); + BN_init(&(val[1][1])); + BN_init(&(val[0][1])); + BN_init(&(val[1][0])); + ts=1; + if (BN_ucmp(a1,m) >= 0) + { + BN_mod(&(val[1][0]),a1,m,ctx); + aa1= &(val[1][0]); + } + else + aa1=a1; + if (BN_ucmp(a2,m) >= 0) + { + BN_mod(&(val[0][1]),a2,m,ctx); + aa2= &(val[0][1]); + } + else + aa2=a2; + if (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err; + if (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err; + if (!BN_mod_mul_montgomery(&(val[1][1]), + &(val[1][0]),&(val[0][1]),mont,ctx)) + goto err; + +#if 0 + if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */ + window=1; + else if (bits > 250) + window=5; /* max size of window */ + else if (bits >= 120) + window=4; + else + window=3; +#else + window=EXP2_TABLE_BITS; +#endif + + k=1<= 2) + { + BN_init(&(val[x][0])); + BN_init(&(val[x][1])); + if (!BN_mod_mul_montgomery(&(val[x][0]), + &(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err; + if (!BN_mod_mul_montgomery(&(val[x][1]), + &(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err; + } + for (y=2; ytos-=2; + for (i=0; ibn[ctx->tos]; - b=ctx->bn[ctx->tos+1]; + bn_check_top(in_a); + bn_check_top(in_b); + + a= &(ctx->bn[ctx->tos]); + b= &(ctx->bn[ctx->tos+1]); if (BN_copy(a,in_a) == NULL) goto err; if (BN_copy(b,in_b) == NULL) goto err; @@ -89,12 +85,14 @@ err: return(ret); } -static BIGNUM *euclid(a,b) -BIGNUM *a,*b; +static BIGNUM *euclid(BIGNUM *a, BIGNUM *b) { BIGNUM *t; int shifts=0; + bn_check_top(a); + bn_check_top(b); + for (;;) { if (BN_is_zero(b)) @@ -142,23 +140,26 @@ err: } /* solves ax == 1 (mod n) */ -BIGNUM *BN_mod_inverse(a, n, ctx) -BIGNUM *a; -BIGNUM *n; -BN_CTX *ctx; +BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) { BIGNUM *A,*B,*X,*Y,*M,*D,*R; - BIGNUM *ret=NULL,*T; + BIGNUM *T,*ret=NULL; int sign; - A=ctx->bn[ctx->tos]; - B=ctx->bn[ctx->tos+1]; - X=ctx->bn[ctx->tos+2]; - D=ctx->bn[ctx->tos+3]; - M=ctx->bn[ctx->tos+4]; - Y=ctx->bn[ctx->tos+5]; + bn_check_top(a); + bn_check_top(n); + + A= &(ctx->bn[ctx->tos]); + B= &(ctx->bn[ctx->tos+1]); + X= &(ctx->bn[ctx->tos+2]); + D= &(ctx->bn[ctx->tos+3]); + M= &(ctx->bn[ctx->tos+4]); + Y= &(ctx->bn[ctx->tos+5]); ctx->tos+=6; - R=BN_new(); + if (in == NULL) + R=BN_new(); + else + R=in; if (R == NULL) goto err; BN_zero(X); @@ -175,7 +176,7 @@ BN_CTX *ctx; B=M; /* T has a struct, M does not */ - if (!BN_mul(T,D,X)) goto err; + if (!BN_mul(T,D,X,ctx)) goto err; if (!BN_add(T,T,Y)) goto err; M=Y; Y=X; @@ -196,7 +197,7 @@ BN_CTX *ctx; } ret=R; err: - if ((ret == NULL) && (R != NULL)) BN_free(R); + if ((ret == NULL) && (in == NULL)) BN_free(R); ctx->tos-=6; return(ret); } diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h index edfd788338..85a372695b 100644 --- a/src/lib/libcrypto/bn/bn_lcl.h +++ b/src/lib/libcrypto/bn/bn_lcl.h @@ -59,23 +59,79 @@ #ifndef HEADER_BN_LCL_H #define HEADER_BN_LCL_H -#include "bn.h" +#include #ifdef __cplusplus extern "C" { #endif +/* Pentium pro 16,16,16,32,64 */ +/* Alpha 16,16,16,16.64 */ +#define BN_MULL_SIZE_NORMAL (16) /* 32 */ +#define BN_MUL_RECURSIVE_SIZE_NORMAL (16) /* 32 less than */ +#define BN_SQR_RECURSIVE_SIZE_NORMAL (16) /* 32 */ +#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */ +#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */ + +#if 0 +#ifndef BN_MUL_COMBA +/* #define bn_mul_comba8(r,a,b) bn_mul_normal(r,a,8,b,8) */ +/* #define bn_mul_comba4(r,a,b) bn_mul_normal(r,a,4,b,4) */ +#endif + +#ifndef BN_SQR_COMBA +/* This is probably faster than using the C code - I need to check */ +#define bn_sqr_comba8(r,a) bn_mul_normal(r,a,8,a,8) +#define bn_sqr_comba4(r,a) bn_mul_normal(r,a,4,a,4) +#endif +#endif + /************************************************************* * Using the long long type */ #define Lw(t) (((BN_ULONG)(t))&BN_MASK2) #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) -#define bn_fix_top(a) \ - { \ - BN_ULONG *fix_top_l; \ - for (fix_top_l= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ - if (*(fix_top_l--)) break; \ +/* These are used for internal error checking and are not normally used */ +#ifdef BN_DEBUG +#define bn_check_top(a) \ + { if (((a)->top < 0) || ((a)->top > (a)->max)) \ + { char *nullp=NULL; *nullp='z'; } } +#define bn_check_num(a) if ((a) < 0) { char *nullp=NULL; *nullp='z'; } +#else +#define bn_check_top(a) +#define bn_check_num(a) +#endif + +/* This macro is to add extra stuff for development checking */ +#ifdef BN_DEBUG +#define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA)) +#else +#define bn_set_max(r) +#endif + +/* These macros are used to 'take' a section of a bignum for read only use */ +#define bn_set_low(r,a,n) \ + { \ + (r)->top=((a)->top > (n))?(n):(a)->top; \ + (r)->d=(a)->d; \ + (r)->neg=(a)->neg; \ + (r)->flags|=BN_FLG_STATIC_DATA; \ + bn_set_max(r); \ + } + +#define bn_set_high(r,a,n) \ + { \ + if ((a)->top > (n)) \ + { \ + (r)->top=(a)->top-n; \ + (r)->d= &((a)->d[n]); \ + } \ + else \ + (r)->top=0; \ + (r)->neg=(a)->neg; \ + (r)->flags|=BN_FLG_STATIC_DATA; \ + bn_set_max(r); \ } /* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */ @@ -175,22 +231,35 @@ extern "C" { #endif -#ifndef NOPROTO +OPENSSL_EXTERN int bn_limit_bits; +OPENSSL_EXTERN int bn_limit_num; /* (1<= 0) + { + if (mult > (sizeof(int)*8)-1) + mult=sizeof(int)*8-1; + bn_limit_bits=mult; + bn_limit_num=1<= 0) + { + if (high > (sizeof(int)*8)-1) + high=sizeof(int)*8-1; + bn_limit_bits_high=high; + bn_limit_num_high=1<= 0) + { + if (low > (sizeof(int)*8)-1) + low=sizeof(int)*8-1; + bn_limit_bits_low=low; + bn_limit_num_low=1<= 0) + { + if (mont > (sizeof(int)*8)-1) + mont=sizeof(int)*8-1; + bn_limit_bits_mont=mont; + bn_limit_num_mont=1<>56]+56); + return(bits[(int)(l>>56)]+56); } - else return(bits[l>>48]+48); + else return(bits[(int)(l>>48)]+48); } else { if (l & 0x0000ff0000000000L) { - return(bits[l>>40]+40); + return(bits[(int)(l>>40)]+40); } - else return(bits[l>>32]+32); + else return(bits[(int)(l>>32)]+32); } } else @@ -140,17 +198,17 @@ BN_ULONG l; { if (l & 0xff00000000000000LL) { - return(bits[l>>56]+56); + return(bits[(int)(l>>56)]+56); } - else return(bits[l>>48]+48); + else return(bits[(int)(l>>48)]+48); } else { if (l & 0x0000ff0000000000LL) { - return(bits[l>>40]+40); + return(bits[(int)(l>>40)]+40); } - else return(bits[l>>32]+32); + else return(bits[(int)(l>>32)]+32); } } else @@ -161,28 +219,29 @@ BN_ULONG l; if (l & 0xffff0000L) { if (l & 0xff000000L) - return(bits[l>>24L]+24); - else return(bits[l>>16L]+16); + return(bits[(int)(l>>24L)]+24); + else return(bits[(int)(l>>16L)]+16); } else #endif { #if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) if (l & 0xff00L) - return(bits[l>>8]+8); + return(bits[(int)(l>>8)]+8); else #endif - return(bits[l ] ); + return(bits[(int)(l )] ); } } } -int BN_num_bits(a) -BIGNUM *a; +int BN_num_bits(const BIGNUM *a) { BN_ULONG l; int i; + bn_check_top(a); + if (a->top == 0) return(0); l=a->d[a->top-1]; i=(a->top-1)*BN_BITS2; @@ -196,126 +255,256 @@ BIGNUM *a; return(i+BN_num_bits_word(l)); } -void BN_clear_free(a) -BIGNUM *a; +void BN_clear_free(BIGNUM *a) { + int i; + if (a == NULL) return; if (a->d != NULL) { memset(a->d,0,a->max*sizeof(a->d[0])); - Free(a->d); + if (!(BN_get_flags(a,BN_FLG_STATIC_DATA))) + Free(a->d); } + i=BN_get_flags(a,BN_FLG_MALLOCED); memset(a,0,sizeof(BIGNUM)); - Free(a); + if (i) + Free(a); } -void BN_free(a) -BIGNUM *a; +void BN_free(BIGNUM *a) { if (a == NULL) return; - if (a->d != NULL) Free(a->d); - Free(a); + if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) + Free(a->d); + a->flags|=BN_FLG_FREE; /* REMOVE? */ + if (a->flags & BN_FLG_MALLOCED) + Free(a); + } + +void BN_init(BIGNUM *a) + { + memset(a,0,sizeof(BIGNUM)); } -BIGNUM *BN_new() +BIGNUM *BN_new(void) { BIGNUM *ret; - BN_ULONG *p; - ret=(BIGNUM *)Malloc(sizeof(BIGNUM)); - if (ret == NULL) goto err; + if ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL) + { + BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); + return(NULL); + } + ret->flags=BN_FLG_MALLOCED; ret->top=0; ret->neg=0; - ret->max=(BN_DEFAULT_BITS/BN_BITS2); - p=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(ret->max+1)); - if (p == NULL) goto err; - ret->d=p; - - memset(p,0,(ret->max+1)*sizeof(p[0])); + ret->max=0; + ret->d=NULL; return(ret); -err: - BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); - return(NULL); } -BN_CTX *BN_CTX_new() + +BN_CTX *BN_CTX_new(void) { BN_CTX *ret; - BIGNUM *n; - int i,j; ret=(BN_CTX *)Malloc(sizeof(BN_CTX)); - if (ret == NULL) goto err2; - - for (i=0; ibn[i]=n; + BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE); + return(NULL); } - /* There is actually an extra one, this is for debugging my - * stuff */ - ret->bn[BN_CTX_NUM]=NULL; - - ret->tos=0; + BN_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; return(ret); -err: - for (j=0; jbn[j]); - Free(ret); -err2: - BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE); - return(NULL); } -void BN_CTX_free(c) -BN_CTX *c; +void BN_CTX_init(BN_CTX *ctx) + { + memset(ctx,0,sizeof(BN_CTX)); + ctx->tos=0; + ctx->flags=0; + } + +void BN_CTX_free(BN_CTX *c) { int i; + if(c == NULL) + return; + for (i=0; ibn[i]); - Free(c); + BN_clear_free(&(c->bn[i])); + if (c->flags & BN_FLG_MALLOCED) + Free(c); } -BIGNUM *bn_expand2(b, words) -BIGNUM *b; -int words; +BIGNUM *bn_expand2(BIGNUM *b, int words) { - BN_ULONG *p; + BN_ULONG *A,*a; + const BN_ULONG *B; + int i; + + bn_check_top(b); if (words > b->max) { - p=(BN_ULONG *)Realloc(b->d,sizeof(BN_ULONG)*(words+1)); - if (p == NULL) + bn_check_top(b); + if (BN_get_flags(b,BN_FLG_STATIC_DATA)) + { + BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); + return(NULL); + } + a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); + if (A == NULL) { BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); return(NULL); } - b->d=p; - memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG)); +#if 1 + B=b->d; + /* Check if the previous number needs to be copied */ + if (B != NULL) + { +#if 0 + /* This lot is an unrolled loop to copy b->top + * BN_ULONGs from B to A + */ +/* + * I have nothing against unrolling but it's usually done for + * several reasons, namely: + * - minimize percentage of decision making code, i.e. branches; + * - avoid cache trashing; + * - make it possible to schedule loads earlier; + * Now let's examine the code below. The cornerstone of C is + * "programmer is always right" and that's what we love it for:-) + * For this very reason C compilers have to be paranoid when it + * comes to data aliasing and assume the worst. Yeah, but what + * does it mean in real life? This means that loop body below will + * be compiled to sequence of loads immediately followed by stores + * as compiler assumes the worst, something in A==B+1 style. As a + * result CPU pipeline is going to starve for incoming data. Secondly + * if A and B happen to share same cache line such code is going to + * cause severe cache trashing. Both factors have severe impact on + * performance of modern CPUs and this is the reason why this + * particulare piece of code is #ifdefed away and replaced by more + * "friendly" version found in #else section below. This comment + * also applies to BN_copy function. + * + * + */ + for (i=b->top&(~7); i>0; i-=8) + { + A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3]; + A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7]; + A+=8; + B+=8; + } + switch (b->top&7) + { + case 7: + A[6]=B[6]; + case 6: + A[5]=B[5]; + case 5: + A[4]=B[4]; + case 4: + A[3]=B[3]; + case 3: + A[2]=B[2]; + case 2: + A[1]=B[1]; + case 1: + A[0]=B[0]; + case 0: + /* I need the 'case 0' entry for utrix cc. + * If the optimiser is turned on, it does the + * switch table by doing + * a=top&7 + * a--; + * goto jump_table[a]; + * If top is 0, this makes us jump to 0xffffffc + * which is rather bad :-(. + * eric 23-Apr-1998 + */ + ; + } +#else + for (i=b->top>>2; i>0; i--,A+=4,B+=4) + { + /* + * The fact that the loop is unrolled + * 4-wise is a tribute to Intel. It's + * the one that doesn't have enough + * registers to accomodate more data. + * I'd unroll it 8-wise otherwise:-) + * + * + */ + BN_ULONG a0,a1,a2,a3; + a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3]; + A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3; + } + switch (b->top&3) + { + case 3: A[2]=B[2]; + case 2: A[1]=B[1]; + case 1: A[0]=B[0]; + case 0: ; /* ultrix cc workaround, see above */ + } +#endif + Free(b->d); + } + + b->d=a; b->max=words; + + /* Now need to zero any data between b->top and b->max */ + + A= &(b->d[b->top]); + for (i=(b->max - b->top)>>3; i>0; i--,A+=8) + { + A[0]=0; A[1]=0; A[2]=0; A[3]=0; + A[4]=0; A[5]=0; A[6]=0; A[7]=0; + } + for (i=(b->max - b->top)&7; i>0; i--,A++) + A[0]=0; +#else + memset(A,0,sizeof(BN_ULONG)*(words+1)); + memcpy(A,b->d,sizeof(b->d[0])*b->top); + b->d=a; + b->max=words; +#endif + +/* memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG)); */ +/* { int i; for (i=b->max; itop) == NULL) return(NULL); @@ -323,35 +512,18 @@ BIGNUM *b; #if 1 A=a->d; B=b->d; - for (i=b->top&(~7); i>0; i-=8) + for (i=b->top>>2; i>0; i--,A+=4,B+=4) { - A[0]=B[0]; - A[1]=B[1]; - A[2]=B[2]; - A[3]=B[3]; - A[4]=B[4]; - A[5]=B[5]; - A[6]=B[6]; - A[7]=B[7]; - A+=8; - B+=8; + BN_ULONG a0,a1,a2,a3; + a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3]; + A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3; } - switch (b->top&7) + switch (b->top&3) { - case 7: - A[6]=B[6]; - case 6: - A[5]=B[5]; - case 5: - A[4]=B[4]; - case 4: - A[3]=B[3]; - case 3: - A[2]=B[2]; - case 2: - A[1]=B[1]; - case 1: - A[0]=B[0]; + case 3: A[2]=B[2]; + case 2: A[1]=B[1]; + case 1: A[0]=B[0]; + case 0: ; /* ultrix cc workaround, see comments in bn_expand2 */ } #else memcpy(a->d,b->d,sizeof(b->d[0])*b->top); @@ -359,52 +531,47 @@ BIGNUM *b; /* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/ a->top=b->top; - if (a->top == 0) + if ((a->top == 0) && (a->d != NULL)) a->d[0]=0; a->neg=b->neg; return(a); } -void BN_clear(a) -BIGNUM *a; +void BN_clear(BIGNUM *a) { - memset(a->d,0,a->max*sizeof(a->d[0])); + if (a->d != NULL) + memset(a->d,0,a->max*sizeof(a->d[0])); a->top=0; a->neg=0; } -unsigned long BN_get_word(a) -BIGNUM *a; +BN_ULONG BN_get_word(BIGNUM *a) { int i,n; - unsigned long ret=0; + BN_ULONG ret=0; n=BN_num_bytes(a); - if (n > sizeof(unsigned long)) -#ifdef SIXTY_FOUR_BIT_LONG + if (n > sizeof(BN_ULONG)) return(BN_MASK2); -#else - return(0xFFFFFFFFL); -#endif for (i=a->top-1; i>=0; i--) { #ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ ret<<=BN_BITS4; /* stops the compiler complaining */ ret<<=BN_BITS4; +#else + ret=0; #endif ret|=a->d[i]; } return(ret); } -int BN_set_word(a,w) -BIGNUM *a; -unsigned long w; +int BN_set_word(BIGNUM *a, BN_ULONG w) { int i,n; - if (bn_expand(a,sizeof(unsigned long)*8) == NULL) return(0); + if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0); - n=sizeof(unsigned long)/BN_BYTES; + n=sizeof(BN_ULONG)/BN_BYTES; a->neg=0; a->top=0; a->d[0]=(BN_ULONG)w&BN_MASK2; @@ -417,6 +584,8 @@ unsigned long w; #ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ w>>=BN_BITS4; w>>=BN_BITS4; +#else + w=0; #endif a->d[i]=(BN_ULONG)w&BN_MASK2; if (a->d[i] != 0) a->top=i+1; @@ -425,10 +594,7 @@ unsigned long w; } /* ignore negative */ -BIGNUM *BN_bin2bn(s, len, ret) -unsigned char *s; -int len; -BIGNUM *ret; +BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret) { unsigned int i,m; unsigned int n; @@ -465,9 +631,7 @@ BIGNUM *ret; } /* ignore negative */ -int BN_bn2bin(a, to) -BIGNUM *a; -unsigned char *to; +int BN_bn2bin(const BIGNUM *a, unsigned char *to) { int n,i; BN_ULONG l; @@ -481,13 +645,14 @@ unsigned char *to; return(n); } -int BN_ucmp(a, b) -BIGNUM *a; -BIGNUM *b; +int BN_ucmp(const BIGNUM *a, const BIGNUM *b) { int i; BN_ULONG t1,t2,*ap,*bp; + bn_check_top(a); + bn_check_top(b); + i=a->top-b->top; if (i != 0) return(i); ap=a->d; @@ -502,9 +667,7 @@ BIGNUM *b; return(0); } -int BN_cmp(a, b) -BIGNUM *a; -BIGNUM *b; +int BN_cmp(const BIGNUM *a, const BIGNUM *b) { int i; int gt,lt; @@ -519,6 +682,10 @@ BIGNUM *b; else return(0); } + + bn_check_top(a); + bn_check_top(b); + if (a->neg != b->neg) { if (a->neg) @@ -541,27 +708,25 @@ BIGNUM *b; return(0); } -int BN_set_bit(a, n) -BIGNUM *a; -int n; +int BN_set_bit(BIGNUM *a, int n) { - int i,j; + int i,j,k; i=n/BN_BITS2; j=n%BN_BITS2; if (a->top <= i) { - if (bn_expand(a,n) == NULL) return(0); + if (bn_wexpand(a,i+1) == NULL) return(0); + for(k=a->top; kd[k]=0; a->top=i+1; } - a->d[i]|=(1L<d[i]|=(((BN_ULONG)1)<top <= i) return(0); - a->d[i]&=(~(1L<d[i]&=(~(((BN_ULONG)1)<d[i]&(((BN_ULONG)1)<top=w+1; a->d[w]&= ~(BN_MASK2<= 0) && (a->d[w] == 0)) - { - a->top--; - w--; - } } + bn_fix_top(a); return(1); } + +int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n) + { + int i; + BN_ULONG aa,bb; + + aa=a[n-1]; + bb=b[n-1]; + if (aa != bb) return((aa > bb)?1:-1); + for (i=n-2; i>=0; i--) + { + aa=a[i]; + bb=b[i]; + if (aa != bb) return((aa > bb)?1:-1); + } + return(0); + } + diff --git a/src/lib/libcrypto/bn/bn_m.c b/src/lib/libcrypto/bn/bn_m.c deleted file mode 100644 index 5166daaeec..0000000000 --- a/src/lib/libcrypto/bn/bn_m.c +++ /dev/null @@ -1,169 +0,0 @@ -/* crypto/bn/bn_m.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "cryptlib.h" -#include "bn_lcl.h" -#include "stack.h" - -int limit=16; - -typedef struct bn_pool_st - { - int used; - int tos; - STACK *sk; - } BN_POOL; - -BIGNUM *BN_POOL_push(bp) -BN_POOL *bp; - { - BIGNUM *ret; - - if (bp->used >= bp->tos) - { - ret=BN_new(); - sk_push(bp->sk,(char *)ret); - bp->tos++; - bp->used++; - } - else - { - ret=(BIGNUM *)sk_value(bp->sk,bp->used); - bp->used++; - } - return(ret); - } - -void BN_POOL_pop(bp,num) -BN_POOL *bp; -int num; - { - bp->used-=num; - } - -int BN_m(r,a,b) -BIGNUM *r,*a,*b; - { - static BN_POOL bp; - static init=1; - - if (init) - { - bp.used=0; - bp.tos=0; - bp.sk=sk_new_null(); - init=0; - } - return(BN_mm(r,a,b,&bp)); - } - -/* r must be different to a and b */ -int BN_mm(m, A, B, bp) -BIGNUM *m,*A,*B; -BN_POOL *bp; - { - int i,num; - int an,bn; - BIGNUM *a,*b,*c,*d,*ac,*bd; - - an=A->top; - bn=B->top; - if ((an <= limit) || (bn <= limit)) - { - return(BN_mul(m,A,B)); - } - - a=BN_POOL_push(bp); - b=BN_POOL_push(bp); - c=BN_POOL_push(bp); - d=BN_POOL_push(bp); - ac=BN_POOL_push(bp); - bd=BN_POOL_push(bp); - - num=(an <= bn)?an:bn; - num=1<<(BN_num_bits_word(num-1)-1); - - /* Are going to now chop things into 'num' word chunks. */ - num*=BN_BITS2; - - BN_copy(a,A); - BN_mask_bits(a,num); - BN_rshift(b,A,num); - - BN_copy(c,B); - BN_mask_bits(c,num); - BN_rshift(d,B,num); - - BN_sub(ac ,b,a); - BN_sub(bd,c,d); - BN_mm(m,ac,bd,bp); - BN_mm(ac,a,c,bp); - BN_mm(bd,b,d,bp); - - BN_add(m,m,ac); - BN_add(m,m,bd); - BN_lshift(m,m,num); - BN_lshift(bd,bd,num*2); - - BN_add(m,m,ac); - BN_add(m,m,bd); - BN_POOL_pop(bp,6); - return(1); - } - diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/bn/bn_mod.c deleted file mode 100644 index c351aac14f..0000000000 --- a/src/lib/libcrypto/bn/bn_mod.c +++ /dev/null @@ -1,97 +0,0 @@ -/* crypto/bn/bn_mod.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "cryptlib.h" -#include "bn_lcl.h" - -/* rem != m */ -int BN_mod(rem, m, d,ctx) -BIGNUM *rem; -BIGNUM *m; -BIGNUM *d; -BN_CTX *ctx; - { -#if 0 /* The old slow way */ - int i,nm,nd; - BIGNUM *dv; - - if (BN_ucmp(m,d) < 0) - return((BN_copy(rem,m) == NULL)?0:1); - - dv=ctx->bn[ctx->tos]; - - if (!BN_copy(rem,m)) return(0); - - nm=BN_num_bits(rem); - nd=BN_num_bits(d); - if (!BN_lshift(dv,d,nm-nd)) return(0); - for (i=nm-nd; i>=0; i--) - { - if (BN_cmp(rem,dv) >= 0) - { - if (!BN_sub(rem,rem,dv)) return(0); - } - if (!BN_rshift1(dv,dv)) return(0); - } - return(1); -#else - return(BN_div(NULL,rem,m,d,ctx)); -#endif - } - diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c index e435df61f8..ee0f410c22 100644 --- a/src/lib/libcrypto/bn/bn_mont.c +++ b/src/lib/libcrypto/bn/bn_mont.c @@ -56,251 +56,352 @@ * [including the GNU Public Licence.] */ +/* + * Details about Montgomery multiplication algorithms can be found at: + * http://www.ece.orst.edu/ISL/Publications.html + * http://www.ece.orst.edu/ISL/Koc/papers/j37acmon.pdf + */ + #include #include "cryptlib.h" #include "bn_lcl.h" -int BN_mod_mul_montgomery(r,a,b,mont,ctx) -BIGNUM *r,*a,*b; -BN_MONT_CTX *mont; -BN_CTX *ctx; +#define MONT_WORD + +int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, + BN_MONT_CTX *mont, BN_CTX *ctx) { - BIGNUM *tmp; + BIGNUM *tmp,*tmp2; + + tmp= &(ctx->bn[ctx->tos]); + tmp2= &(ctx->bn[ctx->tos]); + ctx->tos+=2; - tmp=ctx->bn[ctx->tos++]; + bn_check_top(tmp); + bn_check_top(tmp2); if (a == b) { +#if 0 + bn_wexpand(tmp,a->top*2); + bn_wexpand(tmp2,a->top*4); + bn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d); + tmp->top=a->top*2; + if (tmp->d[tmp->top-1] == 0) + tmp->top--; +#else if (!BN_sqr(tmp,a,ctx)) goto err; +#endif } else { - if (!BN_mul(tmp,a,b)) goto err; + if (!BN_mul(tmp,a,b,ctx)) goto err; } /* reduce from aRR to aR */ if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err; - ctx->tos--; + ctx->tos-=2; return(1); err: return(0); } -#define MONT_WORD - -#ifdef MONT_WORD -int BN_from_montgomery(ret,a,mont,ctx) -BIGNUM *ret; -BIGNUM *a; -BN_MONT_CTX *mont; -BN_CTX *ctx; +int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont, + BN_CTX *ctx) { - BIGNUM *n,*t1,*r; - BN_ULONG *ap,*np,*rp,n0,v; - int al,nl,max,i,x,ri; - int retn=0; +#ifdef BN_RECURSION_MONT + if (mont->use_word) +#endif + { + BIGNUM *n,*r; + BN_ULONG *ap,*np,*rp,n0,v,*nrp; + int al,nl,max,i,x,ri; + int retn=0; - t1=ctx->bn[ctx->tos]; - r=ctx->bn[ctx->tos+1]; + r= &(ctx->bn[ctx->tos]); - if (!BN_copy(r,a)) goto err; - n=mont->N; + if (!BN_copy(r,a)) goto err1; + n= &(mont->N); - ap=a->d; - /* mont->ri is the size of mont->N in bits/words */ - al=ri=mont->ri/BN_BITS2; + ap=a->d; + /* mont->ri is the size of mont->N in bits/words */ + al=ri=mont->ri/BN_BITS2; - nl=n->top; - if ((al == 0) || (nl == 0)) { r->top=0; return(1); } + nl=n->top; + if ((al == 0) || (nl == 0)) { r->top=0; return(1); } - max=(nl+al+1); /* allow for overflow (no?) XXX */ - if (bn_wexpand(r,max) == NULL) goto err; - if (bn_wexpand(ret,max) == NULL) goto err; + max=(nl+al+1); /* allow for overflow (no?) XXX */ + if (bn_wexpand(r,max) == NULL) goto err1; + if (bn_wexpand(ret,max) == NULL) goto err1; - r->neg=a->neg^n->neg; - np=n->d; - rp=r->d; + r->neg=a->neg^n->neg; + np=n->d; + rp=r->d; + nrp= &(r->d[nl]); - /* clear the top words of T */ + /* clear the top words of T */ #if 1 - for (i=r->top; id[i]=0; + for (i=r->top; id[i]=0; #else - memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); + memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); #endif - r->top=max; - n0=mont->n0; - - for (i=0; itop=max; + n0=mont->n0; - if (i+4 > nl) +#ifdef BN_COUNT +printf("word BN_from_montgomery %d * %d\n",nl,nl); +#endif + for (i=0; i= v) + continue; + else + { + if (((++nrp[0])&BN_MASK2) != 0) continue; + if (((++nrp[1])&BN_MASK2) != 0) continue; + for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ; + } } + bn_fix_top(r); + + /* mont->ri will be a multiple of the word size */ +#if 0 + BN_rshift(ret,r,mont->ri); +#else + x=ri; + rp=ret->d; + ap= &(r->d[x]); + if (r->top < x) + al=0; else + al=r->top-x; + ret->top=al; + al-=4; + for (i=0; iN)) >= 0) { - for (x=(nl+1); (((++rp[x])&BN_MASK2) == 0); x++) - ; + BN_usub(ret,ret,&(mont->N)); /* XXX */ } - rp++; + retn=1; +err1: + return(retn); } - while (r->d[r->top-1] == 0) - r->top--; - - /* mont->ri will be a multiple of the word size */ -#if 0 - BN_rshift(ret,r,mont->ri); -#else - ap=r->d; - rp=ret->d; - x=ri; - al=r->top-x; - for (i=0; itop=al; + BIGNUM *t1,*t2,*t3; + int j,i; + +#ifdef BN_COUNT +printf("number BN_from_montgomery\n"); #endif - if (BN_ucmp(ret,mont->N) >= 0) - { - bn_qsub(ret,ret,mont->N); /* XXX */ - } - retn=1; -err: - return(retn); - } -#else -int BN_from_montgomery(r,a,mont,ctx) -BIGNUM *r; -BIGNUM *a; -BN_MONT_CTX *mont; -BN_CTX *ctx; - { - BIGNUM *t1,*t2; + t1= &(ctx->bn[ctx->tos]); + t2= &(ctx->bn[ctx->tos+1]); + t3= &(ctx->bn[ctx->tos+2]); - t1=ctx->bn[ctx->tos]; - t2=ctx->bn[ctx->tos+1]; + i=mont->Ni.top; + bn_wexpand(ret,i); /* perhaps only i*2 */ + bn_wexpand(t1,i*4); /* perhaps only i*2 */ + bn_wexpand(t2,i*2); /* perhaps only i */ - if (!BN_copy(t1,a)) goto err; - /* can cheat */ - BN_mask_bits(t1,mont->ri); + bn_mul_low_recursive(t2->d,a->d,mont->Ni.d,i,t1->d); - if (!BN_mul(t2,t1,mont->Ni)) goto err; - BN_mask_bits(t2,mont->ri); + BN_zero(t3); + BN_set_bit(t3,mont->N.top*BN_BITS2); + bn_sub_words(t3->d,t3->d,a->d,i); + bn_mul_high(ret->d,t2->d,mont->N.d,t3->d,i,t1->d); - if (!BN_mul(t1,t2,mont->N)) goto err; - if (!BN_add(t2,a,t1)) goto err; - BN_rshift(r,t2,mont->ri); + /* hmm... if a is between i and 2*i, things are bad */ + if (a->top > i) + { + j=(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i)); + if (j) /* overflow */ + bn_sub_words(ret->d,ret->d,mont->N.d,i); + } + ret->top=i; + bn_fix_top(ret); + if (a->d[0]) + BN_add_word(ret,1); /* Always? */ + else /* Very very rare */ + { + for (i=1; iN.top-1; i++) + { + if (a->d[i]) + { + BN_add_word(ret,1); /* Always? */ + break; + } + } + } - if (BN_ucmp(r,mont->N) >= 0) - bn_qsub(r,r,mont->N); + if (BN_ucmp(ret,&(mont->N)) >= 0) + BN_usub(ret,ret,&(mont->N)); - return(1); -err: - return(0); - } + return(1); + } #endif + } -BN_MONT_CTX *BN_MONT_CTX_new() +BN_MONT_CTX *BN_MONT_CTX_new(void) { BN_MONT_CTX *ret; if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL) return(NULL); - ret->ri=0; - ret->RR=BN_new(); - ret->N=BN_new(); - ret->Ni=NULL; - if ((ret->RR == NULL) || (ret->N == NULL)) - { - BN_MONT_CTX_free(ret); - return(NULL); - } + + BN_MONT_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; return(ret); } -void BN_MONT_CTX_free(mont) -BN_MONT_CTX *mont; +void BN_MONT_CTX_init(BN_MONT_CTX *ctx) + { + ctx->use_word=0; + ctx->ri=0; + BN_init(&(ctx->RR)); + BN_init(&(ctx->N)); + BN_init(&(ctx->Ni)); + ctx->flags=0; + } + +void BN_MONT_CTX_free(BN_MONT_CTX *mont) { - if (mont->RR != NULL) BN_free(mont->RR); - if (mont->N != NULL) BN_free(mont->N); - if (mont->Ni != NULL) BN_free(mont->Ni); - Free(mont); + if(mont == NULL) + return; + + BN_free(&(mont->RR)); + BN_free(&(mont->N)); + BN_free(&(mont->Ni)); + if (mont->flags & BN_FLG_MALLOCED) + Free(mont); } -int BN_MONT_CTX_set(mont,mod,ctx) -BN_MONT_CTX *mont; -BIGNUM *mod; -BN_CTX *ctx; +int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx) { - BIGNUM *Ri=NULL,*R=NULL; - - if (mont->RR == NULL) mont->RR=BN_new(); - if (mont->N == NULL) mont->N=BN_new(); - - R=mont->RR; /* grab RR as a temp */ - BN_copy(mont->N,mod); /* Set N */ - -#ifdef MONT_WORD -{ - BIGNUM tmod; - BN_ULONG buf[2]; - /* int z; */ - - mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; - BN_lshift(R,BN_value_one(),BN_BITS2); /* R */ - /* I was bad, this modification of a passed variable was - * breaking the multithreaded stuff :-( - * z=mod->top; - * mod->top=1; */ - - buf[0]=mod->d[0]; - buf[1]=0; - tmod.d=buf; - tmod.top=1; - tmod.max=mod->max; - tmod.neg=mod->neg; - - if ((Ri=BN_mod_inverse(R,&tmod,ctx)) == NULL) goto err; /* Ri */ - BN_lshift(Ri,Ri,BN_BITS2); /* R*Ri */ - bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */ - BN_div(Ri,NULL,Ri,&tmod,ctx); - mont->n0=Ri->d[0]; - BN_free(Ri); - /* mod->top=z; */ -} + BIGNUM Ri,*R; + + BN_init(&Ri); + R= &(mont->RR); /* grab RR as a temp */ + BN_copy(&(mont->N),mod); /* Set N */ + +#ifdef BN_RECURSION_MONT + if (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD) +#endif + { + BIGNUM tmod; + BN_ULONG buf[2]; + + mont->use_word=1; + + mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; + BN_zero(R); + BN_set_bit(R,BN_BITS2); + /* I was bad, this modification of a passed variable was + * breaking the multithreaded stuff :-( + * z=mod->top; + * mod->top=1; */ + + buf[0]=mod->d[0]; + buf[1]=0; + tmod.d=buf; + tmod.top=1; + tmod.max=mod->max; + tmod.neg=mod->neg; + + if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL) + goto err; + BN_lshift(&Ri,&Ri,BN_BITS2); /* R*Ri */ + if (!BN_is_zero(&Ri)) + { +#if 1 + BN_sub_word(&Ri,1); #else - mont->ri=BN_num_bits(mod); - BN_lshift(R,BN_value_one(),mont->ri); /* R */ - if ((Ri=BN_mod_inverse(R,mod,ctx)) == NULL) goto err; /* Ri */ - BN_lshift(Ri,Ri,mont->ri); /* R*Ri */ - bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */ - BN_div(Ri,NULL,Ri,mod,ctx); - if (mont->Ni != NULL) BN_free(mont->Ni); - mont->Ni=Ri; /* Ni=(R*Ri-1)/N */ + BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */ +#endif + } + else + { + /* This is not common..., 1 in BN_MASK2, + * It happens when buf[0] was == 1. So for 8 bit, + * this is 1/256, 16bit, 1 in 2^16 etc. + */ + BN_set_word(&Ri,BN_MASK2); + } + BN_div(&Ri,NULL,&Ri,&tmod,ctx); + mont->n0=Ri.d[0]; + BN_free(&Ri); + /* mod->top=z; */ + } +#ifdef BN_RECURSION_MONT + else + { + mont->use_word=0; + mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; +#if 1 + BN_zero(R); + BN_set_bit(R,mont->ri); +#else + BN_lshift(R,BN_value_one(),mont->ri); /* R */ +#endif + if ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL) + goto err; + BN_lshift(&Ri,&Ri,mont->ri); /* R*Ri */ +#if 1 + BN_sub_word(&Ri,1); +#else + BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */ +#endif + BN_div(&(mont->Ni),NULL,&Ri,mod,ctx); + BN_free(&Ri); + } #endif /* setup RR for conversions */ +#if 1 + BN_zero(&(mont->RR)); + BN_set_bit(&(mont->RR),mont->ri*2); +#else BN_lshift(mont->RR,BN_value_one(),mont->ri*2); - BN_mod(mont->RR,mont->RR,mont->N,ctx); +#endif + BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx); return(1); err: return(0); } +BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from) + { + if (to == from) return(to); + + BN_copy(&(to->RR),&(from->RR)); + BN_copy(&(to->N),&(from->N)); + BN_copy(&(to->Ni),&(from->Ni)); + to->use_word=from->use_word; + to->ri=from->ri; + to->n0=from->n0; + return(to); + } + diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c index 53945c1057..80e1dca6b7 100644 --- a/src/lib/libcrypto/bn/bn_mpi.c +++ b/src/lib/libcrypto/bn/bn_mpi.c @@ -60,9 +60,7 @@ #include "cryptlib.h" #include "bn_lcl.h" -int BN_bn2mpi(a,d) -BIGNUM *a; -unsigned char *d; +int BN_bn2mpi(const BIGNUM *a, unsigned char *d) { int bits; int num=0; @@ -90,10 +88,7 @@ unsigned char *d; return(num+4+ext); } -BIGNUM *BN_mpi2bn(d,n,a) -unsigned char *d; -int n; -BIGNUM *a; +BIGNUM *BN_mpi2bn(unsigned char *d, int n, BIGNUM *a) { long len; int neg=0; @@ -103,7 +98,7 @@ BIGNUM *a; BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH); return(NULL); } - len=(d[0]<<24)|(d[1]<<16)|(d[2]<<8)|d[3]; + len=((long)d[0]<<24)|((long)d[1]<<16)|((int)d[2]<<8)|(int)d[3]; if ((len+4) != n) { BNerr(BN_F_BN_MPI2BN,BN_R_ENCODING_ERROR); diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c index d0c04e1d4b..38c47f3d1f 100644 --- a/src/lib/libcrypto/bn/bn_mul.c +++ b/src/lib/libcrypto/bn/bn_mul.c @@ -60,150 +60,697 @@ #include "cryptlib.h" #include "bn_lcl.h" -/* r must be different to a and b */ -/* int BN_mmul(r, a, b) */ -int BN_mul(r, a, b) -BIGNUM *r; -BIGNUM *a; -BIGNUM *b; +#ifdef BN_RECURSION +/* r is 2*n2 words in size, + * a and b are both n2 words in size. + * n2 must be a power of 2. + * We multiply and return the result. + * t must be 2*n2 words in size + * We calulate + * a[0]*b[0] + * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) + * a[1]*b[1] + */ +void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, + BN_ULONG *t) { - int i; - int max,al,bl; - BN_ULONG *ap,*bp,*rp; + int n=n2/2,c1,c2; + unsigned int neg,zero; + BN_ULONG ln,lo,*p; - al=a->top; - bl=b->top; - if ((al == 0) || (bl == 0)) +#ifdef BN_COUNT +printf(" bn_mul_recursive %d * %d\n",n2,n2); +#endif +#ifdef BN_MUL_COMBA +/* if (n2 == 4) { - r->top=0; - return(1); + bn_mul_comba4(r,a,b); + return; + } + else */ if (n2 == 8) + { + bn_mul_comba8(r,a,b); + return; + } +#endif + if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) + { + /* This should not happen */ + bn_mul_normal(r,a,n2,b,n2); + return; + } + /* r=(a[0]-a[1])*(b[1]-b[0]) */ + c1=bn_cmp_words(a,&(a[n]),n); + c2=bn_cmp_words(&(b[n]),b,n); + zero=neg=0; + switch (c1*3+c2) + { + case -4: + bn_sub_words(t, &(a[n]),a, n); /* - */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + break; + case -3: + zero=1; + break; + case -2: + bn_sub_words(t, &(a[n]),a, n); /* - */ + bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */ + neg=1; + break; + case -1: + case 0: + case 1: + zero=1; + break; + case 2: + bn_sub_words(t, a, &(a[n]),n); /* + */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ + neg=1; + break; + case 3: + zero=1; + break; + case 4: + bn_sub_words(t, a, &(a[n]),n); + bn_sub_words(&(t[n]),&(b[n]),b, n); + break; } - max=(al+bl); - if (bn_wexpand(r,max) == NULL) return(0); - r->top=max; - r->neg=a->neg^b->neg; - ap=a->d; - bp=b->d; - rp=r->d; +#ifdef BN_MUL_COMBA + if (n == 4) + { + if (!zero) + bn_mul_comba4(&(t[n2]),t,&(t[n])); + else + memset(&(t[n2]),0,8*sizeof(BN_ULONG)); + + bn_mul_comba4(r,a,b); + bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n])); + } + else if (n == 8) + { + if (!zero) + bn_mul_comba8(&(t[n2]),t,&(t[n])); + else + memset(&(t[n2]),0,16*sizeof(BN_ULONG)); + + bn_mul_comba8(r,a,b); + bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n])); + } + else +#endif + { + p= &(t[n2*2]); + if (!zero) + bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); + else + memset(&(t[n2]),0,n2*sizeof(BN_ULONG)); + bn_mul_recursive(r,a,b,n,p); + bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p); + } - rp[al]=bn_mul_words(rp,ap,al,*(bp++)); - rp++; - for (i=1; id[max-1] == 0) r->top--; - return(1); - } -#if 0 -#include "stack.h" + /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + * c1 holds the carry bits + */ + c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2)); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; -int limit=16; + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < (BN_ULONG)c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } -typedef struct bn_pool_st +/* n+tn is the word length + * t needs to be n*4 is size, as does r */ +void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn, + int n, BN_ULONG *t) { - int used; - int tos; - STACK *sk; - } BN_POOL; + int i,j,n2=n*2; + unsigned int c1; + BN_ULONG ln,lo,*p; -BIGNUM *BN_POOL_push(bp) -BN_POOL *bp; - { - BIGNUM *ret; +#ifdef BN_COUNT +printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n); +#endif + if (n < 8) + { + i=tn+n; + bn_mul_normal(r,a,i,b,i); + return; + } + + /* r=(a[0]-a[1])*(b[1]-b[0]) */ + bn_sub_words(t, a, &(a[n]),n); /* + */ + bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ - if (bp->used >= bp->tos) +/* if (n == 4) + { + bn_mul_comba4(&(t[n2]),t,&(t[n])); + bn_mul_comba4(r,a,b); + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); + } + else */ if (n == 8) { - ret=BN_new(); - sk_push(bp->sk,(char *)ret); - bp->tos++; - bp->used++; + bn_mul_comba8(&(t[n2]),t,&(t[n])); + bn_mul_comba8(r,a,b); + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); } else { - ret=(BIGNUM *)sk_value(bp->sk,bp->used); - bp->used++; + p= &(t[n2*2]); + bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); + bn_mul_recursive(r,a,b,n,p); + i=n/2; + /* If there is only a bottom half to the number, + * just do it */ + j=tn-i; + if (j == 0) + { + bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p); + memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2)); + } + else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */ + { + bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]), + j,i,p); + memset(&(r[n2+tn*2]),0, + sizeof(BN_ULONG)*(n2-tn*2)); + } + else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */ + { + memset(&(r[n2]),0,sizeof(BN_ULONG)*n2); + if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL) + { + bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); + } + else + { + for (;;) + { + i/=2; + if (i < tn) + { + bn_mul_part_recursive(&(r[n2]), + &(a[n]),&(b[n]), + tn-i,i,p); + break; + } + else if (i == tn) + { + bn_mul_recursive(&(r[n2]), + &(a[n]),&(b[n]), + i,p); + break; + } + } + } + } + } + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=(int)(bn_add_words(t,r,&(r[n2]),n2)); + c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2)); + + /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1]) + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + * c1 holds the carry bits + */ + c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2)); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } } - return(ret); } -void BN_POOL_pop(bp,num) -BN_POOL *bp; -int num; +/* a and b must be the same size, which is n2. + * r needs to be n2 words and t needs to be n2*2 + */ +void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, + BN_ULONG *t) { - bp->used-=num; + int n=n2/2; + +#ifdef BN_COUNT +printf(" bn_mul_low_recursive %d * %d\n",n2,n2); +#endif + + bn_mul_recursive(r,a,b,n,&(t[0])); + if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) + { + bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2])); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2])); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + } + else + { + bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n); + bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n); + bn_add_words(&(r[n]),&(r[n]),&(t[0]),n); + bn_add_words(&(r[n]),&(r[n]),&(t[n]),n); + } } -int BN_mul(r,a,b) -BIGNUM *r,*a,*b; +/* a and b must be the same size, which is n2. + * r needs to be n2 words and t needs to be n2*2 + * l is the low words of the output. + * t needs to be n2*3 + */ +void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2, + BN_ULONG *t) { - static BN_POOL bp; - static init=1; + int i,n; + int c1,c2; + int neg,oneg,zero; + BN_ULONG ll,lc,*lp,*mp; + +#ifdef BN_COUNT +printf(" bn_mul_high %d * %d\n",n2,n2); +#endif + n=n2/2; + + /* Calculate (al-ah)*(bh-bl) */ + neg=zero=0; + c1=bn_cmp_words(&(a[0]),&(a[n]),n); + c2=bn_cmp_words(&(b[n]),&(b[0]),n); + switch (c1*3+c2) + { + case -4: + bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); + bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); + break; + case -3: + zero=1; + break; + case -2: + bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n); + bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); + neg=1; + break; + case -1: + case 0: + case 1: + zero=1; + break; + case 2: + bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); + bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n); + neg=1; + break; + case 3: + zero=1; + break; + case 4: + bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n); + bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n); + break; + } + + oneg=neg; + /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */ + /* r[10] = (a[1]*b[1]) */ +#ifdef BN_MUL_COMBA + if (n == 8) + { + bn_mul_comba8(&(t[0]),&(r[0]),&(r[n])); + bn_mul_comba8(r,&(a[n]),&(b[n])); + } + else +#endif + { + bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2])); + bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2])); + } + + /* s0 == low(al*bl) + * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl) + * We know s0 and s1 so the only unknown is high(al*bl) + * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl)) + * high(al*bl) == s1 - (r[0]+l[0]+t[0]) + */ + if (l != NULL) + { + lp= &(t[n2+n]); + c1=(int)(bn_add_words(lp,&(r[0]),&(l[0]),n)); + } + else + { + c1=0; + lp= &(r[0]); + } + + if (neg) + neg=(int)(bn_sub_words(&(t[n2]),lp,&(t[0]),n)); + else + { + bn_add_words(&(t[n2]),lp,&(t[0]),n); + neg=0; + } + + if (l != NULL) + { + bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n); + } + else + { + lp= &(t[n2+n]); + mp= &(t[n2]); + for (i=0; i 0) + { + lc=c1; + do { + ll=(r[i]+lc)&BN_MASK2; + r[i++]=ll; + lc=(lc > ll); + } while (lc); + } + else + { + lc= -c1; + do { + ll=r[i]; + r[i++]=(ll-lc)&BN_MASK2; + lc=(lc > ll); + } while (lc); + } + } + if (c2 != 0) /* Add starting at r[1] */ + { + i=n; + if (c2 > 0) + { + lc=c2; + do { + ll=(r[i]+lc)&BN_MASK2; + r[i++]=ll; + lc=(lc > ll); + } while (lc); + } + else + { + lc= -c2; + do { + ll=r[i]; + r[i++]=(ll-lc)&BN_MASK2; + lc=(lc > ll); + } while (lc); + } } - return(BN_mm(r,a,b,&bp)); } +#endif -/* r must be different to a and b */ -int BN_mm(m, A, B, bp) -BIGNUM *m,*A,*B; -BN_POOL *bp; +int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) { - int i,num; - int an,bn; - BIGNUM *a,*b,*c,*d,*ac,*bd; + int top,al,bl; + BIGNUM *rr; +#ifdef BN_RECURSION + BIGNUM *t; + int i,j,k; +#endif + +#ifdef BN_COUNT +printf("BN_mul %d * %d\n",a->top,b->top); +#endif + + bn_check_top(a); + bn_check_top(b); + bn_check_top(r); + + al=a->top; + bl=b->top; + r->neg=a->neg^b->neg; + + if ((al == 0) || (bl == 0)) + { + BN_zero(r); + return(1); + } + top=al+bl; - an=A->top; - bn=B->top; - if ((an <= limit) || (bn <= limit)) + if ((r == a) || (r == b)) + rr= &(ctx->bn[ctx->tos+1]); + else + rr=r; + +#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) + if (al == bl) { - return(BN_mmul(m,A,B)); +# ifdef BN_MUL_COMBA +/* if (al == 4) + { + if (bn_wexpand(rr,8) == NULL) return(0); + rr->top=8; + bn_mul_comba4(rr->d,a->d,b->d); + goto end; + } + else */ if (al == 8) + { + if (bn_wexpand(rr,16) == NULL) return(0); + rr->top=16; + bn_mul_comba8(rr->d,a->d,b->d); + goto end; + } + else +# endif +#ifdef BN_RECURSION + if (al < BN_MULL_SIZE_NORMAL) +#endif + { + if (bn_wexpand(rr,top) == NULL) return(0); + rr->top=top; + bn_mul_normal(rr->d,a->d,al,b->d,bl); + goto end; + } +# ifdef BN_RECURSION + goto symetric; +# endif } +#endif +#ifdef BN_RECURSION + else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL)) + { + if (bn_wexpand(rr,top) == NULL) return(0); + rr->top=top; + bn_mul_normal(rr->d,a->d,al,b->d,bl); + goto end; + } + else + { + i=(al-bl); + if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA)) + { + bn_wexpand(b,al); + b->d[bl]=0; + bl++; + goto symetric; + } + else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) + { + bn_wexpand(a,bl); + a->d[al]=0; + al++; + goto symetric; + } + } +#endif - a=BN_POOL_push(bp); - b=BN_POOL_push(bp); - c=BN_POOL_push(bp); - d=BN_POOL_push(bp); - ac=BN_POOL_push(bp); - bd=BN_POOL_push(bp); + /* asymetric and >= 4 */ + if (bn_wexpand(rr,top) == NULL) return(0); + rr->top=top; + bn_mul_normal(rr->d,a->d,al,b->d,bl); - num=(an <= bn)?an:bn; - num=1<<(BN_num_bits_word(num-1)-1); +#ifdef BN_RECURSION + if (0) + { +symetric: + /* symetric and > 4 */ + /* 16 or larger */ + j=BN_num_bits_word((BN_ULONG)al); + j=1<<(j-1); + k=j+j; + t= &(ctx->bn[ctx->tos]); + if (al == j) /* exact multiple */ + { + bn_wexpand(t,k*2); + bn_wexpand(rr,k*2); + bn_mul_recursive(rr->d,a->d,b->d,al,t->d); + } + else + { + bn_wexpand(a,k); + bn_wexpand(b,k); + bn_wexpand(t,k*4); + bn_wexpand(rr,k*4); + for (i=a->top; id[i]=0; + for (i=b->top; id[i]=0; + bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); + } + rr->top=top; + } +#endif +#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) +end: +#endif + bn_fix_top(rr); + if (r != rr) BN_copy(r,rr); + return(1); + } - /* Are going to now chop things into 'num' word chunks. */ - num*=BN_BITS2; +void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) + { + BN_ULONG *rr; - BN_copy(a,A); - BN_mask_bits(a,num); - BN_rshift(b,A,num); +#ifdef BN_COUNT +printf(" bn_mul_normal %d * %d\n",na,nb); +#endif - BN_copy(c,B); - BN_mask_bits(c,num); - BN_rshift(d,B,num); + if (na < nb) + { + int itmp; + BN_ULONG *ltmp; - BN_sub(ac ,b,a); - BN_sub(bd,c,d); - BN_mm(m,ac,bd,bp); - BN_mm(ac,a,c,bp); - BN_mm(bd,b,d,bp); + itmp=na; na=nb; nb=itmp; + ltmp=a; a=b; b=ltmp; - BN_add(m,m,ac); - BN_add(m,m,bd); - BN_lshift(m,m,num); - BN_lshift(bd,bd,num*2); + } + rr= &(r[na]); + rr[0]=bn_mul_words(r,a,na,b[0]); - BN_add(m,m,ac); - BN_add(m,m,bd); - BN_POOL_pop(bp,6); - return(1); + for (;;) + { + if (--nb <= 0) return; + rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]); + if (--nb <= 0) return; + rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]); + if (--nb <= 0) return; + rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]); + if (--nb <= 0) return; + rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]); + rr+=4; + r+=4; + b+=4; + } } + +void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) + { +#ifdef BN_COUNT +printf(" bn_mul_low_normal %d * %d\n",n,n); #endif + bn_mul_words(r,a,n,b[0]); + + for (;;) + { + if (--n <= 0) return; + bn_mul_add_words(&(r[1]),a,n,b[1]); + if (--n <= 0) return; + bn_mul_add_words(&(r[2]),a,n,b[2]); + if (--n <= 0) return; + bn_mul_add_words(&(r[3]),a,n,b[3]); + if (--n <= 0) return; + bn_mul_add_words(&(r[4]),a,n,b[4]); + r+=4; + b+=4; + } + } + diff --git a/src/lib/libcrypto/bn/bn_mulw.c b/src/lib/libcrypto/bn/bn_mulw.c deleted file mode 100644 index abfc7e4d6c..0000000000 --- a/src/lib/libcrypto/bn/bn_mulw.c +++ /dev/null @@ -1,366 +0,0 @@ -/* crypto/bn/bn_mulw.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "cryptlib.h" -#include "bn_lcl.h" - -#ifdef BN_LLONG - -BN_ULONG bn_mul_add_words(rp,ap,num,w) -BN_ULONG *rp,*ap; -int num; -BN_ULONG w; - { - BN_ULONG c1=0; - - for (;;) - { - mul_add(rp[0],ap[0],w,c1); - if (--num == 0) break; - mul_add(rp[1],ap[1],w,c1); - if (--num == 0) break; - mul_add(rp[2],ap[2],w,c1); - if (--num == 0) break; - mul_add(rp[3],ap[3],w,c1); - if (--num == 0) break; - ap+=4; - rp+=4; - } - - return(c1); - } - -BN_ULONG bn_mul_words(rp,ap,num,w) -BN_ULONG *rp,*ap; -int num; -BN_ULONG w; - { - BN_ULONG c1=0; - - for (;;) - { - mul(rp[0],ap[0],w,c1); - if (--num == 0) break; - mul(rp[1],ap[1],w,c1); - if (--num == 0) break; - mul(rp[2],ap[2],w,c1); - if (--num == 0) break; - mul(rp[3],ap[3],w,c1); - if (--num == 0) break; - ap+=4; - rp+=4; - } - return(c1); - } - -void bn_sqr_words(r,a,n) -BN_ULONG *r,*a; -int n; - { - for (;;) - { - BN_ULLONG t; - - t=(BN_ULLONG)(a[0])*(a[0]); - r[0]=Lw(t); r[1]=Hw(t); - if (--n == 0) break; - - t=(BN_ULLONG)(a[1])*(a[1]); - r[2]=Lw(t); r[3]=Hw(t); - if (--n == 0) break; - - t=(BN_ULLONG)(a[2])*(a[2]); - r[4]=Lw(t); r[5]=Hw(t); - if (--n == 0) break; - - t=(BN_ULLONG)(a[3])*(a[3]); - r[6]=Lw(t); r[7]=Hw(t); - if (--n == 0) break; - - a+=4; - r+=8; - } - } - -BN_ULONG bn_add_words(r,a,b,n) -BN_ULONG *r,*a,*b; -int n; - { - BN_ULLONG ll; - - ll=0; - for (;;) - { - ll+= (BN_ULLONG)a[0]+b[0]; - r[0]=(BN_ULONG)ll&BN_MASK2; - ll>>=BN_BITS2; - if (--n <= 0) break; - - ll+= (BN_ULLONG)a[1]+b[1]; - r[1]=(BN_ULONG)ll&BN_MASK2; - ll>>=BN_BITS2; - if (--n <= 0) break; - - ll+= (BN_ULLONG)a[2]+b[2]; - r[2]=(BN_ULONG)ll&BN_MASK2; - ll>>=BN_BITS2; - if (--n <= 0) break; - - ll+= (BN_ULLONG)a[3]+b[3]; - r[3]=(BN_ULONG)ll&BN_MASK2; - ll>>=BN_BITS2; - if (--n <= 0) break; - - a+=4; - b+=4; - r+=4; - } - return(ll&BN_MASK2); - } - -#else - -BN_ULONG bn_mul_add_words(rp,ap,num,w) -BN_ULONG *rp,*ap; -int num; -BN_ULONG w; - { - BN_ULONG c=0; - BN_ULONG bl,bh; - - bl=LBITS(w); - bh=HBITS(w); - - for (;;) - { - mul_add(rp[0],ap[0],bl,bh,c); - if (--num == 0) break; - mul_add(rp[1],ap[1],bl,bh,c); - if (--num == 0) break; - mul_add(rp[2],ap[2],bl,bh,c); - if (--num == 0) break; - mul_add(rp[3],ap[3],bl,bh,c); - if (--num == 0) break; - ap+=4; - rp+=4; - } - return(c); - } - -BN_ULONG bn_mul_words(rp,ap,num,w) -BN_ULONG *rp,*ap; -int num; -BN_ULONG w; - { - BN_ULONG carry=0; - BN_ULONG bl,bh; - - bl=LBITS(w); - bh=HBITS(w); - - for (;;) - { - mul(rp[0],ap[0],bl,bh,carry); - if (--num == 0) break; - mul(rp[1],ap[1],bl,bh,carry); - if (--num == 0) break; - mul(rp[2],ap[2],bl,bh,carry); - if (--num == 0) break; - mul(rp[3],ap[3],bl,bh,carry); - if (--num == 0) break; - ap+=4; - rp+=4; - } - return(carry); - } - -void bn_sqr_words(r,a,n) -BN_ULONG *r,*a; -int n; - { - for (;;) - { - sqr64(r[0],r[1],a[0]); - if (--n == 0) break; - - sqr64(r[2],r[3],a[1]); - if (--n == 0) break; - - sqr64(r[4],r[5],a[2]); - if (--n == 0) break; - - sqr64(r[6],r[7],a[3]); - if (--n == 0) break; - - a+=4; - r+=8; - } - } - -BN_ULONG bn_add_words(r,a,b,n) -BN_ULONG *r,*a,*b; -int n; - { - BN_ULONG t1,t2; - int carry,i; - - carry=0; - for (i=0; i= ((~t1)&BN_MASK2)); - t2=(t1+t2+1)&BN_MASK2; - } - else - { - t2=(t1+t2)&BN_MASK2; - carry=(t2 (BN_ULONG)1<= d) h-=d; - - if (i) - { - d<<=i; - h=(h<>(BN_BITS2-i)); - l<<=i; - } - dh=(d&BN_MASK2h)>>BN_BITS4; - dl=(d&BN_MASK2l); - for (;;) - { - if ((h>>BN_BITS4) == dh) - q=BN_MASK2l; - else - q=h/dh; - - for (;;) - { - t=(h-q*dh); - if ((t&BN_MASK2h) || - ((dl*q) <= ( - (t<>BN_BITS4)))) - break; - q--; - } - th=q*dh; - tl=q*dl; - t=(tl>>BN_BITS4); - tl=(tl<>BN_BITS4))&BN_MASK2; - l=(l&BN_MASK2l)< +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_SIZE 512 +#define DEFAULT_TIME 3 + +int verbose=1; + +typedef struct parms_st + { + char *name; + void (*func)(); + BIGNUM r; + BIGNUM a; + BIGNUM b; + BIGNUM c; + BIGNUM low; + BN_CTX *ctx; + BN_MONT_CTX *mont; + int w; + } PARMS; + +void do_mul_exp(int num,PARMS *p); +void do_mul(int num,PARMS *p); +void do_sqr(int num,PARMS *p); +void do_mul_low(int num,PARMS *p); +void do_mul_high(int num,PARMS *p); +void do_from_montgomery(int num,PARMS *p); +int time_it(int sec, PARMS *p); +void do_it(int sec, PARMS *p); + +#define P_EXP 1 +#define P_MUL 2 +#define P_SQR 3 +#define P_MULL 4 +#define P_MULH 5 +#define P_MRED 6 + +int main(int argc, char **argv) + { + PARMS p; + BN_MONT_CTX *mont; + int size=0,num; + char *name; + int type=P_EXP; + + mont=BN_MONT_CTX_new(); + p.mont=NULL; + p.ctx=BN_CTX_new(); + BN_init(&p.r); + BN_init(&p.a); + BN_init(&p.b); + BN_init(&p.c); + BN_init(&p.low); + p.w=0; + + for (;;) + { + if (argc > 1) + { + if (argv[1][0] == '-') + { + switch(argv[1][1]) + { + case 'e': type=P_EXP; break; + case 'm': type=P_MUL; break; + case 's': type=P_SQR; break; + case 'l': type=P_MULL; break; + case 'h': type=P_MULH; break; + case 'r': type=P_MRED; break; + default: + fprintf(stderr,"options: -[emslhr]\n"); + exit(1); + } + } + else + { + size=atoi(argv[1]); + } + argc--; + argv++; + } + else + break; + } + if (size == 0) + size=DEFAULT_SIZE; + + printf("bit size:%5d\n",size); + + BN_rand(&p.a,size,1,0); + BN_rand(&p.b,size,1,0); + BN_rand(&p.c,size,1,1); + BN_mod(&p.a,&p.a,&p.c,p.ctx); + BN_mod(&p.b,&p.b,&p.c,p.ctx); + p.w=(p.a.top+1)/2; + + BN_mul(&p.low,&p.a,&p.b,p.ctx); + p.low.top=p.a.top; + + switch(type) + { + case P_EXP: + p.name="r=a^b%c"; + p.func=do_mul_exp; + p.mont=mont; + break; + case P_MUL: + p.name="r=a*b"; + p.func=do_mul; + break; + case P_SQR: + p.name="r=a*a"; + p.func=do_sqr; + break; + case P_MULL: + p.name="r=low(a*b)"; + p.func=do_mul_low; + break; + case P_MULH: + p.name="r=high(a*b)"; + p.func=do_mul_high; + break; + case P_MRED: + p.name="r=montgomery_reduction(a)"; + p.func=do_from_montgomery; + p.mont=mont; + break; + default: + fprintf(stderr,"options: -[emslhr]\n"); + exit(1); + } + + num=time_it(DEFAULT_TIME,&p); + do_it(num,&p); + } + +void do_it(int num, PARMS *p) + { + char *start,*end; + int i,j,number; + double d; + + start=ms_time_new(); + end=ms_time_new(); + + number=BN_num_bits_word((BN_ULONG)BN_num_bits(&(p->c)))- + BN_num_bits_word(BN_BITS2)+2; + for (i=number-1; i >=0; i--) + { + if (i == 1) continue; + BN_set_params(i,i,i,1); + if (p->mont != NULL) + BN_MONT_CTX_set(p->mont,&(p->c),p->ctx); + + printf("Timing %5d (%2d bit) %2d %2d %2d %2d :", + (1<func(num,p); + ms_time_get(end); + d=ms_time_diff(start,end); + printf("%6.6f sec, or %d in %.4f seconds\n", + (double)d/num,num,d); + } + } + +int time_it(int sec, PARMS *p) + { + char *start,*end; + int i,j; + double d; + + if (p->mont != NULL) + BN_MONT_CTX_set(p->mont,&(p->c),p->ctx); + + start=ms_time_new(); + end=ms_time_new(); + + i=1; + for (;;) + { + if (verbose) + printf("timing %s for %d interations\n",p->name,i); + + ms_time_get(start); + p->func(i,p); + ms_time_get(end); + d=ms_time_diff(start,end); + + if (d < 0.01) i*=100; + else if (d < 0.1 ) i*=10; + else if (d > (double)sec) break; + else + { + i=(int)(1.0*i*sec/d); + break; + } + } + if (verbose) + printf("using %d interations\n",i); + return(i); + } + +void do_mul_exp(int num, PARMS *p) + { + int i; + + for (i=0; ir),&(p->a),&(p->b),&(p->c), + p->ctx,p->mont); + } + +void do_mul(int num, PARMS *p) + { + int i; + + for (i=0; ir),&(p->a),&(p->b),p->ctx); + } + +void do_sqr(int num, PARMS *p) + { + int i; + + for (i=0; ir),&(p->a),p->ctx); + } + +void do_mul_low(int num, PARMS *p) + { + int i; + + for (i=0; ir),&(p->a),&(p->b),p->w,p->ctx); + } + +void do_mul_high(int num, PARMS *p) + { + int i; + + for (i=0; ir),&(p->a),&(p->b),&(p->low),p->w,p->ctx); + } + +void do_from_montgomery(int num, PARMS *p) + { + int i; + + for (i=0; ir),&(p->a),p->mont,p->ctx); + } + diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c index 0c85f70b59..6fa0f9be1e 100644 --- a/src/lib/libcrypto/bn/bn_prime.c +++ b/src/lib/libcrypto/bn/bn_prime.c @@ -60,7 +60,7 @@ #include #include "cryptlib.h" #include "bn_lcl.h" -#include "rand.h" +#include /* The quick seive algorithm approach to weeding out primes is * Philip Zimmermann's, as implemented in PGP. I have had a read of @@ -68,7 +68,6 @@ */ #include "bn_prime.h" -#ifndef NOPROTO static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx,BN_CTX *ctx2, BN_MONT_CTX *mont); static int probable_prime(BIGNUM *rnd, int bits); @@ -76,32 +75,23 @@ static int probable_prime_dh(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); static int probable_prime_dh_strong(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); -#else -static int witness(); -static int probable_prime(); -static int probable_prime_dh(); -static int probable_prime_dh_strong(); -#endif - -BIGNUM *BN_generate_prime(bits,strong,add,rem,callback,cb_arg) -int bits; -int strong; -BIGNUM *add; -BIGNUM *rem; -void (*callback)(P_I_I_P); -char *cb_arg; +BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int strong, BIGNUM *add, + BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg) { BIGNUM *rnd=NULL; - BIGNUM *ret=NULL; - BIGNUM *t=NULL; + BIGNUM t; int i,j,c1=0; BN_CTX *ctx; ctx=BN_CTX_new(); if (ctx == NULL) goto err; - if ((rnd=BN_new()) == NULL) goto err; - if (strong) - if ((t=BN_new()) == NULL) goto err; + if (ret == NULL) + { + if ((rnd=BN_new()) == NULL) goto err; + } + else + rnd=ret; + BN_init(&t); loop: /* make a random number and set the top and bottom bits */ if (add == NULL) @@ -136,7 +126,7 @@ loop: * check that (p-1)/2 is prime. * Since a prime is odd, We just * need to divide by 2 */ - if (!BN_rshift1(t,rnd)) goto err; + if (!BN_rshift1(&t,rnd)) goto err; for (i=0; ibn[ctx->tos++]; + check= &(ctx->bn[ctx->tos++]); /* Setup the montgomery structure */ if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err; @@ -214,24 +200,21 @@ err: #define RECP_MUL_MOD -static int witness(a,n,ctx,ctx2,mont) -BIGNUM *a; -BIGNUM *n; -BN_CTX *ctx,*ctx2; -BN_MONT_CTX *mont; +static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2, + BN_MONT_CTX *mont) { int k,i,ret= -1,good; BIGNUM *d,*dd,*tmp,*d1,*d2,*n1; BIGNUM *mont_one,*mont_n1,*mont_a; - d1=ctx->bn[ctx->tos]; - d2=ctx->bn[ctx->tos+1]; - n1=ctx->bn[ctx->tos+2]; + d1= &(ctx->bn[ctx->tos]); + d2= &(ctx->bn[ctx->tos+1]); + n1= &(ctx->bn[ctx->tos+2]); ctx->tos+=3; - mont_one=ctx2->bn[ctx2->tos]; - mont_n1=ctx2->bn[ctx2->tos+1]; - mont_a=ctx2->bn[ctx2->tos+2]; + mont_one= &(ctx2->bn[ctx2->tos]); + mont_n1= &(ctx2->bn[ctx2->tos+1]); + mont_a= &(ctx2->bn[ctx2->tos+2]); ctx2->tos+=3; d=d1; @@ -254,7 +237,7 @@ BN_MONT_CTX *mont; good=0; BN_mod_mul_montgomery(dd,d,d,mont,ctx2); - + if (good && (BN_cmp(dd,mont_one) == 0)) { ret=1; @@ -281,14 +264,13 @@ err: return(ret); } -static int probable_prime(rnd, bits) -BIGNUM *rnd; -int bits; +static int probable_prime(BIGNUM *rnd, int bits) { int i; MS_STATIC BN_ULONG mods[NUMPRIMES]; - BN_ULONG delta; + BN_ULONG delta,d; +again: if (!BN_rand(rnd,bits,1,1)) return(0); /* we now have a random number 'rand' to test. */ for (i=1; ibn[ctx->tos++]; + t1= &(ctx->bn[ctx->tos++]); if (!BN_rand(rnd,bits,0,1)) goto err; @@ -338,7 +319,7 @@ BN_CTX *ctx; loop: for (i=1; ibn[ctx->tos++]; - q=ctx->bn[ctx->tos++]; - qadd=ctx->bn[ctx->tos++]; + t1= &(ctx->bn[ctx->tos++]); + q= &(ctx->bn[ctx->tos++]); + qadd= &(ctx->bn[ctx->tos++]); if (!BN_rshift1(qadd,padd)) goto err; @@ -389,8 +366,8 @@ BN_CTX *ctx; /* check that p and q are prime */ /* check that for p and q * gcd(p-1,primes) == 1 (except for 2) */ - if ( (BN_mod_word(p,(BN_LONG)primes[i]) == 0) || - (BN_mod_word(q,(BN_LONG)primes[i]) == 0)) + if ( (BN_mod_word(p,(BN_ULONG)primes[i]) == 0) || + (BN_mod_word(q,(BN_ULONG)primes[i]) == 0)) { if (!BN_add(p,p,padd)) goto err; if (!BN_add(q,q,qadd)) goto err; @@ -404,20 +381,17 @@ err: } #if 0 -static int witness(a, n,ctx) -BIGNUM *a; -BIGNUM *n; -BN_CTX *ctx; +static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx) { int k,i,nb,ret= -1; BIGNUM *d,*dd,*tmp; BIGNUM *d1,*d2,*x,*n1,*inv; - d1=ctx->bn[ctx->tos]; - d2=ctx->bn[ctx->tos+1]; - x=ctx->bn[ctx->tos+2]; - n1=ctx->bn[ctx->tos+3]; - inv=ctx->bn[ctx->tos+4]; + d1= &(ctx->bn[ctx->tos]); + d2= &(ctx->bn[ctx->tos+1]); + x= &(ctx->bn[ctx->tos+2]); + n1= &(ctx->bn[ctx->tos+3]); + inv=&(ctx->bn[ctx->tos+4]); ctx->tos+=5; d=d1; diff --git a/src/lib/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl index 1b00c21a77..979385a334 100644 --- a/src/lib/libcrypto/bn/bn_prime.pl +++ b/src/lib/libcrypto/bn/bn_prime.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # bn_prime.pl $num=2048; diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c index 2bcc11c852..2f5ab2617b 100644 --- a/src/lib/libcrypto/bn/bn_print.c +++ b/src/lib/libcrypto/bn/bn_print.c @@ -59,14 +59,13 @@ #include #include #include "cryptlib.h" -#include "buffer.h" +#include #include "bn_lcl.h" -static char *Hex="0123456789ABCDEF"; +static const char *Hex="0123456789ABCDEF"; /* Must 'Free' the returned data */ -char *BN_bn2hex(a) -BIGNUM *a; +char *BN_bn2hex(const BIGNUM *a) { int i,j,v,z=0; char *buf; @@ -101,8 +100,7 @@ err: } /* Must 'Free' the returned data */ -char *BN_bn2dec(a) -BIGNUM *a; +char *BN_bn2dec(const BIGNUM *a) { int i=0,num; char *buf=NULL; @@ -156,9 +154,7 @@ err: return(buf); } -int BN_hex2bn(bn,a) -BIGNUM **bn; -char *a; +int BN_hex2bn(BIGNUM **bn, const char *a) { BIGNUM *ret=NULL; BN_ULONG l=0; @@ -169,7 +165,7 @@ char *a; if (*a == '-') { neg=1; a++; } - for (i=0; isxdigit(a[i]); i++) + for (i=0; isxdigit((unsigned char) a[i]); i++) ; num=i+neg; @@ -224,9 +220,7 @@ err: return(0); } -int BN_dec2bn(bn,a) -BIGNUM **bn; -char *a; +int BN_dec2bn(BIGNUM **bn, const char *a) { BIGNUM *ret=NULL; BN_ULONG l=0; @@ -236,7 +230,7 @@ char *a; if ((a == NULL) || (*a == '\0')) return(0); if (*a == '-') { neg=1; a++; } - for (i=0; isdigit(a[i]); i++) + for (i=0; isdigit((unsigned char) a[i]); i++) ; num=i+neg; @@ -286,9 +280,7 @@ err: #ifndef NO_BIO #ifndef NO_FP_API -int BN_print_fp(fp, a) -FILE *fp; -BIGNUM *a; +int BN_print_fp(FILE *fp, BIGNUM *a) { BIO *b; int ret; @@ -302,9 +294,7 @@ BIGNUM *a; } #endif -int BN_print(bp, a) -BIO *bp; -BIGNUM *a; +int BN_print(BIO *bp, const BIGNUM *a) { int i,j,v,z=0; int ret=0; diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c index 75b6b0493b..91b8e34ae6 100644 --- a/src/lib/libcrypto/bn/bn_rand.c +++ b/src/lib/libcrypto/bn/bn_rand.c @@ -60,13 +60,9 @@ #include #include "cryptlib.h" #include "bn_lcl.h" -#include "rand.h" +#include -int BN_rand(rnd, bits, top, bottom) -BIGNUM *rnd; -int bits; -int top; -int bottom; +int BN_rand(BIGNUM *rnd, int bits, int top, int bottom) { unsigned char *buf=NULL; int ret=0,bit,bytes,mask; @@ -85,7 +81,7 @@ int bottom; /* make a random number and set the top and bottom bits */ time(&tim); - RAND_seed((unsigned char *)&tim,sizeof(tim)); + RAND_seed(&tim,sizeof(tim)); RAND_bytes(buf,(int)bytes); if (top) diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c index 72cd69d3fc..c1b0e230ea 100644 --- a/src/lib/libcrypto/bn/bn_recp.c +++ b/src/lib/libcrypto/bn/bn_recp.c @@ -60,66 +60,168 @@ #include "cryptlib.h" #include "bn_lcl.h" -int BN_mod_mul_reciprocal(r, x, y, m, i, nb, ctx) -BIGNUM *r; -BIGNUM *x; -BIGNUM *y; -BIGNUM *m; -BIGNUM *i; -int nb; -BN_CTX *ctx; +void BN_RECP_CTX_init(BN_RECP_CTX *recp) { - int ret=0,j; - BIGNUM *a,*b,*c,*d; + BN_init(&(recp->N)); + BN_init(&(recp->Nr)); + recp->num_bits=0; + recp->flags=0; + } + +BN_RECP_CTX *BN_RECP_CTX_new(void) + { + BN_RECP_CTX *ret; + + if ((ret=(BN_RECP_CTX *)Malloc(sizeof(BN_RECP_CTX))) == NULL) + return(NULL); + + BN_RECP_CTX_init(ret); + ret->flags=BN_FLG_MALLOCED; + return(ret); + } + +void BN_RECP_CTX_free(BN_RECP_CTX *recp) + { + if(recp == NULL) + return; - a=ctx->bn[ctx->tos++]; - b=ctx->bn[ctx->tos++]; - c=ctx->bn[ctx->tos++]; - d=ctx->bn[ctx->tos++]; + BN_free(&(recp->N)); + BN_free(&(recp->Nr)); + if (recp->flags & BN_FLG_MALLOCED) + Free(recp); + } - if (x == y) - { if (!BN_sqr(a,x,ctx)) goto err; } +int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) + { + BN_copy(&(recp->N),d); + BN_zero(&(recp->Nr)); + recp->num_bits=BN_num_bits(d); + recp->shift=0; + return(1); + } + +int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp, + BN_CTX *ctx) + { + int ret=0; + BIGNUM *a; + + a= &(ctx->bn[ctx->tos++]); + if (y != NULL) + { + if (x == y) + { if (!BN_sqr(a,x,ctx)) goto err; } + else + { if (!BN_mul(a,x,y,ctx)) goto err; } + } else - { if (!BN_mul(a,x,y)) goto err; } - if (!BN_rshift(d,a,nb)) goto err; - if (!BN_mul(b,d,i)) goto err; - if (!BN_rshift(c,b,nb)) goto err; - if (!BN_mul(b,m,c)) goto err; - if (!BN_sub(r,a,b)) goto err; + a=x; /* Just do the mod */ + + BN_div_recp(NULL,r,a,recp,ctx); + ret=1; +err: + ctx->tos--; + return(ret); + } + +int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp, + BN_CTX *ctx) + { + int i,j,tos,ret=0,ex; + BIGNUM *a,*b,*d,*r; + + tos=ctx->tos; + a= &(ctx->bn[ctx->tos++]); + b= &(ctx->bn[ctx->tos++]); + if (dv != NULL) + d=dv; + else + d= &(ctx->bn[ctx->tos++]); + if (rem != NULL) + r=rem; + else + r= &(ctx->bn[ctx->tos++]); + + if (BN_ucmp(m,&(recp->N)) < 0) + { + BN_zero(d); + BN_copy(r,m); + ctx->tos=tos; + return(1); + } + + /* We want the remainder + * Given input of ABCDEF / ab + * we need multiply ABCDEF by 3 digests of the reciprocal of ab + * + */ + i=BN_num_bits(m); + + j=recp->num_bits*2; + if (j > i) + { + i=j; + ex=0; + } + else + { + ex=(i-j)/2; + } + + j=i/2; + + if (i != recp->shift) + recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N), + i,ctx); + + if (!BN_rshift(a,m,j-ex)) goto err; + if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err; + if (!BN_rshift(d,b,j+ex)) goto err; + d->neg=0; + if (!BN_mul(b,&(recp->N),d,ctx)) goto err; + if (!BN_usub(r,m,b)) goto err; + r->neg=0; + j=0; - while (BN_cmp(r,m) >= 0) +#if 1 + while (BN_ucmp(r,&(recp->N)) >= 0) { if (j++ > 2) { BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL); goto err; } - if (!BN_sub(r,r,m)) goto err; + if (!BN_usub(r,r,&(recp->N))) goto err; + if (!BN_add_word(d,1)) goto err; } +#endif + r->neg=BN_is_zero(r)?0:m->neg; + d->neg=m->neg^recp->N.neg; ret=1; err: - ctx->tos-=4; + ctx->tos=tos; return(ret); - } + } -int BN_reciprocal(r, m,ctx) -BIGNUM *r; -BIGNUM *m; -BN_CTX *ctx; +/* len is the expected size of the result + * We actually calculate with an extra word of precision, so + * we can do faster division if the remainder is not required. + */ +int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx) { - int nm,ret= -1; - BIGNUM *t; + int ret= -1; + BIGNUM t; - t=ctx->bn[ctx->tos++]; + BN_init(&t); - nm=BN_num_bits(m); - if (!BN_lshift(t,BN_value_one(),nm*2)) goto err; + BN_zero(&t); + if (!BN_set_bit(&t,len)) goto err; - if (!BN_div(r,NULL,t,m,ctx)) goto err; - ret=nm; + if (!BN_div(r,NULL,&t,m,ctx)) goto err; + ret=len; err: - ctx->tos--; + BN_free(&t); return(ret); } diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c index 944bf1794b..61aae65a6b 100644 --- a/src/lib/libcrypto/bn/bn_shift.c +++ b/src/lib/libcrypto/bn/bn_shift.c @@ -60,9 +60,7 @@ #include "cryptlib.h" #include "bn_lcl.h" -int BN_lshift1(r, a) -BIGNUM *r; -BIGNUM *a; +int BN_lshift1(BIGNUM *r, BIGNUM *a) { register BN_ULONG *ap,*rp,t,c; int i; @@ -94,9 +92,7 @@ BIGNUM *a; return(1); } -int BN_rshift1(r, a) -BIGNUM *r; -BIGNUM *a; +int BN_rshift1(BIGNUM *r, BIGNUM *a) { BN_ULONG *ap,*rp,t,c; int i; @@ -125,10 +121,7 @@ BIGNUM *a; return(1); } -int BN_lshift(r, a, n) -BIGNUM *r; -BIGNUM *a; -int n; +int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i,nw,lb,rb; BN_ULONG *t,*f; @@ -160,10 +153,7 @@ int n; return(1); } -int BN_rshift(r, a, n) -BIGNUM *r; -BIGNUM *a; -int n; +int BN_rshift(BIGNUM *r, BIGNUM *a, int n) { int i,j,nw,lb,rb; BN_ULONG *t,*f; diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c index a8464610e5..12cce4d7ce 100644 --- a/src/lib/libcrypto/bn/bn_sqr.c +++ b/src/lib/libcrypto/bn/bn_sqr.c @@ -62,35 +62,98 @@ /* r must not be a */ /* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */ -int BN_sqr(r, a, ctx) -BIGNUM *r; -BIGNUM *a; -BN_CTX *ctx; +int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx) { - int i,j,max,al; - BIGNUM *tmp; - BN_ULONG *ap,*rp; + int max,al; + BIGNUM *tmp,*rr; - tmp=ctx->bn[ctx->tos]; +#ifdef BN_COUNT +printf("BN_sqr %d * %d\n",a->top,a->top); +#endif + bn_check_top(a); + tmp= &(ctx->bn[ctx->tos]); + rr=(a != r)?r: (&ctx->bn[ctx->tos+1]); al=a->top; - if (al == 0) + if (al <= 0) { r->top=0; return(1); } - max=(al*2); - if (bn_wexpand(r,1+max) == NULL) return(0); - if (bn_wexpand(tmp,1+max) == NULL) return(0); + max=(al+al); + if (bn_wexpand(rr,max+1) == NULL) return(0); r->neg=0; + if (al == 4) + { +#ifndef BN_SQR_COMBA + BN_ULONG t[8]; + bn_sqr_normal(rr->d,a->d,4,t); +#else + bn_sqr_comba4(rr->d,a->d); +#endif + } + else if (al == 8) + { +#ifndef BN_SQR_COMBA + BN_ULONG t[16]; + bn_sqr_normal(rr->d,a->d,8,t); +#else + bn_sqr_comba8(rr->d,a->d); +#endif + } + else + { +#if defined(BN_RECURSION) + if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) + { + BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2]; + bn_sqr_normal(rr->d,a->d,al,t); + } + else + { + int j,k; + + j=BN_num_bits_word((BN_ULONG)al); + j=1<<(j-1); + k=j+j; + if (al == j) + { + if (bn_wexpand(a,k*2) == NULL) return(0); + if (bn_wexpand(tmp,k*2) == NULL) return(0); + bn_sqr_recursive(rr->d,a->d,al,tmp->d); + } + else + { + if (bn_wexpand(tmp,max) == NULL) return(0); + bn_sqr_normal(rr->d,a->d,al,tmp->d); + } + } +#else + if (bn_wexpand(tmp,max) == NULL) return(0); + bn_sqr_normal(rr->d,a->d,al,tmp->d); +#endif + } + + rr->top=max; + if ((max > 0) && (rr->d[max-1] == 0)) rr->top--; + if (rr != r) BN_copy(r,rr); + return(1); + } + +/* tmp must have 2*n words */ +void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp) + { + int i,j,max; + BN_ULONG *ap,*rp; - ap=a->d; - rp=r->d; + max=n*2; + ap=a; + rp=r; rp[0]=rp[max-1]=0; rp++; - j=al; + j=n; if (--j > 0) { @@ -99,7 +162,7 @@ BN_CTX *ctx; rp+=2; } - for (i=2; i0; i--) { j--; ap++; @@ -107,16 +170,112 @@ BN_CTX *ctx; rp+=2; } - bn_add_words(r->d,r->d,r->d,max); + bn_add_words(r,r,r,max); /* There will not be a carry */ - bn_sqr_words(tmp->d,a->d,al); + bn_sqr_words(tmp,a,n); - bn_add_words(r->d,r->d,tmp->d,max); - - r->top=max; - if (r->d[max-1] == 0) r->top--; - return(1); + bn_add_words(r,r,tmp,max); } +#ifdef BN_RECURSION +/* r is 2*n words in size, + * a and b are both n words in size. + * n must be a power of 2. + * We multiply and return the result. + * t must be 2*n words in size + * We calulate + * a[0]*b[0] + * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) + * a[1]*b[1] + */ +void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *t) + { + int n=n2/2; + int zero,c1; + BN_ULONG ln,lo,*p; + +#ifdef BN_COUNT +printf(" bn_sqr_recursive %d * %d\n",n2,n2); +#endif + if (n2 == 4) + { +#ifndef BN_SQR_COMBA + bn_sqr_normal(r,a,4,t); +#else + bn_sqr_comba4(r,a); +#endif + return; + } + else if (n2 == 8) + { +#ifndef BN_SQR_COMBA + bn_sqr_normal(r,a,8,t); +#else + bn_sqr_comba8(r,a); +#endif + return; + } + if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL) + { + bn_sqr_normal(r,a,n2,t); + return; + } + /* r=(a[0]-a[1])*(a[1]-a[0]) */ + c1=bn_cmp_words(a,&(a[n]),n); + zero=0; + if (c1 > 0) + bn_sub_words(t,a,&(a[n]),n); + else if (c1 < 0) + bn_sub_words(t,&(a[n]),a,n); + else + zero=1; + + /* The result will always be negative unless it is zero */ + p= &(t[n2*2]); + + if (!zero) + bn_sqr_recursive(&(t[n2]),t,n,p); + else + memset(&(t[n2]),0,n*sizeof(BN_ULONG)); + bn_sqr_recursive(r,a,n,p); + bn_sqr_recursive(&(r[n2]),&(a[n]),n,p); + + /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero + * r[10] holds (a[0]*b[0]) + * r[32] holds (b[1]*b[1]) + */ + + c1=(int)(bn_add_words(t,r,&(r[n2]),n2)); + + /* t[32] is negative */ + c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2)); + + /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1]) + * r[10] holds (a[0]*a[0]) + * r[32] holds (a[1]*a[1]) + * c1 holds the carry bits + */ + c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2)); + if (c1) + { + p= &(r[n+n2]); + lo= *p; + ln=(lo+c1)&BN_MASK2; + *p=ln; + + /* The overflow will stop before we over write + * words we should not overwrite */ + if (ln < (BN_ULONG)c1) + { + do { + p++; + lo= *p; + ln=(lo+1)&BN_MASK2; + *p=ln; + } while (ln == 0); + } + } + } +#endif diff --git a/src/lib/libcrypto/bn/bn_sub.c b/src/lib/libcrypto/bn/bn_sub.c deleted file mode 100644 index bba80f8afb..0000000000 --- a/src/lib/libcrypto/bn/bn_sub.c +++ /dev/null @@ -1,180 +0,0 @@ -/* crypto/bn/bn_sub.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "cryptlib.h" -#include "bn_lcl.h" - -/* unsigned subtraction of b from a, a must be larger than b. */ -void bn_qsub(r, a, b) -BIGNUM *r; -BIGNUM *a; -BIGNUM *b; - { - int max,min; - register BN_ULONG t1,t2,*ap,*bp,*rp; - int i,carry; -#if defined(IRIX_CC_BUG) && !defined(LINT) - int dummy; -#endif - - max=a->top; - min=b->top; - ap=a->d; - bp=b->d; - rp=r->d; - - carry=0; - for (i=0; i t2) break; - } - } -#if 0 - memcpy(rp,ap,sizeof(*rp)*(max-i)); -#else - for (; itop=max; - bn_fix_top(r); - } - -int BN_sub(r, a, b) -BIGNUM *r; -BIGNUM *a; -BIGNUM *b; - { - int max,i; - int add=0,neg=0; - BIGNUM *tmp; - - /* a - b a-b - * a - -b a+b - * -a - b -(a+b) - * -a - -b b-a - */ - if (a->neg) - { - if (b->neg) - { tmp=a; a=b; b=tmp; } - else - { add=1; neg=1; } - } - else - { - if (b->neg) { add=1; neg=0; } - } - - if (add) - { - /* As a fast max size, do a a->top | b->top */ - i=(a->top | b->top)+1; - if (bn_wexpand(r,i) == NULL) - return(0); - if (i) - bn_qadd(r,a,b); - else - bn_qadd(r,b,a); - r->neg=neg; - return(1); - } - - /* We are actually doing a - b :-) */ - - max=(a->top > b->top)?a->top:b->top; - if (bn_wexpand(r,max) == NULL) return(0); - if (BN_ucmp(a,b) < 0) - { - bn_qsub(r,b,a); - r->neg=1; - } - else - { - bn_qsub(r,a,b); - r->neg=0; - } - return(1); - } - diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c index 4b3d0f011d..c0cfbc6797 100644 --- a/src/lib/libcrypto/bn/bn_word.c +++ b/src/lib/libcrypto/bn/bn_word.c @@ -60,9 +60,7 @@ #include "cryptlib.h" #include "bn_lcl.h" -BN_ULONG BN_mod_word(a, w) -BIGNUM *a; -unsigned long w; +BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w) { #ifndef BN_LLONG BN_ULONG ret=0; @@ -75,8 +73,8 @@ unsigned long w; for (i=a->top-1; i>=0; i--) { #ifndef BN_LLONG - ret=((ret<d[i]>>BN_BITS4)&BN_MASK2l))%(unsigned long)w; - ret=((ret<d[i]&BN_MASK2l))%(unsigned long)w; + ret=((ret<d[i]>>BN_BITS4)&BN_MASK2l))%w; + ret=((ret<d[i]&BN_MASK2l))%w; #else ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])% (BN_ULLONG)w); @@ -85,9 +83,7 @@ unsigned long w; return((BN_ULONG)ret); } -BN_ULONG BN_div_word(a, w) -BIGNUM *a; -unsigned long w; +BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w) { BN_ULONG ret; int i; @@ -100,18 +96,16 @@ unsigned long w; BN_ULONG l,d; l=a->d[i]; - d=bn_div64(ret,l,w); + d=bn_div_words(ret,l,w); ret=(l-((d*w)&BN_MASK2))&BN_MASK2; a->d[i]=d; } - if (a->d[a->top-1] == 0) + if ((a->top > 0) && (a->d[a->top-1] == 0)) a->top--; return(ret); } -int BN_add_word(a, w) -BIGNUM *a; -unsigned long w; +int BN_add_word(BIGNUM *a, BN_ULONG w) { BN_ULONG l; int i; @@ -142,9 +136,7 @@ unsigned long w; return(1); } -int BN_sub_word(a, w) -BIGNUM *a; -unsigned long w; +int BN_sub_word(BIGNUM *a, BN_ULONG w) { int i; @@ -183,9 +175,7 @@ unsigned long w; return(1); } -int BN_mul_word(a,w) -BIGNUM *a; -unsigned long w; +int BN_mul_word(BIGNUM *a, BN_ULONG w) { BN_ULONG ll; @@ -199,6 +189,6 @@ unsigned long w; a->d[a->top++]=ll; } } - return(0); + return(1); } diff --git a/src/lib/libcrypto/bn/bnspeed.c b/src/lib/libcrypto/bn/bnspeed.c index f7c2790fff..0922aa3e16 100644 --- a/src/lib/libcrypto/bn/bnspeed.c +++ b/src/lib/libcrypto/bn/bnspeed.c @@ -66,14 +66,13 @@ #include #include #include -#include "crypto.h" -#include "err.h" +#include +#include -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif -#ifndef VMS #ifndef _IRIX #include #endif @@ -81,36 +80,33 @@ #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "bn.h" -#include "x509.h" +#include +#include /* The following if from times(3) man page. It may need to be changed */ #ifndef HZ # ifndef CLK_TCK # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ -# ifndef VMS -# define HZ 100.0 -# else /* VMS */ -# define HZ 100.0 -# endif +# define HZ 100.0 # else /* _BSD_CLK_TCK_ */ # define HZ ((double)_BSD_CLK_TCK_) # endif @@ -123,17 +119,11 @@ struct tms { #define BUFSIZE ((long)1024*8) int run=0; -#ifndef NOPROTO static double Time_F(int s); -#else -static double Time_F(); -#endif - #define START 0 #define STOP 1 -static double Time_F(s) -int s; +static double Time_F(int s) { double ret; #ifdef TIMES @@ -175,27 +165,20 @@ static int sizes[NUM_SIZES]={128,256,512,1024,2048}; void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx); -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { BN_CTX *ctx; - BIGNUM *a,*b,*c,*r; + BIGNUM a,b,c; ctx=BN_CTX_new(); - a=BN_new(); - b=BN_new(); - c=BN_new(); - r=BN_new(); + BN_init(&a); + BN_init(&b); + BN_init(&c); - do_mul(a,b,c,ctx); + do_mul(&a,&b,&c,ctx); } -void do_mul(r,a,b,ctx) -BIGNUM *r; -BIGNUM *a; -BIGNUM *b; -BN_CTX *ctx; +void do_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) { int i,j,k; double tm; @@ -211,7 +194,7 @@ BN_CTX *ctx; BN_rand(b,sizes[j],1,0); Time_F(START); for (k=0; k %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num); } diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c index 9ebd68b429..df4b81f5b2 100644 --- a/src/lib/libcrypto/bn/bntest.c +++ b/src/lib/libcrypto/bn/bntest.c @@ -59,49 +59,35 @@ #include #include #include -#include "e_os.h" -#include "bio.h" -#include "bn.h" -#include "rand.h" -#include "x509.h" -#include "err.h" + +#include "openssl/e_os.h" + +#include +#include +#include +#include +#include #ifdef WINDOWS #include "../bio/bss_file.c" #endif -#ifndef NOPROTO -int test_add (BIO *bp); -int test_sub (BIO *bp); -int test_lshift1 (BIO *bp); -int test_lshift (BIO *bp); -int test_rshift1 (BIO *bp); -int test_rshift (BIO *bp); -int test_div (BIO *bp,BN_CTX *ctx); -int test_mul (BIO *bp); -int test_sqr (BIO *bp,BN_CTX *ctx); -int test_mont (BIO *bp,BN_CTX *ctx); -int test_mod (BIO *bp,BN_CTX *ctx); -int test_mod_mul (BIO *bp,BN_CTX *ctx); -int test_mod_exp (BIO *bp,BN_CTX *ctx); +int test_add(BIO *bp); +int test_sub(BIO *bp); +int test_lshift1(BIO *bp); +int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_); +int test_rshift1(BIO *bp); +int test_rshift(BIO *bp,BN_CTX *ctx); +int test_div(BIO *bp,BN_CTX *ctx); +int test_div_recp(BIO *bp,BN_CTX *ctx); +int test_mul(BIO *bp); +int test_sqr(BIO *bp,BN_CTX *ctx); +int test_mont(BIO *bp,BN_CTX *ctx); +int test_mod(BIO *bp,BN_CTX *ctx); +int test_mod_mul(BIO *bp,BN_CTX *ctx); +int test_mod_exp(BIO *bp,BN_CTX *ctx); +int test_exp(BIO *bp,BN_CTX *ctx); int rand_neg(void); -#else -int test_add (); -int test_sub (); -int test_lshift1 (); -int test_lshift (); -int test_rshift1 (); -int test_rshift (); -int test_div (); -int test_mul (); -int test_sqr (); -int test_mont (); -int test_mod (); -int test_mod_mul (); -int test_mod_exp (); -int rand_neg(); -#endif - static int results=0; #ifdef NO_STDIO @@ -109,16 +95,15 @@ static int results=0; #include "bss_file.c" #endif -int main(argc,argv) -int argc; -char *argv[]; +static unsigned char lst1[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9" +"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0"; + +int main(int argc, char *argv[]) { BN_CTX *ctx; BIO *out; char *outfile=NULL; - srand((unsigned int)time(NULL)); - argc--; argv++; while (argc >= 1) @@ -168,8 +153,13 @@ char *argv[]; if (!test_lshift1(out)) goto err; fflush(stdout); + fprintf(stderr,"test BN_lshift (fixed)\n"); + if (!test_lshift(out,ctx,BN_bin2bn(lst1,sizeof(lst1)-1,NULL))) + goto err; + fflush(stdout); + fprintf(stderr,"test BN_lshift\n"); - if (!test_lshift(out)) goto err; + if (!test_lshift(out,ctx,NULL)) goto err; fflush(stdout); fprintf(stderr,"test BN_rshift1\n"); @@ -177,7 +167,7 @@ char *argv[]; fflush(stdout); fprintf(stderr,"test BN_rshift\n"); - if (!test_rshift(out)) goto err; + if (!test_rshift(out,ctx)) goto err; fflush(stdout); fprintf(stderr,"test BN_sqr\n"); @@ -192,6 +182,10 @@ char *argv[]; if (!test_div(out,ctx)) goto err; fflush(stdout); + fprintf(stderr,"test BN_div_recp\n"); + if (!test_div_recp(out,ctx)) goto err; + fflush(stdout); + fprintf(stderr,"test BN_mod\n"); if (!test_mod(out,ctx)) goto err; fflush(stdout); @@ -209,298 +203,423 @@ char *argv[]; if (!test_mod_exp(out,ctx)) goto err; fflush(stdout); + fprintf(stderr,"test BN_exp\n"); + if (!test_exp(out,ctx)) goto err; + fflush(stdout); + /**/ exit(0); err: + BIO_puts(out,"1\n"); /* make sure bc fails if we are piping to it */ ERR_load_crypto_strings(); ERR_print_errors(out); exit(1); return(1); } -int test_add(bp) -BIO *bp; +int test_add(BIO *bp) { - BIGNUM *a,*b,*c; + BIGNUM a,b,c; int i; int j; - a=BN_new(); - b=BN_new(); - c=BN_new(); + BN_init(&a); + BN_init(&b); + BN_init(&c); - BN_rand(a,512,0,0); + BN_rand(&a,512,0,0); for (i=0; i<100; i++) { - BN_rand(b,450+i,0,0); - a->neg=rand_neg(); - b->neg=rand_neg(); + BN_rand(&b,450+i,0,0); + a.neg=rand_neg(); + b.neg=rand_neg(); if (bp == NULL) for (j=0; j<10000; j++) - BN_add(c,a,b); - BN_add(c,a,b); + BN_add(&c,&a,&b); + BN_add(&c,&a,&b); if (bp != NULL) { if (!results) { - BN_print(bp,a); + BN_print(bp,&a); BIO_puts(bp," + "); - BN_print(bp,b); + BN_print(bp,&b); BIO_puts(bp," - "); } - BN_print(bp,c); + BN_print(bp,&c); BIO_puts(bp,"\n"); } + a.neg=!a.neg; + b.neg=!b.neg; + BN_add(&c,&c,&b); + BN_add(&c,&c,&a); + if(!BN_is_zero(&c)) + { + BIO_puts(bp,"Add test failed!\n"); + return 0; + } } - BN_free(a); - BN_free(b); - BN_free(c); + BN_free(&a); + BN_free(&b); + BN_free(&c); return(1); } -int test_sub(bp) -BIO *bp; +int test_sub(BIO *bp) { - BIGNUM *a,*b,*c; + BIGNUM a,b,c; int i; int j; - a=BN_new(); - b=BN_new(); - c=BN_new(); + BN_init(&a); + BN_init(&b); + BN_init(&c); - BN_rand(a,512,0,0); + BN_rand(&a,512,0,0); for (i=0; i<100; i++) { - BN_rand(b,400+i,0,0); - a->neg=rand_neg(); - b->neg=rand_neg(); + BN_rand(&b,400+i,0,0); + a.neg=rand_neg(); + b.neg=rand_neg(); if (bp == NULL) for (j=0; j<10000; j++) - BN_sub(c,a,b); - BN_sub(c,a,b); + BN_sub(&c,&a,&b); + BN_sub(&c,&a,&b); if (bp != NULL) { if (!results) { - BN_print(bp,a); + BN_print(bp,&a); BIO_puts(bp," - "); - BN_print(bp,b); + BN_print(bp,&b); BIO_puts(bp," - "); } - BN_print(bp,c); + BN_print(bp,&c); BIO_puts(bp,"\n"); } + BN_add(&c,&c,&b); + BN_sub(&c,&c,&a); + if(!BN_is_zero(&c)) + { + BIO_puts(bp,"Subtract test failed!\n"); + return 0; + } } - BN_free(a); - BN_free(b); - BN_free(c); + BN_free(&a); + BN_free(&b); + BN_free(&c); return(1); } -int test_div(bp,ctx) -BIO *bp; -BN_CTX *ctx; +int test_div(BIO *bp, BN_CTX *ctx) { - BIGNUM *a,*b,*c,*d; + BIGNUM a,b,c,d,e; int i; int j; - a=BN_new(); - b=BN_new(); - c=BN_new(); - d=BN_new(); + BN_init(&a); + BN_init(&b); + BN_init(&c); + BN_init(&d); + BN_init(&e); - BN_rand(a,400,0,0); + BN_rand(&a,400,0,0); for (i=0; i<100; i++) { - BN_rand(b,50+i,0,0); - a->neg=rand_neg(); - b->neg=rand_neg(); + BN_rand(&b,50+i,0,0); + a.neg=rand_neg(); + b.neg=rand_neg(); if (bp == NULL) for (j=0; j<100; j++) - BN_div(d,c,a,b,ctx); - BN_div(d,c,a,b,ctx); + BN_div(&d,&c,&a,&b,ctx); + BN_div(&d,&c,&a,&b,ctx); if (bp != NULL) { if (!results) { - BN_print(bp,a); + BN_print(bp,&a); BIO_puts(bp," / "); - BN_print(bp,b); + BN_print(bp,&b); BIO_puts(bp," - "); } - BN_print(bp,d); + BN_print(bp,&d); BIO_puts(bp,"\n"); if (!results) { - BN_print(bp,a); + BN_print(bp,&a); BIO_puts(bp," % "); - BN_print(bp,b); + BN_print(bp,&b); BIO_puts(bp," - "); } - BN_print(bp,c); + BN_print(bp,&c); BIO_puts(bp,"\n"); } + BN_mul(&e,&d,&b,ctx); + BN_add(&d,&e,&c); + BN_sub(&d,&d,&a); + if(!BN_is_zero(&d)) + { + BIO_puts(bp,"Division test failed!\n"); + return 0; + } } - BN_free(a); - BN_free(b); - BN_free(c); - BN_free(d); + BN_free(&a); + BN_free(&b); + BN_free(&c); + BN_free(&d); + BN_free(&e); return(1); } -int test_mul(bp) -BIO *bp; +int test_div_recp(BIO *bp, BN_CTX *ctx) { - BIGNUM *a,*b,*c; + BIGNUM a,b,c,d,e; + BN_RECP_CTX recp; int i; int j; - a=BN_new(); - b=BN_new(); - c=BN_new(); + BN_RECP_CTX_init(&recp); + BN_init(&a); + BN_init(&b); + BN_init(&c); + BN_init(&d); + BN_init(&e); - BN_rand(a,200,0,0); + BN_rand(&a,400,0,0); for (i=0; i<100; i++) { - BN_rand(b,250+i,0,0); - a->neg=rand_neg(); - b->neg=rand_neg(); + BN_rand(&b,50+i,0,0); + a.neg=rand_neg(); + b.neg=rand_neg(); + BN_RECP_CTX_set(&recp,&b,ctx); if (bp == NULL) for (j=0; j<100; j++) - BN_mul(c,a,b); - BN_mul(c,a,b); + BN_div_recp(&d,&c,&a,&recp,ctx); + BN_div_recp(&d,&c,&a,&recp,ctx); if (bp != NULL) { if (!results) { - BN_print(bp,a); + BN_print(bp,&a); + BIO_puts(bp," / "); + BN_print(bp,&b); + BIO_puts(bp," - "); + } + BN_print(bp,&d); + BIO_puts(bp,"\n"); + + if (!results) + { + BN_print(bp,&a); + BIO_puts(bp," % "); + BN_print(bp,&b); + BIO_puts(bp," - "); + } + BN_print(bp,&c); + BIO_puts(bp,"\n"); + } + BN_mul(&e,&d,&b,ctx); + BN_add(&d,&e,&c); + BN_sub(&d,&d,&a); + if(!BN_is_zero(&d)) + { + BIO_puts(bp,"Reciprocal division test failed!\n"); + return 0; + } + } + BN_free(&a); + BN_free(&b); + BN_free(&c); + BN_free(&d); + BN_free(&e); + BN_RECP_CTX_free(&recp); + return(1); + } + +int test_mul(BIO *bp) + { + BIGNUM a,b,c,d,e; + int i; + int j; + BN_CTX ctx; + + BN_CTX_init(&ctx); + BN_init(&a); + BN_init(&b); + BN_init(&c); + BN_init(&d); + BN_init(&e); + + BN_rand(&a,200,0,0); + for (i=0; i<100; i++) + { + BN_rand(&b,250+i,0,0); + BN_rand(&b,200,0,0); + a.neg=rand_neg(); + b.neg=rand_neg(); + if (bp == NULL) + for (j=0; j<100; j++) + BN_mul(&c,&a,&b,&ctx); + BN_mul(&c,&a,&b,&ctx); + if (bp != NULL) + { + if (!results) + { + BN_print(bp,&a); BIO_puts(bp," * "); - BN_print(bp,b); + BN_print(bp,&b); BIO_puts(bp," - "); } - BN_print(bp,c); + BN_print(bp,&c); BIO_puts(bp,"\n"); } + BN_div(&d,&e,&c,&a,&ctx); + BN_sub(&d,&d,&b); + if(!BN_is_zero(&d) || !BN_is_zero(&e)) + { + BIO_puts(bp,"Multiplication test failed!\n"); + return 0; + } } - BN_free(a); - BN_free(b); - BN_free(c); + BN_free(&a); + BN_free(&b); + BN_free(&c); + BN_free(&d); + BN_free(&e); + BN_CTX_free(&ctx); return(1); } -int test_sqr(bp,ctx) -BIO *bp; -BN_CTX *ctx; +int test_sqr(BIO *bp, BN_CTX *ctx) { - BIGNUM *a,*c; + BIGNUM a,c,d,e; int i; int j; - a=BN_new(); - c=BN_new(); + BN_init(&a); + BN_init(&c); + BN_init(&d); + BN_init(&e); for (i=0; i<40; i++) { - BN_rand(a,40+i*10,0,0); - a->neg=rand_neg(); + BN_rand(&a,40+i*10,0,0); + a.neg=rand_neg(); if (bp == NULL) for (j=0; j<100; j++) - BN_sqr(c,a,ctx); - BN_sqr(c,a,ctx); + BN_sqr(&c,&a,ctx); + BN_sqr(&c,&a,ctx); if (bp != NULL) { if (!results) { - BN_print(bp,a); + BN_print(bp,&a); BIO_puts(bp," * "); - BN_print(bp,a); + BN_print(bp,&a); BIO_puts(bp," - "); } - BN_print(bp,c); + BN_print(bp,&c); BIO_puts(bp,"\n"); } + BN_div(&d,&e,&c,&a,ctx); + BN_sub(&d,&d,&a); + if(!BN_is_zero(&d) || !BN_is_zero(&e)) + { + BIO_puts(bp,"Square test failed!\n"); + return 0; + } } - BN_free(a); - BN_free(c); + BN_free(&a); + BN_free(&c); + BN_free(&d); + BN_free(&e); return(1); } -int test_mont(bp,ctx) -BIO *bp; -BN_CTX *ctx; +int test_mont(BIO *bp, BN_CTX *ctx) { - BIGNUM *a,*b,*c,*A,*B; - BIGNUM *n; + BIGNUM a,b,c,d,A,B; + BIGNUM n; int i; int j; BN_MONT_CTX *mont; - a=BN_new(); - b=BN_new(); - c=BN_new(); - A=BN_new(); - B=BN_new(); - n=BN_new(); + BN_init(&a); + BN_init(&b); + BN_init(&c); + BN_init(&d); + BN_init(&A); + BN_init(&B); + BN_init(&n); mont=BN_MONT_CTX_new(); - BN_rand(a,100,0,0); /**/ - BN_rand(b,100,0,0); /**/ + BN_rand(&a,100,0,0); /**/ + BN_rand(&b,100,0,0); /**/ for (i=0; i<10; i++) { - BN_rand(n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/ - BN_MONT_CTX_set(mont,n,ctx); + BN_rand(&n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/ + BN_MONT_CTX_set(mont,&n,ctx); - BN_to_montgomery(A,a,mont,ctx); - BN_to_montgomery(B,b,mont,ctx); + BN_to_montgomery(&A,&a,mont,ctx); + BN_to_montgomery(&B,&b,mont,ctx); if (bp == NULL) for (j=0; j<100; j++) - BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/ - BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/ - BN_from_montgomery(A,c,mont,ctx);/**/ + BN_mod_mul_montgomery(&c,&A,&B,mont,ctx);/**/ + BN_mod_mul_montgomery(&c,&A,&B,mont,ctx);/**/ + BN_from_montgomery(&A,&c,mont,ctx);/**/ if (bp != NULL) { if (!results) { #ifdef undef fprintf(stderr,"%d * %d %% %d\n", -BN_num_bits(a), -BN_num_bits(b), +BN_num_bits(&a), +BN_num_bits(&b), BN_num_bits(mont->N)); #endif - BN_print(bp,a); + BN_print(bp,&a); BIO_puts(bp," * "); - BN_print(bp,b); + BN_print(bp,&b); BIO_puts(bp," % "); - BN_print(bp,mont->N); + BN_print(bp,&(mont->N)); BIO_puts(bp," - "); } - BN_print(bp,A); + BN_print(bp,&A); BIO_puts(bp,"\n"); } + BN_mod_mul(&d,&a,&b,&n,ctx); + BN_sub(&d,&d,&A); + if(!BN_is_zero(&d)) + { + BIO_puts(bp,"Montgomery multiplication test failed!\n"); + return 0; + } } BN_MONT_CTX_free(mont); - BN_free(a); - BN_free(b); - BN_free(c); + BN_free(&a); + BN_free(&b); + BN_free(&c); + BN_free(&d); + BN_free(&A); + BN_free(&B); + BN_free(&n); return(1); } -int test_mod(bp,ctx) -BIO *bp; -BN_CTX *ctx; +int test_mod(BIO *bp, BN_CTX *ctx) { - BIGNUM *a,*b,*c; + BIGNUM *a,*b,*c,*d,*e; int i; int j; a=BN_new(); b=BN_new(); c=BN_new(); + d=BN_new(); + e=BN_new(); BN_rand(a,1024,0,0); /**/ for (i=0; i<20; i++) @@ -524,16 +643,23 @@ BN_CTX *ctx; BN_print(bp,c); BIO_puts(bp,"\n"); } + BN_div(d,e,a,b,ctx); + BN_sub(e,e,c); + if(!BN_is_zero(e)) + { + BIO_puts(bp,"Modulo test failed!\n"); + return 0; + } } BN_free(a); BN_free(b); BN_free(c); + BN_free(d); + BN_free(e); return(1); } -int test_mod_mul(bp,ctx) -BIO *bp; -BN_CTX *ctx; +int test_mod_mul(BIO *bp, BN_CTX *ctx) { BIGNUM *a,*b,*c,*d,*e; int i; @@ -578,6 +704,14 @@ BN_CTX *ctx; BN_print(bp,e); BIO_puts(bp,"\n"); } + BN_mul(d,a,b,ctx); + BN_sub(d,d,e); + BN_div(a,b,d,c,ctx); + if(!BN_is_zero(b)) + { + BIO_puts(bp,"Modulo multiply test failed!\n"); + return 0; + } } BN_free(a); BN_free(b); @@ -587,9 +721,7 @@ BN_CTX *ctx; return(1); } -int test_mod_exp(bp,ctx) -BIO *bp; -BN_CTX *ctx; +int test_mod_exp(BIO *bp, BN_CTX *ctx) { BIGNUM *a,*b,*c,*d,*e; int i; @@ -623,6 +755,14 @@ BN_CTX *ctx; BN_print(bp,d); BIO_puts(bp,"\n"); } + BN_exp(e,a,b,ctx); + BN_sub(e,e,d); + BN_div(a,b,e,c,ctx); + if(!BN_is_zero(b)) + { + BIO_puts(bp,"Modulo exponentiation test failed!\n"); + return 0; + } } BN_free(a); BN_free(b); @@ -632,19 +772,74 @@ BN_CTX *ctx; return(1); } -int test_lshift(bp) -BIO *bp; +int test_exp(BIO *bp, BN_CTX *ctx) { - BIGNUM *a,*b,*c; + BIGNUM *a,*b,*d,*e,*one; int i; a=BN_new(); + b=BN_new(); + d=BN_new(); + e=BN_new(); + one=BN_new(); + BN_one(one); + + for (i=0; i<6; i++) + { + BN_rand(a,20+i*5,0,0); /**/ + BN_rand(b,2+i,0,0); /**/ + + if (!BN_exp(d,a,b,ctx)) + return(00); + + if (bp != NULL) + { + if (!results) + { + BN_print(bp,a); + BIO_puts(bp," ^ "); + BN_print(bp,b); + BIO_puts(bp," - "); + } + BN_print(bp,d); + BIO_puts(bp,"\n"); + } + BN_one(e); + for( ; !BN_is_zero(b) ; BN_sub(b,b,one)) + BN_mul(e,e,a,ctx); + BN_sub(e,e,d); + if(!BN_is_zero(e)) + { + BIO_puts(bp,"Exponentiation test failed!\n"); + return 0; + } + } + BN_free(a); + BN_free(b); + BN_free(d); + BN_free(e); + BN_free(one); + return(1); + } + +int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_) + { + BIGNUM *a,*b,*c,*d; + int i; + b=BN_new(); c=BN_new(); + d=BN_new(); BN_one(c); - BN_rand(a,200,0,0); /**/ - a->neg=rand_neg(); + if(a_) + a=a_; + else + { + a=BN_new(); + BN_rand(a,200,0,0); /**/ + a->neg=rand_neg(); + } for (i=0; i<70; i++) { BN_lshift(b,a,i+1); @@ -661,21 +856,38 @@ BIO *bp; BN_print(bp,b); BIO_puts(bp,"\n"); } + BN_mul(d,a,c,ctx); + BN_sub(d,d,b); + if(!BN_is_zero(d)) + { + BIO_puts(bp,"Left shift test failed!\n"); + BIO_puts(bp,"a="); + BN_print(bp,a); + BIO_puts(bp,"\nb="); + BN_print(bp,b); + BIO_puts(bp,"\nc="); + BN_print(bp,c); + BIO_puts(bp,"\nd="); + BN_print(bp,d); + BIO_puts(bp,"\n"); + return 0; + } } BN_free(a); BN_free(b); BN_free(c); + BN_free(d); return(1); } -int test_lshift1(bp) -BIO *bp; +int test_lshift1(BIO *bp) { - BIGNUM *a,*b; + BIGNUM *a,*b,*c; int i; a=BN_new(); b=BN_new(); + c=BN_new(); BN_rand(a,200,0,0); /**/ a->neg=rand_neg(); @@ -693,22 +905,32 @@ BIO *bp; BN_print(bp,b); BIO_puts(bp,"\n"); } + BN_add(c,a,a); + BN_sub(a,b,c); + if(!BN_is_zero(a)) + { + BIO_puts(bp,"Left shift one test failed!\n"); + return 0; + } + BN_copy(a,b); } BN_free(a); BN_free(b); + BN_free(c); return(1); } -int test_rshift(bp) -BIO *bp; +int test_rshift(BIO *bp,BN_CTX *ctx) { - BIGNUM *a,*b,*c; + BIGNUM *a,*b,*c,*d,*e; int i; a=BN_new(); b=BN_new(); c=BN_new(); + d=BN_new(); + e=BN_new(); BN_one(c); BN_rand(a,200,0,0); /**/ @@ -729,21 +951,30 @@ BIO *bp; BN_print(bp,b); BIO_puts(bp,"\n"); } + BN_div(d,e,a,c,ctx); + BN_sub(d,d,b); + if(!BN_is_zero(d)) + { + BIO_puts(bp,"Right shift test failed!\n"); + return 0; + } } BN_free(a); BN_free(b); BN_free(c); + BN_free(d); + BN_free(e); return(1); } -int test_rshift1(bp) -BIO *bp; +int test_rshift1(BIO *bp) { - BIGNUM *a,*b; + BIGNUM *a,*b,*c; int i; a=BN_new(); b=BN_new(); + c=BN_new(); BN_rand(a,200,0,0); /**/ a->neg=rand_neg(); @@ -761,14 +992,22 @@ BIO *bp; BN_print(bp,b); BIO_puts(bp,"\n"); } + BN_sub(c,a,b); + BN_sub(c,c,b); + if(!BN_is_zero(c) && !BN_is_one(c)) + { + BIO_puts(bp,"Right shift one test failed!\n"); + return 0; + } BN_copy(a,b); } BN_free(a); BN_free(b); + BN_free(c); return(1); } -int rand_neg() +int rand_neg(void) { static unsigned int neg=0; static int sign[8]={0,0,0,1,1,0,1,1}; diff --git a/src/lib/libcrypto/bn/comba.pl b/src/lib/libcrypto/bn/comba.pl new file mode 100644 index 0000000000..211a8b45c7 --- /dev/null +++ b/src/lib/libcrypto/bn/comba.pl @@ -0,0 +1,285 @@ +#!/usr/local/bin/perl + +$num=8; +$num2=8/2; + +print <<"EOF"; +/* crypto/bn/bn_comba.c */ +#include +#include "bn_lcl.h" +/* Auto generated from crypto/bn/comba.pl + */ + +#undef bn_mul_comba8 +#undef bn_mul_comba4 +#undef bn_sqr_comba8 +#undef bn_sqr_comba4 + +#ifdef BN_LLONG +#define mul_add_c(a,b,c0,c1,c2) \\ + t=(BN_ULLONG)a*b; \\ + t1=(BN_ULONG)Lw(t); \\ + t2=(BN_ULONG)Hw(t); \\ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \\ + t=(BN_ULLONG)a*b; \\ + tt=(t+t)&BN_MASK; \\ + if (tt < t) c2++; \\ + t1=(BN_ULONG)Lw(tt); \\ + t2=(BN_ULONG)Hw(tt); \\ + c0=(c0+t1)&BN_MASK2; \\ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \\ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \\ + t=(BN_ULLONG)a[i]*a[i]; \\ + t1=(BN_ULONG)Lw(t); \\ + t2=(BN_ULONG)Hw(t); \\ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \\ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#else +#define mul_add_c(a,b,c0,c1,c2) \\ + t1=LBITS(a); t2=HBITS(a); \\ + bl=LBITS(b); bh=HBITS(b); \\ + mul64(t1,t2,bl,bh); \\ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define mul_add_c2(a,b,c0,c1,c2) \\ + t1=LBITS(a); t2=HBITS(a); \\ + bl=LBITS(b); bh=HBITS(b); \\ + mul64(t1,t2,bl,bh); \\ + if (t2 & BN_TBIT) c2++; \\ + t2=(t2+t2)&BN_MASK2; \\ + if (t1 & BN_TBIT) t2++; \\ + t1=(t1+t1)&BN_MASK2; \\ + c0=(c0+t1)&BN_MASK2; \\ + if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \\ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c(a,i,c0,c1,c2) \\ + sqr64(t1,t2,(a)[i]); \\ + c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\ + c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++; + +#define sqr_add_c2(a,i,j,c0,c1,c2) \\ + mul_add_c2((a)[i],(a)[j],c0,c1,c2) +#endif + +void bn_mul_comba${num}(r,a,b) +BN_ULONG *r,*a,*b; + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + +EOF +$ret=&combas_mul("r","a","b",$num,"c1","c2","c3"); +printf <<"EOF"; + } + +void bn_mul_comba${num2}(r,a,b) +BN_ULONG *r,*a,*b; + { +#ifdef BN_LLONG + BN_ULLONG t; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + +EOF +$ret=&combas_mul("r","a","b",$num2,"c1","c2","c3"); +printf <<"EOF"; + } + +void bn_sqr_comba${num}(r,a) +BN_ULONG *r,*a; + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + +EOF +$ret=&combas_sqr("r","a",$num,"c1","c2","c3"); +printf <<"EOF"; + } + +void bn_sqr_comba${num2}(r,a) +BN_ULONG *r,*a; + { +#ifdef BN_LLONG + BN_ULLONG t,tt; +#else + BN_ULONG bl,bh; +#endif + BN_ULONG t1,t2; + BN_ULONG c1,c2,c3; + +EOF +$ret=&combas_sqr("r","a",$num2,"c1","c2","c3"); +printf <<"EOF"; + } +EOF + +sub bn_str + { + local($var,$val)=@_; + print "\t$var=$val;\n"; + } + +sub bn_ary + { + local($var,$idx)=@_; + return("${var}[$idx]"); + } + +sub bn_clr + { + local($var)=@_; + + print "\t$var=0;\n"; + } + +sub bn_mad + { + local($a,$b,$c0,$c1,$c2,$num)=@_; + + if ($num == 2) + { printf("\tmul_add_c2($a,$b,$c0,$c1,$c2);\n"); } + else + { printf("\tmul_add_c($a,$b,$c0,$c1,$c2);\n"); } + } + +sub bn_sad + { + local($a,$i,$j,$c0,$c1,$c2,$num)=@_; + + if ($num == 2) + { printf("\tsqr_add_c2($a,$i,$j,$c0,$c1,$c2);\n"); } + else + { printf("\tsqr_add_c($a,$i,$c0,$c1,$c2);\n"); } + } + +sub combas_mul + { + local($r,$a,$b,$num,$c0,$c1,$c2)=@_; + local($i,$as,$ae,$bs,$be,$ai,$bi); + local($tot,$end); + + $as=0; + $ae=0; + $bs=0; + $be=0; + $tot=$num+$num-1; + &bn_clr($c0); + &bn_clr($c1); + for ($i=0; $i<$tot; $i++) + { + $ai=$as; + $bi=$bs; + $end=$be+1; + @numa=@numb=(); + +#print "($as $ae) ($bs $be) $bs -> $end [$i $num]\n"; + for ($j=$bs; $j<$end; $j++) + { + push(@numa,$ai); + push(@numb,$bi); + $ai--; + $bi++; + } + + if ($i & 1) + { + @numa=reverse(@numa); + @numb=reverse(@numb); + } + + &bn_clr($c2); + for ($j=0; $j<=$#numa; $j++) + { + &bn_mad(&bn_ary($a,$numa[$j]), + &bn_ary($b,$numb[$j]),$c0,$c1,$c2,1); + } + &bn_str(&bn_ary($r,$i),$c0); + ($c0,$c1,$c2)=($c1,$c2,$c0); + + $as++ if ($i < ($num-1)); + $ae++ if ($i >= ($num-1)); + + $bs++ if ($i >= ($num-1)); + $be++ if ($i < ($num-1)); + } + &bn_str(&bn_ary($r,$i),$c0); + } + +sub combas_sqr + { + local($r,$a,$num,$c0,$c1,$c2)=@_; + local($i,$as,$ae,$bs,$be,$ai,$bi); + local($b,$tot,$end,$half); + + $b=$a; + $as=0; + $ae=0; + $bs=0; + $be=0; + $tot=$num+$num-1; + &bn_clr($c0); + &bn_clr($c1); + for ($i=0; $i<$tot; $i++) + { + $ai=$as; + $bi=$bs; + $end=$be+1; + @numa=@numb=(); + +#print "($as $ae) ($bs $be) $bs -> $end [$i $num]\n"; + for ($j=$bs; $j<$end; $j++) + { + push(@numa,$ai); + push(@numb,$bi); + $ai--; + $bi++; + last if ($ai < $bi); + } + if (!($i & 1)) + { + @numa=reverse(@numa); + @numb=reverse(@numb); + } + + &bn_clr($c2); + for ($j=0; $j <= $#numa; $j++) + { + if ($numa[$j] == $numb[$j]) + {&bn_sad($a,$numa[$j],$numb[$j],$c0,$c1,$c2,1);} + else + {&bn_sad($a,$numa[$j],$numb[$j],$c0,$c1,$c2,2);} + } + &bn_str(&bn_ary($r,$i),$c0); + ($c0,$c1,$c2)=($c1,$c2,$c0); + + $as++ if ($i < ($num-1)); + $ae++ if ($i >= ($num-1)); + + $bs++ if ($i >= ($num-1)); + $be++ if ($i < ($num-1)); + } + &bn_str(&bn_ary($r,$i),$c0); + } diff --git a/src/lib/libcrypto/bn/d.c b/src/lib/libcrypto/bn/d.c new file mode 100644 index 0000000000..ced2291b25 --- /dev/null +++ b/src/lib/libcrypto/bn/d.c @@ -0,0 +1,72 @@ +#include +#include +#include "bn_lcl.h" + +#define SIZE_A (100*4+4) +#define SIZE_B (13*4) + +main(argc,argv) +int argc; +char *argv[]; + { + BN_CTX ctx; + BN_RECP_CTX recp; + BIGNUM a,b,dd,d,r,rr,t,l; + int i; + + MemCheck_start(); + MemCheck_on(); + BN_CTX_init(&ctx); + BN_RECP_CTX_init(&recp); + + BN_init(&r); + BN_init(&rr); + BN_init(&d); + BN_init(&dd); + BN_init(&a); + BN_init(&b); + + { + BN_rand(&a,SIZE_A,0,0); + BN_rand(&b,SIZE_B,0,0); + + a.neg=1; + BN_RECP_CTX_set(&recp,&b,&ctx); + + BN_print_fp(stdout,&a); printf(" a\n"); + BN_print_fp(stdout,&b); printf(" b\n"); + + BN_print_fp(stdout,&recp.N); printf(" N\n"); + BN_print_fp(stdout,&recp.Nr); printf(" Nr num_bits=%d\n",recp.num_bits); + + BN_div_recp(&r,&d,&a,&recp,&ctx); + +for (i=0; i<300; i++) + BN_div(&rr,&dd,&a,&b,&ctx); + + BN_print_fp(stdout,&r); printf(" div recp\n"); + BN_print_fp(stdout,&rr); printf(" div\n"); + BN_print_fp(stdout,&d); printf(" rem recp\n"); + BN_print_fp(stdout,&dd); printf(" rem\n"); + } + BN_CTX_free(&ctx); + BN_RECP_CTX_free(&recp); + + BN_free(&r); + BN_free(&rr); + BN_free(&d); + BN_free(&dd); + BN_free(&a); + BN_free(&b); + + { + BIO *out; + + if ((out=BIO_new(BIO_s_file())) != NULL) + BIO_set_fp(out,stderr,BIO_NOCLOSE|BIO_FP_TEXT); + + CRYPTO_mem_leaks(out); + BIO_free(out); + } + + } diff --git a/src/lib/libcrypto/bn/exp.c b/src/lib/libcrypto/bn/exp.c new file mode 100644 index 0000000000..ec443459d8 --- /dev/null +++ b/src/lib/libcrypto/bn/exp.c @@ -0,0 +1,60 @@ +#include +#include +#include "bn_lcl.h" + +#define SIZE 256 +#define NUM (8*8*8) +#define MOD (8*8*8*8*8) + +main(argc,argv) +int argc; +char *argv[]; + { + BN_CTX ctx; + BIGNUM a,b,c,r,rr,t,l; + int j,i,size=SIZE,num=NUM,mod=MOD; + char *start,*end; + BN_MONT_CTX mont; + double d,md; + + BN_MONT_CTX_init(&mont); + BN_CTX_init(&ctx); + BN_init(&a); + BN_init(&b); + BN_init(&c); + BN_init(&r); + + start=ms_time_new(); + end=ms_time_new(); + while (size <= 1024*8) + { + BN_rand(&a,size,0,0); + BN_rand(&b,size,1,0); + BN_rand(&c,size,0,1); + + BN_mod(&a,&a,&c,&ctx); + + ms_time_get(start); + for (i=0; i<10; i++) + BN_MONT_CTX_set(&mont,&c,&ctx); + ms_time_get(end); + md=ms_time_diff(start,end); + + ms_time_get(start); + for (i=0; i #include #include -#include "crypto.h" -#include "err.h" +#include +#include -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif -#ifndef VMS #ifndef _IRIX #include #endif @@ -81,36 +80,33 @@ #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "bn.h" -#include "x509.h" +#include +#include /* The following if from times(3) man page. It may need to be changed */ #ifndef HZ # ifndef CLK_TCK # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ -# ifndef VMS -# define HZ 100.0 -# else /* VMS */ -# define HZ 100.0 -# endif +# define HZ 100.0 # else /* _BSD_CLK_TCK_ */ # define HZ ((double)_BSD_CLK_TCK_) # endif @@ -123,17 +119,11 @@ struct tms { #define BUFSIZE ((long)1024*8) int run=0; -#ifndef NOPROTO static double Time_F(int s); -#else -static double Time_F(); -#endif - #define START 0 #define STOP 1 -static double Time_F(s) -int s; +static double Time_F(int s) { double ret; #ifdef TIMES @@ -176,9 +166,7 @@ static int mul_c[NUM_SIZES]={8*8*8*8*8,8*8*8*8,8*8*8,8*8,8,1}; void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx); -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { BN_CTX *ctx; BIGNUM *a,*b,*c,*r; @@ -192,12 +180,7 @@ char **argv; do_mul_exp(r,a,b,c,ctx); } -void do_mul_exp(r,a,b,c,ctx) -BIGNUM *r; -BIGNUM *a; -BIGNUM *b; -BIGNUM *c; -BN_CTX *ctx; +void do_mul_exp(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx) { int i,k; double tm; diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c index 67dc95d726..9e4ae91d20 100644 --- a/src/lib/libcrypto/bn/exptest.c +++ b/src/lib/libcrypto/bn/exptest.c @@ -59,30 +59,31 @@ #include #include #include -#include "bio.h" -#include "bn.h" -#include "rand.h" -#include "err.h" +#include +#include +#include +#include #ifdef WINDOWS #include "../bio/bss_file.c" #endif #define NUM_BITS (BN_BITS*2) -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { BN_CTX *ctx; BIO *out=NULL; int i,ret; unsigned char c; - BIGNUM *r_mont,*r_recp,*a,*b,*m; + BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m; + + ERR_load_BN_strings(); ctx=BN_CTX_new(); if (ctx == NULL) exit(1); r_mont=BN_new(); r_recp=BN_new(); + r_simple=BN_new(); a=BN_new(); b=BN_new(); m=BN_new(); @@ -114,29 +115,52 @@ char *argv[]; ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); if (ret <= 0) - { printf("BN_mod_exp_mont() problems\n"); exit(1); } + { + printf("BN_mod_exp_mont() problems\n"); + ERR_print_errors(out); + exit(1); + } ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); if (ret <= 0) - { printf("BN_mod_exp_recp() problems\n"); exit(1); } - - if (BN_cmp(r_mont,r_recp) != 0) { - printf("\nmont and recp results differ\n"); + printf("BN_mod_exp_recp() problems\n"); + ERR_print_errors(out); + exit(1); + } + + ret=BN_mod_exp_simple(r_simple,a,b,m,ctx); + if (ret <= 0) + { + printf("BN_mod_exp_simple() problems\n"); + ERR_print_errors(out); + exit(1); + } + + if (BN_cmp(r_simple, r_mont) == 0 + && BN_cmp(r_simple,r_recp) == 0) + { + printf("."); + fflush(stdout); + } + else + { + if (BN_cmp(r_simple,r_mont) != 0) + printf("\nsimple and mont results differ\n"); + if (BN_cmp(r_simple,r_recp) != 0) + printf("\nsimple and recp results differ\n"); + printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); + printf("\nsimple ="); BN_print(out,r_simple); printf("\nrecp ="); BN_print(out,r_recp); printf("\nmont ="); BN_print(out,r_mont); printf("\n"); exit(1); } - else - { - printf("."); - fflush(stdout); - } } + CRYPTO_mem_leaks(out); printf(" done\n"); exit(0); err: diff --git a/src/lib/libcrypto/bn/new b/src/lib/libcrypto/bn/new new file mode 100644 index 0000000000..285d506f19 --- /dev/null +++ b/src/lib/libcrypto/bn/new @@ -0,0 +1,23 @@ +void BN_RECP_CTX_init(BN_RECP_CTX *recp); +BN_RECP_CTX *BN_RECP_CTX_new(); +void BN_RECP_CTX_free(BN_RECP_CTX *recp); +int BN_RECP_CTX_set(BN_RECP_CTX *recp,BIGNUM *div,BN_CTX *ctx); + +int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, + BN_RECP_CTX *recp,BN_CTX *ctx); + +int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, + BN_RECP_CTX *recp, BN_CTX *ctx); +int BN_mod_recp(BIGNUM *rem, BIGNUM *m, BIGNUM *d, + BN_RECP_CTX *recp, BN_CTX *ctx); +int BN_mod_mul_recp(BIGNUM *ret,BIGNUM *a,BIGNUM *b,BIGNUM *m + +int BN_mod_exp_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *p, + BN_MONT_CTX *m_ctx,BN_CTX *ctx); +int BN_mod_exp2_montgomery(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2, + BIGNUM *p2,BN_MONT_CTX *m_ctx,BN_CTX *ctx); + + +bn_div64 -> bn_div_words + + diff --git a/src/lib/libcrypto/bn/test.c b/src/lib/libcrypto/bn/test.c new file mode 100644 index 0000000000..a048b9f878 --- /dev/null +++ b/src/lib/libcrypto/bn/test.c @@ -0,0 +1,241 @@ +#include +#include "cryptlib.h" +#include "bn_lcl.h" + +#define SIZE 32 + +#define BN_MONT_CTX_set bn_mcs +#define BN_from_montgomery bn_fm +#define BN_mod_mul_montgomery bn_mmm +#undef BN_to_montgomery +#define BN_to_montgomery(r,a,mont,ctx) bn_mmm(\ + r,a,(mont)->RR,(mont),ctx) + +main() + { + BIGNUM prime,a,b,r,A,B,R; + BN_MONT_CTX *mont; + BN_CTX *ctx; + int i; + + ctx=BN_CTX_new(); + BN_init(&prime); + BN_init(&a); BN_init(&b); BN_init(&r); + BN_init(&A); BN_init(&B); BN_init(&R); + + BN_generate_prime(&prime,SIZE,0,NULL,NULL,NULL,NULL); + BN_rand(&A,SIZE,1,0); + BN_rand(&B,SIZE,1,0); + BN_mod(&A,&A,&prime,ctx); + BN_mod(&B,&B,&prime,ctx); + + i=A.top; + BN_mul(&R,&A,&B,ctx); + BN_mask_bits(&R,i*BN_BITS2); + + + BN_print_fp(stdout,&A); printf(" <- a\n"); + BN_print_fp(stdout,&B); printf(" <- b\n"); + BN_mul_high(&r,&A,&B,&R,i); + BN_print_fp(stdout,&r); printf(" <- high(BA*DC)\n"); + + BN_mask_bits(&A,i*32); + BN_mask_bits(&B,i*32); + + BN_mul(&R,&A,&B); + BN_rshift(&R,&R,i*32); + BN_print_fp(stdout,&R); printf(" <- norm BA*DC\n"); + BN_sub(&R,&R,&r); + BN_print_fp(stdout,&R); printf(" <- diff\n"); + } + +#if 0 +int bn_mul_high(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *low, int words) + { + int i; + BIGNUM t1,t2,t3,h,ah,al,bh,bl,m,s0,s1; + + BN_init(&al); BN_init(&ah); + BN_init(&bl); BN_init(&bh); + BN_init(&t1); BN_init(&t2); BN_init(&t3); + BN_init(&s0); BN_init(&s1); + BN_init(&h); BN_init(&m); + + i=a->top; + if (i >= words) + { + al.top=words; + ah.top=a->top-words; + ah.d= &(a->d[ah.top]); + } + else + al.top=i; + al.d=a->d; + + i=b->top; + if (i >= words) + { + bl.top=words; + bh.top=i-words; + bh.d= &(b->d[bh.top]); + } + else + bl.top=i; + bl.d=b->d; + + i=low->top; + if (i >= words) + { + s0.top=words; + s1.top=i-words; + s1.d= &(low->d[s1.top]); + } + else + s0.top=i; + s0.d=low->d; + +al.max=al.top; ah.max=ah.top; +bl.max=bl.top; bh.max=bh.top; +s0.max=bl.top; s1.max=bh.top; + + /* Calculate (al-ah)*(bh-bl) */ + BN_sub(&t1,&al,&ah); + BN_sub(&t2,&bh,&bl); + BN_mul(&m,&t1,&t2); + + /* Calculate ah*bh */ + BN_mul(&h,&ah,&bh); + + /* s0 == low(al*bl) + * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl) + * We know s0 and s1 so the only unknown is high(al*bl) + * high(al*bl) == s1 - low(ah*bh+(al-ah)*(bh-bl)+s0) + */ + BN_add(&m,&m,&h); + BN_add(&t2,&m,&s0); + /* Quick and dirty mask off of high words */ + t3.d=t2.d; + t3.top=(t2.top > words)?words:t2.top; + t3.neg=t2.neg; +t3.max=t3.top; +/* BN_print_fp(stdout,&s1); printf(" s1\n"); */ +/* BN_print_fp(stdout,&t2); printf(" middle value\n"); */ +/* BN_print_fp(stdout,&t3); printf(" low middle value\n"); */ + BN_sub(&t1,&s1,&t3); + + if (t1.neg) + { +/*printf("neg fixup\n"); BN_print_fp(stdout,&t1); printf(" before\n"); */ + BN_lshift(&t2,BN_value_one(),words*32); + BN_add(&t1,&t2,&t1); + BN_mask_bits(&t1,words*32); +/* BN_print_fp(stdout,&t1); printf(" after\n"); */ + } + /* al*bl == high(al*bl)<bn[ctx->tos++]); + + if (a == b) + { + if (!BN_sqr(tmp,a,ctx)) goto err; + } + else + { + if (!BN_mul(tmp,a,b)) goto err; + } + /* reduce from aRR to aR */ + if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err; + ctx->tos--; + return(1); +err: + return(0); + } + +int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont, BN_CTX *ctx) + { + BIGNUM z1; + BIGNUM *t1,*t2; + BN_ULONG *ap,*bp,*rp; + int j,i,bl,al; + + BN_init(&z1); + t1= &(ctx->bn[ctx->tos]); + t2= &(ctx->bn[ctx->tos+1]); + + if (!BN_copy(t1,a)) goto err; + /* can cheat */ + BN_mask_bits(t1,mont->ri); + if (!BN_mul(t2,t1,mont->Ni)) goto err; + BN_mask_bits(t2,mont->ri); + + if (!BN_mul(t1,t2,mont->N)) goto err; + if (!BN_add(t2,t1,a)) goto err; + + /* At this point, t2 has the bottom ri bits set to zero. + * This means that the bottom ri bits == the 1^ri minus the bottom + * ri bits of a. + * This means that only the bits above 'ri' in a need to be added, + * and XXXXXXXXXXXXXXXXXXXXXXXX + */ +BN_print_fp(stdout,t2); printf("\n"); + BN_rshift(r,t2,mont->ri); + + if (BN_ucmp(r,mont->N) >= 0) + BN_usub(r,r,mont->N); + + return(1); +err: + return(0); + } + +int BN_MONT_CTX_set(BN_MONT_CTX *mont, BIGNUM *mod, BN_CTX *ctx) + { + BIGNUM *Ri=NULL,*R=NULL; + + if (mont->RR == NULL) mont->RR=BN_new(); + if (mont->N == NULL) mont->N=BN_new(); + + R=mont->RR; /* grab RR as a temp */ + BN_copy(mont->N,mod); /* Set N */ + + mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; + BN_lshift(R,BN_value_one(),mont->ri); /* R */ + if ((Ri=BN_mod_inverse(NULL,R,mod,ctx)) == NULL) goto err;/* Ri */ + BN_lshift(Ri,Ri,mont->ri); /* R*Ri */ + BN_usub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */ + BN_div(Ri,NULL,Ri,mod,ctx); + if (mont->Ni != NULL) BN_free(mont->Ni); + mont->Ni=Ri; /* Ni=(R*Ri-1)/N */ + + /* setup RR for conversions */ + BN_lshift(mont->RR,BN_value_one(),mont->ri*2); + BN_mod(mont->RR,mont->RR,mont->N,ctx); + + return(1); +err: + return(0); + } + + +#endif diff --git a/src/lib/libcrypto/bn/todo b/src/lib/libcrypto/bn/todo new file mode 100644 index 0000000000..e47e381aea --- /dev/null +++ b/src/lib/libcrypto/bn/todo @@ -0,0 +1,3 @@ +Cache RECP_CTX values +make the result argument independant of the inputs. +split up the _exp_ functions diff --git a/src/lib/libcrypto/bn/vms-helper.c b/src/lib/libcrypto/bn/vms-helper.c new file mode 100644 index 0000000000..73af337069 --- /dev/null +++ b/src/lib/libcrypto/bn/vms-helper.c @@ -0,0 +1,66 @@ +/* vms-helper.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include "bn_lcl.h" + +bn_div_words_abort(int i) +{ +#if !defined(NO_STDIO) && !defined(WIN16) + fprintf(stderr,"Division would overflow (%d)\n",i); +#endif + abort(); +} diff --git a/src/lib/libcrypto/buffer/Makefile.ssl b/src/lib/libcrypto/buffer/Makefile.ssl index a5f150e523..b615c4c12d 100644 --- a/src/lib/libcrypto/buffer/Makefile.ssl +++ b/src/lib/libcrypto/buffer/Makefile.ssl @@ -7,23 +7,23 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=buffer -ERRC=buf_err GENERAL=Makefile TEST= APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= buffer.c $(ERRC).c -LIBOBJ= buffer.o $(ERRC).o +LIBSRC= buffer.c buf_err.c +LIBOBJ= buffer.o buf_err.o SRC= $(LIBSRC) @@ -39,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -68,17 +67,20 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +buf_err.o: ../../include/openssl/buffer.h ../../include/openssl/err.h +buffer.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +buffer.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +buffer.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +buffer.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +buffer.o: ../../include/openssl/stack.h ../cryptlib.h diff --git a/src/lib/libcrypto/buffer/buf_err.c b/src/lib/libcrypto/buffer/buf_err.c index ff988852cc..7f9fd1f6c3 100644 --- a/src/lib/libcrypto/buffer/buf_err.c +++ b/src/lib/libcrypto/buffer/buf_err.c @@ -1,63 +1,65 @@ -/* lib/buf/buf_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/buffer/buf_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. */ + #include -#include "err.h" -#include "buffer.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -66,21 +68,26 @@ static ERR_STRING_DATA BUF_str_functs[]= {ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"}, {ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"}, {ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"}, -{ERR_PACK(0,BUF_F_PXYCLNT_READ,0), "PXYCLNT_READ"}, -{0,NULL}, +{0,NULL} + }; + +static ERR_STRING_DATA BUF_str_reasons[]= + { +{0,NULL} }; #endif -void ERR_load_BUF_strings() +void ERR_load_BUF_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_BUF,BUF_str_functs); + ERR_load_strings(ERR_LIB_BUF,BUF_str_reasons); #endif } diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c index 7e8af9e2fa..c3a108ea52 100644 --- a/src/lib/libcrypto/buffer/buffer.c +++ b/src/lib/libcrypto/buffer/buffer.c @@ -58,13 +58,13 @@ #include #include "cryptlib.h" -#include "buffer.h" +#include -BUF_MEM *BUF_MEM_new() +BUF_MEM *BUF_MEM_new(void) { BUF_MEM *ret; - ret=(BUF_MEM *)Malloc(sizeof(BUF_MEM)); + ret=Malloc(sizeof(BUF_MEM)); if (ret == NULL) { BUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE); @@ -76,9 +76,11 @@ BUF_MEM *BUF_MEM_new() return(ret); } -void BUF_MEM_free(a) -BUF_MEM *a; +void BUF_MEM_free(BUF_MEM *a) { + if(a == NULL) + return; + if (a->data != NULL) { memset(a->data,0,(unsigned int)a->max); @@ -87,9 +89,7 @@ BUF_MEM *a; Free(a); } -int BUF_MEM_grow(str, len) -BUF_MEM *str; -int len; +int BUF_MEM_grow(BUF_MEM *str, int len) { char *ret; unsigned int n; @@ -101,15 +101,15 @@ int len; } if (str->max >= len) { - memset(&(str->data[str->length]),0,len-str->length); + memset(&str->data[str->length],0,len-str->length); str->length=len; return(len); } n=(len+3)/3*4; if (str->data == NULL) - ret=(char *)Malloc(n); + ret=Malloc(n); else - ret=(char *)Realloc(str->data,n); + ret=Realloc(str->data,n); if (ret == NULL) { BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); @@ -124,8 +124,7 @@ int len; return(len); } -char *BUF_strdup(str) -char *str; +char *BUF_strdup(const char *str) { char *ret; int n; diff --git a/src/lib/libcrypto/buffer/buffer.err b/src/lib/libcrypto/buffer/buffer.err deleted file mode 100644 index 62b775e637..0000000000 --- a/src/lib/libcrypto/buffer/buffer.err +++ /dev/null @@ -1,9 +0,0 @@ -/* Error codes for the BUF functions. */ - -/* Function codes. */ -#define BUF_F_BUF_MEM_GROW 100 -#define BUF_F_BUF_MEM_NEW 101 -#define BUF_F_BUF_STRDUP 102 -#define BUF_F_PXYCLNT_READ 103 - -/* Reason codes. */ diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h index 417548c04a..bff26bf391 100644 --- a/src/lib/libcrypto/buffer/buffer.h +++ b/src/lib/libcrypto/buffer/buffer.h @@ -70,36 +70,27 @@ typedef struct buf_mem_st int max; /* size of buffer */ } BUF_MEM; -#ifndef NOPROTO BUF_MEM *BUF_MEM_new(void); void BUF_MEM_free(BUF_MEM *a); int BUF_MEM_grow(BUF_MEM *str, int len); -char * BUF_strdup(char *str); +char * BUF_strdup(const char *str); void ERR_load_BUF_strings(void ); -#else - -BUF_MEM *BUF_MEM_new(); -void BUF_MEM_free(); -int BUF_MEM_grow(); -char * BUF_strdup(); - -void ERR_load_BUF_strings(); - -#endif - /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the BUF functions. */ /* Function codes. */ #define BUF_F_BUF_MEM_GROW 100 #define BUF_F_BUF_MEM_NEW 101 #define BUF_F_BUF_STRDUP 102 -#define BUF_F_PXYCLNT_READ 103 /* Reason codes. */ - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/cast/Makefile.ssl b/src/lib/libcrypto/cast/Makefile.ssl index 0143827ae5..cc040576ae 100644 --- a/src/lib/libcrypto/cast/Makefile.ssl +++ b/src/lib/libcrypto/cast/Makefile.ssl @@ -8,9 +8,11 @@ CC= cc CPP= $(CC) -E INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -45,7 +47,7 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf @@ -64,26 +66,25 @@ asm/cx86-out.o: asm/cx86unix.cpp # bsdi asm/cx86bsdi.o: asm/cx86unix.cpp - $(CPP) -DBSDI asm/cx86unix.cpp | as -o asm/cx86bsdi.o + $(CPP) -DBSDI asm/cx86unix.cpp | sed 's/ :/:/' | as -o asm/cx86bsdi.o -asm/cx86unix.cpp: - (cd asm; perl cast-586.pl cpp >cx86unix.cpp) +asm/cx86unix.cpp: asm/cast-586.pl + (cd asm; $(PERL) cast-586.pl cpp $(PROCESSOR) >cx86unix.cpp) files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -95,15 +96,29 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f asm/cx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +c_cfb64.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_cfb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_cfb64.o: cast_lcl.h +c_ecb.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_ecb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_ecb.o: ../../include/openssl/opensslv.h cast_lcl.h +c_enc.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_enc.o: cast_lcl.h +c_ofb64.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_ofb64.o: cast_lcl.h +c_skey.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_skey.o: cast_lcl.h cast_s.h diff --git a/src/lib/libcrypto/cast/Makefile.uni b/src/lib/libcrypto/cast/Makefile.uni index 780073e75b..a5870897cf 100644 --- a/src/lib/libcrypto/cast/Makefile.uni +++ b/src/lib/libcrypto/cast/Makefile.uni @@ -24,6 +24,7 @@ MAKE= make MAKEDEPEND= makedepend MAKEFILE= Makefile.uni AR= ar r +RANLIB= ranlib CAST_ENC=c_enc.o # or use @@ -55,7 +56,7 @@ all: $(LIB) $(TEST) $(APPS) $(LIB): $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/ranlib.sh $(LIB) + $(RANLIB) $(LIB) # elf asm/cx86-elf.o: asm/cx86unix.cpp $(CPP) -DELF asm/cx86unix.cpp | as -o asm/cx86-elf.o diff --git a/src/lib/libcrypto/cast/asm/c-win32.asm b/src/lib/libcrypto/cast/asm/c-win32.asm index a1d8a2671a..ba78a3c69c 100644 --- a/src/lib/libcrypto/cast/asm/c-win32.asm +++ b/src/lib/libcrypto/cast/asm/c-win32.asm @@ -25,6 +25,9 @@ _CAST_encrypt PROC NEAR ; Load the 2 words mov edi, DWORD PTR [ebx] mov esi, DWORD PTR 4[ebx] + ; Get short key flag + mov eax, DWORD PTR 128[ebp] + push eax xor eax, eax ; round 0 mov edx, DWORD PTR [ebp] @@ -278,6 +281,10 @@ _CAST_encrypt PROC NEAR mov ebx, DWORD PTR _CAST_S_table3[edx*4] sub ecx, ebx xor esi, ecx + ; test short key flag + pop edx + or edx, edx + jnz $L000cast_enc_done ; round 12 mov edx, DWORD PTR 96[ebp] mov ecx, DWORD PTR 100[ebp] @@ -361,9 +368,10 @@ _CAST_encrypt PROC NEAR sub ecx, ebx mov ebx, DWORD PTR _CAST_S_table3[edx*4] add ecx, ebx - mov eax, DWORD PTR 20[esp] xor esi, ecx +$L000cast_enc_done: nop + mov eax, DWORD PTR 20[esp] mov DWORD PTR 4[eax],edi mov DWORD PTR [eax],esi pop edi @@ -391,6 +399,10 @@ _CAST_decrypt PROC NEAR ; Load the 2 words mov edi, DWORD PTR [ebx] mov esi, DWORD PTR 4[ebx] + ; Get short key flag + mov eax, DWORD PTR 128[ebp] + or eax, eax + jnz $L001cast_dec_skip xor eax, eax ; round 15 mov edx, DWORD PTR 120[ebp] @@ -476,6 +488,7 @@ _CAST_decrypt PROC NEAR mov ebx, DWORD PTR _CAST_S_table3[edx*4] add ecx, ebx xor esi, ecx +$L001cast_dec_skip: ; round 11 mov edx, DWORD PTR 88[ebp] mov ecx, DWORD PTR 92[ebp] @@ -727,9 +740,9 @@ _CAST_decrypt PROC NEAR sub ecx, ebx mov ebx, DWORD PTR _CAST_S_table3[edx*4] add ecx, ebx - mov eax, DWORD PTR 20[esp] xor esi, ecx nop + mov eax, DWORD PTR 20[esp] mov DWORD PTR 4[eax],edi mov DWORD PTR [eax],esi pop edi @@ -767,12 +780,12 @@ _CAST_cbc_encrypt PROC NEAR push eax push ebx cmp ecx, 0 - jz $L000decrypt + jz $L002decrypt and ebp, 4294967288 mov eax, DWORD PTR 8[esp] mov ebx, DWORD PTR 12[esp] - jz $L001encrypt_finish -L002encrypt_loop: + jz $L003encrypt_finish +L004encrypt_loop: mov ecx, DWORD PTR [esi] mov edx, DWORD PTR 4[esi] xor eax, ecx @@ -791,35 +804,35 @@ L002encrypt_loop: add esi, 8 add edi, 8 sub ebp, 8 - jnz L002encrypt_loop -$L001encrypt_finish: + jnz L004encrypt_loop +$L003encrypt_finish: mov ebp, DWORD PTR 52[esp] and ebp, 7 - jz $L003finish + jz $L005finish xor ecx, ecx xor edx, edx - mov ebp, DWORD PTR $L004cbc_enc_jmp_table[ebp*4] + mov ebp, DWORD PTR $L006cbc_enc_jmp_table[ebp*4] jmp ebp -L005ej7: +L007ej7: xor edx, edx mov dh, BYTE PTR 6[esi] shl edx, 8 -L006ej6: +L008ej6: mov dh, BYTE PTR 5[esi] -L007ej5: +L009ej5: mov dl, BYTE PTR 4[esi] -L008ej4: +L010ej4: mov ecx, DWORD PTR [esi] - jmp $L009ejend -L010ej3: + jmp $L011ejend +L012ej3: mov ch, BYTE PTR 2[esi] xor ecx, ecx shl ecx, 8 -L011ej2: +L013ej2: mov ch, BYTE PTR 1[esi] -L012ej1: +L014ej1: mov cl, BYTE PTR [esi] -$L009ejend: +$L011ejend: xor eax, ecx xor ebx, edx bswap eax @@ -833,13 +846,13 @@ $L009ejend: bswap ebx mov DWORD PTR [edi],eax mov DWORD PTR 4[edi],ebx - jmp $L003finish -$L000decrypt: + jmp $L005finish +$L002decrypt: and ebp, 4294967288 mov eax, DWORD PTR 16[esp] mov ebx, DWORD PTR 20[esp] - jz $L013decrypt_finish -L014decrypt_loop: + jz $L015decrypt_finish +L016decrypt_loop: mov eax, DWORD PTR [esi] mov ebx, DWORD PTR 4[esi] bswap eax @@ -864,11 +877,11 @@ L014decrypt_loop: add esi, 8 add edi, 8 sub ebp, 8 - jnz L014decrypt_loop -$L013decrypt_finish: + jnz L016decrypt_loop +$L015decrypt_finish: mov ebp, DWORD PTR 52[esp] and ebp, 7 - jz $L003finish + jz $L005finish mov eax, DWORD PTR [esi] mov ebx, DWORD PTR 4[esi] bswap eax @@ -886,28 +899,28 @@ $L013decrypt_finish: xor edx, ebx mov eax, DWORD PTR [esi] mov ebx, DWORD PTR 4[esi] -L015dj7: +L017dj7: ror edx, 16 mov BYTE PTR 6[edi],dl shr edx, 16 -L016dj6: +L018dj6: mov BYTE PTR 5[edi],dh -L017dj5: +L019dj5: mov BYTE PTR 4[edi],dl -L018dj4: +L020dj4: mov DWORD PTR [edi],ecx - jmp $L019djend -L020dj3: + jmp $L021djend +L022dj3: ror ecx, 16 mov BYTE PTR 2[edi],cl shl ecx, 16 -L021dj2: +L023dj2: mov BYTE PTR 1[esi],ch -L022dj1: +L024dj1: mov BYTE PTR [esi], cl -$L019djend: - jmp $L003finish -$L003finish: +$L021djend: + jmp $L005finish +$L005finish: mov ecx, DWORD PTR 60[esp] add esp, 24 mov DWORD PTR [ecx],eax @@ -917,24 +930,24 @@ $L003finish: pop ebx pop ebp ret -$L004cbc_enc_jmp_table: +$L006cbc_enc_jmp_table: DD 0 - DD L012ej1 - DD L011ej2 - DD L010ej3 - DD L008ej4 - DD L007ej5 - DD L006ej6 - DD L005ej7 -L023cbc_dec_jmp_table: + DD L014ej1 + DD L013ej2 + DD L012ej3 + DD L010ej4 + DD L009ej5 + DD L008ej6 + DD L007ej7 +L025cbc_dec_jmp_table: DD 0 - DD L022dj1 - DD L021dj2 - DD L020dj3 - DD L018dj4 - DD L017dj5 - DD L016dj6 - DD L015dj7 + DD L024dj1 + DD L023dj2 + DD L022dj3 + DD L020dj4 + DD L019dj5 + DD L018dj6 + DD L017dj7 _CAST_cbc_encrypt ENDP _TEXT ENDS END diff --git a/src/lib/libcrypto/cast/asm/cast-586.pl b/src/lib/libcrypto/cast/asm/cast-586.pl index d0be004c99..6be0bfe572 100644 --- a/src/lib/libcrypto/cast/asm/cast-586.pl +++ b/src/lib/libcrypto/cast/asm/cast-586.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # define for pentium pro friendly version $ppro=1; @@ -7,7 +7,7 @@ push(@INC,"perlasm","../../perlasm"); require "x86asm.pl"; require "cbc.pl"; -&asm_init($ARGV[0],"cast-586.pl"); +&asm_init($ARGV[0],"cast-586.pl",$ARGV[$#ARGV] eq "386"); $CAST_ROUNDS=16; $L="edi"; @@ -32,136 +32,145 @@ $S4="CAST_S_table3"; &asm_finish(); -sub CAST_encrypt - { - local($name,$enc)=@_; +sub CAST_encrypt { + local($name,$enc)=@_; - local($win_ex)=<<"EOF"; + local($win_ex)=<<"EOF"; EXTERN _CAST_S_table0:DWORD EXTERN _CAST_S_table1:DWORD EXTERN _CAST_S_table2:DWORD EXTERN _CAST_S_table3:DWORD EOF - &main'external_label( - "CAST_S_table0", - "CAST_S_table1", - "CAST_S_table2", - "CAST_S_table3", - ); - - &function_begin_B($name,$win_ex); - - &comment(""); - - &push("ebp"); - &push("ebx"); - &mov($tmp2,&wparam(0)); - &mov($K,&wparam(1)); - &push("esi"); - &push("edi"); - - &comment("Load the 2 words"); - &mov($L,&DWP(0,$tmp2,"",0)); - &mov($R,&DWP(4,$tmp2,"",0)); - - &xor( $tmp3, $tmp3); - - # encrypting part - - if ($enc) - { - &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); - } - else - { - &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); - } - - &nop(); - &mov(&DWP(4,$tmp3,"",0),$L); - &mov(&DWP(0,$tmp3,"",0),$R); - &function_end($name); - } - -sub E_CAST - { - local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4,$lst)=@_; - # Ri needs to have 16 pre added. - - &comment("round $i"); - &mov( $tmp4, &DWP($i*8,$K,"",1)); - - &mov( $tmp1, &DWP($i*8+4,$K,"",1));# must be word - &$OP1( $tmp4, $R); - - &rotl( $tmp4, &LB($tmp1)); - - if ($ppro) - { - &mov( $tmp2, $tmp4); # B - &xor( $tmp1, $tmp1); - - &movb( &LB($tmp1), &HB($tmp4)); # A - &and( $tmp2, 0xff); - - &shr( $tmp4, 16); # - &xor( $tmp3, $tmp3); - } - else - { - &mov( $tmp2, $tmp4); # B - &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD - - &shr( $tmp4, 16); # - &and( $tmp2, 0xff); - } - - &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD - &and( $tmp4, 0xff); # D - - &mov( $tmp1, &DWP($S1,"",$tmp1,4)); - &mov( $tmp2, &DWP($S2,"",$tmp2,4)); - - &$OP2( $tmp1, $tmp2); - &mov( $tmp2, &DWP($S3,"",$tmp3,4)); - - &$OP3( $tmp1, $tmp2); - &mov( $tmp2, &DWP($S4,"",$tmp4,4)); - - &$OP1( $tmp1, $tmp2); - &mov($tmp3,&wparam(0)) if $lst; - # XXX - - &xor( $L, $tmp1); - # XXX - } + &main::external_label( + "CAST_S_table0", + "CAST_S_table1", + "CAST_S_table2", + "CAST_S_table3", + ); + + &function_begin_B($name,$win_ex); + + &comment(""); + + &push("ebp"); + &push("ebx"); + &mov($tmp2,&wparam(0)); + &mov($K,&wparam(1)); + &push("esi"); + &push("edi"); + + &comment("Load the 2 words"); + &mov($L,&DWP(0,$tmp2,"",0)); + &mov($R,&DWP(4,$tmp2,"",0)); + + &comment('Get short key flag'); + &mov($tmp3,&DWP(128,$K,"",0)); + if($enc) { + &push($tmp3); + } else { + &or($tmp3,$tmp3); + &jnz(&label('cast_dec_skip')); + } + + &xor($tmp3, $tmp3); + + # encrypting part + + if ($enc) { + &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &comment('test short key flag'); + &pop($tmp4); + &or($tmp4,$tmp4); + &jnz(&label('cast_enc_done')); + &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + } else { + &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &set_label('cast_dec_skip'); + &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + } + + &set_label('cast_enc_done') if $enc; +# Why the nop? - Ben 17/1/99 + &nop(); + &mov($tmp3,&wparam(0)); + &mov(&DWP(4,$tmp3,"",0),$L); + &mov(&DWP(0,$tmp3,"",0),$R); + &function_end($name); +} + +sub E_CAST { + local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4)=@_; + # Ri needs to have 16 pre added. + + &comment("round $i"); + &mov( $tmp4, &DWP($i*8,$K,"",1)); + + &mov( $tmp1, &DWP($i*8+4,$K,"",1)); + &$OP1( $tmp4, $R); + + &rotl( $tmp4, &LB($tmp1)); + + if ($ppro) { + &mov( $tmp2, $tmp4); # B + &xor( $tmp1, $tmp1); + + &movb( &LB($tmp1), &HB($tmp4)); # A + &and( $tmp2, 0xff); + + &shr( $tmp4, 16); # + &xor( $tmp3, $tmp3); + } else { + &mov( $tmp2, $tmp4); # B + &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD + + &shr( $tmp4, 16); # + &and( $tmp2, 0xff); + } + + &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD + &and( $tmp4, 0xff); # D + + &mov( $tmp1, &DWP($S1,"",$tmp1,4)); + &mov( $tmp2, &DWP($S2,"",$tmp2,4)); + + &$OP2( $tmp1, $tmp2); + &mov( $tmp2, &DWP($S3,"",$tmp3,4)); + + &$OP3( $tmp1, $tmp2); + &mov( $tmp2, &DWP($S4,"",$tmp4,4)); + + &$OP1( $tmp1, $tmp2); + # XXX + + &xor( $L, $tmp1); + # XXX +} + diff --git a/src/lib/libcrypto/cast/asm/cx86unix.cpp b/src/lib/libcrypto/cast/asm/cx86unix.cpp deleted file mode 100644 index 035692a5af..0000000000 --- a/src/lib/libcrypto/cast/asm/cx86unix.cpp +++ /dev/null @@ -1,1010 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define CAST_S_table0 _CAST_S_table0 -#define CAST_S_table1 _CAST_S_table1 -#define CAST_S_table2 _CAST_S_table2 -#define CAST_S_table3 _CAST_S_table3 -#define CAST_encrypt _CAST_encrypt -#define CAST_S_table0 _CAST_S_table0 -#define CAST_S_table1 _CAST_S_table1 -#define CAST_S_table2 _CAST_S_table2 -#define CAST_S_table3 _CAST_S_table3 -#define CAST_decrypt _CAST_decrypt -#define CAST_cbc_encrypt _CAST_cbc_encrypt - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by cast-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "cast-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl CAST_encrypt - TYPE(CAST_encrypt,@function) -CAST_encrypt: - - pushl %ebp - pushl %ebx - movl 12(%esp), %ebx - movl 16(%esp), %ebp - pushl %esi - pushl %edi - /* Load the 2 words */ - movl (%ebx), %edi - movl 4(%ebx), %esi - xorl %eax, %eax - /* round 0 */ - movl (%ebp), %edx - movl 4(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 1 */ - movl 8(%ebp), %edx - movl 12(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 2 */ - movl 16(%ebp), %edx - movl 20(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 3 */ - movl 24(%ebp), %edx - movl 28(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %esi - /* round 4 */ - movl 32(%ebp), %edx - movl 36(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 5 */ - movl 40(%ebp), %edx - movl 44(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 6 */ - movl 48(%ebp), %edx - movl 52(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 7 */ - movl 56(%ebp), %edx - movl 60(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 8 */ - movl 64(%ebp), %edx - movl 68(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 9 */ - movl 72(%ebp), %edx - movl 76(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %esi - /* round 10 */ - movl 80(%ebp), %edx - movl 84(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 11 */ - movl 88(%ebp), %edx - movl 92(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 12 */ - movl 96(%ebp), %edx - movl 100(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 13 */ - movl 104(%ebp), %edx - movl 108(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 14 */ - movl 112(%ebp), %edx - movl 116(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 15 */ - movl 120(%ebp), %edx - movl 124(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - movl 20(%esp), %eax - xorl %ecx, %esi - nop - movl %edi, 4(%eax) - movl %esi, (%eax) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.CAST_encrypt_end: - SIZE(CAST_encrypt,.CAST_encrypt_end-CAST_encrypt) -.ident "CAST_encrypt" -.text - .align ALIGN -.globl CAST_decrypt - TYPE(CAST_decrypt,@function) -CAST_decrypt: - - pushl %ebp - pushl %ebx - movl 12(%esp), %ebx - movl 16(%esp), %ebp - pushl %esi - pushl %edi - /* Load the 2 words */ - movl (%ebx), %edi - movl 4(%ebx), %esi - xorl %eax, %eax - /* round 15 */ - movl 120(%ebp), %edx - movl 124(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 14 */ - movl 112(%ebp), %edx - movl 116(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 13 */ - movl 104(%ebp), %edx - movl 108(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 12 */ - movl 96(%ebp), %edx - movl 100(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %esi - /* round 11 */ - movl 88(%ebp), %edx - movl 92(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 10 */ - movl 80(%ebp), %edx - movl 84(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 9 */ - movl 72(%ebp), %edx - movl 76(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 8 */ - movl 64(%ebp), %edx - movl 68(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 7 */ - movl 56(%ebp), %edx - movl 60(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 6 */ - movl 48(%ebp), %edx - movl 52(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %esi - /* round 5 */ - movl 40(%ebp), %edx - movl 44(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 4 */ - movl 32(%ebp), %edx - movl 36(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 3 */ - movl 24(%ebp), %edx - movl 28(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 2 */ - movl 16(%ebp), %edx - movl 20(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 1 */ - movl 8(%ebp), %edx - movl 12(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 0 */ - movl (%ebp), %edx - movl 4(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - movl 20(%esp), %eax - xorl %ecx, %esi - nop - movl %edi, 4(%eax) - movl %esi, (%eax) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.CAST_decrypt_end: - SIZE(CAST_decrypt,.CAST_decrypt_end-CAST_decrypt) -.ident "CAST_decrypt" -.text - .align ALIGN -.globl CAST_cbc_encrypt - TYPE(CAST_cbc_encrypt,@function) -CAST_cbc_encrypt: - - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - movl 28(%esp), %ebp - /* getting iv ptr from parameter 4 */ - movl 36(%esp), %ebx - movl (%ebx), %esi - movl 4(%ebx), %edi - pushl %edi - pushl %esi - pushl %edi - pushl %esi - movl %esp, %ebx - movl 36(%esp), %esi - movl 40(%esp), %edi - /* getting encrypt flag from parameter 5 */ - movl 56(%esp), %ecx - /* get and push parameter 3 */ - movl 48(%esp), %eax - pushl %eax - pushl %ebx - cmpl $0, %ecx - jz .L000decrypt - andl $4294967288, %ebp - movl 8(%esp), %eax - movl 12(%esp), %ebx - jz .L001encrypt_finish -.L002encrypt_loop: - movl (%esi), %ecx - movl 4(%esi), %edx - xorl %ecx, %eax - xorl %edx, %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call CAST_encrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, (%edi) - movl %ebx, 4(%edi) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L002encrypt_loop -.L001encrypt_finish: - movl 52(%esp), %ebp - andl $7, %ebp - jz .L003finish - xorl %ecx, %ecx - xorl %edx, %edx - movl .L004cbc_enc_jmp_table(,%ebp,4),%ebp - jmp *%ebp -.L005ej7: - xorl %edx, %edx - movb 6(%esi), %dh - sall $8, %edx -.L006ej6: - movb 5(%esi), %dh -.L007ej5: - movb 4(%esi), %dl -.L008ej4: - movl (%esi), %ecx - jmp .L009ejend -.L010ej3: - movb 2(%esi), %ch - xorl %ecx, %ecx - sall $8, %ecx -.L011ej2: - movb 1(%esi), %ch -.L012ej1: - movb (%esi), %cl -.L009ejend: - xorl %ecx, %eax - xorl %edx, %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call CAST_encrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, (%edi) - movl %ebx, 4(%edi) - jmp .L003finish -.align ALIGN -.L000decrypt: - andl $4294967288, %ebp - movl 16(%esp), %eax - movl 20(%esp), %ebx - jz .L013decrypt_finish -.L014decrypt_loop: - movl (%esi), %eax - movl 4(%esi), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call CAST_decrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl 16(%esp), %ecx - movl 20(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx - movl %ecx, (%edi) - movl %edx, 4(%edi) - movl %eax, 16(%esp) - movl %ebx, 20(%esp) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L014decrypt_loop -.L013decrypt_finish: - movl 52(%esp), %ebp - andl $7, %ebp - jz .L003finish - movl (%esi), %eax - movl 4(%esi), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call CAST_decrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx -.byte 15 -.byte 200 /* bswapl %eax */ -.byte 15 -.byte 203 /* bswapl %ebx */ - movl 16(%esp), %ecx - movl 20(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx -.L015dj7: - rorl $16, %edx - movb %dl, 6(%edi) - shrl $16, %edx -.L016dj6: - movb %dh, 5(%edi) -.L017dj5: - movb %dl, 4(%edi) -.L018dj4: - movl %ecx, (%edi) - jmp .L019djend -.L020dj3: - rorl $16, %ecx - movb %cl, 2(%edi) - sall $16, %ecx -.L021dj2: - movb %ch, 1(%esi) -.L022dj1: - movb %cl, (%esi) -.L019djend: - jmp .L003finish -.align ALIGN -.L003finish: - movl 60(%esp), %ecx - addl $24, %esp - movl %eax, (%ecx) - movl %ebx, 4(%ecx) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.align ALIGN -.L004cbc_enc_jmp_table: - .long 0 - .long .L012ej1 - .long .L011ej2 - .long .L010ej3 - .long .L008ej4 - .long .L007ej5 - .long .L006ej6 - .long .L005ej7 -.align ALIGN -.L023cbc_dec_jmp_table: - .long 0 - .long .L022dj1 - .long .L021dj2 - .long .L020dj3 - .long .L018dj4 - .long .L017dj5 - .long .L016dj6 - .long .L015dj7 -.CAST_cbc_encrypt_end: - SIZE(CAST_cbc_encrypt,.CAST_cbc_encrypt_end-CAST_cbc_encrypt) -.ident "desasm.pl" diff --git a/src/lib/libcrypto/cast/c_cfb64.c b/src/lib/libcrypto/cast/c_cfb64.c index c46c375f75..514c005c32 100644 --- a/src/lib/libcrypto/cast/c_cfb64.c +++ b/src/lib/libcrypto/cast/c_cfb64.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include #include "cast_lcl.h" /* The input and output encrypted as though 64bit cfb mode is being @@ -64,14 +64,9 @@ * 64bit block we have used is contained in *num; */ -void CAST_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) -unsigned char *in; -unsigned char *out; -long length; -CAST_KEY *schedule; -unsigned char *ivec; -int *num; -int encrypt; +void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num, int enc) { register CAST_LONG v0,v1,t; register int n= *num; @@ -79,8 +74,8 @@ int encrypt; CAST_LONG ti[2]; unsigned char *iv,c,cc; - iv=(unsigned char *)ivec; - if (encrypt) + iv=ivec; + if (enc) { while (l--) { @@ -89,10 +84,10 @@ int encrypt; n2l(iv,v0); ti[0]=v0; n2l(iv,v1); ti[1]=v1; CAST_encrypt((CAST_LONG *)ti,schedule); - iv=(unsigned char *)ivec; + iv=ivec; t=ti[0]; l2n(t,iv); t=ti[1]; l2n(t,iv); - iv=(unsigned char *)ivec; + iv=ivec; } c= *(in++)^iv[n]; *(out++)=c; @@ -109,10 +104,10 @@ int encrypt; n2l(iv,v0); ti[0]=v0; n2l(iv,v1); ti[1]=v1; CAST_encrypt((CAST_LONG *)ti,schedule); - iv=(unsigned char *)ivec; + iv=ivec; t=ti[0]; l2n(t,iv); t=ti[1]; l2n(t,iv); - iv=(unsigned char *)ivec; + iv=ivec; } cc= *(in++); c=iv[n]; diff --git a/src/lib/libcrypto/cast/c_ecb.c b/src/lib/libcrypto/cast/c_ecb.c index f0f2f4df0e..33182f2b71 100644 --- a/src/lib/libcrypto/cast/c_ecb.c +++ b/src/lib/libcrypto/cast/c_ecb.c @@ -56,22 +56,20 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include #include "cast_lcl.h" +#include -char *CAST_version="CAST part of SSLeay 0.9.0b 29-Jun-1998"; +char *CAST_version="CAST" OPENSSL_VERSION_PTEXT; -void CAST_ecb_encrypt(in, out, ks, encrypt) -unsigned char *in; -unsigned char *out; -CAST_KEY *ks; -int encrypt; +void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, + CAST_KEY *ks, int enc) { CAST_LONG l,d[2]; n2l(in,l); d[0]=l; n2l(in,l); d[1]=l; - if (encrypt) + if (enc) CAST_encrypt(d,ks); else CAST_decrypt(d,ks); diff --git a/src/lib/libcrypto/cast/c_enc.c b/src/lib/libcrypto/cast/c_enc.c index d998dd4953..0fe2cffecc 100644 --- a/src/lib/libcrypto/cast/c_enc.c +++ b/src/lib/libcrypto/cast/c_enc.c @@ -56,12 +56,10 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include #include "cast_lcl.h" -void CAST_encrypt(data,key) -CAST_LONG *data; -CAST_KEY *key; +void CAST_encrypt(CAST_LONG *data, CAST_KEY *key) { register CAST_LONG l,r,*k,t; @@ -81,18 +79,19 @@ CAST_KEY *key; E_CAST( 9,k,r,l,+,^,-); E_CAST(10,k,l,r,^,-,+); E_CAST(11,k,r,l,-,+,^); - E_CAST(12,k,l,r,+,^,-); - E_CAST(13,k,r,l,^,-,+); - E_CAST(14,k,l,r,-,+,^); - E_CAST(15,k,r,l,+,^,-); + if(!key->short_key) + { + E_CAST(12,k,l,r,+,^,-); + E_CAST(13,k,r,l,^,-,+); + E_CAST(14,k,l,r,-,+,^); + E_CAST(15,k,r,l,+,^,-); + } data[1]=l&0xffffffffL; data[0]=r&0xffffffffL; } -void CAST_decrypt(data,key) -CAST_LONG *data; -CAST_KEY *key; +void CAST_decrypt(CAST_LONG *data, CAST_KEY *key) { register CAST_LONG l,r,*k,t; @@ -100,10 +99,13 @@ CAST_KEY *key; l=data[0]; r=data[1]; - E_CAST(15,k,l,r,+,^,-); - E_CAST(14,k,r,l,-,+,^); - E_CAST(13,k,l,r,^,-,+); - E_CAST(12,k,r,l,+,^,-); + if(!key->short_key) + { + E_CAST(15,k,l,r,+,^,-); + E_CAST(14,k,r,l,-,+,^); + E_CAST(13,k,l,r,^,-,+); + E_CAST(12,k,r,l,+,^,-); + } E_CAST(11,k,l,r,-,+,^); E_CAST(10,k,r,l,^,-,+); E_CAST( 9,k,l,r,+,^,-); @@ -121,20 +123,15 @@ CAST_KEY *key; data[0]=r&0xffffffffL; } -void CAST_cbc_encrypt(in, out, length, ks, iv, encrypt) -unsigned char *in; -unsigned char *out; -long length; -CAST_KEY *ks; -unsigned char *iv; -int encrypt; +void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + CAST_KEY *ks, unsigned char *iv, int enc) { register CAST_LONG tin0,tin1; register CAST_LONG tout0,tout1,xor0,xor1; register long l=length; CAST_LONG tin[2]; - if (encrypt) + if (enc) { n2l(iv,tout0); n2l(iv,tout1); diff --git a/src/lib/libcrypto/cast/c_ofb64.c b/src/lib/libcrypto/cast/c_ofb64.c index 2aad2d6d96..fd0469a62f 100644 --- a/src/lib/libcrypto/cast/c_ofb64.c +++ b/src/lib/libcrypto/cast/c_ofb64.c @@ -56,20 +56,16 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include #include "cast_lcl.h" /* The input and output encrypted as though 64bit ofb mode is being * used. The extra state information to record how much of the * 64bit block we have used is contained in *num; */ -void CAST_ofb64_encrypt(in, out, length, schedule, ivec, num) -unsigned char *in; -unsigned char *out; -long length; -CAST_KEY *schedule; -unsigned char *ivec; -int *num; +void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num) { register CAST_LONG v0,v1,t; register int n= *num; @@ -80,7 +76,7 @@ int *num; unsigned char *iv; int save=0; - iv=(unsigned char *)ivec; + iv=ivec; n2l(iv,v0); n2l(iv,v1); ti[0]=v0; @@ -105,7 +101,7 @@ int *num; { v0=ti[0]; v1=ti[1]; - iv=(unsigned char *)ivec; + iv=ivec; l2n(v0,iv); l2n(v1,iv); } diff --git a/src/lib/libcrypto/cast/c_skey.c b/src/lib/libcrypto/cast/c_skey.c index 2fc3363dcd..acf2c3eeb5 100644 --- a/src/lib/libcrypto/cast/c_skey.c +++ b/src/lib/libcrypto/cast/c_skey.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include #include "cast_lcl.h" #include "cast_s.h" @@ -72,10 +72,7 @@ #define S6 CAST_S_table6 #define S7 CAST_S_table7 -void CAST_set_key(key,len,data) -CAST_KEY *key; -int len; -unsigned char *data; +void CAST_set_key(CAST_KEY *key, int len, unsigned char *data) { CAST_LONG x[16]; CAST_LONG z[16]; @@ -88,6 +85,10 @@ unsigned char *data; if (len > 16) len=16; for (i=0; ishort_key=1; + else + key->short_key=0; K= &k[0]; X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL; diff --git a/src/lib/libcrypto/cast/cast.h b/src/lib/libcrypto/cast/cast.h index 528cb7c824..6cc5e8aa8c 100644 --- a/src/lib/libcrypto/cast/cast.h +++ b/src/lib/libcrypto/cast/cast.h @@ -63,6 +63,10 @@ extern "C" { #endif +#ifdef NO_CAST +#error CAST is disabled. +#endif + #define CAST_ENCRYPT 1 #define CAST_DECRYPT 0 @@ -74,33 +78,23 @@ extern "C" { typedef struct cast_key_st { CAST_LONG data[32]; + int short_key; /* Use reduced rounds for short key */ } CAST_KEY; -#ifndef NOPROTO void CAST_set_key(CAST_KEY *key, int len, unsigned char *data); -void CAST_ecb_encrypt(unsigned char *in,unsigned char *out,CAST_KEY *key, - int enc); +void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key, + int enc); void CAST_encrypt(CAST_LONG *data,CAST_KEY *key); void CAST_decrypt(CAST_LONG *data,CAST_KEY *key); -void CAST_cbc_encrypt(unsigned char *in, unsigned char *out, long length, - CAST_KEY *ks, unsigned char *iv, int enc); -void CAST_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, - CAST_KEY *schedule, unsigned char *ivec, int *num, int enc); -void CAST_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, - CAST_KEY *schedule, unsigned char *ivec, int *num); - -#else - -void CAST_set_key(); -void CAST_ecb_encrypt(); -void CAST_encrypt(); -void CAST_decrypt(); -void CAST_cbc_encrypt(); -void CAST_cfb64_encrypt(); -void CAST_ofb64_encrypt(); - -#endif +void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + CAST_KEY *ks, unsigned char *iv, int enc); +void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num, int enc); +void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num); #ifdef __cplusplus } diff --git a/src/lib/libcrypto/cast/cast_lcl.h b/src/lib/libcrypto/cast/cast_lcl.h index 6587952a96..83cf382a91 100644 --- a/src/lib/libcrypto/cast/cast_lcl.h +++ b/src/lib/libcrypto/cast/cast_lcl.h @@ -60,6 +60,9 @@ #include #endif + +#include "openssl/e_os.h" /* OPENSSL_EXTERN */ + #undef c2l #define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ l|=((unsigned long)(*((c)++)))<< 8L, \ @@ -213,12 +216,11 @@ } #endif -extern CAST_LONG CAST_S_table0[256]; -extern CAST_LONG CAST_S_table1[256]; -extern CAST_LONG CAST_S_table2[256]; -extern CAST_LONG CAST_S_table3[256]; -extern CAST_LONG CAST_S_table4[256]; -extern CAST_LONG CAST_S_table5[256]; -extern CAST_LONG CAST_S_table6[256]; -extern CAST_LONG CAST_S_table7[256]; - +OPENSSL_EXTERN CAST_LONG CAST_S_table0[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table1[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table2[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table3[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table4[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table5[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table6[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table7[256]; diff --git a/src/lib/libcrypto/cast/cast_s.h b/src/lib/libcrypto/cast/cast_s.h index 8fe0152149..9af28972c5 100644 --- a/src/lib/libcrypto/cast/cast_s.h +++ b/src/lib/libcrypto/cast/cast_s.h @@ -55,7 +55,7 @@ * copied and put under another distribution licence * [including the GNU Public Licence.] */ -CAST_LONG CAST_S_table0[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table0[256]={ 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a, 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949, 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675, @@ -121,7 +121,7 @@ CAST_LONG CAST_S_table0[256]={ 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d, 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf, }; -CAST_LONG CAST_S_table1[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table1[256]={ 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380, 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651, 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba, @@ -187,7 +187,7 @@ CAST_LONG CAST_S_table1[256]={ 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef, 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1, }; -CAST_LONG CAST_S_table2[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table2[256]={ 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907, 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90, 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae, @@ -253,7 +253,7 @@ CAST_LONG CAST_S_table2[256]={ 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5, 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783, }; -CAST_LONG CAST_S_table3[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table3[256]={ 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298, 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1, 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120, @@ -319,7 +319,7 @@ CAST_LONG CAST_S_table3[256]={ 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e, 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2, }; -CAST_LONG CAST_S_table4[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table4[256]={ 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911, 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f, 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00, @@ -385,7 +385,7 @@ CAST_LONG CAST_S_table4[256]={ 0xe822fe15,0x88570983,0x750e6249,0xda627e55, 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4, }; -CAST_LONG CAST_S_table5[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table5[256]={ 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c, 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac, 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9, @@ -451,7 +451,7 @@ CAST_LONG CAST_S_table5[256]={ 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454, 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f, }; -CAST_LONG CAST_S_table6[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table6[256]={ 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693, 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f, 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82, @@ -517,7 +517,7 @@ CAST_LONG CAST_S_table6[256]={ 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada, 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3, }; -CAST_LONG CAST_S_table7[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table7[256]={ 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095, 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5, 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174, diff --git a/src/lib/libcrypto/cast/cast_spd.c b/src/lib/libcrypto/cast/cast_spd.c index ab75e65386..c0726906c2 100644 --- a/src/lib/libcrypto/cast/cast_spd.c +++ b/src/lib/libcrypto/cast/cast_spd.c @@ -59,19 +59,17 @@ /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include -#ifndef MSDOS -#include -#else -#include -extern int exit(); -#endif + +#include +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include -#ifndef VMS #ifndef _IRIX #include #endif @@ -79,34 +77,31 @@ extern int exit(); #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "cast.h" +#include /* The following if from times(3) man page. It may need to be changed */ #ifndef HZ #ifndef CLK_TCK -#ifndef VMS -#define HZ 100.0 -#else /* VMS */ #define HZ 100.0 -#endif #else /* CLK_TCK */ #define HZ ((double)CLK_TCK) #endif @@ -115,12 +110,7 @@ struct tms { #define BUFSIZE ((long)1024) long run=0; -#ifndef NOPROTO double Time_F(int s); -#else -double Time_F(); -#endif - #ifdef SIGALRM #if defined(__STDC__) || defined(sgi) || defined(_AIX) #define SIGRETTYPE void @@ -128,14 +118,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -148,8 +132,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -185,9 +168,7 @@ int s; #endif } -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; diff --git a/src/lib/libcrypto/cast/castopts.c b/src/lib/libcrypto/cast/castopts.c index 68cf5a4a60..642e9725af 100644 --- a/src/lib/libcrypto/cast/castopts.c +++ b/src/lib/libcrypto/cast/castopts.c @@ -59,19 +59,17 @@ /* define PART1, PART2, PART3 or PART4 to build only with a few of the options. * This is for machines with 64k code segment size restrictions. */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include -#ifndef MSDOS -#include -#else -#include -extern void exit(); -#endif + +#include +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include -#ifndef VMS #ifndef _IRIX #include #endif @@ -79,25 +77,26 @@ extern void exit(); #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "cast.h" +#include #define CAST_DEFAULT_OPTIONS @@ -136,11 +135,7 @@ struct tms { #ifndef HZ # ifndef CLK_TCK # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ -# ifndef VMS -# define HZ 100.0 -# else /* VMS */ -# define HZ 100.0 -# endif +# define HZ 100.0 # else /* _BSD_CLK_TCK_ */ # define HZ ((double)_BSD_CLK_TCK_) # endif @@ -152,12 +147,7 @@ struct tms { #define BUFSIZE ((long)1024) long run=0; -#ifndef NOPROTO double Time_F(int s); -#else -double Time_F(); -#endif - #ifdef SIGALRM #if defined(__STDC__) || defined(sgi) #define SIGRETTYPE void @@ -165,14 +155,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -185,8 +169,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -247,9 +230,7 @@ int s; fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ tm[index]*8,1.0e6/tm[index]); -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; diff --git a/src/lib/libcrypto/cast/casts.cpp b/src/lib/libcrypto/cast/casts.cpp index bac7be2c9c..8d7bd468d2 100644 --- a/src/lib/libcrypto/cast/casts.cpp +++ b/src/lib/libcrypto/cast/casts.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include #include -#include "cast.h" +#include void main(int argc,char *argv[]) { diff --git a/src/lib/libcrypto/cast/casttest.c b/src/lib/libcrypto/cast/casttest.c index 8b009bc249..3244b119e9 100644 --- a/src/lib/libcrypto/cast/casttest.c +++ b/src/lib/libcrypto/cast/casttest.c @@ -59,9 +59,17 @@ #include #include #include -#include "cast.h" -/* #define FULL_TEST */ +#ifdef NO_CAST +int main(int argc, char *argv[]) +{ + printf("No CAST support\n"); + return(0); +} +#else +#include + +#define FULL_TEST unsigned char k[16]={ 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, @@ -70,7 +78,7 @@ unsigned char k[16]={ unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; -int k_len[3]={16,10}; +int k_len[3]={16,10,5}; unsigned char c[3][8]={ {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, @@ -120,104 +128,103 @@ static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ }; #endif -int main(argc,argv) -int argc; -char *argv[]; - { +int main(int argc, char *argv[]) + { #ifdef FULL_TEST - long l; - CAST_KEY key_b; + long l; + CAST_KEY key_b; #endif - int i,z,err=0; - CAST_KEY key; + int i,z,err=0; + CAST_KEY key; - for (z=0; z<1; z++) - { + for (z=0; z<3; z++) + { CAST_set_key(&key,k_len[z],k); CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT); if (memcmp(out,&(c[z][0]),8) != 0) - { - printf("ecb cast error encrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",c[z][i]); - err=20; - printf("\n"); - } + { + printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8); + printf("got :"); + for (i=0; i<8; i++) + printf("%02X ",out[i]); + printf("\n"); + printf("expected:"); + for (i=0; i<8; i++) + printf("%02X ",c[z][i]); + err=20; + printf("\n"); + } CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT); if (memcmp(out,in,8) != 0) - { - printf("ecb cast error decrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",in[i]); - printf("\n"); - err=3; - } + { + printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8); + printf("got :"); + for (i=0; i<8; i++) + printf("%02X ",out[i]); + printf("\n"); + printf("expected:"); + for (i=0; i<8; i++) + printf("%02X ",in[i]); + printf("\n"); + err=3; + } } - if (err == 0) printf("ecb cast5 ok\n"); + if (err == 0) + printf("ecb cast5 ok\n"); #ifdef FULL_TEST - { - unsigned char out_a[16],out_b[16]; - static char *hex="0123456789ABCDEF"; - - printf("This test will take some time...."); - fflush(stdout); - memcpy(out_a,in_a,sizeof(in_a)); - memcpy(out_b,in_b,sizeof(in_b)); - i=1; - - for (l=0; l<1000000L; l++) - { - CAST_set_key(&key_b,16,out_b); - CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); - CAST_set_key(&key,16,out_a); - CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); - if ((l & 0xffff) == 0xffff) - { - printf("%c",hex[i&0x0f]); - fflush(stdout); - i++; - } - } - - if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || + { + unsigned char out_a[16],out_b[16]; + static char *hex="0123456789ABCDEF"; + + printf("This test will take some time...."); + fflush(stdout); + memcpy(out_a,in_a,sizeof(in_a)); + memcpy(out_b,in_b,sizeof(in_b)); + i=1; + + for (l=0; l<1000000L; l++) + { + CAST_set_key(&key_b,16,out_b); + CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); + CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); + CAST_set_key(&key,16,out_a); + CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); + CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); + if ((l & 0xffff) == 0xffff) + { + printf("%c",hex[i&0x0f]); + fflush(stdout); + i++; + } + } + + if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || (memcmp(out_b,c_b,sizeof(c_b)) != 0)) - { - printf("\n"); - printf("Error\n"); - - printf("A out ="); - for (i=0; i<16; i++) printf("%02X ",out_a[i]); - printf("\nactual="); - for (i=0; i<16; i++) printf("%02X ",c_a[i]); - printf("\n"); - - printf("B out ="); - for (i=0; i<16; i++) printf("%02X ",out_b[i]); - printf("\nactual="); - for (i=0; i<16; i++) printf("%02X ",c_b[i]); - printf("\n"); - } - else - printf(" ok\n"); - } + { + printf("\n"); + printf("Error\n"); + + printf("A out ="); + for (i=0; i<16; i++) printf("%02X ",out_a[i]); + printf("\nactual="); + for (i=0; i<16; i++) printf("%02X ",c_a[i]); + printf("\n"); + + printf("B out ="); + for (i=0; i<16; i++) printf("%02X ",out_b[i]); + printf("\nactual="); + for (i=0; i<16; i++) printf("%02X ",c_b[i]); + printf("\n"); + } + else + printf(" ok\n"); + } #endif - exit(err); - return(err); - } - + exit(err); + return(err); + } +#endif diff --git a/src/lib/libcrypto/conf/Makefile.ssl b/src/lib/libcrypto/conf/Makefile.ssl index 00e917aa44..64b763f068 100644 --- a/src/lib/libcrypto/conf/Makefile.ssl +++ b/src/lib/libcrypto/conf/Makefile.ssl @@ -7,24 +7,24 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=conf -ERRC=conf_err GENERAL=Makefile TEST= APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= conf.c $(ERRC).c +LIBSRC= conf.c conf_err.c -LIBOBJ= conf.o $(ERRC).o +LIBOBJ= conf.o conf_err.o SRC= $(LIBSRC) @@ -40,24 +40,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -69,17 +68,25 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +conf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +conf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +conf.o: ../../include/openssl/err.h ../../include/openssl/lhash.h +conf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +conf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +conf.o: ../cryptlib.h conf_lcl.h +conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h +conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/err.h +conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslv.h +conf_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h diff --git a/src/lib/libcrypto/conf/cnf_save.c b/src/lib/libcrypto/conf/cnf_save.c index c9018de10e..e907cc2242 100644 --- a/src/lib/libcrypto/conf/cnf_save.c +++ b/src/lib/libcrypto/conf/cnf_save.c @@ -57,7 +57,7 @@ */ #include -#include "conf.h" +#include void print_conf(CONF_VALUE *cv); @@ -66,7 +66,7 @@ main() LHASH *conf; long l; - conf=CONF_load(NULL,"../../apps/ssleay.cnf",&l); + conf=CONF_load(NULL,"../../apps/openssl.cnf",&l); if (conf == NULL) { fprintf(stderr,"error loading config, line %ld\n",l); @@ -77,8 +77,7 @@ main() } -void print_conf(cv) -CONF_VALUE *cv; +void print_conf(CONF_VALUE *cv) { int i; CONF_VALUE *v; diff --git a/src/lib/libcrypto/conf/conf.c b/src/lib/libcrypto/conf/conf.c index 9e84300c5e..7d8b89168a 100644 --- a/src/lib/libcrypto/conf/conf.c +++ b/src/lib/libcrypto/conf/conf.c @@ -59,19 +59,18 @@ #include #include #include "cryptlib.h" -#include "stack.h" -#include "lhash.h" -#include "conf.h" -#include "buffer.h" -#include "err.h" +#include +#include +#include +#include +#include #include "conf_lcl.h" -#ifndef NOPROTO static void value_free_hash(CONF_VALUE *a, LHASH *conf); static void value_free_stack(CONF_VALUE *a,LHASH *conf); static unsigned long hash(CONF_VALUE *v); -static int cmp(CONF_VALUE *a,CONF_VALUE *b); +static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b); static char *eat_ws(char *p); static char *eat_alpha_numeric(char *p); static void clear_comments(char *p); @@ -79,71 +78,84 @@ static int str_copy(LHASH *conf,char *section,char **to, char *from); static char *scan_quote(char *p); static CONF_VALUE *new_section(LHASH *conf,char *section); static CONF_VALUE *get_section(LHASH *conf,char *section); +#define scan_esc(p) ((((p)[1] == '\0')?(p++):(p+=2)),p) + +const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT; + + +LHASH *CONF_load(LHASH *h, const char *file, long *line) + { + LHASH *ltmp; + FILE *in=NULL; + +#ifdef VMS + in=fopen(file,"r"); #else -static void value_free_hash(); -static void value_free_stack(); -static unsigned long hash(); -static int cmp(); -static char *eat_ws(); -static char *eat_alpha_numeric(); -static void clear_comments(); -static int str_copy(); -static char *scan_quote(); -static CONF_VALUE *new_section(); -static CONF_VALUE *get_section(); + in=fopen(file,"rb"); #endif + if (in == NULL) + { + SYSerr(SYS_F_FOPEN,get_last_sys_error()); + ERR_set_error_data(BUF_strdup(file), + ERR_TXT_MALLOCED|ERR_TXT_STRING); + CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB); + return NULL; + } -#define scan_esc(p) ((*(++p) == '\0')?(p):(++p)) + ltmp = CONF_load_fp(h, in, line); + fclose(in); -char *CONF_version="CONF part of SSLeay 0.9.0b 29-Jun-1998"; + return ltmp; +} + +LHASH *CONF_load_fp(LHASH *h, FILE *in, long *line) +{ + BIO *btmp; + LHASH *ltmp; + if(!(btmp = BIO_new_fp(in, BIO_NOCLOSE))) { + CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB); + return NULL; + } + ltmp = CONF_load_bio(h, btmp, line); + BIO_free(btmp); + return ltmp; +} -LHASH *CONF_load(h,file,line) -LHASH *h; -char *file; -long *line; +LHASH *CONF_load_bio(LHASH *h, BIO *in, long *line) { LHASH *ret=NULL; - FILE *in=NULL; #define BUFSIZE 512 + char btmp[16]; int bufnum=0,i,ii; BUF_MEM *buff=NULL; char *s,*p,*end; - int again,n,eline=0; + int again,n; + long eline=0; CONF_VALUE *v=NULL,*vv,*tv; CONF_VALUE *sv=NULL; char *section=NULL,*buf; - STACK *section_sk=NULL,*ts; + STACK_OF(CONF_VALUE) *section_sk=NULL,*ts; char *start,*psection,*pname; if ((buff=BUF_MEM_new()) == NULL) { - CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB); - goto err; - } - - in=fopen(file,"rb"); - if (in == NULL) - { - SYSerr(SYS_F_FOPEN,get_last_sys_error()); - ERR_set_error_data(BUF_strdup(file), - ERR_TXT_MALLOCED|ERR_TXT_STRING); - CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB); + CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB); goto err; } section=(char *)Malloc(10); if (section == NULL) { - CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); + CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE); goto err; } strcpy(section,"default"); if (h == NULL) { - if ((ret=lh_new(hash,cmp)) == NULL) + if ((ret=lh_new(hash,cmp_conf)) == NULL) { - CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); + CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE); goto err; } } @@ -153,10 +165,11 @@ long *line; sv=new_section(ret,section); if (sv == NULL) { - CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION); + CONFerr(CONF_F_CONF_LOAD_BIO, + CONF_R_UNABLE_TO_CREATE_NEW_SECTION); goto err; } - section_sk=(STACK *)sv->value; + section_sk=(STACK_OF(CONF_VALUE) *)sv->value; bufnum=0; for (;;) @@ -164,12 +177,12 @@ long *line; again=0; if (!BUF_MEM_grow(buff,bufnum+BUFSIZE)) { - CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB); + CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB); goto err; } p= &(buff->data[bufnum]); *p='\0'; - fgets(p,BUFSIZE-1,in); + BIO_gets(in, p, BUFSIZE-1); p[BUFSIZE-1]='\0'; ii=i=strlen(p); if (i == 0) break; @@ -219,13 +232,23 @@ long *line; if (IS_EOF(*s)) continue; /* blank line */ if (*s == '[') { + char *ss; + s++; start=eat_ws(s); - end=eat_alpha_numeric(start); + ss=start; +again: + end=eat_alpha_numeric(ss); p=eat_ws(end); if (*p != ']') { - CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_CLOSE_SQUARE_BRACKET); + if (*p != '\0') + { + ss=p; + goto again; + } + CONFerr(CONF_F_CONF_LOAD_BIO, + CONF_R_MISSING_CLOSE_SQUARE_BRACKET); goto err; } *end='\0'; @@ -234,10 +257,11 @@ long *line; sv=new_section(ret,section); if (sv == NULL) { - CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION); + CONFerr(CONF_F_CONF_LOAD_BIO, + CONF_R_UNABLE_TO_CREATE_NEW_SECTION); goto err; } - section_sk=(STACK *)sv->value; + section_sk=(STACK_OF(CONF_VALUE) *)sv->value; continue; } else @@ -256,7 +280,8 @@ long *line; p=eat_ws(end); if (*p != '=') { - CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_EQUAL_SIGN); + CONFerr(CONF_F_CONF_LOAD_BIO, + CONF_R_MISSING_EQUAL_SIGN); goto err; } *end='\0'; @@ -270,9 +295,10 @@ long *line; p++; *p='\0'; - if ((v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))) == NULL) + if (!(v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE)))) { - CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); + CONFerr(CONF_F_CONF_LOAD_BIO, + ERR_R_MALLOC_FAILURE); goto err; } if (psection == NULL) psection=section; @@ -280,7 +306,8 @@ long *line; v->value=NULL; if (v->name == NULL) { - CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); + CONFerr(CONF_F_CONF_LOAD_BIO, + ERR_R_MALLOC_FAILURE); goto err; } strcpy(v->name,pname); @@ -293,10 +320,11 @@ long *line; tv=new_section(ret,psection); if (tv == NULL) { - CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION); + CONFerr(CONF_F_CONF_LOAD_BIO, + CONF_R_UNABLE_TO_CREATE_NEW_SECTION); goto err; } - ts=(STACK *)tv->value; + ts=(STACK_OF(CONF_VALUE) *)tv->value; } else { @@ -304,15 +332,16 @@ long *line; ts=section_sk; } v->section=tv->section; - if (!sk_push(ts,(char *)v)) + if (!sk_CONF_VALUE_push(ts,v)) { - CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); + CONFerr(CONF_F_CONF_LOAD_BIO, + ERR_R_MALLOC_FAILURE); goto err; } vv=(CONF_VALUE *)lh_insert(ret,(char *)v); if (vv != NULL) { - sk_delete_ptr(ts,(char *)vv); + sk_CONF_VALUE_delete_ptr(ts,vv); Free(vv->name); Free(vv->value); Free(vv); @@ -322,13 +351,13 @@ long *line; } if (buff != NULL) BUF_MEM_free(buff); if (section != NULL) Free(section); - if (in != NULL) fclose(in); return(ret); err: if (buff != NULL) BUF_MEM_free(buff); if (section != NULL) Free(section); if (line != NULL) *line=eline; - if (in != NULL) fclose(in); + sprintf(btmp,"%ld",eline); + ERR_add_error_data(2,"line ",btmp); if ((h != ret) && (ret != NULL)) CONF_free(ret); if (v != NULL) { @@ -338,11 +367,8 @@ err: } return(NULL); } - -char *CONF_get_string(conf,section,name) -LHASH *conf; -char *section; -char *name; + +char *CONF_get_string(LHASH *conf, char *section, char *name) { CONF_VALUE *v,vv; char *p; @@ -374,9 +400,7 @@ char *name; return(Getenv(name)); } -static CONF_VALUE *get_section(conf,section) -LHASH *conf; -char *section; +static CONF_VALUE *get_section(LHASH *conf, char *section) { CONF_VALUE *v,vv; @@ -387,23 +411,18 @@ char *section; return(v); } -STACK *CONF_get_section(conf,section) -LHASH *conf; -char *section; +STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf, char *section) { CONF_VALUE *v; v=get_section(conf,section); if (v != NULL) - return((STACK *)v->value); + return((STACK_OF(CONF_VALUE) *)v->value); else return(NULL); } -long CONF_get_number(conf,section,name) -LHASH *conf; -char *section; -char *name; +long CONF_get_number(LHASH *conf, char *section, char *name) { char *str; long ret=0; @@ -420,8 +439,7 @@ char *name; } } -void CONF_free(conf) -LHASH *conf; +void CONF_free(LHASH *conf) { if (conf == NULL) return; @@ -436,9 +454,7 @@ LHASH *conf; lh_free(conf); } -static void value_free_hash(a,conf) -CONF_VALUE *a; -LHASH *conf; +static void value_free_hash(CONF_VALUE *a, LHASH *conf) { if (a->name != NULL) { @@ -446,9 +462,7 @@ LHASH *conf; } } -static void value_free_stack(a,conf) -CONF_VALUE *a; -LHASH *conf; +static void value_free_stack(CONF_VALUE *a, LHASH *conf) { CONF_VALUE *vv; STACK *sk; @@ -469,8 +483,7 @@ LHASH *conf; Free(a); } -static void clear_comments(p) -char *p; +static void clear_comments(char *p) { char *to; @@ -499,10 +512,7 @@ char *p; } } -static int str_copy(conf,section,pto,from) -LHASH *conf; -char *section; -char **pto,*from; +static int str_copy(LHASH *conf, char *section, char **pto, char *from) { int q,r,rr=0,to=0,len=0; char *s,*e,*rp,*p,*rrp,*np,*cp,v; @@ -616,16 +626,14 @@ err: return(0); } -static char *eat_ws(p) -char *p; +static char *eat_ws(char *p) { while (IS_WS(*p) && (!IS_EOF(*p))) p++; return(p); } -static char *eat_alpha_numeric(p) -char *p; +static char *eat_alpha_numeric(char *p) { for (;;) { @@ -640,14 +648,12 @@ char *p; } } -static unsigned long hash(v) -CONF_VALUE *v; +static unsigned long hash(CONF_VALUE *v) { return((lh_strhash(v->section)<<2)^lh_strhash(v->name)); } -static int cmp(a,b) -CONF_VALUE *a,*b; +static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b) { int i; @@ -668,8 +674,7 @@ CONF_VALUE *a,*b; return((a->name == NULL)?-1:1); } -static char *scan_quote(p) -char *p; +static char *scan_quote(char *p) { int q= *p; @@ -687,9 +692,7 @@ char *p; return(p); } -static CONF_VALUE *new_section(conf,section) -LHASH *conf; -char *section; +static CONF_VALUE *new_section(LHASH *conf, char *section) { STACK *sk=NULL; int ok=0,i; @@ -725,3 +728,5 @@ err: } return(v); } + +IMPLEMENT_STACK_OF(CONF_VALUE) diff --git a/src/lib/libcrypto/conf/conf.err b/src/lib/libcrypto/conf/conf.err deleted file mode 100644 index 933d3d692a..0000000000 --- a/src/lib/libcrypto/conf/conf.err +++ /dev/null @@ -1,12 +0,0 @@ -/* Error codes for the CONF functions. */ - -/* Function codes. */ -#define CONF_F_CONF_LOAD 100 -#define CONF_F_STR_COPY 101 - -/* Reason codes. */ -#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100 -#define CONF_R_MISSING_EQUAL_SIGN 101 -#define CONF_R_NO_CLOSE_BRACE 102 -#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 -#define CONF_R_VARIABLE_HAS_NO_VALUE 104 diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h index 1446226a16..e7c5150097 100644 --- a/src/lib/libcrypto/conf/conf.h +++ b/src/lib/libcrypto/conf/conf.h @@ -63,8 +63,10 @@ extern "C" { #endif -#include "stack.h" -#include "lhash.h" +#include +#include +#include +#include typedef struct { @@ -73,31 +75,29 @@ typedef struct char *value; } CONF_VALUE; -#ifndef NOPROTO +DECLARE_STACK_OF(CONF_VALUE) -LHASH *CONF_load(LHASH *conf,char *file,long *eline); -STACK *CONF_get_section(LHASH *conf,char *section); +LHASH *CONF_load(LHASH *conf,const char *file,long *eline); +LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline); +LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline); +STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section); char *CONF_get_string(LHASH *conf,char *group,char *name); long CONF_get_number(LHASH *conf,char *group,char *name); void CONF_free(LHASH *conf); void ERR_load_CONF_strings(void ); -#else - -LHASH *CONF_load(); -STACK *CONF_get_section(); -char *CONF_get_string(); -long CONF_get_number(); -void CONF_free(); -void ERR_load_CONF_strings(); - -#endif /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the CONF functions. */ /* Function codes. */ #define CONF_F_CONF_LOAD 100 +#define CONF_F_CONF_LOAD_BIO 102 +#define CONF_F_CONF_LOAD_FP 103 #define CONF_F_STR_COPY 101 /* Reason codes. */ @@ -106,7 +106,7 @@ void ERR_load_CONF_strings(); #define CONF_R_NO_CLOSE_BRACE 102 #define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 #define CONF_R_VARIABLE_HAS_NO_VALUE 104 - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c index a8db8f266f..eb4b3cfc70 100644 --- a/src/lib/libcrypto/conf/conf_err.c +++ b/src/lib/libcrypto/conf/conf_err.c @@ -1,71 +1,75 @@ -/* lib/conf/conf_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/conf/conf_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "conf.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR static ERR_STRING_DATA CONF_str_functs[]= { {ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"}, +{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"}, +{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"}, {ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"}, -{0,NULL}, +{0,NULL} }; static ERR_STRING_DATA CONF_str_reasons[]= @@ -75,17 +79,17 @@ static ERR_STRING_DATA CONF_str_reasons[]= {CONF_R_NO_CLOSE_BRACE ,"no close brace"}, {CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"}, {CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_CONF_strings() +void ERR_load_CONF_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_CONF,CONF_str_functs); diff --git a/src/lib/libcrypto/conf/conf_lcl.h b/src/lib/libcrypto/conf/conf_lcl.h index 4e5644ed79..f9a015df57 100644 --- a/src/lib/libcrypto/conf/conf_lcl.h +++ b/src/lib/libcrypto/conf/conf_lcl.h @@ -71,6 +71,7 @@ #define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \ CONF_PUNCTUATION) +#ifndef CHARSET_EBCDIC #define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[(a)&0x7f])) #define IS_EOF(a) ((a) == '\0') #define IS_ESC(a) ((a) == '\\') @@ -81,6 +82,19 @@ (CONF_type[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) #define IS_QUOTE(a) (CONF_type[(a)&0x7f]&CONF_QUOTE) +#else /*CHARSET_EBCDIC*/ + +#define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[os_toascii[a]&0x7f])) +#define IS_EOF(a) (os_toascii[a] == '\0') +#define IS_ESC(a) (os_toascii[a] == '\\') +#define IS_NUMER(a) (CONF_type[os_toascii[a]&0x7f]&CONF_NUMBER) +#define IS_WS(a) (CONF_type[os_toascii[a]&0x7f]&CONF_WS) +#define IS_ALPHA_NUMERIC(a) (CONF_type[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC) +#define IS_ALPHA_NUMERIC_PUNCT(a) \ + (CONF_type[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) +#define IS_QUOTE(a) (CONF_type[os_toascii[a]&0x7f]&CONF_QUOTE) +#endif /*CHARSET_EBCDIC*/ + static unsigned short CONF_type[128]={ 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000, 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000, diff --git a/src/lib/libcrypto/conf/keysets.pl b/src/lib/libcrypto/conf/keysets.pl index e40fed0ca1..1aed0c80c4 100644 --- a/src/lib/libcrypto/conf/keysets.pl +++ b/src/lib/libcrypto/conf/keysets.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl $NUMBER=0x01; $UPPER=0x02; diff --git a/src/lib/libcrypto/conf/test.c b/src/lib/libcrypto/conf/test.c index 899ee2a067..9390a48baf 100644 --- a/src/lib/libcrypto/conf/test.c +++ b/src/lib/libcrypto/conf/test.c @@ -58,7 +58,8 @@ #include #include -#include "conf.h" +#include +#include main() { @@ -66,7 +67,7 @@ main() long eline; char *s,*s2; - conf=CONF_load(NULL,"ssleay.conf",&eline); + conf=CONF_load(NULL,"openssl.conf",&eline); if (conf == NULL) { ERR_load_crypto_strings(); diff --git a/src/lib/libcrypto/cpt_err.c b/src/lib/libcrypto/cpt_err.c index ea3c135d39..c2a2dd4af6 100644 --- a/src/lib/libcrypto/cpt_err.c +++ b/src/lib/libcrypto/cpt_err.c @@ -1,63 +1,65 @@ -/* lib/crypto/crypto_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/cpt_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. */ + #include -#include "err.h" -#include "crypto.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -66,20 +68,26 @@ static ERR_STRING_DATA CRYPTO_str_functs[]= {ERR_PACK(0,CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,0), "CRYPTO_get_ex_new_index"}, {ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_LOCKID,0), "CRYPTO_get_new_lockid"}, {ERR_PACK(0,CRYPTO_F_CRYPTO_SET_EX_DATA,0), "CRYPTO_set_ex_data"}, -{0,NULL}, +{0,NULL} + }; + +static ERR_STRING_DATA CRYPTO_str_reasons[]= + { +{0,NULL} }; #endif -void ERR_load_CRYPTO_strings() +void ERR_load_CRYPTO_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_functs); + ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_reasons); #endif } diff --git a/src/lib/libcrypto/cryptall.h b/src/lib/libcrypto/cryptall.h deleted file mode 100644 index 65a46452a8..0000000000 --- a/src/lib/libcrypto/cryptall.h +++ /dev/null @@ -1,110 +0,0 @@ -/* crypto/cryptall.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#ifndef HEADER_CRYPTOALL_H -#define HEADER_CRYPTOALL_H - -#include "buffer.h" -#include "stack.h" -#include "lhash.h" - -#include "err.h" - -#ifdef NO_MD2 -#include -#else -#include "md2.h" -#endif -#ifdef NO_MD5 -#include -#else -#include "md5.h" -#endif -#include "sha.h" - -#ifdef NO_DES -#include -#else -#include "des.h" -#endif -#include "rc2.h" -#include "rc4.h" -#include "idea.h" - -#include "bn.h" -#include "dh.h" -#include "rsa.h" -#include "dsa.h" - -#include "rand.h" -#include "conf.h" -#include "txt_db.h" - -#include "err.h" -#include "evp.h" - -#include "meth.h" -#include "x509.h" -#include "pkcs7.h" -#include "pem.h" -#include "asn1.h" -#include "objects.h" - -#include "crypto.h" - -#endif diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c index 9a7e80b7f8..356c476a99 100644 --- a/src/lib/libcrypto/cryptlib.c +++ b/src/lib/libcrypto/cryptlib.c @@ -59,15 +59,14 @@ #include #include #include "cryptlib.h" -#include "crypto.h" -#include "date.h" +#include #if defined(WIN32) || defined(WIN16) static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */ #endif /* real #defines in crypto.h, keep these upto date */ -static char* lock_names[CRYPTO_NUM_LOCKS] = +static const char* lock_names[CRYPTO_NUM_LOCKS] = { "<>", "err", @@ -84,30 +83,28 @@ static char* lock_names[CRYPTO_NUM_LOCKS] = "ssl_ctx", "ssl_cert", "ssl_session", + "ssl_sess_cert", "ssl", "rand", "debug_malloc", "BIO", - "bio_gethostbyname", + "gethostbyname", + "getservbyname", + "readdir", "RSA_blinding", +#if CRYPTO_NUM_LOCKS != 24 +# error "Inconsistency between crypto.h and cryptlib.c" +#endif }; static STACK *app_locks=NULL; -#ifndef NOPROTO static void (MS_FAR *locking_callback)(int mode,int type, - char *file,int line)=NULL; + const char *file,int line)=NULL; static int (MS_FAR *add_lock_callback)(int *pointer,int amount, - int type,char *file,int line)=NULL; + int type,const char *file,int line)=NULL; static unsigned long (MS_FAR *id_callback)(void)=NULL; -#else -static void (MS_FAR *locking_callback)()=NULL; -static int (MS_FAR *add_lock_callback)()=NULL; -static unsigned long (MS_FAR *id_callback)()=NULL; -#endif - -int CRYPTO_get_new_lockid(name) -char *name; +int CRYPTO_get_new_lockid(char *name) { char *str; int i; @@ -120,10 +117,11 @@ char *name; SSLeay_MSVC5_hack=(double)name[0]*(double)name[1]; #endif - if (app_locks == NULL) - if ((app_locks=sk_new_null()) == NULL) - CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE); - return(0); + if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL)) + { + CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE); + return(0); + } if ((str=BUF_strdup(name)) == NULL) return(0); i=sk_push(app_locks,str); @@ -134,40 +132,46 @@ char *name; return(i); } -void (*CRYPTO_get_locking_callback(P_V))(P_I_I_P_I) +int CRYPTO_num_locks(void) + { + return CRYPTO_NUM_LOCKS; + } + +void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file, + int line) { return(locking_callback); } -int (*CRYPTO_get_add_lock_callback(P_V))(P_IP_I_I_P_I) +int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type, + const char *file,int line) { return(add_lock_callback); } -void CRYPTO_set_locking_callback(func) -void (*func)(P_I_I_P_I); +void CRYPTO_set_locking_callback(void (*func)(int mode,int type, + const char *file,int line)) { locking_callback=func; } -void CRYPTO_set_add_lock_callback(func) -int (*func)(P_IP_I_I_P_I); +void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type, + const char *file,int line)) { add_lock_callback=func; } -unsigned long (*CRYPTO_get_id_callback(P_V))(P_V) +unsigned long (*CRYPTO_get_id_callback(void))(void) { return(id_callback); } -void CRYPTO_set_id_callback(func) -unsigned long (*func)(P_V); +void CRYPTO_set_id_callback(unsigned long (*func)(void)) { id_callback=func; } -unsigned long CRYPTO_thread_id() +unsigned long CRYPTO_thread_id(void) { unsigned long ret=0; @@ -188,11 +192,7 @@ unsigned long CRYPTO_thread_id() return(ret); } -void CRYPTO_lock(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void CRYPTO_lock(int mode, int type, const char *file, int line) { #ifdef LOCK_DEBUG { @@ -221,12 +221,8 @@ int line; locking_callback(mode,type,file,line); } -int CRYPTO_add_lock(pointer,amount,type,file,line) -int *pointer; -int amount; -int type; -char *file; -int line; +int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file, + int line) { int ret; @@ -264,8 +260,7 @@ int line; return(ret); } -char *CRYPTO_get_lock_name(type) -int type; +const char *CRYPTO_get_lock_name(int type) { if (type < 0) return("ERROR"); @@ -283,10 +278,8 @@ int type; /* All we really need to do is remove the 'error' state when a thread * detaches */ -BOOL WINAPI DLLEntryPoint(hinstDLL,fdwReason,lpvReserved) -HINSTANCE hinstDLL; -DWORD fdwReason; -LPVOID lpvReserved; +BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, + LPVOID lpvReserved) { switch(fdwReason) { diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h index 32757c9efb..e3d38524ae 100644 --- a/src/lib/libcrypto/cryptlib.h +++ b/src/lib/libcrypto/cryptlib.h @@ -66,29 +66,25 @@ extern "C" { #endif -/* #ifdef FLAT_INC */ +#include "openssl/e_os.h" -#include "e_os.h" -#include "crypto.h" -#include "buffer.h" -#include "bio.h" -#include "err.h" +#include +#include +#include +#include +#include -/* +#ifndef VMS +#define X509_CERT_AREA OPENSSLDIR +#define X509_CERT_DIR OPENSSLDIR "/certs" +#define X509_CERT_FILE OPENSSLDIR "/cert.pem" +#define X509_PRIVATE_DIR OPENSSLDIR "/private" #else - -#include "../e_os.h" -#include "crypto.h" -#include "buffer/buffer.h" -#include "bio/bio.h" -#include "err/err.h" +#define X509_CERT_AREA "SSLROOT:[000000]" +#define X509_CERT_DIR "SSLCERTS:" +#define X509_CERT_FILE "SSLCERTS:cert.pem" +#define X509_PRIVATE_DIR "SSLPRIVATE:" #endif -*/ - -#define X509_CERT_AREA "/etc/ssl" -#define X509_CERT_DIR "/etc/ssl/certs" -#define X509_CERT_FILE "/etc/ssl/cert.pem" -#define X509_PRIVATE_DIR "/etc/ssl/private" #define X509_CERT_DIR_EVP "SSL_CERT_DIR" #define X509_CERT_FILE_EVP "SSL_CERT_FILE" diff --git a/src/lib/libcrypto/crypto-lib.com b/src/lib/libcrypto/crypto-lib.com new file mode 100644 index 0000000000..bf916528eb --- /dev/null +++ b/src/lib/libcrypto/crypto-lib.com @@ -0,0 +1,1218 @@ +$! +$! CRYPTO-LIB.COM +$! Written By: Robert Byer +$! Vice-President +$! A-Com Computing, Inc. +$! byer@mail.all-net.net +$! +$! Changes by Richard Levitte +$! +$! This command files compiles and creates the "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" +$! library for OpenSSL. The "xxx" denotes the machine architecture of AXP +$! or VAX. +$! +$! It was re-written so it would try to determine what "C" compiler to use +$! or you can specify which "C" compiler to use. +$! +$! Specify RSAREF as P1 to compile with the RSAREF library instead of +$! the regular one. If you specify NORSAREF it will compile with the +$! regular RSAREF routines. (Note: If you are in the United States +$! you MUST compile with RSAREF unless you have a license from RSA). +$! +$! Note: The RSAREF libraries are NOT INCLUDED and you have to +$! download it from "ftp://ftp.rsa.com/rsaref". You have to +$! get the ".tar-Z" file as the ".zip" file dosen't have the +$! directory structure stored. You have to extract the file +$! into the [.RSAREF] directory under the root directory as that +$! is where the scripts will look for the files. +$! +$! Specify DEBUG or NODEBUG as P2 to compile with or without debugger +$! information. +$! +$! Specify which compiler at P3 to try to compile under. +$! +$! VAXC For VAX C. +$! DECC For DEC C. +$! GNUC For GNU C. +$! +$! If you don't speficy a compiler, it will try to determine which +$! "C" compiler to use. +$! +$! P4, if defined, sets a TCP/IP library to use, through one of the following +$! keywords: +$! +$! UCX for UCX +$! SOCKETSHR for SOCKETSHR+NETLIB +$! +$! P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up) +$! +$! P6, if defined, sets a choice of crypto methods to compile. +$! WARNING: this should only be done to recompile some part of an already +$! fully compiled library. +$! +$! +$! Define A TCP/IP Library That We Will Need To Link To. +$! (That Is, If We Need To Link To One.) +$! +$ TCPIP_LIB = "" +$! +$! Check Which Architecture We Are Using. +$! +$ IF (F$GETSYI("CPU").GE.128) +$ THEN +$! +$! The Architecture Is AXP +$! +$ ARCH := AXP +$! +$! Else... +$! +$ ELSE +$! +$! The Architecture Is VAX. +$! +$ ARCH := VAX +$! +$! End The Architecture Check. +$! +$ ENDIF +$! +$! Define The Different Encryption Types. +$! +$ ENCRYPT_TYPES = ",MD2,MD5,SHA,MDC2,HMAC,RIPEMD,"+ - + "DES,RC2,RC4,RC5,IDEA,BF,CAST,"+ - + "BN,RSA,DSA,DH,"+ - + "BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ - + "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ - + "CONF,TXT_DB,PKCS7,PKCS12,COMP" +$! +$! Check To Make Sure We Have Valid Command Line Parameters. +$! +$ GOSUB CHECK_OPTIONS +$! +$! Initialise logical names and such +$! +$ GOSUB INITIALISE +$! +$! Tell The User What Kind of Machine We Run On. +$! +$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine." +$! +$! Define The OBJ Directory. +$! +$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.CRYPTO] +$! +$! Check To See If The Architecture Specific OBJ Directory Exists. +$! +$ IF (F$PARSE(OBJ_DIR).EQS."") +$ THEN +$! +$! It Dosen't Exist, So Create It. +$! +$ CREATE/DIR 'OBJ_DIR' +$! +$! End The Architecture Specific OBJ Directory Check. +$! +$ ENDIF +$! +$! Define The EXE Directory. +$! +$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.CRYPTO] +$! +$! Check To See If The Architecture Specific Directory Exists. +$! +$ IF (F$PARSE(EXE_DIR).EQS."") +$ THEN +$! +$! It Dosen't Exist, So Create It. +$! +$ CREATE/DIRECTORY 'EXE_DIR' +$! +$! End The Architecture Specific Directory Check. +$! +$ ENDIF +$! +$! Define The Library Name. +$! +$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB +$! +$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library... +$! +$ IF (F$SEARCH(LIB_NAME).EQS."") +$ THEN +$! +$! Guess Not, Create The Library. +$! +$ LIBRARY/CREATE/OBJECT 'LIB_NAME' +$! +$! End The Library Check. +$! +$ ENDIF +$! +$! Define The Different Encryption "library" Strings. +$! +$ LIB_ = "cryptlib,mem,cversion,ex_data,tmdiff,cpt_err" +$ LIB_MD2 = "md2_dgst,md2_one" +$ LIB_MD5 = "md5_dgst,md5_one" +$ LIB_SHA = "sha_dgst,sha1dgst,sha_one,sha1_one" +$ LIB_MDC2 = "mdc2dgst,mdc2_one" +$ LIB_HMAC = "hmac" +$ LIB_RIPEMD = "rmd_dgst,rmd_one" +$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ - + "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ - + "enc_read,enc_writ,ofb64enc,"+ - + "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ - + "des_enc,fcrypt_b,read2pwd,"+ - + "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp,ede_cbcm_enc" +$ LIB_RC2 = "rc2_ecb,rc2_skey,rc2_cbc,rc2cfb64,rc2ofb64" +$ LIB_RC4 = "rc4_skey,rc4_enc" +$ LIB_RC5 = "rc5_skey,rc5_ecb,rc5_enc,rc5cfb64,rc5ofb64" +$ LIB_IDEA = "i_cbc,i_cfb64,i_ofb64,i_ecb,i_skey" +$ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64" +$ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64" +$ LIB_BN_ASM = "[.asm]vms.mar,vms-helper" +$ IF F$TRNLNM("OPENSSL_NO_ASM") .NES. "" THEN LIB_BN_ASM = "bn_asm" +$ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_mul,"+ - + "bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ - + "bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+",bn_recp,bn_mont,"+ - + "bn_mpi,bn_exp2" +$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ - + "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk" +$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err" +$ LIB_DH = "dh_gen,dh_key,dh_lib,dh_check,dh_err" +$ LIB_BUFFER = "buffer,buf_err" +$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ - + "bss_mem,bss_null,bss_fd,"+ - + "bss_file,bss_sock,bss_conn,"+ - + "bf_null,bf_buff,b_print,b_dump,"+ - + "b_sock,bss_acpt,bf_nbio,bss_rtcp,bss_bio" ! + ",bss_log" for syslog +$ LIB_STACK = "stack" +$ LIB_LHASH = "lhash,lh_stats" +$ LIB_RAND = "md_rand,randfile,rand_lib" +$ LIB_ERR = "err,err_all,err_prn" +$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err" +$ LIB_EVP = "encode,digest,evp_enc,evp_key,"+ - + "e_ecb_d,e_cbc_d,e_cfb_d,e_ofb_d,"+ - + "e_ecb_i,e_cbc_i,e_cfb_i,e_ofb_i,"+ - + "e_ecb_3d,e_cbc_3d,e_rc4,names,"+ - + "e_cfb_3d,e_ofb_3d,e_xcbc_d,"+ - + "e_ecb_r2,e_cbc_r2,e_cfb_r2,e_ofb_r2,"+ - + "e_ecb_bf,e_cbc_bf,e_cfb_bf,e_ofb_bf" +$ LIB_EVP_2 = "e_ecb_c,e_cbc_c,e_cfb_c,e_ofb_c,"+ - + "e_ecb_r5,e_cbc_r5,e_cfb_r5,e_ofb_r5,"+ - + "m_null,m_md2,m_md5,m_sha,m_sha1,m_dss,m_dss1,m_mdc2,"+ - + "m_ripemd,"+ - + "p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ - + "bio_md,bio_b64,bio_enc,evp_err,e_null,"+ - + "c_all,evp_lib,bio_ok,evp_pkey,evp_pbe,p5_crpt,p5_crpt2" +$ LIB_ASN1 = "a_object,a_bitstr,a_utctm,a_gentm,a_time,a_int,a_octet,"+ - + "a_print,a_type,a_set,a_dup,a_d2i_fp,a_i2d_fp,a_bmp,"+ - + "a_enum,a_vis,a_utf8,a_sign,a_digest,a_verify,"+ - + "x_algor,x_val,x_pubkey,x_sig,x_req,x_attrib,"+ - + "x_name,x_cinf,x_x509,x_crl,x_info,x_spki,nsseq,"+ - + "d2i_r_pr,i2d_r_pr,d2i_r_pu,i2d_r_pu,"+ - + "d2i_s_pr,i2d_s_pr,d2i_s_pu,i2d_s_pu,"+ - + "d2i_pu,d2i_pr,i2d_pu,i2d_pr" +$ LIB_ASN1_2 = "t_req,t_x509,t_crl,t_pkey,"+ - + "p7_i_s,p7_signi,p7_signd,p7_recip,p7_enc_c,p7_evp,"+ - + "p7_dgst,p7_s_e,p7_enc,p7_lib,"+ - + "f_int,f_string,i2d_dhp,i2d_dsap,d2i_dhp,d2i_dsap,n_pkey,"+ - + "f_enum,a_hdr,x_pkey,a_bool,x_exten,"+ - + "asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,"+ - + "evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey" +$ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err" +$ LIB_X509 = "x509_def,x509_d2,x509_r2x,x509_cmp,"+ - + "x509_obj,x509_req,x509_vfy,"+ - + "x509_set,x509rset,x509_err,"+ - + "x509name,x509_v3,x509_ext,"+ - + "x509type,x509_lu,x_all,x509_txt,"+ - + "by_file,by_dir" +$ LIB_X509V3 = "v3_bcons,v3_bitst,v3_conf,v3_extku,v3_ia5,v3_lib,"+ - + "v3_prn,v3_utl,v3err,v3_genn,v3_alt,v3_skey,v3_akey,v3_pku,"+ - + "v3_int,v3_enum,v3_sxnet,v3_cpols,v3_crld" +$ LIB_CONF = "conf,conf_err" +$ LIB_TXT_DB = "txt_db" +$ LIB_PKCS7 = "pk7_lib,pkcs7err,pk7_doit" +$ LIB_PKCS12 = "p12_add,p12_attr,p12_bags,p12_crpt,p12_crt,p12_decr,"+ - + "p12_init,p12_key,p12_kiss,p12_lib,p12_mac,p12_mutl,"+ - + "p12_sbag,p12_utl,pk12err" +$ LIB_COMP = "comp_lib,"+ - + "c_rle,c_zlib" +$! +$! Setup exceptional compilations +$! +$ COMPILEWITH_CC3 = ",bss_rtcp," +$ COMPILEWITH_CC4 = ",a_utctm," +$ COMPILEWITH_CC5 = ",md2_dgst,md5_dgst,mdc2dgst,sha_dgst,sha1dgst," + - + "rmd_dgst,bf_enc," +$! +$! Check To See If We Are Going To Use RSAREF. +$! +$ IF (RSAREF.EQS."TRUE" .AND. ENCRYPT_TYPES - "RSA".NES.ENCRYPT_TYPES) +$ THEN +$! +$! Check To See If The File [-.RSAREF]RSAREF.C Is Actually There. +$! +$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]RSAREF.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File [-.RSAREF]RSAREF.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ GOTO EXIT +$! +$! End The [-.RSAREF]RSAREF.C Check. +$! +$ ENDIF +$! +$! Tell The User We Are Compiling The [-.RSAREF]RSAREF File. +$! +$ WRITE SYS$OUTPUT "Compiling The [-.RSAREF]RSAREF File." +$! +$! Compile [-.RSAREF]RSAREF.C +$! +$ CC/OBJECT='OBJ_DIR'RSAREF.OBJ SYS$DISK:[-.RSAREF]RSAREF.C +$! +$! Add It To The Library. +$! +$ LIBRARY/REPLACE 'LIB_NAME' 'OBJ_DIR'RSAREF.OBJ +$! +$! Delete The Object File. +$! +$ DELETE 'OBJ_DIR'RSAREF.OBJ;* +$! +$! Check To See If The File [-.RSAREF]RSAR_ERR.C Is Actually There. +$! +$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]RSAR_ERR.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File [-.RSAREF]RSAR_ERR.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ GOTO EXIT +$! +$! End The [-.RSAREF]RSAR_ERR.C File Check. +$! +$ ENDIF +$! +$! Tell The User We Are Compiling The [-.RSAREF]RSAR_ERR File. +$! +$ WRITE SYS$OUTPUT "Compiling The [-.RSAREF]RSAR_ERR File." +$! +$! Compile [-.RSAREF]RSAR_ERR.C +$! +$ CC/OBJECT='OBJ_DIR'RSAR_ERR.OBJ SYS$DISK:[-.RSAREF]RSAR_ERR.C +$! +$! Add It To The Library. +$! +$ LIBRARY/REPLACE 'LIB_NAME' 'OBJ_DIR'RSAR_ERR.OBJ +$! +$! Delete The Object File. +$! +$ DELETE 'OBJ_DIR'RSAR_ERR.OBJ;* +$! +$! End The RSAREF Check. +$! +$ ENDIF +$! +$! Figure Out What Other Modules We Are To Build. +$! +$ BUILD_SET: +$! +$! Define A Module Counter. +$! +$ MODULE_COUNTER = 0 +$! +$! Top Of The Loop. +$! +$ MODULE_NEXT: +$! +$! Extract The Module Name From The Encryption List. +$! +$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES) +$! +$! Check To See If We Are At The End Of The Module List. +$! +$ IF (MODULE_NAME.EQS.",") +$ THEN +$! +$! We Are At The End Of The Module List, Go To MODULE_DONE. +$! +$ GOTO MODULE_DONE +$! +$! End The Module List Check. +$! +$ ENDIF +$! +$! Increment The Moudle Counter. +$! +$ MODULE_COUNTER = MODULE_COUNTER + 1 +$! +$! Tell The User What Module We Are Building. +$! +$ IF (MODULE_NAME.NES."") +$ THEN +$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME," Files." +$ ENDIF +$! +$! Define A File Counter And Set It To "0". +$! +$ FILE_COUNTER = 0 +$! +$! Create The Library Module Name. +$! +$ LIB_MODULE = "LIB_" + MODULE_NAME +$ IF (MODULE_NAME.EQS."ASN1_2") +$ THEN +$ MODULE_NAME = "ASN1" +$ ENDIF +$ IF (MODULE_NAME.EQS."EVP_2") +$ THEN +$ MODULE_NAME = "EVP" +$ ENDIF +$! +$! Check if the library module name actually is defined +$! +$ IF F$TYPE('LIB_MODULE') .EQS. "" +$ THEN +$ WRITE SYS$ERROR "" +$ WRITE SYS$ERROR "The module ",MODULE_NAME," does not exist. Continuing..." +$ WRITE SYS$ERROR "" +$ GOTO MODULE_NEXT +$ ENDIF +$! +$! Top Of The File Loop. +$! +$ NEXT_FILE: +$! +$! O.K, Extract The File Name From The File List. +$! +$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE') +$! +$! Check To See If We Are At The End Of The File List. +$! +$ IF (FILE_NAME.EQS.",") +$ THEN +$! +$! We Are At The End Of The File List, Goto FILE_DONE. +$! +$ GOTO FILE_DONE +$! +$! End The File List Check. +$! +$ ENDIF +$! +$! Increment The Counter. +$! +$ FILE_COUNTER = FILE_COUNTER + 1 +$! +$! Create The Source File Name. +$! +$ TMP_FILE_NAME = F$ELEMENT(1,"]",FILE_NAME) +$ IF TMP_FILE_NAME .EQS. "]" THEN TMP_FILE_NAME = FILE_NAME +$ IF F$ELEMENT(0,".",TMP_FILE_NAME) .EQS. TMP_FILE_NAME THEN - + FILE_NAME = FILE_NAME + ".c" +$ IF (MODULE_NAME.NES."") +$ THEN +$ SOURCE_FILE = "SYS$DISK:[." + MODULE_NAME+ "]" + FILE_NAME +$ ELSE +$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME +$ ENDIF +$ SOURCE_FILE = SOURCE_FILE - "][" +$! +$! Create The Object File Name. +$! +$ OBJECT_FILE = OBJ_DIR + F$PARSE(FILE_NAME,,,"NAME","SYNTAX_ONLY") + ".OBJ" +$ ON WARNING THEN GOTO NEXT_FILE +$! +$! Check To See If The File We Want To Compile Is Actually There. +$! +$ IF (F$SEARCH(SOURCE_FILE).EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ GOTO EXIT +$! +$! End The File Exist Check. +$! +$ ENDIF +$! +$! Tell The User We Are Compiling The File. +$! +$ IF (MODULE_NAME.EQS."") +$ THEN + WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File." +$ ENDIF +$ IF (MODULE_NAME.NES."") +$ THEN +$ WRITE SYS$OUTPUT " ",FILE_NAME,"" +$ ENDIF +$! +$! Compile The File. +$! +$ ON ERROR THEN GOTO NEXT_FILE +$ FILE_NAME0 = F$ELEMENT(0,".",FILE_NAME) +$ IF FILE_NAME - ".mar" .NES. FILE_NAME +$ THEN +$ MACRO/OBJECT='OBJECT_FILE' 'SOURCE_FILE' +$ ELSE +$ IF COMPILEWITH_CC3 - FILE_NAME0 .NES. COMPILEWITH_CC3 +$ THEN +$ CC3/OBJECT='OBJECT_FILE' 'SOURCE_FILE' +$ ELSE +$ IF COMPILEWITH_CC4 - FILE_NAME0 .NES. COMPILEWITH_CC4 +$ THEN +$ CC4/OBJECT='OBJECT_FILE' 'SOURCE_FILE' +$ ELSE +$ IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5 +$ THEN +$ CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE' +$ ELSE +$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE' +$ ENDIF +$ ENDIF +$ ENDIF +$ ENDIF +$! +$! Add It To The Library. +$! +$ LIBRARY/REPLACE 'LIB_NAME' 'OBJECT_FILE' +$! +$! Time To Clean Up The Object File. +$! +$ DELETE 'OBJECT_FILE';* +$! +$! Go Back And Do It Again. +$! +$ GOTO NEXT_FILE +$! +$! All Done With This Library Part. +$! +$ FILE_DONE: +$! +$! Go Back And Get The Next Module. +$! +$ GOTO MODULE_NEXT +$! +$! All Done With This Module. +$! +$ MODULE_DONE: +$! +$! Tell The User That We Are All Done. +$! +$ WRITE SYS$OUTPUT "All Done..." +$ EXIT: +$ GOSUB CLEANUP +$ EXIT +$! +$! Check For The Link Option FIle. +$! +$ CHECK_OPT_FILE: +$! +$! Check To See If We Need To Make A VAX C Option File. +$! +$ IF (COMPILER.EQS."VAXC") +$ THEN +$! +$! Check To See If We Already Have A VAX C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! We Need A VAX C Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable VAX C Runtime Library. +! +SYS$SHARE:VAXCRTL.EXE/SHARE +$EOD +$! +$! End The Option File Check. +$! +$ ENDIF +$! +$! End The VAXC Check. +$! +$ ENDIF +$! +$! Check To See If We Need A GNU C Option File. +$! +$ IF (COMPILER.EQS."GNUC") +$ THEN +$! +$! Check To See If We Already Have A GNU C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! We Need A GNU C Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable C Runtime Library. +! +GNU_CC:[000000]GCCLIB/LIBRARY +SYS$SHARE:VAXCRTL/SHARE +$EOD +$! +$! End The Option File Check. +$! +$ ENDIF +$! +$! End The GNU C Check. +$! +$ ENDIF +$! +$! Check To See If We Need A DEC C Option File. +$! +$ IF (COMPILER.EQS."DECC") +$ THEN +$! +$! Check To See If We Already Have A DEC C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! Figure Out If We Need An AXP Or A VAX Linker Option File. +$! +$ IF ARCH .EQS. "VAX" +$ THEN +$! +$! We Need A DEC C Linker Option File For VAX. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable DEC C Runtime Library. +! +SYS$SHARE:DECC$SHR.EXE/SHARE +$EOD +$! +$! Else... +$! +$ ELSE +$! +$! Create The AXP Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File For AXP To Link Agianst +! The Sharable C Runtime Library. +! +SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE +SYS$SHARE:CMA$OPEN_RTL/SHARE +$EOD +$! +$! End The VAX/AXP DEC C Option File Check. +$! +$ ENDIF +$! +$! End The Option File Search. +$! +$ ENDIF +$! +$! End The DEC C Check. +$! +$ ENDIF +$! +$! Tell The User What Linker Option File We Are Using. +$! +$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"." +$! +$! Time To RETURN. +$! +$ RETURN +$! +$! Check The User's Options. +$! +$ CHECK_OPTIONS: +$! +$! Check To See If P1 Is Blank. +$! +$ IF (P1.EQS."NORSAREF") +$ THEN +$! +$! P1 Is NORSAREF, So Compile With The Regular RSA Libraries. +$! +$ RSAREF = "FALSE" +$ ELSE +$! +$! Check To See If We Are To Use The RSAREF Library. +$! +$ IF (P1.EQS."RSAREF") +$ THEN +$! +$! Check To Make Sure We Have The RSAREF Source Code Directory. +$! +$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]SOURCE.DIR").EQS."") +$ THEN +$! +$! We Don't Have The RSAREF Souce Code Directory, So Tell The +$! User This. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "It appears that you don't have the RSAREF Souce Code." +$ WRITE SYS$OUTPUT "You need to go to 'ftp://ftp.rsa.com/rsaref'. You have to" +$ WRITE SYS$OUTPUT "get the '.tar-Z' file as the '.zip' file dosen't have the" +$ WRITE SYS$OUTPUT "directory structure stored. You have to extract the file" +$ WRITE SYS$OUTPUT "into the [.RSAREF] directory under the root directory" +$ WRITE SYS$OUTPUT "as that is where the scripts will look for the files." +$ WRITE SYS$OUTPUT "" +$! +$! Time To Exit. +$! +$ EXIT +$! +$! Else, Compile Using The RSAREF Library. +$! +$ ELSE +$ RSAREF = "TRUE" +$ ENDIF +$ ELSE +$! +$! They Entered An Invalid Option.. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library." +$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The Valid Arguement Check. +$! +$ ENDIF +$! +$! End The P1 Check. +$! +$ ENDIF +$! +$! Check To See If P2 Is Blank. +$! +$ IF (P2.EQS."NODEBUG") +$ THEN +$! +$! P2 Is NODEBUG, So Compile Without The Debugger Information. +$! +$ DEBUGGER = "NODEBUG" +$ TRACEBACK = "NOTRACEBACK" +$ GCC_OPTIMIZE = "OPTIMIZE" +$ CC_OPTIMIZE = "OPTIMIZE" +$ MACRO_OPTIMIZE = "OPTIMIZE" +$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile." +$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization." +$ ELSE +$! +$! Check To See If We Are To Compile With Debugger Information. +$! +$ IF (P2.EQS."DEBUG") +$ THEN +$! +$! Compile With Debugger Information. +$! +$ DEBUGGER = "DEBUG" +$ TRACEBACK = "TRACEBACK" +$ GCC_OPTIMIZE = "NOOPTIMIZE" +$ CC_OPTIMIZE = "NOOPTIMIZE" +$ MACRO_OPTIMIZE = "NOOPTIMIZE" +$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile." +$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization." +$ ELSE +$! +$! They Entered An Invalid Option.. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information." +$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The Valid Arguement Check. +$! +$ ENDIF +$! +$! End The P2 Check. +$! +$ ENDIF +$! +$! Special Threads For OpenVMS v7.1 Or Later +$! +$! Written By: Richard Levitte +$! richard@levitte.org +$! +$! +$! Check To See If We Have A Option For P5. +$! +$ IF (P5.EQS."") +$ THEN +$! +$! Get The Version Of VMS We Are Using. +$! +$ ISSEVEN := +$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION"))) +$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP)) +$! +$! Check To See If The VMS Version Is v7.1 Or Later. +$! +$ IF (TMP.GE.71) +$ THEN +$! +$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads. +$! +$ ISSEVEN := ,PTHREAD_USE_D4 +$! +$! End The VMS Version Check. +$! +$ ENDIF +$! +$! End The P5 Check. +$! +$ ENDIF +$! +$! Check To See If P3 Is Blank. +$! +$ IF (P3.EQS."") +$ THEN +$! +$! O.K., The User Didn't Specify A Compiler, Let's Try To +$! Find Out Which One To Use. +$! +$! Check To See If We Have GNU C. +$! +$ IF (F$TRNLNM("GNU_CC").NES."") +$ THEN +$! +$! Looks Like GNUC, Set To Use GNUC. +$! +$ P3 = "GNUC" +$! +$! Else... +$! +$ ELSE +$! +$! Check To See If We Have VAXC Or DECC. +$! +$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."") +$ THEN +$! +$! Looks Like DECC, Set To Use DECC. +$! +$ P3 = "DECC" +$! +$! Else... +$! +$ ELSE +$! +$! Looks Like VAXC, Set To Use VAXC. +$! +$ P3 = "VAXC" +$! +$! End The VAXC Compiler Check. +$! +$ ENDIF +$! +$! End The DECC & VAXC Compiler Check. +$! +$ ENDIF +$! +$! End The Compiler Check. +$! +$ ENDIF +$! +$! Check To See If We Have A Option For P4. +$! +$ IF (P4.EQS."") +$ THEN +$! +$! Find out what socket library we have available +$! +$ IF F$PARSE("SOCKETSHR:") .NES. "" +$ THEN +$! +$! We have SOCKETSHR, and it is my opinion that it's the best to use. +$! +$ P4 = "SOCKETSHR" +$! +$! Tell the user +$! +$ WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP" +$! +$! Else, let's look for something else +$! +$ ELSE +$! +$! Like UCX (the reason to do this before Multinet is that the UCX +$! emulation is easier to use...) +$! +$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" - + .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" - + .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. "" +$ THEN +$! +$! Last resort: a UCX or UCX-compatible library +$! +$ P4 = "UCX" +$! +$! Tell the user +$! +$ WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP" +$! +$! That was all... +$! +$ ENDIF +$ ENDIF +$ ENDIF +$! +$! Set Up Initial CC Definitions, Possibly With User Ones +$! +$ CCDEFS = "VMS=1,TCPIP_TYPE_''P4'" +$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS +$ CCEXTRAFLAGS = "" +$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS +$ CCDISABLEWARNINGS = "" +$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN - + CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS +$! +$! Check To See If The User Entered A Valid Paramter. +$! +$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC") +$ THEN +$! +$! Check To See If The User Wanted DECC. +$! +$ IF (P3.EQS."DECC") +$ THEN +$! +$! Looks Like DECC, Set To Use DECC. +$! +$ COMPILER = "DECC" +$! +$! Tell The User We Are Using DECC. +$! +$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler." +$! +$! Use DECC... +$! +$ CC = "CC" +$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" - + THEN CC = "CC/DECC" +$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + - + "/NOLIST/PREFIX=ALL/INCLUDE=SYS$DISK:[]" + CCEXTRAFLAGS +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT" +$! +$! End DECC Check. +$! +$ ENDIF +$! +$! Check To See If We Are To Use VAXC. +$! +$ IF (P3.EQS."VAXC") +$ THEN +$! +$! Looks Like VAXC, Set To Use VAXC. +$! +$ COMPILER = "VAXC" +$! +$! Tell The User We Are Using VAX C. +$! +$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler." +$! +$! Compile Using VAXC. +$! +$ CC = "CC" +$ IF ARCH.EQS."AXP" +$ THEN +$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!" +$ EXIT +$ ENDIF +$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC" +$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST/INCLUDE=SYS$DISK:[]" + - + CCEXTRAFLAGS +$ CCDEFS = """VAXC""," + CCDEFS +$! +$! Define As SYS$COMMON:[SYSLIB] +$! +$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB] +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT" +$! +$! End VAXC Check +$! +$ ENDIF +$! +$! Check To See If We Are To Use GNU C. +$! +$ IF (P3.EQS."GNUC") +$ THEN +$! +$! Looks Like GNUC, Set To Use GNUC. +$! +$ COMPILER = "GNUC" +$! +$! Tell The User We Are Using GNUC. +$! +$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler." +$! +$! Use GNU C... +$! +$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + - + "/INCLUDE=SYS$DISK:[]" + CCEXTRAFLAGS +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT" +$! +$! End The GNU C Check. +$! +$ ENDIF +$! +$! Set up default defines +$! +$ CCDEFS = """FLAT_INC=1""," + CCDEFS +$! +$! Check To See If We Are To Compile With RSAREF Routines. +$! +$ IF (RSAREF.EQS."TRUE") +$ THEN +$! +$! Compile With RSAREF. +$! +$ CCDEFS = CCDEFS + ",""RSAref=1""" +$! +$! Tell The User This. +$! +$ WRITE SYS$OUTPUT "Compiling With RSAREF Routines." +$! +$! Else, We Don't Care. Compile Without The RSAREF Library. +$! +$ ELSE +$! +$! Tell The User We Are Compile Without The RSAREF Routines. +$! +$ WRITE SYS$OUTPUT "Compiling Without The RSAREF Routines. +$! +$! End The RSAREF Check. +$! +$ ENDIF +$! +$! Finish up the definition of CC. +$! +$ IF COMPILER .EQS. "DECC" +$ THEN +$ IF CCDISABLEWARNINGS .EQS. "" +$ THEN +$ CC4DISABLEWARNINGS = "DOLLARID" +$ ELSE +$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID" +$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))" +$ ENDIF +$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))" +$ ELSE +$ CCDISABLEWARNINGS = "" +$ CC4DISABLEWARNINGS = "" +$ ENDIF +$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS +$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS +$ IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P2 .NES. "DEBUG" +$ THEN +$ CC5 = CC + "/OPTIMIZE=NODISJOINT" +$ ELSE +$ CC5 = CC + "/NOOPTIMIZE" +$ ENDIF +$ CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS +$! +$! Show user the result +$! +$ WRITE SYS$OUTPUT "Main C Compiling Command: ",CC +$! +$! Else The User Entered An Invalid Arguement. +$! +$ ELSE +$! +$! Tell The User We Don't Know What They Want. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C." +$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C." +$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The Valid Arguement Check. +$! +$ ENDIF +$! +$! Build a MACRO command for the architecture at hand +$! +$ IF ARCH .EQS. "VAX" THEN MACRO = "MACRO/''DEBUGGER'" +$ IF ARCH .EQS. "AXP" THEN MACRO = "MACRO/MIGRATION/''DEBUGGER'/''MACRO_OPTIMIZE'" +$! +$! Show user the result +$! +$ WRITE SYS$OUTPUT "Main MACRO Compiling Command: ",MACRO +$! +$! Time to check the contents, and to make sure we get the correct library. +$! +$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX" +$ THEN +$! +$! Check to see if SOCKETSHR was chosen +$! +$ IF P4.EQS."SOCKETSHR" +$ THEN +$! +$! Set the library to use SOCKETSHR +$! +$ TCPIP_LIB = "[-.VMS]SOCKETSHR_SHR.OPT/OPT" +$! +$! Done with SOCKETSHR +$! +$ ENDIF +$! +$! Check to see if MULTINET was chosen +$! +$ IF P4.EQS."MULTINET" +$ THEN +$! +$! Set the library to use UCX emulation. +$! +$ P4 = "UCX" +$! +$! Done with MULTINET +$! +$ ENDIF +$! +$! Check to see if UCX was chosen +$! +$ IF P4.EQS."UCX" +$ THEN +$! +$! Set the library to use UCX. +$! +$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC.OPT/OPT" +$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" +$ THEN +$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT" +$ ELSE +$ IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN - + TCPIP_LIB = "[-.VMS]UCX_SHR_VAXC.OPT/OPT" +$ ENDIF +$! +$! Done with UCX +$! +$ ENDIF +$! +$! Print info +$! +$ WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB +$! +$! Else The User Entered An Invalid Arguement. +$! +$ ELSE +$! +$! Tell The User We Don't Know What They Want. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library." +$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! Done with TCP/IP libraries +$! +$ ENDIF +$! +$! Check if the user wanted to compile just a subset of all the encryption +$! methods. +$! +$ IF P6 .NES. "" +$ THEN +$ ENCRYPT_TYPES = P6 +$ ENDIF +$! +$! Time To RETURN... +$! +$ RETURN +$! +$ INITIALISE: +$! +$! Save old value of the logical name OPENSSL +$! +$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE") +$! +$! Save directory information +$! +$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;" +$ __TOP = __HERE - "CRYPTO]" +$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]" +$! +$! Set up the logical name OPENSSL to point at the include directory +$! +$ DEFINE OPENSSL/NOLOG '__INCLUDE' +$! +$! Done +$! +$ RETURN +$! +$ CLEANUP: +$! +$! Restore the logical name OPENSSL if it had a value +$! +$ IF __SAVE_OPENSSL .EQS. "" +$ THEN +$ DEASSIGN OPENSSL +$ ELSE +$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL' +$ ENDIF +$! +$! Done +$! +$ RETURN diff --git a/src/lib/libcrypto/crypto.c b/src/lib/libcrypto/crypto.c deleted file mode 100644 index 366e25c939..0000000000 --- a/src/lib/libcrypto/crypto.c +++ /dev/null @@ -1,575 +0,0 @@ -/* crypto/crypto.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* If you are happy to use the assmbler version of bn/bn_mulw.c, define - * BN_ASM */ -#ifndef BN_ASM -#undef BN_ASM -#define X86_ASM -#endif - -#ifndef DES_ASM -#undef DES_ASM -#endif - -#ifndef BF_ASM -#undef BF_ASM -#endif - -/* The following defines are only to break the compiles into chunks. - * If you wish to not compile some sections, use the 'NO_XXX' macros - */ -#ifndef CRYPTO_SUBSET -/* Define all subset symbols. */ -#define CRYPTO_LIB_SUBSET -#define CRYPTO_ASN1_SUBSET -#define CRYPTO_BN_SUBSET -#define CRYPTO_BUFFER_SUBSET -#define CRYPTO_BIO_SUBSET -#define CRYPTO_CONF_SUBSET -#define CRYPTO_DES_SUBSET -#define CRYPTO_DH_SUBSET -#define CRYPTO_DSA_SUBSET -#define CRYPTO_ERROR_SUBSET -#define CRYPTO_EVP_SUBSET -#define CRYPTO_IDEA_SUBSET -#define CRYPTO_LHASH_SUBSET -#define CRYPTO_MD_SUBSET -#define CRYPTO_MDC2_SUBSET -#define CRYPTO_METH_SUBSET -#define CRYPTO_OBJECTS_SUBSET -#define CRYPTO_PEM_SUBSET -#define CRYPTO_RAND_SUBSET -#define CRYPTO_RC_SUBSET -#define CRYPTO_BLOWFISH_SUBSET -#define CRYPTO_CAST_SUBSET -#define CRYPTO_RSA_SUBSET -#define CRYPTO_SHA_SUBSET -#define CRYPTO_HMAC_SUBSET -#define CRYPTO_SHA1_SUBSET -#define CRYPTO_STACK_SUBSET -#define CRYPTO_TXT_DB_SUBSET -#define CRYPTO_X509_SUBSET -#define CRYPTO_PKCS7_SUBSET -#endif - -#include -#include -#include - -#define USE_SOCKETS -#include "../e_os.h" - -#include "buffer.h" -#include "bio.h" -#include "stack.h" -#include "lhash.h" - -#include "err.h" - -#include "bn.h" -#include "evp.h" - -#include "rand.h" -#include "conf.h" -#include "txt_db.h" - -#include "x509.h" -#include "pkcs7.h" -#include "pem.h" -#include "asn1.h" -#include "objects.h" - -#ifdef CRYPTO_LIB_SUBSET -#include "cryptlib.c" -#include "mem.c" -#include "cversion.c" -#endif - -#ifdef CRYPTO_ASN1_SUBSET -#include "asn1/a_meth.c" -#include "asn1/a_bitstr.c" -#include "asn1/a_d2i_fp.c" -#include "asn1/a_dup.c" -#include "asn1/a_hdr.c" -#include "asn1/a_i2d_fp.c" -#include "asn1/a_int.c" -#include "asn1/a_bool.c" -#include "asn1/a_bytes.c" -#include "asn1/a_object.c" -#include "asn1/a_octet.c" -#include "asn1/a_print.c" -#include "asn1/a_set.c" -#include "asn1/a_sign.c" -#include "asn1/a_type.c" -#include "asn1/a_utctm.c" -#include "asn1/a_verify.c" -#include "asn1/a_digest.c" -#include "asn1/asn1_err.c" -#include "asn1/asn1_lib.c" -#include "asn1/asn1_par.c" -#ifndef NO_DH -#include "asn1/d2i_dhp.c" -#include "asn1/i2d_dhp.c" -#endif -#ifndef NO_DSA -#include "asn1/d2i_dsap.c" -#include "asn1/i2d_dsap.c" -#include "asn1/d2i_s_pr.c" -#include "asn1/i2d_s_pr.c" -#include "asn1/d2i_s_pu.c" -#include "asn1/i2d_s_pu.c" -#endif -#ifndef NO_RSA -#include "asn1/d2i_r_pr.c" -#include "asn1/i2d_r_pr.c" -#include "asn1/d2i_r_pu.c" -#include "asn1/i2d_r_pu.c" -#include "asn1/n_pkey.c" -#endif -#include "asn1/d2i_pr.c" -#include "asn1/d2i_pu.c" -#include "asn1/i2d_pr.c" -#include "asn1/i2d_pu.c" -#include "asn1/f_int.c" -#include "asn1/f_string.c" -#include "asn1/p7_dgst.c" -#include "asn1/p7_enc.c" -#include "asn1/p7_enc_c.c" -#include "asn1/p7_evp.c" -#include "asn1/p7_i_s.c" -#include "asn1/p7_lib.c" -#include "asn1/p7_recip.c" -#include "asn1/p7_s_e.c" -#include "asn1/p7_signd.c" -#include "asn1/p7_signi.c" -#include "asn1/t_pkey.c" -#include "asn1/t_req.c" -#include "asn1/t_x509.c" -#include "asn1/x_algor.c" -#include "asn1/x_attrib.c" -#include "asn1/x_exten.c" -#include "asn1/x_cinf.c" -#include "asn1/x_crl.c" -#include "asn1/x_info.c" -#include "asn1/x_name.c" -#include "asn1/x_pkey.c" -#include "asn1/x_pubkey.c" -#include "asn1/x_req.c" -#include "asn1/x_sig.c" -#include "asn1/x_spki.c" -#include "asn1/x_val.c" -#include "asn1/x_x509.c" -#endif - -#ifdef CRYPTO_BN_SUBSET -#include "bn/bn_add.c" -#include "bn/bn_div.c" -#include "bn/bn_exp.c" -#include "bn/bn_mont.c" -#include "bn/bn_recp.c" -#include "bn/bn_gcd.c" -#include "bn/bn_lib.c" -#include "bn/bn_mod.c" -#include "bn/bn_mul.c" -#ifndef BN_ASM -#include "bn/bn_mulw.c" -#endif -#include "bn/bn_prime.c" -#include "bn/bn_rand.c" -#include "bn/bn_shift.c" -#include "bn/bn_sqr.c" -#include "bn/bn_sub.c" -#include "bn/bn_word.c" -#include "bn/bn_print.c" -#include "bn/bn_err.c" -#include "bn/bn_blind.c" -#endif - -#ifdef CRYPTO_BIO_SUBSET -#include "bio/bf_buff.c" -#include "bio/bf_null.c" -#include "bio/bf_nbio.c" -#include "bio/bio_cb.c" -#include "bio/bio_lib.c" -#include "bio/bss_fd.c" -#include "bio/bss_file.c" -#include "bio/bss_mem.c" -#include "bio/bss_null.c" -#ifdef VMS -#include "bio/bss_rtcp.c" -#endif -#include "bio/bss_sock.c" -#include "bio/bss_conn.c" -#include "bio/bss_acpt.c" -#include "bio/b_sock.c" -#include "bio/b_print.c" -#include "bio/b_dump.c" -#include "bio/bio_err.c" -#endif - -#ifdef CRYPTO_BUFFER_SUBSET -#include "buffer/buf_err.c" -#include "buffer/buffer.c" -#endif - -#ifdef CRYPTO_CONF_SUBSET -#include "conf/conf.c" -#include "conf/conf_err.c" -#endif - -#ifdef CRYPTO_DES_SUBSET -#include "des/read_pwd.c" -#ifndef NO_DES -#ifndef DES_ASM -#include "des/fcrypt_b.c" -#include "des/des_enc.c" -#endif -#include "des/cbc_cksm.c" -#include "des/xcbc_enc.c" -#include "des/cbc_enc.c" -#include "des/cfb64ede.c" -#include "des/cfb64enc.c" -#include "des/cfb_enc.c" -#include "des/ecb3_enc.c" -#include "des/ecb_enc.c" -#include "des/enc_read.c" -#include "des/enc_writ.c" -#include "des/fcrypt.c" -#include "des/ofb64ede.c" -#include "des/ofb64enc.c" -#include "des/ofb_enc.c" -#include "des/pcbc_enc.c" -#include "des/qud_cksm.c" -#include "des/rand_key.c" -#include "des/read2pwd.c" -#include "des/rpc_enc.c" -#include "des/set_key.c" -#include "des/str2key.c" -#include "des/supp.c" -#endif -#endif - -#ifdef CRYPTO_DH_SUBSET -#ifndef NO_DH -#include "dh/dh_check.c" -#include "dh/dh_err.c" -#include "dh/dh_gen.c" -#include "dh/dh_key.c" -#include "dh/dh_lib.c" -#endif -#endif - -#ifdef CRYPTO_DSA_SUBSET -#ifndef NO_DSA -#include "dsa/dsa_gen.c" -#include "dsa/dsa_key.c" -#include "dsa/dsa_lib.c" -#include "dsa/dsa_sign.c" -#include "dsa/dsa_vrf.c" -#include "dsa/dsa_err.c" -#endif -#endif - -#ifdef CRYPTO_ERROR_SUBSET -#include "err/err.c" -#include "err/err_all.c" -#include "err/err_prn.c" -#endif - -#ifdef CRYPTO_EVP_SUBSET -#include "evp/bio_md.c" -#include "evp/bio_b64.c" -#include "evp/bio_enc.c" -#include "evp/c_all.c" -#include "evp/digest.c" -#ifndef NO_DES -#include "evp/e_cbc_3d.c" -#include "evp/e_cfb_3d.c" -#include "evp/e_ecb_3d.c" -#include "evp/e_ofb_3d.c" -#include "evp/e_cbc_d.c" -#include "evp/e_cfb_d.c" -#include "evp/e_xcbc_d.c" -#include "evp/e_ecb_d.c" -#include "evp/e_ofb_d.c" -#endif -#ifndef NO_IDEA -#include "evp/e_cbc_i.c" -#include "evp/e_cfb_i.c" -#include "evp/e_ecb_i.c" -#include "evp/e_ofb_i.c" -#endif -#ifndef NO_RC2 -#include "evp/e_cbc_r2.c" -#include "evp/e_cfb_r2.c" -#include "evp/e_ecb_r2.c" -#include "evp/e_ofb_r2.c" -#endif -#ifndef NO_BLOWFISH -#include "evp/e_cbc_bf.c" -#include "evp/e_cfb_bf.c" -#include "evp/e_ecb_bf.c" -#include "evp/e_ofb_bf.c" -#endif -#ifndef NO_CAST -#include "evp/e_cbc_c.c" -#include "evp/e_cfb_c.c" -#include "evp/e_ecb_c.c" -#include "evp/e_ofb_c.c" -#endif -#ifndef NO_RC4 -#include "evp/e_rc4.c" -#endif -#include "rc5/rc5_enc.c" -#include "rc5/rc5cfb64.c" -#include "rc5/rc5_ecb.c" -#include "rc5/rc5_skey.c" -#include "rc5/rc5ofb64.c" -#include "ripemd/rmd160.c" -#include "ripemd/rmd_dgst.c" -#include "ripemd/rmd_one.c" -#include "evp/evp_lib.c" - -#include "evp/names.c" -#include "evp/e_null.c" -#include "evp/encode.c" -#include "evp/evp_enc.c" -#include "evp/evp_err.c" -#include "evp/evp_key.c" -#include "evp/m_null.c" -#include "evp/p_lib.c" -#ifndef NO_RSA -#include "evp/p_open.c" -#include "evp/p_seal.c" -#endif -#include "evp/p_sign.c" -#include "evp/p_verify.c" -#endif - -#ifdef CRYPTO_IDEA_SUBSET -#ifndef NO_IDEA -#include "idea/i_cbc.c" -#include "idea/i_cfb64.c" -#include "idea/i_ecb.c" -#include "idea/i_ofb64.c" -#include "idea/i_skey.c" -#endif -#endif - -#ifdef CRYPTO_BLOWFISH_SUBSET -#ifndef NO_BLOWFISH -#include "bf/bf_cfb64.c" -#include "bf/bf_ecb.c" -#ifndef BF_ASM -#include "bf/bf_enc.c" -#endif -#include "bf/bf_ofb64.c" -#include "bf/bf_skey.c" -#endif -#endif - -#ifdef CRYPTO_CAST_SUBSET -#ifndef NO_CAST -#include "cast/c_cfb64.c" -#include "cast/c_ecb.c" -#ifndef CAST_ASM -#include "cast/c_enc.c" -#endif -#include "cast/c_ofb64.c" -#include "cast/c_skey.c" -#endif -#endif - -#ifdef CRYPTO_LHASH_SUBSET -#include "lhash/lh_stats.c" -#include "lhash/lhash.c" -#endif - -#ifdef CRYPTO_MD_SUBSET -#ifndef NO_MD2 -#include "md2/md2_dgst.c" -#include "md2/md2_one.c" -#include "evp/m_md2.c" -#endif -#ifndef NO_MD5 -#include "md5/md5_dgst.c" -#include "md5/md5_one.c" -#include "evp/m_md5.c" -#endif -#endif - -#ifdef CRYPTO_MDC2_SUBSET -#ifndef NO_MDC2 -#include "mdc2/mdc2dgst.c" -#include "mdc2/mdc2_one.c" -#include "evp/m_mdc2.c" -#endif -#endif - -#ifdef CRYPTO_OBJECTS_SUBSET -#include "objects/obj_dat.c" -#include "objects/obj_err.c" -#include "objects/obj_lib.c" -#endif - -#ifdef CRYPTO_PEM_SUBSET -#include "pem/pem_err.c" -#include "pem/pem_info.c" -#include "pem/pem_lib.c" -#include "pem/pem_all.c" -#ifndef NO_RSA -#include "pem/pem_seal.c" -#include "pem/pem_sign.c" -#endif -#endif - -#ifdef CRYPTO_RAND_SUBSET -#include "rand/md_rand.c" -#include "rand/randfile.c" -#endif - -#ifdef CRYPTO_RC_SUBSET -#ifndef NO_RC2 -#include "rc2/rc2_cbc.c" -#include "rc2/rc2_ecb.c" -#include "rc2/rc2_skey.c" -#include "rc2/rc2cfb64.c" -#include "rc2/rc2ofb64.c" -#endif -#ifndef NO_RC4 -#include "rc4/rc4_skey.c" -#ifndef RC4_ASM -#include "rc4/rc4_enc.c" -#endif -#endif -#endif - -#ifdef CRYPTO_HMAC_SUBSET -#include "hmac/hmac.c" -#endif - -#ifdef CRYPTO_RSA_SUBSET -#ifndef NO_RSA -#include "rsa/rsa_eay.c" -#include "rsa/rsa_err.c" -#include "rsa/rsa_gen.c" -#include "rsa/rsa_lib.c" -#include "rsa/rsa_sign.c" -#include "rsa/rsa_saos.c" -#endif -#endif - -#ifdef CRYPTO_SHA1_SUBSET -#ifndef NO_SHA1 -#include "sha/sha1_one.c" -#include "sha/sha1dgst.c" -#include "evp/m_dss1.c" -#include "evp/m_sha1.c" -#endif -#endif - -#ifdef CRYPTO_SHA_SUBSET -#ifndef NO_SHA -#include "evp/m_dss.c" -#include "sha/sha_dgst.c" -#include "sha/sha_one.c" -#include "evp/m_sha.c" -#endif -#endif - -#ifdef CRYPTO_STACK_SUBSET -#include "stack/stack.c" -#endif - -#ifdef CRYPTO_TXT_DB_SUBSET -#include "txt_db/txt_db.c" -#endif - -#ifdef CRYPTO_X509_SUBSET -#include "x509/x509_cmp.c" -#include "x509/x509_d2.c" -#include "x509/x509_def.c" -#include "x509/x509_err.c" -#include "x509/x509_ext.c" -#include "x509/x509_lu.c" -#include "x509/x509_obj.c" -#include "x509/x509_r2x.c" -#include "x509/x509_req.c" -#include "x509/x509_set.c" -#include "x509/x509_v3.c" -#include "x509/x509_vfy.c" -#include "x509/x509name.c" -#include "x509/x509pack.c" -#include "x509/x509rset.c" -#include "x509/x509type.c" -#include "x509/x_all.c" -#include "x509/x509_txt.c" -#include "x509/by_dir.c" -#include "x509/by_file.c" -#include "x509/v3_net.c" -#include "x509/v3_x509.c" -#endif - - -#ifdef CRYPTO_PKCS7_SUBSET /* I have an explicit removal of 7 lines */ -#include "pkcs7/pk7_lib.c" -#include "pkcs7/pkcs7err.c" -#include "pkcs7/pk7_doit.c" -#endif /* CRYPTO_PKCS7_SUBSET */ - diff --git a/src/lib/libcrypto/crypto.err b/src/lib/libcrypto/crypto.err deleted file mode 100644 index 4ea3385e73..0000000000 --- a/src/lib/libcrypto/crypto.err +++ /dev/null @@ -1,8 +0,0 @@ -/* Error codes for the CRYPTO functions. */ - -/* Function codes. */ -#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100 -#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101 -#define CRYPTO_F_CRYPTO_SET_EX_DATA 102 - -/* Reason codes. */ diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h index 0a38b5b87c..8ad8c25e5a 100644 --- a/src/lib/libcrypto/crypto.h +++ b/src/lib/libcrypto/crypto.h @@ -63,16 +63,26 @@ extern "C" { #endif -#include "stack.h" +#ifndef NO_FP_API +#include +#endif +#include +#include + +#ifdef CHARSET_EBCDIC +#include +#endif + +/* Backward compatibility to SSLeay */ /* This is more to be used to check the correct DLL is being used * in the MS world. */ -#define SSLEAY_VERSION_NUMBER 0x0902 /* Version 0.5.1c would be 0513 */ - +#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER #define SSLEAY_VERSION 0 /* #define SSLEAY_OPTIONS 1 no longer supported */ #define SSLEAY_CFLAGS 2 #define SSLEAY_BUILT_ON 3 +#define SSLEAY_PLATFORM 4 /* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock * names in cryptlib.c @@ -92,19 +102,23 @@ extern "C" { #define CRYPTO_LOCK_SSL_CTX 12 #define CRYPTO_LOCK_SSL_CERT 13 #define CRYPTO_LOCK_SSL_SESSION 14 -#define CRYPTO_LOCK_SSL 15 -#define CRYPTO_LOCK_RAND 16 -#define CRYPTO_LOCK_MALLOC 17 -#define CRYPTO_LOCK_BIO 18 -#define CRYPTO_LOCK_BIO_GETHOSTBYNAME 19 -#define CRYPTO_LOCK_RSA_BLINDING 20 -#define CRYPTO_NUM_LOCKS 21 +#define CRYPTO_LOCK_SSL_SESS_CERT 15 +#define CRYPTO_LOCK_SSL 16 +#define CRYPTO_LOCK_RAND 17 +#define CRYPTO_LOCK_MALLOC 18 +#define CRYPTO_LOCK_BIO 19 +#define CRYPTO_LOCK_GETHOSTBYNAME 20 +#define CRYPTO_LOCK_GETSERVBYNAME 21 +#define CRYPTO_LOCK_READDIR 22 +#define CRYPTO_LOCK_RSA_BLINDING 23 +#define CRYPTO_NUM_LOCKS 24 #define CRYPTO_LOCK 1 #define CRYPTO_UNLOCK 2 #define CRYPTO_READ 4 #define CRYPTO_WRITE 8 +#ifndef NO_LOCKING #ifndef CRYPTO_w_lock #define CRYPTO_w_lock(type) \ CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) @@ -116,14 +130,22 @@ extern "C" { CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__) #define CRYPTO_add(addr,amount,type) \ CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__) - +#endif +#else +#define CRYPTO_w_lock(a) +#define CRYPTO_w_unlock(a) +#define CRYPTO_r_lock(a) +#define CRYPTO_r_unlock(a) +#define CRYPTO_add(a,b,c) ((*(a))+=(b)) #endif /* The following can be used to detect memory leaks in the SSLeay library. * It used, it turns on malloc checking */ -#define CRYPTO_MEM_CHECK_OFF 0x0 -#define CRYPTO_MEM_CHECK_ON 0x1 +#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */ +#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */ +#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */ +#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */ /* typedef struct crypto_mem_st @@ -178,37 +200,65 @@ typedef struct crypto_ex_data_func_st (char *(*)())realloc,\ (void (*)())free) +#ifdef CRYPTO_MDEBUG_ALL +# ifndef CRYPTO_MDEBUG_TIME +# define CRYPTO_MDEBUG_TIME +# endif +# ifndef CRYPTO_MDEBUG_THREAD +# define CRYPTO_MDEBUG_THREAD +# endif +#endif + +#if defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD +# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */ +# define CRYPTO_MDEBUG +# endif +#endif + #ifdef CRYPTO_MDEBUG +#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON) +#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF) +#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE) +#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE) #define Malloc(num) CRYPTO_dbg_malloc((int)num,__FILE__,__LINE__) #define Realloc(addr,num) \ CRYPTO_dbg_realloc((char *)addr,(int)num,__FILE__,__LINE__) #define Remalloc(addr,num) \ CRYPTO_dbg_remalloc((char **)addr,(int)num,__FILE__,__LINE__) #define FreeFunc CRYPTO_dbg_free -#define Free(addr) CRYPTO_dbg_free((char *)(addr)) +#define Free(addr) CRYPTO_dbg_free(addr) +#define Malloc_locked(num) CRYPTO_malloc_locked((int)num) +#define Free_locked(addr) CRYPTO_free_locked(addr) #else +#define MemCheck_start() +#define MemCheck_stop() +#define MemCheck_on() +#define MemCheck_off() #define Remalloc CRYPTO_remalloc #if defined(WIN32) || defined(MFUNC) #define Malloc CRYPTO_malloc -#define Realloc(a,n) CRYPTO_realloc((char *)(a),(n)) +#define Realloc(a,n) CRYPTO_realloc(a,(n)) #define FreeFunc CRYPTO_free -#define Free(addr) CRYPTO_free((char *)(addr)) +#define Free(addr) CRYPTO_free(addr) +#define Malloc_locked CRYPTO_malloc_locked +#define Free_locked(addr) CRYPTO_free_locked(addr) #else #define Malloc malloc #define Realloc realloc #define FreeFunc free -#define Free(addr) free((char *)(addr)) +#define Free(addr) free(addr) +#define Malloc_locked malloc +#define Free_locked(addr) free(addr) #endif /* WIN32 || MFUNC */ #endif /* MDEBUG */ /* Case insensiteve linking causes problems.... */ -#ifdef WIN16 +#if defined(WIN16) || defined(VMS) #define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings #endif -#ifndef NOPROTO -char *SSLeay_version(int type); +const char *SSLeay_version(int type); unsigned long SSLeay(void); int CRYPTO_get_ex_new_index(int idx,STACK **sk,long argl,char *argp, @@ -221,33 +271,40 @@ void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad); int CRYPTO_mem_ctrl(int mode); int CRYPTO_get_new_lockid(char *name); -void CRYPTO_lock(int mode, int type,char *file,int line); -void CRYPTO_set_locking_callback(void (*func)(int mode,int type,char *file, - int line)); -void (*CRYPTO_get_locking_callback(void))(int mode,int type,char *file, + +int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */ +void CRYPTO_lock(int mode, int type,const char *file,int line); +void CRYPTO_set_locking_callback(void (*func)(int mode,int type, + const char *file,int line)); +void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file, int line); -void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount, - int type,char *file, int line)); -int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount, - int type,char *file,int line); +void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type, + const char *file, int line)); +int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type, + const char *file,int line); void CRYPTO_set_id_callback(unsigned long (*func)(void)); unsigned long (*CRYPTO_get_id_callback(void))(void); unsigned long CRYPTO_thread_id(void); -char *CRYPTO_get_lock_name(int type); -int CRYPTO_add_lock(int *pointer,int amount,int type, char *file,int line); +const char *CRYPTO_get_lock_name(int type); +int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file, + int line); void CRYPTO_set_mem_functions(char *(*m)(),char *(*r)(), void (*free_func)()); void CRYPTO_get_mem_functions(char *(**m)(),char *(**r)(), void (**f)()); - -char *CRYPTO_malloc(int num); -char *CRYPTO_realloc(char *addr,int num); -void CRYPTO_free(char *); -char *CRYPTO_remalloc(char *addr,int num); - -char *CRYPTO_dbg_malloc(int num,char *file,int line); -char *CRYPTO_dbg_realloc(char *addr,int num,char *file,int line); -void CRYPTO_dbg_free(char *); -char *CRYPTO_dbg_remalloc(char *addr,int num,char *file,int line); +void CRYPTO_set_locked_mem_functions(char *(*m)(), void (*free_func)()); +void CRYPTO_get_locked_mem_functions(char *(**m)(), void (**f)()); + +void *CRYPTO_malloc_locked(int num); +void CRYPTO_free_locked(void *); +void *CRYPTO_malloc(int num); +void CRYPTO_free(void *); +void *CRYPTO_realloc(void *addr,int num); +void *CRYPTO_remalloc(void *addr,int num); + +void *CRYPTO_dbg_malloc(int num,const char *file,int line); +void *CRYPTO_dbg_realloc(void *addr,int num,const char *file,int line); +void CRYPTO_dbg_free(void *); +void *CRYPTO_dbg_remalloc(void *addr,int num,const char *file,int line); #ifndef NO_FP_API void CRYPTO_mem_leaks_fp(FILE *); #endif @@ -257,52 +314,11 @@ void CRYPTO_mem_leaks_cb(void (*cb)()); void ERR_load_CRYPTO_strings(void ); -#else - -int CRYPTO_get_ex_new_index(); -int CRYPTO_set_ex_data(); -char *CRYPTO_get_ex_data(); -int CRYPTO_dup_ex_data(); -void CRYPTO_free_ex_data(); -void CRYPTO_new_ex_data(); - -int CRYPTO_mem_ctrl(); -char *SSLeay_version(); -unsigned long SSLeay(); - -int CRYPTO_get_new_lockid(); -void CRYPTO_lock(); -void CRYPTO_set_locking_callback(); -void (*CRYPTO_get_locking_callback())(); -void CRYPTO_set_add_lock_callback(); -int (*CRYPTO_get_add_lock_callback())(); -void CRYPTO_set_id_callback(); -unsigned long (*CRYPTO_get_id_callback())(); -unsigned long CRYPTO_thread_id(); -char *CRYPTO_get_lock_name(); -int CRYPTO_add_lock(); - -void CRYPTO_set_mem_functions(); -void CRYPTO_get_mem_functions(); -char *CRYPTO_malloc(); -char *CRYPTO_realloc(); -void CRYPTO_free(); -char *CRYPTO_remalloc(); -char *CRYPTO_dbg_remalloc(); -char *CRYPTO_dbg_malloc(); -char *CRYPTO_dbg_realloc(); -void CRYPTO_dbg_free(); -#ifndef NO_FP_API -void CRYPTO_mem_leaks_fp(); -#endif -void CRYPTO_mem_leaks(); -void CRYPTO_mem_leaks_cb(); - -void ERR_load_CRYPTO_strings(); - -#endif - /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the CRYPTO functions. */ /* Function codes. */ @@ -311,7 +327,7 @@ void ERR_load_CRYPTO_strings(); #define CRYPTO_F_CRYPTO_SET_EX_DATA 102 /* Reason codes. */ - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/cversion.c b/src/lib/libcrypto/cversion.c index 4e823be52f..affdfca98f 100644 --- a/src/lib/libcrypto/cversion.c +++ b/src/lib/libcrypto/cversion.c @@ -59,40 +59,53 @@ #include #include #include "cryptlib.h" -#include "crypto.h" -#include "date.h" +#include -char *SSLeay_version(t) -int t; +#ifndef NO_WINDOWS_BRAINDEATH +#include "buildinf.h" +#endif + +const char *SSLeay_version(int t) { if (t == SSLEAY_VERSION) - return("SSLeay 0.9.0b 29-Jun-1998"); + return OPENSSL_VERSION_TEXT; if (t == SSLEAY_BUILT_ON) { #ifdef DATE - static char buf[sizeof(DATE)+10]; + static char buf[sizeof(DATE)+11]; - sprintf(buf,"built on %s",DATE); - return(buf); + sprintf(buf,"built on: %s",DATE); + return(buf); #else - return("build date not available"); + return("built on: date not available"); #endif } if (t == SSLEAY_CFLAGS) { #ifdef CFLAGS - static char buf[sizeof(CFLAGS)+10]; + static char buf[sizeof(CFLAGS)+11]; + + sprintf(buf,"compiler: %s",CFLAGS); + return(buf); +#else + return("compiler: information not available"); +#endif + } + if (t == SSLEAY_PLATFORM) + { +#ifdef PLATFORM + static char buf[sizeof(PLATFORM)+11]; - sprintf(buf,"C flags:%s",CFLAGS); + sprintf(buf,"platform: %s", PLATFORM); return(buf); #else - return("C flags not available"); + return("platform: information not available"); #endif } return("not available"); } -unsigned long SSLeay() +unsigned long SSLeay(void) { return(SSLEAY_VERSION_NUMBER); } diff --git a/src/lib/libcrypto/date.h b/src/lib/libcrypto/date.h deleted file mode 100644 index dbb71bd1b7..0000000000 --- a/src/lib/libcrypto/date.h +++ /dev/null @@ -1 +0,0 @@ -#define DATE "Sun Jul 12 21:04:32 MDT 1998" diff --git a/src/lib/libcrypto/des/Makefile.ssl b/src/lib/libcrypto/des/Makefile.ssl index 78b5189ee3..09fdd07305 100644 --- a/src/lib/libcrypto/des/Makefile.ssl +++ b/src/lib/libcrypto/des/Makefile.ssl @@ -6,11 +6,13 @@ DIR= des TOP= ../.. CC= cc CPP= $(CC) -E -INCLUDES= +INCLUDES=-I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r DES_ENC= des_enc.o fcrypt_b.o @@ -19,7 +21,7 @@ DES_ENC= des_enc.o fcrypt_b.o CFLAGS= $(INCLUDES) $(CFLAG) -GENERAL=Makefile des.org des_locl.org +GENERAL=Makefile TEST=destest.c APPS= @@ -30,14 +32,15 @@ LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \ qud_cksm.c rand_key.c read_pwd.c rpc_enc.c set_key.c \ des_enc.c fcrypt_b.c read2pwd.c \ fcrypt.c xcbc_enc.c \ - str2key.c cfb64ede.c ofb64ede.c supp.c + str2key.c cfb64ede.c ofb64ede.c supp.c ede_cbcm_enc.c LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \ ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \ enc_read.o enc_writ.o ofb64enc.o \ ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \ ${DES_ENC} read2pwd.o \ - fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o + fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o \ + ede_cbcm_enc.o SRC= $(LIBSRC) @@ -53,9 +56,12 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib +des: des.o cbc3_enc.o lib + $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB) + # elf asm/dx86-elf.o: asm/dx86unix.cpp $(CPP) -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o @@ -83,38 +89,34 @@ asm/yx86-out.o: asm/yx86unix.cpp # bsdi asm/dx86bsdi.o: asm/dx86unix.cpp - $(CPP) -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o + $(CPP) -DBSDI asm/dx86unix.cpp | sed 's/ :/:/' | as -o asm/dx86bsdi.o asm/yx86bsdi.o: asm/yx86unix.cpp - $(CPP) -DBSDI asm/yx86unix.cpp | as -o asm/yx86bsdi.o + $(CPP) -DBSDI asm/yx86unix.cpp | sed 's/ :/:/' | as -o asm/yx86bsdi.o -asm/dx86unix.cpp: - (cd asm; perl des-586.pl cpp >dx86unix.cpp) +asm/dx86unix.cpp: asm/des-586.pl + (cd asm; $(PERL) des-586.pl cpp >dx86unix.cpp) -asm/yx86unix.cpp: - (cd asm; perl crypt586.pl cpp >yx86unix.cpp) +asm/yx86unix.cpp: asm/crypt586.pl + (cd asm; $(PERL) crypt586.pl cpp >yx86unix.cpp) files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile - /bin/rm -f des.doc - /bin/rm -fr asm/perlasm - $(TOP)/util/point.sh ../../perlasm asm/perlasm - $(TOP)/util/point.sh ../../doc/des.doc des.doc - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(TOP)/util/point.sh ../../perlasm asm/perlasm + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: installs installs: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -126,15 +128,81 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f asm/dx86unix.cpp asm/yx86unix.cpp *.o asm/*.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +cbc_cksm.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +cbc_cksm.o: ../../include/openssl/opensslconf.h des_locl.h +cbc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +cbc_enc.o: ../../include/openssl/opensslconf.h des_locl.h ncbc_enc.c +cfb64ede.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +cfb64ede.o: ../../include/openssl/opensslconf.h des_locl.h +cfb64enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +cfb64enc.o: ../../include/openssl/opensslconf.h des_locl.h +cfb_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +cfb_enc.o: ../../include/openssl/opensslconf.h des_locl.h +des_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +des_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_locl.h ncbc_enc.c +ecb3_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +ecb3_enc.o: ../../include/openssl/opensslconf.h des_locl.h +ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +ecb_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +ecb_enc.o: des_locl.h spr.h +ede_cbcm_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +ede_cbcm_enc.o: ../../include/openssl/opensslconf.h des_locl.h +enc_read.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +enc_read.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +enc_read.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +enc_read.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +enc_read.o: ../cryptlib.h des_locl.h +enc_writ.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +enc_writ.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +enc_writ.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +enc_writ.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +enc_writ.o: ../../include/openssl/stack.h ../cryptlib.h des_locl.h +fcrypt.o: ../../include/openssl/des.h ../../include/openssl/des.h +fcrypt.o: ../../include/openssl/e_os2.h ../../include/openssl/e_os2.h +fcrypt.o: ../../include/openssl/opensslconf.h +fcrypt.o: ../../include/openssl/opensslconf.h des_locl.h des_locl.h +fcrypt_b.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +fcrypt_b.o: ../../include/openssl/opensslconf.h des_locl.h +ofb64ede.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +ofb64ede.o: ../../include/openssl/opensslconf.h des_locl.h +ofb64enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +ofb64enc.o: ../../include/openssl/opensslconf.h des_locl.h +ofb_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +ofb_enc.o: ../../include/openssl/opensslconf.h des_locl.h +pcbc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +pcbc_enc.o: ../../include/openssl/opensslconf.h des_locl.h +qud_cksm.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +qud_cksm.o: ../../include/openssl/opensslconf.h des_locl.h +rand_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +rand_key.o: ../../include/openssl/opensslconf.h des_locl.h +read2pwd.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +read2pwd.o: ../../include/openssl/opensslconf.h des_locl.h +read_pwd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +read_pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +read_pwd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +read_pwd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +read_pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +read_pwd.o: ../cryptlib.h des_locl.h +rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +rpc_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_ver.h rpc_des.h +set_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +set_key.o: ../../include/openssl/opensslconf.h des_locl.h podd.h sk.h +str2key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +str2key.o: ../../include/openssl/opensslconf.h des_locl.h +supp.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +supp.o: ../../include/openssl/opensslconf.h des_locl.h +xcbc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +xcbc_enc.o: ../../include/openssl/opensslconf.h des_locl.h diff --git a/src/lib/libcrypto/des/Makefile.uni b/src/lib/libcrypto/des/Makefile.uni index 8f1759748a..ec19d75b81 100644 --- a/src/lib/libcrypto/des/Makefile.uni +++ b/src/lib/libcrypto/des/Makefile.uni @@ -51,6 +51,7 @@ CFLAG= -O3 -fomit-frame-pointer CFLAGS=$(OPTS) $(CFLAG) CPP=$(CC) -E AS=as +RANLIB=ranlib # Assember version of des_encrypt*(). DES_ENC=des_enc.o fcrypt_b.o # normal C version @@ -169,9 +170,7 @@ test: all $(DLIB): $(OBJ) /bin/rm -f $(DLIB) ar cr $(DLIB) $(OBJ) - -if test -s /bin/ranlib; then /bin/ranlib $(DLIB); \ - else if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(DLIB); \ - else exit 0; fi; fi + $(RANLIB) $(DLIB) des_opts: des_opts.o $(DLIB) $(CC) $(CFLAGS) -o des_opts des_opts.o $(DLIB) @@ -231,25 +230,14 @@ install: des if test $(INSTALLTOP); then \ echo SSL style install; \ cp $(DLIB) $(INSTALLTOP)/lib; \ - if test -s /bin/ranlib; then \ - /bin/ranlib $(INSTALLTOP)/lib/$(DLIB); \ - else \ - if test -s /usr/bin/ranlib; then \ - /usr/bin/ranlib $(INSTALLTOP)/lib/$(DLIB); \ - fi; fi; \ + $(RANLIB) $(DLIB); \ chmod 644 $(INSTALLTOP)/lib/$(DLIB); \ cp des.h $(INSTALLTOP)/include; \ chmod 644 $(INSTALLTOP)/include/des.h; \ else \ echo Standalone install; \ cp $(DLIB) $(LIBDIR)/$(DLIB); \ - if test -s /bin/ranlib; then \ - /bin/ranlib $(LIBDIR)/$(DLIB); \ - else \ - if test -s /usr/bin/ranlib; then \ - /usr/bin/ranlib $(LIBDIR)/$(DLIB); \ - fi; \ - fi; \ + $(RANLIB) $(DLIB); \ chmod 644 $(LIBDIR)/$(DLIB); \ cp des $(BINDIR)/des; \ chmod 711 $(BINDIR)/des; \ diff --git a/src/lib/libcrypto/des/VERSION b/src/lib/libcrypto/des/VERSION index f62d8bdac0..c7d01542bc 100644 --- a/src/lib/libcrypto/des/VERSION +++ b/src/lib/libcrypto/des/VERSION @@ -1,3 +1,4 @@ + Fixed the weak key values which were wrong :-( Defining SIGACTION causes sigaction() to be used instead of signal(). SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it can cause problems. This should hopefully not affect normal diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl index 297e38dec8..197c413ea6 100644 --- a/src/lib/libcrypto/des/asm/crypt586.pl +++ b/src/lib/libcrypto/des/asm/crypt586.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # The inner loop instruction sequence and the IP/FP modifications are from # Svend Olaf Mikkelsen @@ -32,7 +32,7 @@ sub fcrypt_body &xor( $R, $R); &mov($ks,&wparam(1)); - &push(25); # add a variable + &push(&DWC(25)); # add a variable &set_label("start"); for ($i=0; $i<16; $i+=2) diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl index 7f2e09fa7a..f054071077 100644 --- a/src/lib/libcrypto/des/asm/des-586.pl +++ b/src/lib/libcrypto/des/asm/des-586.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # The inner loop instruction sequence and the IP/FP modifications are from # Svend Olaf Mikkelsen @@ -187,6 +187,8 @@ sub R_PERM_OP &mov( $tt, $a ); &xor( $a, $b ); &and( $a, $mask ); + # This can never succeed, and besides it is difficult to see what the + # idea was - Ben 13 Feb 99 if (!$last eq $b) { &xor( $b, $a ); diff --git a/src/lib/libcrypto/des/asm/des686.pl b/src/lib/libcrypto/des/asm/des686.pl index cf1a82fb5c..77dc5b51cd 100644 --- a/src/lib/libcrypto/des/asm/des686.pl +++ b/src/lib/libcrypto/des/asm/des686.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl $prog="des686.pl"; diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl index 8f939953a6..d5106414db 100644 --- a/src/lib/libcrypto/des/asm/desboth.pl +++ b/src/lib/libcrypto/des/asm/desboth.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl $L="edi"; $R="esi"; @@ -44,15 +44,15 @@ sub des_encrypt3 &mov("edi",&wparam(2)); &mov("eax",&wparam(3)); } - &mov(&swtmp(2), (($enc)?"1":"0")); + &mov(&swtmp(2), (DWC(($enc)?"1":"0"))); &mov(&swtmp(1), "eax"); &mov(&swtmp(0), "ebx"); &call("des_encrypt2"); - &mov(&swtmp(2), (($enc)?"0":"1")); + &mov(&swtmp(2), (DWC(($enc)?"0":"1"))); &mov(&swtmp(1), "edi"); &mov(&swtmp(0), "ebx"); &call("des_encrypt2"); - &mov(&swtmp(2), (($enc)?"1":"0")); + &mov(&swtmp(2), (DWC(($enc)?"1":"0"))); &mov(&swtmp(1), "esi"); &mov(&swtmp(0), "ebx"); &call("des_encrypt2"); diff --git a/src/lib/libcrypto/des/asm/dx86unix.cpp b/src/lib/libcrypto/des/asm/dx86unix.cpp deleted file mode 100644 index 6fca9afa16..0000000000 --- a/src/lib/libcrypto/des/asm/dx86unix.cpp +++ /dev/null @@ -1,3202 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define des_SPtrans _des_SPtrans -#define des_encrypt _des_encrypt -#define des_encrypt2 _des_encrypt2 -#define des_encrypt3 _des_encrypt3 -#define des_decrypt3 _des_decrypt3 -#define des_ncbc_encrypt _des_ncbc_encrypt -#define des_ede3_cbc_encrypt _des_ede3_cbc_encrypt - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by des-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "des-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl des_encrypt - TYPE(des_encrypt,@function) -des_encrypt: - pushl %esi - pushl %edi - - /* Load the 2 words */ - movl 12(%esp), %esi - xorl %ecx, %ecx - pushl %ebx - pushl %ebp - movl (%esi), %eax - movl 28(%esp), %ebx - movl 4(%esi), %edi - - /* IP */ - roll $4, %eax - movl %eax, %esi - xorl %edi, %eax - andl $0xf0f0f0f0, %eax - xorl %eax, %esi - xorl %eax, %edi - - roll $20, %edi - movl %edi, %eax - xorl %esi, %edi - andl $0xfff0000f, %edi - xorl %edi, %eax - xorl %edi, %esi - - roll $14, %eax - movl %eax, %edi - xorl %esi, %eax - andl $0x33333333, %eax - xorl %eax, %edi - xorl %eax, %esi - - roll $22, %esi - movl %esi, %eax - xorl %edi, %esi - andl $0x03fc03fc, %esi - xorl %esi, %eax - xorl %esi, %edi - - roll $9, %eax - movl %eax, %esi - xorl %edi, %eax - andl $0xaaaaaaaa, %eax - xorl %eax, %esi - xorl %eax, %edi - -.byte 209 -.byte 199 /* roll $1 %edi */ - movl 24(%esp), %ebp - cmpl $0, %ebx - je .L000start_decrypt - - /* Round 0 */ - movl (%ebp), %eax - xorl %ebx, %ebx - movl 4(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 1 */ - movl 8(%ebp), %eax - xorl %ebx, %ebx - movl 12(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 2 */ - movl 16(%ebp), %eax - xorl %ebx, %ebx - movl 20(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 3 */ - movl 24(%ebp), %eax - xorl %ebx, %ebx - movl 28(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 4 */ - movl 32(%ebp), %eax - xorl %ebx, %ebx - movl 36(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 5 */ - movl 40(%ebp), %eax - xorl %ebx, %ebx - movl 44(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 6 */ - movl 48(%ebp), %eax - xorl %ebx, %ebx - movl 52(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 7 */ - movl 56(%ebp), %eax - xorl %ebx, %ebx - movl 60(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 8 */ - movl 64(%ebp), %eax - xorl %ebx, %ebx - movl 68(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 9 */ - movl 72(%ebp), %eax - xorl %ebx, %ebx - movl 76(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 10 */ - movl 80(%ebp), %eax - xorl %ebx, %ebx - movl 84(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 11 */ - movl 88(%ebp), %eax - xorl %ebx, %ebx - movl 92(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 12 */ - movl 96(%ebp), %eax - xorl %ebx, %ebx - movl 100(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 13 */ - movl 104(%ebp), %eax - xorl %ebx, %ebx - movl 108(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 14 */ - movl 112(%ebp), %eax - xorl %ebx, %ebx - movl 116(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 15 */ - movl 120(%ebp), %eax - xorl %ebx, %ebx - movl 124(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - jmp .L001end -.L000start_decrypt: - - /* Round 15 */ - movl 120(%ebp), %eax - xorl %ebx, %ebx - movl 124(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 14 */ - movl 112(%ebp), %eax - xorl %ebx, %ebx - movl 116(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 13 */ - movl 104(%ebp), %eax - xorl %ebx, %ebx - movl 108(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 12 */ - movl 96(%ebp), %eax - xorl %ebx, %ebx - movl 100(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 11 */ - movl 88(%ebp), %eax - xorl %ebx, %ebx - movl 92(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 10 */ - movl 80(%ebp), %eax - xorl %ebx, %ebx - movl 84(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 9 */ - movl 72(%ebp), %eax - xorl %ebx, %ebx - movl 76(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 8 */ - movl 64(%ebp), %eax - xorl %ebx, %ebx - movl 68(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 7 */ - movl 56(%ebp), %eax - xorl %ebx, %ebx - movl 60(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 6 */ - movl 48(%ebp), %eax - xorl %ebx, %ebx - movl 52(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 5 */ - movl 40(%ebp), %eax - xorl %ebx, %ebx - movl 44(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 4 */ - movl 32(%ebp), %eax - xorl %ebx, %ebx - movl 36(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 3 */ - movl 24(%ebp), %eax - xorl %ebx, %ebx - movl 28(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 2 */ - movl 16(%ebp), %eax - xorl %ebx, %ebx - movl 20(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 1 */ - movl 8(%ebp), %eax - xorl %ebx, %ebx - movl 12(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 0 */ - movl (%ebp), %eax - xorl %ebx, %ebx - movl 4(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi -.L001end: - - /* FP */ - movl 20(%esp), %edx -.byte 209 -.byte 206 /* rorl $1 %esi */ - movl %edi, %eax - xorl %esi, %edi - andl $0xaaaaaaaa, %edi - xorl %edi, %eax - xorl %edi, %esi - - roll $23, %eax - movl %eax, %edi - xorl %esi, %eax - andl $0x03fc03fc, %eax - xorl %eax, %edi - xorl %eax, %esi - - roll $10, %edi - movl %edi, %eax - xorl %esi, %edi - andl $0x33333333, %edi - xorl %edi, %eax - xorl %edi, %esi - - roll $18, %esi - movl %esi, %edi - xorl %eax, %esi - andl $0xfff0000f, %esi - xorl %esi, %edi - xorl %esi, %eax - - roll $12, %edi - movl %edi, %esi - xorl %eax, %edi - andl $0xf0f0f0f0, %edi - xorl %edi, %esi - xorl %edi, %eax - - rorl $4, %eax - movl %eax, (%edx) - movl %esi, 4(%edx) - popl %ebp - popl %ebx - popl %edi - popl %esi - ret -.des_encrypt_end: - SIZE(des_encrypt,.des_encrypt_end-des_encrypt) -.ident "desasm.pl" -.text - .align ALIGN -.globl des_encrypt2 - TYPE(des_encrypt2,@function) -des_encrypt2: - pushl %esi - pushl %edi - - /* Load the 2 words */ - movl 12(%esp), %eax - xorl %ecx, %ecx - pushl %ebx - pushl %ebp - movl (%eax), %esi - movl 28(%esp), %ebx - roll $3, %esi - movl 4(%eax), %edi - roll $3, %edi - movl 24(%esp), %ebp - cmpl $0, %ebx - je .L002start_decrypt - - /* Round 0 */ - movl (%ebp), %eax - xorl %ebx, %ebx - movl 4(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 1 */ - movl 8(%ebp), %eax - xorl %ebx, %ebx - movl 12(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 2 */ - movl 16(%ebp), %eax - xorl %ebx, %ebx - movl 20(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 3 */ - movl 24(%ebp), %eax - xorl %ebx, %ebx - movl 28(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 4 */ - movl 32(%ebp), %eax - xorl %ebx, %ebx - movl 36(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 5 */ - movl 40(%ebp), %eax - xorl %ebx, %ebx - movl 44(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 6 */ - movl 48(%ebp), %eax - xorl %ebx, %ebx - movl 52(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 7 */ - movl 56(%ebp), %eax - xorl %ebx, %ebx - movl 60(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 8 */ - movl 64(%ebp), %eax - xorl %ebx, %ebx - movl 68(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 9 */ - movl 72(%ebp), %eax - xorl %ebx, %ebx - movl 76(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 10 */ - movl 80(%ebp), %eax - xorl %ebx, %ebx - movl 84(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 11 */ - movl 88(%ebp), %eax - xorl %ebx, %ebx - movl 92(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 12 */ - movl 96(%ebp), %eax - xorl %ebx, %ebx - movl 100(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 13 */ - movl 104(%ebp), %eax - xorl %ebx, %ebx - movl 108(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 14 */ - movl 112(%ebp), %eax - xorl %ebx, %ebx - movl 116(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 15 */ - movl 120(%ebp), %eax - xorl %ebx, %ebx - movl 124(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - jmp .L003end -.L002start_decrypt: - - /* Round 15 */ - movl 120(%ebp), %eax - xorl %ebx, %ebx - movl 124(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 14 */ - movl 112(%ebp), %eax - xorl %ebx, %ebx - movl 116(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 13 */ - movl 104(%ebp), %eax - xorl %ebx, %ebx - movl 108(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 12 */ - movl 96(%ebp), %eax - xorl %ebx, %ebx - movl 100(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 11 */ - movl 88(%ebp), %eax - xorl %ebx, %ebx - movl 92(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 10 */ - movl 80(%ebp), %eax - xorl %ebx, %ebx - movl 84(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 9 */ - movl 72(%ebp), %eax - xorl %ebx, %ebx - movl 76(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 8 */ - movl 64(%ebp), %eax - xorl %ebx, %ebx - movl 68(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 7 */ - movl 56(%ebp), %eax - xorl %ebx, %ebx - movl 60(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 6 */ - movl 48(%ebp), %eax - xorl %ebx, %ebx - movl 52(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 5 */ - movl 40(%ebp), %eax - xorl %ebx, %ebx - movl 44(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 4 */ - movl 32(%ebp), %eax - xorl %ebx, %ebx - movl 36(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 3 */ - movl 24(%ebp), %eax - xorl %ebx, %ebx - movl 28(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 2 */ - movl 16(%ebp), %eax - xorl %ebx, %ebx - movl 20(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 1 */ - movl 8(%ebp), %eax - xorl %ebx, %ebx - movl 12(%ebp), %edx - xorl %esi, %eax - xorl %esi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 0 */ - movl (%ebp), %eax - xorl %ebx, %ebx - movl 4(%ebp), %edx - xorl %edi, %eax - xorl %edi, %edx - andl $0xfcfcfcfc, %eax - andl $0xcfcfcfcf, %edx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi -.L003end: - - /* Fixup */ - rorl $3, %edi - movl 20(%esp), %eax - rorl $3, %esi - movl %edi, (%eax) - movl %esi, 4(%eax) - popl %ebp - popl %ebx - popl %edi - popl %esi - ret -.des_encrypt2_end: - SIZE(des_encrypt2,.des_encrypt2_end-des_encrypt2) -.ident "desasm.pl" -.text - .align ALIGN -.globl des_encrypt3 - TYPE(des_encrypt3,@function) -des_encrypt3: - pushl %ebx - movl 8(%esp), %ebx - pushl %ebp - pushl %esi - pushl %edi - - /* Load the data words */ - movl (%ebx), %edi - movl 4(%ebx), %esi - subl $12, %esp - - /* IP */ - roll $4, %edi - movl %edi, %edx - xorl %esi, %edi - andl $0xf0f0f0f0, %edi - xorl %edi, %edx - xorl %edi, %esi - - roll $20, %esi - movl %esi, %edi - xorl %edx, %esi - andl $0xfff0000f, %esi - xorl %esi, %edi - xorl %esi, %edx - - roll $14, %edi - movl %edi, %esi - xorl %edx, %edi - andl $0x33333333, %edi - xorl %edi, %esi - xorl %edi, %edx - - roll $22, %edx - movl %edx, %edi - xorl %esi, %edx - andl $0x03fc03fc, %edx - xorl %edx, %edi - xorl %edx, %esi - - roll $9, %edi - movl %edi, %edx - xorl %esi, %edi - andl $0xaaaaaaaa, %edi - xorl %edi, %edx - xorl %edi, %esi - - rorl $3, %edx - rorl $2, %esi - movl %esi, 4(%ebx) - movl 36(%esp), %eax - movl %edx, (%ebx) - movl 40(%esp), %edi - movl 44(%esp), %esi - movl $1, 8(%esp) - movl %eax, 4(%esp) - movl %ebx, (%esp) - call des_encrypt2 - movl $0, 8(%esp) - movl %edi, 4(%esp) - movl %ebx, (%esp) - call des_encrypt2 - movl $1, 8(%esp) - movl %esi, 4(%esp) - movl %ebx, (%esp) - call des_encrypt2 - addl $12, %esp - movl (%ebx), %edi - movl 4(%ebx), %esi - - /* FP */ - roll $2, %esi - roll $3, %edi - movl %edi, %eax - xorl %esi, %edi - andl $0xaaaaaaaa, %edi - xorl %edi, %eax - xorl %edi, %esi - - roll $23, %eax - movl %eax, %edi - xorl %esi, %eax - andl $0x03fc03fc, %eax - xorl %eax, %edi - xorl %eax, %esi - - roll $10, %edi - movl %edi, %eax - xorl %esi, %edi - andl $0x33333333, %edi - xorl %edi, %eax - xorl %edi, %esi - - roll $18, %esi - movl %esi, %edi - xorl %eax, %esi - andl $0xfff0000f, %esi - xorl %esi, %edi - xorl %esi, %eax - - roll $12, %edi - movl %edi, %esi - xorl %eax, %edi - andl $0xf0f0f0f0, %edi - xorl %edi, %esi - xorl %edi, %eax - - rorl $4, %eax - movl %eax, (%ebx) - movl %esi, 4(%ebx) - popl %edi - popl %esi - popl %ebp - popl %ebx - ret -.des_encrypt3_end: - SIZE(des_encrypt3,.des_encrypt3_end-des_encrypt3) -.ident "desasm.pl" -.text - .align ALIGN -.globl des_decrypt3 - TYPE(des_decrypt3,@function) -des_decrypt3: - pushl %ebx - movl 8(%esp), %ebx - pushl %ebp - pushl %esi - pushl %edi - - /* Load the data words */ - movl (%ebx), %edi - movl 4(%ebx), %esi - subl $12, %esp - - /* IP */ - roll $4, %edi - movl %edi, %edx - xorl %esi, %edi - andl $0xf0f0f0f0, %edi - xorl %edi, %edx - xorl %edi, %esi - - roll $20, %esi - movl %esi, %edi - xorl %edx, %esi - andl $0xfff0000f, %esi - xorl %esi, %edi - xorl %esi, %edx - - roll $14, %edi - movl %edi, %esi - xorl %edx, %edi - andl $0x33333333, %edi - xorl %edi, %esi - xorl %edi, %edx - - roll $22, %edx - movl %edx, %edi - xorl %esi, %edx - andl $0x03fc03fc, %edx - xorl %edx, %edi - xorl %edx, %esi - - roll $9, %edi - movl %edi, %edx - xorl %esi, %edi - andl $0xaaaaaaaa, %edi - xorl %edi, %edx - xorl %edi, %esi - - rorl $3, %edx - rorl $2, %esi - movl %esi, 4(%ebx) - movl 36(%esp), %esi - movl %edx, (%ebx) - movl 40(%esp), %edi - movl 44(%esp), %eax - movl $0, 8(%esp) - movl %eax, 4(%esp) - movl %ebx, (%esp) - call des_encrypt2 - movl $1, 8(%esp) - movl %edi, 4(%esp) - movl %ebx, (%esp) - call des_encrypt2 - movl $0, 8(%esp) - movl %esi, 4(%esp) - movl %ebx, (%esp) - call des_encrypt2 - addl $12, %esp - movl (%ebx), %edi - movl 4(%ebx), %esi - - /* FP */ - roll $2, %esi - roll $3, %edi - movl %edi, %eax - xorl %esi, %edi - andl $0xaaaaaaaa, %edi - xorl %edi, %eax - xorl %edi, %esi - - roll $23, %eax - movl %eax, %edi - xorl %esi, %eax - andl $0x03fc03fc, %eax - xorl %eax, %edi - xorl %eax, %esi - - roll $10, %edi - movl %edi, %eax - xorl %esi, %edi - andl $0x33333333, %edi - xorl %edi, %eax - xorl %edi, %esi - - roll $18, %esi - movl %esi, %edi - xorl %eax, %esi - andl $0xfff0000f, %esi - xorl %esi, %edi - xorl %esi, %eax - - roll $12, %edi - movl %edi, %esi - xorl %eax, %edi - andl $0xf0f0f0f0, %edi - xorl %edi, %esi - xorl %edi, %eax - - rorl $4, %eax - movl %eax, (%ebx) - movl %esi, 4(%ebx) - popl %edi - popl %esi - popl %ebp - popl %ebx - ret -.des_decrypt3_end: - SIZE(des_decrypt3,.des_decrypt3_end-des_decrypt3) -.ident "desasm.pl" -.text - .align ALIGN -.globl des_ncbc_encrypt - TYPE(des_ncbc_encrypt,@function) -des_ncbc_encrypt: - - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - movl 28(%esp), %ebp - /* getting iv ptr from parameter 4 */ - movl 36(%esp), %ebx - movl (%ebx), %esi - movl 4(%ebx), %edi - pushl %edi - pushl %esi - pushl %edi - pushl %esi - movl %esp, %ebx - movl 36(%esp), %esi - movl 40(%esp), %edi - /* getting encrypt flag from parameter 5 */ - movl 56(%esp), %ecx - /* get and push parameter 5 */ - pushl %ecx - /* get and push parameter 3 */ - movl 52(%esp), %eax - pushl %eax - pushl %ebx - cmpl $0, %ecx - jz .L004decrypt - andl $4294967288, %ebp - movl 12(%esp), %eax - movl 16(%esp), %ebx - jz .L005encrypt_finish -.L006encrypt_loop: - movl (%esi), %ecx - movl 4(%esi), %edx - xorl %ecx, %eax - xorl %edx, %ebx - movl %eax, 12(%esp) - movl %ebx, 16(%esp) - call des_encrypt - movl 12(%esp), %eax - movl 16(%esp), %ebx - movl %eax, (%edi) - movl %ebx, 4(%edi) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L006encrypt_loop -.L005encrypt_finish: - movl 56(%esp), %ebp - andl $7, %ebp - jz .L007finish - xorl %ecx, %ecx - xorl %edx, %edx - movl .L008cbc_enc_jmp_table(,%ebp,4),%ebp - jmp *%ebp -.L009ej7: - movb 6(%esi), %dh - sall $8, %edx -.L010ej6: - movb 5(%esi), %dh -.L011ej5: - movb 4(%esi), %dl -.L012ej4: - movl (%esi), %ecx - jmp .L013ejend -.L014ej3: - movb 2(%esi), %ch - sall $8, %ecx -.L015ej2: - movb 1(%esi), %ch -.L016ej1: - movb (%esi), %cl -.L013ejend: - xorl %ecx, %eax - xorl %edx, %ebx - movl %eax, 12(%esp) - movl %ebx, 16(%esp) - call des_encrypt - movl 12(%esp), %eax - movl 16(%esp), %ebx - movl %eax, (%edi) - movl %ebx, 4(%edi) - jmp .L007finish -.align ALIGN -.L004decrypt: - andl $4294967288, %ebp - movl 20(%esp), %eax - movl 24(%esp), %ebx - jz .L017decrypt_finish -.L018decrypt_loop: - movl (%esi), %eax - movl 4(%esi), %ebx - movl %eax, 12(%esp) - movl %ebx, 16(%esp) - call des_encrypt - movl 12(%esp), %eax - movl 16(%esp), %ebx - movl 20(%esp), %ecx - movl 24(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx - movl %ecx, (%edi) - movl %edx, 4(%edi) - movl %eax, 20(%esp) - movl %ebx, 24(%esp) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L018decrypt_loop -.L017decrypt_finish: - movl 56(%esp), %ebp - andl $7, %ebp - jz .L007finish - movl (%esi), %eax - movl 4(%esi), %ebx - movl %eax, 12(%esp) - movl %ebx, 16(%esp) - call des_encrypt - movl 12(%esp), %eax - movl 16(%esp), %ebx - movl 20(%esp), %ecx - movl 24(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx -.L019dj7: - rorl $16, %edx - movb %dl, 6(%edi) - shrl $16, %edx -.L020dj6: - movb %dh, 5(%edi) -.L021dj5: - movb %dl, 4(%edi) -.L022dj4: - movl %ecx, (%edi) - jmp .L023djend -.L024dj3: - rorl $16, %ecx - movb %cl, 2(%edi) - sall $16, %ecx -.L025dj2: - movb %ch, 1(%esi) -.L026dj1: - movb %cl, (%esi) -.L023djend: - jmp .L007finish -.align ALIGN -.L007finish: - movl 64(%esp), %ecx - addl $28, %esp - movl %eax, (%ecx) - movl %ebx, 4(%ecx) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.align ALIGN -.L008cbc_enc_jmp_table: - .long 0 - .long .L016ej1 - .long .L015ej2 - .long .L014ej3 - .long .L012ej4 - .long .L011ej5 - .long .L010ej6 - .long .L009ej7 -.align ALIGN -.L027cbc_dec_jmp_table: - .long 0 - .long .L026dj1 - .long .L025dj2 - .long .L024dj3 - .long .L022dj4 - .long .L021dj5 - .long .L020dj6 - .long .L019dj7 -.des_ncbc_encrypt_end: - SIZE(des_ncbc_encrypt,.des_ncbc_encrypt_end-des_ncbc_encrypt) -.ident "desasm.pl" -.text - .align ALIGN -.globl des_ede3_cbc_encrypt - TYPE(des_ede3_cbc_encrypt,@function) -des_ede3_cbc_encrypt: - - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - movl 28(%esp), %ebp - /* getting iv ptr from parameter 6 */ - movl 44(%esp), %ebx - movl (%ebx), %esi - movl 4(%ebx), %edi - pushl %edi - pushl %esi - pushl %edi - pushl %esi - movl %esp, %ebx - movl 36(%esp), %esi - movl 40(%esp), %edi - /* getting encrypt flag from parameter 7 */ - movl 64(%esp), %ecx - /* get and push parameter 5 */ - movl 56(%esp), %eax - pushl %eax - /* get and push parameter 4 */ - movl 56(%esp), %eax - pushl %eax - /* get and push parameter 3 */ - movl 56(%esp), %eax - pushl %eax - pushl %ebx - cmpl $0, %ecx - jz .L028decrypt - andl $4294967288, %ebp - movl 16(%esp), %eax - movl 20(%esp), %ebx - jz .L029encrypt_finish -.L030encrypt_loop: - movl (%esi), %ecx - movl 4(%esi), %edx - xorl %ecx, %eax - xorl %edx, %ebx - movl %eax, 16(%esp) - movl %ebx, 20(%esp) - call des_encrypt3 - movl 16(%esp), %eax - movl 20(%esp), %ebx - movl %eax, (%edi) - movl %ebx, 4(%edi) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L030encrypt_loop -.L029encrypt_finish: - movl 60(%esp), %ebp - andl $7, %ebp - jz .L031finish - xorl %ecx, %ecx - xorl %edx, %edx - movl .L032cbc_enc_jmp_table(,%ebp,4),%ebp - jmp *%ebp -.L033ej7: - movb 6(%esi), %dh - sall $8, %edx -.L034ej6: - movb 5(%esi), %dh -.L035ej5: - movb 4(%esi), %dl -.L036ej4: - movl (%esi), %ecx - jmp .L037ejend -.L038ej3: - movb 2(%esi), %ch - sall $8, %ecx -.L039ej2: - movb 1(%esi), %ch -.L040ej1: - movb (%esi), %cl -.L037ejend: - xorl %ecx, %eax - xorl %edx, %ebx - movl %eax, 16(%esp) - movl %ebx, 20(%esp) - call des_encrypt3 - movl 16(%esp), %eax - movl 20(%esp), %ebx - movl %eax, (%edi) - movl %ebx, 4(%edi) - jmp .L031finish -.align ALIGN -.L028decrypt: - andl $4294967288, %ebp - movl 24(%esp), %eax - movl 28(%esp), %ebx - jz .L041decrypt_finish -.L042decrypt_loop: - movl (%esi), %eax - movl 4(%esi), %ebx - movl %eax, 16(%esp) - movl %ebx, 20(%esp) - call des_decrypt3 - movl 16(%esp), %eax - movl 20(%esp), %ebx - movl 24(%esp), %ecx - movl 28(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx - movl %ecx, (%edi) - movl %edx, 4(%edi) - movl %eax, 24(%esp) - movl %ebx, 28(%esp) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L042decrypt_loop -.L041decrypt_finish: - movl 60(%esp), %ebp - andl $7, %ebp - jz .L031finish - movl (%esi), %eax - movl 4(%esi), %ebx - movl %eax, 16(%esp) - movl %ebx, 20(%esp) - call des_decrypt3 - movl 16(%esp), %eax - movl 20(%esp), %ebx - movl 24(%esp), %ecx - movl 28(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx -.L043dj7: - rorl $16, %edx - movb %dl, 6(%edi) - shrl $16, %edx -.L044dj6: - movb %dh, 5(%edi) -.L045dj5: - movb %dl, 4(%edi) -.L046dj4: - movl %ecx, (%edi) - jmp .L047djend -.L048dj3: - rorl $16, %ecx - movb %cl, 2(%edi) - sall $16, %ecx -.L049dj2: - movb %ch, 1(%esi) -.L050dj1: - movb %cl, (%esi) -.L047djend: - jmp .L031finish -.align ALIGN -.L031finish: - movl 76(%esp), %ecx - addl $32, %esp - movl %eax, (%ecx) - movl %ebx, 4(%ecx) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.align ALIGN -.L032cbc_enc_jmp_table: - .long 0 - .long .L040ej1 - .long .L039ej2 - .long .L038ej3 - .long .L036ej4 - .long .L035ej5 - .long .L034ej6 - .long .L033ej7 -.align ALIGN -.L051cbc_dec_jmp_table: - .long 0 - .long .L050dj1 - .long .L049dj2 - .long .L048dj3 - .long .L046dj4 - .long .L045dj5 - .long .L044dj6 - .long .L043dj7 -.des_ede3_cbc_encrypt_end: - SIZE(des_ede3_cbc_encrypt,.des_ede3_cbc_encrypt_end-des_ede3_cbc_encrypt) -.ident "desasm.pl" diff --git a/src/lib/libcrypto/des/asm/yx86unix.cpp b/src/lib/libcrypto/des/asm/yx86unix.cpp deleted file mode 100644 index 8719e38607..0000000000 --- a/src/lib/libcrypto/des/asm/yx86unix.cpp +++ /dev/null @@ -1,976 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define des_SPtrans _des_SPtrans -#define fcrypt_body _fcrypt_body - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by crypt586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "crypt586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl fcrypt_body - TYPE(fcrypt_body,@function) -fcrypt_body: - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - - - /* Load the 2 words */ - xorl %edi, %edi - xorl %esi, %esi - movl 24(%esp), %ebp - pushl $25 -.L000start: - - /* Round 0 */ - movl 32(%esp), %eax - movl %esi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %esi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl (%ebp), %ebx - xorl %ebx, %eax - movl 4(%ebp), %ecx - xorl %esi, %eax - xorl %esi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 1 */ - movl 32(%esp), %eax - movl %edi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %edi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 8(%ebp), %ebx - xorl %ebx, %eax - movl 12(%ebp), %ecx - xorl %edi, %eax - xorl %edi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 2 */ - movl 32(%esp), %eax - movl %esi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %esi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 16(%ebp), %ebx - xorl %ebx, %eax - movl 20(%ebp), %ecx - xorl %esi, %eax - xorl %esi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 3 */ - movl 32(%esp), %eax - movl %edi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %edi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 24(%ebp), %ebx - xorl %ebx, %eax - movl 28(%ebp), %ecx - xorl %edi, %eax - xorl %edi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 4 */ - movl 32(%esp), %eax - movl %esi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %esi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 32(%ebp), %ebx - xorl %ebx, %eax - movl 36(%ebp), %ecx - xorl %esi, %eax - xorl %esi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 5 */ - movl 32(%esp), %eax - movl %edi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %edi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 40(%ebp), %ebx - xorl %ebx, %eax - movl 44(%ebp), %ecx - xorl %edi, %eax - xorl %edi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 6 */ - movl 32(%esp), %eax - movl %esi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %esi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 48(%ebp), %ebx - xorl %ebx, %eax - movl 52(%ebp), %ecx - xorl %esi, %eax - xorl %esi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 7 */ - movl 32(%esp), %eax - movl %edi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %edi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 56(%ebp), %ebx - xorl %ebx, %eax - movl 60(%ebp), %ecx - xorl %edi, %eax - xorl %edi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 8 */ - movl 32(%esp), %eax - movl %esi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %esi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 64(%ebp), %ebx - xorl %ebx, %eax - movl 68(%ebp), %ecx - xorl %esi, %eax - xorl %esi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 9 */ - movl 32(%esp), %eax - movl %edi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %edi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 72(%ebp), %ebx - xorl %ebx, %eax - movl 76(%ebp), %ecx - xorl %edi, %eax - xorl %edi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 10 */ - movl 32(%esp), %eax - movl %esi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %esi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 80(%ebp), %ebx - xorl %ebx, %eax - movl 84(%ebp), %ecx - xorl %esi, %eax - xorl %esi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 11 */ - movl 32(%esp), %eax - movl %edi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %edi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 88(%ebp), %ebx - xorl %ebx, %eax - movl 92(%ebp), %ecx - xorl %edi, %eax - xorl %edi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 12 */ - movl 32(%esp), %eax - movl %esi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %esi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 96(%ebp), %ebx - xorl %ebx, %eax - movl 100(%ebp), %ecx - xorl %esi, %eax - xorl %esi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 13 */ - movl 32(%esp), %eax - movl %edi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %edi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 104(%ebp), %ebx - xorl %ebx, %eax - movl 108(%ebp), %ecx - xorl %edi, %eax - xorl %edi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - - /* Round 14 */ - movl 32(%esp), %eax - movl %esi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %esi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 112(%ebp), %ebx - xorl %ebx, %eax - movl 116(%ebp), %ecx - xorl %esi, %eax - xorl %esi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %edi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %edi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %edi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %edi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %edi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %edi - - /* Round 15 */ - movl 32(%esp), %eax - movl %edi, %edx - shrl $16, %edx - movl 36(%esp), %ecx - xorl %edi, %edx - andl %edx, %eax - andl %ecx, %edx - movl %eax, %ebx - sall $16, %ebx - movl %edx, %ecx - sall $16, %ecx - xorl %ebx, %eax - xorl %ecx, %edx - movl 120(%ebp), %ebx - xorl %ebx, %eax - movl 124(%ebp), %ecx - xorl %edi, %eax - xorl %edi, %edx - xorl %ecx, %edx - andl $0xfcfcfcfc, %eax - xorl %ebx, %ebx - andl $0xcfcfcfcf, %edx - xorl %ecx, %ecx - movb %al, %bl - movb %ah, %cl - rorl $4, %edx - movl des_SPtrans(%ebx),%ebp - movb %dl, %bl - xorl %ebp, %esi - movl 0x200+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movb %dh, %cl - shrl $16, %eax - movl 0x100+des_SPtrans(%ebx),%ebp - xorl %ebp, %esi - movb %ah, %bl - shrl $16, %edx - movl 0x300+des_SPtrans(%ecx),%ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - movb %dh, %cl - andl $0xff, %eax - andl $0xff, %edx - movl 0x600+des_SPtrans(%ebx),%ebx - xorl %ebx, %esi - movl 0x700+des_SPtrans(%ecx),%ebx - xorl %ebx, %esi - movl 0x400+des_SPtrans(%eax),%ebx - xorl %ebx, %esi - movl 0x500+des_SPtrans(%edx),%ebx - xorl %ebx, %esi - movl (%esp), %ebx - movl %edi, %eax - decl %ebx - movl %esi, %edi - movl %eax, %esi - movl %ebx, (%esp) - jnz .L000start - - /* FP */ - movl 24(%esp), %edx -.byte 209 -.byte 207 /* rorl $1 %edi */ - movl %esi, %eax - xorl %edi, %esi - andl $0xaaaaaaaa, %esi - xorl %esi, %eax - xorl %esi, %edi - - roll $23, %eax - movl %eax, %esi - xorl %edi, %eax - andl $0x03fc03fc, %eax - xorl %eax, %esi - xorl %eax, %edi - - roll $10, %esi - movl %esi, %eax - xorl %edi, %esi - andl $0x33333333, %esi - xorl %esi, %eax - xorl %esi, %edi - - roll $18, %edi - movl %edi, %esi - xorl %eax, %edi - andl $0xfff0000f, %edi - xorl %edi, %esi - xorl %edi, %eax - - roll $12, %esi - movl %esi, %edi - xorl %eax, %esi - andl $0xf0f0f0f0, %esi - xorl %esi, %edi - xorl %esi, %eax - - rorl $4, %eax - movl %eax, (%edx) - movl %edi, 4(%edx) - popl %ecx - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.fcrypt_body_end: - SIZE(fcrypt_body,.fcrypt_body_end-fcrypt_body) -.ident "fcrypt_body" diff --git a/src/lib/libcrypto/des/cbc3_enc.c b/src/lib/libcrypto/des/cbc3_enc.c index 92a78b05d6..3863a676d4 100644 --- a/src/lib/libcrypto/des/cbc3_enc.c +++ b/src/lib/libcrypto/des/cbc3_enc.c @@ -59,15 +59,9 @@ #include "des_locl.h" /* HAS BUGS? DON'T USE - this is only present for use in des.c */ -void des_3cbc_encrypt(input, output, length, ks1, ks2, iv1, iv2, enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule ks1; -des_key_schedule ks2; -des_cblock (*iv1); -des_cblock (*iv2); -int enc; +void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length, + des_key_schedule ks1, des_key_schedule ks2, des_cblock *iv1, + des_cblock *iv2, int enc) { int off=((int)length-1)/8; long l8=((length+7)/8)*8; diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c index edfdec8a0f..1e543cb2a1 100644 --- a/src/lib/libcrypto/des/cbc_cksm.c +++ b/src/lib/libcrypto/des/cbc_cksm.c @@ -58,21 +58,15 @@ #include "des_locl.h" -DES_LONG des_cbc_cksum(input, output, length, schedule, ivec) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule schedule; -des_cblock (*ivec); +DES_LONG des_cbc_cksum(const unsigned char *in, des_cblock *output, + long length, + des_key_schedule schedule, const_des_cblock *ivec) { register DES_LONG tout0,tout1,tin0,tin1; register long l=length; DES_LONG tin[2]; - unsigned char *in,*out,*iv; - - in=(unsigned char *)input; - out=(unsigned char *)output; - iv=(unsigned char *)ivec; + unsigned char *out = &(*output)[0]; + const unsigned char *iv = &(*ivec)[0]; c2l(iv,tout0); c2l(iv,tout1); diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c index a84a53633c..677903ae4e 100644 --- a/src/lib/libcrypto/des/cbc_enc.c +++ b/src/lib/libcrypto/des/cbc_enc.c @@ -56,80 +56,6 @@ * [including the GNU Public Licence.] */ -#include "des_locl.h" - -void des_cbc_encrypt(input, output, length, schedule, ivec, enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule schedule; -des_cblock (*ivec); -int enc; - { - register DES_LONG tin0,tin1; - register DES_LONG tout0,tout1,xor0,xor1; - register unsigned char *in,*out; - register long l=length; - DES_LONG tin[2]; - unsigned char *iv; - - in=(unsigned char *)input; - out=(unsigned char *)output; - iv=(unsigned char *)ivec; - - if (enc) - { - c2l(iv,tout0); - c2l(iv,tout1); - for (l-=8; l>=0; l-=8) - { - c2l(in,tin0); - c2l(in,tin1); - tin0^=tout0; tin[0]=tin0; - tin1^=tout1; tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); - tout0=tin[0]; l2c(tout0,out); - tout1=tin[1]; l2c(tout1,out); - } - if (l != -8) - { - c2ln(in,tin0,tin1,l+8); - tin0^=tout0; tin[0]=tin0; - tin1^=tout1; tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); - tout0=tin[0]; l2c(tout0,out); - tout1=tin[1]; l2c(tout1,out); - } - } - else - { - c2l(iv,xor0); - c2l(iv,xor1); - for (l-=8; l>=0; l-=8) - { - c2l(in,tin0); tin[0]=tin0; - c2l(in,tin1); tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); - tout0=tin[0]^xor0; - tout1=tin[1]^xor1; - l2c(tout0,out); - l2c(tout1,out); - xor0=tin0; - xor1=tin1; - } - if (l != -8) - { - c2l(in,tin0); tin[0]=tin0; - c2l(in,tin1); tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); - tout0=tin[0]^xor0; - tout1=tin[1]^xor1; - l2cn(tout0,tout1,out,l+8); - /* xor0=tin0; - xor1=tin1; */ - } - } - tin0=tin1=tout0=tout1=xor0=xor1=0; - tin[0]=tin[1]=0; - } +#define CBC_ENC_C__DONT_UPDATE_IV +#include "ncbc_enc.c" /* des_cbc_encrypt */ diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c index 80b8a9eaaa..5362a551bf 100644 --- a/src/lib/libcrypto/des/cfb64ede.c +++ b/src/lib/libcrypto/des/cfb64ede.c @@ -63,14 +63,9 @@ * 64bit block we have used is contained in *num; */ -void des_ede3_cfb64_encrypt(in, out, length, ks1,ks2,ks3, ivec, num, enc) -unsigned char *in; -unsigned char *out; -long length; -des_key_schedule ks1,ks2,ks3; -des_cblock (*ivec); -int *num; -int enc; +void des_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, des_key_schedule ks1, des_key_schedule ks2, + des_key_schedule ks3, des_cblock *ivec, int *num, int enc) { register DES_LONG v0,v1; register long l=length; @@ -78,7 +73,7 @@ int enc; DES_LONG ti[2]; unsigned char *iv,c,cc; - iv=(unsigned char *)ivec; + iv=&(*ivec)[0]; if (enc) { while (l--) @@ -90,14 +85,14 @@ int enc; ti[0]=v0; ti[1]=v1; - des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); + des_encrypt3(ti,ks1,ks2,ks3); v0=ti[0]; v1=ti[1]; - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(v0,iv); l2c(v1,iv); - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; } c= *(in++)^iv[n]; *(out++)=c; @@ -116,14 +111,14 @@ int enc; ti[0]=v0; ti[1]=v1; - des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); + des_encrypt3(ti,ks1,ks2,ks3); v0=ti[0]; v1=ti[1]; - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(v0,iv); l2c(v1,iv); - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; } cc= *(in++); c=iv[n]; @@ -137,14 +132,9 @@ int enc; } #ifdef undef /* MACRO */ -void des_ede2_cfb64_encrypt(in, out, length, ks1,ks2, ivec, num, enc) -unsigned char *in; -unsigned char *out; -long length; -des_key_schedule ks1,ks2; -des_cblock (*ivec); -int *num; -int enc; +void des_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, + des_key_schedule ks1, des_key_schedule ks2, des_cblock (*ivec), + int *num, int enc) { des_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc); } diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c index 403da479df..389a232cb3 100644 --- a/src/lib/libcrypto/des/cfb64enc.c +++ b/src/lib/libcrypto/des/cfb64enc.c @@ -63,14 +63,9 @@ * 64bit block we have used is contained in *num; */ -void des_cfb64_encrypt(in, out, length, schedule, ivec, num, enc) -unsigned char *in; -unsigned char *out; -long length; -des_key_schedule schedule; -des_cblock (*ivec); -int *num; -int enc; +void des_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, des_key_schedule schedule, des_cblock *ivec, + int *num, int enc) { register DES_LONG v0,v1; register long l=length; @@ -78,7 +73,7 @@ int enc; DES_LONG ti[2]; unsigned char *iv,c,cc; - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; if (enc) { while (l--) @@ -87,12 +82,11 @@ int enc; { c2l(iv,v0); ti[0]=v0; c2l(iv,v1); ti[1]=v1; - des_encrypt((DES_LONG *)ti, - schedule,DES_ENCRYPT); - iv=(unsigned char *)ivec; + des_encrypt(ti,schedule,DES_ENCRYPT); + iv = &(*ivec)[0]; v0=ti[0]; l2c(v0,iv); v0=ti[1]; l2c(v0,iv); - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; } c= *(in++)^iv[n]; *(out++)=c; @@ -108,12 +102,11 @@ int enc; { c2l(iv,v0); ti[0]=v0; c2l(iv,v1); ti[1]=v1; - des_encrypt((DES_LONG *)ti, - schedule,DES_ENCRYPT); - iv=(unsigned char *)ivec; + des_encrypt(ti,schedule,DES_ENCRYPT); + iv = &(*ivec)[0]; v0=ti[0]; l2c(v0,iv); v0=ti[1]; l2c(v0,iv); - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; } cc= *(in++); c=iv[n]; diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c index 342e785691..cca34dd7c5 100644 --- a/src/lib/libcrypto/des/cfb_enc.c +++ b/src/lib/libcrypto/des/cfb_enc.c @@ -64,14 +64,8 @@ * the second. The second 12 bits will come from the 3rd and half the 4th * byte. */ -void des_cfb_encrypt(in, out, numbits, length, schedule, ivec, enc) -unsigned char *in; -unsigned char *out; -int numbits; -long length; -des_key_schedule schedule; -des_cblock (*ivec); -int enc; +void des_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, + long length, des_key_schedule schedule, des_cblock *ivec, int enc) { register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8; register DES_LONG mask0,mask1; @@ -96,7 +90,7 @@ int enc; mask1=0x00000000L; } - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; c2l(iv,v0); c2l(iv,v1); if (enc) @@ -163,7 +157,7 @@ int enc; out+=n; } } - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(v0,iv); l2c(v1,iv); v0=v1=d0=d1=ti[0]=ti[1]=0; diff --git a/src/lib/libcrypto/des/des-lib.com b/src/lib/libcrypto/des/des-lib.com new file mode 100644 index 0000000000..2aea7a0dea --- /dev/null +++ b/src/lib/libcrypto/des/des-lib.com @@ -0,0 +1,1003 @@ +$! +$! DES-LIB.COM +$! Written By: Robert Byer +$! Vice-President +$! A-Com Computing, Inc. +$! byer@mail.all-net.net +$! +$! Changes by Richard Levitte +$! +$! This command files compiles and creates the +$! "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" library. The "xxx" denotes the machine +$! architecture of AXP or VAX. +$! +$! It was re-written to try to determine which "C" compiler to try to use +$! or the user can specify a compiler in P3. +$! +$! Specify one of the following to build just that part, specify "ALL" to +$! just build everything. +$! +$! ALL To Just Build "Everything". +$! LIBRARY To Just Build The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library. +$! DESTEST To Just Build The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program. +$! SPEED To Just Build The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program. +$! RPW To Just Build The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program. +$! DES To Just Build The [.xxx.EXE.CRYPTO.DES]DES.EXE Program. +$! DES_OPTS To Just Build The [.xxx.EXE.CRYPTO.DES]DES_OPTS.EXE Program. +$! +$! Specify either DEBUG or NODEBUG as P2 to compile with or without +$! debugging information. +$! +$! Specify which compiler at P3 to try to compile under. +$! +$! VAXC For VAX C. +$! DECC For DEC C. +$! GNUC For GNU C. +$! +$! If you don't speficy a compiler, it will try to determine which +$! "C" compiler to try to use. +$! +$! P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up) +$! +$! +$! Make sure we know what architecture we run on. +$! +$! +$! Check Which Architecture We Are Using. +$! +$ IF (F$GETSYI("CPU").GE.128) +$ THEN +$! +$! The Architecture Is AXP. +$! +$ ARCH := AXP +$! +$! Else... +$! +$ ELSE +$! +$! The Architecture Is VAX. +$! +$ ARCH := VAX +$! +$! End The Architecture Check. +$! +$ ENDIF +$! +$! Check To Make Sure We Have Valid Command Line Parameters. +$! +$ GOSUB CHECK_OPTIONS +$! +$! Tell The User What Kind of Machine We Run On. +$! +$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine." +$! +$! Define The OBJ Directory Name. +$! +$ OBJ_DIR := SYS$DISK:[--.'ARCH'.OBJ.CRYPTO.DES] +$! +$! Check To See If The Architecture Specific OBJ Directory Exists. +$! +$ IF (F$PARSE(OBJ_DIR).EQS."") +$ THEN +$! +$! It Dosen't Exist, So Create It. +$! +$ CREATE/DIR 'OBJ_DIR' +$! +$! End The Architecture Specific OBJ Directory Check. +$! +$ ENDIF +$! +$! Define The EXE Directory Name. +$! +$ EXE_DIR :== SYS$DISK:[--.'ARCH'.EXE.CRYPTO.DES] +$! +$! Check To See If The Architecture Specific Directory Exists. +$! +$ IF (F$PARSE(EXE_DIR).EQS."") +$ THEN +$! +$! It Dosen't Exist, So Create It. +$! +$ CREATE/DIR 'EXE_DIR' +$! +$! End The Architecture Specific Directory Check. +$! +$ ENDIF +$! +$! Define The Library Name. +$! +$ LIB_NAME := 'EXE_DIR'LIBDES.OLB +$! +$! Check To See What We Are To Do. +$! +$ IF (BUILDALL.EQS."TRUE") +$ THEN +$! +$! Since Nothing Special Was Specified, Do Everything. +$! +$ GOSUB LIBRARY +$ GOSUB DESTEST +$ GOSUB SPEED +$ GOSUB RPW +$ GOSUB DES +$ GOSUB DES_OPTS +$! +$! Else... +$! +$ ELSE +$! +$! Build Just What The User Wants Us To Build. +$! +$ GOSUB 'BUILDALL' +$! +$! End The BUILDALL Check. +$! +$ ENDIF +$! +$! Time To EXIT. +$! +$ EXIT +$ LIBRARY: +$! +$! Tell The User That We Are Compiling. +$! +$ WRITE SYS$OUTPUT "Compiling The ",LIB_NAME," Files." +$! +$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" Library... +$! +$ IF (F$SEARCH(LIB_NAME).EQS."") +$ THEN +$! +$! Guess Not, Create The Library. +$! +$ LIBRARY/CREATE/OBJECT 'LIB_NAME' +$! +$! End The Library Exist Check. +$! +$ ENDIF +$! +$! Define The DES Library Files. +$! +$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ - + "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ - + "enc_read,enc_writ,ofb64enc,"+ - + "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ - + "des_enc,fcrypt_b,read2pwd,"+ - + "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp" +$! +$! Define A File Counter And Set It To "0". +$! +$ FILE_COUNTER = 0 +$! +$! Top Of The File Loop. +$! +$ NEXT_FILE: +$! +$! O.K, Extract The File Name From The File List. +$! +$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",LIB_DES) +$! +$! Check To See If We Are At The End Of The File List. +$! +$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE +$! +$! Increment The Counter. +$! +$ FILE_COUNTER = FILE_COUNTER + 1 +$! +$! Create The Source File Name. +$! +$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C" +$! +$! Tell The User We Are Compiling The Source File. +$! +$ WRITE SYS$OUTPUT " ",FILE_NAME,".C" +$! +$! Create The Object File Name. +$! +$ OBJECT_FILE = OBJ_DIR + FILE_NAME + "." + ARCH + "OBJ" +$ ON WARNING THEN GOTO NEXT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH(SOURCE_FILE).EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The File Exists Check. +$! +$ ENDIF +$! +$! Compile The File. +$! +$ ON ERROR THEN GOTO NEXT_FILE +$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE' +$! +$! Add It To The Library. +$! +$ LIBRARY/REPLACE/OBJECT 'LIB_NAME' 'OBJECT_FILE' +$! +$! Time To Clean Up The Object File. +$! +$ DELETE 'OBJECT_FILE';* +$! +$! Go Back And Do It Again. +$! +$ GOTO NEXT_FILE +$! +$! All Done With This Library Part. +$! +$ FILE_DONE: +$! +$! Tell The User That We Are All Done. +$! +$ WRITE SYS$OUTPUT "Library ",LIB_NAME," Built." +$! +$! All Done, Time To Return. +$! +$ RETURN +$! +$! Compile The DESTEST Program. +$! +$ DESTEST: +$! +$! Check To See If We Have The Proper Libraries. +$! +$ GOSUB LIB_CHECK +$! +$! Check To See If We Have A Linker Option File. +$! +$ GOSUB CHECK_OPT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH("SYS$DISK:[]DESTEST.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File DESTEST.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The DESTEST.C File Check. +$! +$ ENDIF +$! +$! Tell The User What We Are Building. +$! +$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DESTEST.EXE" +$! +$! Compile The DESTEST Program. +$! +$ CC/OBJECT='OBJ_DIR'DESTEST.OBJ SYS$DISK:[]DESTEST.C +$! +$! Link The DESTEST Program. +$! +$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DESTEST.EXE - + 'OBJ_DIR'DESTEST.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION +$! +$! All Done, Time To Return. +$! +$ RETURN +$! +$! Compile The SPEED Program. +$! +$ SPEED: +$! +$! Check To See If We Have The Proper Libraries. +$! +$ GOSUB LIB_CHECK +$! +$! Check To See If We Have A Linker Option File. +$! +$ GOSUB CHECK_OPT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH("SYS$DISK:[]SPEED.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File SPEED.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The SPEED.C File Check. +$! +$ ENDIF +$! +$! Tell The User What We Are Building. +$! +$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"SPEED.EXE" +$! +$! Compile The SPEED Program. +$! +$ CC/OBJECT='OBJ_DIR'SPEED.OBJ SYS$DISK:[]SPEED.C +$! +$! Link The SPEED Program. +$! +$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'SPEED.EXE - + 'OBJ_DIR'SPEED.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION +$! +$! All Done, Time To Return. +$! +$ RETURN +$! +$! Compile The RPW Program. +$! +$ RPW: +$! +$! Check To See If We Have The Proper Libraries. +$! +$ GOSUB LIB_CHECK +$! +$! Check To See If We Have A Linker Option File. +$! +$ GOSUB CHECK_OPT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH("SYS$DISK:[]RPW.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File RPW.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The RPW.C File Check. +$! +$ ENDIF +$! +$! Tell The User What We Are Building. +$! +$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"RPW.EXE" +$! +$! Compile The RPW Program. +$! +$ CC/OBJECT='OBJ_DIR'RPW.OBJ SYS$DISK:[]RPW.C +$! +$! Link The RPW Program. +$! +$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'RPW.EXE - + 'OBJ_DIR'RPW.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION +$! +$! All Done, Time To Return. +$! +$ RETURN +$! +$! Compile The DES Program. +$! +$ DES: +$! +$! Check To See If We Have The Proper Libraries. +$! +$ GOSUB LIB_CHECK +$! +$! Check To See If We Have A Linker Option File. +$! +$ GOSUB CHECK_OPT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH("SYS$DISK:[]DES.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File DES.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The DES.C File Check. +$! +$ ENDIF +$! +$! Tell The User What We Are Building. +$! +$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES.EXE" +$! +$! Compile The DES Program. +$! +$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]DES.C +$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]CBC3_ENC.C +$! +$! Link The DES Program. +$! +$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES.EXE - + 'OBJ_DIR'DES.OBJ,'OBJ_DIR'CBC3_ENC.OBJ,- + 'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION +$! +$! All Done, Time To Return. +$! +$ RETURN +$! +$! Compile The DES_OPTS Program. +$! +$ DES_OPTS: +$! +$! Check To See If We Have The Proper Libraries. +$! +$ GOSUB LIB_CHECK +$! +$! Check To See If We Have A Linker Option File. +$! +$ GOSUB CHECK_OPT_FILE +$! +$! Check To See If The File We Want To Compile Actually Exists. +$! +$ IF (F$SEARCH("SYS$DISK:[]DES_OPTS.C").EQS."") +$ THEN +$! +$! Tell The User That The File Dosen't Exist. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The File DES_OPTS.C Dosen't Exist." +$ WRITE SYS$OUTPUT "" +$! +$! Exit The Build. +$! +$ EXIT +$! +$! End The DES_OPTS.C File Check. +$! +$ ENDIF +$! +$! Tell The User What We Are Building. +$! +$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES_OPTS.EXE" +$! +$! Compile The DES_OPTS Program. +$! +$ CC/OBJECT='OBJ_DIR'DES_OPTS.OBJ SYS$DISK:[]DES_OPTS.C +$! +$! Link The DES_OPTS Program. +$! +$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES_OPTS.EXE - + 'OBJ_DIR'DES_OPTS.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION +$! +$! All Done, Time To Return. +$! +$ RETURN +$ EXIT +$! +$! Check For The Link Option FIle. +$! +$ CHECK_OPT_FILE: +$! +$! Check To See If We Need To Make A VAX C Option File. +$! +$ IF (COMPILER.EQS."VAXC") +$ THEN +$! +$! Check To See If We Already Have A VAX C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! We Need A VAX C Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable VAX C Runtime Library. +! +SYS$SHARE:VAXCRTL.EXE/SHARE +$EOD +$! +$! End The Option File Check. +$! +$ ENDIF +$! +$! End The VAXC Check. +$! +$ ENDIF +$! +$! Check To See If We Need A GNU C Option File. +$! +$ IF (COMPILER.EQS."GNUC") +$ THEN +$! +$! Check To See If We Already Have A GNU C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! We Need A GNU C Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable C Runtime Library. +! +GNU_CC:[000000]GCCLIB/LIBRARY +SYS$SHARE:VAXCRTL/SHARE +$EOD +$! +$! End The Option File Check. +$! +$ ENDIF +$! +$! End The GNU C Check. +$! +$ ENDIF +$! +$! Check To See If We Need A DEC C Option File. +$! +$ IF (COMPILER.EQS."DECC") +$ THEN +$! +$! Check To See If We Already Have A DEC C Linker Option File. +$! +$ IF (F$SEARCH(OPT_FILE).EQS."") +$ THEN +$! +$! Figure Out If We Need An AXP Or A VAX Linker Option File. +$! +$ IF (F$GETSYI("CPU").LT.128) +$ THEN +$! +$! We Need A DEC C Linker Option File For VAX. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File To Link Agianst +! The Sharable DEC C Runtime Library. +! +SYS$SHARE:DECC$SHR.EXE/SHARE +$EOD +$! +$! Else... +$! +$ ELSE +$! +$! Create The AXP Linker Option File. +$! +$ CREATE 'OPT_FILE' +$DECK +! +! Default System Options File For AXP To Link Agianst +! The Sharable C Runtime Library. +! +SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE +SYS$SHARE:CMA$OPEN_RTL/SHARE +$EOD +$! +$! End The VAX/AXP DEC C Option File Check. +$! +$ ENDIF +$! +$! End The Option File Search. +$! +$ ENDIF +$! +$! End The DEC C Check. +$! +$ ENDIF +$! +$! Tell The User What Linker Option File We Are Using. +$! +$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"." +$! +$! Time To RETURN. +$! +$ RETURN +$! +$! Library Check. +$! +$ LIB_CHECK: +$! +$! Look For The Library LIBDES.OLB. +$! +$ IF (F$SEARCH(LIB_NAME).EQS."") +$ THEN +$! +$! Tell The User We Can't Find The [.xxx.CRYPTO.DES]LIBDES.OLB Library. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "Can't Find The Library ",LIB_NAME,"." +$ WRITE SYS$OUTPUT "We Can't Link Without It." +$ WRITE SYS$OUTPUT "" +$! +$! Since We Can't Link Without It, Exit. +$! +$ EXIT +$ ENDIF +$! +$! Time To Return. +$! +$ RETURN +$! +$! Check The User's Options. +$! +$ CHECK_OPTIONS: +$! +$! Check To See If We Are To "Just Build Everything". +$! +$ IF (P1.EQS."ALL") +$ THEN +$! +$! P1 Is "ALL", So Build Everything. +$! +$ BUILDALL = "TRUE" +$! +$! Else... +$! +$ ELSE +$! +$! Else, Check To See If P1 Has A Valid Arguement. +$! +$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."DESTEST").OR.(P1.EQS."SPEED") - + .OR.(P1.EQS."RPW").OR.(P1.EQS."DES").OR.(P1.EQS."DES_OPTS") +$ THEN +$! +$! A Valid Arguement. +$! +$ BUILDALL = P1 +$! +$! Else... +$! +$ ELSE +$! +$! Tell The User We Don't Know What They Want. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " ALL : Just Build Everything. +$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library." +$ WRITE SYS$OUTPUT " DESTEST : To Compile Just The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program." +$ WRITE SYS$OUTPUT " SPEED : To Compile Just The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program." +$ WRITE SYS$OUTPUT " RPW : To Compile Just The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program." +$ WRITE SYS$OUTPUT " DES : To Compile Just The [.xxx.EXE.CRYPTO.DES]DES.EXE Program." +$ WRITE SYS$OUTPUT " DES_OPTS : To Compile Just The [.xxx.EXE.CRYTPO.DES]DES_OPTS.EXE Program." +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " Where 'xxx' Stands For: " +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " AXP : Alpha Architecture." +$ WRITE SYS$OUTPUT " VAX : VAX Architecture." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The Valid Arguement Check. +$! +$ ENDIF +$! +$! End The P1 Check. +$! +$ ENDIF +$! +$! Check To See If We Are To Compile Without Debugger Information. +$! +$ IF (P2.EQS."NODEBUG") +$ THEN +$! +$! P2 Is Blank, So Compile Without Debugger Information. +$! +$ DEBUGGER = "NODEBUG" +$ TRACEBACK = "NOTRACEBACK" +$ GCC_OPTIMIZE = "OPTIMIZE" +$ CC_OPTIMIZE = "OPTIMIZE" +$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile." +$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization." +$! +$! Else... +$! +$ ELSE +$! +$! Check To See If We Are To Compile With Debugger Information. +$! +$ IF (P2.EQS."DEBUG") +$ THEN +$! +$! Compile With Debugger Information. +$! +$ DEBUGGER = "DEBUG" +$ TRACEBACK = "TRACEBACK" +$ GCC_OPTIMIZE = "NOOPTIMIZE" +$ CC_OPTIMIZE = "NOOPTIMIZE" +$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile." +$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization." +$! +$! Else... +$! +$ ELSE +$! +$! Tell The User Entered An Invalid Option.. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information." +$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The Valid Arguement Check. +$! +$ ENDIF +$! +$! End The P2 Check. +$! +$ ENDIF +$! +$! Special Threads For OpenVMS v7.1 Or Later. +$! +$! Written By: Richard Levitte +$! richard@levitte.org +$! +$! +$! Check To See If We Have A Option For P4. +$! +$ IF (P4.EQS."") +$ THEN +$! +$! Get The Version Of VMS We Are Using. +$! +$ ISSEVEN := "" +$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION"))) +$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP)) +$! +$! Check To See If The VMS Version Is v7.1 Or Later. +$! +$ IF (TMP.GE.71) +$ THEN +$! +$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads. +$! +$ ISSEVEN := ,PTHREAD_USE_D4 +$! +$! End The VMS Version Check. +$! +$ ENDIF +$! +$! End The P4 Check. +$! +$ ENDIF +$! +$! Check To See If P3 Is Blank. +$! +$ IF (P3.EQS."") +$ THEN +$! +$! O.K., The User Didn't Specify A Compiler, Let's Try To +$! Find Out Which One To Use. +$! +$! Check To See If We Have GNU C. +$! +$ IF (F$TRNLNM("GNU_CC").NES."") +$ THEN +$! +$! Looks Like GNUC, Set To Use GNUC. +$! +$ P3 = "GNUC" +$! +$! Else... +$! +$ ELSE +$! +$! Check To See If We Have VAXC Or DECC. +$! +$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."") +$ THEN +$! +$! Looks Like DECC, Set To Use DECC. +$! +$ P3 = "DECC" +$! +$! Else... +$! +$ ELSE +$! +$! Looks Like VAXC, Set To Use VAXC. +$! +$ P3 = "VAXC" +$! +$! End The VAXC Compiler Check. +$! +$ ENDIF +$! +$! End The DECC & VAXC Compiler Check. +$! +$ ENDIF +$! +$! End The Compiler Check. +$! +$ ENDIF +$! +$! Set Up Initial CC Definitions, Possibly With User Ones +$! +$ CCDEFS = "VMS=1" +$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS +$ CCEXTRAFLAGS = "" +$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS +$ CCDISABLEWARNINGS = "" +$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN - + CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS +$! +$! Check To See If The User Entered A Valid Paramter. +$! +$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC") +$ THEN +$! +$! Check To See If The User Wanted DECC. +$! +$ IF (P3.EQS."DECC") +$ THEN +$! +$! Looks Like DECC, Set To Use DECC. +$! +$ COMPILER = "DECC" +$! +$! Tell The User We Are Using DECC. +$! +$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler." +$! +$! Use DECC... +$! +$ CC = "CC" +$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" - + THEN CC = "CC/DECC" +$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + - + "/NOLIST/PREFIX=ALL" + CCEXTRAFLAGS +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT" +$! +$! End DECC Check. +$! +$ ENDIF +$! +$! Check To See If We Are To Use VAXC. +$! +$ IF (P3.EQS."VAXC") +$ THEN +$! +$! Looks Like VAXC, Set To Use VAXC. +$! +$ COMPILER = "VAXC" +$! +$! Tell The User We Are Using VAX C. +$! +$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler." +$! +$! Compile Using VAXC. +$! +$ CC = "CC" +$ IF ARCH.EQS."AXP" +$ THEN +$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!" +$ EXIT +$ ENDIF +$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC" +$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS +$ CCDEFS = """VAXC""," + CCDEFS +$! +$! Define As SYS$COMMON:[SYSLIB] +$! +$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB] +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT" +$! +$! End VAXC Check +$! +$ ENDIF +$! +$! Check To See If We Are To Use GNU C. +$! +$ IF (P3.EQS."GNUC") +$ THEN +$! +$! Looks Like GNUC, Set To Use GNUC. +$! +$ COMPILER = "GNUC" +$! +$! Tell The User We Are Using GNUC. +$! +$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler." +$! +$! Use GNU C... +$! +$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS +$! +$! Define The Linker Options File Name. +$! +$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT" +$! +$! End The GNU C Check. +$! +$ ENDIF +$! +$! Set up default defines +$! +$ CCDEFS = """FLAT_INC=1""," + CCDEFS +$! +$! Finish up the definition of CC. +$! +$ IF COMPILER .EQS. "DECC" +$ THEN +$ IF CCDISABLEWARNINGS .EQS. "" +$ THEN +$ CC4DISABLEWARNINGS = "DOLLARID" +$ ELSE +$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID" +$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))" +$ ENDIF +$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))" +$ ELSE +$ CCDISABLEWARNINGS = "" +$ CC4DISABLEWARNINGS = "" +$ ENDIF +$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS +$! +$! Show user the result +$! +$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC +$! +$! Else The User Entered An Invalid Arguement. +$! +$ ELSE +$! +$! Tell The User We Don't Know What They Want. +$! +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:" +$ WRITE SYS$OUTPUT "" +$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C." +$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C." +$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C." +$ WRITE SYS$OUTPUT "" +$! +$! Time To EXIT. +$! +$ EXIT +$! +$! End The P3 Check. +$! +$ ENDIF +$! +$! Time To RETURN... +$! +$ RETURN diff --git a/src/lib/libcrypto/des/des.c b/src/lib/libcrypto/des/des.c index c1e5005474..b2d7f0da78 100644 --- a/src/lib/libcrypto/des/des.c +++ b/src/lib/libcrypto/des/des.c @@ -59,10 +59,18 @@ #include #include #ifndef MSDOS +#ifndef VMS +#include +#include OPENSSL_UNISTD +#else /* VMS */ +#ifdef __DECC #include +#else /* not __DECC */ +#include +#endif /* __DECC */ +#endif /* VMS */ #else #include -#define RAND #endif #include @@ -77,21 +85,13 @@ #endif #include #endif -#if defined(NOCONST) -#define const -#endif -#include "des.h" +#include +#include #if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS) #include #endif -#ifdef RAND -#define random rand -#define srandom(s) srand(s) -#endif - -#ifndef NOPROTO void usage(void); void doencryption(void); int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp); @@ -102,17 +102,6 @@ int uudecode(unsigned char *in,int num,unsigned char *out); void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length, des_key_schedule sk1,des_key_schedule sk2, des_cblock *ivec1,des_cblock *ivec2,int enc); -#else -void usage(); -void doencryption(); -int uufwrite(); -void uufwriteEnd(); -int uufread(); -int uuencode(); -int uudecode(); -void des_3cbc_encrypt(); -#endif - #ifdef VMS #define EXIT(a) exit(a&0x10000000L) #else @@ -138,9 +127,7 @@ char cksumname[200]=""; int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error; -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int i; struct stat ins,outs; @@ -331,7 +318,7 @@ char **argv; EXIT(0); } -void usage() +void usage(void) { char **u; static const char *Usage[]={ @@ -357,7 +344,7 @@ void usage() "-3 : encrypt using tripple DES encryption. This uses 2 keys", " generated from the input key. If the input key is less", " than 8 characters long, this is equivelent to normal", -" encryption. Default is tripple cbc, -b makes it tripple ecb.", +" encryption. Default is triple cbc, -b makes it triple ecb.", NULL }; for (u=(char **)Usage; *u; u++) @@ -369,17 +356,15 @@ NULL EXIT(1); } -void doencryption() +void doencryption(void) { #ifdef _LIBC - extern int srandom(); - extern int random(); extern unsigned long time(); #endif register int i; des_key_schedule ks,ks2; - unsigned char iv[8],iv2[8]; + des_cblock iv,iv2; char *p; int num=0,j,k,l,rem,ll,len,last,ex=0; des_cblock kk,k2; @@ -392,8 +377,8 @@ void doencryption() if (buf == NULL) { - if ( (( buf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL) || - ((obuf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL)) + if ( (( buf=Malloc(BUFSIZE+8)) == NULL) || + ((obuf=Malloc(BUFSIZE+8)) == NULL)) { fputs("Not enough memory\n",stderr); Exit=10; @@ -440,19 +425,19 @@ void doencryption() else k2[i-8]=k; } - des_set_key((C_Block *)k2,ks2); + des_set_key(&k2,ks2); memset(k2,0,sizeof(k2)); } else if (longk || flag3) { if (flag3) { - des_string_to_2keys(key,(C_Block *)kk,(C_Block *)k2); - des_set_key((C_Block *)k2,ks2); + des_string_to_2keys(key,&kk,&k2); + des_set_key(&k2,ks2); memset(k2,0,sizeof(k2)); } else - des_string_to_key(key,(C_Block *)kk); + des_string_to_key(key,&kk); } else for (i=0; i0; i--) - buf[l++]=random()&0xff; + RAND_bytes(buf + l++, 1); buf[l++]=rem; ex=1; len+=rem; @@ -510,8 +494,8 @@ void doencryption() if (cflag) { - des_cbc_cksum((C_Block *)buf,(C_Block *)cksum, - (long)len,ks,(C_Block *)cksum); + des_cbc_cksum(buf,&cksum, + (long)len,ks,&cksum); if (!eflag) { if (feof(DES_IN)) break; @@ -539,16 +523,16 @@ void doencryption() (unsigned int)rem); des_3cbc_encrypt( (des_cblock *)buf,(des_cblock *)obuf, - (long)l,ks,ks2,(des_cblock *)iv, - (des_cblock *)iv2,do_encrypt); + (long)l,ks,ks2,&iv, + &iv2,do_encrypt); if (rem) memcpy(&(buf[l]),tmpbuf, (unsigned int)rem); } else { des_cbc_encrypt( - (des_cblock *)buf,(des_cblock *)obuf, - (long)l,ks,(des_cblock *)iv,do_encrypt); + buf,obuf, + (long)l,ks,&iv,do_encrypt); if (l >= 8) memcpy(iv,&(obuf[l-8]),8); } if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem); @@ -614,14 +598,14 @@ void doencryption() { des_3cbc_encrypt( (des_cblock *)buf,(des_cblock *)obuf, - (long)l,ks,ks2,(des_cblock *)iv, - (des_cblock *)iv2,do_encrypt); + (long)l,ks,ks2,&iv, + &iv2,do_encrypt); } else { des_cbc_encrypt( - (des_cblock *)buf,(des_cblock *)obuf, - (long)l,ks,(des_cblock *)iv,do_encrypt); + buf,obuf, + (long)l,ks,&iv,do_encrypt); if (l >= 8) memcpy(iv,&(buf[l-8]),8); } @@ -646,9 +630,9 @@ void doencryption() l=l-8+last; } i=0; - if (cflag) des_cbc_cksum((C_Block *)obuf, - (C_Block *)cksum,(long)l/8*8,ks, - (C_Block *)cksum); + if (cflag) des_cbc_cksum(obuf, + (des_cblock *)cksum,(long)l/8*8,ks, + (des_cblock *)cksum); while (i != l) { j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT); @@ -696,15 +680,8 @@ problems: if (Exit) EXIT(Exit); } -int uufwrite(data, size, num, fp) -unsigned char *data; -int size; -unsigned int num; -FILE *fp; - - /* We ignore this parameter but it should be > ~50 I believe */ - - +/* We ignore this parameter but it should be > ~50 I believe */ +int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp) { int i,j,left,rem,ret=num; static int start=1; @@ -757,8 +734,7 @@ FILE *fp; return(ret); } -void uufwriteEnd(fp) -FILE *fp; +void uufwriteEnd(FILE *fp) { int j; static const char *end=" \nend\n"; @@ -774,11 +750,8 @@ FILE *fp; fwrite(end,1,strlen(end),fp); } -int uufread(out, size, num, fp) -unsigned char *out; -int size; /* should always be > ~ 60; I actually ignore this parameter :-) */ -unsigned int num; -FILE *fp; +/* int size: should always be > ~ 60; I actually ignore this parameter :-) */ +int uufread(unsigned char *out, int size, unsigned int num, FILE *fp) { int i,j,tot; static int done=0; @@ -850,10 +823,7 @@ FILE *fp; *((c)++)=(unsigned char)(((l) )&0xff)) -int uuencode(in, num, out) -unsigned char *in; -int num; -unsigned char *out; +int uuencode(unsigned char *in, int num, unsigned char *out) { int j,i,n,tot=0; DES_LONG l; @@ -883,10 +853,7 @@ unsigned char *out; return(tot); } -int uudecode(in, num, out) -unsigned char *in; -int num; -unsigned char *out; +int uudecode(unsigned char *in, int num, unsigned char *out) { int j,i,k; unsigned int n=0,space=0; diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h new file mode 100644 index 0000000000..67f90aaf17 --- /dev/null +++ b/src/lib/libcrypto/des/des.h @@ -0,0 +1,249 @@ +/* crypto/des/des.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_DES_H +#define HEADER_DES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef NO_DES +#error DES is disabled. +#endif + +#ifdef _KERBEROS_DES_H +#error replaces . +#endif + +#include +#include /* DES_LONG */ +#include /* OPENSSL_EXTERN */ + +typedef unsigned char des_cblock[8]; +typedef /* const */ unsigned char const_des_cblock[8]; +/* With "const", gcc 2.8.1 on Solaris thinks that des_cblock * + * and const_des_cblock * are incompatible pointer types. + * I haven't seen that warning on other systems ... I'll look + * what the standard says. */ + + +typedef struct des_ks_struct + { + union { + des_cblock cblock; + /* make sure things are correct size on machines with + * 8 byte longs */ + DES_LONG deslong[2]; + } ks; + int weak_key; + } des_key_schedule[16]; + +#define DES_KEY_SZ (sizeof(des_cblock)) +#define DES_SCHEDULE_SZ (sizeof(des_key_schedule)) + +#define DES_ENCRYPT 1 +#define DES_DECRYPT 0 + +#define DES_CBC_MODE 0 +#define DES_PCBC_MODE 1 + +#define des_ecb2_encrypt(i,o,k1,k2,e) \ + des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) + +#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ + des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) + +#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ + des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) + +#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ + des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) + +OPENSSL_EXTERN int des_check_key; /* defaults to false */ +OPENSSL_EXTERN int des_rw_mode; /* defaults to DES_PCBC_MODE */ +OPENSSL_EXTERN int des_set_weak_key_flag; /* set the weak key flag */ + +const char *des_options(void); +void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output, + des_key_schedule ks1,des_key_schedule ks2, + des_key_schedule ks3, int enc); +DES_LONG des_cbc_cksum(const unsigned char *input,des_cblock *output, + long length,des_key_schedule schedule, + const_des_cblock *ivec); +/* des_cbc_encrypt does not update the IV! Use des_ncbc_encrypt instead. */ +void des_cbc_encrypt(const unsigned char *input,unsigned char *output, + long length,des_key_schedule schedule,des_cblock *ivec, + int enc); +void des_ncbc_encrypt(const unsigned char *input,unsigned char *output, + long length,des_key_schedule schedule,des_cblock *ivec, + int enc); +void des_xcbc_encrypt(const unsigned char *input,unsigned char *output, + long length,des_key_schedule schedule,des_cblock *ivec, + const_des_cblock *inw,const_des_cblock *outw,int enc); +void des_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits, + long length,des_key_schedule schedule,des_cblock *ivec, + int enc); +void des_ecb_encrypt(const_des_cblock *input,des_cblock *output, + des_key_schedule ks,int enc); +void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc); +void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc); +void des_encrypt3(DES_LONG *data, des_key_schedule ks1, + des_key_schedule ks2, des_key_schedule ks3); +void des_decrypt3(DES_LONG *data, des_key_schedule ks1, + des_key_schedule ks2, des_key_schedule ks3); +void des_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output, + long length, + des_key_schedule ks1,des_key_schedule ks2, + des_key_schedule ks3,des_cblock *ivec,int enc); +void des_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out, + long length, + des_key_schedule ks1,des_key_schedule ks2, + des_key_schedule ks3, + des_cblock *ivec1,des_cblock *ivec2, + int enc); +void des_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, + long length,des_key_schedule ks1, + des_key_schedule ks2,des_key_schedule ks3, + des_cblock *ivec,int *num,int enc); +void des_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out, + long length,des_key_schedule ks1, + des_key_schedule ks2,des_key_schedule ks3, + des_cblock *ivec,int *num); + +void des_xwhite_in2out(const_des_cblock *des_key,const_des_cblock *in_white, + des_cblock *out_white); + +int des_enc_read(int fd,void *buf,int len,des_key_schedule sched, + des_cblock *iv); +int des_enc_write(int fd,const void *buf,int len,des_key_schedule sched, + des_cblock *iv); +char *des_fcrypt(const char *buf,const char *salt, char *ret); +char *des_crypt(const char *buf,const char *salt); +#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) +char *crypt(const char *buf,const char *salt); +#endif +void des_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits, + long length,des_key_schedule schedule,des_cblock *ivec); +void des_pcbc_encrypt(const unsigned char *input,unsigned char *output, + long length,des_key_schedule schedule,des_cblock *ivec, + int enc); +DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[], + long length,int out_count,des_cblock *seed); +void des_random_seed(des_cblock *key); +void des_random_key(des_cblock *ret); +int des_read_password(des_cblock *key,const char *prompt,int verify); +int des_read_2passwords(des_cblock *key1,des_cblock *key2, + const char *prompt,int verify); +int des_read_pw_string(char *buf,int length,const char *prompt,int verify); +void des_set_odd_parity(des_cblock *key); +int des_is_weak_key(const_des_cblock *key); +int des_set_key(const_des_cblock *key,des_key_schedule schedule); +int des_key_sched(const_des_cblock *key,des_key_schedule schedule); +void des_string_to_key(const char *str,des_cblock *key); +void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2); +void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, + des_key_schedule schedule,des_cblock *ivec,int *num, + int enc); +void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, + des_key_schedule schedule,des_cblock *ivec,int *num); +int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify); + +/* Extra functions from Mark Murray */ +void des_cblock_print_file(const_des_cblock *cb, FILE *fp); + +/* The following definitions provide compatibility with the MIT Kerberos + * library. The des_key_schedule structure is not binary compatible. */ + +#define _KERBEROS_DES_H + +#define KRBDES_ENCRYPT DES_ENCRYPT +#define KRBDES_DECRYPT DES_DECRYPT + +#ifdef KERBEROS +# define ENCRYPT DES_ENCRYPT +# define DECRYPT DES_DECRYPT +#endif + +#ifndef NCOMPAT +# define C_Block des_cblock +# define Key_schedule des_key_schedule +# define KEY_SZ DES_KEY_SZ +# define string_to_key des_string_to_key +# define read_pw_string des_read_pw_string +# define random_key des_random_key +# define pcbc_encrypt des_pcbc_encrypt +# define set_key des_set_key +# define key_sched des_key_sched +# define ecb_encrypt des_ecb_encrypt +# define cbc_encrypt des_cbc_encrypt +# define ncbc_encrypt des_ncbc_encrypt +# define xcbc_encrypt des_xcbc_encrypt +# define cbc_cksum des_cbc_cksum +# define quad_cksum des_quad_cksum +#endif + +typedef des_key_schedule bit_64; +#define des_fixup_key_parity des_set_odd_parity +#define des_check_key_parity check_parity + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/libcrypto/des/des.org b/src/lib/libcrypto/des/des.org deleted file mode 100644 index a4cf5c8770..0000000000 --- a/src/lib/libcrypto/des/des.org +++ /dev/null @@ -1,301 +0,0 @@ -/* crypto/des/des.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify des.org since des.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - -#ifndef HEADER_DES_H -#define HEADER_DES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a - * %20 speed up (longs are 8 bytes, int's are 4). */ -#ifndef DES_LONG -#define DES_LONG unsigned long -#endif - -typedef unsigned char des_cblock[8]; -typedef struct des_ks_struct - { - union { - des_cblock _; - /* make sure things are correct size on machines with - * 8 byte longs */ - DES_LONG pad[2]; - } ks; -#undef _ -#define _ ks._ - } des_key_schedule[16]; - -#define DES_KEY_SZ (sizeof(des_cblock)) -#define DES_SCHEDULE_SZ (sizeof(des_key_schedule)) - -#define DES_ENCRYPT 1 -#define DES_DECRYPT 0 - -#define DES_CBC_MODE 0 -#define DES_PCBC_MODE 1 - -#define des_ecb2_encrypt(i,o,k1,k2,e) \ - des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) - -#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ - des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) - -#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ - des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) - -#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ - des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) - -#define C_Block des_cblock -#define Key_schedule des_key_schedule -#ifdef KERBEROS -#define ENCRYPT DES_ENCRYPT -#define DECRYPT DES_DECRYPT -#endif -#define KEY_SZ DES_KEY_SZ -#define string_to_key des_string_to_key -#define read_pw_string des_read_pw_string -#define random_key des_random_key -#define pcbc_encrypt des_pcbc_encrypt -#define set_key des_set_key -#define key_sched des_key_sched -#define ecb_encrypt des_ecb_encrypt -#define cbc_encrypt des_cbc_encrypt -#define ncbc_encrypt des_ncbc_encrypt -#define xcbc_encrypt des_xcbc_encrypt -#define cbc_cksum des_cbc_cksum -#define quad_cksum des_quad_cksum - -/* For compatibility with the MIT lib - eay 20/05/92 */ -typedef des_key_schedule bit_64; -#define des_fixup_key_parity des_set_odd_parity -#define des_check_key_parity check_parity - -extern int des_check_key; /* defaults to false */ -extern int des_rw_mode; /* defaults to DES_PCBC_MODE */ - -/* The next line is used to disable full ANSI prototypes, if your - * compiler has problems with the prototypes, make sure this line always - * evaluates to true :-) */ -#if defined(MSDOS) || defined(__STDC__) -#undef NOPROTO -#endif -#ifndef NOPROTO -char *des_options(void); -void des_ecb3_encrypt(des_cblock *input,des_cblock *output, - des_key_schedule ks1,des_key_schedule ks2, - des_key_schedule ks3, int enc); -DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output, - long length,des_key_schedule schedule,des_cblock *ivec); -void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length, - des_key_schedule schedule,des_cblock *ivec,int enc); -void des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length, - des_key_schedule schedule,des_cblock *ivec,int enc); -void des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length, - des_key_schedule schedule,des_cblock *ivec, - des_cblock *inw,des_cblock *outw,int enc); -void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits, - long length,des_key_schedule schedule,des_cblock *ivec,int enc); -void des_ecb_encrypt(des_cblock *input,des_cblock *output, - des_key_schedule ks,int enc); -void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc); -void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc); -void des_encrypt3(DES_LONG *data, des_key_schedule ks1, - des_key_schedule ks2, des_key_schedule ks3); -void des_decrypt3(DES_LONG *data, des_key_schedule ks1, - des_key_schedule ks2, des_key_schedule ks3); -void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output, - long length, des_key_schedule ks1, des_key_schedule ks2, - des_key_schedule ks3, des_cblock *ivec, int enc); -void des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out, - long length, des_key_schedule ks1, des_key_schedule ks2, - des_key_schedule ks3, des_cblock *ivec, int *num, int enc); -void des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out, - long length, des_key_schedule ks1, des_key_schedule ks2, - des_key_schedule ks3, des_cblock *ivec, int *num); - -void des_xwhite_in2out(des_cblock (*des_key), des_cblock (*in_white), - des_cblock (*out_white)); - -int des_enc_read(int fd,char *buf,int len,des_key_schedule sched, - des_cblock *iv); -int des_enc_write(int fd,char *buf,int len,des_key_schedule sched, - des_cblock *iv); -char *des_fcrypt(const char *buf,const char *salt, char *ret); -#ifdef PERL5 -char *des_crypt(const char *buf,const char *salt); -#else -/* some stupid compilers complain because I have declared char instead - * of const char */ -#ifdef HEADER_DES_LOCL_H -char *crypt(const char *buf,const char *salt); -#else -char *crypt(); -#endif -#endif -void des_ofb_encrypt(unsigned char *in,unsigned char *out, - int numbits,long length,des_key_schedule schedule,des_cblock *ivec); -void des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length, - des_key_schedule schedule,des_cblock *ivec,int enc); -DES_LONG des_quad_cksum(des_cblock *input,des_cblock *output, - long length,int out_count,des_cblock *seed); -void des_random_seed(des_cblock key); -void des_random_key(des_cblock ret); -int des_read_password(des_cblock *key,char *prompt,int verify); -int des_read_2passwords(des_cblock *key1,des_cblock *key2, - char *prompt,int verify); -int des_read_pw_string(char *buf,int length,char *prompt,int verify); -void des_set_odd_parity(des_cblock *key); -int des_is_weak_key(des_cblock *key); -int des_set_key(des_cblock *key,des_key_schedule schedule); -int des_key_sched(des_cblock *key,des_key_schedule schedule); -void des_string_to_key(char *str,des_cblock *key); -void des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2); -void des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, - des_key_schedule schedule, des_cblock *ivec, int *num, int enc); -void des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, - des_key_schedule schedule, des_cblock *ivec, int *num); -int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify); - -/* Extra functions from Mark Murray */ -void des_cblock_print_file(des_cblock *cb, FILE *fp); -/* The following functions are not in the normal unix build or the - * SSLeay build. When using the SSLeay build, use RAND_seed() - * and RAND_bytes() instead. */ -int des_new_random_key(des_cblock *key); -void des_init_random_number_generator(des_cblock *key); -void des_set_random_generator_seed(des_cblock *key); -void des_set_sequence_number(des_cblock new_sequence_number); -void des_generate_random_block(des_cblock *block); - -#else - -char *des_options(); -void des_ecb3_encrypt(); -DES_LONG des_cbc_cksum(); -void des_cbc_encrypt(); -void des_ncbc_encrypt(); -void des_xcbc_encrypt(); -void des_cfb_encrypt(); -void des_ede3_cfb64_encrypt(); -void des_ede3_ofb64_encrypt(); -void des_ecb_encrypt(); -void des_encrypt(); -void des_encrypt2(); -void des_encrypt3(); -void des_decrypt3(); -void des_ede3_cbc_encrypt(); -int des_enc_read(); -int des_enc_write(); -char *des_fcrypt(); -#ifdef PERL5 -char *des_crypt(); -#else -char *crypt(); -#endif -void des_ofb_encrypt(); -void des_pcbc_encrypt(); -DES_LONG des_quad_cksum(); -void des_random_seed(); -void des_random_key(); -int des_read_password(); -int des_read_2passwords(); -int des_read_pw_string(); -void des_set_odd_parity(); -int des_is_weak_key(); -int des_set_key(); -int des_key_sched(); -void des_string_to_key(); -void des_string_to_2keys(); -void des_cfb64_encrypt(); -void des_ofb64_encrypt(); -int des_read_pw(); -void des_xwhite_in2out(); - -/* Extra functions from Mark Murray */ -void des_cblock_print_file(); -/* The following functions are not in the normal unix build or the - * SSLeay build. When using the SSLeay build, use RAND_seed() - * and RAND_bytes() instead. */ -#ifdef FreeBSD -int des_new_random_key(); -void des_init_random_number_generator(); -void des_set_random_generator_seed(); -void des_set_sequence_number(); -void des_generate_random_block(); -#endif - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/lib/libcrypto/des/des.pl b/src/lib/libcrypto/des/des.pl index 935eacb504..8a3f7e3ed6 100644 --- a/src/lib/libcrypto/des/des.pl +++ b/src/lib/libcrypto/des/des.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # des.pl - eric young 22/11/1991 eay@cryptsoft.com # # Copyright (C) 1993 Eric Young diff --git a/src/lib/libcrypto/des/des3s.cpp b/src/lib/libcrypto/des/des3s.cpp index 9aff6494d9..02d527c057 100644 --- a/src/lib/libcrypto/des/des3s.cpp +++ b/src/lib/libcrypto/des/des3s.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include #include -#include "des.h" +#include void main(int argc,char *argv[]) { diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c index e4db09299e..8311e10628 100644 --- a/src/lib/libcrypto/des/des_enc.c +++ b/src/lib/libcrypto/des/des_enc.c @@ -58,14 +58,11 @@ #include "des_locl.h" -void des_encrypt(data, ks, enc) -DES_LONG *data; -des_key_schedule ks; -int enc; +void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc) { register DES_LONG l,r,t,u; #ifdef DES_PTR - register unsigned char *des_SP=(unsigned char *)des_SPtrans; + register const unsigned char *des_SP=(const unsigned char *)des_SPtrans; #endif #ifndef DES_UNROLL register int i; @@ -87,7 +84,7 @@ int enc; r=ROTATE(r,29)&0xffffffffL; l=ROTATE(l,29)&0xffffffffL; - s=(DES_LONG *)ks; + s=ks->ks.deslong; /* I don't know if it is worth the effort of loop unrolling the * inner loop */ if (enc) @@ -159,14 +156,11 @@ int enc; l=r=t=u=0; } -void des_encrypt2(data, ks, enc) -DES_LONG *data; -des_key_schedule ks; -int enc; +void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc) { register DES_LONG l,r,t,u; #ifdef DES_PTR - register unsigned char *des_SP=(unsigned char *)des_SPtrans; + register const unsigned char *des_SP=(const unsigned char *)des_SPtrans; #endif #ifndef DES_UNROLL register int i; @@ -186,7 +180,7 @@ int enc; r=ROTATE(r,29)&0xffffffffL; l=ROTATE(l,29)&0xffffffffL; - s=(DES_LONG *)ks; + s=ks->ks.deslong; /* I don't know if it is worth the effort of loop unrolling the * inner loop */ if (enc) @@ -253,11 +247,8 @@ int enc; l=r=t=u=0; } -void des_encrypt3(data,ks1,ks2,ks3) -DES_LONG *data; -des_key_schedule ks1; -des_key_schedule ks2; -des_key_schedule ks3; +void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2, + des_key_schedule ks3) { register DES_LONG l,r; @@ -276,11 +267,8 @@ des_key_schedule ks3; data[1]=r; } -void des_decrypt3(data,ks1,ks2,ks3) -DES_LONG *data; -des_key_schedule ks1; -des_key_schedule ks2; -des_key_schedule ks3; +void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2, + des_key_schedule ks3) { register DES_LONG l,r; @@ -301,108 +289,24 @@ des_key_schedule ks3; #ifndef DES_DEFAULT_OPTIONS -void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule schedule; -des_cblock (*ivec); -int enc; - { - register DES_LONG tin0,tin1; - register DES_LONG tout0,tout1,xor0,xor1; - register unsigned char *in,*out; - register long l=length; - DES_LONG tin[2]; - unsigned char *iv; - - in=(unsigned char *)input; - out=(unsigned char *)output; - iv=(unsigned char *)ivec; - - if (enc) - { - c2l(iv,tout0); - c2l(iv,tout1); - for (l-=8; l>=0; l-=8) - { - c2l(in,tin0); - c2l(in,tin1); - tin0^=tout0; tin[0]=tin0; - tin1^=tout1; tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); - tout0=tin[0]; l2c(tout0,out); - tout1=tin[1]; l2c(tout1,out); - } - if (l != -8) - { - c2ln(in,tin0,tin1,l+8); - tin0^=tout0; tin[0]=tin0; - tin1^=tout1; tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); - tout0=tin[0]; l2c(tout0,out); - tout1=tin[1]; l2c(tout1,out); - } - iv=(unsigned char *)ivec; - l2c(tout0,iv); - l2c(tout1,iv); - } - else - { - c2l(iv,xor0); - c2l(iv,xor1); - for (l-=8; l>=0; l-=8) - { - c2l(in,tin0); tin[0]=tin0; - c2l(in,tin1); tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); - tout0=tin[0]^xor0; - tout1=tin[1]^xor1; - l2c(tout0,out); - l2c(tout1,out); - xor0=tin0; - xor1=tin1; - } - if (l != -8) - { - c2l(in,tin0); tin[0]=tin0; - c2l(in,tin1); tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); - tout0=tin[0]^xor0; - tout1=tin[1]^xor1; - l2cn(tout0,tout1,out,l+8); - xor0=tin0; - xor1=tin1; - } - - iv=(unsigned char *)ivec; - l2c(xor0,iv); - l2c(xor1,iv); - } - tin0=tin1=tout0=tout1=xor0=xor1=0; - tin[0]=tin[1]=0; - } +#undef CBC_ENC_C__DONT_UPDATE_IV +#include "ncbc_enc.c" /* des_ncbc_encrypt */ -void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule ks1; -des_key_schedule ks2; -des_key_schedule ks3; -des_cblock (*ivec); -int enc; +void des_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, + long length, des_key_schedule ks1, des_key_schedule ks2, + des_key_schedule ks3, des_cblock *ivec, int enc) { register DES_LONG tin0,tin1; register DES_LONG tout0,tout1,xor0,xor1; - register unsigned char *in,*out; + register const unsigned char *in; + unsigned char *out; register long l=length; DES_LONG tin[2]; unsigned char *iv; - in=(unsigned char *)input; - out=(unsigned char *)output; - iv=(unsigned char *)ivec; + in=input; + out=output; + iv = &(*ivec)[0]; if (enc) { @@ -439,7 +343,7 @@ int enc; l2c(tout0,out); l2c(tout1,out); } - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(tout0,iv); l2c(tout1,iv); } @@ -491,7 +395,7 @@ int enc; xor1=t1; } - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(xor0,iv); l2c(xor1,iv); } diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h new file mode 100644 index 0000000000..d6ea17cb68 --- /dev/null +++ b/src/lib/libcrypto/des/des_locl.h @@ -0,0 +1,408 @@ +/* crypto/des/des_locl.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_DES_LOCL_H +#define HEADER_DES_LOCL_H + +#if defined(WIN32) || defined(WIN16) +#ifndef MSDOS +#define MSDOS +#endif +#endif + +#include +#include + +#include + +#ifndef MSDOS +#if !defined(VMS) || defined(__DECC) +#include OPENSSL_UNISTD +#include +#endif +#endif +#include + +#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */ +#include +#include +#include +#include +#endif + +#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS) +#include +#endif + +#define ITERATIONS 16 +#define HALF_ITERATIONS 8 + +/* used in des_read and des_write */ +#define MAXWRITE (1024*16) +#define BSIZE (MAXWRITE+4) + +#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ + l|=((DES_LONG)(*((c)++)))<< 8L, \ + l|=((DES_LONG)(*((c)++)))<<16L, \ + l|=((DES_LONG)(*((c)++)))<<24L) + +/* NOTE - c is not incremented as per c2l */ +#define c2ln(c,l1,l2,n) { \ + c+=n; \ + l1=l2=0; \ + switch (n) { \ + case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \ + case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \ + case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \ + case 5: l2|=((DES_LONG)(*(--(c)))); \ + case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \ + case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \ + case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \ + case 1: l1|=((DES_LONG)(*(--(c)))); \ + } \ + } + +#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ + *((c)++)=(unsigned char)(((l)>>24L)&0xff)) + +/* replacements for htonl and ntohl since I have no idea what to do + * when faced with machines with 8 byte longs. */ +#define HDRSIZE 4 + +#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \ + l|=((DES_LONG)(*((c)++)))<<16L, \ + l|=((DES_LONG)(*((c)++)))<< 8L, \ + l|=((DES_LONG)(*((c)++)))) + +#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ + *((c)++)=(unsigned char)(((l) )&0xff)) + +/* NOTE - c is not incremented as per l2c */ +#define l2cn(l1,l2,c,n) { \ + c+=n; \ + switch (n) { \ + case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ + case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ + case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ + case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ + case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ + case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ + case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ + case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ + } \ + } + +#if defined(WIN32) +#define ROTATE(a,n) (_lrotr(a,n)) +#else +#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) +#endif + +/* Don't worry about the LOAD_DATA() stuff, that is used by + * fcrypt() to add it's little bit to the front */ + +#ifdef DES_FCRYPT + +#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \ + { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); } + +#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \ + t=R^(R>>16L); \ + u=t&E0; t&=E1; \ + tmp=(u<<16); u^=R^s[S ]; u^=tmp; \ + tmp=(t<<16); t^=R^s[S+1]; t^=tmp +#else +#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g) +#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \ + u=R^s[S ]; \ + t=R^s[S+1] +#endif + +/* The changes to this macro may help or hinder, depending on the + * compiler and the achitecture. gcc2 always seems to do well :-). + * Inspired by Dana How + * DO NOT use the alternative version on machines with 8 byte longs. + * It does not seem to work on the Alpha, even when DES_LONG is 4 + * bytes, probably an issue of accessing non-word aligned objects :-( */ +#ifdef DES_PTR + +/* It recently occured to me that 0^0^0^0^0^0^0 == 0, so there + * is no reason to not xor all the sub items together. This potentially + * saves a register since things can be xored directly into L */ + +#if defined(DES_RISC1) || defined(DES_RISC2) +#ifdef DES_RISC1 +#define D_ENCRYPT(LL,R,S) { \ + unsigned int u1,u2,u3; \ + LOAD_DATA(R,S,u,t,E0,E1,u1); \ + u2=(int)u>>8L; \ + u1=(int)u&0xfc; \ + u2&=0xfc; \ + t=ROTATE(t,4); \ + u>>=16L; \ + LL^= *(const DES_LONG *)(des_SP +u1); \ + LL^= *(const DES_LONG *)(des_SP+0x200+u2); \ + u3=(int)(u>>8L); \ + u1=(int)u&0xfc; \ + u3&=0xfc; \ + LL^= *(const DES_LONG *)(des_SP+0x400+u1); \ + LL^= *(const DES_LONG *)(des_SP+0x600+u3); \ + u2=(int)t>>8L; \ + u1=(int)t&0xfc; \ + u2&=0xfc; \ + t>>=16L; \ + LL^= *(const DES_LONG *)(des_SP+0x100+u1); \ + LL^= *(const DES_LONG *)(des_SP+0x300+u2); \ + u3=(int)t>>8L; \ + u1=(int)t&0xfc; \ + u3&=0xfc; \ + LL^= *(const DES_LONG *)(des_SP+0x500+u1); \ + LL^= *(const DES_LONG *)(des_SP+0x700+u3); } +#endif +#ifdef DES_RISC2 +#define D_ENCRYPT(LL,R,S) { \ + unsigned int u1,u2,s1,s2; \ + LOAD_DATA(R,S,u,t,E0,E1,u1); \ + u2=(int)u>>8L; \ + u1=(int)u&0xfc; \ + u2&=0xfc; \ + t=ROTATE(t,4); \ + LL^= *(const DES_LONG *)(des_SP +u1); \ + LL^= *(const DES_LONG *)(des_SP+0x200+u2); \ + s1=(int)(u>>16L); \ + s2=(int)(u>>24L); \ + s1&=0xfc; \ + s2&=0xfc; \ + LL^= *(const DES_LONG *)(des_SP+0x400+s1); \ + LL^= *(const DES_LONG *)(des_SP+0x600+s2); \ + u2=(int)t>>8L; \ + u1=(int)t&0xfc; \ + u2&=0xfc; \ + LL^= *(const DES_LONG *)(des_SP+0x100+u1); \ + LL^= *(const DES_LONG *)(des_SP+0x300+u2); \ + s1=(int)(t>>16L); \ + s2=(int)(t>>24L); \ + s1&=0xfc; \ + s2&=0xfc; \ + LL^= *(const DES_LONG *)(des_SP+0x500+s1); \ + LL^= *(const DES_LONG *)(des_SP+0x700+s2); } +#endif +#else +#define D_ENCRYPT(LL,R,S) { \ + LOAD_DATA_tmp(R,S,u,t,E0,E1); \ + t=ROTATE(t,4); \ + LL^= \ + *(const DES_LONG *)(des_SP +((u )&0xfc))^ \ + *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \ + *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \ + *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \ + *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \ + *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \ + *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \ + *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); } +#endif + +#else /* original version */ + +#if defined(DES_RISC1) || defined(DES_RISC2) +#ifdef DES_RISC1 +#define D_ENCRYPT(LL,R,S) {\ + unsigned int u1,u2,u3; \ + LOAD_DATA(R,S,u,t,E0,E1,u1); \ + u>>=2L; \ + t=ROTATE(t,6); \ + u2=(int)u>>8L; \ + u1=(int)u&0x3f; \ + u2&=0x3f; \ + u>>=16L; \ + LL^=des_SPtrans[0][u1]; \ + LL^=des_SPtrans[2][u2]; \ + u3=(int)u>>8L; \ + u1=(int)u&0x3f; \ + u3&=0x3f; \ + LL^=des_SPtrans[4][u1]; \ + LL^=des_SPtrans[6][u3]; \ + u2=(int)t>>8L; \ + u1=(int)t&0x3f; \ + u2&=0x3f; \ + t>>=16L; \ + LL^=des_SPtrans[1][u1]; \ + LL^=des_SPtrans[3][u2]; \ + u3=(int)t>>8L; \ + u1=(int)t&0x3f; \ + u3&=0x3f; \ + LL^=des_SPtrans[5][u1]; \ + LL^=des_SPtrans[7][u3]; } +#endif +#ifdef DES_RISC2 +#define D_ENCRYPT(LL,R,S) {\ + unsigned int u1,u2,s1,s2; \ + LOAD_DATA(R,S,u,t,E0,E1,u1); \ + u>>=2L; \ + t=ROTATE(t,6); \ + u2=(int)u>>8L; \ + u1=(int)u&0x3f; \ + u2&=0x3f; \ + LL^=des_SPtrans[0][u1]; \ + LL^=des_SPtrans[2][u2]; \ + s1=(int)u>>16L; \ + s2=(int)u>>24L; \ + s1&=0x3f; \ + s2&=0x3f; \ + LL^=des_SPtrans[4][s1]; \ + LL^=des_SPtrans[6][s2]; \ + u2=(int)t>>8L; \ + u1=(int)t&0x3f; \ + u2&=0x3f; \ + LL^=des_SPtrans[1][u1]; \ + LL^=des_SPtrans[3][u2]; \ + s1=(int)t>>16; \ + s2=(int)t>>24L; \ + s1&=0x3f; \ + s2&=0x3f; \ + LL^=des_SPtrans[5][s1]; \ + LL^=des_SPtrans[7][s2]; } +#endif + +#else + +#define D_ENCRYPT(LL,R,S) {\ + LOAD_DATA_tmp(R,S,u,t,E0,E1); \ + t=ROTATE(t,4); \ + LL^=\ + des_SPtrans[0][(u>> 2L)&0x3f]^ \ + des_SPtrans[2][(u>>10L)&0x3f]^ \ + des_SPtrans[4][(u>>18L)&0x3f]^ \ + des_SPtrans[6][(u>>26L)&0x3f]^ \ + des_SPtrans[1][(t>> 2L)&0x3f]^ \ + des_SPtrans[3][(t>>10L)&0x3f]^ \ + des_SPtrans[5][(t>>18L)&0x3f]^ \ + des_SPtrans[7][(t>>26L)&0x3f]; } +#endif +#endif + + /* IP and FP + * The problem is more of a geometric problem that random bit fiddling. + 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6 + 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4 + 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2 + 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0 + + 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7 + 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5 + 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3 + 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1 + + The output has been subject to swaps of the form + 0 1 -> 3 1 but the odd and even bits have been put into + 2 3 2 0 + different words. The main trick is to remember that + t=((l>>size)^r)&(mask); + r^=t; + l^=(t<>(n))^(b))&(m)),\ + (b)^=(t),\ + (a)^=((t)<<(n))) + +#define IP(l,r) \ + { \ + register DES_LONG tt; \ + PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \ + PERM_OP(l,r,tt,16,0x0000ffffL); \ + PERM_OP(r,l,tt, 2,0x33333333L); \ + PERM_OP(l,r,tt, 8,0x00ff00ffL); \ + PERM_OP(r,l,tt, 1,0x55555555L); \ + } + +#define FP(l,r) \ + { \ + register DES_LONG tt; \ + PERM_OP(l,r,tt, 1,0x55555555L); \ + PERM_OP(r,l,tt, 8,0x00ff00ffL); \ + PERM_OP(l,r,tt, 2,0x33333333L); \ + PERM_OP(r,l,tt,16,0x0000ffffL); \ + PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ + } + +OPENSSL_EXTERN const DES_LONG des_SPtrans[8][64]; + +void fcrypt_body(DES_LONG *out,des_key_schedule ks, + DES_LONG Eswap0, DES_LONG Eswap1); +#endif diff --git a/src/lib/libcrypto/des/des_locl.org b/src/lib/libcrypto/des/des_locl.org deleted file mode 100644 index e2e503cbed..0000000000 --- a/src/lib/libcrypto/des/des_locl.org +++ /dev/null @@ -1,516 +0,0 @@ -/* crypto/des/des_locl.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify des_locl.org since des_locl.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - -#ifndef HEADER_DES_LOCL_H -#define HEADER_DES_LOCL_H - -#if defined(WIN32) || defined(WIN16) -#ifndef MSDOS -#define MSDOS -#endif -#endif - -#include -#include -#ifndef MSDOS -#include -#endif -#include "des.h" - -#ifndef DES_DEFAULT_OPTIONS -/* the following is tweaked from a config script, that is why it is a - * protected undef/define */ -#ifndef DES_PTR -#undef DES_PTR -#endif - -/* This helps C compiler generate the correct code for multiple functional - * units. It reduces register dependancies at the expense of 2 more - * registers */ -#ifndef DES_RISC1 -#undef DES_RISC1 -#endif - -#ifndef DES_RISC2 -#undef DES_RISC2 -#endif - -#if defined(DES_RISC1) && defined(DES_RISC2) -YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!! -#endif - -/* Unroll the inner loop, this sometimes helps, sometimes hinders. - * Very mucy CPU dependant */ -#ifndef DES_UNROLL -#undef DES_UNROLL -#endif - -/* These default values were supplied by - * Peter Gutman - * They are only used if nothing else has been defined */ -#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL) -/* Special defines which change the way the code is built depending on the - CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find - even newer MIPS CPU's, but at the moment one size fits all for - optimization options. Older Sparc's work better with only UNROLL, but - there's no way to tell at compile time what it is you're running on */ - -#if defined( sun ) /* Newer Sparc's */ - #define DES_PTR - #define DES_RISC1 - #define DES_UNROLL -#elif defined( __ultrix ) /* Older MIPS */ - #define DES_PTR - #define DES_RISC2 - #define DES_UNROLL -#elif defined( __osf1__ ) /* Alpha */ - #define DES_PTR - #define DES_RISC2 -#elif defined ( _AIX ) /* RS6000 */ - /* Unknown */ -#elif defined( __hpux ) /* HP-PA */ - /* Unknown */ -#elif defined( __aux ) /* 68K */ - /* Unknown */ -#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */ - #define DES_UNROLL -#elif defined( __sgi ) /* Newer MIPS */ - #define DES_PTR - #define DES_RISC2 - #define DES_UNROLL -#elif defined( i386 ) /* x86 boxes, should be gcc */ - #define DES_PTR - #define DES_RISC1 - #define DES_UNROLL -#endif /* Systems-specific speed defines */ -#endif - -#endif /* DES_DEFAULT_OPTIONS */ - -#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */ -#include -#include -#include -#include -#ifndef RAND -#define RAND -#endif -#undef NOPROTO -#endif - -#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS) -#include -#endif - -#ifndef RAND -#define RAND -#endif - -#ifdef linux -#undef RAND -#endif - -#ifdef MSDOS -#define getpid() 2 -#define RAND -#undef NOPROTO -#endif - -#if defined(NOCONST) -#define const -#endif - -#ifdef __STDC__ -#undef NOPROTO -#endif - -#ifdef RAND -#define srandom(s) srand(s) -#define random rand -#endif - -#define ITERATIONS 16 -#define HALF_ITERATIONS 8 - -/* used in des_read and des_write */ -#define MAXWRITE (1024*16) -#define BSIZE (MAXWRITE+4) - -#define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ - l|=((DES_LONG)(*((c)++)))<< 8L, \ - l|=((DES_LONG)(*((c)++)))<<16L, \ - l|=((DES_LONG)(*((c)++)))<<24L) - -/* NOTE - c is not incremented as per c2l */ -#define c2ln(c,l1,l2,n) { \ - c+=n; \ - l1=l2=0; \ - switch (n) { \ - case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \ - case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \ - case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \ - case 5: l2|=((DES_LONG)(*(--(c)))); \ - case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \ - case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \ - case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \ - case 1: l1|=((DES_LONG)(*(--(c)))); \ - } \ - } - -#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ - *((c)++)=(unsigned char)(((l)>>24L)&0xff)) - -/* replacements for htonl and ntohl since I have no idea what to do - * when faced with machines with 8 byte longs. */ -#define HDRSIZE 4 - -#define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \ - l|=((DES_LONG)(*((c)++)))<<16L, \ - l|=((DES_LONG)(*((c)++)))<< 8L, \ - l|=((DES_LONG)(*((c)++)))) - -#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ - *((c)++)=(unsigned char)(((l) )&0xff)) - -/* NOTE - c is not incremented as per l2c */ -#define l2cn(l1,l2,c,n) { \ - c+=n; \ - switch (n) { \ - case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ - case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ - case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ - case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ - case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ - case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ - case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ - case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ - } \ - } - -#if defined(WIN32) -#define ROTATE(a,n) (_lrotr(a,n)) -#else -#define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) -#endif - -/* Don't worry about the LOAD_DATA() stuff, that is used by - * fcrypt() to add it's little bit to the front */ - -#ifdef DES_FCRYPT - -#define LOAD_DATA_tmp(R,S,u,t,E0,E1) \ - { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); } - -#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \ - t=R^(R>>16L); \ - u=t&E0; t&=E1; \ - tmp=(u<<16); u^=R^s[S ]; u^=tmp; \ - tmp=(t<<16); t^=R^s[S+1]; t^=tmp -#else -#define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g) -#define LOAD_DATA(R,S,u,t,E0,E1,tmp) \ - u=R^s[S ]; \ - t=R^s[S+1] -#endif - -/* The changes to this macro may help or hinder, depending on the - * compiler and the achitecture. gcc2 always seems to do well :-). - * Inspired by Dana How - * DO NOT use the alternative version on machines with 8 byte longs. - * It does not seem to work on the Alpha, even when DES_LONG is 4 - * bytes, probably an issue of accessing non-word aligned objects :-( */ -#ifdef DES_PTR - -/* It recently occured to me that 0^0^0^0^0^0^0 == 0, so there - * is no reason to not xor all the sub items together. This potentially - * saves a register since things can be xored directly into L */ - -#if defined(DES_RISC1) || defined(DES_RISC2) -#ifdef DES_RISC1 -#define D_ENCRYPT(LL,R,S) { \ - unsigned int u1,u2,u3; \ - LOAD_DATA(R,S,u,t,E0,E1,u1); \ - u2=(int)u>>8L; \ - u1=(int)u&0xfc; \ - u2&=0xfc; \ - t=ROTATE(t,4); \ - u>>=16L; \ - LL^= *(DES_LONG *)((unsigned char *)des_SP +u1); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x200+u2); \ - u3=(int)(u>>8L); \ - u1=(int)u&0xfc; \ - u3&=0xfc; \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x400+u1); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x600+u3); \ - u2=(int)t>>8L; \ - u1=(int)t&0xfc; \ - u2&=0xfc; \ - t>>=16L; \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x100+u1); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x300+u2); \ - u3=(int)t>>8L; \ - u1=(int)t&0xfc; \ - u3&=0xfc; \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x500+u1); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x700+u3); } -#endif -#ifdef DES_RISC2 -#define D_ENCRYPT(LL,R,S) { \ - unsigned int u1,u2,s1,s2; \ - LOAD_DATA(R,S,u,t,E0,E1,u1); \ - u2=(int)u>>8L; \ - u1=(int)u&0xfc; \ - u2&=0xfc; \ - t=ROTATE(t,4); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP +u1); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x200+u2); \ - s1=(int)(u>>16L); \ - s2=(int)(u>>24L); \ - s1&=0xfc; \ - s2&=0xfc; \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x400+s1); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x600+s2); \ - u2=(int)t>>8L; \ - u1=(int)t&0xfc; \ - u2&=0xfc; \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x100+u1); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x300+u2); \ - s1=(int)(t>>16L); \ - s2=(int)(t>>24L); \ - s1&=0xfc; \ - s2&=0xfc; \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x500+s1); \ - LL^= *(DES_LONG *)((unsigned char *)des_SP+0x700+s2); } -#endif -#else -#define D_ENCRYPT(LL,R,S) { \ - LOAD_DATA_tmp(R,S,u,t,E0,E1); \ - t=ROTATE(t,4); \ - LL^= \ - *(DES_LONG *)((unsigned char *)des_SP +((u )&0xfc))^ \ - *(DES_LONG *)((unsigned char *)des_SP+0x200+((u>> 8L)&0xfc))^ \ - *(DES_LONG *)((unsigned char *)des_SP+0x400+((u>>16L)&0xfc))^ \ - *(DES_LONG *)((unsigned char *)des_SP+0x600+((u>>24L)&0xfc))^ \ - *(DES_LONG *)((unsigned char *)des_SP+0x100+((t )&0xfc))^ \ - *(DES_LONG *)((unsigned char *)des_SP+0x300+((t>> 8L)&0xfc))^ \ - *(DES_LONG *)((unsigned char *)des_SP+0x500+((t>>16L)&0xfc))^ \ - *(DES_LONG *)((unsigned char *)des_SP+0x700+((t>>24L)&0xfc)); } -#endif - -#else /* original version */ - -#if defined(DES_RISC1) || defined(DES_RISC2) -#ifdef DES_RISC1 -#define D_ENCRYPT(LL,R,S) {\ - unsigned int u1,u2,u3; \ - LOAD_DATA(R,S,u,t,E0,E1,u1); \ - u>>=2L; \ - t=ROTATE(t,6); \ - u2=(int)u>>8L; \ - u1=(int)u&0x3f; \ - u2&=0x3f; \ - u>>=16L; \ - LL^=des_SPtrans[0][u1]; \ - LL^=des_SPtrans[2][u2]; \ - u3=(int)u>>8L; \ - u1=(int)u&0x3f; \ - u3&=0x3f; \ - LL^=des_SPtrans[4][u1]; \ - LL^=des_SPtrans[6][u3]; \ - u2=(int)t>>8L; \ - u1=(int)t&0x3f; \ - u2&=0x3f; \ - t>>=16L; \ - LL^=des_SPtrans[1][u1]; \ - LL^=des_SPtrans[3][u2]; \ - u3=(int)t>>8L; \ - u1=(int)t&0x3f; \ - u3&=0x3f; \ - LL^=des_SPtrans[5][u1]; \ - LL^=des_SPtrans[7][u3]; } -#endif -#ifdef DES_RISC2 -#define D_ENCRYPT(LL,R,S) {\ - unsigned int u1,u2,s1,s2; \ - LOAD_DATA(R,S,u,t,E0,E1,u1); \ - u>>=2L; \ - t=ROTATE(t,6); \ - u2=(int)u>>8L; \ - u1=(int)u&0x3f; \ - u2&=0x3f; \ - LL^=des_SPtrans[0][u1]; \ - LL^=des_SPtrans[2][u2]; \ - s1=(int)u>>16L; \ - s2=(int)u>>24L; \ - s1&=0x3f; \ - s2&=0x3f; \ - LL^=des_SPtrans[4][s1]; \ - LL^=des_SPtrans[6][s2]; \ - u2=(int)t>>8L; \ - u1=(int)t&0x3f; \ - u2&=0x3f; \ - LL^=des_SPtrans[1][u1]; \ - LL^=des_SPtrans[3][u2]; \ - s1=(int)t>>16; \ - s2=(int)t>>24L; \ - s1&=0x3f; \ - s2&=0x3f; \ - LL^=des_SPtrans[5][s1]; \ - LL^=des_SPtrans[7][s2]; } -#endif - -#else - -#define D_ENCRYPT(LL,R,S) {\ - LOAD_DATA_tmp(R,S,u,t,E0,E1); \ - t=ROTATE(t,4); \ - LL^=\ - des_SPtrans[0][(u>> 2L)&0x3f]^ \ - des_SPtrans[2][(u>>10L)&0x3f]^ \ - des_SPtrans[4][(u>>18L)&0x3f]^ \ - des_SPtrans[6][(u>>26L)&0x3f]^ \ - des_SPtrans[1][(t>> 2L)&0x3f]^ \ - des_SPtrans[3][(t>>10L)&0x3f]^ \ - des_SPtrans[5][(t>>18L)&0x3f]^ \ - des_SPtrans[7][(t>>26L)&0x3f]; } -#endif -#endif - - /* IP and FP - * The problem is more of a geometric problem that random bit fiddling. - 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6 - 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4 - 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2 - 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0 - - 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7 - 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5 - 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3 - 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1 - - The output has been subject to swaps of the form - 0 1 -> 3 1 but the odd and even bits have been put into - 2 3 2 0 - different words. The main trick is to remember that - t=((l>>size)^r)&(mask); - r^=t; - l^=(t<>(n))^(b))&(m)),\ - (b)^=(t),\ - (a)^=((t)<<(n))) - -#define IP(l,r) \ - { \ - register DES_LONG tt; \ - PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \ - PERM_OP(l,r,tt,16,0x0000ffffL); \ - PERM_OP(r,l,tt, 2,0x33333333L); \ - PERM_OP(l,r,tt, 8,0x00ff00ffL); \ - PERM_OP(r,l,tt, 1,0x55555555L); \ - } - -#define FP(l,r) \ - { \ - register DES_LONG tt; \ - PERM_OP(l,r,tt, 1,0x55555555L); \ - PERM_OP(r,l,tt, 8,0x00ff00ffL); \ - PERM_OP(l,r,tt, 2,0x33333333L); \ - PERM_OP(r,l,tt,16,0x0000ffffL); \ - PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ - } - -extern const DES_LONG des_SPtrans[8][64]; - -#ifndef NOPROTO -void fcrypt_body(DES_LONG *out,des_key_schedule ks, - DES_LONG Eswap0, DES_LONG Eswap1); -#else -void fcrypt_body(); -#endif - -#endif diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c index fdf0fbf461..746c456f8f 100644 --- a/src/lib/libcrypto/des/des_opts.c +++ b/src/lib/libcrypto/des/des_opts.c @@ -59,19 +59,19 @@ /* define PART1, PART2, PART3 or PART4 to build only with a few of the options. * This is for machines with 64k code segment size restrictions. */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include #ifndef MSDOS -#include +#include +#include OPENSSL_UNISTD #else #include extern void exit(); #endif #include -#ifndef VMS #ifndef _IRIX #include #endif @@ -79,25 +79,27 @@ extern void exit(); #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun + +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "des.h" +#include #include "spr.h" #define DES_DEFAULT_OPTIONS @@ -317,11 +319,7 @@ struct tms { #ifndef HZ # ifndef CLK_TCK # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ -# ifndef VMS -# define HZ 100.0 -# else /* VMS */ -# define HZ 100.0 -# endif +# define HZ 100.0 # else /* _BSD_CLK_TCK_ */ # define HZ ((double)_BSD_CLK_TCK_) # endif @@ -333,12 +331,7 @@ struct tms { #define BUFSIZE ((long)1024) long run=0; -#ifndef NOPROTO double Time_F(int s); -#else -double Time_F(); -#endif - #ifdef SIGALRM #if defined(__STDC__) || defined(sgi) #define SIGRETTYPE void @@ -346,14 +339,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -366,8 +353,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -425,9 +411,7 @@ int s; fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ tm[index]*8,1.0e6/tm[index]); -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; @@ -454,13 +438,13 @@ char **argv; fprintf(stderr,"program when this computer is idle.\n"); #endif - des_set_key((C_Block *)key,sch); - des_set_key((C_Block *)key2,sch2); - des_set_key((C_Block *)key3,sch3); + des_set_key(&key,sch); + des_set_key(&key2,sch2); + des_set_key(&key3,sch3); #ifndef SIGALRM fprintf(stderr,"First we calculate the approximate speed ...\n"); - des_set_key((C_Block *)key,sch); + des_set_key(&key,sch); count=10; do { long i; diff --git a/src/lib/libcrypto/des/des_ver.h b/src/lib/libcrypto/des/des_ver.h index 7041a9271d..de3c02f110 100644 --- a/src/lib/libcrypto/des/des_ver.h +++ b/src/lib/libcrypto/des/des_ver.h @@ -56,5 +56,6 @@ * [including the GNU Public Licence.] */ -extern char *DES_version; /* SSLeay version string */ -extern char *libdes_version; /* old libdes version string */ +#include +OPENSSL_EXTERN char *DES_version; /* SSLeay version string */ +OPENSSL_EXTERN char *libdes_version; /* old libdes version string */ diff --git a/src/lib/libcrypto/des/dess.cpp b/src/lib/libcrypto/des/dess.cpp index 7fb5987314..753e67ad9b 100644 --- a/src/lib/libcrypto/des/dess.cpp +++ b/src/lib/libcrypto/des/dess.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include #include -#include "des.h" +#include void main(int argc,char *argv[]) { diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c index 620c13ba6f..5a04fc9298 100644 --- a/src/lib/libcrypto/des/destest.c +++ b/src/lib/libcrypto/des/destest.c @@ -65,12 +65,27 @@ #include #include #ifndef MSDOS -#include +#if !defined(VMS) || defined(__DECC) +#include +#include OPENSSL_UNISTD +#endif /* VMS */ #else #include #endif #include -#include "des.h" + +#ifdef NO_DES +int main(int argc, char *argv[]) +{ + printf("No DES support\n"); + return(0); +} +#else +#include + +#if defined(PERL5) || defined(__FreeBSD__) +#define crypt(c,s) (des_crypt((c),(s))) +#endif /* tisk tisk - the test keys don't all have odd parity :-( */ /* test data */ @@ -225,7 +240,7 @@ static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10}; /* Changed the following text constant to binary so it will work on ebcdic * machines :-) */ /* static char cbc_data[40]="7654321 Now is the time for \0001"; */ -static char cbc_data[40]={ +static unsigned char cbc_data[40]={ 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, @@ -297,24 +312,14 @@ static unsigned char ofb_cipher[24]= DES_LONG cbc_cksum_ret=0xB462FEF7L; unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; -#ifndef NOPROTO static char *pt(unsigned char *p); static int cfb_test(int bits, unsigned char *cfb_cipher); static int cfb64_test(unsigned char *cfb_cipher); static int ede_cfb64_test(unsigned char *cfb_cipher); -#else -static char *pt(); -static int cfb_test(); -static int cfb64_test(); -static int ede_cfb64_test(); -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,j,err=0; - des_cblock in,out,outin,iv3; + des_cblock in,out,outin,iv3,iv2; des_key_schedule ks,ks2,ks3; unsigned char cbc_in[40]; unsigned char cbc_out[40]; @@ -324,10 +329,63 @@ char *argv[]; int num; char *str; +#ifndef NO_DESCBCM + printf("Doing cbcm\n"); + if ((j=des_key_sched(&cbc_key,ks)) != 0) + { + printf("Key error %d\n",j); + err=1; + } + if ((j=des_key_sched(&cbc2_key,ks2)) != 0) + { + printf("Key error %d\n",j); + err=1; + } + if ((j=des_key_sched(&cbc3_key,ks3)) != 0) + { + printf("Key error %d\n",j); + err=1; + } + memset(cbc_out,0,40); + memset(cbc_in,0,40); + i=strlen((char *)cbc_data)+1; + /* i=((i+7)/8)*8; */ + memcpy(iv3,cbc_iv,sizeof(cbc_iv)); + memset(iv2,'\0',sizeof iv2); + + des_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,&iv2, + DES_ENCRYPT); + des_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,ks,ks2,ks3, + &iv3,&iv2,DES_ENCRYPT); + /* if (memcmp(cbc_out,cbc3_ok, + (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) + { + printf("des_ede3_cbc_encrypt encrypt error\n"); + err=1; + } + */ + memcpy(iv3,cbc_iv,sizeof(cbc_iv)); + memset(iv2,'\0',sizeof iv2); + des_ede3_cbcm_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,&iv2,DES_DECRYPT); + if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) + { + int n; + + printf("des_ede3_cbcm_encrypt decrypt error\n"); + for(n=0 ; n < i ; ++n) + printf(" %02x",cbc_data[n]); + printf("\n"); + for(n=0 ; n < i ; ++n) + printf(" %02x",cbc_in[n]); + printf("\n"); + err=1; + } +#endif + printf("Doing ecb\n"); for (i=0; i 0) lqret[i]=lqret[i]>>(j*8); /* For Cray */ + if (!c[0] && (j > 0)) + lqret[i]=lqret[i]>>(j*8); /* For Cray */ } - { /* Big-endian fix */ - static DES_LONG l=1; - static unsigned char *c=(unsigned char *)&l; - DES_LONG ll; if (!c[0]) { @@ -691,25 +741,25 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); if (lqret[0] != 0x327eba8dL) { printf("quad_cksum error, out[0] %08lx is not %08lx\n", - (unsigned long)lqret[0],0x327eba8dL); + (unsigned long)lqret[0],0x327eba8dUL); err=1; } if (lqret[1] != 0x201a49ccL) { printf("quad_cksum error, out[1] %08lx is not %08lx\n", - (unsigned long)lqret[1],0x201a49ccL); + (unsigned long)lqret[1],0x201a49ccUL); err=1; } if (lqret[2] != 0x70d7a63aL) { printf("quad_cksum error, out[2] %08lx is not %08lx\n", - (unsigned long)lqret[2],0x70d7a63aL); + (unsigned long)lqret[2],0x70d7a63aUL); err=1; } if (lqret[3] != 0x501c2c26L) { printf("quad_cksum error, out[3] %08lx is not %08lx\n", - (unsigned long)lqret[3],0x501c2c26L); + (unsigned long)lqret[3],0x501c2c26UL); err=1; } #endif @@ -718,17 +768,17 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); for (i=0; i<4; i++) { printf(" %d",i); - des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in, - (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, - DES_ENCRYPT); + des_ncbc_encrypt(&(cbc_out[i]),cbc_in, + strlen((char *)cbc_data)+1,ks, + &cbc_iv,DES_ENCRYPT); } printf("\noutput word alignment test"); for (i=0; i<4; i++) { printf(" %d",i); - des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]), - (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, - DES_ENCRYPT); + des_ncbc_encrypt(cbc_out,&(cbc_in[i]), + strlen((char *)cbc_data)+1,ks, + &cbc_iv,DES_ENCRYPT); } printf("\n"); printf("fast crypt test "); @@ -749,8 +799,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]); return(0); } -static char *pt(p) -unsigned char *p; +static char *pt(unsigned char *p) { static char bufs[10][20]; static int bnum=0; @@ -771,17 +820,15 @@ unsigned char *p; #ifndef LIBDES_LIT -static int cfb_test(bits, cfb_cipher) -int bits; -unsigned char *cfb_cipher; +static int cfb_test(int bits, unsigned char *cfb_cipher) { des_key_schedule ks; int i,err=0; - des_key_sched((C_Block *)cfb_key,ks); + des_key_sched(&cfb_key,ks); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks, - (C_Block *)cfb_tmp,DES_ENCRYPT); + des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp, + DES_ENCRYPT); if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) { err=1; @@ -790,8 +837,8 @@ unsigned char *cfb_cipher; printf("%s\n",pt(&(cfb_buf1[i]))); } memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); - des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks, - (C_Block *)cfb_tmp,DES_DECRYPT); + des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp, + DES_DECRYPT); if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) { err=1; @@ -802,20 +849,17 @@ unsigned char *cfb_cipher; return(err); } -static int cfb64_test(cfb_cipher) -unsigned char *cfb_cipher; +static int cfb64_test(unsigned char *cfb_cipher) { des_key_schedule ks; int err=0,i,n; - des_key_sched((C_Block *)cfb_key,ks); + des_key_sched(&cfb_key,ks); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); n=0; - des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks, - (C_Block *)cfb_tmp,&n,DES_ENCRYPT); - des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), - (long)sizeof(plain)-12,ks, - (C_Block *)cfb_tmp,&n,DES_ENCRYPT); + des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT); + des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks, + &cfb_tmp,&n,DES_ENCRYPT); if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) { err=1; @@ -825,11 +869,9 @@ unsigned char *cfb_cipher; } memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); n=0; - des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks, - (C_Block *)cfb_tmp,&n,DES_DECRYPT); + des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT); des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), - (long)sizeof(plain)-17,ks, - (C_Block *)cfb_tmp,&n,DES_DECRYPT); + sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT); if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) { err=1; @@ -840,20 +882,19 @@ unsigned char *cfb_cipher; return(err); } -static int ede_cfb64_test(cfb_cipher) -unsigned char *cfb_cipher; +static int ede_cfb64_test(unsigned char *cfb_cipher) { des_key_schedule ks; int err=0,i,n; - des_key_sched((C_Block *)cfb_key,ks); + des_key_sched(&cfb_key,ks); memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); n=0; - des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks, - (C_Block *)cfb_tmp,&n,DES_ENCRYPT); + des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n, + DES_ENCRYPT); des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), - (long)sizeof(plain)-12,ks,ks,ks, - (C_Block *)cfb_tmp,&n,DES_ENCRYPT); + sizeof(plain)-12,ks,ks,ks, + &cfb_tmp,&n,DES_ENCRYPT); if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) { err=1; @@ -864,10 +905,10 @@ unsigned char *cfb_cipher; memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); n=0; des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, - (C_Block *)cfb_tmp,&n,DES_DECRYPT); + &cfb_tmp,&n,DES_DECRYPT); des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), - (long)sizeof(plain)-17,ks,ks,ks, - (C_Block *)cfb_tmp,&n,DES_DECRYPT); + sizeof(plain)-17,ks,ks,ks, + &cfb_tmp,&n,DES_DECRYPT); if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) { err=1; @@ -879,4 +920,4 @@ unsigned char *cfb_cipher; } #endif - +#endif diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c index 140f6b5285..fb28b97e1a 100644 --- a/src/lib/libcrypto/des/ecb3_enc.c +++ b/src/lib/libcrypto/des/ecb3_enc.c @@ -58,20 +58,15 @@ #include "des_locl.h" -void des_ecb3_encrypt(input, output, ks1, ks2, ks3, enc) -des_cblock (*input); -des_cblock (*output); -des_key_schedule ks1; -des_key_schedule ks2; -des_key_schedule ks3; -int enc; +void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output, + des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3, + int enc) { register DES_LONG l0,l1; - register unsigned char *in,*out; DES_LONG ll[2]; + const unsigned char *in = &(*input)[0]; + unsigned char *out = &(*output)[0]; - in=(unsigned char *)input; - out=(unsigned char *)output; c2l(in,l0); c2l(in,l1); ll[0]=l0; diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c index acf23fdd00..b261a8aad9 100644 --- a/src/lib/libcrypto/des/ecb_enc.c +++ b/src/lib/libcrypto/des/ecb_enc.c @@ -58,20 +58,20 @@ #include "des_locl.h" #include "spr.h" +#include -char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; -char *DES_version="DES part of SSLeay 0.9.0b 29-Jun-1998"; +OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT; +OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT; -char *des_options() +const char *des_options(void) { static int init=1; static char buf[32]; if (init) { - char *ptr,*unroll,*risc,*size; + const char *ptr,*unroll,*risc,*size; - init=0; #ifdef DES_PTR ptr="ptr"; #else @@ -97,23 +97,21 @@ char *des_options() else size="long"; sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size); + init=0; } return(buf); } -void des_ecb_encrypt(input, output, ks, enc) -des_cblock (*input); -des_cblock (*output); -des_key_schedule ks; -int enc; +void des_ecb_encrypt(const_des_cblock *input, des_cblock *output, + des_key_schedule ks, + int enc) { register DES_LONG l; - register unsigned char *in,*out; DES_LONG ll[2]; + const unsigned char *in = &(*input)[0]; + unsigned char *out = &(*output)[0]; - in=(unsigned char *)input; - out=(unsigned char *)output; c2l(in,l); ll[0]=l; c2l(in,l); ll[1]=l; des_encrypt(ll,ks,enc); diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c new file mode 100644 index 0000000000..c53062481d --- /dev/null +++ b/src/lib/libcrypto/des/ede_cbcm_enc.c @@ -0,0 +1,197 @@ +/* ede_cbcm_enc.c */ +/* Written by Ben Laurie for the OpenSSL + * project 13 Feb 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + +This is an implementation of Triple DES Cipher Block Chaining with Output +Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom). + +Note that there is a known attack on this by Biham and Knudsen but it takes +a lot of work: + +http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz + +*/ + +#ifndef NO_DESCBCM +#include "des_locl.h" + +void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out, + long length, des_key_schedule ks1, des_key_schedule ks2, + des_key_schedule ks3, des_cblock *ivec1, des_cblock *ivec2, + int enc) + { + register DES_LONG tin0,tin1; + register DES_LONG tout0,tout1,xor0,xor1,m0,m1; + register long l=length; + DES_LONG tin[2]; + unsigned char *iv1,*iv2; + + iv1 = &(*ivec1)[0]; + iv2 = &(*ivec2)[0]; + + if (enc) + { + c2l(iv1,m0); + c2l(iv1,m1); + c2l(iv2,tout0); + c2l(iv2,tout1); + for (l-=8; l>=-7; l-=8) + { + tin[0]=m0; + tin[1]=m1; + des_encrypt(tin,ks3,1); + m0=tin[0]; + m1=tin[1]; + + if(l < 0) + { + c2ln(in,tin0,tin1,l+8); + } + else + { + c2l(in,tin0); + c2l(in,tin1); + } + tin0^=tout0; + tin1^=tout1; + + tin[0]=tin0; + tin[1]=tin1; + des_encrypt(tin,ks1,1); + tin[0]^=m0; + tin[1]^=m1; + des_encrypt(tin,ks2,0); + tin[0]^=m0; + tin[1]^=m1; + des_encrypt(tin,ks1,1); + tout0=tin[0]; + tout1=tin[1]; + + l2c(tout0,out); + l2c(tout1,out); + } + iv1=&(*ivec1)[0]; + l2c(m0,iv1); + l2c(m1,iv1); + + iv2=&(*ivec2)[0]; + l2c(tout0,iv2); + l2c(tout1,iv2); + } + else + { + register DES_LONG t0,t1; + + c2l(iv1,m0); + c2l(iv1,m1); + c2l(iv2,xor0); + c2l(iv2,xor1); + for (l-=8; l>=-7; l-=8) + { + tin[0]=m0; + tin[1]=m1; + des_encrypt(tin,ks3,1); + m0=tin[0]; + m1=tin[1]; + + c2l(in,tin0); + c2l(in,tin1); + + t0=tin0; + t1=tin1; + + tin[0]=tin0; + tin[1]=tin1; + des_encrypt(tin,ks1,0); + tin[0]^=m0; + tin[1]^=m1; + des_encrypt(tin,ks2,1); + tin[0]^=m0; + tin[1]^=m1; + des_encrypt(tin,ks1,0); + tout0=tin[0]; + tout1=tin[1]; + + tout0^=xor0; + tout1^=xor1; + if(l < 0) + { + l2cn(tout0,tout1,out,l+8); + } + else + { + l2c(tout0,out); + l2c(tout1,out); + } + xor0=t0; + xor1=t1; + } + + iv1=&(*ivec1)[0]; + l2c(m0,iv1); + l2c(m1,iv1); + + iv2=&(*ivec2)[0]; + l2c(xor0,iv2); + l2c(xor1,iv2); + } + tin0=tin1=tout0=tout1=xor0=xor1=0; + tin[0]=tin[1]=0; + } +#endif diff --git a/src/lib/libcrypto/des/ede_enc.c b/src/lib/libcrypto/des/ede_enc.c deleted file mode 100644 index 9f75dd1037..0000000000 --- a/src/lib/libcrypto/des/ede_enc.c +++ /dev/null @@ -1,190 +0,0 @@ -/* crypto/des/ede_enc.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include "des_locl.h" - -void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule ks1; -des_key_schedule ks2; -des_key_schedule ks3; -des_cblock (*ivec); -int enc; - { - register DES_LONG tin0,tin1; - register DES_LONG tout0,tout1,xor0,xor1; - register unsigned char *in,*out; - register long l=length; - DES_LONG tin[2]; - unsigned char *iv; - - in=(unsigned char *)input; - out=(unsigned char *)output; - iv=(unsigned char *)ivec; - - if (enc) - { - c2l(iv,tout0); - c2l(iv,tout1); - for (l-=8; l>=0; l-=8) - { - c2l(in,tin0); - c2l(in,tin1); - tin0^=tout0; - tin1^=tout1; - - tin[0]=tin0; - tin[1]=tin1; - des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); - tout0=tin[0]; - tout1=tin[1]; - - l2c(tout0,out); - l2c(tout1,out); - } - if (l != -8) - { - c2ln(in,tin0,tin1,l+8); - tin0^=tout0; - tin1^=tout1; - - tin[0]=tin0; - tin[1]=tin1; - des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); - tout0=tin[0]; - tout1=tin[1]; - - l2c(tout0,out); - l2c(tout1,out); - } - iv=(unsigned char *)ivec; - l2c(tout0,iv); - l2c(tout1,iv); - } - else - { - register DES_LONG t0,t1; - - c2l(iv,xor0); - c2l(iv,xor1); - for (l-=8; l>=0; l-=8) - { - c2l(in,tin0); - c2l(in,tin1); - - t0=tin0; - t1=tin1; - - tin[0]=tin0; - tin[1]=tin1; - des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); - tout0=tin[0]; - tout1=tin[1]; - - tout0^=xor0; - tout1^=xor1; - l2c(tout0,out); - l2c(tout1,out); - xor0=t0; - xor1=t1; - } - if (l != -8) - { - c2l(in,tin0); - c2l(in,tin1); - - t0=tin0; - t1=tin1; - - tin[0]=tin0; - tin[1]=tin1; - des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); - tout0=tin[0]; - tout1=tin[1]; - - tout0^=xor0; - tout1^=xor1; - l2cn(tout0,tout1,out,l+8); - xor0=t0; - xor1=t1; - } - - iv=(unsigned char *)ivec; - l2c(xor0,iv); - l2c(xor1,iv); - } - tin0=tin1=tout0=tout1=xor0=xor1=0; - tin[0]=tin[1]=0; - } - -#ifdef undef /* MACRO */ -void des_ede2_cbc_encrypt(input, output, length, ks1, ks2, ivec, enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule ks1; -des_key_schedule ks2; -des_cblock (*ivec); -int enc; - { - des_ede3_cbc_encrypt(input,output,length,ks1,ks2,ks1,ivec,enc); - } -#endif - diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c index e08a904d75..694970ccd2 100644 --- a/src/lib/libcrypto/des/enc_read.c +++ b/src/lib/libcrypto/des/enc_read.c @@ -58,18 +58,34 @@ #include #include +#include "cryptlib.h" #include "des_locl.h" /* This has some uglies in it but it works - even over sockets. */ /*extern int errno;*/ -int des_rw_mode=DES_PCBC_MODE; - -int des_enc_read(fd, buf, len, sched, iv) -int fd; -char *buf; -int len; -des_key_schedule sched; -des_cblock (*iv); +OPENSSL_GLOBAL int des_rw_mode=DES_PCBC_MODE; + + +/* + * WARNINGS: + * + * - The data format used by des_enc_write() and des_enc_read() + * has a cryptographic weakness: When asked to write more + * than MAXWRITE bytes, des_enc_write will split the data + * into several chunks that are all encrypted + * using the same IV. So don't use these functions unless you + * are sure you know what you do (in which case you might + * not want to use them anyway). + * + * - This code cannot handle non-blocking sockets. + * + * - This function uses an internal state and thus cannot be + * used on multiple files. + */ + + +int des_enc_read(int fd, void *buf, int len, des_key_schedule sched, + des_cblock *iv) { /* data to be unencrypted */ int net_num=0; @@ -77,27 +93,27 @@ des_cblock (*iv); /* extra unencrypted data * for when a block of 100 comes in but is des_read one byte at * a time. */ - static char *unnet=NULL; + static unsigned char *unnet=NULL; static int unnet_start=0; static int unnet_left=0; - static char *tmpbuf=NULL; + static unsigned char *tmpbuf=NULL; int i; long num=0,rnum; unsigned char *p; if (tmpbuf == NULL) { - tmpbuf=(char *)malloc(BSIZE); + tmpbuf=Malloc(BSIZE); if (tmpbuf == NULL) return(-1); } if (net == NULL) { - net=(unsigned char *)malloc(BSIZE); + net=Malloc(BSIZE); if (net == NULL) return(-1); } if (unnet == NULL) { - unnet=(char *)malloc(BSIZE); + unnet=Malloc(BSIZE); if (unnet == NULL) return(-1); } /* left over data from last decrypt */ @@ -109,7 +125,7 @@ des_cblock (*iv); * with the number of bytes we have - should always * check the return value */ memcpy(buf,&(unnet[unnet_start]), - (unsigned int)unnet_left); + unnet_left); /* eay 26/08/92 I had the next 2 lines * reversed :-( */ i=unnet_left; @@ -117,7 +133,7 @@ des_cblock (*iv); } else { - memcpy(buf,&(unnet[unnet_start]),(unsigned int)len); + memcpy(buf,&(unnet[unnet_start]),len); unnet_start+=len; unnet_left-=len; i=len; @@ -131,7 +147,7 @@ des_cblock (*iv); /* first - get the length */ while (net_num < HDRSIZE) { - i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num); + i=read(fd,&(net[net_num]),HDRSIZE-net_num); #ifdef EINTR if ((i == -1) && (errno == EINTR)) continue; #endif @@ -153,7 +169,7 @@ des_cblock (*iv); net_num=0; while (net_num < rnum) { - i=read(fd,&(net[net_num]),(unsigned int)rnum-net_num); + i=read(fd,&(net[net_num]),rnum-net_num); #ifdef EINTR if ((i == -1) && (errno == EINTR)) continue; #endif @@ -165,14 +181,12 @@ des_cblock (*iv); if (len < num) { if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet, - num,sched,iv,DES_DECRYPT); + des_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT); else - des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet, - num,sched,iv,DES_DECRYPT); - memcpy(buf,unnet,(unsigned int)len); + des_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT); + memcpy(buf,unnet,len); unnet_start=len; - unnet_left=(int)num-len; + unnet_left=num-len; /* The following line is done because we return num * as the number of bytes read. */ @@ -189,30 +203,26 @@ des_cblock (*iv); { if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)net, - (des_cblock *)tmpbuf, - num,sched,iv,DES_DECRYPT); + des_pcbc_encrypt(net,tmpbuf,num,sched,iv, + DES_DECRYPT); else - des_cbc_encrypt((des_cblock *)net, - (des_cblock *)tmpbuf, - num,sched,iv,DES_DECRYPT); + des_cbc_encrypt(net,tmpbuf,num,sched,iv, + DES_DECRYPT); /* eay 26/08/92 fix a bug that returned more * bytes than you asked for (returned len bytes :-( */ - memcpy(buf,tmpbuf,(unsigned int)num); + memcpy(buf,tmpbuf,num); } else { if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)net, - (des_cblock *)buf,num,sched,iv, - DES_DECRYPT); + des_pcbc_encrypt(net,buf,num,sched,iv, + DES_DECRYPT); else - des_cbc_encrypt((des_cblock *)net, - (des_cblock *)buf,num,sched,iv, - DES_DECRYPT); + des_cbc_encrypt(net,buf,num,sched,iv, + DES_DECRYPT); } } - return((int)num); + return num; } diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c index 29a7330fb0..ba3f0822ef 100644 --- a/src/lib/libcrypto/des/enc_writ.c +++ b/src/lib/libcrypto/des/enc_writ.c @@ -58,32 +58,44 @@ #include #include +#include +#include "cryptlib.h" #include "des_locl.h" +#include -int des_enc_write(fd, buf, len, sched, iv) -int fd; -char *buf; -int len; -des_key_schedule sched; -des_cblock (*iv); +/* + * WARNINGS: + * + * - The data format used by des_enc_write() and des_enc_read() + * has a cryptographic weakness: When asked to write more + * than MAXWRITE bytes, des_enc_write will split the data + * into several chunks that are all encrypted + * using the same IV. So don't use these functions unless you + * are sure you know what you do (in which case you might + * not want to use them anyway). + * + * - This code cannot handle non-blocking sockets. + */ + +int des_enc_write(int fd, const void *_buf, int len, + des_key_schedule sched, des_cblock *iv) { #ifdef _LIBC - extern int srandom(); extern unsigned long time(); - extern int random(); extern int write(); #endif - + const unsigned char *buf=_buf; long rnum; int i,j,k,outnum; - static char *outbuf=NULL; - char shortbuf[8]; - char *p; + static unsigned char *outbuf=NULL; + unsigned char shortbuf[8]; + unsigned char *p; + const unsigned char *cp; static int start=1; if (outbuf == NULL) { - outbuf=(char *)malloc(BSIZE+HDRSIZE); + outbuf=Malloc(BSIZE+HDRSIZE); if (outbuf == NULL) return(-1); } /* If we are sending less than 8 bytes, the same char will look @@ -91,7 +103,6 @@ des_cblock (*iv); if (start) { start=0; - srandom((unsigned int)time(NULL)); } /* lets recurse if we want to send the data in small chunks */ @@ -117,35 +128,32 @@ des_cblock (*iv); /* pad short strings */ if (len < 8) { - p=shortbuf; - memcpy(shortbuf,buf,(unsigned int)len); - for (i=len; i<8; i++) - shortbuf[i]=random(); + cp=shortbuf; + memcpy(shortbuf,buf,len); + RAND_bytes(shortbuf+len, 8-len); rnum=8; } else { - p=buf; + cp=(unsigned char*)buf; rnum=((len+7)/8*8); /* round up to nearest eight */ } if (des_rw_mode & DES_PCBC_MODE) - des_pcbc_encrypt((des_cblock *)p, - (des_cblock *)&(outbuf[HDRSIZE]), - (long)((len<8)?8:len),sched,iv,DES_ENCRYPT); + des_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv, + DES_ENCRYPT); else - des_cbc_encrypt((des_cblock *)p, - (des_cblock *)&(outbuf[HDRSIZE]), - (long)((len<8)?8:len),sched,iv,DES_ENCRYPT); + des_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv, + DES_ENCRYPT); /* output */ - outnum=(int)rnum+HDRSIZE; + outnum=rnum+HDRSIZE; for (j=0; j>(16-(n))))\ -void fcrypt_body(out, ks, Eswap0, Eswap1) -DES_LONG *out; -des_key_schedule ks; -DES_LONG Eswap0; -DES_LONG Eswap1; +void fcrypt_body(DES_LONG *out, des_key_schedule ks, DES_LONG Eswap0, + DES_LONG Eswap1) { register DES_LONG l,r,t,u; #ifdef DES_PTR - register unsigned char *des_SP=(unsigned char *)des_SPtrans; + register const unsigned char *des_SP=(const unsigned char *)des_SPtrans; #endif register DES_LONG *s; register int j; diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c index 1d1a368c22..e0e67a417d 100644 --- a/src/lib/libcrypto/des/ncbc_enc.c +++ b/src/lib/libcrypto/des/ncbc_enc.c @@ -58,24 +58,21 @@ #include "des_locl.h" -void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule schedule; -des_cblock (*ivec); -int enc; +#ifdef CBC_ENC_C__DONT_UPDATE_IV +void des_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + des_key_schedule schedule, des_cblock *ivec, int enc) +#else +void des_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length, + des_key_schedule schedule, des_cblock *ivec, int enc) +#endif { register DES_LONG tin0,tin1; register DES_LONG tout0,tout1,xor0,xor1; - register unsigned char *in,*out; register long l=length; DES_LONG tin[2]; unsigned char *iv; - in=(unsigned char *)input; - out=(unsigned char *)output; - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; if (enc) { @@ -100,9 +97,11 @@ int enc; tout0=tin[0]; l2c(tout0,out); tout1=tin[1]; l2c(tout1,out); } - iv=(unsigned char *)ivec; +#ifndef CBC_ENC_C__DONT_UPDATE_IV + iv = &(*ivec)[0]; l2c(tout0,iv); l2c(tout1,iv); +#endif } else { @@ -120,11 +119,25 @@ int enc; xor0=tin0; xor1=tin1; } - iv=(unsigned char *)ivec; + if (l != -8) + { + c2l(in,tin0); tin[0]=tin0; + c2l(in,tin1); tin[1]=tin1; + des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); + tout0=tin[0]^xor0; + tout1=tin[1]^xor1; + l2cn(tout0,tout1,out,l+8); +#ifndef CBC_ENC_C__DONT_UPDATE_IV + xor0=tin0; + xor1=tin1; +#endif + } +#ifndef CBC_ENC_C__DONT_UPDATE_IV + iv = &(*ivec)[0]; l2c(xor0,iv); l2c(xor1,iv); +#endif } tin0=tin1=tout0=tout1=xor0=xor1=0; tin[0]=tin[1]=0; } - diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c index 4b1b0199f1..6eafe908da 100644 --- a/src/lib/libcrypto/des/ofb64ede.c +++ b/src/lib/libcrypto/des/ofb64ede.c @@ -62,13 +62,10 @@ * used. The extra state information to record how much of the * 64bit block we have used is contained in *num; */ -void des_ede3_ofb64_encrypt(in, out, length, k1,k2,k3, ivec, num) -register unsigned char *in; -register unsigned char *out; -long length; -des_key_schedule k1,k2,k3; -des_cblock (*ivec); -int *num; +void des_ede3_ofb64_encrypt(register const unsigned char *in, + register unsigned char *out, long length, des_key_schedule k1, + des_key_schedule k2, des_key_schedule k3, des_cblock *ivec, + int *num) { register DES_LONG v0,v1; register int n= *num; @@ -79,7 +76,7 @@ int *num; unsigned char *iv; int save=0; - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; c2l(iv,v0); c2l(iv,v1); ti[0]=v0; @@ -93,7 +90,7 @@ int *num; { /* ti[0]=v0; */ /* ti[1]=v1; */ - des_encrypt3((DES_LONG *)ti,k1,k2,k3); + des_encrypt3(ti,k1,k2,k3); v0=ti[0]; v1=ti[1]; @@ -109,7 +106,7 @@ int *num; { /* v0=ti[0]; v1=ti[1];*/ - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(v0,iv); l2c(v1,iv); } @@ -118,13 +115,9 @@ int *num; } #ifdef undef /* MACRO */ -void des_ede2_ofb64_encrypt(in, out, length, k1,k2, ivec, num) -register unsigned char *in; -register unsigned char *out; -long length; -des_key_schedule k1,k2; -des_cblock (*ivec); -int *num; +void des_ede2_ofb64_encrypt(register unsigned char *in, + register unsigned char *out, long length, des_key_schedule k1, + des_key_schedule k2, des_cblock (*ivec), int *num) { des_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num); } diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c index ea7e612697..64953959ca 100644 --- a/src/lib/libcrypto/des/ofb64enc.c +++ b/src/lib/libcrypto/des/ofb64enc.c @@ -62,37 +62,33 @@ * used. The extra state information to record how much of the * 64bit block we have used is contained in *num; */ -void des_ofb64_encrypt(in, out, length, schedule, ivec, num) -register unsigned char *in; -register unsigned char *out; -long length; -des_key_schedule schedule; -des_cblock (*ivec); -int *num; +void des_ofb64_encrypt(register const unsigned char *in, + register unsigned char *out, long length, des_key_schedule schedule, + des_cblock *ivec, int *num) { register DES_LONG v0,v1,t; register int n= *num; register long l=length; des_cblock d; - register char *dp; + register unsigned char *dp; DES_LONG ti[2]; unsigned char *iv; int save=0; - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; c2l(iv,v0); c2l(iv,v1); ti[0]=v0; ti[1]=v1; - dp=(char *)d; + dp=d; l2c(v0,dp); l2c(v1,dp); while (l--) { if (n == 0) { - des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); - dp=(char *)d; + des_encrypt(ti,schedule,DES_ENCRYPT); + dp=d; t=ti[0]; l2c(t,dp); t=ti[1]; l2c(t,dp); save++; @@ -104,7 +100,7 @@ int *num; { v0=ti[0]; v1=ti[1]; - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(v0,iv); l2c(v1,iv); } diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c index 4db0cdbd60..a8f425a575 100644 --- a/src/lib/libcrypto/des/ofb_enc.c +++ b/src/lib/libcrypto/des/ofb_enc.c @@ -64,13 +64,8 @@ * the second. The second 12 bits will come from the 3rd and half the 4th * byte. */ -void des_ofb_encrypt(in, out, numbits, length, schedule, ivec) -unsigned char *in; -unsigned char *out; -int numbits; -long length; -des_key_schedule schedule; -des_cblock (*ivec); +void des_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits, + long length, des_key_schedule schedule, des_cblock *ivec) { register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8; register DES_LONG mask0,mask1; @@ -97,7 +92,7 @@ des_cblock (*ivec); mask1=0x00000000L; } - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; c2l(iv,v0); c2l(iv,v1); ti[0]=v0; @@ -131,7 +126,7 @@ des_cblock (*ivec); v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL; } } - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(v0,iv); l2c(v1,iv); v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0; diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c index 4513207d90..dd69a26d4a 100644 --- a/src/lib/libcrypto/des/pcbc_enc.c +++ b/src/lib/libcrypto/des/pcbc_enc.c @@ -58,21 +58,17 @@ #include "des_locl.h" -void des_pcbc_encrypt(input, output, length, schedule, ivec, enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule schedule; -des_cblock (*ivec); -int enc; +void des_pcbc_encrypt(const unsigned char *input, unsigned char *output, + long length, des_key_schedule schedule, des_cblock *ivec, int enc) { register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1; DES_LONG tin[2]; - unsigned char *in,*out,*iv; + const unsigned char *in; + unsigned char *out,*iv; - in=(unsigned char *)input; - out=(unsigned char *)output; - iv=(unsigned char *)ivec; + in=input; + out=output; + iv = &(*ivec)[0]; if (enc) { diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c index 8526abf334..6ce8c61b42 100644 --- a/src/lib/libcrypto/des/qud_cksm.c +++ b/src/lib/libcrypto/des/qud_cksm.c @@ -73,28 +73,24 @@ /* Got the value MIT uses via brute force :-) 2/10/90 eay */ #define NOISE ((DES_LONG)83653421L) -DES_LONG des_quad_cksum(input, output, length, out_count, seed) -des_cblock (*input); -des_cblock (*output); -long length; -int out_count; -des_cblock (*seed); +DES_LONG des_quad_cksum(const unsigned char *input, des_cblock output[], + long length, int out_count, des_cblock *seed) { DES_LONG z0,z1,t0,t1; int i; long l; - unsigned char *cp; + const unsigned char *cp; unsigned char *lp; if (out_count < 1) out_count=1; - lp=(unsigned char *)output; + lp = &(output[0])[0]; z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]); z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]); for (i=0; ((i<4)&&(i 0) { @@ -133,7 +129,7 @@ des_cblock (*seed); } else { - lp=output[out_count-i-1]; + lp = &(output[out_count-i-1])[0]; l2n(z1,lp); l2n(z0,lp); } diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c index 8c30bd029a..fc11792cda 100644 --- a/src/lib/libcrypto/des/rand_key.c +++ b/src/lib/libcrypto/des/rand_key.c @@ -62,15 +62,13 @@ static int seed=0; static des_cblock init; -void des_random_seed(key) -des_cblock key; +void des_random_seed(des_cblock *key) { - memcpy(init,key,sizeof(des_cblock)); + memcpy(&init,key,sizeof(des_cblock)); seed=1; } -void des_random_key(ret) -unsigned char *ret; +void des_random_key(des_cblock *ret) { des_key_schedule ks; static DES_LONG c=0; @@ -101,15 +99,13 @@ unsigned char *ret; t=(DES_LONG)((pid)|((c++)<<16)); l2c(t,p); - des_set_odd_parity((des_cblock *)data); - des_set_key((des_cblock *)data,ks); - des_cbc_cksum((des_cblock *)key,(des_cblock *)key, - (long)sizeof(key),ks,(des_cblock *)data); + des_set_odd_parity(&data); + des_set_key(&data,ks); + des_cbc_cksum(key,&key,sizeof(key),ks,&data); - des_set_odd_parity((des_cblock *)key); - des_set_key((des_cblock *)key,ks); - des_cbc_cksum((des_cblock *)key,(des_cblock *)data, - (long)sizeof(key),ks,(des_cblock *)key); + des_set_odd_parity(&key); + des_set_key(&key,ks); + des_cbc_cksum(key,&data,sizeof(key),ks,&key); memcpy(ret,data,sizeof(key)); memset(key,0,sizeof(key)); diff --git a/src/lib/libcrypto/des/ranlib.sh b/src/lib/libcrypto/des/ranlib.sh deleted file mode 100644 index 543f712c6b..0000000000 --- a/src/lib/libcrypto/des/ranlib.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -cwd=`pwd` -cd /tmp - -if [ -s /bin/ranlib ] ; then - RL=/bin/ranlib -else if [ -s /usr/bin/ranlib ] ; then - RL=/usr/bin/ranlib -fi -fi - -if [ "x$RL" != "x" ] -then - case "$1" in - /*) - $RL "$1" - ;; - *) - $RL "$cwd/$1" - ;; - esac -fi diff --git a/src/lib/libcrypto/des/read2pwd.c b/src/lib/libcrypto/des/read2pwd.c index a0d53793e4..a8ceaf088a 100644 --- a/src/lib/libcrypto/des/read2pwd.c +++ b/src/lib/libcrypto/des/read2pwd.c @@ -58,10 +58,7 @@ #include "des_locl.h" -int des_read_password(key, prompt, verify) -des_cblock (*key); -char *prompt; -int verify; +int des_read_password(des_cblock *key, const char *prompt, int verify) { int ok; char buf[BUFSIZ],buff[BUFSIZ]; @@ -73,11 +70,8 @@ int verify; return(ok); } -int des_read_2passwords(key1, key2, prompt, verify) -des_cblock (*key1); -des_cblock (*key2); -char *prompt; -int verify; +int des_read_2passwords(des_cblock *key1, des_cblock *key2, const char *prompt, + int verify) { int ok; char buf[BUFSIZ],buff[BUFSIZ]; diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c index 99920f2f86..fed49652c0 100644 --- a/src/lib/libcrypto/des/read_pwd.c +++ b/src/lib/libcrypto/des/read_pwd.c @@ -56,7 +56,23 @@ * [including the GNU Public Licence.] */ +#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32) +#include +#include OPENSSL_UNISTD +/* If unistd.h defines _POSIX_VERSION, we conclude that we + * are on a POSIX system and have sigaction and termios. */ +#if defined(_POSIX_VERSION) + +# define SIGACTION +# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY) +# define TERMIOS +# endif + +#endif +#endif + /* #define SIGACTION */ /* Define this if you have sigaction() */ + #ifdef WIN16TTY #undef WIN16 #undef _WINDOWS @@ -65,11 +81,26 @@ /* 06-Apr-92 Luke Brennan Support for VMS */ #include "des_locl.h" +#include "cryptlib.h" #include +#include #include #include #include +#ifdef VMS /* prototypes for sys$whatever */ +#include +#ifdef __DECC +#pragma message disable DOLLARID +#endif +#endif + +#ifdef WIN_CONSOLE_BUG +#include +#include +#endif + + /* There are 5 types of terminal interface supported, * TERMIO, TERMIOS, VMS, MSDOS and SGTTY */ @@ -147,7 +178,6 @@ struct IOSB { #define NX509_SIG 32 #endif -#ifndef NOPROTO static void read_till_nl(FILE *); static void recsig(int); static void pushsig(void); @@ -155,32 +185,15 @@ static void popsig(void); #if defined(MSDOS) && !defined(WIN16) static int noecho_fgets(char *buf, int size, FILE *tty); #endif -#else -static void read_till_nl(); -static void recsig(); -static void pushsig(); -static void popsig(); -#if defined(MSDOS) && !defined(WIN16) -static int noecho_fgets(); -#endif -#endif - #ifdef SIGACTION static struct sigaction savsig[NX509_SIG]; #else -# ifndef NOPROTO static void (*savsig[NX509_SIG])(int ); -# else - static void (*savsig[NX509_SIG])(); -# endif #endif static jmp_buf save; -int des_read_pw_string(buf, length, prompt, verify) -char *buf; -int length; -char *prompt; -int verify; +int des_read_pw_string(char *buf, int length, const char *prompt, + int verify) { char buff[BUFSIZ]; int ret; @@ -192,8 +205,7 @@ int verify; #ifndef WIN16 -static void read_till_nl(in) -FILE *in; +static void read_till_nl(FILE *in) { #define SIZE 4 char buf[SIZE+1]; @@ -205,12 +217,8 @@ FILE *in; /* return 0 if ok, 1 (or -1) otherwise */ -int des_read_pw(buf, buff, size, prompt, verify) -char *buf; -char *buff; -int size; -char *prompt; -int verify; +int des_read_pw(char *buf, char *buff, int size, const char *prompt, + int verify) { #ifdef VMS struct IOSB iosb; @@ -223,14 +231,27 @@ int verify; TTY_STRUCT tty_orig,tty_new; #endif #endif - int number=5; - int ok=0; - int ps=0; - int is_a_tty=1; - - FILE *tty=NULL; + int number; + int ok; + /* statics are simply to avoid warnings about longjmp clobbering + things */ + static int ps; + int is_a_tty; + static FILE *tty; char *p; + if (setjmp(save)) + { + ok=0; + goto error; + } + + number=5; + ok=0; + ps=0; + is_a_tty=1; + tty=NULL; + #ifndef MSDOS if ((tty=fopen("/dev/tty","r")) == NULL) tty=stdin; @@ -259,19 +280,14 @@ int verify; memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); #endif #ifdef VMS - status = SYS$ASSIGN(&terminal,&channel,0,0); + status = sys$assign(&terminal,&channel,0,0); if (status != SS$_NORMAL) return(-1); - status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); + status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) return(-1); #endif - if (setjmp(save)) - { - ok=0; - goto error; - } pushsig(); ps=1; @@ -287,7 +303,7 @@ int verify; tty_new[0] = tty_orig[0]; tty_new[1] = tty_orig[1] | TT$M_NOECHO; tty_new[2] = tty_orig[2]; - status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); + status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) return(-1); #endif @@ -333,31 +349,26 @@ error: perror("fgets(tty)"); #endif /* What can we do if there is an error? */ -#if defined(TTY_set) && !defined(VMS) +#if defined(TTY_set) && !defined(VMS) if (ps >= 2) TTY_set(fileno(tty),&tty_orig); #endif #ifdef VMS if (ps >= 2) - status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0 + status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0 ,tty_orig,12,0,0,0,0); #endif if (ps >= 1) popsig(); if (stdin != tty) fclose(tty); #ifdef VMS - status = SYS$DASSGN(channel); + status = sys$dassgn(channel); #endif return(!ok); } #else /* WIN16 */ -int des_read_pw(buf, buff, size, prompt, verify) -char *buf; -char *buff; -int size; -char *prompt; -int verify; +int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify) { memset(buf,0,size); memset(buff,0,size); @@ -366,9 +377,15 @@ int verify; #endif -static void pushsig() +static void pushsig(void) { int i; +#ifdef SIGACTION + struct sigaction sa; + + memset(&sa,0,sizeof sa); + sa.sa_handler=recsig; +#endif for (i=1; ides_key,ks); + des_set_key(&desp->des_key,ks); enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT; if (desp->des_mode == CBC) - des_ecb_encrypt((des_cblock *)desp->UDES.UDES_buf, - (des_cblock *)desp->UDES.UDES_buf,ks,enc); + des_ecb_encrypt((const_des_cblock *)desp->UDES.UDES_buf, + (des_cblock *)desp->UDES.UDES_buf,ks, + enc); else { - des_ncbc_encrypt((des_cblock *)desp->UDES.UDES_buf, - (des_cblock *)desp->UDES.UDES_buf, - (long)len,ks, - (des_cblock *)desp->des_ivec,enc); + des_ncbc_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf, + len,ks,&desp->des_ivec,enc); #ifdef undef /* len will always be %8 if called from common_crypt * in secure_rpc. diff --git a/src/lib/libcrypto/des/rpw.c b/src/lib/libcrypto/des/rpw.c index 6447ed9cf0..0b6b1519b0 100644 --- a/src/lib/libcrypto/des/rpw.c +++ b/src/lib/libcrypto/des/rpw.c @@ -57,17 +57,15 @@ */ #include -#include "des.h" +#include -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { des_cblock k,k1; int i; printf("read passwd\n"); - if ((i=des_read_password((C_Block *)k,"Enter password:",0)) == 0) + if ((i=des_read_password(&k,"Enter password:",0)) == 0) { printf("password = "); for (i=0; i<8; i++) @@ -77,7 +75,7 @@ char *argv[]; printf("error %d\n",i); printf("\n"); printf("read 2passwds and verify\n"); - if ((i=des_read_2passwords((C_Block *)k,(C_Block *)k1, + if ((i=des_read_2passwords(&k,&k1, "Enter verified password:",1)) == 0) { printf("password1 = "); diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c index c3bcd7ee2b..52553a4c16 100644 --- a/src/lib/libcrypto/des/set_key.c +++ b/src/lib/libcrypto/des/set_key.c @@ -67,16 +67,10 @@ #include "podd.h" #include "sk.h" -#ifndef NOPROTO -static int check_parity(des_cblock (*key)); -#else -static int check_parity(); -#endif +static int check_parity(const_des_cblock *key); +OPENSSL_GLOBAL int des_check_key=0; -int des_check_key=0; - -void des_set_odd_parity(key) -des_cblock (*key); +void des_set_odd_parity(des_cblock *key) { int i; @@ -84,8 +78,7 @@ des_cblock (*key); (*key)[i]=odd_parity[(*key)[i]]; } -static int check_parity(key) -des_cblock (*key); +static int check_parity(const_des_cblock *key) { int i; @@ -111,8 +104,8 @@ static des_cblock weak_keys[NUM_WEAK_KEY]={ /* weak keys */ {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, - {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, - {0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0}, + {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, + {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1}, /* semi-weak keys */ {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE}, {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01}, @@ -127,8 +120,7 @@ static des_cblock weak_keys[NUM_WEAK_KEY]={ {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}}; -int des_is_weak_key(key) -des_cblock (*key); +int des_is_weak_key(const_des_cblock *key) { int i; @@ -157,13 +149,11 @@ des_cblock (*key); * return -1 if key parity error, * return -2 if illegal weak key. */ -int des_set_key(key, schedule) -des_cblock (*key); -des_key_schedule schedule; +int des_set_key(const_des_cblock *key, des_key_schedule schedule) { static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; register DES_LONG c,d,t,s,t2; - register unsigned char *in; + register const unsigned char *in; register DES_LONG *k; register int i; @@ -176,8 +166,8 @@ des_key_schedule schedule; return(-2); } - k=(DES_LONG *)schedule; - in=(unsigned char *)key; + k = &schedule->ks.deslong[0]; + in = &(*key)[0]; c2l(in,c); c2l(in,d); @@ -238,9 +228,7 @@ des_key_schedule schedule; return(0); } -int des_key_sched(key, schedule) -des_cblock (*key); -des_key_schedule schedule; +int des_key_sched(const_des_cblock *key, des_key_schedule schedule) { return(des_set_key(key,schedule)); } diff --git a/src/lib/libcrypto/des/shifts.pl b/src/lib/libcrypto/des/shifts.pl index d8a240c1ba..ba686d8ef5 100644 --- a/src/lib/libcrypto/des/shifts.pl +++ b/src/lib/libcrypto/des/shifts.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl sub lab_shift { diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c index 5bbe8b01d6..da41abcb03 100644 --- a/src/lib/libcrypto/des/speed.c +++ b/src/lib/libcrypto/des/speed.c @@ -59,19 +59,17 @@ /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include -#ifndef MSDOS -#include -#else -#include -extern int exit(); -#endif + +#include +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include -#ifndef VMS #ifndef _IRIX #include #endif @@ -79,35 +77,32 @@ extern int exit(); #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "des.h" +#include /* The following if from times(3) man page. It may need to be changed */ #ifndef HZ # ifndef CLK_TCK # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ -# ifndef VMS -# define HZ 100.0 -# else /* VMS */ -# define HZ 100.0 -# endif +# define HZ 100.0 # else /* _BSD_CLK_TCK_ */ # define HZ ((double)_BSD_CLK_TCK_) # endif @@ -119,12 +114,7 @@ struct tms { #define BUFSIZE ((long)1024) long run=0; -#ifndef NOPROTO double Time_F(int s); -#else -double Time_F(); -#endif - #ifdef SIGALRM #if defined(__STDC__) || defined(sgi) || defined(_AIX) #define SIGRETTYPE void @@ -132,14 +122,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -152,8 +136,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -189,9 +172,7 @@ int s; #endif } -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; @@ -209,12 +190,12 @@ char **argv; printf("program when this computer is idle.\n"); #endif - des_set_key((C_Block *)key2,sch2); - des_set_key((C_Block *)key3,sch3); + des_set_key(&key2,sch2); + des_set_key(&key3,sch3); #ifndef SIGALRM printf("First we calculate the approximate speed ...\n"); - des_set_key((C_Block *)key,sch); + des_set_key(&key,sch); count=10; do { long i; @@ -244,7 +225,7 @@ char **argv; Time_F(START); for (count=0,run=1; COND(ca); count++) - des_set_key((C_Block *)key,sch); + des_set_key(&key,sch); d=Time_F(STOP); printf("%ld set_key's in %.2f seconds\n",count,d); a=((double)COUNT(ca))/d; @@ -276,8 +257,8 @@ char **argv; #endif Time_F(START); for (count=0,run=1; COND(cc); count++) - des_ncbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,&(sch[0]), - (C_Block *)&(key[0]),DES_ENCRYPT); + des_ncbc_encrypt(buf,buf,BUFSIZE,&(sch[0]), + &key,DES_ENCRYPT); d=Time_F(STOP); printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n", count,BUFSIZE,d); @@ -293,11 +274,11 @@ char **argv; #endif Time_F(START); for (count=0,run=1; COND(cd); count++) - des_ede3_cbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE, + des_ede3_cbc_encrypt(buf,buf,BUFSIZE, &(sch[0]), &(sch2[0]), &(sch3[0]), - (C_Block *)&(key[0]), + &key, DES_ENCRYPT); d=Time_F(STOP); printf("%ld des_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n", diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h index 81813f9f7a..b8fbdcf8d3 100644 --- a/src/lib/libcrypto/des/spr.h +++ b/src/lib/libcrypto/des/spr.h @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -const DES_LONG des_SPtrans[8][64]={ +OPENSSL_GLOBAL const DES_LONG des_SPtrans[8][64]={ { /* nibble 0 */ 0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L, diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c index 3365c1bcf3..24841452f1 100644 --- a/src/lib/libcrypto/des/str2key.c +++ b/src/lib/libcrypto/des/str2key.c @@ -58,11 +58,9 @@ #include "des_locl.h" -extern int des_check_key; +OPENSSL_EXTERN int des_check_key; -void des_string_to_key(str, key) -char *str; -des_cblock (*key); +void des_string_to_key(const char *str, des_cblock *key) { des_key_schedule ks; int i,length; @@ -89,21 +87,17 @@ des_cblock (*key); } } #endif - des_set_odd_parity((des_cblock *)key); + des_set_odd_parity(key); i=des_check_key; des_check_key=0; - des_set_key((des_cblock *)key,ks); + des_set_key(key,ks); des_check_key=i; - des_cbc_cksum((des_cblock *)str,(des_cblock *)key,(long)length,ks, - (des_cblock *)key); + des_cbc_cksum((unsigned char*)str,key,length,ks,key); memset(ks,0,sizeof(ks)); - des_set_odd_parity((des_cblock *)key); + des_set_odd_parity(key); } -void des_string_to_2keys(str, key1, key2) -char *str; -des_cblock (*key1); -des_cblock (*key2); +void des_string_to_2keys(const char *str, des_cblock *key1, des_cblock *key2) { des_key_schedule ks; int i,length; @@ -154,16 +148,14 @@ des_cblock (*key2); } if (length <= 8) memcpy(key2,key1,8); #endif - des_set_odd_parity((des_cblock *)key1); - des_set_odd_parity((des_cblock *)key2); + des_set_odd_parity(key1); + des_set_odd_parity(key2); i=des_check_key; des_check_key=0; - des_set_key((des_cblock *)key1,ks); - des_cbc_cksum((des_cblock *)str,(des_cblock *)key1,(long)length,ks, - (des_cblock *)key1); - des_set_key((des_cblock *)key2,ks); - des_cbc_cksum((des_cblock *)str,(des_cblock *)key2,(long)length,ks, - (des_cblock *)key2); + des_set_key(key1,ks); + des_cbc_cksum((unsigned char*)str,key1,length,ks,key1); + des_set_key(key2,ks); + des_cbc_cksum((unsigned char*)str,key2,length,ks,key2); des_check_key=i; memset(ks,0,sizeof(ks)); des_set_odd_parity(key1); diff --git a/src/lib/libcrypto/des/supp.c b/src/lib/libcrypto/des/supp.c index f8e5833f69..8c570c2586 100644 --- a/src/lib/libcrypto/des/supp.c +++ b/src/lib/libcrypto/des/supp.c @@ -87,18 +87,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: supp.c,v 1.1.1.1 1998/10/05 20:12:45 ryker Exp $ + * $Id: supp.c,v 1.2 1999/09/29 04:36:01 beck Exp $ */ #include #include "des_locl.h" -void des_cblock_print_file(cb, fp) - des_cblock *cb; - FILE *fp; +void des_cblock_print_file(const_des_cblock *cb, FILE *fp) { int i; - unsigned int *p = (unsigned int *)cb; + const unsigned int *p = (const unsigned int *)cb; fprintf(fp, " 0x { "); for (i = 0; i < 8; i++) { diff --git a/src/lib/libcrypto/des/testdes.pl b/src/lib/libcrypto/des/testdes.pl index 67fbd47f36..01a165a963 100644 --- a/src/lib/libcrypto/des/testdes.pl +++ b/src/lib/libcrypto/des/testdes.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # des.pl tesing code diff --git a/src/lib/libcrypto/des/vms.com b/src/lib/libcrypto/des/vms.com deleted file mode 100644 index 62ca1fbda4..0000000000 --- a/src/lib/libcrypto/des/vms.com +++ /dev/null @@ -1,90 +0,0 @@ -$! --- VMS.com --- -$! -$ GoSub defines -$ GoSub linker_options -$ If (P1 .nes. "") -$ Then -$ GoSub 'P1' -$ Else -$ GoSub lib -$ GoSub destest -$ GoSub rpw -$ GoSub speed -$ GoSub des -$ EndIF -$! -$ Exit -$! -$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -$! -$DEFINES: -$ OPT_FILE := "VAX_LINKER_OPTIONS.OPT" -$! -$ CC_OPTS := "/NODebug/OPTimize/NOWarn" -$! -$ LINK_OPTS := "/NODebug/NOTraceback/Contiguous" -$! -$ OBJS = "cbc_cksm.obj,cbc_enc.obj,ecb_enc.obj,pcbc_enc.obj," + - - "qud_cksm.obj,rand_key.obj,read_pwd.obj,set_key.obj," + - - "str2key.obj,enc_read.obj,enc_writ.obj,fcrypt.obj," + - - "cfb_enc.obj,ecb3_enc.obj,ofb_enc.obj" - - -$! -$ LIBDES = "cbc_cksm.c,cbc_enc.c,ecb_enc.c,enc_read.c," + - - "enc_writ.c,pcbc_enc.c,qud_cksm.c,rand_key.c," + - - "read_pwd.c,set_key.c,str2key.c,fcrypt.c," + - - "cfb_enc.c,ecb3_enc.c,ofb_enc.c" -$ Return -$! -$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -$! -$LINKER_OPTIONS: -$ If (f$search(OPT_FILE) .eqs. "") -$ Then -$ Create 'OPT_FILE' -$DECK -! Default system options file to link against the sharable C runtime library -! -Sys$Share:VAXcRTL.exe/Share -$EOD -$ EndIF -$ Return -$! -$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -$! -$LIB: -$ CC 'CC_OPTS' 'LIBDES' -$ If (f$search("LIBDES.OLB") .nes. "") -$ Then Library /Object /Replace libdes 'OBJS' -$ Else Library /Create /Object libdes 'OBJS' -$ EndIF -$ Return -$! -$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -$! -$DESTEST: -$ CC 'CC_OPTS' destest -$ Link 'link_opts' /Exec=destest destest.obj,libdes/LIBRARY,'opt_file'/Option -$ Return -$! -$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -$! -$RPW: -$ CC 'CC_OPTS' rpw -$ Link 'link_opts' /Exec=rpw rpw.obj,libdes/LIBRARY,'opt_file'/Option -$ Return -$! -$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -$! -$SPEED: -$ CC 'CC_OPTS' speed -$ Link 'link_opts' /Exec=speed speed.obj,libdes/LIBRARY,'opt_file'/Option -$ Return -$! -$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -$! -$DES: -$ CC 'CC_OPTS' des -$ Link 'link_opts' /Exec=des des.obj,libdes/LIBRARY,'opt_file'/Option -$ Return diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c index 031589bf50..51e17e6b8a 100644 --- a/src/lib/libcrypto/des/xcbc_enc.c +++ b/src/lib/libcrypto/des/xcbc_enc.c @@ -79,18 +79,14 @@ static unsigned char desx_white_in2out[256]={ 0xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB, }; -void des_xwhite_in2out(des_key,in_white,out_white) -des_cblock (*des_key); -des_cblock (*in_white); -des_cblock (*out_white); +void des_xwhite_in2out(const_des_cblock *des_key, const_des_cblock *in_white, + des_cblock *out_white) { - unsigned char *key,*in,*out; int out0,out1; int i; - - key=(unsigned char *)des_key; - in=(unsigned char *)in_white; - out=(unsigned char *)out_white; + const unsigned char *key = &(*des_key)[0]; + const unsigned char *in = &(*in_white)[0]; + unsigned char *out = &(*out_white)[0]; out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0; out0=out1=0; @@ -111,34 +107,26 @@ des_cblock (*out_white); } } -void des_xcbc_encrypt(input, output, length, schedule, ivec, inw,outw,enc) -des_cblock (*input); -des_cblock (*output); -long length; -des_key_schedule schedule; -des_cblock (*ivec); -des_cblock (*inw); -des_cblock (*outw); -int enc; +void des_xcbc_encrypt(const unsigned char *in, unsigned char *out, + long length, des_key_schedule schedule, des_cblock *ivec, + const_des_cblock *inw, const_des_cblock *outw, int enc) { register DES_LONG tin0,tin1; register DES_LONG tout0,tout1,xor0,xor1; register DES_LONG inW0,inW1,outW0,outW1; - register unsigned char *in,*out; + register const unsigned char *in2; register long l=length; DES_LONG tin[2]; unsigned char *iv; - in=(unsigned char *)inw; - c2l(in,inW0); - c2l(in,inW1); - in=(unsigned char *)outw; - c2l(in,outW0); - c2l(in,outW1); + in2 = &(*inw)[0]; + c2l(in2,inW0); + c2l(in2,inW1); + in2 = &(*outw)[0]; + c2l(in2,outW0); + c2l(in2,outW1); - in=(unsigned char *)input; - out=(unsigned char *)output; - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; if (enc) { @@ -150,7 +138,7 @@ int enc; c2l(in,tin1); tin0^=tout0^inW0; tin[0]=tin0; tin1^=tout1^inW1; tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); + des_encrypt(tin,schedule,DES_ENCRYPT); tout0=tin[0]^outW0; l2c(tout0,out); tout1=tin[1]^outW1; l2c(tout1,out); } @@ -159,11 +147,11 @@ int enc; c2ln(in,tin0,tin1,l+8); tin0^=tout0^inW0; tin[0]=tin0; tin1^=tout1^inW1; tin[1]=tin1; - des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); + des_encrypt(tin,schedule,DES_ENCRYPT); tout0=tin[0]^outW0; l2c(tout0,out); tout1=tin[1]^outW1; l2c(tout1,out); } - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(tout0,iv); l2c(tout1,iv); } @@ -175,7 +163,7 @@ int enc; { c2l(in,tin0); tin[0]=tin0^outW0; c2l(in,tin1); tin[1]=tin1^outW1; - des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); + des_encrypt(tin,schedule,DES_DECRYPT); tout0=tin[0]^xor0^inW0; tout1=tin[1]^xor1^inW1; l2c(tout0,out); @@ -187,7 +175,7 @@ int enc; { c2l(in,tin0); tin[0]=tin0^outW0; c2l(in,tin1); tin[1]=tin1^outW1; - des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); + des_encrypt(tin,schedule,DES_DECRYPT); tout0=tin[0]^xor0^inW0; tout1=tin[1]^xor1^inW1; l2cn(tout0,tout1,out,l+8); @@ -195,7 +183,7 @@ int enc; xor1=tin1; } - iv=(unsigned char *)ivec; + iv = &(*ivec)[0]; l2c(xor0,iv); l2c(xor1,iv); } diff --git a/src/lib/libcrypto/dh/Makefile.ssl b/src/lib/libcrypto/dh/Makefile.ssl index dfa7e4525d..37e388d1b4 100644 --- a/src/lib/libcrypto/dh/Makefile.ssl +++ b/src/lib/libcrypto/dh/Makefile.ssl @@ -7,23 +7,23 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=dh -ERRC=dh_err GENERAL=Makefile TEST= dhtest.c APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c $(ERRC).c -LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o $(ERRC).o +LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c +LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o SRC= $(LIBSRC) @@ -39,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -68,17 +67,42 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +dh_check.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h +dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +dh_check.o: ../../include/openssl/opensslconf.h +dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +dh_check.o: ../cryptlib.h +dh_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h +dh_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h +dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +dh_gen.o: ../../include/openssl/stack.h ../cryptlib.h +dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h +dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +dh_key.o: ../../include/openssl/rand.h ../../include/openssl/stack.h +dh_key.o: ../cryptlib.h +dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h +dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +dh_lib.o: ../../include/openssl/stack.h ../cryptlib.h diff --git a/src/lib/libcrypto/dh/dh.err b/src/lib/libcrypto/dh/dh.err deleted file mode 100644 index a4fe746985..0000000000 --- a/src/lib/libcrypto/dh/dh.err +++ /dev/null @@ -1,12 +0,0 @@ -/* Error codes for the DH functions. */ - -/* Function codes. */ -#define DH_F_DHPARAMS_PRINT 100 -#define DH_F_DHPARAMS_PRINT_FP 101 -#define DH_F_DH_COMPUTE_KEY 102 -#define DH_F_DH_GENERATE_KEY 103 -#define DH_F_DH_GENERATE_PARAMETERS 104 -#define DH_F_DH_NEW 105 - -/* Reason codes. */ -#define DH_R_NO_PRIVATE_VALUE 100 diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h index 4cc1df2650..2cc3797a94 100644 --- a/src/lib/libcrypto/dh/dh.h +++ b/src/lib/libcrypto/dh/dh.h @@ -63,10 +63,14 @@ extern "C" { #endif -#ifndef HEADER_BN_H -#define BIGNUM char +#ifdef NO_DH +#error DH is disabled. #endif +#include + +#define DH_FLAG_CACHE_MONT_P 0x01 + typedef struct dh_st { /* This first argument is used to pick up errors when @@ -78,6 +82,9 @@ typedef struct dh_st int length; /* optional */ BIGNUM *pub_key; /* y */ BIGNUM *priv_key; /* x */ + + int flags; + char *method_mont_p; } DH; #define DH_GENERATOR_2 2 @@ -98,15 +105,19 @@ typedef struct dh_st (unsigned char *)(x)) #define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \ (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x)) +#ifdef __cplusplus +#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \ + (unsigned char *)(x)) +#else #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \ (unsigned char *)(x)) +#endif -#ifndef NOPROTO DH * DH_new(void); void DH_free(DH *dh); int DH_size(DH *dh); DH * DH_generate_parameters(int prime_len,int generator, - void (*callback)(int,int,char *),char *cb_arg); + void (*callback)(int,int,void *),void *cb_arg); int DH_check(DH *dh,int *codes); int DH_generate_key(DH *dh); int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh); @@ -122,26 +133,11 @@ int DHparams_print(char *bp, DH *x); #endif void ERR_load_DH_strings(void ); -#else - -DH * DH_new(); -void DH_free(); -int DH_size(); -DH * DH_generate_parameters(); -int DH_check(); -int DH_generate_key(); -int DH_compute_key(); -DH * d2i_DHparams(); -int i2d_DHparams(); -#ifndef NO_FP_API -int DHparams_print_fp(); -#endif -int DHparams_print(); -void ERR_load_DH_strings(); - -#endif - /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the DH functions. */ /* Function codes. */ @@ -154,7 +150,7 @@ void ERR_load_DH_strings(); /* Reason codes. */ #define DH_R_NO_PRIVATE_VALUE 100 - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c index 65602e494f..95ce9cfad0 100644 --- a/src/lib/libcrypto/dh/dh_check.c +++ b/src/lib/libcrypto/dh/dh_check.c @@ -58,8 +58,8 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "dh.h" +#include +#include /* Check that p is a strong prime and * if g is 2, 3 or 5, check that is is a suitable generator @@ -70,9 +70,7 @@ * should hold. */ -int DH_check(dh,ret) -DH *dh; -int *ret; +int DH_check(DH *dh, int *ret) { int ok=0; BN_CTX *ctx=NULL; diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c index 9d5c06ac24..0348bd24a2 100644 --- a/src/lib/libcrypto/dh/dh_err.c +++ b/src/lib/libcrypto/dh/dh_err.c @@ -1,63 +1,65 @@ -/* lib/dh/dh_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/dh/dh_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "dh.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -69,23 +71,23 @@ static ERR_STRING_DATA DH_str_functs[]= {ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"}, {ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"}, {ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"}, -{0,NULL}, +{0,NULL} }; static ERR_STRING_DATA DH_str_reasons[]= { {DH_R_NO_PRIVATE_VALUE ,"no private value"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_DH_strings() +void ERR_load_DH_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_DH,DH_str_functs); diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c index 04c7046a7b..b7bcd2c7a4 100644 --- a/src/lib/libcrypto/dh/dh_gen.c +++ b/src/lib/libcrypto/dh/dh_gen.c @@ -58,8 +58,8 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "dh.h" +#include +#include /* We generate DH parameters as follows * find a prime q which is prime_len/2 bits long. @@ -83,11 +83,8 @@ * this generator function can take a very very long time to run. */ -DH *DH_generate_parameters(prime_len,generator,callback,cb_arg) -int prime_len; -int generator; -void (*callback)(P_I_I_P); -char *cb_arg; +DH *DH_generate_parameters(int prime_len, int generator, + void (*callback)(int,int,void *), void *cb_arg) { BIGNUM *p=NULL,*t1,*t2; DH *ret=NULL; @@ -95,10 +92,11 @@ char *cb_arg; BN_CTX *ctx=NULL; ret=DH_new(); + if (ret == NULL) goto err; ctx=BN_CTX_new(); if (ctx == NULL) goto err; - t1=ctx->bn[0]; - t2=ctx->bn[1]; + t1= &(ctx->bn[0]); + t2= &(ctx->bn[1]); ctx->tos=2; if (generator == DH_GENERATOR_2) @@ -126,7 +124,7 @@ char *cb_arg; else g=generator; - p=BN_generate_prime(prime_len,1,t1,t2,callback,cb_arg); + p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg); if (p == NULL) goto err; if (callback != NULL) callback(3,0,cb_arg); ret->p=p; diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c index 7576772bcd..cede53bfc1 100644 --- a/src/lib/libcrypto/dh/dh_key.c +++ b/src/lib/libcrypto/dh/dh_key.c @@ -58,20 +58,19 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "rand.h" -#include "dh.h" +#include +#include +#include -int DH_generate_key(dh) -DH *dh; +int DH_generate_key(DH *dh) { int ok=0; unsigned int i; - BN_CTX *ctx=NULL; + BN_CTX ctx; + BN_MONT_CTX *mont; BIGNUM *pub_key=NULL,*priv_key=NULL; - ctx=BN_CTX_new(); - if (ctx == NULL) goto err; + BN_CTX_init(&ctx); if (dh->priv_key == NULL) { @@ -96,7 +95,15 @@ DH *dh; else pub_key=dh->pub_key; - if (!BN_mod_exp(pub_key,dh->g,priv_key,dh->p,ctx)) goto err; + if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P)) + { + if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) + if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p, + dh->p,&ctx)) goto err; + } + mont=(BN_MONT_CTX *)dh->method_mont_p; + + if (!BN_mod_exp_mont(pub_key,dh->g,priv_key,dh->p,&ctx,mont)) goto err; dh->pub_key=pub_key; dh->priv_key=priv_key; @@ -107,29 +114,34 @@ err: if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key); if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key); - if (ctx != NULL) BN_CTX_free(ctx); + BN_CTX_free(&ctx); return(ok); } -int DH_compute_key(key,pub_key,dh) -unsigned char *key; -BIGNUM *pub_key; -DH *dh; +int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh) { - BN_CTX *ctx; + BN_CTX ctx; + BN_MONT_CTX *mont; BIGNUM *tmp; int ret= -1; - ctx=BN_CTX_new(); - if (ctx == NULL) goto err; - tmp=ctx->bn[ctx->tos++]; + BN_CTX_init(&ctx); + tmp= &(ctx.bn[ctx.tos++]); if (dh->priv_key == NULL) { DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE); goto err; } - if (!BN_mod_exp(tmp,pub_key,dh->priv_key,dh->p,ctx)) + if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P)) + { + if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) + if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p, + dh->p,&ctx)) goto err; + } + + mont=(BN_MONT_CTX *)dh->method_mont_p; + if (!BN_mod_exp_mont(tmp,pub_key,dh->priv_key,dh->p,&ctx,mont)) { DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB); goto err; @@ -137,6 +149,6 @@ DH *dh; ret=BN_bn2bin(tmp,key); err: - if (ctx != NULL) BN_CTX_free(ctx); + BN_CTX_free(&ctx); return(ret); } diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c index a300b38396..61e0720e8a 100644 --- a/src/lib/libcrypto/dh/dh_lib.c +++ b/src/lib/libcrypto/dh/dh_lib.c @@ -58,12 +58,12 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "dh.h" +#include +#include -char *DH_version="Diffie-Hellman part of SSLeay 0.9.0b 29-Jun-1998"; +const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT; -DH *DH_new() +DH *DH_new(void) { DH *ret; @@ -80,21 +80,24 @@ DH *DH_new() ret->length=0; ret->pub_key=NULL; ret->priv_key=NULL; + ret->flags=DH_FLAG_CACHE_MONT_P; + ret->method_mont_p=NULL; return(ret); } -void DH_free(r) -DH *r; +void DH_free(DH *r) { + if(r == NULL) return; if (r->p != NULL) BN_clear_free(r->p); if (r->g != NULL) BN_clear_free(r->g); if (r->pub_key != NULL) BN_clear_free(r->pub_key); if (r->priv_key != NULL) BN_clear_free(r->priv_key); + if (r->method_mont_p != NULL) + BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p); Free(r); } -int DH_size(dh) -DH *dh; +int DH_size(DH *dh) { return(BN_num_bytes(dh->p)); } diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c index 488f10fd41..770331971f 100644 --- a/src/lib/libcrypto/dh/dhtest.c +++ b/src/lib/libcrypto/dh/dhtest.c @@ -62,10 +62,18 @@ #ifdef WINDOWS #include "../bio/bss_file.c" #endif -#include "crypto.h" -#include "bio.h" -#include "bn.h" -#include "dh.h" +#include +#include +#include + +#ifdef NO_DH +int main(int argc, char *argv[]) +{ + printf("No DH support\n"); + return(0); +} +#else +#include #ifdef WIN16 #define MS_CALLBACK _far _loadds @@ -73,12 +81,7 @@ #define MS_CALLBACK #endif -#ifndef NOPROTO -static void MS_CALLBACK cb(int p, int n, char *arg); -#else -static void MS_CALLBACK cb(); -#endif - +static void MS_CALLBACK cb(int p, int n, void *arg); #ifdef NO_STDIO #define APPS_WIN16 #include "bss_file.c" @@ -86,9 +89,7 @@ static void MS_CALLBACK cb(); BIO *out=NULL; -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { DH *a,*b; char buf[12]; @@ -103,7 +104,7 @@ char *argv[]; if (out == NULL) exit(1); BIO_set_fp(out,stdout,BIO_NOCLOSE); - a=DH_generate_parameters(64,DH_GENERATOR_5,cb,(char *)out); + a=DH_generate_parameters(64,DH_GENERATOR_5,cb,out); if (a == NULL) goto err; BIO_puts(out,"\np ="); @@ -170,10 +171,7 @@ err: return(ret); } -static void MS_CALLBACK cb(p, n,arg) -int p; -int n; -char *arg; +static void MS_CALLBACK cb(int p, int n, void *arg) { char c='*'; @@ -182,7 +180,9 @@ char *arg; if (p == 2) c='*'; if (p == 3) c='\n'; BIO_write((BIO *)arg,&c,1); + (void)BIO_flush((BIO *)arg); #ifdef LINT p=n; #endif } +#endif diff --git a/src/lib/libcrypto/dh/p1024.c b/src/lib/libcrypto/dh/p1024.c index 0c50c24cfb..368ceca4eb 100644 --- a/src/lib/libcrypto/dh/p1024.c +++ b/src/lib/libcrypto/dh/p1024.c @@ -57,10 +57,10 @@ */ #include -#include "bn.h" -#include "asn1.h" -#include "dh.h" -#include "pem.h" +#include +#include +#include +#include unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD, 0x28,0x28,0xE1,0x3F,0x1D,0x68,0xB6,0xD3, diff --git a/src/lib/libcrypto/dh/p192.c b/src/lib/libcrypto/dh/p192.c index 881908169a..7bdf40410e 100644 --- a/src/lib/libcrypto/dh/p192.c +++ b/src/lib/libcrypto/dh/p192.c @@ -57,10 +57,10 @@ */ #include -#include "bn.h" -#include "asn1.h" -#include "dh.h" -#include "pem.h" +#include +#include +#include +#include unsigned char data[]={ 0xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E, diff --git a/src/lib/libcrypto/dh/p512.c b/src/lib/libcrypto/dh/p512.c index cc84e8e50e..a9b6aa83f0 100644 --- a/src/lib/libcrypto/dh/p512.c +++ b/src/lib/libcrypto/dh/p512.c @@ -57,10 +57,10 @@ */ #include -#include "bn.h" -#include "asn1.h" -#include "dh.h" -#include "pem.h" +#include +#include +#include +#include unsigned char data[]={ 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89, diff --git a/src/lib/libcrypto/dsa/Makefile.ssl b/src/lib/libcrypto/dsa/Makefile.ssl index 2cc4ddb39e..6d80ce77be 100644 --- a/src/lib/libcrypto/dsa/Makefile.ssl +++ b/src/lib/libcrypto/dsa/Makefile.ssl @@ -7,23 +7,23 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=dsa -ERRC=dsa_err GENERAL=Makefile TEST=dsatest.c APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c dsa_sign.c $(ERRC).c -LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_vrf.o dsa_sign.o $(ERRC).o +LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c dsa_err.c +LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o dsa_err.o SRC= $(LIBSRC) @@ -39,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -68,17 +67,67 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +dsa_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +dsa_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +dsa_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +dsa_asn1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +dsa_asn1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h +dsa_asn1.o: ../../include/openssl/stack.h ../cryptlib.h +dsa_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h +dsa_err.o: ../../include/openssl/dsa.h ../../include/openssl/err.h +dsa_err.o: ../../include/openssl/opensslconf.h +dsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +dsa_gen.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +dsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +dsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +dsa_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +dsa_gen.o: ../cryptlib.h +dsa_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +dsa_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +dsa_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +dsa_key.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +dsa_key.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +dsa_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +dsa_key.o: ../cryptlib.h +dsa_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +dsa_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +dsa_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h +dsa_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +dsa_lib.o: ../cryptlib.h +dsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +dsa_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +dsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h +dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +dsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +dsa_sign.o: ../../include/openssl/opensslconf.h +dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +dsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +dsa_sign.o: ../cryptlib.h +dsa_vrf.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +dsa_vrf.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +dsa_vrf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +dsa_vrf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +dsa_vrf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +dsa_vrf.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +dsa_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +dsa_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +dsa_vrf.o: ../cryptlib.h diff --git a/src/lib/libcrypto/dsa/dsa.err b/src/lib/libcrypto/dsa/dsa.err deleted file mode 100644 index 1131e9fa74..0000000000 --- a/src/lib/libcrypto/dsa/dsa.err +++ /dev/null @@ -1,15 +0,0 @@ -/* Error codes for the DSA functions. */ - -/* Function codes. */ -#define DSA_F_DSAPARAMS_PRINT 100 -#define DSA_F_DSAPARAMS_PRINT_FP 101 -#define DSA_F_DSA_IS_PRIME 102 -#define DSA_F_DSA_NEW 103 -#define DSA_F_DSA_PRINT 104 -#define DSA_F_DSA_PRINT_FP 105 -#define DSA_F_DSA_SIGN 106 -#define DSA_F_DSA_SIGN_SETUP 107 -#define DSA_F_DSA_VERIFY 108 - -/* Reason codes. */ -#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h index 1ca87c1cbe..20b3f8d90a 100644 --- a/src/lib/libcrypto/dsa/dsa.h +++ b/src/lib/libcrypto/dsa/dsa.h @@ -69,7 +69,16 @@ extern "C" { #endif -#include "bn.h" +#ifdef NO_DSA +#error DSA is disabled. +#endif + +#include +#ifndef NO_DH +# include +#endif + +#define DSA_FLAG_CACHE_MONT_P 0x01 typedef struct dsa_st { @@ -88,9 +97,19 @@ typedef struct dsa_st BIGNUM *kinv; /* Signing pre-calc */ BIGNUM *r; /* Signing pre-calc */ + int flags; + /* Normally used to cache montgomery values */ + char *method_mont_p; + int references; } DSA; +typedef struct DSA_SIG_st + { + BIGNUM *r; + BIGNUM *s; + } DSA_SIG; + #define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \ (char *(*)())d2i_DSAparams,(char *)(x)) #define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ @@ -102,15 +121,23 @@ typedef struct dsa_st #define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \ (unsigned char *)(x)) -#ifndef NOPROTO + +DSA_SIG * DSA_SIG_new(void); +void DSA_SIG_free(DSA_SIG *a); +int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp); +DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length); + +DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa); +int DSA_do_verify(const unsigned char *dgst,int dgst_len, + DSA_SIG *sig,DSA *dsa); DSA * DSA_new(void); int DSA_size(DSA *); /* next 4 return -1 on error */ int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); -int DSA_sign(int type,unsigned char *dgst,int dlen, +int DSA_sign(int type,const unsigned char *dgst,int dlen, unsigned char *sig, unsigned int *siglen, DSA *dsa); -int DSA_verify(int type,unsigned char *dgst,int dgst_len, +int DSA_verify(int type,const unsigned char *dgst,int dgst_len, unsigned char *sigbuf, int siglen, DSA *dsa); void DSA_free (DSA *r); @@ -138,55 +165,38 @@ int DSA_print_fp(FILE *bp, DSA *x, int off); int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg); -#else - -DSA * DSA_new(); -int DSA_size(); -int DSA_sign_setup(); -int DSA_sign(); -int DSA_verify(); -void DSA_free (); - -void ERR_load_DSA_strings(); - -DSA * d2i_DSAPublicKey(); -DSA * d2i_DSAPrivateKey(); -DSA * d2i_DSAparams(); -DSA * DSA_generate_parameters(); -int DSA_generate_key(); -int i2d_DSAPublicKey(); -int i2d_DSAPrivateKey(); -int i2d_DSAparams(); - -int DSA_is_prime(); - -int DSAparams_print(); -int DSA_print(); - -#ifndef NO_FP_API -int DSAparams_print_fp(); -int DSA_print_fp(); -#endif - +#ifndef NO_DH +/* Convert DSA structure (key or just parameters) into DH structure + * (be careful to avoid small subgroup attacks when using this!) */ +DH *DSA_dup_DH(DSA *r); #endif /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the DSA functions. */ /* Function codes. */ +#define DSA_F_D2I_DSA_SIG 110 #define DSA_F_DSAPARAMS_PRINT 100 #define DSA_F_DSAPARAMS_PRINT_FP 101 +#define DSA_F_DSA_DO_SIGN 112 +#define DSA_F_DSA_DO_VERIFY 113 #define DSA_F_DSA_IS_PRIME 102 #define DSA_F_DSA_NEW 103 #define DSA_F_DSA_PRINT 104 #define DSA_F_DSA_PRINT_FP 105 #define DSA_F_DSA_SIGN 106 #define DSA_F_DSA_SIGN_SETUP 107 +#define DSA_F_DSA_SIG_NEW 109 #define DSA_F_DSA_VERIFY 108 +#define DSA_F_I2D_DSA_SIG 111 /* Reason codes. */ #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c new file mode 100644 index 0000000000..7523b21654 --- /dev/null +++ b/src/lib/libcrypto/dsa/dsa_asn1.c @@ -0,0 +1,96 @@ +/* crypto/dsa/dsa_asn1.c */ + +#include +#include "cryptlib.h" +#include +#include +#include + +DSA_SIG *DSA_SIG_new(void) +{ + DSA_SIG *ret; + + ret = Malloc(sizeof(DSA_SIG)); + if (ret == NULL) + { + DSAerr(DSA_F_DSA_SIG_NEW,ERR_R_MALLOC_FAILURE); + return(NULL); + } + ret->r = NULL; + ret->s = NULL; + return(ret); +} + +void DSA_SIG_free(DSA_SIG *r) +{ + if (r == NULL) return; + if (r->r) BN_clear_free(r->r); + if (r->s) BN_clear_free(r->s); + Free(r); +} + +int i2d_DSA_SIG(DSA_SIG *v, unsigned char **pp) +{ + int t=0,len; + ASN1_INTEGER rbs,sbs; + unsigned char *p; + + rbs.data=Malloc(BN_num_bits(v->r)/8+1); + if (rbs.data == NULL) + { + DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE); + return(0); + } + rbs.type=V_ASN1_INTEGER; + rbs.length=BN_bn2bin(v->r,rbs.data); + sbs.data=Malloc(BN_num_bits(v->s)/8+1); + if (sbs.data == NULL) + { + Free(rbs.data); + DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE); + return(0); + } + sbs.type=V_ASN1_INTEGER; + sbs.length=BN_bn2bin(v->s,sbs.data); + + len=i2d_ASN1_INTEGER(&rbs,NULL); + len+=i2d_ASN1_INTEGER(&sbs,NULL); + + if (pp) + { + p=*pp; + ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + i2d_ASN1_INTEGER(&rbs,&p); + i2d_ASN1_INTEGER(&sbs,&p); + } + t=ASN1_object_size(1,len,V_ASN1_SEQUENCE); + Free(rbs.data); + Free(sbs.data); + return(t); +} + +DSA_SIG *d2i_DSA_SIG(DSA_SIG **a, unsigned char **pp, long length) +{ + int i=ERR_R_NESTED_ASN1_ERROR; + ASN1_INTEGER *bs=NULL; + M_ASN1_D2I_vars(a,DSA_SIG *,DSA_SIG_new); + + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->r=BN_bin2bn(bs->data,bs->length,ret->r)) == NULL) + goto err_bn; + M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); + if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL) + goto err_bn; + ASN1_BIT_STRING_free(bs); + M_ASN1_D2I_Finish_2(a); + +err_bn: + i=ERR_R_BN_LIB; +err: + DSAerr(DSA_F_D2I_DSA_SIG,i); + if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret); + if (bs != NULL) ASN1_BIT_STRING_free(bs); + return(NULL); +} diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c index 318e9f31aa..33a8270afd 100644 --- a/src/lib/libcrypto/dsa/dsa_err.c +++ b/src/lib/libcrypto/dsa/dsa_err.c @@ -1,94 +1,101 @@ -/* lib/dsa/dsa_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/dsa/dsa_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "dsa.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR static ERR_STRING_DATA DSA_str_functs[]= { +{ERR_PACK(0,DSA_F_D2I_DSA_SIG,0), "d2i_DSA_SIG"}, {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"}, {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"}, +{ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"}, +{ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"}, {ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"}, {ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"}, {ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"}, {ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"}, {ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"}, {ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"}, +{ERR_PACK(0,DSA_F_DSA_SIG_NEW,0), "DSA_SIG_new"}, {ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"}, -{0,NULL}, +{ERR_PACK(0,DSA_F_I2D_DSA_SIG,0), "i2d_DSA_SIG"}, +{0,NULL} }; static ERR_STRING_DATA DSA_str_reasons[]= { {DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_DSA_strings() +void ERR_load_DSA_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_DSA,DSA_str_functs); diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c index d7d30bf90a..b5e5ec06e5 100644 --- a/src/lib/libcrypto/dsa/dsa_gen.c +++ b/src/lib/libcrypto/dsa/dsa_gen.c @@ -64,23 +64,18 @@ #define HASH SHA1 #endif +#ifndef NO_SHA #include #include #include "cryptlib.h" -#include "sha.h" -#include "bn.h" -#include "dsa.h" -#include "rand.h" - -DSA *DSA_generate_parameters(bits,seed_in,seed_len,counter_ret,h_ret,callback, - cb_arg) -int bits; -unsigned char *seed_in; -int seed_len; -int *counter_ret; -unsigned long *h_ret; -void (*callback)(); -char *cb_arg; +#include +#include +#include +#include + +DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, + int *counter_ret, unsigned long *h_ret, void (*callback)(), + char *cb_arg) { int ok=0; unsigned char seed[SHA_DIGEST_LENGTH]; @@ -88,6 +83,7 @@ char *cb_arg; unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH]; BIGNUM *r0,*W,*X,*c,*test; BIGNUM *g=NULL,*q=NULL,*p=NULL; + BN_MONT_CTX *mont=NULL; int k,n=0,i,b,m=0; int counter=0; BN_CTX *ctx=NULL,*ctx2=NULL; @@ -100,20 +96,20 @@ char *cb_arg; if ((seed_in != NULL) && (seed_len == 20)) memcpy(seed,seed_in,seed_len); - ctx=BN_CTX_new(); - if (ctx == NULL) goto err; - ctx2=BN_CTX_new(); - if (ctx2 == NULL) goto err; - ret=DSA_new(); - if (ret == NULL) goto err; - r0=ctx2->bn[0]; - g=ctx2->bn[1]; - W=ctx2->bn[2]; - q=ctx2->bn[3]; - X=ctx2->bn[4]; - c=ctx2->bn[5]; - p=ctx2->bn[6]; - test=ctx2->bn[7]; + if ((ctx=BN_CTX_new()) == NULL) goto err; + if ((ctx2=BN_CTX_new()) == NULL) goto err; + if ((ret=DSA_new()) == NULL) goto err; + + if ((mont=BN_MONT_CTX_new()) == NULL) goto err; + + r0= &(ctx2->bn[0]); + g= &(ctx2->bn[1]); + W= &(ctx2->bn[2]); + q= &(ctx2->bn[3]); + X= &(ctx2->bn[4]); + c= &(ctx2->bn[5]); + p= &(ctx2->bn[6]); + test= &(ctx2->bn[7]); BN_lshift(test,BN_value_one(),bits-1); @@ -216,14 +212,16 @@ end: /* We now need to gernerate g */ /* Set r0=(p-1)/q */ - BN_sub(test,p,BN_value_one()); - BN_div(r0,NULL,test,q,ctx); + BN_sub(test,p,BN_value_one()); + BN_div(r0,NULL,test,q,ctx); BN_set_word(test,h); + BN_MONT_CTX_set(mont,p,ctx); + for (;;) { /* g=test^r0%p */ - BN_mod_exp(g,test,r0,p,ctx); + BN_mod_exp_mont(g,test,r0,p,ctx,mont); if (!BN_is_one(g)) break; BN_add(test,test,BN_value_one()); h++; @@ -246,32 +244,32 @@ err: if (counter_ret != NULL) *counter_ret=counter; if (h_ret != NULL) *h_ret=h; } - BN_CTX_free(ctx); - BN_CTX_free(ctx2); + if (ctx != NULL) BN_CTX_free(ctx); + if (ctx != NULL) BN_CTX_free(ctx2); + if (mont != NULL) BN_MONT_CTX_free(mont); return(ok?ret:NULL); } -int DSA_is_prime(w, callback,cb_arg) -BIGNUM *w; -void (*callback)(); -char *cb_arg; +int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg) { int ok= -1,j,i,n; BN_CTX *ctx=NULL,*ctx2=NULL; - BIGNUM *w_1,*b,*m,*z; + BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1; int a; + BN_MONT_CTX *mont=NULL; if (!BN_is_bit_set(w,0)) return(0); - ctx=BN_CTX_new(); - if (ctx == NULL) goto err; - ctx2=BN_CTX_new(); - if (ctx2 == NULL) goto err; + if ((ctx=BN_CTX_new()) == NULL) goto err; + if ((ctx2=BN_CTX_new()) == NULL) goto err; + if ((mont=BN_MONT_CTX_new()) == NULL) goto err; - m= ctx2->bn[2]; - b= ctx2->bn[3]; - z= ctx2->bn[4]; - w_1=ctx2->bn[5]; + m= &(ctx2->bn[2]); + b= &(ctx2->bn[3]); + z= &(ctx2->bn[4]); + w_1= &(ctx2->bn[5]); + tmp= &(ctx2->bn[6]); + mont_1= &(ctx2->bn[7]); /* step 1 */ n=50; @@ -282,24 +280,30 @@ char *cb_arg; ; if (!BN_rshift(m,w_1,a)) goto err; + BN_MONT_CTX_set(mont,w,ctx); + BN_to_montgomery(mont_1,BN_value_one(),mont,ctx); + BN_to_montgomery(w_1,w_1,mont,ctx); for (i=1; i < n; i++) { /* step 3 */ BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0); - BN_set_word(b,0x10001L); + /* BN_set_word(b,0x10001L); */ /* step 4 */ j=0; - if (!BN_mod_exp(z,b,m,w,ctx)) goto err; + if (!BN_mod_exp_mont(z,b,m,w,ctx,mont)) goto err; + + if (!BN_to_montgomery(z,z,mont,ctx)) goto err; /* step 5 */ for (;;) { - if (((j == 0) && BN_is_one(z)) || (BN_cmp(z,w_1) == 0)) + if (((j == 0) && (BN_cmp(z,mont_1) == 0)) || + (BN_cmp(z,w_1) == 0)) break; /* step 6 */ - if ((j > 0) && BN_is_one(z)) + if ((j > 0) && (BN_cmp(z,mont_1) == 0)) { ok=0; goto err; @@ -312,7 +316,7 @@ char *cb_arg; goto err; } - if (!BN_mod_mul(z,z,z,w,ctx)) goto err; + if (!BN_mod_mul_montgomery(z,z,z,mont,ctx)) goto err; if (callback != NULL) callback(1,j,cb_arg); } } @@ -322,7 +326,8 @@ err: if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB); BN_CTX_free(ctx); BN_CTX_free(ctx2); + BN_MONT_CTX_free(mont); return(ok); } - +#endif diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c index d51ed9395f..ab7f38fc7c 100644 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ b/src/lib/libcrypto/dsa/dsa_key.c @@ -56,16 +56,16 @@ * [including the GNU Public Licence.] */ +#ifndef NO_SHA #include #include #include "cryptlib.h" -#include "sha.h" -#include "bn.h" -#include "dsa.h" -#include "rand.h" +#include +#include +#include +#include -int DSA_generate_key(dsa) -DSA *dsa; +int DSA_generate_key(DSA *dsa) { int ok=0; unsigned int i; @@ -109,4 +109,4 @@ err: if (ctx != NULL) BN_CTX_free(ctx); return(ok); } - +#endif diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c index b647257f9f..ce8e204f7e 100644 --- a/src/lib/libcrypto/dsa/dsa_lib.c +++ b/src/lib/libcrypto/dsa/dsa_lib.c @@ -56,17 +56,17 @@ * [including the GNU Public Licence.] */ -/* Origional version from Steven Schoch */ +/* Original version from Steven Schoch */ #include #include "cryptlib.h" -#include "bn.h" -#include "dsa.h" -#include "asn1.h" +#include +#include +#include -char *DSA_version="\0DSA part of SSLeay 0.9.0b 29-Jun-1998"; +const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; -DSA *DSA_new() +DSA *DSA_new(void) { DSA *ret; @@ -82,19 +82,20 @@ DSA *DSA_new() ret->p=NULL; ret->q=NULL; ret->g=NULL; + ret->flags=DSA_FLAG_CACHE_MONT_P; ret->pub_key=NULL; ret->priv_key=NULL; ret->kinv=NULL; ret->r=NULL; + ret->method_mont_p=NULL; ret->references=1; return(ret); } -void DSA_free(r) -DSA *r; +void DSA_free(DSA *r) { int i; @@ -120,11 +121,12 @@ DSA *r; if (r->priv_key != NULL) BN_clear_free(r->priv_key); if (r->kinv != NULL) BN_clear_free(r->kinv); if (r->r != NULL) BN_clear_free(r->r); + if (r->method_mont_p != NULL) + BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p); Free(r); } -int DSA_size(r) -DSA *r; +int DSA_size(DSA *r) { int ret,i; ASN1_INTEGER bs; @@ -143,3 +145,40 @@ DSA *r; return(ret); } +#ifndef NO_DH +DH *DSA_dup_DH(DSA *r) + { + /* DSA has p, q, g, optional pub_key, optional priv_key. + * DH has p, optional length, g, optional pub_key, optional priv_key. + */ + + DH *ret = NULL; + + if (r == NULL) + goto err; + ret = DH_new(); + if (ret == NULL) + goto err; + if (r->p != NULL) + if ((ret->p = BN_dup(r->p)) == NULL) + goto err; + if (r->q != NULL) + ret->length = BN_num_bits(r->q); + if (r->g != NULL) + if ((ret->g = BN_dup(r->g)) == NULL) + goto err; + if (r->pub_key != NULL) + if ((ret->pub_key = BN_dup(r->pub_key)) == NULL) + goto err; + if (r->priv_key != NULL) + if ((ret->priv_key = BN_dup(r->priv_key)) == NULL) + goto err; + + return ret; + + err: + if (ret != NULL) + DH_free(ret); + return NULL; + } +#endif diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c index 6ca1c318f2..774c161964 100644 --- a/src/lib/libcrypto/dsa/dsa_sign.c +++ b/src/lib/libcrypto/dsa/dsa_sign.c @@ -56,35 +56,28 @@ * [including the GNU Public Licence.] */ -/* Origional version from Steven Schoch */ +/* Original version from Steven Schoch */ #include #include "cryptlib.h" -#include "bn.h" -#include "dsa.h" -#include "rand.h" -#include "asn1.h" +#include +#include +#include +#include -/* data has already been hashed (probably with SHA or SHA-1). */ -/* DSAerr(DSA_F_DSA_SIGN,DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); */ - -int DSA_sign(type,dgst,dlen,sig,siglen,dsa) -int type; -unsigned char *dgst; -int dlen; -unsigned char *sig; /* out */ -unsigned int *siglen; /* out */ -DSA *dsa; +DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) { - BIGNUM *kinv=NULL,*r=NULL; - BIGNUM *m=NULL; - BIGNUM *xr=NULL,*s=NULL; + BIGNUM *kinv=NULL,*r=NULL,*s=NULL; + BIGNUM m; + BIGNUM xr; BN_CTX *ctx=NULL; - unsigned char *p; - int i,len=0,ret=0,reason=ERR_R_BN_LIB; - ASN1_INTEGER rbs,sbs; - MS_STATIC unsigned char rbuf[50]; /* assuming r is 20 bytes +extra */ - MS_STATIC unsigned char sbuf[50]; /* assuming s is 20 bytes +extra */ + int i,reason=ERR_R_BN_LIB; + DSA_SIG *ret=NULL; + + BN_init(&m); + BN_init(&xr); + s=BN_new(); + if (s == NULL) goto err; i=BN_num_bytes(dsa->q); /* should be 20 */ if ((dlen > i) || (dlen > 50)) @@ -108,59 +101,58 @@ DSA *dsa; dsa->r=NULL; } - m=BN_new(); - xr=BN_new(); - s=BN_new(); - if (m == NULL || xr == NULL || s == NULL) goto err; - - if (BN_bin2bn(dgst,dlen,m) == NULL) goto err; + if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err; /* Compute s = inv(k) (m + xr) mod q */ - if (!BN_mul(xr, dsa->priv_key, r)) goto err; /* s = xr */ - if (!BN_add(s, xr, m)) goto err; /* s = m + xr */ + if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */ + if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */ + if (BN_cmp(s,dsa->q) > 0) + BN_sub(s,s,dsa->q); if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err; - /* - * Now create a ASN.1 sequence of the integers R and S. - */ - rbs.data=rbuf; - sbs.data=sbuf; - rbs.type = V_ASN1_INTEGER; - sbs.type = V_ASN1_INTEGER; - rbs.length=BN_bn2bin(r,rbs.data); - sbs.length=BN_bn2bin(s,sbs.data); - - len =i2d_ASN1_INTEGER(&rbs,NULL); - len+=i2d_ASN1_INTEGER(&sbs,NULL); - - p=sig; - ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); - i2d_ASN1_INTEGER(&rbs,&p); - i2d_ASN1_INTEGER(&sbs,&p); - *siglen=(p-sig); - ret=1; + ret=DSA_SIG_new(); + if (ret == NULL) goto err; + ret->r = r; + ret->s = s; + err: - if (!ret) DSAerr(DSA_F_DSA_SIGN,reason); - -#if 1 /* do the right thing :-) */ - if (kinv != NULL) BN_clear_free(kinv); - if (r != NULL) BN_clear_free(r); -#endif + if (!ret) + { + DSAerr(DSA_F_DSA_DO_SIGN,reason); + BN_free(r); + BN_free(s); + } if (ctx != NULL) BN_CTX_free(ctx); - if (m != NULL) BN_clear_free(m); - if (xr != NULL) BN_clear_free(xr); - if (s != NULL) BN_clear_free(s); + BN_clear_free(&m); + BN_clear_free(&xr); + if (kinv != NULL) /* dsa->kinv is NULL now if we used it */ + BN_clear_free(kinv); return(ret); } -int DSA_sign_setup(dsa,ctx_in,kinvp,rp) -DSA *dsa; -BN_CTX *ctx_in; -BIGNUM **kinvp; -BIGNUM **rp; +/* data has already been hashed (probably with SHA or SHA-1). */ + +/* unsigned char *sig: out */ +/* unsigned int *siglen: out */ +int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, + unsigned int *siglen, DSA *dsa) + { + DSA_SIG *s; + s=DSA_do_sign(dgst,dlen,dsa); + if (s == NULL) + { + *siglen=0; + return(0); + } + *siglen=i2d_DSA_SIG(s,&sig); + DSA_SIG_free(s); + return(1); + } + +int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) { BN_CTX *ctx; - BIGNUM *k=NULL,*kinv=NULL,*r=NULL; + BIGNUM k,*kinv=NULL,*r=NULL; int ret=0; if (ctx_in == NULL) @@ -170,29 +162,33 @@ BIGNUM **rp; else ctx=ctx_in; - r=BN_new(); - k=BN_new(); - if ((r == NULL) || (k == NULL)) - goto err; + BN_init(&k); + if ((r=BN_new()) == NULL) goto err; kinv=NULL; - if (r == NULL) goto err; - /* Get random k */ for (;;) { - if (!BN_rand(k, BN_num_bits(dsa->q), 1, 0)) goto err; - if (BN_cmp(k,dsa->q) >= 0) - BN_sub(k,k,dsa->q); - if (!BN_is_zero(k)) break; + if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err; + if (BN_cmp(&k,dsa->q) >= 0) + BN_sub(&k,&k,dsa->q); + if (!BN_is_zero(&k)) break; + } + + if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) + { + if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) + if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p, + dsa->p,ctx)) goto err; } /* Compute r = (g^k mod p) mod q */ - if (!BN_mod_exp(r,dsa->g,k,dsa->p,ctx)) goto err; + if (!BN_mod_exp_mont(r,dsa->g,&k,dsa->p,ctx, + (BN_MONT_CTX *)dsa->method_mont_p)) goto err; if (!BN_mod(r,r,dsa->q,ctx)) goto err; /* Compute part of 's = inv(k) (m + xr) mod q' */ - if ((kinv=BN_mod_inverse(k,dsa->q,ctx)) == NULL) goto err; + if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err; if (*kinvp != NULL) BN_clear_free(*kinvp); *kinvp=kinv; @@ -208,8 +204,8 @@ err: if (r != NULL) BN_clear_free(r); } if (ctx_in == NULL) BN_CTX_free(ctx); - if (k != NULL) BN_clear_free(k); if (kinv != NULL) BN_clear_free(kinv); + BN_clear_free(&k); return(ret); } diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c index 0f860984ed..ff552208aa 100644 --- a/src/lib/libcrypto/dsa/dsa_vrf.c +++ b/src/lib/libcrypto/dsa/dsa_vrf.c @@ -56,97 +56,105 @@ * [including the GNU Public Licence.] */ -/* Origional version from Steven Schoch */ +/* Original version from Steven Schoch */ #include #include "cryptlib.h" -#include "bn.h" -#include "dsa.h" -#include "rand.h" -#include "asn1.h" -#include "asn1_mac.h" +#include +#include +#include +#include +#include -/* data has already been hashed (probably with SHA or SHA-1). */ -/* returns - * 1: correct signature - * 0: incorrect signature - * -1: error - */ -int DSA_verify(type,dgst,dgst_len,sigbuf,siglen, dsa) -int type; -unsigned char *dgst; -int dgst_len; -unsigned char *sigbuf; -int siglen; -DSA *dsa; +int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, + DSA *dsa) { - /* The next 3 are used by the M_ASN1 macros */ - long length=siglen; - ASN1_CTX c; - unsigned char **pp= &sigbuf; BN_CTX *ctx; - BIGNUM *r=NULL; - BIGNUM *t1=NULL,*t2=NULL; - BIGNUM *u1=NULL,*u2=NULL; - ASN1_INTEGER *bs=NULL; + BIGNUM u1,u2,t1; + BN_MONT_CTX *mont=NULL; int ret = -1; - ctx=BN_CTX_new(); - if (ctx == NULL) goto err; - - t1=BN_new(); - t2=BN_new(); - if (t1 == NULL || t2 == NULL) goto err; - - M_ASN1_D2I_Init(); - M_ASN1_D2I_start_sequence(); - M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); - if ((r=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn; - M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); - if ((u1=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn; - if (!asn1_Finish(&c)) goto err; + if ((ctx=BN_CTX_new()) == NULL) goto err; + BN_init(&u1); + BN_init(&u2); + BN_init(&t1); /* Calculate W = inv(S) mod Q * save W in u2 */ - if ((u2=BN_mod_inverse(u1,dsa->q,ctx)) == NULL) goto err_bn; + if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err; /* save M in u1 */ - if (BN_bin2bn(dgst,dgst_len,u1) == NULL) goto err_bn; + if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err; /* u1 = M * w mod q */ - if (!BN_mod_mul(u1,u1,u2,dsa->q,ctx)) goto err_bn; + if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err; /* u2 = r * w mod q */ - if (!BN_mod_mul(u2,r,u2,dsa->q,ctx)) goto err_bn; + if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err; + + if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) + { + if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) + if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p, + dsa->p,ctx)) goto err; + } + mont=(BN_MONT_CTX *)dsa->method_mont_p; + +#if 0 + { + BIGNUM t2; + BN_init(&t2); /* v = ( g^u1 * y^u2 mod p ) mod q */ /* let t1 = g ^ u1 mod p */ - if (!BN_mod_exp(t1,dsa->g,u1,dsa->p,ctx)) goto err_bn; + if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err; /* let t2 = y ^ u2 mod p */ - if (!BN_mod_exp(t2,dsa->pub_key,u2,dsa->p,ctx)) goto err_bn; + if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err; /* let u1 = t1 * t2 mod p */ - if (!BN_mod_mul(u1,t1,t2,dsa->p,ctx)) goto err_bn; + if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn; + BN_free(&t2); + } /* let u1 = u1 mod q */ - if (!BN_mod(u1,u1,dsa->q,ctx)) goto err_bn; + if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err; +#else + { + if (!BN_mod_exp2_mont(&t1,dsa->g,&u1,dsa->pub_key,&u2,dsa->p,ctx,mont)) + goto err; + /* BN_copy(&u1,&t1); */ + /* let u1 = u1 mod q */ + if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err; + } +#endif /* V is now in u1. If the signature is correct, it will be * equal to R. */ - ret=(BN_ucmp(u1, r) == 0); - if (0) - { -err: /* ASN1 error */ - DSAerr(DSA_F_DSA_VERIFY,c.error); - } - if (0) - { -err_bn: /* BN error */ - DSAerr(DSA_F_DSA_VERIFY,ERR_R_BN_LIB); - } + ret=(BN_ucmp(&u1, sig->r) == 0); + + err: + if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB); if (ctx != NULL) BN_CTX_free(ctx); - if (r != NULL) BN_free(r); - if (t1 != NULL) BN_free(t1); - if (t2 != NULL) BN_free(t2); - if (u1 != NULL) BN_free(u1); - if (u2 != NULL) BN_free(u2); - if (bs != NULL) ASN1_BIT_STRING_free(bs); + BN_free(&u1); + BN_free(&u2); + BN_free(&t1); + return(ret); + } + +/* data has already been hashed (probably with SHA or SHA-1). */ +/* returns + * 1: correct signature + * 0: incorrect signature + * -1: error + */ +int DSA_verify(int type, const unsigned char *dgst, int dgst_len, + unsigned char *sigbuf, int siglen, DSA *dsa) + { + DSA_SIG *s; + int ret=-1; + + s = DSA_SIG_new(); + if (s == NULL) return(ret); + if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err; + ret=DSA_do_verify(dgst,dgst_len,s,dsa); +err: + DSA_SIG_free(s); return(ret); } diff --git a/src/lib/libcrypto/dsa/dsagen.c b/src/lib/libcrypto/dsa/dsagen.c index 20335de250..a0b0976640 100644 --- a/src/lib/libcrypto/dsa/dsagen.c +++ b/src/lib/libcrypto/dsa/dsagen.c @@ -57,7 +57,7 @@ */ #include -#include "dsa.h" +#include #define TEST #define GENUINE_DSA @@ -77,8 +77,7 @@ unsigned char seed[20]={ 0xe0,0x42,0x7d,LAST_VALUE}; #endif -int cb(p,n) -int p,n; +int cb(int p, int n) { char c='*'; diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c index 39bb712c4a..fc25c9a1b7 100644 --- a/src/lib/libcrypto/dsa/dsatest.c +++ b/src/lib/libcrypto/dsa/dsatest.c @@ -61,27 +61,30 @@ #include #include #include -#include "crypto.h" -#include "rand.h" -#include "bio.h" -#include "err.h" -#include "dsa.h" +#include +#include +#include +#include #ifdef WINDOWS #include "../bio/bss_file.c" #endif +#ifdef NO_DSA +int main(int argc, char *argv[]) +{ + printf("No DSA support\n"); + return(0); +} +#else +#include + #ifdef WIN16 #define MS_CALLBACK _far _loadds #else #define MS_CALLBACK #endif -#ifndef NOPROTO static void MS_CALLBACK dsa_cb(int p, int n, char *arg); -#else -static void MS_CALLBACK dsa_cb(); -#endif - static unsigned char seed[20]={ 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, @@ -115,20 +118,24 @@ static unsigned char out_g[]={ 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, }; +static const unsigned char str1[]="12345678901234567890"; + static BIO *bio_err=NULL; -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { DSA *dsa=NULL; int counter,ret=0,i,j; unsigned char buf[256]; unsigned long h; + unsigned char sig[256]; + unsigned int siglen; if (bio_err == NULL) bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); + CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); + BIO_printf(bio_err,"test generation of DSA parameters\n"); BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n"); dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, @@ -178,21 +185,21 @@ char **argv; BIO_printf(bio_err,"g value is wrong\n"); goto end; } - - ret=1; + DSA_generate_key(dsa); + DSA_sign(0, str1, 20, sig, &siglen, dsa); + if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1) + ret=1; end: if (!ret) ERR_print_errors(bio_err); - if (bio_err != NULL) BIO_free(bio_err); if (dsa != NULL) DSA_free(dsa); + CRYPTO_mem_leaks(bio_err); + if (bio_err != NULL) BIO_free(bio_err); exit(!ret); return(0); } -static void MS_CALLBACK dsa_cb(p, n, arg) -int p; -int n; -char *arg; +static void MS_CALLBACK dsa_cb(int p, int n, char *arg) { char c='*'; static int ok=0,num=0; @@ -202,7 +209,7 @@ char *arg; if (p == 2) { c='*'; ok++; } if (p == 3) c='\n'; BIO_write((BIO *)arg,&c,1); - BIO_flush((BIO *)arg); + (void)BIO_flush((BIO *)arg); if (!ok && (p == 0) && (num > 1)) { @@ -210,5 +217,4 @@ char *arg; exit(1); } } - - +#endif diff --git a/src/lib/libcrypto/ebcdic.h b/src/lib/libcrypto/ebcdic.h new file mode 100644 index 0000000000..d3b4e98b12 --- /dev/null +++ b/src/lib/libcrypto/ebcdic.h @@ -0,0 +1,17 @@ +#ifndef HEADER_EBCDIC_H +#define HEADER_EBCDIC_H + +#include + +/* Avoid name clashes with other applications */ +#define os_toascii _eay2000_os_toascii +#define os_toebcdic _eay2000_os_toebcdic +#define ebcdic2ascii _eay2000_ebcdic2ascii +#define ascii2ebcdic _eay2000_ascii2ebcdic + +extern const unsigned char os_toascii[256]; +extern const unsigned char os_toebcdic[256]; +void ebcdic2ascii(unsigned char *dest, const unsigned char *srce, size_t count); +void ascii2ebcdic(unsigned char *dest, const unsigned char *srce, size_t count); + +#endif diff --git a/src/lib/libcrypto/err/Makefile.ssl b/src/lib/libcrypto/err/Makefile.ssl index 57c87eb041..e0f5128f43 100644 --- a/src/lib/libcrypto/err/Makefile.ssl +++ b/src/lib/libcrypto/err/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,44 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +err.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h +err.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +err.o: ../cryptlib.h +err_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +err_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +err_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +err_all.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +err_all.o: ../../include/openssl/des.h ../../include/openssl/dh.h +err_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h +err_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h +err_all.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +err_all.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +err_all.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +err_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +err_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h +err_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +err_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +err_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +err_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +err_all.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +err_all.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +err_prn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +err_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h +err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +err_prn.o: ../cryptlib.h diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index 5aef6a1259..8810d838c6 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c @@ -57,34 +57,25 @@ */ #include -#include "lhash.h" -#include "crypto.h" +#include +#include +#include #include "cryptlib.h" -#include "buffer.h" -#include "err.h" -#include "crypto.h" +#include +#include +#include static LHASH *error_hash=NULL; static LHASH *thread_hash=NULL; -#ifndef NOPROTO static unsigned long err_hash(ERR_STRING_DATA *a); static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); static unsigned long pid_hash(ERR_STATE *pid); static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); -static unsigned long get_error_values(int inc,char **file,int *line, - char **data,int *flags); +static unsigned long get_error_values(int inc,const char **file,int *line, + const char **data,int *flags); static void ERR_STATE_free(ERR_STATE *s); -#else -static unsigned long err_hash(); -static int err_cmp(); -static unsigned long pid_hash(); -static int pid_cmp(); -static void ERR_STATE_free(); -ERR_STATE *s; -#endif - #ifndef NO_ERR static ERR_STRING_DATA ERR_str_libraries[]= { @@ -107,6 +98,8 @@ static ERR_STRING_DATA ERR_str_libraries[]= {ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"}, {ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"}, {ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"}, +{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"}, +{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"}, {0,NULL}, }; @@ -123,6 +116,7 @@ static ERR_STRING_DATA ERR_str_functs[]= #ifdef WINDOWS {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"}, #endif + {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"}, {0,NULL}, }; @@ -146,8 +140,17 @@ static ERR_STRING_DATA ERR_str_reasons[]= {ERR_R_PROXY_LIB ,"PROXY lib"}, {ERR_R_BIO_LIB ,"BIO lib"}, {ERR_R_PKCS7_LIB ,"PKCS7 lib"}, +{ERR_R_PKCS12_LIB ,"PKCS12 lib"}, {ERR_R_MALLOC_FAILURE ,"Malloc failure"}, -{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a fuction you should not call"}, +{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"}, +{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"}, +{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"}, +{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"}, +{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"}, +{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"}, +{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"}, +{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"}, + {0,NULL}, }; #endif @@ -161,11 +164,13 @@ static ERR_STRING_DATA ERR_str_reasons[]= } \ (p)->err_data_flags[i]=0; -static void ERR_STATE_free(s) -ERR_STATE *s; +static void ERR_STATE_free(ERR_STATE *s) { int i; + if(s == NULL) + return; + for (i=0; itop=(es->top+1)%ERR_NUM_ERRORS; @@ -257,7 +277,7 @@ int line; err_clear_data(es,es->top); } -void ERR_clear_error() +void ERR_clear_error(void) { ERR_STATE *es; @@ -277,42 +297,32 @@ void ERR_clear_error() } -unsigned long ERR_get_error() +unsigned long ERR_get_error(void) { return(get_error_values(1,NULL,NULL,NULL,NULL)); } -unsigned long ERR_get_error_line(file,line) -char **file; -int *line; +unsigned long ERR_get_error_line(const char **file, + int *line) { return(get_error_values(1,file,line,NULL,NULL)); } -unsigned long ERR_get_error_line_data(file,line,data,flags) -char **file; -int *line; -char **data; -int *flags; - { return(get_error_values(1,file,line,data,flags)); } +unsigned long ERR_get_error_line_data(const char **file, int *line, + const char **data, int *flags) + { return(get_error_values(1,file,line, + data,flags)); } -unsigned long ERR_peek_error() +unsigned long ERR_peek_error(void) { return(get_error_values(0,NULL,NULL,NULL,NULL)); } -unsigned long ERR_peek_error_line(file,line) -char **file; -int *line; +unsigned long ERR_peek_error_line(const char **file, + int *line) { return(get_error_values(0,file,line,NULL,NULL)); } -unsigned long ERR_peek_error_line_data(file,line,data,flags) -char **file; -int *line; -char **data; -int *flags; - { return(get_error_values(0,file,line,data,flags)); } - -static unsigned long get_error_values(inc,file,line,data,flags) -int inc; -char **file; -int *line; -char **data; -int *flags; +unsigned long ERR_peek_error_line_data(const char **file, int *line, + const char **data, int *flags) + { return(get_error_values(0,file,line, + data,flags)); } + +static unsigned long get_error_values(int inc, const char **file, int *line, + const char **data, int *flags) { int i=0; ERR_STATE *es; @@ -361,12 +371,10 @@ int *flags; } /* BAD for multi-threaded, uses a local buffer if ret == NULL */ -char *ERR_error_string(e,ret) -unsigned long e; -char *ret; +char *ERR_error_string(unsigned long e, char *ret) { static char buf[256]; - char *ls,*fs,*rs; + const char *ls,*fs,*rs; unsigned long l,f,r; int i; @@ -397,18 +405,17 @@ char *ret; return(ret); } -LHASH *ERR_get_string_table() +LHASH *ERR_get_string_table(void) { return(error_hash); } -LHASH *ERR_get_err_state_table() +LHASH *ERR_get_err_state_table(void) { return(thread_hash); } -char *ERR_lib_error_string(e) -unsigned long e; +const char *ERR_lib_error_string(unsigned long e) { ERR_STRING_DATA d,*p=NULL; unsigned long l; @@ -428,8 +435,7 @@ unsigned long e; return((p == NULL)?NULL:p->string); } -char *ERR_func_error_string(e) -unsigned long e; +const char *ERR_func_error_string(unsigned long e) { ERR_STRING_DATA d,*p=NULL; unsigned long l,f; @@ -450,8 +456,7 @@ unsigned long e; return((p == NULL)?NULL:p->string); } -char *ERR_reason_error_string(e) -unsigned long e; +const char *ERR_reason_error_string(unsigned long e) { ERR_STRING_DATA d,*p=NULL; unsigned long l,r; @@ -478,8 +483,7 @@ unsigned long e; return((p == NULL)?NULL:p->string); } -static unsigned long err_hash(a) -ERR_STRING_DATA *a; +static unsigned long err_hash(ERR_STRING_DATA *a) { unsigned long ret,l; @@ -488,26 +492,22 @@ ERR_STRING_DATA *a; return(ret^ret%19*13); } -static int err_cmp(a,b) -ERR_STRING_DATA *a,*b; +static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) { return((int)(a->error-b->error)); } -static unsigned long pid_hash(a) -ERR_STATE *a; +static unsigned long pid_hash(ERR_STATE *a) { return(a->pid*13); } -static int pid_cmp(a,b) -ERR_STATE *a,*b; +static int pid_cmp(ERR_STATE *a, ERR_STATE *b) { return((int)((long)a->pid - (long)b->pid)); } -void ERR_remove_state(pid) -unsigned long pid; +void ERR_remove_state(unsigned long pid) { ERR_STATE *p,tmp; @@ -523,7 +523,7 @@ unsigned long pid; if (p != NULL) ERR_STATE_free(p); } -ERR_STATE *ERR_get_state() +ERR_STATE *ERR_get_state(void) { static ERR_STATE fallback; ERR_STATE *ret=NULL,tmp,*tmpp; @@ -539,7 +539,9 @@ ERR_STATE *ERR_get_state() CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (thread_hash == NULL) { + MemCheck_off(); thread_hash=lh_new(pid_hash,pid_cmp); + MemCheck_on(); CRYPTO_w_unlock(CRYPTO_LOCK_ERR); if (thread_hash == NULL) return(&fallback); } @@ -577,16 +579,14 @@ ERR_STATE *ERR_get_state() return(ret); } -int ERR_get_next_error_library() +int ERR_get_next_error_library(void) { static int value=ERR_LIB_USER; return(value++); } -void ERR_set_error_data(data,flags) -char *data; -int flags; +void ERR_set_error_data(char *data, int flags) { ERR_STATE *es; int i; @@ -601,10 +601,9 @@ int flags; es->err_data_flags[es->top]=flags; } -void ERR_add_error_data( VAR_PLIST(int , num)) -VAR_ALIST - { - VAR_BDEFN(args, int, num); +void ERR_add_error_data(int num, ...) + { + va_list args; int i,n,s; char *str,*p,*a; @@ -613,12 +612,14 @@ VAR_ALIST if (str == NULL) return; str[0]='\0'; - VAR_INIT(args,int,num); + va_start(args, num); n=0; for (i=0; i */ + if (a != NULL) + { n+=strlen(a); if (n > s) { @@ -637,6 +638,6 @@ VAR_ALIST } ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); - VAR_END( args ); + va_end(args); } diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h index 75f931be11..9411fb3568 100644 --- a/src/lib/libcrypto/err/err.h +++ b/src/lib/libcrypto/err/err.h @@ -63,6 +63,10 @@ extern "C" { #endif +#ifndef NO_FP_API +#include +#endif + /* The following is a bit of a trick to help the object files only contain * the 'name of the file' string once. Since 'err.h' is protected by the * HEADER_ERR_H stuff, this should be included only once per file. */ @@ -87,7 +91,7 @@ typedef struct err_state_st unsigned long err_buffer[ERR_NUM_ERRORS]; char *err_data[ERR_NUM_ERRORS]; int err_data_flags[ERR_NUM_ERRORS]; - char *err_file[ERR_NUM_ERRORS]; + const char *err_file[ERR_NUM_ERRORS]; int err_line[ERR_NUM_ERRORS]; int top,bottom; } ERR_STATE; @@ -116,6 +120,8 @@ typedef struct err_state_st #define ERR_LIB_PROXY 31 #define ERR_LIB_BIO 32 #define ERR_LIB_PKCS7 33 +#define ERR_LIB_X509V3 34 +#define ERR_LIB_PKCS12 35 #define ERR_LIB_USER 128 @@ -141,6 +147,8 @@ typedef struct err_state_st #define RSAREFerr(f,r) ERR_PUT_error(ERR_LIB_RSAREF,(f),(r),ERR_file_name,__LINE__) #define PROXYerr(f,r) ERR_PUT_error(ERR_LIB_PROXY,(f),(r),ERR_file_name,__LINE__) #define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__) +#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__) +#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__) /* Borland C seems too stupid to be able to shift and do longs in * the pre-processor :-( */ @@ -162,6 +170,7 @@ typedef struct err_state_st #define SYS_F_LISTEN 7 #define SYS_F_ACCEPT 8 #define SYS_F_WSASTARTUP 9 /* Winsock stuff */ +#define SYS_F_OPENDIR 10 #define ERR_R_FATAL 32 /* reasons */ @@ -187,41 +196,47 @@ typedef struct err_state_st #define ERR_R_PROXY_LIB ERR_LIB_PROXY #define ERR_R_BIO_LIB ERR_LIB_BIO #define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 +#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12 /* fatal error */ #define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) #define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) #define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) +#define ERR_R_NESTED_ASN1_ERROR (4) +#define ERR_R_BAD_ASN1_OBJECT_HEADER (5) +#define ERR_R_BAD_GET_ASN1_OBJECT_CALL (6) +#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE (7) +#define ERR_R_ASN1_LENGTH_MISMATCH (8) +#define ERR_R_MISSING_ASN1_EOS (9) typedef struct ERR_string_data_st { unsigned long error; - char *string; + const char *string; } ERR_STRING_DATA; -#ifndef NOPROTO -void ERR_put_error(int lib, int func,int reason,char *file,int line); +void ERR_put_error(int lib, int func,int reason,const char *file,int line); void ERR_set_error_data(char *data,int flags); unsigned long ERR_get_error(void ); -unsigned long ERR_get_error_line(char **file,int *line); -unsigned long ERR_get_error_line_data(char **file,int *line, - char **data, int *flags); +unsigned long ERR_get_error_line(const char **file,int *line); +unsigned long ERR_get_error_line_data(const char **file,int *line, + const char **data, int *flags); unsigned long ERR_peek_error(void ); -unsigned long ERR_peek_error_line(char **file,int *line); -unsigned long ERR_peek_error_line_data(char **file,int *line, - char **data,int *flags); +unsigned long ERR_peek_error_line(const char **file,int *line); +unsigned long ERR_peek_error_line_data(const char **file,int *line, + const char **data,int *flags); void ERR_clear_error(void ); char *ERR_error_string(unsigned long e,char *buf); -char *ERR_lib_error_string(unsigned long e); -char *ERR_func_error_string(unsigned long e); -char *ERR_reason_error_string(unsigned long e); +const char *ERR_lib_error_string(unsigned long e); +const char *ERR_func_error_string(unsigned long e); +const char *ERR_reason_error_string(unsigned long e); #ifndef NO_FP_API void ERR_print_errors_fp(FILE *fp); #endif #ifdef HEADER_BIO_H void ERR_print_errors(BIO *bp); -void ERR_add_error_data( VAR_PLIST( int, num ) ); +void ERR_add_error_data(int num, ...); #endif void ERR_load_strings(int lib,ERR_STRING_DATA str[]); void ERR_load_ERR_strings(void ); @@ -241,45 +256,6 @@ char *ERR_get_err_state_table(void ); int ERR_get_next_error_library(void ); -#else - -void ERR_put_error(); -void ERR_set_error_data(); - -unsigned long ERR_get_error(); -unsigned long ERR_get_error_line(); -unsigned long ERR_peek_error(); -unsigned long ERR_peek_error_line(); -void ERR_clear_error(); -char *ERR_error_string(); -char *ERR_lib_error_string(); -char *ERR_func_error_string(); -char *ERR_reason_error_string(); -#ifndef NO_FP_API -void ERR_print_errors_fp(); -#endif -void ERR_print_errors(); -void ERR_add_error_data(); -void ERR_load_strings(); -void ERR_load_ERR_strings(); -void ERR_load_crypto_strings(); -void ERR_free_strings(); - -void ERR_remove_state(); -ERR_STATE *ERR_get_state(); - -#ifdef HEADER_LHASH_H -LHASH *ERR_get_string_table(); -LHASH *ERR_get_err_state_table(); -#else -char *ERR_get_string_table(); -char *ERR_get_err_state_table(); -#endif - -int ERR_get_next_error_library(); - -#endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c index f874268e1a..ad820227d2 100644 --- a/src/lib/libcrypto/err/err_all.c +++ b/src/lib/libcrypto/err/err_all.c @@ -57,30 +57,32 @@ */ #include -#include "asn1.h" -#include "bn.h" -#include "buffer.h" -#include "bio.h" +#include +#include +#include +#include #ifndef NO_RSA -#include "rsa.h" +#include #endif #ifdef RSAref -#include "rsaref.h" +#include #endif #ifndef NO_DH -#include "dh.h" +#include #endif #ifndef NO_DSA -#include "dsa.h" +#include #endif -#include "evp.h" -#include "objects.h" -#include "pem.h" -#include "x509.h" -#include "conf.h" -#include "err.h" +#include +#include +#include +#include +#include +#include +#include +#include -void ERR_load_crypto_strings() +void ERR_load_crypto_strings(void) { static int done=0; @@ -110,7 +112,9 @@ void ERR_load_crypto_strings() ERR_load_OBJ_strings(); ERR_load_PEM_strings(); ERR_load_X509_strings(); + ERR_load_X509V3_strings(); ERR_load_CRYPTO_strings(); ERR_load_PKCS7_strings(); + ERR_load_PKCS12_strings(); #endif } diff --git a/src/lib/libcrypto/err/err_code.pl b/src/lib/libcrypto/err/err_code.pl deleted file mode 100644 index ebc8eef913..0000000000 --- a/src/lib/libcrypto/err/err_code.pl +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/perl - -while (@ARGV) - { - $in=shift(@ARGV); - if ($in =~ /^-conf$/) - { - $in=shift(@ARGV); - open(IN,"<$in") || die "unable to open '$in'\n"; - while () - { - s/#.*$//; - s/\s+$//; - next if (/^$/); - if (/^L\s+(\S+)\s+(\S+)$/) - { $errfile{$1}=$2; } - elsif (/^F\s+(\S+)$/) - { $function{$1}=1; } - elsif (/^R\s+(\S+)\s+(\S+)$/) - { $r_value{$1}=$2; } - else { die "bad input line: $in:$.\n"; } - } - close(IN); - next; - } - - open(IN,"<$in") || die "unable to open '$in'\n"; - $last=""; - while () - { - if (/err\(([A-Z0-9]+_F_[0-9A-Z_]+)\s*,\s*([0-9A-Z]+_R_[0-9A-Z_]+)\s*\)/) - { - if ($1 != $last) - { - if ($function{$1} == 0) - { - printf STDERR "$. $1 is bad\n"; - } - } - $function{$1}++; - $last=$1; - $reason{$2}++; - } - } - close(IN); - } - -foreach (keys %function,keys %reason) - { - /^([A-Z0-9]+)_/; - $prefix{$1}++; - } - -@F=sort keys %function; -@R=sort keys %reason; -foreach $j (sort keys %prefix) - { - next if $errfile{$j} eq "NONE"; - printf STDERR "doing %-6s - ",$j; - if (defined($errfile{$j})) - { - open(OUT,">$errfile{$j}") || - die "unable to open '$errfile{$j}':$!\n"; - $close_file=1; - } - else - { - *OUT=*STDOUT; - $close=0; - } - @f=grep(/^${j}_/,@F); - @r=grep(/^${j}_/,@R); - $num=100; - print OUT "/* Error codes for the $j functions. */\n\n"; - print OUT "/* Function codes. */\n"; - $f_count=0; - foreach $i (@f) - { - $z=6-int(length($i)/8); - printf OUT "#define $i%s $num\n","\t" x $z; - $num++; - $f_count++; - } - $num=100; - print OUT "\n/* Reason codes. */\n"; - $r_count=0; - foreach $i (@r) - { - $z=6-int(length($i)/8); - if (defined($r_value{$i})) - { - printf OUT "#define $i%s $r_value{$i}\n","\t" x $z; - } - else - { - printf OUT "#define $i%s $num\n","\t" x $z; - $num++; - } - $r_count++; - } - close(OUT) if $close_file; - - printf STDERR "%3d functions, %3d reasons\n",$f_count,$r_count; - } - diff --git a/src/lib/libcrypto/err/err_genc.pl b/src/lib/libcrypto/err/err_genc.pl deleted file mode 100644 index a8e36c2f0c..0000000000 --- a/src/lib/libcrypto/err/err_genc.pl +++ /dev/null @@ -1,198 +0,0 @@ -#!/usr/bin/perl - -if ($ARGV[0] eq "-s") { $static=1; shift @ARGV; } - -($#ARGV == 1) || die "usage: $0 [-s]
\n"; -open(IN,"<$ARGV[0]") || die "unable to open $ARGV[0]:$!\n"; -open(STDOUT,">$ARGV[1]") || die "unable to open $ARGV[1]:$!\n"; - -$Func=0; -$Reas=0; -$fuction{'FOPEN'}='fopen'; -while () - { - if (/(\S+)\s*\(\);/) - { - $t=$1; - $t =~ s/\*//; - ($upper=$t) =~ tr/a-z/A-Z/; - $fuction{$upper}=$t; - } - next unless (/^#define\s+(\S+)\s/); - - $o=$1; - if ($o =~ /^([^_]+)_F_(.*)/) - { - $type=$1; - $Func++; - $n=$2; - $n=$fuction{$n} if (defined($fuction{$n})); - $out{$1."_str_functs"}.= - sprintf("{ERR_PACK(0,%s,0),\t\"$n\"},\n",$o); - } - elsif ($o =~ /^([^_]+)_R_(.*)/) - { - $type=$1; - $Reas++; - $r=$2; - $r =~ tr/A-Z_/a-z /; - $pkg{$type."_str_reasons"}=$type; - $out{$type."_str_reasons"}.=sprintf("{%-40s,\"$r\"},\n",$o); - } - elsif ($ARGV[0] =~ /rsaref/ && $o =~ /^RE_(.*)/) - { - $type="RSAREF"; - $Reas++; - $r=$1; - $r =~ tr/A-Z_/a-z /; - $pkg{$type."_str_reasons"}=$type; - $out{$type."_str_reasons"}.=sprintf("{%-40s,\"$r\"},\n",$o); - } - } -close(IN); - -&header($type,$ARGV[0]); - -foreach (sort keys %out) - { - print "static ERR_STRING_DATA ${_}[]=\n\t{\n"; - print $out{$_}; - print "{0,NULL},\n"; - print "\t};\n\n"; - } -print "#endif\n"; - -if ($static) - { $lib="ERR_LIB_$type"; } -else - { $lib="${type}_lib_error_code"; } - -$str=""; -$str.="#ifndef NO_ERR\n"; -$str.="\t\tERR_load_strings($lib,${type}_str_functs);\n" if $Func; -$str.="\t\tERR_load_strings($lib,${type}_str_reasons);\n" if $Reas; -$str.="#endif\n"; - -if (!$static) - { -print <<"EOF"; - -static int ${type}_lib_error_code=0; - -void ERR_load_${type}_strings() - { - static int init=1; - - if (${type}_lib_error_code == 0) - ${type}_lib_error_code=ERR_get_next_error_library(); - - if (init); - {; - init=0; -$str - } - } - -void ERR_${type}_error(function,reason,file,line) -int function; -int reason; -char *file; -int line; - { - if (${type}_lib_error_code == 0) - ${type}_lib_error_code=ERR_get_next_error_library(); - ERR_PUT_error(${type}_lib_error_code,function,reason,file,line); - } -EOF - } -else # $static - { - print <<"EOF"; - -void ERR_load_${type}_strings() - { - static int init=1; - - if (init); - {; - init=0; -$str - } - } -EOF - } - -sub header - { - ($type,$header)=@_; - - ($lc=$type) =~ tr/A-Z/a-z/; - $header =~ s/^.*\///; - - print "/* lib/$lc/${lc}\_err.c */\n"; - print <<'EOF'; -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ -EOF - - print "#include \n"; - print "#include \"err.h\"\n"; - print "#include \"$header\"\n"; - print "\n/* BEGIN ERROR CODES */\n"; - print "#ifndef NO_ERR\n"; - } - diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c index ecd0e7c4fa..0999ff214b 100644 --- a/src/lib/libcrypto/err/err_prn.c +++ b/src/lib/libcrypto/err/err_prn.c @@ -57,20 +57,19 @@ */ #include -#include "lhash.h" -#include "crypto.h" +#include +#include #include "cryptlib.h" -#include "buffer.h" -#include "err.h" -#include "crypto.h" +#include +#include +#include #ifndef NO_FP_API -void ERR_print_errors_fp(fp) -FILE *fp; +void ERR_print_errors_fp(FILE *fp) { unsigned long l; char buf[200]; - char *file,*data; + const char *file,*data; int line,flags; unsigned long es; @@ -83,13 +82,12 @@ FILE *fp; } #endif -void ERR_print_errors(bp) -BIO *bp; +void ERR_print_errors(BIO *bp) { unsigned long l; char buf[256]; char buf2[256]; - char *file,*data; + const char *file,*data; int line,flags; unsigned long es; diff --git a/src/lib/libcrypto/err/error.err b/src/lib/libcrypto/err/error.err deleted file mode 100644 index f09557d8d9..0000000000 --- a/src/lib/libcrypto/err/error.err +++ /dev/null @@ -1,13 +0,0 @@ -/* Error codes for the ERR functions. */ - -/* Function codes. */ - -/* Reason codes. */ -#define ERR_R_BN_LIB 100 -#define ERR_R_DER_LIB 101 -#define ERR_R_MALLOC_FAILURE 102 -#define ERR_R_PEM_LIB 103 -#define ERR_R_RSA_LIB 104 -#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED 105 -#define ERR_R_SYS_LIB 106 -#define ERR_R_X509_LIB 107 diff --git a/src/lib/libcrypto/err/openssl.ec b/src/lib/libcrypto/err/openssl.ec new file mode 100644 index 0000000000..c2a8acff0c --- /dev/null +++ b/src/lib/libcrypto/err/openssl.ec @@ -0,0 +1,71 @@ +L ERR NONE NONE +L CRYPTO crypto/crypto.h crypto/cpt_err.c +L BN crypto/bn/bn.h crypto/bn/bn_err.c +L RSA crypto/rsa/rsa.h crypto/rsa/rsa_err.c +L DSA crypto/dsa/dsa.h crypto/dsa/dsa_err.c +L DH crypto/dh/dh.h crypto/dh/dh_err.c +L EVP crypto/evp/evp.h crypto/evp/evp_err.c +L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c +L BIO crypto/bio/bio.h crypto/bio/bio_err.c +L OBJ crypto/objects/objects.h crypto/objects/obj_err.c +L PEM crypto/pem/pem.h crypto/pem/pem_err.c +L X509 crypto/x509/x509.h crypto/x509/x509_err.c +L NONE crypto/x509/x509_vfy.h NONE +L X509V3 crypto/x509v3/x509v3.h crypto/x509v3/v3err.c +#L METH crypto/meth/meth.h crypto/meth/meth_err.c +L ASN1 crypto/asn1/asn1.h crypto/asn1/asn1_err.c +L CONF crypto/conf/conf.h crypto/conf/conf_err.c +#L PROXY crypto/proxy/proxy.h crypto/proxy/proxy_err.c +L PKCS7 crypto/pkcs7/pkcs7.h crypto/pkcs7/pkcs7err.c +L PKCS12 crypto/pkcs12/pkcs12.h crypto/pkcs12/pk12err.c +L RSAREF rsaref/rsaref.h rsaref/rsar_err.c +L SSL ssl/ssl.h ssl/ssl_err.c +L COMP crypto/comp/comp.h crypto/comp/comp_err.c + + +F RSAREF_F_RSA_BN2BIN +F RSAREF_F_RSA_PRIVATE_DECRYPT +F RSAREF_F_RSA_PRIVATE_ENCRYPT +F RSAREF_F_RSA_PUBLIC_DECRYPT +F RSAREF_F_RSA_PUBLIC_ENCRYPT +#F SSL_F_CLIENT_CERTIFICATE + +R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010 +R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020 +R SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021 +R SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022 +R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030 +R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040 +R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041 +R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 +R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043 +R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044 +R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045 +R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046 +R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047 +R SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048 +R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049 +R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050 +R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051 +R SSL_R_TLSV1_ALERT_EXPORT_RESTRICION 1060 +R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070 +R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071 +R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080 +R SSL_R_TLSV1_ALERT_USER_CANCLED 1090 +R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100 + +R RSAREF_R_CONTENT_ENCODING 0x0400 +R RSAREF_R_DATA 0x0401 +R RSAREF_R_DIGEST_ALGORITHM 0x0402 +R RSAREF_R_ENCODING 0x0403 +R RSAREF_R_KEY 0x0404 +R RSAREF_R_KEY_ENCODING 0x0405 +R RSAREF_R_LEN 0x0406 +R RSAREF_R_MODULUS_LEN 0x0407 +R RSAREF_R_NEED_RANDOM 0x0408 +R RSAREF_R_PRIVATE_KEY 0x0409 +R RSAREF_R_PUBLIC_KEY 0x040a +R RSAREF_R_SIGNATURE 0x040b +R RSAREF_R_SIGNATURE_ENCODING 0x040c +R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d + diff --git a/src/lib/libcrypto/err/ssleay.ec b/src/lib/libcrypto/err/ssleay.ec deleted file mode 100644 index 10b5dbb59d..0000000000 --- a/src/lib/libcrypto/err/ssleay.ec +++ /dev/null @@ -1,57 +0,0 @@ -L ERR NONE -L CRYPTO crypto.err -L BN bn/bn.err -L RSA rsa/rsa.err -L DSA dsa/dsa.err -L DH dh/dh.err -L EVP evp/evp.err -L BUF buffer/buffer.err -L BIO bio/bio.err -L OBJ objects/objects.err -L PEM pem/pem.err -L X509 x509/x509.err -L METH meth/meth.err -L ASN1 asn1/asn1.err -L CONF conf/conf.err -L PROXY proxy/proxy.err -L PKCS7 pkcs7/pkcs7.err -L RSAREF ../rsaref/rsaref.err -L SSL ../ssl/ssl.err -L SSL2 ../ssl/ssl2.err -L SSL3 ../ssl/ssl3.err -L SSL23 ../ssl/ssl23.err - -F RSAREF_F_RSA_BN2BIN -F RSAREF_F_RSA_PRIVATE_DECRYPT -F RSAREF_F_RSA_PRIVATE_ENCRYPT -F RSAREF_F_RSA_PUBLIC_DECRYPT -F RSAREF_F_RSA_PUBLIC_ENCRYPT -#F SSL_F_CLIENT_CERTIFICATE - -R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010 -R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020 -R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030 -R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040 -R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041 -R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042 -R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043 -R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044 -R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045 -R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046 -R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047 - -R RSAREF_R_CONTENT_ENCODING 0x0400 -R RSAREF_R_DATA 0x0401 -R RSAREF_R_DIGEST_ALGORITHM 0x0402 -R RSAREF_R_ENCODING 0x0403 -R RSAREF_R_KEY 0x0404 -R RSAREF_R_KEY_ENCODING 0x0405 -R RSAREF_R_LEN 0x0406 -R RSAREF_R_MODULUS_LEN 0x0407 -R RSAREF_R_NEED_RANDOM 0x0408 -R RSAREF_R_PRIVATE_KEY 0x0409 -R RSAREF_R_PUBLIC_KEY 0x040a -R RSAREF_R_SIGNATURE 0x040b -R RSAREF_R_SIGNATURE_ENCODING 0x040c -R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d - diff --git a/src/lib/libcrypto/evp/Makefile.ssl b/src/lib/libcrypto/evp/Makefile.ssl index 8bf2516458..dda2586ed1 100644 --- a/src/lib/libcrypto/evp/Makefile.ssl +++ b/src/lib/libcrypto/evp/Makefile.ssl @@ -7,16 +7,16 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=evp -ERRC=evp_err GENERAL=Makefile TEST= APPS= @@ -34,8 +34,8 @@ LIBSRC= encode.c digest.c evp_enc.c evp_key.c \ m_null.c m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c m_dss1.c m_mdc2.c \ m_ripemd.c \ p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \ - bio_md.c bio_b64.c bio_enc.c $(ERRC).c e_null.c \ - c_all.c evp_lib.c + bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \ + c_all.c evp_lib.c bio_ok.c evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \ e_ecb_d.o e_cbc_d.o e_cfb_d.o e_ofb_d.o \ @@ -49,8 +49,8 @@ LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \ m_null.o m_md2.o m_md5.o m_sha.o m_sha1.o m_dss.o m_dss1.o m_mdc2.o \ m_ripemd.o \ p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \ - bio_md.o bio_b64.o bio_enc.o $(ERRC).o e_null.o \ - c_all.o evp_lib.o + bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \ + c_all.o evp_lib.o bio_ok.o evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o SRC= $(LIBSRC) @@ -66,24 +66,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -95,17 +94,1006 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +bio_b64.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bio_b64.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bio_b64.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bio_b64.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bio_b64.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bio_b64.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bio_b64.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bio_b64.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bio_b64.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bio_b64.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bio_b64.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +bio_b64.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +bio_b64.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +bio_b64.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +bio_b64.o: ../../include/openssl/stack.h ../cryptlib.h +bio_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bio_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bio_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bio_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bio_enc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bio_enc.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bio_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bio_enc.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bio_enc.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bio_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bio_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +bio_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +bio_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +bio_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +bio_enc.o: ../../include/openssl/stack.h ../cryptlib.h +bio_md.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bio_md.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bio_md.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bio_md.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bio_md.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bio_md.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bio_md.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bio_md.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bio_md.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bio_md.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bio_md.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +bio_md.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +bio_md.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +bio_md.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +bio_md.o: ../../include/openssl/stack.h ../cryptlib.h +bio_ok.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +bio_ok.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +bio_ok.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +bio_ok.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +bio_ok.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +bio_ok.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +bio_ok.o: ../../include/openssl/err.h ../../include/openssl/evp.h +bio_ok.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +bio_ok.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +bio_ok.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +bio_ok.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +bio_ok.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +bio_ok.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +bio_ok.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +bio_ok.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +bio_ok.o: ../cryptlib.h +c_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +c_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +c_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +c_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +c_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +c_all.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +c_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h +c_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +c_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +c_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +c_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs12.h +c_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +c_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +c_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +c_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +c_all.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +c_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +digest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +digest.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +digest.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +digest.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +digest.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h +digest.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +digest.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +digest.o: ../../include/openssl/stack.h ../cryptlib.h +e_cbc_3d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cbc_3d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cbc_3d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cbc_3d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cbc_3d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cbc_3d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cbc_3d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cbc_3d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cbc_3d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cbc_3d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cbc_3d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cbc_3d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cbc_3d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cbc_3d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cbc_3d.o: ../../include/openssl/stack.h ../cryptlib.h +e_cbc_bf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cbc_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cbc_bf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cbc_bf.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cbc_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cbc_bf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cbc_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cbc_bf.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cbc_bf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cbc_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cbc_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cbc_bf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cbc_bf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cbc_bf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cbc_bf.o: ../../include/openssl/stack.h ../cryptlib.h +e_cbc_c.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cbc_c.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cbc_c.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cbc_c.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cbc_c.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cbc_c.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cbc_c.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cbc_c.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cbc_c.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cbc_c.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cbc_c.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cbc_c.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cbc_c.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cbc_c.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cbc_c.o: ../../include/openssl/stack.h ../cryptlib.h +e_cbc_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cbc_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cbc_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cbc_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cbc_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cbc_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cbc_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cbc_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cbc_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cbc_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cbc_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cbc_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cbc_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cbc_d.o: ../../include/openssl/stack.h ../cryptlib.h +e_cbc_i.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cbc_i.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cbc_i.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cbc_i.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cbc_i.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cbc_i.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cbc_i.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cbc_i.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cbc_i.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cbc_i.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cbc_i.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cbc_i.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cbc_i.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cbc_i.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cbc_i.o: ../../include/openssl/stack.h ../cryptlib.h +e_cbc_r2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cbc_r2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cbc_r2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cbc_r2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cbc_r2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cbc_r2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cbc_r2.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cbc_r2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cbc_r2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cbc_r2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cbc_r2.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cbc_r2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cbc_r2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cbc_r2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cbc_r2.o: ../../include/openssl/stack.h ../cryptlib.h +e_cbc_r5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cbc_r5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cbc_r5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cbc_r5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cbc_r5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cbc_r5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cbc_r5.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cbc_r5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cbc_r5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cbc_r5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cbc_r5.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cbc_r5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cbc_r5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cbc_r5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cbc_r5.o: ../../include/openssl/stack.h ../cryptlib.h +e_cfb_3d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cfb_3d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cfb_3d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cfb_3d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cfb_3d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cfb_3d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cfb_3d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cfb_3d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cfb_3d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cfb_3d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cfb_3d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cfb_3d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cfb_3d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cfb_3d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cfb_3d.o: ../../include/openssl/stack.h ../cryptlib.h +e_cfb_bf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cfb_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cfb_bf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cfb_bf.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cfb_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cfb_bf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cfb_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cfb_bf.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cfb_bf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cfb_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cfb_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cfb_bf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cfb_bf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cfb_bf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cfb_bf.o: ../../include/openssl/stack.h ../cryptlib.h +e_cfb_c.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cfb_c.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cfb_c.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cfb_c.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cfb_c.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cfb_c.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cfb_c.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cfb_c.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cfb_c.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cfb_c.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cfb_c.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cfb_c.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cfb_c.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cfb_c.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cfb_c.o: ../../include/openssl/stack.h ../cryptlib.h +e_cfb_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cfb_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cfb_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cfb_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cfb_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cfb_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cfb_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cfb_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cfb_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cfb_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cfb_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cfb_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cfb_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cfb_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cfb_d.o: ../../include/openssl/stack.h ../cryptlib.h +e_cfb_i.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cfb_i.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cfb_i.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cfb_i.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cfb_i.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cfb_i.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cfb_i.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cfb_i.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cfb_i.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cfb_i.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cfb_i.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cfb_i.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cfb_i.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cfb_i.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cfb_i.o: ../../include/openssl/stack.h ../cryptlib.h +e_cfb_r2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cfb_r2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cfb_r2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cfb_r2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cfb_r2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cfb_r2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cfb_r2.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cfb_r2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cfb_r2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cfb_r2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cfb_r2.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cfb_r2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cfb_r2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cfb_r2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cfb_r2.o: ../../include/openssl/stack.h ../cryptlib.h +e_cfb_r5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_cfb_r5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_cfb_r5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_cfb_r5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_cfb_r5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_cfb_r5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_cfb_r5.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_cfb_r5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_cfb_r5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_cfb_r5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_cfb_r5.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_cfb_r5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_cfb_r5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_cfb_r5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_cfb_r5.o: ../../include/openssl/stack.h ../cryptlib.h +e_ecb_3d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ecb_3d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ecb_3d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ecb_3d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ecb_3d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ecb_3d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ecb_3d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ecb_3d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ecb_3d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ecb_3d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ecb_3d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ecb_3d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ecb_3d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ecb_3d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ecb_3d.o: ../../include/openssl/stack.h ../cryptlib.h +e_ecb_bf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ecb_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ecb_bf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ecb_bf.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ecb_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ecb_bf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ecb_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ecb_bf.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ecb_bf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ecb_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ecb_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ecb_bf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ecb_bf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ecb_bf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ecb_bf.o: ../../include/openssl/stack.h ../cryptlib.h +e_ecb_c.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ecb_c.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ecb_c.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ecb_c.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ecb_c.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ecb_c.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ecb_c.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ecb_c.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ecb_c.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ecb_c.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ecb_c.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ecb_c.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ecb_c.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ecb_c.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ecb_c.o: ../../include/openssl/stack.h ../cryptlib.h +e_ecb_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ecb_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ecb_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ecb_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ecb_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ecb_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ecb_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ecb_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ecb_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ecb_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ecb_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ecb_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ecb_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ecb_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ecb_d.o: ../../include/openssl/stack.h ../cryptlib.h +e_ecb_i.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ecb_i.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ecb_i.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ecb_i.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ecb_i.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ecb_i.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ecb_i.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ecb_i.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ecb_i.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ecb_i.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ecb_i.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ecb_i.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ecb_i.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ecb_i.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ecb_i.o: ../../include/openssl/stack.h ../cryptlib.h +e_ecb_r2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ecb_r2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ecb_r2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ecb_r2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ecb_r2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ecb_r2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ecb_r2.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ecb_r2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ecb_r2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ecb_r2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ecb_r2.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ecb_r2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ecb_r2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ecb_r2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ecb_r2.o: ../../include/openssl/stack.h ../cryptlib.h +e_ecb_r5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ecb_r5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ecb_r5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ecb_r5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ecb_r5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ecb_r5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ecb_r5.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ecb_r5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ecb_r5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ecb_r5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ecb_r5.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ecb_r5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ecb_r5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ecb_r5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ecb_r5.o: ../../include/openssl/stack.h ../cryptlib.h +e_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_null.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_null.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_null.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_null.o: ../../include/openssl/stack.h ../cryptlib.h +e_ofb_3d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ofb_3d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ofb_3d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ofb_3d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ofb_3d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ofb_3d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ofb_3d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ofb_3d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ofb_3d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ofb_3d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ofb_3d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ofb_3d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ofb_3d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ofb_3d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ofb_3d.o: ../../include/openssl/stack.h ../cryptlib.h +e_ofb_bf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ofb_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ofb_bf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ofb_bf.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ofb_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ofb_bf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ofb_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ofb_bf.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ofb_bf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ofb_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ofb_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ofb_bf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ofb_bf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ofb_bf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ofb_bf.o: ../../include/openssl/stack.h ../cryptlib.h +e_ofb_c.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ofb_c.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ofb_c.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ofb_c.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ofb_c.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ofb_c.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ofb_c.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ofb_c.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ofb_c.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ofb_c.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ofb_c.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ofb_c.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ofb_c.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ofb_c.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ofb_c.o: ../../include/openssl/stack.h ../cryptlib.h +e_ofb_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ofb_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ofb_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ofb_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ofb_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ofb_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ofb_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ofb_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ofb_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ofb_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ofb_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ofb_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ofb_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ofb_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ofb_d.o: ../../include/openssl/stack.h ../cryptlib.h +e_ofb_i.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ofb_i.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ofb_i.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ofb_i.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ofb_i.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ofb_i.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ofb_i.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ofb_i.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ofb_i.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ofb_i.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ofb_i.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ofb_i.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ofb_i.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ofb_i.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ofb_i.o: ../../include/openssl/stack.h ../cryptlib.h +e_ofb_r2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ofb_r2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ofb_r2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ofb_r2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ofb_r2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ofb_r2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ofb_r2.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ofb_r2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ofb_r2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ofb_r2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ofb_r2.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ofb_r2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ofb_r2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ofb_r2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ofb_r2.o: ../../include/openssl/stack.h ../cryptlib.h +e_ofb_r5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_ofb_r5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_ofb_r5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_ofb_r5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_ofb_r5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_ofb_r5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_ofb_r5.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_ofb_r5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_ofb_r5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_ofb_r5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_ofb_r5.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_ofb_r5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_ofb_r5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_ofb_r5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_ofb_r5.o: ../../include/openssl/stack.h ../cryptlib.h +e_rc4.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_rc4.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_rc4.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_rc4.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_rc4.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_rc4.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_rc4.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_rc4.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_rc4.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_rc4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_rc4.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_rc4.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_rc4.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_rc4.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_rc4.o: ../../include/openssl/stack.h ../cryptlib.h +e_xcbc_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +e_xcbc_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +e_xcbc_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +e_xcbc_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +e_xcbc_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +e_xcbc_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +e_xcbc_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h +e_xcbc_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +e_xcbc_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +e_xcbc_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +e_xcbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +e_xcbc_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +e_xcbc_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +e_xcbc_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +e_xcbc_d.o: ../../include/openssl/stack.h ../cryptlib.h +encode.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +encode.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +encode.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +encode.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +encode.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +encode.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +encode.o: ../../include/openssl/err.h ../../include/openssl/evp.h +encode.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +encode.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +encode.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +encode.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +encode.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +encode.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +encode.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +encode.o: ../../include/openssl/stack.h ../cryptlib.h +evp_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +evp_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +evp_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +evp_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +evp_enc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +evp_enc.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +evp_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h +evp_enc.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +evp_enc.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +evp_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +evp_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +evp_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +evp_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +evp_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +evp_enc.o: ../../include/openssl/stack.h ../cryptlib.h +evp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +evp_err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +evp_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +evp_err.o: ../../include/openssl/des.h ../../include/openssl/dh.h +evp_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h +evp_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h +evp_err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +evp_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +evp_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +evp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +evp_err.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +evp_err.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +evp_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +evp_err.o: ../../include/openssl/stack.h +evp_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +evp_key.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +evp_key.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +evp_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +evp_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +evp_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +evp_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h +evp_key.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +evp_key.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +evp_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +evp_key.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +evp_key.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +evp_key.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +evp_key.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +evp_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +evp_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +evp_key.o: ../cryptlib.h +evp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +evp_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +evp_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +evp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +evp_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +evp_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +evp_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h +evp_lib.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +evp_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +evp_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +evp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +evp_lib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +evp_lib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +evp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +evp_lib.o: ../../include/openssl/stack.h ../cryptlib.h +evp_pbe.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +evp_pbe.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +evp_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +evp_pbe.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +evp_pbe.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +evp_pbe.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +evp_pbe.o: ../../include/openssl/err.h ../../include/openssl/evp.h +evp_pbe.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +evp_pbe.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +evp_pbe.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +evp_pbe.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +evp_pbe.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +evp_pbe.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +evp_pbe.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +evp_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +evp_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +evp_pbe.o: ../cryptlib.h +evp_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +evp_pkey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +evp_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +evp_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +evp_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +evp_pkey.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +evp_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h +evp_pkey.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +evp_pkey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +evp_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +evp_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +evp_pkey.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h +evp_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +evp_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +evp_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +evp_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +evp_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +m_dss.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_dss.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_dss.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_dss.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_dss.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_dss.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_dss.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_dss.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_dss.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_dss.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_dss.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_dss.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_dss.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_dss.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_dss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_dss.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_dss.o: ../cryptlib.h +m_dss1.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_dss1.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_dss1.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_dss1.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_dss1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_dss1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_dss1.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_dss1.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_dss1.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_dss1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_dss1.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_dss1.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_dss1.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_dss1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_dss1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_dss1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_dss1.o: ../cryptlib.h +m_md2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_md2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_md2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_md2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_md2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_md2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_md2.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_md2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_md2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_md2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_md2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_md2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_md2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_md2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_md2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_md2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_md2.o: ../cryptlib.h +m_md5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_md5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_md5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_md5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_md5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_md5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_md5.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_md5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_md5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_md5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_md5.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_md5.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_md5.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_md5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_md5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_md5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_md5.o: ../cryptlib.h +m_mdc2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_mdc2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_mdc2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_mdc2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_mdc2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_mdc2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_mdc2.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_mdc2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_mdc2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_mdc2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_mdc2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_mdc2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_mdc2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_mdc2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_mdc2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_mdc2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_mdc2.o: ../cryptlib.h +m_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_null.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_null.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_null.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_null.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_null.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_null.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_null.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_null.o: ../cryptlib.h +m_ripemd.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_ripemd.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_ripemd.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_ripemd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_ripemd.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_ripemd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_ripemd.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_ripemd.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_ripemd.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_ripemd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_ripemd.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_ripemd.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_ripemd.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_ripemd.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_ripemd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_ripemd.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_ripemd.o: ../cryptlib.h +m_sha.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_sha.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_sha.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_sha.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_sha.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_sha.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_sha.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_sha.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_sha.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_sha.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_sha.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_sha.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_sha.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_sha.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_sha.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_sha.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_sha.o: ../cryptlib.h +m_sha1.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +m_sha1.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +m_sha1.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +m_sha1.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +m_sha1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +m_sha1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +m_sha1.o: ../../include/openssl/err.h ../../include/openssl/evp.h +m_sha1.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +m_sha1.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +m_sha1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +m_sha1.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +m_sha1.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +m_sha1.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +m_sha1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +m_sha1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +m_sha1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +m_sha1.o: ../cryptlib.h +names.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +names.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +names.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +names.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +names.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +names.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +names.o: ../../include/openssl/err.h ../../include/openssl/evp.h +names.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +names.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +names.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +names.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +names.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +names.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +names.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +names.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +names.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +names.o: ../cryptlib.h +p5_crpt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +p5_crpt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +p5_crpt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +p5_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +p5_crpt.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +p5_crpt.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +p5_crpt.o: ../../include/openssl/err.h ../../include/openssl/evp.h +p5_crpt.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +p5_crpt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +p5_crpt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +p5_crpt.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p5_crpt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p5_crpt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p5_crpt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p5_crpt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p5_crpt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p5_crpt.o: ../cryptlib.h +p5_crpt2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +p5_crpt2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +p5_crpt2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +p5_crpt2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +p5_crpt2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +p5_crpt2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +p5_crpt2.o: ../../include/openssl/err.h ../../include/openssl/evp.h +p5_crpt2.o: ../../include/openssl/hmac.h ../../include/openssl/idea.h +p5_crpt2.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p5_crpt2.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p5_crpt2.o: ../../include/openssl/opensslconf.h +p5_crpt2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p5_crpt2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p5_crpt2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p5_crpt2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p5_crpt2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p5_crpt2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p5_crpt2.o: ../cryptlib.h +p_dec.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +p_dec.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +p_dec.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +p_dec.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +p_dec.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +p_dec.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +p_dec.o: ../../include/openssl/err.h ../../include/openssl/evp.h +p_dec.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +p_dec.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +p_dec.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +p_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p_dec.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h +p_dec.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p_dec.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p_dec.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p_dec.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p_dec.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +p_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +p_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +p_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +p_enc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +p_enc.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +p_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h +p_enc.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +p_enc.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +p_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +p_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p_enc.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h +p_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p_enc.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +p_lib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +p_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +p_lib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +p_lib.o: ../../include/openssl/des.h ../../include/openssl/dh.h +p_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +p_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +p_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +p_lib.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +p_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +p_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +p_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +p_lib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p_lib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p_lib.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p_open.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +p_open.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +p_open.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +p_open.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +p_open.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +p_open.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +p_open.o: ../../include/openssl/err.h ../../include/openssl/evp.h +p_open.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +p_open.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +p_open.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +p_open.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p_open.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p_open.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p_open.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p_open.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p_open.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p_open.o: ../cryptlib.h +p_seal.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +p_seal.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +p_seal.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +p_seal.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +p_seal.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +p_seal.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +p_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h +p_seal.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +p_seal.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +p_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +p_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p_seal.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h +p_seal.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +p_seal.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +p_seal.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +p_seal.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +p_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +p_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +p_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +p_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +p_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +p_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +p_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +p_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h +p_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +p_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +p_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +p_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p_sign.o: ../cryptlib.h +p_verify.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +p_verify.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +p_verify.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +p_verify.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +p_verify.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +p_verify.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +p_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h +p_verify.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +p_verify.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +p_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +p_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +p_verify.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +p_verify.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +p_verify.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +p_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +p_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +p_verify.o: ../cryptlib.h diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c index 73172b9a07..84729119df 100644 --- a/src/lib/libcrypto/evp/bio_b64.c +++ b/src/lib/libcrypto/evp/bio_b64.c @@ -59,10 +59,9 @@ #include #include #include "cryptlib.h" -#include "buffer.h" -#include "evp.h" +#include +#include -#ifndef NOPROTO static int b64_write(BIO *h,char *buf,int num); static int b64_read(BIO *h,char *buf,int size); /*static int b64_puts(BIO *h,char *str); */ @@ -70,16 +69,6 @@ static int b64_read(BIO *h,char *buf,int size); static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int b64_new(BIO *h); static int b64_free(BIO *data); -#else -static int b64_write(); -static int b64_read(); -/*static int b64_puts(); */ -/*static int b64_gets(); */ -static long b64_ctrl(); -static int b64_new(); -static int b64_free(); -#endif - #define B64_BLOCK_SIZE 1024 #define B64_BLOCK_SIZE2 768 #define B64_NONE 0 @@ -113,13 +102,12 @@ static BIO_METHOD methods_b64= b64_free, }; -BIO_METHOD *BIO_f_base64() +BIO_METHOD *BIO_f_base64(void) { return(&methods_b64); } -static int b64_new(bi) -BIO *bi; +static int b64_new(BIO *bi) { BIO_B64_CTX *ctx; @@ -140,8 +128,7 @@ BIO *bi; return(1); } -static int b64_free(a) -BIO *a; +static int b64_free(BIO *a) { if (a == NULL) return(0); Free(a->ptr); @@ -151,10 +138,7 @@ BIO *a; return(1); } -static int b64_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int b64_read(BIO *b, char *out, int outl) { int ret=0,i,ii,j,k,x,n,num,ret_code=0; BIO_B64_CTX *ctx; @@ -354,10 +338,7 @@ int outl; return((ret == 0)?ret_code:ret); } -static int b64_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int b64_write(BIO *b, char *in, int inl) { int ret=inl,n,i; BIO_B64_CTX *ctx; @@ -451,11 +432,7 @@ int inl; return(ret); } -static long b64_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long b64_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO_B64_CTX *ctx; long ret=1; diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c index 6c30ddfc54..0a7b1ecf07 100644 --- a/src/lib/libcrypto/evp/bio_enc.c +++ b/src/lib/libcrypto/evp/bio_enc.c @@ -59,10 +59,9 @@ #include #include #include "cryptlib.h" -#include "buffer.h" -#include "evp.h" +#include +#include -#ifndef NOPROTO static int enc_write(BIO *h,char *buf,int num); static int enc_read(BIO *h,char *buf,int size); /*static int enc_puts(BIO *h,char *str); */ @@ -70,16 +69,6 @@ static int enc_read(BIO *h,char *buf,int size); static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int enc_new(BIO *h); static int enc_free(BIO *data); -#else -static int enc_write(); -static int enc_read(); -/*static int enc_puts(); */ -/*static int enc_gets(); */ -static long enc_ctrl(); -static int enc_new(); -static int enc_free(); -#endif - #define ENC_BLOCK_SIZE (1024*4) typedef struct enc_struct @@ -105,13 +94,12 @@ static BIO_METHOD methods_enc= enc_free, }; -BIO_METHOD *BIO_f_cipher() +BIO_METHOD *BIO_f_cipher(void) { return(&methods_enc); } -static int enc_new(bi) -BIO *bi; +static int enc_new(BIO *bi) { BIO_ENC_CTX *ctx; @@ -131,8 +119,7 @@ BIO *bi; return(1); } -static int enc_free(a) -BIO *a; +static int enc_free(BIO *a) { BIO_ENC_CTX *b; @@ -147,10 +134,7 @@ BIO *a; return(1); } -static int enc_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int enc_read(BIO *b, char *out, int outl) { int ret=0,i; BIO_ENC_CTX *ctx; @@ -230,10 +214,7 @@ int outl; return((ret == 0)?ctx->cont:ret); } -static int enc_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int enc_write(BIO *b, char *in, int inl) { int ret=0,n,i; BIO_ENC_CTX *ctx; @@ -288,16 +269,13 @@ int inl; return(ret); } -static long enc_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long enc_ctrl(BIO *b, int cmd, long num, char *ptr) { BIO *dbio; BIO_ENC_CTX *ctx,*dctx; long ret=1; int i; + EVP_CIPHER_CTX **c_ctx; ctx=(BIO_ENC_CTX *)b->ptr; @@ -364,7 +342,11 @@ again: ret=BIO_ctrl(b->next_bio,cmd,num,ptr); BIO_copy_next_retry(b); break; - + case BIO_C_GET_CIPHER_CTX: + c_ctx=(EVP_CIPHER_CTX **)ptr; + (*c_ctx)= &(ctx->cipher); + b->init=1; + break; case BIO_CTRL_DUP: dbio=(BIO *)ptr; dctx=(BIO_ENC_CTX *)dbio->ptr; @@ -398,19 +380,15 @@ EVP_CIPHER_ctx *c; } */ -void BIO_set_cipher(b,c,k,i,e) -BIO *b; -EVP_CIPHER *c; -unsigned char *k; -unsigned char *i; -int e; +void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k, + unsigned char *i, int e) { BIO_ENC_CTX *ctx; if (b == NULL) return; if ((b->callback != NULL) && - (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) + (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0)) return; b->init=1; @@ -418,6 +396,6 @@ int e; EVP_CipherInit(&(ctx->cipher),c,k,i,e); if (b->callback != NULL) - b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); + b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L); } diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c index fa5fdc055b..317167f9c4 100644 --- a/src/lib/libcrypto/evp/bio_md.c +++ b/src/lib/libcrypto/evp/bio_md.c @@ -59,13 +59,12 @@ #include #include #include "cryptlib.h" -#include "buffer.h" -#include "evp.h" +#include +#include /* BIO_put and BIO_get both add to the digest, * BIO_gets returns the digest */ -#ifndef NOPROTO static int md_write(BIO *h,char *buf,int num); static int md_read(BIO *h,char *buf,int size); /*static int md_puts(BIO *h,char *str); */ @@ -73,16 +72,6 @@ static int md_gets(BIO *h,char *str,int size); static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2); static int md_new(BIO *h); static int md_free(BIO *data); -#else -static int md_write(); -static int md_read(); -/*static int md_puts(); */ -static int md_gets(); -static long md_ctrl(); -static int md_new(); -static int md_free(); -#endif - static BIO_METHOD methods_md= { BIO_TYPE_MD,"message digest", @@ -95,13 +84,12 @@ static BIO_METHOD methods_md= md_free, }; -BIO_METHOD *BIO_f_md() +BIO_METHOD *BIO_f_md(void) { return(&methods_md); } -static int md_new(bi) -BIO *bi; +static int md_new(BIO *bi) { EVP_MD_CTX *ctx; @@ -114,8 +102,7 @@ BIO *bi; return(1); } -static int md_free(a) -BIO *a; +static int md_free(BIO *a) { if (a == NULL) return(0); Free(a->ptr); @@ -125,10 +112,7 @@ BIO *a; return(1); } -static int md_read(b,out,outl) -BIO *b; -char *out; -int outl; +static int md_read(BIO *b, char *out, int outl) { int ret=0; EVP_MD_CTX *ctx; @@ -152,10 +136,7 @@ int outl; return(ret); } -static int md_write(b,in,inl) -BIO *b; -char *in; -int inl; +static int md_write(BIO *b, char *in, int inl) { int ret=0; EVP_MD_CTX *ctx; @@ -178,14 +159,10 @@ int inl; return(ret); } -static long md_ctrl(b,cmd,num,ptr) -BIO *b; -int cmd; -long num; -char *ptr; +static long md_ctrl(BIO *b, int cmd, long num, char *ptr) { EVP_MD_CTX *ctx,*dctx,**pctx; - EVP_MD **ppmd; + const EVP_MD **ppmd; EVP_MD *md; long ret=1; BIO *dbio; @@ -204,7 +181,7 @@ char *ptr; case BIO_C_GET_MD: if (b->init) { - ppmd=(EVP_MD **)ptr; + ppmd=(const EVP_MD **)ptr; *ppmd=ctx->digest; } else @@ -243,10 +220,7 @@ char *ptr; return(ret); } -static int md_gets(bp,buf,size) -BIO *bp; -char *buf; -int size; +static int md_gets(BIO *bp, char *buf, int size) { EVP_MD_CTX *ctx; unsigned int ret; diff --git a/src/lib/libcrypto/evp/bio_ok.c b/src/lib/libcrypto/evp/bio_ok.c new file mode 100644 index 0000000000..101275d648 --- /dev/null +++ b/src/lib/libcrypto/evp/bio_ok.c @@ -0,0 +1,552 @@ +/* crypto/evp/bio_ok.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* + From: Arne Ansper + + Why BIO_f_reliable? + + I wrote function which took BIO* as argument, read data from it + and processed it. Then I wanted to store the input file in + encrypted form. OK I pushed BIO_f_cipher to the BIO stack + and everything was OK. BUT if user types wrong password + BIO_f_cipher outputs only garbage and my function crashes. Yes + I can and I should fix my function, but BIO_f_cipher is + easy way to add encryption support to many exisiting applications + and it's hard to debug and fix them all. + + So I wanted another BIO which would catch the incorrect passwords and + file damages which cause garbage on BIO_f_cipher's output. + + The easy way is to push the BIO_f_md and save the checksum at + the end of the file. However there are several problems with this + approach: + + 1) you must somehow separate checksum from actual data. + 2) you need lot's of memory when reading the file, because you + must read to the end of the file and verify the checksum before + leting the application to read the data. + + BIO_f_reliable tries to solve both problems, so that you can + read and write arbitraly long streams using only fixed amount + of memory. + + BIO_f_reliable splits data stream into blocks. Each block is prefixed + with it's length and suffixed with it's digest. So you need only + several Kbytes of memory to buffer single block before verifying + it's digest. + + BIO_f_reliable goes futher and adds several important capabilities: + + 1) the digest of the block is computed over the whole stream + -- so nobody can rearrange the blocks or remove or replace them. + + 2) to detect invalid passwords right at the start BIO_f_reliable + adds special prefix to the stream. In order to avoid known plain-text + attacks this prefix is generated as follows: + + *) digest is initialized with random seed instead of + standardized one. + *) same seed is written to ouput + *) well-known text is then hashed and the output + of the digest is also written to output. + + reader can now read the seed from stream, hash the same string + and then compare the digest output. + + Bad things: BIO_f_reliable knows what's going on in EVP_Digest. I + initialy wrote and tested this code on x86 machine and wrote the + digests out in machine-dependent order :( There are people using + this code and I cannot change this easily without making existing + data files unreadable. + +*/ + +#include +#include +#include "cryptlib.h" +#include +#include +#include +#include + +static int ok_write(BIO *h,char *buf,int num); +static int ok_read(BIO *h,char *buf,int size); +static long ok_ctrl(BIO *h,int cmd,long arg1,char *arg2); +static int ok_new(BIO *h); +static int ok_free(BIO *data); +static void sig_out(BIO* b); +static void sig_in(BIO* b); +static void block_out(BIO* b); +static void block_in(BIO* b); +#define OK_BLOCK_SIZE (1024*4) +#define OK_BLOCK_BLOCK 4 +#define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE) +#define WELLKNOWN "The quick brown fox jumped over the lazy dog's back." + +#ifndef L_ENDIAN +#define swapem(x) \ + ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \ + (((unsigned long int)(x) & 0x0000ff00U) << 8) | \ + (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \ + (((unsigned long int)(x) & 0xff000000U) >> 24))) +#else +#define swapem(x) (x) +#endif + +typedef struct ok_struct + { + int buf_len; + int buf_off; + int buf_len_save; + int buf_off_save; + int cont; /* <= 0 when finished */ + int finished; + EVP_MD_CTX md; + int blockout; /* output block is ready */ + int sigio; /* must process signature */ + char buf[IOBS]; + } BIO_OK_CTX; + +static BIO_METHOD methods_ok= + { + BIO_TYPE_CIPHER,"reliable", + ok_write, + ok_read, + NULL, /* ok_puts, */ + NULL, /* ok_gets, */ + ok_ctrl, + ok_new, + ok_free, + }; + +BIO_METHOD *BIO_f_reliable(void) + { + return(&methods_ok); + } + +static int ok_new(BIO *bi) + { + BIO_OK_CTX *ctx; + + ctx=(BIO_OK_CTX *)Malloc(sizeof(BIO_OK_CTX)); + if (ctx == NULL) return(0); + + ctx->buf_len=0; + ctx->buf_off=0; + ctx->buf_len_save=0; + ctx->buf_off_save=0; + ctx->cont=1; + ctx->finished=0; + ctx->blockout= 0; + ctx->sigio=1; + + bi->init=0; + bi->ptr=(char *)ctx; + bi->flags=0; + return(1); + } + +static int ok_free(BIO *a) + { + if (a == NULL) return(0); + memset(a->ptr,0,sizeof(BIO_OK_CTX)); + Free(a->ptr); + a->ptr=NULL; + a->init=0; + a->flags=0; + return(1); + } + +static int ok_read(BIO *b, char *out, int outl) + { + int ret=0,i,n; + BIO_OK_CTX *ctx; + + if (out == NULL) return(0); + ctx=(BIO_OK_CTX *)b->ptr; + + if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0); + + while(outl > 0) + { + + /* copy clean bytes to output buffer */ + if (ctx->blockout) + { + i=ctx->buf_len-ctx->buf_off; + if (i > outl) i=outl; + memcpy(out,&(ctx->buf[ctx->buf_off]),i); + ret+=i; + out+=i; + outl-=i; + ctx->buf_off+=i; + + /* all clean bytes are out */ + if (ctx->buf_len == ctx->buf_off) + { + ctx->buf_off=0; + + /* copy start of the next block into proper place */ + if(ctx->buf_len_save- ctx->buf_off_save > 0) + { + ctx->buf_len= ctx->buf_len_save- ctx->buf_off_save; + memmove(ctx->buf, &(ctx->buf[ctx->buf_off_save]), + ctx->buf_len); + } + else + { + ctx->buf_len=0; + } + ctx->blockout= 0; + } + } + + /* output buffer full -- cancel */ + if (outl == 0) break; + + /* no clean bytes in buffer -- fill it */ + n=IOBS- ctx->buf_len; + i=BIO_read(b->next_bio,&(ctx->buf[ctx->buf_len]),n); + + if (i <= 0) break; /* nothing new */ + + ctx->buf_len+= i; + + /* no signature yet -- check if we got one */ + if (ctx->sigio == 1) sig_in(b); + + /* signature ok -- check if we got block */ + if (ctx->sigio == 0) block_in(b); + + /* invalid block -- cancel */ + if (ctx->cont <= 0) break; + + } + + BIO_clear_retry_flags(b); + BIO_copy_next_retry(b); + return(ret); + } + +static int ok_write(BIO *b, char *in, int inl) + { + int ret=0,n,i; + BIO_OK_CTX *ctx; + + ctx=(BIO_OK_CTX *)b->ptr; + ret=inl; + + if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0); + + if(ctx->sigio) sig_out(b); + + do{ + BIO_clear_retry_flags(b); + n=ctx->buf_len-ctx->buf_off; + while (ctx->blockout && n > 0) + { + i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); + if (i <= 0) + { + BIO_copy_next_retry(b); + if(!BIO_should_retry(b)) + ctx->cont= 0; + return(i); + } + ctx->buf_off+=i; + n-=i; + } + + /* at this point all pending data has been written */ + ctx->blockout= 0; + if (ctx->buf_len == ctx->buf_off) + { + ctx->buf_len=OK_BLOCK_BLOCK; + ctx->buf_off=0; + } + + if ((in == NULL) || (inl <= 0)) return(0); + + n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ? + OK_BLOCK_SIZE+ OK_BLOCK_BLOCK- ctx->buf_len : inl; + + memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n); + ctx->buf_len+= n; + inl-=n; + in+=n; + + if(ctx->buf_len >= OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) + { + block_out(b); + } + }while(inl > 0); + + BIO_clear_retry_flags(b); + BIO_copy_next_retry(b); + return(ret); + } + +static long ok_ctrl(BIO *b, int cmd, long num, char *ptr) + { + BIO_OK_CTX *ctx; + EVP_MD *md; + const EVP_MD **ppmd; + long ret=1; + int i; + + ctx=(BIO_OK_CTX *)b->ptr; + + switch (cmd) + { + case BIO_CTRL_RESET: + ctx->buf_len=0; + ctx->buf_off=0; + ctx->buf_len_save=0; + ctx->buf_off_save=0; + ctx->cont=1; + ctx->finished=0; + ctx->blockout= 0; + ctx->sigio=1; + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_CTRL_EOF: /* More to read */ + if (ctx->cont <= 0) + ret=1; + else + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_CTRL_PENDING: /* More to read in buffer */ + case BIO_CTRL_WPENDING: /* More to read in buffer */ + ret=ctx->blockout ? ctx->buf_len-ctx->buf_off : 0; + if (ret <= 0) + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_CTRL_FLUSH: + /* do a final write */ + if(ctx->blockout == 0) + block_out(b); + + while (ctx->blockout) + { + i=ok_write(b,NULL,0); + if (i < 0) + { + ret=i; + break; + } + } + + ctx->finished=1; + ctx->buf_off=ctx->buf_len=0; + ctx->cont=(int)ret; + + /* Finally flush the underlying BIO */ + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_C_DO_STATE_MACHINE: + BIO_clear_retry_flags(b); + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + BIO_copy_next_retry(b); + break; + case BIO_CTRL_INFO: + ret=(long)ctx->cont; + break; + case BIO_C_SET_MD: + md=(EVP_MD *)ptr; + EVP_DigestInit(&(ctx->md),md); + b->init=1; + break; + case BIO_C_GET_MD: + if (b->init) + { + ppmd=(const EVP_MD **)ptr; + *ppmd=ctx->md.digest; + } + else + ret=0; + break; + default: + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + } + return(ret); + } + +static void longswap(void *_ptr, int len) +{ +#ifndef L_ENDIAN + int i; + char *ptr=_ptr; + + for(i= 0;i < len;i+= 4){ + *((unsigned long *)&(ptr[i]))= swapem(*((unsigned long *)&(ptr[i]))); + } +#endif +} + +static void sig_out(BIO* b) + { + BIO_OK_CTX *ctx; + EVP_MD_CTX *md; + + ctx=(BIO_OK_CTX *)b->ptr; + md= &(ctx->md); + + if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return; + + EVP_DigestInit(md, md->digest); + RAND_bytes(&(md->md.base[0]), md->digest->md_size); + memcpy(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]), md->digest->md_size); + longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size); + ctx->buf_len+= md->digest->md_size; + + EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN)); + md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0])); + ctx->buf_len+= md->digest->md_size; + ctx->blockout= 1; + ctx->sigio= 0; + } + +static void sig_in(BIO* b) + { + BIO_OK_CTX *ctx; + EVP_MD_CTX *md; + unsigned char tmp[EVP_MAX_MD_SIZE]; + int ret= 0; + + ctx=(BIO_OK_CTX *)b->ptr; + md= &(ctx->md); + + if(ctx->buf_len- ctx->buf_off < 2* md->digest->md_size) return; + + EVP_DigestInit(md, md->digest); + memcpy(&(md->md.base[0]), &(ctx->buf[ctx->buf_off]), md->digest->md_size); + longswap(&(md->md.base[0]), md->digest->md_size); + ctx->buf_off+= md->digest->md_size; + + EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN)); + md->digest->final(tmp, &(md->md.base[0])); + ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0; + ctx->buf_off+= md->digest->md_size; + if(ret == 1) + { + ctx->sigio= 0; + if(ctx->buf_len != ctx->buf_off) + { + memmove(ctx->buf, &(ctx->buf[ctx->buf_off]), ctx->buf_len- ctx->buf_off); + } + ctx->buf_len-= ctx->buf_off; + ctx->buf_off= 0; + } + else + { + ctx->cont= 0; + } + } + +static void block_out(BIO* b) + { + BIO_OK_CTX *ctx; + EVP_MD_CTX *md; + unsigned long tl; + + ctx=(BIO_OK_CTX *)b->ptr; + md= &(ctx->md); + + tl= ctx->buf_len- OK_BLOCK_BLOCK; + tl= swapem(tl); + memcpy(ctx->buf, &tl, OK_BLOCK_BLOCK); + tl= swapem(tl); + EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl); + md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0])); + ctx->buf_len+= md->digest->md_size; + ctx->blockout= 1; + } + +static void block_in(BIO* b) + { + BIO_OK_CTX *ctx; + EVP_MD_CTX *md; + long tl= 0; + unsigned char tmp[EVP_MAX_MD_SIZE]; + + ctx=(BIO_OK_CTX *)b->ptr; + md= &(ctx->md); + + memcpy(&tl, ctx->buf, OK_BLOCK_BLOCK); + tl= swapem(tl); + if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return; + + EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl); + md->digest->final(tmp, &(md->md.base[0])); + if(memcmp(&(ctx->buf[tl+ OK_BLOCK_BLOCK]), tmp, md->digest->md_size) == 0) + { + /* there might be parts from next block lurking around ! */ + ctx->buf_off_save= tl+ OK_BLOCK_BLOCK+ md->digest->md_size; + ctx->buf_len_save= ctx->buf_len; + ctx->buf_off= OK_BLOCK_BLOCK; + ctx->buf_len= tl+ OK_BLOCK_BLOCK; + ctx->blockout= 1; + } + else + { + ctx->cont= 0; + } + } + diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c index e77d1c896b..a4d3b43fb9 100644 --- a/src/lib/libcrypto/evp/c_all.c +++ b/src/lib/libcrypto/evp/c_all.c @@ -58,16 +58,17 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include +#include -void SSLeay_add_all_algorithms() +void SSLeay_add_all_algorithms(void) { SSLeay_add_all_ciphers(); SSLeay_add_all_digests(); } -void SSLeay_add_all_ciphers() +void SSLeay_add_all_ciphers(void) { #ifndef NO_DES EVP_add_cipher(EVP_des_cfb()); @@ -79,16 +80,16 @@ void SSLeay_add_all_ciphers() EVP_add_cipher(EVP_des_ede3_ofb()); EVP_add_cipher(EVP_desx_cbc()); - EVP_add_alias(SN_desx_cbc,"DESX"); - EVP_add_alias(SN_desx_cbc,"desx"); + EVP_add_cipher_alias(SN_desx_cbc,"DESX"); + EVP_add_cipher_alias(SN_desx_cbc,"desx"); EVP_add_cipher(EVP_des_cbc()); - EVP_add_alias(SN_des_cbc,"DES"); - EVP_add_alias(SN_des_cbc,"des"); + EVP_add_cipher_alias(SN_des_cbc,"DES"); + EVP_add_cipher_alias(SN_des_cbc,"des"); EVP_add_cipher(EVP_des_ede_cbc()); EVP_add_cipher(EVP_des_ede3_cbc()); - EVP_add_alias(SN_des_ede3_cbc,"DES3"); - EVP_add_alias(SN_des_ede3_cbc,"des3"); + EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3"); + EVP_add_cipher_alias(SN_des_ede3_cbc,"des3"); EVP_add_cipher(EVP_des_ecb()); EVP_add_cipher(EVP_des_ede()); @@ -105,8 +106,8 @@ void SSLeay_add_all_ciphers() EVP_add_cipher(EVP_idea_cfb()); EVP_add_cipher(EVP_idea_ofb()); EVP_add_cipher(EVP_idea_cbc()); - EVP_add_alias(SN_idea_cbc,"IDEA"); - EVP_add_alias(SN_idea_cbc,"idea"); + EVP_add_cipher_alias(SN_idea_cbc,"IDEA"); + EVP_add_cipher_alias(SN_idea_cbc,"idea"); #endif #ifndef NO_RC2 @@ -115,18 +116,19 @@ void SSLeay_add_all_ciphers() EVP_add_cipher(EVP_rc2_ofb()); EVP_add_cipher(EVP_rc2_cbc()); EVP_add_cipher(EVP_rc2_40_cbc()); - EVP_add_alias(SN_rc2_cbc,"RC2"); - EVP_add_alias(SN_rc2_cbc,"rc2"); + EVP_add_cipher(EVP_rc2_64_cbc()); + EVP_add_cipher_alias(SN_rc2_cbc,"RC2"); + EVP_add_cipher_alias(SN_rc2_cbc,"rc2"); #endif -#ifndef NO_BLOWFISH +#ifndef NO_BF EVP_add_cipher(EVP_bf_ecb()); EVP_add_cipher(EVP_bf_cfb()); EVP_add_cipher(EVP_bf_ofb()); EVP_add_cipher(EVP_bf_cbc()); - EVP_add_alias(SN_bf_cbc,"BF"); - EVP_add_alias(SN_bf_cbc,"bf"); - EVP_add_alias(SN_bf_cbc,"blowfish"); + EVP_add_cipher_alias(SN_bf_cbc,"BF"); + EVP_add_cipher_alias(SN_bf_cbc,"bf"); + EVP_add_cipher_alias(SN_bf_cbc,"blowfish"); #endif #ifndef NO_CAST @@ -134,10 +136,10 @@ void SSLeay_add_all_ciphers() EVP_add_cipher(EVP_cast5_cfb()); EVP_add_cipher(EVP_cast5_ofb()); EVP_add_cipher(EVP_cast5_cbc()); - EVP_add_alias(SN_cast5_cbc,"CAST"); - EVP_add_alias(SN_cast5_cbc,"cast"); - EVP_add_alias(SN_cast5_cbc,"CAST-cbc"); - EVP_add_alias(SN_cast5_cbc,"cast-cbc"); + EVP_add_cipher_alias(SN_cast5_cbc,"CAST"); + EVP_add_cipher_alias(SN_cast5_cbc,"cast"); + EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc"); + EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc"); #endif #ifndef NO_RC5 @@ -145,23 +147,21 @@ void SSLeay_add_all_ciphers() EVP_add_cipher(EVP_rc5_32_12_16_cfb()); EVP_add_cipher(EVP_rc5_32_12_16_ofb()); EVP_add_cipher(EVP_rc5_32_12_16_cbc()); - EVP_add_alias(SN_rc5_cbc,"rc5"); - EVP_add_alias(SN_rc5_cbc,"RC5"); - EVP_add_alias(SN_rc5_cbc,"rc5-cbc"); - EVP_add_alias(SN_rc5_cbc,"RC5-cbc"); + EVP_add_cipher_alias(SN_rc5_cbc,"rc5"); + EVP_add_cipher_alias(SN_rc5_cbc,"RC5"); #endif } -void SSLeay_add_all_digests() +void SSLeay_add_all_digests(void) { #ifndef NO_MD2 EVP_add_digest(EVP_md2()); #endif #ifndef NO_MD5 EVP_add_digest(EVP_md5()); - EVP_add_alias(SN_md5,"ssl2-md5"); - EVP_add_alias(SN_md5,"ssl3-md5"); + EVP_add_digest_alias(SN_md5,"ssl2-md5"); + EVP_add_digest_alias(SN_md5,"ssl3-md5"); #endif #ifndef NO_SHA EVP_add_digest(EVP_sha()); @@ -169,22 +169,25 @@ void SSLeay_add_all_digests() EVP_add_digest(EVP_dss()); #endif #endif -#ifndef NO_SHA1 +#ifndef NO_SHA EVP_add_digest(EVP_sha1()); - EVP_add_alias(SN_sha1,"ssl3-sha1"); + EVP_add_digest_alias(SN_sha1,"ssl3-sha1"); + EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA); #ifndef NO_DSA EVP_add_digest(EVP_dss1()); - EVP_add_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2); - EVP_add_alias(SN_dsaWithSHA1,"DSS1"); - EVP_add_alias(SN_dsaWithSHA1,"dss1"); + EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2); + EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1"); + EVP_add_digest_alias(SN_dsaWithSHA1,"dss1"); #endif #endif #if !defined(NO_MDC2) && !defined(NO_DES) EVP_add_digest(EVP_mdc2()); #endif -#ifndef NO_RIPEMD160 +#ifndef NO_RIPEMD EVP_add_digest(EVP_ripemd160()); - EVP_add_alias(SN_ripemd160,"ripemd"); - EVP_add_alias(SN_ripemd160,"rmd160"); + EVP_add_digest_alias(SN_ripemd160,"ripemd"); + EVP_add_digest_alias(SN_ripemd160,"rmd160"); #endif + PKCS12_PBE_add(); + PKCS5_PBE_add(); } diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index d65f0036f7..c560733568 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c @@ -58,32 +58,35 @@ #include #include "cryptlib.h" -#include "objects.h" -#include "evp.h" +#include +#include -void EVP_DigestInit(ctx,type) -EVP_MD_CTX *ctx; -EVP_MD *type; +void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) { ctx->digest=type; type->init(&(ctx->md)); } -void EVP_DigestUpdate(ctx,data,count) -EVP_MD_CTX *ctx; -unsigned char *data; -unsigned int count; +void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, + unsigned int count) { ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count); } -void EVP_DigestFinal(ctx,md,size) -EVP_MD_CTX *ctx; -unsigned char *md; -unsigned int *size; +void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) { ctx->digest->final(md,&(ctx->md.base[0])); if (size != NULL) *size=ctx->digest->md_size; memset(&(ctx->md),0,sizeof(ctx->md)); } + +int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in) +{ + if ((in == NULL) || (in->digest == NULL)) { + EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); + return 0; + } + memcpy((char *)out,(char *)in,in->digest->ctx_size); + return 1; +} diff --git a/src/lib/libcrypto/evp/e_cbc_3d.c b/src/lib/libcrypto/evp/e_cbc_3d.c index 5761bf186a..02ccc6dc90 100644 --- a/src/lib/libcrypto/evp/e_cbc_3d.c +++ b/src/lib/libcrypto/evp/e_cbc_3d.c @@ -56,24 +56,18 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DES #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void des_cbc_ede_init_key(); -static void des_cbc_ede3_init_key(); -static void des_cbc_ede_cipher(); -#endif - static EVP_CIPHER d_cbc_ede_cipher2= { NID_des_ede_cbc, @@ -83,8 +77,8 @@ static EVP_CIPHER d_cbc_ede_cipher2= NULL, sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ sizeof((((EVP_CIPHER_CTX *)NULL)->c.des_ede)), - EVP_CIPHER_get_asn1_iv, EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, }; static EVP_CIPHER d_cbc_ede_cipher3= @@ -100,64 +94,58 @@ static EVP_CIPHER d_cbc_ede_cipher3= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_des_ede_cbc() +EVP_CIPHER *EVP_des_ede_cbc(void) { return(&d_cbc_ede_cipher2); } -EVP_CIPHER *EVP_des_ede3_cbc() +EVP_CIPHER *EVP_des_ede3_cbc(void) { return(&d_cbc_ede_cipher3); } -static void des_cbc_ede_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); - des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); + des_set_key(&deskey[0],ctx->c.des_ede.ks1); + des_set_key(&deskey[1],ctx->c.des_ede.ks2); memcpy( (char *)ctx->c.des_ede.ks3, (char *)ctx->c.des_ede.ks1, sizeof(ctx->c.des_ede.ks1)); } } -static void des_cbc_ede3_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); - des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); - des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); + des_set_key(&deskey[0],ctx->c.des_ede.ks1); + des_set_key(&deskey[1],ctx->c.des_ede.ks2); + des_set_key(&deskey[2],ctx->c.des_ede.ks3); } } -static void des_cbc_ede_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { - des_ede3_cbc_encrypt( - (des_cblock *)in,(des_cblock *)out, - (long)inl, ctx->c.des_ede.ks1, + des_ede3_cbc_encrypt(in,out,inl, ctx->c.des_ede.ks1, ctx->c.des_ede.ks2,ctx->c.des_ede.ks3, - (des_cblock *)&(ctx->iv[0]), + (des_cblock *) &(ctx->iv[0]), ctx->encrypt); } +#endif diff --git a/src/lib/libcrypto/evp/e_cbc_bf.c b/src/lib/libcrypto/evp/e_cbc_bf.c index be605f4a13..9bcba3c516 100644 --- a/src/lib/libcrypto/evp/e_cbc_bf.c +++ b/src/lib/libcrypto/evp/e_cbc_bf.c @@ -56,23 +56,16 @@ * [including the GNU Public Licence.] */ -#ifndef NO_BLOWFISH - +#ifndef NO_BF #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void bf_cbc_init_key(); -static void bf_cbc_cipher(); -#endif - static EVP_CIPHER bfish_cbc_cipher= { NID_bf_cbc, @@ -82,20 +75,17 @@ static EVP_CIPHER bfish_cbc_cipher= NULL, sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ sizeof((((EVP_CIPHER_CTX *)NULL)->c.bf_ks)), - EVP_CIPHER_get_asn1_iv, EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_bf_cbc() +EVP_CIPHER *EVP_bf_cbc(void) { return(&bfish_cbc_cipher); } -static void bf_cbc_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); @@ -104,11 +94,8 @@ int enc; BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); } -static void bf_cbc_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { BF_cbc_encrypt( in,out,(long)inl, diff --git a/src/lib/libcrypto/evp/e_cbc_c.c b/src/lib/libcrypto/evp/e_cbc_c.c index b50c7874b3..6845b0b44c 100644 --- a/src/lib/libcrypto/evp/e_cbc_c.c +++ b/src/lib/libcrypto/evp/e_cbc_c.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void cast_cbc_init_key(); -static void cast_cbc_cipher(); -#endif - static EVP_CIPHER cast5_cbc_cipher= { NID_cast5_cbc, @@ -82,20 +76,17 @@ static EVP_CIPHER cast5_cbc_cipher= NULL, sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ sizeof((((EVP_CIPHER_CTX *)NULL)->c.cast_ks)), - EVP_CIPHER_get_asn1_iv, EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_cast5_cbc() +EVP_CIPHER *EVP_cast5_cbc(void) { return(&cast5_cbc_cipher); } -static void cast_cbc_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); @@ -104,11 +95,8 @@ int enc; CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key); } -static void cast_cbc_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { CAST_cbc_encrypt( in,out,(long)inl, diff --git a/src/lib/libcrypto/evp/e_cbc_d.c b/src/lib/libcrypto/evp/e_cbc_d.c index c67706e3a0..9203f3f52d 100644 --- a/src/lib/libcrypto/evp/e_cbc_d.c +++ b/src/lib/libcrypto/evp/e_cbc_d.c @@ -56,21 +56,16 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DES #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void des_cbc_init_key(); -static void des_cbc_cipher(); -#endif - static EVP_CIPHER d_cbc_cipher= { NID_des_cbc, @@ -80,37 +75,32 @@ static EVP_CIPHER d_cbc_cipher= NULL, sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ sizeof((((EVP_CIPHER_CTX *)NULL)->c.des_ks)), - EVP_CIPHER_get_asn1_iv, EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_des_cbc() +EVP_CIPHER *EVP_des_cbc(void) { return(&d_cbc_cipher); } -static void des_cbc_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) - des_set_key((des_cblock *)key,ctx->c.des_ks); + if (deskey != NULL) + des_set_key(deskey,ctx->c.des_ks); } -static void des_cbc_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { - des_ncbc_encrypt( - (des_cblock *)in,(des_cblock *)out, - (long)inl, ctx->c.des_ks, + des_ncbc_encrypt(in,out,inl,ctx->c.des_ks, (des_cblock *)&(ctx->iv[0]), ctx->encrypt); } +#endif diff --git a/src/lib/libcrypto/evp/e_cbc_i.c b/src/lib/libcrypto/evp/e_cbc_i.c index 312ffcb721..34b44aa21f 100644 --- a/src/lib/libcrypto/evp/e_cbc_i.c +++ b/src/lib/libcrypto/evp/e_cbc_i.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void idea_cbc_init_key(); -static void idea_cbc_cipher(); -#endif - static EVP_CIPHER i_cbc_cipher= { NID_idea_cbc, @@ -82,20 +76,17 @@ static EVP_CIPHER i_cbc_cipher= NULL, sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ sizeof((((EVP_CIPHER_CTX *)NULL)->c.idea_ks)), - EVP_CIPHER_get_asn1_iv, EVP_CIPHER_set_asn1_iv, + EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_idea_cbc() +EVP_CIPHER *EVP_idea_cbc(void) { return(&i_cbc_cipher); } -static void idea_cbc_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); @@ -116,11 +107,8 @@ int enc; } } -static void idea_cbc_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { idea_cbc_encrypt( in,out,(long)inl, diff --git a/src/lib/libcrypto/evp/e_cbc_r2.c b/src/lib/libcrypto/evp/e_cbc_r2.c index 4f8002f16d..9dfada4ea6 100644 --- a/src/lib/libcrypto/evp/e_cbc_r2.c +++ b/src/lib/libcrypto/evp/e_cbc_r2.c @@ -60,18 +60,21 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void rc2_cbc_init_key(); -static void rc2_cbc_cipher(); -#endif +static int rc2_meth_to_magic(const EVP_CIPHER *e); +static EVP_CIPHER *rc2_magic_to_meth(int i); +static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); +static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type); + +#define RC2_40_MAGIC 0xa0 +#define RC2_64_MAGIC 0x78 +#define RC2_128_MAGIC 0x3a static EVP_CIPHER r2_cbc_cipher= { @@ -82,8 +85,21 @@ static EVP_CIPHER r2_cbc_cipher= NULL, sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)), - EVP_CIPHER_get_asn1_iv, - EVP_CIPHER_set_asn1_iv, + rc2_set_asn1_type_and_iv, + rc2_get_asn1_type_and_iv, + }; + +static EVP_CIPHER r2_64_cbc_cipher= + { + NID_rc2_64_cbc, + 8,8 /* 64 bit */,8, + rc2_cbc_init_key, + rc2_cbc_cipher, + NULL, + sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ + sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)), + rc2_set_asn1_type_and_iv, + rc2_get_asn1_type_and_iv, }; static EVP_CIPHER r2_40_cbc_cipher= @@ -95,23 +111,27 @@ static EVP_CIPHER r2_40_cbc_cipher= NULL, sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)), + rc2_set_asn1_type_and_iv, + rc2_get_asn1_type_and_iv, }; -EVP_CIPHER *EVP_rc2_cbc() +EVP_CIPHER *EVP_rc2_cbc(void) { return(&r2_cbc_cipher); } -EVP_CIPHER *EVP_rc2_40_cbc() +EVP_CIPHER *EVP_rc2_64_cbc(void) + { + return(&r2_64_cbc_cipher); + } + +EVP_CIPHER *EVP_rc2_40_cbc(void) { return(&r2_40_cbc_cipher); } -static void rc2_cbc_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); @@ -121,11 +141,8 @@ int enc; key,EVP_CIPHER_CTX_key_length(ctx)*8); } -static void rc2_cbc_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { RC2_cbc_encrypt( in,out,(long)inl, @@ -133,4 +150,67 @@ unsigned int inl; ctx->encrypt); } +static int rc2_meth_to_magic(const EVP_CIPHER *e) + { + int i; + + i=EVP_CIPHER_key_length(e); + if (i == 16) return(RC2_128_MAGIC); + else if (i == 8) return(RC2_64_MAGIC); + else if (i == 5) return(RC2_40_MAGIC); + else return(0); + } + +static EVP_CIPHER *rc2_magic_to_meth(int i) + { + if (i == RC2_128_MAGIC) return(EVP_rc2_cbc()); + else if (i == RC2_64_MAGIC) return(EVP_rc2_64_cbc()); + else if (i == RC2_40_MAGIC) return(EVP_rc2_40_cbc()); + else + { + EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE); + return(NULL); + } + } + +static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) + { + long num=0; + int i=0,l; + EVP_CIPHER *e; + + if (type != NULL) + { + l=EVP_CIPHER_CTX_iv_length(c); + i=ASN1_TYPE_get_int_octetstring(type,&num,c->oiv,l); + if (i != l) + return(-1); + else if (i > 0) + memcpy(c->iv,c->oiv,l); + e=rc2_magic_to_meth((int)num); + if (e == NULL) + return(-1); + if (e != EVP_CIPHER_CTX_cipher(c)) + { + EVP_CIPHER_CTX_cipher(c)=e; + rc2_cbc_init_key(c,NULL,NULL,1); + } + } + return(i); + } + +static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) + { + long num; + int i=0,j; + + if (type != NULL) + { + num=rc2_meth_to_magic(EVP_CIPHER_CTX_cipher(c)); + j=EVP_CIPHER_CTX_iv_length(c); + i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j); + } + return(i); + } + #endif diff --git a/src/lib/libcrypto/evp/e_cbc_r5.c b/src/lib/libcrypto/evp/e_cbc_r5.c index f7d46ca91f..cea3fe333a 100644 --- a/src/lib/libcrypto/evp/e_cbc_r5.c +++ b/src/lib/libcrypto/evp/e_cbc_r5.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void r_32_12_16_cbc_init_key(); -static void r_32_12_16_cbc_cipher(); -#endif - static EVP_CIPHER rc5_32_12_16_cbc_cipher= { NID_rc5_cbc, @@ -86,16 +80,13 @@ static EVP_CIPHER rc5_32_12_16_cbc_cipher= NULL, }; -EVP_CIPHER *EVP_rc5_32_12_16_cbc() +EVP_CIPHER *EVP_rc5_32_12_16_cbc(void) { return(&rc5_32_12_16_cbc_cipher); } -static void r_32_12_16_cbc_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); @@ -105,11 +96,8 @@ int enc; key,RC5_12_ROUNDS); } -static void r_32_12_16_cbc_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { RC5_32_cbc_encrypt( in,out,(long)inl, diff --git a/src/lib/libcrypto/evp/e_cfb_3d.c b/src/lib/libcrypto/evp/e_cfb_3d.c index e7e3419411..bd32b072e2 100644 --- a/src/lib/libcrypto/evp/e_cfb_3d.c +++ b/src/lib/libcrypto/evp/e_cfb_3d.c @@ -56,24 +56,18 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DES #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void des_ede_cfb_init_key(); -static void des_ede3_cfb_init_key(); -static void des_ede_cfb_cipher(); -#endif - static EVP_CIPHER d_ede_cfb_cipher2= { NID_des_ede_cfb64, @@ -100,67 +94,62 @@ static EVP_CIPHER d_ede3_cfb_cipher3= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_des_ede_cfb() +EVP_CIPHER *EVP_des_ede_cfb(void) { return(&d_ede_cfb_cipher2); } -EVP_CIPHER *EVP_des_ede3_cfb() +EVP_CIPHER *EVP_des_ede3_cfb(void) { return(&d_ede3_cfb_cipher3); } -static void des_ede_cfb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + ctx->num=0; if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); - des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); + des_set_key(&deskey[0],ctx->c.des_ede.ks1); + des_set_key(&deskey[1],ctx->c.des_ede.ks2); memcpy( (char *)ctx->c.des_ede.ks3, (char *)ctx->c.des_ede.ks1, sizeof(ctx->c.des_ede.ks1)); } } -static void des_ede3_cfb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + ctx->num=0; if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); - des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); - des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); + des_set_key(&deskey[0],ctx->c.des_ede.ks1); + des_set_key(&deskey[1],ctx->c.des_ede.ks2); + des_set_key(&deskey[2],ctx->c.des_ede.ks3); } } -static void des_ede_cfb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { - des_ede3_cfb64_encrypt( - in,out,(long)inl, - ctx->c.des_ede.ks1, - ctx->c.des_ede.ks2, - ctx->c.des_ede.ks3, - (des_cblock *)&(ctx->iv[0]), - &ctx->num,ctx->encrypt); + des_ede3_cfb64_encrypt(in,out,(long)inl, + ctx->c.des_ede.ks1, + ctx->c.des_ede.ks2, + ctx->c.des_ede.ks3, + (des_cblock*)&(ctx->iv[0]), + &ctx->num,ctx->encrypt); } +#endif diff --git a/src/lib/libcrypto/evp/e_cfb_bf.c b/src/lib/libcrypto/evp/e_cfb_bf.c index 8aba2564b8..63e1e624ea 100644 --- a/src/lib/libcrypto/evp/e_cfb_bf.c +++ b/src/lib/libcrypto/evp/e_cfb_bf.c @@ -56,23 +56,16 @@ * [including the GNU Public Licence.] */ -#ifndef NO_BLOWFISH - +#ifndef NO_BF #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void bf_cfb_init_key(); -static void bf_cfb_cipher(); -#endif - static EVP_CIPHER bfish_cfb_cipher= { NID_bf_cfb64, @@ -86,16 +79,13 @@ static EVP_CIPHER bfish_cfb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_bf_cfb() +EVP_CIPHER *EVP_bf_cfb(void) { return(&bfish_cfb_cipher); } -static void bf_cfb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -106,11 +96,8 @@ int enc; BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); } -static void bf_cfb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { BF_cfb64_encrypt( in,out, diff --git a/src/lib/libcrypto/evp/e_cfb_c.c b/src/lib/libcrypto/evp/e_cfb_c.c index 936df55fd8..f04bac034b 100644 --- a/src/lib/libcrypto/evp/e_cfb_c.c +++ b/src/lib/libcrypto/evp/e_cfb_c.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void cast_cfb_init_key(); -static void cast_cfb_cipher(); -#endif - static EVP_CIPHER cast5_cfb_cipher= { NID_cast5_cfb64, @@ -86,16 +80,13 @@ static EVP_CIPHER cast5_cfb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_cast5_cfb() +EVP_CIPHER *EVP_cast5_cfb(void) { return(&cast5_cfb_cipher); } -static void cast_cfb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -106,11 +97,8 @@ int enc; CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key); } -static void cast_cfb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { CAST_cfb64_encrypt( in,out, diff --git a/src/lib/libcrypto/evp/e_cfb_d.c b/src/lib/libcrypto/evp/e_cfb_d.c index 9ae4558f51..6bdf20b646 100644 --- a/src/lib/libcrypto/evp/e_cfb_d.c +++ b/src/lib/libcrypto/evp/e_cfb_d.c @@ -58,19 +58,14 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO +#ifndef NO_DES static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void des_cfb_init_key(); -static void des_cfb_cipher(); -#endif - static EVP_CIPHER d_cfb_cipher= { NID_des_cfb64, @@ -84,31 +79,27 @@ static EVP_CIPHER d_cfb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_des_cfb() +EVP_CIPHER *EVP_des_cfb(void) { return(&d_cfb_cipher); } -static void des_cfb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + ctx->num=0; if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) - des_set_key((des_cblock *)key,ctx->c.des_ks); + if (deskey != NULL) + des_set_key(deskey,ctx->c.des_ks); } -static void des_cfb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { des_cfb64_encrypt( in,out, @@ -116,3 +107,4 @@ unsigned int inl; (des_cblock *)&(ctx->iv[0]), &ctx->num,ctx->encrypt); } +#endif diff --git a/src/lib/libcrypto/evp/e_cfb_i.c b/src/lib/libcrypto/evp/e_cfb_i.c index 9225efaa86..31c76c6dac 100644 --- a/src/lib/libcrypto/evp/e_cfb_i.c +++ b/src/lib/libcrypto/evp/e_cfb_i.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void idea_cfb_init_key(); -static void idea_cfb_cipher(); -#endif - static EVP_CIPHER i_cfb_cipher= { NID_idea_cfb64, @@ -86,16 +80,13 @@ static EVP_CIPHER i_cfb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_idea_cfb() +EVP_CIPHER *EVP_idea_cfb(void) { return(&i_cfb_cipher); } -static void idea_cfb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -106,11 +97,8 @@ int enc; idea_set_encrypt_key(key,&(ctx->c.idea_ks)); } -static void idea_cfb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { idea_cfb64_encrypt( in,out,(long)inl, diff --git a/src/lib/libcrypto/evp/e_cfb_r2.c b/src/lib/libcrypto/evp/e_cfb_r2.c index af5a39d1f4..32dd77eb7c 100644 --- a/src/lib/libcrypto/evp/e_cfb_r2.c +++ b/src/lib/libcrypto/evp/e_cfb_r2.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void rc2_cfb_init_key(); -static void rc2_cfb_cipher(); -#endif - static EVP_CIPHER r2_cfb_cipher= { NID_rc2_cfb64, @@ -86,16 +80,13 @@ static EVP_CIPHER r2_cfb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_rc2_cfb() +EVP_CIPHER *EVP_rc2_cfb(void) { return(&r2_cfb_cipher); } -static void rc2_cfb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -103,15 +94,12 @@ int enc; memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (key != NULL) - RC2_set_key(&(ctx->c.rc2_ks),EVP_RC2_KEY_SIZE,key, - EVP_RC2_KEY_SIZE*8); + RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx), + key,EVP_CIPHER_CTX_key_length(ctx)*8); } -static void rc2_cfb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { RC2_cfb64_encrypt( in,out, diff --git a/src/lib/libcrypto/evp/e_cfb_r5.c b/src/lib/libcrypto/evp/e_cfb_r5.c index a2fddaedc0..8e79728946 100644 --- a/src/lib/libcrypto/evp/e_cfb_r5.c +++ b/src/lib/libcrypto/evp/e_cfb_r5.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void rc5_32_12_16_cfb_init_key(); -static void rc5_32_12_16_cfb_cipher(); -#endif - static EVP_CIPHER rc5_cfb_cipher= { NID_rc5_cfb64, @@ -86,16 +80,13 @@ static EVP_CIPHER rc5_cfb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_rc5_32_12_16_cfb() +EVP_CIPHER *EVP_rc5_32_12_16_cfb(void) { return(&rc5_cfb_cipher); } -static void rc5_32_12_16_cfb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -107,11 +98,8 @@ int enc; RC5_12_ROUNDS); } -static void rc5_32_12_16_cfb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { RC5_32_cfb64_encrypt( in,out, diff --git a/src/lib/libcrypto/evp/e_dsa.c b/src/lib/libcrypto/evp/e_dsa.c index 6715c3e95e..b96f2738b3 100644 --- a/src/lib/libcrypto/evp/e_dsa.c +++ b/src/lib/libcrypto/evp/e_dsa.c @@ -58,9 +58,9 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include static EVP_PKEY_METHOD dss_method= { diff --git a/src/lib/libcrypto/evp/e_ecb_3d.c b/src/lib/libcrypto/evp/e_ecb_3d.c index 908fc0760a..354a8b79a7 100644 --- a/src/lib/libcrypto/evp/e_ecb_3d.c +++ b/src/lib/libcrypto/evp/e_ecb_3d.c @@ -56,24 +56,18 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DES #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void des_ede_init_key(); -static void des_ede3_init_key(); -static void des_ede_cipher(); -#endif - static EVP_CIPHER d_ede_cipher2= { NID_des_ede, @@ -99,63 +93,66 @@ static EVP_CIPHER d_ede3_cipher3= NULL, }; -EVP_CIPHER *EVP_des_ede() +EVP_CIPHER *EVP_des_ede(void) { return(&d_ede_cipher2); } -EVP_CIPHER *EVP_des_ede3() +EVP_CIPHER *EVP_des_ede3(void) { return(&d_ede3_cipher3); } -static void des_ede_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { - if (key != NULL) + des_cblock *deskey = (des_cblock *)key; + + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); - des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); + des_set_key(&deskey[0],ctx->c.des_ede.ks1); + des_set_key(&deskey[1],ctx->c.des_ede.ks2); memcpy( (char *)ctx->c.des_ede.ks3, (char *)ctx->c.des_ede.ks1, sizeof(ctx->c.des_ede.ks1)); } } -static void des_ede3_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { - if (key != NULL) + des_cblock *deskey = (des_cblock *)key; + + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); - des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); - des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); + des_set_key(&deskey[0],ctx->c.des_ede.ks1); + des_set_key(&deskey[1],ctx->c.des_ede.ks2); + des_set_key(&deskey[2],ctx->c.des_ede.ks3); } } -static void des_ede_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { unsigned int i; + des_cblock *output /* = (des_cblock *)out */; + des_cblock *input /* = (des_cblock *)in */; if (inl < 8) return; inl-=8; for (i=0; i<=inl; i+=8) { - des_ecb3_encrypt( - (des_cblock *)&(in[i]),(des_cblock *)&(out[i]), + output = (des_cblock *)(out + i); + input = (des_cblock *)(in + i); + + des_ecb3_encrypt(input,output, ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, ctx->encrypt); + + /* output++; */ + /* input++; */ } } +#endif diff --git a/src/lib/libcrypto/evp/e_ecb_bf.c b/src/lib/libcrypto/evp/e_ecb_bf.c index 142a9d3123..334736d253 100644 --- a/src/lib/libcrypto/evp/e_ecb_bf.c +++ b/src/lib/libcrypto/evp/e_ecb_bf.c @@ -56,23 +56,16 @@ * [including the GNU Public Licence.] */ -#ifndef NO_BLOWFISH - +#ifndef NO_BF #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void bf_ecb_init_key(); -static void bf_ecb_cipher(); -#endif - static EVP_CIPHER bfish_ecb_cipher= { NID_bf_ecb, @@ -86,26 +79,20 @@ static EVP_CIPHER bfish_ecb_cipher= NULL, }; -EVP_CIPHER *EVP_bf_ecb() +EVP_CIPHER *EVP_bf_ecb(void) { return(&bfish_ecb_cipher); } -static void bf_ecb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (key != NULL) BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); } -static void bf_ecb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { unsigned int i; diff --git a/src/lib/libcrypto/evp/e_ecb_c.c b/src/lib/libcrypto/evp/e_ecb_c.c index 34e0c18296..ad14e203cb 100644 --- a/src/lib/libcrypto/evp/e_ecb_c.c +++ b/src/lib/libcrypto/evp/e_ecb_c.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void cast_ecb_init_key(); -static void cast_ecb_cipher(); -#endif - static EVP_CIPHER cast5_ecb_cipher= { NID_cast5_ecb, @@ -86,26 +80,20 @@ static EVP_CIPHER cast5_ecb_cipher= NULL, }; -EVP_CIPHER *EVP_cast5_ecb() +EVP_CIPHER *EVP_cast5_ecb(void) { return(&cast5_ecb_cipher); } -static void cast_ecb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (key != NULL) CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key); } -static void cast_ecb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { unsigned int i; diff --git a/src/lib/libcrypto/evp/e_ecb_d.c b/src/lib/libcrypto/evp/e_ecb_d.c index 7a409d6459..5fb4e64b1c 100644 --- a/src/lib/libcrypto/evp/e_ecb_d.c +++ b/src/lib/libcrypto/evp/e_ecb_d.c @@ -56,21 +56,16 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DES #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void des_ecb_init_key(); -static void des_ecb_cipher(); -#endif - static EVP_CIPHER d_ecb_cipher= { NID_des_ecb, @@ -84,35 +79,40 @@ static EVP_CIPHER d_ecb_cipher= NULL, }; -EVP_CIPHER *EVP_des_ecb() +EVP_CIPHER *EVP_des_ecb(void) { return(&d_ecb_cipher); } -static void des_ecb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { - if (key != NULL) - des_set_key((des_cblock *)key,ctx->c.des_ks); + des_cblock *deskey = (des_cblock *)key; + + if (deskey != NULL) + des_set_key(deskey,ctx->c.des_ks); } -static void des_ecb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { unsigned int i; + des_cblock *output /* = (des_cblock *)out */; + des_cblock *input /* = (des_cblock *)in */; if (inl < 8) return; inl-=8; for (i=0; i<=inl; i+=8) { - des_ecb_encrypt( - (des_cblock *)&(in[i]),(des_cblock *)&(out[i]), - ctx->c.des_ks,ctx->encrypt); + /* Either this ... */ + output = (des_cblock *)(out + i); + input = (des_cblock *)(in + i); + + des_ecb_encrypt(input,output,ctx->c.des_ks,ctx->encrypt); + + /* ... or this. */ + /* output++; */ + /* input++; */ } } +#endif diff --git a/src/lib/libcrypto/evp/e_ecb_i.c b/src/lib/libcrypto/evp/e_ecb_i.c index e24022a12c..50a3da1bba 100644 --- a/src/lib/libcrypto/evp/e_ecb_i.c +++ b/src/lib/libcrypto/evp/e_ecb_i.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void idea_ecb_init_key(); -static void idea_ecb_cipher(); -#endif - static EVP_CIPHER i_ecb_cipher= { NID_idea_ecb, @@ -86,16 +80,13 @@ static EVP_CIPHER i_ecb_cipher= NULL, }; -EVP_CIPHER *EVP_idea_ecb() +EVP_CIPHER *EVP_idea_ecb(void) { return(&i_ecb_cipher); } -static void idea_ecb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (key != NULL) { @@ -113,11 +104,8 @@ int enc; } } -static void idea_ecb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { unsigned int i; diff --git a/src/lib/libcrypto/evp/e_ecb_r2.c b/src/lib/libcrypto/evp/e_ecb_r2.c index e35b06dc6d..3c2330130d 100644 --- a/src/lib/libcrypto/evp/e_ecb_r2.c +++ b/src/lib/libcrypto/evp/e_ecb_r2.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void rc2_ecb_init_key(); -static void rc2_ecb_cipher(); -#endif - static EVP_CIPHER r2_ecb_cipher= { NID_rc2_ecb, @@ -86,27 +80,21 @@ static EVP_CIPHER r2_ecb_cipher= NULL, }; -EVP_CIPHER *EVP_rc2_ecb() +EVP_CIPHER *EVP_rc2_ecb(void) { return(&r2_ecb_cipher); } -static void rc2_ecb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (key != NULL) - RC2_set_key(&(ctx->c.rc2_ks),EVP_RC2_KEY_SIZE,key, - EVP_RC2_KEY_SIZE*8); + RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx), + key,EVP_CIPHER_CTX_key_length(ctx)*8); } -static void rc2_ecb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { unsigned int i; diff --git a/src/lib/libcrypto/evp/e_ecb_r5.c b/src/lib/libcrypto/evp/e_ecb_r5.c index 08f4a82651..ef43ce34bf 100644 --- a/src/lib/libcrypto/evp/e_ecb_r5.c +++ b/src/lib/libcrypto/evp/e_ecb_r5.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void rc5_32_12_16_ecb_init_key(); -static void rc5_32_12_16_ecb_cipher(); -#endif - static EVP_CIPHER rc5_ecb_cipher= { NID_rc5_ecb, @@ -86,27 +80,21 @@ static EVP_CIPHER rc5_ecb_cipher= NULL, }; -EVP_CIPHER *EVP_rc5_32_12_16_ecb() +EVP_CIPHER *EVP_rc5_32_12_16_ecb(void) { return(&rc5_ecb_cipher); } -static void rc5_32_12_16_ecb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (key != NULL) RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key, RC5_12_ROUNDS); } -static void rc5_32_12_16_ecb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { unsigned int i; diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c index e4e7ca7606..0a62c10aa9 100644 --- a/src/lib/libcrypto/evp/e_null.c +++ b/src/lib/libcrypto/evp/e_null.c @@ -58,19 +58,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void null_init_key(); -static void null_cipher(); -#endif - static EVP_CIPHER n_cipher= { NID_undef, @@ -83,25 +77,19 @@ static EVP_CIPHER n_cipher= NULL, }; -EVP_CIPHER *EVP_enc_null() +EVP_CIPHER *EVP_enc_null(void) { return(&n_cipher); } -static void null_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { memset(&(ctx->c),0,sizeof(ctx->c)); } -static void null_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { if (in != out) memcpy((char *)out,(char *)in,(int)inl); diff --git a/src/lib/libcrypto/evp/e_ofb_3d.c b/src/lib/libcrypto/evp/e_ofb_3d.c index c3add18e93..5233567c0c 100644 --- a/src/lib/libcrypto/evp/e_ofb_3d.c +++ b/src/lib/libcrypto/evp/e_ofb_3d.c @@ -56,24 +56,18 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DES #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void des_ede_ofb_init_key(); -static void des_ede3_ofb_init_key(); -static void des_ede_ofb_cipher(); -#endif - static EVP_CIPHER d_ede_ofb_cipher2= { NID_des_ede_ofb64, @@ -100,66 +94,59 @@ static EVP_CIPHER d_ede3_ofb_cipher3= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_des_ede_ofb() +EVP_CIPHER *EVP_des_ede_ofb(void) { return(&d_ede_ofb_cipher2); } -EVP_CIPHER *EVP_des_ede3_ofb() +EVP_CIPHER *EVP_des_ede3_ofb(void) { return(&d_ede3_ofb_cipher3); } -static void des_ede_ofb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + ctx->num=0; if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); - des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); + des_set_key(&deskey[0],ctx->c.des_ede.ks1); + des_set_key(&deskey[1],ctx->c.des_ede.ks2); memcpy( (char *)ctx->c.des_ede.ks3, (char *)ctx->c.des_ede.ks1, sizeof(ctx->c.des_ede.ks1)); } } -static void des_ede3_ofb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + ctx->num=0; if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); - des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); - des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); + des_set_key(&deskey[0],ctx->c.des_ede.ks1); + des_set_key(&deskey[1],ctx->c.des_ede.ks2); + des_set_key(&deskey[2],ctx->c.des_ede.ks3); } } -static void des_ede_ofb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { - des_ede3_ofb64_encrypt( - in,out, - (long)inl, - ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, - (des_cblock *)&(ctx->iv[0]), - &ctx->num); + des_ede3_ofb64_encrypt(in,out,inl,ctx->c.des_ede.ks1, + ctx->c.des_ede.ks2, ctx->c.des_ede.ks3, + (des_cblock *)&(ctx->iv[0]),&ctx->num); } +#endif diff --git a/src/lib/libcrypto/evp/e_ofb_bf.c b/src/lib/libcrypto/evp/e_ofb_bf.c index 492f9b9082..c82154b549 100644 --- a/src/lib/libcrypto/evp/e_ofb_bf.c +++ b/src/lib/libcrypto/evp/e_ofb_bf.c @@ -56,23 +56,16 @@ * [including the GNU Public Licence.] */ -#ifndef NO_BLOWFISH - +#ifndef NO_BF #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void bf_ofb_init_key(); -static void bf_ofb_cipher(); -#endif - static EVP_CIPHER bfish_ofb_cipher= { NID_bf_ofb64, @@ -86,16 +79,13 @@ static EVP_CIPHER bfish_ofb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_bf_ofb() +EVP_CIPHER *EVP_bf_ofb(void) { return(&bfish_ofb_cipher); } -static void bf_ofb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -106,11 +96,8 @@ int enc; BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); } -static void bf_ofb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { BF_ofb64_encrypt( in,out, diff --git a/src/lib/libcrypto/evp/e_ofb_c.c b/src/lib/libcrypto/evp/e_ofb_c.c index f1eef4469c..971043de4c 100644 --- a/src/lib/libcrypto/evp/e_ofb_c.c +++ b/src/lib/libcrypto/evp/e_ofb_c.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void cast_ofb_init_key(); -static void cast_ofb_cipher(); -#endif - static EVP_CIPHER cast5_ofb_cipher= { NID_cast5_ofb64, @@ -86,16 +80,13 @@ static EVP_CIPHER cast5_ofb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_cast5_ofb() +EVP_CIPHER *EVP_cast5_ofb(void) { return(&cast5_ofb_cipher); } -static void cast_ofb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -106,11 +97,8 @@ int enc; CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key); } -static void cast_ofb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { CAST_ofb64_encrypt( in,out, diff --git a/src/lib/libcrypto/evp/e_ofb_d.c b/src/lib/libcrypto/evp/e_ofb_d.c index 09d4b4139d..398b3a002e 100644 --- a/src/lib/libcrypto/evp/e_ofb_d.c +++ b/src/lib/libcrypto/evp/e_ofb_d.c @@ -56,21 +56,16 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DES #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void des_ofb_init_key(); -static void des_ofb_cipher(); -#endif - static EVP_CIPHER d_ofb_cipher= { NID_des_ofb64, @@ -84,35 +79,29 @@ static EVP_CIPHER d_ofb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_des_ofb() +EVP_CIPHER *EVP_des_ofb(void) { return(&d_ofb_cipher); } -static void des_ofb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + ctx->num=0; if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) - des_set_key((des_cblock *)key,ctx->c.des_ks); + if (deskey != NULL) + des_set_key(deskey,ctx->c.des_ks); } -static void des_ofb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { - des_ofb64_encrypt( - in,out, - (long)inl, ctx->c.des_ks, - (des_cblock *)&(ctx->iv[0]), - &ctx->num); + des_ofb64_encrypt(in,out,inl,ctx->c.des_ks, + (des_cblock *)&(ctx->iv[0]),&ctx->num); } +#endif diff --git a/src/lib/libcrypto/evp/e_ofb_i.c b/src/lib/libcrypto/evp/e_ofb_i.c index 96c8afd9c8..389206ef36 100644 --- a/src/lib/libcrypto/evp/e_ofb_i.c +++ b/src/lib/libcrypto/evp/e_ofb_i.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void idea_ofb_init_key(); -static void idea_ofb_cipher(); -#endif - static EVP_CIPHER i_ofb_cipher= { NID_idea_ofb64, @@ -86,16 +80,13 @@ static EVP_CIPHER i_ofb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_idea_ofb() +EVP_CIPHER *EVP_idea_ofb(void) { return(&i_ofb_cipher); } -static void idea_ofb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -106,11 +97,8 @@ int enc; idea_set_encrypt_key(key,&(ctx->c.idea_ks)); } -static void idea_ofb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { idea_ofb64_encrypt( in,out,(long)inl, diff --git a/src/lib/libcrypto/evp/e_ofb_r2.c b/src/lib/libcrypto/evp/e_ofb_r2.c index 0f6d729988..60ae3d4507 100644 --- a/src/lib/libcrypto/evp/e_ofb_r2.c +++ b/src/lib/libcrypto/evp/e_ofb_r2.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void rc2_ofb_init_key(); -static void rc2_ofb_cipher(); -#endif - static EVP_CIPHER r2_ofb_cipher= { NID_rc2_ofb64, @@ -86,16 +80,13 @@ static EVP_CIPHER r2_ofb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_rc2_ofb() +EVP_CIPHER *EVP_rc2_ofb(void) { return(&r2_ofb_cipher); } -static void rc2_ofb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -103,15 +94,12 @@ int enc; memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); if (key != NULL) - RC2_set_key(&(ctx->c.rc2_ks),EVP_RC2_KEY_SIZE,key, - EVP_RC2_KEY_SIZE*8); + RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx), + key,EVP_CIPHER_CTX_key_length(ctx)*8); } -static void rc2_ofb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { RC2_ofb64_encrypt( in,out, diff --git a/src/lib/libcrypto/evp/e_ofb_r5.c b/src/lib/libcrypto/evp/e_ofb_r5.c index db28d6c317..30136824eb 100644 --- a/src/lib/libcrypto/evp/e_ofb_r5.c +++ b/src/lib/libcrypto/evp/e_ofb_r5.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void rc5_32_12_16_ofb_init_key(); -static void rc5_32_12_16_ofb_cipher(); -#endif - static EVP_CIPHER rc5_ofb_cipher= { NID_rc5_ofb64, @@ -86,16 +80,13 @@ static EVP_CIPHER rc5_ofb_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_rc5_32_12_16_ofb() +EVP_CIPHER *EVP_rc5_32_12_16_ofb(void) { return(&rc5_ofb_cipher); } -static void rc5_32_12_16_ofb_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { ctx->num=0; @@ -107,11 +98,8 @@ int enc; RC5_12_ROUNDS); } -static void rc5_32_12_16_ofb_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { RC5_32_ofb64_encrypt( in,out, diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c index 7e9790a94c..c7e58a75cc 100644 --- a/src/lib/libcrypto/evp/e_rc4.c +++ b/src/lib/libcrypto/evp/e_rc4.c @@ -60,19 +60,13 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void rc4_init_key(); -static void rc4_cipher(); -#endif - static EVP_CIPHER r4_cipher= { NID_rc4, @@ -94,21 +88,18 @@ static EVP_CIPHER r4_40_cipher= rc4_cipher, }; -EVP_CIPHER *EVP_rc4() +EVP_CIPHER *EVP_rc4(void) { return(&r4_cipher); } -EVP_CIPHER *EVP_rc4_40() +EVP_CIPHER *EVP_rc4_40(void) { return(&r4_40_cipher); } -static void rc4_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { if (key != NULL) memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx)); @@ -116,11 +107,8 @@ int enc; ctx->c.rc4.key); } -static void rc4_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { RC4(&(ctx->c.rc4.ks),inl,in,out); } diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c index 0d7fda0c47..3a6628a75c 100644 --- a/src/lib/libcrypto/evp/e_xcbc_d.c +++ b/src/lib/libcrypto/evp/e_xcbc_d.c @@ -56,21 +56,16 @@ * [including the GNU Public Licence.] */ +#ifndef NO_DES #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -#ifndef NOPROTO static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, unsigned char *iv,int enc); static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, unsigned char *in, unsigned int inl); -#else -static void desx_cbc_init_key(); -static void desx_cbc_cipher(); -#endif - static EVP_CIPHER d_xcbc_cipher= { NID_desx_cbc, @@ -84,39 +79,34 @@ static EVP_CIPHER d_xcbc_cipher= EVP_CIPHER_get_asn1_iv, }; -EVP_CIPHER *EVP_desx_cbc() +EVP_CIPHER *EVP_desx_cbc(void) { return(&d_xcbc_cipher); } -static void desx_cbc_init_key(ctx,key,iv,enc) -EVP_CIPHER_CTX *ctx; -unsigned char *key; -unsigned char *iv; -int enc; +static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, + unsigned char *iv, int enc) { + des_cblock *deskey = (des_cblock *)key; + if (iv != NULL) memcpy(&(ctx->oiv[0]),iv,8); memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); - if (key != NULL) + if (deskey != NULL) { - des_set_key((des_cblock *)key,ctx->c.desx_cbc.ks); + des_set_key(deskey,ctx->c.desx_cbc.ks); memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); } } -static void desx_cbc_cipher(ctx,out,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -unsigned char *in; -unsigned int inl; +static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, + unsigned char *in, unsigned int inl) { - des_xcbc_encrypt( - (des_cblock *)in,(des_cblock *)out, - (long)inl, ctx->c.desx_cbc.ks, + des_xcbc_encrypt(in,out,inl,ctx->c.desx_cbc.ks, (des_cblock *)&(ctx->iv[0]), - (des_cblock *)&(ctx->c.desx_cbc.inw[0]), - (des_cblock *)&(ctx->c.desx_cbc.outw[0]), + &ctx->c.desx_cbc.inw, + &ctx->c.desx_cbc.outw, ctx->encrypt); } +#endif diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c index 14d47c1eed..0152624a76 100644 --- a/src/lib/libcrypto/evp/encode.c +++ b/src/lib/libcrypto/evp/encode.c @@ -58,10 +58,21 @@ #include #include "cryptlib.h" -#include "evp.h" +#include +#ifndef CHARSET_EBCDIC #define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) #define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f]) +#else +/* We assume that PEM encoded files are EBCDIC files + * (i.e., printable text files). Convert them here while decoding. + * When encoding, output is EBCDIC (text) format again. + * (No need for conversion in the conv_bin2ascii macro, as the + * underlying textstring data_bin2ascii[] is already EBCDIC) + */ +#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) +#define conv_ascii2bin(a) (data_ascii2bin[os_toascii[a]&0x7f]) +#endif /* 64 char lines * pad input with 0 @@ -110,20 +121,15 @@ static unsigned char data_ascii2bin[128]={ 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF, }; -void EVP_EncodeInit(ctx) -EVP_ENCODE_CTX *ctx; +void EVP_EncodeInit(EVP_ENCODE_CTX *ctx) { ctx->length=48; ctx->num=0; ctx->line_num=0; } -void EVP_EncodeUpdate(ctx,out,outl,in,inl) -EVP_ENCODE_CTX *ctx; -unsigned char *out; -int *outl; -unsigned char *in; -int inl; +void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, + unsigned char *in, int inl) { int i,j; unsigned int total=0; @@ -165,10 +171,7 @@ int inl; *outl=total; } -void EVP_EncodeFinal(ctx,out,outl) -EVP_ENCODE_CTX *ctx; -unsigned char *out; -int *outl; +void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl) { unsigned int ret=0; @@ -182,9 +185,7 @@ int *outl; *outl=ret; } -int EVP_EncodeBlock(t,f,dlen) -unsigned char *t,*f; -int dlen; +int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int dlen) { int i,ret=0; unsigned long l; @@ -218,8 +219,7 @@ int dlen; return(ret); } -void EVP_DecodeInit(ctx) -EVP_ENCODE_CTX *ctx; +void EVP_DecodeInit(EVP_ENCODE_CTX *ctx) { ctx->length=30; ctx->num=0; @@ -231,12 +231,8 @@ EVP_ENCODE_CTX *ctx; * 0 for last line * 1 for full line */ -int EVP_DecodeUpdate(ctx,out,outl,in,inl) -EVP_ENCODE_CTX *ctx; -unsigned char *out; -int *outl; -unsigned char *in; -int inl; +int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, + unsigned char *in, int inl) { int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; unsigned char *d; @@ -341,9 +337,7 @@ end: return(rv); } -int EVP_DecodeBlock(t,f,n) -unsigned char *t,*f; -int n; +int EVP_DecodeBlock(unsigned char *t, unsigned char *f, int n) { int i,ret=0,a,b,c,d; unsigned long l; @@ -383,10 +377,7 @@ int n; return(ret); } -int EVP_DecodeFinal(ctx,out,outl) -EVP_ENCODE_CTX *ctx; -unsigned char *out; -int *outl; +int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl) { int i; @@ -404,9 +395,7 @@ int *outl; } #ifdef undef -int EVP_DecodeValid(buf,len) -unsigned char *buf; -int len; +int EVP_DecodeValid(unsigned char *buf, int len) { int i,num=0,bad=0; diff --git a/src/lib/libcrypto/evp/evp.err b/src/lib/libcrypto/evp/evp.err deleted file mode 100644 index cfc17437bc..0000000000 --- a/src/lib/libcrypto/evp/evp.err +++ /dev/null @@ -1,24 +0,0 @@ -/* Error codes for the EVP functions. */ - -/* Function codes. */ -#define EVP_F_D2I_PKEY 100 -#define EVP_F_EVP_DECRYPTFINAL 101 -#define EVP_F_EVP_OPENINIT 102 -#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 -#define EVP_F_EVP_PKEY_DECRYPT 104 -#define EVP_F_EVP_PKEY_ENCRYPT 105 -#define EVP_F_EVP_PKEY_NEW 106 -#define EVP_F_EVP_SIGNFINAL 107 -#define EVP_F_EVP_VERIFYFINAL 108 - -/* Reason codes. */ -#define EVP_R_BAD_DECRYPT 100 -#define EVP_R_DIFFERENT_KEY_TYPES 101 -#define EVP_R_IV_TOO_LARGE 102 -#define EVP_R_MISSING_PARMATERS 103 -#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 -#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 -#define EVP_R_PUBLIC_KEY_NOT_RSA 106 -#define EVP_R_UNSUPPORTED_CIPHER 107 -#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108 -#define EVP_R_WRONG_PUBLIC_KEY_TYPE 109 diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h index b39fad93a4..570fe27d39 100644 --- a/src/lib/libcrypto/evp/evp.h +++ b/src/lib/libcrypto/evp/evp.h @@ -64,40 +64,40 @@ extern "C" { #endif #ifndef NO_MD2 -#include "md2.h" +#include #endif #ifndef NO_MD5 -#include "md5.h" +#include #endif -#if !defined(NO_SHA) || !defined(NO_SHA1) -#include "sha.h" +#ifndef NO_SHA +#include #endif #ifndef NO_RIPEMD -#include "ripemd.h" +#include #endif #ifndef NO_DES -#include "des.h" +#include #endif #ifndef NO_RC4 -#include "rc4.h" +#include #endif #ifndef NO_RC2 -#include "rc2.h" +#include #endif #ifndef NO_RC5 -#include "rc5.h" +#include #endif -#ifndef NO_BLOWFISH -#include "blowfish.h" +#ifndef NO_BF +#include #endif #ifndef NO_CAST -#include "cast.h" +#include #endif #ifndef NO_IDEA -#include "idea.h" +#include #endif #ifndef NO_MDC2 -#include "mdc2.h" +#include #endif #define EVP_RC2_KEY_SIZE 16 @@ -109,25 +109,23 @@ extern "C" { #define EVP_MAX_KEY_LENGTH 24 #define EVP_MAX_IV_LENGTH 8 +#define PKCS5_SALT_LEN 8 +/* Default PKCS#5 iteration count */ +#define PKCS5_DEFAULT_ITER 2048 + #ifndef NO_RSA -#include "rsa.h" -#else -#define RSA long +#include #endif #ifndef NO_DSA -#include "dsa.h" -#else -#define DSA long +#include #endif #ifndef NO_DH -#include "dh.h" -#else -#define DH long +#include #endif -#include "objects.h" +#include #define EVP_PK_RSA 0x0001 #define EVP_PK_DSA 0x0002 @@ -159,16 +157,18 @@ typedef struct evp_pkey_st int references; union { char *ptr; +#ifndef NO_RSA struct rsa_st *rsa; /* RSA */ +#endif +#ifndef NO_DSA struct dsa_st *dsa; /* DSA */ +#endif +#ifndef NO_DH struct dh_st *dh; /* DH */ +#endif } pkey; int save_parameters; -#ifdef HEADER_STACK_H - STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ -#else - char /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ -#endif + STACK /*X509_ATTRIBUTE*/ *attributes; /* [ 0 ] */ } EVP_PKEY; #define EVP_PKEY_MO_SIGN 0x0001 @@ -183,7 +183,7 @@ typedef struct evp_pkey_st * This is required because for various smart-card perform the digest and * signing/verification on-board. To handle this case, the specific * EVP_MD and EVP_PKEY_METHODs need to be closely associated. - * When a PKEY is created, it will have a EVP_PKEY_METHOD ossociated with it. + * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it. * This can either be software or a token to provide the required low level * routines. */ @@ -194,28 +194,28 @@ typedef struct evp_pkey_md_st EVP_PKEY_METHOD *pkey; } EVP_PKEY_MD; -#define EVP_rsa_md2() +#define EVP_rsa_md2() \ EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\ EVP_rsa_pkcs1(),EVP_md2()) -#define EVP_rsa_md5() +#define EVP_rsa_md5() \ EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\ EVP_rsa_pkcs1(),EVP_md5()) -#define EVP_rsa_sha0() +#define EVP_rsa_sha0() \ EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\ EVP_rsa_pkcs1(),EVP_sha()) -#define EVP_rsa_sha1() +#define EVP_rsa_sha1() \ EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\ EVP_rsa_pkcs1(),EVP_sha1()) -#define EVP_rsa_ripemd160() +#define EVP_rsa_ripemd160() \ EVP_PKEY_MD_add(NID_ripemd160WithRSA,\ EVP_rsa_pkcs1(),EVP_ripemd160()) -#define EVP_rsa_mdc2() +#define EVP_rsa_mdc2() \ EVP_PKEY_MD_add(NID_mdc2WithRSA,\ EVP_rsa_octet_string(),EVP_mdc2()) -#define EVP_dsa_sha() +#define EVP_dsa_sha() \ EVP_PKEY_MD_add(NID_dsaWithSHA,\ EVP_dsa(),EVP_mdc2()) -#define EVP_dsa_sha1() +#define EVP_dsa_sha1() \ EVP_PKEY_MD_add(NID_dsaWithSHA1,\ EVP_dsa(),EVP_sha1()) @@ -261,6 +261,8 @@ typedef struct env_md_st int ctx_size; /* how big does the ctx need to be */ } EVP_MD; + + #define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} #ifndef NO_DSA @@ -287,7 +289,7 @@ typedef struct env_md_st typedef struct env_md_ctx_st { - EVP_MD *digest; + const EVP_MD *digest; union { unsigned char base[4]; #ifndef NO_MD2 @@ -296,10 +298,10 @@ typedef struct env_md_ctx_st #ifndef NO_MD5 MD5_CTX md5; #endif -#ifndef NO_MD5 +#ifndef NO_RIPEMD RIPEMD160_CTX ripemd160; #endif -#if !defined(NO_SHA) || !defined(NO_SHA1) +#ifndef NO_SHA SHA_CTX sha; #endif #ifndef NO_MDC2 @@ -326,13 +328,13 @@ typedef struct evp_cipher_st typedef struct evp_cipher_info_st { - EVP_CIPHER *cipher; + const EVP_CIPHER *cipher; unsigned char iv[EVP_MAX_IV_LENGTH]; } EVP_CIPHER_INFO; typedef struct evp_cipher_ctx_st { - EVP_CIPHER *cipher; + const EVP_CIPHER *cipher; int encrypt; /* encrypt or decrypt */ int buf_len; /* number we have left */ @@ -355,8 +357,8 @@ typedef struct evp_cipher_ctx_st struct { des_key_schedule ks;/* key schedule */ - C_Block inw; - C_Block outw; + des_cblock inw; + des_cblock outw; } desx_cbc; struct { @@ -374,7 +376,7 @@ typedef struct evp_cipher_ctx_st #ifndef NO_RC5 RC5_32_KEY rc5_ks;/* key schedule */ #endif -#ifndef NO_BLOWFISH +#ifndef NO_BF BF_KEY bf_ks;/* key schedule */ #endif #ifndef NO_CAST @@ -396,6 +398,11 @@ typedef struct evp_Encode_Ctx_st int expect_nl; } EVP_ENCODE_CTX; +/* Password based encryption function */ +typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER *cipher, + EVP_MD *md, int en_de); + #define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ (char *)(rsa)) #define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ @@ -430,6 +437,7 @@ typedef struct evp_Encode_Ctx_st #define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) #define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) #define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) +#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) #define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) #define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) @@ -441,43 +449,56 @@ typedef struct evp_Encode_Ctx_st #define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) #define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) -#define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) +#ifdef CONST_STRICT +void BIO_set_md(BIO *,const EVP_MD *md); +#else +# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) +#endif #define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp) #define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp) #define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) +#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp) #define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l)) -#ifndef NOPROTO +#define EVP_add_cipher_alias(n,alias) \ + OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)) +#define EVP_add_digest_alias(n,alias) \ + OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n)) +#define EVP_delete_cipher_alias(alias) \ + OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS); +#define EVP_delete_digest_alias(alias) \ + OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS); -void EVP_DigestInit(EVP_MD_CTX *ctx, EVP_MD *type); -void EVP_DigestUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); + +int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in); +void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); +void EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d, + unsigned int cnt); void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); -int EVP_read_pw_string(char *buf,int length,char *prompt,int verify); +int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify); void EVP_set_pw_prompt(char *prompt); char * EVP_get_pw_prompt(void); -int EVP_BytesToKey(EVP_CIPHER *type,EVP_MD *md,unsigned char *salt, +int EVP_BytesToKey(const EVP_CIPHER *type,EVP_MD *md,unsigned char *salt, unsigned char *data, int datal, int count, unsigned char *key,unsigned char *iv); -EVP_CIPHER *EVP_get_cipherbyname(char *name); - -void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, +void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, unsigned char *key, unsigned char *iv); void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); -void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, +void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, unsigned char *key, unsigned char *iv); void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); -void EVP_CipherInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, unsigned char *key, - unsigned char *iv,int enc); +void EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, + unsigned char *key,unsigned char *iv,int enc); void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, unsigned char *in, int inl); int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); @@ -519,7 +540,8 @@ void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); BIO_METHOD *BIO_f_md(void); BIO_METHOD *BIO_f_base64(void); BIO_METHOD *BIO_f_cipher(void); -void BIO_set_cipher(BIO *b,EVP_CIPHER *c,unsigned char *k, +BIO_METHOD *BIO_f_reliable(void); +void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k, unsigned char *i, int enc); #endif @@ -556,6 +578,7 @@ EVP_CIPHER *EVP_idea_cbc(void); EVP_CIPHER *EVP_rc2_ecb(void); EVP_CIPHER *EVP_rc2_cbc(void); EVP_CIPHER *EVP_rc2_40_cbc(void); +EVP_CIPHER *EVP_rc2_64_cbc(void); EVP_CIPHER *EVP_rc2_cfb(void); EVP_CIPHER *EVP_rc2_ofb(void); EVP_CIPHER *EVP_bf_ecb(void); @@ -577,11 +600,9 @@ void SSLeay_add_all_digests(void); int EVP_add_cipher(EVP_CIPHER *cipher); int EVP_add_digest(EVP_MD *digest); -int EVP_add_alias(char *name,char *alias); -int EVP_delete_alias(char *name); -EVP_CIPHER *EVP_get_cipherbyname(char *name); -EVP_MD *EVP_get_digestbyname(char *name); +const EVP_CIPHER *EVP_get_cipherbyname(const char *name); +const EVP_MD *EVP_get_digestbyname(const char *name); void EVP_cleanup(void); int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key, @@ -607,6 +628,8 @@ int EVP_PKEY_missing_parameters(EVP_PKEY *pkey); int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode); int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b); +int EVP_CIPHER_type(const EVP_CIPHER *ctx); + /* calls methods */ int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); @@ -615,177 +638,81 @@ int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); -#else - -void EVP_DigestInit(); -void EVP_DigestUpdate(); -void EVP_DigestFinal(); - -int EVP_read_pw_string(); -void EVP_set_pw_prompt(); -char * EVP_get_pw_prompt(); - -int EVP_BytesToKey(); - -EVP_CIPHER *EVP_get_cipherbyname(); - -void EVP_EncryptInit(); -void EVP_EncryptUpdate(); -void EVP_EncryptFinal(); - -void EVP_DecryptInit(); -void EVP_DecryptUpdate(); -int EVP_DecryptFinal(); - -void EVP_CipherInit(); -void EVP_CipherUpdate(); -int EVP_CipherFinal(); - -int EVP_SignFinal(); - -int EVP_VerifyFinal(); - -int EVP_OpenInit(); -int EVP_OpenFinal(); - -int EVP_SealInit(); -void EVP_SealFinal(); - -void EVP_EncodeInit(); -void EVP_EncodeUpdate(); -void EVP_EncodeFinal(); -int EVP_EncodeBlock(); - -void EVP_DecodeInit(); -int EVP_DecodeUpdate(); -int EVP_DecodeFinal(); -int EVP_DecodeBlock(); - -void ERR_load_EVP_strings(); - -void EVP_CIPHER_CTX_init(); -void EVP_CIPHER_CTX_cleanup(); - -#ifdef HEADER_BIO_H -BIO_METHOD *BIO_f_md(); -BIO_METHOD *BIO_f_base64(); -BIO_METHOD *BIO_f_cipher(); -void BIO_set_cipher(); -#endif - -EVP_MD *EVP_md_null(); -EVP_MD *EVP_md2(); -EVP_MD *EVP_md5(); -EVP_MD *EVP_sha(); -EVP_MD *EVP_sha1(); -EVP_MD *EVP_dss(); -EVP_MD *EVP_dss1(); -EVP_MD *EVP_mdc2(); - -EVP_CIPHER *EVP_enc_null(); -EVP_CIPHER *EVP_des_ecb(); -EVP_CIPHER *EVP_des_ede(); -EVP_CIPHER *EVP_des_ede3(); -EVP_CIPHER *EVP_des_cfb(); -EVP_CIPHER *EVP_des_ede_cfb(); -EVP_CIPHER *EVP_des_ede3_cfb(); -EVP_CIPHER *EVP_des_ofb(); -EVP_CIPHER *EVP_des_ede_ofb(); -EVP_CIPHER *EVP_des_ede3_ofb(); -EVP_CIPHER *EVP_des_cbc(); -EVP_CIPHER *EVP_des_ede_cbc(); -EVP_CIPHER *EVP_des_ede3_cbc(); -EVP_CIPHER *EVP_desx_cbc(); -EVP_CIPHER *EVP_rc4(); -EVP_CIPHER *EVP_rc4_40(); -EVP_CIPHER *EVP_idea_ecb(); -EVP_CIPHER *EVP_idea_cfb(); -EVP_CIPHER *EVP_idea_ofb(); -EVP_CIPHER *EVP_idea_cbc(); -EVP_CIPHER *EVP_rc2_ecb(); -EVP_CIPHER *EVP_rc2_cbc(); -EVP_CIPHER *EVP_rc2_40_cbc(); -EVP_CIPHER *EVP_rc2_cfb(); -EVP_CIPHER *EVP_rc2_ofb(); -EVP_CIPHER *EVP_bf_ecb(); -EVP_CIPHER *EVP_bf_cbc(); -EVP_CIPHER *EVP_bf_cfb(); -EVP_CIPHER *EVP_bf_ofb(); -EVP_CIPHER *EVP_cast5_ecb(); -EVP_CIPHER *EVP_cast5_cbc(); -EVP_CIPHER *EVP_cast5_cfb(); -EVP_CIPHER *EVP_cast5_ofb(); -EVP_CIPHER *EVP_rc5_32_12_16_cbc(); -EVP_CIPHER *EVP_rc5_32_12_16_ecb(); -EVP_CIPHER *EVP_rc5_32_12_16_cfb(); -EVP_CIPHER *EVP_rc5_32_12_16_ofb(); - -void SSLeay_add_all_algorithms(); -void SSLeay_add_all_ciphers(); -void SSLeay_add_all_digests(); - -int EVP_add_cipher(); -int EVP_add_digest(); -int EVP_add_alias(); -int EVP_delete_alias(); - -EVP_CIPHER *EVP_get_cipherbyname(); -EVP_MD *EVP_get_digestbyname(); -void EVP_cleanup(); - -int EVP_PKEY_decrypt(); -int EVP_PKEY_encrypt(); -int EVP_PKEY_type(); -int EVP_PKEY_bits(); -int EVP_PKEY_size(); -int EVP_PKEY_assign(); -EVP_PKEY * EVP_PKEY_new(); -void EVP_PKEY_free(); -EVP_PKEY * d2i_PublicKey(); -int i2d_PublicKey(); - -EVP_PKEY * d2i_PrivateKey(); -int i2d_PrivateKey(); - -int EVP_PKEY_copy_parameters(); -int EVP_PKEY_missing_parameters(); -int EVP_PKEY_save_parameters(); -int EVP_PKEY_cmp_parameters(); - -int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); -int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); - -int EVP_CIPHER_set_asn1_iv(); -int EVP_CIPHER_get_asn1_iv(); - -#endif +/* PKCS5 password based encryption */ +int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, + int en_de); +int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + int keylen, unsigned char *out); +int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, + int en_de); + +void PKCS5_PBE_add(void); + +int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de); +int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md, + EVP_PBE_KEYGEN *keygen); +void EVP_PBE_cleanup(void); /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the EVP functions. */ /* Function codes. */ #define EVP_F_D2I_PKEY 100 #define EVP_F_EVP_DECRYPTFINAL 101 +#define EVP_F_EVP_MD_CTX_COPY 110 #define EVP_F_EVP_OPENINIT 102 +#define EVP_F_EVP_PBE_ALG_ADD 115 +#define EVP_F_EVP_PBE_CIPHERINIT 116 +#define EVP_F_EVP_PKCS82PKEY 111 +#define EVP_F_EVP_PKCS8_SET_BROKEN 112 +#define EVP_F_EVP_PKEY2PKCS8 113 #define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 #define EVP_F_EVP_PKEY_DECRYPT 104 #define EVP_F_EVP_PKEY_ENCRYPT 105 #define EVP_F_EVP_PKEY_NEW 106 #define EVP_F_EVP_SIGNFINAL 107 #define EVP_F_EVP_VERIFYFINAL 108 +#define EVP_F_PKCS5_PBE_KEYIVGEN 117 +#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118 +#define EVP_F_RC2_MAGIC_TO_METH 109 /* Reason codes. */ #define EVP_R_BAD_DECRYPT 100 +#define EVP_R_BN_DECODE_ERROR 112 +#define EVP_R_BN_PUBKEY_ERROR 113 +#define EVP_R_CIPHER_PARAMETER_ERROR 122 +#define EVP_R_DECODE_ERROR 114 #define EVP_R_DIFFERENT_KEY_TYPES 101 +#define EVP_R_ENCODE_ERROR 115 +#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119 +#define EVP_R_INPUT_NOT_INITIALIZED 111 #define EVP_R_IV_TOO_LARGE 102 +#define EVP_R_KEYGEN_FAILURE 120 #define EVP_R_MISSING_PARMATERS 103 +#define EVP_R_NO_DSA_PARAMETERS 116 #define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 #define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 +#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117 #define EVP_R_PUBLIC_KEY_NOT_RSA 106 +#define EVP_R_UNKNOWN_PBE_ALGORITHM 121 #define EVP_R_UNSUPPORTED_CIPHER 107 -#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108 -#define EVP_R_WRONG_PUBLIC_KEY_TYPE 109 - +#define EVP_R_UNSUPPORTED_KEYLENGTH 123 +#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124 +#define EVP_R_UNSUPPORTED_KEY_SIZE 108 +#define EVP_R_UNSUPPORTED_PRF 125 +#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118 +#define EVP_R_UNSUPPORTED_SALT_TYPE 126 +#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 +#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110 + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index 93cc3a9464..5299a65b6a 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c @@ -58,23 +58,18 @@ #include #include "cryptlib.h" -#include "evp.h" +#include -char *EVP_version="EVP part of SSLeay 0.9.0b 29-Jun-1998"; +const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT; -void EVP_CIPHER_CTX_init(ctx) -EVP_CIPHER_CTX *ctx; +void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) { memset(ctx,0,sizeof(EVP_CIPHER_CTX)); /* ctx->cipher=NULL; */ } -void EVP_CipherInit(ctx,data,key,iv,enc) -EVP_CIPHER_CTX *ctx; -EVP_CIPHER *data; -unsigned char *key; -unsigned char *iv; -int enc; +void EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *data, + unsigned char *key, unsigned char *iv, int enc) { if (enc) EVP_EncryptInit(ctx,data,key,iv); @@ -82,22 +77,15 @@ int enc; EVP_DecryptInit(ctx,data,key,iv); } -void EVP_CipherUpdate(ctx,out,outl,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -int *outl; -unsigned char *in; -int inl; +void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, + unsigned char *in, int inl) { if (ctx->encrypt) EVP_EncryptUpdate(ctx,out,outl,in,inl); else EVP_DecryptUpdate(ctx,out,outl,in,inl); } -int EVP_CipherFinal(ctx,out,outl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -int *outl; +int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { if (ctx->encrypt) { @@ -107,11 +95,8 @@ int *outl; else return(EVP_DecryptFinal(ctx,out,outl)); } -void EVP_EncryptInit(ctx,cipher,key,iv) -EVP_CIPHER_CTX *ctx; -EVP_CIPHER *cipher; -unsigned char *key; -unsigned char *iv; +void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + unsigned char *key, unsigned char *iv) { if (cipher != NULL) ctx->cipher=cipher; @@ -120,11 +105,8 @@ unsigned char *iv; ctx->buf_len=0; } -void EVP_DecryptInit(ctx,cipher,key,iv) -EVP_CIPHER_CTX *ctx; -EVP_CIPHER *cipher; -unsigned char *key; -unsigned char *iv; +void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, + unsigned char *key, unsigned char *iv) { if (cipher != NULL) ctx->cipher=cipher; @@ -134,12 +116,8 @@ unsigned char *iv; } -void EVP_EncryptUpdate(ctx,out,outl,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -int *outl; -unsigned char *in; -int inl; +void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, + unsigned char *in, int inl) { int i,j,bl; @@ -179,10 +157,7 @@ int inl; ctx->buf_len=i; } -void EVP_EncryptFinal(ctx,out,outl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -int *outl; +void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { int i,n,b,bl; @@ -200,12 +175,8 @@ int *outl; *outl=b; } -void EVP_DecryptUpdate(ctx,out,outl,in,inl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -int *outl; -unsigned char *in; -int inl; +void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, + unsigned char *in, int inl) { int b,bl,n; int keep_last=0; @@ -249,10 +220,7 @@ int inl; } } -int EVP_DecryptFinal(ctx,out,outl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -int *outl; +int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { int i,b; int n; @@ -293,8 +261,7 @@ int *outl; return(1); } -void EVP_CIPHER_CTX_cleanup(c) -EVP_CIPHER_CTX *c; +void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) { if ((c->cipher != NULL) && (c->cipher->cleanup != NULL)) c->cipher->cleanup(c); diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c index 2b0a0ab93f..c61cc922e8 100644 --- a/src/lib/libcrypto/evp/evp_err.c +++ b/src/lib/libcrypto/evp/evp_err.c @@ -1,63 +1,65 @@ -/* lib/evp/evp_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/evp/evp_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "evp.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -65,39 +67,65 @@ static ERR_STRING_DATA EVP_str_functs[]= { {ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"}, {ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"}, +{ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"}, {ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"}, +{ERR_PACK(0,EVP_F_EVP_PBE_ALG_ADD,0), "EVP_PBE_alg_add"}, +{ERR_PACK(0,EVP_F_EVP_PBE_CIPHERINIT,0), "EVP_PBE_CipherInit"}, +{ERR_PACK(0,EVP_F_EVP_PKCS82PKEY,0), "EVP_PKCS82PKEY"}, +{ERR_PACK(0,EVP_F_EVP_PKCS8_SET_BROKEN,0), "EVP_PKCS8_SET_BROKEN"}, +{ERR_PACK(0,EVP_F_EVP_PKEY2PKCS8,0), "EVP_PKEY2PKCS8"}, {ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"}, {ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"}, {ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"}, {ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"}, {ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"}, {ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"}, -{0,NULL}, +{ERR_PACK(0,EVP_F_PKCS5_PBE_KEYIVGEN,0), "PKCS5_PBE_keyivgen"}, +{ERR_PACK(0,EVP_F_PKCS5_V2_PBE_KEYIVGEN,0), "PKCS5_v2_PBE_keyivgen"}, +{ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"}, +{0,NULL} }; static ERR_STRING_DATA EVP_str_reasons[]= { {EVP_R_BAD_DECRYPT ,"bad decrypt"}, +{EVP_R_BN_DECODE_ERROR ,"bn decode error"}, +{EVP_R_BN_PUBKEY_ERROR ,"bn pubkey error"}, +{EVP_R_CIPHER_PARAMETER_ERROR ,"cipher parameter error"}, +{EVP_R_DECODE_ERROR ,"decode error"}, {EVP_R_DIFFERENT_KEY_TYPES ,"different key types"}, +{EVP_R_ENCODE_ERROR ,"encode error"}, +{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"}, +{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"}, {EVP_R_IV_TOO_LARGE ,"iv too large"}, +{EVP_R_KEYGEN_FAILURE ,"keygen failure"}, {EVP_R_MISSING_PARMATERS ,"missing parmaters"}, +{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"}, {EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"}, {EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"}, +{EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE ,"pkcs8 unknown broken type"}, {EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"}, +{EVP_R_UNKNOWN_PBE_ALGORITHM ,"unknown pbe algorithm"}, {EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, +{EVP_R_UNSUPPORTED_KEYLENGTH ,"unsupported keylength"}, +{EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION,"unsupported key derivation function"}, +{EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"}, +{EVP_R_UNSUPPORTED_PRF ,"unsupported prf"}, +{EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM ,"unsupported private key algorithm"}, +{EVP_R_UNSUPPORTED_SALT_TYPE ,"unsupported salt type"}, {EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"}, {EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_EVP_strings() +void ERR_load_EVP_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_EVP,EVP_str_functs); diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c index dafa686f64..21eda418bc 100644 --- a/src/lib/libcrypto/evp/evp_key.c +++ b/src/lib/libcrypto/evp/evp_key.c @@ -58,15 +58,14 @@ #include #include "cryptlib.h" -#include "x509.h" -#include "objects.h" -#include "evp.h" +#include +#include +#include /* should be init to zeros. */ static char prompt_string[80]; -void EVP_set_pw_prompt(prompt) -char *prompt; +void EVP_set_pw_prompt(char *prompt) { if (prompt == NULL) prompt_string[0]='\0'; @@ -74,7 +73,7 @@ char *prompt; strncpy(prompt_string,prompt,79); } -char *EVP_get_pw_prompt() +char *EVP_get_pw_prompt(void) { if (prompt_string[0] == '\0') return(NULL); @@ -83,29 +82,19 @@ char *EVP_get_pw_prompt() } #ifdef NO_DES -int des_read_pw_string(char *buf,int len,char *prompt,int verify); +int des_read_pw_string(char *buf,int len,const char *prompt,int verify); #endif -int EVP_read_pw_string(buf,len,prompt,verify) -char *buf; -int len; -char *prompt; -int verify; +int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) { if ((prompt == NULL) && (prompt_string[0] != '\0')) prompt=prompt_string; return(des_read_pw_string(buf,len,prompt,verify)); } -int EVP_BytesToKey(type,md,salt,data,datal,count,key,iv) -EVP_CIPHER *type; -EVP_MD *md; -unsigned char *salt; -unsigned char *data; -int datal; -int count; -unsigned char *key; -unsigned char *iv; +int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, unsigned char *salt, + unsigned char *data, int datal, int count, unsigned char *key, + unsigned char *iv) { EVP_MD_CTX c; unsigned char md_buf[EVP_MAX_MD_SIZE]; diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c index 69784eb555..3f9bf55828 100644 --- a/src/lib/libcrypto/evp/evp_lib.c +++ b/src/lib/libcrypto/evp/evp_lib.c @@ -58,12 +58,10 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include -int EVP_CIPHER_param_to_asn1(c,type) -EVP_CIPHER_CTX *c; -ASN1_TYPE *type; +int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type) { int ret; @@ -74,9 +72,7 @@ ASN1_TYPE *type; return(ret); } -int EVP_CIPHER_asn1_to_param(c,type) -EVP_CIPHER_CTX *c; -ASN1_TYPE *type; +int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type) { int ret; @@ -87,9 +83,7 @@ ASN1_TYPE *type; return(ret); } -int EVP_CIPHER_get_asn1_iv(c,type) -EVP_CIPHER_CTX *c; -ASN1_TYPE *type; +int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) { int i=0,l; @@ -97,14 +91,15 @@ ASN1_TYPE *type; { l=EVP_CIPHER_CTX_iv_length(c); i=ASN1_TYPE_get_octetstring(type,c->oiv,l); - memcpy(c->iv,c->oiv,l); + if (i != l) + return(-1); + else if (i > 0) + memcpy(c->iv,c->oiv,l); } return(i); } -int EVP_CIPHER_set_asn1_iv(c,type) -EVP_CIPHER_CTX *c; -ASN1_TYPE *type; +int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) { int i=0,j; @@ -115,3 +110,29 @@ ASN1_TYPE *type; } return(i); } + +/* Convert the various cipher NIDs and dummies to a proper OID NID */ +int EVP_CIPHER_type(const EVP_CIPHER *ctx) +{ + int nid; + nid = EVP_CIPHER_nid(ctx); + + switch(nid) { + + case NID_rc2_cbc: + case NID_rc2_64_cbc: + case NID_rc2_40_cbc: + + return NID_rc2_cbc; + + case NID_rc4: + case NID_rc4_40: + + return NID_rc4; + + default: + + return nid; + } +} + diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c new file mode 100644 index 0000000000..353c3ad667 --- /dev/null +++ b/src/lib/libcrypto/evp/evp_pbe.c @@ -0,0 +1,134 @@ +/* evp_pbe.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include +#include +#include "cryptlib.h" + +/* Password based encryption (PBE) functions */ + +static STACK *pbe_algs; + +/* Setup a cipher context from a PBE algorithm */ + +typedef struct { +int pbe_nid; +EVP_CIPHER *cipher; +EVP_MD *md; +EVP_PBE_KEYGEN *keygen; +} EVP_PBE_CTL; + +int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de) +{ + + EVP_PBE_CTL *pbetmp, pbelu; + int i; + pbelu.pbe_nid = OBJ_obj2nid(pbe_obj); + if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu); + else i = -1; + + if (i == -1) { + char obj_tmp[80]; + EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM); + if (!pbe_obj) strcpy (obj_tmp, "NULL"); + else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj); + ERR_add_error_data(2, "TYPE=", obj_tmp); + return 0; + } + if (passlen == -1) passlen = strlen(pass); + pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i); + i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher, + pbetmp->md, en_de); + if (!i) { + EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE); + return 0; + } + return 1; +} + +static int pbe_cmp (EVP_PBE_CTL **pbe1, EVP_PBE_CTL **pbe2) +{ + return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid); +} + +/* Add a PBE algorithm */ + +int EVP_PBE_alg_add (int nid, EVP_CIPHER *cipher, EVP_MD *md, + EVP_PBE_KEYGEN *keygen) +{ + EVP_PBE_CTL *pbe_tmp; + if (!pbe_algs) pbe_algs = sk_new (pbe_cmp); + if (!(pbe_tmp = (EVP_PBE_CTL*) Malloc (sizeof(EVP_PBE_CTL)))) { + EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE); + return 0; + } + pbe_tmp->pbe_nid = nid; + pbe_tmp->cipher = cipher; + pbe_tmp->md = md; + pbe_tmp->keygen = keygen; + sk_push (pbe_algs, (char *)pbe_tmp); + return 1; +} + +void EVP_PBE_cleanup(void) +{ + sk_pop_free(pbe_algs, FreeFunc); + pbe_algs = NULL; +} diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c new file mode 100644 index 0000000000..421e452db1 --- /dev/null +++ b/src/lib/libcrypto/evp/evp_pkey.c @@ -0,0 +1,298 @@ +/* evp_pkey.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include +#include "cryptlib.h" +#include +#include + +/* Extract a private key from a PKCS8 structure */ + +EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8) +{ + EVP_PKEY *pkey; +#ifndef NO_RSA + RSA *rsa; +#endif +#ifndef NO_DSA + DSA *dsa; + ASN1_INTEGER *dsapriv; + STACK *ndsa; + BN_CTX *ctx; + int plen; +#endif + X509_ALGOR *a; + unsigned char *p; + int pkeylen; + char obj_tmp[80]; + + switch (p8->broken) { + case PKCS8_OK: + p = p8->pkey->value.octet_string->data; + pkeylen = p8->pkey->value.octet_string->length; + break; + + case PKCS8_NO_OCTET: + p = p8->pkey->value.sequence->data; + pkeylen = p8->pkey->value.sequence->length; + break; + + default: + EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE); + return NULL; + break; + } + if (!(pkey = EVP_PKEY_new())) { + EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); + return NULL; + } + a = p8->pkeyalg; + switch (OBJ_obj2nid(a->algorithm)) + { +#ifndef NO_RSA + case NID_rsaEncryption: + if (!(rsa = d2i_RSAPrivateKey (NULL, &p, pkeylen))) { + EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); + return NULL; + } + EVP_PKEY_assign_RSA (pkey, rsa); + break; +#endif +#ifndef NO_DSA + case NID_dsa: + /* PKCS#8 DSA is weird: you just get a private key integer + * and parameters in the AlgorithmIdentifier the pubkey must + * be recalculated. + */ + + /* Check for broken Netscape Database DSA PKCS#8, UGH! */ + if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) { + if(!(ndsa = ASN1_seq_unpack(p, pkeylen, + (char *(*)())d2i_ASN1_INTEGER, + ASN1_STRING_free))) { + EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); + return NULL; + } + if(sk_num(ndsa) != 2 ) { + EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); + sk_pop_free(ndsa, ASN1_STRING_free); + return NULL; + } + dsapriv = (ASN1_INTEGER *) sk_pop(ndsa); + sk_pop_free(ndsa, ASN1_STRING_free); + } else if (!(dsapriv=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) { + EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); + return NULL; + } + /* Retrieve parameters */ + if (a->parameter->type != V_ASN1_SEQUENCE) { + EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_NO_DSA_PARAMETERS); + return NULL; + } + p = a->parameter->value.sequence->data; + plen = a->parameter->value.sequence->length; + if (!(dsa = d2i_DSAparams (NULL, &p, plen))) { + EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR); + return NULL; + } + /* We have parameters now set private key */ + if (!(dsa->priv_key = ASN1_INTEGER_to_BN(dsapriv, NULL))) { + EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR); + DSA_free (dsa); + return NULL; + } + /* Calculate public key (ouch!) */ + if (!(dsa->pub_key = BN_new())) { + EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); + DSA_free (dsa); + return NULL; + } + if (!(ctx = BN_CTX_new())) { + EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE); + DSA_free (dsa); + return NULL; + } + + if (!BN_mod_exp(dsa->pub_key, dsa->g, + dsa->priv_key, dsa->p, ctx)) { + + EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR); + BN_CTX_free (ctx); + DSA_free (dsa); + return NULL; + } + + EVP_PKEY_assign_DSA (pkey, dsa); + BN_CTX_free (ctx); + break; +#endif + default: + EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM); + if (!a->algorithm) strcpy (obj_tmp, "NULL"); + else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm); + ERR_add_error_data(2, "TYPE=", obj_tmp); + EVP_PKEY_free (pkey); + return NULL; + } + return pkey; +} + +/* Turn a private key into a PKCS8 structure */ + +PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey) +{ + PKCS8_PRIV_KEY_INFO *p8; +#ifndef NO_DSA + ASN1_INTEGER *dpkey; + unsigned char *p, *q; + int len; +#endif + if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) { + EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); + return NULL; + } + ASN1_INTEGER_set (p8->version, 0); + if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) { + EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); + PKCS8_PRIV_KEY_INFO_free (p8); + return NULL; + } + switch (EVP_PKEY_type(pkey->type)) { +#ifndef NO_RSA + case EVP_PKEY_RSA: + + p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption); + p8->pkeyalg->parameter->type = V_ASN1_NULL; + if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey, + &p8->pkey->value.octet_string)) { + EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); + PKCS8_PRIV_KEY_INFO_free (p8); + return NULL; + } + break; +#endif +#ifndef NO_DSA + case EVP_PKEY_DSA: + p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa); + + /* get paramaters and place in AlgorithmIdentifier */ + len = i2d_DSAparams (pkey->pkey.dsa, NULL); + if (!(p = Malloc(len))) { + EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); + PKCS8_PRIV_KEY_INFO_free (p8); + return NULL; + } + q = p; + i2d_DSAparams (pkey->pkey.dsa, &q); + p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE; + p8->pkeyalg->parameter->value.sequence = ASN1_STRING_new(); + ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, len); + Free(p); + /* Get private key into an integer and pack */ + if (!(dpkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) { + EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR); + PKCS8_PRIV_KEY_INFO_free (p8); + return NULL; + } + + if (!ASN1_pack_string((char *)dpkey, i2d_ASN1_INTEGER, + &p8->pkey->value.octet_string)) { + EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); + ASN1_INTEGER_free (dpkey); + PKCS8_PRIV_KEY_INFO_free (p8); + return NULL; + } + ASN1_INTEGER_free (dpkey); + break; +#endif + default: + EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM); + PKCS8_PRIV_KEY_INFO_free (p8); + return NULL; + } + p8->pkey->type = V_ASN1_OCTET_STRING; + RAND_seed (p8->pkey->value.octet_string->data, + p8->pkey->value.octet_string->length); + return p8; +} + +PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken) +{ + switch (broken) { + + case PKCS8_OK: + p8->broken = PKCS8_OK; + return p8; + break; + + case PKCS8_NO_OCTET: + p8->broken = PKCS8_NO_OCTET; + p8->pkey->type = V_ASN1_SEQUENCE; + return p8; + break; + + default: + EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE); + return NULL; + break; + + } +} + + diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c index 3549b1699c..8ea826868e 100644 --- a/src/lib/libcrypto/evp/m_dss.c +++ b/src/lib/libcrypto/evp/m_dss.c @@ -58,10 +58,11 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include +#ifndef NO_SHA static EVP_MD dsa_md= { NID_dsaWithSHA, @@ -75,8 +76,8 @@ static EVP_MD dsa_md= sizeof(EVP_MD *)+sizeof(SHA_CTX), }; -EVP_MD *EVP_dss() +EVP_MD *EVP_dss(void) { return(&dsa_md); } - +#endif diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c index ff256b7b20..9d8d1ce23e 100644 --- a/src/lib/libcrypto/evp/m_dss1.c +++ b/src/lib/libcrypto/evp/m_dss1.c @@ -56,11 +56,12 @@ * [including the GNU Public Licence.] */ +#ifndef NO_SHA #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include static EVP_MD dss1_md= { @@ -75,7 +76,8 @@ static EVP_MD dss1_md= sizeof(EVP_MD *)+sizeof(SHA_CTX), }; -EVP_MD *EVP_dss1() +EVP_MD *EVP_dss1(void) { return(&dss1_md); } +#endif diff --git a/src/lib/libcrypto/evp/m_md2.c b/src/lib/libcrypto/evp/m_md2.c index 2209416142..3281e91809 100644 --- a/src/lib/libcrypto/evp/m_md2.c +++ b/src/lib/libcrypto/evp/m_md2.c @@ -56,11 +56,12 @@ * [including the GNU Public Licence.] */ +#ifndef NO_MD2 #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include static EVP_MD md2_md= { @@ -75,8 +76,8 @@ static EVP_MD md2_md= sizeof(EVP_MD *)+sizeof(MD2_CTX), }; -EVP_MD *EVP_md2() +EVP_MD *EVP_md2(void) { return(&md2_md); } - +#endif diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c index d65db9aa1d..9fc9530127 100644 --- a/src/lib/libcrypto/evp/m_md5.c +++ b/src/lib/libcrypto/evp/m_md5.c @@ -56,11 +56,12 @@ * [including the GNU Public Licence.] */ +#ifndef NO_MD5 #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include static EVP_MD md5_md= { @@ -75,7 +76,8 @@ static EVP_MD md5_md= sizeof(EVP_MD *)+sizeof(MD5_CTX), }; -EVP_MD *EVP_md5() +EVP_MD *EVP_md5(void) { return(&md5_md); } +#endif diff --git a/src/lib/libcrypto/evp/m_mdc2.c b/src/lib/libcrypto/evp/m_mdc2.c index 64a853eb7f..2c7f1ae515 100644 --- a/src/lib/libcrypto/evp/m_mdc2.c +++ b/src/lib/libcrypto/evp/m_mdc2.c @@ -56,11 +56,12 @@ * [including the GNU Public Licence.] */ +#ifndef NO_MDC2 #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include static EVP_MD mdc2_md= { @@ -75,7 +76,8 @@ static EVP_MD mdc2_md= sizeof(EVP_MD *)+sizeof(MDC2_CTX), }; -EVP_MD *EVP_mdc2() +EVP_MD *EVP_mdc2(void) { return(&mdc2_md); } +#endif diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c index 6d80560df2..e2dadf3dab 100644 --- a/src/lib/libcrypto/evp/m_null.c +++ b/src/lib/libcrypto/evp/m_null.c @@ -58,11 +58,11 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include -static void function() +static void function(void) { } @@ -80,7 +80,7 @@ static EVP_MD null_md= sizeof(EVP_MD *), }; -EVP_MD *EVP_md_null() +EVP_MD *EVP_md_null(void) { return(&null_md); } diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c index 04c5d8897b..3d781a4e8d 100644 --- a/src/lib/libcrypto/evp/m_ripemd.c +++ b/src/lib/libcrypto/evp/m_ripemd.c @@ -56,11 +56,13 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RIPEMD #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include +#include static EVP_MD ripemd160_md= { @@ -75,7 +77,8 @@ static EVP_MD ripemd160_md= sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX), }; -EVP_MD *EVP_ripemd160() +EVP_MD *EVP_ripemd160(void) { return(&ripemd160_md); } +#endif diff --git a/src/lib/libcrypto/evp/m_sha.c b/src/lib/libcrypto/evp/m_sha.c index af4e434a22..6d35b71b85 100644 --- a/src/lib/libcrypto/evp/m_sha.c +++ b/src/lib/libcrypto/evp/m_sha.c @@ -56,11 +56,12 @@ * [including the GNU Public Licence.] */ +#ifndef NO_SHA #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include static EVP_MD sha_md= { @@ -75,8 +76,8 @@ static EVP_MD sha_md= sizeof(EVP_MD *)+sizeof(SHA_CTX), }; -EVP_MD *EVP_sha() +EVP_MD *EVP_sha(void) { return(&sha_md); } - +#endif diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c index 87135a9cf2..57a1ab0cce 100644 --- a/src/lib/libcrypto/evp/m_sha1.c +++ b/src/lib/libcrypto/evp/m_sha1.c @@ -56,11 +56,12 @@ * [including the GNU Public Licence.] */ +#ifndef NO_SHA #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include static EVP_MD sha1_md= { @@ -75,7 +76,8 @@ static EVP_MD sha1_md= sizeof(EVP_MD *)+sizeof(SHA_CTX), }; -EVP_MD *EVP_sha1() +EVP_MD *EVP_sha1(void) { return(&sha1_md); } +#endif diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c index e0774da20d..3e8f460328 100644 --- a/src/lib/libcrypto/evp/names.c +++ b/src/lib/libcrypto/evp/names.c @@ -58,228 +58,61 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" +#include +#include +#include -typedef struct aliases_st { - char *alias; - /* This must be the last field becaue I will allocate things - * so they go off the end of it */ - char name[4]; - } ALIASES; - -static STACK /* ALIASES */ *aliases=NULL; -static STACK /* EVP_CIPHERS */ *ciphers=NULL; -static STACK /* EVP_MD */ *digests=NULL; - -static int cipher_nid_cmp(a,b) -EVP_CIPHER **a,**b; - { return((*a)->nid - (*b)->nid); } - -static int digest_type_cmp(a,b) -EVP_MD **a,**b; - { return((*a)->pkey_type - (*b)->pkey_type); } - -int EVP_add_cipher(c) -EVP_CIPHER *c; - { - int i; - - if (ciphers == NULL) - { - ciphers=sk_new(cipher_nid_cmp); - if (ciphers == NULL) return(0); - } - if ((i=sk_find(ciphers,(char *)c)) >= 0) - { - if (sk_value(ciphers,i) == (char *)c) - return(1); - sk_delete(ciphers,i); - } - return(sk_push(ciphers,(char *)c)); - } - -int EVP_add_digest(md) -EVP_MD *md; +int EVP_add_cipher(EVP_CIPHER *c) { - int i; - char *n; + int r; - if (digests == NULL) - { - digests=sk_new(digest_type_cmp); - if (digests == NULL) return(0); - } - if ((i=sk_find(digests,(char *)md)) >= 0) - { - if (sk_value(digests,i) == (char *)md) - return(1); - sk_delete(digests,i); - } - if (md->type != md->pkey_type) - { - n=OBJ_nid2sn(md->pkey_type); - EVP_add_alias(n,OBJ_nid2sn(md->type)); - EVP_add_alias(n,OBJ_nid2ln(md->type)); - } - sk_push(digests,(char *)md); - return(1); - } - -static int alias_cmp(a,b) -ALIASES **a,**b; - { - return(strcmp((*a)->alias,(*b)->alias)); + r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c); + if (r == 0) return(0); + r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c); + return(r); } -int EVP_add_alias(name,aname) -char *name; -char *aname; +int EVP_add_digest(EVP_MD *md) { - int l1,l2,i; - ALIASES *a; - char *p; + int r; + const char *name; - if ((name == NULL) || (aname == NULL)) return(0); - l1=strlen(name)+1; - l2=strlen(aname)+1; - i=sizeof(ALIASES)+l1+l2; - if ((a=(ALIASES *)Malloc(i)) == NULL) - return(0); - strcpy(a->name,name); - p= &(a->name[l1]); - strcpy(p,aname); - a->alias=p; + name=OBJ_nid2sn(md->type); + r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md); + if (r == 0) return(0); + r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md); + if (r == 0) return(0); - if (aliases == NULL) - { - aliases=sk_new(alias_cmp); - if (aliases == NULL) goto err; - } - - if ((i=sk_find(aliases,(char *)a)) >= 0) + if (md->type != md->pkey_type) { - Free(sk_delete(aliases,i)); + r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type), + OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name); + if (r == 0) return(0); + r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type), + OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name); } - if (!sk_push(aliases,(char *)a)) goto err; - return(1); -err: - return(0); + return(r); } -int EVP_delete_alias(name) -char *name; +const EVP_CIPHER *EVP_get_cipherbyname(const char *name) { - ALIASES a; - int i; + const EVP_CIPHER *cp; - if (aliases != NULL) - { - a.alias=name; - if ((i=sk_find(aliases,(char *)&a)) >= 0) - { - Free(sk_delete(aliases,i)); - return(1); - } - } - return(0); + cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH); + return(cp); } -EVP_CIPHER *EVP_get_cipherbyname(name) -char *name; +const EVP_MD *EVP_get_digestbyname(const char *name) { - int nid,num=6,i; - EVP_CIPHER c,*cp; - ALIASES a,*ap; - - if (ciphers == NULL) return(NULL); - for (;;) - { - if (num-- <= 0) return(NULL); - if (aliases != NULL) - { - a.alias=name; - i=sk_find(aliases,(char *)&a); - if (i >= 0) - { - ap=(ALIASES *)sk_value(aliases,i); - name=ap->name; - continue; - } - } + const EVP_MD *cp; - nid=OBJ_txt2nid(name); - if (nid == NID_undef) return(NULL); - c.nid=nid; - i=sk_find(ciphers,(char *)&c); - if (i >= 0) - { - cp=(EVP_CIPHER *)sk_value(ciphers,i); - return(cp); - } - else - return(NULL); - } + cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH); + return(cp); } -EVP_MD *EVP_get_digestbyname(name) -char *name; +void EVP_cleanup(void) { - int nid,num=6,i; - EVP_MD c,*cp; - ALIASES a,*ap; - - if (digests == NULL) return(NULL); - - for (;;) - { - if (num-- <= 0) return(NULL); - - if (aliases != NULL) - { - a.alias=name; - i=sk_find(aliases,(char *)&a); - if (i >= 0) - { - ap=(ALIASES *)sk_value(aliases,i); - name=ap->name; - continue; - } - } - - nid=OBJ_txt2nid(name); - if (nid == NID_undef) return(NULL); - c.pkey_type=nid; - i=sk_find(digests,(char *)&c); - if (i >= 0) - { - cp=(EVP_MD *)sk_value(digests,i); - return(cp); - } - else - return(NULL); - } - } - -void EVP_cleanup() - { - int i; - - if (aliases != NULL) - { - for (i=0; i +#include +#include +#include +#include "cryptlib.h" + +/* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info. + */ + +void PKCS5_PBE_add(void) +{ +#ifndef NO_DES +# ifndef NO_MD5 +EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(), + PKCS5_PBE_keyivgen); +# endif +# ifndef NO_MD2 +EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(), + PKCS5_PBE_keyivgen); +# endif +# ifndef NO_SHA +EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(), + PKCS5_PBE_keyivgen); +# endif +#endif +#ifndef NO_RC2 +# ifndef NO_MD5 +EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(), + PKCS5_PBE_keyivgen); +# endif +# ifndef NO_MD2 +EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(), + PKCS5_PBE_keyivgen); +# endif +# ifndef NO_SHA +EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(), + PKCS5_PBE_keyivgen); +# endif +#endif +#ifndef NO_HMAC +EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen); +#endif +} + +int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md, + int en_de) +{ + EVP_MD_CTX ctx; + unsigned char md_tmp[EVP_MAX_MD_SIZE]; + unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH]; + int i; + PBEPARAM *pbe; + int saltlen, iter; + unsigned char *salt, *pbuf; + + /* Extract useful info from parameter */ + pbuf = param->value.sequence->data; + if (!param || (param->type != V_ASN1_SEQUENCE) || + !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) { + EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); + return 0; + } + + if (!pbe->iter) iter = 1; + else iter = ASN1_INTEGER_get (pbe->iter); + salt = pbe->salt->data; + saltlen = pbe->salt->length; + + EVP_DigestInit (&ctx, md); + EVP_DigestUpdate (&ctx, pass, passlen); + EVP_DigestUpdate (&ctx, salt, saltlen); + PBEPARAM_free(pbe); + EVP_DigestFinal (&ctx, md_tmp, NULL); + for (i = 1; i < iter; i++) { + EVP_DigestInit(&ctx, md); + EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md)); + EVP_DigestFinal (&ctx, md_tmp, NULL); + } + memcpy (key, md_tmp, EVP_CIPHER_key_length(cipher)); + memcpy (iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), + EVP_CIPHER_iv_length(cipher)); + EVP_CipherInit(cctx, cipher, key, iv, en_de); + memset(md_tmp, 0, EVP_MAX_MD_SIZE); + memset(key, 0, EVP_MAX_KEY_LENGTH); + memset(iv, 0, EVP_MAX_IV_LENGTH); + return 1; +} diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c new file mode 100644 index 0000000000..27a2c518be --- /dev/null +++ b/src/lib/libcrypto/evp/p5_crpt2.c @@ -0,0 +1,247 @@ +/* p5_crpt2.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +#if !defined(NO_HMAC) && !defined(NO_SHA) +#include +#include +#include +#include +#include +#include "cryptlib.h" + +/* set this to print out info about the keygen algorithm */ +/* #define DEBUG_PKCS5V2 */ + +#ifdef DEBUG_PKCS5V2 + static void h__dump (const unsigned char *p, int len); +#endif + +/* This is an implementation of PKCS#5 v2.0 password based encryption key + * derivation function PBKDF2 using the only currently defined function HMAC + * with SHA1. Verified against test vectors posted by Peter Gutmann + * to the PKCS-TNG mailing list. + */ + +int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, + unsigned char *salt, int saltlen, int iter, + int keylen, unsigned char *out) +{ + unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4]; + int cplen, j, k, tkeylen; + unsigned long i = 1; + HMAC_CTX hctx; + p = out; + tkeylen = keylen; + if(passlen == -1) passlen = strlen(pass); + while(tkeylen) { + if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH; + else cplen = tkeylen; + /* We are unlikely to ever use more than 256 blocks (5120 bits!) + * but just in case... + */ + itmp[0] = (unsigned char)((i >> 24) & 0xff); + itmp[1] = (unsigned char)((i >> 16) & 0xff); + itmp[2] = (unsigned char)((i >> 8) & 0xff); + itmp[3] = (unsigned char)(i & 0xff); + HMAC_Init(&hctx, pass, passlen, EVP_sha1()); + HMAC_Update(&hctx, salt, saltlen); + HMAC_Update(&hctx, itmp, 4); + HMAC_Final(&hctx, digtmp, NULL); + memcpy(p, digtmp, cplen); + for(j = 1; j < iter; j++) { + HMAC(EVP_sha1(), pass, passlen, + digtmp, SHA_DIGEST_LENGTH, digtmp, NULL); + for(k = 0; k < cplen; k++) p[k] ^= digtmp[k]; + } + tkeylen-= cplen; + i++; + p+= cplen; + } + HMAC_cleanup(&hctx); +#ifdef DEBUG_PKCS5V2 + fprintf(stderr, "Password:\n"); + h__dump (pass, passlen); + fprintf(stderr, "Salt:\n"); + h__dump (salt, saltlen); + fprintf(stderr, "Iteration count %d\n", iter); + fprintf(stderr, "Key:\n"); + h__dump (out, keylen); +#endif + return 1; +} + +#ifdef DO_TEST +main() +{ + unsigned char out[4]; + unsigned char salt[] = {0x12, 0x34, 0x56, 0x78}; + PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out); + fprintf(stderr, "Out %02X %02X %02X %02X\n", + out[0], out[1], out[2], out[3]); +} + +#endif + +/* Now the key derivation function itself. This is a bit evil because + * it has to check the ASN1 parameters are valid: and there are quite a + * few of them... + */ + +int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, + ASN1_TYPE *param, EVP_CIPHER *c, EVP_MD *md, + int en_de) +{ + unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH]; + int saltlen, keylen, iter, plen; + PBE2PARAM *pbe2 = NULL; + const EVP_CIPHER *cipher; + PBKDF2PARAM *kdf = NULL; + + pbuf = param->value.sequence->data; + plen = param->value.sequence->length; + if(!param || (param->type != V_ASN1_SEQUENCE) || + !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) { + EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); + return 0; + } + + /* See if we recognise the key derivation function */ + + if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) { + EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, + EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION); + goto err; + } + + /* lets see if we recognise the encryption algorithm. + */ + + cipher = EVP_get_cipherbyname( + OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm))); + + if(!cipher) { + EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, + EVP_R_UNSUPPORTED_CIPHER); + goto err; + } + + /* Fixup cipher based on AlgorithmIdentifier */ + EVP_CipherInit(ctx, cipher, NULL, NULL, en_de); + if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) { + EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, + EVP_R_CIPHER_PARAMETER_ERROR); + goto err; + } + keylen = EVP_CIPHER_CTX_key_length(ctx); + + /* Now decode key derivation function */ + + pbuf = pbe2->keyfunc->parameter->value.sequence->data; + plen = pbe2->keyfunc->parameter->value.sequence->length; + if(!pbe2->keyfunc->parameter || + (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) || + !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) { + EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); + goto err; + } + + PBE2PARAM_free(pbe2); + pbe2 = NULL; + + /* Now check the parameters of the kdf */ + + if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){ + EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, + EVP_R_UNSUPPORTED_KEYLENGTH); + goto err; + } + + if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) { + EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF); + goto err; + } + + if(kdf->salt->type != V_ASN1_OCTET_STRING) { + EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, + EVP_R_UNSUPPORTED_SALT_TYPE); + goto err; + } + + /* it seems that its all OK */ + salt = kdf->salt->value.octet_string->data; + saltlen = kdf->salt->value.octet_string->length; + iter = ASN1_INTEGER_get(kdf->iter); + PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key); + EVP_CipherInit(ctx, NULL, key, NULL, en_de); + memset(key, 0, keylen); + PBKDF2PARAM_free(kdf); + return 1; + + err: + PBE2PARAM_free(pbe2); + PBKDF2PARAM_free(kdf); + return 0; +} + +#ifdef DEBUG_PKCS5V2 +static void h__dump (const unsigned char *p, int len) +{ + for (; len --; p++) fprintf(stderr, "%02X ", *p); + fprintf(stderr, "\n"); +} +#endif +#endif diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c index e845ce70c7..57b5daa453 100644 --- a/src/lib/libcrypto/evp/p_dec.c +++ b/src/lib/libcrypto/evp/p_dec.c @@ -58,27 +58,30 @@ #include #include "cryptlib.h" -#include "rand.h" -#include "rsa.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#ifndef NO_RSA +#include +#endif +#include +#include +#include -int EVP_PKEY_decrypt(key,ek,ekl,priv) -unsigned char *key; -unsigned char *ek; -int ekl; -EVP_PKEY *priv; +int EVP_PKEY_decrypt(unsigned char *key, unsigned char *ek, int ekl, + EVP_PKEY *priv) { int ret= -1; +#ifndef NO_RSA if (priv->type != EVP_PKEY_RSA) { +#endif EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); +#ifndef NO_RSA goto err; } ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING); err: +#endif return(ret); } diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c index a26bfad02a..4cf6acaf5d 100644 --- a/src/lib/libcrypto/evp/p_enc.c +++ b/src/lib/libcrypto/evp/p_enc.c @@ -58,26 +58,29 @@ #include #include "cryptlib.h" -#include "rand.h" -#include "rsa.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#ifndef NO_RSA +#include +#endif +#include +#include +#include -int EVP_PKEY_encrypt(ek,key,key_len,pubk) -unsigned char *ek; -unsigned char *key; -int key_len; -EVP_PKEY *pubk; +int EVP_PKEY_encrypt(unsigned char *ek, unsigned char *key, int key_len, + EVP_PKEY *pubk) { int ret=0; +#ifndef NO_RSA if (pubk->type != EVP_PKEY_RSA) { +#endif EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); +#ifndef NO_RSA goto err; } ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING); err: +#endif return(ret); } diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c index 395351b373..3422b77de6 100644 --- a/src/lib/libcrypto/evp/p_lib.c +++ b/src/lib/libcrypto/evp/p_lib.c @@ -58,22 +58,13 @@ #include #include "cryptlib.h" -#include "objects.h" -#include "evp.h" -#include "asn1_mac.h" -#include "x509.h" +#include +#include +#include +#include -/* EVPerr(EVP_F_D2I_PKEY,EVP_R_UNSUPPORTED_CIPHER); */ -/* EVPerr(EVP_F_D2I_PKEY,EVP_R_IV_TOO_LARGE); */ - -#ifndef NOPROTO static void EVP_PKEY_free_it(EVP_PKEY *x); -#else -static void EVP_PKEY_free_it(); -#endif - -int EVP_PKEY_bits(pkey) -EVP_PKEY *pkey; +int EVP_PKEY_bits(EVP_PKEY *pkey) { #ifndef NO_RSA if (pkey->type == EVP_PKEY_RSA) @@ -87,9 +78,10 @@ EVP_PKEY *pkey; return(0); } -int EVP_PKEY_size(pkey) -EVP_PKEY *pkey; +int EVP_PKEY_size(EVP_PKEY *pkey) { + if (pkey == NULL) + return(0); #ifndef NO_RSA if (pkey->type == EVP_PKEY_RSA) return(RSA_size(pkey->pkey.rsa)); @@ -102,9 +94,7 @@ EVP_PKEY *pkey; return(0); } -int EVP_PKEY_save_parameters(pkey,mode) -EVP_PKEY *pkey; -int mode; +int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode) { #ifndef NO_DSA if (pkey->type == EVP_PKEY_DSA) @@ -119,8 +109,7 @@ int mode; return(0); } -int EVP_PKEY_copy_parameters(to,from) -EVP_PKEY *to,*from; +int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from) { if (to->type != from->type) { @@ -156,8 +145,7 @@ err: return(0); } -int EVP_PKEY_missing_parameters(pkey) -EVP_PKEY *pkey; +int EVP_PKEY_missing_parameters(EVP_PKEY *pkey) { #ifndef NO_DSA if (pkey->type == EVP_PKEY_DSA) @@ -172,8 +160,7 @@ EVP_PKEY *pkey; return(0); } -int EVP_PKEY_cmp_parameters(a,b) -EVP_PKEY *a,*b; +int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b) { #ifndef NO_DSA if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) @@ -189,7 +176,7 @@ EVP_PKEY *a,*b; return(-1); } -EVP_PKEY *EVP_PKEY_new() +EVP_PKEY *EVP_PKEY_new(void) { EVP_PKEY *ret; @@ -207,10 +194,7 @@ EVP_PKEY *EVP_PKEY_new() return(ret); } -int EVP_PKEY_assign(pkey,type,key) -EVP_PKEY *pkey; -int type; -char *key; +int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key) { if (pkey == NULL) return(0); if (pkey->pkey.ptr != NULL) @@ -221,8 +205,7 @@ char *key; return(1); } -int EVP_PKEY_type(type) -int type; +int EVP_PKEY_type(int type) { switch (type) { @@ -242,8 +225,7 @@ int type; } } -void EVP_PKEY_free(x) -EVP_PKEY *x; +void EVP_PKEY_free(EVP_PKEY *x) { int i; @@ -265,8 +247,7 @@ EVP_PKEY *x; Free((char *)x); } -static void EVP_PKEY_free_it(x) -EVP_PKEY *x; +static void EVP_PKEY_free_it(EVP_PKEY *x) { switch (x->type) { diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c index 28a8e02252..ddb9fd6942 100644 --- a/src/lib/libcrypto/evp/p_open.c +++ b/src/lib/libcrypto/evp/p_open.c @@ -56,19 +56,15 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RSA #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include -int EVP_OpenInit(ctx,type,ek,ekl,iv,priv) -EVP_CIPHER_CTX *ctx; -EVP_CIPHER *type; -unsigned char *ek; -int ekl; -unsigned char *iv; -EVP_PKEY *priv; +int EVP_OpenInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char *ek, + int ekl, unsigned char *iv, EVP_PKEY *priv) { unsigned char *key=NULL; int i,size=0,ret=0; @@ -106,10 +102,7 @@ err: return(ret); } -int EVP_OpenFinal(ctx,out,outl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -int *outl; +int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { int i; @@ -117,3 +110,4 @@ int *outl; EVP_DecryptInit(ctx,NULL,NULL,NULL); return(i); } +#endif diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c index 09a408de35..09b46f4b0e 100644 --- a/src/lib/libcrypto/evp/p_seal.c +++ b/src/lib/libcrypto/evp/p_seal.c @@ -58,20 +58,16 @@ #include #include "cryptlib.h" -#include "rand.h" -#include "rsa.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#ifndef NO_RSA +#include +#endif +#include +#include +#include -int EVP_SealInit(ctx,type,ek,ekl,iv,pubk,npubk) -EVP_CIPHER_CTX *ctx; -EVP_CIPHER *type; -unsigned char **ek; -int *ekl; -unsigned char *iv; -EVP_PKEY **pubk; -int npubk; +int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek, + int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk) { unsigned char key[EVP_MAX_KEY_LENGTH]; int i; @@ -105,10 +101,7 @@ int inl; } */ -void EVP_SealFinal(ctx,out,outl) -EVP_CIPHER_CTX *ctx; -unsigned char *out; -int *outl; +void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { EVP_EncryptFinal(ctx,out,outl); EVP_EncryptInit(ctx,NULL,NULL,NULL); diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c index 073270ce31..1fa32ac17e 100644 --- a/src/lib/libcrypto/evp/p_sign.c +++ b/src/lib/libcrypto/evp/p_sign.c @@ -58,32 +58,25 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include #ifdef undef -void EVP_SignInit(ctx,type) -EVP_MD_CTX *ctx; -EVP_MD *type; +void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type) { EVP_DigestInit(ctx,type); } -void EVP_SignUpdate(ctx,data,count) -EVP_MD_CTX *ctx; -unsigned char *data; -unsigned int count; +void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, + unsigned int count) { EVP_DigestUpdate(ctx,data,count); } #endif -int EVP_SignFinal(ctx,sigret,siglen,pkey) -EVP_MD_CTX *ctx; -unsigned char *sigret; -unsigned int *siglen; -EVP_PKEY *pkey; +int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, + EVP_PKEY *pkey) { unsigned char m[EVP_MAX_MD_SIZE]; unsigned int m_len; @@ -91,7 +84,7 @@ EVP_PKEY *pkey; MS_STATIC EVP_MD_CTX tmp_ctx; *siglen=0; - memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); + EVP_MD_CTX_copy(&tmp_ctx,ctx); EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); for (i=0; i<4; i++) { diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c index 8d727d8f02..dcb54f3abb 100644 --- a/src/lib/libcrypto/evp/p_verify.c +++ b/src/lib/libcrypto/evp/p_verify.c @@ -58,15 +58,12 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include -int EVP_VerifyFinal(ctx,sigbuf,siglen,pkey) -EVP_MD_CTX *ctx; -unsigned char *sigbuf; -unsigned int siglen; -EVP_PKEY *pkey; +int EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf, + unsigned int siglen, EVP_PKEY *pkey) { unsigned char m[EVP_MAX_MD_SIZE]; unsigned int m_len; @@ -88,7 +85,7 @@ EVP_PKEY *pkey; EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); return(-1); } - memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); + EVP_MD_CTX_copy(&tmp_ctx,ctx); EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); if (ctx->digest->verify == NULL) { diff --git a/src/lib/libcrypto/evp/pk_lib.c b/src/lib/libcrypto/evp/pk_lib.c deleted file mode 100644 index 08f9fabbae..0000000000 --- a/src/lib/libcrypto/evp/pk_lib.c +++ /dev/null @@ -1,82 +0,0 @@ -/* crypto/evp/pk_lib.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "cryptlib.h" -#include "evp.h" -#include "objects.h" - -static LHASH *pk_md=NULL; - -static LHASH *pk_md=NULL; - -int EVP_add_pkey_md(oid,pkm,md) -int oid; -EVP_PKEY_METHOD *pkm; -EVP_MD *md; - { - } - -EVP_add_pkey(pkm) -EVP_PKEY_METHOD *pkm; - { - } - -EVP_PKEY_METHOD:q - - diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c index c858b518ff..176574766b 100644 --- a/src/lib/libcrypto/ex_data.c +++ b/src/lib/libcrypto/ex_data.c @@ -58,34 +58,30 @@ #include #include -#include "buffer.h" -#include "bio.h" -#include "lhash.h" +#include +#include +#include #include "cryptlib.h" -int CRYPTO_get_ex_new_index(idx,skp,argl,argp,new_func,dup_func,free_func) -int idx; -STACK **skp; -long argl; -char *argp; -int (*new_func)(); -int (*dup_func)(); -void (*free_func)(); +int CRYPTO_get_ex_new_index(int idx, STACK **skp, long argl, char *argp, + int (*new_func)(), int (*dup_func)(), void (*free_func)()) { + int ret= -1; CRYPTO_EX_DATA_FUNCS *a; + MemCheck_off(); if (*skp == NULL) *skp=sk_new_null(); if (*skp == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); - return(-1); + goto err; } a=(CRYPTO_EX_DATA_FUNCS *)Malloc(sizeof(CRYPTO_EX_DATA_FUNCS)); if (a == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); - return(-1); + goto err; } a->argl=argl; a->argp=argp; @@ -98,17 +94,17 @@ void (*free_func)(); { CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); Free(a); - return(-1); + goto err; } } - sk_value(*skp,idx)=(char *)a; + sk_set(*skp,idx, (char *)a); + ret=idx; +err: + MemCheck_on(); return(idx); } -int CRYPTO_set_ex_data(ad,idx,val) -CRYPTO_EX_DATA *ad; -int idx; -char *val; +int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, char *val) { int i; @@ -131,13 +127,11 @@ char *val; } i++; } - sk_value(ad->sk,idx)=val; + sk_set(ad->sk,idx,val); return(1); } -char *CRYPTO_get_ex_data(ad,idx) -CRYPTO_EX_DATA *ad; -int idx; +char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad, int idx) { if (ad->sk == NULL) return(0); @@ -147,13 +141,12 @@ int idx; return(sk_value(ad->sk,idx)); } -/* The callback is called with the 'object', which is the origional data object +/* The callback is called with the 'object', which is the original data object * being duplicated, a pointer to the * 'new' object to be inserted, the index, and the argi/argp */ -int CRYPTO_dup_ex_data(meth,to,from) -STACK *meth; -CRYPTO_EX_DATA *to,*from; +int CRYPTO_dup_ex_data(STACK *meth, CRYPTO_EX_DATA *to, + CRYPTO_EX_DATA *from) { int i,j,m,r; CRYPTO_EX_DATA_FUNCS *mm; @@ -179,10 +172,7 @@ CRYPTO_EX_DATA *to,*from; } /* Call each free callback */ -void CRYPTO_free_ex_data(meth,obj,ad) -STACK *meth; -char *obj; -CRYPTO_EX_DATA *ad; +void CRYPTO_free_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad) { CRYPTO_EX_DATA_FUNCS *m; char *ptr; @@ -208,10 +198,7 @@ CRYPTO_EX_DATA *ad; } } -void CRYPTO_new_ex_data(meth,obj,ad) -STACK *meth; -char *obj; -CRYPTO_EX_DATA *ad; +void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad) { CRYPTO_EX_DATA_FUNCS *m; char *ptr; diff --git a/src/lib/libcrypto/hmac/Makefile.ssl b/src/lib/libcrypto/hmac/Makefile.ssl index 7a042b7261..4f5512877e 100644 --- a/src/lib/libcrypto/hmac/Makefile.ssl +++ b/src/lib/libcrypto/hmac/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,28 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +hmac.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +hmac.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +hmac.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +hmac.o: ../../include/openssl/des.h ../../include/openssl/dh.h +hmac.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h +hmac.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h +hmac.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +hmac.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +hmac.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +hmac.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h +hmac.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +hmac.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +hmac.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +hmac.o: ../../include/openssl/stack.h diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c index fb09129963..5c349bbb56 100644 --- a/src/lib/libcrypto/hmac/hmac.c +++ b/src/lib/libcrypto/hmac/hmac.c @@ -58,13 +58,10 @@ #include #include #include -#include "hmac.h" +#include -void HMAC_Init(ctx,key,len,md) -HMAC_CTX *ctx; -unsigned char *key; -int len; -EVP_MD *md; +void HMAC_Init(HMAC_CTX *ctx, const void *key, int len, + const EVP_MD *md) { int i,j,reset=0; unsigned char pad[HMAC_MAX_MD_CBLOCK]; @@ -112,18 +109,12 @@ EVP_MD *md; memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx)); } -void HMAC_Update(ctx,data,len) -HMAC_CTX *ctx; -unsigned char *data; -int len; +void HMAC_Update(HMAC_CTX *ctx, unsigned char *data, int len) { EVP_DigestUpdate(&(ctx->md_ctx),data,len); } -void HMAC_Final(ctx,md,len) -HMAC_CTX *ctx; -unsigned char *md; -unsigned int *len; +void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) { int j; unsigned int i; @@ -137,20 +128,14 @@ unsigned int *len; EVP_DigestFinal(&(ctx->md_ctx),md,len); } -void HMAC_cleanup(ctx) -HMAC_CTX *ctx; +void HMAC_cleanup(HMAC_CTX *ctx) { memset(ctx,0,sizeof(HMAC_CTX)); } -unsigned char *HMAC(evp_md,key,key_len,d,n,md,md_len) -EVP_MD *evp_md; -unsigned char *key; -int key_len; -unsigned char *d; -int n; -unsigned char *md; -unsigned int *md_len; +unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, + unsigned char *d, int n, unsigned char *md, + unsigned int *md_len) { HMAC_CTX c; static unsigned char m[EVP_MAX_MD_SIZE]; diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h index e6b43f52c4..f928975fcd 100644 --- a/src/lib/libcrypto/hmac/hmac.h +++ b/src/lib/libcrypto/hmac/hmac.h @@ -62,13 +62,17 @@ extern "C" { #endif -#include "evp.h" +#ifdef NO_HMAC +#error HMAC is disabled. +#endif + +#include #define HMAC_MAX_MD_CBLOCK 64 typedef struct hmac_ctx_st { - EVP_MD *md; + const EVP_MD *md; EVP_MD_CTX md_ctx; EVP_MD_CTX i_ctx; EVP_MD_CTX o_ctx; @@ -78,26 +82,16 @@ typedef struct hmac_ctx_st #define HMAC_size(e) (EVP_MD_size((e)->md)) -#ifndef NOPROTO -void HMAC_Init(HMAC_CTX *ctx, unsigned char *key, int len, - EVP_MD *md); +void HMAC_Init(HMAC_CTX *ctx, const void *key, int len, + const EVP_MD *md); void HMAC_Update(HMAC_CTX *ctx,unsigned char *key, int len); void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); void HMAC_cleanup(HMAC_CTX *ctx); -unsigned char *HMAC(EVP_MD *evp_md, unsigned char *key, int key_len, - unsigned char *d, int n, unsigned char *md, unsigned int *md_len); - +unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, + unsigned char *d, int n, unsigned char *md, + unsigned int *md_len); -#else - -void HMAC_Init(); -void HMAC_Update(); -void HMAC_Final(); -void HMAC_cleanup(); -unsigned char *HMAC(); - -#endif #ifdef __cplusplus } diff --git a/src/lib/libcrypto/hmac/hmactest.c b/src/lib/libcrypto/hmac/hmactest.c index 5938e375dc..9a67dff36a 100644 --- a/src/lib/libcrypto/hmac/hmactest.c +++ b/src/lib/libcrypto/hmac/hmactest.c @@ -59,7 +59,19 @@ #include #include #include -#include "hmac.h" + +#ifdef NO_HMAC +int main(int argc, char *argv[]) +{ + printf("No HMAC support\n"); + return(0); +} +#else +#include + +#ifdef CHARSET_EBCDIC +#include +#endif struct test_st { @@ -102,19 +114,19 @@ struct test_st }; -#ifndef NOPROTO static char *pt(unsigned char *md); -#else -static char *pt(); -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,err=0; char *p; +#ifdef CHARSET_EBCDIC + ebcdic2ascii(test[0].data, test[0].data, test[0].data_len); + ebcdic2ascii(test[1].data, test[1].data, test[1].data_len); + ebcdic2ascii(test[2].key, test[2].key, test[2].key_len); + ebcdic2ascii(test[2].data, test[2].data, test[2].data_len); +#endif + for (i=0; i<4; i++) { p=pt(HMAC(EVP_md5(), @@ -135,8 +147,7 @@ char *argv[]; return(0); } -static char *pt(md) -unsigned char *md; +static char *pt(unsigned char *md) { int i; static char buf[80]; @@ -145,3 +156,4 @@ unsigned char *md; sprintf(&(buf[i*2]),"%02x",md[i]); return(buf); } +#endif diff --git a/src/lib/libcrypto/idea/Makefile.ssl b/src/lib/libcrypto/idea/Makefile.ssl index 41b42ce03b..3bd3e53ef4 100644 --- a/src/lib/libcrypto/idea/Makefile.ssl +++ b/src/lib/libcrypto/idea/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,24 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +i_cbc.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h +i_cbc.o: idea_lcl.h +i_cfb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h +i_cfb64.o: idea_lcl.h +i_ecb.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h +i_ecb.o: ../../include/openssl/opensslv.h idea_lcl.h +i_ofb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h +i_ofb64.o: idea_lcl.h +i_skey.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h +i_skey.o: idea_lcl.h diff --git a/src/lib/libcrypto/idea/idea.h b/src/lib/libcrypto/idea/idea.h new file mode 100644 index 0000000000..ae32f5692e --- /dev/null +++ b/src/lib/libcrypto/idea/idea.h @@ -0,0 +1,99 @@ +/* crypto/idea/idea.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_IDEA_H +#define HEADER_IDEA_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef NO_IDEA +#error IDEA is disabled. +#endif + +#define IDEA_ENCRYPT 1 +#define IDEA_DECRYPT 0 + +#include /* IDEA_INT */ +#define IDEA_BLOCK 8 +#define IDEA_KEY_LENGTH 16 + +typedef struct idea_key_st + { + IDEA_INT data[9][6]; + } IDEA_KEY_SCHEDULE; + +const char *idea_options(void); +void idea_ecb_encrypt(unsigned char *in, unsigned char *out, + IDEA_KEY_SCHEDULE *ks); +void idea_set_encrypt_key(unsigned char *key, IDEA_KEY_SCHEDULE *ks); +void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); +void idea_cbc_encrypt(unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc); +void idea_cfb64_encrypt(unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, + int *num,int enc); +void idea_ofb64_encrypt(unsigned char *in, unsigned char *out, + long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num); +void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/libcrypto/install.com b/src/lib/libcrypto/install.com new file mode 100644 index 0000000000..b75d1b44b2 --- /dev/null +++ b/src/lib/libcrypto/install.com @@ -0,0 +1,128 @@ +$! INSTALL.COM -- Installs the files in a given directory tree +$! +$! Author: Richard Levitte +$! Time of creation: 22-MAY-1998 10:13 +$! +$! P1 root of the directory tree +$! +$ IF P1 .EQS. "" +$ THEN +$ WRITE SYS$OUTPUT "First argument missing." +$ WRITE SYS$OUTPUT "Should be the directory where you want things installed." +$ EXIT +$ ENDIF +$ +$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0" +$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY") +$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") - + - "[000000." - "][" - "[" - "]" +$ ROOT = ROOT_DEV + "[" + ROOT_DIR +$ +$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC +$ DEFINE/NOLOG WRK_SSLVLIB WRK_SSLROOT:[VAX_LIB] +$ DEFINE/NOLOG WRK_SSLALIB WRK_SSLROOT:[ALPHA_LIB] +$ DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE] +$ +$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN - + CREATE/DIR/LOG WRK_SSLROOT:[000000] +$ IF F$PARSE("WRK_SSLVLIB:") .EQS. "" THEN - + CREATE/DIR/LOG WRK_SSLVLIB: +$ IF F$PARSE("WRK_SSLALIB:") .EQS. "" THEN - + CREATE/DIR/LOG WRK_SSLALIB: +$ IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN - + CREATE/DIR/LOG WRK_SSLINCLUDE: +$ +$ SDIRS := ,MD2,MD5,SHA,MDC2,HMAC,RIPEMD,- + DES,RC2,RC4,RC5,IDEA,BF,CAST,- + BN,RSA,DSA,DH,- + BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,- + EVP,ASN1,PEM,X509,X509V3,- + CONF,TXT_DB,PKCS7,PKCS12,COMP +$ EXHEADER_ := crypto.h,tmdiff.h,opensslv.h,opensslconf.h,ebcdic.h +$ EXHEADER_MD2 := md2.h +$ EXHEADER_MD5 := md5.h +$ EXHEADER_SHA := sha.h +$ EXHEADER_MDC2 := mdc2.h +$ EXHEADER_HMAC := hmac.h +$ EXHEADER_RIPEMD := ripemd.h +$ EXHEADER_DES := des.h +$ EXHEADER_RC2 := rc2.h +$ EXHEADER_RC4 := rc4.h +$ EXHEADER_RC5 := rc5.h +$ EXHEADER_IDEA := idea.h +$ EXHEADER_BF := blowfish.h +$ EXHEADER_CAST := cast.h +$ EXHEADER_BN := bn.h +$ EXHEADER_RSA := rsa.h +$ EXHEADER_DSA := dsa.h +$ EXHEADER_DH := dh.h +$ EXHEADER_BUFFER := buffer.h +$ EXHEADER_BIO := bio.h +$ EXHEADER_STACK := stack.h,safestack.h +$ EXHEADER_LHASH := lhash.h +$ EXHEADER_RAND := rand.h +$ EXHEADER_ERR := err.h +$ EXHEADER_OBJECTS := objects.h +$ EXHEADER_EVP := evp.h +$ EXHEADER_ASN1 := asn1.h,asn1_mac.h +$ EXHEADER_PEM := pem.h,pem2.h +$ EXHEADER_X509 := x509.h,x509_vfy.h +$ EXHEADER_X509V3 := x509v3.h +$ EXHEADER_CONF := conf.h +$ EXHEADER_TXT_DB := txt_db.h +$ EXHEADER_PKCS7 := pkcs7.h +$ EXHEADER_PKCS12 := pkcs12.h +$ EXHEADER_COMP := comp.h +$ LIBS := LIBCRYPTO +$ +$ VEXE_DIR := [-.VAX.EXE.CRYPTO] +$ AEXE_DIR := [-.AXP.EXE.CRYPTO] +$ +$ I = 0 +$ LOOP_SDIRS: +$ D = F$EDIT(F$ELEMENT(I, ",", SDIRS),"TRIM") +$ I = I + 1 +$ IF D .EQS. "," THEN GOTO LOOP_SDIRS_END +$ tmp = EXHEADER_'D' +$ IF D .EQS. "" +$ THEN +$ COPY 'tmp' WRK_SSLINCLUDE: /LOG +$ ELSE +$ COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG +$ ENDIF +$ GOTO LOOP_SDIRS +$ LOOP_SDIRS_END: +$ +$ I = 0 +$ LOOP_LIB: +$ E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM") +$ I = I + 1 +$ IF E .EQS. "," THEN GOTO LOOP_LIB_END +$ SET NOON +$ IF F$SEARCH(VEXE_DIR+E+".OLB") .NES. "" +$ THEN +$ COPY 'VEXE_DIR''E'.OLB WRK_SSLVLIB:'E'.OLB/log +$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.OLB +$ ENDIF +$ ! Preparing for the time when we have shareable images +$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. "" +$ THEN +$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVLIB:'E'.EXE/log +$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.EXE +$ ENDIF +$ IF F$SEARCH(AEXE_DIR+E+".OLB") .NES. "" +$ THEN +$ COPY 'AEXE_DIR''E'.OLB WRK_SSLALIB:'E'.OLB/log +$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.OLB +$ ENDIF +$ ! Preparing for the time when we have shareable images +$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. "" +$ THEN +$ COPY 'AEXE_DIR''E'.EXE WRK_SSLALIB:'E'.EXE/log +$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.EXE +$ ENDIF +$ SET ON +$ GOTO LOOP_LIB +$ LOOP_LIB_END: +$ +$ EXIT diff --git a/src/lib/libcrypto/lhash/Makefile.ssl b/src/lib/libcrypto/lhash/Makefile.ssl index cb08547b4f..cc9ff46b04 100644 --- a/src/lib/libcrypto/lhash/Makefile.ssl +++ b/src/lib/libcrypto/lhash/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,22 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +lh_stats.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +lh_stats.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h +lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +lh_stats.o: ../cryptlib.h +lhash.o: ../../include/openssl/crypto.h ../../include/openssl/lhash.h +lhash.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h diff --git a/src/lib/libcrypto/lhash/lh_stats.c b/src/lib/libcrypto/lhash/lh_stats.c index 23fe82f777..80b931c12b 100644 --- a/src/lib/libcrypto/lhash/lh_stats.c +++ b/src/lib/libcrypto/lhash/lh_stats.c @@ -63,13 +63,11 @@ * and things should work as expected */ #include "cryptlib.h" -#include "lhash.h" +#include #ifndef HEADER_BIO_H -void lh_stats(lh, out) -LHASH *lh; -FILE *out; +void lh_stats(LHASH *lh, FILE *out) { fprintf(out,"num_items = %lu\n",lh->num_items); fprintf(out,"num_nodes = %u\n",lh->num_nodes); @@ -95,9 +93,7 @@ FILE *out; #endif } -void lh_node_stats(lh, out) -LHASH *lh; -FILE *out; +void lh_node_stats(LHASH *lh, FILE *out) { LHASH_NODE *n; unsigned int i,num; @@ -110,9 +106,7 @@ FILE *out; } } -void lh_node_usage_stats(lh, out) -LHASH *lh; -FILE *out; +void lh_node_usage_stats(LHASH *lh, FILE *out) { LHASH_NODE *n; unsigned long num; @@ -142,9 +136,7 @@ FILE *out; #else #ifndef NO_FP_API -void lh_stats(lh,fp) -LHASH *lh; -FILE *fp; +void lh_stats(LHASH *lh, FILE *fp) { BIO *bp; @@ -156,9 +148,7 @@ FILE *fp; end:; } -void lh_node_stats(lh,fp) -LHASH *lh; -FILE *fp; +void lh_node_stats(LHASH *lh, FILE *fp) { BIO *bp; @@ -170,9 +160,7 @@ FILE *fp; end:; } -void lh_node_usage_stats(lh,fp) -LHASH *lh; -FILE *fp; +void lh_node_usage_stats(LHASH *lh, FILE *fp) { BIO *bp; @@ -186,9 +174,7 @@ end:; #endif -void lh_stats_bio(lh, out) -LHASH *lh; -BIO *out; +void lh_stats_bio(LHASH *lh, BIO *out) { char buf[128]; @@ -236,9 +222,7 @@ BIO *out; #endif } -void lh_node_stats_bio(lh, out) -LHASH *lh; -BIO *out; +void lh_node_stats_bio(LHASH *lh, BIO *out) { LHASH_NODE *n; unsigned int i,num; @@ -253,9 +237,7 @@ BIO *out; } } -void lh_node_usage_stats_bio(lh, out) -LHASH *lh; -BIO *out; +void lh_node_usage_stats_bio(LHASH *lh, BIO *out) { LHASH_NODE *n; unsigned long num; diff --git a/src/lib/libcrypto/lhash/lh_test.c b/src/lib/libcrypto/lhash/lh_test.c index 294b42bc82..08138b52c3 100644 --- a/src/lib/libcrypto/lhash/lh_test.c +++ b/src/lib/libcrypto/lhash/lh_test.c @@ -59,7 +59,7 @@ #include #include #include -#include "lhash.h" +#include main() { diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c index 6dfb5c9ccc..801322beb6 100644 --- a/src/lib/libcrypto/lhash/lhash.c +++ b/src/lib/libcrypto/lhash/lhash.c @@ -56,11 +56,14 @@ * [including the GNU Public Licence.] */ -char *lh_version="lhash part of SSLeay 0.9.0b 29-Jun-1998"; - /* Code for dynamic hash table routines * Author - Eric Young v 2.0 * + * 2.2 eay - added #include "crypto.h" so the memory leak checking code is + * present. eay 18-Jun-98 + * + * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98 + * * 2.0 eay - Fixed a bug that occured when using lh_delete * from inside lh_doall(). As entries were deleted, * the 'table' was 'contract()ed', making some entries @@ -94,14 +97,16 @@ char *lh_version="lhash part of SSLeay 0.9.0b 29-Jun-1998"; #include #include #include -#include "lhash.h" +#include +#include + +const char *lh_version="lhash" OPENSSL_VERSION_PTEXT; #undef MIN_NODES #define MIN_NODES 16 #define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ #define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */ -#ifndef NOPROTO #define P_CP char * #define P_CPP char *,char * @@ -109,26 +114,14 @@ static void expand(LHASH *lh); static void contract(LHASH *lh); static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash); -#else - -#define P_CP -#define P_CPP -static void expand(); -static void contract(); -static LHASH_NODE **getrn(); - -#endif - -LHASH *lh_new(h, c) -unsigned long (*h)(); -int (*c)(); +LHASH *lh_new(unsigned long (*h)(), int (*c)()) { LHASH *ret; int i; - if ((ret=(LHASH *)malloc(sizeof(LHASH))) == NULL) + if ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL) goto err0; - if ((ret->b=(LHASH_NODE **)malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL) + if ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL) goto err1; for (i=0; ib[i]=NULL; @@ -156,41 +149,43 @@ int (*c)(); ret->num_retrieve_miss=0; ret->num_hash_comps=0; + ret->error=0; return(ret); err1: - free((char *)ret); + Free((char *)ret); err0: return(NULL); } -void lh_free(lh) -LHASH *lh; +void lh_free(LHASH *lh) { unsigned int i; LHASH_NODE *n,*nn; + if(lh == NULL) + return; + for (i=0; inum_nodes; i++) { n=lh->b[i]; while (n != NULL) { nn=n->next; - free(n); + Free(n); n=nn; } } - free((char *)lh->b); - free((char *)lh); + Free((char *)lh->b); + Free((char *)lh); } -char *lh_insert(lh, data) -LHASH *lh; -char *data; +char *lh_insert(LHASH *lh, char *data) { unsigned long hash; LHASH_NODE *nn,**rn; char *ret; + lh->error=0; if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) expand(lh); @@ -198,8 +193,11 @@ char *data; if (*rn == NULL) { - if ((nn=(LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL) + if ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL) + { + lh->error++; return(NULL); + } nn->data=data; nn->next=NULL; #ifndef NO_HASH_COMP @@ -219,14 +217,13 @@ char *data; return(ret); } -char *lh_delete(lh, data) -LHASH *lh; -char *data; +char *lh_delete(LHASH *lh, char *data) { unsigned long hash; LHASH_NODE *nn,**rn; char *ret; + lh->error=0; rn=getrn(lh,data,&hash); if (*rn == NULL) @@ -239,7 +236,7 @@ char *data; nn= *rn; *rn=nn->next; ret=nn->data; - free((char *)nn); + Free((char *)nn); lh->num_delete++; } @@ -251,14 +248,13 @@ char *data; return(ret); } -char *lh_retrieve(lh, data) -LHASH *lh; -char *data; +char *lh_retrieve(LHASH *lh, char *data) { unsigned long hash; LHASH_NODE **rn; char *ret; + lh->error=0; rn=getrn(lh,data,&hash); if (*rn == NULL) @@ -274,17 +270,12 @@ char *data; return(ret); } -void lh_doall(lh, func) -LHASH *lh; -void (*func)(); +void lh_doall(LHASH *lh, void (*func)()) { lh_doall_arg(lh,func,NULL); } -void lh_doall_arg(lh, func, arg) -LHASH *lh; -void (*func)(); -char *arg; +void lh_doall_arg(LHASH *lh, void (*func)(), char *arg) { int i; LHASH_NODE *a,*n; @@ -305,8 +296,7 @@ char *arg; } } -static void expand(lh) -LHASH *lh; +static void expand(LHASH *lh) { LHASH_NODE **n,**n1,**n2,*np; unsigned int p,i,j; @@ -342,11 +332,12 @@ LHASH *lh; if ((lh->p) >= lh->pmax) { j=(int)lh->num_alloc_nodes*2; - n=(LHASH_NODE **)realloc((char *)lh->b, + n=(LHASH_NODE **)Realloc((char *)lh->b, (unsigned int)sizeof(LHASH_NODE *)*j); if (n == NULL) { /* fputs("realloc error in lhash",stderr); */ + lh->error++; lh->p=0; return; } @@ -361,8 +352,7 @@ LHASH *lh; } } -static void contract(lh) -LHASH *lh; +static void contract(LHASH *lh) { LHASH_NODE **n,*n1,*np; @@ -370,11 +360,12 @@ LHASH *lh; lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */ if (lh->p == 0) { - n=(LHASH_NODE **)realloc((char *)lh->b, + n=(LHASH_NODE **)Realloc((char *)lh->b, (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); if (n == NULL) { /* fputs("realloc error in lhash",stderr); */ + lh->error++; return; } lh->num_contract_reallocs++; @@ -400,10 +391,7 @@ LHASH *lh; } } -static LHASH_NODE **getrn(lh, data, rhash) -LHASH *lh; -char *data; -unsigned long *rhash; +static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash) { LHASH_NODE **ret,*n1; unsigned long hash,nn; @@ -457,8 +445,7 @@ char *str; * no collisions on /usr/dict/words and it distributes on %2^n quite * well, not as good as MD5, but still good. */ -unsigned long lh_strhash(c) -char *c; +unsigned long lh_strhash(const char *c) { unsigned long ret=0; long n; diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h index 70cbc6dfe7..6e5a1fe708 100644 --- a/src/lib/libcrypto/lhash/lhash.h +++ b/src/lib/libcrypto/lhash/lhash.h @@ -67,6 +67,10 @@ extern "C" { #endif +#ifndef NO_FP_API +#include +#endif + typedef struct lhash_node_st { char *data; @@ -102,11 +106,16 @@ typedef struct lhash_st unsigned long num_retrieve; unsigned long num_retrieve_miss; unsigned long num_hash_comps; + + int error; } LHASH; #define LH_LOAD_MULT 256 -#ifndef NOPROTO +/* Indicates a malloc() error in the last call, this is only bad + * in lh_insert(). */ +#define lh_error(lh) ((lh)->error) + LHASH *lh_new(unsigned long (*h)(), int (*c)()); void lh_free(LHASH *lh); char *lh_insert(LHASH *lh, char *data); @@ -114,7 +123,7 @@ char *lh_delete(LHASH *lh, char *data); char *lh_retrieve(LHASH *lh, char *data); void lh_doall(LHASH *lh, void (*func)(/* char *b */)); void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg); -unsigned long lh_strhash(char *c); +unsigned long lh_strhash(const char *c); #ifndef NO_FP_API void lh_stats(LHASH *lh, FILE *out); @@ -127,26 +136,6 @@ void lh_stats_bio(LHASH *lh, BIO *out); void lh_node_stats_bio(LHASH *lh, BIO *out); void lh_node_usage_stats_bio(LHASH *lh, BIO *out); #endif -#else -LHASH *lh_new(); -void lh_free(); -char *lh_insert(); -char *lh_delete(); -char *lh_retrieve(); -void lh_doall(); -void lh_doall_arg(); -unsigned long lh_strhash(); - -#ifndef NO_FP_API -void lh_stats(); -void lh_node_stats(); -void lh_node_usage_stats(); -#endif -void lh_stats_bio(); -void lh_node_stats_bio(); -void lh_node_usage_stats_bio(); -#endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/lhash/num.pl b/src/lib/libcrypto/lhash/num.pl index 4d937c1f90..30fedf9cd5 100644 --- a/src/lib/libcrypto/lhash/num.pl +++ b/src/lib/libcrypto/lhash/num.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl #node 10 -> 4 diff --git a/src/lib/libcrypto/libvms.com b/src/lib/libcrypto/libvms.com deleted file mode 100644 index 44f90c65b0..0000000000 --- a/src/lib/libcrypto/libvms.com +++ /dev/null @@ -1,31 +0,0 @@ -$! -$! Compile crypto.c as several subset modules and insert in crypto-xxx.olb. -$! If P1 is specifed, it specifies alternate list of subsets to compile. -$! -$ libname = "CRYPTO-AXP.OLB" -$ subset_list = "LIB,ASN1,BN,BUFFER,CONF,DES,DH,DSA,ERROR,EVP,IDEA,LHASH,MD," + - - "METH,OBJECTS,PEM,RAND,RC,RSA,SHA,STACK,TXT_DB,X509" -$ if p1 .nes. "" then subset_list = p1 -$! -$ if f$getsyi("CPU") .lt. 128 then libname = "CRYPTO-VAX.OLB" -$ if f$search(libname) .eqs. "" then library/create/object/log 'libname' -$! -$ cc = "cc/include=[-.include]/prefix=all" + P2 -$! -$ i = 0 -$ next_subset: -$ subset = f$element(i,",",subset_list) -$ if subset .eqs. "," then goto done -$ i = i + 1 -$ create crypto_'subset'.subset -#include "crypto.c" -$ ofile = "sys$disk:[]crypto_" + subset + ".obj" -$ on warning then goto next_subset -$ write sys$output "Compiling ", ofile -$ cc /object='ofile' crypto_'subset'.subset - - /define=(CRYPTO_SUBSET,CRYPTO_'subset'_SUBSET) -$ library/replace/log 'libname'/module=CRYPTO_'subset' 'ofile' -$ goto next_subset -$! -$ done: -$ exit diff --git a/src/lib/libcrypto/md2/Makefile.ssl b/src/lib/libcrypto/md2/Makefile.ssl index d8e7200c83..67ce450788 100644 --- a/src/lib/libcrypto/md2/Makefile.ssl +++ b/src/lib/libcrypto/md2/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -20,7 +22,7 @@ TEST=md2test.c APPS= LIB=$(TOP)/libcrypto.a -LIBSRC=md2_dgst.c md5_one.c +LIBSRC=md2_dgst.c md2_one.c LIBOBJ=md2_dgst.o md2_one.o SRC= $(LIBSRC) @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,22 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +md2_dgst.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h +md2_dgst.o: ../../include/openssl/opensslv.h +md2_one.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +md2_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +md2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +md2_one.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h +md2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +md2_one.o: ../cryptlib.h diff --git a/src/lib/libcrypto/md2/md2.c b/src/lib/libcrypto/md2/md2.c index 7f3ab64a43..f4d6f62264 100644 --- a/src/lib/libcrypto/md2/md2.c +++ b/src/lib/libcrypto/md2/md2.c @@ -58,25 +58,15 @@ #include #include -#include "md2.h" +#include #define BUFSIZE 1024*16 -#ifndef NOPROTO void do_fp(FILE *f); void pt(unsigned char *md); int read(int, void *, unsigned int); void exit(int); -#else -void do_fp(); -void pt(); -int read(); -void exit(); -#endif - -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,err=0; FILE *IN; @@ -105,8 +95,7 @@ char *argv[]; return(err); } -void do_fp(f) -FILE *f; +void do_fp(FILE *f) { MD2_CTX c; unsigned char md[MD2_DIGEST_LENGTH]; @@ -125,8 +114,7 @@ FILE *f; pt(md); } -void pt(md) -unsigned char *md; +void pt(unsigned char *md) { int i; diff --git a/src/lib/libcrypto/md2/md2.h b/src/lib/libcrypto/md2/md2.h new file mode 100644 index 0000000000..0d3592506c --- /dev/null +++ b/src/lib/libcrypto/md2/md2.h @@ -0,0 +1,91 @@ +/* crypto/md/md2.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_MD2_H +#define HEADER_MD2_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef NO_MD2 +#error MD2 is disabled. +#endif + +#define MD2_DIGEST_LENGTH 16 +#define MD2_BLOCK 16 +#include /* MD2_INT */ + +typedef struct MD2state_st + { + int num; + unsigned char data[MD2_BLOCK]; + MD2_INT cksm[MD2_BLOCK]; + MD2_INT state[MD2_BLOCK]; + } MD2_CTX; + +const char *MD2_options(void); +void MD2_Init(MD2_CTX *c); +void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len); +void MD2_Final(unsigned char *md, MD2_CTX *c); +unsigned char *MD2(unsigned char *d, unsigned long n,unsigned char *md); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/libcrypto/md2/md2.org b/src/lib/libcrypto/md2/md2.org deleted file mode 100644 index 9f39933790..0000000000 --- a/src/lib/libcrypto/md2/md2.org +++ /dev/null @@ -1,106 +0,0 @@ -/* crypto/md/md2.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify md2.org since md2.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - - -#ifndef HEADER_MD2_H -#define HEADER_MD2_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define MD2_DIGEST_LENGTH 16 -#define MD2_BLOCK 16 - -#define MD2_INT unsigned int - -typedef struct MD2state_st - { - int num; - unsigned char data[MD2_BLOCK]; - MD2_INT cksm[MD2_BLOCK]; - MD2_INT state[MD2_BLOCK]; - } MD2_CTX; - -#ifndef NOPROTO -char *MD2_options(void); -void MD2_Init(MD2_CTX *c); -void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len); -void MD2_Final(unsigned char *md, MD2_CTX *c); -unsigned char *MD2(unsigned char *d, unsigned long n,unsigned char *md); -#else -char *MD2_options(); -void MD2_Init(); -void MD2_Update(); -void MD2_Final(); -unsigned char *MD2(); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/lib/libcrypto/md2/md2_dgst.c b/src/lib/libcrypto/md2/md2_dgst.c index 5cbd36f3fe..c7d8d6aef5 100644 --- a/src/lib/libcrypto/md2/md2_dgst.c +++ b/src/lib/libcrypto/md2/md2_dgst.c @@ -59,21 +59,17 @@ #include #include #include -#include "md2.h" +#include +#include -char *MD2_version="MD2 part of SSLeay 0.9.0b 29-Jun-1998"; +const char *MD2_version="MD2" OPENSSL_VERSION_PTEXT; /* Implemented from RFC1319 The MD2 Message-Digest Algorithm */ #define UCHAR unsigned char -#ifndef NOPROTO static void md2_block(MD2_CTX *c, unsigned char *d); -#else -static void md2_block(); -#endif - /* The magic S table - I have converted it to hex since it is * basicaly just a random byte string. */ static MD2_INT S[256]={ @@ -111,7 +107,7 @@ static MD2_INT S[256]={ 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14, }; -char *MD2_options() +const char *MD2_options(void) { if (sizeof(MD2_INT) == 1) return("md2(char)"); @@ -119,8 +115,7 @@ char *MD2_options() return("md2(int)"); } -void MD2_Init(c) -MD2_CTX *c; +void MD2_Init(MD2_CTX *c) { c->num=0; memset(c->state,0,MD2_BLOCK*sizeof(MD2_INT)); @@ -128,10 +123,7 @@ MD2_CTX *c; memset(c->data,0,MD2_BLOCK); } -void MD2_Update(c, data, len) -MD2_CTX *c; -register unsigned char *data; -unsigned long len; +void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len) { register UCHAR *p; @@ -169,9 +161,7 @@ unsigned long len; c->num=(int)len; } -static void md2_block(c, d) -MD2_CTX *c; -unsigned char *d; +static void md2_block(MD2_CTX *c, unsigned char *d) { register MD2_INT t,*sp1,*sp2; register int i,j; @@ -207,9 +197,7 @@ unsigned char *d; memset(state,0,48*sizeof(MD2_INT)); } -void MD2_Final(md, c) -unsigned char *md; -MD2_CTX *c; +void MD2_Final(unsigned char *md, MD2_CTX *c) { int i,v; register UCHAR *cp; diff --git a/src/lib/libcrypto/md2/md2_one.c b/src/lib/libcrypto/md2/md2_one.c index 513bf62fdb..7157299d95 100644 --- a/src/lib/libcrypto/md2/md2_one.c +++ b/src/lib/libcrypto/md2/md2_one.c @@ -58,22 +58,35 @@ #include #include "cryptlib.h" -#include "md2.h" +#include /* This is a separate file so that #defines in cryptlib.h can * map my MD functions to different names */ -unsigned char *MD2(d, n, md) -unsigned char *d; -unsigned long n; -unsigned char *md; +unsigned char *MD2(unsigned char *d, unsigned long n, unsigned char *md) { MD2_CTX c; static unsigned char m[MD2_DIGEST_LENGTH]; if (md == NULL) md=m; MD2_Init(&c); +#ifndef CHARSET_EBCDIC MD2_Update(&c,d,n); +#else + { + char temp[1024]; + unsigned long chunk; + + while (n > 0) + { + chunk = (n > sizeof(temp)) ? sizeof(temp) : n; + ebcdic2ascii(temp, d, chunk); + MD2_Update(&c,temp,chunk); + n -= chunk; + d += chunk; + } + } +#endif MD2_Final(md,&c); memset(&c,0,sizeof(c)); /* Security consideration */ return(md); diff --git a/src/lib/libcrypto/md2/md2test.c b/src/lib/libcrypto/md2/md2test.c index 55924d44cd..461d124957 100644 --- a/src/lib/libcrypto/md2/md2test.c +++ b/src/lib/libcrypto/md2/md2test.c @@ -59,7 +59,19 @@ #include #include #include -#include "md2.h" + +#ifdef NO_MD2 +int main(int argc, char *argv[]) +{ + printf("No MD2 support\n"); + return(0); +} +#else +#include + +#ifdef CHARSET_EBCDIC +#include +#endif char *test[]={ "", @@ -82,15 +94,8 @@ char *ret[]={ "d5976f79d83d3a0dc9806c3c66f3efd8", }; -#ifndef NOPROTO static char *pt(unsigned char *md); -#else -static char *pt(); -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,err=0; char **P,**R; @@ -118,8 +123,7 @@ char *argv[]; return(0); } -static char *pt(md) -unsigned char *md; +static char *pt(unsigned char *md) { int i; static char buf[80]; @@ -128,3 +132,4 @@ unsigned char *md; sprintf(&(buf[i*2]),"%02x",md[i]); return(buf); } +#endif diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h new file mode 100644 index 0000000000..2b91f9eef2 --- /dev/null +++ b/src/lib/libcrypto/md32_common.h @@ -0,0 +1,594 @@ +/* crypto/md32_common.h */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + * This is a generic 32 bit "collector" for message digest algorithms. + * Whenever needed it collects input character stream into chunks of + * 32 bit values and invokes a block function that performs actual hash + * calculations. + * + * Porting guide. + * + * Obligatory macros: + * + * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN + * this macro defines byte order of input stream. + * HASH_CBLOCK + * size of a unit chunk HASH_BLOCK operates on. + * HASH_LONG + * has to be at lest 32 bit wide, if it's wider, then + * HASH_LONG_LOG2 *has to* be defined along + * HASH_CTX + * context structure that at least contains following + * members: + * typedef struct { + * ... + * HASH_LONG Nl,Nh; + * HASH_LONG data[HASH_LBLOCK]; + * int num; + * ... + * } HASH_CTX; + * HASH_UPDATE + * name of "Update" function, implemented here. + * HASH_TRANSFORM + * name of "Transform" function, implemented here. + * HASH_FINAL + * name of "Final" function, implemented here. + * HASH_BLOCK_HOST_ORDER + * name of "block" function treating *aligned* input message + * in host byte order, implemented externally. + * HASH_BLOCK_DATA_ORDER + * name of "block" function treating *unaligned* input message + * in original (data) byte order, implemented externally (it + * actually is optional if data and host are of the same + * "endianess"). + * + * Optional macros: + * + * B_ENDIAN or L_ENDIAN + * defines host byte-order. + * HASH_LONG_LOG2 + * defaults to 2 if not states otherwise. + * HASH_LBLOCK + * assumed to be HASH_CBLOCK/4 if not stated otherwise. + * HASH_BLOCK_DATA_ORDER_ALIGNED + * alternative "block" function capable of treating + * aligned input message in original (data) order, + * implemented externally. + * + * MD5 example: + * + * #define DATA_ORDER_IS_LITTLE_ENDIAN + * + * #define HASH_LONG MD5_LONG + * #define HASH_LONG_LOG2 MD5_LONG_LOG2 + * #define HASH_CTX MD5_CTX + * #define HASH_CBLOCK MD5_CBLOCK + * #define HASH_LBLOCK MD5_LBLOCK + * #define HASH_UPDATE MD5_Update + * #define HASH_TRANSFORM MD5_Transform + * #define HASH_FINAL MD5_Final + * #define HASH_BLOCK_HOST_ORDER md5_block_host_order + * #define HASH_BLOCK_DATA_ORDER md5_block_data_order + * + * + */ + +#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) +#error "DATA_ORDER must be defined!" +#endif + +#ifndef HASH_CBLOCK +#error "HASH_CBLOCK must be defined!" +#endif +#ifndef HASH_LONG +#error "HASH_LONG must be defined!" +#endif +#ifndef HASH_CTX +#error "HASH_CTX must be defined!" +#endif + +#ifndef HASH_UPDATE +#error "HASH_UPDATE must be defined!" +#endif +#ifndef HASH_TRANSFORM +#error "HASH_TRANSFORM must be defined!" +#endif +#ifndef HASH_FINAL +#error "HASH_FINAL must be defined!" +#endif + +#ifndef HASH_BLOCK_HOST_ORDER +#error "HASH_BLOCK_HOST_ORDER must be defined!" +#endif + +#if 0 +/* + * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED + * isn't defined. + */ +#ifndef HASH_BLOCK_DATA_ORDER +#error "HASH_BLOCK_DATA_ORDER must be defined!" +#endif +#endif + +#ifndef HASH_LBLOCK +#define HASH_LBLOCK (HASH_CBLOCK/4) +#endif + +#ifndef HASH_LONG_LOG2 +#define HASH_LONG_LOG2 2 +#endif + +/* + * Engage compiler specific rotate intrinsic function if available. + */ +#undef ROTATE +#ifndef PEDANTIC +# if defined(_MSC_VER) +# define ROTATE(a,n) _lrotl(a,n) +# elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) + /* + * Some GNU C inline assembler templates. Note that these are + * rotates by *constant* number of bits! But that's exactly + * what we need here... + * + * + */ +# if defined(__i386) +# define ROTATE(a,n) ({ register unsigned int ret; \ + asm volatile ( \ + "roll %1,%0" \ + : "=r"(ret) \ + : "I"(n), "0"(a) \ + : "cc"); \ + ret; \ + }) +# elif defined(__powerpc) +# define ROTATE(a,n) ({ register unsigned int ret; \ + asm volatile ( \ + "rlwinm %0,%1,%2,0,31" \ + : "=r"(ret) \ + : "r"(a), "I"(n)); \ + ret; \ + }) +# endif +# endif + +/* + * Engage compiler specific "fetch in reverse byte order" + * intrinsic function if available. + */ +# if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM) + /* some GNU C inline assembler templates by */ +# if defined(__i386) && !defined(I386_ONLY) +# define BE_FETCH32(a) ({ register unsigned int l=(a);\ + asm volatile ( \ + "bswapl %0" \ + : "=r"(l) : "0"(l)); \ + l; \ + }) +# elif defined(__powerpc) +# define LE_FETCH32(a) ({ register unsigned int l; \ + asm volatile ( \ + "lwbrx %0,0,%1" \ + : "=r"(l) \ + : "r"(a)); \ + l; \ + }) + +# elif defined(__sparc) && defined(ULTRASPARC) +# define LE_FETCH32(a) ({ register unsigned int l; \ + asm volatile ( \ + "lda [%1]#ASI_PRIMARY_LITTLE,%0"\ + : "=r"(l) \ + : "r"(a)); \ + l; \ + }) +# endif +# endif +#endif /* PEDANTIC */ + +#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */ +/* A nice byte order reversal from Wei Dai */ +#ifdef ROTATE +/* 5 instructions with rotate instruction, else 9 */ +#define REVERSE_FETCH32(a,l) ( \ + l=*(const HASH_LONG *)(a), \ + ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \ + ) +#else +/* 6 instructions with rotate instruction, else 8 */ +#define REVERSE_FETCH32(a,l) ( \ + l=*(const HASH_LONG *)(a), \ + l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \ + ROTATE(l,16) \ + ) +/* + * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|... + * It's rewritten as above for two reasons: + * - RISCs aren't good at long constants and have to explicitely + * compose 'em with several (well, usually 2) instructions in a + * register before performing the actual operation and (as you + * already realized:-) having same constant should inspire the + * compiler to permanently allocate the only register for it; + * - most modern CPUs have two ALUs, but usually only one has + * circuitry for shifts:-( this minor tweak inspires compiler + * to schedule shift instructions in a better way... + * + * + */ +#endif +#endif + +#ifndef ROTATE +#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) +#endif + +/* + * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED + * and HASH_BLOCK_HOST_ORDER ought to be the same if input data + * and host are of the same "endianess". It's possible to mask + * this with blank #define HASH_BLOCK_DATA_ORDER though... + * + * + */ +#if defined(B_ENDIAN) +# if defined(DATA_ORDER_IS_BIG_ENDIAN) +# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2 +# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER +# endif +# elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) +# ifndef HOST_FETCH32 +# ifdef LE_FETCH32 +# define HOST_FETCH32(p,l) LE_FETCH32(p) +# elif defined(REVERSE_FETCH32) +# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l) +# endif +# endif +# endif +#elif defined(L_ENDIAN) +# if defined(DATA_ORDER_IS_LITTLE_ENDIAN) +# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2 +# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER +# endif +# elif defined(DATA_ORDER_IS_BIG_ENDIAN) +# ifndef HOST_FETCH32 +# ifdef BE_FETCH32 +# define HOST_FETCH32(p,l) BE_FETCH32(p) +# elif defined(REVERSE_FETCH32) +# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l) +# endif +# endif +# endif +#endif + +#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) +#ifndef HASH_BLOCK_DATA_ORDER +#error "HASH_BLOCK_DATA_ORDER must be defined!" +#endif +#endif + +#if defined(DATA_ORDER_IS_BIG_ENDIAN) + +#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ + l|=(((unsigned long)(*((c)++)))<<16), \ + l|=(((unsigned long)(*((c)++)))<< 8), \ + l|=(((unsigned long)(*((c)++))) ), \ + l) +#define HOST_p_c2l(c,l,n) { \ + switch (n) { \ + case 0: l =((unsigned long)(*((c)++)))<<24; \ + case 1: l|=((unsigned long)(*((c)++)))<<16; \ + case 2: l|=((unsigned long)(*((c)++)))<< 8; \ + case 3: l|=((unsigned long)(*((c)++))); \ + } } +#define HOST_p_c2l_p(c,l,sc,len) { \ + switch (sc) { \ + case 0: l =((unsigned long)(*((c)++)))<<24; \ + if (--len == 0) break; \ + case 1: l|=((unsigned long)(*((c)++)))<<16; \ + if (--len == 0) break; \ + case 2: l|=((unsigned long)(*((c)++)))<< 8; \ + } } +/* NOTE the pointer is not incremented at the end of this */ +#define HOST_c2l_p(c,l,n) { \ + l=0; (c)+=n; \ + switch (n) { \ + case 3: l =((unsigned long)(*(--(c))))<< 8; \ + case 2: l|=((unsigned long)(*(--(c))))<<16; \ + case 1: l|=((unsigned long)(*(--(c))))<<24; \ + } } +#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16)&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ + *((c)++)=(unsigned char)(((l) )&0xff), \ + l) + +#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) + +#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ + l|=(((unsigned long)(*((c)++)))<< 8), \ + l|=(((unsigned long)(*((c)++)))<<16), \ + l|=(((unsigned long)(*((c)++)))<<24), \ + l) +#define HOST_p_c2l(c,l,n) { \ + switch (n) { \ + case 0: l =((unsigned long)(*((c)++))); \ + case 1: l|=((unsigned long)(*((c)++)))<< 8; \ + case 2: l|=((unsigned long)(*((c)++)))<<16; \ + case 3: l|=((unsigned long)(*((c)++)))<<24; \ + } } +#define HOST_p_c2l_p(c,l,sc,len) { \ + switch (sc) { \ + case 0: l =((unsigned long)(*((c)++))); \ + if (--len == 0) break; \ + case 1: l|=((unsigned long)(*((c)++)))<< 8; \ + if (--len == 0) break; \ + case 2: l|=((unsigned long)(*((c)++)))<<16; \ + } } +/* NOTE the pointer is not incremented at the end of this */ +#define HOST_c2l_p(c,l,n) { \ + l=0; (c)+=n; \ + switch (n) { \ + case 3: l =((unsigned long)(*(--(c))))<<16; \ + case 2: l|=((unsigned long)(*(--(c))))<< 8; \ + case 1: l|=((unsigned long)(*(--(c)))); \ + } } +#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ + *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ + *((c)++)=(unsigned char)(((l)>>16)&0xff), \ + *((c)++)=(unsigned char)(((l)>>24)&0xff), \ + l) + +#endif + +/* + * Time for some action:-) + */ + +void HASH_UPDATE (HASH_CTX *c, const unsigned char *data, unsigned long len) + { + register HASH_LONG * p; + register unsigned long l; + int sw,sc,ew,ec; + + if (len==0) return; + + l=(c->Nl+(len<<3))&0xffffffffL; + /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to + * Wei Dai for pointing it out. */ + if (l < c->Nl) /* overflow */ + c->Nh++; + c->Nh+=(len>>29); + c->Nl=l; + + if (c->num != 0) + { + p=c->data; + sw=c->num>>2; + sc=c->num&0x03; + + if ((c->num+len) >= HASH_CBLOCK) + { + l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l; + for (; swnum); + c->num=0; + /* drop through and do the rest */ + } + else + { + c->num+=len; + if ((sc+len) < 4) /* ugly, add char's to a word */ + { + l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l; + } + else + { + ew=(c->num>>2); + ec=(c->num&0x03); + l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l; + for (; sw < ew; sw++) + { + HOST_c2l(data,l); p[sw]=l; + } + if (ec) + { + HOST_c2l_p(data,l,ec); p[sw]=l; + } + } + return; + } + } + + sw=len/HASH_CBLOCK; + if (sw > 0) + { +#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED) + /* + * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined + * only if sizeof(HASH_LONG)==4. + */ + if ((((unsigned long)data)%4) == 0) + { + /* data is properly aligned so that we can cast it: */ + HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw); + sw*=HASH_CBLOCK; + data+=sw; + len-=sw; + } + else +#if !defined(HASH_BLOCK_DATA_ORDER) + while (sw--) + { + memcpy (p=c->data,data,HASH_CBLOCK); + HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1); + data+=HASH_CBLOCK; + len-=HASH_CBLOCK; + } +#endif +#endif +#if defined(HASH_BLOCK_DATA_ORDER) + { + HASH_BLOCK_DATA_ORDER(c,data,sw); + sw*=HASH_CBLOCK; + data+=sw; + len-=sw; + } +#endif + } + + if (len!=0) + { + p = c->data; + c->num = len; + ew=len>>2; /* words to copy */ + ec=len&0x03; + for (; ew; ew--,p++) + { + HOST_c2l(data,l); *p=l; + } + HOST_c2l_p(data,l,ec); + *p=l; + } + } + + +void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data) + { +#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED) + if ((((unsigned long)data)%4) == 0) + /* data is properly aligned so that we can cast it: */ + HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1); + else +#if !defined(HASH_BLOCK_DATA_ORDER) + { + memcpy (c->data,data,HASH_CBLOCK); + HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1); + } +#endif +#endif +#if defined(HASH_BLOCK_DATA_ORDER) + HASH_BLOCK_DATA_ORDER (c,data,1); +#endif + } + + +void HASH_FINAL (unsigned char *md, HASH_CTX *c) + { + register HASH_LONG *p; + register unsigned long l; + register int i,j; + static const unsigned char end[4]={0x80,0x00,0x00,0x00}; + const unsigned char *cp=end; + + /* c->num should definitly have room for at least one more byte. */ + p=c->data; + i=c->num>>2; + j=c->num&0x03; + +#if 0 + /* purify often complains about the following line as an + * Uninitialized Memory Read. While this can be true, the + * following p_c2l macro will reset l when that case is true. + * This is because j&0x03 contains the number of 'valid' bytes + * already in p[i]. If and only if j&0x03 == 0, the UMR will + * occur but this is also the only time p_c2l will do + * l= *(cp++) instead of l|= *(cp++) + * Many thanks to Alex Tang for pickup this + * 'potential bug' */ +#ifdef PURIFY + if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */ +#endif + l=p[i]; +#else + l = (j==0) ? 0 : p[i]; +#endif + HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */ + + if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */ + { + if (iNh; + p[HASH_LBLOCK-1]=c->Nl; +#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) + p[HASH_LBLOCK-2]=c->Nl; + p[HASH_LBLOCK-1]=c->Nh; +#endif + HASH_BLOCK_HOST_ORDER (c,p,1); + + l=c->A; HOST_l2c(l,md); + l=c->B; HOST_l2c(l,md); + l=c->C; HOST_l2c(l,md); + l=c->D; HOST_l2c(l,md); + + c->num=0; + /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack + * but I'm not worried :-) + memset((void *)c,0,sizeof(HASH_CTX)); + */ + } diff --git a/src/lib/libcrypto/md5/Makefile.ssl b/src/lib/libcrypto/md5/Makefile.ssl index 47e1ce05ca..29ae1b7458 100644 --- a/src/lib/libcrypto/md5/Makefile.ssl +++ b/src/lib/libcrypto/md5/Makefile.ssl @@ -8,15 +8,18 @@ CC= cc CPP= $(CC) -E INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r MD5_ASM_OBJ= CFLAGS= $(INCLUDES) $(CFLAG) +ASFLAGS=$(CFLAGS) GENERAL=Makefile TEST=md5test.c @@ -40,7 +43,7 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf @@ -59,26 +62,43 @@ asm/mx86-out.o: asm/mx86unix.cpp # bsdi asm/mx86bsdi.o: asm/mx86unix.cpp - $(CPP) -DBSDI asm/mx86unix.cpp | as -o asm/mx86bsdi.o + $(CPP) -DBSDI asm/mx86unix.cpp | sed 's/ :/:/' | as -o asm/mx86bsdi.o -asm/mx86unix.cpp: - (cd asm; perl md5-586.pl cpp >mx86unix.cpp) +asm/mx86unix.cpp: asm/md5-586.pl + (cd asm; $(PERL) md5-586.pl cpp >mx86unix.cpp) + +asm/md5-sparcv8plus.o: asm/md5-sparcv9.S + $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -c \ + -o asm/md5-sparcv8plus.o asm/md5-sparcv9.S + +# Old GNU assembler doesn't understand V9 instructions, so we +# hire /usr/ccs/bin/as to do the job. Note that option is called +# *-gcc27, but even gcc 2>=8 users may experience similar problem +# if they didn't bother to upgrade GNU assembler. Such users should +# not choose this option, but be adviced to *remove* GNU assembler +# or upgrade it. +sm/md5-sparcv8plus-gcc27.o: asm/md5-sparcv9.S + $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -E asm/md5-sparcv9.S | \ + /usr/ccs/bin/as -xarch=v8plus - -o asm/md5-sparcv8plus-gcc27.o + +asm/md5-sparcv9.o: asm/md5-sparcv9.S + $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -c \ + -o asm/md5-sparcv9.o asm/md5-sparcv9.S files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -90,15 +110,17 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f asm/mx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +md5_dgst.o: ../../include/openssl/md5.h ../../include/openssl/opensslconf.h +md5_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md5_locl.h +md5_one.o: ../../include/openssl/md5.h diff --git a/src/lib/libcrypto/md5/Makefile.uni b/src/lib/libcrypto/md5/Makefile.uni index 54685712db..d21c72f3ea 100644 --- a/src/lib/libcrypto/md5/Makefile.uni +++ b/src/lib/libcrypto/md5/Makefile.uni @@ -19,6 +19,7 @@ MAKE= make MAKEDEPEND= makedepend MAKEFILE= Makefile.uni AR= ar r +RANLIB= ranlib MD5_ASM_OBJ= @@ -43,7 +44,7 @@ all: $(LIB) $(TEST) $(APPS) $(LIB): $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/ranlib.sh $(LIB) + $(RANLIB) $(LIB) # elf asm/mx86-elf.o: asm/mx86unix.cpp diff --git a/src/lib/libcrypto/md5/asm/m5-win32.asm b/src/lib/libcrypto/md5/asm/m5-win32.asm index c2081da746..51f5f17ca3 100644 --- a/src/lib/libcrypto/md5/asm/m5-win32.asm +++ b/src/lib/libcrypto/md5/asm/m5-win32.asm @@ -8,15 +8,16 @@ .386 .model FLAT _TEXT SEGMENT -PUBLIC _md5_block_x86 +PUBLIC _md5_block_asm_host_order -_md5_block_x86 PROC NEAR +_md5_block_asm_host_order PROC NEAR push esi push edi mov edi, DWORD PTR 12[esp] mov esi, DWORD PTR 16[esp] mov ecx, DWORD PTR 20[esp] push ebp + shl ecx, 6 push ebx add ecx, esi sub ecx, 64 @@ -34,161 +35,161 @@ L000start: xor edi, edx and edi, ebx lea eax, DWORD PTR 3614090360[ebp*1+eax] - mov ebp, DWORD PTR 4[esi] xor edi, edx add eax, edi mov edi, ebx rol eax, 7 + mov ebp, DWORD PTR 4[esi] add eax, ebx ; R0 1 xor edi, ecx and edi, eax lea edx, DWORD PTR 3905402710[ebp*1+edx] - mov ebp, DWORD PTR 8[esi] xor edi, ecx add edx, edi mov edi, eax rol edx, 12 + mov ebp, DWORD PTR 8[esi] add edx, eax ; R0 2 xor edi, ebx and edi, edx lea ecx, DWORD PTR 606105819[ebp*1+ecx] - mov ebp, DWORD PTR 12[esi] xor edi, ebx add ecx, edi mov edi, edx rol ecx, 17 + mov ebp, DWORD PTR 12[esi] add ecx, edx ; R0 3 xor edi, eax and edi, ecx lea ebx, DWORD PTR 3250441966[ebp*1+ebx] - mov ebp, DWORD PTR 16[esi] xor edi, eax add ebx, edi mov edi, ecx rol ebx, 22 + mov ebp, DWORD PTR 16[esi] add ebx, ecx ; R0 4 xor edi, edx and edi, ebx lea eax, DWORD PTR 4118548399[ebp*1+eax] - mov ebp, DWORD PTR 20[esi] xor edi, edx add eax, edi mov edi, ebx rol eax, 7 + mov ebp, DWORD PTR 20[esi] add eax, ebx ; R0 5 xor edi, ecx and edi, eax lea edx, DWORD PTR 1200080426[ebp*1+edx] - mov ebp, DWORD PTR 24[esi] xor edi, ecx add edx, edi mov edi, eax rol edx, 12 + mov ebp, DWORD PTR 24[esi] add edx, eax ; R0 6 xor edi, ebx and edi, edx lea ecx, DWORD PTR 2821735955[ebp*1+ecx] - mov ebp, DWORD PTR 28[esi] xor edi, ebx add ecx, edi mov edi, edx rol ecx, 17 + mov ebp, DWORD PTR 28[esi] add ecx, edx ; R0 7 xor edi, eax and edi, ecx lea ebx, DWORD PTR 4249261313[ebp*1+ebx] - mov ebp, DWORD PTR 32[esi] xor edi, eax add ebx, edi mov edi, ecx rol ebx, 22 + mov ebp, DWORD PTR 32[esi] add ebx, ecx ; R0 8 xor edi, edx and edi, ebx lea eax, DWORD PTR 1770035416[ebp*1+eax] - mov ebp, DWORD PTR 36[esi] xor edi, edx add eax, edi mov edi, ebx rol eax, 7 + mov ebp, DWORD PTR 36[esi] add eax, ebx ; R0 9 xor edi, ecx and edi, eax lea edx, DWORD PTR 2336552879[ebp*1+edx] - mov ebp, DWORD PTR 40[esi] xor edi, ecx add edx, edi mov edi, eax rol edx, 12 + mov ebp, DWORD PTR 40[esi] add edx, eax ; R0 10 xor edi, ebx and edi, edx lea ecx, DWORD PTR 4294925233[ebp*1+ecx] - mov ebp, DWORD PTR 44[esi] xor edi, ebx add ecx, edi mov edi, edx rol ecx, 17 + mov ebp, DWORD PTR 44[esi] add ecx, edx ; R0 11 xor edi, eax and edi, ecx lea ebx, DWORD PTR 2304563134[ebp*1+ebx] - mov ebp, DWORD PTR 48[esi] xor edi, eax add ebx, edi mov edi, ecx rol ebx, 22 + mov ebp, DWORD PTR 48[esi] add ebx, ecx ; R0 12 xor edi, edx and edi, ebx lea eax, DWORD PTR 1804603682[ebp*1+eax] - mov ebp, DWORD PTR 52[esi] xor edi, edx add eax, edi mov edi, ebx rol eax, 7 + mov ebp, DWORD PTR 52[esi] add eax, ebx ; R0 13 xor edi, ecx and edi, eax lea edx, DWORD PTR 4254626195[ebp*1+edx] - mov ebp, DWORD PTR 56[esi] xor edi, ecx add edx, edi mov edi, eax rol edx, 12 + mov ebp, DWORD PTR 56[esi] add edx, eax ; R0 14 xor edi, ebx and edi, edx lea ecx, DWORD PTR 2792965006[ebp*1+ecx] - mov ebp, DWORD PTR 60[esi] xor edi, ebx add ecx, edi mov edi, edx rol ecx, 17 + mov ebp, DWORD PTR 60[esi] add ecx, edx ; R0 15 xor edi, eax and edi, ecx lea ebx, DWORD PTR 1236535329[ebp*1+ebx] - mov ebp, DWORD PTR 4[esi] xor edi, eax add ebx, edi mov edi, ecx rol ebx, 22 + mov ebp, DWORD PTR 4[esi] add ebx, ecx ; ; R1 section @@ -359,8 +360,8 @@ L000start: xor edi, ebx lea eax, DWORD PTR 4294588738[ebp*1+eax] add eax, edi - mov ebp, DWORD PTR 32[esi] rol eax, 4 + mov ebp, DWORD PTR 32[esi] mov edi, ebx ; R2 33 lea edx, DWORD PTR 2272392833[ebp*1+edx] @@ -377,8 +378,8 @@ L000start: xor edi, edx lea ecx, DWORD PTR 1839030562[ebp*1+ecx] add ecx, edi - mov ebp, DWORD PTR 56[esi] rol ecx, 16 + mov ebp, DWORD PTR 56[esi] mov edi, edx ; R2 35 lea ebx, DWORD PTR 4259657740[ebp*1+ebx] @@ -395,8 +396,8 @@ L000start: xor edi, ebx lea eax, DWORD PTR 2763975236[ebp*1+eax] add eax, edi - mov ebp, DWORD PTR 16[esi] rol eax, 4 + mov ebp, DWORD PTR 16[esi] mov edi, ebx ; R2 37 lea edx, DWORD PTR 1272893353[ebp*1+edx] @@ -413,8 +414,8 @@ L000start: xor edi, edx lea ecx, DWORD PTR 4139469664[ebp*1+ecx] add ecx, edi - mov ebp, DWORD PTR 40[esi] rol ecx, 16 + mov ebp, DWORD PTR 40[esi] mov edi, edx ; R2 39 lea ebx, DWORD PTR 3200236656[ebp*1+ebx] @@ -431,8 +432,8 @@ L000start: xor edi, ebx lea eax, DWORD PTR 681279174[ebp*1+eax] add eax, edi - mov ebp, DWORD PTR [esi] rol eax, 4 + mov ebp, DWORD PTR [esi] mov edi, ebx ; R2 41 lea edx, DWORD PTR 3936430074[ebp*1+edx] @@ -449,8 +450,8 @@ L000start: xor edi, edx lea ecx, DWORD PTR 3572445317[ebp*1+ecx] add ecx, edi - mov ebp, DWORD PTR 24[esi] rol ecx, 16 + mov ebp, DWORD PTR 24[esi] mov edi, edx ; R2 43 lea ebx, DWORD PTR 76029189[ebp*1+ebx] @@ -467,8 +468,8 @@ L000start: xor edi, ebx lea eax, DWORD PTR 3654602809[ebp*1+eax] add eax, edi - mov ebp, DWORD PTR 48[esi] rol eax, 4 + mov ebp, DWORD PTR 48[esi] mov edi, ebx ; R2 45 lea edx, DWORD PTR 3873151461[ebp*1+edx] @@ -485,8 +486,8 @@ L000start: xor edi, edx lea ecx, DWORD PTR 530742520[ebp*1+ecx] add ecx, edi - mov ebp, DWORD PTR 8[esi] rol ecx, 16 + mov ebp, DWORD PTR 8[esi] mov edi, edx ; R2 47 lea ebx, DWORD PTR 3299628645[ebp*1+ebx] @@ -681,6 +682,6 @@ L000start: pop edi pop esi ret -_md5_block_x86 ENDP +_md5_block_asm_host_order ENDP _TEXT ENDS END diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl index 2c7fb7dd98..5fc6a205ce 100644 --- a/src/lib/libcrypto/md5/asm/md5-586.pl +++ b/src/lib/libcrypto/md5/asm/md5-586.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # Normal is the # md5_block_x86(MD5_CTX *c, ULONG *X); @@ -29,7 +29,7 @@ $X="esi"; 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3 ); -&md5_block("md5_block_x86"); +&md5_block("md5_block_asm_host_order"); &asm_finish(); sub Np @@ -44,7 +44,7 @@ sub R0 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; &mov($tmp1,$C) if $pos < 0; - &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one + &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one # body proper @@ -54,7 +54,6 @@ sub R0 &and($tmp1,$b); # F function - part 3 &lea($a,&DWP($t,$a,$tmp2,1)); - &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); &xor($tmp1,$d); # F function - part 4 &add($a,$tmp1); @@ -62,8 +61,10 @@ sub R0 &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1 &rotl($a,$s); - &add($a,$b); + &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); + + &add($a,$b); } sub R1 @@ -100,16 +101,16 @@ if (($n & 1) == 0) # make sure to do 'D' first, not 'B', else we clash with # the last add from the previous round. - &xor($tmp1,$d); # H function - part 2 + &xor($tmp1,$d); # H function - part 2 &xor($tmp1,$b); # H function - part 3 - &lea($a,&DWP($t,$a,$tmp2,1)); + &lea($a,&DWP($t,$a,$tmp2,1)); &add($a,$tmp1); - &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)); &rotl($a,$s); + &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)); &mov($tmp1,&Np($c)); } else @@ -118,17 +119,17 @@ else # make sure to do 'D' first, not 'B', else we clash with # the last add from the previous round. - &lea($a,&DWP($t,$a,$tmp2,1)); + &lea($a,&DWP($t,$a,$tmp2,1)); &add($b,$c); # MOVED FORWARD - &xor($tmp1,$d); # H function - part 2 + &xor($tmp1,$d); # H function - part 2 &xor($tmp1,$b); # H function - part 3 - &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); + &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); &add($a,$tmp1); - &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1 - &mov($tmp1,-1) if $pos == 1; # I function - part 1 + &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1 + &mov($tmp1,-1) if $pos == 1; # I function - part 1 &rotl($a,$s); @@ -146,21 +147,21 @@ sub R3 &xor($tmp1,$d) if $pos < 0; # I function - part 2 &or($tmp1,$b); # I function - part 3 - &lea($a,&DWP($t,$a,$tmp2,1)); + &lea($a,&DWP($t,$a,$tmp2,1)); &xor($tmp1,$c); # I function - part 4 - &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value - &mov($tmp2,&wparam(0)) if $pos == 2; + &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value + &mov($tmp2,&wparam(0)) if $pos == 2; &add($a,$tmp1); - &mov($tmp1,-1) if $pos < 1; # H function - part 1 - &add($K,64) if $pos >=1 && !$normal; + &mov($tmp1,-1) if $pos < 1; # H function - part 1 + &add($K,64) if $pos >=1 && !$normal; &rotl($a,$s); &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0; - &add($a,$b); + &add($a,$b); } @@ -182,6 +183,7 @@ sub md5_block &mov($X, &wparam(1)); # esi &mov($C, &wparam(2)); &push("ebp"); + &shl($C, 6); &push("ebx"); &add($C, $X); # offset we end at &sub($C, 64); diff --git a/src/lib/libcrypto/md5/asm/md5-sparcv9.S b/src/lib/libcrypto/md5/asm/md5-sparcv9.S new file mode 100644 index 0000000000..ca4257f134 --- /dev/null +++ b/src/lib/libcrypto/md5/asm/md5-sparcv9.S @@ -0,0 +1,1029 @@ +.ident "md5-sparcv9.S, Version 1.0" +.ident "SPARC V9 ISA artwork by Andy Polyakov " +.file "md5-sparcv9.S" + +/* + * ==================================================================== + * Copyright (c) 1999 Andy Polyakov . + * + * Rights for redistribution and usage in source and binary forms are + * granted as long as above copyright notices are retained. Warranty + * of any kind is (of course:-) disclaimed. + * ==================================================================== + */ + +/* + * This is my modest contribution to OpenSSL project (see + * http://www.openssl.org/ for more information about it) and is an + * assembler implementation of MD5 block hash function. I've hand-coded + * this for the sole reason to reach UltraSPARC-specific "load in + * little-endian byte order" instruction. This gives up to 15% + * performance improvement for cases when input message is aligned at + * 32 bits boundary. The module was tested under both 32 *and* 64 bit + * kernels. For updates see http://fy.chalmers.se/~appro/hpe/. + * + * To compile with SC4.x/SC5.x: + * + * cc -xarch=v[9|8plus] -DULTRASPARC -DMD5_BLOCK_DATA_ORDER \ + * -c md5-sparcv9.S + * + * and with gcc: + * + * gcc -mcpu=ultrasparc -DULTRASPARC -DMD5_BLOCK_DATA_ORDER \ + * -c md5-sparcv9.S + * + * or if above fails (it does if you have gas): + * + * gcc -E -DULTRASPARC -DMD5_BLOCK_DATA_ORDER md5_block.sparc.S | \ + * as -xarch=v8plus /dev/fd/0 -o md5-sparcv9.o + */ + +#define A %o0 +#define B %o1 +#define C %o2 +#define D %o3 +#define T1 %o4 +#define T2 %o5 + +#define R0 %l0 +#define R1 %l1 +#define R2 %l2 +#define R3 %l3 +#define R4 %l4 +#define R5 %l5 +#define R6 %l6 +#define R7 %l7 +#define R8 %i3 +#define R9 %i4 +#define R10 %i5 +#define R11 %g1 +#define R12 %g2 +#define R13 %g3 +#define RX %g4 + +#define Aptr %i0+0 +#define Bptr %i0+4 +#define Cptr %i0+8 +#define Dptr %i0+12 + +#define Aval R5 /* those not used at the end of the last round */ +#define Bval R6 +#define Cval R7 +#define Dval R8 + +#if defined(MD5_BLOCK_DATA_ORDER) +# if defined(ULTRASPARC) +# define LOAD lda +# define X(i) [%i1+i*4]%asi +# define md5_block md5_block_asm_data_order_aligned +# define ASI_PRIMARY_LITTLE 0x88 +# else +# error "MD5_BLOCK_DATA_ORDER is supported only on UltraSPARC!" +# endif +#else +# define LOAD ld +# define X(i) [%i1+i*4] +# define md5_block md5_block_asm_host_order +#endif + +.section ".text",#alloc,#execinstr + +#if defined(__SUNPRO_C) && defined(__sparcv9) + /* They've said -xarch=v9 at command line */ + .register %g2,#scratch + .register %g3,#scratch +# define FRAME -192 +#elif defined(__GNUC__) && defined(__arch64__) + /* They've said -m64 at command line */ + .register %g2,#scratch + .register %g3,#scratch +# define FRAME -192 +#else +# define FRAME -96 +#endif + +.align 32 + +.global md5_block +md5_block: + save %sp,FRAME,%sp + + ld [Dptr],D + ld [Cptr],C + ld [Bptr],B + ld [Aptr],A +#ifdef ASI_PRIMARY_LITTLE + rd %asi,%o7 ! How dare I? Well, I just do:-) + wr %g0,ASI_PRIMARY_LITTLE,%asi +#endif + LOAD X(0),R0 + +.Lmd5_block_loop: + +!!!!!!!!Round 0 + + xor C,D,T1 + sethi %hi(0xd76aa478),T2 + and T1,B,T1 + or T2,%lo(0xd76aa478),T2 != + xor T1,D,T1 + add T1,R0,T1 + LOAD X(1),R1 + add T1,T2,T1 != + add A,T1,A + sll A,7,T2 + srl A,32-7,A + or A,T2,A != + xor B,C,T1 + add A,B,A + + sethi %hi(0xe8c7b756),T2 + and T1,A,T1 != + or T2,%lo(0xe8c7b756),T2 + xor T1,C,T1 + LOAD X(2),R2 + add T1,R1,T1 != + add T1,T2,T1 + add D,T1,D + sll D,12,T2 + srl D,32-12,D != + or D,T2,D + xor A,B,T1 + add D,A,D + + sethi %hi(0x242070db),T2 != + and T1,D,T1 + or T2,%lo(0x242070db),T2 + xor T1,B,T1 + add T1,R2,T1 != + LOAD X(3),R3 + add T1,T2,T1 + add C,T1,C + sll C,17,T2 != + srl C,32-17,C + or C,T2,C + xor D,A,T1 + add C,D,C != + + sethi %hi(0xc1bdceee),T2 + and T1,C,T1 + or T2,%lo(0xc1bdceee),T2 + xor T1,A,T1 != + add T1,R3,T1 + LOAD X(4),R4 + add T1,T2,T1 + add B,T1,B != + sll B,22,T2 + srl B,32-22,B + or B,T2,B + xor C,D,T1 != + add B,C,B + + sethi %hi(0xf57c0faf),T2 + and T1,B,T1 + or T2,%lo(0xf57c0faf),T2 != + xor T1,D,T1 + add T1,R4,T1 + LOAD X(5),R5 + add T1,T2,T1 != + add A,T1,A + sll A,7,T2 + srl A,32-7,A + or A,T2,A != + xor B,C,T1 + add A,B,A + + sethi %hi(0x4787c62a),T2 + and T1,A,T1 != + or T2,%lo(0x4787c62a),T2 + xor T1,C,T1 + LOAD X(6),R6 + add T1,R5,T1 != + add T1,T2,T1 + add D,T1,D + sll D,12,T2 + srl D,32-12,D != + or D,T2,D + xor A,B,T1 + add D,A,D + + sethi %hi(0xa8304613),T2 != + and T1,D,T1 + or T2,%lo(0xa8304613),T2 + xor T1,B,T1 + add T1,R6,T1 != + LOAD X(7),R7 + add T1,T2,T1 + add C,T1,C + sll C,17,T2 != + srl C,32-17,C + or C,T2,C + xor D,A,T1 + add C,D,C != + + sethi %hi(0xfd469501),T2 + and T1,C,T1 + or T2,%lo(0xfd469501),T2 + xor T1,A,T1 != + add T1,R7,T1 + LOAD X(8),R8 + add T1,T2,T1 + add B,T1,B != + sll B,22,T2 + srl B,32-22,B + or B,T2,B + xor C,D,T1 != + add B,C,B + + sethi %hi(0x698098d8),T2 + and T1,B,T1 + or T2,%lo(0x698098d8),T2 != + xor T1,D,T1 + add T1,R8,T1 + LOAD X(9),R9 + add T1,T2,T1 != + add A,T1,A + sll A,7,T2 + srl A,32-7,A + or A,T2,A != + xor B,C,T1 + add A,B,A + + sethi %hi(0x8b44f7af),T2 + and T1,A,T1 != + or T2,%lo(0x8b44f7af),T2 + xor T1,C,T1 + LOAD X(10),R10 + add T1,R9,T1 != + add T1,T2,T1 + add D,T1,D + sll D,12,T2 + srl D,32-12,D != + or D,T2,D + xor A,B,T1 + add D,A,D + + sethi %hi(0xffff5bb1),T2 != + and T1,D,T1 + or T2,%lo(0xffff5bb1),T2 + xor T1,B,T1 + add T1,R10,T1 != + LOAD X(11),R11 + add T1,T2,T1 + add C,T1,C + sll C,17,T2 != + srl C,32-17,C + or C,T2,C + xor D,A,T1 + add C,D,C != + + sethi %hi(0x895cd7be),T2 + and T1,C,T1 + or T2,%lo(0x895cd7be),T2 + xor T1,A,T1 != + add T1,R11,T1 + LOAD X(12),R12 + add T1,T2,T1 + add B,T1,B != + sll B,22,T2 + srl B,32-22,B + or B,T2,B + xor C,D,T1 != + add B,C,B + + sethi %hi(0x6b901122),T2 + and T1,B,T1 + or T2,%lo(0x6b901122),T2 != + xor T1,D,T1 + add T1,R12,T1 + LOAD X(13),R13 + add T1,T2,T1 != + add A,T1,A + sll A,7,T2 + srl A,32-7,A + or A,T2,A != + xor B,C,T1 + add A,B,A + + sethi %hi(0xfd987193),T2 + and T1,A,T1 != + or T2,%lo(0xfd987193),T2 + xor T1,C,T1 + LOAD X(14),RX + add T1,R13,T1 != + add T1,T2,T1 + add D,T1,D + sll D,12,T2 + srl D,32-12,D != + or D,T2,D + xor A,B,T1 + add D,A,D + + sethi %hi(0xa679438e),T2 != + and T1,D,T1 + or T2,%lo(0xa679438e),T2 + xor T1,B,T1 + add T1,RX,T1 != + LOAD X(15),RX + add T1,T2,T1 + add C,T1,C + sll C,17,T2 != + srl C,32-17,C + or C,T2,C + xor D,A,T1 + add C,D,C != + + sethi %hi(0x49b40821),T2 + and T1,C,T1 + or T2,%lo(0x49b40821),T2 + xor T1,A,T1 != + add T1,RX,T1 + !pre-LOADed X(1),R1 + add T1,T2,T1 + add B,T1,B + sll B,22,T2 != + srl B,32-22,B + or B,T2,B + add B,C,B + +!!!!!!!!Round 1 + + xor B,C,T1 != + sethi %hi(0xf61e2562),T2 + and T1,D,T1 + or T2,%lo(0xf61e2562),T2 + xor T1,C,T1 != + add T1,R1,T1 + !pre-LOADed X(6),R6 + add T1,T2,T1 + add A,T1,A + sll A,5,T2 != + srl A,32-5,A + or A,T2,A + add A,B,A + + xor A,B,T1 != + sethi %hi(0xc040b340),T2 + and T1,C,T1 + or T2,%lo(0xc040b340),T2 + xor T1,B,T1 != + add T1,R6,T1 + !pre-LOADed X(11),R11 + add T1,T2,T1 + add D,T1,D + sll D,9,T2 != + srl D,32-9,D + or D,T2,D + add D,A,D + + xor D,A,T1 != + sethi %hi(0x265e5a51),T2 + and T1,B,T1 + or T2,%lo(0x265e5a51),T2 + xor T1,A,T1 != + add T1,R11,T1 + !pre-LOADed X(0),R0 + add T1,T2,T1 + add C,T1,C + sll C,14,T2 != + srl C,32-14,C + or C,T2,C + add C,D,C + + xor C,D,T1 != + sethi %hi(0xe9b6c7aa),T2 + and T1,A,T1 + or T2,%lo(0xe9b6c7aa),T2 + xor T1,D,T1 != + add T1,R0,T1 + !pre-LOADed X(5),R5 + add T1,T2,T1 + add B,T1,B + sll B,20,T2 != + srl B,32-20,B + or B,T2,B + add B,C,B + + xor B,C,T1 != + sethi %hi(0xd62f105d),T2 + and T1,D,T1 + or T2,%lo(0xd62f105d),T2 + xor T1,C,T1 != + add T1,R5,T1 + !pre-LOADed X(10),R10 + add T1,T2,T1 + add A,T1,A + sll A,5,T2 != + srl A,32-5,A + or A,T2,A + add A,B,A + + xor A,B,T1 != + sethi %hi(0x02441453),T2 + and T1,C,T1 + or T2,%lo(0x02441453),T2 + xor T1,B,T1 != + add T1,R10,T1 + LOAD X(15),RX + add T1,T2,T1 + add D,T1,D != + sll D,9,T2 + srl D,32-9,D + or D,T2,D + add D,A,D != + + xor D,A,T1 + sethi %hi(0xd8a1e681),T2 + and T1,B,T1 + or T2,%lo(0xd8a1e681),T2 != + xor T1,A,T1 + add T1,RX,T1 + !pre-LOADed X(4),R4 + add T1,T2,T1 + add C,T1,C != + sll C,14,T2 + srl C,32-14,C + or C,T2,C + add C,D,C != + + xor C,D,T1 + sethi %hi(0xe7d3fbc8),T2 + and T1,A,T1 + or T2,%lo(0xe7d3fbc8),T2 != + xor T1,D,T1 + add T1,R4,T1 + !pre-LOADed X(9),R9 + add T1,T2,T1 + add B,T1,B != + sll B,20,T2 + srl B,32-20,B + or B,T2,B + add B,C,B != + + xor B,C,T1 + sethi %hi(0x21e1cde6),T2 + and T1,D,T1 + or T2,%lo(0x21e1cde6),T2 != + xor T1,C,T1 + add T1,R9,T1 + LOAD X(14),RX + add T1,T2,T1 != + add A,T1,A + sll A,5,T2 + srl A,32-5,A + or A,T2,A != + add A,B,A + + xor A,B,T1 + sethi %hi(0xc33707d6),T2 + and T1,C,T1 != + or T2,%lo(0xc33707d6),T2 + xor T1,B,T1 + add T1,RX,T1 + !pre-LOADed X(3),R3 + add T1,T2,T1 != + add D,T1,D + sll D,9,T2 + srl D,32-9,D + or D,T2,D != + add D,A,D + + xor D,A,T1 + sethi %hi(0xf4d50d87),T2 + and T1,B,T1 != + or T2,%lo(0xf4d50d87),T2 + xor T1,A,T1 + add T1,R3,T1 + !pre-LOADed X(8),R8 + add T1,T2,T1 != + add C,T1,C + sll C,14,T2 + srl C,32-14,C + or C,T2,C != + add C,D,C + + xor C,D,T1 + sethi %hi(0x455a14ed),T2 + and T1,A,T1 != + or T2,%lo(0x455a14ed),T2 + xor T1,D,T1 + add T1,R8,T1 + !pre-LOADed X(13),R13 + add T1,T2,T1 != + add B,T1,B + sll B,20,T2 + srl B,32-20,B + or B,T2,B != + add B,C,B + + xor B,C,T1 + sethi %hi(0xa9e3e905),T2 + and T1,D,T1 != + or T2,%lo(0xa9e3e905),T2 + xor T1,C,T1 + add T1,R13,T1 + !pre-LOADed X(2),R2 + add T1,T2,T1 != + add A,T1,A + sll A,5,T2 + srl A,32-5,A + or A,T2,A != + add A,B,A + + xor A,B,T1 + sethi %hi(0xfcefa3f8),T2 + and T1,C,T1 != + or T2,%lo(0xfcefa3f8),T2 + xor T1,B,T1 + add T1,R2,T1 + !pre-LOADed X(7),R7 + add T1,T2,T1 != + add D,T1,D + sll D,9,T2 + srl D,32-9,D + or D,T2,D != + add D,A,D + + xor D,A,T1 + sethi %hi(0x676f02d9),T2 + and T1,B,T1 != + or T2,%lo(0x676f02d9),T2 + xor T1,A,T1 + add T1,R7,T1 + !pre-LOADed X(12),R12 + add T1,T2,T1 != + add C,T1,C + sll C,14,T2 + srl C,32-14,C + or C,T2,C != + add C,D,C + + xor C,D,T1 + sethi %hi(0x8d2a4c8a),T2 + and T1,A,T1 != + or T2,%lo(0x8d2a4c8a),T2 + xor T1,D,T1 + add T1,R12,T1 + !pre-LOADed X(5),R5 + add T1,T2,T1 != + add B,T1,B + sll B,20,T2 + srl B,32-20,B + or B,T2,B != + add B,C,B + +!!!!!!!!Round 2 + + xor B,C,T1 + sethi %hi(0xfffa3942),T2 + xor T1,D,T1 != + or T2,%lo(0xfffa3942),T2 + add T1,R5,T1 + !pre-LOADed X(8),R8 + add T1,T2,T1 + add A,T1,A != + sll A,4,T2 + srl A,32-4,A + or A,T2,A + add A,B,A != + + xor A,B,T1 + sethi %hi(0x8771f681),T2 + xor T1,C,T1 + or T2,%lo(0x8771f681),T2 != + add T1,R8,T1 + !pre-LOADed X(11),R11 + add T1,T2,T1 + add D,T1,D + sll D,11,T2 != + srl D,32-11,D + or D,T2,D + add D,A,D + + xor D,A,T1 != + sethi %hi(0x6d9d6122),T2 + xor T1,B,T1 + or T2,%lo(0x6d9d6122),T2 + add T1,R11,T1 != + LOAD X(14),RX + add T1,T2,T1 + add C,T1,C + sll C,16,T2 != + srl C,32-16,C + or C,T2,C + add C,D,C + + xor C,D,T1 != + sethi %hi(0xfde5380c),T2 + xor T1,A,T1 + or T2,%lo(0xfde5380c),T2 + add T1,RX,T1 != + !pre-LOADed X(1),R1 + add T1,T2,T1 + add B,T1,B + sll B,23,T2 + srl B,32-23,B != + or B,T2,B + add B,C,B + + xor B,C,T1 + sethi %hi(0xa4beea44),T2 != + xor T1,D,T1 + or T2,%lo(0xa4beea44),T2 + add T1,R1,T1 + !pre-LOADed X(4),R4 + add T1,T2,T1 != + add A,T1,A + sll A,4,T2 + srl A,32-4,A + or A,T2,A != + add A,B,A + + xor A,B,T1 + sethi %hi(0x4bdecfa9),T2 + xor T1,C,T1 != + or T2,%lo(0x4bdecfa9),T2 + add T1,R4,T1 + !pre-LOADed X(7),R7 + add T1,T2,T1 + add D,T1,D != + sll D,11,T2 + srl D,32-11,D + or D,T2,D + add D,A,D != + + xor D,A,T1 + sethi %hi(0xf6bb4b60),T2 + xor T1,B,T1 + or T2,%lo(0xf6bb4b60),T2 != + add T1,R7,T1 + !pre-LOADed X(10),R10 + add T1,T2,T1 + add C,T1,C + sll C,16,T2 != + srl C,32-16,C + or C,T2,C + add C,D,C + + xor C,D,T1 != + sethi %hi(0xbebfbc70),T2 + xor T1,A,T1 + or T2,%lo(0xbebfbc70),T2 + add T1,R10,T1 != + !pre-LOADed X(13),R13 + add T1,T2,T1 + add B,T1,B + sll B,23,T2 + srl B,32-23,B != + or B,T2,B + add B,C,B + + xor B,C,T1 + sethi %hi(0x289b7ec6),T2 != + xor T1,D,T1 + or T2,%lo(0x289b7ec6),T2 + add T1,R13,T1 + !pre-LOADed X(0),R0 + add T1,T2,T1 != + add A,T1,A + sll A,4,T2 + srl A,32-4,A + or A,T2,A != + add A,B,A + + xor A,B,T1 + sethi %hi(0xeaa127fa),T2 + xor T1,C,T1 != + or T2,%lo(0xeaa127fa),T2 + add T1,R0,T1 + !pre-LOADed X(3),R3 + add T1,T2,T1 + add D,T1,D != + sll D,11,T2 + srl D,32-11,D + or D,T2,D + add D,A,D != + + xor D,A,T1 + sethi %hi(0xd4ef3085),T2 + xor T1,B,T1 + or T2,%lo(0xd4ef3085),T2 != + add T1,R3,T1 + !pre-LOADed X(6),R6 + add T1,T2,T1 + add C,T1,C + sll C,16,T2 != + srl C,32-16,C + or C,T2,C + add C,D,C + + xor C,D,T1 != + sethi %hi(0x04881d05),T2 + xor T1,A,T1 + or T2,%lo(0x04881d05),T2 + add T1,R6,T1 != + !pre-LOADed X(9),R9 + add T1,T2,T1 + add B,T1,B + sll B,23,T2 + srl B,32-23,B != + or B,T2,B + add B,C,B + + xor B,C,T1 + sethi %hi(0xd9d4d039),T2 != + xor T1,D,T1 + or T2,%lo(0xd9d4d039),T2 + add T1,R9,T1 + !pre-LOADed X(12),R12 + add T1,T2,T1 != + add A,T1,A + sll A,4,T2 + srl A,32-4,A + or A,T2,A != + add A,B,A + + xor A,B,T1 + sethi %hi(0xe6db99e5),T2 + xor T1,C,T1 != + or T2,%lo(0xe6db99e5),T2 + add T1,R12,T1 + LOAD X(15),RX + add T1,T2,T1 != + add D,T1,D + sll D,11,T2 + srl D,32-11,D + or D,T2,D != + add D,A,D + + xor D,A,T1 + sethi %hi(0x1fa27cf8),T2 + xor T1,B,T1 != + or T2,%lo(0x1fa27cf8),T2 + add T1,RX,T1 + !pre-LOADed X(2),R2 + add T1,T2,T1 + add C,T1,C != + sll C,16,T2 + srl C,32-16,C + or C,T2,C + add C,D,C != + + xor C,D,T1 + sethi %hi(0xc4ac5665),T2 + xor T1,A,T1 + or T2,%lo(0xc4ac5665),T2 != + add T1,R2,T1 + !pre-LOADed X(0),R0 + add T1,T2,T1 + add B,T1,B + sll B,23,T2 != + srl B,32-23,B + or B,T2,B + add B,C,B + +!!!!!!!!Round 3 + + orn B,D,T1 != + sethi %hi(0xf4292244),T2 + xor T1,C,T1 + or T2,%lo(0xf4292244),T2 + add T1,R0,T1 != + !pre-LOADed X(7),R7 + add T1,T2,T1 + add A,T1,A + sll A,6,T2 + srl A,32-6,A != + or A,T2,A + add A,B,A + + orn A,C,T1 + sethi %hi(0x432aff97),T2 != + xor T1,B,T1 + or T2,%lo(0x432aff97),T2 + LOAD X(14),RX + add T1,R7,T1 != + add T1,T2,T1 + add D,T1,D + sll D,10,T2 + srl D,32-10,D != + or D,T2,D + add D,A,D + + orn D,B,T1 + sethi %hi(0xab9423a7),T2 != + xor T1,A,T1 + or T2,%lo(0xab9423a7),T2 + add T1,RX,T1 + !pre-LOADed X(5),R5 + add T1,T2,T1 != + add C,T1,C + sll C,15,T2 + srl C,32-15,C + or C,T2,C != + add C,D,C + + orn C,A,T1 + sethi %hi(0xfc93a039),T2 + xor T1,D,T1 != + or T2,%lo(0xfc93a039),T2 + add T1,R5,T1 + !pre-LOADed X(12),R12 + add T1,T2,T1 + add B,T1,B != + sll B,21,T2 + srl B,32-21,B + or B,T2,B + add B,C,B != + + orn B,D,T1 + sethi %hi(0x655b59c3),T2 + xor T1,C,T1 + or T2,%lo(0x655b59c3),T2 != + add T1,R12,T1 + !pre-LOADed X(3),R3 + add T1,T2,T1 + add A,T1,A + sll A,6,T2 != + srl A,32-6,A + or A,T2,A + add A,B,A + + orn A,C,T1 != + sethi %hi(0x8f0ccc92),T2 + xor T1,B,T1 + or T2,%lo(0x8f0ccc92),T2 + add T1,R3,T1 != + !pre-LOADed X(10),R10 + add T1,T2,T1 + add D,T1,D + sll D,10,T2 + srl D,32-10,D != + or D,T2,D + add D,A,D + + orn D,B,T1 + sethi %hi(0xffeff47d),T2 != + xor T1,A,T1 + or T2,%lo(0xffeff47d),T2 + add T1,R10,T1 + !pre-LOADed X(1),R1 + add T1,T2,T1 != + add C,T1,C + sll C,15,T2 + srl C,32-15,C + or C,T2,C != + add C,D,C + + orn C,A,T1 + sethi %hi(0x85845dd1),T2 + xor T1,D,T1 != + or T2,%lo(0x85845dd1),T2 + add T1,R1,T1 + !pre-LOADed X(8),R8 + add T1,T2,T1 + add B,T1,B != + sll B,21,T2 + srl B,32-21,B + or B,T2,B + add B,C,B != + + orn B,D,T1 + sethi %hi(0x6fa87e4f),T2 + xor T1,C,T1 + or T2,%lo(0x6fa87e4f),T2 != + add T1,R8,T1 + LOAD X(15),RX + add T1,T2,T1 + add A,T1,A != + sll A,6,T2 + srl A,32-6,A + or A,T2,A + add A,B,A != + + orn A,C,T1 + sethi %hi(0xfe2ce6e0),T2 + xor T1,B,T1 + or T2,%lo(0xfe2ce6e0),T2 != + add T1,RX,T1 + !pre-LOADed X(6),R6 + add T1,T2,T1 + add D,T1,D + sll D,10,T2 != + srl D,32-10,D + or D,T2,D + add D,A,D + + orn D,B,T1 != + sethi %hi(0xa3014314),T2 + xor T1,A,T1 + or T2,%lo(0xa3014314),T2 + add T1,R6,T1 != + !pre-LOADed X(13),R13 + add T1,T2,T1 + add C,T1,C + sll C,15,T2 + srl C,32-15,C != + or C,T2,C + add C,D,C + + orn C,A,T1 + sethi %hi(0x4e0811a1),T2 != + xor T1,D,T1 + or T2,%lo(0x4e0811a1),T2 + !pre-LOADed X(4),R4 + ld [Aptr],Aval + add T1,R13,T1 != + add T1,T2,T1 + add B,T1,B + sll B,21,T2 + srl B,32-21,B != + or B,T2,B + add B,C,B + + orn B,D,T1 + sethi %hi(0xf7537e82),T2 != + xor T1,C,T1 + or T2,%lo(0xf7537e82),T2 + !pre-LOADed X(11),R11 + ld [Dptr],Dval + add T1,R4,T1 != + add T1,T2,T1 + add A,T1,A + sll A,6,T2 + srl A,32-6,A != + or A,T2,A + add A,B,A + + orn A,C,T1 + sethi %hi(0xbd3af235),T2 != + xor T1,B,T1 + or T2,%lo(0xbd3af235),T2 + !pre-LOADed X(2),R2 + ld [Cptr],Cval + add T1,R11,T1 != + add T1,T2,T1 + add D,T1,D + sll D,10,T2 + srl D,32-10,D != + or D,T2,D + add D,A,D + + orn D,B,T1 + sethi %hi(0x2ad7d2bb),T2 != + xor T1,A,T1 + or T2,%lo(0x2ad7d2bb),T2 + !pre-LOADed X(9),R9 + ld [Bptr],Bval + add T1,R2,T1 != + add Aval,A,Aval + add T1,T2,T1 + st Aval,[Aptr] + add C,T1,C != + sll C,15,T2 + add Dval,D,Dval + srl C,32-15,C + or C,T2,C != + st Dval,[Dptr] + add C,D,C + + orn C,A,T1 + sethi %hi(0xeb86d391),T2 != + xor T1,D,T1 + or T2,%lo(0xeb86d391),T2 + add T1,R9,T1 + !pre-LOADed X(0),R0 + mov Aval,A != + add T1,T2,T1 + mov Dval,D + add B,T1,B + sll B,21,T2 != + add Cval,C,Cval + srl B,32-21,B + st Cval,[Cptr] + or B,T2,B != + add B,C,B + + deccc %i2 + mov Cval,C + add B,Bval,B != + inc 64,%i1 + nop + st B,[Bptr] + nop != + +#ifdef ULTRASPARC + bg,a,pt %icc,.Lmd5_block_loop +#else + bg,a .Lmd5_block_loop +#endif + LOAD X(0),R0 + +#ifdef ASI_PRIMARY_LITTLE + wr %g0,%o7,%asi +#endif + ret + restore %g0,0,%o0 + +.type md5_block,#function +.size md5_block,(.-md5_block) diff --git a/src/lib/libcrypto/md5/asm/mx86unix.cpp b/src/lib/libcrypto/md5/asm/mx86unix.cpp deleted file mode 100644 index 5d399122b6..0000000000 --- a/src/lib/libcrypto/md5/asm/mx86unix.cpp +++ /dev/null @@ -1,730 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define md5_block_x86 _md5_block_x86 - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by md5-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "md5-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl md5_block_x86 - TYPE(md5_block_x86,@function) -md5_block_x86: - pushl %esi - pushl %edi - movl 12(%esp), %edi - movl 16(%esp), %esi - movl 20(%esp), %ecx - pushl %ebp - pushl %ebx - addl %esi, %ecx - subl $64, %ecx - movl (%edi), %eax - pushl %ecx - movl 4(%edi), %ebx - movl 8(%edi), %ecx - movl 12(%edi), %edx -.L000start: - - /* R0 section */ - movl %ecx, %edi - movl (%esi), %ebp - /* R0 0 */ - xorl %edx, %edi - andl %ebx, %edi - leal 3614090360(%eax,%ebp,1),%eax - movl 4(%esi), %ebp - xorl %edx, %edi - addl %edi, %eax - movl %ebx, %edi - roll $7, %eax - addl %ebx, %eax - /* R0 1 */ - xorl %ecx, %edi - andl %eax, %edi - leal 3905402710(%edx,%ebp,1),%edx - movl 8(%esi), %ebp - xorl %ecx, %edi - addl %edi, %edx - movl %eax, %edi - roll $12, %edx - addl %eax, %edx - /* R0 2 */ - xorl %ebx, %edi - andl %edx, %edi - leal 606105819(%ecx,%ebp,1),%ecx - movl 12(%esi), %ebp - xorl %ebx, %edi - addl %edi, %ecx - movl %edx, %edi - roll $17, %ecx - addl %edx, %ecx - /* R0 3 */ - xorl %eax, %edi - andl %ecx, %edi - leal 3250441966(%ebx,%ebp,1),%ebx - movl 16(%esi), %ebp - xorl %eax, %edi - addl %edi, %ebx - movl %ecx, %edi - roll $22, %ebx - addl %ecx, %ebx - /* R0 4 */ - xorl %edx, %edi - andl %ebx, %edi - leal 4118548399(%eax,%ebp,1),%eax - movl 20(%esi), %ebp - xorl %edx, %edi - addl %edi, %eax - movl %ebx, %edi - roll $7, %eax - addl %ebx, %eax - /* R0 5 */ - xorl %ecx, %edi - andl %eax, %edi - leal 1200080426(%edx,%ebp,1),%edx - movl 24(%esi), %ebp - xorl %ecx, %edi - addl %edi, %edx - movl %eax, %edi - roll $12, %edx - addl %eax, %edx - /* R0 6 */ - xorl %ebx, %edi - andl %edx, %edi - leal 2821735955(%ecx,%ebp,1),%ecx - movl 28(%esi), %ebp - xorl %ebx, %edi - addl %edi, %ecx - movl %edx, %edi - roll $17, %ecx - addl %edx, %ecx - /* R0 7 */ - xorl %eax, %edi - andl %ecx, %edi - leal 4249261313(%ebx,%ebp,1),%ebx - movl 32(%esi), %ebp - xorl %eax, %edi - addl %edi, %ebx - movl %ecx, %edi - roll $22, %ebx - addl %ecx, %ebx - /* R0 8 */ - xorl %edx, %edi - andl %ebx, %edi - leal 1770035416(%eax,%ebp,1),%eax - movl 36(%esi), %ebp - xorl %edx, %edi - addl %edi, %eax - movl %ebx, %edi - roll $7, %eax - addl %ebx, %eax - /* R0 9 */ - xorl %ecx, %edi - andl %eax, %edi - leal 2336552879(%edx,%ebp,1),%edx - movl 40(%esi), %ebp - xorl %ecx, %edi - addl %edi, %edx - movl %eax, %edi - roll $12, %edx - addl %eax, %edx - /* R0 10 */ - xorl %ebx, %edi - andl %edx, %edi - leal 4294925233(%ecx,%ebp,1),%ecx - movl 44(%esi), %ebp - xorl %ebx, %edi - addl %edi, %ecx - movl %edx, %edi - roll $17, %ecx - addl %edx, %ecx - /* R0 11 */ - xorl %eax, %edi - andl %ecx, %edi - leal 2304563134(%ebx,%ebp,1),%ebx - movl 48(%esi), %ebp - xorl %eax, %edi - addl %edi, %ebx - movl %ecx, %edi - roll $22, %ebx - addl %ecx, %ebx - /* R0 12 */ - xorl %edx, %edi - andl %ebx, %edi - leal 1804603682(%eax,%ebp,1),%eax - movl 52(%esi), %ebp - xorl %edx, %edi - addl %edi, %eax - movl %ebx, %edi - roll $7, %eax - addl %ebx, %eax - /* R0 13 */ - xorl %ecx, %edi - andl %eax, %edi - leal 4254626195(%edx,%ebp,1),%edx - movl 56(%esi), %ebp - xorl %ecx, %edi - addl %edi, %edx - movl %eax, %edi - roll $12, %edx - addl %eax, %edx - /* R0 14 */ - xorl %ebx, %edi - andl %edx, %edi - leal 2792965006(%ecx,%ebp,1),%ecx - movl 60(%esi), %ebp - xorl %ebx, %edi - addl %edi, %ecx - movl %edx, %edi - roll $17, %ecx - addl %edx, %ecx - /* R0 15 */ - xorl %eax, %edi - andl %ecx, %edi - leal 1236535329(%ebx,%ebp,1),%ebx - movl 4(%esi), %ebp - xorl %eax, %edi - addl %edi, %ebx - movl %ecx, %edi - roll $22, %ebx - addl %ecx, %ebx - - /* R1 section */ - /* R1 16 */ - leal 4129170786(%eax,%ebp,1),%eax - xorl %ebx, %edi - andl %edx, %edi - movl 24(%esi), %ebp - xorl %ecx, %edi - addl %edi, %eax - movl %ebx, %edi - roll $5, %eax - addl %ebx, %eax - /* R1 17 */ - leal 3225465664(%edx,%ebp,1),%edx - xorl %eax, %edi - andl %ecx, %edi - movl 44(%esi), %ebp - xorl %ebx, %edi - addl %edi, %edx - movl %eax, %edi - roll $9, %edx - addl %eax, %edx - /* R1 18 */ - leal 643717713(%ecx,%ebp,1),%ecx - xorl %edx, %edi - andl %ebx, %edi - movl (%esi), %ebp - xorl %eax, %edi - addl %edi, %ecx - movl %edx, %edi - roll $14, %ecx - addl %edx, %ecx - /* R1 19 */ - leal 3921069994(%ebx,%ebp,1),%ebx - xorl %ecx, %edi - andl %eax, %edi - movl 20(%esi), %ebp - xorl %edx, %edi - addl %edi, %ebx - movl %ecx, %edi - roll $20, %ebx - addl %ecx, %ebx - /* R1 20 */ - leal 3593408605(%eax,%ebp,1),%eax - xorl %ebx, %edi - andl %edx, %edi - movl 40(%esi), %ebp - xorl %ecx, %edi - addl %edi, %eax - movl %ebx, %edi - roll $5, %eax - addl %ebx, %eax - /* R1 21 */ - leal 38016083(%edx,%ebp,1),%edx - xorl %eax, %edi - andl %ecx, %edi - movl 60(%esi), %ebp - xorl %ebx, %edi - addl %edi, %edx - movl %eax, %edi - roll $9, %edx - addl %eax, %edx - /* R1 22 */ - leal 3634488961(%ecx,%ebp,1),%ecx - xorl %edx, %edi - andl %ebx, %edi - movl 16(%esi), %ebp - xorl %eax, %edi - addl %edi, %ecx - movl %edx, %edi - roll $14, %ecx - addl %edx, %ecx - /* R1 23 */ - leal 3889429448(%ebx,%ebp,1),%ebx - xorl %ecx, %edi - andl %eax, %edi - movl 36(%esi), %ebp - xorl %edx, %edi - addl %edi, %ebx - movl %ecx, %edi - roll $20, %ebx - addl %ecx, %ebx - /* R1 24 */ - leal 568446438(%eax,%ebp,1),%eax - xorl %ebx, %edi - andl %edx, %edi - movl 56(%esi), %ebp - xorl %ecx, %edi - addl %edi, %eax - movl %ebx, %edi - roll $5, %eax - addl %ebx, %eax - /* R1 25 */ - leal 3275163606(%edx,%ebp,1),%edx - xorl %eax, %edi - andl %ecx, %edi - movl 12(%esi), %ebp - xorl %ebx, %edi - addl %edi, %edx - movl %eax, %edi - roll $9, %edx - addl %eax, %edx - /* R1 26 */ - leal 4107603335(%ecx,%ebp,1),%ecx - xorl %edx, %edi - andl %ebx, %edi - movl 32(%esi), %ebp - xorl %eax, %edi - addl %edi, %ecx - movl %edx, %edi - roll $14, %ecx - addl %edx, %ecx - /* R1 27 */ - leal 1163531501(%ebx,%ebp,1),%ebx - xorl %ecx, %edi - andl %eax, %edi - movl 52(%esi), %ebp - xorl %edx, %edi - addl %edi, %ebx - movl %ecx, %edi - roll $20, %ebx - addl %ecx, %ebx - /* R1 28 */ - leal 2850285829(%eax,%ebp,1),%eax - xorl %ebx, %edi - andl %edx, %edi - movl 8(%esi), %ebp - xorl %ecx, %edi - addl %edi, %eax - movl %ebx, %edi - roll $5, %eax - addl %ebx, %eax - /* R1 29 */ - leal 4243563512(%edx,%ebp,1),%edx - xorl %eax, %edi - andl %ecx, %edi - movl 28(%esi), %ebp - xorl %ebx, %edi - addl %edi, %edx - movl %eax, %edi - roll $9, %edx - addl %eax, %edx - /* R1 30 */ - leal 1735328473(%ecx,%ebp,1),%ecx - xorl %edx, %edi - andl %ebx, %edi - movl 48(%esi), %ebp - xorl %eax, %edi - addl %edi, %ecx - movl %edx, %edi - roll $14, %ecx - addl %edx, %ecx - /* R1 31 */ - leal 2368359562(%ebx,%ebp,1),%ebx - xorl %ecx, %edi - andl %eax, %edi - movl 20(%esi), %ebp - xorl %edx, %edi - addl %edi, %ebx - movl %ecx, %edi - roll $20, %ebx - addl %ecx, %ebx - - /* R2 section */ - /* R2 32 */ - xorl %edx, %edi - xorl %ebx, %edi - leal 4294588738(%eax,%ebp,1),%eax - addl %edi, %eax - movl 32(%esi), %ebp - roll $4, %eax - movl %ebx, %edi - /* R2 33 */ - leal 2272392833(%edx,%ebp,1),%edx - addl %ebx, %eax - xorl %ecx, %edi - xorl %eax, %edi - movl 44(%esi), %ebp - addl %edi, %edx - movl %eax, %edi - roll $11, %edx - addl %eax, %edx - /* R2 34 */ - xorl %ebx, %edi - xorl %edx, %edi - leal 1839030562(%ecx,%ebp,1),%ecx - addl %edi, %ecx - movl 56(%esi), %ebp - roll $16, %ecx - movl %edx, %edi - /* R2 35 */ - leal 4259657740(%ebx,%ebp,1),%ebx - addl %edx, %ecx - xorl %eax, %edi - xorl %ecx, %edi - movl 4(%esi), %ebp - addl %edi, %ebx - movl %ecx, %edi - roll $23, %ebx - addl %ecx, %ebx - /* R2 36 */ - xorl %edx, %edi - xorl %ebx, %edi - leal 2763975236(%eax,%ebp,1),%eax - addl %edi, %eax - movl 16(%esi), %ebp - roll $4, %eax - movl %ebx, %edi - /* R2 37 */ - leal 1272893353(%edx,%ebp,1),%edx - addl %ebx, %eax - xorl %ecx, %edi - xorl %eax, %edi - movl 28(%esi), %ebp - addl %edi, %edx - movl %eax, %edi - roll $11, %edx - addl %eax, %edx - /* R2 38 */ - xorl %ebx, %edi - xorl %edx, %edi - leal 4139469664(%ecx,%ebp,1),%ecx - addl %edi, %ecx - movl 40(%esi), %ebp - roll $16, %ecx - movl %edx, %edi - /* R2 39 */ - leal 3200236656(%ebx,%ebp,1),%ebx - addl %edx, %ecx - xorl %eax, %edi - xorl %ecx, %edi - movl 52(%esi), %ebp - addl %edi, %ebx - movl %ecx, %edi - roll $23, %ebx - addl %ecx, %ebx - /* R2 40 */ - xorl %edx, %edi - xorl %ebx, %edi - leal 681279174(%eax,%ebp,1),%eax - addl %edi, %eax - movl (%esi), %ebp - roll $4, %eax - movl %ebx, %edi - /* R2 41 */ - leal 3936430074(%edx,%ebp,1),%edx - addl %ebx, %eax - xorl %ecx, %edi - xorl %eax, %edi - movl 12(%esi), %ebp - addl %edi, %edx - movl %eax, %edi - roll $11, %edx - addl %eax, %edx - /* R2 42 */ - xorl %ebx, %edi - xorl %edx, %edi - leal 3572445317(%ecx,%ebp,1),%ecx - addl %edi, %ecx - movl 24(%esi), %ebp - roll $16, %ecx - movl %edx, %edi - /* R2 43 */ - leal 76029189(%ebx,%ebp,1),%ebx - addl %edx, %ecx - xorl %eax, %edi - xorl %ecx, %edi - movl 36(%esi), %ebp - addl %edi, %ebx - movl %ecx, %edi - roll $23, %ebx - addl %ecx, %ebx - /* R2 44 */ - xorl %edx, %edi - xorl %ebx, %edi - leal 3654602809(%eax,%ebp,1),%eax - addl %edi, %eax - movl 48(%esi), %ebp - roll $4, %eax - movl %ebx, %edi - /* R2 45 */ - leal 3873151461(%edx,%ebp,1),%edx - addl %ebx, %eax - xorl %ecx, %edi - xorl %eax, %edi - movl 60(%esi), %ebp - addl %edi, %edx - movl %eax, %edi - roll $11, %edx - addl %eax, %edx - /* R2 46 */ - xorl %ebx, %edi - xorl %edx, %edi - leal 530742520(%ecx,%ebp,1),%ecx - addl %edi, %ecx - movl 8(%esi), %ebp - roll $16, %ecx - movl %edx, %edi - /* R2 47 */ - leal 3299628645(%ebx,%ebp,1),%ebx - addl %edx, %ecx - xorl %eax, %edi - xorl %ecx, %edi - movl (%esi), %ebp - addl %edi, %ebx - movl $-1, %edi - roll $23, %ebx - addl %ecx, %ebx - - /* R3 section */ - /* R3 48 */ - xorl %edx, %edi - orl %ebx, %edi - leal 4096336452(%eax,%ebp,1),%eax - xorl %ecx, %edi - movl 28(%esi), %ebp - addl %edi, %eax - movl $-1, %edi - roll $6, %eax - xorl %ecx, %edi - addl %ebx, %eax - /* R3 49 */ - orl %eax, %edi - leal 1126891415(%edx,%ebp,1),%edx - xorl %ebx, %edi - movl 56(%esi), %ebp - addl %edi, %edx - movl $-1, %edi - roll $10, %edx - xorl %ebx, %edi - addl %eax, %edx - /* R3 50 */ - orl %edx, %edi - leal 2878612391(%ecx,%ebp,1),%ecx - xorl %eax, %edi - movl 20(%esi), %ebp - addl %edi, %ecx - movl $-1, %edi - roll $15, %ecx - xorl %eax, %edi - addl %edx, %ecx - /* R3 51 */ - orl %ecx, %edi - leal 4237533241(%ebx,%ebp,1),%ebx - xorl %edx, %edi - movl 48(%esi), %ebp - addl %edi, %ebx - movl $-1, %edi - roll $21, %ebx - xorl %edx, %edi - addl %ecx, %ebx - /* R3 52 */ - orl %ebx, %edi - leal 1700485571(%eax,%ebp,1),%eax - xorl %ecx, %edi - movl 12(%esi), %ebp - addl %edi, %eax - movl $-1, %edi - roll $6, %eax - xorl %ecx, %edi - addl %ebx, %eax - /* R3 53 */ - orl %eax, %edi - leal 2399980690(%edx,%ebp,1),%edx - xorl %ebx, %edi - movl 40(%esi), %ebp - addl %edi, %edx - movl $-1, %edi - roll $10, %edx - xorl %ebx, %edi - addl %eax, %edx - /* R3 54 */ - orl %edx, %edi - leal 4293915773(%ecx,%ebp,1),%ecx - xorl %eax, %edi - movl 4(%esi), %ebp - addl %edi, %ecx - movl $-1, %edi - roll $15, %ecx - xorl %eax, %edi - addl %edx, %ecx - /* R3 55 */ - orl %ecx, %edi - leal 2240044497(%ebx,%ebp,1),%ebx - xorl %edx, %edi - movl 32(%esi), %ebp - addl %edi, %ebx - movl $-1, %edi - roll $21, %ebx - xorl %edx, %edi - addl %ecx, %ebx - /* R3 56 */ - orl %ebx, %edi - leal 1873313359(%eax,%ebp,1),%eax - xorl %ecx, %edi - movl 60(%esi), %ebp - addl %edi, %eax - movl $-1, %edi - roll $6, %eax - xorl %ecx, %edi - addl %ebx, %eax - /* R3 57 */ - orl %eax, %edi - leal 4264355552(%edx,%ebp,1),%edx - xorl %ebx, %edi - movl 24(%esi), %ebp - addl %edi, %edx - movl $-1, %edi - roll $10, %edx - xorl %ebx, %edi - addl %eax, %edx - /* R3 58 */ - orl %edx, %edi - leal 2734768916(%ecx,%ebp,1),%ecx - xorl %eax, %edi - movl 52(%esi), %ebp - addl %edi, %ecx - movl $-1, %edi - roll $15, %ecx - xorl %eax, %edi - addl %edx, %ecx - /* R3 59 */ - orl %ecx, %edi - leal 1309151649(%ebx,%ebp,1),%ebx - xorl %edx, %edi - movl 16(%esi), %ebp - addl %edi, %ebx - movl $-1, %edi - roll $21, %ebx - xorl %edx, %edi - addl %ecx, %ebx - /* R3 60 */ - orl %ebx, %edi - leal 4149444226(%eax,%ebp,1),%eax - xorl %ecx, %edi - movl 44(%esi), %ebp - addl %edi, %eax - movl $-1, %edi - roll $6, %eax - xorl %ecx, %edi - addl %ebx, %eax - /* R3 61 */ - orl %eax, %edi - leal 3174756917(%edx,%ebp,1),%edx - xorl %ebx, %edi - movl 8(%esi), %ebp - addl %edi, %edx - movl $-1, %edi - roll $10, %edx - xorl %ebx, %edi - addl %eax, %edx - /* R3 62 */ - orl %edx, %edi - leal 718787259(%ecx,%ebp,1),%ecx - xorl %eax, %edi - movl 36(%esi), %ebp - addl %edi, %ecx - movl $-1, %edi - roll $15, %ecx - xorl %eax, %edi - addl %edx, %ecx - /* R3 63 */ - orl %ecx, %edi - leal 3951481745(%ebx,%ebp,1),%ebx - xorl %edx, %edi - movl 24(%esp), %ebp - addl %edi, %ebx - addl $64, %esi - roll $21, %ebx - movl (%ebp), %edi - addl %ecx, %ebx - addl %edi, %eax - movl 4(%ebp), %edi - addl %edi, %ebx - movl 8(%ebp), %edi - addl %edi, %ecx - movl 12(%ebp), %edi - addl %edi, %edx - movl %eax, (%ebp) - movl %ebx, 4(%ebp) - movl (%esp), %edi - movl %ecx, 8(%ebp) - movl %edx, 12(%ebp) - cmpl %esi, %edi - jge .L000start - popl %eax - popl %ebx - popl %ebp - popl %edi - popl %esi - ret -.md5_block_x86_end: - SIZE(md5_block_x86,.md5_block_x86_end-md5_block_x86) -.ident "desasm.pl" diff --git a/src/lib/libcrypto/md5/md5.c b/src/lib/libcrypto/md5/md5.c index 9d6f5a6003..7ed0024ae1 100644 --- a/src/lib/libcrypto/md5/md5.c +++ b/src/lib/libcrypto/md5/md5.c @@ -58,23 +58,17 @@ #include #include -#include "md5.h" +#include #define BUFSIZE 1024*16 -#ifndef NOPROTO void do_fp(FILE *f); void pt(unsigned char *md); +#ifndef _OSD_POSIX int read(int, void *, unsigned int); -#else -void do_fp(); -void pt(); -int read(); #endif -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int i,err=0; FILE *IN; @@ -102,8 +96,7 @@ char **argv; exit(err); } -void do_fp(f) -FILE *f; +void do_fp(FILE *f) { MD5_CTX c; unsigned char md[MD5_DIGEST_LENGTH]; @@ -123,8 +116,7 @@ FILE *f; pt(md); } -void pt(md) -unsigned char *md; +void pt(unsigned char *md) { int i; diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h index 357c6c625d..bdab6d45e8 100644 --- a/src/lib/libcrypto/md5/md5.h +++ b/src/lib/libcrypto/md5/md5.h @@ -63,35 +63,50 @@ extern "C" { #endif +#ifdef NO_MD5 +#error MD5 is disabled. +#endif + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then ! + * ! MD5_LONG_LOG2 has to be defined along. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + +#if defined(WIN16) || defined(__LP32__) +#define MD5_LONG unsigned long +#elif defined(_CRAY) || defined(__ILP64__) +#define MD5_LONG unsigned long +#define MD5_LONG_LOG2 3 +/* + * _CRAY note. I could declare short, but I have no idea what impact + * does it have on performance on none-T3E machines. I could declare + * int, but at least on C90 sizeof(int) can be chosen at compile time. + * So I've chosen long... + * + */ +#else +#define MD5_LONG unsigned int +#endif + #define MD5_CBLOCK 64 -#define MD5_LBLOCK 16 -#define MD5_BLOCK 16 -#define MD5_LAST_BLOCK 56 -#define MD5_LENGTH_BLOCK 8 +#define MD5_LBLOCK (MD5_CBLOCK/4) #define MD5_DIGEST_LENGTH 16 typedef struct MD5state_st { - unsigned long A,B,C,D; - unsigned long Nl,Nh; - unsigned long data[MD5_LBLOCK]; + MD5_LONG A,B,C,D; + MD5_LONG Nl,Nh; + MD5_LONG data[MD5_LBLOCK]; int num; } MD5_CTX; -#ifndef NOPROTO void MD5_Init(MD5_CTX *c); -void MD5_Update(MD5_CTX *c, unsigned char *data, unsigned long len); +void MD5_Update(MD5_CTX *c, const unsigned char *data, unsigned long len); void MD5_Final(unsigned char *md, MD5_CTX *c); unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md); -void MD5_Transform(MD5_CTX *c, unsigned char *b); -#else -void MD5_Init(); -void MD5_Update(); -void MD5_Final(); -unsigned char *MD5(); -void MD5_Transform(); -#endif - +void MD5_Transform(MD5_CTX *c, const unsigned char *b); #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c index 43b3498d92..ba0115ae79 100644 --- a/src/lib/libcrypto/md5/md5_dgst.c +++ b/src/lib/libcrypto/md5/md5_dgst.c @@ -58,8 +58,9 @@ #include #include "md5_locl.h" +#include -char *MD5_version="MD5 part of SSLeay 0.9.0b 29-Jun-1998"; +char *MD5_version="MD5" OPENSSL_VERSION_PTEXT; /* Implemented from RFC1321 The MD5 Message-Digest Algorithm */ @@ -69,24 +70,7 @@ char *MD5_version="MD5 part of SSLeay 0.9.0b 29-Jun-1998"; #define INIT_DATA_C (unsigned long)0x98badcfeL #define INIT_DATA_D (unsigned long)0x10325476L -#ifndef NOPROTO -# ifdef MD5_ASM - void md5_block_x86(MD5_CTX *c, unsigned long *p,int num); -# define md5_block md5_block_x86 -# else - static void md5_block(MD5_CTX *c, unsigned long *p,int num); -# endif -#else -# ifdef MD5_ASM - void md5_block_x86(); -# define md5_block md5_block_x86 -# else - static void md5_block(); -# endif -#endif - -void MD5_Init(c) -MD5_CTX *c; +void MD5_Init(MD5_CTX *c) { c->A=INIT_DATA_A; c->B=INIT_DATA_B; @@ -97,190 +81,32 @@ MD5_CTX *c; c->num=0; } -void MD5_Update(c, data, len) -MD5_CTX *c; -register unsigned char *data; -unsigned long len; - { - register ULONG *p; - int sw,sc; - ULONG l; - - if (len == 0) return; - - l=(c->Nl+(len<<3))&0xffffffffL; - /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to - * Wei Dai for pointing it out. */ - if (l < c->Nl) /* overflow */ - c->Nh++; - c->Nh+=(len>>29); - c->Nl=l; - - if (c->num != 0) - { - p=c->data; - sw=c->num>>2; - sc=c->num&0x03; - - if ((c->num+len) >= MD5_CBLOCK) - { - l= p[sw]; - p_c2l(data,l,sc); - p[sw++]=l; - for (; swnum); - - md5_block(c,p,64); - c->num=0; - /* drop through and do the rest */ - } - else - { - int ew,ec; - - c->num+=(int)len; - if ((sc+len) < 4) /* ugly, add char's to a word */ - { - l= p[sw]; - p_c2l_p(data,l,sc,len); - p[sw]=l; - } - else - { - ew=(c->num>>2); - ec=(c->num&0x03); - l= p[sw]; - p_c2l(data,l,sc); - p[sw++]=l; - for (; sw < ew; sw++) - { c2l(data,l); p[sw]=l; } - if (ec) - { - c2l_p(data,l,ec); - p[sw]=l; - } - } - return; - } - } - /* we now can process the input data in blocks of MD5_CBLOCK - * chars and save the leftovers to c->data. */ -#ifdef L_ENDIAN - if ((((unsigned long)data)%sizeof(ULONG)) == 0) - { - sw=(int)len/MD5_CBLOCK; - if (sw > 0) - { - sw*=MD5_CBLOCK; - md5_block(c,(ULONG *)data,sw); - data+=sw; - len-=sw; - } - } -#endif - p=c->data; - while (len >= MD5_CBLOCK) - { -#if defined(L_ENDIAN) || defined(B_ENDIAN) - if (p != (unsigned long *)data) - memcpy(p,data,MD5_CBLOCK); - data+=MD5_CBLOCK; -#ifdef B_ENDIAN - for (sw=(MD5_LBLOCK/4); sw; sw--) - { - Endian_Reverse32(p[0]); - Endian_Reverse32(p[1]); - Endian_Reverse32(p[2]); - Endian_Reverse32(p[3]); - p+=4; - } -#endif -#else - for (sw=(MD5_LBLOCK/4); sw; sw--) - { - c2l(data,l); *(p++)=l; - c2l(data,l); *(p++)=l; - c2l(data,l); *(p++)=l; - c2l(data,l); *(p++)=l; - } -#endif - p=c->data; - md5_block(c,p,64); - len-=MD5_CBLOCK; - } - sc=(int)len; - c->num=sc; - if (sc) - { - sw=sc>>2; /* words to copy */ -#ifdef L_ENDIAN - p[sw]=0; - memcpy(p,data,sc); -#else - sc&=0x03; - for ( ; sw; sw--) - { c2l(data,l); *(p++)=l; } - c2l_p(data,l,sc); - *p=l; -#endif - } - } - -void MD5_Transform(c,b) -MD5_CTX *c; -unsigned char *b; +#ifndef md5_block_host_order +void md5_block_host_order (MD5_CTX *c, const void *data, int num) { - ULONG p[16]; -#if !defined(L_ENDIAN) - ULONG *q; - int i; -#endif - -#if defined(B_ENDIAN) || defined(L_ENDIAN) - memcpy(p,b,64); -#ifdef B_ENDIAN - q=p; - for (i=(MD5_LBLOCK/4); i; i--) - { - Endian_Reverse32(q[0]); - Endian_Reverse32(q[1]); - Endian_Reverse32(q[2]); - Endian_Reverse32(q[3]); - q+=4; - } -#endif -#else - q=p; - for (i=(MD5_LBLOCK/4); i; i--) - { - ULONG l; - c2l(b,l); *(q++)=l; - c2l(b,l); *(q++)=l; - c2l(b,l); *(q++)=l; - c2l(b,l); *(q++)=l; - } -#endif - md5_block(c,p,64); - } - -#ifndef MD5_ASM - -static void md5_block(c, X, num) -MD5_CTX *c; -register ULONG *X; -int num; - { - register ULONG A,B,C,D; + const MD5_LONG *X=data; + register unsigned long A,B,C,D; + /* + * In case you wonder why A-D are declared as long and not + * as MD5_LONG. Doing so results in slight performance + * boost on LP64 architectures. The catch is we don't + * really care if 32 MSBs of a 64-bit register get polluted + * with eventual overflows as we *save* only 32 LSBs in + * *either* case. Now declaring 'em long excuses the compiler + * from keeping 32 MSBs zeroed resulting in 13% performance + * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. + * Well, to be honest it should say that this *prevents* + * performance degradation. + * + * + */ A=c->A; B=c->B; C=c->C; D=c->D; - for (;;) + + for (;num--;X+=HASH_LBLOCK) { /* Round 0 */ R0(A,B,C,D,X[ 0], 7,0xd76aa478L); @@ -351,80 +177,131 @@ int num; R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL); R3(B,C,D,A,X[ 9],21,0xeb86d391L); - A+=c->A&0xffffffffL; - B+=c->B&0xffffffffL; - c->A=A; - c->B=B; - C+=c->C&0xffffffffL; - D+=c->D&0xffffffffL; - c->C=C; - c->D=D; - X+=16; - num-=64; - if (num <= 0) break; + A = c->A += A; + B = c->B += B; + C = c->C += C; + D = c->D += D; } } #endif -void MD5_Final(md, c) -unsigned char *md; -MD5_CTX *c; +#ifndef md5_block_data_order +void md5_block_data_order (MD5_CTX *c, const void *data_, int num) { - register int i,j; - register ULONG l; - register ULONG *p; - static unsigned char end[4]={0x80,0x00,0x00,0x00}; - unsigned char *cp=end; + const unsigned char *data=data_; + register unsigned long A,B,C,D,l; + /* + * In case you wonder why A-D are declared as long and not + * as MD5_LONG. Doing so results in slight performance + * boost on LP64 architectures. The catch is we don't + * really care if 32 MSBs of a 64-bit register get polluted + * with eventual overflows as we *save* only 32 LSBs in + * *either* case. Now declaring 'em long excuses the compiler + * from keeping 32 MSBs zeroed resulting in 13% performance + * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. + * Well, to be honest it should say that this *prevents* + * performance degradation. + * + * + */ + MD5_LONG X[MD5_LBLOCK]; + /* + * In case you wonder why don't I use c->data for this. + * RISCs usually have a handful of registers and if X is + * declared as automatic array good optimizing compiler + * shall accomodate at least part of it in register bank + * instead of memory. + * + * + */ - /* c->num should definitly have room for at least one more byte. */ - p=c->data; - j=c->num; - i=j>>2; + A=c->A; + B=c->B; + C=c->C; + D=c->D; - /* purify often complains about the following line as an - * Uninitialized Memory Read. While this can be true, the - * following p_c2l macro will reset l when that case is true. - * This is because j&0x03 contains the number of 'valid' bytes - * already in p[i]. If and only if j&0x03 == 0, the UMR will - * occur but this is also the only time p_c2l will do - * l= *(cp++) instead of l|= *(cp++) - * Many thanks to Alex Tang for pickup this - * 'potential bug' */ -#ifdef PURIFY - if ((j&0x03) == 0) p[i]=0; -#endif - l=p[i]; - p_c2l(cp,l,j&0x03); - p[i]=l; - i++; - /* i is the next 'undefined word' */ - if (c->num >= MD5_LAST_BLOCK) + for (;num--;) { - for (; iNl; - p[MD5_LBLOCK-1]=c->Nh; - md5_block(c,p,64); - cp=md; - l=c->A; l2c(l,cp); - l=c->B; l2c(l,cp); - l=c->C; l2c(l,cp); - l=c->D; l2c(l,cp); + HOST_c2l(data,l); X[ 0]=l; HOST_c2l(data,l); X[ 1]=l; + /* Round 0 */ + R0(A,B,C,D,X[ 0], 7,0xd76aa478L); HOST_c2l(data,l); X[ 2]=l; + R0(D,A,B,C,X[ 1],12,0xe8c7b756L); HOST_c2l(data,l); X[ 3]=l; + R0(C,D,A,B,X[ 2],17,0x242070dbL); HOST_c2l(data,l); X[ 4]=l; + R0(B,C,D,A,X[ 3],22,0xc1bdceeeL); HOST_c2l(data,l); X[ 5]=l; + R0(A,B,C,D,X[ 4], 7,0xf57c0fafL); HOST_c2l(data,l); X[ 6]=l; + R0(D,A,B,C,X[ 5],12,0x4787c62aL); HOST_c2l(data,l); X[ 7]=l; + R0(C,D,A,B,X[ 6],17,0xa8304613L); HOST_c2l(data,l); X[ 8]=l; + R0(B,C,D,A,X[ 7],22,0xfd469501L); HOST_c2l(data,l); X[ 9]=l; + R0(A,B,C,D,X[ 8], 7,0x698098d8L); HOST_c2l(data,l); X[10]=l; + R0(D,A,B,C,X[ 9],12,0x8b44f7afL); HOST_c2l(data,l); X[11]=l; + R0(C,D,A,B,X[10],17,0xffff5bb1L); HOST_c2l(data,l); X[12]=l; + R0(B,C,D,A,X[11],22,0x895cd7beL); HOST_c2l(data,l); X[13]=l; + R0(A,B,C,D,X[12], 7,0x6b901122L); HOST_c2l(data,l); X[14]=l; + R0(D,A,B,C,X[13],12,0xfd987193L); HOST_c2l(data,l); X[15]=l; + R0(C,D,A,B,X[14],17,0xa679438eL); + R0(B,C,D,A,X[15],22,0x49b40821L); + /* Round 1 */ + R1(A,B,C,D,X[ 1], 5,0xf61e2562L); + R1(D,A,B,C,X[ 6], 9,0xc040b340L); + R1(C,D,A,B,X[11],14,0x265e5a51L); + R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL); + R1(A,B,C,D,X[ 5], 5,0xd62f105dL); + R1(D,A,B,C,X[10], 9,0x02441453L); + R1(C,D,A,B,X[15],14,0xd8a1e681L); + R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L); + R1(A,B,C,D,X[ 9], 5,0x21e1cde6L); + R1(D,A,B,C,X[14], 9,0xc33707d6L); + R1(C,D,A,B,X[ 3],14,0xf4d50d87L); + R1(B,C,D,A,X[ 8],20,0x455a14edL); + R1(A,B,C,D,X[13], 5,0xa9e3e905L); + R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L); + R1(C,D,A,B,X[ 7],14,0x676f02d9L); + R1(B,C,D,A,X[12],20,0x8d2a4c8aL); + /* Round 2 */ + R2(A,B,C,D,X[ 5], 4,0xfffa3942L); + R2(D,A,B,C,X[ 8],11,0x8771f681L); + R2(C,D,A,B,X[11],16,0x6d9d6122L); + R2(B,C,D,A,X[14],23,0xfde5380cL); + R2(A,B,C,D,X[ 1], 4,0xa4beea44L); + R2(D,A,B,C,X[ 4],11,0x4bdecfa9L); + R2(C,D,A,B,X[ 7],16,0xf6bb4b60L); + R2(B,C,D,A,X[10],23,0xbebfbc70L); + R2(A,B,C,D,X[13], 4,0x289b7ec6L); + R2(D,A,B,C,X[ 0],11,0xeaa127faL); + R2(C,D,A,B,X[ 3],16,0xd4ef3085L); + R2(B,C,D,A,X[ 6],23,0x04881d05L); + R2(A,B,C,D,X[ 9], 4,0xd9d4d039L); + R2(D,A,B,C,X[12],11,0xe6db99e5L); + R2(C,D,A,B,X[15],16,0x1fa27cf8L); + R2(B,C,D,A,X[ 2],23,0xc4ac5665L); + /* Round 3 */ + R3(A,B,C,D,X[ 0], 6,0xf4292244L); + R3(D,A,B,C,X[ 7],10,0x432aff97L); + R3(C,D,A,B,X[14],15,0xab9423a7L); + R3(B,C,D,A,X[ 5],21,0xfc93a039L); + R3(A,B,C,D,X[12], 6,0x655b59c3L); + R3(D,A,B,C,X[ 3],10,0x8f0ccc92L); + R3(C,D,A,B,X[10],15,0xffeff47dL); + R3(B,C,D,A,X[ 1],21,0x85845dd1L); + R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL); + R3(D,A,B,C,X[15],10,0xfe2ce6e0L); + R3(C,D,A,B,X[ 6],15,0xa3014314L); + R3(B,C,D,A,X[13],21,0x4e0811a1L); + R3(A,B,C,D,X[ 4], 6,0xf7537e82L); + R3(D,A,B,C,X[11],10,0xbd3af235L); + R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL); + R3(B,C,D,A,X[ 9],21,0xeb86d391L); - /* clear stuff, md5_block may be leaving some stuff on the stack - * but I'm not worried :-) */ - c->num=0; -/* memset((char *)&c,0,sizeof(c));*/ + A = c->A += A; + B = c->B += B; + C = c->C += C; + D = c->D += D; + } } +#endif #ifdef undef -int printit(l) -unsigned long *l; +int printit(unsigned long *l) { int i,ii; diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h index dbbe1b71ca..9d04696dbd 100644 --- a/src/lib/libcrypto/md5/md5_locl.h +++ b/src/lib/libcrypto/md5/md5_locl.h @@ -56,102 +56,84 @@ * [including the GNU Public Licence.] */ -/* On sparc, this actually slows things down :-( */ -#if defined(sun) -#undef B_ENDIAN -#endif - #include #include -#include "md5.h" - -#define ULONG unsigned long -#define UCHAR unsigned char -#define UINT unsigned int +#include +#include -#if defined(NOCONST) -#define const +#ifndef MD5_LONG_LOG2 +#define MD5_LONG_LOG2 2 /* default to 32 bits */ #endif -#undef c2l -#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<<24)) - -#undef p_c2l -#define p_c2l(c,l,n) { \ - switch (n) { \ - case 0: l =((unsigned long)(*((c)++))); \ - case 1: l|=((unsigned long)(*((c)++)))<< 8; \ - case 2: l|=((unsigned long)(*((c)++)))<<16; \ - case 3: l|=((unsigned long)(*((c)++)))<<24; \ - } \ - } - -/* NOTE the pointer is not incremented at the end of this */ -#undef c2l_p -#define c2l_p(c,l,n) { \ - l=0; \ - (c)+=n; \ - switch (n) { \ - case 3: l =((unsigned long)(*(--(c))))<<16; \ - case 2: l|=((unsigned long)(*(--(c))))<< 8; \ - case 1: l|=((unsigned long)(*(--(c)))) ; \ - } \ - } +#ifdef MD5_ASM +# if defined(__i386) || defined(_M_IX86) +# define md5_block_host_order md5_block_asm_host_order +# elif defined(__sparc) && defined(ULTRASPARC) + void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num); +# define HASH_BLOCK_DATA_ORDER_ALIGNED md5_block_asm_data_order_aligned +# endif +#endif -#undef p_c2l_p -#define p_c2l_p(c,l,sc,len) { \ - switch (sc) \ - { \ - case 0: l =((unsigned long)(*((c)++))); \ - if (--len == 0) break; \ - case 1: l|=((unsigned long)(*((c)++)))<< 8; \ - if (--len == 0) break; \ - case 2: l|=((unsigned long)(*((c)++)))<<16; \ - } \ - } +void md5_block_host_order (MD5_CTX *c, const void *p,int num); +void md5_block_data_order (MD5_CTX *c, const void *p,int num); -#undef l2c -#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>>24)&0xff)) +#if defined(__i386) || defined(_M_IX86) +/* + * *_block_host_order is expected to handle aligned data while + * *_block_data_order - unaligned. As algorithm and host (x86) + * are in this case of the same "endianess" these two are + * otherwise indistinguishable. But normally you don't want to + * call the same function because unaligned access in places + * where alignment is expected is usually a "Bad Thing". Indeed, + * on RISCs you get punished with BUS ERROR signal or *severe* + * performance degradation. Intel CPUs are in turn perfectly + * capable of loading unaligned data without such drastic side + * effect. Yes, they say it's slower than aligned load, but no + * exception is generated and therefore performance degradation + * is *incomparable* with RISCs. What we should weight here is + * costs of unaligned access against costs of aligning data. + * According to my measurements allowing unaligned access results + * in ~9% performance improvement on Pentium II operating at + * 266MHz. I won't be surprised if the difference will be higher + * on faster systems:-) + * + * + */ +#define md5_block_data_order md5_block_host_order +#endif -/* NOTE - c is not incremented as per l2c */ -#undef l2cn -#define l2cn(l1,l2,c,n) { \ - c+=n; \ - switch (n) { \ - case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ - case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ - case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ - case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ - case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ - case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ - case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ - case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ - } \ - } +#define DATA_ORDER_IS_LITTLE_ENDIAN + +#define HASH_LONG MD5_LONG +#define HASH_LONG_LOG2 MD5_LONG_LOG2 +#define HASH_CTX MD5_CTX +#define HASH_CBLOCK MD5_CBLOCK +#define HASH_LBLOCK MD5_LBLOCK +#define HASH_UPDATE MD5_Update +#define HASH_TRANSFORM MD5_Transform +#define HASH_FINAL MD5_Final +#define HASH_BLOCK_HOST_ORDER md5_block_host_order +#if !defined(L_ENDIAN) || defined(md5_block_data_order) +#define HASH_BLOCK_DATA_ORDER md5_block_data_order +/* + * Little-endians (Intel and Alpha) feel better without this. + * It looks like memcpy does better job than generic + * md5_block_data_order on copying-n-aligning input data. + * But franlky speaking I didn't expect such result on Alpha. + * On the other hand I've got this with egcs-1.0.2 and if + * program is compiled with another (better?) compiler it + * might turn out other way around. + * + * + */ +#endif -/* A nice byte order reversal from Wei Dai */ -#if defined(WIN32) -/* 5 instructions with rotate instruction, else 9 */ -#define Endian_Reverse32(a) \ - { \ - unsigned long l=(a); \ - (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ - } +#ifndef FLAT_INC +#include "../md32_common.h" #else -/* 6 instructions with rotate instruction, else 8 */ -#define Endian_Reverse32(a) \ - { \ - unsigned long l=(a); \ - l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ - (a)=ROTATE(l,16L); \ - } +#include "md32_common.h" #endif + /* #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) #define G(x,y,z) (((x) & (z)) | ((y) & (~(z)))) @@ -166,14 +148,6 @@ #define H(b,c,d) ((b) ^ (c) ^ (d)) #define I(b,c,d) (((~(d)) | (b)) ^ (c)) -#undef ROTATE -#if defined(WIN32) -#define ROTATE(a,n) _lrotl(a,n) -#else -#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) -#endif - - #define R0(a,b,c,d,k,s,t) { \ a+=((k)+(t)+F((b),(c),(d))); \ a=ROTATE(a,s); \ diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c index ab6bb435f9..4b10e7f940 100644 --- a/src/lib/libcrypto/md5/md5_one.c +++ b/src/lib/libcrypto/md5/md5_one.c @@ -57,19 +57,37 @@ */ #include -#include "md5_locl.h" +#include +#include -unsigned char *MD5(d, n, md) -unsigned char *d; -unsigned long n; -unsigned char *md; +#ifdef CHARSET_EBCDIC +#include +#endif + +unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md) { MD5_CTX c; static unsigned char m[MD5_DIGEST_LENGTH]; if (md == NULL) md=m; MD5_Init(&c); +#ifndef CHARSET_EBCDIC MD5_Update(&c,d,n); +#else + { + char temp[1024]; + unsigned long chunk; + + while (n > 0) + { + chunk = (n > sizeof(temp)) ? sizeof(temp) : n; + ebcdic2ascii(temp, d, chunk); + MD5_Update(&c,temp,chunk); + n -= chunk; + d += chunk; + } + } +#endif MD5_Final(md,&c); memset(&c,0,sizeof(c)); /* security consideration */ return(md); diff --git a/src/lib/libcrypto/md5/md5s.cpp b/src/lib/libcrypto/md5/md5s.cpp index ef8e175df0..dd343fd4e6 100644 --- a/src/lib/libcrypto/md5/md5s.cpp +++ b/src/lib/libcrypto/md5/md5s.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include #include -#include "md5.h" +#include extern "C" { void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num); diff --git a/src/lib/libcrypto/md5/md5test.c b/src/lib/libcrypto/md5/md5test.c index 74b84bc67f..a192a62bb3 100644 --- a/src/lib/libcrypto/md5/md5test.c +++ b/src/lib/libcrypto/md5/md5test.c @@ -59,7 +59,15 @@ #include #include #include -#include "md5.h" + +#ifdef NO_MD5 +int main(int argc, char *argv[]) +{ + printf("No MD5 support\n"); + return(0); +} +#else +#include char *test[]={ "", @@ -82,15 +90,8 @@ char *ret[]={ "57edf4a22be3c955ac49da2e2107b67a", }; -#ifndef NOPROTO static char *pt(unsigned char *md); -#else -static char *pt(); -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,err=0; unsigned char **P,**R; @@ -118,8 +119,7 @@ char *argv[]; return(0); } -static char *pt(md) -unsigned char *md; +static char *pt(unsigned char *md) { int i; static char buf[80]; @@ -128,3 +128,4 @@ unsigned char *md; sprintf(&(buf[i*2]),"%02x",md[i]); return(buf); } +#endif diff --git a/src/lib/libcrypto/mdc2/Makefile.ssl b/src/lib/libcrypto/mdc2/Makefile.ssl index 495a2789a0..3a5ad990a6 100644 --- a/src/lib/libcrypto/mdc2/Makefile.ssl +++ b/src/lib/libcrypto/mdc2/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,23 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +mdc2_one.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +mdc2_one.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +mdc2_one.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +mdc2_one.o: ../../include/openssl/err.h ../../include/openssl/mdc2.h +mdc2_one.o: ../../include/openssl/opensslconf.h +mdc2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +mdc2_one.o: ../cryptlib.h +mdc2dgst.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h +mdc2dgst.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 0b104be184..ec8e159fc9 100644 --- a/src/lib/libcrypto/mdc2/mdc2.h +++ b/src/lib/libcrypto/mdc2/mdc2.h @@ -63,7 +63,11 @@ extern "C" { #endif -#include "des.h" +#include + +#ifdef NO_MDC2 +#error MDC2 is disabled. +#endif #define MDC2_BLOCK 8 #define MDC2_DIGEST_LENGTH 16 @@ -76,22 +80,12 @@ typedef struct mdc2_ctx_st int pad_type; /* either 1 or 2, default 1 */ } MDC2_CTX; -#ifndef NOPROTO void MDC2_Init(MDC2_CTX *c); void MDC2_Update(MDC2_CTX *c, unsigned char *data, unsigned long len); void MDC2_Final(unsigned char *md, MDC2_CTX *c); unsigned char *MDC2(unsigned char *d, unsigned long n, unsigned char *md); -#else - -void MDC2_Init(); -void MDC2_Update(); -void MDC2_Final(); -unsigned char *MDC2(); - -#endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c index 72e501ad0f..61fc1e184e 100644 --- a/src/lib/libcrypto/mem.c +++ b/src/lib/libcrypto/mem.c @@ -58,12 +58,30 @@ #include #include -#include "buffer.h" -#include "bio.h" -#include "lhash.h" +#include +#ifdef CRYPTO_MDEBUG_TIME +# include +#endif +#include +#include +#include #include "cryptlib.h" +/* #ifdef CRYPTO_MDEBUG */ +/* static int mh_mode=CRYPTO_MEM_CHECK_ON; */ +/* #else */ static int mh_mode=CRYPTO_MEM_CHECK_OFF; +/* #endif */ +/* State CRYPTO_MEM_CHECK_ON exists only temporarily when the library + * thinks that certain allocations should not be checked (e.g. the data + * structures used for memory checking). It is not suitable as an initial + * state: the library will unexpectedly enable memory checking when it + * executes one of those sections that want to disable checking + * temporarily. + * + * State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes no sense whatsoever. + */ + static unsigned long order=0; static LHASH *mh=NULL; @@ -72,25 +90,41 @@ typedef struct mem_st { char *addr; int num; - char *file; + const char *file; int line; +#ifdef CRYPTO_MDEBUG_THREAD + unsigned long thread; +#endif unsigned long order; +#ifdef CRYPTO_MDEBUG_TIME + time_t time; +#endif } MEM; -int CRYPTO_mem_ctrl(mode) -int mode; +int CRYPTO_mem_ctrl(int mode) { int ret=mh_mode; CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); switch (mode) { - case CRYPTO_MEM_CHECK_ON: - mh_mode|=CRYPTO_MEM_CHECK_ON; + /* for applications: */ + case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */ + mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE; + break; + case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */ + mh_mode = 0; break; - case CRYPTO_MEM_CHECK_OFF: - mh_mode&= ~CRYPTO_MEM_CHECK_ON; + + /* switch off temporarily (for library-internal use): */ + case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */ + mh_mode&= ~CRYPTO_MEM_CHECK_ENABLE; break; + case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */ + if (mh_mode&CRYPTO_MEM_CHECK_ON) + mh_mode|=CRYPTO_MEM_CHECK_ENABLE; + break; + default: break; } @@ -98,14 +132,12 @@ int mode; return(ret); } -static int mem_cmp(a,b) -MEM *a,*b; +static int mem_cmp(MEM *a, MEM *b) { return(a->addr - b->addr); } -static unsigned long mem_hash(a) -MEM *a; +static unsigned long mem_hash(MEM *a) { unsigned long ret; @@ -115,54 +147,69 @@ MEM *a; return(ret); } +static char *(*malloc_locked_func)()=(char *(*)())malloc; +static void (*free_locked_func)()=(void (*)())free; static char *(*malloc_func)()= (char *(*)())malloc; static char *(*realloc_func)()= (char *(*)())realloc; static void (*free_func)()= (void (*)())free; -void CRYPTO_set_mem_functions(m,r,f) -char *(*m)(); -char *(*r)(); -void (*f)(); +void CRYPTO_set_mem_functions(char *(*m)(), char *(*r)(), void (*f)()) { if ((m == NULL) || (r == NULL) || (f == NULL)) return; malloc_func=m; realloc_func=r; free_func=f; + malloc_locked_func=m; + free_locked_func=f; } -void CRYPTO_get_mem_functions(m,r,f) -char *(**m)(); -char *(**r)(); -void (**f)(); +void CRYPTO_set_locked_mem_functions(char *(*m)(), void (*f)()) + { + if ((m == NULL) || (f == NULL)) return; + malloc_locked_func=m; + free_locked_func=f; + } + +void CRYPTO_get_mem_functions(char *(**m)(), char *(**r)(), void (**f)()) { if (m != NULL) *m=malloc_func; if (r != NULL) *r=realloc_func; if (f != NULL) *f=free_func; } -char *CRYPTO_malloc(num) -int num; +void CRYPTO_get_locked_mem_functions(char *(**m)(), void (**f)()) + { + if (m != NULL) *m=malloc_locked_func; + if (f != NULL) *f=free_locked_func; + } + +void *CRYPTO_malloc_locked(int num) + { + return(malloc_locked_func(num)); + } + +void CRYPTO_free_locked(void *str) + { + free_locked_func(str); + } + +void *CRYPTO_malloc(int num) { return(malloc_func(num)); } -char *CRYPTO_realloc(str,num) -char *str; -int num; +void *CRYPTO_realloc(void *str, int num) { return(realloc_func(str,num)); } -void CRYPTO_free(str) -char *str; +void CRYPTO_free(void *str) { free_func(str); } -char *CRYPTO_dbg_malloc(num,file,line) -int num; -char *file; -int line; +static unsigned long break_order_num=0; +void *CRYPTO_dbg_malloc(int num, const char *file, int line) { char *ret; MEM *m,*mm; @@ -170,11 +217,13 @@ int line; if ((ret=malloc_func(num)) == NULL) return(NULL); - if (mh_mode & CRYPTO_MEM_CHECK_ON) + if (mh_mode & CRYPTO_MEM_CHECK_ENABLE) { - if ((m=(MEM *)malloc(sizeof(MEM))) == NULL) + MemCheck_off(); + if ((m=(MEM *)Malloc(sizeof(MEM))) == NULL) { - free(ret); + Free(ret); + MemCheck_on(); return(NULL); } CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); @@ -182,9 +231,10 @@ int line; { if ((mh=lh_new(mem_hash,mem_cmp)) == NULL) { - free(ret); - free(m); - return(NULL); + Free(ret); + Free(m); + ret=NULL; + goto err; } } @@ -192,39 +242,49 @@ int line; m->file=file; m->line=line; m->num=num; +#ifdef CRYPTO_MDEBUG_THREAD + m->thread=CRYPTO_thread_id(); +#endif + if (order == break_order_num) + { + /* BREAK HERE */ + m->order=order; + } m->order=order++; +#ifdef CRYPTO_MDEBUG_TIME + m->time=time(NULL); +#endif if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL) { /* Not good, but don't sweat it */ - free(mm); + Free(mm); } +err: CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); + MemCheck_on(); } return(ret); } -void CRYPTO_dbg_free(addr) -char *addr; +void CRYPTO_dbg_free(void *addr) { MEM m,*mp; - if ((mh_mode & CRYPTO_MEM_CHECK_ON) && (mh != NULL)) + if ((mh_mode & CRYPTO_MEM_CHECK_ENABLE) && (mh != NULL)) { + MemCheck_off(); CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); m.addr=addr; mp=(MEM *)lh_delete(mh,(char *)&m); if (mp != NULL) - free(mp); + Free(mp); CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); + MemCheck_on(); } free_func(addr); } -char *CRYPTO_dbg_realloc(addr,num,file,line) -char *addr; -int num; -char *file; -int line; +void *CRYPTO_dbg_realloc(void *addr, int num, const char *file, int line) { char *ret; MEM m,*mp; @@ -232,8 +292,9 @@ int line; ret=realloc_func(addr,num); if (ret == addr) return(ret); - if (mh_mode & CRYPTO_MEM_CHECK_ON) + if (mh_mode & CRYPTO_MEM_CHECK_ENABLE) { + MemCheck_off(); if (ret == NULL) return(NULL); m.addr=addr; CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); @@ -244,24 +305,19 @@ int line; lh_insert(mh,(char *)mp); } CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); + MemCheck_on(); } return(ret); } -char *CRYPTO_remalloc(a,n) -char *a; -int n; +void *CRYPTO_remalloc(void *a, int n) { if (a != NULL) Free(a); a=(char *)Malloc(n); return(a); } -char *CRYPTO_dbg_remalloc(a,n,file,line) -char *a; -int n; -char *file; -int line; +void *CRYPTO_dbg_remalloc(void *a, int n, const char *file, int line) { if (a != NULL) CRYPTO_dbg_free(a); a=(char *)CRYPTO_dbg_malloc(n,file,line); @@ -276,21 +332,44 @@ typedef struct mem_leak_st long bytes; } MEM_LEAK; -static void print_leak(m,l) -MEM *m; -MEM_LEAK *l; +static void print_leak(MEM *m, MEM_LEAK *l) { char buf[128]; +#ifdef CRYPTO_MDEBUG_TIME + struct tm *lcl; +#endif + + if(m->addr == (char *)l->bio) + return; + +#ifdef CRYPTO_MDEBUG_TIME + lcl = localtime(&m->time); +#endif + + sprintf(buf, +#ifdef CRYPTO_MDEBUG_TIME + "[%02d:%02d:%02d] " +#endif + "%5lu file=%s, line=%d, " +#ifdef CRYPTO_MDEBUG_THREAD + "thread=%lu, " +#endif + "number=%d, address=%08lX\n", +#ifdef CRYPTO_MDEBUG_TIME + lcl->tm_hour,lcl->tm_min,lcl->tm_sec, +#endif + m->order,m->file,m->line, +#ifdef CRYPTO_MDEBUG_THREAD + m->thread, +#endif + m->num,(unsigned long)m->addr); - sprintf(buf,"%5ld file=%s, line=%d, number=%d, address=%08lX\n", - m->order,m->file,m->line,m->num,(long)m->addr); BIO_puts(l->bio,buf); l->chunks++; l->bytes+=m->num; } -void CRYPTO_mem_leaks(b) -BIO *b; +void CRYPTO_mem_leaks(BIO *b) { MEM_LEAK ml; char buf[80]; @@ -308,25 +387,23 @@ BIO *b; ml.bytes,ml.chunks); BIO_puts(b,buf); } - /* + +#if 0 lh_stats_bio(mh,b); - lh_node_stats_bio(mh,b); - lh_node_usage_stats_bio(mh,b); - */ + lh_node_stats_bio(mh,b); + lh_node_usage_stats_bio(mh,b); +#endif } static void (*mem_cb)()=NULL; -static void cb_leak(m,cb) -MEM *m; -char *cb; +static void cb_leak(MEM *m, char *cb) { void (*mem_callback)()=(void (*)())cb; mem_callback(m->order,m->file,m->line,m->num,m->addr); } -void CRYPTO_mem_leaks_cb(cb) -void (*cb)(); +void CRYPTO_mem_leaks_cb(void (*cb)()) { if (mh == NULL) return; CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); @@ -337,8 +414,7 @@ void (*cb)(); } #ifndef NO_FP_API -void CRYPTO_mem_leaks_fp(fp) -FILE *fp; +void CRYPTO_mem_leaks_fp(FILE *fp) { BIO *b; diff --git a/src/lib/libcrypto/objects/Makefile.ssl b/src/lib/libcrypto/objects/Makefile.ssl index 320523cea1..a3a15c13c1 100644 --- a/src/lib/libcrypto/objects/Makefile.ssl +++ b/src/lib/libcrypto/objects/Makefile.ssl @@ -7,23 +7,23 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=objects -ERRC=obj_err GENERAL=Makefile README TEST= APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= obj_dat.c obj_lib.c $(ERRC).c -LIBOBJ= obj_dat.o obj_lib.o $(ERRC).o +LIBSRC= o_names.c obj_dat.c obj_lib.c obj_err.c +LIBOBJ= o_names.o obj_dat.o obj_lib.o obj_err.o SRC= $(LIBSRC) @@ -38,28 +38,27 @@ top: all: obj_dat.h lib obj_dat.h: objects.h obj_dat.pl - perl ./obj_dat.pl < objects.h > obj_dat.h + $(PERL) ./obj_dat.pl < objects.h > obj_dat.h lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -71,17 +70,40 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +o_names.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +o_names.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +o_names.o: ../../include/openssl/lhash.h ../../include/openssl/objects.h +o_names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +o_names.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +obj_dat.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +obj_dat.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +obj_dat.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +obj_dat.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +obj_dat.o: ../../include/openssl/lhash.h ../../include/openssl/objects.h +obj_dat.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +obj_dat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +obj_dat.o: ../cryptlib.h obj_dat.h +obj_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +obj_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +obj_err.o: ../../include/openssl/err.h ../../include/openssl/objects.h +obj_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +obj_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +obj_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +obj_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +obj_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +obj_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +obj_lib.o: ../../include/openssl/lhash.h ../../include/openssl/objects.h +obj_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +obj_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h +obj_lib.o: ../cryptlib.h diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c new file mode 100644 index 0000000000..4da5e45b9c --- /dev/null +++ b/src/lib/libcrypto/objects/o_names.c @@ -0,0 +1,243 @@ +#include +#include +#include + +#include +#include + +/* I use the ex_data stuff to manage the identifiers for the obj_name_types + * that applications may define. I only really use the free function field. + */ +static LHASH *names_lh=NULL; +static int names_type_num=OBJ_NAME_TYPE_NUM; +static STACK *names_cmp=NULL; +static STACK *names_hash=NULL; +static STACK *names_free=NULL; + +static unsigned long obj_name_hash(OBJ_NAME *a); +static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); + +int OBJ_NAME_init(void) + { + if (names_lh != NULL) return(1); + MemCheck_off(); + names_lh=lh_new(obj_name_hash,obj_name_cmp); + MemCheck_on(); + return(names_lh != NULL); + } + +int OBJ_NAME_new_index(unsigned long (*hash_func)(), int (*cmp_func)(), + void (*free_func)()) + { + int ret; + int i; + + if (names_free == NULL) + { + MemCheck_off(); + names_hash=sk_new_null(); + names_cmp=sk_new_null(); + names_free=sk_new_null(); + MemCheck_on(); + } + if ((names_free == NULL) || (names_hash == NULL) || (names_cmp == NULL)) + { + /* ERROR */ + return(0); + } + ret=names_type_num; + names_type_num++; + for (i=sk_num(names_free); itype-b->type; + if (ret == 0) + { + if ((names_cmp != NULL) && (sk_num(names_cmp) > a->type)) + { + cmp=(int (*)())sk_value(names_cmp,a->type); + ret=cmp(a->name,b->name); + } + else + ret=strcmp(a->name,b->name); + } + return(ret); + } + +static unsigned long obj_name_hash(OBJ_NAME *a) + { + unsigned long ret; + unsigned long (*hash)(); + + if ((names_hash != NULL) && (sk_num(names_hash) > a->type)) + { + hash=(unsigned long (*)())sk_value(names_hash,a->type); + ret=hash(a->name); + } + else + { + ret=lh_strhash(a->name); + } + ret^=a->type; + return(ret); + } + +const char *OBJ_NAME_get(const char *name, int type) + { + OBJ_NAME on,*ret; + int num=0,alias; + + if (name == NULL) return(NULL); + if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL); + + alias=type&OBJ_NAME_ALIAS; + type&= ~OBJ_NAME_ALIAS; + + on.name=name; + on.type=type; + + for (;;) + { + ret=(OBJ_NAME *)lh_retrieve(names_lh,(char *)&on); + if (ret == NULL) return(NULL); + if ((ret->alias) && !alias) + { + if (++num > 10) return(NULL); + on.name=ret->data; + } + else + { + return(ret->data); + } + } + } + +int OBJ_NAME_add(const char *name, int type, const char *data) + { + void (*f)(); + OBJ_NAME *onp,*ret; + int alias; + + if ((names_lh == NULL) && !OBJ_NAME_init()) return(0); + + alias=type&OBJ_NAME_ALIAS; + type&= ~OBJ_NAME_ALIAS; + + onp=(OBJ_NAME *)Malloc(sizeof(OBJ_NAME)); + if (onp == NULL) + { + /* ERROR */ + return(0); + } + + onp->name=name; + onp->alias=alias; + onp->type=type; + onp->data=data; + + ret=(OBJ_NAME *)lh_insert(names_lh,(char *)onp); + if (ret != NULL) + { + /* free things */ + if ((names_free != NULL) && (sk_num(names_free) > ret->type)) + { + f=(void (*)())sk_value(names_free,ret->type); + f(ret->name,ret->type,ret->data); + } + Free((char *)ret); + } + else + { + if (lh_error(names_lh)) + { + /* ERROR */ + return(0); + } + } + return(1); + } + +int OBJ_NAME_remove(const char *name, int type) + { + OBJ_NAME on,*ret; + void (*f)(); + + if (names_lh == NULL) return(0); + + type&= ~OBJ_NAME_ALIAS; + on.name=name; + on.type=type; + ret=(OBJ_NAME *)lh_delete(names_lh,(char *)&on); + if (ret != NULL) + { + /* free things */ + if ((names_free != NULL) && (sk_num(names_free) > type)) + { + f=(void (*)())sk_value(names_free,type); + f(ret->name,ret->type,ret->data); + } + Free((char *)ret); + return(1); + } + else + return(0); + } + +static int free_type; + +static void names_lh_free(OBJ_NAME *onp, int type) +{ + if(onp == NULL) + return; + + if ((free_type < 0) || (free_type == onp->type)) + { + OBJ_NAME_remove(onp->name,onp->type); + } + } + +void OBJ_NAME_cleanup(int type) + { + unsigned long down_load; + + if (names_lh == NULL) return; + + free_type=type; + down_load=names_lh->down_load; + names_lh->down_load=0; + + lh_doall(names_lh,names_lh_free); + if (type < 0) + { + lh_free(names_lh); + sk_free(names_hash); + sk_free(names_cmp); + sk_free(names_free); + names_lh=NULL; + names_hash=NULL; + names_cmp=NULL; + names_free=NULL; + } + else + 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 34866ebbd2..d47b874399 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c @@ -59,23 +59,29 @@ #include #include #include "cryptlib.h" -#include "lhash.h" -#include "asn1.h" -#include "objects.h" +#include +#include +#include /* obj_dat.h is generated from objects.h by obj_dat.pl */ +#ifndef NO_OBJECT #include "obj_dat.h" +#else +/* You will have to load all the objects needed manually in the application */ +#define NUM_NID 0 +#define NUM_SN 0 +#define NUM_LN 0 +#define NUM_OBJ 0 +static unsigned char lvalues[1]; +static ASN1_OBJECT nid_objs[1]; +static ASN1_OBJECT *sn_objs[1]; +static ASN1_OBJECT *ln_objs[1]; +static ASN1_OBJECT *obj_objs[1]; +#endif -#ifndef NOPROTO static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); -#else -static int sn_cmp(); -static int ln_cmp(); -static int obj_cmp(); -#endif - #define ADDED_DATA 0 #define ADDED_SNAME 1 #define ADDED_LNAME 2 @@ -90,18 +96,13 @@ typedef struct added_obj_st static int new_nid=NUM_NID; static LHASH *added=NULL; -static int sn_cmp(ap,bp) -ASN1_OBJECT **ap; -ASN1_OBJECT **bp; +static int sn_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp) { return(strcmp((*ap)->sn,(*bp)->sn)); } -static int ln_cmp(ap,bp) -ASN1_OBJECT **ap; -ASN1_OBJECT **bp; +static int ln_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp) { return(strcmp((*ap)->ln,(*bp)->ln)); } -static unsigned long add_hash(ca) -ADDED_OBJ *ca; +static unsigned long add_hash(ADDED_OBJ *ca) { ASN1_OBJECT *a; int i; @@ -134,8 +135,7 @@ ADDED_OBJ *ca; return(ret); } -static int add_cmp(ca,cb) -ADDED_OBJ *ca,*cb; +static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb) { ASN1_OBJECT *a,*b; int i; @@ -163,36 +163,35 @@ ADDED_OBJ *ca,*cb; default: abort(); } + return(1); /* should not get here */ } -static int init_added() +static int init_added(void) { if (added != NULL) return(1); added=lh_new(add_hash,add_cmp); return(added != NULL); } -static void cleanup1(a) -ADDED_OBJ *a; +static void cleanup1(ADDED_OBJ *a) { a->obj->nid=0; a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| - ASN1_OBJECT_FLAG_DYNAMIC_STRINGS; + ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| + ASN1_OBJECT_FLAG_DYNAMIC_DATA; } -static void cleanup2(a) -ADDED_OBJ *a; +static void cleanup2(ADDED_OBJ *a) { a->obj->nid++; } -static void cleanup3(a) -ADDED_OBJ *a; +static void cleanup3(ADDED_OBJ *a) { if (--a->obj->nid == 0) ASN1_OBJECT_free(a->obj); Free(a); } -void OBJ_cleanup() +void OBJ_cleanup(void) { if (added == NULL) return; added->down_load=0; @@ -203,8 +202,7 @@ void OBJ_cleanup() added=NULL; } -int OBJ_new_nid(num) -int num; +int OBJ_new_nid(int num) { int i; @@ -213,8 +211,7 @@ int num; return(i); } -int OBJ_add_object(obj) -ASN1_OBJECT *obj; +int OBJ_add_object(ASN1_OBJECT *obj) { ASN1_OBJECT *o; ADDED_OBJ *ao[4],*aop; @@ -247,7 +244,9 @@ ASN1_OBJECT *obj; Free(aop); } } - o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS); + o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| + ASN1_OBJECT_FLAG_DYNAMIC_DATA); + return(o->nid); err: for (i=ADDED_DATA; i<=ADDED_NID; i++) @@ -256,8 +255,7 @@ err: return(NID_undef); } -ASN1_OBJECT *OBJ_nid2obj(n) -int n; +ASN1_OBJECT *OBJ_nid2obj(int n) { ADDED_OBJ ad,*adp; ASN1_OBJECT ob; @@ -289,8 +287,7 @@ int n; } } -char *OBJ_nid2sn(n) -int n; +const char *OBJ_nid2sn(int n) { ADDED_OBJ ad,*adp; ASN1_OBJECT ob; @@ -322,8 +319,7 @@ int n; } } -char *OBJ_nid2ln(n) -int n; +const char *OBJ_nid2ln(int n) { ADDED_OBJ ad,*adp; ASN1_OBJECT ob; @@ -355,8 +351,7 @@ int n; } } -int OBJ_obj2nid(a) -ASN1_OBJECT *a; +int OBJ_obj2nid(ASN1_OBJECT *a) { ASN1_OBJECT **op; ADDED_OBJ ad,*adp; @@ -380,45 +375,126 @@ ASN1_OBJECT *a; return((*op)->nid); } -int OBJ_txt2nid(s) -char *s; +/* Convert an object name into an ASN1_OBJECT + * if "noname" is not set then search for short and long names first. + * This will convert the "dotted" form into an object: unlike OBJ_txt2nid + * it can be used with any objects, not just registered ones. + */ + +ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name) { - int ret; + int nid = NID_undef; + ASN1_OBJECT *op=NULL; + unsigned char *buf,*p; + int i, j; - ret=OBJ_sn2nid(s); - if (ret == NID_undef) - { - ret=OBJ_ln2nid(s); - if (ret == NID_undef) - { - ASN1_OBJECT *op=NULL; - unsigned char *buf,*p; - int i; + if(!no_name) { + if( ((nid = OBJ_sn2nid(s)) != NID_undef) || + ((nid = OBJ_ln2nid(s)) != NID_undef) ) + return OBJ_nid2obj(nid); + } - i=a2d_ASN1_OBJECT(NULL,0,s,-1); - if (i <= 0) - { - /* clear the error */ - ERR_get_error(); - return(0); - } + /* Work out size of content octets */ + i=a2d_ASN1_OBJECT(NULL,0,s,-1); + if (i <= 0) { + /* Clear the error */ + ERR_get_error(); + return NULL; + } + /* Work out total size */ + j = ASN1_object_size(0,i,V_ASN1_OBJECT); + + if((buf=(unsigned char *)Malloc(j)) == NULL) return NULL; + + p = buf; + /* Write out tag+length */ + ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); + /* Write out contents */ + a2d_ASN1_OBJECT(p,i,s,-1); + + p=buf; + op=d2i_ASN1_OBJECT(NULL,&p,i); + Free(buf); + return op; + } + +int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name) +{ + int i,idx=0,n=0,len,nid; + unsigned long l; + unsigned char *p; + const char *s; + char tbuf[32]; + + if (buf_len <= 0) return(0); + + if ((a == NULL) || (a->data == NULL)) { + buf[0]='\0'; + return(0); + } - if ((buf=(unsigned char *)Malloc(i)) == NULL) - return(NID_undef); - a2d_ASN1_OBJECT(buf,i,s,-1); - p=buf; - op=d2i_ASN1_OBJECT(NULL,&p,i); - if (op == NULL) return(NID_undef); - ret=OBJ_obj2nid(op); - ASN1_OBJECT_free(op); - Free(buf); + nid=OBJ_obj2nid(a); + if ((nid == NID_undef) || no_name) { + len=a->length; + p=a->data; + + idx=0; + l=0; + while (idx < a->length) { + l|=(p[idx]&0x7f); + if (!(p[idx] & 0x80)) break; + l<<=7L; + idx++; + } + idx++; + i=(int)(l/40); + if (i > 2) i=2; + l-=(long)(i*40); + + sprintf(tbuf,"%d.%lu",i,l); + i=strlen(tbuf); + strncpy(buf,tbuf,buf_len); + buf_len-=i; + buf+=i; + n+=i; + + l=0; + for (; idx 0) + strncpy(buf,tbuf,buf_len); + buf_len-=i; + buf+=i; + n+=i; + l=0; } + l<<=7L; } - return(ret); + } else { + s=OBJ_nid2ln(nid); + if (s == NULL) + s=OBJ_nid2sn(nid); + strncpy(buf,s,buf_len); + n=strlen(s); } + buf[buf_len-1]='\0'; + return(n); +} -int OBJ_ln2nid(s) -char *s; +int OBJ_txt2nid(char *s) +{ + ASN1_OBJECT *obj; + int nid; + obj = OBJ_txt2obj(s, 0); + nid = OBJ_obj2nid(obj); + ASN1_OBJECT_free(obj); + return nid; +} + +int OBJ_ln2nid(const char *s) { ASN1_OBJECT o,*oo= &o,**op; ADDED_OBJ ad,*adp; @@ -437,8 +513,7 @@ char *s; return((*op)->nid); } -int OBJ_sn2nid(s) -char *s; +int OBJ_sn2nid(const char *s) { ASN1_OBJECT o,*oo= &o,**op; ADDED_OBJ ad,*adp; @@ -457,9 +532,7 @@ char *s; return((*op)->nid); } -static int obj_cmp(ap, bp) -ASN1_OBJECT **ap; -ASN1_OBJECT **bp; +static int obj_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp) { int j; ASN1_OBJECT *a= *ap; @@ -470,12 +543,7 @@ ASN1_OBJECT **bp; return(memcmp(a->data,b->data,a->length)); } -char *OBJ_bsearch(key,base,num,size,cmp) -char *key; -char *base; -int num; -int size; -int (*cmp)(); +char *OBJ_bsearch(char *key, char *base, int num, int size, int (*cmp)()) { int l,h,i,c; char *p; @@ -495,14 +563,24 @@ int (*cmp)(); else return(p); } +#ifdef CHARSET_EBCDIC +/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and + * I don't have perl (yet), we revert to a *LINEAR* search + * when the object wasn't found in the binary search. + */ + for (i=0; i obj_dat.h - */ - -#define NUM_NID 124 -#define NUM_SN 95 -#define NUM_LN 122 -#define NUM_OBJ 95 - -static unsigned char lvalues[600]={ -0x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x05, /* [ 21] OBJ_md5 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x04, /* [ 29] OBJ_rc4 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,/* [ 37] OBJ_rsaEncryption */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,/* [ 46] OBJ_md2WithRSAEncryption */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,/* [ 55] OBJ_md5WithRSAEncryption */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x01,/* [ 64] OBJ_pbeWithMD2AndDES_CBC */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x03,/* [ 73] OBJ_pbeWithMD5AndDES_CBC */ -0x55, /* [ 82] OBJ_X500 */ -0x55,0x04, /* [ 83] OBJ_X509 */ -0x55,0x04,0x03, /* [ 85] OBJ_commonName */ -0x55,0x04,0x06, /* [ 88] OBJ_countryName */ -0x55,0x04,0x07, /* [ 91] OBJ_localityName */ -0x55,0x04,0x08, /* [ 94] OBJ_stateOrProvinceName */ -0x55,0x04,0x0A, /* [ 97] OBJ_organizationName */ -0x55,0x04,0x0B, /* [100] OBJ_organizationalUnitName */ -0x55,0x08,0x01,0x01, /* [103] OBJ_rsa */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07, /* [107] OBJ_pkcs7 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x01,/* [115] OBJ_pkcs7_data */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,/* [124] OBJ_pkcs7_signed */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x03,/* [133] OBJ_pkcs7_enveloped */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x04,/* [142] OBJ_pkcs7_signedAndEnveloped */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x05,/* [151] OBJ_pkcs7_digest */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x06,/* [160] OBJ_pkcs7_encrypted */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03, /* [169] OBJ_pkcs3 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03,0x01,/* [177] OBJ_dhKeyAgreement */ -0x2B,0x0E,0x03,0x02,0x06, /* [186] OBJ_des_ecb */ -0x2B,0x0E,0x03,0x02,0x09, /* [191] OBJ_des_cfb64 */ -0x2B,0x0E,0x03,0x02,0x07, /* [196] OBJ_des_cbc */ -0x2B,0x0E,0x03,0x02,0x11, /* [201] OBJ_des_ede */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x02, /* [206] OBJ_rc2_cbc */ -0x2B,0x0E,0x03,0x02,0x12, /* [214] OBJ_sha */ -0x2B,0x0E,0x03,0x02,0x0F, /* [219] OBJ_shaWithRSAEncryption */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x07, /* [224] OBJ_des_ede3_cbc */ -0x2B,0x0E,0x03,0x02,0x08, /* [232] OBJ_des_ofb64 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09, /* [237] OBJ_pkcs9 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x01,/* [245] OBJ_pkcs9_emailAddress */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x02,/* [254] OBJ_pkcs9_unstructuredName */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,/* [263] OBJ_pkcs9_contentType */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x04,/* [272] OBJ_pkcs9_messageDigest */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x05,/* [281] OBJ_pkcs9_signingTime */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x06,/* [290] OBJ_pkcs9_countersignature */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x07,/* [299] OBJ_pkcs9_challengePassword */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x08,/* [308] OBJ_pkcs9_unstructuredAddress */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x09,/* [317] OBJ_pkcs9_extCertAttributes */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42, /* [326] OBJ_netscape */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01, /* [333] OBJ_netscape_cert_extension */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02, /* [341] OBJ_netscape_data_type */ -0x2B,0x0E,0x03,0x02,0x1A, /* [349] OBJ_sha1 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,/* [354] OBJ_sha1WithRSAEncryption */ -0x2B,0x0E,0x03,0x02,0x0D, /* [363] OBJ_dsaWithSHA */ -0x2B,0x0E,0x03,0x02,0x0C, /* [368] OBJ_dsa_2 */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0B,/* [373] OBJ_pbeWithSHA1AndRC2_CBC */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0C,/* [382] OBJ_pbeWithSHA1AndRC4 */ -0x2B,0x0E,0x03,0x02,0x1B, /* [391] OBJ_dsaWithSHA1_2 */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x01,/* [396] OBJ_netscape_cert_type */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x02,/* [405] OBJ_netscape_base_url */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x03,/* [414] OBJ_netscape_revocation_url */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x04,/* [423] OBJ_netscape_ca_revocation_url */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x07,/* [432] OBJ_netscape_renewal_url */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x08,/* [441] OBJ_netscape_ca_policy_url */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0C,/* [450] OBJ_netscape_ssl_server_name */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0D,/* [459] OBJ_netscape_comment */ -0x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02,0x05,/* [468] OBJ_netscape_cert_sequence */ -0x55,0x1D, /* [477] OBJ_ld_ce */ -0x55,0x1D,0x0E, /* [479] OBJ_subject_key_identifier */ -0x55,0x1D,0x0F, /* [482] OBJ_key_usage */ -0x55,0x1D,0x10, /* [485] OBJ_private_key_usage_period */ -0x55,0x1D,0x11, /* [488] OBJ_subject_alt_name */ -0x55,0x1D,0x12, /* [491] OBJ_issuer_alt_name */ -0x55,0x1D,0x13, /* [494] OBJ_basic_constraints */ -0x55,0x1D,0x14, /* [497] OBJ_crl_number */ -0x55,0x1D,0x20, /* [500] OBJ_certificate_policies */ -0x55,0x1D,0x23, /* [503] OBJ_authority_key_identifier */ -0x55,0x08,0x03,0x65, /* [506] OBJ_mdc2 */ -0x55,0x08,0x03,0x64, /* [510] OBJ_mdc2WithRSA */ -0x55,0x04,0x2A, /* [514] OBJ_givenName */ -0x55,0x04,0x04, /* [517] OBJ_surname */ -0x55,0x04,0x2B, /* [520] OBJ_initials */ -0x55,0x04,0x2D, /* [523] OBJ_uniqueIdentifier */ -0x55,0x1D,0x1F, /* [526] OBJ_crl_distribution_points */ -0x2B,0x0E,0x03,0x02,0x03, /* [529] OBJ_md5WithRSA */ -0x55,0x04,0x05, /* [534] OBJ_serialNumber */ -0x55,0x04,0x0C, /* [537] OBJ_title */ -0x55,0x04,0x0D, /* [540] OBJ_description */ -0x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0A,/* [543] OBJ_cast5_cbc */ -0x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0C,/* [552] OBJ_pbeWithMD5AndCast5_CBC */ -0x2A,0x86,0x48,0xCE,0x38,0x04,0x03, /* [561] OBJ_dsaWithSHA1 */ -0x2B,0x0E,0x03,0x02,0x1D, /* [568] OBJ_sha1WithRSA */ -0x2A,0x86,0x48,0xCE,0x38,0x04,0x01, /* [573] OBJ_dsa */ -0x2B,0x24,0x03,0x02,0x01, /* [580] OBJ_ripemd160 */ -0x2B,0x24,0x03,0x03,0x01,0x02, /* [585] OBJ_ripemd160WithRSA */ -0x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x08, /* [591] OBJ_rc5_cbc */ -}; - -static ASN1_OBJECT nid_objs[NUM_NID]={ -{"UNDEF","undefined",NID_undef,0,NULL}, -{"rsadsi","rsadsi",NID_rsadsi,6,&(lvalues[0]),0}, -{"pkcs","pkcs",NID_pkcs,7,&(lvalues[6]),0}, -{"MD2","md2",NID_md2,8,&(lvalues[13]),0}, -{"MD5","md5",NID_md5,8,&(lvalues[21]),0}, -{"RC4","rc4",NID_rc4,8,&(lvalues[29]),0}, -{"rsaEncryption","rsaEncryption",NID_rsaEncryption,9,&(lvalues[37]),0}, -{"RSA-MD2","md2WithRSAEncryption",NID_md2WithRSAEncryption,9, - &(lvalues[46]),0}, -{"RSA-MD5","md5WithRSAEncryption",NID_md5WithRSAEncryption,9, - &(lvalues[55]),0}, -{"pbeWithMD2AndDES-CBC","pbeWithMD2AndDES-CBC", - NID_pbeWithMD2AndDES_CBC,9,&(lvalues[64]),0}, -{"pbeWithMD5AndDES-CBC","pbeWithMD5AndDES-CBC", - NID_pbeWithMD5AndDES_CBC,9,&(lvalues[73]),0}, -{"X500","X500",NID_X500,1,&(lvalues[82]),0}, -{"X509","X509",NID_X509,2,&(lvalues[83]),0}, -{"CN","commonName",NID_commonName,3,&(lvalues[85]),0}, -{"C","countryName",NID_countryName,3,&(lvalues[88]),0}, -{"L","localityName",NID_localityName,3,&(lvalues[91]),0}, -{"ST","stateOrProvinceName",NID_stateOrProvinceName,3,&(lvalues[94]),0}, -{"O","organizationName",NID_organizationName,3,&(lvalues[97]),0}, -{"OU","organizationalUnitName",NID_organizationalUnitName,3, - &(lvalues[100]),0}, -{"RSA","rsa",NID_rsa,4,&(lvalues[103]),0}, -{"pkcs7","pkcs7",NID_pkcs7,8,&(lvalues[107]),0}, -{"pkcs7-data","pkcs7-data",NID_pkcs7_data,9,&(lvalues[115]),0}, -{"pkcs7-signedData","pkcs7-signedData",NID_pkcs7_signed,9, - &(lvalues[124]),0}, -{"pkcs7-envelopedData","pkcs7-envelopedData",NID_pkcs7_enveloped,9, - &(lvalues[133]),0}, -{"pkcs7-signedAndEnvelopedData","pkcs7-signedAndEnvelopedData", - NID_pkcs7_signedAndEnveloped,9,&(lvalues[142]),0}, -{"pkcs7-digestData","pkcs7-digestData",NID_pkcs7_digest,9, - &(lvalues[151]),0}, -{"pkcs7-encryptedData","pkcs7-encryptedData",NID_pkcs7_encrypted,9, - &(lvalues[160]),0}, -{"pkcs3","pkcs3",NID_pkcs3,8,&(lvalues[169]),0}, -{"dhKeyAgreement","dhKeyAgreement",NID_dhKeyAgreement,9, - &(lvalues[177]),0}, -{"DES-ECB","des-ecb",NID_des_ecb,5,&(lvalues[186]),0}, -{"DES-CFB","des-cfb",NID_des_cfb64,5,&(lvalues[191]),0}, -{"DES-CBC","des-cbc",NID_des_cbc,5,&(lvalues[196]),0}, -{"DES-EDE","des-ede",NID_des_ede,5,&(lvalues[201]),0}, -{"DES-EDE3","des-ede3",NID_des_ede3,0,NULL}, -{"IDEA-CBC","idea-cbc",NID_idea_cbc,0,NULL}, -{"IDEA-CFB","idea-cfb",NID_idea_cfb64,0,NULL}, -{"IDEA-ECB","idea-ecb",NID_idea_ecb,0,NULL}, -{"RC2-CBC","rc2-cbc",NID_rc2_cbc,8,&(lvalues[206]),0}, -{"RC2-ECB","rc2-ecb",NID_rc2_ecb,0,NULL}, -{"RC2-CFB","rc2-cfb",NID_rc2_cfb64,0,NULL}, -{"RC2-OFB","rc2-ofb",NID_rc2_ofb64,0,NULL}, -{"SHA","sha",NID_sha,5,&(lvalues[214]),0}, -{"RSA-SHA","shaWithRSAEncryption",NID_shaWithRSAEncryption,5, - &(lvalues[219]),0}, -{"DES-EDE-CBC","des-ede-cbc",NID_des_ede_cbc,0,NULL}, -{"DES-EDE3-CBC","des-ede3-cbc",NID_des_ede3_cbc,8,&(lvalues[224]),0}, -{"DES-OFB","des-ofb",NID_des_ofb64,5,&(lvalues[232]),0}, -{"IDEA-OFB","idea-ofb",NID_idea_ofb64,0,NULL}, -{"pkcs9","pkcs9",NID_pkcs9,8,&(lvalues[237]),0}, -{"Email","emailAddress",NID_pkcs9_emailAddress,9,&(lvalues[245]),0}, -{"unstructuredName","unstructuredName",NID_pkcs9_unstructuredName,9, - &(lvalues[254]),0}, -{"contentType","contentType",NID_pkcs9_contentType,9,&(lvalues[263]),0}, -{"messageDigest","messageDigest",NID_pkcs9_messageDigest,9, - &(lvalues[272]),0}, -{"signingTime","signingTime",NID_pkcs9_signingTime,9,&(lvalues[281]),0}, -{"countersignature","countersignature",NID_pkcs9_countersignature,9, - &(lvalues[290]),0}, -{"challengePassword","challengePassword",NID_pkcs9_challengePassword, - 9,&(lvalues[299]),0}, -{"unstructuredAddress","unstructuredAddress", - NID_pkcs9_unstructuredAddress,9,&(lvalues[308]),0}, -{"extendedCertificateAttributes","extendedCertificateAttributes", - NID_pkcs9_extCertAttributes,9,&(lvalues[317]),0}, -{"Netscape","Netscape Communications Corp.",NID_netscape,7, - &(lvalues[326]),0}, -{"nsCertExt","Netscape Certificate Extension", - NID_netscape_cert_extension,8,&(lvalues[333]),0}, -{"nsDataType","Netscape Data Type",NID_netscape_data_type,8, - &(lvalues[341]),0}, -{"DES-EDE-CFB","des-ede-cfb",NID_des_ede_cfb64,0,NULL}, -{"DES-EDE3-CFB","des-ede3-cfb",NID_des_ede3_cfb64,0,NULL}, -{"DES-EDE-OFB","des-ede-ofb",NID_des_ede_ofb64,0,NULL}, -{"DES-EDE3-OFB","des-ede3-ofb",NID_des_ede3_ofb64,0,NULL}, -{"SHA1","sha1",NID_sha1,5,&(lvalues[349]),0}, -{"RSA-SHA1","sha1WithRSAEncryption",NID_sha1WithRSAEncryption,9, - &(lvalues[354]),0}, -{"DSA-SHA","dsaWithSHA",NID_dsaWithSHA,5,&(lvalues[363]),0}, -{"DSA-old","dsaEncryption-old",NID_dsa_2,5,&(lvalues[368]),0}, -{"pbeWithSHA1AndRC2-CBC","pbeWithSHA1AndRC2-CBC", - NID_pbeWithSHA1AndRC2_CBC,9,&(lvalues[373]),0}, -{"pbeWithSHA1AndRC4","pbeWithSHA1AndRC4",NID_pbeWithSHA1AndRC4,9, - &(lvalues[382]),0}, -{"DSA-SHA1-old","dsaWithSHA1",NID_dsaWithSHA1_2,5,&(lvalues[391]),0}, -{"nsCertType","Netscape Cert Type",NID_netscape_cert_type,9, - &(lvalues[396]),0}, -{"nsBaseUrl","Netscape Base Url",NID_netscape_base_url,9, - &(lvalues[405]),0}, -{"nsRevocationUrl","Netscape Revocation Url", - NID_netscape_revocation_url,9,&(lvalues[414]),0}, -{"nsCaRevocationUrl","Netscape CA Revocation Url", - NID_netscape_ca_revocation_url,9,&(lvalues[423]),0}, -{"nsRenewalUrl","Netscape Renewal Url",NID_netscape_renewal_url,9, - &(lvalues[432]),0}, -{"nsCaPolicyUrl","Netscape CA Policy Url",NID_netscape_ca_policy_url, - 9,&(lvalues[441]),0}, -{"nsSslServerName","Netscape SSL Server Name", - NID_netscape_ssl_server_name,9,&(lvalues[450]),0}, -{"nsComment","Netscape Comment",NID_netscape_comment,9,&(lvalues[459]),0}, -{"nsCertSequence","Netscape Certificate Sequence", - NID_netscape_cert_sequence,9,&(lvalues[468]),0}, -{"DESX-CBC","desx-cbc",NID_desx_cbc,0,NULL}, -{"ld-ce","ld-ce",NID_ld_ce,2,&(lvalues[477]),0}, -{"subjectKeyIdentifier","X509v3 Subject Key Identifier", - NID_subject_key_identifier,3,&(lvalues[479]),0}, -{"keyUsage","X509v3 Key Usage",NID_key_usage,3,&(lvalues[482]),0}, -{"privateKeyUsagePeriod","X509v3 Private Key Usage Period", - NID_private_key_usage_period,3,&(lvalues[485]),0}, -{"subjectAltName","X509v3 Subject Alternative Name", - NID_subject_alt_name,3,&(lvalues[488]),0}, -{"issuerAltName","X509v3 Issuer Alternative Name",NID_issuer_alt_name, - 3,&(lvalues[491]),0}, -{"basicConstraints","X509v3 Basic Constraints",NID_basic_constraints, - 3,&(lvalues[494]),0}, -{"crlNumber","X509v3 CRL Number",NID_crl_number,3,&(lvalues[497]),0}, -{"certificatePolicies","X509v3 Certificate Policies", - NID_certificate_policies,3,&(lvalues[500]),0}, -{"authorityKeyIdentifier","X509v3 Authority Key Identifier", - NID_authority_key_identifier,3,&(lvalues[503]),0}, -{"BF-CBC","bf-cbc",NID_bf_cbc,0,NULL}, -{"BF-ECB","bf-ecb",NID_bf_ecb,0,NULL}, -{"BF-CFB","bf-cfb",NID_bf_cfb64,0,NULL}, -{"BF-OFB","bf-ofb",NID_bf_ofb64,0,NULL}, -{"MDC2","mdc2",NID_mdc2,4,&(lvalues[506]),0}, -{"RSA-MDC2","mdc2withRSA",NID_mdc2WithRSA,4,&(lvalues[510]),0}, -{"RC4-40","rc4-40",NID_rc4_40,0,NULL}, -{"RC2-40-CBC","rc2-40-cbc",NID_rc2_40_cbc,0,NULL}, -{"G","givenName",NID_givenName,3,&(lvalues[514]),0}, -{"S","surname",NID_surname,3,&(lvalues[517]),0}, -{"I","initials",NID_initials,3,&(lvalues[520]),0}, -{"UID","uniqueIdentifier",NID_uniqueIdentifier,3,&(lvalues[523]),0}, -{"crlDistributionPoints","X509v3 CRL Distribution Points", - NID_crl_distribution_points,3,&(lvalues[526]),0}, -{"RSA-NP-MD5","md5WithRSA",NID_md5WithRSA,5,&(lvalues[529]),0}, -{"SN","serialNumber",NID_serialNumber,3,&(lvalues[534]),0}, -{"T","title",NID_title,3,&(lvalues[537]),0}, -{"D","description",NID_description,3,&(lvalues[540]),0}, -{"CAST5-CBC","cast5-cbc",NID_cast5_cbc,9,&(lvalues[543]),0}, -{"CAST5-ECB","cast5-ecb",NID_cast5_ecb,0,NULL}, -{"CAST5-CFB","cast5-cfb",NID_cast5_cfb64,0,NULL}, -{"CAST5-OFB","cast5-ofb",NID_cast5_ofb64,0,NULL}, -{"pbeWithMD5AndCast5CBC","pbeWithMD5AndCast5CBC", - NID_pbeWithMD5AndCast5_CBC,9,&(lvalues[552]),0}, -{"DSA-SHA1","dsaWithSHA1",NID_dsaWithSHA1,7,&(lvalues[561]),0}, -{"MD5-SHA1","md5-sha1",NID_md5_sha1,0,NULL}, -{"RSA-SHA1-2","sha1WithRSA",NID_sha1WithRSA,5,&(lvalues[568]),0}, -{"DSA","dsaEncryption",NID_dsa,7,&(lvalues[573]),0}, -{"RIPEMD160","ripemd160",NID_ripemd160,5,&(lvalues[580]),0}, -{NULL,NULL,NID_undef,0,NULL}, -{"RSA-RIPEMD160","ripemd160WithRSA",NID_ripemd160WithRSA,6, - &(lvalues[585]),0}, -{"RC5-CBC","rc5-cbc",NID_rc5_cbc,8,&(lvalues[591]),0}, -{"RC5-ECB","rc5-ecb",NID_rc5_ecb,0,NULL}, -{"RC5-CFB","rc5-cfb",NID_rc5_cfb64,0,NULL}, -{"RC5-OFB","rc5-ofb",NID_rc5_ofb64,0,NULL}, -}; - -static ASN1_OBJECT *sn_objs[NUM_SN]={ -&(nid_objs[91]),/* "BF-CBC" */ -&(nid_objs[93]),/* "BF-CFB" */ -&(nid_objs[92]),/* "BF-ECB" */ -&(nid_objs[94]),/* "BF-OFB" */ -&(nid_objs[14]),/* "C" */ -&(nid_objs[108]),/* "CAST5-CBC" */ -&(nid_objs[110]),/* "CAST5-CFB" */ -&(nid_objs[109]),/* "CAST5-ECB" */ -&(nid_objs[111]),/* "CAST5-OFB" */ -&(nid_objs[13]),/* "CN" */ -&(nid_objs[107]),/* "D" */ -&(nid_objs[31]),/* "DES-CBC" */ -&(nid_objs[30]),/* "DES-CFB" */ -&(nid_objs[29]),/* "DES-ECB" */ -&(nid_objs[32]),/* "DES-EDE" */ -&(nid_objs[43]),/* "DES-EDE-CBC" */ -&(nid_objs[60]),/* "DES-EDE-CFB" */ -&(nid_objs[62]),/* "DES-EDE-OFB" */ -&(nid_objs[33]),/* "DES-EDE3" */ -&(nid_objs[44]),/* "DES-EDE3-CBC" */ -&(nid_objs[61]),/* "DES-EDE3-CFB" */ -&(nid_objs[63]),/* "DES-EDE3-OFB" */ -&(nid_objs[45]),/* "DES-OFB" */ -&(nid_objs[80]),/* "DESX-CBC" */ -&(nid_objs[116]),/* "DSA" */ -&(nid_objs[66]),/* "DSA-SHA" */ -&(nid_objs[113]),/* "DSA-SHA1" */ -&(nid_objs[70]),/* "DSA-SHA1-old" */ -&(nid_objs[67]),/* "DSA-old" */ -&(nid_objs[48]),/* "Email" */ -&(nid_objs[99]),/* "G" */ -&(nid_objs[101]),/* "I" */ -&(nid_objs[34]),/* "IDEA-CBC" */ -&(nid_objs[35]),/* "IDEA-CFB" */ -&(nid_objs[36]),/* "IDEA-ECB" */ -&(nid_objs[46]),/* "IDEA-OFB" */ -&(nid_objs[15]),/* "L" */ -&(nid_objs[ 3]),/* "MD2" */ -&(nid_objs[ 4]),/* "MD5" */ -&(nid_objs[114]),/* "MD5-SHA1" */ -&(nid_objs[95]),/* "MDC2" */ -&(nid_objs[57]),/* "Netscape" */ -&(nid_objs[17]),/* "O" */ -&(nid_objs[18]),/* "OU" */ -&(nid_objs[98]),/* "RC2-40-CBC" */ -&(nid_objs[37]),/* "RC2-CBC" */ -&(nid_objs[39]),/* "RC2-CFB" */ -&(nid_objs[38]),/* "RC2-ECB" */ -&(nid_objs[40]),/* "RC2-OFB" */ -&(nid_objs[ 5]),/* "RC4" */ -&(nid_objs[97]),/* "RC4-40" */ -&(nid_objs[120]),/* "RC5-CBC" */ -&(nid_objs[122]),/* "RC5-CFB" */ -&(nid_objs[121]),/* "RC5-ECB" */ -&(nid_objs[123]),/* "RC5-OFB" */ -&(nid_objs[117]),/* "RIPEMD160" */ -&(nid_objs[19]),/* "RSA" */ -&(nid_objs[ 7]),/* "RSA-MD2" */ -&(nid_objs[ 8]),/* "RSA-MD5" */ -&(nid_objs[96]),/* "RSA-MDC2" */ -&(nid_objs[104]),/* "RSA-NP-MD5" */ -&(nid_objs[119]),/* "RSA-RIPEMD160" */ -&(nid_objs[42]),/* "RSA-SHA" */ -&(nid_objs[65]),/* "RSA-SHA1" */ -&(nid_objs[115]),/* "RSA-SHA1-2" */ -&(nid_objs[100]),/* "S" */ -&(nid_objs[41]),/* "SHA" */ -&(nid_objs[64]),/* "SHA1" */ -&(nid_objs[105]),/* "SN" */ -&(nid_objs[16]),/* "ST" */ -&(nid_objs[106]),/* "T" */ -&(nid_objs[102]),/* "UID" */ -&(nid_objs[ 0]),/* "UNDEF" */ -&(nid_objs[90]),/* "authorityKeyIdentifier" */ -&(nid_objs[87]),/* "basicConstraints" */ -&(nid_objs[89]),/* "certificatePolicies" */ -&(nid_objs[103]),/* "crlDistributionPoints" */ -&(nid_objs[88]),/* "crlNumber" */ -&(nid_objs[86]),/* "issuerAltName" */ -&(nid_objs[83]),/* "keyUsage" */ -&(nid_objs[81]),/* "ld-ce" */ -&(nid_objs[72]),/* "nsBaseUrl" */ -&(nid_objs[76]),/* "nsCaPolicyUrl" */ -&(nid_objs[74]),/* "nsCaRevocationUrl" */ -&(nid_objs[58]),/* "nsCertExt" */ -&(nid_objs[79]),/* "nsCertSequence" */ -&(nid_objs[71]),/* "nsCertType" */ -&(nid_objs[78]),/* "nsComment" */ -&(nid_objs[59]),/* "nsDataType" */ -&(nid_objs[75]),/* "nsRenewalUrl" */ -&(nid_objs[73]),/* "nsRevocationUrl" */ -&(nid_objs[77]),/* "nsSslServerName" */ -&(nid_objs[84]),/* "privateKeyUsagePeriod" */ -&(nid_objs[85]),/* "subjectAltName" */ -&(nid_objs[82]),/* "subjectKeyIdentifier" */ -}; - -static ASN1_OBJECT *ln_objs[NUM_LN]={ -&(nid_objs[72]),/* "Netscape Base Url" */ -&(nid_objs[76]),/* "Netscape CA Policy Url" */ -&(nid_objs[74]),/* "Netscape CA Revocation Url" */ -&(nid_objs[71]),/* "Netscape Cert Type" */ -&(nid_objs[58]),/* "Netscape Certificate Extension" */ -&(nid_objs[79]),/* "Netscape Certificate Sequence" */ -&(nid_objs[78]),/* "Netscape Comment" */ -&(nid_objs[57]),/* "Netscape Communications Corp." */ -&(nid_objs[59]),/* "Netscape Data Type" */ -&(nid_objs[75]),/* "Netscape Renewal Url" */ -&(nid_objs[73]),/* "Netscape Revocation Url" */ -&(nid_objs[77]),/* "Netscape SSL Server Name" */ -&(nid_objs[11]),/* "X500" */ -&(nid_objs[12]),/* "X509" */ -&(nid_objs[90]),/* "X509v3 Authority Key Identifier" */ -&(nid_objs[87]),/* "X509v3 Basic Constraints" */ -&(nid_objs[103]),/* "X509v3 CRL Distribution Points" */ -&(nid_objs[88]),/* "X509v3 CRL Number" */ -&(nid_objs[89]),/* "X509v3 Certificate Policies" */ -&(nid_objs[86]),/* "X509v3 Issuer Alternative Name" */ -&(nid_objs[83]),/* "X509v3 Key Usage" */ -&(nid_objs[84]),/* "X509v3 Private Key Usage Period" */ -&(nid_objs[85]),/* "X509v3 Subject Alternative Name" */ -&(nid_objs[82]),/* "X509v3 Subject Key Identifier" */ -&(nid_objs[91]),/* "bf-cbc" */ -&(nid_objs[93]),/* "bf-cfb" */ -&(nid_objs[92]),/* "bf-ecb" */ -&(nid_objs[94]),/* "bf-ofb" */ -&(nid_objs[108]),/* "cast5-cbc" */ -&(nid_objs[110]),/* "cast5-cfb" */ -&(nid_objs[109]),/* "cast5-ecb" */ -&(nid_objs[111]),/* "cast5-ofb" */ -&(nid_objs[54]),/* "challengePassword" */ -&(nid_objs[13]),/* "commonName" */ -&(nid_objs[50]),/* "contentType" */ -&(nid_objs[53]),/* "countersignature" */ -&(nid_objs[14]),/* "countryName" */ -&(nid_objs[31]),/* "des-cbc" */ -&(nid_objs[30]),/* "des-cfb" */ -&(nid_objs[29]),/* "des-ecb" */ -&(nid_objs[32]),/* "des-ede" */ -&(nid_objs[43]),/* "des-ede-cbc" */ -&(nid_objs[60]),/* "des-ede-cfb" */ -&(nid_objs[62]),/* "des-ede-ofb" */ -&(nid_objs[33]),/* "des-ede3" */ -&(nid_objs[44]),/* "des-ede3-cbc" */ -&(nid_objs[61]),/* "des-ede3-cfb" */ -&(nid_objs[63]),/* "des-ede3-ofb" */ -&(nid_objs[45]),/* "des-ofb" */ -&(nid_objs[107]),/* "description" */ -&(nid_objs[80]),/* "desx-cbc" */ -&(nid_objs[28]),/* "dhKeyAgreement" */ -&(nid_objs[116]),/* "dsaEncryption" */ -&(nid_objs[67]),/* "dsaEncryption-old" */ -&(nid_objs[66]),/* "dsaWithSHA" */ -&(nid_objs[113]),/* "dsaWithSHA1" */ -&(nid_objs[70]),/* "dsaWithSHA1" */ -&(nid_objs[48]),/* "emailAddress" */ -&(nid_objs[56]),/* "extendedCertificateAttributes" */ -&(nid_objs[99]),/* "givenName" */ -&(nid_objs[34]),/* "idea-cbc" */ -&(nid_objs[35]),/* "idea-cfb" */ -&(nid_objs[36]),/* "idea-ecb" */ -&(nid_objs[46]),/* "idea-ofb" */ -&(nid_objs[101]),/* "initials" */ -&(nid_objs[15]),/* "localityName" */ -&(nid_objs[ 3]),/* "md2" */ -&(nid_objs[ 7]),/* "md2WithRSAEncryption" */ -&(nid_objs[ 4]),/* "md5" */ -&(nid_objs[114]),/* "md5-sha1" */ -&(nid_objs[104]),/* "md5WithRSA" */ -&(nid_objs[ 8]),/* "md5WithRSAEncryption" */ -&(nid_objs[95]),/* "mdc2" */ -&(nid_objs[96]),/* "mdc2withRSA" */ -&(nid_objs[51]),/* "messageDigest" */ -&(nid_objs[17]),/* "organizationName" */ -&(nid_objs[18]),/* "organizationalUnitName" */ -&(nid_objs[ 9]),/* "pbeWithMD2AndDES-CBC" */ -&(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */ -&(nid_objs[10]),/* "pbeWithMD5AndDES-CBC" */ -&(nid_objs[68]),/* "pbeWithSHA1AndRC2-CBC" */ -&(nid_objs[69]),/* "pbeWithSHA1AndRC4" */ -&(nid_objs[ 2]),/* "pkcs" */ -&(nid_objs[27]),/* "pkcs3" */ -&(nid_objs[20]),/* "pkcs7" */ -&(nid_objs[21]),/* "pkcs7-data" */ -&(nid_objs[25]),/* "pkcs7-digestData" */ -&(nid_objs[26]),/* "pkcs7-encryptedData" */ -&(nid_objs[23]),/* "pkcs7-envelopedData" */ -&(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */ -&(nid_objs[22]),/* "pkcs7-signedData" */ -&(nid_objs[47]),/* "pkcs9" */ -&(nid_objs[98]),/* "rc2-40-cbc" */ -&(nid_objs[37]),/* "rc2-cbc" */ -&(nid_objs[39]),/* "rc2-cfb" */ -&(nid_objs[38]),/* "rc2-ecb" */ -&(nid_objs[40]),/* "rc2-ofb" */ -&(nid_objs[ 5]),/* "rc4" */ -&(nid_objs[97]),/* "rc4-40" */ -&(nid_objs[120]),/* "rc5-cbc" */ -&(nid_objs[122]),/* "rc5-cfb" */ -&(nid_objs[121]),/* "rc5-ecb" */ -&(nid_objs[123]),/* "rc5-ofb" */ -&(nid_objs[117]),/* "ripemd160" */ -&(nid_objs[119]),/* "ripemd160WithRSA" */ -&(nid_objs[19]),/* "rsa" */ -&(nid_objs[ 6]),/* "rsaEncryption" */ -&(nid_objs[ 1]),/* "rsadsi" */ -&(nid_objs[105]),/* "serialNumber" */ -&(nid_objs[41]),/* "sha" */ -&(nid_objs[64]),/* "sha1" */ -&(nid_objs[115]),/* "sha1WithRSA" */ -&(nid_objs[65]),/* "sha1WithRSAEncryption" */ -&(nid_objs[42]),/* "shaWithRSAEncryption" */ -&(nid_objs[52]),/* "signingTime" */ -&(nid_objs[16]),/* "stateOrProvinceName" */ -&(nid_objs[100]),/* "surname" */ -&(nid_objs[106]),/* "title" */ -&(nid_objs[ 0]),/* "undefined" */ -&(nid_objs[102]),/* "uniqueIdentifier" */ -&(nid_objs[55]),/* "unstructuredAddress" */ -&(nid_objs[49]),/* "unstructuredName" */ -}; - -static ASN1_OBJECT *obj_objs[NUM_OBJ]={ -&(nid_objs[11]),/* OBJ_X500 2 5 */ -&(nid_objs[12]),/* OBJ_X509 2 5 4 */ -&(nid_objs[81]),/* OBJ_ld_ce 2 5 29 */ -&(nid_objs[13]),/* OBJ_commonName 2 5 4 3 */ -&(nid_objs[100]),/* OBJ_surname 2 5 4 4 */ -&(nid_objs[105]),/* OBJ_serialNumber 2 5 4 5 */ -&(nid_objs[14]),/* OBJ_countryName 2 5 4 6 */ -&(nid_objs[15]),/* OBJ_localityName 2 5 4 7 */ -&(nid_objs[16]),/* OBJ_stateOrProvinceName 2 5 4 8 */ -&(nid_objs[17]),/* OBJ_organizationName 2 5 4 10 */ -&(nid_objs[18]),/* OBJ_organizationalUnitName 2 5 4 11 */ -&(nid_objs[106]),/* OBJ_title 2 5 4 12 */ -&(nid_objs[107]),/* OBJ_description 2 5 4 13 */ -&(nid_objs[99]),/* OBJ_givenName 2 5 4 42 */ -&(nid_objs[101]),/* OBJ_initials 2 5 4 43 */ -&(nid_objs[102]),/* OBJ_uniqueIdentifier 2 5 4 45 */ -&(nid_objs[82]),/* OBJ_subject_key_identifier 2 5 29 14 */ -&(nid_objs[83]),/* OBJ_key_usage 2 5 29 15 */ -&(nid_objs[84]),/* OBJ_private_key_usage_period 2 5 29 16 */ -&(nid_objs[85]),/* OBJ_subject_alt_name 2 5 29 17 */ -&(nid_objs[86]),/* OBJ_issuer_alt_name 2 5 29 18 */ -&(nid_objs[87]),/* OBJ_basic_constraints 2 5 29 19 */ -&(nid_objs[88]),/* OBJ_crl_number 2 5 29 20 */ -&(nid_objs[103]),/* OBJ_crl_distribution_points 2 5 29 31 */ -&(nid_objs[89]),/* OBJ_certificate_policies 2 5 29 32 */ -&(nid_objs[90]),/* OBJ_authority_key_identifier 2 5 29 35 */ -&(nid_objs[19]),/* OBJ_rsa 2 5 8 1 1 */ -&(nid_objs[96]),/* OBJ_mdc2WithRSA 2 5 8 3 100 */ -&(nid_objs[95]),/* OBJ_mdc2 2 5 8 3 101 */ -&(nid_objs[104]),/* OBJ_md5WithRSA 1 3 14 3 2 3 */ -&(nid_objs[29]),/* OBJ_des_ecb 1 3 14 3 2 6 */ -&(nid_objs[31]),/* OBJ_des_cbc 1 3 14 3 2 7 */ -&(nid_objs[45]),/* OBJ_des_ofb64 1 3 14 3 2 8 */ -&(nid_objs[30]),/* OBJ_des_cfb64 1 3 14 3 2 9 */ -&(nid_objs[67]),/* OBJ_dsa_2 1 3 14 3 2 12 */ -&(nid_objs[66]),/* OBJ_dsaWithSHA 1 3 14 3 2 13 */ -&(nid_objs[42]),/* OBJ_shaWithRSAEncryption 1 3 14 3 2 15 */ -&(nid_objs[32]),/* OBJ_des_ede 1 3 14 3 2 17 */ -&(nid_objs[41]),/* OBJ_sha 1 3 14 3 2 18 */ -&(nid_objs[64]),/* OBJ_sha1 1 3 14 3 2 26 */ -&(nid_objs[70]),/* OBJ_dsaWithSHA1_2 1 3 14 3 2 27 */ -&(nid_objs[115]),/* OBJ_sha1WithRSA 1 3 14 3 2 29 */ -&(nid_objs[117]),/* OBJ_ripemd160 1 3 36 3 2 1 */ -&(nid_objs[ 1]),/* OBJ_rsadsi 1 2 840 113549 */ -&(nid_objs[119]),/* OBJ_ripemd160WithRSA 1 3 36 3 3 1 2 */ -&(nid_objs[ 2]),/* OBJ_pkcs 1 2 840 113549 1 */ -&(nid_objs[116]),/* OBJ_dsa 1 2 840 10040 4 1 */ -&(nid_objs[113]),/* OBJ_dsaWithSHA1 1 2 840 10040 4 3 */ -&(nid_objs[57]),/* OBJ_netscape 2 16 840 1 113730 */ -&(nid_objs[27]),/* OBJ_pkcs3 1 2 840 113549 1 3 */ -&(nid_objs[20]),/* OBJ_pkcs7 1 2 840 113549 1 7 */ -&(nid_objs[47]),/* OBJ_pkcs9 1 2 840 113549 1 9 */ -&(nid_objs[ 3]),/* OBJ_md2 1 2 840 113549 2 2 */ -&(nid_objs[ 4]),/* OBJ_md5 1 2 840 113549 2 5 */ -&(nid_objs[37]),/* OBJ_rc2_cbc 1 2 840 113549 3 2 */ -&(nid_objs[ 5]),/* OBJ_rc4 1 2 840 113549 3 4 */ -&(nid_objs[44]),/* OBJ_des_ede3_cbc 1 2 840 113549 3 7 */ -&(nid_objs[120]),/* OBJ_rc5_cbc 1 2 840 113549 3 8 */ -&(nid_objs[58]),/* OBJ_netscape_cert_extension 2 16 840 1 113730 1 */ -&(nid_objs[59]),/* OBJ_netscape_data_type 2 16 840 1 113730 2 */ -&(nid_objs[108]),/* OBJ_cast5_cbc 1 2 840 113533 7 66 10 */ -&(nid_objs[112]),/* OBJ_pbeWithMD5AndCast5_CBC 1 2 840 113533 7 66 12 */ -&(nid_objs[ 6]),/* OBJ_rsaEncryption 1 2 840 113549 1 1 1 */ -&(nid_objs[ 7]),/* OBJ_md2WithRSAEncryption 1 2 840 113549 1 1 2 */ -&(nid_objs[ 8]),/* OBJ_md5WithRSAEncryption 1 2 840 113549 1 1 4 */ -&(nid_objs[65]),/* OBJ_sha1WithRSAEncryption 1 2 840 113549 1 1 5 */ -&(nid_objs[28]),/* OBJ_dhKeyAgreement 1 2 840 113549 1 3 1 */ -&(nid_objs[ 9]),/* OBJ_pbeWithMD2AndDES_CBC 1 2 840 113549 1 5 1 */ -&(nid_objs[10]),/* OBJ_pbeWithMD5AndDES_CBC 1 2 840 113549 1 5 3 */ -&(nid_objs[68]),/* OBJ_pbeWithSHA1AndRC2_CBC 1 2 840 113549 1 5 11 */ -&(nid_objs[69]),/* OBJ_pbeWithSHA1AndRC4 1 2 840 113549 1 5 12 */ -&(nid_objs[21]),/* OBJ_pkcs7_data 1 2 840 113549 1 7 1 */ -&(nid_objs[22]),/* OBJ_pkcs7_signed 1 2 840 113549 1 7 2 */ -&(nid_objs[23]),/* OBJ_pkcs7_enveloped 1 2 840 113549 1 7 3 */ -&(nid_objs[24]),/* OBJ_pkcs7_signedAndEnveloped 1 2 840 113549 1 7 4 */ -&(nid_objs[25]),/* OBJ_pkcs7_digest 1 2 840 113549 1 7 5 */ -&(nid_objs[26]),/* OBJ_pkcs7_encrypted 1 2 840 113549 1 7 6 */ -&(nid_objs[48]),/* OBJ_pkcs9_emailAddress 1 2 840 113549 1 9 1 */ -&(nid_objs[49]),/* OBJ_pkcs9_unstructuredName 1 2 840 113549 1 9 2 */ -&(nid_objs[50]),/* OBJ_pkcs9_contentType 1 2 840 113549 1 9 3 */ -&(nid_objs[51]),/* OBJ_pkcs9_messageDigest 1 2 840 113549 1 9 4 */ -&(nid_objs[52]),/* OBJ_pkcs9_signingTime 1 2 840 113549 1 9 5 */ -&(nid_objs[53]),/* OBJ_pkcs9_countersignature 1 2 840 113549 1 9 6 */ -&(nid_objs[54]),/* OBJ_pkcs9_challengePassword 1 2 840 113549 1 9 7 */ -&(nid_objs[55]),/* OBJ_pkcs9_unstructuredAddress 1 2 840 113549 1 9 8 */ -&(nid_objs[56]),/* OBJ_pkcs9_extCertAttributes 1 2 840 113549 1 9 9 */ -&(nid_objs[71]),/* OBJ_netscape_cert_type 2 16 840 1 113730 1 1 */ -&(nid_objs[72]),/* OBJ_netscape_base_url 2 16 840 1 113730 1 2 */ -&(nid_objs[73]),/* OBJ_netscape_revocation_url 2 16 840 1 113730 1 3 */ -&(nid_objs[74]),/* OBJ_netscape_ca_revocation_url 2 16 840 1 113730 1 4 */ -&(nid_objs[75]),/* OBJ_netscape_renewal_url 2 16 840 1 113730 1 7 */ -&(nid_objs[76]),/* OBJ_netscape_ca_policy_url 2 16 840 1 113730 1 8 */ -&(nid_objs[77]),/* OBJ_netscape_ssl_server_name 2 16 840 1 113730 1 12 */ -&(nid_objs[78]),/* OBJ_netscape_comment 2 16 840 1 113730 1 13 */ -&(nid_objs[79]),/* OBJ_netscape_cert_sequence 2 16 840 1 113730 2 5 */ -}; - diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl index 4e7879d3f3..5043daef2a 100644 --- a/src/lib/libcrypto/objects/obj_dat.pl +++ b/src/lib/libcrypto/objects/obj_dat.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl sub obj_cmp { @@ -252,7 +252,7 @@ sub der_it $ret.=pack("C*",$a[0]*40+$a[1]); shift @a; shift @a; - while ($_=shift(@a)) + foreach (@a) { @r=(); $t=0; diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c index 45206c616c..cef401db27 100644 --- a/src/lib/libcrypto/objects/obj_err.c +++ b/src/lib/libcrypto/objects/obj_err.c @@ -1,63 +1,65 @@ -/* lib/obj/obj_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/objects/obj_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "objects.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -68,24 +70,24 @@ static ERR_STRING_DATA OBJ_str_functs[]= {ERR_PACK(0,OBJ_F_OBJ_NID2LN,0), "OBJ_nid2ln"}, {ERR_PACK(0,OBJ_F_OBJ_NID2OBJ,0), "OBJ_nid2obj"}, {ERR_PACK(0,OBJ_F_OBJ_NID2SN,0), "OBJ_nid2sn"}, -{0,NULL}, +{0,NULL} }; static ERR_STRING_DATA OBJ_str_reasons[]= { {OBJ_R_MALLOC_FAILURE ,"malloc failure"}, {OBJ_R_UNKNOWN_NID ,"unknown nid"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_OBJ_strings() +void ERR_load_OBJ_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_OBJ,OBJ_str_functs); diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c index 0a9c756197..1a1ba0fc06 100644 --- a/src/lib/libcrypto/objects/obj_lib.c +++ b/src/lib/libcrypto/objects/obj_lib.c @@ -58,27 +58,27 @@ #include #include "cryptlib.h" -#include "lhash.h" -#include "objects.h" -#include "buffer.h" +#include +#include +#include -ASN1_OBJECT *OBJ_dup(o) -ASN1_OBJECT *o; +ASN1_OBJECT *OBJ_dup(ASN1_OBJECT *o) { ASN1_OBJECT *r; int i; + char *ln=NULL; if (o == NULL) return(NULL); if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) return(o); - r=(ASN1_OBJECT *)ASN1_OBJECT_new(); + r=ASN1_OBJECT_new(); if (r == NULL) { OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); return(NULL); } - r->data=(unsigned char *)Malloc(o->length); + r->data=Malloc(o->length); if (r->data == NULL) goto err; memcpy(r->data,o->data,o->length); @@ -88,35 +88,35 @@ ASN1_OBJECT *o; if (o->ln != NULL) { i=strlen(o->ln)+1; - r->ln=(char *)Malloc(i); + r->ln=ln=Malloc(i); if (r->ln == NULL) goto err; - memcpy(r->ln,o->ln,i); + memcpy(ln,o->ln,i); } if (o->sn != NULL) { + char *s; + i=strlen(o->sn)+1; - r->sn=(char *)Malloc(i); + r->sn=s=Malloc(i); if (r->sn == NULL) goto err; - memcpy(r->sn,o->sn,i); + memcpy(s,o->sn,i); } r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC| - ASN1_OBJECT_FLAG_DYNAMIC_STRINGS); + ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA); return(r); err: OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE); if (r != NULL) { - if (r->ln != NULL) Free(r->ln); + if (ln != NULL) Free(ln); if (r->data != NULL) Free(r->data); Free(r); } return(NULL); } -int OBJ_cmp(a,b) -ASN1_OBJECT *a; -ASN1_OBJECT *b; +int OBJ_cmp(ASN1_OBJECT *a, ASN1_OBJECT *b) { int ret; diff --git a/src/lib/libcrypto/objects/objects.err b/src/lib/libcrypto/objects/objects.err deleted file mode 100644 index 8bec3eaea2..0000000000 --- a/src/lib/libcrypto/objects/objects.err +++ /dev/null @@ -1,12 +0,0 @@ -/* Error codes for the OBJ functions. */ - -/* Function codes. */ -#define OBJ_F_OBJ_CREATE 100 -#define OBJ_F_OBJ_DUP 101 -#define OBJ_F_OBJ_NID2LN 102 -#define OBJ_F_OBJ_NID2OBJ 103 -#define OBJ_F_OBJ_NID2SN 104 - -/* Reason codes. */ -#define OBJ_R_MALLOC_FAILURE 100 -#define OBJ_R_UNKNOWN_NID 101 diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h index e1d555b47c..d03748e022 100644 --- a/src/lib/libcrypto/objects/objects.h +++ b/src/lib/libcrypto/objects/objects.h @@ -66,6 +66,7 @@ extern "C" { #define SN_undef "UNDEF" #define LN_undef "undefined" #define NID_undef 0 +#define OBJ_undef 0L #define SN_Algorithm "Algorithm" #define LN_algorithm "algorithm" @@ -383,13 +384,16 @@ extern "C" { #define NID_pbeWithSHA1AndRC2_CBC 68 #define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L -/* proposed by microsoft to RSA */ -#define LN_pbeWithSHA1AndRC4 "pbeWithSHA1AndRC4" -#define NID_pbeWithSHA1AndRC4 69 -#define OBJ_pbeWithSHA1AndRC4 OBJ_pkcs,5L,12L +/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now + * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something + * completely different. + */ +#define LN_id_pbkdf2 "PBKDF2" +#define NID_id_pbkdf2 69 +#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L #define SN_dsaWithSHA1_2 "DSA-SHA1-old" -#define LN_dsaWithSHA1_2 "dsaWithSHA1" +#define LN_dsaWithSHA1_2 "dsaWithSHA1-old" #define NID_dsaWithSHA1_2 70 /* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */ #define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L @@ -654,21 +658,280 @@ extern "C" { #define LN_rc5_ofb64 "rc5-ofb" #define NID_rc5_ofb64 123 -#include "bio.h" -#include "asn1.h" +#define SN_rle_compression "RLE" +#define LN_rle_compression "run length compression" +#define NID_rle_compression 124 +#define OBJ_rle_compression 1L,1L,1L,1L,666L.1L + +#define SN_zlib_compression "ZLIB" +#define LN_zlib_compression "zlib compression" +#define NID_zlib_compression 125 +#define OBJ_zlib_compression 1L,1L,1L,1L,666L.2L + +#define SN_ext_key_usage "extendedKeyUsage" +#define LN_ext_key_usage "X509v3 Extended Key Usage" +#define NID_ext_key_usage 126 +#define OBJ_ext_key_usage OBJ_ld_ce,37 + +#define SN_id_pkix "PKIX" +#define NID_id_pkix 127 +#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L + +#define SN_id_kp "id-kp" +#define NID_id_kp 128 +#define OBJ_id_kp OBJ_id_pkix,3L + +/* PKIX extended key usage OIDs */ + +#define SN_server_auth "serverAuth" +#define LN_server_auth "TLS Web Server Authentication" +#define NID_server_auth 129 +#define OBJ_server_auth OBJ_id_kp,1L + +#define SN_client_auth "clientAuth" +#define LN_client_auth "TLS Web Client Authentication" +#define NID_client_auth 130 +#define OBJ_client_auth OBJ_id_kp,2L + +#define SN_code_sign "codeSigning" +#define LN_code_sign "Code Signing" +#define NID_code_sign 131 +#define OBJ_code_sign OBJ_id_kp,3L + +#define SN_email_protect "emailProtection" +#define LN_email_protect "E-mail Protection" +#define NID_email_protect 132 +#define OBJ_email_protect OBJ_id_kp,4L + +#define SN_time_stamp "timeStamping" +#define LN_time_stamp "Time Stamping" +#define NID_time_stamp 133 +#define OBJ_time_stamp OBJ_id_kp,8L + +/* Additional extended key usage OIDs: Microsoft */ + +#define SN_ms_code_ind "msCodeInd" +#define LN_ms_code_ind "Microsoft Individual Code Signing" +#define NID_ms_code_ind 134 +#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L + +#define SN_ms_code_com "msCodeCom" +#define LN_ms_code_com "Microsoft Commercial Code Signing" +#define NID_ms_code_com 135 +#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L + +#define SN_ms_ctl_sign "msCTLSign" +#define LN_ms_ctl_sign "Microsoft Trust List Signing" +#define NID_ms_ctl_sign 136 +#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L + +#define SN_ms_sgc "msSGC" +#define LN_ms_sgc "Microsoft Server Gated Crypto" +#define NID_ms_sgc 137 +#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L + +#define SN_ms_efs "msEFS" +#define LN_ms_efs "Microsoft Encrypted File System" +#define NID_ms_efs 138 +#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L + +/* Addidional usage: Netscape */ + +#define SN_ns_sgc "nsSGC" +#define LN_ns_sgc "Netscape Server Gated Crypto" +#define NID_ns_sgc 139 +#define OBJ_ns_sgc OBJ_netscape,4L,1L + +#define SN_delta_crl "deltaCRL" +#define LN_delta_crl "X509v3 Delta CRL Indicator" +#define NID_delta_crl 140 +#define OBJ_delta_crl OBJ_ld_ce,27L + +#define SN_crl_reason "CRLReason" +#define LN_crl_reason "CRL Reason Code" +#define NID_crl_reason 141 +#define OBJ_crl_reason OBJ_ld_ce,21L + +#define SN_invalidity_date "invalidityDate" +#define LN_invalidity_date "Invalidity Date" +#define NID_invalidity_date 142 +#define OBJ_invalidity_date OBJ_ld_ce,24L + +#define SN_sxnet "SXNetID" +#define LN_sxnet "Strong Extranet ID" +#define NID_sxnet 143 +#define OBJ_sxnet 1L,3L,101L,1L,4L,1L + +/* PKCS12 and related OBJECT IDENTIFIERS */ + +#define OBJ_pkcs12 OBJ_pkcs,12L +#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1 + +#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4" +#define NID_pbe_WithSHA1And128BitRC4 144 +#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L + +#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4" +#define NID_pbe_WithSHA1And40BitRC4 145 +#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L + +#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146 +#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L + +#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC" +#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147 +#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L + +#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC" +#define NID_pbe_WithSHA1And128BitRC2_CBC 148 +#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L + +#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC" +#define NID_pbe_WithSHA1And40BitRC2_CBC 149 +#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L + +#define OBJ_pkcs12_Version1 OBJ_pkcs12, 10L + +#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1, 1L + +#define LN_keyBag "keyBag" +#define NID_keyBag 150 +#define OBJ_keyBag OBJ_pkcs12_BagIds, 1L + +#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag" +#define NID_pkcs8ShroudedKeyBag 151 +#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds, 2L + +#define LN_certBag "certBag" +#define NID_certBag 152 +#define OBJ_certBag OBJ_pkcs12_BagIds, 3L + +#define LN_crlBag "crlBag" +#define NID_crlBag 153 +#define OBJ_crlBag OBJ_pkcs12_BagIds, 4L + +#define LN_secretBag "secretBag" +#define NID_secretBag 154 +#define OBJ_secretBag OBJ_pkcs12_BagIds, 5L + +#define LN_safeContentsBag "safeContentsBag" +#define NID_safeContentsBag 155 +#define OBJ_safeContentsBag OBJ_pkcs12_BagIds, 6L + +#define LN_friendlyName "friendlyName" +#define NID_friendlyName 156 +#define OBJ_friendlyName OBJ_pkcs9, 20L + +#define LN_localKeyID "localKeyID" +#define NID_localKeyID 157 +#define OBJ_localKeyID OBJ_pkcs9, 21L + +#define OBJ_certTypes OBJ_pkcs9, 22L + +#define LN_x509Certificate "x509Certificate" +#define NID_x509Certificate 158 +#define OBJ_x509Certificate OBJ_certTypes, 1L + +#define LN_sdsiCertificate "sdsiCertificate" +#define NID_sdsiCertificate 159 +#define OBJ_sdsiCertificate OBJ_certTypes, 2L + +#define OBJ_crlTypes OBJ_pkcs9, 23L + +#define LN_x509Crl "x509Crl" +#define NID_x509Crl 160 +#define OBJ_x509Crl OBJ_crlTypes, 1L + +/* PKCS#5 v2 OIDs */ + +#define LN_pbes2 "PBES2" +#define NID_pbes2 161 +#define OBJ_pbes2 OBJ_pkcs,5L,13L + +#define LN_pbmac1 "PBMAC1" +#define NID_pbmac1 162 +#define OBJ_pbmac1 OBJ_pkcs,5L,14L + +#define LN_hmacWithSHA1 "hmacWithSHA1" +#define NID_hmacWithSHA1 163 +#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L + +/* Policy Qualifier Ids */ + +#define LN_id_qt_cps "Policy Qualifier CPS" +#define SN_id_qt_cps "id-qt-cps" +#define NID_id_qt_cps 164 +#define OBJ_id_qt_cps OBJ_id_pkix,2L,1L + +#define LN_id_qt_unotice "Policy Qualifier User Notice" +#define SN_id_qt_unotice "id-qt-unotice" +#define NID_id_qt_unotice 165 +#define OBJ_id_qt_unotice OBJ_id_pkix,2L,2L + +#define SN_rc2_64_cbc "RC2-64-CBC" +#define LN_rc2_64_cbc "rc2-64-cbc" +#define NID_rc2_64_cbc 166 + +#define SN_SMIMECapabilities "SMIME-CAPS" +#define LN_SMIMECapabilities "S/MIME Capabilities" +#define NID_SMIMECapabilities 167 +#define OBJ_SMIMECapabilities OBJ_id_pkcs9,15L + +#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC" +#define NID_pbeWithMD2AndRC2_CBC 168 +#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L + +#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC" +#define NID_pbeWithMD5AndRC2_CBC 169 +#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L + +#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC" +#define NID_pbeWithSHA1AndDES_CBC 170 +#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L + +#include +#include + +#define OBJ_NAME_TYPE_UNDEF 0x00 +#define OBJ_NAME_TYPE_MD_METH 0x01 +#define OBJ_NAME_TYPE_CIPHER_METH 0x02 +#define OBJ_NAME_TYPE_PKEY_METH 0x03 +#define OBJ_NAME_TYPE_COMP_METH 0x04 +#define OBJ_NAME_TYPE_NUM 0x05 + +#define OBJ_NAME_ALIAS 0x8000 + + +typedef struct obj_name_st + { + int type; + int alias; + const char *name; + const char *data; + } OBJ_NAME; #define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) -#ifndef NOPROTO + +int OBJ_NAME_init(void); +int OBJ_NAME_new_index(unsigned long (*hash_func)(),int (*cmp_func)(), + void (*free_func)()); +const char *OBJ_NAME_get(const char *name,int type); +int OBJ_NAME_add(const char *name,int type,const char *data); +int OBJ_NAME_remove(const char *name,int type); +void OBJ_NAME_cleanup(int type); /* -1 for everything */ ASN1_OBJECT * OBJ_dup(ASN1_OBJECT *o); ASN1_OBJECT * OBJ_nid2obj(int n); -char * OBJ_nid2ln(int n); -char * OBJ_nid2sn(int n); +const char * OBJ_nid2ln(int n); +const char * OBJ_nid2sn(int n); int OBJ_obj2nid(ASN1_OBJECT *o); +ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name); +int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name); int OBJ_txt2nid(char *s); -int OBJ_ln2nid(char *s); -int OBJ_sn2nid(char *s); +int OBJ_ln2nid(const char *s); +int OBJ_sn2nid(const char *s); int OBJ_cmp(ASN1_OBJECT *a,ASN1_OBJECT *b); char * OBJ_bsearch(char *key,char *base,int num,int size,int (*cmp)()); @@ -680,30 +943,11 @@ int OBJ_create(char *oid,char *sn,char *ln); void OBJ_cleanup(void ); int OBJ_create_objects(BIO *in); -#else - -ASN1_OBJECT * OBJ_dup(); -ASN1_OBJECT * OBJ_nid2obj(); -char * OBJ_nid2ln(); -char * OBJ_nid2sn(); -int OBJ_obj2nid(); -int OBJ_txt2nid(); -int OBJ_ln2nid(); -int OBJ_sn2nid(); -int OBJ_cmp(); -char * OBJ_bsearch(); - -void ERR_load_OBJ_strings(); - -int OBJ_new_nid(); -int OBJ_add_object(); -int OBJ_create(); -void OBJ_cleanup(); -int OBJ_create_objects(); - -#endif - /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the OBJ functions. */ /* Function codes. */ @@ -716,7 +960,7 @@ int OBJ_create_objects(); /* Reason codes. */ #define OBJ_R_MALLOC_FAILURE 100 #define OBJ_R_UNKNOWN_NID 101 - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/opensslconf.h.in b/src/lib/libcrypto/opensslconf.h.in new file mode 100644 index 0000000000..e4a8f8ad54 --- /dev/null +++ b/src/lib/libcrypto/opensslconf.h.in @@ -0,0 +1,142 @@ +/* crypto/opensslconf.h */ +/* WARNING: This file is autogenerated by Configure */ + +/* Generate 80386 code? */ +#undef I386_ONLY + +#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */ +#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR) +#define OPENSSLDIR "/usr/local/ssl" +#endif +#endif + +#define OPENSSL_UNISTD + +#if defined(HEADER_IDEA_H) && !defined(IDEA_INT) +#define IDEA_INT unsigned int +#endif + +#if defined(HEADER_MD2_H) && !defined(MD2_INT) +#define MD2_INT unsigned int +#endif + +#if defined(HEADER_RC2_H) && !defined(RC2_INT) +/* I need to put in a mod for the alpha - eay */ +#define RC2_INT unsigned int +#endif + +#if defined(HEADER_RC4_H) && !defined(RC4_INT) +/* using int types make the structure larger but make the code faster + * on most boxes I have tested - up to %20 faster. */ +#define RC4_INT unsigned int +#endif + +#if defined(HEADER_DES_H) && !defined(DES_LONG) +/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a + * %20 speed up (longs are 8 bytes, int's are 4). */ +#ifndef DES_LONG +#define DES_LONG unsigned long +#endif +#endif + +#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H) +#define CONFIG_HEADER_BN_H +#undef BN_LLONG + +/* Should we define BN_DIV2W here? */ + +/* Only one for the following should be defined */ +/* The prime number generation stuff may not work when + * EIGHT_BIT but I don't care since I've only used this mode + * for debuging the bignum libraries */ +#undef SIXTY_FOUR_BIT_LONG +#undef SIXTY_FOUR_BIT +#define THIRTY_TWO_BIT +#undef SIXTEEN_BIT +#undef EIGHT_BIT +#endif + +#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H) +#define CONFIG_HEADER_RC4_LOCL_H +/* if this is defined data[i] is used instead of *data, this is a %20 + * speedup on x86 */ +#undef RC4_INDEX +#endif + +#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H) +#define CONFIG_HEADER_BF_LOCL_H +#undef BF_PTR +#endif /* HEADER_BF_LOCL_H */ + +#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H) +#define CONFIG_HEADER_DES_LOCL_H +#ifndef DES_DEFAULT_OPTIONS +/* the following is tweaked from a config script, that is why it is a + * protected undef/define */ +#ifndef DES_PTR +#undef DES_PTR +#endif + +/* This helps C compiler generate the correct code for multiple functional + * units. It reduces register dependancies at the expense of 2 more + * registers */ +#ifndef DES_RISC1 +#undef DES_RISC1 +#endif + +#ifndef DES_RISC2 +#undef DES_RISC2 +#endif + +#if defined(DES_RISC1) && defined(DES_RISC2) +YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!! +#endif + +/* Unroll the inner loop, this sometimes helps, sometimes hinders. + * Very mucy CPU dependant */ +#ifndef DES_UNROLL +#undef DES_UNROLL +#endif + +/* These default values were supplied by + * Peter Gutman + * They are only used if nothing else has been defined */ +#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL) +/* Special defines which change the way the code is built depending on the + CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find + even newer MIPS CPU's, but at the moment one size fits all for + optimization options. Older Sparc's work better with only UNROLL, but + there's no way to tell at compile time what it is you're running on */ + +#if defined( sun ) /* Newer Sparc's */ +# define DES_PTR +# define DES_RISC1 +# define DES_UNROLL +#elif defined( __ultrix ) /* Older MIPS */ +# define DES_PTR +# define DES_RISC2 +# define DES_UNROLL +#elif defined( __osf1__ ) /* Alpha */ +# define DES_PTR +# define DES_RISC2 +#elif defined ( _AIX ) /* RS6000 */ + /* Unknown */ +#elif defined( __hpux ) /* HP-PA */ + /* Unknown */ +#elif defined( __aux ) /* 68K */ + /* Unknown */ +#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */ +# define DES_UNROLL +#elif defined( __sgi ) /* Newer MIPS */ +# define DES_PTR +# define DES_RISC2 +# define DES_UNROLL +#elif defined( i386 ) /* x86 boxes, should be gcc */ +# define DES_PTR +# define DES_RISC1 +# define DES_UNROLL +#endif /* Systems-specific speed defines */ +#endif + +#endif /* DES_DEFAULT_OPTIONS */ +#endif /* HEADER_DES_LOCL_H */ diff --git a/src/lib/libcrypto/opensslv.h b/src/lib/libcrypto/opensslv.h new file mode 100644 index 0000000000..b841347f05 --- /dev/null +++ b/src/lib/libcrypto/opensslv.h @@ -0,0 +1,21 @@ +#ifndef HEADER_OPENSSLV_H +#define HEADER_OPENSSLV_H + +/* Numeric release version identifier: + * MMNNFFRBB: major minor fix final beta/patch + * For example: + * 0.9.3-dev 0x00903000 + * 0.9.3beta1 0x00903001 + * 0.9.3beta2-dev 0x00903002 + * 0.9.3beta2 0x00903002 + * 0.9.3 0x00903100 + * 0.9.3a 0x00903101 + * 0.9.4 0x00904100 + * 1.2.3z 0x1020311a + * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.) + */ +#define OPENSSL_VERSION_NUMBER 0x00904100L +#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.4 09 Aug 1999" +#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT + +#endif /* HEADER_OPENSSLV_H */ diff --git a/src/lib/libcrypto/pem/Makefile.ssl b/src/lib/libcrypto/pem/Makefile.ssl index fc04a88fd9..b4e7524ea2 100644 --- a/src/lib/libcrypto/pem/Makefile.ssl +++ b/src/lib/libcrypto/pem/Makefile.ssl @@ -7,30 +7,28 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=pem -ERRC=pem_err GENERAL=Makefile TEST= APPS= -CTX_SIZE= ctx_size - LIB=$(TOP)/libcrypto.a -LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c $(ERRC).c +LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c pem_err.c -LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o $(ERRC).o +LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o pem_err.o SRC= $(LIBSRC) -EXHEADER= pem.h +EXHEADER= pem.h pem2.h HEADER= $(EXHEADER) ALL= $(GENERAL) $(SRC) $(HEADER) @@ -38,36 +36,27 @@ ALL= $(GENERAL) $(SRC) $(HEADER) top: (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) -all: pem.h lib - -pem.h: $(CTX_SIZE) - ./$(CTX_SIZE) pem.new - if [ -f pem.h ]; then mv -f pem.h pem.old; fi - mv -f pem.new pem.h - -$(CTX_SIZE): $(CTX_SIZE).o - $(CC) $(CFLAGS) -o $(CTX_SIZE) $(CTX_SIZE).o +all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO -links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) +links: $(EXHEADER) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -79,18 +68,121 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(CTX_SIZE).c $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f $(CTX_SIZE) *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # SPECIAL CASE .org - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +pem_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pem_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pem_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +pem_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +pem_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +pem_all.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +pem_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pem_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pem_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pem_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pem_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h +pem_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h +pem_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +pem_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +pem_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +pem_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +pem_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +pem_all.o: ../cryptlib.h +pem_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pem_err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pem_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +pem_err.o: ../../include/openssl/des.h ../../include/openssl/dh.h +pem_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h +pem_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pem_err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pem_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pem_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pem_err.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h +pem_err.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h +pem_err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +pem_err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +pem_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +pem_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +pem_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +pem_info.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pem_info.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pem_info.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +pem_info.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +pem_info.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +pem_info.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +pem_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pem_info.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pem_info.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pem_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pem_info.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h +pem_info.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h +pem_info.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +pem_info.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +pem_info.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +pem_info.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +pem_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +pem_info.o: ../cryptlib.h +pem_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pem_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pem_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +pem_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +pem_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +pem_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +pem_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pem_lib.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pem_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pem_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pem_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h +pem_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h +pem_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h +pem_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +pem_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +pem_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +pem_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +pem_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +pem_lib.o: ../cryptlib.h +pem_seal.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pem_seal.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pem_seal.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +pem_seal.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +pem_seal.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +pem_seal.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +pem_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pem_seal.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pem_seal.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pem_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pem_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h +pem_seal.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h +pem_seal.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h +pem_seal.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +pem_seal.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +pem_seal.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +pem_seal.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +pem_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +pem_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pem_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pem_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +pem_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +pem_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +pem_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +pem_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pem_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pem_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pem_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pem_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h +pem_sign.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h +pem_sign.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h +pem_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +pem_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +pem_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +pem_sign.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +pem_sign.o: ../../include/openssl/x509_vfy.h ../cryptlib.h diff --git a/src/lib/libcrypto/pem/ctx_size.c b/src/lib/libcrypto/pem/ctx_size.c deleted file mode 100644 index 87469bc4af..0000000000 --- a/src/lib/libcrypto/pem/ctx_size.c +++ /dev/null @@ -1,122 +0,0 @@ -/* crypto/pem/ctx_size.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "cryptlib.h" -#include "evp.h" - -int main(argc,argv) -int argc; -char *argv[]; - { - int i,j; - char buf[256]; - - for (;;) - { - char *str; - buf[0]='\0'; - fgets(buf,256,stdin); - if (buf[0] == '\0') break; - - str="#define EVP_ENCODE_CTX_SIZE "; - if (strncmp(buf,str,strlen(str)) == 0) - { - printf("%s %d\n",str,(int)sizeof(EVP_ENCODE_CTX)); - continue; - } - str="#define EVP_MD_SIZE "; - if (strncmp(buf,str,strlen(str)) == 0) - { - printf("%s %d\n",str,(int)sizeof(EVP_MD)); - continue; - } - str="#define EVP_MD_CTX_SIZE "; - if (strncmp(buf,str,strlen(str)) == 0) - { - printf("%s %d\n",str,(int)sizeof(EVP_MD_CTX)); - continue; - } - str="#define EVP_CIPHER_SIZE "; - if (strncmp(buf,str,strlen(str)) == 0) - { - printf("%s %d\n",str,(int)sizeof(EVP_CIPHER)); - continue; - } - str="#define EVP_CIPHER_CTX_SIZE "; - if (strncmp(buf,str,strlen(str)) == 0) - { - printf("%s %d\n",str,(int)sizeof(EVP_CIPHER_CTX)); - continue; - } - - str="#define EVP_MAX_MD_SIZE "; - if (strncmp(buf,str,strlen(str)) == 0) - { - i=MD2_DIGEST_LENGTH; - j=MD5_DIGEST_LENGTH; - if (j > i) i=j; - j=SHA_DIGEST_LENGTH; - if (j > i) i=j; - printf("%s %d\n",str,i); - continue; - } - fputs(buf,stdout); - } - exit(0); - } diff --git a/src/lib/libcrypto/pem/pem.err b/src/lib/libcrypto/pem/pem.err deleted file mode 100644 index 0e523abf82..0000000000 --- a/src/lib/libcrypto/pem/pem.err +++ /dev/null @@ -1,38 +0,0 @@ -/* Error codes for the PEM functions. */ - -/* Function codes. */ -#define PEM_F_DEF_CALLBACK 100 -#define PEM_F_LOAD_IV 101 -#define PEM_F_PEM_ASN1_READ 102 -#define PEM_F_PEM_ASN1_READ_BIO 103 -#define PEM_F_PEM_ASN1_WRITE 104 -#define PEM_F_PEM_ASN1_WRITE_BIO 105 -#define PEM_F_PEM_DO_HEADER 106 -#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 -#define PEM_F_PEM_READ 108 -#define PEM_F_PEM_READ_BIO 109 -#define PEM_F_PEM_SEALFINAL 110 -#define PEM_F_PEM_SEALINIT 111 -#define PEM_F_PEM_SIGNFINAL 112 -#define PEM_F_PEM_WRITE 113 -#define PEM_F_PEM_WRITE_BIO 114 -#define PEM_F_PEM_X509_INFO_READ 115 -#define PEM_F_PEM_X509_INFO_READ_BIO 116 -#define PEM_F_PEM_X509_INFO_WRITE_BIO 117 - -/* Reason codes. */ -#define PEM_R_BAD_BASE64_DECODE 100 -#define PEM_R_BAD_DECRYPT 101 -#define PEM_R_BAD_END_LINE 102 -#define PEM_R_BAD_IV_CHARS 103 -#define PEM_R_BAD_PASSWORD_READ 104 -#define PEM_R_NOT_DEK_INFO 105 -#define PEM_R_NOT_ENCRYPTED 106 -#define PEM_R_NOT_PROC_TYPE 107 -#define PEM_R_NO_START_LINE 108 -#define PEM_R_PROBLEMS_GETTING_PASSWORD 109 -#define PEM_R_PUBLIC_KEY_NO_RSA 110 -#define PEM_R_READ_KEY 111 -#define PEM_R_SHORT_HEADER 112 -#define PEM_R_UNSUPPORTED_CIPHER 113 -#define PEM_R_UNSUPPORTED_ENCRYPTION 114 diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h index 55fbaeffe2..fc333e42c8 100644 --- a/src/lib/libcrypto/pem/pem.h +++ b/src/lib/libcrypto/pem/pem.h @@ -1,4 +1,4 @@ -/* crypto/pem/pem.org */ +/* crypto/pem/pem.h */ /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -56,14 +56,6 @@ * [including the GNU Public Licence.] */ -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify pem.org since pem.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - #ifndef HEADER_PEM_H #define HEADER_PEM_H @@ -71,8 +63,11 @@ extern "C" { #endif -#include "evp.h" -#include "x509.h" +#include +#include +#include + +#define PEM_BUFSIZE 1024 #define PEM_OBJ_UNDEF 0 #define PEM_OBJ_X509 1 @@ -111,45 +106,17 @@ extern "C" { #define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" #define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" #define PEM_STRING_X509_CRL "X509 CRL" -#define PEM_STRING_EVP_PKEY "PRIVATE KEY" +#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY" #define PEM_STRING_RSA "RSA PRIVATE KEY" #define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" #define PEM_STRING_DSA "DSA PRIVATE KEY" #define PEM_STRING_PKCS7 "PKCS7" +#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY" +#define PEM_STRING_PKCS8INF "PRIVATE KEY" #define PEM_STRING_DHPARAMS "DH PARAMETERS" #define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" #define PEM_STRING_DSAPARAMS "DSA PARAMETERS" -#ifndef HEADER_ENVELOPE_H - -#define EVP_ENCODE_CTX_SIZE 96 -#define EVP_MD_SIZE 60 -#define EVP_MD_CTX_SIZE 152 -#define EVP_CIPHER_SIZE 40 -#define EVP_CIPHER_CTX_SIZE 4212 -#define EVP_MAX_MD_SIZE 20 - -typedef struct evp_encode_ctx_st - { - char data[EVP_ENCODE_CTX_SIZE]; - } EVP_ENCODE_CTX; - -typedef struct env_md_ctx_st - { - char data[EVP_MD_CTX_SIZE]; - } EVP_MD_CTX; - -typedef struct evp_cipher_st - { - char data[EVP_CIPHER_SIZE]; - } EVP_CIPHER; - -typedef struct evp_cipher_ctx_st - { - char data[EVP_CIPHER_CTX_SIZE]; - } EVP_CIPHER_CTX; -#endif - typedef struct PEM_Encode_Seal_st { @@ -217,151 +184,322 @@ typedef struct pem_ctx_st unsigned char *data; } PEM_CTX; +/* These macros make the PEM_read/PEM_write functions easier to maintain and + * write. Now they are all implemented with either: + * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) + */ + +#ifdef NO_FP_API + +#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ +#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ +#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ + +#else + +#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ +type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ +{ \ +return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\ + cb,u)); \ +} \ + +#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x) \ +{ \ +return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \ + NULL,NULL,0,NULL,NULL)); \ +} + +#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ +int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, \ + void *u) \ + { \ + return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \ + (char *)x,enc,kstr,klen,cb,u)); \ + } + +#endif + +#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ +type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ +{ \ +return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\ + (char **)x,cb,u)); \ +} + +#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x) \ +{ \ +return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \ + NULL,NULL,0,NULL,NULL)); \ +} + +#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ +int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ + { \ + return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \ + (char *)x,enc,kstr,klen,cb,u)); \ + } + +#define IMPLEMENT_PEM_write(name, type, str, asn1) \ + IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_write_fp(name, type, str, asn1) + +#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) + +#define IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ + IMPLEMENT_PEM_read_fp(name, type, str, asn1) + +#define IMPLEMENT_PEM_rw(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write(name, type, str, asn1) + +#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ + IMPLEMENT_PEM_read(name, type, str, asn1) \ + IMPLEMENT_PEM_write_cb(name, type, str, asn1) + +/* These are the same except they are for the declarations */ + +#if defined(WIN16) || defined(NO_FP_API) + +#define DECLARE_PEM_read_fp(name, type) /**/ +#define DECLARE_PEM_write_fp(name, type) /**/ +#define DECLARE_PEM_write_cb_fp(name, type) /**/ + +#else + +#define DECLARE_PEM_read_fp(name, type) \ + type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); + +#define DECLARE_PEM_write_fp(name, type) \ + int PEM_write_##name(FILE *fp, type *x); + +#define DECLARE_PEM_write_cb_fp(name, type) \ + int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u); + +#endif + +#ifdef HEADER_BIO_H +#define DECLARE_PEM_read_bio(name, type) \ + type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); + +#define DECLARE_PEM_write_bio(name, type) \ + int PEM_write_bio_##name(BIO *bp, type *x); + +#define DECLARE_PEM_write_cb_bio(name, type) \ + int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ + unsigned char *kstr, int klen, pem_password_cb *cb, void *u); + +#else + +#define DECLARE_PEM_read_bio(name, type) /**/ +#define DECLARE_PEM_write_bio(name, type) /**/ +#define DECLARE_PEM_write_cb_bio(name, type) /**/ + +#endif + +#define DECLARE_PEM_write(name, type) \ + DECLARE_PEM_write_bio(name, type) \ + DECLARE_PEM_write_fp(name, type) + +#define DECLARE_PEM_write_cb(name, type) \ + DECLARE_PEM_write_cb_bio(name, type) \ + DECLARE_PEM_write_cb_fp(name, type) + +#define DECLARE_PEM_read(name, type) \ + DECLARE_PEM_read_bio(name, type) \ + DECLARE_PEM_read_fp(name, type) + +#define DECLARE_PEM_rw(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write(name, type) + +#define DECLARE_PEM_rw_cb(name, type) \ + DECLARE_PEM_read(name, type) \ + DECLARE_PEM_write_cb(name, type) + #ifdef SSLEAY_MACROS #define PEM_write_SSL_SESSION(fp,x) \ PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ - PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL) + PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL) #define PEM_write_X509(fp,x) \ PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ - (char *)x, NULL,NULL,0,NULL) + (char *)x, NULL,NULL,0,NULL,NULL) #define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ - NULL,NULL,0,NULL) + NULL,NULL,0,NULL,NULL) #define PEM_write_X509_CRL(fp,x) \ PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ - fp,(char *)x, NULL,NULL,0,NULL) -#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \ + fp,(char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ - (char *)x,enc,kstr,klen,cb) + (char *)x,enc,kstr,klen,cb,u) #define PEM_write_RSAPublicKey(fp,x) \ PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ - PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL) -#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \ + PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL) +#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \ PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ - (char *)x,enc,kstr,klen,cb) -#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \ + (char *)x,enc,kstr,klen,cb,u) +#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ PEM_ASN1_write((int (*)())i2d_PrivateKey,\ (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ - bp,(char *)x,enc,kstr,klen,cb) + bp,(char *)x,enc,kstr,klen,cb,u) #define PEM_write_PKCS7(fp,x) \ PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ - (char *)x, NULL,NULL,0,NULL) + (char *)x, NULL,NULL,0,NULL,NULL) #define PEM_write_DHparams(fp,x) \ PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ - (char *)x,NULL,NULL,0,NULL) - -#define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \ - (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb) -#define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \ - (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb) -#define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \ - (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb) -#define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \ - (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb) -#define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ - (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb) -#define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ - (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb) -#define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \ - (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb) -#define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \ - (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb) -#define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \ - (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb) -#define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \ - (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb) + (char *)x,NULL,NULL,0,NULL,NULL) + +#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \ + PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ + PEM_STRING_X509,fp, \ + (char *)x, NULL,NULL,0,NULL,NULL) + +#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \ + (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u) +#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \ + (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u) +#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \ + (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u) +#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \ + (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u) +#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ + (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u) +#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \ + (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u) +#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \ + (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u) +#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \ + (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u) +#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \ + (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u) +#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \ + (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u) + +#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \ + (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \ + (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\ + (char **)x,cb,u) #define PEM_write_bio_SSL_SESSION(bp,x) \ PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ - PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL) + PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL) #define PEM_write_bio_X509(bp,x) \ PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ - (char *)x, NULL,NULL,0,NULL) + (char *)x, NULL,NULL,0,NULL,NULL) #define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ - NULL,NULL,0,NULL) + NULL,NULL,0,NULL,NULL) #define PEM_write_bio_X509_CRL(bp,x) \ PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ - bp,(char *)x, NULL,NULL,0,NULL) -#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \ + bp,(char *)x, NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ - bp,(char *)x,enc,kstr,klen,cb) + bp,(char *)x,enc,kstr,klen,cb,u) #define PEM_write_bio_RSAPublicKey(bp,x) \ PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ PEM_STRING_RSA_PUBLIC,\ - bp,(char *)x,NULL,NULL,0,NULL) -#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \ + bp,(char *)x,NULL,NULL,0,NULL,NULL) +#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \ PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ - bp,(char *)x,enc,kstr,klen,cb) -#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \ + bp,(char *)x,enc,kstr,klen,cb,u) +#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \ PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ - bp,(char *)x,enc,kstr,klen,cb) + bp,(char *)x,enc,kstr,klen,cb,u) #define PEM_write_bio_PKCS7(bp,x) \ PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ - (char *)x, NULL,NULL,0,NULL) + (char *)x, NULL,NULL,0,NULL,NULL) #define PEM_write_bio_DHparams(bp,x) \ PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ - bp,(char *)x,NULL,NULL,0,NULL) + bp,(char *)x,NULL,NULL,0,NULL,NULL) #define PEM_write_bio_DSAparams(bp,x) \ PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ - PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL) - -#define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb) -#define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb) -#define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb) -#define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb) -#define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb) -#define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb) -#define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb) -#define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb) - -#define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb) -#define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb) -#define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb) + PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL) + +#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \ + PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \ + PEM_STRING_X509,bp, \ + (char *)x, NULL,NULL,0,NULL,NULL) + +#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u) +#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u) +#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u) +#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u) +#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u) +#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u) +#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u) +#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u) + +#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u) +#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u) +#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u) + +#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \ + (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \ + (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\ + (char **)x,cb,u) #endif -#ifndef NOPROTO +#if 1 +/* "userdata": new with OpenSSL 0.9.4 */ +typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); +#else +/* OpenSSL 0.9.3, 0.9.3a */ +typedef int pem_password_cb(char *buf, int size, int rwflag); +#endif + int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, - int (*callback)()); + pem_password_cb *callback,void *u); #ifdef HEADER_BIO_H int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,long *len); -int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data, +int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data, long len); -char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x, - int (*cb)()); -int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x, - EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); -STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)()); +char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x, + pem_password_cb *cb, void *u); +int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x, + const EVP_CIPHER *enc,unsigned char *kstr,int klen, + pem_password_cb *cb, void *u); +STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, - unsigned char *kstr, int klen, int (*cb)()); + unsigned char *kstr, int klen, pem_password_cb *cd, void *u); #endif #ifndef WIN16 int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,long *len); int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); -char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x, - int (*cb)()); -int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x, - EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); -STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)()); +char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x, + pem_password_cb *cb, void *u); +int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x, + const EVP_CIPHER *enc,unsigned char *kstr,int klen, + pem_password_cb *callback, void *u); +STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, + pem_password_cb *cb, void *u); #endif int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, @@ -380,142 +518,64 @@ int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, void ERR_load_PEM_strings(void); void PEM_proc_type(char *buf, int type); -void PEM_dek_info(char *buf, char *type, int len, char *str); +void PEM_dek_info(char *buf, const char *type, int len, char *str); #ifndef SSLEAY_MACROS -#ifndef WIN16 -X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)()); -X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)()); -X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)()); -RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)()); -RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)()); -DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)()); -EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)()); -PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)()); -DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)()); -DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)()); -int PEM_write_X509(FILE *fp,X509 *x); -int PEM_write_X509_REQ(FILE *fp,X509_REQ *x); -int PEM_write_X509_CRL(FILE *fp,X509_CRL *x); -int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr, - int klen,int (*cb)()); -int PEM_write_RSAPublicKey(FILE *fp,RSA *x); -int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr, - int klen,int (*cb)()); -int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc, - unsigned char *kstr,int klen,int (*cb)()); -int PEM_write_PKCS7(FILE *fp,PKCS7 *x); -int PEM_write_DHparams(FILE *fp,DH *x); -int PEM_write_DSAparams(FILE *fp,DSA *x); +#ifdef VMS +#include #endif -#ifdef HEADER_BIO_H -X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)()); -X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)()); -X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)()); -RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)()); -RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)()); -DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)()); -EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)()); -PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)()); -DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)()); -DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)()); -int PEM_write_bio_X509(BIO *bp,X509 *x); -int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x); -int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x); -int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc, - unsigned char *kstr,int klen,int (*cb)()); -int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x); -int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc, - unsigned char *kstr,int klen,int (*cb)()); -int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc, - unsigned char *kstr,int klen,int (*cb)()); -int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x); -int PEM_write_bio_DHparams(BIO *bp,DH *x); -int PEM_write_bio_DSAparams(BIO *bp,DSA *x); +DECLARE_PEM_rw(X509, X509) + +DECLARE_PEM_rw(X509_REQ, X509_REQ) + +DECLARE_PEM_rw(X509_CRL, X509_CRL) + +DECLARE_PEM_rw(PKCS7, PKCS7) + +DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) + +DECLARE_PEM_rw(PKCS8, X509_SIG) + +DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) + +#ifndef NO_RSA + +DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) + +DECLARE_PEM_rw(RSAPublicKey, RSA) + #endif -#endif /* SSLEAY_MACROS */ +#ifndef NO_DSA +DECLARE_PEM_rw_cb(DSAPrivateKey, DSA) -#else +DECLARE_PEM_rw(DSAparams, DSA) -int PEM_get_EVP_CIPHER_INFO(); -int PEM_do_header(); -int PEM_read_bio(); -int PEM_write_bio(); -#ifndef WIN16 -int PEM_read(); -int PEM_write(); -STACK * PEM_X509_INFO_read(); -char * PEM_ASN1_read(); -int PEM_ASN1_write(); #endif -STACK * PEM_X509_INFO_read_bio(); -int PEM_X509_INFO_write_bio(); -char * PEM_ASN1_read_bio(); -int PEM_ASN1_write_bio(); -int PEM_SealInit(); -void PEM_SealUpdate(); -int PEM_SealFinal(); -int PEM_SignFinal(); -void ERR_load_PEM_strings(); +#ifndef NO_DH -void PEM_proc_type(); -void PEM_dek_info(); +DECLARE_PEM_rw(DHparams, DH) -#ifndef SSLEAY_MACROS -#ifndef WIN16 -X509 *PEM_read_X509(); -X509_REQ *PEM_read_X509_REQ(); -X509_CRL *PEM_read_X509_CRL(); -RSA *PEM_read_RSAPrivateKey(); -RSA *PEM_read_RSAPublicKey(); -DSA *PEM_read_DSAPrivateKey(); -EVP_PKEY *PEM_read_PrivateKey(); -PKCS7 *PEM_read_PKCS7(); -DH *PEM_read_DHparams(); -DSA *PEM_read_DSAparams(); -int PEM_write_X509(); -int PEM_write_X509_REQ(); -int PEM_write_X509_CRL(); -int PEM_write_RSAPrivateKey(); -int PEM_write_RSAPublicKey(); -int PEM_write_DSAPrivateKey(); -int PEM_write_PrivateKey(); -int PEM_write_PKCS7(); -int PEM_write_DHparams(); -int PEM_write_DSAparams(); #endif -X509 *PEM_read_bio_X509(); -X509_REQ *PEM_read_bio_X509_REQ(); -X509_CRL *PEM_read_bio_X509_CRL(); -RSA *PEM_read_bio_RSAPrivateKey(); -RSA *PEM_read_bio_RSAPublicKey(); -DSA *PEM_read_bio_DSAPrivateKey(); -EVP_PKEY *PEM_read_bio_PrivateKey(); -PKCS7 *PEM_read_bio_PKCS7(); -DH *PEM_read_bio_DHparams(); -DSA *PEM_read_bio_DSAparams(); -int PEM_write_bio_X509(); -int PEM_write_bio_X509_REQ(); -int PEM_write_bio_X509_CRL(); -int PEM_write_bio_RSAPrivateKey(); -int PEM_write_bio_RSAPublicKey(); -int PEM_write_bio_DSAPrivateKey(); -int PEM_write_bio_PrivateKey(); -int PEM_write_bio_PKCS7(); -int PEM_write_bio_DHparams(); -int PEM_write_bio_DSAparams(); +DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) +int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, + char *, int, pem_password_cb *, void *); +int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, + char *kstr,int klen, pem_password_cb *cd, void *u); #endif /* SSLEAY_MACROS */ -#endif /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the PEM functions. */ /* Function codes. */ @@ -526,6 +586,7 @@ int PEM_write_bio_DSAparams(); #define PEM_F_PEM_ASN1_WRITE 104 #define PEM_F_PEM_ASN1_WRITE_BIO 105 #define PEM_F_PEM_DO_HEADER 106 +#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 #define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 #define PEM_F_PEM_READ 108 #define PEM_F_PEM_READ_BIO 109 @@ -534,6 +595,7 @@ int PEM_write_bio_DSAparams(); #define PEM_F_PEM_SIGNFINAL 112 #define PEM_F_PEM_WRITE 113 #define PEM_F_PEM_WRITE_BIO 114 +#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119 #define PEM_F_PEM_X509_INFO_READ 115 #define PEM_F_PEM_X509_INFO_READ_BIO 116 #define PEM_F_PEM_X509_INFO_WRITE_BIO 117 @@ -544,6 +606,7 @@ int PEM_write_bio_DSAparams(); #define PEM_R_BAD_END_LINE 102 #define PEM_R_BAD_IV_CHARS 103 #define PEM_R_BAD_PASSWORD_READ 104 +#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115 #define PEM_R_NOT_DEK_INFO 105 #define PEM_R_NOT_ENCRYPTED 106 #define PEM_R_NOT_PROC_TYPE 107 @@ -554,7 +617,7 @@ int PEM_write_bio_DSAparams(); #define PEM_R_SHORT_HEADER 112 #define PEM_R_UNSUPPORTED_CIPHER 113 #define PEM_R_UNSUPPORTED_ENCRYPTION 114 - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/pem/pem.org b/src/lib/libcrypto/pem/pem.org deleted file mode 100644 index 38952509dd..0000000000 --- a/src/lib/libcrypto/pem/pem.org +++ /dev/null @@ -1,562 +0,0 @@ -/* crypto/pem/pem.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify pem.org since pem.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - -#ifndef HEADER_PEM_H -#define HEADER_PEM_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "evp.h" -#include "x509.h" - -#define PEM_OBJ_UNDEF 0 -#define PEM_OBJ_X509 1 -#define PEM_OBJ_X509_REQ 2 -#define PEM_OBJ_CRL 3 -#define PEM_OBJ_SSL_SESSION 4 -#define PEM_OBJ_PRIV_KEY 10 -#define PEM_OBJ_PRIV_RSA 11 -#define PEM_OBJ_PRIV_DSA 12 -#define PEM_OBJ_PRIV_DH 13 -#define PEM_OBJ_PUB_RSA 14 -#define PEM_OBJ_PUB_DSA 15 -#define PEM_OBJ_PUB_DH 16 -#define PEM_OBJ_DHPARAMS 17 -#define PEM_OBJ_DSAPARAMS 18 -#define PEM_OBJ_PRIV_RSA_PUBLIC 19 - -#define PEM_ERROR 30 -#define PEM_DEK_DES_CBC 40 -#define PEM_DEK_IDEA_CBC 45 -#define PEM_DEK_DES_EDE 50 -#define PEM_DEK_DES_ECB 60 -#define PEM_DEK_RSA 70 -#define PEM_DEK_RSA_MD2 80 -#define PEM_DEK_RSA_MD5 90 - -#define PEM_MD_MD2 NID_md2 -#define PEM_MD_MD5 NID_md5 -#define PEM_MD_SHA NID_sha -#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption -#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption -#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption - -#define PEM_STRING_X509_OLD "X509 CERTIFICATE" -#define PEM_STRING_X509 "CERTIFICATE" -#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" -#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" -#define PEM_STRING_X509_CRL "X509 CRL" -#define PEM_STRING_EVP_PKEY "PRIVATE KEY" -#define PEM_STRING_RSA "RSA PRIVATE KEY" -#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" -#define PEM_STRING_DSA "DSA PRIVATE KEY" -#define PEM_STRING_PKCS7 "PKCS7" -#define PEM_STRING_DHPARAMS "DH PARAMETERS" -#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" -#define PEM_STRING_DSAPARAMS "DSA PARAMETERS" - -#ifndef HEADER_ENVELOPE_H - -#define EVP_ENCODE_CTX_SIZE 92 -#define EVP_MD_SIZE 48 -#define EVP_MD_CTX_SIZE 152 -#define EVP_CIPHER_SIZE 28 -#define EVP_CIPHER_CTX_SIZE 4212 -#define EVP_MAX_MD_SIZE 20 - -typedef struct evp_encode_ctx_st - { - char data[EVP_ENCODE_CTX_SIZE]; - } EVP_ENCODE_CTX; - -typedef struct env_md_ctx_st - { - char data[EVP_MD_CTX_SIZE]; - } EVP_MD_CTX; - -typedef struct evp_cipher_st - { - char data[EVP_CIPHER_SIZE]; - } EVP_CIPHER; - -typedef struct evp_cipher_ctx_st - { - char data[EVP_CIPHER_CTX_SIZE]; - } EVP_CIPHER_CTX; -#endif - - -typedef struct PEM_Encode_Seal_st - { - EVP_ENCODE_CTX encode; - EVP_MD_CTX md; - EVP_CIPHER_CTX cipher; - } PEM_ENCODE_SEAL_CTX; - -/* enc_type is one off */ -#define PEM_TYPE_ENCRYPTED 10 -#define PEM_TYPE_MIC_ONLY 20 -#define PEM_TYPE_MIC_CLEAR 30 -#define PEM_TYPE_CLEAR 40 - -typedef struct pem_recip_st - { - char *name; - X509_NAME *dn; - - int cipher; - int key_enc; - char iv[8]; - } PEM_USER; - -typedef struct pem_ctx_st - { - int type; /* what type of object */ - - struct { - int version; - int mode; - } proc_type; - - char *domain; - - struct { - int cipher; - unsigned char iv[8]; - } DEK_info; - - PEM_USER *originator; - - int num_recipient; - PEM_USER **recipient; - -#ifdef HEADER_STACK_H - STACK *x509_chain; /* certificate chain */ -#else - char *x509_chain; /* certificate chain */ -#endif - EVP_MD *md; /* signature type */ - - int md_enc; /* is the md encrypted or not? */ - int md_len; /* length of md_data */ - char *md_data; /* message digest, could be pkey encrypted */ - - EVP_CIPHER *dec; /* date encryption cipher */ - int key_len; /* key length */ - unsigned char *key; /* key */ - unsigned char iv[8]; /* the iv */ - - - int data_enc; /* is the data encrypted */ - int data_len; - unsigned char *data; - } PEM_CTX; - -#ifdef SSLEAY_MACROS - -#define PEM_write_SSL_SESSION(fp,x) \ - PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ - PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL) -#define PEM_write_X509(fp,x) \ - PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ - (char *)x, NULL,NULL,0,NULL) -#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ - (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ - NULL,NULL,0,NULL) -#define PEM_write_X509_CRL(fp,x) \ - PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ - fp,(char *)x, NULL,NULL,0,NULL) -#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \ - PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ - (char *)x,enc,kstr,klen,cb) -#define PEM_write_RSAPublicKey(fp,x) \ - PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ - PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL) -#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \ - PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ - (char *)x,enc,kstr,klen,cb) -#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \ - PEM_ASN1_write((int (*)())i2d_PrivateKey,\ - (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ - bp,(char *)x,enc,kstr,klen,cb) -#define PEM_write_PKCS7(fp,x) \ - PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ - (char *)x, NULL,NULL,0,NULL) -#define PEM_write_DHparams(fp,x) \ - PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ - (char *)x,NULL,NULL,0,NULL) - -#define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \ - (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb) -#define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \ - (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb) -#define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \ - (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb) -#define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \ - (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb) -#define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ - (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb) -#define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ - (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb) -#define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \ - (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb) -#define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \ - (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb) -#define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \ - (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb) -#define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \ - (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb) - -#define PEM_write_bio_SSL_SESSION(bp,x) \ - PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ - PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL) -#define PEM_write_bio_X509(bp,x) \ - PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ - (char *)x, NULL,NULL,0,NULL) -#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ - (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ - NULL,NULL,0,NULL) -#define PEM_write_bio_X509_CRL(bp,x) \ - PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ - bp,(char *)x, NULL,NULL,0,NULL) -#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \ - PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ - bp,(char *)x,enc,kstr,klen,cb) -#define PEM_write_bio_RSAPublicKey(bp,x) \ - PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ - PEM_STRING_RSA_PUBLIC,\ - bp,(char *)x,NULL,NULL,0,NULL) -#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \ - PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ - bp,(char *)x,enc,kstr,klen,cb) -#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \ - PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ - (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ - bp,(char *)x,enc,kstr,klen,cb) -#define PEM_write_bio_PKCS7(bp,x) \ - PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ - (char *)x, NULL,NULL,0,NULL) -#define PEM_write_bio_DHparams(bp,x) \ - PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ - bp,(char *)x,NULL,NULL,0,NULL) -#define PEM_write_bio_DSAparams(bp,x) \ - PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ - PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL) - -#define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb) -#define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb) -#define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb) -#define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb) -#define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb) -#define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb) -#define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb) -#define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb) - -#define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb) -#define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb) -#define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ - (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb) - -#endif - -#ifndef NOPROTO -int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); -int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, - int (*callback)()); - -#ifdef HEADER_BIO_H -int PEM_read_bio(BIO *bp, char **name, char **header, - unsigned char **data,long *len); -int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data, - long len); -char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x, - int (*cb)()); -int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x, - EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); -STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)()); -int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, - unsigned char *kstr, int klen, int (*cb)()); -#endif - -#ifndef WIN16 -int PEM_read(FILE *fp, char **name, char **header, - unsigned char **data,long *len); -int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); -char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x, - int (*cb)()); -int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x, - EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); -STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)()); -#endif - -int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, - EVP_MD *md_type, unsigned char **ek, int *ekl, - unsigned char *iv, EVP_PKEY **pubk, int npubk); -void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, - unsigned char *in, int inl); -int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl, - unsigned char *out, int *outl, EVP_PKEY *priv); - -void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type); -void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); -int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, - unsigned int *siglen, EVP_PKEY *pkey); - -void ERR_load_PEM_strings(void); - -void PEM_proc_type(char *buf, int type); -void PEM_dek_info(char *buf, char *type, int len, char *str); - -#ifndef SSLEAY_MACROS - -#ifndef WIN16 -X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)()); -X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)()); -X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)()); -RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)()); -RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)()); -DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)()); -EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)()); -PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)()); -DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)()); -DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)()); -int PEM_write_X509(FILE *fp,X509 *x); -int PEM_write_X509_REQ(FILE *fp,X509_REQ *x); -int PEM_write_X509_CRL(FILE *fp,X509_CRL *x); -int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr, - int klen,int (*cb)()); -int PEM_write_RSAPublicKey(FILE *fp,RSA *x); -int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr, - int klen,int (*cb)()); -int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc, - unsigned char *kstr,int klen,int (*cb)()); -int PEM_write_PKCS7(FILE *fp,PKCS7 *x); -int PEM_write_DHparams(FILE *fp,DH *x); -int PEM_write_DSAparams(FILE *fp,DSA *x); -#endif - -#ifdef HEADER_BIO_H -X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)()); -X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)()); -X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)()); -RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)()); -RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)()); -DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)()); -EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)()); -PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)()); -DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)()); -DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)()); -int PEM_write_bio_X509(BIO *bp,X509 *x); -int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x); -int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x); -int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc, - unsigned char *kstr,int klen,int (*cb)()); -int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x); -int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc, - unsigned char *kstr,int klen,int (*cb)()); -int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc, - unsigned char *kstr,int klen,int (*cb)()); -int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x); -int PEM_write_bio_DHparams(BIO *bp,DH *x); -int PEM_write_bio_DSAparams(BIO *bp,DSA *x); -#endif - -#endif /* SSLEAY_MACROS */ - - -#else - -int PEM_get_EVP_CIPHER_INFO(); -int PEM_do_header(); -int PEM_read_bio(); -int PEM_write_bio(); -#ifndef WIN16 -int PEM_read(); -int PEM_write(); -STACK * PEM_X509_INFO_read(); -char * PEM_ASN1_read(); -int PEM_ASN1_write(); -#endif -STACK * PEM_X509_INFO_read_bio(); -int PEM_X509_INFO_write_bio(); -char * PEM_ASN1_read_bio(); -int PEM_ASN1_write_bio(); -int PEM_SealInit(); -void PEM_SealUpdate(); -int PEM_SealFinal(); -int PEM_SignFinal(); - -void ERR_load_PEM_strings(); - -void PEM_proc_type(); -void PEM_dek_info(); - -#ifndef SSLEAY_MACROS -#ifndef WIN16 -X509 *PEM_read_X509(); -X509_REQ *PEM_read_X509_REQ(); -X509_CRL *PEM_read_X509_CRL(); -RSA *PEM_read_RSAPrivateKey(); -RSA *PEM_read_RSAPublicKey(); -DSA *PEM_read_DSAPrivateKey(); -EVP_PKEY *PEM_read_PrivateKey(); -PKCS7 *PEM_read_PKCS7(); -DH *PEM_read_DHparams(); -DSA *PEM_read_DSAparams(); -int PEM_write_X509(); -int PEM_write_X509_REQ(); -int PEM_write_X509_CRL(); -int PEM_write_RSAPrivateKey(); -int PEM_write_RSAPublicKey(); -int PEM_write_DSAPrivateKey(); -int PEM_write_PrivateKey(); -int PEM_write_PKCS7(); -int PEM_write_DHparams(); -int PEM_write_DSAparams(); -#endif - -X509 *PEM_read_bio_X509(); -X509_REQ *PEM_read_bio_X509_REQ(); -X509_CRL *PEM_read_bio_X509_CRL(); -RSA *PEM_read_bio_RSAPrivateKey(); -RSA *PEM_read_bio_RSAPublicKey(); -DSA *PEM_read_bio_DSAPrivateKey(); -EVP_PKEY *PEM_read_bio_PrivateKey(); -PKCS7 *PEM_read_bio_PKCS7(); -DH *PEM_read_bio_DHparams(); -DSA *PEM_read_bio_DSAparams(); -int PEM_write_bio_X509(); -int PEM_write_bio_X509_REQ(); -int PEM_write_bio_X509_CRL(); -int PEM_write_bio_RSAPrivateKey(); -int PEM_write_bio_RSAPublicKey(); -int PEM_write_bio_DSAPrivateKey(); -int PEM_write_bio_PrivateKey(); -int PEM_write_bio_PKCS7(); -int PEM_write_bio_DHparams(); -int PEM_write_bio_DSAparams(); - -#endif /* SSLEAY_MACROS */ - -#endif - -/* BEGIN ERROR CODES */ -/* Error codes for the PEM functions. */ - -/* Function codes. */ -#define PEM_F_DEF_CALLBACK 100 -#define PEM_F_LOAD_IV 101 -#define PEM_F_PEM_ASN1_READ 102 -#define PEM_F_PEM_ASN1_READ_BIO 103 -#define PEM_F_PEM_ASN1_WRITE 104 -#define PEM_F_PEM_ASN1_WRITE_BIO 105 -#define PEM_F_PEM_DO_HEADER 106 -#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 -#define PEM_F_PEM_READ 108 -#define PEM_F_PEM_READ_BIO 109 -#define PEM_F_PEM_SEALFINAL 110 -#define PEM_F_PEM_SEALINIT 111 -#define PEM_F_PEM_SIGNFINAL 112 -#define PEM_F_PEM_WRITE 113 -#define PEM_F_PEM_WRITE_BIO 114 -#define PEM_F_PEM_X509_INFO_READ 115 -#define PEM_F_PEM_X509_INFO_READ_BIO 116 -#define PEM_F_PEM_X509_INFO_WRITE_BIO 117 - -/* Reason codes. */ -#define PEM_R_BAD_BASE64_DECODE 100 -#define PEM_R_BAD_DECRYPT 101 -#define PEM_R_BAD_END_LINE 102 -#define PEM_R_BAD_IV_CHARS 103 -#define PEM_R_BAD_PASSWORD_READ 104 -#define PEM_R_NOT_DEK_INFO 105 -#define PEM_R_NOT_ENCRYPTED 106 -#define PEM_R_NOT_PROC_TYPE 107 -#define PEM_R_NO_START_LINE 108 -#define PEM_R_PROBLEMS_GETTING_PASSWORD 109 -#define PEM_R_PUBLIC_KEY_NO_RSA 110 -#define PEM_R_READ_KEY 111 -#define PEM_R_SHORT_HEADER 112 -#define PEM_R_UNSUPPORTED_CIPHER 113 -#define PEM_R_UNSUPPORTED_ENCRYPTION 114 - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/src/lib/libcrypto/pem/pem2.h b/src/lib/libcrypto/pem/pem2.h new file mode 100644 index 0000000000..4a016aacd2 --- /dev/null +++ b/src/lib/libcrypto/pem/pem2.h @@ -0,0 +1,60 @@ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + * This header only exists to break a circular dependency between pem and err + * Ben 30 Jan 1999. + */ + +void ERR_load_PEM_strings(void); diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c index d1cda7aabe..bc473f3cff 100644 --- a/src/lib/libcrypto/pem/pem_all.c +++ b/src/lib/libcrypto/pem/pem_all.c @@ -59,430 +59,55 @@ #include #undef SSLEAY_MACROS #include "cryptlib.h" -#include "bio.h" -#include "evp.h" -#include "x509.h" -#include "pkcs7.h" -#include "pem.h" +#include +#include +#include +#include +#include -#ifndef NO_FP_API -/* The X509 functions */ -X509 *PEM_read_X509(fp,x,cb) -FILE *fp; -X509 **x; -int (*cb)(); - { - return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509, - PEM_STRING_X509,fp,(char **)x,cb)); - } -#endif - -X509 *PEM_read_bio_X509(bp,x,cb) -BIO *bp; -X509 **x; -int (*cb)(); - { - return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509, - PEM_STRING_X509,bp,(char **)x,cb)); - } - -#ifndef NO_FP_API -int PEM_write_X509(fp,x) -FILE *fp; -X509 *x; - { - return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, - (char *)x, NULL,NULL,0,NULL)); - } -#endif +IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509) -int PEM_write_bio_X509(bp,x) -BIO *bp; -X509 *x; - { - return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, - (char *)x, NULL,NULL,0,NULL)); - } +IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ) -#ifndef NO_FP_API -/* The X509_REQ functions */ -X509_REQ *PEM_read_X509_REQ(fp,x,cb) -FILE *fp; -X509_REQ **x; -int (*cb)(); - { - return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ, - PEM_STRING_X509_REQ,fp,(char **)x,cb)); - } -#endif +IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL) -X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb) -BIO *bp; -X509_REQ **x; -int (*cb)(); - { - return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ, - PEM_STRING_X509_REQ,bp,(char **)x,cb)); - } +IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7) -#ifndef NO_FP_API -int PEM_write_X509_REQ(fp,x) -FILE *fp; -X509_REQ *x; - { - return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp, - (char *)x, NULL,NULL,0,NULL)); - } -#endif +IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE, + PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE) -int PEM_write_bio_X509_REQ(bp,x) -BIO *bp; -X509_REQ *x; - { - return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ, - bp,(char *)x, NULL,NULL,0,NULL)); - } - -#ifndef NO_FP_API -/* The X509_CRL functions */ -X509_CRL *PEM_read_X509_CRL(fp,x,cb) -FILE *fp; -X509_CRL **x; -int (*cb)(); - { - return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL, - PEM_STRING_X509_CRL,fp,(char **)x,cb)); - } -#endif - -X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb) -BIO *bp; -X509_CRL **x; -int (*cb)(); - { - return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL, - PEM_STRING_X509_CRL,bp,(char **)x,cb)); - } - -#ifndef NO_FP_API -int PEM_write_X509_CRL(fp,x) -FILE *fp; -X509_CRL *x; - { - return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp, - (char *)x, NULL,NULL,0,NULL)); - } -#endif - -int PEM_write_bio_X509_CRL(bp,x) -BIO *bp; -X509_CRL *x; - { - return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, - bp,(char *)x, NULL,NULL,0,NULL)); - } +IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG) +IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF, + PKCS8_PRIV_KEY_INFO) #ifndef NO_RSA -#ifndef NO_FP_API -/* The RSAPrivateKey functions */ -RSA *PEM_read_RSAPrivateKey(fp,x,cb) -FILE *fp; -RSA **x; -int (*cb)(); - { - return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey, - PEM_STRING_RSA,fp,(char **)x,cb)); - } - -RSA *PEM_read_RSAPublicKey(fp,x,cb) -FILE *fp; -RSA **x; -int (*cb)(); - { - return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey, - PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb)); - } -#endif -RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb) -BIO *bp; -RSA **x; -int (*cb)(); - { - return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey, - PEM_STRING_RSA,bp,(char **)x,cb)); - } +IMPLEMENT_PEM_rw_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey) -RSA *PEM_read_bio_RSAPublicKey(bp,x,cb) -BIO *bp; -RSA **x; -int (*cb)(); - { - return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey, - PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb)); - } +IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey) -#ifndef NO_FP_API -int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) -FILE *fp; -RSA *x; -EVP_CIPHER *enc; -unsigned char *kstr; -int klen; -int (*cb)(); - { - return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp, - (char *)x,enc,kstr,klen,cb)); - } - -int PEM_write_RSAPublicKey(fp,x) -FILE *fp; -RSA *x; - { - return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey, - PEM_STRING_RSA_PUBLIC,fp, - (char *)x,NULL,NULL,0,NULL)); - } #endif -int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) -BIO *bp; -RSA *x; -EVP_CIPHER *enc; -unsigned char *kstr; -int klen; -int (*cb)(); - { - return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA, - bp,(char *)x,enc,kstr,klen,cb)); - } - -int PEM_write_bio_RSAPublicKey(bp,x) -BIO *bp; -RSA *x; - { - return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, - PEM_STRING_RSA_PUBLIC, - bp,(char *)x,NULL,NULL,0,NULL)); - } -#endif /* !NO_RSA */ - #ifndef NO_DSA -#ifndef NO_FP_API -/* The DSAPrivateKey functions */ -DSA *PEM_read_DSAPrivateKey(fp,x,cb) -FILE *fp; -DSA **x; -int (*cb)(); - { - return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey, - PEM_STRING_DSA,fp,(char **)x,cb)); - } -#endif - -DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb) -BIO *bp; -DSA **x; -int (*cb)(); - { - return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey, - PEM_STRING_DSA,bp,(char **)x,cb)); - } - -#ifndef NO_FP_API -int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) -FILE *fp; -DSA *x; -EVP_CIPHER *enc; -unsigned char *kstr; -int klen; -int (*cb)(); - { - return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp, - (char *)x,enc,kstr,klen,cb)); - } -#endif -int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) -BIO *bp; -DSA *x; -EVP_CIPHER *enc; -unsigned char *kstr; -int klen; -int (*cb)(); - { - return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA, - bp,(char *)x,enc,kstr,klen,cb)); - } -#endif - -#ifndef NO_FP_API -/* The PrivateKey functions */ -EVP_PKEY *PEM_read_PrivateKey(fp,x,cb) -FILE *fp; -EVP_PKEY **x; -int (*cb)(); - { - return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey, - PEM_STRING_EVP_PKEY,fp,(char **)x,cb)); - } -#endif - -EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb) -BIO *bp; -EVP_PKEY **x; -int (*cb)(); - { - return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey, - PEM_STRING_EVP_PKEY,bp,(char **)x,cb)); - } - -#ifndef NO_FP_API -int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb) -FILE *fp; -EVP_PKEY *x; -EVP_CIPHER *enc; -unsigned char *kstr; -int klen; -int (*cb)(); - { - return(PEM_ASN1_write((int (*)())i2d_PrivateKey, - ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), - fp,(char *)x,enc,kstr,klen,cb)); - } -#endif +IMPLEMENT_PEM_rw_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey) -int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) -BIO *bp; -EVP_PKEY *x; -EVP_CIPHER *enc; -unsigned char *kstr; -int klen; -int (*cb)(); - { - return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey, - ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), - bp,(char *)x,enc,kstr,klen,cb)); - } +IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams) -#ifndef NO_FP_API -/* The PKCS7 functions */ -PKCS7 *PEM_read_PKCS7(fp,x,cb) -FILE *fp; -PKCS7 **x; -int (*cb)(); - { - return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7, - PEM_STRING_PKCS7,fp,(char **)x,cb)); - } #endif -PKCS7 *PEM_read_bio_PKCS7(bp,x,cb) -BIO *bp; -PKCS7 **x; -int (*cb)(); - { - return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7, - PEM_STRING_PKCS7,bp,(char **)x,cb)); - } - -#ifndef NO_FP_API -int PEM_write_PKCS7(fp,x) -FILE *fp; -PKCS7 *x; - { - return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, - (char *)x, NULL,NULL,0,NULL)); - } -#endif - -int PEM_write_bio_PKCS7(bp,x) -BIO *bp; -PKCS7 *x; - { - return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, - (char *)x, NULL,NULL,0,NULL)); - } - #ifndef NO_DH -#ifndef NO_FP_API -/* The DHparams functions */ -DH *PEM_read_DHparams(fp,x,cb) -FILE *fp; -DH **x; -int (*cb)(); - { - return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams, - PEM_STRING_DHPARAMS,fp,(char **)x,cb)); - } -#endif -DH *PEM_read_bio_DHparams(bp,x,cb) -BIO *bp; -DH **x; -int (*cb)(); - { - return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams, - PEM_STRING_DHPARAMS,bp,(char **)x,cb)); - } +IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams) -#ifndef NO_FP_API -int PEM_write_DHparams(fp,x) -FILE *fp; -DH *x; - { - return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp, - (char *)x, NULL,NULL,0,NULL)); - } #endif -int PEM_write_bio_DHparams(bp,x) -BIO *bp; -DH *x; - { - return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS, - bp,(char *)x, NULL,NULL,0,NULL)); - } -#endif - -#ifndef NO_DSA -#ifndef NO_FP_API -/* The DSAparams functions */ -DSA *PEM_read_DSAparams(fp,x,cb) -FILE *fp; -DSA **x; -int (*cb)(); - { - return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams, - PEM_STRING_DSAPARAMS,fp,(char **)x,cb)); - } -#endif - -DSA *PEM_read_bio_DSAparams(bp,x,cb) -BIO *bp; -DSA **x; -int (*cb)(); - { - return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams, - PEM_STRING_DSAPARAMS,bp,(char **)x,cb)); - } - -#ifndef NO_FP_API -int PEM_write_DSAparams(fp,x) -FILE *fp; -DSA *x; - { - return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp, - (char *)x, NULL,NULL,0,NULL)); - } -#endif - -int PEM_write_bio_DSAparams(bp,x) -BIO *bp; -DSA *x; - { - return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS, - bp,(char *)x, NULL,NULL,0,NULL)); - } -#endif +/* The PrivateKey case is not that straightforward. + * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey) + * does not work, RSA and DSA keys have specific strings. + * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything + * appropriate.) + */ +IMPLEMENT_PEM_read(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey) +IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey) diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c index e17fcdb540..fa70f60998 100644 --- a/src/lib/libcrypto/pem/pem_err.c +++ b/src/lib/libcrypto/pem/pem_err.c @@ -1,63 +1,65 @@ -/* lib/pem/pem_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/pem/pem_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "pem.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -70,6 +72,7 @@ static ERR_STRING_DATA PEM_str_functs[]= {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"}, {ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"}, {ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"}, +{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"}, {ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"}, {ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"}, {ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"}, @@ -78,10 +81,11 @@ static ERR_STRING_DATA PEM_str_functs[]= {ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"}, {ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"}, {ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"}, +{ERR_PACK(0,PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,0), "PEM_write_bio_PKCS8PrivateKey"}, {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"}, {ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"}, {ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"}, -{0,NULL}, +{0,NULL} }; static ERR_STRING_DATA PEM_str_reasons[]= @@ -91,6 +95,7 @@ static ERR_STRING_DATA PEM_str_reasons[]= {PEM_R_BAD_END_LINE ,"bad end line"}, {PEM_R_BAD_IV_CHARS ,"bad iv chars"}, {PEM_R_BAD_PASSWORD_READ ,"bad password read"}, +{PEM_R_ERROR_CONVERTING_PRIVATE_KEY ,"error converting private key"}, {PEM_R_NOT_DEK_INFO ,"not dek info"}, {PEM_R_NOT_ENCRYPTED ,"not encrypted"}, {PEM_R_NOT_PROC_TYPE ,"not proc type"}, @@ -101,17 +106,17 @@ static ERR_STRING_DATA PEM_str_reasons[]= {PEM_R_SHORT_HEADER ,"short header"}, {PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, {PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_PEM_strings() +void ERR_load_PEM_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_PEM,PEM_str_functs); diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c index 4b69833b62..fec18a4c2e 100644 --- a/src/lib/libcrypto/pem/pem_info.c +++ b/src/lib/libcrypto/pem/pem_info.c @@ -58,20 +58,17 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "objects.h" -#include "evp.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include +#include #ifndef NO_FP_API -STACK *PEM_X509_INFO_read(fp,sk,cb) -FILE *fp; -STACK *sk; -int (*cb)(); +STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) { BIO *b; - STACK *ret; + STACK_OF(X509_INFO) *ret; if ((b=BIO_new(BIO_s_file())) == NULL) { @@ -79,29 +76,26 @@ int (*cb)(); return(0); } BIO_set_fp(b,fp,BIO_NOCLOSE); - ret=PEM_X509_INFO_read_bio(b,sk,cb); + ret=PEM_X509_INFO_read_bio(b,sk,cb,u); BIO_free(b); return(ret); } #endif -STACK *PEM_X509_INFO_read_bio(bp,sk,cb) -BIO *bp; -STACK *sk; -int (*cb)(); +STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) { X509_INFO *xi=NULL; char *name=NULL,*header=NULL,**pp; unsigned char *data=NULL,*p; long len,error=0; int ok=0; - STACK *ret=NULL; + STACK_OF(X509_INFO) *ret=NULL; unsigned int i,raw; char *(*d2i)(); if (sk == NULL) { - if ((ret=sk_new_null()) == NULL) + if ((ret=sk_X509_INFO_new_null()) == NULL) { PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; @@ -132,7 +126,7 @@ start: d2i=(char *(*)())d2i_X509; if (xi->x509 != NULL) { - if (!sk_push(ret,(char *)xi)) goto err; + if (!sk_X509_INFO_push(ret,xi)) goto err; if ((xi=X509_INFO_new()) == NULL) goto err; goto start; } @@ -143,7 +137,7 @@ start: d2i=(char *(*)())d2i_X509_CRL; if (xi->crl != NULL) { - if (!sk_push(ret,(char *)xi)) goto err; + if (!sk_X509_INFO_push(ret,xi)) goto err; if ((xi=X509_INFO_new()) == NULL) goto err; goto start; } @@ -156,7 +150,7 @@ start: d2i=(char *(*)())d2i_RSAPrivateKey; if (xi->x_pkey != NULL) { - if (!sk_push(ret,(char *)xi)) goto err; + if (!sk_X509_INFO_push(ret,xi)) goto err; if ((xi=X509_INFO_new()) == NULL) goto err; goto start; } @@ -180,7 +174,7 @@ start: d2i=(char *(*)())d2i_DSAPrivateKey; if (xi->x_pkey != NULL) { - if (!sk_push(ret,(char *)xi)) goto err; + if (!sk_X509_INFO_push(ret,xi)) goto err; if ((xi=X509_INFO_new()) == NULL) goto err; goto start; } @@ -211,7 +205,7 @@ start: if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; - if (!PEM_do_header(&cipher,data,&len,cb)) + if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err; p=data; if (d2i(pp,&p,len) == NULL) @@ -246,7 +240,7 @@ start: if ((xi->x509 != NULL) || (xi->crl != NULL) || (xi->x_pkey != NULL) || (xi->enc_data != NULL)) { - if (!sk_push(ret,(char *)xi)) goto err; + if (!sk_X509_INFO_push(ret,xi)) goto err; xi=NULL; } ok=1; @@ -254,12 +248,12 @@ err: if (xi != NULL) X509_INFO_free(xi); if (!ok) { - for (i=0; ((int)i)x_pkey->dec_pkey->pkey.rsa, - enc,kstr,klen,cb)<=0) + enc,kstr,klen,cb,u)<=0) goto err; #endif } diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c index 7a2c0ad83b..90f02011ba 100644 --- a/src/lib/libcrypto/pem/pem_lib.c +++ b/src/lib/libcrypto/pem/pem_lib.c @@ -58,36 +58,25 @@ #include #include "cryptlib.h" -#include "buffer.h" -#include "objects.h" -#include "evp.h" -#include "rand.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include +#include +#include +#include #ifndef NO_DES -#include "des.h" +#include #endif -char *PEM_version="PEM part of SSLeay 0.9.0b 29-Jun-1998"; +const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT; #define MIN_LENGTH 4 -/* PEMerr(PEM_F_PEM_WRITE_BIO,ERR_R_MALLOC_FAILURE); - * PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); - */ - -#ifndef NOPROTO -static int def_callback(char *buf, int num, int w); +static int def_callback(char *buf, int num, int w, void *userdata); static int load_iv(unsigned char **fromp,unsigned char *to, int num); -#else -static int def_callback(); -static int load_iv(); -#endif -static int def_callback(buf, num, w) -char *buf; -int num; -int w; +static int def_callback(char *buf, int num, int w, void *userdata) { #ifdef NO_FP_API /* We should not ever call the default callback routine from @@ -96,7 +85,7 @@ int w; return(-1); #else int i,j; - char *prompt; + const char *prompt; prompt=EVP_get_pw_prompt(); if (prompt == NULL) @@ -123,11 +112,9 @@ int w; #endif } -void PEM_proc_type(buf, type) -char *buf; -int type; +void PEM_proc_type(char *buf, int type) { - char *str; + const char *str; if (type == PEM_TYPE_ENCRYPTED) str="ENCRYPTED"; @@ -143,11 +130,7 @@ int type; strcat(buf,"\n"); } -void PEM_dek_info(buf, type, len, str) -char *buf; -char *type; -int len; -char *str; +void PEM_dek_info(char *buf, const char *type, int len, char *str) { static unsigned char map[17]="0123456789ABCDEF"; long i; @@ -167,12 +150,8 @@ char *str; } #ifndef NO_FP_API -char *PEM_ASN1_read(d2i,name,fp, x, cb) -char *(*d2i)(); -char *name; -FILE *fp; -char **x; -int (*cb)(); +char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x, + pem_password_cb *cb, void *u) { BIO *b; char *ret; @@ -183,18 +162,14 @@ int (*cb)(); return(0); } BIO_set_fp(b,fp,BIO_NOCLOSE); - ret=PEM_ASN1_read_bio(d2i,name,b,x,cb); + ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u); BIO_free(b); return(ret); } #endif -char *PEM_ASN1_read_bio(d2i,name,bp, x, cb) -char *(*d2i)(); -char *name; -BIO *bp; -char **x; -int (*cb)(); +char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x, + pem_password_cb *cb, void *u) { EVP_CIPHER_INFO cipher; char *nm=NULL,*header=NULL; @@ -210,10 +185,14 @@ int (*cb)(); (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || ((strcmp(nm,PEM_STRING_DSA) == 0) && (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || + ((strcmp(nm,PEM_STRING_PKCS8) == 0) && + (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || + ((strcmp(nm,PEM_STRING_PKCS8INF) == 0) && + (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || ((strcmp(nm,PEM_STRING_X509_OLD) == 0) && (strcmp(name,PEM_STRING_X509) == 0)) || ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) && - (strcmp(name,PEM_STRING_X509_REQ) == 0)) + (strcmp(name,PEM_STRING_X509_REQ) == 0)) ) break; Free(nm); @@ -221,17 +200,41 @@ int (*cb)(); Free(data); } if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; - if (!PEM_do_header(&cipher,data,&len,cb)) goto err; + if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err; p=data; - if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) - { + if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) { if (strcmp(nm,PEM_STRING_RSA) == 0) ret=d2i(EVP_PKEY_RSA,x,&p,len); else if (strcmp(nm,PEM_STRING_DSA) == 0) ret=d2i(EVP_PKEY_DSA,x,&p,len); + else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) { + PKCS8_PRIV_KEY_INFO *p8inf; + p8inf=d2i_PKCS8_PRIV_KEY_INFO( + (PKCS8_PRIV_KEY_INFO **) x, &p, len); + ret = (char *)EVP_PKCS82PKEY(p8inf); + PKCS8_PRIV_KEY_INFO_free(p8inf); + } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) { + PKCS8_PRIV_KEY_INFO *p8inf; + X509_SIG *p8; + int klen; + char psbuf[PEM_BUFSIZE]; + p8 = d2i_X509_SIG((X509_SIG **)x, &p, len); + if(!p8) goto p8err; + if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u); + else klen=def_callback(psbuf,PEM_BUFSIZE,0,u); + if (klen <= 0) { + PEMerr(PEM_F_PEM_ASN1_READ_BIO, + PEM_R_BAD_PASSWORD_READ); + goto err; + } + p8inf = M_PKCS8_decrypt(p8, psbuf, klen); + X509_SIG_free(p8); + if(!p8inf) goto p8err; + ret = (char *)EVP_PKCS82PKEY(p8inf); + PKCS8_PRIV_KEY_INFO_free(p8inf); } - else - ret=d2i(x,&p,len); + } else ret=d2i(x,&p,len); +p8err: if (ret == NULL) PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); err: @@ -242,15 +245,9 @@ err: } #ifndef NO_FP_API -int PEM_ASN1_write(i2d,name,fp, x, enc, kstr, klen, callback) -int (*i2d)(); -char *name; -FILE *fp; -char *x; -EVP_CIPHER *enc; -unsigned char *kstr; -int klen; -int (*callback)(); +int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x, + const EVP_CIPHER *enc, unsigned char *kstr, int klen, + pem_password_cb *callback, void *u) { BIO *b; int ret; @@ -261,27 +258,20 @@ int (*callback)(); return(0); } BIO_set_fp(b,fp,BIO_NOCLOSE); - ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback); + ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u); BIO_free(b); return(ret); } #endif -int PEM_ASN1_write_bio(i2d,name,bp, x, enc, kstr, klen, callback) -int (*i2d)(); -char *name; -BIO *bp; -char *x; -EVP_CIPHER *enc; -unsigned char *kstr; -int klen; -int (*callback)(); +int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x, + const EVP_CIPHER *enc, unsigned char *kstr, int klen, + pem_password_cb *callback, void *u) { EVP_CIPHER_CTX ctx; int dsize=0,i,j,ret=0; unsigned char *p,*data=NULL; - char *objstr=NULL; -#define PEM_BUFSIZE 1024 + const char *objstr=NULL; char buf[PEM_BUFSIZE]; unsigned char key[EVP_MAX_KEY_LENGTH]; unsigned char iv[EVP_MAX_IV_LENGTH]; @@ -317,14 +307,18 @@ int (*callback)(); if (kstr == NULL) { if (callback == NULL) - klen=def_callback(buf,PEM_BUFSIZE,1); + klen=def_callback(buf,PEM_BUFSIZE,1,u); else - klen=(*callback)(buf,PEM_BUFSIZE,1); + klen=(*callback)(buf,PEM_BUFSIZE,1,u); if (klen <= 0) { PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY); goto err; } +#ifdef CHARSET_EBCDIC + /* Convert the pass phrase from EBCDIC */ + ebcdic2ascii(buf, buf, klen); +#endif kstr=(unsigned char *)buf; } RAND_seed(data,i);/* put in the RSA key. */ @@ -363,11 +357,8 @@ err: return(ret); } -int PEM_do_header(cipher, data, plen, callback) -EVP_CIPHER_INFO *cipher; -unsigned char *data; -long *plen; -int (*callback)(); +int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, + pem_password_cb *callback,void *u) { int i,j,o,klen; long len; @@ -379,14 +370,19 @@ int (*callback)(); if (cipher->cipher == NULL) return(1); if (callback == NULL) - klen=def_callback(buf,PEM_BUFSIZE,0); + klen=def_callback(buf,PEM_BUFSIZE,0,u); else - klen=callback(buf,PEM_BUFSIZE,0); + klen=callback(buf,PEM_BUFSIZE,0,u); if (klen <= 0) { PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ); return(0); } +#ifdef CHARSET_EBCDIC + /* Convert the pass phrase from EBCDIC */ + ebcdic2ascii(buf, buf, klen); +#endif + EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), (unsigned char *)buf,klen,1,key,NULL); @@ -407,12 +403,10 @@ int (*callback)(); return(1); } -int PEM_get_EVP_CIPHER_INFO(header,cipher) -char *header; -EVP_CIPHER_INFO *cipher; +int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher) { int o; - EVP_CIPHER *enc=NULL; + const EVP_CIPHER *enc=NULL; char *p,c; cipher->cipher=NULL; @@ -438,9 +432,15 @@ EVP_CIPHER_INFO *cipher; for (;;) { c= *header; +#ifndef CHARSET_EBCDIC if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') || ((c >= '0') && (c <= '9')))) break; +#else + if (!( isupper(c) || (c == '-') || + isdigit(c))) + break; +#endif header++; } *header='\0'; @@ -459,9 +459,7 @@ EVP_CIPHER_INFO *cipher; return(1); } -static int load_iv(fromp,to,num) -unsigned char **fromp,*to; -int num; +static int load_iv(unsigned char **fromp, unsigned char *to, int num) { int v,i; unsigned char *from; @@ -491,12 +489,8 @@ int num; } #ifndef NO_FP_API -int PEM_write(fp, name, header, data,len) -FILE *fp; -char *name; -char *header; -unsigned char *data; -long len; +int PEM_write(FILE *fp, char *name, char *header, unsigned char *data, + long len) { BIO *b; int ret; @@ -513,12 +507,8 @@ long len; } #endif -int PEM_write_bio(bp, name, header, data,len) -BIO *bp; -char *name; -char *header; -unsigned char *data; -long len; +int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data, + long len) { int nlen,n,i,j,outl; unsigned char *buf; @@ -573,12 +563,8 @@ err: } #ifndef NO_FP_API -int PEM_read(fp, name, header, data,len) -FILE *fp; -char **name; -char **header; -unsigned char **data; -long *len; +int PEM_read(FILE *fp, char **name, char **header, unsigned char **data, + long *len) { BIO *b; int ret; @@ -595,12 +581,8 @@ long *len; } #endif -int PEM_read_bio(bp, name, header, data, len) -BIO *bp; -char **name; -char **header; -unsigned char **data; -long *len; +int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data, + long *len) { EVP_ENCODE_CTX ctx; int end=0,i,k,bl=0,hl=0,nohead=0; @@ -643,7 +625,7 @@ long *len; PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } - strncpy(nameB->data,&(buf[11]),(unsigned int)i-6); + memcpy(nameB->data,&(buf[11]),i-6); nameB->data[i-6]='\0'; break; } @@ -668,7 +650,7 @@ long *len; nohead=1; break; } - strncpy(&(headerB->data[hl]),buf,(unsigned int)i); + memcpy(&(headerB->data[hl]),buf,i); headerB->data[hl+i]='\0'; hl+=i; } @@ -696,7 +678,7 @@ long *len; PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; } - strncpy(&(dataB->data[bl]),buf,(unsigned int)i); + memcpy(&(dataB->data[bl]),buf,i); dataB->data[bl+i]='\0'; bl+=i; if (end) @@ -721,7 +703,7 @@ long *len; } i=strlen(nameB->data); if ( (strncmp(buf,"-----END ",9) != 0) || - (strncmp(nameB->data,&(buf[9]),(unsigned int)i) != 0) || + (strncmp(nameB->data,&(buf[9]),i) != 0) || (strncmp(&(buf[9+i]),"-----\n",6) != 0)) { PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE); @@ -760,3 +742,62 @@ err: BUF_MEM_free(dataB); return(0); } + +/* This function writes a private key in PKCS#8 format: it is a "drop in" + * replacement for PEM_write_bio_PrivateKey(). As usual if 'enc' is NULL then + * it uses the unencrypted private key form. It uses PKCS#5 v2.0 password based + * encryption algorithms. + */ + +int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, + pem_password_cb *cb, void *u) +{ + X509_SIG *p8; + PKCS8_PRIV_KEY_INFO *p8inf; + char buf[PEM_BUFSIZE]; + int ret; + if(!(p8inf = EVP_PKEY2PKCS8(x))) { + PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY, + PEM_R_ERROR_CONVERTING_PRIVATE_KEY); + return 0; + } + if(enc) { + if(!kstr) { + if(!cb) klen = def_callback(buf, PEM_BUFSIZE, 1, u); + else klen = cb(buf, PEM_BUFSIZE, 1, u); + if(klen <= 0) { + PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY, + PEM_R_READ_KEY); + PKCS8_PRIV_KEY_INFO_free(p8inf); + return 0; + } + + kstr = buf; + } + p8 = PKCS8_encrypt(-1, enc, kstr, klen, NULL, 0, 0, p8inf); + if(kstr == buf) memset(buf, 0, klen); + PKCS8_PRIV_KEY_INFO_free(p8inf); + ret = PEM_write_bio_PKCS8(bp, p8); + X509_SIG_free(p8); + return ret; + } else { + ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf); + PKCS8_PRIV_KEY_INFO_free(p8inf); + return ret; + } +} + +int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, + char *kstr, int klen, pem_password_cb *cb, void *u) +{ + BIO *bp; + int ret; + if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { + PEMerr(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,ERR_R_BUF_LIB); + return(0); + } + ret = PEM_write_bio_PKCS8PrivateKey(bp, x, enc, kstr, klen, cb, u); + BIO_free(bp); + return ret; +} diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c index b4b36df453..23f95beb1e 100644 --- a/src/lib/libcrypto/pem/pem_seal.c +++ b/src/lib/libcrypto/pem/pem_seal.c @@ -56,23 +56,18 @@ * [including the GNU Public Licence.] */ +#ifndef NO_RSA #include #include "cryptlib.h" -#include "evp.h" -#include "rand.h" -#include "objects.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include +#include -int PEM_SealInit(ctx,type,md_type,ek,ekl,iv,pubk,npubk) -PEM_ENCODE_SEAL_CTX *ctx; -EVP_CIPHER *type; -EVP_MD *md_type; -unsigned char **ek; -int *ekl; -unsigned char *iv; -EVP_PKEY **pubk; -int npubk; +int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, + unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, + int npubk) { unsigned char key[EVP_MAX_KEY_LENGTH]; int ret= -1; @@ -118,12 +113,8 @@ err: return(ret); } -void PEM_SealUpdate(ctx,out,outl,in,inl) -PEM_ENCODE_SEAL_CTX *ctx; -unsigned char *out; -int *outl; -unsigned char *in; -int inl; +void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl, + unsigned char *in, int inl) { unsigned char buffer[1600]; int i,j; @@ -146,13 +137,8 @@ int inl; } } -int PEM_SealFinal(ctx,sig,sigl,out,outl,priv) -PEM_ENCODE_SEAL_CTX *ctx; -unsigned char *sig; -int *sigl; -unsigned char *out; -int *outl; -EVP_PKEY *priv; +int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl, + unsigned char *out, int *outl, EVP_PKEY *priv) { unsigned char *s=NULL; int ret=0,j; @@ -189,3 +175,4 @@ err: if (s != NULL) Free(s); return(ret); } +#endif diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c index d56f9f9e14..aabafb702d 100644 --- a/src/lib/libcrypto/pem/pem_sign.c +++ b/src/lib/libcrypto/pem/pem_sign.c @@ -58,32 +58,25 @@ #include #include "cryptlib.h" -#include "rand.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include +#include -void PEM_SignInit(ctx,type) -EVP_MD_CTX *ctx; -EVP_MD *type; +void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type) { EVP_DigestInit(ctx,type); } -void PEM_SignUpdate(ctx,data,count) -EVP_MD_CTX *ctx; -unsigned char *data; -unsigned int count; +void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, + unsigned int count) { EVP_DigestUpdate(ctx,data,count); } -int PEM_SignFinal(ctx,sigret,siglen,pkey) -EVP_MD_CTX *ctx; -unsigned char *sigret; -unsigned int *siglen; -EVP_PKEY *pkey; +int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, + EVP_PKEY *pkey) { unsigned char *m; int i,ret=0; diff --git a/src/lib/libcrypto/perlasm/alpha.pl b/src/lib/libcrypto/perlasm/alpha.pl new file mode 100644 index 0000000000..3dac571743 --- /dev/null +++ b/src/lib/libcrypto/perlasm/alpha.pl @@ -0,0 +1,434 @@ +#!/usr/local/bin/perl + +package alpha; +use Carp qw(croak cluck); + +$label="100"; + +$n_debug=0; +$smear_regs=1; +$reg_alloc=1; + +$align="3"; +$com_start="#"; + +sub main'asm_init_output { @out=(); } +sub main'asm_get_output { return(@out); } +sub main'get_labels { return(@labels); } +sub main'external_label { push(@labels,@_); } + +# General registers + +%regs=( 'r0', '$0', + 'r1', '$1', + 'r2', '$2', + 'r3', '$3', + 'r4', '$4', + 'r5', '$5', + 'r6', '$6', + 'r7', '$7', + 'r8', '$8', + 'r9', '$22', + 'r10', '$23', + 'r11', '$24', + 'r12', '$25', + 'r13', '$27', + 'r14', '$28', + 'r15', '$21', # argc == 5 + 'r16', '$20', # argc == 4 + 'r17', '$19', # argc == 3 + 'r18', '$18', # argc == 2 + 'r19', '$17', # argc == 1 + 'r20', '$16', # argc == 0 + 'r21', '$9', # save 0 + 'r22', '$10', # save 1 + 'r23', '$11', # save 2 + 'r24', '$12', # save 3 + 'r25', '$13', # save 4 + 'r26', '$14', # save 5 + + 'a0', '$16', + 'a1', '$17', + 'a2', '$18', + 'a3', '$19', + 'a4', '$20', + 'a5', '$21', + + 's0', '$9', + 's1', '$10', + 's2', '$11', + 's3', '$12', + 's4', '$13', + 's5', '$14', + 'zero', '$31', + 'sp', '$30', + ); + +$main'reg_s0="r21"; +$main'reg_s1="r22"; +$main'reg_s2="r23"; +$main'reg_s3="r24"; +$main'reg_s4="r25"; +$main'reg_s5="r26"; + +@reg=( '$0', '$1' ,'$2' ,'$3' ,'$4' ,'$5' ,'$6' ,'$7' ,'$8', + '$22','$23','$24','$25','$20','$21','$27','$28'); + + +sub main'sub { &out3("subq",@_); } +sub main'add { &out3("addq",@_); } +sub main'mov { &out3("bis",$_[0],$_[0],$_[1]); } +sub main'or { &out3("bis",@_); } +sub main'bis { &out3("bis",@_); } +sub main'br { &out1("br",@_); } +sub main'ld { &out2("ldq",@_); } +sub main'st { &out2("stq",@_); } +sub main'cmpult { &out3("cmpult",@_); } +sub main'cmplt { &out3("cmplt",@_); } +sub main'bgt { &out2("bgt",@_); } +sub main'ble { &out2("ble",@_); } +sub main'blt { &out2("blt",@_); } +sub main'mul { &out3("mulq",@_); } +sub main'muh { &out3("umulh",@_); } + +$main'QWS=8; + +sub main'asm_add + { + push(@out,@_); + } + +sub main'asm_finish + { + &main'file_end(); + print &main'asm_get_output(); + } + +sub main'asm_init + { + ($type,$fn)=@_; + $filename=$fn; + + &main'asm_init_output(); + &main'comment("Don't even think of reading this code"); + &main'comment("It was automatically generated by $filename"); + &main'comment("Which is a perl program used to generate the alpha assember."); + &main'comment("eric "); + &main'comment(""); + + $filename =~ s/\.pl$//; + &main'file($filename); + } + +sub conv + { + local($r)=@_; + local($v); + + return($regs{$r}) if defined($regs{$r}); + return($r); + } + +sub main'QWPw + { + local($off,$reg)=@_; + + return(&main'QWP($off*8,$reg)); + } + +sub main'QWP + { + local($off,$reg)=@_; + + $ret="$off(".&conv($reg).")"; + return($ret); + } + +sub out3 + { + local($name,$p1,$p2,$p3)=@_; + + $p1=&conv($p1); + $p2=&conv($p2); + $p3=&conv($p3); + push(@out,"\t$name\t"); + $l=length($p1)+1; + push(@out,$p1.","); + $ll=3-($l+9)/8; + $tmp1=sprintf("\t" x $ll); + push(@out,$tmp1); + + $l=length($p2)+1; + push(@out,$p2.","); + $ll=3-($l+9)/8; + $tmp1=sprintf("\t" x $ll); + push(@out,$tmp1); + + push(@out,&conv($p3)."\n"); + } + +sub out2 + { + local($name,$p1,$p2,$p3)=@_; + + $p1=&conv($p1); + $p2=&conv($p2); + push(@out,"\t$name\t"); + $l=length($p1)+1; + push(@out,$p1.","); + $ll=3-($l+9)/8; + $tmp1=sprintf("\t" x $ll); + push(@out,$tmp1); + + push(@out,&conv($p2)."\n"); + } + +sub out1 + { + local($name,$p1)=@_; + + $p1=&conv($p1); + push(@out,"\t$name\t".$p1."\n"); + } + +sub out0 + { + push(@out,"\t$_[0]\n"); + } + +sub main'file + { + local($file)=@_; + + local($tmp)=<<"EOF"; + # DEC Alpha assember + # Generated from perl scripts contains in SSLeay + .file 1 "$file.s" + .set noat +EOF + push(@out,$tmp); + } + +sub main'function_begin + { + local($func)=@_; + +print STDERR "$func\n"; + local($tmp)=<<"EOF"; + .text + .align $align + .globl $func + .ent $func +${func}: +${func}..ng: + .frame \$30,0,\$26,0 + .prologue 0 +EOF + push(@out,$tmp); + $stack=0; + } + +sub main'function_end + { + local($func)=@_; + + local($tmp)=<<"EOF"; + ret \$31,(\$26),1 + .end $func +EOF + push(@out,$tmp); + $stack=0; + %label=(); + } + +sub main'function_end_A + { + local($func)=@_; + + local($tmp)=<<"EOF"; + ret \$31,(\$26),1 +EOF + push(@out,$tmp); + } + +sub main'function_end_B + { + local($func)=@_; + + $func=$under.$func; + + push(@out,"\t.end $func\n"); + $stack=0; + %label=(); + } + +sub main'wparam + { + local($num)=@_; + + if ($num < 6) + { + $num=20-$num; + return("r$num"); + } + else + { return(&main'QWP($stack+$num*8,"sp")); } + } + +sub main'stack_push + { + local($num)=@_; + $stack+=$num*8; + &main'sub("sp",$num*8,"sp"); + } + +sub main'stack_pop + { + local($num)=@_; + $stack-=$num*8; + &main'add("sp",$num*8,"sp"); + } + +sub main'swtmp + { + return(&main'QWP(($_[0])*8,"sp")); + } + +# Should use swtmp, which is above sp. Linix can trash the stack above esp +#sub main'wtmp +# { +# local($num)=@_; +# +# return(&main'QWP(-($num+1)*4,"esp","",0)); +# } + +sub main'comment + { + foreach (@_) + { + if (/^\s*$/) + { push(@out,"\n"); } + else + { push(@out,"\t$com_start $_ $com_end\n"); } + } + } + +sub main'label + { + if (!defined($label{$_[0]})) + { + $label{$_[0]}=$label; + $label++; + } + return('$'.$label{$_[0]}); + } + +sub main'set_label + { + if (!defined($label{$_[0]})) + { + $label{$_[0]}=$label; + $label++; + } +# push(@out,".align $align\n") if ($_[1] != 0); + push(@out,'$'."$label{$_[0]}:\n"); + } + +sub main'file_end + { + } + +sub main'data_word + { + push(@out,"\t.long $_[0]\n"); + } + +@pool_free=(); +@pool_taken=(); +$curr_num=0; +$max=0; + +sub main'init_pool + { + local($args)=@_; + local($i); + + @pool_free=(); + for ($i=(14+(6-$args)); $i >= 0; $i--) + { + push(@pool_free,"r$i"); + } + print STDERR "START :register pool:@pool_free\n"; + $curr_num=$max=0; + } + +sub main'fin_pool + { + printf STDERR "END %2d:register pool:@pool_free\n",$max; + } + +sub main'GR + { + local($r)=@_; + local($i,@n,$_); + + foreach (@pool_free) + { + if ($r ne $_) + { push(@n,$_); } + else + { + $curr_num++; + $max=$curr_num if ($curr_num > $max); + } + } + @pool_free=@n; +print STDERR "GR:@pool_free\n" if $reg_alloc; + return(@_); + } + +sub main'NR + { + local($num)=@_; + local(@ret); + + $num=1 if $num == 0; + ($#pool_free >= ($num-1)) || croak "out of registers: want $num, have @pool_free"; + while ($num > 0) + { + push(@ret,pop @pool_free); + $curr_num++; + $max=$curr_num if ($curr_num > $max); + $num-- + } + print STDERR "nr @ret\n" if $n_debug; +print STDERR "NR:@pool_free\n" if $reg_alloc; + return(@ret); + + } + +sub main'FR + { + local(@r)=@_; + local(@a,$v,$w); + + print STDERR "fr @r\n" if $n_debug; +# cluck "fr @r"; + for $w (@pool_free) + { + foreach $v (@r) + { + croak "double register free of $v (@pool_free)" if $w eq $v; + } + } + foreach $v (@r) + { + croak "bad argument to FR" if ($v !~ /^r\d+$/); + if ($smear_regs) + { unshift(@pool_free,$v); } + else { push(@pool_free,$v); } + $curr_num--; + } +print STDERR "FR:@pool_free\n" if $reg_alloc; + } +1; diff --git a/src/lib/libcrypto/perlasm/cbc.pl b/src/lib/libcrypto/perlasm/cbc.pl index 2789305790..0145c4f0cc 100644 --- a/src/lib/libcrypto/perlasm/cbc.pl +++ b/src/lib/libcrypto/perlasm/cbc.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) # des_cblock (*input); diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl index 6a9156ae9a..44e330eb8d 100644 --- a/src/lib/libcrypto/perlasm/x86asm.pl +++ b/src/lib/libcrypto/perlasm/x86asm.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # require 'x86asm.pl'; # &asm_init("cpp","des-586.pl"); @@ -15,7 +15,7 @@ sub main'asm_finish sub main'asm_init { - ($type,$fn)=@_; + ($type,$fn,$i386)=@_; $filename=$fn; $cpp=$sol=$aout=$win32=0; @@ -29,6 +29,8 @@ sub main'asm_init { $cpp=1; require "x86unix.pl"; } elsif ( ($type eq "win32")) { $win32=1; require "x86ms.pl"; } + elsif ( ($type eq "win32n")) + { $win32=1; require "x86nasm.pl"; } else { print STDERR <<"EOF"; @@ -38,6 +40,7 @@ Pick one target type from sol - x86 solaris cpp - format so x86unix.cpp can be used win32 - Windows 95/Windows NT + win32n - Windows 95/Windows NT NASM format EOF exit(1); } @@ -75,7 +78,7 @@ sub asm_finish_cpp #define TYPE(a,b) .type a,b #define SIZE(a,b) .size a,b -#if defined(OUT) || defined(BSDI) +#if defined(OUT) || (defined(BSDI) && !defined(ELF)) $tmp #endif @@ -84,7 +87,7 @@ $tmp #define ALIGN 4 #endif -#ifdef BSDI +#if defined(BSDI) && !defined(ELF) #define OK 1 #define ALIGN 4 #undef SIZE diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl index 893b50b1a4..51dcce067f 100644 --- a/src/lib/libcrypto/perlasm/x86ms.pl +++ b/src/lib/libcrypto/perlasm/x86ms.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl package x86ms; @@ -51,6 +51,16 @@ sub main'DWP &get_mem("DWORD",@_); } +sub main'BC + { + return @_; + } + +sub main'DWC + { + return @_; + } + sub main'stack_push { local($num)=@_; diff --git a/src/lib/libcrypto/perlasm/x86nasm.pl b/src/lib/libcrypto/perlasm/x86nasm.pl new file mode 100644 index 0000000000..b4da364bbf --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86nasm.pl @@ -0,0 +1,342 @@ +#!/usr/local/bin/perl + +package x86nasm; + +$label="L000"; + +%lb=( 'eax', 'al', + 'ebx', 'bl', + 'ecx', 'cl', + 'edx', 'dl', + 'ax', 'al', + 'bx', 'bl', + 'cx', 'cl', + 'dx', 'dl', + ); + +%hb=( 'eax', 'ah', + 'ebx', 'bh', + 'ecx', 'ch', + 'edx', 'dh', + 'ax', 'ah', + 'bx', 'bh', + 'cx', 'ch', + 'dx', 'dh', + ); + +sub main'asm_init_output { @out=(); } +sub main'asm_get_output { return(@out); } +sub main'get_labels { return(@labels); } + +sub main'external_label +{ + push(@labels,@_); + foreach (@_) { + push(@out, "extern\t_$_\n"); + } +} + +sub main'LB + { + (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; + return($lb{$_[0]}); + } + +sub main'HB + { + (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n"; + return($hb{$_[0]}); + } + +sub main'BP + { + &get_mem("BYTE",@_); + } + +sub main'DWP + { + &get_mem("DWORD",@_); + } + +sub main'BC + { + return "BYTE @_"; + } + +sub main'DWC + { + return "DWORD @_"; + } + +sub main'stack_push + { + my($num)=@_; + $stack+=$num*4; + &main'sub("esp",$num*4); + } + +sub main'stack_pop + { + my($num)=@_; + $stack-=$num*4; + &main'add("esp",$num*4); + } + +sub get_mem + { + my($size,$addr,$reg1,$reg2,$idx)=@_; + my($t,$post); + my($ret)="["; + $addr =~ s/^\s+//; + if ($addr =~ /^(.+)\+(.+)$/) + { + $reg2=&conv($1); + $addr="_$2"; + } + elsif ($addr =~ /^[_a-zA-Z]/) + { + $addr="_$addr"; + } + + $reg1="$regs{$reg1}" if defined($regs{$reg1}); + $reg2="$regs{$reg2}" if defined($regs{$reg2}); + if (($addr ne "") && ($addr ne 0)) + { + if ($addr !~ /^-/) + { $ret.="${addr}+"; } + else { $post=$addr; } + } + if ($reg2 ne "") + { + $t=""; + $t="*$idx" if ($idx != 0); + $reg1="+".$reg1 if ("$reg1$post" ne ""); + $ret.="$reg2$t$reg1$post]"; + } + else + { + $ret.="$reg1$post]" + } + return($ret); + } + +sub main'mov { &out2("mov",@_); } +sub main'movb { &out2("mov",@_); } +sub main'and { &out2("and",@_); } +sub main'or { &out2("or",@_); } +sub main'shl { &out2("shl",@_); } +sub main'shr { &out2("shr",@_); } +sub main'xor { &out2("xor",@_); } +sub main'xorb { &out2("xor",@_); } +sub main'add { &out2("add",@_); } +sub main'adc { &out2("adc",@_); } +sub main'sub { &out2("sub",@_); } +sub main'rotl { &out2("rol",@_); } +sub main'rotr { &out2("ror",@_); } +sub main'exch { &out2("xchg",@_); } +sub main'cmp { &out2("cmp",@_); } +sub main'lea { &out2("lea",@_); } +sub main'mul { &out1("mul",@_); } +sub main'div { &out1("div",@_); } +sub main'dec { &out1("dec",@_); } +sub main'inc { &out1("inc",@_); } +sub main'jmp { &out1("jmp",@_); } +sub main'jmp_ptr { &out1p("jmp",@_); } + +# This is a bit of a kludge: declare all branches as NEAR. +sub main'je { &out1("je NEAR",@_); } +sub main'jle { &out1("jle NEAR",@_); } +sub main'jz { &out1("jz NEAR",@_); } +sub main'jge { &out1("jge NEAR",@_); } +sub main'jl { &out1("jl NEAR",@_); } +sub main'jb { &out1("jb NEAR",@_); } +sub main'jc { &out1("jc NEAR",@_); } +sub main'jnc { &out1("jnc NEAR",@_); } +sub main'jnz { &out1("jnz NEAR",@_); } +sub main'jne { &out1("jne NEAR",@_); } +sub main'jno { &out1("jno NEAR",@_); } + +sub main'push { &out1("push",@_); $stack+=4; } +sub main'pop { &out1("pop",@_); $stack-=4; } +sub main'bswap { &out1("bswap",@_); &using486(); } +sub main'not { &out1("not",@_); } +sub main'call { &out1("call",'_'.$_[0]); } +sub main'ret { &out0("ret"); } +sub main'nop { &out0("nop"); } + +sub out2 + { + my($name,$p1,$p2)=@_; + my($l,$t); + + push(@out,"\t$name\t"); + $t=&conv($p1).","; + $l=length($t); + push(@out,$t); + $l=4-($l+9)/8; + push(@out,"\t" x $l); + push(@out,&conv($p2)); + push(@out,"\n"); + } + +sub out0 + { + my($name)=@_; + + push(@out,"\t$name\n"); + } + +sub out1 + { + my($name,$p1)=@_; + my($l,$t); + push(@out,"\t$name\t".&conv($p1)."\n"); + } + +sub conv + { + my($p)=@_; + $p =~ s/0x([0-9A-Fa-f]+)/0$1h/; + return $p; + } + +sub using486 + { + return if $using486; + $using486++; + grep(s/\.386/\.486/,@out); + } + +sub main'file + { + push(@out, "segment .text\n"); + } + +sub main'function_begin + { + my($func,$extra)=@_; + + push(@labels,$func); + my($tmp)=<<"EOF"; +global _$func +_$func: + push ebp + push ebx + push esi + push edi +EOF + push(@out,$tmp); + $stack=20; + } + +sub main'function_begin_B + { + my($func,$extra)=@_; + my($tmp)=<<"EOF"; +global _$func +_$func: +EOF + push(@out,$tmp); + $stack=4; + } + +sub main'function_end + { + my($func)=@_; + + my($tmp)=<<"EOF"; + pop edi + pop esi + pop ebx + pop ebp + ret +EOF + push(@out,$tmp); + $stack=0; + %label=(); + } + +sub main'function_end_B + { + $stack=0; + %label=(); + } + +sub main'function_end_A + { + my($func)=@_; + + my($tmp)=<<"EOF"; + pop edi + pop esi + pop ebx + pop ebp + ret +EOF + push(@out,$tmp); + } + +sub main'file_end + { + } + +sub main'wparam + { + my($num)=@_; + + return(&main'DWP($stack+$num*4,"esp","",0)); + } + +sub main'swtmp + { + return(&main'DWP($_[0]*4,"esp","",0)); + } + +# Should use swtmp, which is above esp. Linix can trash the stack above esp +#sub main'wtmp +# { +# my($num)=@_; +# +# return(&main'DWP(-(($num+1)*4),"esp","",0)); +# } + +sub main'comment + { + foreach (@_) + { + push(@out,"\t; $_\n"); + } + } + +sub main'label + { + if (!defined($label{$_[0]})) + { + $label{$_[0]}="\$${label}${_[0]}"; + $label++; + } + return($label{$_[0]}); + } + +sub main'set_label + { + if (!defined($label{$_[0]})) + { + $label{$_[0]}="${label}${_[0]}"; + $label++; + } + push(@out,"$label{$_[0]}:\n"); + } + +sub main'data_word + { + push(@out,"\tDD\t$_[0]\n"); + } + +sub out1p + { + my($name,$p1)=@_; + my($l,$t); + + push(@out,"\t$name\t ".&conv($p1)."\n"); + } diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl index 6ee4dd3245..8c456b14af 100644 --- a/src/lib/libcrypto/perlasm/x86unix.pl +++ b/src/lib/libcrypto/perlasm/x86unix.pl @@ -1,10 +1,4 @@ -#!/usr/bin/perl - -# Because the bswapl instruction is not supported for old assembers -# (it was a new instruction for the 486), I've added .byte xxxx code -# to put it in. -# eric 24-Apr-1998 -# +#!/usr/local/bin/perl package x86unix; @@ -90,7 +84,12 @@ sub main'DWP $reg2="$regs{$reg2}" if defined($regs{$reg2}); $ret.=$addr if ($addr ne "") && ($addr ne 0); if ($reg2 ne "") - { $ret.="($reg1,$reg2,$idx)"; } + { + if($idx ne "") + { $ret.="($reg1,$reg2,$idx)"; } + else + { $ret.="($reg1,$reg2)"; } + } else { $ret.="($reg1)" } return($ret); @@ -101,6 +100,16 @@ sub main'BP return(&main'DWP(@_)); } +sub main'BC + { + return @_; + } + +sub main'DWC + { + return @_; + } + #sub main'BP # { # local($addr,$reg1,$reg2,$idx)=@_; @@ -153,12 +162,27 @@ sub main'dec { &out1("decl",@_); } sub main'inc { &out1("incl",@_); } sub main'push { &out1("pushl",@_); $stack+=4; } sub main'pop { &out1("popl",@_); $stack-=4; } -sub main'bswap { &out1("bswapl",@_); } sub main'not { &out1("notl",@_); } sub main'call { &out1("call",$under.$_[0]); } sub main'ret { &out0("ret"); } sub main'nop { &out0("nop"); } +# The bswapl instruction is new for the 486. Emulate if i386. +sub main'bswap + { + if ($main'i386) + { + &main'comment("bswapl @_"); + &main'exch(main'HB(@_),main'LB(@_)); + &main'rotr(@_,16); + &main'exch(main'HB(@_),main'LB(@_)); + } + else + { + &out1("bswapl",@_); + } + } + sub out2 { local($name,$p1,$p2)=@_; diff --git a/src/lib/libcrypto/pkcs7/Makefile.ssl b/src/lib/libcrypto/pkcs7/Makefile.ssl index a88359b320..436442a7a1 100644 --- a/src/lib/libcrypto/pkcs7/Makefile.ssl +++ b/src/lib/libcrypto/pkcs7/Makefile.ssl @@ -7,16 +7,16 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=pkcs7 -ERRC=pkcs7err GENERAL=Makefile README TEST= APPS= @@ -39,26 +39,39 @@ test: all: lib +testapps: enc dec sign verify + +enc: enc.o lib + $(CC) $(CFLAGS) -o enc enc.o $(LIB) + +dec: dec.o lib + $(CC) $(CFLAGS) -o dec dec.o $(LIB) + +sign: sign.o lib + $(CC) $(CFLAGS) -o sign sign.o $(LIB) + +verify: verify.o example.o lib + $(CC) $(CFLAGS) -o verify verify.o example.o $(LIB) + lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -70,17 +83,63 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +pk7_doit.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pk7_doit.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pk7_doit.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +pk7_doit.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +pk7_doit.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +pk7_doit.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +pk7_doit.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pk7_doit.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pk7_doit.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pk7_doit.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pk7_doit.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +pk7_doit.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h +pk7_doit.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +pk7_doit.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +pk7_doit.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +pk7_doit.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +pk7_doit.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +pk7_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pk7_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pk7_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +pk7_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +pk7_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +pk7_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +pk7_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pk7_lib.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pk7_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pk7_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pk7_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +pk7_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +pk7_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +pk7_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +pk7_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +pk7_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +pk7_lib.o: ../cryptlib.h +pkcs7err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +pkcs7err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +pkcs7err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +pkcs7err.o: ../../include/openssl/des.h ../../include/openssl/dh.h +pkcs7err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h +pkcs7err.o: ../../include/openssl/err.h ../../include/openssl/evp.h +pkcs7err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +pkcs7err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +pkcs7err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +pkcs7err.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +pkcs7err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +pkcs7err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +pkcs7err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +pkcs7err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +pkcs7err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h diff --git a/src/lib/libcrypto/pkcs7/bio_ber.c b/src/lib/libcrypto/pkcs7/bio_ber.c new file mode 100644 index 0000000000..2f17723e98 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/bio_ber.c @@ -0,0 +1,450 @@ +/* crypto/evp/bio_ber.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include +#include "cryptlib.h" +#include +#include + +static int ber_write(BIO *h,char *buf,int num); +static int ber_read(BIO *h,char *buf,int size); +/*static int ber_puts(BIO *h,char *str); */ +/*static int ber_gets(BIO *h,char *str,int size); */ +static long ber_ctrl(BIO *h,int cmd,long arg1,char *arg2); +static int ber_new(BIO *h); +static int ber_free(BIO *data); +#define BER_BUF_SIZE (32) + +/* This is used to hold the state of the BER objects being read. */ +typedef struct ber_struct + { + int tag; + int class; + long length; + int inf; + int num_left; + int depth; + } BER_CTX; + +typedef struct bio_ber_struct + { + int tag; + int class; + long length; + int inf; + + /* most of the following are used when doing non-blocking IO */ + /* reading */ + long num_left; /* number of bytes still to read/write in block */ + int depth; /* used with idefinite encoding. */ + int finished; /* No more read data */ + + /* writting */ + char *w_addr; + int w_offset; + int w_left; + + int buf_len; + int buf_off; + unsigned char buf[BER_BUF_SIZE]; + } BIO_BER_CTX; + +static BIO_METHOD methods_ber= + { + BIO_TYPE_CIPHER,"cipher", + ber_write, + ber_read, + NULL, /* ber_puts, */ + NULL, /* ber_gets, */ + ber_ctrl, + ber_new, + ber_free, + }; + +BIO_METHOD *BIO_f_ber(void) + { + return(&methods_ber); + } + +static int ber_new(BIO *bi) + { + BIO_BER_CTX *ctx; + + ctx=(BIO_BER_CTX *)Malloc(sizeof(BIO_BER_CTX)); + if (ctx == NULL) return(0); + + memset((char *)ctx,0,sizeof(BIO_BER_CTX)); + + bi->init=0; + bi->ptr=(char *)ctx; + bi->flags=0; + return(1); + } + +static int ber_free(BIO *a) + { + BIO_BER_CTX *b; + + if (a == NULL) return(0); + b=(BIO_BER_CTX *)a->ptr; + memset(a->ptr,0,sizeof(BIO_BER_CTX)); + Free(a->ptr); + a->ptr=NULL; + a->init=0; + a->flags=0; + return(1); + } + +int bio_ber_get_header(BIO *bio, BIO_BER_CTX *ctx) + { + char buf[64]; + int i,j,n; + int ret; + unsigned char *p; + unsigned long length + int tag; + int class; + long max; + + BIO_clear_retry_flags(b); + + /* Pack the buffer down if there is a hole at the front */ + if (ctx->buf_off != 0) + { + p=ctx->buf; + j=ctx->buf_off; + n=ctx->buf_len-j; + for (i=0; ibuf_len-j; + ctx->buf_off=0; + } + + /* If there is more room, read some more data */ + i=BER_BUF_SIZE-ctx->buf_len; + if (i) + { + i=BIO_read(bio->next_bio,&(ctx->buf[ctx->buf_len]),i); + if (i <= 0) + { + BIO_copy_next_retry(b); + return(i); + } + else + ctx->buf_len+=i; + } + + max=ctx->buf_len; + p=ctx->buf; + ret=ASN1_get_object(&p,&length,&tag,&class,max); + + if (ret & 0x80) + { + if ((ctx->buf_len < BER_BUF_SIZE) && + (ERR_GET_REASON(ERR_peek_error()) == ASN1_R_TOO_LONG)) + { + ERR_get_error(); /* clear the error */ + BIO_set_retry_read(b); + } + return(-1); + } + + /* We have no error, we have a header, so make use of it */ + + if ((ctx->tag >= 0) && (ctx->tag != tag)) + { + BIOerr(BIO_F_BIO_BER_GET_HEADER,BIO_R_TAG_MISMATCH); + sprintf(buf,"tag=%d, got %d",ctx->tag,tag); + ERR_add_error_data(1,buf); + return(-1); + } + if (ret & 0x01) + if (ret & V_ASN1_CONSTRUCTED) + } + +static int ber_read(BIO *b, char *out, int outl) + { + int ret=0,i,n; + BIO_BER_CTX *ctx; + + BIO_clear_retry_flags(b); + + if (out == NULL) return(0); + ctx=(BIO_BER_CTX *)b->ptr; + + if ((ctx == NULL) || (b->next_bio == NULL)) return(0); + + if (ctx->finished) return(0); + +again: + /* First see if we are half way through reading a block */ + if (ctx->num_left > 0) + { + if (ctx->num_left < outl) + n=ctx->num_left; + else + n=outl; + i=BIO_read(b->next_bio,out,n); + if (i <= 0) + { + BIO_copy_next_retry(b); + return(i); + } + ctx->num_left-=i; + outl-=i; + ret+=i; + if (ctx->num_left <= 0) + { + ctx->depth--; + if (ctx->depth <= 0) + ctx->finished=1; + } + if (outl <= 0) + return(ret); + else + goto again; + } + else /* we need to read another BER header */ + { + } + } + +static int ber_write(BIO *b, char *in, int inl) + { + int ret=0,n,i; + BIO_ENC_CTX *ctx; + + ctx=(BIO_ENC_CTX *)b->ptr; + ret=inl; + + BIO_clear_retry_flags(b); + n=ctx->buf_len-ctx->buf_off; + while (n > 0) + { + i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); + if (i <= 0) + { + BIO_copy_next_retry(b); + return(i); + } + ctx->buf_off+=i; + n-=i; + } + /* at this point all pending data has been written */ + + if ((in == NULL) || (inl <= 0)) return(0); + + ctx->buf_off=0; + while (inl > 0) + { + n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl; + EVP_CipherUpdate(&(ctx->cipher), + (unsigned char *)ctx->buf,&ctx->buf_len, + (unsigned char *)in,n); + inl-=n; + in+=n; + + ctx->buf_off=0; + n=ctx->buf_len; + while (n > 0) + { + i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n); + if (i <= 0) + { + BIO_copy_next_retry(b); + return(i); + } + n-=i; + ctx->buf_off+=i; + } + ctx->buf_len=0; + ctx->buf_off=0; + } + BIO_copy_next_retry(b); + return(ret); + } + +static long ber_ctrl(BIO *b, int cmd, long num, char *ptr) + { + BIO *dbio; + BIO_ENC_CTX *ctx,*dctx; + long ret=1; + int i; + + ctx=(BIO_ENC_CTX *)b->ptr; + + switch (cmd) + { + case BIO_CTRL_RESET: + ctx->ok=1; + ctx->finished=0; + EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL, + ctx->cipher.berrypt); + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_CTRL_EOF: /* More to read */ + if (ctx->cont <= 0) + ret=1; + else + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_CTRL_WPENDING: + ret=ctx->buf_len-ctx->buf_off; + if (ret <= 0) + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_CTRL_PENDING: /* More to read in buffer */ + ret=ctx->buf_len-ctx->buf_off; + if (ret <= 0) + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_CTRL_FLUSH: + /* do a final write */ +again: + while (ctx->buf_len != ctx->buf_off) + { + i=ber_write(b,NULL,0); + if (i < 0) + { + ret=i; + break; + } + } + + if (!ctx->finished) + { + ctx->finished=1; + ctx->buf_off=0; + ret=EVP_CipherFinal(&(ctx->cipher), + (unsigned char *)ctx->buf, + &(ctx->buf_len)); + ctx->ok=(int)ret; + if (ret <= 0) break; + + /* push out the bytes */ + goto again; + } + + /* Finally flush the underlying BIO */ + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + case BIO_C_GET_CIPHER_STATUS: + ret=(long)ctx->ok; + break; + case BIO_C_DO_STATE_MACHINE: + BIO_clear_retry_flags(b); + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + BIO_copy_next_retry(b); + break; + + case BIO_CTRL_DUP: + dbio=(BIO *)ptr; + dctx=(BIO_ENC_CTX *)dbio->ptr; + memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher)); + dbio->init=1; + break; + default: + ret=BIO_ctrl(b->next_bio,cmd,num,ptr); + break; + } + return(ret); + } + +/* +void BIO_set_cipher_ctx(b,c) +BIO *b; +EVP_CIPHER_ctx *c; + { + if (b == NULL) return; + + if ((b->callback != NULL) && + (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) + return; + + b->init=1; + ctx=(BIO_ENC_CTX *)b->ptr; + memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX)); + + if (b->callback != NULL) + b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); + } +*/ + +void BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *k, unsigned char *i, + int e) + { + BIO_ENC_CTX *ctx; + + if (b == NULL) return; + + if ((b->callback != NULL) && + (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) + return; + + b->init=1; + ctx=(BIO_ENC_CTX *)b->ptr; + EVP_CipherInit(&(ctx->cipher),c,k,i,e); + + if (b->callback != NULL) + b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); + } + diff --git a/src/lib/libcrypto/pkcs7/dec.c b/src/lib/libcrypto/pkcs7/dec.c new file mode 100644 index 0000000000..b3661f28d3 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/dec.c @@ -0,0 +1,246 @@ +/* crypto/pkcs7/verify.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ +#include +#include +#include +#include +#include +#include +#include + +int verify_callback(int ok, X509_STORE_CTX *ctx); + +BIO *bio_err=NULL; + +int main(argc,argv) +int argc; +char *argv[]; + { + char *keyfile=NULL; + BIO *in; + EVP_PKEY *pkey; + X509 *x509; + PKCS7 *p7; + PKCS7_SIGNER_INFO *si; + X509_STORE_CTX cert_ctx; + X509_STORE *cert_store=NULL; + BIO *data,*detached=NULL,*p7bio=NULL; + char buf[1024*4]; + unsigned char *pp; + int i,printit=0; + STACK_OF(PKCS7_SIGNER_INFO) *sk; + + SSLeay_add_all_algorithms(); + bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); + + data=BIO_new(BIO_s_file()); + pp=NULL; + while (argc > 1) + { + argc--; + argv++; + if (strcmp(argv[0],"-p") == 0) + { + printit=1; + } + else if ((strcmp(argv[0],"-k") == 0) && (argc >= 2)) { + keyfile = argv[1]; + argc-=1; + argv+=1; + } else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2)) + { + detached=BIO_new(BIO_s_file()); + if (!BIO_read_filename(detached,argv[1])) + goto err; + argc-=1; + argv+=1; + } + else break; + } + + if (!BIO_read_filename(data,argv[0])) goto err; + + if(!keyfile) { + fprintf(stderr, "No private key file specified\n"); + goto err; + } + + if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err; + if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; + BIO_reset(in); + if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; + BIO_free(in); + + if (pp == NULL) + BIO_set_fp(data,stdin,BIO_NOCLOSE); + + + /* Load the PKCS7 object from a file */ + if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err; + + + + /* This stuff is being setup for certificate verification. + * When using SSL, it could be replaced with a + * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */ + cert_store=X509_STORE_new(); + X509_STORE_set_default_paths(cert_store); + X509_STORE_load_locations(cert_store,NULL,"../../certs"); + X509_STORE_set_verify_cb_func(cert_store,verify_callback); + + ERR_clear_error(); + + /* We need to process the data */ + /* We cannot support detached encryption */ + p7bio=PKCS7_dataDecode(p7,pkey,detached,x509); + + if (p7bio == NULL) + { + printf("problems decoding\n"); + goto err; + } + + /* We now have to 'read' from p7bio to calculate digests etc. */ + for (;;) + { + i=BIO_read(p7bio,buf,sizeof(buf)); + /* print it? */ + if (i <= 0) break; + fwrite(buf,1, i, stdout); + } + + /* We can now verify signatures */ + sk=PKCS7_get_signer_info(p7); + if (sk == NULL) + { + fprintf(stderr, "there are no signatures on this data\n"); + } + else + { + /* Ok, first we need to, for each subject entry, + * see if we can verify */ + ERR_clear_error(); + for (i=0; ierror) + { + case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: + X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256); + BIO_printf(bio_err,"issuer= %s\n",buf); + break; + case X509_V_ERR_CERT_NOT_YET_VALID: + case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: + BIO_printf(bio_err,"notBefore="); + ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert)); + BIO_printf(bio_err,"\n"); + break; + case X509_V_ERR_CERT_HAS_EXPIRED: + case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: + BIO_printf(bio_err,"notAfter="); + ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert)); + BIO_printf(bio_err,"\n"); + break; + } + BIO_printf(bio_err,"verify return:%d\n",ok); + return(ok); + } diff --git a/src/lib/libcrypto/pkcs7/des.pem b/src/lib/libcrypto/pkcs7/des.pem new file mode 100644 index 0000000000..62d1657e3e --- /dev/null +++ b/src/lib/libcrypto/pkcs7/des.pem @@ -0,0 +1,15 @@ + +MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG +A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m +dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD +ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ +/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw +AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI +QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU +UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G +CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N +WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA +oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL +lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8 +5PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA= + diff --git a/src/lib/libcrypto/pkcs7/enc.c b/src/lib/libcrypto/pkcs7/enc.c index 625a7c2285..43bfd10a23 100644 --- a/src/lib/libcrypto/pkcs7/enc.c +++ b/src/lib/libcrypto/pkcs7/enc.c @@ -56,61 +56,82 @@ * [including the GNU Public Licence.] */ #include -#include "bio.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { X509 *x509; - EVP_PKEY *pkey; PKCS7 *p7; - PKCS7 *p7_data; - PKCS7_SIGNER_INFO *si; BIO *in; BIO *data,*p7bio; char buf[1024*4]; - int i,j; - int nodetach=0; + int i; + int nodetach=1; + char *keyfile = NULL; + const EVP_CIPHER *cipher=NULL; + STACK_OF(X509) *recips=NULL; - EVP_add_digest(EVP_sha1()); - EVP_add_cipher(EVP_des_cbc()); + SSLeay_add_all_algorithms(); data=BIO_new(BIO_s_file()); -again: - if (argc > 1) + while(argc > 1) { if (strcmp(argv[1],"-nd") == 0) { nodetach=1; argv++; argc--; - goto again; } - if (!BIO_read_filename(data,argv[1])) - goto err; - } - else - BIO_set_fp(data,stdin,BIO_NOCLOSE); + else if ((strcmp(argv[1],"-c") == 0) && (argc >= 2)) { + if(!(cipher = EVP_get_cipherbyname(argv[2]))) { + fprintf(stderr, "Unknown cipher %s\n", argv[2]); + goto err; + } + argc-=2; + argv+=2; + } else if ((strcmp(argv[1],"-k") == 0) && (argc >= 2)) { + keyfile = argv[2]; + argc-=2; + argv+=2; + if (!(in=BIO_new_file(keyfile,"r"))) goto err; + if (!(x509=PEM_read_bio_X509(in,NULL,NULL))) goto err; + if(!recips) recips = sk_X509_new_null(); + sk_X509_push(recips, x509); + BIO_free(in); + } else break; + } - if ((in=BIO_new_file("server.pem","r")) == NULL) goto err; - if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; + if(!recips) { + fprintf(stderr, "No recipients\n"); + goto err; + } + + if (!BIO_read_filename(data,argv[1])) goto err; + + p7=PKCS7_new(); +#if 0 BIO_reset(in); if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; BIO_free(in); - - p7=PKCS7_new(); PKCS7_set_type(p7,NID_pkcs7_signedAndEnveloped); if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err; - - if (!PKCS7_set_cipher(p7,EVP_des_cbc())) goto err; - if (PKCS7_add_recipient(p7,x509) == NULL) goto err; - /* we may want to add more */ PKCS7_add_certificate(p7,x509); - +#else + PKCS7_set_type(p7,NID_pkcs7_enveloped); +#endif + if(!cipher) cipher = EVP_des_ede3_cbc(); + + if (!PKCS7_set_cipher(p7,cipher)) goto err; + for(i = 0; i < sk_X509_num(recips); i++) { + if (!PKCS7_add_recipient(p7,sk_X509_value(recips, i))) goto err; + } + sk_X509_pop_free(recips, X509_free); /* Set the content of the signed to 'data' */ /* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */ @@ -129,7 +150,7 @@ again: } BIO_flush(p7bio); - if (!PKCS7_dataSign(p7,p7bio)) goto err; + if (!PKCS7_dataFinal(p7,p7bio)) goto err; BIO_free(p7bio); PEM_write_PKCS7(stdout,p7); diff --git a/src/lib/libcrypto/pkcs7/es1.pem b/src/lib/libcrypto/pkcs7/es1.pem new file mode 100644 index 0000000000..47112a238f --- /dev/null +++ b/src/lib/libcrypto/pkcs7/es1.pem @@ -0,0 +1,66 @@ +-----BEGIN PKCS7----- +MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG +A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m +dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD +ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqGSIb3DQEBAQUABEDWak0y/5XZJhQJeCLo +KECcHXkTEbjzYkYNHIinbiPmRK4QbNfs9z2mA3z/c2ykQ4eAqFR2jyNrUMN/+I5XEiv6MIHw +AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI +QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU +UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G +CSqGSIb3DQEBAQUABEAWg9+KgtCjc77Jdj1Ve4wGgHjVHbbSYEA1ZqKFDoi15vSr9hfpHmC4 +ycZzcRo16JkTfolefiHZzmyjVz94vSN6MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA +oAQI7X4Tk4mcbV6ggASBsHl1mCaJ3RhXWlNPCgCRU53d7M5x6TDZRkvwdtdvW96m1lupT03F +XtonkBqk7oMkH7kGfs5/REQOPjx0QE2Ixmgt1W3szum82EZwA7pZNppcraK7W/odw/7bYZO+ +II3HPmRklE2N9qiu1LPaPUsnYogkO6SennyeL5tZ382vBweL/8pnG0qsbT1OBb65v+llnsjT +pa1T/p+fIx/iJJGE6K9fYFokC6gXLQ6ozXRdOu5oBDB8mPCYYvAqKycidM/MrGGUkpEtS4f0 +lS31PwQi5YTim8Ig3/TOwVpPX32i46FTuEIEIMHkD/OvpfwCCzXUHHJnKnKUAUvIsSY3vGBs +8ezpUDfBBBj9LHDy32hZ2tQilkDefP5VM2LLdrWgamYEgfiyITQvn08Ul5lQOQxbFKBheFq5 +otCCN4MR+w5eq12xQu6y+f9z0159ag2ru87D0lLtUtXXtCELbO1nUkT2sJ0k/iDs9TOXr6Cx +go1XKYho83hlkXYiCteVizdAbgVGNsNRD4wtIdajsorET/LuJECgp11YeL9w1dlDB0HLEZfi +XCsUphH4jGagba3hDeUSibnjSiJlN0ukfuQurBBbI2UkBAujiEAubKPn7C1FZJRSw6CPPX5t +KEpmcqT1JNk6LO8Js6/1sCmmBh1VGCy1+EuTI9J1p7Dagf4nQ8cHitoCRpHuKZlFHnZyv7tw +Rn/KOhHaYP2VzAh40gQIvKMAAWh9oFsEEIMwIoOmLwLH5wf+8QdbDhoECH8HwZt9a12dBAjL +r4j2zlvtfgQIt7nmEM3wz1EECKlc3EIy1irCBBCAKINcermK3A+jI6ISN2RzBFA3dsh/xwMu +l61aWMBBZzEz/SF92k6n35KZhCC0d6fIVC/1WMv0fnCwQ8oEDynSre216VEFiYKBaQLJe5o/ +mTAxC7Ht3goXnuc+i1FItOkLrgRI/wyvTICEn2WsNZiMADnGaee2bqPnUopo+VMGexJEtCPk +l0ZNlDJGquPDkpUwaEtecVZzCNyVPYyyF4J/l8rmGDhDdYUIC8IKBEg/ip/E0BuubBLWVbv+ +HRl4QrnGpyCyeXRXXK603QP3sT1Zbbm1v5pI/loOhVHi724LmtXHSyp5qv9MDcxE1PoX10LY +gBRtlwwESPeCF8bK5jk4xIQMhK5NMHj1Y1KQWTZ9NGITBL4hjRq2qp4Qk5GIpGgOVPopAuCo +TIyPikpqBRNtLSPRSsDs6QPUPzWBh6JgxwRQblnDKKUkxUcnJiD4i9QtGa/ZabMn4KxtNOBL +5JSh1nJkaLXCZY070131WWPAByLcd5TiXq8x84pmzV5NNk4tiMpoXhJNsx8e4rskQQlKd6ME +SCe2eYDHKcKPX3WJbUzhrJSQ92/aWnI2iUY8WQ+kSNyiZ2QUjyuUg9Z66g/0d2STlvPOBHT/ +y5ODP2CwbcWX4QmCbUc9TT66fQRIrRVuwvtOfnUueyGgYhJ3HpAJfVaB/7kap5bj7Fi/azW4 +9JDfd1bC/W9h0Kyk7RO2gxvE0hIHc26mZJHTm9MNP5D328MnM2MdBEjKjQBtgrp+lFIii7MP +nGHFTKUkG4WAIZJCf/CsT+p6/SW0qG71Me/YcSw5STB24j+a+HgMV8RVIeUlkP4z0IWWrSoB +Gh4d/Z0EUMCVHs/HZ/bWgiyhtHpvuVAzidm8D81p1LJ5BQX5/5f/m+q5+fS/npL27dTEbNqs +LSB6ij3MZAi7LwHWpTn9zWnDajCMEj9vlaV7mcKtHK5iBEg85agFi1h3MvicqLtoFe5hVv9T +tG0j6CRkjkixPzivltlrf44KHv14gLM0XJxCGyq7vd3l8QYr3+9at0zNnX/yqTiBnsnE5dUE +SIgrYuz87M2gi/ER9PcDoTtONH3+CkcqVy03q/Sj8cVWD/b1KgEhqnNOfc8Ak9PctyR/ItcR +8Me5XVn1GJKkQJk4O29fxvgNoAQIrIESvUWGshAEQByXiFoFTDUByjTlgjcy77H1lrH+y3P/ +wAInJjJAut9kCNyGJV0PA4kdPB5USWltuO6t8gk4Pd2YBMl09zqUWkAEUCjFrtZ3mapjcGZI +uQTASKR5LSjXoWxTT5gae/+64MerF/oCEeO3ehRTpjnPrsiRDo0rWIQTaj9+Nro8Z2xtWstw +RnfoAHIxV1lEamPwjsceBEi2SD9hiifFeO5ECiVoaE1FdXUXhU+jwYAMx6jHWO9hMkYzS9pM +Y3IyWR5ybtOjiQgkUdvRJPUPGf5DVVMPnymGX25aDh5PYpIESPbsM9akCpOOVuscywcUswmU +o7dXvlB48WWCfg/al3BQKAZbn5ZXtWNwpUZkrEdHsrxAVv3rxRcdkT3Z1fzUbIuYkLJN200o +WgRIJvn6RO8KEj7/HOg2sYuuM8nz1kR0TSgwX7/0y/7JfjBa0JIlP7o75sNJscE8oyoIMzuy +Dvn6/U9g3BCDXn83A/s+ke60qn9gBFC6NAeLOlXal1YVWYhMQNOqCyUfAjiXBTawaysQb1Mk +YgeNlF8xuEFcUQWIP+vNG7FJ5JPMaMRL4YEoaQ3sVFhYOERJR1cSb+8xt4QCYtBKQgRIUOmJ +CHW5o1hXJWJiTkZK2qWFcEMzTINSj5EpYFySr8aVBjkRnI7vxegRT/+XZZXoYedQ3UNsnGI3 +DdkWii5VzX0PNF6C60pfBEiVpausYuX7Wjb3Lfm8cBj7GgN69i6Pm2gxtobVcmpo2nS4D714 +ePyhlX9n8kJ6QAcqWMRj22smDPrHVGNTizfzHBh5zNllK9gESJizILOWI327og3ZWp+qUht5 +kNDJCzMK7Z09UAy+h+vq0VTQuEo3FgLzVdqkJujjSL4Nx97lXg51AovrEn3nd4evydwcjKLX +1wRIo72NaeWuUEQ+rt1SlCsOJ7k1ioJSqhrPOfvwcaFcb4beVet1JWiy4yvowTjLDGbUje2s +xjrlVt4BJWI/uA6jbQsrxSe89ADZBAi5YAlR4qszeAQIXD3VSBVKbRUECNTtyvw9vvqXBAhb +IZNn4H4cxgQI+XW7GkfL+ekECCCCg2reMyGDBAh1PYqkg3lw3gQQkNlggEPU+BH8eh7Gm7n7 +7AQIjC5EWbkil5cEEKcpuqwTWww/X89KnQAg8TcECJPomqHvrlZFBBiRSuIiHpmN+PaujXpv +qZV2VhjkB2j09GEECOIdv8AVOJgKBAjlHgIqAD9jZQQIXHbs44+wogcEIGGqTACRJxrhMcMG +X8drNjksIPt+snxTXUBIkTVpZWoABAh6unXPTyIr8QQgBF8xKoX27MWk7iTNmkSNZggZXa2a +DWCGHSYLngbSOHIECD9XmO6VsvTgBAjfqB70CEW4WwQIVIBkbCocznUEEHB/zFXy/sR4OYHe +UfbNPnIEEDWBB/NTCLMGE+o8BfyujcAECFik7GQnnF9VBBAhLXExQeWAofZNc6NtN7qZBCC1 +gVIS3ruTwKltmcrgx3heT3M8ZJhCfWa+6KzchnmKygQQ+1NL5sSzR4m/fdrqxHFyUAQYCT2x +PamQr3wK3h0lyZER+4H0zPM86AhFBBC3CkmvL2vjflMfujnzPBVpBBge9rMbI5+0q9DLrTiT +5F3AIgXLpD8PQWAECHkHVo6RomV3BAgMbi8E271UeAQIqtS8wnI3XngECG3TWmOMb3/iBEha +y+mvCS6I3n3JfL8e1B5P4qX9/czJRaERLuKpGNjLiL4A+zxN0LZ0UHd0qfmJjwOTxAx3iJAC +lGXX4nB9ATYPUT5EU+o1Y4sECN01pP6vWNIdBDAsiE0Ts8/9ltJlqX2B3AoOM4qOt9EaCjXf +lB+aEmrhtjUwuZ6GqS5Ke7P6XnakTk4ECCLIMatNdootAAAAAAAAAAAAAA== +-----END PKCS7----- diff --git a/src/lib/libcrypto/pkcs7/example.c b/src/lib/libcrypto/pkcs7/example.c new file mode 100644 index 0000000000..7354890084 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/example.c @@ -0,0 +1,327 @@ +#include +#include +#include +#include + +int add_signed_time(PKCS7_SIGNER_INFO *si) + { + ASN1_UTCTIME *sign_time; + + /* The last parameter is the amount to add/subtract from the current + * time (in seconds) */ + sign_time=X509_gmtime_adj(NULL,0); + PKCS7_add_signed_attribute(si,NID_pkcs9_signingTime, + V_ASN1_UTCTIME,(char *)sign_time); + return(1); + } + +ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si) + { + ASN1_TYPE *so; + + so=PKCS7_get_signed_attribute(si,NID_pkcs9_signingTime); + if (so->type == V_ASN1_UTCTIME) + return so->value.utctime; + return NULL; + } + +static int signed_string_nid= -1; + +void add_signed_string(PKCS7_SIGNER_INFO *si, char *str) + { + ASN1_OCTET_STRING *os; + + /* To a an object of OID 1.2.3.4.5, which is an octet string */ + if (signed_string_nid == -1) + signed_string_nid= + OBJ_create("1.2.3.4.5","OID_example","Our example OID"); + os=ASN1_OCTET_STRING_new(); + ASN1_OCTET_STRING_set(os,str,strlen(str)); + /* When we add, we do not free */ + PKCS7_add_signed_attribute(si,signed_string_nid, + V_ASN1_OCTET_STRING,(char *)os); + } + +int get_signed_string(PKCS7_SIGNER_INFO *si, char *buf, int len) + { + ASN1_TYPE *so; + ASN1_OCTET_STRING *os; + int i; + + if (signed_string_nid == -1) + signed_string_nid= + OBJ_create("1.2.3.4.5","OID_example","Our example OID"); + /* To retrieve */ + so=PKCS7_get_signed_attribute(si,signed_string_nid); + if (so != NULL) + { + if (so->type == V_ASN1_OCTET_STRING) + { + os=so->value.octet_string; + i=os->length; + if ((i+1) > len) + i=len-1; + memcpy(buf,os->data,i); + return(i); + } + } + return(0); + } + +static signed_seq2string_nid= -1; +/* ########################################### */ +int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2) + { + /* To add an object of OID 1.9.999, which is a sequence containing + * 2 octet strings */ + unsigned char *p; + ASN1_OCTET_STRING *os1,*os2; + ASN1_STRING *seq; + unsigned char *data; + int i,total; + + if (signed_seq2string_nid == -1) + signed_seq2string_nid= + OBJ_create("1.9.9999","OID_example","Our example OID"); + + os1=ASN1_OCTET_STRING_new(); + os2=ASN1_OCTET_STRING_new(); + ASN1_OCTET_STRING_set(os1,str1,strlen(str1)); + ASN1_OCTET_STRING_set(os2,str1,strlen(str1)); + i =i2d_ASN1_OCTET_STRING(os1,NULL); + i+=i2d_ASN1_OCTET_STRING(os2,NULL); + total=ASN1_object_size(1,i,V_ASN1_SEQUENCE); + + data=malloc(total); + p=data; + ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + i2d_ASN1_OCTET_STRING(os1,&p); + i2d_ASN1_OCTET_STRING(os2,&p); + + seq=ASN1_STRING_new(); + ASN1_STRING_set(seq,data,total); + free(data); + ASN1_OCTET_STRING_free(os1); + ASN1_OCTET_STRING_free(os2); + + PKCS7_add_signed_attribute(si,signed_seq2string_nid, + V_ASN1_SEQUENCE,(char *)seq); + return(1); + } + +/* For this case, I will malloc the return strings */ +int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2) + { + ASN1_TYPE *so; + + if (signed_seq2string_nid == -1) + signed_seq2string_nid= + OBJ_create("1.9.9999","OID_example","Our example OID"); + /* To retrieve */ + so=PKCS7_get_signed_attribute(si,signed_seq2string_nid); + if (so && (so->type == V_ASN1_SEQUENCE)) + { + ASN1_CTX c; + ASN1_STRING *s; + long length; + ASN1_OCTET_STRING *os1,*os2; + + s=so->value.sequence; + c.p=ASN1_STRING_data(s); + c.max=c.p+ASN1_STRING_length(s); + if (!asn1_GetSequence(&c,&length)) goto err; + /* Length is the length of the seqence */ + + c.q=c.p; + if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) + goto err; + c.slen-=(c.p-c.q); + + c.q=c.p; + if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) + goto err; + c.slen-=(c.p-c.q); + + if (!asn1_Finish(&c)) goto err; + *str1=malloc(os1->length+1); + *str2=malloc(os2->length+1); + memcpy(*str1,os1->data,os1->length); + memcpy(*str2,os2->data,os2->length); + (*str1)[os1->length]='\0'; + (*str2)[os2->length]='\0'; + ASN1_OCTET_STRING_free(os1); + ASN1_OCTET_STRING_free(os2); + return(1); + } +err: + return(0); + } + + +/* ####################################### + * THE OTHER WAY TO DO THINGS + * ####################################### + */ +X509_ATTRIBUTE *create_time(void) + { + ASN1_UTCTIME *sign_time; + X509_ATTRIBUTE *ret; + + /* The last parameter is the amount to add/subtract from the current + * time (in seconds) */ + sign_time=X509_gmtime_adj(NULL,0); + ret=X509_ATTRIBUTE_create(NID_pkcs9_signingTime, + V_ASN1_UTCTIME,(char *)sign_time); + return(ret); + } + +ASN1_UTCTIME *sk_get_time(STACK_OF(X509_ATTRIBUTE) *sk) + { + ASN1_TYPE *so; + PKCS7_SIGNER_INFO si; + + si.auth_attr=sk; + so=PKCS7_get_signed_attribute(&si,NID_pkcs9_signingTime); + if (so->type == V_ASN1_UTCTIME) + return so->value.utctime; + return NULL; + } + +X509_ATTRIBUTE *create_string(char *str) + { + ASN1_OCTET_STRING *os; + X509_ATTRIBUTE *ret; + + /* To a an object of OID 1.2.3.4.5, which is an octet string */ + if (signed_string_nid == -1) + signed_string_nid= + OBJ_create("1.2.3.4.5","OID_example","Our example OID"); + os=ASN1_OCTET_STRING_new(); + ASN1_OCTET_STRING_set(os,str,strlen(str)); + /* When we add, we do not free */ + ret=X509_ATTRIBUTE_create(signed_string_nid, + V_ASN1_OCTET_STRING,(char *)os); + return(ret); + } + +int sk_get_string(STACK_OF(X509_ATTRIBUTE) *sk, char *buf, int len) + { + ASN1_TYPE *so; + ASN1_OCTET_STRING *os; + int i; + PKCS7_SIGNER_INFO si; + + si.auth_attr=sk; + + if (signed_string_nid == -1) + signed_string_nid= + OBJ_create("1.2.3.4.5","OID_example","Our example OID"); + /* To retrieve */ + so=PKCS7_get_signed_attribute(&si,signed_string_nid); + if (so != NULL) + { + if (so->type == V_ASN1_OCTET_STRING) + { + os=so->value.octet_string; + i=os->length; + if ((i+1) > len) + i=len-1; + memcpy(buf,os->data,i); + return(i); + } + } + return(0); + } + +X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2) + { + /* To add an object of OID 1.9.999, which is a sequence containing + * 2 octet strings */ + unsigned char *p; + ASN1_OCTET_STRING *os1,*os2; + ASN1_STRING *seq; + X509_ATTRIBUTE *ret; + unsigned char *data; + int i,total; + + if (signed_seq2string_nid == -1) + signed_seq2string_nid= + OBJ_create("1.9.9999","OID_example","Our example OID"); + + os1=ASN1_OCTET_STRING_new(); + os2=ASN1_OCTET_STRING_new(); + ASN1_OCTET_STRING_set(os1,str1,strlen(str1)); + ASN1_OCTET_STRING_set(os2,str1,strlen(str1)); + i =i2d_ASN1_OCTET_STRING(os1,NULL); + i+=i2d_ASN1_OCTET_STRING(os2,NULL); + total=ASN1_object_size(1,i,V_ASN1_SEQUENCE); + + data=malloc(total); + p=data; + ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); + i2d_ASN1_OCTET_STRING(os1,&p); + i2d_ASN1_OCTET_STRING(os2,&p); + + seq=ASN1_STRING_new(); + ASN1_STRING_set(seq,data,total); + free(data); + ASN1_OCTET_STRING_free(os1); + ASN1_OCTET_STRING_free(os2); + + ret=X509_ATTRIBUTE_create(signed_seq2string_nid, + V_ASN1_SEQUENCE,(char *)seq); + return(ret); + } + +/* For this case, I will malloc the return strings */ +int sk_get_seq2string(STACK_OF(X509_ATTRIBUTE) *sk, char **str1, char **str2) + { + ASN1_TYPE *so; + PKCS7_SIGNER_INFO si; + + if (signed_seq2string_nid == -1) + signed_seq2string_nid= + OBJ_create("1.9.9999","OID_example","Our example OID"); + + si.auth_attr=sk; + /* To retrieve */ + so=PKCS7_get_signed_attribute(&si,signed_seq2string_nid); + if (so->type == V_ASN1_SEQUENCE) + { + ASN1_CTX c; + ASN1_STRING *s; + long length; + ASN1_OCTET_STRING *os1,*os2; + + s=so->value.sequence; + c.p=ASN1_STRING_data(s); + c.max=c.p+ASN1_STRING_length(s); + if (!asn1_GetSequence(&c,&length)) goto err; + /* Length is the length of the seqence */ + + c.q=c.p; + if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) + goto err; + c.slen-=(c.p-c.q); + + c.q=c.p; + if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) + goto err; + c.slen-=(c.p-c.q); + + if (!asn1_Finish(&c)) goto err; + *str1=malloc(os1->length+1); + *str2=malloc(os2->length+1); + memcpy(*str1,os1->data,os1->length); + memcpy(*str2,os2->data,os2->length); + (*str1)[os1->length]='\0'; + (*str2)[os2->length]='\0'; + ASN1_OCTET_STRING_free(os1); + ASN1_OCTET_STRING_free(os2); + return(1); + } +err: + return(0); + } + + diff --git a/src/lib/libcrypto/pkcs7/example.h b/src/lib/libcrypto/pkcs7/example.h new file mode 100644 index 0000000000..96167de188 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/example.h @@ -0,0 +1,57 @@ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +int add_signed_time(PKCS7_SIGNER_INFO *si); +ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si); +int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2); diff --git a/src/lib/libcrypto/pkcs7/info.pem b/src/lib/libcrypto/pkcs7/info.pem new file mode 100644 index 0000000000..989baf8709 --- /dev/null +++ b/src/lib/libcrypto/pkcs7/info.pem @@ -0,0 +1,57 @@ +issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA +subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com +serial :047D + +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 1149 (0x47d) + Signature Algorithm: md5withRSAEncryption + Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA + Validity + Not Before: May 13 05:40:58 1998 GMT + Not After : May 12 05:40:58 2000 GMT + Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + Modulus: + 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81: + 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc: + 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29: + fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f: + e7:e7:0c:4d:0b + Exponent: 65537 (0x10001) + X509v3 extensions: + Netscape Comment: + Generated with SSLeay + Signature Algorithm: md5withRSAEncryption + 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55: + f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97: + d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b: + 50:74:ad:92:cb:4e:90:e5:fa:7d + +-----BEGIN CERTIFICATE----- +MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV +MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE +ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E +IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw +NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK +UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m +dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0 +aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG +9w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf +lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB +hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA +UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8 +4A3ZItobUHStkstOkOX6fQ== +-----END CERTIFICATE----- + +-----BEGIN RSA PRIVATE KEY----- +MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9 +mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG +fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/ +zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29 +p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b +bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk +IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG +-----END RSA PRIVATE KEY----- diff --git a/src/lib/libcrypto/pkcs7/infokey.pem b/src/lib/libcrypto/pkcs7/infokey.pem new file mode 100644 index 0000000000..1e2acc954d --- /dev/null +++ b/src/lib/libcrypto/pkcs7/infokey.pem @@ -0,0 +1,9 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9 +mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG +fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/ +zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29 +p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b +bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk +IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG +-----END RSA PRIVATE KEY----- diff --git a/src/lib/libcrypto/pkcs7/mf.p7 b/src/lib/libcrypto/pkcs7/mf.p7 deleted file mode 100644 index 524335b4b3..0000000000 --- a/src/lib/libcrypto/pkcs7/mf.p7 +++ /dev/null @@ -1,18 +0,0 @@ ------BEGIN PKCS7----- -MIAGCSqGSIb3DQEHAqCAMIIC2QIBATEMMAoGCCqGSIb3DQIFMIAGCSqGSIb3DQEH -AQAAoIIB7TCCAekwggFSAgEAMA0GCSqGSIb3DQEBBAUAMFsxCzAJBgNVBAYTAkFV -MRMwEQYDVQQIEwpRdWVlbnNsYW5kMRowGAYDVQQKExFDcnlwdFNvZnQgUHR5IEx0 -ZDEbMBkGA1UEAxMSVGVzdCBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTc0NloX -DTk4MDYwOTEzNTc0NlowYzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xh -bmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMSMwIQYDVQQDExpTZXJ2ZXIg -dGVzdCBjZXJ0ICg1MTIgYml0KTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCfs8OE -J5X/EjFSDxXvRhHErYDmNlsP3YDXYY3g/HJFCTT+VWZFQ0xol2r+qKCl3194/+7X -ZLg/BMtv/yr+/rntAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAeEzEdgr2nChPcALL -vY8gl/GIlpoAjPmKD+pLeGZI9s+SEX5u1q8nCrJ6ZzkfrRnqgI5Anmev9+qPZfdU -bz5zdVSf4sUL9nX9ChXjK9NCJA3UzQHSFqhZErGUwGNkAHYHp2+zAdY6Ho6rmMzt -g0CDu/sKR4qzm6REsQGS8kgpjz4xgcUwgcICAQEwYDBbMQswCQYDVQQGEwJBVTET -MBEGA1UECBMKUXVlZW5zbGFuZDEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQx -GzAZBgNVBAMTElRlc3QgQ0EgKDEwMjQgYml0KQIBADAKBggqhkiG9w0CBTANBgkq -hkiG9w0BAQQFAARALnrxJiOX9XZf2D+3vL8SKMQmMq55LltomwOLGUru/q1uVXzi -ARg7FSCegOpA1nunsTURMUGgrPXKK4XmL4IseQAAAAA= ------END PKCS7----- diff --git a/src/lib/libcrypto/pkcs7/p7.tst b/src/lib/libcrypto/pkcs7/p7.tst deleted file mode 100644 index 6d14dce163..0000000000 --- a/src/lib/libcrypto/pkcs7/p7.tst +++ /dev/null @@ -1,33 +0,0 @@ ------BEGIN PKCS7----- -MIAGCSqGSIb3DQEHAqCAMIIFsQIBATELMAkGBSsOAwIaBQAwgAYJKoZIhvcNAQcB -AACgggQdMIICJTCCAc+gAwIBAgIBIjANBgkqhkiG9w0BAQQFADCBgjELMAkGA1UE -BhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRow -GAYDVQQKExFDcnlwdFNvZnQgUHR5IEx0ZDEUMBIGA1UECxMLZGV2ZWxvcG1lbnQx -GTAXBgNVBAMTEENyeXB0U29mdCBEZXYgQ0EwHhcNOTcwNjEzMTgxMDE3WhcNOTgw -NjEzMTgxMDE3WjCBiDELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQx -ETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdFNvZnQgUHR5IEx0ZDEU -MBIGA1UECxMLSUlTIHRlc3RpbmcxDjAMBgNVBAMTBXRlc3QxMQ8wDQYJKoZIhvcN -AQkBFgAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAxtWiv59VH42+rotrmFAyDxTc -J2osFt5uy/zEllx3vvjtwewqQxGUOwf6cjqFOTrnpEdVvwywpEhIQ5364bJqIwID -AQABoygwJjAkBglghkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0G -CSqGSIb3DQEBBAUAA0EAMnYkNV2AdpeHPy/qlcdZx6MDGIJgrLhklhcn6Or6KiAP -t9+nv9XdOGHyMyQr9ufsweuQfAgJ9yjKPZR2/adTjTCCAfAwggGaAgEAMA0GCSqG -SIb3DQEBBAUAMIGCMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDER -MA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRQw -EgYDVQQLEwtkZXZlbG9wbWVudDEZMBcGA1UEAxMQQ3J5cHRTb2Z0IERldiBDQTAe -Fw05NzAzMjIxMzM0MDRaFw05ODAzMjIxMzM0MDRaMIGCMQswCQYDVQQGEwJBVTET -MBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoT -EUNyeXB0U29mdCBQdHkgTHRkMRQwEgYDVQQLEwtkZXZlbG9wbWVudDEZMBcGA1UE -AxMQQ3J5cHRTb2Z0IERldiBDQTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDgDgKq -IBuUMAJi4c8juAqEZ8f8FcuDWT+HcScvNztRJy9K8DnbGpiSrzzix4El6N4A7vbl -crwn/0CZmQJguZpfAgMBAAEwDQYJKoZIhvcNAQEEBQADQQA0UUvxlXXe6wKkVukn -ZoCyXbjlNsqt2rwbvfZEam6fQP3S7uq+o1Pnj+KDgE33WxWbQAA9h8fY1LWN7X3a -yTm/MYIBbTCCAWkCAQEwgYgwgYIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVl -bnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0 -eSBMdGQxFDASBgNVBAsTC2RldmVsb3BtZW50MRkwFwYDVQQDExBDcnlwdFNvZnQg -RGV2IENBAgEiMAkGBSsOAwIaBQCgfTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcB -MCMGCSqGSIb3DQEJBDEWBBSUVhbGkNE+KGqpOK13+FkfOkaoizAcBgkqhkiG9w0B -CQUxDxcNOTcwNzAxMDE0MzM0WjAeBgkqhkiG9w0BCQ8xETAPMA0GCCqGSIb3DQMC -AgEoMA0GCSqGSIb3DQEBAQUABECa9Jpo4w/fZOc3Vy78wZFAVF8kvpn7il99Ldsr -AQ4JiBmcfiSwEBBY6WuKT+/SYtFwZl1oXkTwB5AVCFIC/IFNAAAAAA== ------END PKCS7----- diff --git a/src/lib/libcrypto/pkcs7/pk7_dgst.c b/src/lib/libcrypto/pkcs7/pk7_dgst.c index 7769abeb1e..90edfa5001 100644 --- a/src/lib/libcrypto/pkcs7/pk7_dgst.c +++ b/src/lib/libcrypto/pkcs7/pk7_dgst.c @@ -58,9 +58,9 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "rand.h" -#include "objects.h" -#include "x509.h" -#include "pkcs7.h" +#include +#include +#include +#include +#include diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c index b5689b3fe4..dee81b547a 100644 --- a/src/lib/libcrypto/pkcs7/pk7_doit.c +++ b/src/lib/libcrypto/pkcs7/pk7_doit.c @@ -58,20 +58,23 @@ #include #include "cryptlib.h" -#include "rand.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include -BIO *PKCS7_dataInit(p7,bio) -PKCS7 *p7; -BIO *bio; +static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, + void *value); +static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid); + +BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio) { int i,j; - BIO *out=NULL,*btmp; + BIO *out=NULL,*btmp=NULL; X509_ALGOR *xa; - EVP_MD *evp_md; - EVP_CIPHER *evp_cipher=NULL; - STACK *md_sk=NULL,*rsk=NULL; + const EVP_MD *evp_md; + const EVP_CIPHER *evp_cipher=NULL; + STACK_OF(X509_ALGOR) *md_sk=NULL; + STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL; X509_ALGOR *xalg=NULL; PKCS7_RECIP_INFO *ri=NULL; EVP_PKEY *pkey; @@ -87,13 +90,25 @@ BIO *bio; case NID_pkcs7_signedAndEnveloped: rsk=p7->d.signed_and_enveloped->recipientinfo; md_sk=p7->d.signed_and_enveloped->md_algs; - evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(p7->d.signed_and_enveloped->enc_data->algorithm->algorithm))); + xalg=p7->d.signed_and_enveloped->enc_data->algorithm; + evp_cipher=p7->d.signed_and_enveloped->enc_data->cipher; if (evp_cipher == NULL) { - PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); + PKCS7err(PKCS7_F_PKCS7_DATAINIT, + PKCS7_R_CIPHER_NOT_INITIALIZED); + goto err; + } + break; + case NID_pkcs7_enveloped: + rsk=p7->d.enveloped->recipientinfo; + xalg=p7->d.enveloped->enc_data->algorithm; + evp_cipher=p7->d.enveloped->enc_data->cipher; + if (evp_cipher == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATAINIT, + PKCS7_R_CIPHER_NOT_INITIALIZED); goto err; } - xalg=p7->d.signed_and_enveloped->enc_data->algorithm; break; default: PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); @@ -102,10 +117,14 @@ BIO *bio; if (md_sk != NULL) { - for (i=0; ialgorithm); evp_md=EVP_get_digestbyname(OBJ_nid2sn(j)); @@ -120,6 +139,7 @@ BIO *bio; out=btmp; else BIO_push(out,btmp); + btmp=NULL; } } @@ -130,49 +150,70 @@ BIO *bio; int keylen,ivlen; int jj,max; unsigned char *tmp; + EVP_CIPHER_CTX *ctx; - if ((btmp=BIO_new(BIO_f_cipher())) == NULL) goto err; + if ((btmp=BIO_new(BIO_f_cipher())) == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB); + goto err; + } + BIO_get_cipher_ctx(btmp, &ctx); keylen=EVP_CIPHER_key_length(evp_cipher); ivlen=EVP_CIPHER_iv_length(evp_cipher); - - if (ivlen > 0) - { - ASN1_OCTET_STRING *os; - - RAND_bytes(iv,ivlen); - os=ASN1_OCTET_STRING_new(); - ASN1_OCTET_STRING_set(os,iv,ivlen); - /* ASN1_TYPE_set(xalg->parameter,V_ASN1_OCTET_STRING, - (char *)os); - */ } RAND_bytes(key,keylen); + xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher)); + if (ivlen > 0) RAND_bytes(iv,ivlen); + EVP_CipherInit(ctx, evp_cipher, key, iv, 1); + + if (ivlen > 0) { + if (xalg->parameter == NULL) + xalg->parameter=ASN1_TYPE_new(); + if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0) + goto err; + } /* Lets do the pub key stuff :-) */ max=0; - for (i=0; icert == NULL) abort(); + ri=sk_PKCS7_RECIP_INFO_value(rsk,i); + if (ri->cert == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO); + goto err; + } pkey=X509_get_pubkey(ri->cert); jj=EVP_PKEY_size(pkey); + EVP_PKEY_free(pkey); if (max < jj) max=jj; } - if ((tmp=(unsigned char *)Malloc(max)) == NULL) abort(); - for (i=0; icert); jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey); - if (jj <= 0) abort(); + EVP_PKEY_free(pkey); + if (jj <= 0) + { + PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB); + Free(tmp); + goto err; + } ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj); } - - BIO_set_cipher(btmp,evp_cipher,key,iv,1); + Free(tmp); + memset(key, 0, keylen); if (out == NULL) out=btmp; else BIO_push(out,btmp); + btmp=NULL; } if (bio == NULL) /* ??????????? */ @@ -182,6 +223,11 @@ BIO *bio; else { bio=BIO_new(BIO_s_mem()); + /* We need to set this so that when we have read all + * the data, the encrypt BIO, if present, will read + * EOF and encode the last few bytes */ + BIO_set_mem_eof_return(bio,0); + if (PKCS7_type_is_signed(p7) && PKCS7_type_is_data(p7->d.sign->contents)) { @@ -195,14 +241,222 @@ BIO *bio; } } BIO_push(out,bio); + bio=NULL; + if (0) + { +err: + if (out != NULL) + BIO_free_all(out); + if (btmp != NULL) + BIO_free_all(btmp); + out=NULL; + } return(out); + } + +/* int */ +BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) + { + int i,j; + BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL; + char *tmp=NULL; + X509_ALGOR *xa; + ASN1_OCTET_STRING *data_body=NULL; + const EVP_MD *evp_md; + const EVP_CIPHER *evp_cipher=NULL; + EVP_CIPHER_CTX *evp_ctx=NULL; + X509_ALGOR *enc_alg=NULL; + STACK_OF(X509_ALGOR) *md_sk=NULL; + STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL; + X509_ALGOR *xalg=NULL; + PKCS7_RECIP_INFO *ri=NULL; +/* EVP_PKEY *pkey; */ +#if 0 + X509_STORE_CTX s_ctx; +#endif + + i=OBJ_obj2nid(p7->type); + p7->state=PKCS7_S_HEADER; + + switch (i) + { + case NID_pkcs7_signed: + data_body=p7->d.sign->contents->d.data; + md_sk=p7->d.sign->md_algs; + break; + case NID_pkcs7_signedAndEnveloped: + rsk=p7->d.signed_and_enveloped->recipientinfo; + md_sk=p7->d.signed_and_enveloped->md_algs; + data_body=p7->d.signed_and_enveloped->enc_data->enc_data; + enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm; + evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm))); + if (evp_cipher == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); + goto err; + } + xalg=p7->d.signed_and_enveloped->enc_data->algorithm; + break; + case NID_pkcs7_enveloped: + rsk=p7->d.enveloped->recipientinfo; + enc_alg=p7->d.enveloped->enc_data->algorithm; + data_body=p7->d.enveloped->enc_data->enc_data; + evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm))); + if (evp_cipher == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); + goto err; + } + xalg=p7->d.enveloped->enc_data->algorithm; + break; + default: + PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); + goto err; + } + + /* We will be checking the signature */ + if (md_sk != NULL) + { + for (i=0; ialgorithm); + evp_md=EVP_get_digestbyname(OBJ_nid2sn(j)); + if (evp_md == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE); + goto err; + } + + BIO_set_md(btmp,evp_md); + if (out == NULL) + out=btmp; + else + BIO_push(out,btmp); + btmp=NULL; + } + } + + if (evp_cipher != NULL) + { +#if 0 + unsigned char key[EVP_MAX_KEY_LENGTH]; + unsigned char iv[EVP_MAX_IV_LENGTH]; + unsigned char *p; + int keylen,ivlen; + int max; + X509_OBJECT ret; +#endif + int jj; + + if ((etmp=BIO_new(BIO_f_cipher())) == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB); + goto err; + } + + /* It was encrypted, we need to decrypt the secret key + * with the private key */ + + /* Find the recipientInfo which matches the passed certificate + * (if any) + */ + + for (i=0; iissuer_and_serial->issuer, + pcert->cert_info->issuer) && + !ASN1_INTEGER_cmp(pcert->cert_info->serialNumber, + ri->issuer_and_serial->serial)) break; + ri=NULL; + } + if (ri == NULL) { + PKCS7err(PKCS7_F_PKCS7_DATADECODE, + PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE); + return(NULL); + } + + jj=EVP_PKEY_size(pkey); + tmp=Malloc(jj+10); + if (tmp == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE); + goto err; + } + + jj=EVP_PKEY_decrypt((unsigned char *)tmp, + ASN1_STRING_data(ri->enc_key), + ASN1_STRING_length(ri->enc_key), + pkey); + if (jj <= 0) + { + PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB); + goto err; + } + + evp_ctx=NULL; + BIO_get_cipher_ctx(etmp,&evp_ctx); + EVP_CipherInit(evp_ctx,evp_cipher,NULL,NULL,0); + if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0) + return(NULL); + + if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) + { + PKCS7err(PKCS7_F_PKCS7_DATADECODE, + PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH); + goto err; + } + EVP_CipherInit(evp_ctx,NULL,(unsigned char *)tmp,NULL,0); + + memset(tmp,0,jj); + + if (out == NULL) + out=etmp; + else + BIO_push(out,etmp); + etmp=NULL; + } + +#if 1 + if (p7->detached || (in_bio != NULL)) + { + bio=in_bio; + } + else + { + bio=BIO_new(BIO_s_mem()); + /* We need to set this so that when we have read all + * the data, the encrypt BIO, if present, will read + * EOF and encode the last few bytes */ + BIO_set_mem_eof_return(bio,0); + + if (data_body->length > 0) + BIO_write(bio,(char *)data_body->data,data_body->length); + } + BIO_push(out,bio); + bio=NULL; +#endif + if (0) + { err: - return(NULL); + if (out != NULL) BIO_free_all(out); + if (btmp != NULL) BIO_free_all(btmp); + if (etmp != NULL) BIO_free_all(etmp); + if (bio != NULL) BIO_free_all(bio); + out=NULL; + } + if (tmp != NULL) + Free(tmp); + return(out); } -int PKCS7_dataSign(p7,bio) -PKCS7 *p7; -BIO *bio; +int PKCS7_dataFinal(PKCS7 *p7, BIO *bio) { int ret=0; int i,j; @@ -211,7 +465,8 @@ BIO *bio; BUF_MEM *buf=NULL; PKCS7_SIGNER_INFO *si; EVP_MD_CTX *mdc,ctx_tmp; - STACK *sk,*si_sk=NULL; + STACK_OF(X509_ATTRIBUTE) *sk; + STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL; unsigned char *p,*pp=NULL; int x; ASN1_OCTET_STRING *os=NULL; @@ -227,22 +482,35 @@ BIO *bio; os=ASN1_OCTET_STRING_new(); p7->d.signed_and_enveloped->enc_data->enc_data=os; break; + case NID_pkcs7_enveloped: + /* XXXXXXXXXXXXXXXX */ + os=ASN1_OCTET_STRING_new(); + p7->d.enveloped->enc_data->enc_data=os; + break; case NID_pkcs7_signed: si_sk=p7->d.sign->signer_info; os=p7->d.sign->contents->d.data; + /* If detached data then the content is excluded */ + if(p7->detached) { + ASN1_OCTET_STRING_free(os); + p7->d.sign->contents->d.data = NULL; + } break; } if (si_sk != NULL) { - if ((buf=BUF_MEM_new()) == NULL) goto err; - for (i=0; ipkey == NULL) - continue; - j=OBJ_obj2nid(si->digest_enc_alg->algorithm); + si=sk_PKCS7_SIGNER_INFO_value(si_sk,i); + if (si->pkey == NULL) continue; + + j=OBJ_obj2nid(si->digest_alg->algorithm); btmp=bio; for (;;) @@ -259,7 +527,7 @@ BIO *bio; PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR); goto err; } - if (EVP_MD_pkey_type(EVP_MD_CTX_type(mdc)) == j) + if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == j) break; else btmp=btmp->next_bio; @@ -269,75 +537,117 @@ BIO *bio; * signing. */ memcpy(&ctx_tmp,mdc,sizeof(ctx_tmp)); if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey))) + { + PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB); goto err; + } sk=si->auth_attr; - if ((sk != NULL) && (sk_num(sk) != 0)) + + /* If there are attributes, we add the digest + * attribute and only sign the attributes */ + if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0)) { - x=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE, - V_ASN1_SET,V_ASN1_UNIVERSAL); - pp=(unsigned char *)Malloc(i); + unsigned char md_data[EVP_MAX_MD_SIZE]; + unsigned int md_len; + ASN1_OCTET_STRING *digest; + ASN1_UTCTIME *sign_time; + const EVP_MD *md_tmp; + + /* Add signing time */ + sign_time=X509_gmtime_adj(NULL,0); + PKCS7_add_signed_attribute(si, + NID_pkcs9_signingTime, + V_ASN1_UTCTIME,sign_time); + + /* Add digest */ + md_tmp=EVP_MD_CTX_type(&ctx_tmp); + EVP_DigestFinal(&ctx_tmp,md_data,&md_len); + digest=ASN1_OCTET_STRING_new(); + ASN1_OCTET_STRING_set(digest,md_data,md_len); + PKCS7_add_signed_attribute(si, + NID_pkcs9_messageDigest, + V_ASN1_OCTET_STRING,digest); + + /* Now sign the mess */ + EVP_SignInit(&ctx_tmp,md_tmp); + x=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL, + i2d_X509_ATTRIBUTE, + V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); + pp=(unsigned char *)Malloc(x); p=pp; - i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE, - V_ASN1_SET,V_ASN1_UNIVERSAL); + i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p, + i2d_X509_ATTRIBUTE, + V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); EVP_SignUpdate(&ctx_tmp,pp,x); Free(pp); + pp=NULL; } + if (si->pkey->type == EVP_PKEY_DSA) + ctx_tmp.digest=EVP_dss1(); + if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data, (unsigned int *)&buf->length,si->pkey)) + { + PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_EVP_LIB); goto err; + } if (!ASN1_STRING_set(si->enc_digest, (unsigned char *)buf->data,buf->length)) - goto err; - } - if (p7->detached) - ASN1_OCTET_STRING_set(os,(unsigned char *)"",0); - else - { - btmp=BIO_find_type(bio,BIO_TYPE_MEM); - if (btmp == NULL) { - PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO); + PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_ASN1_LIB); goto err; } - BIO_get_mem_ptr(btmp,&buf_mem); - ASN1_OCTET_STRING_set(os, - (unsigned char *)buf_mem->data,buf_mem->length); } - if (pp != NULL) Free(pp); - pp=NULL; } + if (!p7->detached) + { + btmp=BIO_find_type(bio,BIO_TYPE_MEM); + if (btmp == NULL) + { + PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO); + goto err; + } + BIO_get_mem_ptr(btmp,&buf_mem); + ASN1_OCTET_STRING_set(os, + (unsigned char *)buf_mem->data,buf_mem->length); + } + if (pp != NULL) Free(pp); + pp=NULL; + ret=1; err: if (buf != NULL) BUF_MEM_free(buf); return(ret); } -int PKCS7_dataVerify(cert_store,ctx,bio,p7,si) -X509_STORE *cert_store; -X509_STORE_CTX *ctx; -BIO *bio; -PKCS7 *p7; -PKCS7_SIGNER_INFO *si; +int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio, + PKCS7 *p7, PKCS7_SIGNER_INFO *si) { - PKCS7_SIGNED *s; - ASN1_OCTET_STRING *os; - EVP_MD_CTX mdc_tmp,*mdc; - unsigned char *pp,*p; PKCS7_ISSUER_AND_SERIAL *ias; - int ret=0,md_type,i; - STACK *sk; - BIO *btmp; + int ret=0,i; + STACK_OF(X509) *cert; X509 *x509; - if (!PKCS7_type_is_signed(p7)) abort(); + if (PKCS7_type_is_signed(p7)) + { + cert=p7->d.sign->cert; + } + else if (PKCS7_type_is_signedAndEnveloped(p7)) + { + cert=p7->d.signed_and_enveloped->cert; + } + else + { + PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE); + goto err; + } /* XXXXXXXXXXXXXXXXXXXXXXX */ ias=si->issuer_and_serial; - s=p7->d.sign; - x509=X509_find_by_issuer_and_serial(s->cert,ias->issuer,ias->serial); + x509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial); /* were we able to find the cert in passed to us */ if (x509 == NULL) @@ -347,12 +657,39 @@ PKCS7_SIGNER_INFO *si; } /* Lets verify */ - X509_STORE_CTX_init(ctx,cert_store,x509,s->cert); + X509_STORE_CTX_init(ctx,cert_store,x509,cert); i=X509_verify_cert(ctx); - if (i <= 0) goto err; + if (i <= 0) + { + PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB); + goto err; + } X509_STORE_CTX_cleanup(ctx); - /* So we like 'x509', lets check the signature. */ + return PKCS7_signatureVerify(bio, p7, si, x509); + err: + return ret; + } + +int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, + X509 *x509) + { + ASN1_OCTET_STRING *os; + EVP_MD_CTX mdc_tmp,*mdc; + unsigned char *pp,*p; + int ret=0,i; + int md_type; + STACK_OF(X509_ATTRIBUTE) *sk; + BIO *btmp; + EVP_PKEY *pkey; + + if (!PKCS7_type_is_signed(p7) && + !PKCS7_type_is_signedAndEnveloped(p7)) { + PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, + PKCS7_R_WRONG_PKCS7_TYPE); + goto err; + } + md_type=OBJ_obj2nid(si->digest_alg->algorithm); btmp=bio; @@ -361,13 +698,15 @@ PKCS7_SIGNER_INFO *si; if ((btmp == NULL) || ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL)) { - PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); + PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, + PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); goto err; } BIO_get_md_ctx(btmp,&mdc); if (mdc == NULL) { - PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_INTERNAL_ERROR); + PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, + PKCS7_R_INTERNAL_ERROR); goto err; } if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type) @@ -375,28 +714,68 @@ PKCS7_SIGNER_INFO *si; btmp=btmp->next_bio; } - /* mdc is the digest ctx that we want */ + /* mdc is the digest ctx that we want, unless there are attributes, + * in which case the digest is the signed attributes */ memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp)); sk=si->auth_attr; - if ((sk != NULL) && (sk_num(sk) != 0)) + if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0)) { - i=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE, - V_ASN1_SET,V_ASN1_UNIVERSAL); - pp=(unsigned char *)malloc(i); + unsigned char md_dat[EVP_MAX_MD_SIZE]; + unsigned int md_len; + ASN1_OCTET_STRING *message_digest; + + EVP_DigestFinal(&mdc_tmp,md_dat,&md_len); + message_digest=PKCS7_digest_from_attributes(sk); + if (!message_digest) + { + PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, + PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); + goto err; + } + if ((message_digest->length != (int)md_len) || + (memcmp(message_digest->data,md_dat,md_len))) + { +#if 0 +{ +int ii; +for (ii=0; iilength; ii++) + printf("%02X",message_digest->data[ii]); printf(" sent\n"); +for (ii=0; iienc_digest; - i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, - X509_get_pubkey(x509)); + pkey = X509_get_pubkey(x509); + if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1(); + + i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey); + EVP_PKEY_free(pkey); if (i <= 0) { - PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_SIGNATURE_FAILURE); + PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, + PKCS7_R_SIGNATURE_FAILURE); ret= -1; goto err; } @@ -406,3 +785,138 @@ err: return(ret); } +PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx) + { + STACK_OF(PKCS7_RECIP_INFO) *rsk; + PKCS7_RECIP_INFO *ri; + int i; + + i=OBJ_obj2nid(p7->type); + if (i != NID_pkcs7_signedAndEnveloped) return(NULL); + rsk=p7->d.signed_and_enveloped->recipientinfo; + ri=sk_PKCS7_RECIP_INFO_value(rsk,0); + if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL); + ri=sk_PKCS7_RECIP_INFO_value(rsk,idx); + return(ri->issuer_and_serial); + } + +ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid) + { + return(get_attribute(si->auth_attr,nid)); + } + +ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid) + { + return(get_attribute(si->unauth_attr,nid)); + } + +static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid) + { + int i; + X509_ATTRIBUTE *xa; + ASN1_OBJECT *o; + + o=OBJ_nid2obj(nid); + if (!o || !sk) return(NULL); + for (i=0; iobject,o) == 0) + { + if (xa->set && sk_ASN1_TYPE_num(xa->value.set)) + return(sk_ASN1_TYPE_value(xa->value.set,0)); + else + return(NULL); + } + } + return(NULL); + } + +ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk) +{ + ASN1_TYPE *astype; + if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL; + return astype->value.octet_string; +} + +int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, + STACK_OF(X509_ATTRIBUTE) *sk) + { + int i; + + if (p7si->auth_attr != NULL) + sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free); + p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk); + for (i=0; iauth_attr,i, + X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i)))) + == NULL) + return(0); + } + return(1); + } + +int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk) + { + int i; + + if (p7si->unauth_attr != NULL) + sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr, + X509_ATTRIBUTE_free); + p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk); + for (i=0; iunauth_attr,i, + X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i)))) + == NULL) + return(0); + } + return(1); + } + +int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, + void *value) + { + return(add_attribute(&(p7si->auth_attr),nid,atrtype,value)); + } + +int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, + void *value) + { + return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value)); + } + +static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, + void *value) + { + X509_ATTRIBUTE *attr=NULL; + + if (*sk == NULL) + { + *sk = sk_X509_ATTRIBUTE_new(NULL); +new_attrib: + attr=X509_ATTRIBUTE_create(nid,atrtype,value); + sk_X509_ATTRIBUTE_push(*sk,attr); + } + else + { + int i; + + for (i=0; iobject) == nid) + { + X509_ATTRIBUTE_free(attr); + attr=X509_ATTRIBUTE_create(nid,atrtype,value); + sk_X509_ATTRIBUTE_set(*sk,i,attr); + goto end; + } + } + goto new_attrib; + } +end: + return(1); + } + diff --git a/src/lib/libcrypto/pkcs7/pk7_enc.c b/src/lib/libcrypto/pkcs7/pk7_enc.c index a5b6dc463f..acbb189c59 100644 --- a/src/lib/libcrypto/pkcs7/pk7_enc.c +++ b/src/lib/libcrypto/pkcs7/pk7_enc.c @@ -58,11 +58,11 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "rand.h" -#include "objects.h" -#include "x509.h" -#include "pkcs7.h" +#include +#include +#include +#include +#include PKCS7_in_bio(PKCS7 *p7,BIO *in); PKCS7_out_bio(PKCS7 *p7,BIO *out); diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c index 7d14ad1173..8b863d0558 100644 --- a/src/lib/libcrypto/pkcs7/pk7_lib.c +++ b/src/lib/libcrypto/pkcs7/pk7_lib.c @@ -58,14 +58,10 @@ #include #include "cryptlib.h" -#include "objects.h" -#include "x509.h" - -long PKCS7_ctrl(p7,cmd,larg,parg) -PKCS7 *p7; -int cmd; -long larg; -char *parg; +#include +#include + +long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg) { int nid; long ret; @@ -98,14 +94,13 @@ char *parg; break; default: - abort(); + PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_UNKNOWN_OPERATION); + ret=0; } return(ret); } -int PKCS7_content_new(p7,type) -PKCS7 *p7; -int type; +int PKCS7_content_new(PKCS7 *p7, int type) { PKCS7 *ret=NULL; @@ -119,9 +114,7 @@ err: return(0); } -int PKCS7_set_content(p7,p7_data) -PKCS7 *p7; -PKCS7 *p7_data; +int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data) { int i; @@ -147,9 +140,7 @@ err: return(0); } -int PKCS7_set_type(p7,type) -PKCS7 *p7; -int type; +int PKCS7_set_type(PKCS7 *p7, int type) { ASN1_OBJECT *obj; @@ -172,12 +163,19 @@ int type; case NID_pkcs7_signedAndEnveloped: p7->type=obj; if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new()) - == NULL) - goto err; - ASN1_INTEGER_set(p7->d.sign->version,1); + == NULL) goto err; + ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1); +/* p7->d.signed_and_enveloped->enc_data->content_type= + OBJ_nid2obj(NID_pkcs7_encrypted);*/ + break; - case NID_pkcs7_digest: case NID_pkcs7_enveloped: + p7->type=obj; + if ((p7->d.enveloped=PKCS7_ENVELOPE_new()) + == NULL) goto err; + ASN1_INTEGER_set(p7->d.enveloped->version,0); + break; + case NID_pkcs7_digest: case NID_pkcs7_encrypted: default: PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); @@ -188,14 +186,12 @@ err: return(0); } -int PKCS7_add_signer(p7,psi) -PKCS7 *p7; -PKCS7_SIGNER_INFO *psi; +int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi) { int i,j,nid; X509_ALGOR *alg; - STACK *signer_sk; - STACK *md_sk; + STACK_OF(PKCS7_SIGNER_INFO) *signer_sk; + STACK_OF(X509_ALGOR) *md_sk; i=OBJ_obj2nid(p7->type); switch (i) @@ -217,9 +213,9 @@ PKCS7_SIGNER_INFO *psi; /* If the digest is not currently listed, add it */ j=0; - for (i=0; ialgorithm) == nid) { j=1; @@ -230,19 +226,17 @@ PKCS7_SIGNER_INFO *psi; { alg=X509_ALGOR_new(); alg->algorithm=OBJ_nid2obj(nid); - sk_push(md_sk,(char *)alg); + sk_X509_ALGOR_push(md_sk,alg); } - sk_push(signer_sk,(char *)psi); + sk_PKCS7_SIGNER_INFO_push(signer_sk,psi); return(1); } -int PKCS7_add_certificate(p7,x509) -PKCS7 *p7; -X509 *x509; +int PKCS7_add_certificate(PKCS7 *p7, X509 *x509) { int i; - STACK **sk; + STACK_OF(X509) **sk; i=OBJ_obj2nid(p7->type); switch (i) @@ -259,18 +253,16 @@ X509 *x509; } if (*sk == NULL) - *sk=sk_new_null(); + *sk=sk_X509_new_null(); CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); - sk_push(*sk,(char *)x509); + sk_X509_push(*sk,x509); return(1); } -int PKCS7_add_crl(p7,crl) -PKCS7 *p7; -X509_CRL *crl; +int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl) { int i; - STACK **sk; + STACK_OF(X509_CRL) **sk; i=OBJ_obj2nid(p7->type); switch (i) @@ -287,18 +279,15 @@ X509_CRL *crl; } if (*sk == NULL) - *sk=sk_new_null(); + *sk=sk_X509_CRL_new_null(); CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL); - sk_push(*sk,(char *)crl); + sk_X509_CRL_push(*sk,crl); return(1); } -int PKCS7_SIGNER_INFO_set(p7i,x509,pkey,dgst) -PKCS7_SIGNER_INFO *p7i; -X509 *x509; -EVP_PKEY *pkey; -EVP_MD *dgst; +int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, + EVP_MD *dgst) { /* We now need to add another PKCS7_SIGNER_INFO entry */ ASN1_INTEGER_set(p7i->version,1); @@ -316,27 +305,32 @@ EVP_MD *dgst; p7i->pkey=pkey; /* Set the algorithms */ - p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst)); - p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_MD_pkey_type(dgst)); + if (pkey->type == EVP_PKEY_DSA) + p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1); + else + p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst)); + + if (p7i->digest_alg->parameter != NULL) + ASN1_TYPE_free(p7i->digest_alg->parameter); + if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL) + goto err; + p7i->digest_alg->parameter->type=V_ASN1_NULL; + + p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type)); -#if 1 if (p7i->digest_enc_alg->parameter != NULL) ASN1_TYPE_free(p7i->digest_enc_alg->parameter); if ((p7i->digest_enc_alg->parameter=ASN1_TYPE_new()) == NULL) goto err; p7i->digest_enc_alg->parameter->type=V_ASN1_NULL; -#endif return(1); err: return(0); } -PKCS7_SIGNER_INFO *PKCS7_add_signature(p7,x509,pkey,dgst) -PKCS7 *p7; -X509 *x509; -EVP_PKEY *pkey; -EVP_MD *dgst; +PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey, + EVP_MD *dgst) { PKCS7_SIGNER_INFO *si; @@ -348,20 +342,21 @@ err: return(NULL); } -STACK *PKCS7_get_signer_info(p7) -PKCS7 *p7; +STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7) { if (PKCS7_type_is_signed(p7)) { return(p7->d.sign->signer_info); } + else if (PKCS7_type_is_signedAndEnveloped(p7)) + { + return(p7->d.signed_and_enveloped->signer_info); + } else return(NULL); } -PKCS7_RECIP_INFO *PKCS7_add_recipient(p7,x509) -PKCS7 *p7; -X509 *x509; +PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509) { PKCS7_RECIP_INFO *ri; @@ -373,12 +368,10 @@ err: return(NULL); } -int PKCS7_add_recipient_info(p7,ri) -PKCS7 *p7; -PKCS7_RECIP_INFO *ri; +int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri) { int i; - STACK *sk; + STACK_OF(PKCS7_RECIP_INFO) *sk; i=OBJ_obj2nid(p7->type); switch (i) @@ -386,18 +379,19 @@ PKCS7_RECIP_INFO *ri; case NID_pkcs7_signedAndEnveloped: sk= p7->d.signed_and_enveloped->recipientinfo; break; + case NID_pkcs7_enveloped: + sk= p7->d.enveloped->recipientinfo; + break; default: PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE); return(0); } - sk_push(sk,(char *)ri); + sk_PKCS7_RECIP_INFO_push(sk,ri); return(1); } -int PKCS7_RECIP_INFO_set(p7i,x509) -PKCS7_RECIP_INFO *p7i; -X509 *x509; +int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509) { ASN1_INTEGER_set(p7i->version,0); X509_NAME_set(&p7i->issuer_and_serial->issuer, @@ -407,15 +401,18 @@ X509 *x509; p7i->issuer_and_serial->serial= ASN1_INTEGER_dup(X509_get_serialNumber(x509)); + X509_ALGOR_free(p7i->key_enc_algor); + p7i->key_enc_algor=(X509_ALGOR *)ASN1_dup(i2d_X509_ALGOR, + (char *(*)())d2i_X509_ALGOR, + (char *)x509->cert_info->key->algor); + CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); p7i->cert=x509; return(1); } -X509 *PKCS7_cert_from_signer_info(p7,si) -PKCS7 *p7; -PKCS7_SIGNER_INFO *si; +X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si) { if (PKCS7_type_is_signed(p7)) return(X509_find_by_issuer_and_serial(p7->d.sign->cert, @@ -425,9 +422,7 @@ PKCS7_SIGNER_INFO *si; return(NULL); } -int PKCS7_set_cipher(p7,cipher) -PKCS7 *p7; -EVP_CIPHER *cipher; +int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher) { int i; PKCS7_ENC_CONTENT *ec; @@ -438,12 +433,17 @@ EVP_CIPHER *cipher; case NID_pkcs7_signedAndEnveloped: ec=p7->d.signed_and_enveloped->enc_data; break; + case NID_pkcs7_enveloped: + ec=p7->d.enveloped->enc_data; + break; default: PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE); return(0); } - ec->algorithm->algorithm=OBJ_nid2obj(EVP_CIPHER_nid(cipher)); - return(ec->algorithm->algorithm != NULL); + /* Setup cipher OID */ + + ec->cipher = cipher; + return 1; } diff --git a/src/lib/libcrypto/pkcs7/pkcs7.err b/src/lib/libcrypto/pkcs7/pkcs7.err deleted file mode 100644 index 91413aae43..0000000000 --- a/src/lib/libcrypto/pkcs7/pkcs7.err +++ /dev/null @@ -1,26 +0,0 @@ -/* Error codes for the PKCS7 functions. */ - -/* Function codes. */ -#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100 -#define PKCS7_F_PKCS7_ADD_CRL 101 -#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 -#define PKCS7_F_PKCS7_ADD_SIGNER 103 -#define PKCS7_F_PKCS7_CTRL 104 -#define PKCS7_F_PKCS7_DATAINIT 105 -#define PKCS7_F_PKCS7_DATASIGN 106 -#define PKCS7_F_PKCS7_DATAVERIFY 107 -#define PKCS7_F_PKCS7_SET_CIPHER 108 -#define PKCS7_F_PKCS7_SET_CONTENT 109 -#define PKCS7_F_PKCS7_SET_TYPE 110 - -/* Reason codes. */ -#define PKCS7_R_INTERNAL_ERROR 100 -#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 101 -#define PKCS7_R_SIGNATURE_FAILURE 102 -#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 103 -#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 104 -#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 105 -#define PKCS7_R_UNKNOWN_DIGEST_TYPE 106 -#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 107 -#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 108 -#define PKCS7_R_WRONG_CONTENT_TYPE 109 diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h index ee12f670a8..c42bd6d391 100644 --- a/src/lib/libcrypto/pkcs7/pkcs7.h +++ b/src/lib/libcrypto/pkcs7/pkcs7.h @@ -63,8 +63,17 @@ extern "C" { #endif -#include "bio.h" -#include "x509.h" +#include +#include + +#ifdef VMS +#include +#endif + +#ifdef WIN32 +/* Under Win32 this is defined in wincrypt.h */ +#undef PKCS7_ISSUER_AND_SERIAL +#endif /* Encryption_ID DES-CBC @@ -84,15 +93,18 @@ typedef struct pkcs7_signer_info_st ASN1_INTEGER *version; /* version 1 */ PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; X509_ALGOR *digest_alg; - STACK /* X509_ATTRIBUTE */ *auth_attr; /* [ 0 ] */ + STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */ X509_ALGOR *digest_enc_alg; ASN1_OCTET_STRING *enc_digest; - STACK /* X509_ATTRIBUTE */ *unauth_attr; /* [ 1 ] */ + STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */ /* The private key to sign with */ EVP_PKEY *pkey; } PKCS7_SIGNER_INFO; +DECLARE_STACK_OF(PKCS7_SIGNER_INFO) +DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) + typedef struct pkcs7_recip_info_st { ASN1_INTEGER *version; /* version 0 */ @@ -102,13 +114,16 @@ typedef struct pkcs7_recip_info_st X509 *cert; /* get the pub-key from this */ } PKCS7_RECIP_INFO; +DECLARE_STACK_OF(PKCS7_RECIP_INFO) +DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) + typedef struct pkcs7_signed_st { ASN1_INTEGER *version; /* version 1 */ - STACK /* X509_ALGOR's */ *md_algs; /* md used */ - STACK /* X509 */ *cert; /* [ 0 ] */ - STACK /* X509_CRL */ *crl; /* [ 1 ] */ - STACK /* PKCS7_SIGNER_INFO */ *signer_info; + STACK_OF(X509_ALGOR) *md_algs; /* md used */ + STACK_OF(X509) *cert; /* [ 0 ] */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ + STACK_OF(PKCS7_SIGNER_INFO) *signer_info; struct pkcs7_st *contents; } PKCS7_SIGNED; @@ -120,25 +135,26 @@ typedef struct pkcs7_enc_content_st ASN1_OBJECT *content_type; X509_ALGOR *algorithm; ASN1_OCTET_STRING *enc_data; /* [ 0 ] */ + const EVP_CIPHER *cipher; } PKCS7_ENC_CONTENT; typedef struct pkcs7_enveloped_st { ASN1_INTEGER *version; /* version 0 */ - STACK /* PKCS7_RECIP_INFO */ *recipientinfo; + STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; PKCS7_ENC_CONTENT *enc_data; } PKCS7_ENVELOPE; - + typedef struct pkcs7_signedandenveloped_st { ASN1_INTEGER *version; /* version 1 */ - STACK /* X509_ALGOR's */ *md_algs; /* md used */ - STACK /* X509 */ *cert; /* [ 0 ] */ - STACK /* X509_CRL */ *crl; /* [ 1 ] */ - STACK /* PKCS7_SIGNER_INFO */ *signer_info; + STACK_OF(X509_ALGOR) *md_algs; /* md used */ + STACK_OF(X509) *cert; /* [ 0 ] */ + STACK_OF(X509_CRL) *crl; /* [ 1 ] */ + STACK_OF(PKCS7_SIGNER_INFO) *signer_info; PKCS7_ENC_CONTENT *enc_data; - STACK /* PKCS7_RECIP_INFO */ *recipientinfo; + STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; } PKCS7_SIGN_ENVELOPE; typedef struct pkcs7_digest_st @@ -199,7 +215,12 @@ typedef struct pkcs7_st #define PKCS7_OP_SET_DETACHED_SIGNATURE 1 #define PKCS7_OP_GET_DETACHED_SIGNATURE 2 +#define PKCS7_get_signed_attributes(si) ((si)->auth_attr) +#define PKCS7_get_attributes(si) ((si)->unauth_attr) + #define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) +#define PKCS7_type_is_signedAndEnveloped(a) \ + (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) #define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) #define PKCS7_set_detached(p,v) \ @@ -208,14 +229,14 @@ typedef struct pkcs7_st PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) #ifdef SSLEAY_MACROS - +#ifndef PKCS7_ISSUER_AND_SERIAL_digest #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ (char *)data,md,len) #endif +#endif -#ifndef NOPROTO PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void ); void PKCS7_ISSUER_AND_SERIAL_free( PKCS7_ISSUER_AND_SERIAL *a); @@ -229,11 +250,11 @@ PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL( int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,EVP_MD *type, unsigned char *md,unsigned int *len); #ifndef NO_FP_API -PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 *p7); +PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7); int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7); #endif PKCS7 *PKCS7_dup(PKCS7 *p7); -PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 *p7); +PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7); int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7); #endif @@ -314,107 +335,45 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); int PKCS7_add_certificate(PKCS7 *p7, X509 *x509); int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); int PKCS7_content_new(PKCS7 *p7, int nid); -int PKCS7_dataSign(PKCS7 *p7, BIO *bio); int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); +int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, + X509 *x509); BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); -/*int PKCS7_DataFinal(PKCS7 *p7, BIO *bio); */ +int PKCS7_dataFinal(PKCS7 *p7, BIO *bio); +BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert); + PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey, EVP_MD *dgst); X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); -STACK *PKCS7_get_signer_info(PKCS7 *p7); +STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7); PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); -int PKCS7_set_cipher(PKCS7 *p7, EVP_CIPHER *cipher); - +int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher); +PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx); +ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk); +int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type, + void *data); +int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, + void *value); +ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid); +ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid); +int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, + STACK_OF(X509_ATTRIBUTE) *sk); +int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk); -#else -PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(); -void PKCS7_ISSUER_AND_SERIAL_free(); -int i2d_PKCS7_ISSUER_AND_SERIAL(); -PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(); - -#ifndef SSLEAY_MACROS -int PKCS7_ISSUER_AND_SERIAL_digest(); -#ifndef NO_FP_API -PKCS7 *d2i_PKCS7_fp(); -int i2d_PKCS7_fp(); -#endif -PKCS7 *PKCS7_dup(); -PKCS7 *d2i_PKCS7_bio(); -int i2d_PKCS7_bio(); - -#endif - -PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(); -void PKCS7_SIGNER_INFO_free(); -int i2d_PKCS7_SIGNER_INFO(); -PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(); -PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(); -void PKCS7_RECIP_INFO_free(); -int i2d_PKCS7_RECIP_INFO(); -PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(); -PKCS7_SIGNED *PKCS7_SIGNED_new(); -void PKCS7_SIGNED_free(); -int i2d_PKCS7_SIGNED(); -PKCS7_SIGNED *d2i_PKCS7_SIGNED(); -PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(); -void PKCS7_ENC_CONTENT_free(); -int i2d_PKCS7_ENC_CONTENT(); -PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(); -PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(); -void PKCS7_ENVELOPE_free(); -int i2d_PKCS7_ENVELOPE(); -PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(); -PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(); -void PKCS7_SIGN_ENVELOPE_free(); -int i2d_PKCS7_SIGN_ENVELOPE(); -PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(); -PKCS7_DIGEST *PKCS7_DIGEST_new(); -void PKCS7_DIGEST_free(); -int i2d_PKCS7_DIGEST(); -PKCS7_DIGEST *d2i_PKCS7_DIGEST(); -PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(); -void PKCS7_ENCRYPT_free(); -int i2d_PKCS7_ENCRYPT(); -PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(); -PKCS7 *PKCS7_new(); -void PKCS7_free(); -void PKCS7_content_free(); -int i2d_PKCS7(); -PKCS7 *d2i_PKCS7(); - -void ERR_load_PKCS7_strings(); - -long PKCS7_ctrl(); -int PKCS7_set_type(); -int PKCS7_set_content(); -int PKCS7_SIGNER_INFO_set(); -int PKCS7_add_signer(); -int PKCS7_add_certificate(); -int PKCS7_add_crl(); -int PKCS7_content_new(); -int PKCS7_dataSign(); -int PKCS7_dataVerify(); -BIO *PKCS7_dataInit(); -PKCS7_SIGNER_INFO *PKCS7_add_signature(); -X509 *PKCS7_cert_from_signer_info(); -STACK *PKCS7_get_signer_info(); - -PKCS7_RECIP_INFO *PKCS7_add_recipient(); -int PKCS7_add_recipient_info(); -int PKCS7_RECIP_INFO_set(); -int PKCS7_set_cipher(); - -#endif /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the PKCS7 functions. */ /* Function codes. */ @@ -423,25 +382,34 @@ int PKCS7_set_cipher(); #define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 #define PKCS7_F_PKCS7_ADD_SIGNER 103 #define PKCS7_F_PKCS7_CTRL 104 +#define PKCS7_F_PKCS7_DATADECODE 112 #define PKCS7_F_PKCS7_DATAINIT 105 #define PKCS7_F_PKCS7_DATASIGN 106 #define PKCS7_F_PKCS7_DATAVERIFY 107 #define PKCS7_F_PKCS7_SET_CIPHER 108 #define PKCS7_F_PKCS7_SET_CONTENT 109 #define PKCS7_F_PKCS7_SET_TYPE 110 +#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113 /* Reason codes. */ -#define PKCS7_R_INTERNAL_ERROR 100 -#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 101 -#define PKCS7_R_SIGNATURE_FAILURE 102 -#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 103 -#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 104 -#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 105 -#define PKCS7_R_UNKNOWN_DIGEST_TYPE 106 -#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 107 -#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 108 -#define PKCS7_R_WRONG_CONTENT_TYPE 109 - +#define PKCS7_R_CIPHER_NOT_INITIALIZED 116 +#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100 +#define PKCS7_R_DIGEST_FAILURE 101 +#define PKCS7_R_INTERNAL_ERROR 102 +#define PKCS7_R_MISSING_CERIPEND_INFO 103 +#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115 +#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104 +#define PKCS7_R_SIGNATURE_FAILURE 105 +#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106 +#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107 +#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108 +#define PKCS7_R_UNKNOWN_DIGEST_TYPE 109 +#define PKCS7_R_UNKNOWN_OPERATION 110 +#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111 +#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112 +#define PKCS7_R_WRONG_CONTENT_TYPE 113 +#define PKCS7_R_WRONG_PKCS7_TYPE 114 + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c index f851057422..82be3c2ca1 100644 --- a/src/lib/libcrypto/pkcs7/pkcs7err.c +++ b/src/lib/libcrypto/pkcs7/pkcs7err.c @@ -1,63 +1,65 @@ -/* lib/pkcs7/pkcs7_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/pkcs7/pkcs7err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "pkcs7.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -68,38 +70,47 @@ static ERR_STRING_DATA PKCS7_str_functs[]= {ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"}, {ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"}, {ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"}, +{ERR_PACK(0,PKCS7_F_PKCS7_DATADECODE,0), "PKCS7_dataDecode"}, {ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"}, -{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_dataSign"}, +{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_DATASIGN"}, {ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"}, {ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"}, {ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"}, {ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"}, -{0,NULL}, +{ERR_PACK(0,PKCS7_F_PKCS7_SIGNATUREVERIFY,0), "PKCS7_signatureVerify"}, +{0,NULL} }; static ERR_STRING_DATA PKCS7_str_reasons[]= { +{PKCS7_R_CIPHER_NOT_INITIALIZED ,"cipher not initialized"}, +{PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH ,"decrypted key is wrong length"}, +{PKCS7_R_DIGEST_FAILURE ,"digest failure"}, {PKCS7_R_INTERNAL_ERROR ,"internal error"}, +{PKCS7_R_MISSING_CERIPEND_INFO ,"missing ceripend info"}, +{PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE,"no recipient matches certificate"}, {PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"}, {PKCS7_R_SIGNATURE_FAILURE ,"signature failure"}, {PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"}, {PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"}, {PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"}, {PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"}, +{PKCS7_R_UNKNOWN_OPERATION ,"unknown operation"}, {PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"}, {PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"}, {PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"}, -{0,NULL}, +{PKCS7_R_WRONG_PKCS7_TYPE ,"wrong pkcs7 type"}, +{0,NULL} }; #endif -void ERR_load_PKCS7_strings() +void ERR_load_PKCS7_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_functs); diff --git a/src/lib/libcrypto/pkcs7/sign.c b/src/lib/libcrypto/pkcs7/sign.c index ead1cb65ca..d5f1154006 100644 --- a/src/lib/libcrypto/pkcs7/sign.c +++ b/src/lib/libcrypto/pkcs7/sign.c @@ -56,23 +56,23 @@ * [including the GNU Public Licence.] */ #include -#include "bio.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { X509 *x509; EVP_PKEY *pkey; PKCS7 *p7; - PKCS7 *p7_data; PKCS7_SIGNER_INFO *si; BIO *in; BIO *data,*p7bio; char buf[1024*4]; - int i,j; + int i; int nodetach=0; EVP_add_digest(EVP_md2()); @@ -105,7 +105,12 @@ again: p7=PKCS7_new(); PKCS7_set_type(p7,NID_pkcs7_signed); - if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err; + si=PKCS7_add_signature(p7,x509,pkey,EVP_sha1()); + if (si == NULL) goto err; + + /* If you do this then you get signing time automatically added */ + PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, V_ASN1_OBJECT, + OBJ_nid2obj(NID_pkcs7_data)); /* we may want to add more */ PKCS7_add_certificate(p7,x509); @@ -125,7 +130,7 @@ again: BIO_write(p7bio,buf,i); } - if (!PKCS7_dataSign(p7,p7bio)) goto err; + if (!PKCS7_dataFinal(p7,p7bio)) goto err; BIO_free(p7bio); PEM_write_PKCS7(stdout,p7); diff --git a/src/lib/libcrypto/pkcs7/verify.c b/src/lib/libcrypto/pkcs7/verify.c index 0e1c1b26dc..32d9783e45 100644 --- a/src/lib/libcrypto/pkcs7/verify.c +++ b/src/lib/libcrypto/pkcs7/verify.c @@ -56,41 +56,41 @@ * [including the GNU Public Licence.] */ #include -#include "asn1.h" -#include "bio.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include +#include +#include "example.h" int verify_callback(int ok, X509_STORE_CTX *ctx); BIO *bio_err=NULL; +BIO *bio_out=NULL; -main(argc,argv) +int main(argc,argv) int argc; char *argv[]; { - X509 *x509,*x; PKCS7 *p7; - PKCS7_SIGNED *s; PKCS7_SIGNER_INFO *si; - PKCS7_ISSUER_AND_SERIAL *ias; X509_STORE_CTX cert_ctx; X509_STORE *cert_store=NULL; - X509_LOOKUP *lookup=NULL; BIO *data,*detached=NULL,*p7bio=NULL; char buf[1024*4]; - unsigned char *p,*pp; - int i,j,printit=0; - STACK *sk; + char *pp; + int i,printit=0; + STACK_OF(PKCS7_SIGNER_INFO) *sk; bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); + bio_out=BIO_new_fp(stdout,BIO_NOCLOSE); EVP_add_digest(EVP_md2()); EVP_add_digest(EVP_md5()); EVP_add_digest(EVP_sha1()); EVP_add_digest(EVP_mdc2()); data=BIO_new(BIO_s_file()); -again: + pp=NULL; while (argc > 1) { @@ -131,10 +131,10 @@ again: X509_STORE_load_locations(cert_store,NULL,"../../certs"); X509_STORE_set_verify_cb_func(cert_store,verify_callback); - ERR_clear_errors(); + ERR_clear_error(); /* We need to process the data */ - if (PKCS7_get_detached(p7)) + if ((PKCS7_get_detached(p7) || detached)) { if (detached == NULL) { @@ -166,12 +166,29 @@ again: } /* Ok, first we need to, for each subject entry, see if we can verify */ - for (i=0; i> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,21 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +md_rand.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +rand_lib.o: ../../include/openssl/rand.h +randfile.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +randfile.o: ../../include/openssl/opensslconf.h ../../include/openssl/rand.h diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c index f44b36a8b9..6bd1960e1d 100644 --- a/src/lib/libcrypto/rand/md_rand.c +++ b/src/lib/libcrypto/rand/md_rand.c @@ -57,21 +57,25 @@ */ #include -#include "cryptlib.h" #include #include +#include + +#include "openssl/e_os.h" + +#include #if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND) -#ifndef NO_MD5 -#define USE_MD5_RAND -#elif !defined(NO_SHA1) +#if !defined(NO_SHA) && !defined(NO_SHA1) #define USE_SHA1_RAND -#elif !defined(NO_MDC2) +#elif !defined(NO_MD5) +#define USE_MD5_RAND +#elif !defined(NO_MDC2) && !defined(NO_DES) #define USE_MDC2_RAND #elif !defined(NO_MD2) #define USE_MD2_RAND #else -We need a message digest of some type +#error No message digest algorithm available #endif #endif @@ -82,60 +86,78 @@ We need a message digest of some type */ #if defined(USE_MD5_RAND) -#include "md5.h" +#include #define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH #define MD_CTX MD5_CTX #define MD_Init(a) MD5_Init(a) #define MD_Update(a,b,c) MD5_Update(a,b,c) #define MD_Final(a,b) MD5_Final(a,b) +#define MD(a,b,c) MD5(a,b,c) #elif defined(USE_SHA1_RAND) -#include "sha.h" +#include #define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH #define MD_CTX SHA_CTX #define MD_Init(a) SHA1_Init(a) #define MD_Update(a,b,c) SHA1_Update(a,b,c) #define MD_Final(a,b) SHA1_Final(a,b) +#define MD(a,b,c) SHA1(a,b,c) #elif defined(USE_MDC2_RAND) -#include "mdc2.h" +#include #define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH #define MD_CTX MDC2_CTX #define MD_Init(a) MDC2_Init(a) #define MD_Update(a,b,c) MDC2_Update(a,b,c) #define MD_Final(a,b) MDC2_Final(a,b) +#define MD(a,b,c) MDC2(a,b,c) #elif defined(USE_MD2_RAND) -#include "md2.h" +#include #define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH #define MD_CTX MD2_CTX #define MD_Init(a) MD2_Init(a) #define MD_Update(a,b,c) MD2_Update(a,b,c) #define MD_Final(a,b) MD2_Final(a,b) +#define MD(a,b,c) MD2(a,b,c) #endif -#include "rand.h" +#include -/*#define NORAND 1 */ -/*#define PREDICT 1 */ +/* #define NORAND 1 */ +/* #define PREDICT 1 */ #define STATE_SIZE 1023 static int state_num=0,state_index=0; static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH]; static unsigned char md[MD_DIGEST_LENGTH]; -static int md_count=0; +static long md_count[2]={0,0}; + +const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT; + +static void ssleay_rand_cleanup(void); +static void ssleay_rand_seed(const void *buf, int num); +static void ssleay_rand_bytes(unsigned char *buf, int num); -char *RAND_version="RAND part of SSLeay 0.9.0b 29-Jun-1998"; +RAND_METHOD rand_ssleay_meth={ + ssleay_rand_seed, + ssleay_rand_bytes, + ssleay_rand_cleanup, + }; -void RAND_cleanup() +RAND_METHOD *RAND_SSLeay(void) + { + return(&rand_ssleay_meth); + } + +static void ssleay_rand_cleanup(void) { memset(state,0,sizeof(state)); state_num=0; state_index=0; memset(md,0,MD_DIGEST_LENGTH); - md_count=0; + md_count[0]=0; + md_count[1]=0; } -void RAND_seed(buf,num) -unsigned char *buf; -int num; +static void ssleay_rand_seed(const void *buf, int num) { int i,j,k,st_idx,st_num; MD_CTX m; @@ -178,9 +200,11 @@ int num; MD_Update(&m,&(state[st_idx]),j); MD_Update(&m,buf,j); + MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count)); MD_Final(md,&m); + md_count[1]++; - buf+=j; + buf=(const char *)buf + j; for (k=0; k -#include +#include /***************************************************************************** * Initialisation function for the SSL random generator. Takes the contents @@ -320,13 +344,13 @@ int num; * ; * the original copyright message is: * -// (C) Copyright Microsoft Corp. 1993. All rights reserved. -// -// You have a royalty-free right to use, modify, reproduce and -// distribute the Sample Files (and/or any modified version) in -// any way you find useful, provided that you agree that -// Microsoft has no warranty obligations or liability for any -// Sample Application Files which are modified. + * (C) Copyright Microsoft Corp. 1993. All rights reserved. + * + * You have a royalty-free right to use, modify, reproduce and + * distribute the Sample Files (and/or any modified version) in + * any way you find useful, provided that you agree that + * Microsoft has no warranty obligations or liability for any + * Sample Application Files which are modified. */ /* * I have modified the loading of bytes via RAND_seed() mechanism since @@ -385,7 +409,7 @@ void RAND_screen(void) GetBitmapBits(hBitmap, size, bmbits); /* Get the MD5 of the bitmap */ - MD5(bmbits,size,md); + MD(bmbits,size,md); /* Seed the random generator with the MD5 digest */ RAND_seed(md, MD_DIGEST_LENGTH); diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h index 477d7a150a..fd8ee38366 100644 --- a/src/lib/libcrypto/rand/rand.h +++ b/src/lib/libcrypto/rand/rand.h @@ -63,28 +63,25 @@ extern "C" { #endif -#ifndef NOPROTO +typedef struct rand_meth_st + { + void (*seed)(const void *buf, int num); + void (*bytes)(unsigned char *buf, int num); + void (*cleanup)(void); + } RAND_METHOD; + +void RAND_set_rand_method(RAND_METHOD *meth); +RAND_METHOD *RAND_get_rand_method(void ); +RAND_METHOD *RAND_SSLeay(void); void RAND_cleanup(void ); -void RAND_bytes( unsigned char *buf,int num); -void RAND_seed( unsigned char *buf,int num); -int RAND_load_file(char *file,long max_bytes); -int RAND_write_file(char *file); +void RAND_bytes(unsigned char *buf,int num); +void RAND_seed(const void *buf,int num); +int RAND_load_file(const char *file,long max_bytes); +int RAND_write_file(const char *file); char *RAND_file_name(char *file,int num); #ifdef WINDOWS void RAND_screen(void); #endif -#else -void RAND_cleanup(); -void RAND_bytes(); -void RAND_seed(); -int RAND_load_file(); -int RAND_write_file(); -char *RAND_file_name(); -#ifdef WINDOWS -void RAND_screen(); -#endif -#endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c new file mode 100644 index 0000000000..34c6d5b968 --- /dev/null +++ b/src/lib/libcrypto/rand/rand_lib.c @@ -0,0 +1,98 @@ +/* crypto/rand/rand_lib.c */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#include +#include +#include +#include + +#ifdef NO_RAND +static RAND_METHOD *rand_meth=NULL; +#else +extern RAND_METHOD rand_ssleay_meth; +static RAND_METHOD *rand_meth= &rand_ssleay_meth; +#endif + +void RAND_set_rand_method(RAND_METHOD *meth) + { + rand_meth=meth; + } + +RAND_METHOD *RAND_get_rand_method(void) + { + return(rand_meth); + } + +void RAND_cleanup(void) + { + if (rand_meth != NULL) + rand_meth->cleanup(); + } + +void RAND_seed(const void *buf, int num) + { + if (rand_meth != NULL) + rand_meth->seed(buf,num); + } + +void RAND_bytes(unsigned char *buf, int num) + { + if (rand_meth != NULL) + rand_meth->bytes(buf,num); + } + diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index f2b3746363..6829d4ec37 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c @@ -56,11 +56,17 @@ * [including the GNU Public Licence.] */ +#include #include -#include "cryptlib.h" +#include +#include +#include #include #include -#include "rand.h" + +#include "openssl/e_os.h" + +#include #undef BUFSIZE #define BUFSIZE 1024 @@ -68,9 +74,7 @@ /* #define RFILE ".rand" - defined in ../../e_os.h */ -int RAND_load_file(file,bytes) -char *file; -long bytes; +int RAND_load_file(const char *file, long bytes) { MS_STATIC unsigned char buf[BUFSIZE]; struct stat sb; @@ -81,12 +85,12 @@ long bytes; i=stat(file,&sb); /* If the state fails, put some crap in anyway */ - RAND_seed((unsigned char *)&sb,sizeof(sb)); + RAND_seed(&sb,sizeof(sb)); ret+=sizeof(sb); if (i < 0) return(0); if (bytes <= 0) return(ret); - in=fopen(file,"r"); + in=fopen(file,"rb"); if (in == NULL) goto err; for (;;) { @@ -105,15 +109,24 @@ err: return(ret); } -int RAND_write_file(file) -char *file; +int RAND_write_file(const char *file) { unsigned char buf[BUFSIZE]; int i,ret=0; FILE *out; int n; - out=fopen(file,"w"); + /* Under VMS, fopen(file, "wb") will craete a new version of the + same file. This is not good, so let's try updating an existing + one, and create file only if it doesn't already exist. This + should be completely harmless on system that have no file + versions. -- Richard Levitte */ + out=fopen(file,"rb+"); + if (out == NULL && errno == ENOENT) + { + errno = 0; + out=fopen(file,"wb"); + } if (out == NULL) goto err; chmod(file,0600); n=RAND_DATA; @@ -137,9 +150,7 @@ err: return(ret); } -char *RAND_file_name(buf,size) -char *buf; -int size; +char *RAND_file_name(char *buf, int size) { char *s; char *ret=NULL; @@ -158,7 +169,9 @@ int size; if (((int)(strlen(s)+strlen(RFILE)+2)) > size) return(RFILE); strcpy(buf,s); +#ifndef VMS strcat(buf,"/"); +#endif strcat(buf,RFILE); ret=buf; } diff --git a/src/lib/libcrypto/rand/randtest.c b/src/lib/libcrypto/rand/randtest.c index e0ba61e123..f0706d779a 100644 --- a/src/lib/libcrypto/rand/randtest.c +++ b/src/lib/libcrypto/rand/randtest.c @@ -58,7 +58,7 @@ #include #include -#include "rand.h" +#include /* some FIPS 140-1 random number test */ /* some simple tests */ @@ -117,7 +117,7 @@ int main() /* test 1 */ if (!((9654 < n1) && (n1 < 10346))) { - printf("test 1 failed, X=%ld\n",n1); + printf("test 1 failed, X=%lu\n",n1); err++; } printf("test 1 done\n"); @@ -150,37 +150,37 @@ int main() { if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) { - printf("test 3 failed, bit=%d run=%d num=%ld\n", + printf("test 3 failed, bit=%d run=%d num=%lu\n", i,1,runs[i][0]); err++; } if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) { - printf("test 3 failed, bit=%d run=%d num=%ld\n", + printf("test 3 failed, bit=%d run=%d num=%lu\n", i,2,runs[i][1]); err++; } if (!(( 502 < runs[i][2]) && (runs[i][2] < 748))) { - printf("test 3 failed, bit=%d run=%d num=%ld\n", + printf("test 3 failed, bit=%d run=%d num=%lu\n", i,3,runs[i][2]); err++; } if (!(( 223 < runs[i][3]) && (runs[i][3] < 402))) { - printf("test 3 failed, bit=%d run=%d num=%ld\n", + printf("test 3 failed, bit=%d run=%d num=%lu\n", i,4,runs[i][3]); err++; } if (!(( 90 < runs[i][4]) && (runs[i][4] < 223))) { - printf("test 3 failed, bit=%d run=%d num=%ld\n", + printf("test 3 failed, bit=%d run=%d num=%lu\n", i,5,runs[i][4]); err++; } if (!(( 90 < runs[i][5]) && (runs[i][5] < 223))) { - printf("test 3 failed, bit=%d run=%d num=%ld\n", + printf("test 3 failed, bit=%d run=%d num=%lu\n", i,6,runs[i][5]); err++; } @@ -190,13 +190,13 @@ int main() /* test 4 */ if (runs[0][33] != 0) { - printf("test 4 failed, bit=%d run=%d num=%ld\n", + printf("test 4 failed, bit=%d run=%d num=%lu\n", 0,34,runs[0][33]); err++; } if (runs[1][33] != 0) { - printf("test 4 failed, bit=%d run=%d num=%ld\n", + printf("test 4 failed, bit=%d run=%d num=%lu\n", 1,34,runs[1][33]); err++; } diff --git a/src/lib/libcrypto/ranlib.sh b/src/lib/libcrypto/ranlib.sh deleted file mode 100644 index 543f712c6b..0000000000 --- a/src/lib/libcrypto/ranlib.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -cwd=`pwd` -cd /tmp - -if [ -s /bin/ranlib ] ; then - RL=/bin/ranlib -else if [ -s /usr/bin/ranlib ] ; then - RL=/usr/bin/ranlib -fi -fi - -if [ "x$RL" != "x" ] -then - case "$1" in - /*) - $RL "$1" - ;; - *) - $RL "$cwd/$1" - ;; - esac -fi diff --git a/src/lib/libcrypto/rc2/Makefile.ssl b/src/lib/libcrypto/rc2/Makefile.ssl index c5138f13e2..542397d69a 100644 --- a/src/lib/libcrypto/rc2/Makefile.ssl +++ b/src/lib/libcrypto/rc2/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,24 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +rc2_cbc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h +rc2_cbc.o: rc2_locl.h +rc2_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +rc2_ecb.o: ../../include/openssl/rc2.h rc2_locl.h +rc2_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h +rc2_skey.o: rc2_locl.h +rc2cfb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h +rc2cfb64.o: rc2_locl.h +rc2ofb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h +rc2ofb64.o: rc2_locl.h diff --git a/src/lib/libcrypto/rc2/Makefile.uni b/src/lib/libcrypto/rc2/Makefile.uni index e50b3f2d19..4dc20c6fcf 100644 --- a/src/lib/libcrypto/rc2/Makefile.uni +++ b/src/lib/libcrypto/rc2/Makefile.uni @@ -15,6 +15,7 @@ MAKE= make MAKEDEPEND= makedepend MAKEFILE= Makefile.uni AR= ar r +RANLIB= ranlib IDEA_ENC=rc2_cbc.o @@ -39,7 +40,7 @@ all: $(LIB) $(TEST) $(APPS) $(LIB): $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/ranlib.sh $(LIB) + $(RANLIB) $(LIB) test: $(TEST) ./$(TEST) diff --git a/src/lib/libcrypto/rc2/rc2.h b/src/lib/libcrypto/rc2/rc2.h new file mode 100644 index 0000000000..9571efb755 --- /dev/null +++ b/src/lib/libcrypto/rc2/rc2.h @@ -0,0 +1,99 @@ +/* crypto/rc2/rc2.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_RC2_H +#define HEADER_RC2_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef NO_RC2 +#error RC2 is disabled. +#endif + +#define RC2_ENCRYPT 1 +#define RC2_DECRYPT 0 + +#include /* RC2_INT */ +#define RC2_BLOCK 8 +#define RC2_KEY_LENGTH 16 + +typedef struct rc2_key_st + { + RC2_INT data[64]; + } RC2_KEY; + + +void RC2_set_key(RC2_KEY *key, int len, unsigned char *data,int bits); +void RC2_ecb_encrypt(unsigned char *in,unsigned char *out,RC2_KEY *key, + int enc); +void RC2_encrypt(unsigned long *data,RC2_KEY *key); +void RC2_decrypt(unsigned long *data,RC2_KEY *key); +void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length, + RC2_KEY *ks, unsigned char *iv, int enc); +void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, + RC2_KEY *schedule, unsigned char *ivec, int *num, int enc); +void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, + RC2_KEY *schedule, unsigned char *ivec, int *num); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/libcrypto/rc2/rc2.org b/src/lib/libcrypto/rc2/rc2.org deleted file mode 100644 index 37354cfa62..0000000000 --- a/src/lib/libcrypto/rc2/rc2.org +++ /dev/null @@ -1,118 +0,0 @@ -/* crypto/rc2/rc2.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify rc2.org since rc2.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - -#ifndef HEADER_RC2_H -#define HEADER_RC2_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define RC2_ENCRYPT 1 -#define RC2_DECRYPT 0 - -/* I need to put in a mod for the alpha - eay */ -#define RC2_INT unsigned short - -#define RC2_BLOCK 8 -#define RC2_KEY_LENGTH 16 - -typedef struct rc2_key_st - { - RC2_INT data[64]; - } RC2_KEY; - -#ifndef NOPROTO - -void RC2_set_key(RC2_KEY *key, int len, unsigned char *data,int bits); -void RC2_ecb_encrypt(unsigned char *in,unsigned char *out,RC2_KEY *key, - int enc); -void RC2_encrypt(unsigned long *data,RC2_KEY *key); -void RC2_decrypt(unsigned long *data,RC2_KEY *key); -void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length, - RC2_KEY *ks, unsigned char *iv, int enc); -void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, - RC2_KEY *schedule, unsigned char *ivec, int *num, int enc); -void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, - RC2_KEY *schedule, unsigned char *ivec, int *num); - -#else - -void RC2_set_key(); -void RC2_ecb_encrypt(); -void RC2_encrypt(); -void RC2_decrypt(); -void RC2_cbc_encrypt(); -void RC2_cfb64_encrypt(); -void RC2_ofb64_encrypt(); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/lib/libcrypto/rc2/rc2_cbc.c b/src/lib/libcrypto/rc2/rc2_cbc.c index 22e89f0441..1202184e85 100644 --- a/src/lib/libcrypto/rc2/rc2_cbc.c +++ b/src/lib/libcrypto/rc2/rc2_cbc.c @@ -56,16 +56,11 @@ * [including the GNU Public Licence.] */ -#include "rc2.h" +#include #include "rc2_locl.h" -void RC2_cbc_encrypt(in, out, length, ks, iv, encrypt) -unsigned char *in; -unsigned char *out; -long length; -RC2_KEY *ks; -unsigned char *iv; -int encrypt; +void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length, + RC2_KEY *ks, unsigned char *iv, int encrypt) { register unsigned long tin0,tin1; register unsigned long tout0,tout1,xor0,xor1; @@ -138,9 +133,7 @@ int encrypt; tin[0]=tin[1]=0; } -void RC2_encrypt(d,key) -unsigned long *d; -RC2_KEY *key; +void RC2_encrypt(unsigned long *d, RC2_KEY *key) { int i,n; register RC2_INT *p0,*p1; @@ -185,9 +178,7 @@ RC2_KEY *key; d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); } -void RC2_decrypt(d,key) -unsigned long *d; -RC2_KEY *key; +void RC2_decrypt(unsigned long *d, RC2_KEY *key) { int i,n; register RC2_INT *p0,*p1; diff --git a/src/lib/libcrypto/rc2/rc2_ecb.c b/src/lib/libcrypto/rc2/rc2_ecb.c index 96239cd4e0..7d77b9186c 100644 --- a/src/lib/libcrypto/rc2/rc2_ecb.c +++ b/src/lib/libcrypto/rc2/rc2_ecb.c @@ -56,10 +56,11 @@ * [including the GNU Public Licence.] */ -#include "rc2.h" +#include #include "rc2_locl.h" +#include -char *RC2_version="RC2 part of SSLeay 0.9.0b 29-Jun-1998"; +const char *RC2_version="RC2" OPENSSL_VERSION_PTEXT; /* RC2 as implemented frm a posting from * Newsgroups: sci.crypt @@ -69,11 +70,8 @@ char *RC2_version="RC2 part of SSLeay 0.9.0b 29-Jun-1998"; * Date: 11 Feb 1996 06:45:03 GMT */ -void RC2_ecb_encrypt(in, out, ks, encrypt) -unsigned char *in; -unsigned char *out; -RC2_KEY *ks; -int encrypt; +void RC2_ecb_encrypt(unsigned char *in, unsigned char *out, RC2_KEY *ks, + int encrypt) { unsigned long l,d[2]; diff --git a/src/lib/libcrypto/rc2/rc2_skey.c b/src/lib/libcrypto/rc2/rc2_skey.c index 0f1f253395..7143c4e591 100644 --- a/src/lib/libcrypto/rc2/rc2_skey.c +++ b/src/lib/libcrypto/rc2/rc2_skey.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "rc2.h" +#include #include "rc2_locl.h" static unsigned char key_table[256]={ @@ -90,11 +90,7 @@ static unsigned char key_table[256]={ * BSAFE uses the 'retarded' version. What I previously shipped is * the same as specifying 1024 for the 'bits' parameter. Bsafe uses * a version where the bits parameter is the same as len*8 */ -void RC2_set_key(key,len,data,bits) -RC2_KEY *key; -int len; -unsigned char *data; -int bits; +void RC2_set_key(RC2_KEY *key, int len, unsigned char *data, int bits) { int i,j; unsigned char *k; diff --git a/src/lib/libcrypto/rc2/rc2cfb64.c b/src/lib/libcrypto/rc2/rc2cfb64.c index d409fb77e9..5e3fa07d90 100644 --- a/src/lib/libcrypto/rc2/rc2cfb64.c +++ b/src/lib/libcrypto/rc2/rc2cfb64.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "rc2.h" +#include #include "rc2_locl.h" /* The input and output encrypted as though 64bit cfb mode is being @@ -64,14 +64,8 @@ * 64bit block we have used is contained in *num; */ -void RC2_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) -unsigned char *in; -unsigned char *out; -long length; -RC2_KEY *schedule; -unsigned char *ivec; -int *num; -int encrypt; +void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, + RC2_KEY *schedule, unsigned char *ivec, int *num, int encrypt) { register unsigned long v0,v1,t; register int n= *num; diff --git a/src/lib/libcrypto/rc2/rc2ofb64.c b/src/lib/libcrypto/rc2/rc2ofb64.c index 4f09167447..42cdd40cdd 100644 --- a/src/lib/libcrypto/rc2/rc2ofb64.c +++ b/src/lib/libcrypto/rc2/rc2ofb64.c @@ -56,20 +56,15 @@ * [including the GNU Public Licence.] */ -#include "rc2.h" +#include #include "rc2_locl.h" /* The input and output encrypted as though 64bit ofb mode is being * used. The extra state information to record how much of the * 64bit block we have used is contained in *num; */ -void RC2_ofb64_encrypt(in, out, length, schedule, ivec, num) -unsigned char *in; -unsigned char *out; -long length; -RC2_KEY *schedule; -unsigned char *ivec; -int *num; +void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, + RC2_KEY *schedule, unsigned char *ivec, int *num) { register unsigned long v0,v1,t; register int n= *num; diff --git a/src/lib/libcrypto/rc2/rc2speed.c b/src/lib/libcrypto/rc2/rc2speed.c index 6cd8ea8f27..c3da63e77e 100644 --- a/src/lib/libcrypto/rc2/rc2speed.c +++ b/src/lib/libcrypto/rc2/rc2speed.c @@ -59,19 +59,17 @@ /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include -#ifndef MSDOS -#include -#else -#include -extern int exit(); -#endif + +#include +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include -#ifndef VMS #ifndef _IRIX #include #endif @@ -79,48 +77,40 @@ extern int exit(); #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "rc2.h" +#include /* The following if from times(3) man page. It may need to be changed */ #ifndef HZ #ifndef CLK_TCK -#ifndef VMS -#define HZ 100.0 -#else /* VMS */ #define HZ 100.0 #endif #else /* CLK_TCK */ #define HZ ((double)CLK_TCK) #endif -#endif #define BUFSIZE ((long)1024) long run=0; -#ifndef NOPROTO double Time_F(int s); -#else -double Time_F(); -#endif - #ifdef SIGALRM #if defined(__STDC__) || defined(sgi) || defined(_AIX) #define SIGRETTYPE void @@ -128,14 +118,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -148,8 +132,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -185,9 +168,7 @@ int s; #endif } -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; diff --git a/src/lib/libcrypto/rc2/rc2test.c b/src/lib/libcrypto/rc2/rc2test.c index 9d0f8016ec..6a5defa6ea 100644 --- a/src/lib/libcrypto/rc2/rc2test.c +++ b/src/lib/libcrypto/rc2/rc2test.c @@ -62,7 +62,15 @@ #include #include #include -#include "rc2.h" + +#ifdef NO_RC2 +int main(int argc, char *argv[]) +{ + printf("No RC2 support\n"); + return(0); +} +#else +#include unsigned char RC2key[4][16]={ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -125,19 +133,11 @@ static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ }; -#ifndef NOPROTO /*static int cfb64_test(unsigned char *cfb_cipher);*/ static char *pt(unsigned char *p); -#else -/*static int cfb64_test(); */ -static char *pt(); #endif -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,n,err=0; RC2_KEY key; @@ -208,8 +208,7 @@ char *argv[]; } #ifdef undef -static int cfb64_test(cfb_cipher) -unsigned char *cfb_cipher; +static int cfb64_test(unsigned char *cfb_cipher) { IDEA_KEY_SCHEDULE eks,dks; int err=0,i,n; @@ -247,8 +246,7 @@ unsigned char *cfb_cipher; return(err); } -static char *pt(p) -unsigned char *p; +static char *pt(unsigned char *p) { static char bufs[10][20]; static int bnum=0; @@ -268,3 +266,4 @@ unsigned char *p; } #endif +#endif diff --git a/src/lib/libcrypto/rc2/tab.c b/src/lib/libcrypto/rc2/tab.c new file mode 100644 index 0000000000..25dc14eeba --- /dev/null +++ b/src/lib/libcrypto/rc2/tab.c @@ -0,0 +1,86 @@ +#include + +unsigned char ebits_to_num[256]={ + 0xbd,0x56,0xea,0xf2,0xa2,0xf1,0xac,0x2a, + 0xb0,0x93,0xd1,0x9c,0x1b,0x33,0xfd,0xd0, + 0x30,0x04,0xb6,0xdc,0x7d,0xdf,0x32,0x4b, + 0xf7,0xcb,0x45,0x9b,0x31,0xbb,0x21,0x5a, + 0x41,0x9f,0xe1,0xd9,0x4a,0x4d,0x9e,0xda, + 0xa0,0x68,0x2c,0xc3,0x27,0x5f,0x80,0x36, + 0x3e,0xee,0xfb,0x95,0x1a,0xfe,0xce,0xa8, + 0x34,0xa9,0x13,0xf0,0xa6,0x3f,0xd8,0x0c, + 0x78,0x24,0xaf,0x23,0x52,0xc1,0x67,0x17, + 0xf5,0x66,0x90,0xe7,0xe8,0x07,0xb8,0x60, + 0x48,0xe6,0x1e,0x53,0xf3,0x92,0xa4,0x72, + 0x8c,0x08,0x15,0x6e,0x86,0x00,0x84,0xfa, + 0xf4,0x7f,0x8a,0x42,0x19,0xf6,0xdb,0xcd, + 0x14,0x8d,0x50,0x12,0xba,0x3c,0x06,0x4e, + 0xec,0xb3,0x35,0x11,0xa1,0x88,0x8e,0x2b, + 0x94,0x99,0xb7,0x71,0x74,0xd3,0xe4,0xbf, + 0x3a,0xde,0x96,0x0e,0xbc,0x0a,0xed,0x77, + 0xfc,0x37,0x6b,0x03,0x79,0x89,0x62,0xc6, + 0xd7,0xc0,0xd2,0x7c,0x6a,0x8b,0x22,0xa3, + 0x5b,0x05,0x5d,0x02,0x75,0xd5,0x61,0xe3, + 0x18,0x8f,0x55,0x51,0xad,0x1f,0x0b,0x5e, + 0x85,0xe5,0xc2,0x57,0x63,0xca,0x3d,0x6c, + 0xb4,0xc5,0xcc,0x70,0xb2,0x91,0x59,0x0d, + 0x47,0x20,0xc8,0x4f,0x58,0xe0,0x01,0xe2, + 0x16,0x38,0xc4,0x6f,0x3b,0x0f,0x65,0x46, + 0xbe,0x7e,0x2d,0x7b,0x82,0xf9,0x40,0xb5, + 0x1d,0x73,0xf8,0xeb,0x26,0xc7,0x87,0x97, + 0x25,0x54,0xb1,0x28,0xaa,0x98,0x9d,0xa5, + 0x64,0x6d,0x7a,0xd4,0x10,0x81,0x44,0xef, + 0x49,0xd6,0xae,0x2e,0xdd,0x76,0x5c,0x2f, + 0xa7,0x1c,0xc9,0x09,0x69,0x9a,0x83,0xcf, + 0x29,0x39,0xb9,0xe9,0x4c,0xff,0x43,0xab, + }; + +unsigned char num_to_ebits[256]={ + 0x5d,0xbe,0x9b,0x8b,0x11,0x99,0x6e,0x4d, + 0x59,0xf3,0x85,0xa6,0x3f,0xb7,0x83,0xc5, + 0xe4,0x73,0x6b,0x3a,0x68,0x5a,0xc0,0x47, + 0xa0,0x64,0x34,0x0c,0xf1,0xd0,0x52,0xa5, + 0xb9,0x1e,0x96,0x43,0x41,0xd8,0xd4,0x2c, + 0xdb,0xf8,0x07,0x77,0x2a,0xca,0xeb,0xef, + 0x10,0x1c,0x16,0x0d,0x38,0x72,0x2f,0x89, + 0xc1,0xf9,0x80,0xc4,0x6d,0xae,0x30,0x3d, + 0xce,0x20,0x63,0xfe,0xe6,0x1a,0xc7,0xb8, + 0x50,0xe8,0x24,0x17,0xfc,0x25,0x6f,0xbb, + 0x6a,0xa3,0x44,0x53,0xd9,0xa2,0x01,0xab, + 0xbc,0xb6,0x1f,0x98,0xee,0x9a,0xa7,0x2d, + 0x4f,0x9e,0x8e,0xac,0xe0,0xc6,0x49,0x46, + 0x29,0xf4,0x94,0x8a,0xaf,0xe1,0x5b,0xc3, + 0xb3,0x7b,0x57,0xd1,0x7c,0x9c,0xed,0x87, + 0x40,0x8c,0xe2,0xcb,0x93,0x14,0xc9,0x61, + 0x2e,0xe5,0xcc,0xf6,0x5e,0xa8,0x5c,0xd6, + 0x75,0x8d,0x62,0x95,0x58,0x69,0x76,0xa1, + 0x4a,0xb5,0x55,0x09,0x78,0x33,0x82,0xd7, + 0xdd,0x79,0xf5,0x1b,0x0b,0xde,0x26,0x21, + 0x28,0x74,0x04,0x97,0x56,0xdf,0x3c,0xf0, + 0x37,0x39,0xdc,0xff,0x06,0xa4,0xea,0x42, + 0x08,0xda,0xb4,0x71,0xb0,0xcf,0x12,0x7a, + 0x4e,0xfa,0x6c,0x1d,0x84,0x00,0xc8,0x7f, + 0x91,0x45,0xaa,0x2b,0xc2,0xb1,0x8f,0xd5, + 0xba,0xf2,0xad,0x19,0xb2,0x67,0x36,0xf7, + 0x0f,0x0a,0x92,0x7d,0xe3,0x9d,0xe9,0x90, + 0x3e,0x23,0x27,0x66,0x13,0xec,0x81,0x15, + 0xbd,0x22,0xbf,0x9f,0x7e,0xa9,0x51,0x4b, + 0x4c,0xfb,0x02,0xd3,0x70,0x86,0x31,0xe7, + 0x3b,0x05,0x03,0x54,0x60,0x48,0x65,0x18, + 0xd2,0xcd,0x5f,0x32,0x88,0x0e,0x35,0xfd, + }; + +main() + { + int i,j; + + for (i=0; i<256; i++) + { + for (j=0; j<256; j++) + if (ebits_to_num[j] == i) + { + printf("0x%02x,",j); + break; + } + } + } diff --git a/src/lib/libcrypto/rc4/Makefile.ssl b/src/lib/libcrypto/rc4/Makefile.ssl index 19c1e980f3..64092fd4f1 100644 --- a/src/lib/libcrypto/rc4/Makefile.ssl +++ b/src/lib/libcrypto/rc4/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -44,7 +46,7 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf @@ -63,26 +65,25 @@ asm/rx86-out.o: asm/rx86unix.cpp # bsdi asm/rx86bsdi.o: asm/rx86unix.cpp - $(CPP) -DBSDI asm/rx86unix.cpp | as -o asm/rx86bsdi.o + $(CPP) -DBSDI asm/rx86unix.cpp | sed 's/ :/:/' | as -o asm/rx86bsdi.o -asm/rx86unix.cpp: - (cd asm; perl rc4-586.pl cpp >rx86unix.cpp) +asm/rx86unix.cpp: asm/rc4-586.pl + (cd asm; $(PERL) rc4-586.pl cpp >rx86unix.cpp) files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -94,15 +95,19 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o - -errors: + rm -f asm/rx86unix.cpp *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o # DO NOT DELETE THIS LINE -- make depend depends on it. + +rc4_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc4.h +rc4_enc.o: rc4_locl.h +rc4_skey.o: ../../include/openssl/opensslconf.h +rc4_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/rc4.h +rc4_skey.o: rc4_locl.h diff --git a/src/lib/libcrypto/rc4/Makefile.uni b/src/lib/libcrypto/rc4/Makefile.uni index 79dc17b8d1..855d9e50f3 100644 --- a/src/lib/libcrypto/rc4/Makefile.uni +++ b/src/lib/libcrypto/rc4/Makefile.uni @@ -19,6 +19,7 @@ MAKE= make MAKEDEPEND= makedepend MAKEFILE= Makefile.uni AR= ar r +RANLIB= ranlib RC4_ENC=rc4_enc.o # or use @@ -48,7 +49,7 @@ all: $(LIB) $(TEST) $(APPS) $(LIB): $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/ranlib.sh $(LIB) + $(RANLIB) $(LIB) # elf asm/rx86-elf.o: asm/rx86unix.cpp diff --git a/src/lib/libcrypto/rc4/asm/rc4-586.pl b/src/lib/libcrypto/rc4/asm/rc4-586.pl index 0dd8eb1ba9..7ef889e5a1 100644 --- a/src/lib/libcrypto/rc4/asm/rc4-586.pl +++ b/src/lib/libcrypto/rc4/asm/rc4-586.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # define for pentium pro friendly version diff --git a/src/lib/libcrypto/rc4/asm/rx86unix.cpp b/src/lib/libcrypto/rc4/asm/rx86unix.cpp deleted file mode 100644 index ec1d72a110..0000000000 --- a/src/lib/libcrypto/rc4/asm/rx86unix.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define RC4 _RC4 - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by rc4-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "rc4-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl RC4 - TYPE(RC4,@function) -RC4: - - pushl %ebp - pushl %ebx - movl 12(%esp), %ebp - movl 16(%esp), %ebx - pushl %esi - pushl %edi - movl (%ebp), %ecx - movl 4(%ebp), %edx - movl 28(%esp), %esi - incl %ecx - subl $12, %esp - addl $8, %ebp - andl $255, %ecx - leal -8(%ebx,%esi,), %ebx - movl 44(%esp), %edi - movl %ebx, 8(%esp) - movl (%ebp,%ecx,4), %eax - cmpl %esi, %ebx - jl .L000end -.L001start: - addl $8, %esi - /* Round 0 */ - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb %bl, (%esp) - /* Round 1 */ - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb %bl, 1(%esp) - /* Round 2 */ - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb %bl, 2(%esp) - /* Round 3 */ - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb %bl, 3(%esp) - /* Round 4 */ - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb %bl, 4(%esp) - /* Round 5 */ - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb %bl, 5(%esp) - /* Round 6 */ - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb %bl, 6(%esp) - /* Round 7 */ - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - addl $8, %edi - movb %bl, 7(%esp) - /* apply the cipher text */ - movl (%esp), %eax - movl -8(%esi), %ebx - xorl %ebx, %eax - movl -4(%esi), %ebx - movl %eax, -8(%edi) - movl 4(%esp), %eax - xorl %ebx, %eax - movl 8(%esp), %ebx - movl %eax, -4(%edi) - movl (%ebp,%ecx,4), %eax - cmpl %ebx, %esi - jle .L001start -.L000end: - /* Round 0 */ - addl $8, %ebx - incl %esi - cmpl %esi, %ebx - jl .L002finished - movl %ebx, 8(%esp) - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb -1(%esi), %bh - xorb %bh, %bl - movb %bl, (%edi) - /* Round 1 */ - movl 8(%esp), %ebx - cmpl %esi, %ebx - jle .L002finished - incl %esi - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb -1(%esi), %bh - xorb %bh, %bl - movb %bl, 1(%edi) - /* Round 2 */ - movl 8(%esp), %ebx - cmpl %esi, %ebx - jle .L002finished - incl %esi - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb -1(%esi), %bh - xorb %bh, %bl - movb %bl, 2(%edi) - /* Round 3 */ - movl 8(%esp), %ebx - cmpl %esi, %ebx - jle .L002finished - incl %esi - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb -1(%esi), %bh - xorb %bh, %bl - movb %bl, 3(%edi) - /* Round 4 */ - movl 8(%esp), %ebx - cmpl %esi, %ebx - jle .L002finished - incl %esi - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb -1(%esi), %bh - xorb %bh, %bl - movb %bl, 4(%edi) - /* Round 5 */ - movl 8(%esp), %ebx - cmpl %esi, %ebx - jle .L002finished - incl %esi - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movl (%ebp,%ecx,4), %eax - movb -1(%esi), %bh - xorb %bh, %bl - movb %bl, 5(%edi) - /* Round 6 */ - movl 8(%esp), %ebx - cmpl %esi, %ebx - jle .L002finished - incl %esi - addl %eax, %edx - andl $255, %edx - incl %ecx - movl (%ebp,%edx,4), %ebx - movl %ebx, -4(%ebp,%ecx,4) - addl %eax, %ebx - andl $255, %ecx - andl $255, %ebx - movl %eax, (%ebp,%edx,4) - nop - movl (%ebp,%ebx,4), %ebx - movb -1(%esi), %bh - xorb %bh, %bl - movb %bl, 6(%edi) -.L002finished: - decl %ecx - addl $12, %esp - movl %edx, -4(%ebp) - movb %cl, -8(%ebp) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.RC4_end: - SIZE(RC4,.RC4_end-RC4) -.ident "RC4" diff --git a/src/lib/libcrypto/rc4/rc4.c b/src/lib/libcrypto/rc4/rc4.c index 127e8a5093..709b7aff35 100644 --- a/src/lib/libcrypto/rc4/rc4.c +++ b/src/lib/libcrypto/rc4/rc4.c @@ -59,7 +59,7 @@ #include #include #include -#include "rc4.h" +#include char *usage[]={ "usage: rc4 args\n", @@ -70,9 +70,7 @@ char *usage[]={ NULL }; -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { FILE *in=NULL,*out=NULL; char *infile=NULL,*outfile=NULL,*keystr=NULL; diff --git a/src/lib/libcrypto/rc4/rc4.h b/src/lib/libcrypto/rc4/rc4.h new file mode 100644 index 0000000000..7418c2a9a2 --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4.h @@ -0,0 +1,88 @@ +/* crypto/rc4/rc4.h */ +/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +#ifndef HEADER_RC4_H +#define HEADER_RC4_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef NO_RC4 +#error RC4 is disabled. +#endif + +#include /* RC4_INT */ + +typedef struct rc4_key_st + { + RC4_INT x,y; + RC4_INT data[256]; + } RC4_KEY; + + +const char *RC4_options(void); +void RC4_set_key(RC4_KEY *key, int len, unsigned char *data); +void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata, + unsigned char *outdata); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lib/libcrypto/rc4/rc4.org b/src/lib/libcrypto/rc4/rc4.org deleted file mode 100644 index c558651af8..0000000000 --- a/src/lib/libcrypto/rc4/rc4.org +++ /dev/null @@ -1,103 +0,0 @@ -/* crypto/rc4/rc4.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify rc4.org since rc4.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - -#ifndef HEADER_RC4_H -#define HEADER_RC4_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* using int types make the structure larger but make the code faster - * on most boxes I have tested - up to %20 faster. */ -#define RC4_INT unsigned int - -typedef struct rc4_key_st - { - RC4_INT x,y; - RC4_INT data[256]; - } RC4_KEY; - -#ifndef NOPROTO - -char *RC4_options(void); -void RC4_set_key(RC4_KEY *key, int len, unsigned char *data); -void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata, - unsigned char *outdata); - -#else - -char *RC4_options(); -void RC4_set_key(); -void RC4(); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/lib/libcrypto/rc4/rc4_enc.c b/src/lib/libcrypto/rc4/rc4_enc.c index ab8a111b52..3256bea8cc 100644 --- a/src/lib/libcrypto/rc4/rc4_enc.c +++ b/src/lib/libcrypto/rc4/rc4_enc.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "rc4.h" +#include #include "rc4_locl.h" /* RC4 as implemented from a posting from @@ -67,11 +67,8 @@ * Date: Wed, 14 Sep 1994 06:35:31 GMT */ -void RC4(key, len, indata, outdata) -RC4_KEY *key; -unsigned long len; -unsigned char *indata; -unsigned char *outdata; +void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata, + unsigned char *outdata) { register RC4_INT *d; register RC4_INT x,y,tx,ty; @@ -95,7 +92,6 @@ unsigned char *outdata; #define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) #endif - i= -(int)len; i=(int)(len>>3L); if (i) { diff --git a/src/lib/libcrypto/rc4/rc4_locl.h b/src/lib/libcrypto/rc4/rc4_locl.h new file mode 100644 index 0000000000..3bb80b6ce9 --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4_locl.h @@ -0,0 +1,4 @@ +#ifndef HEADER_RC4_LOCL_H +#define HEADER_RC4_LOCL_H +#include +#endif diff --git a/src/lib/libcrypto/rc4/rc4_locl.org b/src/lib/libcrypto/rc4/rc4_locl.org deleted file mode 100644 index 1ef4455fb7..0000000000 --- a/src/lib/libcrypto/rc4/rc4_locl.org +++ /dev/null @@ -1,70 +0,0 @@ -/* crypto/rc4/rc4_locl.org */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - * - * Always modify bf_locl.org since bf_locl.h is automatically generated from - * it during SSLeay configuration. - * - * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING - */ - -/* if this is defined data[i] is used instead of *data, this is a %20 - * speedup on x86 */ -#undef RC4_INDEX - diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c index 0be5fde67b..c67a445f1f 100644 --- a/src/lib/libcrypto/rc4/rc4_skey.c +++ b/src/lib/libcrypto/rc4/rc4_skey.c @@ -56,12 +56,13 @@ * [including the GNU Public Licence.] */ -#include "rc4.h" +#include #include "rc4_locl.h" +#include -char *RC4_version="RC4 part of SSLeay 0.9.0b 29-Jun-1998"; +const char *RC4_version="RC4" OPENSSL_VERSION_PTEXT; -char *RC4_options() +const char *RC4_options(void) { #ifdef RC4_INDEX if (sizeof(RC4_INT) == 1) @@ -84,10 +85,7 @@ char *RC4_options() * Date: Wed, 14 Sep 1994 06:35:31 GMT */ -void RC4_set_key(key, len, data) -RC4_KEY *key; -int len; -register unsigned char *data; +void RC4_set_key(RC4_KEY *key, int len, register unsigned char *data) { register RC4_INT tmp; register int id1,id2; diff --git a/src/lib/libcrypto/rc4/rc4s.cpp b/src/lib/libcrypto/rc4/rc4s.cpp index 39f1727dd3..3814fde997 100644 --- a/src/lib/libcrypto/rc4/rc4s.cpp +++ b/src/lib/libcrypto/rc4/rc4s.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include #include -#include "rc4.h" +#include void main(int argc,char *argv[]) { diff --git a/src/lib/libcrypto/rc4/rc4speed.c b/src/lib/libcrypto/rc4/rc4speed.c index 5298dad6d0..4fb5ebf573 100644 --- a/src/lib/libcrypto/rc4/rc4speed.c +++ b/src/lib/libcrypto/rc4/rc4speed.c @@ -59,19 +59,17 @@ /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include -#ifndef MSDOS -#include -#else -#include -extern int exit(); -#endif + +#include +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include -#ifndef VMS #ifndef _IRIX #include #endif @@ -79,34 +77,31 @@ extern int exit(); #include #include #endif -#else /* VMS */ -#include -struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif -#include "rc4.h" +#include /* The following if from times(3) man page. It may need to be changed */ #ifndef HZ #ifndef CLK_TCK -#ifndef VMS -#define HZ 100.0 -#else /* VMS */ #define HZ 100.0 -#endif #else /* CLK_TCK */ #define HZ ((double)CLK_TCK) #endif @@ -115,12 +110,7 @@ struct tms { #define BUFSIZE ((long)1024) long run=0; -#ifndef NOPROTO double Time_F(int s); -#else -double Time_F(); -#endif - #ifdef SIGALRM #if defined(__STDC__) || defined(sgi) || defined(_AIX) #define SIGRETTYPE void @@ -128,14 +118,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -148,8 +132,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -185,9 +168,7 @@ int s; #endif } -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; diff --git a/src/lib/libcrypto/rc4/rc4test.c b/src/lib/libcrypto/rc4/rc4test.c index 041e1aff95..5abf8cff30 100644 --- a/src/lib/libcrypto/rc4/rc4test.c +++ b/src/lib/libcrypto/rc4/rc4test.c @@ -59,7 +59,15 @@ #include #include #include -#include "rc4.h" + +#ifdef NO_RC4 +int main(int argc, char *argv[]) +{ + printf("No RC4 support\n"); + return(0); +} +#else +#include unsigned char keys[7][30]={ {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, @@ -101,9 +109,7 @@ unsigned char output[7][30]={ {0}, }; -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,err=0; int j; @@ -192,4 +198,4 @@ char *argv[]; exit(err); return(0); } - +#endif diff --git a/src/lib/libcrypto/rc5/Makefile.ssl b/src/lib/libcrypto/rc5/Makefile.ssl index 5e98ee2348..666c4b6539 100644 --- a/src/lib/libcrypto/rc5/Makefile.ssl +++ b/src/lib/libcrypto/rc5/Makefile.ssl @@ -8,9 +8,11 @@ CC= cc CPP= $(CC) -E INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -42,7 +44,7 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf @@ -61,27 +63,25 @@ asm/r586-out.o: asm/r586unix.cpp # bsdi asm/r586bsdi.o: asm/r586unix.cpp - $(CPP) -DBSDI asm/r586unix.cpp | as -o asm/r586bsdi.o + $(CPP) -DBSDI asm/r586unix.cpp | sed 's/ :/:/' | as -o asm/r586bsdi.o asm/r586unix.cpp: - (cd asm; perl rc5-586.pl cpp >r586unix.cpp) + (cd asm; $(PERL) rc5-586.pl cpp >r586unix.cpp) files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/point.sh ../../doc/rc5.doc rc5.doc ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -93,15 +93,20 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f asm/r586unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +rc5_ecb.o: ../../include/openssl/opensslv.h ../../include/openssl/rc5.h +rc5_ecb.o: rc5_locl.h +rc5_enc.o: ../../include/openssl/rc5.h rc5_locl.h +rc5_skey.o: ../../include/openssl/rc5.h rc5_locl.h +rc5cfb64.o: ../../include/openssl/rc5.h rc5_locl.h +rc5ofb64.o: ../../include/openssl/rc5.h rc5_locl.h diff --git a/src/lib/libcrypto/rc5/Makefile.uni b/src/lib/libcrypto/rc5/Makefile.uni index e50b3f2d19..4dc20c6fcf 100644 --- a/src/lib/libcrypto/rc5/Makefile.uni +++ b/src/lib/libcrypto/rc5/Makefile.uni @@ -15,6 +15,7 @@ MAKE= make MAKEDEPEND= makedepend MAKEFILE= Makefile.uni AR= ar r +RANLIB= ranlib IDEA_ENC=rc2_cbc.o @@ -39,7 +40,7 @@ all: $(LIB) $(TEST) $(APPS) $(LIB): $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/ranlib.sh $(LIB) + $(RANLIB) $(LIB) test: $(TEST) ./$(TEST) diff --git a/src/lib/libcrypto/rc5/asm/r586unix.cpp b/src/lib/libcrypto/rc5/asm/r586unix.cpp deleted file mode 100644 index a25dd5a9a4..0000000000 --- a/src/lib/libcrypto/rc5/asm/r586unix.cpp +++ /dev/null @@ -1,628 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define RC5_32_encrypt _RC5_32_encrypt -#define RC5_32_decrypt _RC5_32_decrypt -#define RC5_32_cbc_encrypt _RC5_32_cbc_encrypt - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by rc5-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "rc5-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl RC5_32_encrypt - TYPE(RC5_32_encrypt,@function) -RC5_32_encrypt: - - pushl %ebp - pushl %esi - pushl %edi - movl 16(%esp), %edx - movl 20(%esp), %ebp - /* Load the 2 words */ - movl (%edx), %edi - movl 4(%edx), %esi - pushl %ebx - movl (%ebp), %ebx - addl 4(%ebp), %edi - addl 8(%ebp), %esi - xorl %esi, %edi - movl 12(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 16(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 20(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 24(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 28(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 32(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 36(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 40(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 44(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 48(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 52(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 56(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 60(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 64(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 68(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 72(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - cmpl $8, %ebx - je .L000rc5_exit - xorl %esi, %edi - movl 76(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 80(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 84(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 88(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 92(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 96(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 100(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 104(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - cmpl $12, %ebx - je .L000rc5_exit - xorl %esi, %edi - movl 108(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 112(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 116(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 120(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 124(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 128(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi - xorl %esi, %edi - movl 132(%ebp), %eax - movl %esi, %ecx - roll %cl, %edi - addl %eax, %edi - xorl %edi, %esi - movl 136(%ebp), %eax - movl %edi, %ecx - roll %cl, %esi - addl %eax, %esi -.L000rc5_exit: - movl %edi, (%edx) - movl %esi, 4(%edx) - popl %ebx - popl %edi - popl %esi - popl %ebp - ret -.RC5_32_encrypt_end: - SIZE(RC5_32_encrypt,.RC5_32_encrypt_end-RC5_32_encrypt) -.ident "desasm.pl" -.text - .align ALIGN -.globl RC5_32_decrypt - TYPE(RC5_32_decrypt,@function) -RC5_32_decrypt: - - pushl %ebp - pushl %esi - pushl %edi - movl 16(%esp), %edx - movl 20(%esp), %ebp - /* Load the 2 words */ - movl (%edx), %edi - movl 4(%edx), %esi - pushl %ebx - movl (%ebp), %ebx - cmpl $12, %ebx - je .L001rc5_dec_12 - cmpl $8, %ebx - je .L002rc5_dec_8 - movl 136(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 132(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 128(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 124(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 120(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 116(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 112(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 108(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi -.L001rc5_dec_12: - movl 104(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 100(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 96(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 92(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 88(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 84(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 80(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 76(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi -.L002rc5_dec_8: - movl 72(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 68(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 64(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 60(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 56(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 52(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 48(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 44(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 40(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 36(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 32(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 28(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 24(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 20(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - movl 16(%ebp), %eax - subl %eax, %esi - movl %edi, %ecx - rorl %cl, %esi - xorl %edi, %esi - movl 12(%ebp), %eax - subl %eax, %edi - movl %esi, %ecx - rorl %cl, %edi - xorl %esi, %edi - subl 8(%ebp), %esi - subl 4(%ebp), %edi -.L003rc5_exit: - movl %edi, (%edx) - movl %esi, 4(%edx) - popl %ebx - popl %edi - popl %esi - popl %ebp - ret -.RC5_32_decrypt_end: - SIZE(RC5_32_decrypt,.RC5_32_decrypt_end-RC5_32_decrypt) -.ident "desasm.pl" -.text - .align ALIGN -.globl RC5_32_cbc_encrypt - TYPE(RC5_32_cbc_encrypt,@function) -RC5_32_cbc_encrypt: - - pushl %ebp - pushl %ebx - pushl %esi - pushl %edi - movl 28(%esp), %ebp - /* getting iv ptr from parameter 4 */ - movl 36(%esp), %ebx - movl (%ebx), %esi - movl 4(%ebx), %edi - pushl %edi - pushl %esi - pushl %edi - pushl %esi - movl %esp, %ebx - movl 36(%esp), %esi - movl 40(%esp), %edi - /* getting encrypt flag from parameter 5 */ - movl 56(%esp), %ecx - /* get and push parameter 3 */ - movl 48(%esp), %eax - pushl %eax - pushl %ebx - cmpl $0, %ecx - jz .L004decrypt - andl $4294967288, %ebp - movl 8(%esp), %eax - movl 12(%esp), %ebx - jz .L005encrypt_finish -.L006encrypt_loop: - movl (%esi), %ecx - movl 4(%esi), %edx - xorl %ecx, %eax - xorl %edx, %ebx - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call RC5_32_encrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx - movl %eax, (%edi) - movl %ebx, 4(%edi) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L006encrypt_loop -.L005encrypt_finish: - movl 52(%esp), %ebp - andl $7, %ebp - jz .L007finish - xorl %ecx, %ecx - xorl %edx, %edx - movl .L008cbc_enc_jmp_table(,%ebp,4),%ebp - jmp *%ebp -.L009ej7: - movb 6(%esi), %dh - sall $8, %edx -.L010ej6: - movb 5(%esi), %dh -.L011ej5: - movb 4(%esi), %dl -.L012ej4: - movl (%esi), %ecx - jmp .L013ejend -.L014ej3: - movb 2(%esi), %ch - sall $8, %ecx -.L015ej2: - movb 1(%esi), %ch -.L016ej1: - movb (%esi), %cl -.L013ejend: - xorl %ecx, %eax - xorl %edx, %ebx - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call RC5_32_encrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx - movl %eax, (%edi) - movl %ebx, 4(%edi) - jmp .L007finish -.align ALIGN -.L004decrypt: - andl $4294967288, %ebp - movl 16(%esp), %eax - movl 20(%esp), %ebx - jz .L017decrypt_finish -.L018decrypt_loop: - movl (%esi), %eax - movl 4(%esi), %ebx - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call RC5_32_decrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx - movl 16(%esp), %ecx - movl 20(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx - movl %ecx, (%edi) - movl %edx, 4(%edi) - movl %eax, 16(%esp) - movl %ebx, 20(%esp) - addl $8, %esi - addl $8, %edi - subl $8, %ebp - jnz .L018decrypt_loop -.L017decrypt_finish: - movl 52(%esp), %ebp - andl $7, %ebp - jz .L007finish - movl (%esi), %eax - movl 4(%esi), %ebx - movl %eax, 8(%esp) - movl %ebx, 12(%esp) - call RC5_32_decrypt - movl 8(%esp), %eax - movl 12(%esp), %ebx - movl 16(%esp), %ecx - movl 20(%esp), %edx - xorl %eax, %ecx - xorl %ebx, %edx - movl (%esi), %eax - movl 4(%esi), %ebx -.L019dj7: - rorl $16, %edx - movb %dl, 6(%edi) - shrl $16, %edx -.L020dj6: - movb %dh, 5(%edi) -.L021dj5: - movb %dl, 4(%edi) -.L022dj4: - movl %ecx, (%edi) - jmp .L023djend -.L024dj3: - rorl $16, %ecx - movb %cl, 2(%edi) - sall $16, %ecx -.L025dj2: - movb %ch, 1(%esi) -.L026dj1: - movb %cl, (%esi) -.L023djend: - jmp .L007finish -.align ALIGN -.L007finish: - movl 60(%esp), %ecx - addl $24, %esp - movl %eax, (%ecx) - movl %ebx, 4(%ecx) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.align ALIGN -.L008cbc_enc_jmp_table: - .long 0 - .long .L016ej1 - .long .L015ej2 - .long .L014ej3 - .long .L012ej4 - .long .L011ej5 - .long .L010ej6 - .long .L009ej7 -.align ALIGN -.L027cbc_dec_jmp_table: - .long 0 - .long .L026dj1 - .long .L025dj2 - .long .L024dj3 - .long .L022dj4 - .long .L021dj5 - .long .L020dj6 - .long .L019dj7 -.RC5_32_cbc_encrypt_end: - SIZE(RC5_32_cbc_encrypt,.RC5_32_cbc_encrypt_end-RC5_32_cbc_encrypt) -.ident "desasm.pl" diff --git a/src/lib/libcrypto/rc5/asm/rc5-586.pl b/src/lib/libcrypto/rc5/asm/rc5-586.pl index 172bd9ee1b..edff1d1e64 100644 --- a/src/lib/libcrypto/rc5/asm/rc5-586.pl +++ b/src/lib/libcrypto/rc5/asm/rc5-586.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl push(@INC,"perlasm","../../perlasm"); require "x86asm.pl"; diff --git a/src/lib/libcrypto/rc5/rc5.h b/src/lib/libcrypto/rc5/rc5.h index 5fd64e3f10..38e901502b 100644 --- a/src/lib/libcrypto/rc5/rc5.h +++ b/src/lib/libcrypto/rc5/rc5.h @@ -63,6 +63,10 @@ extern "C" { #endif +#ifdef NO_RC5 +#error RC5 is disabled. +#endif + #define RC5_ENCRYPT 1 #define RC5_DECRYPT 0 @@ -88,7 +92,6 @@ typedef struct rc5_key_st RC5_32_INT data[2*(RC5_16_ROUNDS+1)]; } RC5_32_KEY; -#ifndef NOPROTO void RC5_32_set_key(RC5_32_KEY *key, int len, unsigned char *data, int rounds); @@ -103,18 +106,6 @@ void RC5_32_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, void RC5_32_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, RC5_32_KEY *schedule, unsigned char *ivec, int *num); -#else - -void RC5_32_set_key(); -void RC5_32_ecb_encrypt(); -void RC5_32_encrypt(); -void RC5_32_decrypt(); -void RC5_32_cbc_encrypt(); -void RC5_32_cfb64_encrypt(); -void RC5_32_ofb64_encrypt(); - -#endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/ripemd/Makefile.ssl b/src/lib/libcrypto/ripemd/Makefile.ssl index 67d47ceb2c..b7cd25f123 100644 --- a/src/lib/libcrypto/ripemd/Makefile.ssl +++ b/src/lib/libcrypto/ripemd/Makefile.ssl @@ -8,9 +8,11 @@ CC= cc CPP= $(CC) -E INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -40,7 +42,7 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf @@ -59,26 +61,25 @@ asm/rm86-out.o: asm/rm86unix.cpp # bsdi asm/rm86bsdi.o: asm/rm86unix.cpp - $(CPP) -DBSDI asm/rm86unix.cpp | as -o asm/rm86bsdi.o + $(CPP) -DBSDI asm/rm86unix.cpp | sed 's/ :/:/' | as -o asm/rm86bsdi.o -asm/rm86unix.cpp: - (cd asm; perl rmd-586.pl cpp >rm86unix.cpp) +asm/rm86unix.cpp: asm/rmd-586.pl + (cd asm; $(PERL) rmd-586.pl cpp >rm86unix.cpp) files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -90,15 +91,17 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f asm/rm86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +rmd_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ripemd.h +rmd_dgst.o: rmd_locl.h rmdconst.h +rmd_one.o: ../../include/openssl/ripemd.h rmd_locl.h rmdconst.h diff --git a/src/lib/libcrypto/ripemd/Makefile.uni b/src/lib/libcrypto/ripemd/Makefile.uni index 54685712db..5310020eb1 100644 --- a/src/lib/libcrypto/ripemd/Makefile.uni +++ b/src/lib/libcrypto/ripemd/Makefile.uni @@ -43,7 +43,7 @@ all: $(LIB) $(TEST) $(APPS) $(LIB): $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/ranlib.sh $(LIB) + $(RANLIB) $(LIB) # elf asm/mx86-elf.o: asm/mx86unix.cpp diff --git a/src/lib/libcrypto/ripemd/asm/rips.cpp b/src/lib/libcrypto/ripemd/asm/rips.cpp index 78a933c448..321a98443e 100644 --- a/src/lib/libcrypto/ripemd/asm/rips.cpp +++ b/src/lib/libcrypto/ripemd/asm/rips.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include #include -#include "ripemd.h" +#include extern "C" { void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num); diff --git a/src/lib/libcrypto/ripemd/asm/rm86unix.cpp b/src/lib/libcrypto/ripemd/asm/rm86unix.cpp deleted file mode 100644 index f90f6f2fd6..0000000000 --- a/src/lib/libcrypto/ripemd/asm/rm86unix.cpp +++ /dev/null @@ -1,2016 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define ripemd160_block_x86 _ripemd160_block_x86 - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by rmd-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "rmd-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl ripemd160_block_x86 - TYPE(ripemd160_block_x86,@function) -ripemd160_block_x86: - pushl %esi - movl 16(%esp), %ecx - pushl %edi - movl 16(%esp), %esi - pushl %ebp - addl %esi, %ecx - pushl %ebx - subl $64, %ecx - subl $88, %esp - movl %ecx, (%esp) - movl 108(%esp), %edi -.L000start: - - movl (%esi), %eax - movl 4(%esi), %ebx - movl %eax, 4(%esp) - movl %ebx, 8(%esp) - movl 8(%esi), %eax - movl 12(%esi), %ebx - movl %eax, 12(%esp) - movl %ebx, 16(%esp) - movl 16(%esi), %eax - movl 20(%esi), %ebx - movl %eax, 20(%esp) - movl %ebx, 24(%esp) - movl 24(%esi), %eax - movl 28(%esi), %ebx - movl %eax, 28(%esp) - movl %ebx, 32(%esp) - movl 32(%esi), %eax - movl 36(%esi), %ebx - movl %eax, 36(%esp) - movl %ebx, 40(%esp) - movl 40(%esi), %eax - movl 44(%esi), %ebx - movl %eax, 44(%esp) - movl %ebx, 48(%esp) - movl 48(%esi), %eax - movl 52(%esi), %ebx - movl %eax, 52(%esp) - movl %ebx, 56(%esp) - movl 56(%esi), %eax - movl 60(%esi), %ebx - movl %eax, 60(%esp) - movl %ebx, 64(%esp) - addl $64, %esi - movl (%edi), %eax - movl %esi, 112(%esp) - movl 4(%edi), %ebx - movl 8(%edi), %ecx - movl 12(%edi), %edx - movl 16(%edi), %ebp - /* 0 */ - movl %ecx, %esi - xorl %edx, %esi - movl 4(%esp), %edi - xorl %ebx, %esi - addl %edi, %eax - roll $10, %ecx - addl %esi, %eax - movl %ebx, %esi - roll $11, %eax - addl %ebp, %eax - /* 1 */ - xorl %ecx, %esi - movl 8(%esp), %edi - xorl %eax, %esi - addl %esi, %ebp - movl %eax, %esi - roll $10, %ebx - addl %edi, %ebp - xorl %ebx, %esi - roll $14, %ebp - addl %edx, %ebp - /* 2 */ - movl 12(%esp), %edi - xorl %ebp, %esi - addl %edi, %edx - roll $10, %eax - addl %esi, %edx - movl %ebp, %esi - roll $15, %edx - addl %ecx, %edx - /* 3 */ - xorl %eax, %esi - movl 16(%esp), %edi - xorl %edx, %esi - addl %esi, %ecx - movl %edx, %esi - roll $10, %ebp - addl %edi, %ecx - xorl %ebp, %esi - roll $12, %ecx - addl %ebx, %ecx - /* 4 */ - movl 20(%esp), %edi - xorl %ecx, %esi - addl %edi, %ebx - roll $10, %edx - addl %esi, %ebx - movl %ecx, %esi - roll $5, %ebx - addl %eax, %ebx - /* 5 */ - xorl %edx, %esi - movl 24(%esp), %edi - xorl %ebx, %esi - addl %esi, %eax - movl %ebx, %esi - roll $10, %ecx - addl %edi, %eax - xorl %ecx, %esi - roll $8, %eax - addl %ebp, %eax - /* 6 */ - movl 28(%esp), %edi - xorl %eax, %esi - addl %edi, %ebp - roll $10, %ebx - addl %esi, %ebp - movl %eax, %esi - roll $7, %ebp - addl %edx, %ebp - /* 7 */ - xorl %ebx, %esi - movl 32(%esp), %edi - xorl %ebp, %esi - addl %esi, %edx - movl %ebp, %esi - roll $10, %eax - addl %edi, %edx - xorl %eax, %esi - roll $9, %edx - addl %ecx, %edx - /* 8 */ - movl 36(%esp), %edi - xorl %edx, %esi - addl %edi, %ecx - roll $10, %ebp - addl %esi, %ecx - movl %edx, %esi - roll $11, %ecx - addl %ebx, %ecx - /* 9 */ - xorl %ebp, %esi - movl 40(%esp), %edi - xorl %ecx, %esi - addl %esi, %ebx - movl %ecx, %esi - roll $10, %edx - addl %edi, %ebx - xorl %edx, %esi - roll $13, %ebx - addl %eax, %ebx - /* 10 */ - movl 44(%esp), %edi - xorl %ebx, %esi - addl %edi, %eax - roll $10, %ecx - addl %esi, %eax - movl %ebx, %esi - roll $14, %eax - addl %ebp, %eax - /* 11 */ - xorl %ecx, %esi - movl 48(%esp), %edi - xorl %eax, %esi - addl %esi, %ebp - movl %eax, %esi - roll $10, %ebx - addl %edi, %ebp - xorl %ebx, %esi - roll $15, %ebp - addl %edx, %ebp - /* 12 */ - movl 52(%esp), %edi - xorl %ebp, %esi - addl %edi, %edx - roll $10, %eax - addl %esi, %edx - movl %ebp, %esi - roll $6, %edx - addl %ecx, %edx - /* 13 */ - xorl %eax, %esi - movl 56(%esp), %edi - xorl %edx, %esi - addl %esi, %ecx - movl %edx, %esi - roll $10, %ebp - addl %edi, %ecx - xorl %ebp, %esi - roll $7, %ecx - addl %ebx, %ecx - /* 14 */ - movl 60(%esp), %edi - xorl %ecx, %esi - addl %edi, %ebx - roll $10, %edx - addl %esi, %ebx - movl %ecx, %esi - roll $9, %ebx - addl %eax, %ebx - /* 15 */ - xorl %edx, %esi - movl 64(%esp), %edi - xorl %ebx, %esi - addl %esi, %eax - movl $-1, %esi - roll $10, %ecx - addl %edi, %eax - movl 32(%esp), %edi - roll $8, %eax - addl %ebp, %eax - /* 16 */ - addl %edi, %ebp - movl %ebx, %edi - subl %eax, %esi - andl %eax, %edi - andl %ecx, %esi - orl %esi, %edi - movl 20(%esp), %esi - roll $10, %ebx - leal 1518500249(%ebp,%edi,1),%ebp - movl $-1, %edi - roll $7, %ebp - addl %edx, %ebp - /* 17 */ - addl %esi, %edx - movl %eax, %esi - subl %ebp, %edi - andl %ebp, %esi - andl %ebx, %edi - orl %edi, %esi - movl 56(%esp), %edi - roll $10, %eax - leal 1518500249(%edx,%esi,1),%edx - movl $-1, %esi - roll $6, %edx - addl %ecx, %edx - /* 18 */ - addl %edi, %ecx - movl %ebp, %edi - subl %edx, %esi - andl %edx, %edi - andl %eax, %esi - orl %esi, %edi - movl 8(%esp), %esi - roll $10, %ebp - leal 1518500249(%ecx,%edi,1),%ecx - movl $-1, %edi - roll $8, %ecx - addl %ebx, %ecx - /* 19 */ - addl %esi, %ebx - movl %edx, %esi - subl %ecx, %edi - andl %ecx, %esi - andl %ebp, %edi - orl %edi, %esi - movl 44(%esp), %edi - roll $10, %edx - leal 1518500249(%ebx,%esi,1),%ebx - movl $-1, %esi - roll $13, %ebx - addl %eax, %ebx - /* 20 */ - addl %edi, %eax - movl %ecx, %edi - subl %ebx, %esi - andl %ebx, %edi - andl %edx, %esi - orl %esi, %edi - movl 28(%esp), %esi - roll $10, %ecx - leal 1518500249(%eax,%edi,1),%eax - movl $-1, %edi - roll $11, %eax - addl %ebp, %eax - /* 21 */ - addl %esi, %ebp - movl %ebx, %esi - subl %eax, %edi - andl %eax, %esi - andl %ecx, %edi - orl %edi, %esi - movl 64(%esp), %edi - roll $10, %ebx - leal 1518500249(%ebp,%esi,1),%ebp - movl $-1, %esi - roll $9, %ebp - addl %edx, %ebp - /* 22 */ - addl %edi, %edx - movl %eax, %edi - subl %ebp, %esi - andl %ebp, %edi - andl %ebx, %esi - orl %esi, %edi - movl 16(%esp), %esi - roll $10, %eax - leal 1518500249(%edx,%edi,1),%edx - movl $-1, %edi - roll $7, %edx - addl %ecx, %edx - /* 23 */ - addl %esi, %ecx - movl %ebp, %esi - subl %edx, %edi - andl %edx, %esi - andl %eax, %edi - orl %edi, %esi - movl 52(%esp), %edi - roll $10, %ebp - leal 1518500249(%ecx,%esi,1),%ecx - movl $-1, %esi - roll $15, %ecx - addl %ebx, %ecx - /* 24 */ - addl %edi, %ebx - movl %edx, %edi - subl %ecx, %esi - andl %ecx, %edi - andl %ebp, %esi - orl %esi, %edi - movl 4(%esp), %esi - roll $10, %edx - leal 1518500249(%ebx,%edi,1),%ebx - movl $-1, %edi - roll $7, %ebx - addl %eax, %ebx - /* 25 */ - addl %esi, %eax - movl %ecx, %esi - subl %ebx, %edi - andl %ebx, %esi - andl %edx, %edi - orl %edi, %esi - movl 40(%esp), %edi - roll $10, %ecx - leal 1518500249(%eax,%esi,1),%eax - movl $-1, %esi - roll $12, %eax - addl %ebp, %eax - /* 26 */ - addl %edi, %ebp - movl %ebx, %edi - subl %eax, %esi - andl %eax, %edi - andl %ecx, %esi - orl %esi, %edi - movl 24(%esp), %esi - roll $10, %ebx - leal 1518500249(%ebp,%edi,1),%ebp - movl $-1, %edi - roll $15, %ebp - addl %edx, %ebp - /* 27 */ - addl %esi, %edx - movl %eax, %esi - subl %ebp, %edi - andl %ebp, %esi - andl %ebx, %edi - orl %edi, %esi - movl 12(%esp), %edi - roll $10, %eax - leal 1518500249(%edx,%esi,1),%edx - movl $-1, %esi - roll $9, %edx - addl %ecx, %edx - /* 28 */ - addl %edi, %ecx - movl %ebp, %edi - subl %edx, %esi - andl %edx, %edi - andl %eax, %esi - orl %esi, %edi - movl 60(%esp), %esi - roll $10, %ebp - leal 1518500249(%ecx,%edi,1),%ecx - movl $-1, %edi - roll $11, %ecx - addl %ebx, %ecx - /* 29 */ - addl %esi, %ebx - movl %edx, %esi - subl %ecx, %edi - andl %ecx, %esi - andl %ebp, %edi - orl %edi, %esi - movl 48(%esp), %edi - roll $10, %edx - leal 1518500249(%ebx,%esi,1),%ebx - movl $-1, %esi - roll $7, %ebx - addl %eax, %ebx - /* 30 */ - addl %edi, %eax - movl %ecx, %edi - subl %ebx, %esi - andl %ebx, %edi - andl %edx, %esi - orl %esi, %edi - movl 36(%esp), %esi - roll $10, %ecx - leal 1518500249(%eax,%edi,1),%eax - movl $-1, %edi - roll $13, %eax - addl %ebp, %eax - /* 31 */ - addl %esi, %ebp - movl %ebx, %esi - subl %eax, %edi - andl %eax, %esi - andl %ecx, %edi - orl %edi, %esi - movl $-1, %edi - roll $10, %ebx - leal 1518500249(%ebp,%esi,1),%ebp - subl %eax, %edi - roll $12, %ebp - addl %edx, %ebp - /* 32 */ - movl 16(%esp), %esi - orl %ebp, %edi - addl %esi, %edx - xorl %ebx, %edi - movl $-1, %esi - roll $10, %eax - leal 1859775393(%edx,%edi,1),%edx - subl %ebp, %esi - roll $11, %edx - addl %ecx, %edx - /* 33 */ - movl 44(%esp), %edi - orl %edx, %esi - addl %edi, %ecx - xorl %eax, %esi - movl $-1, %edi - roll $10, %ebp - leal 1859775393(%ecx,%esi,1),%ecx - subl %edx, %edi - roll $13, %ecx - addl %ebx, %ecx - /* 34 */ - movl 60(%esp), %esi - orl %ecx, %edi - addl %esi, %ebx - xorl %ebp, %edi - movl $-1, %esi - roll $10, %edx - leal 1859775393(%ebx,%edi,1),%ebx - subl %ecx, %esi - roll $6, %ebx - addl %eax, %ebx - /* 35 */ - movl 20(%esp), %edi - orl %ebx, %esi - addl %edi, %eax - xorl %edx, %esi - movl $-1, %edi - roll $10, %ecx - leal 1859775393(%eax,%esi,1),%eax - subl %ebx, %edi - roll $7, %eax - addl %ebp, %eax - /* 36 */ - movl 40(%esp), %esi - orl %eax, %edi - addl %esi, %ebp - xorl %ecx, %edi - movl $-1, %esi - roll $10, %ebx - leal 1859775393(%ebp,%edi,1),%ebp - subl %eax, %esi - roll $14, %ebp - addl %edx, %ebp - /* 37 */ - movl 64(%esp), %edi - orl %ebp, %esi - addl %edi, %edx - xorl %ebx, %esi - movl $-1, %edi - roll $10, %eax - leal 1859775393(%edx,%esi,1),%edx - subl %ebp, %edi - roll $9, %edx - addl %ecx, %edx - /* 38 */ - movl 36(%esp), %esi - orl %edx, %edi - addl %esi, %ecx - xorl %eax, %edi - movl $-1, %esi - roll $10, %ebp - leal 1859775393(%ecx,%edi,1),%ecx - subl %edx, %esi - roll $13, %ecx - addl %ebx, %ecx - /* 39 */ - movl 8(%esp), %edi - orl %ecx, %esi - addl %edi, %ebx - xorl %ebp, %esi - movl $-1, %edi - roll $10, %edx - leal 1859775393(%ebx,%esi,1),%ebx - subl %ecx, %edi - roll $15, %ebx - addl %eax, %ebx - /* 40 */ - movl 12(%esp), %esi - orl %ebx, %edi - addl %esi, %eax - xorl %edx, %edi - movl $-1, %esi - roll $10, %ecx - leal 1859775393(%eax,%edi,1),%eax - subl %ebx, %esi - roll $14, %eax - addl %ebp, %eax - /* 41 */ - movl 32(%esp), %edi - orl %eax, %esi - addl %edi, %ebp - xorl %ecx, %esi - movl $-1, %edi - roll $10, %ebx - leal 1859775393(%ebp,%esi,1),%ebp - subl %eax, %edi - roll $8, %ebp - addl %edx, %ebp - /* 42 */ - movl 4(%esp), %esi - orl %ebp, %edi - addl %esi, %edx - xorl %ebx, %edi - movl $-1, %esi - roll $10, %eax - leal 1859775393(%edx,%edi,1),%edx - subl %ebp, %esi - roll $13, %edx - addl %ecx, %edx - /* 43 */ - movl 28(%esp), %edi - orl %edx, %esi - addl %edi, %ecx - xorl %eax, %esi - movl $-1, %edi - roll $10, %ebp - leal 1859775393(%ecx,%esi,1),%ecx - subl %edx, %edi - roll $6, %ecx - addl %ebx, %ecx - /* 44 */ - movl 56(%esp), %esi - orl %ecx, %edi - addl %esi, %ebx - xorl %ebp, %edi - movl $-1, %esi - roll $10, %edx - leal 1859775393(%ebx,%edi,1),%ebx - subl %ecx, %esi - roll $5, %ebx - addl %eax, %ebx - /* 45 */ - movl 48(%esp), %edi - orl %ebx, %esi - addl %edi, %eax - xorl %edx, %esi - movl $-1, %edi - roll $10, %ecx - leal 1859775393(%eax,%esi,1),%eax - subl %ebx, %edi - roll $12, %eax - addl %ebp, %eax - /* 46 */ - movl 24(%esp), %esi - orl %eax, %edi - addl %esi, %ebp - xorl %ecx, %edi - movl $-1, %esi - roll $10, %ebx - leal 1859775393(%ebp,%edi,1),%ebp - subl %eax, %esi - roll $7, %ebp - addl %edx, %ebp - /* 47 */ - movl 52(%esp), %edi - orl %ebp, %esi - addl %edi, %edx - xorl %ebx, %esi - movl $-1, %edi - roll $10, %eax - leal 1859775393(%edx,%esi,1),%edx - movl %eax, %esi - roll $5, %edx - addl %ecx, %edx - /* 48 */ - subl %eax, %edi - andl %edx, %esi - andl %ebp, %edi - orl %esi, %edi - movl 8(%esp), %esi - roll $10, %ebp - leal 2400959708(%ecx,%edi,),%ecx - movl $-1, %edi - addl %esi, %ecx - movl %ebp, %esi - roll $11, %ecx - addl %ebx, %ecx - /* 49 */ - subl %ebp, %edi - andl %ecx, %esi - andl %edx, %edi - orl %esi, %edi - movl 40(%esp), %esi - roll $10, %edx - leal 2400959708(%ebx,%edi,),%ebx - movl $-1, %edi - addl %esi, %ebx - movl %edx, %esi - roll $12, %ebx - addl %eax, %ebx - /* 50 */ - subl %edx, %edi - andl %ebx, %esi - andl %ecx, %edi - orl %esi, %edi - movl 48(%esp), %esi - roll $10, %ecx - leal 2400959708(%eax,%edi,),%eax - movl $-1, %edi - addl %esi, %eax - movl %ecx, %esi - roll $14, %eax - addl %ebp, %eax - /* 51 */ - subl %ecx, %edi - andl %eax, %esi - andl %ebx, %edi - orl %esi, %edi - movl 44(%esp), %esi - roll $10, %ebx - leal 2400959708(%ebp,%edi,),%ebp - movl $-1, %edi - addl %esi, %ebp - movl %ebx, %esi - roll $15, %ebp - addl %edx, %ebp - /* 52 */ - subl %ebx, %edi - andl %ebp, %esi - andl %eax, %edi - orl %esi, %edi - movl 4(%esp), %esi - roll $10, %eax - leal 2400959708(%edx,%edi,),%edx - movl $-1, %edi - addl %esi, %edx - movl %eax, %esi - roll $14, %edx - addl %ecx, %edx - /* 53 */ - subl %eax, %edi - andl %edx, %esi - andl %ebp, %edi - orl %esi, %edi - movl 36(%esp), %esi - roll $10, %ebp - leal 2400959708(%ecx,%edi,),%ecx - movl $-1, %edi - addl %esi, %ecx - movl %ebp, %esi - roll $15, %ecx - addl %ebx, %ecx - /* 54 */ - subl %ebp, %edi - andl %ecx, %esi - andl %edx, %edi - orl %esi, %edi - movl 52(%esp), %esi - roll $10, %edx - leal 2400959708(%ebx,%edi,),%ebx - movl $-1, %edi - addl %esi, %ebx - movl %edx, %esi - roll $9, %ebx - addl %eax, %ebx - /* 55 */ - subl %edx, %edi - andl %ebx, %esi - andl %ecx, %edi - orl %esi, %edi - movl 20(%esp), %esi - roll $10, %ecx - leal 2400959708(%eax,%edi,),%eax - movl $-1, %edi - addl %esi, %eax - movl %ecx, %esi - roll $8, %eax - addl %ebp, %eax - /* 56 */ - subl %ecx, %edi - andl %eax, %esi - andl %ebx, %edi - orl %esi, %edi - movl 56(%esp), %esi - roll $10, %ebx - leal 2400959708(%ebp,%edi,),%ebp - movl $-1, %edi - addl %esi, %ebp - movl %ebx, %esi - roll $9, %ebp - addl %edx, %ebp - /* 57 */ - subl %ebx, %edi - andl %ebp, %esi - andl %eax, %edi - orl %esi, %edi - movl 16(%esp), %esi - roll $10, %eax - leal 2400959708(%edx,%edi,),%edx - movl $-1, %edi - addl %esi, %edx - movl %eax, %esi - roll $14, %edx - addl %ecx, %edx - /* 58 */ - subl %eax, %edi - andl %edx, %esi - andl %ebp, %edi - orl %esi, %edi - movl 32(%esp), %esi - roll $10, %ebp - leal 2400959708(%ecx,%edi,),%ecx - movl $-1, %edi - addl %esi, %ecx - movl %ebp, %esi - roll $5, %ecx - addl %ebx, %ecx - /* 59 */ - subl %ebp, %edi - andl %ecx, %esi - andl %edx, %edi - orl %esi, %edi - movl 64(%esp), %esi - roll $10, %edx - leal 2400959708(%ebx,%edi,),%ebx - movl $-1, %edi - addl %esi, %ebx - movl %edx, %esi - roll $6, %ebx - addl %eax, %ebx - /* 60 */ - subl %edx, %edi - andl %ebx, %esi - andl %ecx, %edi - orl %esi, %edi - movl 60(%esp), %esi - roll $10, %ecx - leal 2400959708(%eax,%edi,),%eax - movl $-1, %edi - addl %esi, %eax - movl %ecx, %esi - roll $8, %eax - addl %ebp, %eax - /* 61 */ - subl %ecx, %edi - andl %eax, %esi - andl %ebx, %edi - orl %esi, %edi - movl 24(%esp), %esi - roll $10, %ebx - leal 2400959708(%ebp,%edi,),%ebp - movl $-1, %edi - addl %esi, %ebp - movl %ebx, %esi - roll $6, %ebp - addl %edx, %ebp - /* 62 */ - subl %ebx, %edi - andl %ebp, %esi - andl %eax, %edi - orl %esi, %edi - movl 28(%esp), %esi - roll $10, %eax - leal 2400959708(%edx,%edi,),%edx - movl $-1, %edi - addl %esi, %edx - movl %eax, %esi - roll $5, %edx - addl %ecx, %edx - /* 63 */ - subl %eax, %edi - andl %edx, %esi - andl %ebp, %edi - orl %esi, %edi - movl 12(%esp), %esi - roll $10, %ebp - leal 2400959708(%ecx,%edi,),%ecx - movl $-1, %edi - addl %esi, %ecx - subl %ebp, %edi - roll $12, %ecx - addl %ebx, %ecx - /* 64 */ - movl 20(%esp), %esi - orl %edx, %edi - addl %esi, %ebx - xorl %ecx, %edi - movl $-1, %esi - roll $10, %edx - leal 2840853838(%ebx,%edi,1),%ebx - subl %edx, %esi - roll $9, %ebx - addl %eax, %ebx - /* 65 */ - movl 4(%esp), %edi - orl %ecx, %esi - addl %edi, %eax - xorl %ebx, %esi - movl $-1, %edi - roll $10, %ecx - leal 2840853838(%eax,%esi,1),%eax - subl %ecx, %edi - roll $15, %eax - addl %ebp, %eax - /* 66 */ - movl 24(%esp), %esi - orl %ebx, %edi - addl %esi, %ebp - xorl %eax, %edi - movl $-1, %esi - roll $10, %ebx - leal 2840853838(%ebp,%edi,1),%ebp - subl %ebx, %esi - roll $5, %ebp - addl %edx, %ebp - /* 67 */ - movl 40(%esp), %edi - orl %eax, %esi - addl %edi, %edx - xorl %ebp, %esi - movl $-1, %edi - roll $10, %eax - leal 2840853838(%edx,%esi,1),%edx - subl %eax, %edi - roll $11, %edx - addl %ecx, %edx - /* 68 */ - movl 32(%esp), %esi - orl %ebp, %edi - addl %esi, %ecx - xorl %edx, %edi - movl $-1, %esi - roll $10, %ebp - leal 2840853838(%ecx,%edi,1),%ecx - subl %ebp, %esi - roll $6, %ecx - addl %ebx, %ecx - /* 69 */ - movl 52(%esp), %edi - orl %edx, %esi - addl %edi, %ebx - xorl %ecx, %esi - movl $-1, %edi - roll $10, %edx - leal 2840853838(%ebx,%esi,1),%ebx - subl %edx, %edi - roll $8, %ebx - addl %eax, %ebx - /* 70 */ - movl 12(%esp), %esi - orl %ecx, %edi - addl %esi, %eax - xorl %ebx, %edi - movl $-1, %esi - roll $10, %ecx - leal 2840853838(%eax,%edi,1),%eax - subl %ecx, %esi - roll $13, %eax - addl %ebp, %eax - /* 71 */ - movl 44(%esp), %edi - orl %ebx, %esi - addl %edi, %ebp - xorl %eax, %esi - movl $-1, %edi - roll $10, %ebx - leal 2840853838(%ebp,%esi,1),%ebp - subl %ebx, %edi - roll $12, %ebp - addl %edx, %ebp - /* 72 */ - movl 60(%esp), %esi - orl %eax, %edi - addl %esi, %edx - xorl %ebp, %edi - movl $-1, %esi - roll $10, %eax - leal 2840853838(%edx,%edi,1),%edx - subl %eax, %esi - roll $5, %edx - addl %ecx, %edx - /* 73 */ - movl 8(%esp), %edi - orl %ebp, %esi - addl %edi, %ecx - xorl %edx, %esi - movl $-1, %edi - roll $10, %ebp - leal 2840853838(%ecx,%esi,1),%ecx - subl %ebp, %edi - roll $12, %ecx - addl %ebx, %ecx - /* 74 */ - movl 16(%esp), %esi - orl %edx, %edi - addl %esi, %ebx - xorl %ecx, %edi - movl $-1, %esi - roll $10, %edx - leal 2840853838(%ebx,%edi,1),%ebx - subl %edx, %esi - roll $13, %ebx - addl %eax, %ebx - /* 75 */ - movl 36(%esp), %edi - orl %ecx, %esi - addl %edi, %eax - xorl %ebx, %esi - movl $-1, %edi - roll $10, %ecx - leal 2840853838(%eax,%esi,1),%eax - subl %ecx, %edi - roll $14, %eax - addl %ebp, %eax - /* 76 */ - movl 48(%esp), %esi - orl %ebx, %edi - addl %esi, %ebp - xorl %eax, %edi - movl $-1, %esi - roll $10, %ebx - leal 2840853838(%ebp,%edi,1),%ebp - subl %ebx, %esi - roll $11, %ebp - addl %edx, %ebp - /* 77 */ - movl 28(%esp), %edi - orl %eax, %esi - addl %edi, %edx - xorl %ebp, %esi - movl $-1, %edi - roll $10, %eax - leal 2840853838(%edx,%esi,1),%edx - subl %eax, %edi - roll $8, %edx - addl %ecx, %edx - /* 78 */ - movl 64(%esp), %esi - orl %ebp, %edi - addl %esi, %ecx - xorl %edx, %edi - movl $-1, %esi - roll $10, %ebp - leal 2840853838(%ecx,%edi,1),%ecx - subl %ebp, %esi - roll $5, %ecx - addl %ebx, %ecx - /* 79 */ - movl 56(%esp), %edi - orl %edx, %esi - addl %edi, %ebx - xorl %ecx, %esi - movl 108(%esp), %edi - roll $10, %edx - leal 2840853838(%ebx,%esi,1),%ebx - movl %eax, 68(%esp) - roll $6, %ebx - addl %eax, %ebx - movl (%edi), %eax - movl %ebx, 72(%esp) - movl %ecx, 76(%esp) - movl 4(%edi), %ebx - movl %edx, 80(%esp) - movl 8(%edi), %ecx - movl %ebp, 84(%esp) - movl 12(%edi), %edx - movl 16(%edi), %ebp - /* 80 */ - movl $-1, %edi - subl %edx, %edi - movl 24(%esp), %esi - orl %ecx, %edi - addl %esi, %eax - xorl %ebx, %edi - movl $-1, %esi - roll $10, %ecx - leal 1352829926(%eax,%edi,1),%eax - subl %ecx, %esi - roll $8, %eax - addl %ebp, %eax - /* 81 */ - movl 60(%esp), %edi - orl %ebx, %esi - addl %edi, %ebp - xorl %eax, %esi - movl $-1, %edi - roll $10, %ebx - leal 1352829926(%ebp,%esi,1),%ebp - subl %ebx, %edi - roll $9, %ebp - addl %edx, %ebp - /* 82 */ - movl 32(%esp), %esi - orl %eax, %edi - addl %esi, %edx - xorl %ebp, %edi - movl $-1, %esi - roll $10, %eax - leal 1352829926(%edx,%edi,1),%edx - subl %eax, %esi - roll $9, %edx - addl %ecx, %edx - /* 83 */ - movl 4(%esp), %edi - orl %ebp, %esi - addl %edi, %ecx - xorl %edx, %esi - movl $-1, %edi - roll $10, %ebp - leal 1352829926(%ecx,%esi,1),%ecx - subl %ebp, %edi - roll $11, %ecx - addl %ebx, %ecx - /* 84 */ - movl 40(%esp), %esi - orl %edx, %edi - addl %esi, %ebx - xorl %ecx, %edi - movl $-1, %esi - roll $10, %edx - leal 1352829926(%ebx,%edi,1),%ebx - subl %edx, %esi - roll $13, %ebx - addl %eax, %ebx - /* 85 */ - movl 12(%esp), %edi - orl %ecx, %esi - addl %edi, %eax - xorl %ebx, %esi - movl $-1, %edi - roll $10, %ecx - leal 1352829926(%eax,%esi,1),%eax - subl %ecx, %edi - roll $15, %eax - addl %ebp, %eax - /* 86 */ - movl 48(%esp), %esi - orl %ebx, %edi - addl %esi, %ebp - xorl %eax, %edi - movl $-1, %esi - roll $10, %ebx - leal 1352829926(%ebp,%edi,1),%ebp - subl %ebx, %esi - roll $15, %ebp - addl %edx, %ebp - /* 87 */ - movl 20(%esp), %edi - orl %eax, %esi - addl %edi, %edx - xorl %ebp, %esi - movl $-1, %edi - roll $10, %eax - leal 1352829926(%edx,%esi,1),%edx - subl %eax, %edi - roll $5, %edx - addl %ecx, %edx - /* 88 */ - movl 56(%esp), %esi - orl %ebp, %edi - addl %esi, %ecx - xorl %edx, %edi - movl $-1, %esi - roll $10, %ebp - leal 1352829926(%ecx,%edi,1),%ecx - subl %ebp, %esi - roll $7, %ecx - addl %ebx, %ecx - /* 89 */ - movl 28(%esp), %edi - orl %edx, %esi - addl %edi, %ebx - xorl %ecx, %esi - movl $-1, %edi - roll $10, %edx - leal 1352829926(%ebx,%esi,1),%ebx - subl %edx, %edi - roll $7, %ebx - addl %eax, %ebx - /* 90 */ - movl 64(%esp), %esi - orl %ecx, %edi - addl %esi, %eax - xorl %ebx, %edi - movl $-1, %esi - roll $10, %ecx - leal 1352829926(%eax,%edi,1),%eax - subl %ecx, %esi - roll $8, %eax - addl %ebp, %eax - /* 91 */ - movl 36(%esp), %edi - orl %ebx, %esi - addl %edi, %ebp - xorl %eax, %esi - movl $-1, %edi - roll $10, %ebx - leal 1352829926(%ebp,%esi,1),%ebp - subl %ebx, %edi - roll $11, %ebp - addl %edx, %ebp - /* 92 */ - movl 8(%esp), %esi - orl %eax, %edi - addl %esi, %edx - xorl %ebp, %edi - movl $-1, %esi - roll $10, %eax - leal 1352829926(%edx,%edi,1),%edx - subl %eax, %esi - roll $14, %edx - addl %ecx, %edx - /* 93 */ - movl 44(%esp), %edi - orl %ebp, %esi - addl %edi, %ecx - xorl %edx, %esi - movl $-1, %edi - roll $10, %ebp - leal 1352829926(%ecx,%esi,1),%ecx - subl %ebp, %edi - roll $14, %ecx - addl %ebx, %ecx - /* 94 */ - movl 16(%esp), %esi - orl %edx, %edi - addl %esi, %ebx - xorl %ecx, %edi - movl $-1, %esi - roll $10, %edx - leal 1352829926(%ebx,%edi,1),%ebx - subl %edx, %esi - roll $12, %ebx - addl %eax, %ebx - /* 95 */ - movl 52(%esp), %edi - orl %ecx, %esi - addl %edi, %eax - xorl %ebx, %esi - movl $-1, %edi - roll $10, %ecx - leal 1352829926(%eax,%esi,1),%eax - movl %ecx, %esi - roll $6, %eax - addl %ebp, %eax - /* 96 */ - subl %ecx, %edi - andl %eax, %esi - andl %ebx, %edi - orl %esi, %edi - movl 28(%esp), %esi - roll $10, %ebx - leal 1548603684(%ebp,%edi,),%ebp - movl $-1, %edi - addl %esi, %ebp - movl %ebx, %esi - roll $9, %ebp - addl %edx, %ebp - /* 97 */ - subl %ebx, %edi - andl %ebp, %esi - andl %eax, %edi - orl %esi, %edi - movl 48(%esp), %esi - roll $10, %eax - leal 1548603684(%edx,%edi,),%edx - movl $-1, %edi - addl %esi, %edx - movl %eax, %esi - roll $13, %edx - addl %ecx, %edx - /* 98 */ - subl %eax, %edi - andl %edx, %esi - andl %ebp, %edi - orl %esi, %edi - movl 16(%esp), %esi - roll $10, %ebp - leal 1548603684(%ecx,%edi,),%ecx - movl $-1, %edi - addl %esi, %ecx - movl %ebp, %esi - roll $15, %ecx - addl %ebx, %ecx - /* 99 */ - subl %ebp, %edi - andl %ecx, %esi - andl %edx, %edi - orl %esi, %edi - movl 32(%esp), %esi - roll $10, %edx - leal 1548603684(%ebx,%edi,),%ebx - movl $-1, %edi - addl %esi, %ebx - movl %edx, %esi - roll $7, %ebx - addl %eax, %ebx - /* 100 */ - subl %edx, %edi - andl %ebx, %esi - andl %ecx, %edi - orl %esi, %edi - movl 4(%esp), %esi - roll $10, %ecx - leal 1548603684(%eax,%edi,),%eax - movl $-1, %edi - addl %esi, %eax - movl %ecx, %esi - roll $12, %eax - addl %ebp, %eax - /* 101 */ - subl %ecx, %edi - andl %eax, %esi - andl %ebx, %edi - orl %esi, %edi - movl 56(%esp), %esi - roll $10, %ebx - leal 1548603684(%ebp,%edi,),%ebp - movl $-1, %edi - addl %esi, %ebp - movl %ebx, %esi - roll $8, %ebp - addl %edx, %ebp - /* 102 */ - subl %ebx, %edi - andl %ebp, %esi - andl %eax, %edi - orl %esi, %edi - movl 24(%esp), %esi - roll $10, %eax - leal 1548603684(%edx,%edi,),%edx - movl $-1, %edi - addl %esi, %edx - movl %eax, %esi - roll $9, %edx - addl %ecx, %edx - /* 103 */ - subl %eax, %edi - andl %edx, %esi - andl %ebp, %edi - orl %esi, %edi - movl 44(%esp), %esi - roll $10, %ebp - leal 1548603684(%ecx,%edi,),%ecx - movl $-1, %edi - addl %esi, %ecx - movl %ebp, %esi - roll $11, %ecx - addl %ebx, %ecx - /* 104 */ - subl %ebp, %edi - andl %ecx, %esi - andl %edx, %edi - orl %esi, %edi - movl 60(%esp), %esi - roll $10, %edx - leal 1548603684(%ebx,%edi,),%ebx - movl $-1, %edi - addl %esi, %ebx - movl %edx, %esi - roll $7, %ebx - addl %eax, %ebx - /* 105 */ - subl %edx, %edi - andl %ebx, %esi - andl %ecx, %edi - orl %esi, %edi - movl 64(%esp), %esi - roll $10, %ecx - leal 1548603684(%eax,%edi,),%eax - movl $-1, %edi - addl %esi, %eax - movl %ecx, %esi - roll $7, %eax - addl %ebp, %eax - /* 106 */ - subl %ecx, %edi - andl %eax, %esi - andl %ebx, %edi - orl %esi, %edi - movl 36(%esp), %esi - roll $10, %ebx - leal 1548603684(%ebp,%edi,),%ebp - movl $-1, %edi - addl %esi, %ebp - movl %ebx, %esi - roll $12, %ebp - addl %edx, %ebp - /* 107 */ - subl %ebx, %edi - andl %ebp, %esi - andl %eax, %edi - orl %esi, %edi - movl 52(%esp), %esi - roll $10, %eax - leal 1548603684(%edx,%edi,),%edx - movl $-1, %edi - addl %esi, %edx - movl %eax, %esi - roll $7, %edx - addl %ecx, %edx - /* 108 */ - subl %eax, %edi - andl %edx, %esi - andl %ebp, %edi - orl %esi, %edi - movl 20(%esp), %esi - roll $10, %ebp - leal 1548603684(%ecx,%edi,),%ecx - movl $-1, %edi - addl %esi, %ecx - movl %ebp, %esi - roll $6, %ecx - addl %ebx, %ecx - /* 109 */ - subl %ebp, %edi - andl %ecx, %esi - andl %edx, %edi - orl %esi, %edi - movl 40(%esp), %esi - roll $10, %edx - leal 1548603684(%ebx,%edi,),%ebx - movl $-1, %edi - addl %esi, %ebx - movl %edx, %esi - roll $15, %ebx - addl %eax, %ebx - /* 110 */ - subl %edx, %edi - andl %ebx, %esi - andl %ecx, %edi - orl %esi, %edi - movl 8(%esp), %esi - roll $10, %ecx - leal 1548603684(%eax,%edi,),%eax - movl $-1, %edi - addl %esi, %eax - movl %ecx, %esi - roll $13, %eax - addl %ebp, %eax - /* 111 */ - subl %ecx, %edi - andl %eax, %esi - andl %ebx, %edi - orl %esi, %edi - movl 12(%esp), %esi - roll $10, %ebx - leal 1548603684(%ebp,%edi,),%ebp - movl $-1, %edi - addl %esi, %ebp - subl %eax, %edi - roll $11, %ebp - addl %edx, %ebp - /* 112 */ - movl 64(%esp), %esi - orl %ebp, %edi - addl %esi, %edx - xorl %ebx, %edi - movl $-1, %esi - roll $10, %eax - leal 1836072691(%edx,%edi,1),%edx - subl %ebp, %esi - roll $9, %edx - addl %ecx, %edx - /* 113 */ - movl 24(%esp), %edi - orl %edx, %esi - addl %edi, %ecx - xorl %eax, %esi - movl $-1, %edi - roll $10, %ebp - leal 1836072691(%ecx,%esi,1),%ecx - subl %edx, %edi - roll $7, %ecx - addl %ebx, %ecx - /* 114 */ - movl 8(%esp), %esi - orl %ecx, %edi - addl %esi, %ebx - xorl %ebp, %edi - movl $-1, %esi - roll $10, %edx - leal 1836072691(%ebx,%edi,1),%ebx - subl %ecx, %esi - roll $15, %ebx - addl %eax, %ebx - /* 115 */ - movl 16(%esp), %edi - orl %ebx, %esi - addl %edi, %eax - xorl %edx, %esi - movl $-1, %edi - roll $10, %ecx - leal 1836072691(%eax,%esi,1),%eax - subl %ebx, %edi - roll $11, %eax - addl %ebp, %eax - /* 116 */ - movl 32(%esp), %esi - orl %eax, %edi - addl %esi, %ebp - xorl %ecx, %edi - movl $-1, %esi - roll $10, %ebx - leal 1836072691(%ebp,%edi,1),%ebp - subl %eax, %esi - roll $8, %ebp - addl %edx, %ebp - /* 117 */ - movl 60(%esp), %edi - orl %ebp, %esi - addl %edi, %edx - xorl %ebx, %esi - movl $-1, %edi - roll $10, %eax - leal 1836072691(%edx,%esi,1),%edx - subl %ebp, %edi - roll $6, %edx - addl %ecx, %edx - /* 118 */ - movl 28(%esp), %esi - orl %edx, %edi - addl %esi, %ecx - xorl %eax, %edi - movl $-1, %esi - roll $10, %ebp - leal 1836072691(%ecx,%edi,1),%ecx - subl %edx, %esi - roll $6, %ecx - addl %ebx, %ecx - /* 119 */ - movl 40(%esp), %edi - orl %ecx, %esi - addl %edi, %ebx - xorl %ebp, %esi - movl $-1, %edi - roll $10, %edx - leal 1836072691(%ebx,%esi,1),%ebx - subl %ecx, %edi - roll $14, %ebx - addl %eax, %ebx - /* 120 */ - movl 48(%esp), %esi - orl %ebx, %edi - addl %esi, %eax - xorl %edx, %edi - movl $-1, %esi - roll $10, %ecx - leal 1836072691(%eax,%edi,1),%eax - subl %ebx, %esi - roll $12, %eax - addl %ebp, %eax - /* 121 */ - movl 36(%esp), %edi - orl %eax, %esi - addl %edi, %ebp - xorl %ecx, %esi - movl $-1, %edi - roll $10, %ebx - leal 1836072691(%ebp,%esi,1),%ebp - subl %eax, %edi - roll $13, %ebp - addl %edx, %ebp - /* 122 */ - movl 52(%esp), %esi - orl %ebp, %edi - addl %esi, %edx - xorl %ebx, %edi - movl $-1, %esi - roll $10, %eax - leal 1836072691(%edx,%edi,1),%edx - subl %ebp, %esi - roll $5, %edx - addl %ecx, %edx - /* 123 */ - movl 12(%esp), %edi - orl %edx, %esi - addl %edi, %ecx - xorl %eax, %esi - movl $-1, %edi - roll $10, %ebp - leal 1836072691(%ecx,%esi,1),%ecx - subl %edx, %edi - roll $14, %ecx - addl %ebx, %ecx - /* 124 */ - movl 44(%esp), %esi - orl %ecx, %edi - addl %esi, %ebx - xorl %ebp, %edi - movl $-1, %esi - roll $10, %edx - leal 1836072691(%ebx,%edi,1),%ebx - subl %ecx, %esi - roll $13, %ebx - addl %eax, %ebx - /* 125 */ - movl 4(%esp), %edi - orl %ebx, %esi - addl %edi, %eax - xorl %edx, %esi - movl $-1, %edi - roll $10, %ecx - leal 1836072691(%eax,%esi,1),%eax - subl %ebx, %edi - roll $13, %eax - addl %ebp, %eax - /* 126 */ - movl 20(%esp), %esi - orl %eax, %edi - addl %esi, %ebp - xorl %ecx, %edi - movl $-1, %esi - roll $10, %ebx - leal 1836072691(%ebp,%edi,1),%ebp - subl %eax, %esi - roll $7, %ebp - addl %edx, %ebp - /* 127 */ - movl 56(%esp), %edi - orl %ebp, %esi - addl %edi, %edx - xorl %ebx, %esi - movl 36(%esp), %edi - roll $10, %eax - leal 1836072691(%edx,%esi,1),%edx - movl $-1, %esi - roll $5, %edx - addl %ecx, %edx - /* 128 */ - addl %edi, %ecx - movl %ebp, %edi - subl %edx, %esi - andl %edx, %edi - andl %eax, %esi - orl %esi, %edi - movl 28(%esp), %esi - roll $10, %ebp - leal 2053994217(%ecx,%edi,1),%ecx - movl $-1, %edi - roll $15, %ecx - addl %ebx, %ecx - /* 129 */ - addl %esi, %ebx - movl %edx, %esi - subl %ecx, %edi - andl %ecx, %esi - andl %ebp, %edi - orl %edi, %esi - movl 20(%esp), %edi - roll $10, %edx - leal 2053994217(%ebx,%esi,1),%ebx - movl $-1, %esi - roll $5, %ebx - addl %eax, %ebx - /* 130 */ - addl %edi, %eax - movl %ecx, %edi - subl %ebx, %esi - andl %ebx, %edi - andl %edx, %esi - orl %esi, %edi - movl 8(%esp), %esi - roll $10, %ecx - leal 2053994217(%eax,%edi,1),%eax - movl $-1, %edi - roll $8, %eax - addl %ebp, %eax - /* 131 */ - addl %esi, %ebp - movl %ebx, %esi - subl %eax, %edi - andl %eax, %esi - andl %ecx, %edi - orl %edi, %esi - movl 16(%esp), %edi - roll $10, %ebx - leal 2053994217(%ebp,%esi,1),%ebp - movl $-1, %esi - roll $11, %ebp - addl %edx, %ebp - /* 132 */ - addl %edi, %edx - movl %eax, %edi - subl %ebp, %esi - andl %ebp, %edi - andl %ebx, %esi - orl %esi, %edi - movl 48(%esp), %esi - roll $10, %eax - leal 2053994217(%edx,%edi,1),%edx - movl $-1, %edi - roll $14, %edx - addl %ecx, %edx - /* 133 */ - addl %esi, %ecx - movl %ebp, %esi - subl %edx, %edi - andl %edx, %esi - andl %eax, %edi - orl %edi, %esi - movl 64(%esp), %edi - roll $10, %ebp - leal 2053994217(%ecx,%esi,1),%ecx - movl $-1, %esi - roll $14, %ecx - addl %ebx, %ecx - /* 134 */ - addl %edi, %ebx - movl %edx, %edi - subl %ecx, %esi - andl %ecx, %edi - andl %ebp, %esi - orl %esi, %edi - movl 4(%esp), %esi - roll $10, %edx - leal 2053994217(%ebx,%edi,1),%ebx - movl $-1, %edi - roll $6, %ebx - addl %eax, %ebx - /* 135 */ - addl %esi, %eax - movl %ecx, %esi - subl %ebx, %edi - andl %ebx, %esi - andl %edx, %edi - orl %edi, %esi - movl 24(%esp), %edi - roll $10, %ecx - leal 2053994217(%eax,%esi,1),%eax - movl $-1, %esi - roll $14, %eax - addl %ebp, %eax - /* 136 */ - addl %edi, %ebp - movl %ebx, %edi - subl %eax, %esi - andl %eax, %edi - andl %ecx, %esi - orl %esi, %edi - movl 52(%esp), %esi - roll $10, %ebx - leal 2053994217(%ebp,%edi,1),%ebp - movl $-1, %edi - roll $6, %ebp - addl %edx, %ebp - /* 137 */ - addl %esi, %edx - movl %eax, %esi - subl %ebp, %edi - andl %ebp, %esi - andl %ebx, %edi - orl %edi, %esi - movl 12(%esp), %edi - roll $10, %eax - leal 2053994217(%edx,%esi,1),%edx - movl $-1, %esi - roll $9, %edx - addl %ecx, %edx - /* 138 */ - addl %edi, %ecx - movl %ebp, %edi - subl %edx, %esi - andl %edx, %edi - andl %eax, %esi - orl %esi, %edi - movl 56(%esp), %esi - roll $10, %ebp - leal 2053994217(%ecx,%edi,1),%ecx - movl $-1, %edi - roll $12, %ecx - addl %ebx, %ecx - /* 139 */ - addl %esi, %ebx - movl %edx, %esi - subl %ecx, %edi - andl %ecx, %esi - andl %ebp, %edi - orl %edi, %esi - movl 40(%esp), %edi - roll $10, %edx - leal 2053994217(%ebx,%esi,1),%ebx - movl $-1, %esi - roll $9, %ebx - addl %eax, %ebx - /* 140 */ - addl %edi, %eax - movl %ecx, %edi - subl %ebx, %esi - andl %ebx, %edi - andl %edx, %esi - orl %esi, %edi - movl 32(%esp), %esi - roll $10, %ecx - leal 2053994217(%eax,%edi,1),%eax - movl $-1, %edi - roll $12, %eax - addl %ebp, %eax - /* 141 */ - addl %esi, %ebp - movl %ebx, %esi - subl %eax, %edi - andl %eax, %esi - andl %ecx, %edi - orl %edi, %esi - movl 44(%esp), %edi - roll $10, %ebx - leal 2053994217(%ebp,%esi,1),%ebp - movl $-1, %esi - roll $5, %ebp - addl %edx, %ebp - /* 142 */ - addl %edi, %edx - movl %eax, %edi - subl %ebp, %esi - andl %ebp, %edi - andl %ebx, %esi - orl %esi, %edi - movl 60(%esp), %esi - roll $10, %eax - leal 2053994217(%edx,%edi,1),%edx - movl $-1, %edi - roll $15, %edx - addl %ecx, %edx - /* 143 */ - addl %esi, %ecx - movl %ebp, %esi - subl %edx, %edi - andl %edx, %esi - andl %eax, %edi - orl %esi, %edi - movl %edx, %esi - roll $10, %ebp - leal 2053994217(%ecx,%edi,1),%ecx - xorl %ebp, %esi - roll $8, %ecx - addl %ebx, %ecx - /* 144 */ - movl 52(%esp), %edi - xorl %ecx, %esi - addl %edi, %ebx - roll $10, %edx - addl %esi, %ebx - movl %ecx, %esi - roll $8, %ebx - addl %eax, %ebx - /* 145 */ - xorl %edx, %esi - movl 64(%esp), %edi - xorl %ebx, %esi - addl %esi, %eax - movl %ebx, %esi - roll $10, %ecx - addl %edi, %eax - xorl %ecx, %esi - roll $5, %eax - addl %ebp, %eax - /* 146 */ - movl 44(%esp), %edi - xorl %eax, %esi - addl %edi, %ebp - roll $10, %ebx - addl %esi, %ebp - movl %eax, %esi - roll $12, %ebp - addl %edx, %ebp - /* 147 */ - xorl %ebx, %esi - movl 20(%esp), %edi - xorl %ebp, %esi - addl %esi, %edx - movl %ebp, %esi - roll $10, %eax - addl %edi, %edx - xorl %eax, %esi - roll $9, %edx - addl %ecx, %edx - /* 148 */ - movl 8(%esp), %edi - xorl %edx, %esi - addl %edi, %ecx - roll $10, %ebp - addl %esi, %ecx - movl %edx, %esi - roll $12, %ecx - addl %ebx, %ecx - /* 149 */ - xorl %ebp, %esi - movl 24(%esp), %edi - xorl %ecx, %esi - addl %esi, %ebx - movl %ecx, %esi - roll $10, %edx - addl %edi, %ebx - xorl %edx, %esi - roll $5, %ebx - addl %eax, %ebx - /* 150 */ - movl 36(%esp), %edi - xorl %ebx, %esi - addl %edi, %eax - roll $10, %ecx - addl %esi, %eax - movl %ebx, %esi - roll $14, %eax - addl %ebp, %eax - /* 151 */ - xorl %ecx, %esi - movl 32(%esp), %edi - xorl %eax, %esi - addl %esi, %ebp - movl %eax, %esi - roll $10, %ebx - addl %edi, %ebp - xorl %ebx, %esi - roll $6, %ebp - addl %edx, %ebp - /* 152 */ - movl 28(%esp), %edi - xorl %ebp, %esi - addl %edi, %edx - roll $10, %eax - addl %esi, %edx - movl %ebp, %esi - roll $8, %edx - addl %ecx, %edx - /* 153 */ - xorl %eax, %esi - movl 12(%esp), %edi - xorl %edx, %esi - addl %esi, %ecx - movl %edx, %esi - roll $10, %ebp - addl %edi, %ecx - xorl %ebp, %esi - roll $13, %ecx - addl %ebx, %ecx - /* 154 */ - movl 56(%esp), %edi - xorl %ecx, %esi - addl %edi, %ebx - roll $10, %edx - addl %esi, %ebx - movl %ecx, %esi - roll $6, %ebx - addl %eax, %ebx - /* 155 */ - xorl %edx, %esi - movl 60(%esp), %edi - xorl %ebx, %esi - addl %esi, %eax - movl %ebx, %esi - roll $10, %ecx - addl %edi, %eax - xorl %ecx, %esi - roll $5, %eax - addl %ebp, %eax - /* 156 */ - movl 4(%esp), %edi - xorl %eax, %esi - addl %edi, %ebp - roll $10, %ebx - addl %esi, %ebp - movl %eax, %esi - roll $15, %ebp - addl %edx, %ebp - /* 157 */ - xorl %ebx, %esi - movl 16(%esp), %edi - xorl %ebp, %esi - addl %esi, %edx - movl %ebp, %esi - roll $10, %eax - addl %edi, %edx - xorl %eax, %esi - roll $13, %edx - addl %ecx, %edx - /* 158 */ - movl 40(%esp), %edi - xorl %edx, %esi - addl %edi, %ecx - roll $10, %ebp - addl %esi, %ecx - movl %edx, %esi - roll $11, %ecx - addl %ebx, %ecx - /* 159 */ - xorl %ebp, %esi - movl 48(%esp), %edi - xorl %ecx, %esi - addl %esi, %ebx - roll $10, %edx - addl %edi, %ebx - movl 108(%esp), %edi - roll $11, %ebx - addl %eax, %ebx - movl 4(%edi), %esi - addl %esi, %edx - movl 76(%esp), %esi - addl %esi, %edx - movl 8(%edi), %esi - addl %esi, %ebp - movl 80(%esp), %esi - addl %esi, %ebp - movl 12(%edi), %esi - addl %esi, %eax - movl 84(%esp), %esi - addl %esi, %eax - movl 16(%edi), %esi - addl %esi, %ebx - movl 68(%esp), %esi - addl %esi, %ebx - movl (%edi), %esi - addl %esi, %ecx - movl 72(%esp), %esi - addl %esi, %ecx - movl %edx, (%edi) - movl %ebp, 4(%edi) - movl %eax, 8(%edi) - movl %ebx, 12(%edi) - movl %ecx, 16(%edi) - movl (%esp), %edi - movl 112(%esp), %esi - cmpl %esi, %edi - movl 108(%esp), %edi - jge .L000start - addl $88, %esp - popl %ebx - popl %ebp - popl %edi - popl %esi - ret -.ripemd160_block_x86_end: - SIZE(ripemd160_block_x86,.ripemd160_block_x86_end-ripemd160_block_x86) -.ident "desasm.pl" diff --git a/src/lib/libcrypto/ripemd/asm/rmd-586.pl b/src/lib/libcrypto/ripemd/asm/rmd-586.pl index dc3f6c792e..e53c5fadba 100644 --- a/src/lib/libcrypto/ripemd/asm/rmd-586.pl +++ b/src/lib/libcrypto/ripemd/asm/rmd-586.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # Normal is the # ripemd160_block_x86(MD5_CTX *c, ULONG *X); @@ -530,7 +530,7 @@ sub ripemd160_block # &mov($tmp2, &wparam(0)); # Moved into last round &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B - &add($D, $tmp1); + &add($D, $tmp1); &mov($tmp1, &swtmp(1+18)); # $c &add($D, $tmp1); diff --git a/src/lib/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h index a3bc6e3ab2..ab76be4c33 100644 --- a/src/lib/libcrypto/ripemd/ripemd.h +++ b/src/lib/libcrypto/ripemd/ripemd.h @@ -63,6 +63,10 @@ extern "C" { #endif +#ifdef NO_RIPEMD +#error RIPEMD is disabled. +#endif + #define RIPEMD160_CBLOCK 64 #define RIPEMD160_LBLOCK 16 #define RIPEMD160_BLOCK 16 @@ -78,20 +82,11 @@ typedef struct RIPEMD160state_st int num; } RIPEMD160_CTX; -#ifndef NOPROTO void RIPEMD160_Init(RIPEMD160_CTX *c); void RIPEMD160_Update(RIPEMD160_CTX *c, unsigned char *data, unsigned long len); void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); unsigned char *RIPEMD160(unsigned char *d, unsigned long n, unsigned char *md); void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b); -#else -void RIPEMD160_Init(); -void RIPEMD160_Update(); -void RIPEMD160_Final(); -unsigned char *RIPEMD160(); -void RIPEMD160_Transform(); -#endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/ripemd/rmd160.c b/src/lib/libcrypto/ripemd/rmd160.c index 3fa1b8096e..4f8b88a18a 100644 --- a/src/lib/libcrypto/ripemd/rmd160.c +++ b/src/lib/libcrypto/ripemd/rmd160.c @@ -58,23 +58,17 @@ #include #include -#include "ripemd.h" +#include #define BUFSIZE 1024*16 -#ifndef NOPROTO void do_fp(FILE *f); void pt(unsigned char *md); +#ifndef _OSD_POSIX int read(int, void *, unsigned int); -#else -void do_fp(); -void pt(); -int read(); #endif -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int i,err=0; FILE *IN; @@ -102,8 +96,7 @@ char **argv; exit(err); } -void do_fp(f) -FILE *f; +void do_fp(FILE *f) { RIPEMD160_CTX c; unsigned char md[RIPEMD160_DIGEST_LENGTH]; @@ -123,8 +116,7 @@ FILE *f; pt(md); } -void pt(md) -unsigned char *md; +void pt(unsigned char *md) { int i; diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c index 210de1977d..b590856229 100644 --- a/src/lib/libcrypto/ripemd/rmd_dgst.c +++ b/src/lib/libcrypto/ripemd/rmd_dgst.c @@ -58,27 +58,17 @@ #include #include "rmd_locl.h" +#include -char *RMD160_version="RIPEMD160 part of SSLeay 0.9.0b 29-Jun-1998"; +char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT; -#ifndef NOPROTO # ifdef RMD160_ASM void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num); # define ripemd160_block ripemd160_block_x86 # else void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num); # endif -#else -# ifdef RMD160_ASM - void ripemd160_block_x86(); -# define ripemd160_block ripemd160_block_x86 -# else - static void ripemd160_block(); -# endif -#endif - -void RIPEMD160_Init(c) -RIPEMD160_CTX *c; +void RIPEMD160_Init(RIPEMD160_CTX *c) { c->A=RIPEMD160_A; c->B=RIPEMD160_B; @@ -90,10 +80,8 @@ RIPEMD160_CTX *c; c->num=0; } -void RIPEMD160_Update(c, data, len) -RIPEMD160_CTX *c; -register unsigned char *data; -unsigned long len; +void RIPEMD160_Update(RIPEMD160_CTX *c, register unsigned char *data, + unsigned long len) { register ULONG *p; int sw,sc; @@ -221,9 +209,7 @@ unsigned long len; } } -void RIPEMD160_Transform(c,b) -RIPEMD160_CTX *c; -unsigned char *b; +void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b) { ULONG p[16]; #if !defined(L_ENDIAN) @@ -260,10 +246,7 @@ unsigned char *b; #ifndef RMD160_ASM -void ripemd160_block(ctx, X, num) -RIPEMD160_CTX *ctx; -register ULONG *X; -int num; +void ripemd160_block(RIPEMD160_CTX *ctx, register ULONG *X, int num) { register ULONG A,B,C,D,E; ULONG a,b,c,d,e; @@ -460,9 +443,7 @@ int num; } #endif -void RIPEMD160_Final(md, c) -unsigned char *md; -RIPEMD160_CTX *c; +void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c) { register int i,j; register ULONG l; @@ -518,8 +499,7 @@ RIPEMD160_CTX *c; } #ifdef undef -int printit(l) -unsigned long *l; +int printit(unsigned long *l) { int i,ii; diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h index a1feccf7c1..d6ba02001a 100644 --- a/src/lib/libcrypto/ripemd/rmd_locl.h +++ b/src/lib/libcrypto/ripemd/rmd_locl.h @@ -58,16 +58,12 @@ #include #include -#include "ripemd.h" +#include #define ULONG unsigned long #define UCHAR unsigned char #define UINT unsigned int -#ifdef NOCONST -#define const -#endif - #undef c2nl #define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ l|=(((unsigned long)(*((c)++)))<<16), \ diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c index a7626dbcda..5b6ff14714 100644 --- a/src/lib/libcrypto/ripemd/rmd_one.c +++ b/src/lib/libcrypto/ripemd/rmd_one.c @@ -59,10 +59,8 @@ #include #include "rmd_locl.h" -unsigned char *RIPEMD160(d, n, md) -unsigned char *d; -unsigned long n; -unsigned char *md; +unsigned char *RIPEMD160(unsigned char *d, unsigned long n, + unsigned char *md) { RIPEMD160_CTX c; static unsigned char m[RIPEMD160_DIGEST_LENGTH]; diff --git a/src/lib/libcrypto/ripemd/rmdtest.c b/src/lib/libcrypto/ripemd/rmdtest.c index 6a0297f975..5e93d4627c 100644 --- a/src/lib/libcrypto/ripemd/rmdtest.c +++ b/src/lib/libcrypto/ripemd/rmdtest.c @@ -59,7 +59,19 @@ #include #include #include -#include "ripemd.h" + +#ifdef NO_RIPEMD +int main(int argc, char *argv[]) +{ + printf("No ripemd support\n"); + return(0); +} +#else +#include + +#ifdef CHARSET_EBCDIC +#include +#endif char *test[]={ "", @@ -84,15 +96,8 @@ char *ret[]={ "9b752e45573d4b39f4dbd3323cab82bf63326bfb", }; -#ifndef NOPROTO static char *pt(unsigned char *md); -#else -static char *pt(); -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,err=0; unsigned char **P,**R; @@ -103,6 +108,9 @@ char *argv[]; i=1; while (*P != NULL) { +#ifdef CHARSET_EBCDIC + ebcdic2ascii((char *)*P, (char *)*P, strlen((char *)*P)); +#endif p=pt(RIPEMD160(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL)); if (strcmp(p,(char *)*R) != 0) { @@ -120,8 +128,7 @@ char *argv[]; return(0); } -static char *pt(md) -unsigned char *md; +static char *pt(unsigned char *md) { int i; static char buf[80]; @@ -130,4 +137,4 @@ unsigned char *md; sprintf(&(buf[i*2]),"%02x",md[i]); return(buf); } - +#endif diff --git a/src/lib/libcrypto/rsa/Makefile.ssl b/src/lib/libcrypto/rsa/Makefile.ssl index d52f2e609e..da704fc558 100644 --- a/src/lib/libcrypto/rsa/Makefile.ssl +++ b/src/lib/libcrypto/rsa/Makefile.ssl @@ -7,25 +7,25 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=rsa -ERRC=rsa_err GENERAL=Makefile -TEST= +TEST=rsa_oaep_test.c APPS= LIB=$(TOP)/libcrypto.a -LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c $(ERRC).c \ - rsa_pk1.c rsa_ssl.c rsa_none.c -LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o $(ERRC).o \ - rsa_pk1.o rsa_ssl.o rsa_none.o +LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \ + rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c +LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \ + rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o SRC= $(LIBSRC) @@ -41,24 +41,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -70,17 +69,104 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +rsa_chk.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h +rsa_chk.o: ../../include/openssl/stack.h +rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +rsa_eay.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_eay.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +rsa_eay.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h +rsa_eay.o: ../cryptlib.h +rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h +rsa_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h +rsa_err.o: ../../include/openssl/stack.h +rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +rsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h +rsa_gen.o: ../../include/openssl/stack.h ../cryptlib.h +rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +rsa_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h +rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h +rsa_lib.o: ../cryptlib.h +rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +rsa_none.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_none.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +rsa_none.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h +rsa_none.o: ../cryptlib.h +rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +rsa_oaep.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +rsa_oaep.o: ../../include/openssl/rsa.h ../../include/openssl/sha.h +rsa_oaep.o: ../../include/openssl/stack.h ../cryptlib.h +rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +rsa_pk1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_pk1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +rsa_pk1.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h +rsa_pk1.o: ../cryptlib.h +rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +rsa_saos.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +rsa_saos.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +rsa_saos.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h +rsa_saos.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +rsa_saos.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +rsa_saos.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +rsa_saos.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +rsa_saos.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +rsa_saos.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +rsa_saos.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +rsa_saos.o: ../cryptlib.h +rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +rsa_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +rsa_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +rsa_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h +rsa_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +rsa_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +rsa_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +rsa_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +rsa_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +rsa_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +rsa_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +rsa_sign.o: ../cryptlib.h +rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h +rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h +rsa_ssl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +rsa_ssl.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h +rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h +rsa_ssl.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h +rsa_ssl.o: ../cryptlib.h diff --git a/src/lib/libcrypto/rsa/rsa.err b/src/lib/libcrypto/rsa/rsa.err deleted file mode 100644 index 5ded1b5fa2..0000000000 --- a/src/lib/libcrypto/rsa/rsa.err +++ /dev/null @@ -1,45 +0,0 @@ -/* Error codes for the RSA functions. */ - -/* Function codes. */ -#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 100 -#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 101 -#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 102 -#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 103 -#define RSA_F_RSA_GENERATE_KEY 104 -#define RSA_F_RSA_NEW_METHOD 105 -#define RSA_F_RSA_PADDING_ADD_NONE 106 -#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 107 -#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 108 -#define RSA_F_RSA_PADDING_ADD_SSLV23 109 -#define RSA_F_RSA_PADDING_CHECK_NONE 110 -#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 111 -#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 112 -#define RSA_F_RSA_PADDING_CHECK_SSLV23 113 -#define RSA_F_RSA_PRINT 114 -#define RSA_F_RSA_PRINT_FP 115 -#define RSA_F_RSA_SIGN 116 -#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 117 -#define RSA_F_RSA_VERIFY 118 -#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 119 - -/* Reason codes. */ -#define RSA_R_ALGORITHM_MISMATCH 100 -#define RSA_R_BAD_E_VALUE 101 -#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 -#define RSA_R_BAD_PAD_BYTE_COUNT 103 -#define RSA_R_BAD_SIGNATURE 104 -#define RSA_R_BAD_ZERO_BYTE 105 -#define RSA_R_BLOCK_TYPE_IS_NOT_01 106 -#define RSA_R_BLOCK_TYPE_IS_NOT_02 107 -#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 -#define RSA_R_DATA_TOO_LARGE 109 -#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 -#define RSA_R_DATA_TOO_SMALL 111 -#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 -#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 -#define RSA_R_PADDING_CHECK_FAILED 114 -#define RSA_R_SSLV3_ROLLBACK_ATTACK 115 -#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 -#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 -#define RSA_R_UNKNOWN_PADDING_TYPE 118 -#define RSA_R_WRONG_SIGNATURE_LENGTH 119 diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h index aeb78ffcd3..9230b2fcc9 100644 --- a/src/lib/libcrypto/rsa/rsa.h +++ b/src/lib/libcrypto/rsa/rsa.h @@ -63,26 +63,37 @@ extern "C" { #endif -#include "bn.h" -#include "crypto.h" +#include +#include + +#ifdef NO_RSA +#error RSA is disabled. +#endif + +typedef struct rsa_st RSA; typedef struct rsa_meth_st { - char *name; - int (*rsa_pub_enc)(); - int (*rsa_pub_dec)(); - int (*rsa_priv_enc)(); - int (*rsa_priv_dec)(); - int (*rsa_mod_exp)(); /* Can be null */ - int (*bn_mod_exp)(); /* Can be null */ - int (*init)(/* RSA * */); /* called at new */ - int (*finish)(/* RSA * */); /* called at free */ - + const char *name; + int (*rsa_pub_enc)(int flen,unsigned char *from,unsigned char *to, + RSA *rsa,int padding); + int (*rsa_pub_dec)(int flen,unsigned char *from,unsigned char *to, + RSA *rsa,int padding); + int (*rsa_priv_enc)(int flen,unsigned char *from,unsigned char *to, + RSA *rsa,int padding); + int (*rsa_priv_dec)(int flen,unsigned char *from,unsigned char *to, + RSA *rsa,int padding); + int (*rsa_mod_exp)(BIGNUM *r0,BIGNUM *I,RSA *rsa); /* Can be null */ + int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p, + const BIGNUM *m, BN_CTX *ctx, + BN_MONT_CTX *m_ctx); /* Can be null */ + int (*init)(RSA *rsa); /* called at new */ + int (*finish)(RSA *rsa); /* called at free */ int flags; /* RSA_METHOD_FLAG_* things */ char *app_data; /* may be needed! */ } RSA_METHOD; -typedef struct rsa_st +struct rsa_st { /* The first parameter is used to pickup errors where * this is passed instead of aEVP_PKEY, it is set to 0 */ @@ -97,41 +108,52 @@ typedef struct rsa_st BIGNUM *dmp1; BIGNUM *dmq1; BIGNUM *iqmp; - /* be carefull using this if the RSA structure is shared */ + /* be careful using this if the RSA structure is shared */ CRYPTO_EX_DATA ex_data; int references; int flags; - /* Normally used to cached montgomery values */ - char *method_mod_n; - char *method_mod_p; - char *method_mod_q; + /* Used to cache montgomery values */ + BN_MONT_CTX *_method_mod_n; + BN_MONT_CTX *_method_mod_p; + BN_MONT_CTX *_method_mod_q; + /* all BIGNUM values are actually in the following data, if it is not + * NULL */ + char *bignum_data; BN_BLINDING *blinding; - } RSA; + }; #define RSA_3 0x3L #define RSA_F4 0x10001L #define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */ + #define RSA_FLAG_CACHE_PUBLIC 0x02 #define RSA_FLAG_CACHE_PRIVATE 0x04 #define RSA_FLAG_BLINDING 0x08 #define RSA_FLAG_THREAD_SAFE 0x10 +/* This flag means the private key operations will be handled by rsa_mod_exp + * and that they do not depend on the private key components being present: + * for example a key stored in external hardware. Without this flag bn_mod_exp + * gets called when private key components are absent. + */ +#define RSA_FLAG_EXT_PKEY 0x20 #define RSA_PKCS1_PADDING 1 #define RSA_SSLV23_PADDING 2 #define RSA_NO_PADDING 3 +#define RSA_PKCS1_OAEP_PADDING 4 #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg) #define RSA_get_app_data(s) RSA_get_ex_data(s,0) -#ifndef NOPROTO RSA * RSA_new(void); RSA * RSA_new_method(RSA_METHOD *method); int RSA_size(RSA *); RSA * RSA_generate_key(int bits, unsigned long e,void - (*callback)(int,int,char *),char *cb_arg); + (*callback)(int,int,void *),void *cb_arg); +int RSA_check_key(RSA *); /* next 4 return -1 on error */ int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa,int padding); @@ -146,6 +168,12 @@ void RSA_free (RSA *r); int RSA_flags(RSA *r); void RSA_set_default_method(RSA_METHOD *meth); +RSA_METHOD *RSA_get_default_method(void); +RSA_METHOD *RSA_get_method(RSA *rsa); +RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth); + +/* This function needs the memory locking malloc callbacks to be installed */ +int RSA_memory_lock(RSA *r); /* If you have RSAref compiled in. */ RSA_METHOD *RSA_PKCS1_RSAref(void); @@ -193,107 +221,63 @@ void RSA_blinding_off(RSA *rsa); int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, unsigned char *f,int fl); int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen, - unsigned char *f,int fl); + unsigned char *f,int fl,int rsa_len); int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, unsigned char *f,int fl); int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, - unsigned char *f,int fl); + unsigned char *f,int fl,int rsa_len); +int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen, + unsigned char *f,int fl,unsigned char *p, + int pl); +int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen, + unsigned char *f,int fl,int rsa_len, + unsigned char *p,int pl); int RSA_padding_add_SSLv23(unsigned char *to,int tlen, unsigned char *f,int fl); int RSA_padding_check_SSLv23(unsigned char *to,int tlen, - unsigned char *f,int fl); + unsigned char *f,int fl,int rsa_len); int RSA_padding_add_none(unsigned char *to,int tlen, unsigned char *f,int fl); int RSA_padding_check_none(unsigned char *to,int tlen, - unsigned char *f,int fl); + unsigned char *f,int fl,int rsa_len); int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), int (*dup_func)(), void (*free_func)()); int RSA_set_ex_data(RSA *r,int idx,char *arg); char *RSA_get_ex_data(RSA *r, int idx); -#else - -RSA * RSA_new(); -RSA * RSA_new_method(); -int RSA_size(); -RSA * RSA_generate_key(); -int RSA_public_encrypt(); -int RSA_private_encrypt(); -int RSA_public_decrypt(); -int RSA_private_decrypt(); -void RSA_free (); - -int RSA_flags(); - -void RSA_set_default_method(); - -/* RSA_METHOD *RSA_PKCS1_RSAref(); */ -RSA_METHOD *RSA_PKCS1_SSLeay(); - -void ERR_load_RSA_strings(); - -RSA * d2i_RSAPublicKey(); -int i2d_RSAPublicKey(); -RSA * d2i_RSAPrivateKey(); -int i2d_RSAPrivateKey(); -#ifndef NO_FP_API -int RSA_print_fp(); -#endif - -int RSA_print(); - -int i2d_Netscape_RSA(); -RSA *d2i_Netscape_RSA(); -RSA *d2i_Netscape_RSA_2(); - -int RSA_sign(); -int RSA_verify(); - -int RSA_sign_ASN1_OCTET_STRING(); -int RSA_verify_ASN1_OCTET_STRING(); -int RSA_blinding_on(); -void RSA_blinding_off(); - -int RSA_padding_add_PKCS1_type_1(); -int RSA_padding_check_PKCS1_type_1(); -int RSA_padding_add_PKCS1_type_2(); -int RSA_padding_check_PKCS1_type_2(); -int RSA_padding_add_SSLv23(); -int RSA_padding_check_SSLv23(); -int RSA_padding_add_none(); -int RSA_padding_check_none(); - -int RSA_get_ex_new_index(); -int RSA_set_ex_data(); -char *RSA_get_ex_data(); - -#endif - /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the RSA functions. */ /* Function codes. */ -#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 100 -#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 101 -#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 102 -#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 103 -#define RSA_F_RSA_GENERATE_KEY 104 -#define RSA_F_RSA_NEW_METHOD 105 -#define RSA_F_RSA_PADDING_ADD_NONE 106 -#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 107 -#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 108 -#define RSA_F_RSA_PADDING_ADD_SSLV23 109 -#define RSA_F_RSA_PADDING_CHECK_NONE 110 -#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 111 -#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 112 -#define RSA_F_RSA_PADDING_CHECK_SSLV23 113 -#define RSA_F_RSA_PRINT 114 -#define RSA_F_RSA_PRINT_FP 115 -#define RSA_F_RSA_SIGN 116 -#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 117 -#define RSA_F_RSA_VERIFY 118 -#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 119 +#define RSA_F_MEMORY_LOCK 100 +#define RSA_F_RSA_CHECK_KEY 123 +#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101 +#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102 +#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103 +#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104 +#define RSA_F_RSA_GENERATE_KEY 105 +#define RSA_F_RSA_NEW_METHOD 106 +#define RSA_F_RSA_PADDING_ADD_NONE 107 +#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 +#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108 +#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109 +#define RSA_F_RSA_PADDING_ADD_SSLV23 110 +#define RSA_F_RSA_PADDING_CHECK_NONE 111 +#define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122 +#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112 +#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113 +#define RSA_F_RSA_PADDING_CHECK_SSLV23 114 +#define RSA_F_RSA_PRINT 115 +#define RSA_F_RSA_PRINT_FP 116 +#define RSA_F_RSA_SIGN 117 +#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 +#define RSA_F_RSA_VERIFY 119 +#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120 /* Reason codes. */ #define RSA_R_ALGORITHM_MISMATCH 100 @@ -301,22 +285,31 @@ char *RSA_get_ex_data(); #define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 #define RSA_R_BAD_PAD_BYTE_COUNT 103 #define RSA_R_BAD_SIGNATURE 104 -#define RSA_R_BAD_ZERO_BYTE 105 #define RSA_R_BLOCK_TYPE_IS_NOT_01 106 #define RSA_R_BLOCK_TYPE_IS_NOT_02 107 #define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 #define RSA_R_DATA_TOO_LARGE 109 #define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 #define RSA_R_DATA_TOO_SMALL 111 +#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122 +#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123 #define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 +#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124 +#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125 +#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126 +#define RSA_R_KEY_SIZE_TOO_SMALL 120 #define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 +#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 +#define RSA_R_OAEP_DECODING_ERROR 121 #define RSA_R_PADDING_CHECK_FAILED 114 +#define RSA_R_P_NOT_PRIME 128 +#define RSA_R_Q_NOT_PRIME 129 #define RSA_R_SSLV3_ROLLBACK_ATTACK 115 #define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 #define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 #define RSA_R_UNKNOWN_PADDING_TYPE 118 #define RSA_R_WRONG_SIGNATURE_LENGTH 119 - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c new file mode 100644 index 0000000000..91b9115798 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_chk.c @@ -0,0 +1,184 @@ +/* crypto/rsa/rsa_chk.c -*- Mode: C; c-file-style: "eay" -*- */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + */ + +#include +#include +#include + + +int RSA_check_key(RSA *key) + { + BIGNUM *i, *j, *k, *l, *m; + BN_CTX *ctx; + int r; + int ret=1; + + i = BN_new(); + j = BN_new(); + k = BN_new(); + l = BN_new(); + m = BN_new(); + ctx = BN_CTX_new(); + if (i == NULL || j == NULL || k == NULL || l == NULL || + m == NULL || ctx == NULL) + { + ret = -1; + RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE); + goto err; + } + + /* p prime? */ + r = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL); + if (r != 1) + { + ret = r; + if (r != 0) + goto err; + RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME); + } + + /* q prime? */ + r = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL); + if (r != 1) + { + ret = r; + if (r != 0) + goto err; + RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME); + } + + /* n = p*q? */ + r = BN_mul(i, key->p, key->q, ctx); + if (!r) { ret = -1; goto err; } + + if (BN_cmp(i, key->n) != 0) + { + ret = 0; + RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q); + } + + /* d*e = 1 mod lcm(p-1,q-1)? */ + + r = BN_sub(i, key->p, BN_value_one()); + if (!r) { ret = -1; goto err; } + r = BN_sub(j, key->q, BN_value_one()); + if (!r) { ret = -1; goto err; } + + /* now compute k = lcm(i,j) */ + r = BN_mul(l, i, j, ctx); + if (!r) { ret = -1; goto err; } + r = BN_gcd(m, i, j, ctx); + if (!r) { ret = -1; goto err; } + r = BN_div(k, NULL, l, m, ctx); /* remainder is 0 */ + if (!r) { ret = -1; goto err; } + + r = BN_mod_mul(i, key->d, key->e, k, ctx); + if (!r) { ret = -1; goto err; } + + if (!BN_is_one(i)) + { + ret = 0; + RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1); + } + + if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) + { + /* dmp1 = d mod (p-1)? */ + r = BN_sub(i, key->p, BN_value_one()); + if (!r) { ret = -1; goto err; } + + r = BN_mod(j, key->d, i, ctx); + if (!r) { ret = -1; goto err; } + + if (BN_cmp(j, key->dmp1) != 0) + { + ret = 0; + RSAerr(RSA_F_RSA_CHECK_KEY, + RSA_R_DMP1_NOT_CONGRUENT_TO_D); + } + + /* dmq1 = d mod (q-1)? */ + r = BN_sub(i, key->q, BN_value_one()); + if (!r) { ret = -1; goto err; } + + r = BN_mod(j, key->d, i, ctx); + if (!r) { ret = -1; goto err; } + + if (BN_cmp(j, key->dmq1) != 0) + { + ret = 0; + RSAerr(RSA_F_RSA_CHECK_KEY, + RSA_R_DMQ1_NOT_CONGRUENT_TO_D); + } + + /* iqmp = q^-1 mod p? */ + if(!BN_mod_inverse(i, key->q, key->p, ctx)) + { + ret = -1; + goto err; + } + + if (BN_cmp(i, key->iqmp) != 0) + { + ret = 0; + RSAerr(RSA_F_RSA_CHECK_KEY, + RSA_R_IQMP_NOT_INVERSE_OF_Q); + } + } + + err: + if (i != NULL) BN_free(i); + if (j != NULL) BN_free(j); + if (k != NULL) BN_free(k); + if (l != NULL) BN_free(l); + if (m != NULL) BN_free(m); + if (ctx != NULL) BN_CTX_free(ctx); + return (ret); + } diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c index 42a77f11cd..776324860c 100644 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ b/src/lib/libcrypto/rsa/rsa_eay.c @@ -68,11 +68,10 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "rand.h" +#include +#include +#include -#ifndef NOPROTO static int RSA_eay_public_encrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa,int padding); static int RSA_eay_private_encrypt(int flen, unsigned char *from, @@ -84,16 +83,6 @@ static int RSA_eay_private_decrypt(int flen, unsigned char *from, static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa); static int RSA_eay_init(RSA *rsa); static int RSA_eay_finish(RSA *rsa); -#else -static int RSA_eay_public_encrypt(); -static int RSA_eay_private_encrypt(); -static int RSA_eay_public_decrypt(); -static int RSA_eay_private_decrypt(); -static int RSA_eay_mod_exp(); -static int RSA_eay_init(); -static int RSA_eay_finish(); -#endif - static RSA_METHOD rsa_pkcs1_eay_meth={ "Eric Young's PKCS#1 RSA", RSA_eay_public_encrypt, @@ -108,31 +97,75 @@ static RSA_METHOD rsa_pkcs1_eay_meth={ NULL, }; -RSA_METHOD *RSA_PKCS1_SSLeay() +RSA_METHOD *RSA_PKCS1_SSLeay(void) { return(&rsa_pkcs1_eay_meth); } -static int RSA_eay_public_encrypt(flen, from, to, rsa, padding) -int flen; -unsigned char *from; -unsigned char *to; -RSA *rsa; -int padding; +static int RSA_eay_public_encrypt(int flen, unsigned char *from, + unsigned char *to, RSA *rsa, int padding) { - BIGNUM *f=NULL,*ret=NULL; + BIGNUM f,ret; int i,j,k,num=0,r= -1; unsigned char *buf=NULL; BN_CTX *ctx=NULL; - /* Body of this routine removed for OpenBSD - will return - * when the RSA patent expires - */ + BN_init(&f); + BN_init(&ret); + if ((ctx=BN_CTX_new()) == NULL) goto err; + num=BN_num_bytes(rsa->n); + if ((buf=(unsigned char *)Malloc(num)) == NULL) + { + RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE); + goto err; + } + + switch (padding) + { + case RSA_PKCS1_PADDING: + i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen); + break; +#ifndef NO_SHA + case RSA_PKCS1_OAEP_PADDING: + i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0); + break; +#endif + case RSA_SSLV23_PADDING: + i=RSA_padding_add_SSLv23(buf,num,from,flen); + break; + case RSA_NO_PADDING: + i=RSA_padding_add_none(buf,num,from,flen); + break; + default: + RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE); + goto err; + } + if (i <= 0) goto err; + + if (BN_bin2bn(buf,num,&f) == NULL) goto err; + + if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) + { + if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL) + if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx)) + goto err; + } + + if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, + rsa->_method_mod_n)) goto err; + /* put in leading 0 bytes if the number is less than the + * length of the modulus */ + j=BN_num_bytes(&ret); + i=BN_bn2bin(&ret,&(to[num-j])); + for (k=0; k<(num-i); k++) + to[k]=0; + + r=num; err: if (ctx != NULL) BN_CTX_free(ctx); - if (f != NULL) BN_free(f); - if (ret != NULL) BN_free(ret); + BN_clear_free(&f); + BN_clear_free(&ret); if (buf != NULL) { memset(buf,0,num); @@ -141,14 +174,10 @@ err: return(r); } -static int RSA_eay_private_encrypt(flen, from, to, rsa, padding) -int flen; -unsigned char *from; -unsigned char *to; -RSA *rsa; -int padding; +static int RSA_eay_private_encrypt(int flen, unsigned char *from, + unsigned char *to, RSA *rsa, int padding) { - BIGNUM *f=NULL,*ret=NULL; + BIGNUM f,ret; int i,j,k,num=0,r= -1; unsigned char *buf=NULL; BN_CTX *ctx=NULL; @@ -159,8 +188,8 @@ int padding; err: if (ctx != NULL) BN_CTX_free(ctx); - if (ret != NULL) BN_free(ret); - if (f != NULL) BN_free(f); + BN_clear_free(&ret); + BN_clear_free(&f); if (buf != NULL) { memset(buf,0,num); @@ -169,14 +198,10 @@ err: return(r); } -static int RSA_eay_private_decrypt(flen, from, to, rsa,padding) -int flen; -unsigned char *from; -unsigned char *to; -RSA *rsa; -int padding; +static int RSA_eay_private_decrypt(int flen, unsigned char *from, + unsigned char *to, RSA *rsa, int padding) { - BIGNUM *f=NULL,*ret=NULL; + BIGNUM f,ret; int j,num=0,r= -1; unsigned char *p; unsigned char *buf=NULL; @@ -188,8 +213,8 @@ int padding; err: if (ctx != NULL) BN_CTX_free(ctx); - if (f != NULL) BN_free(f); - if (ret != NULL) BN_free(ret); + BN_clear_free(&f); + BN_clear_free(&ret); if (buf != NULL) { memset(buf,0,num); @@ -198,28 +223,23 @@ err: return(r); } -static int RSA_eay_public_decrypt(flen, from, to, rsa, padding) -int flen; -unsigned char *from; -unsigned char *to; -RSA *rsa; -int padding; +static int RSA_eay_public_decrypt(int flen, unsigned char *from, + unsigned char *to, RSA *rsa, int padding) { - BIGNUM *f=NULL,*ret=NULL; + BIGNUM f,ret; int i,num=0,r= -1; unsigned char *p; unsigned char *buf=NULL; BN_CTX *ctx=NULL; - /* Body of this routine removed for OpenBSD - will return * when the RSA patent expires */ err: if (ctx != NULL) BN_CTX_free(ctx); - if (f != NULL) BN_free(f); - if (ret != NULL) BN_free(ret); + BN_clear_free(&f); + BN_clear_free(&ret); if (buf != NULL) { memset(buf,0,num); @@ -228,46 +248,40 @@ err: return(r); } -static int RSA_eay_mod_exp(r0, I, rsa) -BIGNUM *r0; -BIGNUM *I; -RSA *rsa; +static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa) { - BIGNUM *r1=NULL,*m1=NULL; + BIGNUM r1,m1; int ret=0; BN_CTX *ctx; if ((ctx=BN_CTX_new()) == NULL) goto err; - m1=BN_new(); - r1=BN_new(); - if ((m1 == NULL) || (r1 == NULL)) goto err; + BN_init(&m1); + BN_init(&r1); /* Body of this routine removed for OpenBSD - will return * when the RSA patent expires */ err: - if (m1 != NULL) BN_free(m1); - if (r1 != NULL) BN_free(r1); + BN_clear_free(&m1); + BN_clear_free(&r1); BN_CTX_free(ctx); return(ret); } -static int RSA_eay_init(rsa) -RSA *rsa; +static int RSA_eay_init(RSA *rsa) { rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE; return(1); } -static int RSA_eay_finish(rsa) -RSA *rsa; +static int RSA_eay_finish(RSA *rsa) { - if (rsa->method_mod_n != NULL) - BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_n); - if (rsa->method_mod_p != NULL) - BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_p); - if (rsa->method_mod_q != NULL) - BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_q); + if (rsa->_method_mod_n != NULL) + BN_MONT_CTX_free(rsa->_method_mod_n); + if (rsa->_method_mod_p != NULL) + BN_MONT_CTX_free(rsa->_method_mod_p); + if (rsa->_method_mod_q != NULL) + BN_MONT_CTX_free(rsa->_method_mod_q); return(1); } diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c index 796b3afd47..9fb15e398d 100644 --- a/src/lib/libcrypto/rsa/rsa_err.c +++ b/src/lib/libcrypto/rsa/rsa_err.c @@ -1,68 +1,72 @@ -/* lib/rsa/rsa_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/rsa/rsa_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "rsa.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR static ERR_STRING_DATA RSA_str_functs[]= { +{ERR_PACK(0,RSA_F_MEMORY_LOCK,0), "MEMORY_LOCK"}, +{ERR_PACK(0,RSA_F_RSA_CHECK_KEY,0), "RSA_check_key"}, {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"}, {ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"}, {ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"}, @@ -70,10 +74,12 @@ static ERR_STRING_DATA RSA_str_functs[]= {ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"}, {ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"}, {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"}, +{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"}, {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"}, {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"}, {ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"}, {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"}, +{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,0), "RSA_padding_check_PKCS1_OAEP"}, {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"}, {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"}, {ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"}, @@ -83,7 +89,7 @@ static ERR_STRING_DATA RSA_str_functs[]= {ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"}, {ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"}, {ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"}, -{0,NULL}, +{0,NULL} }; static ERR_STRING_DATA RSA_str_reasons[]= @@ -93,32 +99,41 @@ static ERR_STRING_DATA RSA_str_reasons[]= {RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"}, {RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"}, {RSA_R_BAD_SIGNATURE ,"bad signature"}, -{RSA_R_BAD_ZERO_BYTE ,"bad zero byte"}, {RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"}, {RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"}, {RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"}, {RSA_R_DATA_TOO_LARGE ,"data too large"}, {RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, {RSA_R_DATA_TOO_SMALL ,"data too small"}, +{RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"}, +{RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"}, {RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"}, +{RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"}, +{RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"}, +{RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"}, +{RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"}, {RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"}, +{RSA_R_N_DOES_NOT_EQUAL_P_Q ,"n does not equal p q"}, +{RSA_R_OAEP_DECODING_ERROR ,"oaep decoding error"}, {RSA_R_PADDING_CHECK_FAILED ,"padding check failed"}, +{RSA_R_P_NOT_PRIME ,"p not prime"}, +{RSA_R_Q_NOT_PRIME ,"q not prime"}, {RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"}, {RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, {RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, {RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"}, {RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_RSA_strings() +void ERR_load_RSA_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_RSA,RSA_str_functs); diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c index 4cbd373829..3227dba794 100644 --- a/src/lib/libcrypto/rsa/rsa_gen.c +++ b/src/lib/libcrypto/rsa/rsa_gen.c @@ -59,18 +59,15 @@ #include #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" +#include +#include -RSA *RSA_generate_key(bits, e_value, callback,cb_arg) -int bits; -unsigned long e_value; -void (*callback)(P_I_I_P); -char *cb_arg; +RSA *RSA_generate_key(int bits, unsigned long e_value, + void (*callback)(int,int,void *), void *cb_arg) { RSA *rsa=NULL; BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp; - int bitsp,bitsq,ok= -1,n=0; + int bitsp,bitsq,ok= -1,n=0,i; BN_CTX *ctx=NULL,*ctx2=NULL; ctx=BN_CTX_new(); @@ -81,6 +78,7 @@ char *cb_arg; /* Body of this routine removed for OpenBSD - will return * when the RSA patent expires */ + err: if (ok == -1) { diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c index 95a56f8a28..c0ca2923a6 100644 --- a/src/lib/libcrypto/rsa/rsa_lib.c +++ b/src/lib/libcrypto/rsa/rsa_lib.c @@ -57,31 +57,49 @@ */ #include -#include "crypto.h" +#include #include "cryptlib.h" -#include "lhash.h" -#include "bn.h" -#include "rsa.h" +#include +#include +#include -char *RSA_version="RSA part of SSLeay 0.9.0b 29-Jun-1998"; +const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT; static RSA_METHOD *default_RSA_meth=NULL; static int rsa_meth_num=0; static STACK *rsa_meth=NULL; -RSA *RSA_new() +RSA *RSA_new(void) { return(RSA_new_method(NULL)); } -void RSA_set_default_method(meth) -RSA_METHOD *meth; +void RSA_set_default_method(RSA_METHOD *meth) { default_RSA_meth=meth; } -RSA *RSA_new_method(meth) -RSA_METHOD *meth; +RSA_METHOD *RSA_get_default_method(void) +{ + return default_RSA_meth; +} + +RSA_METHOD *RSA_get_method(RSA *rsa) +{ + return rsa->meth; +} + +RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth) +{ + RSA_METHOD *mtmp; + mtmp = rsa->meth; + if (mtmp->finish) mtmp->finish(rsa); + rsa->meth = meth; + if (meth->init) meth->init(rsa); + return mtmp; +} + +RSA *RSA_new_method(RSA_METHOD *meth) { RSA *ret; @@ -116,22 +134,23 @@ RSA_METHOD *meth; ret->dmq1=NULL; ret->iqmp=NULL; ret->references=1; - ret->method_mod_n=NULL; - ret->method_mod_p=NULL; - ret->method_mod_q=NULL; + ret->_method_mod_n=NULL; + ret->_method_mod_p=NULL; + ret->_method_mod_q=NULL; ret->blinding=NULL; + ret->bignum_data=NULL; ret->flags=ret->meth->flags; if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { Free(ret); ret=NULL; } - CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data); + else + CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data); return(ret); } -void RSA_free(r) -RSA *r; +void RSA_free(RSA *r) { int i; @@ -164,90 +183,63 @@ RSA *r; if (r->dmq1 != NULL) BN_clear_free(r->dmq1); if (r->iqmp != NULL) BN_clear_free(r->iqmp); if (r->blinding != NULL) BN_BLINDING_free(r->blinding); + if (r->bignum_data != NULL) Free_locked(r->bignum_data); Free(r); } -int RSA_get_ex_new_index(argl,argp,new_func,dup_func,free_func) -long argl; -char *argp; -int (*new_func)(); -int (*dup_func)(); -void (*free_func)(); +int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), + int (*dup_func)(), void (*free_func)()) { rsa_meth_num++; return(CRYPTO_get_ex_new_index(rsa_meth_num-1, &rsa_meth,argl,argp,new_func,dup_func,free_func)); } -int RSA_set_ex_data(r,idx,arg) -RSA *r; -int idx; -char *arg; +int RSA_set_ex_data(RSA *r, int idx, char *arg) { return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); } -char *RSA_get_ex_data(r,idx) -RSA *r; -int idx; +char *RSA_get_ex_data(RSA *r, int idx) { return(CRYPTO_get_ex_data(&r->ex_data,idx)); } -int RSA_size(r) -RSA *r; +int RSA_size(RSA *r) { return(BN_num_bytes(r->n)); } -int RSA_public_encrypt(flen, from, to, rsa, padding) -int flen; -unsigned char *from; -unsigned char *to; -RSA *rsa; -int padding; +int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to, + RSA *rsa, int padding) { return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding)); } -int RSA_private_encrypt(flen, from, to, rsa, padding) -int flen; -unsigned char *from; -unsigned char *to; -RSA *rsa; -int padding; +int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to, + RSA *rsa, int padding) { return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding)); } -int RSA_private_decrypt(flen, from, to, rsa, padding) -int flen; -unsigned char *from; -unsigned char *to; -RSA *rsa; -int padding; +int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to, + RSA *rsa, int padding) { return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding)); } -int RSA_public_decrypt(flen, from, to, rsa, padding) -int flen; -unsigned char *from; -unsigned char *to; -RSA *rsa; -int padding; +int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to, + RSA *rsa, int padding) { return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding)); } -int RSA_flags(r) -RSA *r; +int RSA_flags(RSA *r) { return((r == NULL)?0:r->meth->flags); } -void RSA_blinding_off(rsa) -RSA *rsa; +void RSA_blinding_off(RSA *rsa) { if (rsa->blinding != NULL) { @@ -257,9 +249,7 @@ RSA *rsa; rsa->flags&= ~RSA_FLAG_BLINDING; } -int RSA_blinding_on(rsa,p_ctx) -RSA *rsa; -BN_CTX *p_ctx; +int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) { BIGNUM *A,*Ai; BN_CTX *ctx; @@ -275,13 +265,13 @@ BN_CTX *p_ctx; if (rsa->blinding != NULL) BN_BLINDING_free(rsa->blinding); - A=ctx->bn[0]; + A= &(ctx->bn[0]); ctx->tos++; if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err; - if ((Ai=BN_mod_inverse(A,rsa->n,ctx)) == NULL) goto err; + if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; - if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx, - (char *)rsa->method_mod_n)) goto err; + if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) + goto err; rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); ctx->tos--; rsa->flags|=RSA_FLAG_BLINDING; @@ -292,3 +282,48 @@ err: return(ret); } +int RSA_memory_lock(RSA *r) + { + int i,j,k,off; + char *p; + BIGNUM *bn,**t[6],*b; + BN_ULONG *ul; + + if (r->d == NULL) return(1); + t[0]= &r->d; + t[1]= &r->p; + t[2]= &r->q; + t[3]= &r->dmp1; + t[4]= &r->dmq1; + t[5]= &r->iqmp; + k=sizeof(BIGNUM)*6; + off=k/sizeof(BN_ULONG)+1; + j=1; + for (i=0; i<6; i++) + j+= (*t[i])->top; + if ((p=Malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL) + { + RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE); + return(0); + } + bn=(BIGNUM *)p; + ul=(BN_ULONG *)&(p[off]); + for (i=0; i<6; i++) + { + b= *(t[i]); + *(t[i])= &(bn[i]); + memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM)); + bn[i].flags=BN_FLG_STATIC_DATA; + bn[i].d=ul; + memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top); + ul+=b->top; + BN_clear_free(b); + } + + /* I should fix this so it can still be done */ + r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC); + + r->bignum_data=p; + return(1); + } + diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c index f0dd943657..f22fce5016 100644 --- a/src/lib/libcrypto/rsa/rsa_none.c +++ b/src/lib/libcrypto/rsa/rsa_none.c @@ -58,52 +58,41 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "rand.h" +#include +#include +#include -int RSA_padding_add_none(to,tlen,from,flen) -unsigned char *to; -int tlen; -unsigned char *from; -int flen; +int RSA_padding_add_none(unsigned char *to, int tlen, unsigned char *from, + int flen) { - if (flen >= tlen) + if (flen > tlen) { RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); return(0); } + + if (flen < tlen) + { + RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE); + return(0); + } - *(to++)=0; memcpy(to,from,(unsigned int)flen); return(1); } -int RSA_padding_check_none(to,tlen,from,flen) -unsigned char *to; -int tlen; -unsigned char *from; -int flen; +int RSA_padding_check_none(unsigned char *to, int tlen, unsigned char *from, + int flen, int num) { - int j; - from++; - if (flen+1 > tlen) + if (flen > tlen) { RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE); return(-1); } - if (*(from++) != 0) - { - RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_BAD_ZERO_BYTE); - return(-1); - } - /* scan over padding data */ - j=flen-1; /* one for type and one for the prepended 0. */ - memset(to,0,tlen-j); - to+=(tlen-j); - memcpy(to,from,j); - return(j); + memset(to,0,tlen-flen); + memcpy(to+tlen-flen,from,flen); + return(tlen); } diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c new file mode 100644 index 0000000000..843c40c864 --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_oaep.c @@ -0,0 +1,162 @@ +/* crypto/rsa/rsa_oaep.c */ +/* Written by Ulf Moeller. This software is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */ + +/* EME_OAEP as defined in RFC 2437 (PKCS #1 v2.0) */ + +#if !defined(NO_SHA) && !defined(NO_SHA1) +#include +#include "cryptlib.h" +#include +#include +#include +#include + +int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen); + +int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, + unsigned char *from, int flen, unsigned char *param, int plen) + { + int i, emlen = tlen - 1; + unsigned char *db, *seed; + unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH]; + + if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1) + { + RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, + RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); + return (0); + } + + if (emlen < 2 * SHA_DIGEST_LENGTH + 1) + { + RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL); + return (0); + } + + dbmask = Malloc(emlen - SHA_DIGEST_LENGTH); + if (dbmask == NULL) + { + RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); + return (0); + } + + to[0] = 0; + seed = to + 1; + db = to + SHA_DIGEST_LENGTH + 1; + + SHA1(param, plen, db); + memset(db + SHA_DIGEST_LENGTH, 0, + emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); + db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01; + memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen); + RAND_bytes(seed, SHA_DIGEST_LENGTH); +#ifdef PKCS_TESTVECT + memcpy(seed, + "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f", + 20); +#endif + + MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH); + for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) + db[i] ^= dbmask[i]; + + MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH); + for (i = 0; i < SHA_DIGEST_LENGTH; i++) + seed[i] ^= seedmask[i]; + + Free(dbmask); + return (1); + } + +int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen, + unsigned char *from, int flen, int num, unsigned char *param, + int plen) + { + int i, dblen, mlen = -1; + unsigned char *maskeddb; + int lzero; + unsigned char *db, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH]; + + if (--num < 2 * SHA_DIGEST_LENGTH + 1) + { + RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR); + return (-1); + } + + dblen = num - SHA_DIGEST_LENGTH; + db = Malloc(dblen); + if (db == NULL) + { + RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); + return (-1); + } + + lzero = num - flen; + maskeddb = from - lzero + SHA_DIGEST_LENGTH; + + MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen); + for (i = lzero; i < SHA_DIGEST_LENGTH; i++) + seed[i] ^= from[i - lzero]; + + MGF1(db, dblen, seed, SHA_DIGEST_LENGTH); + for (i = 0; i < dblen; i++) + db[i] ^= maskeddb[i]; + + SHA1(param, plen, phash); + + if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0) + RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR); + else + { + for (i = SHA_DIGEST_LENGTH; i < dblen; i++) + if (db[i] != 0x00) + break; + if (db[i] != 0x01 || i++ >= dblen) + RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, + RSA_R_OAEP_DECODING_ERROR); + else + { + mlen = dblen - i; + if (tlen < mlen) + { + RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE); + mlen = -1; + } + else + memcpy(to, db + i, mlen); + } + } + Free(db); + return (mlen); + } + +int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen) + { + long i, outlen = 0; + unsigned char cnt[4]; + SHA_CTX c; + unsigned char md[SHA_DIGEST_LENGTH]; + + for (i = 0; outlen < len; i++) + { + cnt[0] = (i >> 24) & 255, cnt[1] = (i >> 16) & 255, + cnt[2] = (i >> 8) & 255, cnt[3] = i & 255; + SHA1_Init(&c); + SHA1_Update(&c, seed, seedlen); + SHA1_Update(&c, cnt, 4); + if (outlen + SHA_DIGEST_LENGTH <= len) + { + SHA1_Final(mask + outlen, &c); + outlen += SHA_DIGEST_LENGTH; + } + else + { + SHA1_Final(md, &c); + memcpy(mask + outlen, md, len - outlen); + outlen = len; + } + } + return (0); + } +#endif diff --git a/src/lib/libcrypto/rsa/rsa_oaep_test.c b/src/lib/libcrypto/rsa/rsa_oaep_test.c new file mode 100644 index 0000000000..0d4e39d3da --- /dev/null +++ b/src/lib/libcrypto/rsa/rsa_oaep_test.c @@ -0,0 +1,309 @@ +/* test vectors from p1ovect1.txt */ + +#include +#include + +#include "openssl/e_os.h" + +#include +#include +#ifdef NO_RSA +int main(int argc, char *argv[]) +{ + printf("No RSA support\n"); + return(0); +} +#else +#include + +#define SetKey \ + key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \ + key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \ + key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \ + key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \ + key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \ + key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \ + key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \ + key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \ + memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \ + return (sizeof(ctext_ex) - 1); + +static int key1(RSA *key, unsigned char *c) + { + static unsigned char n[] = +"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F" +"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5" +"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93" +"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1" +"\xF5"; + + static unsigned char e[] = "\x11"; + + static unsigned char d[] = +"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44" +"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64" +"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9" +"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51"; + + static unsigned char p[] = +"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" +"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12" +"\x0D"; + + static unsigned char q[] = +"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" +"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" +"\x89"; + + static unsigned char dmp1[] = +"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF" +"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05"; + + static unsigned char dmq1[] = +"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99" +"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D" +"\x51"; + + static unsigned char iqmp[] = +"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8" +"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26"; + + static unsigned char ctext_ex[] = +"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89" +"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52" +"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44" +"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2"; + + SetKey; + } + +static int key2(RSA *key, unsigned char *c) + { + static unsigned char n[] = +"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8" +"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26" +"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8" +"\x34\x77\xCF"; + + static unsigned char e[] = "\x3"; + + static unsigned char d[] = +"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2" +"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41" +"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21" +"\xE5\xEB"; + + static unsigned char p[] = +"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92" +"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91"; + + static unsigned char q[] = +"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" +"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F"; + + static unsigned char dmp1[] = +"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61" +"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B"; + + static unsigned char dmq1[] = +"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90" +"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F"; + + static unsigned char iqmp[] = +"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13" +"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D"; + + static unsigned char ctext_ex[] = +"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a" +"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4" +"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52" +"\x62\x51"; + + SetKey; + } + +static int key3(RSA *key, unsigned char *c) + { + static unsigned char n[] = +"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71" +"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5" +"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD" +"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80" +"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25" +"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39" +"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68" +"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD" +"\xCB"; + + static unsigned char e[] = "\x11"; + + static unsigned char d[] = +"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD" +"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41" +"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69" +"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA" +"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94" +"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A" +"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94" +"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3" +"\xC1"; + + static unsigned char p[] = +"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60" +"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6" +"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A" +"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65" +"\x99"; + + static unsigned char q[] = +"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" +"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" +"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" +"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15" +"\x03"; + + static unsigned char dmp1[] = +"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A" +"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E" +"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E" +"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81"; + + static unsigned char dmq1[] = +"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9" +"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7" +"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D" +"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D"; + + static unsigned char iqmp[] = +"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23" +"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11" +"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E" +"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39" +"\xF7"; + + static unsigned char ctext_ex[] = +"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7" +"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce" +"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3" +"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06" +"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86" +"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4" +"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a" +"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1"; + + SetKey; + } + +static int pad_unknown(void) +{ + unsigned long l; + while ((l = ERR_get_error()) != 0) + if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE) + return(1); + return(0); +} + +int main() + { + int err=0; + int v; + RSA *key; + unsigned char ptext[256]; + unsigned char ctext[256]; + static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a"; + unsigned char ctext_ex[256]; + int plen; + int clen = 0; + int num; + + CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); + + plen = sizeof(ptext_ex) - 1; + + for (v = 0; v < 3; v++) + { + key = RSA_new(); + switch (v) { + case 0: + clen = key1(key, ctext_ex); + break; + case 1: + clen = key2(key, ctext_ex); + break; + case 2: + clen = key3(key, ctext_ex); + break; + } + + num = RSA_public_encrypt(plen, ptext_ex, ctext, key, + RSA_PKCS1_PADDING); + if (num != clen) + { + printf("PKCS#1 v1.5 encryption failed!\n"); + err=1; + goto oaep; + } + + num = RSA_private_decrypt(num, ctext, ptext, key, + RSA_PKCS1_PADDING); + if (num != plen || memcmp(ptext, ptext_ex, num) != 0) + { + printf("PKCS#1 v1.5 decryption failed!\n"); + err=1; + } + else + printf("PKCS #1 v1.5 encryption/decryption ok\n"); + + oaep: + ERR_clear_error(); + num = RSA_public_encrypt(plen, ptext_ex, ctext, key, + RSA_PKCS1_OAEP_PADDING); + if (num == -1 && pad_unknown()) + { + printf("No OAEP support\n"); + goto next; + } + if (num != clen) + { + printf("OAEP encryption failed!\n"); + err=1; + goto next; + } + + num = RSA_private_decrypt(num, ctext, ptext, key, + RSA_PKCS1_OAEP_PADDING); + if (num != plen || memcmp(ptext, ptext_ex, num) != 0) + { + printf("OAEP decryption (encrypted data) failed!\n"); + err=1; + } + else if (memcmp(ctext, ctext_ex, num) == 0) + { + printf("OAEP test vector %d passed!\n", v); + goto next; + } + + /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). + Try decrypting ctext_ex */ + + num = RSA_private_decrypt(clen, ctext_ex, ptext, key, + RSA_PKCS1_OAEP_PADDING); + + if (num != plen || memcmp(ptext, ptext_ex, num) != 0) + { + printf("OAEP decryption (test vector data) failed!\n"); + err=1; + } + else + printf("OAEP encryption/decryption ok\n"); + next: + RSA_free(key); + } + + ERR_remove_state(0); + + CRYPTO_mem_leaks_fp(stdout); + + return err; + } +#endif diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c index 2791291b94..f0ae51f234 100644 --- a/src/lib/libcrypto/rsa/rsa_pk1.c +++ b/src/lib/libcrypto/rsa/rsa_pk1.c @@ -58,27 +58,12 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "rand.h" - -#ifndef NOPROTO -int RSA_padding_add_PKCS1_type_1(); -int RSA_padding_check_PKCS1_type_1(); -int RSA_padding_add_PKCS1_type_2(); -int RSA_padding_check_PKCS1_type_2(); -int RSA_padding_add_SSLv23(); -int RSA_padding_check_SSLv23(); -int RSA_padding_add_none(); -int RSA_padding_check_none(); +#include +#include +#include -#endif - -int RSA_padding_add_PKCS1_type_1(to,tlen,from,flen) -unsigned char *to; -int tlen; -unsigned char *from; -int flen; +int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, + unsigned char *from, int flen) { int j; unsigned char *p; @@ -103,17 +88,14 @@ int flen; return(1); } -int RSA_padding_check_PKCS1_type_1(to,tlen,from,flen) -unsigned char *to; -int tlen; -unsigned char *from; -int flen; +int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, + unsigned char *from, int flen, int num) { int i,j; unsigned char *p; p=from; - if (*(p++) != 01) + if ((num != (flen+1)) || (*(p++) != 01)) { RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01); return(-1); @@ -153,11 +135,8 @@ int flen; return(j); } -int RSA_padding_add_PKCS1_type_2(to,tlen,from,flen) -unsigned char *to; -int tlen; -unsigned char *from; -int flen; +int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen, + unsigned char *from, int flen) { int i,j; unsigned char *p; @@ -192,21 +171,21 @@ int flen; return(1); } -int RSA_padding_check_PKCS1_type_2(to,tlen,from,flen) -unsigned char *to; -int tlen; -unsigned char *from; -int flen; +int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen, + unsigned char *from, int flen, int num) { int i,j; unsigned char *p; p=from; - if (*(p++) != 02) + if ((num != (flen+1)) || (*(p++) != 02)) { RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02); return(-1); } +#ifdef PKCS1_CHECK + return(num-11); +#endif /* scan over padding data */ j=flen-1; /* one for type. */ diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c index fb0fae5a43..73b8b0c7ad 100644 --- a/src/lib/libcrypto/rsa/rsa_saos.c +++ b/src/lib/libcrypto/rsa/rsa_saos.c @@ -58,18 +58,13 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include +#include -int RSA_sign_ASN1_OCTET_STRING(type,m,m_len,sigret,siglen,rsa) -int type; -unsigned char *m; -unsigned int m_len; -unsigned char *sigret; -unsigned int *siglen; -RSA *rsa; +int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len, + unsigned char *sigret, unsigned int *siglen, RSA *rsa) { ASN1_OCTET_STRING sig; int i,j,ret=1; @@ -105,13 +100,9 @@ RSA *rsa; return(ret); } -int RSA_verify_ASN1_OCTET_STRING(dtype, m, m_len, sigbuf, siglen, rsa) -int dtype; -unsigned char *m; -unsigned int m_len; -unsigned char *sigbuf; -unsigned int siglen; -RSA *rsa; +int RSA_verify_ASN1_OCTET_STRING(int dtype, unsigned char *m, + unsigned int m_len, unsigned char *sigbuf, unsigned int siglen, + RSA *rsa) { int i,ret=0; unsigned char *p,*s; diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c index 28c5571e74..1740494a4c 100644 --- a/src/lib/libcrypto/rsa/rsa_sign.c +++ b/src/lib/libcrypto/rsa/rsa_sign.c @@ -58,18 +58,13 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include +#include -int RSA_sign(type,m,m_len,sigret,siglen,rsa) -int type; -unsigned char *m; -unsigned int m_len; -unsigned char *sigret; -unsigned int *siglen; -RSA *rsa; +int RSA_sign(int type, unsigned char *m, unsigned int m_len, + unsigned char *sigret, unsigned int *siglen, RSA *rsa) { X509_SIG sig; ASN1_TYPE parameter; @@ -124,13 +119,8 @@ RSA *rsa; return(ret); } -int RSA_verify(dtype, m, m_len, sigbuf, siglen, rsa) -int dtype; -unsigned char *m; -unsigned int m_len; -unsigned char *sigbuf; -unsigned int siglen; -RSA *rsa; +int RSA_verify(int dtype, unsigned char *m, unsigned int m_len, + unsigned char *sigbuf, unsigned int siglen, RSA *rsa) { int i,ret=0,sigtype; unsigned char *p,*s; @@ -154,9 +144,11 @@ RSA *rsa; p=s; sig=d2i_X509_SIG(NULL,&p,(long)i); + if (sig == NULL) goto err; sigtype=OBJ_obj2nid(sig->algor->algorithm); + #ifdef RSA_DEBUG /* put a backward compatability flag in EAY */ fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype), diff --git a/src/lib/libcrypto/rsa/rsa_ssl.c b/src/lib/libcrypto/rsa/rsa_ssl.c index 9bcd4b2c03..1050844f8d 100644 --- a/src/lib/libcrypto/rsa/rsa_ssl.c +++ b/src/lib/libcrypto/rsa/rsa_ssl.c @@ -58,15 +58,12 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "rsa.h" -#include "rand.h" +#include +#include +#include -int RSA_padding_add_SSLv23(to,tlen,from,flen) -unsigned char *to; -int tlen; -unsigned char *from; -int flen; +int RSA_padding_add_SSLv23(unsigned char *to, int tlen, unsigned char *from, + int flen) { int i,j; unsigned char *p; @@ -103,11 +100,8 @@ int flen; return(1); } -int RSA_padding_check_SSLv23(to,tlen,from,flen) -unsigned char *to; -int tlen; -unsigned char *from; -int flen; +int RSA_padding_check_SSLv23(unsigned char *to, int tlen, unsigned char *from, + int flen, int num) { int i,j,k; unsigned char *p; @@ -118,7 +112,7 @@ int flen; RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL); return(-1); } - if (*(p++) != 02) + if ((num != (flen+1)) || (*(p++) != 02)) { RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02); return(-1); diff --git a/src/lib/libcrypto/sha/Makefile.ssl b/src/lib/libcrypto/sha/Makefile.ssl index eeb545d140..d01245ce37 100644 --- a/src/lib/libcrypto/sha/Makefile.ssl +++ b/src/lib/libcrypto/sha/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -39,7 +41,7 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf @@ -58,26 +60,25 @@ asm/sx86-out.o: asm/sx86unix.cpp # bsdi asm/sx86bsdi.o: asm/sx86unix.cpp - $(CPP) -DBSDI asm/sx86unix.cpp | as -o asm/sx86bsdi.o + $(CPP) -DBSDI asm/sx86unix.cpp | sed 's/ :/:/' | as -o asm/sx86bsdi.o asm/sx86unix.cpp: - (cd asm; perl sha1-586.pl cpp >sx86unix.cpp) + (cd asm; $(PERL) sha1-586.pl cpp $(PROCESSOR) >sx86unix.cpp) files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -89,15 +90,22 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o - -errors: + rm -f asm/sx86unix.cpp *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o # DO NOT DELETE THIS LINE -- make depend depends on it. + +sha1_one.o: ../../include/openssl/sha.h +sha1dgst.o: ../../include/openssl/opensslconf.h +sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h +sha1dgst.o: sha_locl.h +sha_dgst.o: ../../include/openssl/opensslconf.h +sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h +sha_dgst.o: sha_locl.h +sha_one.o: ../../include/openssl/sha.h diff --git a/src/lib/libcrypto/sha/Makefile.uni b/src/lib/libcrypto/sha/Makefile.uni index f3236755b2..b7ec5caa4e 100644 --- a/src/lib/libcrypto/sha/Makefile.uni +++ b/src/lib/libcrypto/sha/Makefile.uni @@ -49,7 +49,7 @@ all: $(LIB) $(TEST) $(APPS) $(LIB): $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/ranlib.sh $(LIB) + $(RANLIB) $(LIB) # elf asm/sx86-elf.o: asm/sx86unix.cpp diff --git a/src/lib/libcrypto/sha/asm/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl index d6d998f8ee..04e42ab09f 100644 --- a/src/lib/libcrypto/sha/asm/sha1-586.pl +++ b/src/lib/libcrypto/sha/asm/sha1-586.pl @@ -1,11 +1,11 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl $normal=0; push(@INC,"perlasm","../../perlasm"); require "x86asm.pl"; -&asm_init($ARGV[0],"sha1-586.pl"); +&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386"); $A="eax"; $B="ebx"; diff --git a/src/lib/libcrypto/sha/asm/sx86unix.cpp b/src/lib/libcrypto/sha/asm/sx86unix.cpp deleted file mode 100644 index 8366664a39..0000000000 --- a/src/lib/libcrypto/sha/asm/sx86unix.cpp +++ /dev/null @@ -1,1948 +0,0 @@ -/* Run the C pre-processor over this file with one of the following defined - * ELF - elf object files, - * OUT - a.out object files, - * BSDI - BSDI style a.out object files - * SOL - Solaris style elf - */ - -#define TYPE(a,b) .type a,b -#define SIZE(a,b) .size a,b - -#if defined(OUT) || defined(BSDI) -#define sha1_block_x86 _sha1_block_x86 - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#define OK 1 -#define ALIGN 4 -#undef SIZE -#undef TYPE -#define SIZE(a,b) -#define TYPE(a,b) -#endif - -#if defined(ELF) || defined(SOL) -#define OK 1 -#define ALIGN 16 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by sha1-586.pl */ - /* Which is a perl program used to generate the x86 assember for */ - /* any of elf, a.out, BSDI,Win32, or Solaris */ - /* eric */ - - .file "sha1-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl sha1_block_x86 - TYPE(sha1_block_x86,@function) -sha1_block_x86: - pushl %esi - pushl %ebp - movl 20(%esp), %eax - movl 16(%esp), %esi - addl %esi, %eax - movl 12(%esp), %ebp - pushl %ebx - subl $64, %eax - pushl %edi - movl 4(%ebp), %ebx - subl $72, %esp - movl 12(%ebp), %edx - movl 16(%ebp), %edi - movl 8(%ebp), %ecx - movl %eax, 68(%esp) - /* First we need to setup the X array */ - movl (%esi), %eax -.L000start: - /* First, load the words onto the stack in network byte order */ -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, (%esp) - movl 4(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 4(%esp) - movl 8(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 8(%esp) - movl 12(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 12(%esp) - movl 16(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 16(%esp) - movl 20(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 20(%esp) - movl 24(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 24(%esp) - movl 28(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 28(%esp) - movl 32(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 32(%esp) - movl 36(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 36(%esp) - movl 40(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 40(%esp) - movl 44(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 44(%esp) - movl 48(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 48(%esp) - movl 52(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 52(%esp) - movl 56(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 56(%esp) - movl 60(%esi), %eax -.byte 15 -.byte 200 /* bswapl %eax */ - movl %eax, 60(%esp) - /* We now have the X array on the stack */ - /* starting at sp-4 */ - movl %esi, 64(%esp) - - /* Start processing */ - movl (%ebp), %eax - /* 00_15 0 */ - movl %ecx, %esi - movl %eax, %ebp - xorl %edx, %esi - roll $5, %ebp - andl %ebx, %esi - addl %edi, %ebp -.byte 209 -.byte 203 /* rorl $1 %ebx */ - movl (%esp), %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - xorl %edx, %esi - leal 1518500249(%ebp,%edi,1),%ebp - movl %ebx, %edi - addl %ebp, %esi - xorl %ecx, %edi - movl %esi, %ebp - andl %eax, %edi - roll $5, %ebp - addl %edx, %ebp - movl 4(%esp), %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - xorl %ecx, %edi -.byte 209 -.byte 200 /* rorl $1 %eax */ - leal 1518500249(%ebp,%edx,1),%ebp - addl %ebp, %edi - /* 00_15 2 */ - movl %eax, %edx - movl %edi, %ebp - xorl %ebx, %edx - roll $5, %ebp - andl %esi, %edx - addl %ecx, %ebp -.byte 209 -.byte 206 /* rorl $1 %esi */ - movl 8(%esp), %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - xorl %ebx, %edx - leal 1518500249(%ebp,%ecx,1),%ebp - movl %esi, %ecx - addl %ebp, %edx - xorl %eax, %ecx - movl %edx, %ebp - andl %edi, %ecx - roll $5, %ebp - addl %ebx, %ebp - movl 12(%esp), %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - xorl %eax, %ecx -.byte 209 -.byte 207 /* rorl $1 %edi */ - leal 1518500249(%ebp,%ebx,1),%ebp - addl %ebp, %ecx - /* 00_15 4 */ - movl %edi, %ebx - movl %ecx, %ebp - xorl %esi, %ebx - roll $5, %ebp - andl %edx, %ebx - addl %eax, %ebp -.byte 209 -.byte 202 /* rorl $1 %edx */ - movl 16(%esp), %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - xorl %esi, %ebx - leal 1518500249(%ebp,%eax,1),%ebp - movl %edx, %eax - addl %ebp, %ebx - xorl %edi, %eax - movl %ebx, %ebp - andl %ecx, %eax - roll $5, %ebp - addl %esi, %ebp - movl 20(%esp), %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - xorl %edi, %eax -.byte 209 -.byte 201 /* rorl $1 %ecx */ - leal 1518500249(%ebp,%esi,1),%ebp - addl %ebp, %eax - /* 00_15 6 */ - movl %ecx, %esi - movl %eax, %ebp - xorl %edx, %esi - roll $5, %ebp - andl %ebx, %esi - addl %edi, %ebp -.byte 209 -.byte 203 /* rorl $1 %ebx */ - movl 24(%esp), %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - xorl %edx, %esi - leal 1518500249(%ebp,%edi,1),%ebp - movl %ebx, %edi - addl %ebp, %esi - xorl %ecx, %edi - movl %esi, %ebp - andl %eax, %edi - roll $5, %ebp - addl %edx, %ebp - movl 28(%esp), %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - xorl %ecx, %edi -.byte 209 -.byte 200 /* rorl $1 %eax */ - leal 1518500249(%ebp,%edx,1),%ebp - addl %ebp, %edi - /* 00_15 8 */ - movl %eax, %edx - movl %edi, %ebp - xorl %ebx, %edx - roll $5, %ebp - andl %esi, %edx - addl %ecx, %ebp -.byte 209 -.byte 206 /* rorl $1 %esi */ - movl 32(%esp), %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - xorl %ebx, %edx - leal 1518500249(%ebp,%ecx,1),%ebp - movl %esi, %ecx - addl %ebp, %edx - xorl %eax, %ecx - movl %edx, %ebp - andl %edi, %ecx - roll $5, %ebp - addl %ebx, %ebp - movl 36(%esp), %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - xorl %eax, %ecx -.byte 209 -.byte 207 /* rorl $1 %edi */ - leal 1518500249(%ebp,%ebx,1),%ebp - addl %ebp, %ecx - /* 00_15 10 */ - movl %edi, %ebx - movl %ecx, %ebp - xorl %esi, %ebx - roll $5, %ebp - andl %edx, %ebx - addl %eax, %ebp -.byte 209 -.byte 202 /* rorl $1 %edx */ - movl 40(%esp), %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - xorl %esi, %ebx - leal 1518500249(%ebp,%eax,1),%ebp - movl %edx, %eax - addl %ebp, %ebx - xorl %edi, %eax - movl %ebx, %ebp - andl %ecx, %eax - roll $5, %ebp - addl %esi, %ebp - movl 44(%esp), %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - xorl %edi, %eax -.byte 209 -.byte 201 /* rorl $1 %ecx */ - leal 1518500249(%ebp,%esi,1),%ebp - addl %ebp, %eax - /* 00_15 12 */ - movl %ecx, %esi - movl %eax, %ebp - xorl %edx, %esi - roll $5, %ebp - andl %ebx, %esi - addl %edi, %ebp -.byte 209 -.byte 203 /* rorl $1 %ebx */ - movl 48(%esp), %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - xorl %edx, %esi - leal 1518500249(%ebp,%edi,1),%ebp - movl %ebx, %edi - addl %ebp, %esi - xorl %ecx, %edi - movl %esi, %ebp - andl %eax, %edi - roll $5, %ebp - addl %edx, %ebp - movl 52(%esp), %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - xorl %ecx, %edi -.byte 209 -.byte 200 /* rorl $1 %eax */ - leal 1518500249(%ebp,%edx,1),%ebp - addl %ebp, %edi - /* 00_15 14 */ - movl %eax, %edx - movl %edi, %ebp - xorl %ebx, %edx - roll $5, %ebp - andl %esi, %edx - addl %ecx, %ebp -.byte 209 -.byte 206 /* rorl $1 %esi */ - movl 56(%esp), %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - xorl %ebx, %edx - leal 1518500249(%ebp,%ecx,1),%ebp - movl %esi, %ecx - addl %ebp, %edx - xorl %eax, %ecx - movl %edx, %ebp - andl %edi, %ecx - roll $5, %ebp - addl %ebx, %ebp - movl 60(%esp), %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - xorl %eax, %ecx -.byte 209 -.byte 207 /* rorl $1 %edi */ - leal 1518500249(%ebp,%ebx,1),%ebp - addl %ebp, %ecx - /* 16_19 16 */ - nop - movl (%esp), %ebp - movl 8(%esp), %ebx - xorl %ebp, %ebx - movl 32(%esp), %ebp - xorl %ebp, %ebx - movl 52(%esp), %ebp - xorl %ebp, %ebx - movl %edi, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - xorl %esi, %ebp - movl %ebx, (%esp) - andl %edx, %ebp - leal 1518500249(%ebx,%eax,1),%ebx - xorl %esi, %ebp - movl %ecx, %eax - addl %ebp, %ebx - roll $5, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %eax, %ebx - movl 4(%esp), %eax - movl 12(%esp), %ebp - xorl %ebp, %eax - movl 36(%esp), %ebp - xorl %ebp, %eax - movl 56(%esp), %ebp -.byte 209 -.byte 202 /* rorl $1 %edx */ - xorl %ebp, %eax -.byte 209 -.byte 192 /* roll $1 %eax */ - movl %edx, %ebp - xorl %edi, %ebp - movl %eax, 4(%esp) - andl %ecx, %ebp - leal 1518500249(%eax,%esi,1),%eax - xorl %edi, %ebp - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %eax -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %eax - /* 16_19 18 */ - movl 8(%esp), %ebp - movl 16(%esp), %esi - xorl %ebp, %esi - movl 40(%esp), %ebp - xorl %ebp, %esi - movl 60(%esp), %ebp - xorl %ebp, %esi - movl %ecx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - xorl %edx, %ebp - movl %esi, 8(%esp) - andl %ebx, %ebp - leal 1518500249(%esi,%edi,1),%esi - xorl %edx, %ebp - movl %eax, %edi - addl %ebp, %esi - roll $5, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %edi, %esi - movl 12(%esp), %edi - movl 20(%esp), %ebp - xorl %ebp, %edi - movl 44(%esp), %ebp - xorl %ebp, %edi - movl (%esp), %ebp -.byte 209 -.byte 203 /* rorl $1 %ebx */ - xorl %ebp, %edi -.byte 209 -.byte 199 /* roll $1 %edi */ - movl %ebx, %ebp - xorl %ecx, %ebp - movl %edi, 12(%esp) - andl %eax, %ebp - leal 1518500249(%edi,%edx,1),%edi - xorl %ecx, %ebp - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %edi -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edi - /* 20_39 20 */ - movl 16(%esp), %edx - movl 24(%esp), %ebp - xorl %ebp, %edx - movl 48(%esp), %ebp - xorl %ebp, %edx - movl 4(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - xorl %eax, %ebp - movl %edx, 16(%esp) - xorl %ebx, %ebp - leal 1859775393(%edx,%ecx,1),%edx - movl %edi, %ecx - roll $5, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ebp, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ecx, %edx - /* 20_39 21 */ - movl 20(%esp), %ecx - movl 28(%esp), %ebp - xorl %ebp, %ecx - movl 52(%esp), %ebp - xorl %ebp, %ecx - movl 8(%esp), %ebp - xorl %ebp, %ecx - movl %edi, %ebp -.byte 209 -.byte 193 /* roll $1 %ecx */ - xorl %esi, %ebp - movl %ecx, 20(%esp) - xorl %eax, %ebp - leal 1859775393(%ecx,%ebx,1),%ecx - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ecx - /* 20_39 22 */ - movl 24(%esp), %ebx - movl 32(%esp), %ebp - xorl %ebp, %ebx - movl 56(%esp), %ebp - xorl %ebp, %ebx - movl 12(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - xorl %edi, %ebp - movl %ebx, 24(%esp) - xorl %esi, %ebp - leal 1859775393(%ebx,%eax,1),%ebx - movl %ecx, %eax - roll $5, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %ebp, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %eax, %ebx - /* 20_39 23 */ - movl 28(%esp), %eax - movl 36(%esp), %ebp - xorl %ebp, %eax - movl 60(%esp), %ebp - xorl %ebp, %eax - movl 16(%esp), %ebp - xorl %ebp, %eax - movl %ecx, %ebp -.byte 209 -.byte 192 /* roll $1 %eax */ - xorl %edx, %ebp - movl %eax, 28(%esp) - xorl %edi, %ebp - leal 1859775393(%eax,%esi,1),%eax - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %eax - /* 20_39 24 */ - movl 32(%esp), %esi - movl 40(%esp), %ebp - xorl %ebp, %esi - movl (%esp), %ebp - xorl %ebp, %esi - movl 20(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - xorl %ecx, %ebp - movl %esi, 32(%esp) - xorl %edx, %ebp - leal 1859775393(%esi,%edi,1),%esi - movl %eax, %edi - roll $5, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %ebp, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %edi, %esi - /* 20_39 25 */ - movl 36(%esp), %edi - movl 44(%esp), %ebp - xorl %ebp, %edi - movl 4(%esp), %ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - xorl %ebp, %edi - movl %eax, %ebp -.byte 209 -.byte 199 /* roll $1 %edi */ - xorl %ebx, %ebp - movl %edi, 36(%esp) - xorl %ecx, %ebp - leal 1859775393(%edi,%edx,1),%edi - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %edi - /* 20_39 26 */ - movl 40(%esp), %edx - movl 48(%esp), %ebp - xorl %ebp, %edx - movl 8(%esp), %ebp - xorl %ebp, %edx - movl 28(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - xorl %eax, %ebp - movl %edx, 40(%esp) - xorl %ebx, %ebp - leal 1859775393(%edx,%ecx,1),%edx - movl %edi, %ecx - roll $5, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ebp, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ecx, %edx - /* 20_39 27 */ - movl 44(%esp), %ecx - movl 52(%esp), %ebp - xorl %ebp, %ecx - movl 12(%esp), %ebp - xorl %ebp, %ecx - movl 32(%esp), %ebp - xorl %ebp, %ecx - movl %edi, %ebp -.byte 209 -.byte 193 /* roll $1 %ecx */ - xorl %esi, %ebp - movl %ecx, 44(%esp) - xorl %eax, %ebp - leal 1859775393(%ecx,%ebx,1),%ecx - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ecx - /* 20_39 28 */ - movl 48(%esp), %ebx - movl 56(%esp), %ebp - xorl %ebp, %ebx - movl 16(%esp), %ebp - xorl %ebp, %ebx - movl 36(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - xorl %edi, %ebp - movl %ebx, 48(%esp) - xorl %esi, %ebp - leal 1859775393(%ebx,%eax,1),%ebx - movl %ecx, %eax - roll $5, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %ebp, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %eax, %ebx - /* 20_39 29 */ - movl 52(%esp), %eax - movl 60(%esp), %ebp - xorl %ebp, %eax - movl 20(%esp), %ebp - xorl %ebp, %eax - movl 40(%esp), %ebp - xorl %ebp, %eax - movl %ecx, %ebp -.byte 209 -.byte 192 /* roll $1 %eax */ - xorl %edx, %ebp - movl %eax, 52(%esp) - xorl %edi, %ebp - leal 1859775393(%eax,%esi,1),%eax - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %eax - /* 20_39 30 */ - movl 56(%esp), %esi - movl (%esp), %ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - xorl %ebp, %esi - movl 44(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - xorl %ecx, %ebp - movl %esi, 56(%esp) - xorl %edx, %ebp - leal 1859775393(%esi,%edi,1),%esi - movl %eax, %edi - roll $5, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %ebp, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %edi, %esi - /* 20_39 31 */ - movl 60(%esp), %edi - movl 4(%esp), %ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - xorl %ebp, %edi - movl 48(%esp), %ebp - xorl %ebp, %edi - movl %eax, %ebp -.byte 209 -.byte 199 /* roll $1 %edi */ - xorl %ebx, %ebp - movl %edi, 60(%esp) - xorl %ecx, %ebp - leal 1859775393(%edi,%edx,1),%edi - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %edi - /* 20_39 32 */ - movl (%esp), %edx - movl 8(%esp), %ebp - xorl %ebp, %edx - movl 32(%esp), %ebp - xorl %ebp, %edx - movl 52(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - xorl %eax, %ebp - movl %edx, (%esp) - xorl %ebx, %ebp - leal 1859775393(%edx,%ecx,1),%edx - movl %edi, %ecx - roll $5, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ebp, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ecx, %edx - /* 20_39 33 */ - movl 4(%esp), %ecx - movl 12(%esp), %ebp - xorl %ebp, %ecx - movl 36(%esp), %ebp - xorl %ebp, %ecx - movl 56(%esp), %ebp - xorl %ebp, %ecx - movl %edi, %ebp -.byte 209 -.byte 193 /* roll $1 %ecx */ - xorl %esi, %ebp - movl %ecx, 4(%esp) - xorl %eax, %ebp - leal 1859775393(%ecx,%ebx,1),%ecx - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ecx - /* 20_39 34 */ - movl 8(%esp), %ebx - movl 16(%esp), %ebp - xorl %ebp, %ebx - movl 40(%esp), %ebp - xorl %ebp, %ebx - movl 60(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - xorl %edi, %ebp - movl %ebx, 8(%esp) - xorl %esi, %ebp - leal 1859775393(%ebx,%eax,1),%ebx - movl %ecx, %eax - roll $5, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %ebp, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %eax, %ebx - /* 20_39 35 */ - movl 12(%esp), %eax - movl 20(%esp), %ebp - xorl %ebp, %eax - movl 44(%esp), %ebp - xorl %ebp, %eax - movl (%esp), %ebp - xorl %ebp, %eax - movl %ecx, %ebp -.byte 209 -.byte 192 /* roll $1 %eax */ - xorl %edx, %ebp - movl %eax, 12(%esp) - xorl %edi, %ebp - leal 1859775393(%eax,%esi,1),%eax - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %eax - /* 20_39 36 */ - movl 16(%esp), %esi - movl 24(%esp), %ebp - xorl %ebp, %esi - movl 48(%esp), %ebp - xorl %ebp, %esi - movl 4(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - xorl %ecx, %ebp - movl %esi, 16(%esp) - xorl %edx, %ebp - leal 1859775393(%esi,%edi,1),%esi - movl %eax, %edi - roll $5, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %ebp, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %edi, %esi - /* 20_39 37 */ - movl 20(%esp), %edi - movl 28(%esp), %ebp - xorl %ebp, %edi - movl 52(%esp), %ebp - xorl %ebp, %edi - movl 8(%esp), %ebp - xorl %ebp, %edi - movl %eax, %ebp -.byte 209 -.byte 199 /* roll $1 %edi */ - xorl %ebx, %ebp - movl %edi, 20(%esp) - xorl %ecx, %ebp - leal 1859775393(%edi,%edx,1),%edi - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %edi - /* 20_39 38 */ - movl 24(%esp), %edx - movl 32(%esp), %ebp - xorl %ebp, %edx - movl 56(%esp), %ebp - xorl %ebp, %edx - movl 12(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - xorl %eax, %ebp - movl %edx, 24(%esp) - xorl %ebx, %ebp - leal 1859775393(%edx,%ecx,1),%edx - movl %edi, %ecx - roll $5, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ebp, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ecx, %edx - /* 20_39 39 */ - movl 28(%esp), %ecx - movl 36(%esp), %ebp - xorl %ebp, %ecx - movl 60(%esp), %ebp - xorl %ebp, %ecx - movl 16(%esp), %ebp - xorl %ebp, %ecx - movl %edi, %ebp -.byte 209 -.byte 193 /* roll $1 %ecx */ - xorl %esi, %ebp - movl %ecx, 28(%esp) - xorl %eax, %ebp - leal 1859775393(%ecx,%ebx,1),%ecx - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ecx - /* 40_59 40 */ - movl 32(%esp), %ebx - movl 40(%esp), %ebp - xorl %ebp, %ebx - movl (%esp), %ebp - xorl %ebp, %ebx - movl 20(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - orl %edi, %ebp - movl %ebx, 32(%esp) - andl %esi, %ebp - leal 2400959708(%ebx,%eax,1),%ebx - movl %edx, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - andl %edi, %eax - orl %eax, %ebp - movl %ecx, %eax - roll $5, %eax - addl %eax, %ebp - movl 36(%esp), %eax - addl %ebp, %ebx - movl 44(%esp), %ebp - xorl %ebp, %eax - movl 4(%esp), %ebp - xorl %ebp, %eax - movl 24(%esp), %ebp -.byte 209 -.byte 202 /* rorl $1 %edx */ - xorl %ebp, %eax -.byte 209 -.byte 192 /* roll $1 %eax */ - movl %ecx, %ebp - movl %eax, 36(%esp) - orl %edx, %ebp - leal 2400959708(%eax,%esi,1),%eax - movl %ecx, %esi - andl %edi, %ebp - andl %edx, %esi - orl %esi, %ebp - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %ebp -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %eax - /* 40_59 41 */ - /* 40_59 42 */ - movl 40(%esp), %esi - movl 48(%esp), %ebp - xorl %ebp, %esi - movl 8(%esp), %ebp - xorl %ebp, %esi - movl 28(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - orl %ecx, %ebp - movl %esi, 40(%esp) - andl %edx, %ebp - leal 2400959708(%esi,%edi,1),%esi - movl %ebx, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - andl %ecx, %edi - orl %edi, %ebp - movl %eax, %edi - roll $5, %edi - addl %edi, %ebp - movl 44(%esp), %edi - addl %ebp, %esi - movl 52(%esp), %ebp - xorl %ebp, %edi - movl 12(%esp), %ebp - xorl %ebp, %edi - movl 32(%esp), %ebp -.byte 209 -.byte 203 /* rorl $1 %ebx */ - xorl %ebp, %edi -.byte 209 -.byte 199 /* roll $1 %edi */ - movl %eax, %ebp - movl %edi, 44(%esp) - orl %ebx, %ebp - leal 2400959708(%edi,%edx,1),%edi - movl %eax, %edx - andl %ecx, %ebp - andl %ebx, %edx - orl %edx, %ebp - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %ebp -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edi - /* 40_59 43 */ - /* 40_59 44 */ - movl 48(%esp), %edx - movl 56(%esp), %ebp - xorl %ebp, %edx - movl 16(%esp), %ebp - xorl %ebp, %edx - movl 36(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - orl %eax, %ebp - movl %edx, 48(%esp) - andl %ebx, %ebp - leal 2400959708(%edx,%ecx,1),%edx - movl %esi, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - andl %eax, %ecx - orl %ecx, %ebp - movl %edi, %ecx - roll $5, %ecx - addl %ecx, %ebp - movl 52(%esp), %ecx - addl %ebp, %edx - movl 60(%esp), %ebp - xorl %ebp, %ecx - movl 20(%esp), %ebp - xorl %ebp, %ecx - movl 40(%esp), %ebp -.byte 209 -.byte 206 /* rorl $1 %esi */ - xorl %ebp, %ecx -.byte 209 -.byte 193 /* roll $1 %ecx */ - movl %edi, %ebp - movl %ecx, 52(%esp) - orl %esi, %ebp - leal 2400959708(%ecx,%ebx,1),%ecx - movl %edi, %ebx - andl %eax, %ebp - andl %esi, %ebx - orl %ebx, %ebp - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ebp -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ecx - /* 40_59 45 */ - /* 40_59 46 */ - movl 56(%esp), %ebx - movl (%esp), %ebp - xorl %ebp, %ebx - movl 24(%esp), %ebp - xorl %ebp, %ebx - movl 44(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - orl %edi, %ebp - movl %ebx, 56(%esp) - andl %esi, %ebp - leal 2400959708(%ebx,%eax,1),%ebx - movl %edx, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - andl %edi, %eax - orl %eax, %ebp - movl %ecx, %eax - roll $5, %eax - addl %eax, %ebp - movl 60(%esp), %eax - addl %ebp, %ebx - movl 4(%esp), %ebp - xorl %ebp, %eax - movl 28(%esp), %ebp - xorl %ebp, %eax - movl 48(%esp), %ebp -.byte 209 -.byte 202 /* rorl $1 %edx */ - xorl %ebp, %eax -.byte 209 -.byte 192 /* roll $1 %eax */ - movl %ecx, %ebp - movl %eax, 60(%esp) - orl %edx, %ebp - leal 2400959708(%eax,%esi,1),%eax - movl %ecx, %esi - andl %edi, %ebp - andl %edx, %esi - orl %esi, %ebp - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %ebp -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %eax - /* 40_59 47 */ - /* 40_59 48 */ - movl (%esp), %esi - movl 8(%esp), %ebp - xorl %ebp, %esi - movl 32(%esp), %ebp - xorl %ebp, %esi - movl 52(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - orl %ecx, %ebp - movl %esi, (%esp) - andl %edx, %ebp - leal 2400959708(%esi,%edi,1),%esi - movl %ebx, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - andl %ecx, %edi - orl %edi, %ebp - movl %eax, %edi - roll $5, %edi - addl %edi, %ebp - movl 4(%esp), %edi - addl %ebp, %esi - movl 12(%esp), %ebp - xorl %ebp, %edi - movl 36(%esp), %ebp - xorl %ebp, %edi - movl 56(%esp), %ebp -.byte 209 -.byte 203 /* rorl $1 %ebx */ - xorl %ebp, %edi -.byte 209 -.byte 199 /* roll $1 %edi */ - movl %eax, %ebp - movl %edi, 4(%esp) - orl %ebx, %ebp - leal 2400959708(%edi,%edx,1),%edi - movl %eax, %edx - andl %ecx, %ebp - andl %ebx, %edx - orl %edx, %ebp - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %ebp -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edi - /* 40_59 49 */ - /* 40_59 50 */ - movl 8(%esp), %edx - movl 16(%esp), %ebp - xorl %ebp, %edx - movl 40(%esp), %ebp - xorl %ebp, %edx - movl 60(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - orl %eax, %ebp - movl %edx, 8(%esp) - andl %ebx, %ebp - leal 2400959708(%edx,%ecx,1),%edx - movl %esi, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - andl %eax, %ecx - orl %ecx, %ebp - movl %edi, %ecx - roll $5, %ecx - addl %ecx, %ebp - movl 12(%esp), %ecx - addl %ebp, %edx - movl 20(%esp), %ebp - xorl %ebp, %ecx - movl 44(%esp), %ebp - xorl %ebp, %ecx - movl (%esp), %ebp -.byte 209 -.byte 206 /* rorl $1 %esi */ - xorl %ebp, %ecx -.byte 209 -.byte 193 /* roll $1 %ecx */ - movl %edi, %ebp - movl %ecx, 12(%esp) - orl %esi, %ebp - leal 2400959708(%ecx,%ebx,1),%ecx - movl %edi, %ebx - andl %eax, %ebp - andl %esi, %ebx - orl %ebx, %ebp - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ebp -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ecx - /* 40_59 51 */ - /* 40_59 52 */ - movl 16(%esp), %ebx - movl 24(%esp), %ebp - xorl %ebp, %ebx - movl 48(%esp), %ebp - xorl %ebp, %ebx - movl 4(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - orl %edi, %ebp - movl %ebx, 16(%esp) - andl %esi, %ebp - leal 2400959708(%ebx,%eax,1),%ebx - movl %edx, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - andl %edi, %eax - orl %eax, %ebp - movl %ecx, %eax - roll $5, %eax - addl %eax, %ebp - movl 20(%esp), %eax - addl %ebp, %ebx - movl 28(%esp), %ebp - xorl %ebp, %eax - movl 52(%esp), %ebp - xorl %ebp, %eax - movl 8(%esp), %ebp -.byte 209 -.byte 202 /* rorl $1 %edx */ - xorl %ebp, %eax -.byte 209 -.byte 192 /* roll $1 %eax */ - movl %ecx, %ebp - movl %eax, 20(%esp) - orl %edx, %ebp - leal 2400959708(%eax,%esi,1),%eax - movl %ecx, %esi - andl %edi, %ebp - andl %edx, %esi - orl %esi, %ebp - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %ebp -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %eax - /* 40_59 53 */ - /* 40_59 54 */ - movl 24(%esp), %esi - movl 32(%esp), %ebp - xorl %ebp, %esi - movl 56(%esp), %ebp - xorl %ebp, %esi - movl 12(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - orl %ecx, %ebp - movl %esi, 24(%esp) - andl %edx, %ebp - leal 2400959708(%esi,%edi,1),%esi - movl %ebx, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - andl %ecx, %edi - orl %edi, %ebp - movl %eax, %edi - roll $5, %edi - addl %edi, %ebp - movl 28(%esp), %edi - addl %ebp, %esi - movl 36(%esp), %ebp - xorl %ebp, %edi - movl 60(%esp), %ebp - xorl %ebp, %edi - movl 16(%esp), %ebp -.byte 209 -.byte 203 /* rorl $1 %ebx */ - xorl %ebp, %edi -.byte 209 -.byte 199 /* roll $1 %edi */ - movl %eax, %ebp - movl %edi, 28(%esp) - orl %ebx, %ebp - leal 2400959708(%edi,%edx,1),%edi - movl %eax, %edx - andl %ecx, %ebp - andl %ebx, %edx - orl %edx, %ebp - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %ebp -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edi - /* 40_59 55 */ - /* 40_59 56 */ - movl 32(%esp), %edx - movl 40(%esp), %ebp - xorl %ebp, %edx - movl (%esp), %ebp - xorl %ebp, %edx - movl 20(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - orl %eax, %ebp - movl %edx, 32(%esp) - andl %ebx, %ebp - leal 2400959708(%edx,%ecx,1),%edx - movl %esi, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - andl %eax, %ecx - orl %ecx, %ebp - movl %edi, %ecx - roll $5, %ecx - addl %ecx, %ebp - movl 36(%esp), %ecx - addl %ebp, %edx - movl 44(%esp), %ebp - xorl %ebp, %ecx - movl 4(%esp), %ebp - xorl %ebp, %ecx - movl 24(%esp), %ebp -.byte 209 -.byte 206 /* rorl $1 %esi */ - xorl %ebp, %ecx -.byte 209 -.byte 193 /* roll $1 %ecx */ - movl %edi, %ebp - movl %ecx, 36(%esp) - orl %esi, %ebp - leal 2400959708(%ecx,%ebx,1),%ecx - movl %edi, %ebx - andl %eax, %ebp - andl %esi, %ebx - orl %ebx, %ebp - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ebp -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ecx - /* 40_59 57 */ - /* 40_59 58 */ - movl 40(%esp), %ebx - movl 48(%esp), %ebp - xorl %ebp, %ebx - movl 8(%esp), %ebp - xorl %ebp, %ebx - movl 28(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - orl %edi, %ebp - movl %ebx, 40(%esp) - andl %esi, %ebp - leal 2400959708(%ebx,%eax,1),%ebx - movl %edx, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - andl %edi, %eax - orl %eax, %ebp - movl %ecx, %eax - roll $5, %eax - addl %eax, %ebp - movl 44(%esp), %eax - addl %ebp, %ebx - movl 52(%esp), %ebp - xorl %ebp, %eax - movl 12(%esp), %ebp - xorl %ebp, %eax - movl 32(%esp), %ebp -.byte 209 -.byte 202 /* rorl $1 %edx */ - xorl %ebp, %eax -.byte 209 -.byte 192 /* roll $1 %eax */ - movl %ecx, %ebp - movl %eax, 44(%esp) - orl %edx, %ebp - leal 2400959708(%eax,%esi,1),%eax - movl %ecx, %esi - andl %edi, %ebp - andl %edx, %esi - orl %esi, %ebp - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %ebp -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %eax - /* 40_59 59 */ - /* 20_39 60 */ - movl 48(%esp), %esi - movl 56(%esp), %ebp - xorl %ebp, %esi - movl 16(%esp), %ebp - xorl %ebp, %esi - movl 36(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - xorl %ecx, %ebp - movl %esi, 48(%esp) - xorl %edx, %ebp - leal 3395469782(%esi,%edi,1),%esi - movl %eax, %edi - roll $5, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %ebp, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %edi, %esi - /* 20_39 61 */ - movl 52(%esp), %edi - movl 60(%esp), %ebp - xorl %ebp, %edi - movl 20(%esp), %ebp - xorl %ebp, %edi - movl 40(%esp), %ebp - xorl %ebp, %edi - movl %eax, %ebp -.byte 209 -.byte 199 /* roll $1 %edi */ - xorl %ebx, %ebp - movl %edi, 52(%esp) - xorl %ecx, %ebp - leal 3395469782(%edi,%edx,1),%edi - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %edi - /* 20_39 62 */ - movl 56(%esp), %edx - movl (%esp), %ebp - xorl %ebp, %edx - movl 24(%esp), %ebp - xorl %ebp, %edx - movl 44(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - xorl %eax, %ebp - movl %edx, 56(%esp) - xorl %ebx, %ebp - leal 3395469782(%edx,%ecx,1),%edx - movl %edi, %ecx - roll $5, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ebp, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ecx, %edx - /* 20_39 63 */ - movl 60(%esp), %ecx - movl 4(%esp), %ebp - xorl %ebp, %ecx - movl 28(%esp), %ebp - xorl %ebp, %ecx - movl 48(%esp), %ebp - xorl %ebp, %ecx - movl %edi, %ebp -.byte 209 -.byte 193 /* roll $1 %ecx */ - xorl %esi, %ebp - movl %ecx, 60(%esp) - xorl %eax, %ebp - leal 3395469782(%ecx,%ebx,1),%ecx - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ecx - /* 20_39 64 */ - movl (%esp), %ebx - movl 8(%esp), %ebp - xorl %ebp, %ebx - movl 32(%esp), %ebp - xorl %ebp, %ebx - movl 52(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - xorl %edi, %ebp - movl %ebx, (%esp) - xorl %esi, %ebp - leal 3395469782(%ebx,%eax,1),%ebx - movl %ecx, %eax - roll $5, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %ebp, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %eax, %ebx - /* 20_39 65 */ - movl 4(%esp), %eax - movl 12(%esp), %ebp - xorl %ebp, %eax - movl 36(%esp), %ebp - xorl %ebp, %eax - movl 56(%esp), %ebp - xorl %ebp, %eax - movl %ecx, %ebp -.byte 209 -.byte 192 /* roll $1 %eax */ - xorl %edx, %ebp - movl %eax, 4(%esp) - xorl %edi, %ebp - leal 3395469782(%eax,%esi,1),%eax - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %eax - /* 20_39 66 */ - movl 8(%esp), %esi - movl 16(%esp), %ebp - xorl %ebp, %esi - movl 40(%esp), %ebp - xorl %ebp, %esi - movl 60(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - xorl %ecx, %ebp - movl %esi, 8(%esp) - xorl %edx, %ebp - leal 3395469782(%esi,%edi,1),%esi - movl %eax, %edi - roll $5, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %ebp, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %edi, %esi - /* 20_39 67 */ - movl 12(%esp), %edi - movl 20(%esp), %ebp - xorl %ebp, %edi - movl 44(%esp), %ebp - xorl %ebp, %edi - movl (%esp), %ebp - xorl %ebp, %edi - movl %eax, %ebp -.byte 209 -.byte 199 /* roll $1 %edi */ - xorl %ebx, %ebp - movl %edi, 12(%esp) - xorl %ecx, %ebp - leal 3395469782(%edi,%edx,1),%edi - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %edi - /* 20_39 68 */ - movl 16(%esp), %edx - movl 24(%esp), %ebp - xorl %ebp, %edx - movl 48(%esp), %ebp - xorl %ebp, %edx - movl 4(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - xorl %eax, %ebp - movl %edx, 16(%esp) - xorl %ebx, %ebp - leal 3395469782(%edx,%ecx,1),%edx - movl %edi, %ecx - roll $5, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ebp, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ecx, %edx - /* 20_39 69 */ - movl 20(%esp), %ecx - movl 28(%esp), %ebp - xorl %ebp, %ecx - movl 52(%esp), %ebp - xorl %ebp, %ecx - movl 8(%esp), %ebp - xorl %ebp, %ecx - movl %edi, %ebp -.byte 209 -.byte 193 /* roll $1 %ecx */ - xorl %esi, %ebp - movl %ecx, 20(%esp) - xorl %eax, %ebp - leal 3395469782(%ecx,%ebx,1),%ecx - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ecx - /* 20_39 70 */ - movl 24(%esp), %ebx - movl 32(%esp), %ebp - xorl %ebp, %ebx - movl 56(%esp), %ebp - xorl %ebp, %ebx - movl 12(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - xorl %edi, %ebp - movl %ebx, 24(%esp) - xorl %esi, %ebp - leal 3395469782(%ebx,%eax,1),%ebx - movl %ecx, %eax - roll $5, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %ebp, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %eax, %ebx - /* 20_39 71 */ - movl 28(%esp), %eax - movl 36(%esp), %ebp - xorl %ebp, %eax - movl 60(%esp), %ebp - xorl %ebp, %eax - movl 16(%esp), %ebp - xorl %ebp, %eax - movl %ecx, %ebp -.byte 209 -.byte 192 /* roll $1 %eax */ - xorl %edx, %ebp - movl %eax, 28(%esp) - xorl %edi, %ebp - leal 3395469782(%eax,%esi,1),%eax - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %eax - /* 20_39 72 */ - movl 32(%esp), %esi - movl 40(%esp), %ebp - xorl %ebp, %esi - movl (%esp), %ebp - xorl %ebp, %esi - movl 20(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - xorl %ecx, %ebp - movl %esi, 32(%esp) - xorl %edx, %ebp - leal 3395469782(%esi,%edi,1),%esi - movl %eax, %edi - roll $5, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %ebp, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %edi, %esi - /* 20_39 73 */ - movl 36(%esp), %edi - movl 44(%esp), %ebp - xorl %ebp, %edi - movl 4(%esp), %ebp - xorl %ebp, %edi - movl 24(%esp), %ebp - xorl %ebp, %edi - movl %eax, %ebp -.byte 209 -.byte 199 /* roll $1 %edi */ - xorl %ebx, %ebp - movl %edi, 36(%esp) - xorl %ecx, %ebp - leal 3395469782(%edi,%edx,1),%edi - movl %esi, %edx - roll $5, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %ebp, %edx -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %edi - /* 20_39 74 */ - movl 40(%esp), %edx - movl 48(%esp), %ebp - xorl %ebp, %edx - movl 8(%esp), %ebp - xorl %ebp, %edx - movl 28(%esp), %ebp - xorl %ebp, %edx - movl %esi, %ebp -.byte 209 -.byte 194 /* roll $1 %edx */ - xorl %eax, %ebp - movl %edx, 40(%esp) - xorl %ebx, %ebp - leal 3395469782(%edx,%ecx,1),%edx - movl %edi, %ecx - roll $5, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ebp, %ecx -.byte 209 -.byte 206 /* rorl $1 %esi */ - addl %ecx, %edx - /* 20_39 75 */ - movl 44(%esp), %ecx - movl 52(%esp), %ebp - xorl %ebp, %ecx - movl 12(%esp), %ebp - xorl %ebp, %ecx - movl 32(%esp), %ebp - xorl %ebp, %ecx - movl %edi, %ebp -.byte 209 -.byte 193 /* roll $1 %ecx */ - xorl %esi, %ebp - movl %ecx, 44(%esp) - xorl %eax, %ebp - leal 3395469782(%ecx,%ebx,1),%ecx - movl %edx, %ebx - roll $5, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebp, %ebx -.byte 209 -.byte 207 /* rorl $1 %edi */ - addl %ebx, %ecx - /* 20_39 76 */ - movl 48(%esp), %ebx - movl 56(%esp), %ebp - xorl %ebp, %ebx - movl 16(%esp), %ebp - xorl %ebp, %ebx - movl 36(%esp), %ebp - xorl %ebp, %ebx - movl %edx, %ebp -.byte 209 -.byte 195 /* roll $1 %ebx */ - xorl %edi, %ebp - movl %ebx, 48(%esp) - xorl %esi, %ebp - leal 3395469782(%ebx,%eax,1),%ebx - movl %ecx, %eax - roll $5, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %ebp, %eax -.byte 209 -.byte 202 /* rorl $1 %edx */ - addl %eax, %ebx - /* 20_39 77 */ - movl 52(%esp), %eax - movl 60(%esp), %ebp - xorl %ebp, %eax - movl 20(%esp), %ebp - xorl %ebp, %eax - movl 40(%esp), %ebp - xorl %ebp, %eax - movl %ecx, %ebp -.byte 209 -.byte 192 /* roll $1 %eax */ - xorl %edx, %ebp - movl %eax, 52(%esp) - xorl %edi, %ebp - leal 3395469782(%eax,%esi,1),%eax - movl %ebx, %esi - roll $5, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %ebp, %esi -.byte 209 -.byte 201 /* rorl $1 %ecx */ - addl %esi, %eax - /* 20_39 78 */ - movl 56(%esp), %esi - movl (%esp), %ebp - xorl %ebp, %esi - movl 24(%esp), %ebp - xorl %ebp, %esi - movl 44(%esp), %ebp - xorl %ebp, %esi - movl %ebx, %ebp -.byte 209 -.byte 198 /* roll $1 %esi */ - xorl %ecx, %ebp - movl %esi, 56(%esp) - xorl %edx, %ebp - leal 3395469782(%esi,%edi,1),%esi - movl %eax, %edi - roll $5, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %ebp, %edi -.byte 209 -.byte 203 /* rorl $1 %ebx */ - addl %edi, %esi - /* 20_39 79 */ - movl 60(%esp), %edi - movl 4(%esp), %ebp - xorl %ebp, %edi - movl 28(%esp), %ebp - xorl %ebp, %edi - movl 48(%esp), %ebp - xorl %ebp, %edi - movl %eax, %ebp -.byte 209 -.byte 199 /* roll $1 %edi */ - xorl %ebx, %ebp - movl %edi, 60(%esp) - xorl %ecx, %ebp - leal 3395469782(%edi,%edx,1),%edi - movl %esi, %edx - roll $5, %edx - addl %ebp, %edx - movl 92(%esp), %ebp -.byte 209 -.byte 200 /* rorl $1 %eax */ - addl %edx, %edi -.byte 209 -.byte 200 /* rorl $1 %eax */ - /* End processing */ - - movl 12(%ebp), %edx - addl %ebx, %edx - movl 4(%ebp), %ebx - addl %esi, %ebx - movl %eax, %esi - movl (%ebp), %eax - movl %edx, 12(%ebp) - addl %edi, %eax - movl 16(%ebp), %edi - addl %ecx, %edi - movl 8(%ebp), %ecx - addl %esi, %ecx - movl %eax, (%ebp) - movl 64(%esp), %esi - movl %ecx, 8(%ebp) - addl $64, %esi - movl 68(%esp), %eax - movl %edi, 16(%ebp) - cmpl %esi, %eax - movl %ebx, 4(%ebp) - jl .L001end - movl (%esi), %eax - jmp .L000start -.L001end: - addl $72, %esp - popl %edi - popl %ebx - popl %ebp - popl %esi - ret -.sha1_block_x86_end: - SIZE(sha1_block_x86,.sha1_block_x86_end-sha1_block_x86) -.ident "desasm.pl" diff --git a/src/lib/libcrypto/sha/sha.c b/src/lib/libcrypto/sha/sha.c index 713fec3610..42126551d1 100644 --- a/src/lib/libcrypto/sha/sha.c +++ b/src/lib/libcrypto/sha/sha.c @@ -58,23 +58,14 @@ #include #include -#include "sha.h" +#include #define BUFSIZE 1024*16 -#ifndef NOPROTO void do_fp(FILE *f); void pt(unsigned char *md); int read(int, void *, unsigned int); -#else -void do_fp(); -void pt(); -int read(); -#endif - -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int i,err=0; FILE *IN; @@ -102,8 +93,7 @@ char **argv; exit(err); } -void do_fp(f) -FILE *f; +void do_fp(FILE *f) { SHA_CTX c; unsigned char md[SHA_DIGEST_LENGTH]; @@ -123,8 +113,7 @@ FILE *f; pt(md); } -void pt(md) -unsigned char *md; +void pt(unsigned char *md) { int i; diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h index 4cf0ea0225..cd6960ee1a 100644 --- a/src/lib/libcrypto/sha/sha.h +++ b/src/lib/libcrypto/sha/sha.h @@ -63,45 +63,55 @@ extern "C" { #endif -#define SHA_CBLOCK 64 +#ifdef NO_SHA +#error SHA is disabled. +#endif + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then ! + * ! SHA_LONG_LOG2 has to be defined along. ! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + +#if defined(WIN16) || defined(__LP32__) +#define SHA_LONG unsigned long +#elif defined(_CRAY) || defined(__ILP64__) +#define SHA_LONG unsigned long +#define SHA_LONG_LOG2 3 +#else +#define SHA_LONG unsigned int +#endif + #define SHA_LBLOCK 16 -#define SHA_BLOCK 16 -#define SHA_LAST_BLOCK 56 -#define SHA_LENGTH_BLOCK 8 +#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a + * contiguous array of 32 bit + * wide big-endian values. */ +#define SHA_LAST_BLOCK (SHA_CBLOCK-8) #define SHA_DIGEST_LENGTH 20 typedef struct SHAstate_st { - unsigned long h0,h1,h2,h3,h4; - unsigned long Nl,Nh; - unsigned long data[SHA_LBLOCK]; + SHA_LONG h0,h1,h2,h3,h4; + SHA_LONG Nl,Nh; + SHA_LONG data[SHA_LBLOCK]; int num; } SHA_CTX; -#ifndef NOPROTO +#ifndef NO_SHA0 void SHA_Init(SHA_CTX *c); -void SHA_Update(SHA_CTX *c, unsigned char *data, unsigned long len); +void SHA_Update(SHA_CTX *c, const unsigned char *data, unsigned long len); void SHA_Final(unsigned char *md, SHA_CTX *c); -unsigned char *SHA(unsigned char *d, unsigned long n,unsigned char *md); +unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md); void SHA_Transform(SHA_CTX *c, unsigned char *data); +#endif +#ifndef NO_SHA1 void SHA1_Init(SHA_CTX *c); -void SHA1_Update(SHA_CTX *c, unsigned char *data, unsigned long len); +void SHA1_Update(SHA_CTX *c, const unsigned char *data, unsigned long len); void SHA1_Final(unsigned char *md, SHA_CTX *c); -unsigned char *SHA1(unsigned char *d, unsigned long n,unsigned char *md); +unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md); void SHA1_Transform(SHA_CTX *c, unsigned char *data); -#else -void SHA_Init(); -void SHA_Update(); -void SHA_Final(); -unsigned char *SHA(); -void SHA_Transform(); -void SHA1_Init(); -void SHA1_Update(); -void SHA1_Final(); -unsigned char *SHA1(); -void SHA1_Transform(); #endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/sha/sha1.c b/src/lib/libcrypto/sha/sha1.c index a4739ac9fd..d350c88ee4 100644 --- a/src/lib/libcrypto/sha/sha1.c +++ b/src/lib/libcrypto/sha/sha1.c @@ -58,23 +58,17 @@ #include #include -#include "sha.h" +#include #define BUFSIZE 1024*16 -#ifndef NOPROTO void do_fp(FILE *f); void pt(unsigned char *md); +#ifndef _OSD_POSIX int read(int, void *, unsigned int); -#else -void do_fp(); -void pt(); -int read(); #endif -int main(argc, argv) -int argc; -char **argv; +int main(int argc, char **argv) { int i,err=0; FILE *IN; @@ -102,8 +96,7 @@ char **argv; exit(err); } -void do_fp(f) -FILE *f; +void do_fp(FILE *f) { SHA_CTX c; unsigned char md[SHA_DIGEST_LENGTH]; @@ -123,8 +116,7 @@ FILE *f; pt(md); } -void pt(md) -unsigned char *md; +void pt(unsigned char *md) { int i; diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c index fe5770d601..861752eaa7 100644 --- a/src/lib/libcrypto/sha/sha1_one.c +++ b/src/lib/libcrypto/sha/sha1_one.c @@ -58,12 +58,10 @@ #include #include -#include "sha.h" +#include -unsigned char *SHA1(d, n, md) -unsigned char *d; -unsigned long n; -unsigned char *md; +#ifndef NO_SHA1 +unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md) { SHA_CTX c; static unsigned char m[SHA_DIGEST_LENGTH]; @@ -75,3 +73,4 @@ unsigned char *md; memset(&c,0,sizeof(c)); return(md); } +#endif diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c index 2b0ae1f0d4..66e885dd76 100644 --- a/src/lib/libcrypto/sha/sha1dgst.c +++ b/src/lib/libcrypto/sha/sha1dgst.c @@ -60,43 +60,35 @@ #include #undef SHA_0 #define SHA_1 -#include "sha.h" +#include #include "sha_locl.h" +#include -char *SHA1_version="SHA1 part of SSLeay 0.9.0b 29-Jun-1998"; +#ifndef NO_SHA1 +char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT; /* Implemented from SHA-1 document - The Secure Hash Algorithm */ -#define INIT_DATA_h0 (unsigned long)0x67452301L -#define INIT_DATA_h1 (unsigned long)0xefcdab89L -#define INIT_DATA_h2 (unsigned long)0x98badcfeL -#define INIT_DATA_h3 (unsigned long)0x10325476L -#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L +#define INIT_DATA_h0 0x67452301UL +#define INIT_DATA_h1 0xefcdab89UL +#define INIT_DATA_h2 0x98badcfeUL +#define INIT_DATA_h3 0x10325476UL +#define INIT_DATA_h4 0xc3d2e1f0UL -#define K_00_19 0x5a827999L -#define K_20_39 0x6ed9eba1L -#define K_40_59 0x8f1bbcdcL -#define K_60_79 0xca62c1d6L +#define K_00_19 0x5a827999UL +#define K_20_39 0x6ed9eba1UL +#define K_40_59 0x8f1bbcdcUL +#define K_60_79 0xca62c1d6UL -#ifndef NOPROTO -# ifdef SHA1_ASM - void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int num); -# define sha1_block sha1_block_x86 -# else - void sha1_block(SHA_CTX *c, register unsigned long *p, int num); -# endif +#ifdef SHA1_ASM + void sha1_block_x86(SHA_CTX *c, register SHA_LONG *p, int num); +# define sha1_block(c,p,n) sha1_block_x86((c),(p),(n)*SHA_CBLOCK) #else -# ifdef SHA1_ASM - void sha1_block_x86(); -# define sha1_block sha1_block_x86 -# else - void sha1_block(); -# endif + static void sha1_block(SHA_CTX *c, register SHA_LONG *p, int num); #endif - -#if defined(L_ENDIAN) && defined(SHA1_ASM) +#if !defined(B_ENDIAN) && defined(SHA1_ASM) # define M_c2nl c2l # define M_p_c2nl p_c2l # define M_c2nl_p c2l_p @@ -110,8 +102,7 @@ char *SHA1_version="SHA1 part of SSLeay 0.9.0b 29-Jun-1998"; # define M_nl2c nl2c #endif -void SHA1_Init(c) -SHA_CTX *c; +void SHA1_Init(SHA_CTX *c) { c->h0=INIT_DATA_h0; c->h1=INIT_DATA_h1; @@ -123,14 +114,12 @@ SHA_CTX *c; c->num=0; } -void SHA1_Update(c, data, len) -SHA_CTX *c; -register unsigned char *data; -unsigned long len; +void SHA1_Update(SHA_CTX *c, register const unsigned char *data, + unsigned long len) { - register ULONG *p; + register SHA_LONG *p; int ew,ec,sw,sc; - ULONG l; + SHA_LONG l; if (len == 0) return; @@ -158,7 +147,7 @@ unsigned long len; } len-=(SHA_CBLOCK-c->num); - sha1_block(c,p,64); + sha1_block(c,p,1); c->num=0; /* drop through and do the rest */ } @@ -195,15 +184,15 @@ unsigned long len; * copies it to a local array. I should be able to do this for * the C version as well.... */ -#if 1 +#if SHA_LONG_LOG2==2 #if defined(B_ENDIAN) || defined(SHA1_ASM) - if ((((unsigned int)data)%sizeof(ULONG)) == 0) + if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0) { sw=len/SHA_CBLOCK; if (sw) { + sha1_block(c,(SHA_LONG *)data,sw); sw*=SHA_CBLOCK; - sha1_block(c,(ULONG *)data,sw); data+=sw; len-=sw; } @@ -215,35 +204,61 @@ unsigned long len; p=c->data; while (len >= SHA_CBLOCK) { -#if defined(B_ENDIAN) || defined(L_ENDIAN) - if (p != (unsigned long *)data) +#if SHA_LONG_LOG2==2 +#if defined(B_ENDIAN) || defined(SHA1_ASM) +#define SHA_NO_TAIL_CODE + /* + * Basically we get here only when data happens + * to be unaligned. + */ + if (p != (SHA_LONG *)data) memcpy(p,data,SHA_CBLOCK); data+=SHA_CBLOCK; -# ifdef L_ENDIAN -# ifndef SHA1_ASM /* Will not happen */ - for (sw=(SHA_LBLOCK/4); sw; sw--) + sha1_block(c,p=c->data,1); + len-=SHA_CBLOCK; +#elif defined(L_ENDIAN) +#define BE_COPY(dst,src,i) { \ + l = ((SHA_LONG *)src)[i]; \ + Endian_Reverse32(l); \ + dst[i] = l; \ + } + if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0) { - Endian_Reverse32(p[0]); - Endian_Reverse32(p[1]); - Endian_Reverse32(p[2]); - Endian_Reverse32(p[3]); - p+=4; + for (sw=(SHA_LBLOCK/4); sw; sw--) + { + BE_COPY(p,data,0); + BE_COPY(p,data,1); + BE_COPY(p,data,2); + BE_COPY(p,data,3); + p+=4; + data += 4*sizeof(SHA_LONG); + } + sha1_block(c,p=c->data,1); + len-=SHA_CBLOCK; + continue; } +#endif +#endif +#ifndef SHA_NO_TAIL_CODE + /* + * In addition to "sizeof(SHA_LONG)!= 4" case the + * following code covers unaligned access cases on + * little-endian machines. + * + */ p=c->data; -# endif -# endif -#else - for (sw=(SHA_BLOCK/4); sw; sw--) + for (sw=(SHA_LBLOCK/4); sw; sw--) { - M_c2nl(data,l); *(p++)=l; - M_c2nl(data,l); *(p++)=l; - M_c2nl(data,l); *(p++)=l; - M_c2nl(data,l); *(p++)=l; + M_c2nl(data,l); p[0]=l; + M_c2nl(data,l); p[1]=l; + M_c2nl(data,l); p[2]=l; + M_c2nl(data,l); p[3]=l; + p+=4; } p=c->data; -#endif - sha1_block(c,p,64); + sha1_block(c,p,1); len-=SHA_CBLOCK; +#endif } ec=(int)len; c->num=ec; @@ -256,52 +271,61 @@ unsigned long len; p[sw]=l; } -void SHA1_Transform(c,b) -SHA_CTX *c; -unsigned char *b; +void SHA1_Transform(SHA_CTX *c, unsigned char *b) { - ULONG p[16]; -#ifndef B_ENDIAN - ULONG *q; - int i; -#endif + SHA_LONG p[SHA_LBLOCK]; -#if defined(B_ENDIAN) || defined(L_ENDIAN) - memcpy(p,b,64); -#ifdef L_ENDIAN - q=p; - for (i=(SHA_LBLOCK/4); i; i--) +#if SHA_LONG_LOG2==2 +#if defined(B_ENDIAN) || defined(SHA1_ASM) + memcpy(p,b,SHA_CBLOCK); + sha1_block(c,p,1); + return; +#elif defined(L_ENDIAN) + if (((unsigned long)b%sizeof(SHA_LONG)) == 0) { - Endian_Reverse32(q[0]); - Endian_Reverse32(q[1]); - Endian_Reverse32(q[2]); - Endian_Reverse32(q[3]); - q+=4; + SHA_LONG *q; + int i; + + q=p; + for (i=(SHA_LBLOCK/4); i; i--) + { + unsigned long l; + BE_COPY(q,b,0); /* BE_COPY was defined above */ + BE_COPY(q,b,1); + BE_COPY(q,b,2); + BE_COPY(q,b,3); + q+=4; + b+=4*sizeof(SHA_LONG); + } + sha1_block(c,p,1); + return; } #endif -#else - q=p; - for (i=(SHA_LBLOCK/4); i; i--) +#endif +#ifndef SHA_NO_TAIL_CODE /* defined above, see comment */ { - ULONG l; - c2nl(b,l); *(q++)=l; - c2nl(b,l); *(q++)=l; - c2nl(b,l); *(q++)=l; - c2nl(b,l); *(q++)=l; - } + SHA_LONG *q; + int i; + + q=p; + for (i=(SHA_LBLOCK/4); i; i--) + { + SHA_LONG l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + } + sha1_block(c,p,1); + } #endif - sha1_block(c,p,64); } #ifndef SHA1_ASM - -void sha1_block(c, W, num) -SHA_CTX *c; -register unsigned long *W; -int num; +static void sha1_block(SHA_CTX *c, register SHA_LONG *W, int num) { - register ULONG A,B,C,D,E,T; - ULONG X[16]; + register SHA_LONG A,B,C,D,E,T; + SHA_LONG X[SHA_LBLOCK]; A=c->h0; B=c->h1; @@ -401,8 +425,7 @@ int num; c->h3=(c->h3+B)&0xffffffffL; c->h4=(c->h4+C)&0xffffffffL; - num-=64; - if (num <= 0) break; + if (--num <= 0) break; A=c->h0; B=c->h1; @@ -410,18 +433,21 @@ int num; D=c->h3; E=c->h4; - W+=16; + W+=SHA_LBLOCK; /* Note! This can happen only when sizeof(SHA_LONG) + * is 4. Whenever it's not the actual case this + * function is never called with num larger than 1 + * and we never advance down here. + * + */ } } #endif -void SHA1_Final(md, c) -unsigned char *md; -SHA_CTX *c; +void SHA1_Final(unsigned char *md, SHA_CTX *c) { register int i,j; - register ULONG l; - register ULONG *p; + register SHA_LONG l; + register SHA_LONG *p; static unsigned char end[4]={0x80,0x00,0x00,0x00}; unsigned char *cp=end; @@ -441,18 +467,20 @@ SHA_CTX *c; { for (; iNh; p[SHA_LBLOCK-1]=c->Nl; -#if defined(L_ENDIAN) && defined(SHA1_ASM) +#if SHA_LONG_LOG2==2 +#if !defined(B_ENDIAN) && defined(SHA1_ASM) Endian_Reverse32(p[SHA_LBLOCK-2]); Endian_Reverse32(p[SHA_LBLOCK-1]); #endif - sha1_block(c,p,64); +#endif + sha1_block(c,p,1); cp=md; l=c->h0; nl2c(l,cp); l=c->h1; nl2c(l,cp); @@ -460,9 +488,11 @@ SHA_CTX *c; l=c->h3; nl2c(l,cp); l=c->h4; nl2c(l,cp); - /* clear stuff, sha1_block may be leaving some stuff on the stack - * but I'm not worried :-) */ c->num=0; -/* memset((char *)&c,0,sizeof(c));*/ + /* sha_block may be leaving some stuff on the stack + * but I'm not worried :-) + memset((void *)c,0,sizeof(SHA_CTX)); + */ } +#endif diff --git a/src/lib/libcrypto/sha/sha1s.cpp b/src/lib/libcrypto/sha/sha1s.cpp index 0163377de6..3103e1871b 100644 --- a/src/lib/libcrypto/sha/sha1s.cpp +++ b/src/lib/libcrypto/sha/sha1s.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include #include -#include "sha.h" +#include extern "C" { void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num); diff --git a/src/lib/libcrypto/sha/sha1test.c b/src/lib/libcrypto/sha/sha1test.c index 3c62a218b4..9400ad2a61 100644 --- a/src/lib/libcrypto/sha/sha1test.c +++ b/src/lib/libcrypto/sha/sha1test.c @@ -59,7 +59,19 @@ #include #include #include -#include "sha.h" + +#ifdef NO_SHA +int main(int argc, char *argv[]) +{ + printf("No SHA support\n"); + return(0); +} +#else +#include + +#ifdef CHARSET_EBCDIC +#include +#endif #undef SHA_0 /* FIPS 180 */ #define SHA_1 /* FIPS 180-1 */ @@ -87,15 +99,8 @@ char *bigret= "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; #endif -#ifndef NOPROTO static char *pt(unsigned char *md); -#else -static char *pt(); -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,err=0; unsigned char **P,**R; @@ -104,6 +109,11 @@ char *argv[]; SHA_CTX c; unsigned char md[SHA_DIGEST_LENGTH]; +#ifdef CHARSET_EBCDIC + ebcdic2ascii(test[0], test[0], strlen(test[0])); + ebcdic2ascii(test[1], test[1], strlen(test[1])); +#endif + P=(unsigned char **)test; R=(unsigned char **)ret; i=1; @@ -124,6 +134,9 @@ char *argv[]; } memset(buf,'a',1000); +#ifdef CHARSET_EBCDIC + ebcdic2ascii(buf, buf, 1000); +#endif /*CHARSET_EBCDIC*/ SHA1_Init(&c); for (i=0; i<1000; i++) SHA1_Update(&c,buf,1000); @@ -143,8 +156,7 @@ char *argv[]; return(0); } -static char *pt(md) -unsigned char *md; +static char *pt(unsigned char *md) { int i; static char buf[80]; @@ -153,3 +165,4 @@ unsigned char *md; sprintf(&(buf[i*2]),"%02x",md[i]); return(buf); } +#endif diff --git a/src/lib/libcrypto/sha/sha_dgst.c b/src/lib/libcrypto/sha/sha_dgst.c index 8ed533ea26..4df535360f 100644 --- a/src/lib/libcrypto/sha/sha_dgst.c +++ b/src/lib/libcrypto/sha/sha_dgst.c @@ -60,39 +60,44 @@ #include #define SHA_0 #undef SHA_1 -#include "sha.h" +#include #include "sha_locl.h" +#include -char *SHA_version="SHA part of SSLeay 0.9.0b 29-Jun-1998"; +#ifndef NO_SHA0 +char *SHA_version="SHA" OPENSSL_VERSION_PTEXT; /* Implemented from SHA-0 document - The Secure Hash Algorithm */ -#define INIT_DATA_h0 (unsigned long)0x67452301L -#define INIT_DATA_h1 (unsigned long)0xefcdab89L -#define INIT_DATA_h2 (unsigned long)0x98badcfeL -#define INIT_DATA_h3 (unsigned long)0x10325476L -#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L +#define INIT_DATA_h0 0x67452301UL +#define INIT_DATA_h1 0xefcdab89UL +#define INIT_DATA_h2 0x98badcfeUL +#define INIT_DATA_h3 0x10325476UL +#define INIT_DATA_h4 0xc3d2e1f0UL -#define K_00_19 0x5a827999L -#define K_20_39 0x6ed9eba1L -#define K_40_59 0x8f1bbcdcL -#define K_60_79 0xca62c1d6L +#define K_00_19 0x5a827999UL +#define K_20_39 0x6ed9eba1UL +#define K_40_59 0x8f1bbcdcUL +#define K_60_79 0xca62c1d6UL -#ifndef NOPROTO - void sha_block(SHA_CTX *c, register unsigned long *p, int num); +static void sha_block(SHA_CTX *c, register SHA_LONG *p, int num); + +#if !defined(B_ENDIAN) && defined(SHA_ASM) +# define M_c2nl c2l +# define M_p_c2nl p_c2l +# define M_c2nl_p c2l_p +# define M_p_c2nl_p p_c2l_p +# define M_nl2c l2c #else - void sha_block(); +# define M_c2nl c2nl +# define M_p_c2nl p_c2nl +# define M_c2nl_p c2nl_p +# define M_p_c2nl_p p_c2nl_p +# define M_nl2c nl2c #endif -#define M_c2nl c2nl -#define M_p_c2nl p_c2nl -#define M_c2nl_p c2nl_p -#define M_p_c2nl_p p_c2nl_p -#define M_nl2c nl2c - -void SHA_Init(c) -SHA_CTX *c; +void SHA_Init(SHA_CTX *c) { c->h0=INIT_DATA_h0; c->h1=INIT_DATA_h1; @@ -104,14 +109,12 @@ SHA_CTX *c; c->num=0; } -void SHA_Update(c, data, len) -SHA_CTX *c; -register unsigned char *data; -unsigned long len; +void SHA_Update(SHA_CTX *c, register const unsigned char *data, + unsigned long len) { - register ULONG *p; + register SHA_LONG *p; int ew,ec,sw,sc; - ULONG l; + SHA_LONG l; if (len == 0) return; @@ -139,7 +142,7 @@ unsigned long len; } len-=(SHA_CBLOCK-c->num); - sha_block(c,p,64); + sha_block(c,p,1); c->num=0; /* drop through and do the rest */ } @@ -176,15 +179,15 @@ unsigned long len; * copies it to a local array. I should be able to do this for * the C version as well.... */ -#if 1 +#if SHA_LONG_LOG2==2 #if defined(B_ENDIAN) || defined(SHA_ASM) - if ((((unsigned int)data)%sizeof(ULONG)) == 0) + if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0) { sw=len/SHA_CBLOCK; if (sw) { + sha_block(c,(SHA_LONG *)data,sw); sw*=SHA_CBLOCK; - sha_block(c,(ULONG *)data,sw); data+=sw; len-=sw; } @@ -196,35 +199,61 @@ unsigned long len; p=c->data; while (len >= SHA_CBLOCK) { -#if defined(B_ENDIAN) || defined(L_ENDIAN) - if (p != (unsigned long *)data) +#if SHA_LONG_LOG2==2 +#if defined(B_ENDIAN) || defined(SHA_ASM) +#define SHA_NO_TAIL_CODE + /* + * Basically we get here only when data happens + * to be unaligned. + */ + if (p != (SHA_LONG *)data) memcpy(p,data,SHA_CBLOCK); data+=SHA_CBLOCK; -# ifdef L_ENDIAN -# ifndef SHA_ASM /* Will not happen */ - for (sw=(SHA_LBLOCK/4); sw; sw--) + sha_block(c,p=c->data,1); + len-=SHA_CBLOCK; +#elif defined(L_ENDIAN) +#define BE_COPY(dst,src,i) { \ + l = ((SHA_LONG *)src)[i]; \ + Endian_Reverse32(l); \ + dst[i] = l; \ + } + if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0) { - Endian_Reverse32(p[0]); - Endian_Reverse32(p[1]); - Endian_Reverse32(p[2]); - Endian_Reverse32(p[3]); - p+=4; + for (sw=(SHA_LBLOCK/4); sw; sw--) + { + BE_COPY(p,data,0); + BE_COPY(p,data,1); + BE_COPY(p,data,2); + BE_COPY(p,data,3); + p+=4; + data += 4*sizeof(SHA_LONG); + } + sha_block(c,p=c->data,1); + len-=SHA_CBLOCK; + continue; } +#endif +#endif +#ifndef SHA_NO_TAIL_CODE + /* + * In addition to "sizeof(SHA_LONG)!= 4" case the + * following code covers unaligned access cases on + * little-endian machines. + * + */ p=c->data; -# endif -# endif -#else - for (sw=(SHA_BLOCK/4); sw; sw--) + for (sw=(SHA_LBLOCK/4); sw; sw--) { - M_c2nl(data,l); *(p++)=l; - M_c2nl(data,l); *(p++)=l; - M_c2nl(data,l); *(p++)=l; - M_c2nl(data,l); *(p++)=l; + M_c2nl(data,l); p[0]=l; + M_c2nl(data,l); p[1]=l; + M_c2nl(data,l); p[2]=l; + M_c2nl(data,l); p[3]=l; + p+=4; } p=c->data; -#endif - sha_block(c,p,64); + sha_block(c,p,1); len-=SHA_CBLOCK; +#endif } ec=(int)len; c->num=ec; @@ -237,50 +266,61 @@ unsigned long len; p[sw]=l; } -void SHA_Transform(c,b) -SHA_CTX *c; -unsigned char *b; +void SHA_Transform(SHA_CTX *c, unsigned char *b) { - ULONG p[16]; -#if !defined(B_ENDIAN) - ULONG *q; - int i; -#endif + SHA_LONG p[SHA_LBLOCK]; -#if defined(B_ENDIAN) || defined(L_ENDIAN) - memcpy(p,b,64); -#ifdef L_ENDIAN - q=p; - for (i=(SHA_LBLOCK/4); i; i--) +#if SHA_LONG_LOG2==2 +#if defined(B_ENDIAN) || defined(SHA_ASM) + memcpy(p,b,SHA_CBLOCK); + sha_block(c,p,1); + return; +#elif defined(L_ENDIAN) + if (((unsigned long)b%sizeof(SHA_LONG)) == 0) { - Endian_Reverse32(q[0]); - Endian_Reverse32(q[1]); - Endian_Reverse32(q[2]); - Endian_Reverse32(q[3]); - q+=4; + SHA_LONG *q; + int i; + + q=p; + for (i=(SHA_LBLOCK/4); i; i--) + { + unsigned long l; + BE_COPY(q,b,0); /* BE_COPY was defined above */ + BE_COPY(q,b,1); + BE_COPY(q,b,2); + BE_COPY(q,b,3); + q+=4; + b+=4*sizeof(SHA_LONG); + } + sha_block(c,p,1); + return; } #endif -#else - q=p; - for (i=(SHA_LBLOCK/4); i; i--) +#endif +#ifndef SHA_NO_TAIL_CODE /* defined above, see comment */ { - ULONG l; - c2nl(b,l); *(q++)=l; - c2nl(b,l); *(q++)=l; - c2nl(b,l); *(q++)=l; - c2nl(b,l); *(q++)=l; - } + SHA_LONG *q; + int i; + + q=p; + for (i=(SHA_LBLOCK/4); i; i--) + { + SHA_LONG l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + c2nl(b,l); *(q++)=l; + } + sha_block(c,p,1); + } #endif - sha_block(c,p,64); } -void sha_block(c, W, num) -SHA_CTX *c; -register unsigned long *W; -int num; +#ifndef SHA_ASM +static void sha_block(SHA_CTX *c, register SHA_LONG *W, int num) { - register ULONG A,B,C,D,E,T; - ULONG X[16]; + register SHA_LONG A,B,C,D,E,T; + SHA_LONG X[SHA_LBLOCK]; A=c->h0; B=c->h1; @@ -380,8 +420,7 @@ int num; c->h3=(c->h3+B)&0xffffffffL; c->h4=(c->h4+C)&0xffffffffL; - num-=64; - if (num <= 0) break; + if (--num <= 0) break; A=c->h0; B=c->h1; @@ -389,17 +428,21 @@ int num; D=c->h3; E=c->h4; - W+=16; + W+=SHA_LBLOCK; /* Note! This can happen only when sizeof(SHA_LONG) + * is 4. Whenever it's not the actual case this + * function is never called with num larger than 1 + * and we never advance down here. + * + */ } } +#endif -void SHA_Final(md, c) -unsigned char *md; -SHA_CTX *c; +void SHA_Final(unsigned char *md, SHA_CTX *c) { register int i,j; - register ULONG l; - register ULONG *p; + register SHA_LONG l; + register SHA_LONG *p; static unsigned char end[4]={0x80,0x00,0x00,0x00}; unsigned char *cp=end; @@ -419,14 +462,20 @@ SHA_CTX *c; { for (; iNh; p[SHA_LBLOCK-1]=c->Nl; - sha_block(c,p,64); +#if SHA_LONG_LOG2==2 +#if !defined(B_ENDIAN) && defined(SHA_ASM) + Endian_Reverse32(p[SHA_LBLOCK-2]); + Endian_Reverse32(p[SHA_LBLOCK-1]); +#endif +#endif + sha_block(c,p,1); cp=md; l=c->h0; nl2c(l,cp); l=c->h1; nl2c(l,cp); @@ -434,9 +483,10 @@ SHA_CTX *c; l=c->h3; nl2c(l,cp); l=c->h4; nl2c(l,cp); - /* clear stuff, sha_block may be leaving some stuff on the stack - * but I'm not worried :-) */ c->num=0; -/* memset((char *)&c,0,sizeof(c));*/ + /* sha_block may be leaving some stuff on the stack + * but I'm not worried :-) + memset((void *)c,0,sizeof(SHA_CTX)); + */ } - +#endif diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h index 2814ad15fa..6646a8915b 100644 --- a/src/lib/libcrypto/sha/sha_locl.h +++ b/src/lib/libcrypto/sha/sha_locl.h @@ -59,6 +59,8 @@ #include #include +#include + #ifdef undef /* one or the other needs to be defined */ #ifndef SHA_1 /* FIPE 180-1 */ @@ -66,14 +68,6 @@ #endif #endif -#define ULONG unsigned long -#define UCHAR unsigned char -#define UINT unsigned int - -#ifdef NOCONST -#define const -#endif - #undef c2nl #define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ l|=(((unsigned long)(*((c)++)))<<16), \ @@ -166,30 +160,79 @@ *((c)++)=(unsigned char)(((l)>>16)&0xff), \ *((c)++)=(unsigned char)(((l)>>24)&0xff)) +#ifndef SHA_LONG_LOG2 +#define SHA_LONG_LOG2 2 /* default to 32 bits */ +#endif + #undef ROTATE +#undef Endian_Reverse32 #if defined(WIN32) #define ROTATE(a,n) _lrotl(a,n) -#else -#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) +#elif defined(__GNUC__) && !defined(PEDANTIC) +/* some inline assembler templates by */ +#if defined(__i386) && !defined(NO_ASM) +#define ROTATE(a,n) ({ register unsigned int ret; \ + asm ("roll %1,%0" \ + : "=r"(ret) \ + : "I"(n), "0"(a) \ + : "cc"); \ + ret; \ + }) +#ifndef I386_ONLY +#define Endian_Reverse32(a) \ + { register unsigned int ltmp=(a); \ + asm ("bswapl %0" \ + : "=r"(ltmp) : "0"(ltmp)); \ + (a)=ltmp; \ + } +#endif +#elif defined(__powerpc) +#define ROTATE(a,n) ({ register unsigned int ret; \ + asm ("rlwinm %0,%1,%2,0,31" \ + : "=r"(ret) \ + : "r"(a), "I"(n)); \ + ret; \ + }) +/* Endian_Reverse32 is not needed for PowerPC */ +#endif #endif /* A nice byte order reversal from Wei Dai */ -#if defined(WIN32) +#ifdef ROTATE +#ifndef Endian_Reverse32 /* 5 instructions with rotate instruction, else 9 */ #define Endian_Reverse32(a) \ { \ - unsigned long l=(a); \ - (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ + unsigned long t=(a); \ + (a)=((ROTATE(t,8)&0x00FF00FF)|(ROTATE((t&0x00FF00FF),24))); \ } +#endif #else +#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) +#ifndef Endian_Reverse32 /* 6 instructions with rotate instruction, else 8 */ #define Endian_Reverse32(a) \ { \ - unsigned long l=(a); \ - l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ - (a)=ROTATE(l,16L); \ + unsigned long t=(a); \ + t=(((t>>8)&0x00FF00FF)|((t&0x00FF00FF)<<8)); \ + (a)=ROTATE(t,16); \ } #endif +/* + * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|... + * It's rewritten as above for two reasons: + * - RISCs aren't good at long constants and have to explicitely + * compose 'em with several (well, usually 2) instructions in a + * register before performing the actual operation and (as you + * already realized:-) having same constant should inspire the + * compiler to permanently allocate the only register for it; + * - most modern CPUs have two ALUs, but usually only one has + * circuitry for shifts:-( this minor tweak inspires compiler + * to schedule shift instructions in a better way... + * + * + */ +#endif /* As pointed out by Wei Dai , F() below can be * simplified to the code in F_00_19. Wei attributes these optimisations @@ -203,13 +246,12 @@ #define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) #define F_60_79(b,c,d) F_20_39(b,c,d) -#ifdef SHA_0 #undef Xupdate +#ifdef SHA_0 #define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\ (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]); #endif #ifdef SHA_1 -#undef Xupdate #define Xupdate(a,i,ia,ib,ic,id) (a)=\ (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\ X[(i)&0x0f]=(a)=ROTATE((a),1); diff --git a/src/lib/libcrypto/sha/sha_one.c b/src/lib/libcrypto/sha/sha_one.c index 18ab7f61bc..2d955de162 100644 --- a/src/lib/libcrypto/sha/sha_one.c +++ b/src/lib/libcrypto/sha/sha_one.c @@ -58,12 +58,10 @@ #include #include -#include "sha.h" +#include -unsigned char *SHA(d, n, md) -unsigned char *d; -unsigned long n; -unsigned char *md; +#ifndef NO_SHA0 +unsigned char *SHA(const unsigned char *d, unsigned long n, unsigned char *md) { SHA_CTX c; static unsigned char m[SHA_DIGEST_LENGTH]; @@ -75,3 +73,4 @@ unsigned char *md; memset(&c,0,sizeof(c)); return(md); } +#endif diff --git a/src/lib/libcrypto/sha/sha_sgst.c b/src/lib/libcrypto/sha/sha_sgst.c deleted file mode 100644 index 8a16801328..0000000000 --- a/src/lib/libcrypto/sha/sha_sgst.c +++ /dev/null @@ -1,246 +0,0 @@ -/* crypto/sha/sha_sgst.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include - -#ifdef undef -/* one or the other needs to be defined */ -#ifndef SHA_1 /* FIPE 180-1 */ -#define SHA_0 /* FIPS 180 */ -#endif -#endif - -#define ULONG unsigned long -#define UCHAR unsigned char -#define UINT unsigned int - -#ifdef NOCONST -#define const -#endif - -#undef c2nl -#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++))) )) - -#undef p_c2nl -#define p_c2nl(c,l,n) { \ - switch (n) { \ - case 0: l =((unsigned long)(*((c)++)))<<24; \ - case 1: l|=((unsigned long)(*((c)++)))<<16; \ - case 2: l|=((unsigned long)(*((c)++)))<< 8; \ - case 3: l|=((unsigned long)(*((c)++))); \ - } \ - } - -#undef c2nl_p -/* NOTE the pointer is not incremented at the end of this */ -#define c2nl_p(c,l,n) { \ - l=0; \ - (c)+=n; \ - switch (n) { \ - case 3: l =((unsigned long)(*(--(c))))<< 8; \ - case 2: l|=((unsigned long)(*(--(c))))<<16; \ - case 1: l|=((unsigned long)(*(--(c))))<<24; \ - } \ - } - -#undef p_c2nl_p -#define p_c2nl_p(c,l,sc,len) { \ - switch (sc) \ - { \ - case 0: l =((unsigned long)(*((c)++)))<<24; \ - if (--len == 0) break; \ - case 1: l|=((unsigned long)(*((c)++)))<<16; \ - if (--len == 0) break; \ - case 2: l|=((unsigned long)(*((c)++)))<< 8; \ - } \ - } - -#undef nl2c -#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l) )&0xff)) - -#undef c2l -#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<<24)) - -#undef p_c2l -#define p_c2l(c,l,n) { \ - switch (n) { \ - case 0: l =((unsigned long)(*((c)++))); \ - case 1: l|=((unsigned long)(*((c)++)))<< 8; \ - case 2: l|=((unsigned long)(*((c)++)))<<16; \ - case 3: l|=((unsigned long)(*((c)++)))<<24; \ - } \ - } - -#undef c2l_p -/* NOTE the pointer is not incremented at the end of this */ -#define c2l_p(c,l,n) { \ - l=0; \ - (c)+=n; \ - switch (n) { \ - case 3: l =((unsigned long)(*(--(c))))<<16; \ - case 2: l|=((unsigned long)(*(--(c))))<< 8; \ - case 1: l|=((unsigned long)(*(--(c)))); \ - } \ - } - -#undef p_c2l_p -#define p_c2l_p(c,l,sc,len) { \ - switch (sc) \ - { \ - case 0: l =((unsigned long)(*((c)++))); \ - if (--len == 0) break; \ - case 1: l|=((unsigned long)(*((c)++)))<< 8; \ - if (--len == 0) break; \ - case 2: l|=((unsigned long)(*((c)++)))<<16; \ - } \ - } - -#undef l2c -#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>>24)&0xff)) - -#undef ROTATE -#if defined(WIN32) -#define ROTATE(a,n) _lrotl(a,n) -#else -#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) -#endif - -/* A nice byte order reversal from Wei Dai */ -#if defined(WIN32) -/* 5 instructions with rotate instruction, else 9 */ -#define Endian_Reverse32(a) \ - { \ - unsigned long l=(a); \ - (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ - } -#else -/* 6 instructions with rotate instruction, else 8 */ -#define Endian_Reverse32(a) \ - { \ - unsigned long l=(a); \ - l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ - (a)=ROTATE(l,16L); \ - } -#endif - -/* As pointed out by Wei Dai , F() below can be - * simplified to the code in F_00_19. Wei attributes these optimisations - * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. - * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) - * I've just become aware of another tweak to be made, again from Wei Dai, - * in F_40_59, (x&a)|(y&a) -> (x|y)&a - */ -#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) -#define F_20_39(b,c,d) ((b) ^ (c) ^ (d)) -#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) -#define F_60_79(b,c,d) F_20_39(b,c,d) - -#ifdef SHA_0 -#undef Xupdate -#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\ - (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]); -#endif -#ifdef SHA_1 -#undef Xupdate -#define Xupdate(a,i,ia,ib,ic,id) (a)=\ - (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\ - X[(i)&0x0f]=(a)=ROTATE((a),1); -#endif - -#define BODY_00_15(i,a,b,c,d,e,f,xa) \ - (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \ - Xupdate(f,i,xa,xb,xc,xd); \ - (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \ - Xupdate(f,i,xa,xb,xc,xd); \ - (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_32_39(i,a,b,c,d,e,f,xa) \ - Xupdate(f,i,xa,xa,xa,xa); \ - (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_40_59(i,a,b,c,d,e,f,xa) \ - Xupdate(f,i,xa,xa,xa,xa); \ - (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \ - (b)=ROTATE((b),30); - -#define BODY_60_79(i,a,b,c,d,e,f,xa) \ - Xupdate(f,i,xa,xa,xa,xa); \ - (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \ - (b)=ROTATE((b),30); - diff --git a/src/lib/libcrypto/sha/shatest.c b/src/lib/libcrypto/sha/shatest.c index 03816e9b39..2b0744d937 100644 --- a/src/lib/libcrypto/sha/shatest.c +++ b/src/lib/libcrypto/sha/shatest.c @@ -59,7 +59,19 @@ #include #include #include -#include "sha.h" + +#ifdef NO_SHA +int main(int argc, char *argv[]) +{ + printf("No SHA support\n"); + return(0); +} +#else +#include + +#ifdef CHARSET_EBCDIC +#include +#endif #define SHA_0 /* FIPS 180 */ #undef SHA_1 /* FIPS 180-1 */ @@ -87,15 +99,8 @@ char *bigret= "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; #endif -#ifndef NOPROTO static char *pt(unsigned char *md); -#else -static char *pt(); -#endif - -int main(argc,argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { int i,err=0; unsigned char **P,**R; @@ -104,6 +109,11 @@ char *argv[]; SHA_CTX c; unsigned char md[SHA_DIGEST_LENGTH]; +#ifdef CHARSET_EBCDIC + ebcdic2ascii(test[0], test[0], strlen(test[0])); + ebcdic2ascii(test[1], test[1], strlen(test[1])); +#endif + P=(unsigned char **)test; R=(unsigned char **)ret; i=1; @@ -124,6 +134,9 @@ char *argv[]; } memset(buf,'a',1000); +#ifdef CHARSET_EBCDIC + ebcdic2ascii(buf, buf, 1000); +#endif /*CHARSET_EBCDIC*/ SHA_Init(&c); for (i=0; i<1000; i++) SHA_Update(&c,buf,1000); @@ -143,8 +156,7 @@ char *argv[]; return(0); } -static char *pt(md) -unsigned char *md; +static char *pt(unsigned char *md) { int i; static char buf[80]; @@ -153,3 +165,4 @@ unsigned char *md; sprintf(&(buf[i*2]),"%02x",md[i]); return(buf); } +#endif diff --git a/src/lib/libcrypto/stack/Makefile.ssl b/src/lib/libcrypto/stack/Makefile.ssl index 0d232c08cf..82b36ca624 100644 --- a/src/lib/libcrypto/stack/Makefile.ssl +++ b/src/lib/libcrypto/stack/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -25,7 +27,7 @@ LIBOBJ=stack.o SRC= $(LIBSRC) -EXHEADER= stack.h +EXHEADER= stack.h safestack.h HEADER= $(EXHEADER) ALL= $(GENERAL) $(SRC) $(HEADER) @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,19 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +stack.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +stack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +stack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +stack.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +stack.o: ../../include/openssl/stack.h ../cryptlib.h diff --git a/src/lib/libcrypto/stack/safestack.h b/src/lib/libcrypto/stack/safestack.h new file mode 100644 index 0000000000..38934981e3 --- /dev/null +++ b/src/lib/libcrypto/stack/safestack.h @@ -0,0 +1,129 @@ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@openssl.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.openssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#ifndef HEADER_SAFESTACK_H +#define HEADER_SAFESTACK_H + +#include + +#define STACK_OF(type) STACK_##type + +#define DECLARE_STACK_OF(type) \ +typedef struct stack_st_##type \ + { \ + STACK stack; \ + } STACK_OF(type); \ +STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)); \ +STACK_OF(type) *sk_##type##_new_null(void); \ +void sk_##type##_free(STACK_OF(type) *sk); \ +int sk_##type##_num(const STACK_OF(type) *sk); \ +type *sk_##type##_value(const STACK_OF(type) *sk,int n); \ +type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v); \ +void sk_##type##_zero(STACK_OF(type) *sk); \ +int sk_##type##_push(STACK_OF(type) *sk,type *v); \ +int sk_##type##_unshift(STACK_OF(type) *sk,type *v); \ +int sk_##type##_find(STACK_OF(type) *sk,type *v); \ +type *sk_##type##_delete(STACK_OF(type) *sk,int n); \ +void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v); \ +int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n); \ +int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \ + int (*cmp)(type **,type **)))(type **,type **); \ +STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk); \ +void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)); \ +type *sk_##type##_shift(STACK_OF(type) *sk); \ +type *sk_##type##_pop(STACK_OF(type) *sk); \ +void sk_##type##_sort(STACK_OF(type) *sk); + +#define IMPLEMENT_STACK_OF(type) \ +STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)) \ + { return (STACK_OF(type) *)sk_new(cmp); } \ +STACK_OF(type) *sk_##type##_new_null() \ + { return (STACK_OF(type) *)sk_new_null(); } \ +void sk_##type##_free(STACK_OF(type) *sk) \ + { sk_free((STACK *)sk); } \ +int sk_##type##_num(const STACK_OF(type) *sk) \ + { return M_sk_num((const STACK *)sk); } \ +type *sk_##type##_value(const STACK_OF(type) *sk,int n) \ + { return (type *)sk_value((STACK *)sk,n); } \ +type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v) \ + { return (type *)(sk_set((STACK *)sk,n,(char *)v)); } \ +void sk_##type##_zero(STACK_OF(type) *sk) \ + { sk_zero((STACK *)sk); } \ +int sk_##type##_push(STACK_OF(type) *sk,type *v) \ + { return sk_push((STACK *)sk,(char *)v); } \ +int sk_##type##_unshift(STACK_OF(type) *sk,type *v) \ + { return sk_unshift((STACK *)sk,(char *)v); } \ +int sk_##type##_find(STACK_OF(type) *sk,type *v) \ + { return sk_find((STACK *)sk,(char *)v); } \ +type *sk_##type##_delete(STACK_OF(type) *sk,int n) \ + { return (type *)sk_delete((STACK *)sk,n); } \ +void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v) \ + { sk_delete_ptr((STACK *)sk,(char *)v); } \ +int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n) \ + { return sk_insert((STACK *)sk,(char *)v,n); } \ +int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \ + int (*cmp)(type **,type **)))(type **,type **) \ + { return (int (*)(type **,type **))sk_set_cmp_func((STACK *)sk,cmp); } \ +STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk) \ + { return (STACK_OF(type) *)sk_dup((STACK *)sk); } \ +void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)) \ + { sk_pop_free((STACK *)sk,func); } \ +type *sk_##type##_shift(STACK_OF(type) *sk) \ + { return (type *)sk_shift((STACK *)sk); } \ +type *sk_##type##_pop(STACK_OF(type) *sk) \ + { return (type *)sk_pop((STACK *)sk); } \ +void sk_##type##_sort(STACK_OF(type) *sk) \ + { sk_sort((STACK *)sk); } + +#endif /* ndef HEADER_SAFESTACK_H */ diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c index 610ccbb756..8b96713884 100644 --- a/src/lib/libcrypto/stack/stack.c +++ b/src/lib/libcrypto/stack/stack.c @@ -67,32 +67,28 @@ */ #include #include "cryptlib.h" -#include "stack.h" +#include #undef MIN_NODES #define MIN_NODES 4 -char *STACK_version="STACK part of SSLeay 0.9.0b 29-Jun-1998"; +const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT; -#ifndef NOPROTO #define FP_ICC (int (*)(const void *,const void *)) -#else -#define FP_ICC -#endif - #include -void sk_set_cmp_func(sk,c) -STACK *sk; -int (*c)(); +int (*sk_set_cmp_func(STACK *sk, int (*c)()))(void) { + int (*old)()=sk->comp; + if (sk->comp != c) sk->sorted=0; sk->comp=c; + + return old; } -STACK *sk_dup(sk) -STACK *sk; +STACK *sk_dup(STACK *sk) { STACK *ret; char **s; @@ -113,8 +109,7 @@ err: return(NULL); } -STACK *sk_new(c) -int (*c)(); +STACK *sk_new(int (*c)()) { STACK *ret; int i; @@ -136,13 +131,11 @@ err0: return(NULL); } -int sk_insert(st,data,loc) -STACK *st; -char *data; -int loc; +int sk_insert(STACK *st, char *data, int loc) { char **s; + if(st == NULL) return 0; if (st->num_alloc <= st->num+1) { s=(char **)Realloc((char *)st->data, @@ -161,7 +154,7 @@ int loc; f=(char **)st->data; t=(char **)&(st->data[1]); - for (i=st->num; i>loc; i--) + for (i=st->num; i>=loc; i--) t[i]=f[i]; #ifdef undef /* no memmove on sunos :-( */ @@ -176,9 +169,7 @@ int loc; return(st->num); } -char *sk_delete_ptr(st,p) -STACK *st; -char *p; +char *sk_delete_ptr(STACK *st, char *p) { int i; @@ -188,14 +179,13 @@ char *p; return(NULL); } -char *sk_delete(st,loc) -STACK *st; -int loc; +char *sk_delete(STACK *st, int loc) { char *ret; int i,j; - if ((st->num == 0) || (loc < 0) || (loc >= st->num)) return(NULL); + if ((st == NULL) || (st->num == 0) || (loc < 0) + || (loc >= st->num)) return(NULL); ret=st->data[loc]; if (loc != st->num-1) @@ -213,13 +203,12 @@ int loc; return(ret); } -int sk_find(st,data) -STACK *st; -char *data; +int sk_find(STACK *st, char *data) { char **r; int i; int (*comp_func)(); + if(st == NULL) return -1; if (st->comp == NULL) { @@ -228,13 +217,9 @@ char *data; return(i); return(-1); } - comp_func=(int (*)())st->comp; - if (!st->sorted) - { - qsort((char *)st->data,st->num,sizeof(char *),FP_ICC comp_func); - st->sorted=1; - } + sk_sort(st); if (data == NULL) return(-1); + comp_func=(int (*)())st->comp; r=(char **)bsearch(&data,(char *)st->data, st->num,sizeof(char *),FP_ICC comp_func); if (r == NULL) return(-1); @@ -245,38 +230,31 @@ char *data; return(i); } -int sk_push(st,data) -STACK *st; -char *data; +int sk_push(STACK *st, char *data) { return(sk_insert(st,data,st->num)); } -int sk_unshift(st,data) -STACK *st; -char *data; +int sk_unshift(STACK *st, char *data) { return(sk_insert(st,data,0)); } -char *sk_shift(st) -STACK *st; +char *sk_shift(STACK *st) { if (st == NULL) return(NULL); if (st->num <= 0) return(NULL); return(sk_delete(st,0)); } -char *sk_pop(st) -STACK *st; +char *sk_pop(STACK *st) { if (st == NULL) return(NULL); if (st->num <= 0) return(NULL); return(sk_delete(st,st->num-1)); } -void sk_zero(st) -STACK *st; +void sk_zero(STACK *st) { if (st == NULL) return; if (st->num <= 0) return; @@ -284,9 +262,7 @@ STACK *st; st->num=0; } -void sk_pop_free(st,func) -STACK *st; -void (*func)(); +void sk_pop_free(STACK *st, void (*func)()) { int i; @@ -297,11 +273,39 @@ void (*func)(); sk_free(st); } -void sk_free(st) -STACK *st; +void sk_free(STACK *st) { if (st == NULL) return; if (st->data != NULL) Free((char *)st->data); Free((char *)st); } +int sk_num(STACK *st) +{ + if(st == NULL) return -1; + return st->num; +} + +char *sk_value(STACK *st, int i) +{ + if(st == NULL) return NULL; + return st->data[i]; +} + +char *sk_set(STACK *st, int i, char *value) +{ + if(st == NULL) return NULL; + return (st->data[i] = value); +} + +void sk_sort(STACK *st) + { + if (!st->sorted) + { + int (*comp_func)(); + + comp_func=(int (*)())st->comp; + qsort(st->data,st->num,sizeof(char *),FP_ICC comp_func); + st->sorted=1; + } + } diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h index 615eb6ff94..0f825cc0c4 100644 --- a/src/lib/libcrypto/stack/stack.h +++ b/src/lib/libcrypto/stack/stack.h @@ -73,11 +73,16 @@ typedef struct stack_st int (*comp)(); } STACK; -#define sk_num(sk) ((sk)->num) -#define sk_value(sk,n) ((sk)->data[n]) #define sk_new_null() sk_new(NULL) -#ifndef NOPROTO + +#define M_sk_num(sk) ((sk)->num) +#define M_sk_value(sk,n) ((sk)->data[n]) + +int sk_num(STACK *); +char *sk_value(STACK *, int); + +char *sk_set(STACK *, int, char *); STACK *sk_new(int (*cmp)()); void sk_free(STACK *); @@ -91,27 +96,9 @@ int sk_unshift(STACK *st,char *data); char *sk_shift(STACK *st); char *sk_pop(STACK *st); void sk_zero(STACK *st); -void sk_set_cmp_func(STACK *sk, int (*c)()); +int (*sk_set_cmp_func(STACK *sk, int (*c)()))(); STACK *sk_dup(STACK *st); - -#else - -STACK *sk_new(); -void sk_free(); -void sk_pop_free(); -int sk_insert(); -char *sk_delete(); -char *sk_delete_ptr(); -int sk_find(); -int sk_push(); -int sk_unshift(); -char *sk_shift(); -char *sk_pop(); -void sk_zero(); -void sk_set_cmp_func(); -STACK *sk_dup(); - -#endif +void sk_sort(STACK *st); #ifdef __cplusplus } diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c index be395f2bc4..142623edda 100644 --- a/src/lib/libcrypto/threads/mttest.c +++ b/src/lib/libcrypto/threads/mttest.c @@ -74,13 +74,13 @@ #include #include #endif -#include "lhash.h" -#include "crypto.h" -#include "buffer.h" +#include +#include +#include #include "../e_os.h" -#include "x509.h" -#include "ssl.h" -#include "err.h" +#include +#include +#include #ifdef NO_FP_API #define APPS_WIN16 @@ -92,7 +92,6 @@ #define MAX_THREAD_NUMBER 100 -#ifndef NOPROTO int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, int error,char *arg); void thread_setup(void); @@ -108,23 +107,6 @@ unsigned long irix_thread_id(void ); unsigned long solaris_thread_id(void ); unsigned long pthreads_thread_id(void ); -#else -int MS_CALLBACK verify_callback(); -void thread_setup(); -void thread_cleanup(); -void do_threads(); - -void irix_locking_callback(); -void solaris_locking_callback(); -void win32_locking_callback(); -void pthreads_locking_callback(); - -unsigned long irix_thread_id(); -unsigned long solaris_thread_id(); -unsigned long pthreads_thread_id(); - -#endif - BIO *bio_err=NULL; BIO *bio_stdout=NULL; @@ -139,15 +121,8 @@ int number_of_loops=10; int reconnect=0; int cache_stats=0; -#ifndef NOPROTO int doit(char *ctx[4]); -#else -int doit(); -#endif - -static void print_stats(fp,ctx) -FILE *fp; -SSL_CTX *ctx; +static void print_stats(FILE *fp, SSL_CTX *ctx) { fprintf(fp,"%4ld items in the session cache\n", SSL_CTX_sess_number(ctx)); @@ -164,7 +139,7 @@ SSL_CTX *ctx; fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx)); } -static void sv_usage() +static void sv_usage(void) { fprintf(stderr,"usage: ssltest [args ...]\n"); fprintf(stderr,"\n"); @@ -182,9 +157,7 @@ static void sv_usage() fprintf(stderr," -ssl3 - just SSLv3n\n"); } -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { char *CApath=NULL,*CAfile=NULL; int badop=0; @@ -358,8 +331,7 @@ end: #define C_DONE 1 #define S_DONE 2 -int ndoit(ssl_ctx) -SSL_CTX *ssl_ctx[2]; +int ndoit(SSL_CTX *ssl_ctx[2]) { int i; int ret; @@ -405,8 +377,7 @@ SSL_CTX *ssl_ctx[2]; return(0); } -int doit(ctx) -char *ctx[4]; +int doit(char *ctx[4]) { SSL_CTX *s_ctx,*c_ctx; static char cbuf[200],sbuf[200]; @@ -681,13 +652,8 @@ err: return(0); } -int MS_CALLBACK verify_callback(ok, xs, xi, depth, error, arg) -int ok; -X509 *xs; -X509 *xi; -int depth; -int error; -char *arg; +int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, + int error, char *arg) { char buf[256]; @@ -708,7 +674,7 @@ char *arg; static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; -void thread_setup() +void thread_setup(void) { int i; @@ -721,7 +687,7 @@ void thread_setup() /* id callback defined */ } -void thread_cleanup() +void thread_cleanup(void) { int i; @@ -730,11 +696,7 @@ void thread_cleanup() CloseHandle(lock_cs[i]); } -void win32_locking_callback(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void win32_locking_callback(int mode, int type, char *file, int line) { if (mode & CRYPTO_LOCK) { @@ -746,8 +708,7 @@ int line; } } -void do_threads(s_ctx,c_ctx) -SSL_CTX *s_ctx,*c_ctx; +void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) { double ret; SSL_CTX *ssl_ctx[2]; @@ -806,7 +767,7 @@ static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; /*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */ static long lock_count[CRYPTO_NUM_LOCKS]; -void thread_setup() +void thread_setup(void) { int i; @@ -821,7 +782,7 @@ void thread_setup() CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); } -void thread_cleanup() +void thread_cleanup(void) { int i; @@ -836,11 +797,7 @@ fprintf(stderr,"cleanup\n"); fprintf(stderr,"done cleanup\n"); } -void solaris_locking_callback(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void solaris_locking_callback(int mode, int type, char *file, int line) { #ifdef undef fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", @@ -872,8 +829,7 @@ if (CRYPTO_LOCK_SSL_CERT == type) } } -void do_threads(s_ctx,c_ctx) -SSL_CTX *s_ctx,*c_ctx; +void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) { SSL_CTX *ssl_ctx[2]; thread_t thread_ctx[MAX_THREAD_NUMBER]; @@ -902,7 +858,7 @@ SSL_CTX *s_ctx,*c_ctx; s_ctx->references,c_ctx->references); } -unsigned long solaris_thread_id() +unsigned long solaris_thread_id(void) { unsigned long ret; @@ -917,7 +873,7 @@ unsigned long solaris_thread_id() static usptr_t *arena; static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; -void thread_setup() +void thread_setup(void) { int i; char filename[20]; @@ -941,7 +897,7 @@ void thread_setup() CRYPTO_set_locking_callback((void (*)())irix_locking_callback); } -void thread_cleanup() +void thread_cleanup(void) { int i; @@ -956,11 +912,7 @@ void thread_cleanup() } } -void irix_locking_callback(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void irix_locking_callback(int mode, int type, char *file, int line) { if (mode & CRYPTO_LOCK) { @@ -974,8 +926,7 @@ int line; } } -void do_threads(s_ctx,c_ctx) -SSL_CTX *s_ctx,*c_ctx; +void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) { SSL_CTX *ssl_ctx[2]; int thread_ctx[MAX_THREAD_NUMBER]; @@ -1000,7 +951,7 @@ SSL_CTX *s_ctx,*c_ctx; s_ctx->references,c_ctx->references); } -unsigned long irix_thread_id() +unsigned long irix_thread_id(void) { unsigned long ret; @@ -1014,7 +965,7 @@ unsigned long irix_thread_id() static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; static long lock_count[CRYPTO_NUM_LOCKS]; -void thread_setup() +void thread_setup(void) { int i; @@ -1028,7 +979,7 @@ void thread_setup() CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); } -void thread_cleanup() +void thread_cleanup(void) { int i; @@ -1043,11 +994,8 @@ void thread_cleanup() fprintf(stderr,"done cleanup\n"); } -void pthreads_locking_callback(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void pthreads_locking_callback(int mode, int type, char *file, + int line) { #ifdef undef fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", @@ -1072,8 +1020,7 @@ int line; } } -void do_threads(s_ctx,c_ctx) -SSL_CTX *s_ctx,*c_ctx; +void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) { SSL_CTX *ssl_ctx[2]; pthread_t thread_ctx[MAX_THREAD_NUMBER]; @@ -1101,7 +1048,7 @@ SSL_CTX *s_ctx,*c_ctx; s_ctx->references,c_ctx->references); } -unsigned long pthreads_thread_id() +unsigned long pthreads_thread_id(void) { unsigned long ret; diff --git a/src/lib/libcrypto/threads/th-lock.c b/src/lib/libcrypto/threads/th-lock.c index 039022446d..afb4f4caf2 100644 --- a/src/lib/libcrypto/threads/th-lock.c +++ b/src/lib/libcrypto/threads/th-lock.c @@ -74,15 +74,14 @@ #include #include #endif -#include "lhash.h" -#include "crypto.h" -#include "buffer.h" -#include "e_os.h" -#include "x509.h" -#include "ssl.h" -#include "err.h" - -#ifndef NOPROTO +#include +#include +#include +#include +#include +#include +#include + int CRYPTO_thread_setup(void); void CRYPTO_thread_cleanup(void); @@ -95,21 +94,6 @@ static unsigned long irix_thread_id(void ); static unsigned long solaris_thread_id(void ); static unsigned long pthreads_thread_id(void ); -#else -int CRYPOTO_thread_setup(); -void CRYPTO_cleanup(); - -static void irix_locking_callback(); -static void solaris_locking_callback(); -static void win32_locking_callback(); -static void pthreads_locking_callback(); - -static unsigned long irix_thread_id(); -static unsigned long solaris_thread_id(); -static unsigned long pthreads_thread_id(); - -#endif - /* usage: * CRYPTO_thread_setup(); * applicaion code @@ -122,7 +106,7 @@ static unsigned long pthreads_thread_id(); static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; -int CRYPTO_thread_setup() +int CRYPTO_thread_setup(void) { int i; @@ -136,7 +120,7 @@ int CRYPTO_thread_setup() return(1); } -static void CRYPTO_thread_cleanup() +static void CRYPTO_thread_cleanup(void) { int i; @@ -145,11 +129,7 @@ static void CRYPTO_thread_cleanup() CloseHandle(lock_cs[i]); } -void win32_locking_callback(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void win32_locking_callback(int mode, int type, char *file, int line) { if (mode & CRYPTO_LOCK) { @@ -174,7 +154,7 @@ static long lock_count[CRYPTO_NUM_LOCKS]; static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; #endif -void CRYPTO_thread_setup() +void CRYPTO_thread_setup(void) { int i; @@ -192,7 +172,7 @@ void CRYPTO_thread_setup() CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); } -void CRYPTO_thread_cleanup() +void CRYPTO_thread_cleanup(void) { int i; @@ -207,11 +187,7 @@ void CRYPTO_thread_cleanup() } } -void solaris_locking_callback(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void solaris_locking_callback(int mode, int type, char *file, int line) { #if 0 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", @@ -248,7 +224,7 @@ int line; } } -unsigned long solaris_thread_id() +unsigned long solaris_thread_id(void) { unsigned long ret; @@ -263,7 +239,7 @@ unsigned long solaris_thread_id() static usptr_t *arena; static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; -void CRYPTO_thread_setup() +void CRYPTO_thread_setup(void) { int i; char filename[20]; @@ -287,7 +263,7 @@ void CRYPTO_thread_setup() CRYPTO_set_locking_callback((void (*)())irix_locking_callback); } -void CRYPTO_thread_cleanup() +void CRYPTO_thread_cleanup(void) { int i; @@ -302,11 +278,7 @@ void CRYPTO_thread_cleanup() } } -void irix_locking_callback(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void irix_locking_callback(int mode, int type, char *file, int line) { if (mode & CRYPTO_LOCK) { @@ -318,7 +290,7 @@ int line; } } -unsigned long irix_thread_id() +unsigned long irix_thread_id(void) { unsigned long ret; @@ -333,7 +305,7 @@ unsigned long irix_thread_id() static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; static long lock_count[CRYPTO_NUM_LOCKS]; -void CRYPTO_thread_setup() +void CRYPTO_thread_setup(void) { int i; @@ -347,7 +319,7 @@ void CRYPTO_thread_setup() CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); } -void thread_cleanup() +void thread_cleanup(void) { int i; @@ -358,11 +330,8 @@ void thread_cleanup() } } -void pthreads_locking_callback(mode,type,file,line) -int mode; -int type; -char *file; -int line; +void pthreads_locking_callback(int mode, int type, char *file, + int line) { #if 0 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", @@ -387,7 +356,7 @@ int line; } } -unsigned long pthreads_thread_id() +unsigned long pthreads_thread_id(void) { unsigned long ret; diff --git a/src/lib/libcrypto/tmdiff.c b/src/lib/libcrypto/tmdiff.c index b93799fc03..0ad8a9ed8d 100644 --- a/src/lib/libcrypto/tmdiff.c +++ b/src/lib/libcrypto/tmdiff.c @@ -57,32 +57,40 @@ */ #include #include +#include "cryptlib.h" +#include + +#ifdef TIMEB +#undef WIN32 +#undef TIMES +#endif #ifndef MSDOS # ifndef WIN32 -# define TIMES +# if !defined(VMS) || defined(__DECC) +# define TIMES +# endif # endif #endif -#ifndef VMS -# ifndef _IRIX -# include -# endif -# ifdef TIMES -# include -# include -# endif -#else /* VMS */ -# include - struct tms { - time_t tms_utime; - time_t tms_stime; - time_t tms_uchild; /* I dunno... */ - time_t tms_uchildsys; /* so these names are a guess :-) */ - } -#endif /* VMS */ - -#ifdef sun +#ifndef _IRIX +# include +#endif +#ifdef TIMES +# include +# include +#endif + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES +#endif + +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include #include #endif @@ -99,11 +107,7 @@ #ifndef HZ # ifndef CLK_TCK # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ -# ifndef VMS -# define HZ 100.0 -# else /* VMS */ -# define HZ 100.0 -# endif +# define HZ 100.0 # else /* _BSD_CLK_TCK_ */ # define HZ ((double)_BSD_CLK_TCK_) # endif @@ -126,11 +130,11 @@ typedef struct ms_tm #endif } MS_TM; -char *ms_time_init() +char *ms_time_new(void) { MS_TM *ret; - ret=malloc(sizeof(MS_TM)); + ret=(MS_TM *)Malloc(sizeof(MS_TM)); if (ret == NULL) return(NULL); memset(ret,0,sizeof(MS_TM)); @@ -140,34 +144,31 @@ char *ms_time_init() return((char *)ret); } -void ms_time_final(a) -char *a; +void ms_time_free(char *a) { if (a != NULL) - free(a); + Free(a); } -void ms_time_get(a) -char *a; +void ms_time_get(char *a) { MS_TM *tm=(MS_TM *)a; - FILETIME tmpa,tmpb,tmpc; +#ifdef WIN32 + FILETIME tmpa,tmpb,tmpc; +#endif #ifdef TIMES - printf("AAA\n"); times(&tm->ms_tms); #else # ifdef WIN32 GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32)); # else - printf("CCC\n"); - ftime(tm->ms_timeb); + ftime(&tm->ms_timeb); # endif #endif } -double ms_time_diff(ap,bp) -char *ap,*bp; +double ms_time_diff(char *ap, char *bp) { MS_TM *a=(MS_TM *)ap; MS_TM *b=(MS_TM *)bp; @@ -177,19 +178,30 @@ char *ap,*bp; ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ; #else # ifdef WIN32 - ret =(double)(b->ms_win32.dwHighDateTime&0x000fffff)*10+ - b->ms_win32.dwLowDateTime/1e7; - ret-=(double)(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; + { +#ifdef __GNUC__ + signed long long la,lb; +#else + signed _int64 la,lb; +#endif + la=a->ms_win32.dwHighDateTime; + lb=b->ms_win32.dwHighDateTime; + la<<=32; + lb<<=32; + la+=a->ms_win32.dwLowDateTime; + lb+=b->ms_win32.dwLowDateTime; + ret=((double)(lb-la))/1e7; + } # else - ret= (double)(b->time-a->time)+ - ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0; + ret= (double)(b->ms_timeb.time-a->ms_timeb.time)+ + (((double)b->ms_timeb.millitm)- + ((double)a->ms_timeb.millitm))/1000.0; # endif #endif return((ret < 0.0000001)?0.0000001:ret); } -int ms_time_cmp(ap,bp) -char *ap,*bp; +int ms_time_cmp(char *ap, char *bp) { MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp; double d; @@ -202,8 +214,8 @@ char *ap,*bp; d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7; d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; # else - d= (double)(b->time-a->time)+ - ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0; + d= (double)(b->ms_timeb.time-a->ms_timeb.time)+ + (((double)b->ms_timeb.millitm)-(double)a->ms_timeb.millitm)/1000.0; # endif #endif if (d == 0.0) diff --git a/src/lib/libcrypto/tmdiff.h b/src/lib/libcrypto/tmdiff.h new file mode 100644 index 0000000000..41a8a1e0e0 --- /dev/null +++ b/src/lib/libcrypto/tmdiff.h @@ -0,0 +1,81 @@ +/* crypto/tmdiff.h */ +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) + * All rights reserved. + * + * This package is an SSL implementation written + * by Eric Young (eay@cryptsoft.com). + * The implementation was written so as to conform with Netscapes SSL. + * + * This library is free for commercial and non-commercial use as long as + * the following conditions are aheared to. The following conditions + * apply to all code found in this distribution, be it the RC4, RSA, + * lhash, DES, etc., code; not just the SSL code. The SSL documentation + * included with this distribution is covered by the same copyright terms + * except that the holder is Tim Hudson (tjh@cryptsoft.com). + * + * Copyright remains Eric Young's, and as such any Copyright notices in + * the code are not to be removed. + * If this package is used in a product, Eric Young should be given attribution + * as the author of the parts of the library used. + * This can be in the form of a textual message at program startup or + * in documentation (online or textual) provided with the package. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * "This product includes cryptographic software written by + * Eric Young (eay@cryptsoft.com)" + * The word 'cryptographic' can be left out if the rouines from the library + * being used are not cryptographic related :-). + * 4. If you include any Windows specific code (or a derivative thereof) from + * the apps directory (application code) you must include an acknowledgement: + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" + * + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * The licence and distribution terms for any publically available version or + * derivative of this code cannot be changed. i.e. this code cannot simply be + * copied and put under another distribution licence + * [including the GNU Public Licence.] + */ + +/* Header for dynamic hash table routines + * Author - Eric Young + */ + +#ifndef HEADER_TMDIFF_H +#define HEADER_TMDIFF_H + +#ifdef __cplusplus +extern "C" { +#endif + +char *ms_time_new(void ); +void ms_time_free(char *a); +void ms_time_get(char *a); +double ms_time_diff(char *start,char *end); +int ms_time_cmp(char *ap,char *bp); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/src/lib/libcrypto/txt_db/Makefile.ssl b/src/lib/libcrypto/txt_db/Makefile.ssl index 76e511534f..552ea5580f 100644 --- a/src/lib/libcrypto/txt_db/Makefile.ssl +++ b/src/lib/libcrypto/txt_db/Makefile.ssl @@ -7,9 +7,11 @@ TOP= ../.. CC= cc INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -37,24 +39,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -66,15 +67,20 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +txt_db.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h +txt_db.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h +txt_db.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +txt_db.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h +txt_db.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h +txt_db.o: ../../include/openssl/txt_db.h ../cryptlib.h diff --git a/src/lib/libcrypto/txt_db/txt_db.c b/src/lib/libcrypto/txt_db/txt_db.c index e34ce4efa9..9a9fa5ce55 100644 --- a/src/lib/libcrypto/txt_db/txt_db.c +++ b/src/lib/libcrypto/txt_db/txt_db.c @@ -60,17 +60,15 @@ #include #include #include "cryptlib.h" -#include "buffer.h" -#include "txt_db.h" +#include +#include #undef BUFSIZE #define BUFSIZE 512 -char *TXT_DB_version="TXT_DB part of SSLeay 0.9.0b 29-Jun-1998"; +const char *TXT_DB_version="TXT_DB" OPENSSL_VERSION_PTEXT; -TXT_DB *TXT_DB_read(in,num) -BIO *in; -int num; +TXT_DB *TXT_DB_read(BIO *in, int num) { TXT_DB *ret=NULL; int er=1; @@ -158,7 +156,7 @@ int num; if ((n != num) || (*f != '\0')) { #if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */ - fprintf(stderr,"wrong number of fields on line %ld\n",ln); + fprintf(stderr,"wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f); #endif er=2; goto err; @@ -191,10 +189,7 @@ err: return(ret); } -char **TXT_DB_get_by_index(db,idx,value) -TXT_DB *db; -int idx; -char **value; +char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value) { char **ret; LHASH *lh; @@ -215,12 +210,8 @@ char **value; return(ret); } -int TXT_DB_create_index(db,field,qual,hash,cmp) -TXT_DB *db; -int field; -int (*qual)(); -unsigned long (*hash)(); -int (*cmp)(); +int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(), + unsigned long (*hash)(), int (*cmp)()) { LHASH *idx; char *r; @@ -256,9 +247,7 @@ int (*cmp)(); return(1); } -long TXT_DB_write(out,db) -BIO *out; -TXT_DB *db; +long TXT_DB_write(BIO *out, TXT_DB *db) { long i,j,n,nn,l,tot=0; char *p,**pp,*f; @@ -306,9 +295,7 @@ err: return(ret); } -int TXT_DB_insert(db,row) -TXT_DB *db; -char **row; +int TXT_DB_insert(TXT_DB *db, char **row) { int i; char **r; @@ -350,12 +337,14 @@ err: return(0); } -void TXT_DB_free(db) -TXT_DB *db; +void TXT_DB_free(TXT_DB *db) { int i,n; char **p,*max; + if(db == NULL) + return; + if (db->index != NULL) { for (i=db->num_fields-1; i>=0; i--) diff --git a/src/lib/libcrypto/txt_db/txt_db.h b/src/lib/libcrypto/txt_db/txt_db.h index aca6dae393..58b9de1353 100644 --- a/src/lib/libcrypto/txt_db/txt_db.h +++ b/src/lib/libcrypto/txt_db/txt_db.h @@ -63,8 +63,8 @@ extern "C" { #endif -#include "stack.h" -#include "lhash.h" +#include +#include #define DB_ERROR_OK 0 #define DB_ERROR_MALLOC 1 @@ -85,7 +85,6 @@ typedef struct txt_db_st char **arg_row; } TXT_DB; -#ifndef NOPROTO #ifdef HEADER_BIO_H TXT_DB *TXT_DB_read(BIO *in, int num); long TXT_DB_write(BIO *out, TXT_DB *db); @@ -99,17 +98,6 @@ void TXT_DB_free(TXT_DB *db); char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value); int TXT_DB_insert(TXT_DB *db,char **value); -#else - -TXT_DB *TXT_DB_read(); -long TXT_DB_write(); -int TXT_DB_create_index(); -void TXT_DB_free(); -char **TXT_DB_get_by_index(); -int TXT_DB_insert(); - -#endif - #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/util/add_cr.pl b/src/lib/libcrypto/util/add_cr.pl index ddd6d61e2d..c7b62c11ec 100644 --- a/src/lib/libcrypto/util/add_cr.pl +++ b/src/lib/libcrypto/util/add_cr.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # This adds a copyright message to a souce code file. # It also gets the file name correct. diff --git a/src/lib/libcrypto/util/ck_errf.pl b/src/lib/libcrypto/util/ck_errf.pl index c5764e40df..7a24d6c5a2 100644 --- a/src/lib/libcrypto/util/ck_errf.pl +++ b/src/lib/libcrypto/util/ck_errf.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # This is just a quick script to scan for cases where the 'error' # function name in a XXXerr() macro is wrong. @@ -40,5 +40,6 @@ foreach $file (@ARGV) # print "$func:$1\n"; } } + close(IN); } diff --git a/src/lib/libcrypto/util/clean-depend.pl b/src/lib/libcrypto/util/clean-depend.pl new file mode 100644 index 0000000000..af676af751 --- /dev/null +++ b/src/lib/libcrypto/util/clean-depend.pl @@ -0,0 +1,38 @@ +#!/usr/local/bin/perl -w +# Clean the dependency list in a makefile of standard includes... +# Written by Ben Laurie 19 Jan 1999 + +use strict; + +while() { + print; + last if /^# DO NOT DELETE THIS LINE/; +} + +my %files; + +while() { + my ($file,$deps)=/^(.*): (.*)$/; + next if !defined $deps; + my @deps=split ' ',$deps; + @deps=grep(!/^\/usr\/include/,@deps); + @deps=grep(!/^\/usr\/lib\/gcc-lib/,@deps); + push @{$files{$file}},@deps; +} + +my $file; +foreach $file (sort keys %files) { + my $len=0; + my $dep; + foreach $dep (sort @{$files{$file}}) { + $len=0 if $len+length($dep)+1 >= 80; + if($len == 0) { + print "\n$file:"; + $len=length($file)+1; + } + print " $dep"; + $len+=length($dep)+1; + } +} + +print "\n"; diff --git a/src/lib/libcrypto/util/deleof.pl b/src/lib/libcrypto/util/deleof.pl index 04f30f0e47..155acd88ff 100644 --- a/src/lib/libcrypto/util/deleof.pl +++ b/src/lib/libcrypto/util/deleof.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl while (<>) { diff --git a/src/lib/libcrypto/util/do_ms.sh b/src/lib/libcrypto/util/do_ms.sh index f498d842b7..515b074cff 100644 --- a/src/lib/libcrypto/util/do_ms.sh +++ b/src/lib/libcrypto/util/do_ms.sh @@ -5,11 +5,13 @@ PATH=util:../util:$PATH -# perl util/mk1mf.pl VC-MSDOS no-sock >ms/msdos.mak +# perl util/mk1mf.pl no-sock VC-MSDOS >ms/msdos.mak # perl util/mk1mf.pl VC-W31-32 >ms/w31.mak -perl util/mk1mf.pl VC-WIN16 dll >ms/w31dll.mak +perl util/mk1mf.pl dll VC-WIN16 >ms/w31dll.mak # perl util/mk1mf.pl VC-WIN32 >ms/nt.mak -perl util/mk1mf.pl VC-WIN32 dll >ms/ntdll.mak +perl util/mk1mf.pl dll VC-WIN32 >ms/ntdll.mak +perl util/mk1mf.pl Mingw32 >ms/mingw32.mak +perl util/mk1mf.pl Mingw32-files >ms/mingw32f.mak perl util/mkdef.pl 16 libeay > ms/libeay16.def perl util/mkdef.pl 32 libeay > ms/libeay32.def diff --git a/src/lib/libcrypto/util/domd b/src/lib/libcrypto/util/domd new file mode 100644 index 0000000000..324051f60b --- /dev/null +++ b/src/lib/libcrypto/util/domd @@ -0,0 +1,11 @@ +#!/bin/sh +# Do a makedepend, only leave out the standard headers +# Written by Ben Laurie 19 Jan 1999 + +TOP=$1 +shift + +cp Makefile.ssl Makefile.save +makedepend -f Makefile.ssl $@ +$TOP/util/clean-depend.pl < Makefile.ssl > Makefile.new +mv Makefile.new Makefile.ssl diff --git a/src/lib/libcrypto/util/err-ins.pl b/src/lib/libcrypto/util/err-ins.pl index db1bb48275..31b70df8d0 100644 --- a/src/lib/libcrypto/util/err-ins.pl +++ b/src/lib/libcrypto/util/err-ins.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # tack error codes onto the end of a file # diff --git a/src/lib/libcrypto/util/files.pl b/src/lib/libcrypto/util/files.pl index bf3b7effdc..41f033e3b9 100644 --- a/src/lib/libcrypto/util/files.pl +++ b/src/lib/libcrypto/util/files.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # used to generate the file MINFO for use by util/mk1mf.pl # It is basically a list of all variables from the passed makefile diff --git a/src/lib/libcrypto/util/libeay.num b/src/lib/libcrypto/util/libeay.num index fcaf254287..59c2040a29 100644 --- a/src/lib/libcrypto/util/libeay.num +++ b/src/lib/libcrypto/util/libeay.num @@ -580,7 +580,7 @@ X509_NAME_oneline 585 X509_NAME_print 586 X509_NAME_set 587 X509_OBJECT_free_contents 588 -X509_OBJECT_retrive_by_subject 589 +X509_OBJECT_retrieve_by_subject 589 X509_OBJECT_up_ref_count 590 X509_PKEY_free 591 X509_PKEY_new 592 @@ -695,12 +695,12 @@ a2i_ASN1_INTEGER 700 a2i_ASN1_STRING 701 asn1_Finish 702 asn1_GetSequence 703 -bn_div64 704 +bn_div_words 704 bn_expand2 705 bn_mul_add_words 706 bn_mul_words 707 -bn_qadd 708 -bn_qsub 709 +BN_uadd 708 +BN_usub 709 bn_sqr_words 710 crypt 711 d2i_ASN1_BIT_STRING 712 @@ -1063,3 +1063,784 @@ EVP_rc5_32_12_16_cfb 1088 EVP_rc5_32_12_16_ecb 1089 EVP_rc5_32_12_16_ofb 1090 asn1_add_error 1091 +d2i_ASN1_BMPSTRING 1092 +i2d_ASN1_BMPSTRING 1093 +BIO_f_ber 1094 +BN_init 1095 +COMP_CTX_new 1096 +COMP_CTX_free 1097 +COMP_CTX_compress_block 1098 +COMP_CTX_expand_block 1099 +X509_STORE_CTX_get_ex_new_index 1100 +OBJ_NAME_add 1101 +BIO_socket_nbio 1102 +EVP_rc2_64_cbc 1103 +OBJ_NAME_cleanup 1104 +OBJ_NAME_get 1105 +OBJ_NAME_init 1106 +OBJ_NAME_new_index 1107 +OBJ_NAME_remove 1108 +BN_MONT_CTX_copy 1109 +BIO_new_socks4a_connect 1110 +BIO_s_socks4a_connect 1111 +PROXY_set_connect_mode 1112 +RAND_SSLeay 1113 +RAND_set_rand_method 1114 +RSA_memory_lock 1115 +bn_sub_words 1116 +bn_mul_normal 1117 +bn_mul_comba8 1118 +bn_mul_comba4 1119 +bn_sqr_normal 1120 +bn_sqr_comba8 1121 +bn_sqr_comba4 1122 +bn_cmp_words 1123 +bn_mul_recursive 1124 +bn_mul_part_recursive 1125 +bn_sqr_recursive 1126 +bn_mul_low_normal 1127 +BN_RECP_CTX_init 1128 +BN_RECP_CTX_new 1129 +BN_RECP_CTX_free 1130 +BN_RECP_CTX_set 1131 +BN_mod_mul_reciprocal 1132 +BN_mod_exp_recp 1133 +BN_div_recp 1134 +BN_CTX_init 1135 +BN_MONT_CTX_init 1136 +RAND_get_rand_method 1137 +PKCS7_add_attribute 1138 +PKCS7_add_signed_attribute 1139 +PKCS7_digest_from_attributes 1140 +PKCS7_get_attribute 1141 +PKCS7_get_issuer_and_serial 1142 +PKCS7_get_signed_attribute 1143 +COMP_compress_block 1144 +COMP_expand_block 1145 +COMP_rle 1146 +COMP_zlib 1147 +ms_time_diff 1148 +ms_time_new 1149 +ms_time_free 1150 +ms_time_cmp 1151 +ms_time_get 1152 +PKCS7_set_attributes 1153 +PKCS7_set_signed_attributes 1154 +X509_ATTRIBUTE_create 1155 +X509_ATTRIBUTE_dup 1156 +ASN1_GENERALIZEDTIME_check 1157 +ASN1_GENERALIZEDTIME_print 1158 +ASN1_GENERALIZEDTIME_set 1159 +ASN1_GENERALIZEDTIME_set_string 1160 +ASN1_TIME_print 1161 +BASIC_CONSTRAINTS_free 1162 +BASIC_CONSTRAINTS_new 1163 +ERR_load_X509V3_strings 1164 +NETSCAPE_CERT_SEQUENCE_free 1165 +NETSCAPE_CERT_SEQUENCE_new 1166 +OBJ_txt2obj 1167 +PEM_read_NETSCAPE_CERT_SEQUENCE 1168 +PEM_read_bio_NETSCAPE_CERT_SEQUENCE 1169 +PEM_write_NETSCAPE_CERT_SEQUENCE 1170 +PEM_write_bio_NETSCAPE_CERT_SEQUENCE 1171 +X509V3_EXT_add 1172 +X509V3_EXT_add_alias 1173 +X509V3_EXT_add_conf 1174 +X509V3_EXT_cleanup 1175 +X509V3_EXT_conf 1176 +X509V3_EXT_conf_nid 1177 +X509V3_EXT_get 1178 +X509V3_EXT_get_nid 1179 +X509V3_EXT_print 1180 +X509V3_EXT_print_fp 1181 +X509V3_add_standard_extensions 1182 +X509V3_add_value 1183 +X509V3_add_value_bool 1184 +X509V3_add_value_int 1185 +X509V3_conf_free 1186 +X509V3_get_value_bool 1187 +X509V3_get_value_int 1188 +X509V3_parse_list 1189 +d2i_ASN1_GENERALIZEDTIME 1190 +d2i_ASN1_TIME 1191 +d2i_BASIC_CONSTRAINTS 1192 +d2i_NETSCAPE_CERT_SEQUENCE 1193 +d2i_ext_ku 1194 +ext_ku_free 1195 +ext_ku_new 1196 +i2d_ASN1_GENERALIZEDTIME 1197 +i2d_ASN1_TIME 1198 +i2d_BASIC_CONSTRAINTS 1199 +i2d_NETSCAPE_CERT_SEQUENCE 1200 +i2d_ext_ku 1201 +EVP_MD_CTX_copy 1202 +i2d_ASN1_ENUMERATED 1203 +d2i_ASN1_ENUMERATED 1204 +ASN1_ENUMERATED_set 1205 +ASN1_ENUMERATED_get 1206 +BN_to_ASN1_ENUMERATED 1207 +ASN1_ENUMERATED_to_BN 1208 +i2a_ASN1_ENUMERATED 1209 +a2i_ASN1_ENUMERATED 1210 +i2d_GENERAL_NAME 1211 +d2i_GENERAL_NAME 1212 +GENERAL_NAME_new 1213 +GENERAL_NAME_free 1214 +GENERAL_NAMES_new 1215 +GENERAL_NAMES_free 1216 +d2i_GENERAL_NAMES 1217 +i2d_GENERAL_NAMES 1218 +i2v_GENERAL_NAMES 1219 +i2s_ASN1_OCTET_STRING 1220 +s2i_ASN1_OCTET_STRING 1221 +X509V3_EXT_check_conf 1222 +hex_to_string 1223 +string_to_hex 1224 +des_ede3_cbcm_encrypt 1225 +RSA_padding_add_PKCS1_OAEP 1226 +RSA_padding_check_PKCS1_OAEP 1227 +X509_CRL_print_fp 1228 +X509_CRL_print 1229 +i2v_GENERAL_NAME 1230 +v2i_GENERAL_NAME 1231 +i2d_PKEY_USAGE_PERIOD 1232 +d2i_PKEY_USAGE_PERIOD 1233 +PKEY_USAGE_PERIOD_new 1234 +PKEY_USAGE_PERIOD_free 1235 +v2i_GENERAL_NAMES 1236 +i2s_ASN1_INTEGER 1237 +X509V3_EXT_d2i 1238 +name_cmp 1239 +str_dup 1240 +i2s_ASN1_ENUMERATED 1241 +i2s_ASN1_ENUMERATED_TABLE 1242 +BIO_s_log 1243 +BIO_f_reliable 1244 +PKCS7_dataFinal 1245 +PKCS7_dataDecode 1246 +X509V3_EXT_CRL_add_conf 1247 +BN_set_params 1248 +BN_get_params 1249 +BIO_get_ex_num 1250 +BIO_set_ex_free_func 1251 +EVP_ripemd160 1252 +ASN1_TIME_set 1253 +i2d_AUTHORITY_KEYID 1254 +d2i_AUTHORITY_KEYID 1255 +AUTHORITY_KEYID_new 1256 +AUTHORITY_KEYID_free 1257 +ASN1_seq_unpack 1258 +ASN1_seq_pack 1259 +ASN1_unpack_string 1260 +ASN1_pack_string 1261 +PKCS12_pack_safebag 1262 +PKCS12_MAKE_KEYBAG 1263 +PKCS8_encrypt 1264 +PKCS12_MAKE_SHKEYBAG 1265 +PKCS12_pack_p7data 1266 +PKCS12_pack_p7encdata 1267 +PKCS12_add_localkeyid 1268 +PKCS12_add_friendlyname_asc 1269 +PKCS12_add_friendlyname_uni 1270 +PKCS12_get_friendlyname 1271 +PKCS12_pbe_crypt 1272 +PKCS12_decrypt_d2i 1273 +PKCS12_i2d_encrypt 1274 +PKCS12_init 1275 +PKCS12_key_gen_asc 1276 +PKCS12_key_gen_uni 1277 +PKCS12_gen_mac 1278 +PKCS12_verify_mac 1279 +PKCS12_set_mac 1280 +PKCS12_setup_mac 1281 +asc2uni 1282 +uni2asc 1283 +i2d_PKCS12_BAGS 1284 +PKCS12_BAGS_new 1285 +d2i_PKCS12_BAGS 1286 +PKCS12_BAGS_free 1287 +i2d_PKCS12 1288 +d2i_PKCS12 1289 +PKCS12_new 1290 +PKCS12_free 1291 +i2d_PKCS12_MAC_DATA 1292 +PKCS12_MAC_DATA_new 1293 +d2i_PKCS12_MAC_DATA 1294 +PKCS12_MAC_DATA_free 1295 +i2d_PKCS12_SAFEBAG 1296 +PKCS12_SAFEBAG_new 1297 +d2i_PKCS12_SAFEBAG 1298 +PKCS12_SAFEBAG_free 1299 +ERR_load_PKCS12_strings 1300 +PKCS12_PBE_add 1301 +PKCS8_add_keyusage 1302 +PKCS12_get_attr_gen 1303 +PKCS12_parse 1304 +PKCS12_create 1305 +i2d_PKCS12_bio 1306 +i2d_PKCS12_fp 1307 +d2i_PKCS12_bio 1308 +d2i_PKCS12_fp 1309 +i2d_PBEPARAM 1310 +PBEPARAM_new 1311 +d2i_PBEPARAM 1312 +PBEPARAM_free 1313 +i2d_PKCS8_PRIV_KEY_INFO 1314 +PKCS8_PRIV_KEY_INFO_new 1315 +d2i_PKCS8_PRIV_KEY_INFO 1316 +PKCS8_PRIV_KEY_INFO_free 1317 +EVP_PKCS82PKEY 1318 +EVP_PKEY2PKCS8 1319 +PKCS8_set_broken 1320 +EVP_PBE_ALGOR_CipherInit 1321 +EVP_PBE_alg_add 1322 +PKCS5_pbe_set 1323 +EVP_PBE_cleanup 1324 +i2d_SXNET 1325 +d2i_SXNET 1326 +SXNET_new 1327 +SXNET_free 1328 +i2d_SXNETID 1329 +d2i_SXNETID 1330 +SXNETID_new 1331 +SXNETID_free 1332 +DSA_SIG_new 1333 +DSA_SIG_free 1334 +DSA_do_sign 1335 +DSA_do_verify 1336 +d2i_DSA_SIG 1337 +i2d_DSA_SIG 1338 + +i2d_ASN1_VISIBLESTRING 1339 +d2i_ASN1_VISIBLESTRING 1340 +i2d_ASN1_UTF8STRING 1341 +d2i_ASN1_UTF8STRING 1342 +i2d_DIRECTORYSTRING 1343 +d2i_DIRECTORYSTRING 1344 +i2d_DISPLAYTEXT 1345 +d2i_DISPLAYTEXT 1346 +sk_X509_NAME_new 1347 +sk_X509_NAME_new_null 1348 +sk_X509_NAME_free 1349 +sk_X509_NAME_num 1350 +sk_X509_NAME_value 1351 +sk_X509_NAME_set 1352 +sk_X509_NAME_zero 1353 +sk_X509_NAME_push 1354 +sk_X509_NAME_pop 1355 +sk_X509_NAME_find 1356 +sk_X509_NAME_delete 1357 +sk_X509_NAME_delete_ptr 1358 +sk_X509_NAME_set_cmp_func 1359 +sk_X509_NAME_dup 1360 +sk_X509_NAME_pop_free 1361 +sk_X509_NAME_shift 1362 +sk_X509_new 1363 +sk_X509_new_null 1364 +sk_X509_free 1365 +sk_X509_num 1366 +sk_X509_value 1367 +sk_X509_set 1368 +sk_X509_zero 1369 +sk_X509_push 1370 +sk_X509_pop 1371 +sk_X509_find 1372 +sk_X509_delete 1373 +sk_X509_delete_ptr 1374 +sk_X509_set_cmp_func 1375 +sk_X509_dup 1376 +sk_X509_pop_free 1377 +sk_X509_shift 1378 +d2i_ASN1_SET_OF_X509 1379 +i2d_ASN1_SET_OF_X509 1380 +sk_X509_ATTRIBUTE_new 1381 +sk_X509_ATTRIBUTE_new_null 1382 +sk_X509_ATTRIBUTE_free 1383 +sk_X509_ATTRIBUTE_num 1384 +sk_X509_ATTRIBUTE_value 1385 +sk_X509_ATTRIBUTE_set 1386 +sk_X509_ATTRIBUTE_zero 1387 +sk_X509_ATTRIBUTE_push 1388 +sk_X509_ATTRIBUTE_pop 1389 +sk_X509_ATTRIBUTE_find 1390 +sk_X509_ATTRIBUTE_delete 1391 +sk_X509_ATTRIBUTE_delete_ptr 1392 +sk_X509_ATTRIBUTE_set_cmp_func 1393 +sk_X509_ATTRIBUTE_dup 1394 +sk_X509_ATTRIBUTE_pop_free 1395 +sk_X509_ATTRIBUTE_shift 1396 +i2d_PBKDF2PARAM 1397 +PBKDF2PARAM_new 1398 +d2i_PBKDF2PARAM 1399 +PBKDF2PARAM_free 1400 +i2d_PBE2PARAM 1401 +PBE2PARAM_new 1402 +d2i_PBE2PARAM 1403 +PBE2PARAM_free 1404 +sk_GENERAL_NAME_new 1405 +sk_GENERAL_NAME_new_null 1406 +sk_GENERAL_NAME_free 1407 +sk_GENERAL_NAME_num 1408 +sk_GENERAL_NAME_value 1409 +sk_GENERAL_NAME_set 1410 +sk_GENERAL_NAME_zero 1411 +sk_GENERAL_NAME_push 1412 +sk_GENERAL_NAME_pop 1413 +sk_GENERAL_NAME_find 1414 +sk_GENERAL_NAME_delete 1415 +sk_GENERAL_NAME_delete_ptr 1416 +sk_GENERAL_NAME_set_cmp_func 1417 +sk_GENERAL_NAME_dup 1418 +sk_GENERAL_NAME_pop_free 1419 +sk_GENERAL_NAME_shift 1420 +d2i_ASN1_SET_OF_GENERAL_NAME 1421 +i2d_ASN1_SET_OF_GENERAL_NAME 1422 +sk_SXNETID_new 1423 +sk_SXNETID_new_null 1424 +sk_SXNETID_free 1425 +sk_SXNETID_num 1426 +sk_SXNETID_value 1427 +sk_SXNETID_set 1428 +sk_SXNETID_zero 1429 +sk_SXNETID_push 1430 +sk_SXNETID_pop 1431 +sk_SXNETID_find 1432 +sk_SXNETID_delete 1433 +sk_SXNETID_delete_ptr 1434 +sk_SXNETID_set_cmp_func 1435 +sk_SXNETID_dup 1436 +sk_SXNETID_pop_free 1437 +sk_SXNETID_shift 1438 +d2i_ASN1_SET_OF_SXNETID 1439 +i2d_ASN1_SET_OF_SXNETID 1440 +sk_POLICYQUALINFO_new 1441 +sk_POLICYQUALINFO_new_null 1442 +sk_POLICYQUALINFO_free 1443 +sk_POLICYQUALINFO_num 1444 +sk_POLICYQUALINFO_value 1445 +sk_POLICYQUALINFO_set 1446 +sk_POLICYQUALINFO_zero 1447 +sk_POLICYQUALINFO_push 1448 +sk_POLICYQUALINFO_pop 1449 +sk_POLICYQUALINFO_find 1450 +sk_POLICYQUALINFO_delete 1451 +sk_POLICYQUALINFO_delete_ptr 1452 +sk_POLICYQUALINFO_set_cmp_func 1453 +sk_POLICYQUALINFO_dup 1454 +sk_POLICYQUALINFO_pop_free 1455 +sk_POLICYQUALINFO_shift 1456 +d2i_ASN1_SET_OF_POLICYQUALINFO 1457 +i2d_ASN1_SET_OF_POLICYQUALINFO 1458 +sk_POLICYINFO_new 1459 +sk_POLICYINFO_new_null 1460 +sk_POLICYINFO_free 1461 +sk_POLICYINFO_num 1462 +sk_POLICYINFO_value 1463 +sk_POLICYINFO_set 1464 +sk_POLICYINFO_zero 1465 +sk_POLICYINFO_push 1466 +sk_POLICYINFO_pop 1467 +sk_POLICYINFO_find 1468 +sk_POLICYINFO_delete 1469 +sk_POLICYINFO_delete_ptr 1470 +sk_POLICYINFO_set_cmp_func 1471 +sk_POLICYINFO_dup 1472 +sk_POLICYINFO_pop_free 1473 +sk_POLICYINFO_shift 1474 +d2i_ASN1_SET_OF_POLICYINFO 1475 +i2d_ASN1_SET_OF_POLICYINFO 1476 +SXNET_add_id_asc 1477 +SXNET_add_id_ulong 1478 +SXNET_add_id_INTEGER 1479 +SXNET_get_id_asc 1480 +SXNET_get_id_ulong 1481 +SXNET_get_id_INTEGER 1482 +X509V3_set_conf_lhash 1483 +i2d_CERTIFICATEPOLICIES 1484 +CERTIFICATEPOLICIES_new 1485 +CERTIFICATEPOLICIES_free 1486 +d2i_CERTIFICATEPOLICIES 1487 +i2d_POLICYINFO 1488 +POLICYINFO_new 1489 +d2i_POLICYINFO 1490 +POLICYINFO_free 1491 +i2d_POLICYQUALINFO 1492 +POLICYQUALINFO_new 1493 +d2i_POLICYQUALINFO 1494 +POLICYQUALINFO_free 1495 +i2d_USERNOTICE 1496 +USERNOTICE_new 1497 +d2i_USERNOTICE 1498 +USERNOTICE_free 1499 +i2d_NOTICEREF 1500 +NOTICEREF_new 1501 +d2i_NOTICEREF 1502 +NOTICEREF_free 1503 +X509V3_get_string 1504 +X509V3_get_section 1505 +X509V3_string_free 1506 +X509V3_section_free 1507 +X509V3_set_ctx 1508 +s2i_ASN1_INTEGER 1509 +CRYPTO_set_locked_mem_functions 1510 +CRYPTO_get_locked_mem_functions 1511 +CRYPTO_malloc_locked 1512 +CRYPTO_free_locked 1513 +BN_mod_exp2_mont 1514 +ERR_get_error_line_data 1515 +ERR_peek_error_line_data 1516 +PKCS12_PBE_keyivgen 1517 +X509_ALGOR_dup 1518 +sk_DIST_POINT_new 1519 +sk_DIST_POINT_new_null 1520 +sk_DIST_POINT_free 1521 +sk_DIST_POINT_num 1522 +sk_DIST_POINT_value 1523 +sk_DIST_POINT_set 1524 +sk_DIST_POINT_zero 1525 +sk_DIST_POINT_push 1526 +sk_DIST_POINT_pop 1527 +sk_DIST_POINT_find 1528 +sk_DIST_POINT_delete 1529 +sk_DIST_POINT_delete_ptr 1530 +sk_DIST_POINT_set_cmp_func 1531 +sk_DIST_POINT_dup 1532 +sk_DIST_POINT_pop_free 1533 +sk_DIST_POINT_shift 1534 +d2i_ASN1_SET_OF_DIST_POINT 1535 +i2d_ASN1_SET_OF_DIST_POINT 1536 +i2d_CRL_DIST_POINTS 1537 +CRL_DIST_POINTS_new 1538 +CRL_DIST_POINTS_free 1539 +d2i_CRL_DIST_POINTS 1540 +i2d_DIST_POINT 1541 +DIST_POINT_new 1542 +d2i_DIST_POINT 1543 +DIST_POINT_free 1544 +i2d_DIST_POINT_NAME 1545 +DIST_POINT_NAME_new 1546 +DIST_POINT_NAME_free 1547 +d2i_DIST_POINT_NAME 1548 +X509V3_add_value_uchar 1549 +sk_X509_INFO_new 1550 +sk_X509_EXTENSION_new 1551 +sk_X509_NAME_ENTRY_unshift 1552 +sk_ASN1_TYPE_value 1553 +sk_X509_EXTENSION_find 1554 +d2i_ASN1_SET_OF_X509_ATTRIBUTE 1555 +sk_ASN1_TYPE_pop 1556 +sk_X509_EXTENSION_set_cmp_func 1557 +sk_ASN1_TYPE_new_null 1558 +sk_X509_NAME_ENTRY_delete 1559 +i2d_ASN1_SET_OF_ASN1_TYPE 1560 +sk_X509_NAME_ENTRY_dup 1561 +sk_X509_unshift 1562 +sk_X509_NAME_unshift 1563 +sk_ASN1_TYPE_num 1564 +sk_X509_EXTENSION_new_null 1565 +sk_X509_INFO_value 1566 +d2i_ASN1_SET_OF_X509_EXTENSION 1567 +sk_X509_INFO_delete_ptr 1568 +sk_X509_NAME_ENTRY_new 1569 +sk_DIST_POINT_insert 1570 +sk_ASN1_TYPE_set_cmp_func 1571 +sk_X509_EXTENSION_value 1572 +sk_DIST_POINT_unshift 1573 +d2i_ASN1_SET_OF_X509_NAME_ENTRY 1574 +sk_X509_INFO_pop 1575 +sk_X509_EXTENSION_pop 1576 +sk_X509_NAME_ENTRY_shift 1577 +sk_X509_INFO_num 1578 +sk_X509_EXTENSION_num 1579 +sk_X509_INFO_pop_free 1580 +sk_POLICYQUALINFO_unshift 1581 +sk_POLICYINFO_unshift 1582 +sk_X509_NAME_ENTRY_new_null 1583 +sk_X509_NAME_ENTRY_pop 1584 +sk_X509_ATTRIBUTE_unshift 1585 +sk_X509_NAME_ENTRY_num 1586 +sk_GENERAL_NAME_unshift 1587 +sk_X509_INFO_free 1588 +d2i_ASN1_SET_OF_ASN1_TYPE 1589 +sk_X509_INFO_insert 1590 +sk_X509_NAME_ENTRY_value 1591 +sk_POLICYQUALINFO_insert 1592 +sk_ASN1_TYPE_set 1593 +sk_X509_EXTENSION_delete_ptr 1594 +sk_X509_INFO_unshift 1595 +sk_ASN1_TYPE_unshift 1596 +sk_ASN1_TYPE_free 1597 +sk_ASN1_TYPE_delete_ptr 1598 +sk_ASN1_TYPE_pop_free 1599 +sk_X509_EXTENSION_unshift 1600 +sk_X509_EXTENSION_pop_free 1601 +sk_X509_NAME_ENTRY_set_cmp_func 1602 +sk_ASN1_TYPE_insert 1603 +sk_X509_NAME_ENTRY_free 1604 +sk_SXNETID_insert 1605 +sk_X509_NAME_insert 1606 +sk_X509_insert 1607 +sk_X509_INFO_delete 1608 +sk_X509_INFO_set_cmp_func 1609 +sk_X509_ATTRIBUTE_insert 1610 +sk_X509_INFO_zero 1611 +sk_X509_INFO_set 1612 +sk_X509_EXTENSION_set 1613 +sk_X509_EXTENSION_free 1614 +i2d_ASN1_SET_OF_X509_ATTRIBUTE 1615 +sk_SXNETID_unshift 1616 +sk_X509_INFO_push 1617 +sk_X509_EXTENSION_insert 1618 +sk_X509_INFO_new_null 1619 +sk_ASN1_TYPE_dup 1620 +sk_X509_INFO_find 1621 +sk_POLICYINFO_insert 1622 +sk_ASN1_TYPE_zero 1623 +i2d_ASN1_SET_OF_X509_EXTENSION 1624 +sk_X509_NAME_ENTRY_set 1625 +sk_ASN1_TYPE_push 1626 +sk_X509_NAME_ENTRY_insert 1627 +sk_ASN1_TYPE_new 1628 +sk_GENERAL_NAME_insert 1629 +sk_ASN1_TYPE_shift 1630 +sk_ASN1_TYPE_delete 1631 +sk_X509_NAME_ENTRY_pop_free 1632 +i2d_ASN1_SET_OF_X509_NAME_ENTRY 1633 +sk_X509_NAME_ENTRY_zero 1634 +sk_ASN1_TYPE_find 1635 +sk_X509_NAME_ENTRY_delete_ptr 1636 +sk_X509_NAME_ENTRY_push 1637 +sk_X509_EXTENSION_zero 1638 +sk_X509_INFO_shift 1639 +sk_X509_INFO_dup 1640 +sk_X509_EXTENSION_dup 1641 +sk_X509_EXTENSION_delete 1642 +sk_X509_EXTENSION_shift 1643 +sk_X509_EXTENSION_push 1644 +sk_X509_NAME_ENTRY_find 1645 +X509V3_EXT_i2d 1646 +X509V3_EXT_val_prn 1647 +X509V3_EXT_add_list 1648 +EVP_CIPHER_type 1649 +EVP_PBE_CipherInit 1650 +X509V3_add_value_bool_nf 1651 +d2i_ASN1_UINTEGER 1652 +sk_value 1653 +sk_num 1654 +sk_set 1655 +sk_X509_REVOKED_set_cmp_func 1656 +sk_X509_REVOKED_unshift 1657 +sk_X509_REVOKED_dup 1658 +sk_X509_REVOKED_free 1659 +sk_X509_REVOKED_new 1660 +i2d_ASN1_SET_OF_X509_REVOKED 1661 +sk_X509_REVOKED_shift 1662 +sk_X509_REVOKED_delete_ptr 1663 +sk_X509_REVOKED_pop_free 1664 +sk_X509_REVOKED_insert 1665 +sk_X509_REVOKED_zero 1666 +sk_X509_REVOKED_pop 1667 +sk_X509_REVOKED_value 1668 +sk_X509_REVOKED_num 1669 +sk_X509_REVOKED_push 1670 +sk_sort 1671 +sk_X509_REVOKED_find 1672 +sk_X509_REVOKED_delete 1673 +d2i_ASN1_SET_OF_X509_REVOKED 1674 +sk_X509_REVOKED_new_null 1675 +sk_X509_REVOKED_set 1676 +sk_X509_ALGOR_new 1677 +sk_X509_CRL_set_cmp_func 1678 +sk_X509_CRL_set 1679 +sk_X509_ALGOR_unshift 1680 +sk_X509_CRL_free 1681 +i2d_ASN1_SET_OF_X509_ALGOR 1682 +sk_X509_ALGOR_pop 1683 +sk_X509_CRL_unshift 1684 +i2d_ASN1_SET_OF_X509_CRL 1685 +sk_X509_ALGOR_num 1686 +sk_X509_CRL_insert 1687 +sk_X509_CRL_pop_free 1688 +sk_X509_CRL_delete_ptr 1689 +sk_X509_ALGOR_insert 1690 +sk_X509_CRL_dup 1691 +sk_X509_CRL_zero 1692 +sk_X509_CRL_new 1693 +sk_X509_CRL_push 1694 +sk_X509_ALGOR_new_null 1695 +d2i_ASN1_SET_OF_X509_ALGOR 1696 +sk_X509_CRL_shift 1697 +sk_X509_CRL_find 1698 +sk_X509_CRL_delete 1699 +sk_X509_ALGOR_free 1700 +sk_X509_ALGOR_delete 1701 +d2i_ASN1_SET_OF_X509_CRL 1702 +sk_X509_ALGOR_delete_ptr 1703 +sk_X509_CRL_pop 1704 +sk_X509_ALGOR_set 1705 +sk_X509_CRL_num 1706 +sk_X509_CRL_value 1707 +sk_X509_ALGOR_shift 1708 +sk_X509_ALGOR_zero 1709 +sk_X509_CRL_new_null 1710 +sk_X509_ALGOR_push 1711 +sk_X509_ALGOR_value 1712 +sk_X509_ALGOR_find 1713 +sk_X509_ALGOR_set_cmp_func 1714 +sk_X509_ALGOR_dup 1715 +sk_X509_ALGOR_pop_free 1716 +sk_PKCS7_SIGNER_INFO_new 1717 +sk_PKCS7_SIGNER_INFO_zero 1718 +sk_PKCS7_SIGNER_INFO_unshift 1719 +sk_PKCS7_RECIP_INFO_dup 1720 +sk_PKCS7_SIGNER_INFO_insert 1721 +sk_PKCS7_SIGNER_INFO_push 1722 +i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO 1723 +sk_PKCS7_RECIP_INFO_new 1724 +sk_X509_LOOKUP_new_null 1725 +sk_PKCS7_SIGNER_INFO_find 1726 +sk_PKCS7_SIGNER_INFO_set_cmp_func 1727 +sk_X509_LOOKUP_zero 1728 +sk_PKCS7_RECIP_INFO_shift 1729 +sk_PKCS7_RECIP_INFO_new_null 1730 +sk_PKCS7_SIGNER_INFO_shift 1731 +sk_PKCS7_SIGNER_INFO_pop 1732 +sk_PKCS7_SIGNER_INFO_pop_free 1733 +sk_X509_LOOKUP_push 1734 +sk_X509_LOOKUP_dup 1735 +sk_PKCS7_SIGNER_INFO_num 1736 +sk_X509_LOOKUP_find 1737 +i2d_ASN1_SET_OF_PKCS7_RECIP_INFO 1738 +sk_X509_LOOKUP_new 1739 +sk_PKCS7_SIGNER_INFO_delete 1740 +sk_PKCS7_RECIP_INFO_set_cmp_func 1741 +sk_PKCS7_SIGNER_INFO_delete_ptr 1742 +sk_PKCS7_RECIP_INFO_pop 1743 +sk_X509_LOOKUP_insert 1744 +sk_PKCS7_RECIP_INFO_value 1745 +sk_PKCS7_RECIP_INFO_num 1746 +sk_PKCS7_SIGNER_INFO_value 1747 +d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO 1748 +sk_X509_LOOKUP_pop 1749 +sk_X509_LOOKUP_num 1750 +sk_X509_LOOKUP_delete 1751 +sk_PKCS7_RECIP_INFO_free 1752 +d2i_ASN1_SET_OF_PKCS7_RECIP_INFO 1753 +sk_PKCS7_SIGNER_INFO_set 1754 +sk_X509_LOOKUP_pop_free 1755 +sk_X509_LOOKUP_shift 1756 +sk_X509_LOOKUP_unshift 1757 +sk_PKCS7_SIGNER_INFO_new_null 1758 +sk_PKCS7_RECIP_INFO_delete_ptr 1759 +sk_PKCS7_RECIP_INFO_pop_free 1760 +sk_PKCS7_RECIP_INFO_insert 1761 +sk_PKCS7_SIGNER_INFO_free 1762 +sk_PKCS7_RECIP_INFO_set 1763 +sk_PKCS7_RECIP_INFO_zero 1764 +sk_X509_LOOKUP_value 1765 +sk_PKCS7_RECIP_INFO_push 1766 +sk_PKCS7_RECIP_INFO_unshift 1767 +sk_X509_LOOKUP_set_cmp_func 1768 +sk_X509_LOOKUP_free 1769 +sk_PKCS7_SIGNER_INFO_dup 1770 +sk_X509_LOOKUP_delete_ptr 1771 +sk_X509_LOOKUP_set 1772 +sk_PKCS7_RECIP_INFO_find 1773 +sk_PKCS7_RECIP_INFO_delete 1774 +PKCS5_PBE_add 1775 +PEM_write_bio_PKCS8 1776 +i2d_PKCS8_fp 1777 +PEM_read_bio_PKCS8_PRIV_KEY_INFO 1778 +d2i_PKCS8_bio 1779 +d2i_PKCS8_PRIV_KEY_INFO_fp 1780 +PEM_write_bio_PKCS8_PRIV_KEY_INFO 1781 +PEM_read_PKCS8 1782 +d2i_PKCS8_PRIV_KEY_INFO_bio 1783 +d2i_PKCS8_fp 1784 +PEM_write_PKCS8 1785 +PEM_read_PKCS8_PRIV_KEY_INFO 1786 +PEM_read_bio_PKCS8 1787 +PEM_write_PKCS8_PRIV_KEY_INFO 1788 +PKCS5_PBE_keyivgen 1789 +i2d_PKCS8_bio 1790 +i2d_PKCS8_PRIV_KEY_INFO_fp 1791 +i2d_PKCS8_PRIV_KEY_INFO_bio 1792 +BIO_s_bio 1793 +PKCS5_pbe2_set 1794 +PKCS5_PBKDF2_HMAC_SHA1 1795 +PKCS5_v2_PBE_keyivgen 1796 +PEM_write_bio_PKCS8PrivateKey 1797 +PEM_write_PKCS8PrivateKey 1798 +BIO_ctrl_get_read_request 1799 +BIO_ctrl_pending 1800 +BIO_ctrl_wpending 1801 +BIO_new_bio_pair 1802 +BIO_ctrl_get_write_guarantee 1803 +CRYPTO_num_locks 1804 +CONF_load_bio 1805 +CONF_load_fp 1806 +sk_CONF_VALUE_delete 1807 +sk_CONF_VALUE_pop 1808 +sk_CONF_VALUE_num 1809 +sk_CONF_VALUE_pop_free 1810 +sk_CONF_VALUE_free 1811 +sk_CONF_VALUE_shift 1812 +sk_CONF_VALUE_unshift 1813 +sk_CONF_VALUE_value 1814 +sk_CONF_VALUE_set 1815 +sk_CONF_VALUE_zero 1816 +sk_CONF_VALUE_push 1817 +sk_CONF_VALUE_delete_ptr 1818 +sk_CONF_VALUE_find 1819 +sk_CONF_VALUE_set_cmp_func 1820 +sk_CONF_VALUE_new_null 1821 +sk_CONF_VALUE_dup 1822 +sk_CONF_VALUE_insert 1823 +sk_CONF_VALUE_new 1824 +sk_ASN1_OBJECT_find 1825 +sk_ASN1_OBJECT_pop_free 1826 +sk_ASN1_OBJECT_dup 1827 +sk_ASN1_OBJECT_delete_ptr 1828 +sk_ASN1_OBJECT_new 1829 +sk_ASN1_OBJECT_unshift 1830 +sk_ASN1_OBJECT_delete 1831 +sk_ASN1_OBJECT_shift 1832 +sk_ASN1_OBJECT_pop 1833 +sk_ASN1_OBJECT_num 1834 +sk_ASN1_OBJECT_value 1835 +sk_ASN1_OBJECT_new_null 1836 +i2d_ASN1_SET_OF_ASN1_OBJECT 1837 +sk_ASN1_OBJECT_free 1838 +sk_ASN1_OBJECT_set 1839 +sk_ASN1_OBJECT_set_cmp_func 1840 +sk_ASN1_OBJECT_zero 1841 +sk_ASN1_OBJECT_insert 1842 +sk_ASN1_OBJECT_push 1843 +d2i_ASN1_SET_OF_ASN1_OBJECT 1844 +PKCS7_signatureVerify 1845 +RSA_set_method 1846 +RSA_get_method 1847 +RSA_get_default_method 1848 +sk_CONF_VALUE_sort 1849 +sk_X509_REVOKED_sort 1850 +sk_X509_ATTRIBUTE_sort 1851 +sk_X509_INFO_sort 1852 +sk_POLICYINFO_sort 1853 +sk_GENERAL_NAME_sort 1854 +sk_X509_sort 1855 +sk_X509_NAME_sort 1856 +sk_ASN1_TYPE_sort 1857 +sk_X509_ALGOR_sort 1858 +sk_PKCS7_RECIP_INFO_sort 1859 +sk_X509_NAME_ENTRY_sort 1860 +sk_X509_EXTENSION_sort 1861 +sk_SXNETID_sort 1862 +sk_ASN1_OBJECT_sort 1863 +sk_PKCS7_SIGNER_INFO_sort 1864 +sk_X509_LOOKUP_sort 1865 +sk_POLICYQUALINFO_sort 1866 +sk_X509_CRL_sort 1867 +sk_DIST_POINT_sort 1868 +RSA_check_key 1869 +OBJ_obj2txt 1870 +DSA_dup_DH 1871 diff --git a/src/lib/libcrypto/util/mk1mf.pl b/src/lib/libcrypto/util/mk1mf.pl index 149a0f4f80..6fbf3ceca6 100644 --- a/src/lib/libcrypto/util/mk1mf.pl +++ b/src/lib/libcrypto/util/mk1mf.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # A bit of an evil hack but it post processes the file ../MINFO which # is generated by `make files` in the top directory. # This script outputs one mega makefile that has no shell stuff or any @@ -6,82 +6,59 @@ # $INSTALLTOP="/usr/local/ssl"; +$OPTIONS=""; +$ssl_version=""; + +open(IN,") { + $ssl_version=$1 if (/^VERSION=(.*)$/); + $OPTIONS=$1 if (/^OPTIONS=(.*)$/); + $INSTALLTOP=$1 if (/^INSTALLTOP=(.*$)/); +} +close(IN); -$ssl_version="0.8.2"; +die "Makefile.ssl is not the toplevel Makefile!\n" if $ssl_version eq ""; $infile="MINFO"; %ops=( - "VC-WIN32", "Microsoft Visual C++ 4.[01] - Windows NT [34].x", + "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X", + "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY", "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286", "VC-WIN16", "Alias for VC-W31-32", "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+", "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS", - "BC-NT", "Borland C++ 4.5 - Windows NT - PROBABLY NOT WORKING", + "Mingw32", "GNU C++ - Windows NT or 9x", + "Mingw32-files", "Create files with DOS copy ...", + "BC-NT", "Borland C++ 4.5 - Windows NT", "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING", "BC-MSDOS","Borland C++ 4.5 - MSDOS", "linux-elf","Linux elf", + "ultrix-mips","DEC mips ultrix", "FreeBSD","FreeBSD distribution", "default","cc under unix", ); -$type=""; +$platform=""; foreach (@ARGV) { - if (/^no-rc2$/) { $no_rc2=1; } - elsif (/^no-rc4$/) { $no_rc4=1; } - elsif (/^no-rc5$/) { $no_rc5=1; } - elsif (/^no-idea$/) { $no_idea=1; } - elsif (/^no-des$/) { $no_des=1; } - elsif (/^no-bf$/) { $no_bf=1; } - elsif (/^no-cast$/) { $no_cast=1; } - elsif (/^no-md2$/) { $no_md2=1; } - elsif (/^no-md5$/) { $no_md5=1; } - elsif (/^no-sha$/) { $no_sha=1; } - elsif (/^no-sha1$/) { $no_sha1=1; } - elsif (/^no-rmd160$/) { $no_rmd160=1; } - elsif (/^no-mdc2$/) { $no_mdc2=1; } - elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; } - elsif (/^no-rsa$/) { $no_rsa=1; } - elsif (/^no-dsa$/) { $no_dsa=1; } - elsif (/^no-dh$/) { $no_dh=1; } - elsif (/^no-asm$/) { $no_asm=1; } - elsif (/^no-ssl2$/) { $no_ssl2=1; } - elsif (/^no-ssl3$/) { $no_ssl3=1; } - elsif (/^no-err$/) { $no_err=1; } - elsif (/^no-sock$/) { $no_sock=1; } - - elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1; - $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1; - $no_ssl2=$no_err=1; } - - elsif (/^rsaref$/) { $rsaref=1; } - elsif (/^gcc$/) { $gcc=1; } - elsif (/^debug$/) { $debug=1; } - elsif (/^shlib$/) { $shlib=1; } - elsif (/^dll$/) { $shlib=1; } - elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; } - elsif (/^-[lL].*$/) { $l_flags.="$_ "; } - elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/) - { $c_flags.="$_ "; } - else + if (!&read_options && !defined($ops{$_})) { - if (!defined($ops{$_})) - { - print STDERR "unknown option - $_\n"; - print STDERR "usage: perl mk1mf.pl [system] [options]\n"; - print STDERR "\nwhere [system] can be one of the following\n"; - foreach $i (sort keys %ops) - { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; } - print STDERR <<"EOF"; + print STDERR "unknown option - $_\n"; + print STDERR "usage: perl mk1mf.pl [options] [system]\n"; + print STDERR "\nwhere [system] can be one of the following\n"; + foreach $i (sort keys %ops) + { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; } + print STDERR <<"EOF"; and [options] can be one of - no-md2 no-md5 no-sha no-sha1 no-mdc2 no-rmd160 - Skip this digest + no-md2 no-md5 no-sha no-mdc2 no-ripemd - Skip this digest no-rc2 no-rc4 no-idea no-des no-bf no-cast - Skip this symetric cipher no-rc5 no-rsa no-dsa no-dh - Skip this public key cipher no-ssl2 no-ssl3 - Skip this version of SSL just-ssl - remove all non-ssl keys/digest no-asm - No x86 asm + nasm - Use NASM for x86 asm no-socks - No socket code no-err - No error strings dll/shlib - Build shared libraries (MS) @@ -96,15 +73,18 @@ TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler - - extra 'cc' flags, added (MS), or replace (unix) EOF - exit(1); - } - $type=$_; + exit(1); } + $platform=$_; + } +foreach (split / /, $OPTIONS) + { + print STDERR "unknown option - $_\n" if !&read_options; } $no_mdc2=1 if ($no_des); -$no_ssl3=1 if ($no_md5 || $no_sha1); +$no_ssl3=1 if ($no_md5 || $no_sha); $no_ssl3=1 if ($no_rsa && $no_dh); $no_ssl2=1 if ($no_md5 || $no_rsa); @@ -114,6 +94,7 @@ $out_def="out"; $inc_def="outinc"; $tmp_def="tmp"; +$mkdir="mkdir"; ($ssl,$crypto)=("ssl","crypto"); $RSAglue="RSAglue"; @@ -125,62 +106,79 @@ $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:''; # $bin_dir.=$o causes a core dump on my sparc :-( +$NT=0; + push(@INC,"util/pl","pl"); -if ($type eq "VC-MSDOS") +if ($platform eq "VC-MSDOS") { $asmbits=16; $msdos=1; require 'VC-16.pl'; } -elsif ($type eq "VC-W31-16") +elsif ($platform eq "VC-W31-16") { $asmbits=16; $msdos=1; $win16=1; require 'VC-16.pl'; } -elsif (($type eq "VC-W31-32") || ($type eq "VC-WIN16")) +elsif (($platform eq "VC-W31-32") || ($platform eq "VC-WIN16")) { $asmbits=32; $msdos=1; $win16=1; require 'VC-16.pl'; } -elsif (($type eq "VC-WIN32") || ($type eq "VC-NT")) +elsif (($platform eq "VC-WIN32") || ($platform eq "VC-NT")) { + $NT = 1 if $platform eq "VC-NT"; require 'VC-32.pl'; } -elsif ($type eq "BC-NT") +elsif ($platform eq "Mingw32") + { + require 'Mingw32.pl'; + } +elsif ($platform eq "Mingw32-files") + { + require 'Mingw32f.pl'; + } +elsif ($platform eq "BC-NT") { $bc=1; require 'BC-32.pl'; } -elsif ($type eq "BC-W31") +elsif ($platform eq "BC-W31") { $bc=1; $msdos=1; $w16=1; require 'BC-16.pl'; } -elsif ($type eq "BC-Q16") +elsif ($platform eq "BC-Q16") { $msdos=1; $w16=1; $shlib=0; $qw=1; require 'BC-16.pl'; } -elsif ($type eq "BC-MSDOS") +elsif ($platform eq "BC-MSDOS") { $asmbits=16; $msdos=1; require 'BC-16.pl'; } -elsif ($type eq "FreeBSD") +elsif ($platform eq "FreeBSD") { require 'unix.pl'; $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer'; } -elsif ($type eq "linux-elf") +elsif ($platform eq "linux-elf") { require "unix.pl"; require "linux.pl"; $unix=1; } +elsif ($platform eq "ultrix-mips") + { + require "unix.pl"; + require "ultrix.pl"; + $unix=1; + } else { require "unix.pl"; @@ -203,9 +201,9 @@ $cflags.=" -DNO_MD2" if $no_md2; $cflags.=" -DNO_MD5" if $no_md5; $cflags.=" -DNO_SHA" if $no_sha; $cflags.=" -DNO_SHA1" if $no_sha1; -$cflags.=" -DNO_RMD160" if $no_rmd160; +$cflags.=" -DNO_RIPEMD" if $no_rmd160; $cflags.=" -DNO_MDC2" if $no_mdc2; -$cflags.=" -DNO_BLOWFISH" if $no_bf; +$cflags.=" -DNO_BF" if $no_bf; $cflags.=" -DNO_CAST" if $no_cast; $cflags.=" -DNO_DES" if $no_des; $cflags.=" -DNO_RSA" if $no_rsa; @@ -223,14 +221,9 @@ else { $cflags="$c_flags$cflags" if ($c_flags ne ""); } $ex_libs="$l_flags$ex_libs" if ($l_flags ne ""); -if ($ranlib ne "") - { - $ranlib="\$(SRC_D)$o$ranlib"; - } - if ($msdos) { - $banner ="\t\@echo Make sure you have run 'perl Configure $type' in the\n"; + $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n"; $banner.="\t\@echo top level directory, if you don't have perl, you will\n"; $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n"; $banner.="\t\@echo documentation for details.\n"; @@ -242,8 +235,8 @@ $link="$bin_dir$link" if ($link !~ /^\$/); $INSTALLTOP =~ s|/|$o|g; $defs= <<"EOF"; -# This makefile has been automatically generated from the SSLeay distribution. -# This single makefile will build the complete SSLeay distribution and +# This makefile has been automatically generated from the OpenSSL distribution. +# This single makefile will build the complete OpenSSL distribution and # by default leave the 'intertesting' output files in .${o}out and the stuff # that needs deleting in .${o}tmp. # The file was generated by running 'make makefile.one', which @@ -258,6 +251,7 @@ $defs= <<"EOF"; INSTALLTOP=$INSTALLTOP # Set your compiler options +PLATFORM=$platform CC=$bin_dir${cc} CFLAG=$cflags APP_CFLAG=$app_cflag @@ -269,18 +263,16 @@ SHLIB_EX_OBJ=$shlib_ex_obj # be added EX_LIBS=$ex_libs -# The SSLeay directory +# The OpenSSL directory SRC_D=$src_dir LINK=$link LFLAGS=$lflags -BN_MULW_OBJ=$bn_mulw_obj -BN_MULW_SRC=$bn_mulw_src +BN_ASM_OBJ=$bn_asm_obj +BN_ASM_SRC=$bn_asm_src DES_ENC_OBJ=$des_enc_obj DES_ENC_SRC=$des_enc_src -DES_CRYPT_OBJ=$des_crypt_obj -DES_CRYPT_SRC=$des_crypt_src BF_ENC_OBJ=$bf_enc_obj BF_ENC_SRC=$bf_enc_src CAST_ENC_OBJ=$cast_enc_obj @@ -302,11 +294,12 @@ OUT_D=$out_dir TMP_D=$tmp_dir # The output directory for the header files INC_D=$inc_dir +INCO_D=$inc_dir${o}openssl CP=$cp RM=$rm RANLIB=$ranlib -MKDIR=mkdir +MKDIR=$mkdir MKLIB=$bin_dir$mklib MLFLAGS=$mlflags ASM=$bin_dir$asm @@ -315,7 +308,7 @@ ASM=$bin_dir$asm # You should not need to touch anything below this point ###################################################### -E_EXE=ssleay +E_EXE=openssl SSL=$ssl CRYPTO=$crypto RSAGLUE=$RSAglue @@ -323,6 +316,9 @@ RSAGLUE=$RSAglue # BIN_D - Binary output directory # TEST_D - Binary test file output directory # LIB_D - library output directory +# Note: if you change these point to different directories then uncomment out +# the lines around the 'NB' comment below. +# BIN_D=\$(OUT_D) TEST_D=\$(OUT_D) LIB_D=\$(OUT_D) @@ -337,8 +333,8 @@ O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp O_RSAGLUE= \$(LIB_D)$o$plib\$(RSAGLUE)$libp SO_SSL= $plib\$(SSL)$so_shlibp SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp -L_SSL= \$(LIB_D)$o\$(SSL)$libp -L_CRYPTO= \$(LIB_D)$o\$(CRYPTO)$libp +L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp +L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp L_LIBS= \$(L_SSL) \$(L_CRYPTO) #L_LIBS= \$(O_SSL) \$(O_RSAGLUE) -lrsaref \$(O_CRYPTO) @@ -357,23 +353,26 @@ LIBS_DEP=\$(O_CRYPTO) \$(O_RSAGLUE) \$(O_SSL) EOF $rules=<<"EOF"; -all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INC_D) headers lib exe +all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe banner: $banner \$(TMP_D): \$(MKDIR) \$(TMP_D) - -\$(BIN_D): - \$(MKDIR) \$(BIN_D) - -\$(TEST_D): - \$(MKDIR) \$(TEST_D) +# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different +#\$(BIN_D): +# \$(MKDIR) \$(BIN_D) +# +#\$(TEST_D): +# \$(MKDIR) \$(TEST_D) \$(LIB_D): \$(MKDIR) \$(LIB_D) +\$(INCO_D): \$(INC_D) + \$(MKDIR) \$(INCO_D) + \$(INC_D): \$(MKDIR) \$(INC_D) @@ -387,8 +386,9 @@ install: \$(MKDIR) \$(INSTALLTOP) \$(MKDIR) \$(INSTALLTOP)${o}bin \$(MKDIR) \$(INSTALLTOP)${o}include + \$(MKDIR) \$(INSTALLTOP)${o}include${o}openssl \$(MKDIR) \$(INSTALLTOP)${o}lib - \$(CP) \$(INC_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include + \$(CP) \$(INCO_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include${o}openssl \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib @@ -401,6 +401,42 @@ vclean: \$(RM) \$(OUT_D)$o*.* EOF + +my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform"; +$platform_cpp_symbol =~ s/-/_/g; +if (open(IN,"crypto/buildinf.h")) + { + # Remove entry for this platform in existing file buildinf.h. + + my $old_buildinf_h = ""; + while () + { + if (/^\#ifdef $platform_cpp_symbol$/) + { + while () { last if (/^\#endif/); } + } + else + { + $old_buildinf_h .= $_; + } + } + close(IN); + + open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h"; + print OUT $old_buildinf_h; + close(OUT); + } + +open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h"; +printf OUT <) { + $options=$1 if (/^OPTIONS=(.*)$/); +} +close(IN); + +foreach (@ARGV, split(/ /, $options)) { - $NT=1 if $_ eq "32"; - $NT=0 if $_ eq "16"; + $W32=1 if $_ eq "32"; + $W32=0 if $_ eq "16"; + if($_ eq "NT") { + $W32 = 1; + $NT = 1; + } $do_ssl=1 if $_ eq "ssleay"; + $do_ssl=1 if $_ eq "ssl"; $do_crypto=1 if $_ eq "libeay"; + $do_crypto=1 if $_ eq "crypto"; + $do_update=1 if $_ eq "update"; + $rsaref=1 if $_ eq "rsaref"; + + if (/^no-rc2$/) { $no_rc2=1; } + elsif (/^no-rc4$/) { $no_rc4=1; } + elsif (/^no-rc5$/) { $no_rc5=1; } + elsif (/^no-idea$/) { $no_idea=1; } + elsif (/^no-des$/) { $no_des=1; } + elsif (/^no-bf$/) { $no_bf=1; } + elsif (/^no-cast$/) { $no_cast=1; } + elsif (/^no-md2$/) { $no_md2=1; } + elsif (/^no-md5$/) { $no_md5=1; } + elsif (/^no-sha$/) { $no_sha=1; } + elsif (/^no-ripemd$/) { $no_ripemd=1; } + elsif (/^no-mdc2$/) { $no_mdc2=1; } + elsif (/^no-rsa$/) { $no_rsa=1; } + elsif (/^no-dsa$/) { $no_dsa=1; } + elsif (/^no-dh$/) { $no_dh=1; } + elsif (/^no-hmac$/) { $no_hmac=1; } } if (!$do_ssl && !$do_crypto) { - print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 ]\n"; + print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n"; exit(1); } %ssl_list=&load_numbers($ssl_num); +$max_ssl = $max_num; %crypto_list=&load_numbers($crypto_num); +$max_crypto = $max_num; $ssl="ssl/ssl.h"; $crypto ="crypto/crypto.h"; -$crypto.=" crypto/des/des.h"; -$crypto.=" crypto/idea/idea.h"; -$crypto.=" crypto/rc4/rc4.h"; -$crypto.=" crypto/rc5/rc5.h"; -$crypto.=" crypto/rc2/rc2.h"; -$crypto.=" crypto/bf/blowfish.h"; -$crypto.=" crypto/cast/cast.h"; -$crypto.=" crypto/md2/md2.h"; -$crypto.=" crypto/md5/md5.h"; -$crypto.=" crypto/mdc2/mdc2.h"; -$crypto.=" crypto/sha/sha.h"; -$crypto.=" crypto/ripemd/ripemd.h"; +$crypto.=" crypto/des/des.h" unless $no_des; +$crypto.=" crypto/idea/idea.h" unless $no_idea; +$crypto.=" crypto/rc4/rc4.h" unless $no_rc4; +$crypto.=" crypto/rc5/rc5.h" unless $no_rc5; +$crypto.=" crypto/rc2/rc2.h" unless $no_rc2; +$crypto.=" crypto/bf/blowfish.h" unless $no_bf; +$crypto.=" crypto/cast/cast.h" unless $no_cast; +$crypto.=" crypto/md2/md2.h" unless $no_md2; +$crypto.=" crypto/md5/md5.h" unless $no_md5; +$crypto.=" crypto/mdc2/mdc2.h" unless $no_mdc2; +$crypto.=" crypto/sha/sha.h" unless $no_sha; +$crypto.=" crypto/ripemd/ripemd.h" unless $no_ripemd; $crypto.=" crypto/bn/bn.h"; -$crypto.=" crypto/rsa/rsa.h"; -$crypto.=" crypto/dsa/dsa.h"; -$crypto.=" crypto/dh/dh.h"; +$crypto.=" crypto/rsa/rsa.h" unless $no_rsa; +$crypto.=" crypto/dsa/dsa.h" unless $no_dsa; +$crypto.=" crypto/dh/dh.h" unless $no_dh; +$crypto.=" crypto/hmac/hmac.h" unless $no_hmac; $crypto.=" crypto/stack/stack.h"; $crypto.=" crypto/buffer/buffer.h"; @@ -63,182 +107,255 @@ $crypto.=" crypto/asn1/asn1.h"; $crypto.=" crypto/asn1/asn1_mac.h"; $crypto.=" crypto/err/err.h"; $crypto.=" crypto/pkcs7/pkcs7.h"; +$crypto.=" crypto/pkcs12/pkcs12.h"; $crypto.=" crypto/x509/x509.h"; $crypto.=" crypto/x509/x509_vfy.h"; +$crypto.=" crypto/x509v3/x509v3.h"; $crypto.=" crypto/rand/rand.h"; -$crypto.=" crypto/hmac/hmac.h"; +$crypto.=" crypto/comp/comp.h"; +$crypto.=" crypto/tmdiff.h"; + +@ssl_func = &do_defs("SSLEAY", $ssl); +@crypto_func = &do_defs("LIBEAY", $crypto); + + +if ($do_update) { + +if ($do_ssl == 1) { + open(OUT, ">>$ssl_num"); + &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl, @ssl_func); + close OUT; +} -$match{'NOPROTO'}=1; -$match2{'PERL5'}=1; +if($do_crypto == 1) { + open(OUT, ">>$crypto_num"); + &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto, @crypto_func); + close OUT; +} -&print_def_file(*STDOUT,"SSLEAY",*ssl_list,&do_defs("SSLEAY",$ssl)) - if $do_ssl == 1; +} else { + + &print_def_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func) + if $do_ssl == 1; + + &print_def_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func) + if $do_crypto == 1; + +} -&print_def_file(*STDOUT,"LIBEAY",*crypto_list,&do_defs("LIBEAY",$crypto)) - if $do_crypto == 1; sub do_defs - { - local($name,$files)=@_; - local(@ret); +{ + my($name,$files)=@_; + my @ret; + my %funcs; - $off=-1; foreach $file (split(/\s+/,$files)) { -# print STDERR "reading $file\n"; open(IN,"<$file") || die "unable to open $file:$!\n"; - $depth=0; - $pr=-1; - @np=""; - $/=undef; - $a=; - while (($i=index($a,"/*")) >= 0) - { - $j=index($a,"*/"); - break unless ($j >= 0); - $a=substr($a,0,$i).substr($a,$j+2); - # print "$i $j\n"; + + my $line = "", $def= ""; + my %tag = ( + FreeBSD => 0, + NOPROTO => 0, + WIN16 => 0, + PERL5 => 0, + _WINDLL => 0, + NO_FP_API => 0, + CONST_STRICT => 0, + TRUE => 1, + ); + while() { + last if (/BEGIN ERROR CODES/); + if ($line ne '') { + $_ = $line . $_; + $line = ''; } - foreach (split("\n",$a)) - { - if (/^\#\s*ifndef (.*)/) - { + + if (/\\$/) { + $line = $_; + next; + } + + $cpp = 1 if /^#.*ifdef.*cplusplus/; + if ($cpp) { + $cpp = 0 if /^#.*endif/; + next; + } + + s/\/\*.*?\*\///gs; # ignore comments + s/{[^{}]*}//gs; # ignore {} blocks + if (/^\#\s*ifndef (.*)/) { push(@tag,$1); $tag{$1}=-1; next; - } - elsif (/^\#\s*if !defined\(([^\)]+)\)/) - { + } elsif (/^\#\s*if !defined\(([^\)]+)\)/) { push(@tag,$1); $tag{$1}=-1; next; - } - elsif (/^\#\s*ifdef (.*)/) - { + } elsif (/^\#\s*ifdef (.*)/) { push(@tag,$1); $tag{$1}=1; next; - } - elsif (/^\#\s*if defined(.*)/) - { + } elsif (/^\#\s*if defined(.*)/) { push(@tag,$1); $tag{$1}=1; next; - } - elsif (/^\#\s*endif/) - { + } elsif (/^\#\s*endif/) { $tag{$tag[$#tag]}=0; pop(@tag); next; - } - elsif (/^\#\s*else/) - { - $t=$tag[$#tag]; + } elsif (/^\#\s*else/) { + my $t=$tag[$#tag]; $tag{$t}= -$tag{$t}; next; + } elsif (/^\#\s*if\s+1/) { + # Dummy tag + push(@tag,"TRUE"); + $tag{"TRUE"}=1; + next; + } elsif (/^\#/) { + next; + } + if ($safe_stack_def && + /^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) { + $funcs{"sk_${1}_new"} = 1; + $funcs{"sk_${1}_new_null"} = 1; + $funcs{"sk_${1}_free"} = 1; + $funcs{"sk_${1}_num"} = 1; + $funcs{"sk_${1}_value"} = 1; + $funcs{"sk_${1}_set"} = 1; + $funcs{"sk_${1}_zero"} = 1; + $funcs{"sk_${1}_push"} = 1; + $funcs{"sk_${1}_unshift"} = 1; + $funcs{"sk_${1}_find"} = 1; + $funcs{"sk_${1}_delete"} = 1; + $funcs{"sk_${1}_delete_ptr"} = 1; + $funcs{"sk_${1}_insert"} = 1; + $funcs{"sk_${1}_set_cmp_func"} = 1; + $funcs{"sk_${1}_dup"} = 1; + $funcs{"sk_${1}_pop_free"} = 1; + $funcs{"sk_${1}_shift"} = 1; + $funcs{"sk_${1}_pop"} = 1; + $funcs{"sk_${1}_sort"} = 1; + } elsif ($safe_stack_def && + /^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) { + $funcs{"d2i_ASN1_SET_OF_${1}"} = 1; + $funcs{"i2d_ASN1_SET_OF_${1}"} = 1; + } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ || + /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) { + if($W32) { + $funcs{"PEM_read_${1}"} = 1; + $funcs{"PEM_write_${1}"} = 1; } -#printf STDERR "$_\n%2d %2d %2d %2d %2d $NT\n", -#$tag{'NOPROTO'},$tag{'FreeBSD'},$tag{'WIN16'},$tag{'PERL5'},$tag{'NO_FP_API'}; - - $t=undef; - if (/^extern .*;$/) - { $t=&do_extern($name,$_); } - elsif ( ($tag{'NOPROTO'} == 1) && + $funcs{"PEM_read_bio_${1}"} = 1; + $funcs{"PEM_write_bio_${1}"} = 1; + } elsif ( ($tag{'FreeBSD'} != 1) && - (($NT && ($tag{'WIN16'} != 1)) || - (!$NT && ($tag{'WIN16'} != -1))) && + ($tag{'CONST_STRICT'} != 1) && + (($W32 && ($tag{'WIN16'} != 1)) || + (!$W32 && ($tag{'WIN16'} != -1))) && ($tag{'PERL5'} != 1) && # ($tag{'_WINDLL'} != -1) && - ((!$NT && $tag{'_WINDLL'} != -1) || - ($NT && $tag{'_WINDLL'} != 1)) && - ((($tag{'NO_FP_API'} != 1) && $NT) || - (($tag{'NO_FP_API'} != -1) && !$NT))) - { $t=&do_line($name,$_); } - else - { $t=undef; } - if (($t ne undef) && (!$done{$name,$t})) + ((!$W32 && $tag{'_WINDLL'} != -1) || + ($W32 && $tag{'_WINDLL'} != 1)) && + ((($tag{'NO_FP_API'} != 1) && $W32) || + (($tag{'NO_FP_API'} != -1) && !$W32))) { - $done{$name,$t}++; - push(@ret,$t); -#printf STDERR "one:$t\n" if $t =~ /BIO_/; + if (/{|\/\*/) { # } + $line = $_; + } else { + $def .= $_; + } } } close(IN); + + foreach (split /;/, $def) { + s/^[\n\s]*//g; + s/[\n\s]*$//g; + next if(/typedef\W/); + next if(/EVP_bf/ and $no_bf); + next if(/EVP_cast/ and $no_cast); + next if(/EVP_des/ and $no_des); + next if(/EVP_dss/ and $no_dsa); + next if(/EVP_idea/ and $no_idea); + next if(/EVP_md2/ and $no_md2); + next if(/EVP_md5/ and $no_md5); + next if(/EVP_rc2/ and $no_rc2); + next if(/EVP_rc4/ and $no_rc4); + next if(/EVP_rc5/ and $no_rc5); + next if(/EVP_ripemd/ and $no_ripemd); + next if(/EVP_sha/ and $no_sha); + if (/\(\*(\w*)\([^\)]+/) { + $funcs{$1} = 1; + } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) { + # K&R C + next; + } elsif (/\w+\W+\w+\W*\(.*\)$/s) { + while (not /\(\)$/s) { + s/[^\(\)]*\)$/\)/s; + s/\([^\(\)]*\)\)$/\)/s; + } + s/\(void\)//; + /(\w+)\W*\(\)/s; + $funcs{$1} = 1; + } elsif (/\(/ and not (/=/)) { + print STDERR "File $file: cannot parse: $_;\n"; + } } - return(@ret); } -sub do_line - { - local($file,$_)=@_; - local($n); - - return(undef) if /^$/; - return(undef) if /^\s/; -#printf STDERR "two:$_\n" if $_ =~ /BIO_/; - if (/(CRYPTO_get_locking_callback)/) - { return($1); } - elsif (/(CRYPTO_get_id_callback)/) - { return($1); } - elsif (/(CRYPTO_get_add_lock_callback)/) - { return($1); } - elsif (/(SSL_CTX_get_verify_callback)/) - { return($1); } - elsif (/(SSL_get_info_callback)/) - { return($1); } - elsif ((!$NT) && /(ERR_load_CRYPTO_strings)/) - { return("ERR_load_CRYPTOlib_strings"); } - elsif (!$NT && /BIO_s_file/) - { return(undef); } - elsif (!$NT && /BIO_new_file/) - { return(undef); } - elsif (!$NT && /BIO_new_fp/) - { return(undef); } - elsif ($NT && /BIO_s_file_internal/) - { return(undef); } - elsif ($NT && /BIO_new_file_internal/) - { return(undef); } - elsif ($NT && /BIO_new_fp_internal/) - { return(undef); } - else - { - /\s\**(\S+)\s*\(/; - return($1); + # Prune the returned functions + + delete $funcs{"SSL_add_dir_cert_subjects_to_stack"}; + delete $funcs{"des_crypt"}; + delete $funcs{"RSA_PKCS1_RSAref"} unless $rsaref; + + if($W32) { + delete $funcs{"BIO_s_file_internal"}; + delete $funcs{"BIO_new_file_internal"}; + delete $funcs{"BIO_new_fp_internal"}; + } else { + if(exists $funcs{"ERR_load_CRYPTO_strings"}) { + delete $funcs{"ERR_load_CRYPTO_strings"}; + $funcs{"ERR_load_CRYPTOlib_strings"} = 1; } + delete $funcs{"BIO_s_file"}; + delete $funcs{"BIO_new_file"}; + delete $funcs{"BIO_new_fp"}; + } + if (!$NT) { + delete $funcs{"BIO_s_log"}; } -sub do_extern - { - local($file,$_)=@_; - local($n); + push @ret, keys %funcs; - /\s\**(\S+);$/; - return($1); - } + return(@ret); +} sub print_def_file - { - local(*OUT,$name,*nums,@functions)=@_; - local($n)=1; +{ + (*OUT,my $name,*nums,@functions)=@_; + my $n =1; - if ($NT) + if ($W32) { $name.="32"; } else { $name.="16"; } print OUT <<"EOF"; ; -; Definition file for the DDL version of the $name library from SSLeay +; Definition file for the DLL version of the $name library from OpenSSL ; LIBRARY $name -DESCRIPTION 'SSLeay $name - eay\@cryptsoft.com' +DESCRIPTION 'OpenSSL $name - http://www.openssl.org/' EOF - if (!$NT) - { + if (!$W32) { print <<"EOF"; CODE PRELOAD MOVEABLE DATA PRELOAD MOVEABLE SINGLE @@ -249,7 +366,7 @@ HEAPSIZE 4096 STACKSIZE 8192 EOF - } + } print "EXPORTS\n"; @@ -258,35 +375,52 @@ EOF (@r)=grep(!/^SSLeay/,@functions); @functions=((sort @e),(sort @r)); - foreach $func (@functions) - { - if (!defined($nums{$func})) - { - printf STDERR "$func does not have a number assigned\n"; - } - else - { + foreach $func (@functions) { + if (!defined($nums{$func})) { + printf STDERR "$func does not have a number assigned\n" + if(!$do_update); + } else { $n=$nums{$func}; - printf OUT " %s%-35s@%d\n",($NT)?"":"_",$func,$n; - } + printf OUT " %s%-40s@%d\n",($W32)?"":"_",$func,$n; } - printf OUT "\n"; } + printf OUT "\n"; +} sub load_numbers - { - local($name)=@_; - local($j,@a,%ret); +{ + my($name)=@_; + my(@a,%ret); + + $max_num = 0; open(IN,"<$name") || die "unable to open $name:$!\n"; - while () - { + while () { chop; s/#.*$//; next if /^\s*$/; @a=split; $ret{$a[0]}=$a[1]; - } + $max_num = $a[1] if $a[1] > $max_num; + } close(IN); return(%ret); +} + +sub update_numbers +{ + (*OUT,$name,*nums,my $start_num, my @functions)=@_; + my $new_funcs = 0; + print STDERR "Updating $name\n"; + foreach $func (@functions) { + if (!exists $nums{$func}) { + $new_funcs++; + printf OUT "%s%-40s%d\n","",$func, ++$start_num; + } + } + if($new_funcs) { + print STDERR "$new_funcs New Functions added\n"; + } else { + print STDERR "No New Functions Added\n"; } +} diff --git a/src/lib/libcrypto/util/mkdir-p.pl b/src/lib/libcrypto/util/mkdir-p.pl new file mode 100644 index 0000000000..6c69c2daa4 --- /dev/null +++ b/src/lib/libcrypto/util/mkdir-p.pl @@ -0,0 +1,33 @@ +#!/usr/local/bin/perl + +# mkdir-p.pl + +# On some systems, the -p option to mkdir (= also create any missing parent +# directories) is not available. + +my $arg; + +foreach $arg (@ARGV) { + &do_mkdir_p($arg); +} + + +sub do_mkdir_p { + local($dir) = @_; + + $dir =~ s|/*\Z(?!\n)||s; + + if (-d $dir) { + return; + } + + if ($dir =~ m|[^/]/|s) { + local($parent) = $dir; + $parent =~ s|[^/]*\Z(?!\n)||s; + + do_mkdir_p($parent); + } + + mkdir($dir, 0777) || die "Cannot create directory $dir: $!\n"; + print "created directory `$dir'\n"; +} diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl new file mode 100644 index 0000000000..4b3bccb13e --- /dev/null +++ b/src/lib/libcrypto/util/mkerr.pl @@ -0,0 +1,503 @@ +#!/usr/local/bin/perl -w + +my $config = "crypto/err/openssl.ec"; +my $debug = 0; +my $rebuild = 0; +my $static = 1; +my $recurse = 0; +my $reindex = 0; +my $dowrite = 0; + + +while (@ARGV) { + my $arg = $ARGV[0]; + if($arg eq "-conf") { + shift @ARGV; + $config = shift @ARGV; + } elsif($arg eq "-debug") { + $debug = 1; + shift @ARGV; + } elsif($arg eq "-rebuild") { + $rebuild = 1; + shift @ARGV; + } elsif($arg eq "-recurse") { + $recurse = 1; + shift @ARGV; + } elsif($arg eq "-reindex") { + $reindex = 1; + shift @ARGV; + } elsif($arg eq "-nostatic") { + $static = 0; + shift @ARGV; + } elsif($arg eq "-write") { + $dowrite = 1; + shift @ARGV; + } else { + last; + } +} + +if($recurse) { + @source = (, , ,, ); +} else { + @source = @ARGV; +} + +# Read in the config file + +open(IN, "<$config") || die "Can't open config file $config"; + +# Parse config file + +while() +{ + if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) { + $hinc{$1} = $2; + $cskip{$3} = $1; + if($3 ne "NONE") { + $csrc{$1} = $3; + $fmax{$1} = 99; + $rmax{$1} = 99; + $fnew{$1} = 0; + $rnew{$1} = 0; + } + } elsif (/^F\s+(\S+)/) { + # Add extra function with $1 + } elsif (/^R\s+(\S+)\s+(\S+)/) { + $rextra{$1} = $2; + $rcodes{$1} = $2; + } +} + +close IN; + +# Scan each header file in turn and make a list of error codes +# and function names + +while (($lib, $hdr) = each %hinc) +{ + next if($hdr eq "NONE"); + print STDERR "Scanning header file $hdr\n" if $debug; + open(IN, "<$hdr") || die "Can't open Header file $hdr\n"; + my $line = "", $def= ""; + while() { + last if(/BEGIN\s+ERROR\s+CODES/); + if ($line ne '') { + $_ = $line . $_; + $line = ''; + } + + if (/\\$/) { + $line = $_; + next; + } + + $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration + if ($cpp) { + $cpp = 0 if /^#.*endif/; + next; + } + + next if (/^#/); # skip preprocessor directives + + s/\/\*.*?\*\///gs; # ignore comments + s/{[^{}]*}//gs; # ignore {} blocks + + if (/{|\/\*/) { # Add a } so editor works... + $line = $_; + } else { + $def .= $_; + } + } + + foreach (split /;/, $def) { + s/^[\n\s]*//g; + s/[\n\s]*$//g; + next if(/typedef\W/); + if (/\(\*(\w*)\([^\)]+/) { + my $name = $1; + $name =~ tr/[a-z]/[A-Z]/; + $ftrans{$name} = $1; + } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){ + # K&R C + next ; + } elsif (/\w+\W+\w+\W*\(.*\)$/s) { + while (not /\(\)$/s) { + s/[^\(\)]*\)$/\)/s; + s/\([^\(\)]*\)\)$/\)/s; + } + s/\(void\)//; + /(\w+)\W*\(\)/s; + my $name = $1; + $name =~ tr/[a-z]/[A-Z]/; + $ftrans{$name} = $1; + } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) { + print STDERR "Header $hdr: cannot parse: $_;\n"; + } + } + + next if $reindex; + + # Scan function and reason codes and store them: keep a note of the + # maximum code used. + + while() { + if(/^#define\s+(\S+)\s+(\S+)/) { + $name = $1; + $code = $2; + unless($name =~ /^${lib}_([RF])_(\w+)$/) { + print STDERR "Invalid error code $name\n"; + next; + } + if($1 eq "R") { + $rcodes{$name} = $code; + if(!(exists $rextra{$name}) && + ($code > $rmax{$lib}) ) { + $rmax{$lib} = $code; + } + } else { + if($code > $fmax{$lib}) { + $fmax{$lib} = $code; + } + $fcodes{$name} = $code; + } + } + } + close IN; +} + +# Scan each C source file and look for function and reason codes +# This is done by looking for strings that "look like" function or +# reason codes: basically anything consisting of all upper case and +# numerics which has _F_ or _R_ in it and which has the name of an +# error library at the start. This seems to work fine except for the +# oddly named structure BIO_F_CTX which needs to be ignored. +# If a code doesn't exist in list compiled from headers then mark it +# with the value "X" as a place holder to give it a value later. +# Store all function and reason codes found in %ufcodes and %urcodes +# so all those unreferenced can be printed out. + + +foreach $file (@source) { + # Don't parse the error source file. + next if exists $cskip{$file}; + open(IN, "<$file") || die "Can't open source file $file\n"; + while() { + if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { + next unless exists $csrc{$2}; + next if($1 eq "BIO_F_BUFFER_CTX"); + $ufcodes{$1} = 1; + if(!exists $fcodes{$1}) { + $fcodes{$1} = "X"; + $fnew{$2}++; + } + $notrans{$1} = 1 unless exists $ftrans{$3}; + } + if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) { + next unless exists $csrc{$2}; + $urcodes{$1} = 1; + if(!exists $rcodes{$1}) { + $rcodes{$1} = "X"; + $rnew{$2}++; + } + } + } + close IN; +} + +# Now process each library in turn. + +foreach $lib (keys %csrc) +{ + my $hfile = $hinc{$lib}; + my $cfile = $csrc{$lib}; + if(!$fnew{$lib} && !$rnew{$lib}) { + print STDERR "$lib:\t\tNo new error codes\n"; + next unless $rebuild; + } else { + print STDERR "$lib:\t\t$fnew{$lib} New Functions,"; + print STDERR " $rnew{$lib} New Reasons.\n"; + next unless $dowrite; + } + + # If we get here then we have some new error codes so we + # need to rebuild the header file and C file. + + # Make a sorted list of error and reason codes for later use. + + my @function = sort grep(/^${lib}_/,keys %fcodes); + my @reasons = sort grep(/^${lib}_/,keys %rcodes); + + # Rewrite the header file + + open(IN, "<$hfile") || die "Can't Open Header File $hfile\n"; + + # Copy across the old file + while() { + push @out, $_; + last if (/BEGIN ERROR CODES/); + } + close IN; + + open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n"; + + print OUT @out; + undef @out; + print OUT <<"EOF"; +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +/* Error codes for the $lib functions. */ + +/* Function codes. */ +EOF + + foreach $i (@function) { + $z=6-int(length($i)/8); + if($fcodes{$i} eq "X") { + $fcodes{$i} = ++$fmax{$lib}; + print STDERR "New Function code $i\n" if $debug; + } + printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z; + } + + print OUT "\n/* Reason codes. */\n"; + + foreach $i (@reasons) { + $z=6-int(length($i)/8); + if($rcodes{$i} eq "X") { + $rcodes{$i} = ++$rmax{$lib}; + print STDERR "New Reason code $i\n" if $debug; + } + printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z; + } + print OUT <<"EOF"; + +#ifdef __cplusplus +} +#endif +#endif + +EOF + close OUT; + + # Rewrite the C source file containing the error details. + + my $hincf; + if($static) { + $hfile =~ /([^\/]+)$/; + $hincf = ""; + } else { + $hincf = "\"$hfile\""; + } + + + open (OUT,">$cfile") || die "Can't open $cfile for writing"; + + print OUT <<"EOF"; +/* $cfile */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core\@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay\@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh\@cryptsoft.com). + * + */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + +#include +#include +#include $hincf + +/* BEGIN ERROR CODES */ +#ifndef NO_ERR +static ERR_STRING_DATA ${lib}_str_functs[]= + { +EOF + # Add each function code: if a function name is found then use it. + foreach $i (@function) { + my $fn; + $i =~ /^${lib}_F_(\S+)$/; + $fn = $1; + if(exists $ftrans{$fn}) { + $fn = $ftrans{$fn}; + } + print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n"; + } + print OUT <<"EOF"; +{0,NULL} + }; + +static ERR_STRING_DATA ${lib}_str_reasons[]= + { +EOF + # Add each reason code. + foreach $i (@reasons) { + my $rn; + my $nspc = 0; + $i =~ /^${lib}_R_(\S+)$/; + $rn = $1; + $rn =~ tr/_[A-Z]/ [a-z]/; + $nspc = 40 - length($i) unless length($i) > 40; + $nspc = " " x $nspc; + print OUT "{${i}${nspc},\"$rn\"},\n"; + } +if($static) { + print OUT <<"EOF"; +{0,NULL} + }; + +#endif + +void ERR_load_${lib}_strings(void) + { + static int init=1; + + if (init) + { + init=0; +#ifndef NO_ERR + ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs); + ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons); +#endif + + } + } +EOF +} else { + print OUT <<"EOF"; +{0,NULL} + }; + +#endif + +#ifdef ${lib}_LIB_NAME +static ERR_STRING_DATA ${lib}_lib_name[]= + { +{0 ,${lib}_LIB_NAME}, +{0,NULL} + }; +#endif + + +int ${lib}_lib_error_code=0; + +void ERR_load_${lib}_strings(void) + { + static int init=1; + + if (${lib}_lib_error_code == 0) + ${lib}_lib_error_code=ERR_get_next_error_library(); + + if (init) + { + init=0; +#ifndef NO_ERR + ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs); + ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons); +#endif + +#ifdef ${lib}_LIB_NAME + ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0); + ERR_load_strings(0,${lib}_lib_name); +#endif; + } + } + +void ERR_${lib}_error(int function, int reason, char *file, int line) + { + if (${lib}_lib_error_code == 0) + ${lib}_lib_error_code=ERR_get_next_error_library(); + ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line); + } +EOF + +} + + close OUT; + +} + +if($debug && defined(%notrans)) { + print STDERR "The following function codes were not translated:\n"; + foreach(sort keys %notrans) + { + print STDERR "$_\n"; + } +} + +# Make a list of unreferenced function and reason codes + +foreach (keys %fcodes) { + push (@funref, $_) unless exists $ufcodes{$_}; +} + +foreach (keys %rcodes) { + push (@runref, $_) unless exists $urcodes{$_}; +} + +if($debug && defined(@funref) ) { + print STDERR "The following function codes were not referenced:\n"; + foreach(sort @funref) + { + print STDERR "$_\n"; + } +} + +if($debug && defined(@runref) ) { + print STDERR "The following reason codes were not referenced:\n"; + foreach(sort @runref) + { + print STDERR "$_\n"; + } +} diff --git a/src/lib/libcrypto/util/mkfiles.pl b/src/lib/libcrypto/util/mkfiles.pl new file mode 100644 index 0000000000..6fa424bd19 --- /dev/null +++ b/src/lib/libcrypto/util/mkfiles.pl @@ -0,0 +1,110 @@ +#!/usr/local/bin/perl +# +# This is a hacked version of files.pl for systems that can't do a 'make files'. +# Do a perl util/mkminfo.pl >MINFO to build MINFO +# Written by Steve Henson 1999. + +# List of directories to process + +my @dirs = ( +".", +"crypto", +"crypto/md2", +"crypto/md5", +"crypto/sha", +"crypto/mdc2", +"crypto/hmac", +"crypto/ripemd", +"crypto/des", +"crypto/rc2", +"crypto/rc4", +"crypto/rc5", +"crypto/idea", +"crypto/bf", +"crypto/cast", +"crypto/bn", +"crypto/rsa", +"crypto/dsa", +"crypto/dh", +"crypto/buffer", +"crypto/bio", +"crypto/stack", +"crypto/lhash", +"crypto/rand", +"crypto/err", +"crypto/objects", +"crypto/evp", +"crypto/asn1", +"crypto/pem", +"crypto/x509", +"crypto/x509v3", +"crypto/conf", +"crypto/txt_db", +"crypto/pkcs7", +"crypto/pkcs12", +"crypto/comp", +"ssl", +"rsaref", +"apps", +"test", +"tools" +); + +foreach (@dirs) { + &files_dir ($_, "Makefile.ssl"); +} + +exit(0); + +sub files_dir +{ +my ($dir, $makefile) = @_; + +my %sym; + +open (IN, "$dir/$makefile") || die "Can't open $dir/$makefile"; + +my $s=""; + +while () + { + chop; + s/#.*//; + if (/^(\S+)\s*=\s*(.*)$/) + { + $o=""; + ($s,$b)=($1,$2); + for (;;) + { + if ($b =~ /\\$/) + { + chop($b); + $o.=$b." "; + $b=; + chop($b); + } + else + { + $o.=$b." "; + last; + } + } + $o =~ s/^\s+//; + $o =~ s/\s+$//; + $o =~ s/\s+/ /g; + + $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g; + $sym{$s}=$o; + } + } + +print "RELATIVE_DIRECTORY=$dir\n"; + +foreach (sort keys %sym) + { + print "$_=$sym{$_}\n"; + } +print "RELATIVE_DIRECTORY=\n"; + +close (IN); +} diff --git a/src/lib/libcrypto/util/mklink.pl b/src/lib/libcrypto/util/mklink.pl new file mode 100644 index 0000000000..de555820ec --- /dev/null +++ b/src/lib/libcrypto/util/mklink.pl @@ -0,0 +1,55 @@ +#!/usr/local/bin/perl + +# mklink.pl + +# The first command line argument is a non-empty relative path +# specifying the "from" directory. +# Each other argument is a file name not containing / and +# names a file in the current directory. +# +# For each of these files, we create in the "from" directory a link +# of the same name pointing to the local file. +# +# We assume that the directory structure is a tree, i.e. that it does +# not contain symbolic links and that the parent of / is never referenced. +# Apart from this, this script should be able to handle even the most +# pathological cases. + +my $from = shift; +my @files = @ARGV; + +my @from_path = split(/\//, $from); +my $pwd = `pwd`; +chop($pwd); +my @pwd_path = split(/\//, $pwd); + +my @to_path = (); + +my $dirname; +foreach $dirname (@from_path) { + + # In this loop, @to_path always is a relative path from + # @pwd_path (interpreted is an absolute path) to the original pwd. + + # At the end, @from_path (as a relative path from the original pwd) + # designates the same directory as the absolute path @pwd_path, + # which means that @to_path then is a path from there to the original pwd. + + next if ($dirname eq "" || $dirname eq "."); + + if ($dirname eq "..") { + @to_path = (pop(@pwd_path), @to_path); + } else { + @to_path = ("..", @to_path); + push(@pwd_path, $dirname); + } +} + +my $to = join('/', @to_path); + +my $file; +foreach $file (@files) { +# print "ln -s $to/$file $from/$file\n"; + symlink("$to/$file", "$from/$file"); + print $file . " => $from/$file\n"; +} diff --git a/src/lib/libcrypto/util/mklink.sh b/src/lib/libcrypto/util/mklink.sh deleted file mode 100644 index 1e052ed6ee..0000000000 --- a/src/lib/libcrypto/util/mklink.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -# -# A bit of an ugly shell script used to actually 'link' files. -# Used by 'make links' -# - -PATH=$PATH:.:util:../util:../../util -export PATH - -from=$1 -shift - -here=`pwd` -tmp=`dirname $from` -while [ "$tmp"x != "x" -a "$tmp"x != ".x" ] -do - t=`basename $here` - here=`dirname $here` - to="/$t$to" - tmp=`dirname $tmp` -done -to=..$to - -#echo from=$from -#echo to =$to -#exit 1 - -if [ "$*"x != "x" ]; then - for i in $* - do - /bin/rm -f $from/$i - point.sh $to/$i $from/$i - done -fi -exit 0; diff --git a/src/lib/libcrypto/util/perlpath.pl b/src/lib/libcrypto/util/perlpath.pl index 9e57e10ad4..a1f236bd98 100644 --- a/src/lib/libcrypto/util/perlpath.pl +++ b/src/lib/libcrypto/util/perlpath.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # modify the '#!/usr/local/bin/perl' # line in all scripts that rely on perl. @@ -17,7 +17,12 @@ sub wanted @a=; close(IN); - $a[0]="#!$ARGV[0]/perl\n"; + if (-d $ARGV[0]) { + $a[0]="#!$ARGV[0]/perl\n"; + } + else { + $a[0]="#!$ARGV[0]\n"; + } # Playing it safe... $new="$_.new"; diff --git a/src/lib/libcrypto/util/pl/BC-16.pl b/src/lib/libcrypto/util/pl/BC-16.pl index 7c3fdb68f4..6c6df4fe0b 100644 --- a/src/lib/libcrypto/util/pl/BC-16.pl +++ b/src/lib/libcrypto/util/pl/BC-16.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries # @@ -66,18 +66,18 @@ $asm='bcc -c -B -Tml'; $afile='/o'; if ($no_asm) { - $bn_mulw_obj=''; - $bn_mulw_src=''; + $bn_asm_obj=''; + $bn_asm_src=''; } elsif ($asmbits == 32) { - $bn_mulw_obj='crypto\bn\asm\x86w32.obj'; - $bn_mulw_src='crypto\bn\asm\x86w32.asm'; + $bn_asm_obj='crypto\bn\asm\x86w32.obj'; + $bn_asm_src='crypto\bn\asm\x86w32.asm'; } else { - $bn_mulw_obj='crypto\bn\asm\x86w16.obj'; - $bn_mulw_src='crypto\bn\asm\x86w16.asm'; + $bn_asm_obj='crypto\bn\asm\x86w16.obj'; + $bn_asm_src='crypto\bn\asm\x86w16.asm'; } sub do_lib_rule diff --git a/src/lib/libcrypto/util/pl/BC-32.pl b/src/lib/libcrypto/util/pl/BC-32.pl index 3898d16f61..09c45a21a6 100644 --- a/src/lib/libcrypto/util/pl/BC-32.pl +++ b/src/lib/libcrypto/util/pl/BC-32.pl @@ -1,102 +1,121 @@ -#!/usr/bin/perl -# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries +#!/usr/local/bin/perl +# Borland C++ builder 3 and 4 -- Janez Jere # +$ssl= "ssleay32"; +$crypto="libeay32"; +$RSAref="RSAref32"; + $o='\\'; $cp='copy'; $rm='del'; # C compiler stuff $cc='bcc32'; - +$lflags="-ap -Tpe -x -Gn "; +$mlflags=''; + +$out_def="out32"; +$tmp_def="tmp32"; +$inc_def="inc32"; +#enable max error messages, disable most common warnings +$cflags="-DWIN32_LEAN_AND_MEAN -j255 -w-aus -w-par -w-inl -c -tWC -tWM -DWINDOWS -DWIN32 -DL_ENDIAN "; if ($debug) - { $op="-v "; } -else { $op="-O "; } - -$cflags="-d $op -DL_ENDIAN "; -# I add the stack opt -$base_lflags="-c"; -$lflags="$base_lflags"; - -$cflags.=" -DWINDOWS -DWIN32"; -$app_cflag="-WC"; -$lib_cflag="-WC"; -$lflags.=" -Tpe"; - -if ($shlib) - { - $mlflags="$base_lflags -Tpe"; # stack if defined in .def file - $libs="libw ldllcew"; - } +{ + $cflags.="-Od -y -v -vi- -D_DEBUG"; + $mlflags.=' '; +} else - { $mlflags=''; } +{ + $cflags.="-O2 -ff -fp"; +} $obj='.obj'; $ofile="-o"; # EXE linking stuff -$link="tlink32"; +$link="ilink32"; $efile=""; $exep='.exe'; -$ex_libs="CW32.LIB IMPORT32.LIB"; -$ex_libs.=$no_sock?"":" wsock32.lib"; -$shlib_ex_obj="" if $shlib; -$app_ex_obj="C0X32.OBJ"; +if ($no_sock) + { $ex_libs=""; } +else { $ex_libs="cw32mt.lib import32.lib"; } # static library stuff -$mklib='tlib'; +$mklib='tlib /P64'; $ranlib=''; $plib=""; $libp=".lib"; $shlibp=($shlib)?".dll":".lib"; $lfile=''; -$asm='ml /Cp /c /Cx'; +$shlib_ex_obj=""; +$app_ex_obj="c0x32.obj"; + +$asm='n_o_T_a_s_m'; +$asm.=" /Zi" if $debug; $afile='/Fo'; -if ($noasm) + +$bn_mulw_obj=''; +$bn_mulw_src=''; +$des_enc_obj=''; +$des_enc_src=''; +$bf_enc_obj=''; +$bf_enc_src=''; + +if (!$no_asm) { - $bn_mulw_obj=''; - $bn_mulw_src=''; + $bn_mulw_obj='crypto\bn\asm\bn-win32.obj'; + $bn_mulw_src='crypto\bn\asm\bn-win32.asm'; + $des_enc_obj='crypto\des\asm\d-win32.obj crypto\des\asm\y-win32.obj'; + $des_enc_src='crypto\des\asm\d-win32.asm crypto\des\asm\y-win32.asm'; + $bf_enc_obj='crypto\bf\asm\b-win32.obj'; + $bf_enc_src='crypto\bf\asm\b-win32.asm'; + $cast_enc_obj='crypto\cast\asm\c-win32.obj'; + $cast_enc_src='crypto\cast\asm\c-win32.asm'; + $rc4_enc_obj='crypto\rc4\asm\r4-win32.obj'; + $rc4_enc_src='crypto\rc4\asm\r4-win32.asm'; + $rc5_enc_obj='crypto\rc5\asm\r5-win32.obj'; + $rc5_enc_src='crypto\rc5\asm\r5-win32.asm'; + $md5_asm_obj='crypto\md5\asm\m5-win32.obj'; + $md5_asm_src='crypto\md5\asm\m5-win32.asm'; + $sha1_asm_obj='crypto\sha\asm\s1-win32.obj'; + $sha1_asm_src='crypto\sha\asm\s1-win32.asm'; + $rmd160_asm_obj='crypto\ripemd\asm\rm-win32.obj'; + $rmd160_asm_src='crypto\ripemd\asm\rm-win32.asm'; + $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM"; } -else + +if ($shlib) { - $bn_mulw_obj='crypto\bn\asm\x86b32.obj'; - $bn_mulw_src='crypto\bn\asm\x86m32.asm'; + $mlflags.=" $lflags /dll"; +# $cflags =~ s| /MD| /MT|; + $lib_cflag=" /GD -D_WINDLL -D_DLL"; + $out_def="out32dll"; + $tmp_def="tmp32dll"; } sub do_lib_rule { - local($target,$name,$shlib)=@_; + local($objs,$target,$name,$shlib)=@_; local($ret,$Name); $taget =~ s/\//$o/g if $o ne '/'; ($Name=$name) =~ tr/a-z/A-Z/; - $ret.="$target: \$(${Name}OBJ)\n"; - $ret.="\t\$(RM) \$(O_$Name)\n"; - - # Due to a pathetic line length limit, I unwrap the args. - local($lib_names)=""; - local($dll_names)=""; - foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"})) - { - $lib_names.=" +$_ &\n"; - $dll_names.=" $_\n"; - } - +# $target="\$(LIB_D)$o$target"; + $ret.="$target: $objs\n"; if (!$shlib) { - $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n"; + # $ret.="\t\$(RM) \$(O_$Name)\n"; + $ret.="\techo LIB $<\n"; + $ret.="\t\$(MKLIB) $lfile$target \$(addprefix +, $objs)\n"; } else { - # $(SHLIB_EX_OBJ) - local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':""; - $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n"; - $ret.=$dll_names; - $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n"; - ($out_lib=$target) =~ s/O_/L_/; - $ret.="\timplib /nowep $out_lib $target\n\n"; + local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':''; + $ex.=' wsock32.lib gdi32.lib'; + $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n"; } $ret.="\n"; return($ret); @@ -105,30 +124,12 @@ sub do_lib_rule sub do_link_rule { local($target,$files,$dep_libs,$libs)=@_; - local($ret,$f,$_,@f); + local($ret,$_); $file =~ s/\//$o/g if $o ne '/'; $n=&bname($targer); $ret.="$target: $files $dep_libs\n"; - $ret.=" \$(LINK) @&&|"; - - # Due to a pathetic line length limit, I have to unwrap the args. - $r=" \$(LFLAGS) "; - if ($files =~ /\(([^)]*)\)$/) - { - @a=('$(APP_EX_OBJ)'); - push(@a,sort split(/\s+/,$Vars{$1})); - foreach $_ (@a) - { - $ret.="\n $r $_ +"; - $r=""; - } - chop($ret); - $ret.="\n"; - } - else - { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; } - $ret.=" $target\n\n $libs\n\n|\n\n"; + $ret.="\t\$(LINK) \$(LFLAGS) $files \$(APP_EX_OBJ), $target,, $libs\n\n"; return($ret); } diff --git a/src/lib/libcrypto/util/pl/Mingw32.pl b/src/lib/libcrypto/util/pl/Mingw32.pl new file mode 100644 index 0000000000..84c2a22db3 --- /dev/null +++ b/src/lib/libcrypto/util/pl/Mingw32.pl @@ -0,0 +1,79 @@ +#!/usr/local/bin/perl +# +# Mingw32.pl -- Mingw32 with GNU cp (Mingw32f.pl uses DOS tools) +# + +$o='/'; +$cp='cp'; +$rm='rem'; # use 'rm -f' if using GNU file utilities +$mkdir='gmkdir'; + +# gcc wouldn't accept backslashes in paths +#$o='\\'; +#$cp='copy'; +#$rm='del'; + +# C compiler stuff + +$cc='gcc'; +if ($debug) + { $cflags="-g2 -ggdb"; } +else + { $cflags="-DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall"; } + +$obj='.o'; +$ofile='-o '; + +# EXE linking stuff +$link='${CC}'; +$lflags='${CFLAGS}'; +$efile='-o '; +$exep=''; +$ex_libs="-lwsock32 -lgdi32"; + +# static library stuff +$mklib='ar r'; +$mlflags=''; +$ranlib='ranlib'; +$plib='lib'; +$libp=".a"; +$shlibp=".a"; +$lfile=''; + +$asm='as'; +$afile='-o '; +$bn_asm_obj=""; +$bn_asm_src=""; +$des_enc_obj=""; +$des_enc_src=""; +$bf_enc_obj=""; +$bf_enc_src=""; + +sub do_lib_rule + { + local($obj,$target,$name,$shlib)=@_; + local($ret,$_,$Name); + + $target =~ s/\//$o/g if $o ne '/'; + $target="$target"; + ($Name=$name) =~ tr/a-z/A-Z/; + + $ret.="$target: \$(${Name}OBJ)\n"; + $ret.="\t\$(RM) $target\n"; + $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n"; + $ret.="\t\$(RANLIB) $target\n\n"; + } + +sub do_link_rule + { + local($target,$files,$dep_libs,$libs)=@_; + local($ret,$_); + + $file =~ s/\//$o/g if $o ne '/'; + $n=&bname($target); + $ret.="$target: $files $dep_libs\n"; + $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n"; + return($ret); + } +1; + diff --git a/src/lib/libcrypto/util/pl/Mingw32f.pl b/src/lib/libcrypto/util/pl/Mingw32f.pl new file mode 100644 index 0000000000..a53c537646 --- /dev/null +++ b/src/lib/libcrypto/util/pl/Mingw32f.pl @@ -0,0 +1,73 @@ +#!/usr/local/bin/perl +# +# Mingw32f.pl -- copy files; Mingw32.pl is needed to do the compiling. +# + +$o='\\'; +$cp='copy'; +$rm='del'; + +# C compiler stuff + +$cc='gcc'; +if ($debug) + { $cflags="-g2 -ggdb"; } +else + { $cflags="-O3 -fomit-frame-pointer"; } + +$obj='.o'; +$ofile='-o '; + +# EXE linking stuff +$link='${CC}'; +$lflags='${CFLAGS}'; +$efile='-o '; +$exep=''; +$ex_libs="-lwsock32 -lgdi32"; + +# static library stuff +$mklib='ar r'; +$mlflags=''; +$ranlib='ranlib'; +$plib='lib'; +$libp=".a"; +$shlibp=".a"; +$lfile=''; + +$asm='as'; +$afile='-o '; +$bn_asm_obj=""; +$bn_asm_src=""; +$des_enc_obj=""; +$des_enc_src=""; +$bf_enc_obj=""; +$bf_enc_src=""; + +sub do_lib_rule + { + local($obj,$target,$name,$shlib)=@_; + local($ret,$_,$Name); + + $target =~ s/\//$o/g if $o ne '/'; + $target="$target"; + ($Name=$name) =~ tr/a-z/A-Z/; + + $ret.="$target: \$(${Name}OBJ)\n"; + $ret.="\t\$(RM) $target\n"; + $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n"; + $ret.="\t\$(RANLIB) $target\n\n"; + } + +sub do_link_rule + { + local($target,$files,$dep_libs,$libs)=@_; + local($ret,$_); + + $file =~ s/\//$o/g if $o ne '/'; + $n=&bname($target); + $ret.="$target: $files $dep_libs\n"; + $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n"; + return($ret); + } +1; + diff --git a/src/lib/libcrypto/util/pl/VC-16.pl b/src/lib/libcrypto/util/pl/VC-16.pl index a6e6c0241c..a5079d4ca7 100644 --- a/src/lib/libcrypto/util/pl/VC-16.pl +++ b/src/lib/libcrypto/util/pl/VC-16.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries # @@ -84,8 +84,8 @@ $lfile=''; $asm='ml /Cp /c /Cx'; $afile='/Fo'; -$bn_mulw_obj=''; -$bn_mulw_src=''; +$bn_asm_obj=''; +$bn_asm_src=''; $des_enc_obj=''; $des_enc_src=''; $bf_enc_obj=''; @@ -95,13 +95,13 @@ if (!$no_asm) { if ($asmbits == 32) { - $bn_mulw_obj='crypto\bn\asm\x86w32.obj'; - $bn_mulw_src='crypto\bn\asm\x86w32.asm'; + $bn_asm_obj='crypto\bn\asm\x86w32.obj'; + $bn_asm_src='crypto\bn\asm\x86w32.asm'; } else { - $bn_mulw_obj='crypto\bn\asm\x86w16.obj'; - $bn_mulw_src='crypto\bn\asm\x86w16.asm'; + $bn_asm_obj='crypto\bn\asm\x86w16.obj'; + $bn_asm_src='crypto\bn\asm\x86w16.asm'; } } diff --git a/src/lib/libcrypto/util/pl/VC-32.pl b/src/lib/libcrypto/util/pl/VC-32.pl index 701e282c33..6db1c9fe23 100644 --- a/src/lib/libcrypto/util/pl/VC-32.pl +++ b/src/lib/libcrypto/util/pl/VC-32.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries # @@ -7,7 +7,7 @@ $crypto="libeay32"; $RSAref="RSAref32"; $o='\\'; -$cp='copy'; +$cp='copy nul+'; # Timestamps get stuffed otherwise $rm='del'; # C compiler stuff @@ -22,10 +22,11 @@ $inc_def="inc32"; if ($debug) { - $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWINDOWS -DWIN32 -D_DEBUG -DL_ENDIAN"; + $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWINDOWS -DWIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG"; $lflags.=" /debug"; $mlflags.=' /debug'; } +$cflags .= " -DWINNT" if $NT == 1; $obj='.obj'; $ofile="/Fo"; @@ -48,13 +49,17 @@ $lfile='/out:'; $shlib_ex_obj=""; $app_ex_obj="setargv.obj"; - -$asm='ml /Cp /coff /c /Cx'; -$asm.=" /Zi" if $debug; -$afile='/Fo'; - -$bn_mulw_obj=''; -$bn_mulw_src=''; +if ($nasm) { + $asm='nasmw -f win32'; + $afile='-o '; +} else { + $asm='ml /Cp /coff /c /Cx'; + $asm.=" /Zi" if $debug; + $afile='/Fo'; +} + +$bn_asm_obj=''; +$bn_asm_src=''; $des_enc_obj=''; $des_enc_src=''; $bf_enc_obj=''; @@ -62,8 +67,8 @@ $bf_enc_src=''; if (!$no_asm) { - $bn_mulw_obj='crypto\bn\asm\bn-win32.obj'; - $bn_mulw_src='crypto\bn\asm\bn-win32.asm'; + $bn_asm_obj='crypto\bn\asm\bn-win32.obj'; + $bn_asm_src='crypto\bn\asm\bn-win32.asm'; $des_enc_obj='crypto\des\asm\d-win32.obj crypto\des\asm\y-win32.obj'; $des_enc_src='crypto\des\asm\d-win32.asm crypto\des\asm\y-win32.asm'; $bf_enc_obj='crypto\bf\asm\b-win32.obj'; @@ -92,6 +97,8 @@ if ($shlib) $tmp_def="tmp32dll"; } +$cflags.=" /Fd$out_def"; + sub do_lib_rule { local($objs,$target,$name,$shlib)=@_; @@ -110,7 +117,7 @@ sub do_lib_rule else { local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':''; - $ex.=' wsock32.lib gdi32.lib'; + $ex.=' wsock32.lib gdi32.lib advapi32.lib'; $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n"; } $ret.="\n"; diff --git a/src/lib/libcrypto/util/pl/linux.pl b/src/lib/libcrypto/util/pl/linux.pl index 2b13da1bfc..a8cfdc578a 100644 --- a/src/lib/libcrypto/util/pl/linux.pl +++ b/src/lib/libcrypto/util/pl/linux.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # linux.pl - the standard unix makefile stuff. # @@ -17,8 +17,8 @@ else if (!$no_asm) { - $bn_mulw_obj='$(OBJ_D)/bn86-elf.o'; - $bn_mulw_src='crypto/bn/asm/bn86unix.cpp'; + $bn_asm_obj='$(OBJ_D)/bn86-elf.o'; + $bn_asm_src='crypto/bn/asm/bn86unix.cpp'; $des_enc_obj='$(OBJ_D)/dx86-elf.o $(OBJ_D)/yx86-elf.o'; $des_enc_src='crypto/des/asm/dx86unix.cpp crypto/des/asm/yx86unix.cpp'; $bf_enc_obj='$(OBJ_D)/bx86-elf.o'; @@ -27,8 +27,12 @@ if (!$no_asm) $cast_enc_src='crypto/cast/asm/cx86unix.cpp'; $rc4_enc_obj='$(OBJ_D)/rx86-elf.o'; $rc4_enc_src='crypto/rc4/asm/rx86unix.cpp'; + $rc5_enc_obj='$(OBJ_D)/r586-elf.o'; + $rc5_enc_src='crypto/rc5/asm/r586unix.cpp'; $md5_asm_obj='$(OBJ_D)/mx86-elf.o'; $md5_asm_src='crypto/md5/asm/mx86unix.cpp'; + $rmd160_asm_obj='$(OBJ_D)/rm86-elf.o'; + $rmd160_asm_src='crypto/ripemd/asm/rm86unix.cpp'; $sha1_asm_obj='$(OBJ_D)/sx86-elf.o'; $sha1_asm_src='crypto/sha/asm/sx86unix.cpp'; $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM"; @@ -51,9 +55,9 @@ sub do_shlib_rule $target =~ s/\//$o/g if $o ne '/'; ($Name=$name) =~ tr/a-z/A-Z/; - $ret.="\$(LIB_D)$o$target: \$(${Name}OBJ)\n"; - $ret.="\t\$(RM) \$(LIB_D)$o$target\n"; - $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o \$(LIB_D)$o$target \$(${Name}OBJ)\n"; + $ret.="$target: \$(${Name}OBJ)\n"; + $ret.="\t\$(RM) target\n"; + $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o $target \$(${Name}OBJ)\n"; ($t=$target) =~ s/(^.*)\/[^\/]*$/$1/; if ($so_name ne "") { diff --git a/src/lib/libcrypto/util/pl/ultrix.pl b/src/lib/libcrypto/util/pl/ultrix.pl new file mode 100644 index 0000000000..ea370c71f9 --- /dev/null +++ b/src/lib/libcrypto/util/pl/ultrix.pl @@ -0,0 +1,38 @@ +#!/usr/local/bin/perl +# +# linux.pl - the standard unix makefile stuff. +# + +$o='/'; +$cp='/bin/cp'; +$rm='/bin/rm -f'; + +# C compiler stuff + +$cc='cc'; +if ($debug) + { $cflags="-g -DREF_CHECK -DCRYPTO_MDEBUG"; } +else + { $cflags="-O2"; } + +$cflags.=" -std1 -DL_ENDIAN"; + +if (!$no_asm) + { + $bn_asm_obj='$(OBJ_D)/mips1.o'; + $bn_asm_src='crypto/bn/asm/mips1.s'; + } + +sub do_link_rule + { + local($target,$files,$dep_libs,$libs)=@_; + local($ret,$_); + + $file =~ s/\//$o/g if $o ne '/'; + $n=&bname($target); + $ret.="$target: $files $dep_libs\n"; + $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n"; + return($ret); + } + +1; diff --git a/src/lib/libcrypto/util/pl/unix.pl b/src/lib/libcrypto/util/pl/unix.pl index ab4978fd20..146611ad99 100644 --- a/src/lib/libcrypto/util/pl/unix.pl +++ b/src/lib/libcrypto/util/pl/unix.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # unix.pl - the standard unix makefile stuff. # @@ -38,7 +38,7 @@ $ex_libs=""; # static library stuff $mklib='ar r'; $mlflags=''; -$ranlib='util/ranlib.sh'; +$ranlib=&which("ranlib") or $ranlib="true"; $plib='lib'; $libp=".a"; $shlibp=".a"; @@ -46,8 +46,8 @@ $lfile=''; $asm='as'; $afile='-o '; -$bn_mulw_obj=""; -$bn_mulw_src=""; +$bn_asm_obj=""; +$bn_asm_src=""; $des_enc_obj=""; $des_enc_src=""; $bf_enc_obj=""; @@ -59,7 +59,7 @@ sub do_lib_rule local($ret,$_,$Name); $target =~ s/\//$o/g if $o ne '/'; - $target="\$(LIB_D)$o$target"; + $target="$target"; ($Name=$name) =~ tr/a-z/A-Z/; $ret.="$target: \$(${Name}OBJ)\n"; @@ -80,4 +80,17 @@ sub do_link_rule return($ret); } +sub which + { + my ($name)=@_; + my $path; + foreach $path (split /:/, $ENV{PATH}) + { + if (-x "$path/$name") + { + return "$path/$name"; + } + } + } + 1; diff --git a/src/lib/libcrypto/util/point.sh b/src/lib/libcrypto/util/point.sh index 92c12e8282..47543c88e2 100644 --- a/src/lib/libcrypto/util/point.sh +++ b/src/lib/libcrypto/util/point.sh @@ -1,4 +1,6 @@ #!/bin/sh -/bin/rm -f $2 +rm -f $2 ln -s $1 $2 +echo "$2 => $1" + diff --git a/src/lib/libcrypto/util/ranlib.sh b/src/lib/libcrypto/util/ranlib.sh deleted file mode 100644 index 543f712c6b..0000000000 --- a/src/lib/libcrypto/util/ranlib.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh - -cwd=`pwd` -cd /tmp - -if [ -s /bin/ranlib ] ; then - RL=/bin/ranlib -else if [ -s /usr/bin/ranlib ] ; then - RL=/usr/bin/ranlib -fi -fi - -if [ "x$RL" != "x" ] -then - case "$1" in - /*) - $RL "$1" - ;; - *) - $RL "$cwd/$1" - ;; - esac -fi diff --git a/src/lib/libcrypto/util/sep_lib.sh b/src/lib/libcrypto/util/sep_lib.sh index 2348db874e..34c2c9f8ba 100644 --- a/src/lib/libcrypto/util/sep_lib.sh +++ b/src/lib/libcrypto/util/sep_lib.sh @@ -21,9 +21,6 @@ do /bin/rm -f *.old /bin/mv Makefile.uni Makefile - cp $cwd/util/ranlib.sh . - chmod +x ranlib.sh - if [ -d asm ]; then mkdir asm/perlasm cp $cwd/crypto/perlasm/*.pl asm/perlasm diff --git a/src/lib/libcrypto/util/sp-diff.pl b/src/lib/libcrypto/util/sp-diff.pl index 2c88336858..f81e50201b 100644 --- a/src/lib/libcrypto/util/sp-diff.pl +++ b/src/lib/libcrypto/util/sp-diff.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # # This file takes as input, the files that have been output from # ssleay speed. diff --git a/src/lib/libcrypto/util/src-dep.pl b/src/lib/libcrypto/util/src-dep.pl index 91242f7bb6..ad997e4746 100644 --- a/src/lib/libcrypto/util/src-dep.pl +++ b/src/lib/libcrypto/util/src-dep.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # we make up an array of # $file{function_name}=filename; diff --git a/src/lib/libcrypto/util/ssldir.pl b/src/lib/libcrypto/util/ssldir.pl deleted file mode 100644 index 10584686da..0000000000 --- a/src/lib/libcrypto/util/ssldir.pl +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/perl - -$#ARGV == 0 || die "usage: ssldir.pl /new/path\n"; -@files=('crypto/cryptlib.h', - 'Makefile.ssl', - 'tools/c_rehash', - 'util/mk1mf.pl', - ); - -%cryptlib=( - '\sX509_CERT_AREA\s',"#define X509_CERT_AREA\t\t".'"%s"', - '\sX509_CERT_DIR\s', "#define X509_CERT_DIR\t\t".'"%s/certs"', - '\sX509_CERT_FILE\s', "#define X509_CERT_FILE\t\t".'"%s/cert.pem"', - '\sX509_PRIVATE_DIR\s',"#define X509_PRIVATE_DIR\t".'"%s/private"', - ); - -%Makefile_ssl=( - '^INSTALLTOP=','INSTALLTOP=%s', - ); - -%c_rehash=( - '^DIR=', 'DIR=%s', - ); - -%mk1mf=( - '^$INSTALLTOP=','$INSTALLTOP="%s";', - ); - -&dofile("crypto/cryptlib.h",$ARGV[0],%cryptlib); -&dofile("Makefile.ssl",$ARGV[0],%Makefile_ssl); -&dofile("tools/c_rehash",$ARGV[0],%c_rehash); -&dofile("util/mk1mf.pl",$ARGV[0],%mk1mf); - -sub dofile - { - ($f,$p,%m)=@_; - - open(IN,"<$f") || die "unable to open $f:$!\n"; - @a=; - close(IN); - foreach $k (keys %m) - { - grep(/$k/ && ($_=sprintf($m{$k}."\n",$p)),@a); - } - ($ff=$f) =~ s/\..*$//; - open(OUT,">$ff.new") || die "unable to open $f:$!\n"; - print OUT @a; - close(OUT); - rename($f,"$ff.old") || die "unable to rename $f\n"; - rename("$ff.new",$f) || die "unable to rename $ff.new\n"; - } - diff --git a/src/lib/libcrypto/util/ssleay.num b/src/lib/libcrypto/util/ssleay.num index 359fa15df1..8121738bd6 100644 --- a/src/lib/libcrypto/util/ssleay.num +++ b/src/lib/libcrypto/util/ssleay.num @@ -154,3 +154,64 @@ TLSv1_server_method 171 TLSv1_client_method 172 BIO_new_buffer_ssl_connect 173 BIO_new_ssl_connect 174 +SSL_get_ex_data_X509_STORE_CTX_idx 175 +SSL_CTX_set_tmp_dh_callback 176 +SSL_CTX_set_tmp_rsa_callback 177 +SSL_CTX_set_timeout 178 +SSL_CTX_get_timeout 179 +SSL_CTX_get_cert_store 180 +SSL_CTX_set_cert_store 181 +SSL_want 182 +SSL_library_init 183 +SSL_COMP_add_compression_method 184 +SSL_add_file_cert_subjects_to_stack 185 +SSL_set_tmp_rsa_callback 186 +SSL_set_tmp_dh_callback 187 +SSL_add_dir_cert_subjects_to_stack 188 +SSL_set_session_id_context 189 +sk_SSL_CIPHER_new 190 +sk_SSL_CIPHER_new_null 191 +sk_SSL_CIPHER_free 192 +sk_SSL_CIPHER_num 193 +sk_SSL_CIPHER_value 194 +sk_SSL_CIPHER_set 195 +sk_SSL_CIPHER_zero 196 +sk_SSL_CIPHER_push 197 +sk_SSL_CIPHER_pop 198 +sk_SSL_CIPHER_find 199 +sk_SSL_CIPHER_delete 200 +sk_SSL_CIPHER_delete_ptr 201 +sk_SSL_CIPHER_set_cmp_func 202 +sk_SSL_CIPHER_dup 203 +sk_SSL_CIPHER_pop_free 204 +sk_SSL_CIPHER_shift 205 +sk_SSL_COMP_new 206 +sk_SSL_COMP_new_null 207 +sk_SSL_COMP_free 208 +sk_SSL_COMP_num 209 +sk_SSL_COMP_value 210 +sk_SSL_COMP_set 211 +sk_SSL_COMP_zero 212 +sk_SSL_COMP_push 213 +sk_SSL_COMP_pop 214 +sk_SSL_COMP_find 215 +sk_SSL_COMP_delete 216 +sk_SSL_COMP_delete_ptr 217 +sk_SSL_COMP_set_cmp_func 218 +sk_SSL_COMP_dup 219 +sk_SSL_COMP_pop_free 220 +sk_SSL_COMP_shift 221 +SSL_CTX_use_certificate_chain_file 222 +sk_SSL_COMP_insert 223 +sk_SSL_CIPHER_insert 224 +SSL_CTX_set_verify_depth 225 +SSL_set_verify_depth 226 +sk_SSL_CIPHER_unshift 227 +SSL_CTX_get_verify_depth 228 +SSL_get_verify_depth 229 +sk_SSL_COMP_unshift 230 +SSL_CTX_set_session_id_context 231 +SSL_CTX_set_cert_verify_callback 232 +sk_SSL_COMP_sort 233 +sk_SSL_CIPHER_sort 234 +SSL_CTX_set_default_passwd_cb_userdata 235 diff --git a/src/lib/libcrypto/util/tab_num.pl b/src/lib/libcrypto/util/tab_num.pl index 77b591d92f..a81ed0edc2 100644 --- a/src/lib/libcrypto/util/tab_num.pl +++ b/src/lib/libcrypto/util/tab_num.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl $num=1; $width=40; diff --git a/src/lib/libcrypto/util/up_ver.pl b/src/lib/libcrypto/util/up_ver.pl deleted file mode 100644 index 32c086b2aa..0000000000 --- a/src/lib/libcrypto/util/up_ver.pl +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/perl -# -# Up the version numbers in the files. -# - -@files=( - "crypto/crypto.h", - "crypto/des/ecb_enc.c", - "crypto/idea/i_ecb.c", - "crypto/lhash/lhash.c", - "crypto/conf/conf.c", - "crypto/md2/md2_dgst.c", - "crypto/md5/md5_dgst.c", - "crypto/ripemd/rmd_dgst.c", - "crypto/pem/pem_lib.c", - "crypto/bn/bn_lib.c", - "crypto/dh/dh_lib.c", - "crypto/rc2/rc2_ecb.c", - "crypto/rc4/rc4_skey.c", - "crypto/rc5/rc5_ecb.c", - "crypto/bf/bf_ecb.c", - "crypto/cast/c_ecb.c", - "crypto/rsa/rsa_lib.c", - "crypto/dsa/dsa_lib.c", - "crypto/sha/sha1dgst.c", - "crypto/sha/sha_dgst.c", - "crypto/asn1/asn1_lib.c", - "crypto/x509/x509_vfy.c", - "crypto/evp/evp_enc.c", - "crypto/rand/md_rand.c", - "crypto/stack/stack.c", - "crypto/txt_db/txt_db.c", - "crypto/cversion.c", - "ssl/ssl_lib.c", - "ssl/s2_lib.c", - "ssl/s3_lib.c", - "ssl/t1_lib.c", - "README", - ); - -@month=('Jan','Feb','Mar','Apr','May','Jun', - 'Jul','Aug','Sep','Oct','Nov','Dec'); -@a=localtime(time()); -$time=sprintf("%02d-%s-%04d",$a[3],$month[$a[4]],$a[5]+1900); - -$ver=$ARGV[0]; -($ver ne "") || die "no version number specified\n"; -($a,$b,$c,$d)=unpack('axaxac',$ver); -$d=defined($d)?$d-96:0; -$xver=sprintf("%x%x%x%x",$a,$b,$c,$d); - -foreach $file (@files) - { - open(IN,"<$file") || die "unable to open $file:$!\n"; - open(OUT,">$file.new") || die "unable to open $file.new:$!\n"; - $found=0; - - print STDERR "$file:"; - - while () - { - if ((s/SSLeay \d\.\d.\d[^"]*(\"|\s)/SSLeay $ver $time\1/) || - s/^(\#define\s+SSLEAY_VERSION_NUMBER\s+0x)[0-9a-zA-Z]+(.*)$/$1$xver$2/) - { - print STDERR " Done"; - $found++; - print OUT; - while () { print OUT; } - last; - } - print OUT; - } - print STDERR "\n"; - close(IN); - close(OUT); - (!$found) && die "unable to update the version number in $file\n"; - rename($file,"$file.old") || die "unable to rename $file:$!\n"; - rename("$file.new",$file) || die "unable to rename $file.new:$!\n"; - } diff --git a/src/lib/libcrypto/util/x86asm.sh b/src/lib/libcrypto/util/x86asm.sh index 81d3289860..d2090a9849 100644 --- a/src/lib/libcrypto/util/x86asm.sh +++ b/src/lib/libcrypto/util/x86asm.sh @@ -2,8 +2,8 @@ echo Generating x86 assember echo Bignum -(cd crypto/bn/asm; perl bn-586.pl cpp > bn86unix.cpp) -(cd crypto/bn/asm; perl bn-586.pl win32 > bn-win32.asm) +(cd crypto/bn/asm; perl x86.pl cpp > bn86unix.cpp) +(cd crypto/bn/asm; perl x86.pl win32 > bn-win32.asm) echo DES (cd crypto/des/asm; perl des-586.pl cpp > dx86unix.cpp) diff --git a/src/lib/libcrypto/x509/Makefile.ssl b/src/lib/libcrypto/x509/Makefile.ssl index 1c1ca2ffa0..14bb60d411 100644 --- a/src/lib/libcrypto/x509/Makefile.ssl +++ b/src/lib/libcrypto/x509/Makefile.ssl @@ -7,16 +7,16 @@ TOP= ../.. CC= cc INCLUDES= -I.. -I../../include CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r CFLAGS= $(INCLUDES) $(CFLAG) -ERR=x509 -ERRC=x509_err GENERAL=Makefile README TEST= APPS= @@ -24,18 +24,16 @@ APPS= LIB=$(TOP)/libcrypto.a LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \ x509_obj.c x509_req.c x509_vfy.c \ - x509_set.c x509rset.c $(ERRC).c \ - x509name.c x509_v3.c x509_ext.c x509pack.c \ + x509_set.c x509rset.c x509_err.c \ + x509name.c x509_v3.c x509_ext.c \ x509type.c x509_lu.c x_all.c x509_txt.c \ - by_file.c by_dir.c \ - v3_net.c v3_x509.c + by_file.c by_dir.c LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \ x509_obj.o x509_req.o x509_vfy.o \ - x509_set.o x509rset.o $(ERRC).o \ - x509name.o x509_v3.o x509_ext.o x509pack.o \ + x509_set.o x509rset.o x509_err.o \ + x509name.o x509_v3.o x509_ext.o \ x509type.o x509_lu.o x_all.o x509_txt.o \ - by_file.o by_dir.o \ - v3_net.o v3_x509.o + by_file.o by_dir.o SRC= $(LIBSRC) @@ -51,24 +49,23 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -80,17 +77,340 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: - perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h - perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +by_dir.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +by_dir.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +by_dir.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +by_dir.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +by_dir.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +by_dir.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +by_dir.o: ../../include/openssl/err.h ../../include/openssl/evp.h +by_dir.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +by_dir.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +by_dir.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +by_dir.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +by_dir.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +by_dir.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +by_dir.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +by_dir.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +by_dir.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +by_dir.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +by_file.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +by_file.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +by_file.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +by_file.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +by_file.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +by_file.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +by_file.o: ../../include/openssl/err.h ../../include/openssl/evp.h +by_file.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +by_file.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +by_file.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +by_file.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +by_file.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h +by_file.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +by_file.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +by_file.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +by_file.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +by_file.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +by_file.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x509_cmp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_cmp.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_cmp.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_cmp.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_cmp.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_cmp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_cmp.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_cmp.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_cmp.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_cmp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_cmp.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_cmp.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_cmp.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_cmp.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_cmp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_cmp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_cmp.o: ../cryptlib.h +x509_d2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_d2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_d2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_d2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_d2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_d2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_d2.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_d2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_d2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_d2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_d2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_d2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_d2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_d2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_d2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_d2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_d2.o: ../cryptlib.h +x509_def.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_def.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_def.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_def.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_def.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_def.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_def.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_def.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_def.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_def.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_def.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_def.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_def.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_def.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_def.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_def.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_def.o: ../cryptlib.h +x509_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h +x509_err.o: ../../include/openssl/des.h ../../include/openssl/dh.h +x509_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h +x509_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_err.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_ext.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_ext.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_ext.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_ext.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_ext.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_ext.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_ext.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_ext.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_ext.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_ext.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_ext.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_ext.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_ext.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_ext.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_ext.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_ext.o: ../cryptlib.h +x509_lu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_lu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_lu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_lu.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_lu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_lu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_lu.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_lu.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +x509_lu.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x509_lu.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x509_lu.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +x509_lu.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +x509_lu.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +x509_lu.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +x509_lu.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +x509_lu.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +x509_lu.o: ../../include/openssl/x509_vfy.h ../cryptlib.h +x509_obj.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_obj.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_obj.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_obj.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_obj.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_obj.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_obj.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_obj.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +x509_obj.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x509_obj.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x509_obj.o: ../../include/openssl/opensslconf.h +x509_obj.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_obj.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_obj.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_obj.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_obj.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_obj.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_obj.o: ../cryptlib.h +x509_r2x.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_r2x.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_r2x.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_r2x.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_r2x.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_r2x.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_r2x.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_r2x.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_r2x.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_r2x.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_r2x.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_r2x.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_r2x.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_r2x.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_r2x.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_r2x.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_r2x.o: ../cryptlib.h +x509_req.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_req.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_req.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_req.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_req.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h +x509_req.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h +x509_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_req.o: ../cryptlib.h +x509_set.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_set.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_set.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_set.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_set.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_set.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_set.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_set.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_set.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_set.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_set.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_set.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_set.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_set.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_set.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_set.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_set.o: ../cryptlib.h +x509_txt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_txt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_txt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_txt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_txt.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_txt.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_txt.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_txt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +x509_txt.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x509_txt.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x509_txt.o: ../../include/openssl/opensslconf.h +x509_txt.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_txt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_txt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_txt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_txt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_txt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_txt.o: ../cryptlib.h +x509_v3.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_v3.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_v3.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_v3.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_v3.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_v3.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_v3.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_v3.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509_v3.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509_v3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509_v3.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_v3.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_v3.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_v3.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_v3.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_v3.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_v3.o: ../cryptlib.h +x509_vfy.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509_vfy.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509_vfy.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509_vfy.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509_vfy.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509_vfy.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509_vfy.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +x509_vfy.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +x509_vfy.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +x509_vfy.o: ../../include/openssl/opensslconf.h +x509_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509_vfy.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509_vfy.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509_vfy.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509_vfy.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509_vfy.o: ../cryptlib.h +x509name.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509name.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509name.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509name.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509name.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509name.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509name.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509name.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509name.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509name.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509name.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509name.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509name.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509name.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509name.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509name.o: ../cryptlib.h +x509rset.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509rset.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509rset.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509rset.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509rset.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509rset.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509rset.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509rset.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509rset.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509rset.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509rset.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509rset.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509rset.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509rset.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509rset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509rset.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509rset.o: ../cryptlib.h +x509type.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x509type.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x509type.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x509type.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x509type.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x509type.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x509type.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x509type.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x509type.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x509type.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x509type.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x509type.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x509type.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x509type.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x509type.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x509type.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x509type.o: ../cryptlib.h +x_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +x_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +x_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +x_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +x_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +x_all.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +x_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h +x_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h +x_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +x_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +x_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +x_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +x_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +x_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +x_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +x_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +x_all.o: ../cryptlib.h diff --git a/src/lib/libcrypto/x509/attrib b/src/lib/libcrypto/x509/attrib deleted file mode 100644 index 37f6cd755f..0000000000 --- a/src/lib/libcrypto/x509/attrib +++ /dev/null @@ -1,38 +0,0 @@ - -PKCS7 - STACK of X509_ATTRIBUTES - ASN1_OBJECT - STACK of ASN1_TYPE - -So it is - -p7.xa[].obj -p7.xa[].data[] - -get_obj_by_nid(STACK , nid) -get_num_by_nid(STACK , nid) -get_data_by_nid(STACK , nid, index) - -X509_ATTRIBUTE *X509_ATTRIBUTE_new(void ); -void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a); - -X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **ex, - int nid, STACK *value); - -X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **ex, - int nid, STACK *value); - -int X509_ATTRIBUTE_set_object(X509_ATTRIBUTE *ex,ASN1_OBJECT *obj); -int X509_ATTRIBUTE_add_data(X509_ATTRIBUTE *ex, int index, - ASN1_TYPE *value); - -ASN1_OBJECT * X509_ATTRIBUTE_get_object(X509_ATTRIBUTE *ex); -int X509_ATTRIBUTE_get_num(X509_ATTRIBUTE *ne); -ASN1_TYPE * X509_ATTRIBUTE_get_data(X509_ATTRIBUTE *ne,int index); - -ASN1_TYPE * X509_ATTRIBUTE_get_data_by_NID(X509_ATTRIBUTE *ne, - ASN1_OBJECT *obj); - -X509_ATTRUBUTE *PKCS7_get_s_att_by_NID(PKCS7 *p7,int nid); -X509_ATTRUBUTE *PKCS7_get_u_att_by_NID(PKCS7 *p7,int nid); - diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c index 11725ec94c..734e39ac77 100644 --- a/src/lib/libcrypto/x509/by_dir.c +++ b/src/lib/libcrypto/x509/by_dir.c @@ -63,9 +63,8 @@ #include #include "cryptlib.h" -#include "lhash.h" -#include "x509.h" -#include "pem.h" +#include +#include typedef struct lookup_dir_st { @@ -76,21 +75,13 @@ typedef struct lookup_dir_st int num_dirs_alloced; } BY_DIR; -#ifndef NOPROTO -static int dir_ctrl(X509_LOOKUP *ctx,int cmd,char *argp,long argl,char **ret); +static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, + char **ret); static int new_dir(X509_LOOKUP *lu); static void free_dir(X509_LOOKUP *lu); -static int add_cert_dir(BY_DIR *ctx,char *dir,int type); +static int add_cert_dir(BY_DIR *ctx,const char *dir,int type); static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name, X509_OBJECT *ret); -#else -static int dir_ctrl(); -static int new_dir(); -static void free_dir(); -static int add_cert_dir(); -static int get_cert_by_subject(); -#endif - X509_LOOKUP_METHOD x509_dir_lookup= { "Load certs from files in a directory", @@ -105,17 +96,13 @@ X509_LOOKUP_METHOD x509_dir_lookup= NULL, /* get_by_alias */ }; -X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir() +X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void) { return(&x509_dir_lookup); } -static int dir_ctrl(ctx,cmd,argp,argl,retp) -X509_LOOKUP *ctx; -int cmd; -long argl; -char *argp; -char **retp; +static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, + char **retp) { int ret=0; BY_DIR *ld; @@ -147,8 +134,7 @@ char **retp; return(ret); } -static int new_dir(lu) -X509_LOOKUP *lu; +static int new_dir(X509_LOOKUP *lu) { BY_DIR *a; @@ -167,8 +153,7 @@ X509_LOOKUP *lu; return(1); } -static void free_dir(lu) -X509_LOOKUP *lu; +static void free_dir(X509_LOOKUP *lu) { BY_DIR *a; int i; @@ -182,17 +167,18 @@ X509_LOOKUP *lu; Free(a); } -static int add_cert_dir(ctx,dir, type) -BY_DIR *ctx; -char *dir; -int type; +static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) { int j,len; int *ip; - char *s,*ss,*p; + const char *s,*ss,*p; char **pp; - if (dir == NULL) return(0); + if (dir == NULL || !*dir) + { + X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY); + return 0; + } s=dir; p=s; @@ -243,11 +229,8 @@ int type; return(1); } -static int get_cert_by_subject(xl,type,name,ret) -X509_LOOKUP *xl; -int type; -X509_NAME *name; -X509_OBJECT *ret; +static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, + X509_OBJECT *ret) { BY_DIR *ctx; union { @@ -266,7 +249,7 @@ X509_OBJECT *ret; BUF_MEM *b=NULL; struct stat st; X509_OBJECT stmp,*tmp; - char *postfix=""; + const char *postfix=""; if (name == NULL) return(0); diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c index 09ebb9bf08..00ee5e8bbc 100644 --- a/src/lib/libcrypto/x509/by_file.c +++ b/src/lib/libcrypto/x509/by_file.c @@ -63,20 +63,15 @@ #include #include "cryptlib.h" -#include "lhash.h" -#include "buffer.h" -#include "x509.h" -#include "pem.h" +#include +#include +#include +#include #ifndef NO_STDIO -#ifndef NOPROTO -static int by_file_ctrl(X509_LOOKUP *ctx,int cmd,char *argc, - long argl,char **ret); -#else -static int by_file_ctrl(); -#endif - +static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, + long argl, char **ret); X509_LOOKUP_METHOD x509_file_lookup= { "Load file into cache", @@ -91,17 +86,13 @@ X509_LOOKUP_METHOD x509_file_lookup= NULL, /* get_by_alias */ }; -X509_LOOKUP_METHOD *X509_LOOKUP_file() +X509_LOOKUP_METHOD *X509_LOOKUP_file(void) { return(&x509_file_lookup); } -static int by_file_ctrl(ctx,cmd,argp,argl,ret) -X509_LOOKUP *ctx; -int cmd; -char *argp; -long argl; -char **ret; +static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, + char **ret) { int ok=0,ok2=0; char *file; @@ -138,10 +129,7 @@ char **ret; return((ok && ok2)?ok:0); } -int X509_load_cert_file(ctx,file,type) -X509_LOOKUP *ctx; -char *file; -int type; +int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) { int ret=0; BIO *in=NULL; @@ -161,7 +149,7 @@ int type; { for (;;) { - x=PEM_read_bio_X509(in,NULL,NULL); + x=PEM_read_bio_X509(in,NULL,NULL,NULL); if (x == NULL) { if ((ERR_GET_REASON(ERR_peek_error()) == @@ -208,10 +196,7 @@ err: return(ret); } -int X509_load_crl_file(ctx,file,type) -X509_LOOKUP *ctx; -char *file; -int type; +int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) { int ret=0; BIO *in=NULL; @@ -231,7 +216,7 @@ int type; { for (;;) { - x=PEM_read_bio_X509_CRL(in,NULL,NULL); + x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL); if (x == NULL) { if ((ERR_GET_REASON(ERR_peek_error()) == diff --git a/src/lib/libcrypto/x509/v3_net.c b/src/lib/libcrypto/x509/v3_net.c deleted file mode 100644 index 0c2d276d13..0000000000 --- a/src/lib/libcrypto/x509/v3_net.c +++ /dev/null @@ -1,87 +0,0 @@ -/* crypto/x509/v3_net.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "stack.h" -#include "cryptlib.h" -#include "asn1.h" -#include "objects.h" -#include "x509.h" - -#define NETSCAPE_X509_EXT_NUM 8 - -static X509_EXTENSION_METHOD netscape_x509_ext[NETSCAPE_X509_EXT_NUM]={ -{NID_netscape_ca_policy_url, V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, -{NID_netscape_ssl_server_name, V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, -{NID_netscape_revocation_url, V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, -{NID_netscape_base_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, -{NID_netscape_cert_type,V_ASN1_BIT_STRING,X509_EXT_PACK_STRING}, -{NID_netscape_ca_revocation_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, -{NID_netscape_renewal_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, -{NID_netscape_comment,V_ASN1_IA5STRING,X509_EXT_PACK_STRING}, - }; - -int X509v3_add_netscape_extensions() - { - int i; - - for (i=0; i -#include -#include "stack.h" -#include "cryptlib.h" -#include "bio.h" -#include "asn1.h" -#include "objects.h" -#include "x509.h" - -#if 0 -static int i2a_key_usage(BIO *bp, X509 *x); -static int a2i_key_usage(X509 *x, char *str, int len); -#endif - -int X509v3_get_key_usage(X509 *x); -int X509v3_set_key_usage(X509 *x,unsigned int use); -int i2a_X509v3_key_usage(BIO *bp, unsigned int use); -unsigned int a2i_X509v3_key_usage(char *p); - -#define STD_X509_EXT_NUM 9 - -#if 0 -static X509_OBJECTS std_x509_ext[STD_X509_EXT_NUM]={ -{NID_subject_key_identifier, NULL,NULL}, -{NID_key_usage, a2i_key_usage,i2a_key_usage}, /**/ -{NID_private_key_usage_period, NULL,NULL}, -{NID_subject_alt_name, NULL,NULL}, -{NID_issuer_alt_name, NULL,NULL}, -{NID_basic_constraints, NULL,NULL}, -{NID_crl_number, NULL,NULL}, -{NID_certificate_policies, NULL,NULL}, -{NID_authority_key_identifier, NULL,NULL}, - }; -#endif - -int X509v3_add_standard_extensions() - { - -#if 0 - for (i=0; i 0) - { - i=1; - data[0]=use&0xff; - } - if (use > 0xff) - { - i=2; - data[1]=(use>>8)&0xff; - } - return((X509v3_pack_string(&os,V_ASN1_BIT_STRING,data,i) == NULL)?0:1); - } - diff --git a/src/lib/libcrypto/x509/x509.doc b/src/lib/libcrypto/x509/x509.doc deleted file mode 100644 index 73cfc9f034..0000000000 --- a/src/lib/libcrypto/x509/x509.doc +++ /dev/null @@ -1,27 +0,0 @@ -X509_verify() -X509_sign() - -X509_get_version() -X509_get_serialNumber() -X509_get_issuer() -X509_get_subject() -X509_get_notBefore() -X509_get_notAfter() -X509_get_pubkey() - -X509_set_version() -X509_set_serialNumber() -X509_set_issuer() -X509_set_subject() -X509_set_notBefore() -X509_set_notAfter() -X509_set_pubkey() - -X509_get_extensions() -X509_set_extensions() - -X509_EXTENSIONS_clear() -X509_EXTENSIONS_retrieve() -X509_EXTENSIONS_add() -X509_EXTENSIONS_delete() - diff --git a/src/lib/libcrypto/x509/x509.err b/src/lib/libcrypto/x509/x509.err deleted file mode 100644 index 8d0862d7d1..0000000000 --- a/src/lib/libcrypto/x509/x509.err +++ /dev/null @@ -1,46 +0,0 @@ -/* Error codes for the X509 functions. */ - -/* Function codes. */ -#define X509_F_ADD_CERT_DIR 100 -#define X509_F_BY_FILE_CTRL 101 -#define X509_F_DIR_CTRL 102 -#define X509_F_GET_CERT_BY_SUBJECT 103 -#define X509_F_X509V3_ADD_EXT 104 -#define X509_F_X509V3_ADD_EXTENSION 105 -#define X509_F_X509V3_PACK_STRING 106 -#define X509_F_X509V3_UNPACK_STRING 107 -#define X509_F_X509_EXTENSION_CREATE_BY_NID 108 -#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 -#define X509_F_X509_GET_PUBKEY_PARAMETERS 110 -#define X509_F_X509_LOAD_CERT_FILE 111 -#define X509_F_X509_LOAD_CRL_FILE 112 -#define X509_F_X509_NAME_ADD_ENTRY 113 -#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 -#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 -#define X509_F_X509_NAME_ONELINE 116 -#define X509_F_X509_NAME_PRINT 117 -#define X509_F_X509_PRINT_FP 118 -#define X509_F_X509_PUBKEY_GET 119 -#define X509_F_X509_PUBKEY_SET 120 -#define X509_F_X509_REQ_PRINT 121 -#define X509_F_X509_REQ_PRINT_FP 122 -#define X509_F_X509_REQ_TO_X509 123 -#define X509_F_X509_STORE_ADD_CERT 124 -#define X509_F_X509_STORE_ADD_CRL 125 -#define X509_F_X509_TO_X509_REQ 126 -#define X509_F_X509_VERIFY_CERT 127 - -/* Reason codes. */ -#define X509_R_BAD_X509_FILETYPE 100 -#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 -#define X509_R_ERR_ASN1_LIB 102 -#define X509_R_LOADING_CERT_DIR 103 -#define X509_R_LOADING_DEFAULTS 104 -#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 -#define X509_R_SHOULD_RETRY 106 -#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 -#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 -#define X509_R_UNKNOWN_NID 109 -#define X509_R_UNKNOWN_STRING_TYPE 110 -#define X509_R_UNSUPPORTED_ALGORITHM 111 -#define X509_R_WRONG_LOOKUP_TYPE 112 diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h index 95114f7c43..35f9484f8b 100644 --- a/src/lib/libcrypto/x509/x509.h +++ b/src/lib/libcrypto/x509/x509.h @@ -63,28 +63,34 @@ extern "C" { #endif -#include "stack.h" -#include "asn1.h" +#ifdef VMS +#undef X509_REVOKED_get_ext_by_critical +#define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic +#endif + +#include +#include +#include #ifndef NO_RSA -#include "rsa.h" -#else -#define RSA long +#include #endif #ifndef NO_DSA -#include "dsa.h" -#else -#define DSA long +#include #endif #ifndef NO_DH -#include "dh.h" -#else -#define DH long +#include #endif -#include "evp.h" +#include + + +#ifdef WIN32 +/* Under Win32 this is defined in wincrypt.h */ +#undef X509_NAME +#endif #define X509_FILETYPE_PEM 1 #define X509_FILETYPE_ASN1 2 @@ -114,6 +120,9 @@ typedef struct X509_algor_st ASN1_TYPE *parameter; } X509_ALGOR; +DECLARE_STACK_OF(X509_ALGOR) +DECLARE_ASN1_SET_OF(X509_ALGOR) + typedef struct X509_val_st { ASN1_UTCTIME *notBefore; @@ -124,7 +133,7 @@ typedef struct X509_pubkey_st { X509_ALGOR *algor; ASN1_BIT_STRING *public_key; - struct evp_pkey_st /* EVP_PKEY*/ *pkey; + EVP_PKEY *pkey; } X509_PUBKEY; typedef struct X509_sig_st @@ -141,10 +150,13 @@ typedef struct X509_name_entry_st int size; /* temp variable */ } X509_NAME_ENTRY; +DECLARE_STACK_OF(X509_NAME_ENTRY) +DECLARE_ASN1_SET_OF(X509_NAME_ENTRY) + /* we always keep X509_NAMEs in 2 forms. */ typedef struct X509_name_st { - STACK *entries; /* of X509_NAME_ENTRY */ + STACK_OF(X509_NAME_ENTRY) *entries; int modified; /* true if 'bytes' needs to be built */ #ifdef HEADER_BUFFER_H BUF_MEM *bytes; @@ -154,6 +166,8 @@ typedef struct X509_name_st unsigned long hash; /* Keep the hash around for lookups */ } X509_NAME; +DECLARE_STACK_OF(X509_NAME) + #define X509_EX_V_NETSCAPE_HACK 0x8000 #define X509_EX_V_INIT 0x0001 typedef struct X509_extension_st @@ -167,23 +181,23 @@ typedef struct X509_extension_st void (*ex_free)(); /* clear argp stuff */ } X509_EXTENSION; -/* #if 1 */ -typedef struct x509_extension_method_st +DECLARE_STACK_OF(X509_EXTENSION) +DECLARE_ASN1_SET_OF(X509_EXTENSION) + +/* a sequence of these are used */ +typedef struct x509_attributes_st { - int nid; - int data_type; - int pack_type; - void (*ex_clear)(); - int (*ex_get_bool)(); - int (*ex_set_bool)(); - int (*ex_get_str)(); - int (*ex_set_str)(); - char *(*ex_get_struct)(); - int (*ex_set_struct)(); - int (*a2i)(); - int (*i2a)(); - } X509_EXTENSION_METHOD; -/* #endif */ + ASN1_OBJECT *object; + int set; /* 1 for a set, 0 for a single item (which is wrong) */ + union { + char *ptr; +/* 1 */ STACK_OF(ASN1_TYPE) *set; +/* 0 */ ASN1_TYPE *single; + } value; + } X509_ATTRIBUTE; + +DECLARE_STACK_OF(X509_ATTRIBUTE) +DECLARE_ASN1_SET_OF(X509_ATTRIBUTE) typedef struct X509_req_info_st { @@ -191,7 +205,7 @@ typedef struct X509_req_info_st X509_NAME *subject; X509_PUBKEY *pubkey; /* d=2 hl=2 l= 0 cons: cont: 00 */ - STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ + STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ int req_kludge; } X509_REQ_INFO; @@ -214,7 +228,7 @@ typedef struct x509_cinf_st X509_PUBKEY *key; ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */ ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */ - STACK /* X509_EXTENSION */ *extensions; /* [ 3 ] optional in v3 */ + STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */ } X509_CINF; typedef struct x509_st @@ -227,14 +241,20 @@ typedef struct x509_st char *name; } X509; +DECLARE_STACK_OF(X509) +DECLARE_ASN1_SET_OF(X509) + typedef struct X509_revoked_st { ASN1_INTEGER *serialNumber; ASN1_UTCTIME *revocationDate; - STACK /* optional X509_EXTENSION */ *extensions; + STACK_OF(X509_EXTENSION) /* optional */ *extensions; int sequence; /* load sequence */ } X509_REVOKED; +DECLARE_STACK_OF(X509_REVOKED) +DECLARE_ASN1_SET_OF(X509_REVOKED) + typedef struct X509_crl_info_st { ASN1_INTEGER *version; @@ -242,8 +262,8 @@ typedef struct X509_crl_info_st X509_NAME *issuer; ASN1_UTCTIME *lastUpdate; ASN1_UTCTIME *nextUpdate; - STACK /* X509_REVOKED */ *revoked; - STACK /* [0] X509_EXTENSION */ *extensions; + STACK_OF(X509_REVOKED) *revoked; + STACK_OF(X509_EXTENSION) /* [0] */ *extensions; } X509_CRL_INFO; typedef struct X509_crl_st @@ -255,17 +275,8 @@ typedef struct X509_crl_st int references; } X509_CRL; -/* a sequence of these are used */ -typedef struct x509_attributes_st - { - ASN1_OBJECT *object; - int set; /* 1 for a set, 0 for a single item (which is wrong) */ - union { - char *ptr; -/* 1 */ STACK /* ASN1_TYPE */ *set; -/* 0 */ ASN1_TYPE *single; - } value; - } X509_ATTRIBUTE; +DECLARE_STACK_OF(X509_CRL) +DECLARE_ASN1_SET_OF(X509_CRL) typedef struct private_key_st { @@ -301,6 +312,8 @@ typedef struct X509_info_st int references; } X509_INFO; + +DECLARE_STACK_OF(X509_INFO) #endif /* The next 2 structures and their 8 routines were sent to me by @@ -320,17 +333,55 @@ typedef struct Netscape_spki_st ASN1_BIT_STRING *signature; } NETSCAPE_SPKI; -#ifndef HEADER_BN_H -#define BIGNUM char -#endif +/* Netscape certificate sequence structure */ +typedef struct Netscape_certificate_sequence + { + ASN1_OBJECT *type; + STACK_OF(X509) *certs; + } NETSCAPE_CERT_SEQUENCE; typedef struct CBCParameter_st { unsigned char iv[8]; } CBC_PARAM; -#include "x509_vfy.h" -#include "pkcs7.h" +/* Password based encryption structure */ + +typedef struct PBEPARAM_st { +ASN1_OCTET_STRING *salt; +ASN1_INTEGER *iter; +} PBEPARAM; + +/* Password based encryption V2 structures */ + +typedef struct PBE2PARAM_st { +X509_ALGOR *keyfunc; +X509_ALGOR *encryption; +} PBE2PARAM; + +typedef struct PBKDF2PARAM_st { +ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */ +ASN1_INTEGER *iter; +ASN1_INTEGER *keylength; +X509_ALGOR *prf; +} PBKDF2PARAM; + + +/* PKCS#8 private key info structure */ + +typedef struct pkcs8_priv_key_info_st + { + int broken; /* Flag for various broken formats */ +#define PKCS8_OK 0 +#define PKCS8_NO_OCTET 1 + ASN1_INTEGER *version; + X509_ALGOR *pkeyalg; + ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */ + STACK_OF(X509_ATTRIBUTE) *attributes; + } PKCS8_PRIV_KEY_INFO; + +#include +#include #ifdef SSLEAY_MACROS #define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\ @@ -355,6 +406,9 @@ typedef struct CBCParameter_st #define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \ (char *(*)())d2i_X509,(char *)x509) +#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\ + (int (*)())i2d_X509_ATTRIBUTE, \ + (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa) #define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \ (int (*)())i2d_X509_EXTENSION, \ (char *(*)())d2i_X509_EXTENSION,(char *)ex) @@ -442,6 +496,9 @@ typedef struct CBCParameter_st #define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \ (unsigned char *)dsa) +#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\ + (char *(*)())d2i_X509_ALGOR,(char *)xn) + #define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \ (char *(*)())d2i_X509_NAME,(char *)xn) #define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \ @@ -453,10 +510,12 @@ typedef struct CBCParameter_st ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len) #define X509_NAME_digest(data,type,md,len) \ ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len) +#ifndef PKCS7_ISSUER_AND_SERIAL_digest #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ (char *)data,md,len) #endif +#endif #define X509_EXT_PACK_UNKNOWN 1 #define X509_EXT_PACK_STRING 2 @@ -472,25 +531,31 @@ typedef struct CBCParameter_st #define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) #define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm)) +#define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version) +#define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate) +#define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate) +#define X509_CRL_get_issuer(x) ((x)->crl->issuer) +#define X509_CRL_get_REVOKED(x) ((x)->crl->revoked) + /* This one is only used so that a binary form can output, as in * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */ #define X509_get_X509_PUBKEY(x) ((x)->cert_info->key) -#ifndef NOPROTO + +const char *X509_verify_cert_error_string(long n); #ifndef SSLEAY_MACROS #ifdef HEADER_ENVELOPE_H int X509_verify(X509 *a, EVP_PKEY *r); -char *X509_verify_cert_error_string(long n); int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); -int X509_sign(X509 *x, EVP_PKEY *pkey, EVP_MD *md); -int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, EVP_MD *md); -int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, EVP_MD *md); -int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, EVP_MD *md); +int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); +int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md); +int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md); int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len); int X509_NAME_digest(X509_NAME *data,EVP_MD *type, @@ -498,55 +563,77 @@ int X509_NAME_digest(X509_NAME *data,EVP_MD *type, #endif #ifndef NO_FP_API -X509 *d2i_X509_fp(FILE *fp, X509 *x509); +X509 *d2i_X509_fp(FILE *fp, X509 **x509); int i2d_X509_fp(FILE *fp,X509 *x509); -X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL *crl); +X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl); int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl); -X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ *req); +X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req); int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req); -RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA *rsa); +#ifndef NO_RSA +RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa); int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa); -DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA *dsa); -int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); -RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA *rsa); +RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa); int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa); #endif +#ifndef NO_DSA +DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); +int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); +X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8); +int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, + PKCS8_PRIV_KEY_INFO **p8inf); +int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf); +#endif +#endif #ifdef HEADER_BIO_H -X509 *d2i_X509_bio(BIO *bp,X509 *x509); +X509 *d2i_X509_bio(BIO *bp,X509 **x509); int i2d_X509_bio(BIO *bp,X509 *x509); -X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL *crl); +X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl); int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl); -X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ *req); +X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req); int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req); -RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA *rsa); +#ifndef NO_RSA +RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa); int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa); -DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA *dsa); -int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); -RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA *rsa); +RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa); int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa); #endif +#ifndef NO_DSA +DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); +int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); +#endif +X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8); +int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, + PKCS8_PRIV_KEY_INFO **p8inf); +int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf); +#endif X509 *X509_dup(X509 *x509); +X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa); X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); X509_CRL *X509_CRL_dup(X509_CRL *crl); X509_REQ *X509_REQ_dup(X509_REQ *req); +X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn); X509_NAME *X509_NAME_dup(X509_NAME *xn); X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); +#ifndef NO_RSA RSA *RSAPublicKey_dup(RSA *rsa); RSA *RSAPrivateKey_dup(RSA *rsa); +#endif #endif /* !SSLEAY_MACROS */ int X509_cmp_current_time(ASN1_UTCTIME *s); ASN1_UTCTIME * X509_gmtime_adj(ASN1_UTCTIME *s, long adj); -char * X509_get_default_cert_area(void ); -char * X509_get_default_cert_dir(void ); -char * X509_get_default_cert_file(void ); -char * X509_get_default_cert_dir_env(void ); -char * X509_get_default_cert_file_env(void ); -char * X509_get_default_private_dir(void ); +const char * X509_get_default_cert_area(void ); +const char * X509_get_default_cert_dir(void ); +const char * X509_get_default_cert_file(void ); +const char * X509_get_default_cert_dir_env(void ); +const char * X509_get_default_cert_file_env(void ); +const char * X509_get_default_private_dir(void ); X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md); X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey); @@ -571,7 +658,8 @@ X509_PUBKEY * d2i_X509_PUBKEY(X509_PUBKEY **a,unsigned char **pp, long length); int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); -int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK *chain); +int X509_get_pubkey_parameters(EVP_PKEY *pkey, + STACK_OF(X509) *chain); X509_SIG * X509_SIG_new(void ); @@ -595,6 +683,8 @@ void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a); int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp); X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp, long length); +X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value); + X509_EXTENSION *X509_EXTENSION_new(void ); void X509_EXTENSION_free(X509_EXTENSION *a); @@ -658,6 +748,12 @@ int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp); NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp, long length); + +int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp); +NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void); +NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length); +void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a); + #ifdef HEADER_ENVELOPE_H X509_INFO * X509_INFO_new(void); void X509_INFO_free(X509_INFO *a); @@ -671,7 +767,7 @@ int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data, int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2, ASN1_BIT_STRING *signature, - char *data,EVP_PKEY *pkey, EVP_MD *type); + char *data,EVP_PKEY *pkey, const EVP_MD *type); #endif int X509_set_version(X509 *x,long version); @@ -709,12 +805,14 @@ unsigned long X509_NAME_hash(X509_NAME *x); int X509_CRL_cmp(X509_CRL *a,X509_CRL *b); #ifndef NO_FP_API int X509_print_fp(FILE *bp,X509 *x); +int X509_CRL_print_fp(FILE *bp,X509_CRL *x); int X509_REQ_print_fp(FILE *bp,X509_REQ *req); #endif #ifdef HEADER_BIO_H int X509_NAME_print(BIO *bp, X509_NAME *name, int obase); int X509_print(BIO *bp,X509 *x); +int X509_CRL_print(BIO *bp,X509_CRL *x); int X509_REQ_print(BIO *bp,X509_REQ *req); #endif @@ -745,18 +843,17 @@ int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne); ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne); -int X509v3_get_ext_count(STACK *x); -int X509v3_get_ext_by_NID(STACK *x, int nid, int lastpos); -int X509v3_get_ext_by_OBJ(STACK *x,ASN1_OBJECT *obj,int lastpos); -int X509v3_get_ext_by_critical(STACK *x, int crit, int lastpos); -X509_EXTENSION *X509v3_get_ext(STACK *x, int loc); -X509_EXTENSION *X509v3_delete_ext(STACK *x, int loc); -STACK * X509v3_add_ext(STACK **x, X509_EXTENSION *ex, int loc); - -int X509v3_data_type_by_OBJ(ASN1_OBJECT *obj); -int X509v3_data_type_by_NID(int nid); -int X509v3_pack_type_by_OBJ(ASN1_OBJECT *obj); -int X509v3_pack_type_by_NID(int nid); +int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); +int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, + int nid, int lastpos); +int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, + ASN1_OBJECT *obj,int lastpos); +int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, + int crit, int lastpos); +X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc); +X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc); +STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, + X509_EXTENSION *ex, int loc); int X509_get_ext_count(X509 *x); int X509_get_ext_by_NID(X509 *x, int nid, int lastpos); @@ -793,311 +890,49 @@ int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex); ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); int X509_EXTENSION_get_critical(X509_EXTENSION *ex); -ASN1_OCTET_STRING *X509v3_pack_string(ASN1_OCTET_STRING **ex,int type, - unsigned char *bytes, int len); -ASN1_STRING * X509v3_unpack_string(ASN1_STRING **ex,int type, - ASN1_OCTET_STRING *os); int X509_verify_cert(X509_STORE_CTX *ctx); /* lookup a cert from a X509 STACK */ -X509 *X509_find_by_issuer_and_serial(STACK *sk,X509_NAME *name, - ASN1_INTEGER *serial); -X509 *X509_find_by_subject(STACK *sk,X509_NAME *name); - -#else - -#ifndef SSLEAY_MACROS -#ifdef HEADER_ENVELOPE_H -int X509_verify(); -int X509_REQ_verify(); -int X509_CRL_verify(); -int NETSCAPE_SPKI_verify(); - -int X509_sign(); -int X509_REQ_sign(); -int X509_CRL_sign(); -int NETSCAPE_SPKI_sign(); - -int X509_digest(); -int X509_NAME_digest(); -#endif - -#ifndef NO_FP_API -X509 *d2i_X509_fp(); -int i2d_X509_fp(); -X509_CRL *d2i_X509_CRL_fp(); -int i2d_X509_CRL_fp(); -X509_REQ *d2i_X509_REQ_fp(); -int i2d_X509_REQ_fp(); -RSA *d2i_RSAPrivateKey_fp(); -int i2d_RSAPrivateKey_fp(); -DSA *d2i_DSAPrivateKey_fp(); -int i2d_DSAPrivateKey_fp(); -RSA *d2i_RSAPublicKey_fp(); -int i2d_RSAPublicKey_fp(); -#endif - -X509 *d2i_X509_bio(); -int i2d_X509_bio(); -X509_CRL *d2i_X509_CRL_bio(); -int i2d_X509_CRL_bio(); -X509_REQ *d2i_X509_REQ_bio(); -int i2d_X509_REQ_bio(); -RSA *d2i_RSAPrivateKey_bio(); -int i2d_RSAPrivateKey_bio(); -DSA *d2i_DSAPrivateKey_bio(); -int i2d_DSAPrivateKey_bio(); -RSA *d2i_RSAPublicKey_bio(); -int i2d_RSAPublicKey_bio(); - -X509 *X509_dup(); -X509_EXTENSION *X509_EXTENSION_dup(); -X509_CRL *X509_CRL_dup(); -X509_REQ *X509_REQ_dup(); -X509_NAME *X509_NAME_dup(); -X509_NAME_ENTRY *X509_NAME_ENTRY_dup(); -RSA *RSAPublicKey_dup(); -RSA *RSAPrivateKey_dup(); - -#endif /* !SSLEAY_MACROS */ - -int X509_cmp_current_time(); -ASN1_UTCTIME * X509_gmtime_adj(); - -char * X509_get_default_cert_area(); -char * X509_get_default_cert_dir(); -char * X509_get_default_cert_file(); -char * X509_get_default_cert_dir_env(); -char * X509_get_default_cert_file_env(); -char * X509_get_default_private_dir(); - -X509_REQ * X509_to_X509_REQ(); -X509 * X509_REQ_to_X509(); -void ERR_load_X509_strings(); - -X509_ALGOR * X509_ALGOR_new(); -void X509_ALGOR_free(); -int i2d_X509_ALGOR(); -X509_ALGOR * d2i_X509_ALGOR(); - -X509_VAL * X509_VAL_new(); -void X509_VAL_free(); -int i2d_X509_VAL(); -X509_VAL * d2i_X509_VAL(); - -X509_PUBKEY * X509_PUBKEY_new(); -void X509_PUBKEY_free(); -int i2d_X509_PUBKEY(); -X509_PUBKEY * d2i_X509_PUBKEY(); -int X509_PUBKEY_set(); -EVP_PKEY * X509_PUBKEY_get(); -int X509_get_pubkey_parameters(); - -X509_SIG * X509_SIG_new(); -void X509_SIG_free(); -int i2d_X509_SIG(); -X509_SIG * d2i_X509_SIG(); - -X509_REQ_INFO *X509_REQ_INFO_new(); -void X509_REQ_INFO_free(); -int i2d_X509_REQ_INFO(); -X509_REQ_INFO *d2i_X509_REQ_INFO(); - -X509_REQ * X509_REQ_new(); -void X509_REQ_free(); -int i2d_X509_REQ(); -X509_REQ * d2i_X509_REQ(); - -X509_ATTRIBUTE *X509_ATTRIBUTE_new(); -void X509_ATTRIBUTE_free(); -int i2d_X509_ATTRIBUTE(); -X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(); - -X509_EXTENSION *X509_EXTENSION_new(); -void X509_EXTENSION_free(); -int i2d_X509_EXTENSION(); -X509_EXTENSION *d2i_X509_EXTENSION(); - -X509_NAME_ENTRY *X509_NAME_ENTRY_new(); -void X509_NAME_ENTRY_free(); -int i2d_X509_NAME_ENTRY(); -X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(); - -X509_NAME * X509_NAME_new(); -void X509_NAME_free(); -int i2d_X509_NAME(); -X509_NAME * d2i_X509_NAME(); -int X509_NAME_set(); - - -X509_CINF * X509_CINF_new(); -void X509_CINF_free(); -int i2d_X509_CINF(); -X509_CINF * d2i_X509_CINF(); - -X509 * X509_new(); -void X509_free(); -int i2d_X509(); -X509 * d2i_X509(); - -X509_REVOKED * X509_REVOKED_new(); -void X509_REVOKED_free(); -int i2d_X509_REVOKED(); -X509_REVOKED * d2i_X509_REVOKED(); - -X509_CRL_INFO *X509_CRL_INFO_new(); -void X509_CRL_INFO_free(); -int i2d_X509_CRL_INFO(); -X509_CRL_INFO *d2i_X509_CRL_INFO(); - -X509_CRL * X509_CRL_new(); -void X509_CRL_free(); -int i2d_X509_CRL(); -X509_CRL * d2i_X509_CRL(); - -X509_PKEY * X509_PKEY_new(); -void X509_PKEY_free(); -int i2d_X509_PKEY(); -X509_PKEY * d2i_X509_PKEY(); - -NETSCAPE_SPKI * NETSCAPE_SPKI_new(); -void NETSCAPE_SPKI_free(); -int i2d_NETSCAPE_SPKI(); -NETSCAPE_SPKI * d2i_NETSCAPE_SPKI(); - -NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(); -void NETSCAPE_SPKAC_free(); -int i2d_NETSCAPE_SPKAC(); -NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(); - -#ifdef HEADER_ENVELOPE_H -X509_INFO * X509_INFO_new(); -void X509_INFO_free(); -#endif - -char * X509_NAME_oneline(); - -int ASN1_verify(); -int ASN1_digest(); -int ASN1_sign(); - -int X509_set_version(); -int X509_set_serialNumber(); -ASN1_INTEGER * X509_get_serialNumber(); -int X509_set_issuer_name(); -X509_NAME * X509_get_issuer_name(); -int X509_set_subject_name(); -X509_NAME * X509_get_subject_name(); -int X509_set_notBefore(); -int X509_set_notAfter(); -int X509_set_pubkey(); -EVP_PKEY * X509_get_pubkey(); -int X509_certificate_type(); - -int X509_REQ_set_version(); -int X509_REQ_set_subject_name(); -int X509_REQ_set_pubkey(); -EVP_PKEY * X509_REQ_get_pubkey(); - -int X509_check_private_key(); - -int X509_issuer_and_serial_cmp(); -unsigned long X509_issuer_and_serial_hash(); - -int X509_issuer_name_cmp(); -unsigned long X509_issuer_name_hash(); - -int X509_subject_name_cmp(); -unsigned long X509_subject_name_hash(); - -int X509_NAME_cmp (); -unsigned long X509_NAME_hash(); - -int X509_CRL_cmp(); -#ifndef NO_FP_API -int X509_print_fp(); -int X509_REQ_print_fp(); -#endif - -int X509_NAME_print(); -int X509_print(); -int X509_REQ_print(); - -int X509_NAME_entry_count(); -int X509_NAME_get_text_by_NID(); -int X509_NAME_get_text_by_OBJ(); - -int X509_NAME_get_index_by_NID(); -int X509_NAME_get_index_by_OBJ(); -X509_NAME_ENTRY *X509_NAME_get_entry(); -X509_NAME_ENTRY *X509_NAME_delete_entry(); -int X509_NAME_add_entry(); -X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(); -X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(); -int X509_NAME_ENTRY_set_object(); -int X509_NAME_ENTRY_set_data(); -ASN1_OBJECT * X509_NAME_ENTRY_get_object(); -ASN1_STRING * X509_NAME_ENTRY_get_data(); - -int X509v3_get_ext_count(); -int X509v3_get_ext_by_NID(); -int X509v3_get_ext_by_OBJ(); -int X509v3_get_ext_by_critical(); -X509_EXTENSION *X509v3_get_ext(); -X509_EXTENSION *X509v3_delete_ext(); -STACK * X509v3_add_ext(); - -int X509v3_data_type_by_OBJ(); -int X509v3_data_type_by_NID(); -int X509v3_pack_type_by_OBJ(); -int X509v3_pack_type_by_NID(); - -int X509_get_ext_count(); -int X509_get_ext_by_NID(); -int X509_get_ext_by_OBJ(); -int X509_get_ext_by_critical(); -X509_EXTENSION *X509_get_ext(); -X509_EXTENSION *X509_delete_ext(); -int X509_add_ext(); - -int X509_CRL_get_ext_count(); -int X509_CRL_get_ext_by_NID(); -int X509_CRL_get_ext_by_OBJ(); -int X509_CRL_get_ext_by_critical(); -X509_EXTENSION *X509_CRL_get_ext(); -X509_EXTENSION *X509_CRL_delete_ext(); -int X509_CRL_add_ext(); - -int X509_REVOKED_get_ext_count(); -int X509_REVOKED_get_ext_by_NID(); -int X509_REVOKED_get_ext_by_OBJ(); -int X509_REVOKED_get_ext_by_critical(); -X509_EXTENSION *X509_REVOKED_get_ext(); -X509_EXTENSION *X509_REVOKED_delete_ext(); -int X509_REVOKED_add_ext(); - -X509_EXTENSION *X509_EXTENSION_create_by_NID(); -X509_EXTENSION *X509_EXTENSION_create_by_OBJ(); -int X509_EXTENSION_set_object(); -int X509_EXTENSION_set_critical(); -int X509_EXTENSION_set_data(); -ASN1_OBJECT * X509_EXTENSION_get_object(); -ASN1_OCTET_STRING *X509_EXTENSION_get_data(); -int X509_EXTENSION_get_critical(); -ASN1_OCTET_STRING *X509v3_pack_string(); -ASN1_STRING * X509v3_unpack_string(); - -int X509_verify_cert(); -char * X509_verify_cert_error_string(); - -/* lookup a cert from a X509 STACK */ -X509 *X509_find_by_issuer_and_serial(); -X509 *X509_find_by_subject(); - -#endif +X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name, + ASN1_INTEGER *serial); +X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name); + +int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp); +PBEPARAM *PBEPARAM_new(void); +PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length); +void PBEPARAM_free(PBEPARAM *a); +X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen); +X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, + unsigned char *salt, int saltlen); + +int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp); +PBKDF2PARAM *PBKDF2PARAM_new(void); +PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, long length); +void PBKDF2PARAM_free(PBKDF2PARAM *a); + +int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp); +PBE2PARAM *PBE2PARAM_new(void); +PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length); +void PBE2PARAM_free(PBE2PARAM *a); + +/* PKCS#8 utilities */ + +int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **pp); +PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void); +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a, + unsigned char **pp, long length); +void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a); + +EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8); +PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); +PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken); /* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + /* Error codes for the X509 functions. */ /* Function codes. */ @@ -1106,9 +941,7 @@ X509 *X509_find_by_subject(); #define X509_F_DIR_CTRL 102 #define X509_F_GET_CERT_BY_SUBJECT 103 #define X509_F_X509V3_ADD_EXT 104 -#define X509_F_X509V3_ADD_EXTENSION 105 -#define X509_F_X509V3_PACK_STRING 106 -#define X509_F_X509V3_UNPACK_STRING 107 +#define X509_F_X509_CHECK_PRIVATE_KEY 128 #define X509_F_X509_EXTENSION_CREATE_BY_NID 108 #define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 #define X509_F_X509_GET_PUBKEY_PARAMETERS 110 @@ -1132,19 +965,23 @@ X509 *X509_find_by_subject(); /* Reason codes. */ #define X509_R_BAD_X509_FILETYPE 100 +#define X509_R_CANT_CHECK_DH_KEY 114 #define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 #define X509_R_ERR_ASN1_LIB 102 +#define X509_R_INVALID_DIRECTORY 113 +#define X509_R_KEY_TYPE_MISMATCH 115 +#define X509_R_KEY_VALUES_MISMATCH 116 #define X509_R_LOADING_CERT_DIR 103 #define X509_R_LOADING_DEFAULTS 104 #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 #define X509_R_SHOULD_RETRY 106 #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 +#define X509_R_UNKNOWN_KEY_TYPE 117 #define X509_R_UNKNOWN_NID 109 -#define X509_R_UNKNOWN_STRING_TYPE 110 #define X509_R_UNSUPPORTED_ALGORITHM 111 #define X509_R_WRONG_LOOKUP_TYPE 112 - + #ifdef __cplusplus } #endif diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c index f9d9510ac5..9a93bae3ff 100644 --- a/src/lib/libcrypto/x509/x509_cmp.c +++ b/src/lib/libcrypto/x509/x509_cmp.c @@ -60,13 +60,11 @@ #include #include #include "cryptlib.h" -#include "asn1.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include -int X509_issuer_and_serial_cmp(a,b) -X509 *a; -X509 *b; +int X509_issuer_and_serial_cmp(X509 *a, X509 *b) { int i; X509_CINF *ai,*bi; @@ -79,8 +77,7 @@ X509 *b; } #ifndef NO_MD5 -unsigned long X509_issuer_and_serial_hash(a) -X509 *a; +unsigned long X509_issuer_and_serial_hash(X509 *a) { unsigned long ret=0; MD5_CTX ctx; @@ -101,70 +98,59 @@ X509 *a; } #endif -int X509_issuer_name_cmp(a, b) -X509 *a; -X509 *b; +int X509_issuer_name_cmp(X509 *a, X509 *b) { return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer)); } -int X509_subject_name_cmp(a, b) -X509 *a; -X509 *b; +int X509_subject_name_cmp(X509 *a, X509 *b) { return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject)); } -int X509_CRL_cmp(a, b) -X509_CRL *a; -X509_CRL *b; +int X509_CRL_cmp(X509_CRL *a, X509_CRL *b) { return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer)); } -X509_NAME *X509_get_issuer_name(a) -X509 *a; +X509_NAME *X509_get_issuer_name(X509 *a) { return(a->cert_info->issuer); } -unsigned long X509_issuer_name_hash(x) -X509 *x; +unsigned long X509_issuer_name_hash(X509 *x) { return(X509_NAME_hash(x->cert_info->issuer)); } -X509_NAME *X509_get_subject_name(a) -X509 *a; +X509_NAME *X509_get_subject_name(X509 *a) { return(a->cert_info->subject); } -ASN1_INTEGER *X509_get_serialNumber(a) -X509 *a; +ASN1_INTEGER *X509_get_serialNumber(X509 *a) { return(a->cert_info->serialNumber); } -unsigned long X509_subject_name_hash(x) -X509 *x; +unsigned long X509_subject_name_hash(X509 *x) { return(X509_NAME_hash(x->cert_info->subject)); } -int X509_NAME_cmp(a, b) -X509_NAME *a; -X509_NAME *b; +int X509_NAME_cmp(X509_NAME *a, X509_NAME *b) { int i,j; X509_NAME_ENTRY *na,*nb; - if (sk_num(a->entries) != sk_num(b->entries)) - return(sk_num(a->entries)-sk_num(b->entries)); - for (i=sk_num(a->entries)-1; i>=0; i--) + if (sk_X509_NAME_ENTRY_num(a->entries) + != sk_X509_NAME_ENTRY_num(b->entries)) + return sk_X509_NAME_ENTRY_num(a->entries) + -sk_X509_NAME_ENTRY_num(b->entries); + for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--) { - na=(X509_NAME_ENTRY *)sk_value(a->entries,i); - nb=(X509_NAME_ENTRY *)sk_value(b->entries,i); + na=sk_X509_NAME_ENTRY_value(a->entries,i); + nb=sk_X509_NAME_ENTRY_value(b->entries,i); j=na->value->length-nb->value->length; if (j) return(j); j=memcmp(na->value->data,nb->value->data, @@ -177,10 +163,10 @@ X509_NAME *b; /* We will check the object types after checking the values * since the values will more often be different than the object * types. */ - for (i=sk_num(a->entries)-1; i>=0; i--) + for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--) { - na=(X509_NAME_ENTRY *)sk_value(a->entries,i); - nb=(X509_NAME_ENTRY *)sk_value(b->entries,i); + na=sk_X509_NAME_ENTRY_value(a->entries,i); + nb=sk_X509_NAME_ENTRY_value(b->entries,i); j=OBJ_cmp(na->object,nb->object); if (j) return(j); } @@ -190,8 +176,7 @@ X509_NAME *b; #ifndef NO_MD5 /* I now DER encode the name and hash it. Since I cache the DER encoding, * this is reasonably effiecent. */ -unsigned long X509_NAME_hash(x) -X509_NAME *x; +unsigned long X509_NAME_hash(X509_NAME *x) { unsigned long ret=0; unsigned char md[16]; @@ -217,10 +202,8 @@ X509_NAME *x; #endif /* Search a stack of X509 for a match */ -X509 *X509_find_by_issuer_and_serial(sk,name,serial) -STACK *sk; -X509_NAME *name; -ASN1_INTEGER *serial; +X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name, + ASN1_INTEGER *serial) { int i; X509_CINF cinf; @@ -230,28 +213,81 @@ ASN1_INTEGER *serial; cinf.serialNumber=serial; cinf.issuer=name; - for (i=0; icert_info == NULL)) + return(NULL); + return(X509_PUBKEY_get(x->cert_info->key)); + } + +int X509_check_private_key(X509 *x, EVP_PKEY *k) + { + EVP_PKEY *xk=NULL; + int ok=0; + + xk=X509_get_pubkey(x); + if (xk->type != k->type) + { + X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH); + goto err; + } + switch (k->type) + { +#ifndef NO_RSA + case EVP_PKEY_RSA: + if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0 + || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0) + { + X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH); + goto err; + } + break; +#endif +#ifndef NO_DSA + case EVP_PKEY_DSA: + if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0) + { + X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH); + goto err; + } + break; +#endif +#ifndef NO_DH + case EVP_PKEY_DH: + /* No idea */ + X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY); + goto err; +#endif + default: + X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE); + goto err; + } + + ok=1; +err: + EVP_PKEY_free(xk); + return(ok); + } diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c index 01e22f4cb4..3e7ec5b432 100644 --- a/src/lib/libcrypto/x509/x509_d2.c +++ b/src/lib/libcrypto/x509/x509_d2.c @@ -60,12 +60,11 @@ #include #include #include "cryptlib.h" -#include "crypto.h" -#include "x509.h" +#include +#include #ifndef NO_STDIO -int X509_STORE_set_default_paths(ctx) -X509_STORE *ctx; +int X509_STORE_set_default_paths(X509_STORE *ctx) { X509_LOOKUP *lookup; @@ -83,10 +82,8 @@ X509_STORE *ctx; return(1); } -int X509_STORE_load_locations(ctx,file,path) -X509_STORE *ctx; -char *file; -char *path; +int X509_STORE_load_locations(X509_STORE *ctx, const char *file, + const char *path) { X509_LOOKUP *lookup; diff --git a/src/lib/libcrypto/x509/x509_def.c b/src/lib/libcrypto/x509/x509_def.c index d9ab39b15a..c4bee71569 100644 --- a/src/lib/libcrypto/x509/x509_def.c +++ b/src/lib/libcrypto/x509/x509_def.c @@ -60,24 +60,24 @@ #include #include #include "cryptlib.h" -#include "crypto.h" -#include "x509.h" +#include +#include -char *X509_get_default_private_dir() +const char *X509_get_default_private_dir(void) { return(X509_PRIVATE_DIR); } -char *X509_get_default_cert_area() +const char *X509_get_default_cert_area(void) { return(X509_CERT_AREA); } -char *X509_get_default_cert_dir() +const char *X509_get_default_cert_dir(void) { return(X509_CERT_DIR); } -char *X509_get_default_cert_file() +const char *X509_get_default_cert_file(void) { return(X509_CERT_FILE); } -char *X509_get_default_cert_dir_env() +const char *X509_get_default_cert_dir_env(void) { return(X509_CERT_DIR_EVP); } -char *X509_get_default_cert_file_env() +const char *X509_get_default_cert_file_env(void) { return(X509_CERT_FILE_EVP); } diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c index 9304721612..9afd4ccde5 100644 --- a/src/lib/libcrypto/x509/x509_err.c +++ b/src/lib/libcrypto/x509/x509_err.c @@ -1,63 +1,65 @@ -/* lib/x509/x509_err.c */ -/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* crypto/x509/x509_err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + #include -#include "err.h" -#include "x509.h" +#include +#include /* BEGIN ERROR CODES */ #ifndef NO_ERR @@ -68,14 +70,12 @@ static ERR_STRING_DATA X509_str_functs[]= {ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"}, {ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"}, {ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"}, -{ERR_PACK(0,X509_F_X509V3_ADD_EXTENSION,0), "X509V3_ADD_EXTENSION"}, -{ERR_PACK(0,X509_F_X509V3_PACK_STRING,0), "X509v3_pack_string"}, -{ERR_PACK(0,X509_F_X509V3_UNPACK_STRING,0), "X509v3_unpack_string"}, +{ERR_PACK(0,X509_F_X509_CHECK_PRIVATE_KEY,0), "X509_check_private_key"}, {ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"}, {ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"}, {ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"}, -{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_LOAD_CERT_FILE"}, -{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_LOAD_CRL_FILE"}, +{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_load_cert_file"}, +{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_load_crl_file"}, {ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"}, {ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"}, {ERR_PACK(0,X509_F_X509_NAME_ENTRY_SET_OBJECT,0), "X509_NAME_ENTRY_set_object"}, @@ -87,39 +87,43 @@ static ERR_STRING_DATA X509_str_functs[]= {ERR_PACK(0,X509_F_X509_REQ_PRINT,0), "X509_REQ_print"}, {ERR_PACK(0,X509_F_X509_REQ_PRINT_FP,0), "X509_REQ_print_fp"}, {ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"}, -{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_ADD_CERT"}, -{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_ADD_CRL"}, +{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_add_cert"}, +{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_add_crl"}, {ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"}, {ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"}, -{0,NULL}, +{0,NULL} }; static ERR_STRING_DATA X509_str_reasons[]= { {X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"}, +{X509_R_CANT_CHECK_DH_KEY ,"cant check dh key"}, {X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"}, {X509_R_ERR_ASN1_LIB ,"err asn1 lib"}, +{X509_R_INVALID_DIRECTORY ,"invalid directory"}, +{X509_R_KEY_TYPE_MISMATCH ,"key type mismatch"}, +{X509_R_KEY_VALUES_MISMATCH ,"key values mismatch"}, {X509_R_LOADING_CERT_DIR ,"loading cert dir"}, {X509_R_LOADING_DEFAULTS ,"loading defaults"}, {X509_R_NO_CERT_SET_FOR_US_TO_VERIFY ,"no cert set for us to verify"}, {X509_R_SHOULD_RETRY ,"should retry"}, {X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN,"unable to find parameters in chain"}, {X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"}, +{X509_R_UNKNOWN_KEY_TYPE ,"unknown key type"}, {X509_R_UNKNOWN_NID ,"unknown nid"}, -{X509_R_UNKNOWN_STRING_TYPE ,"unknown string type"}, {X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"}, {X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"}, -{0,NULL}, +{0,NULL} }; #endif -void ERR_load_X509_strings() +void ERR_load_X509_strings(void) { static int init=1; - if (init); - {; + if (init) + { init=0; #ifndef NO_ERR ERR_load_strings(ERR_LIB_X509,X509_str_functs); diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c index 1d76ecfcfd..f8565a60b2 100644 --- a/src/lib/libcrypto/x509/x509_ext.c +++ b/src/lib/libcrypto/x509/x509_ext.c @@ -57,166 +57,118 @@ */ #include -#include "stack.h" +#include #include "cryptlib.h" -#include "asn1.h" -#include "objects.h" -#include "evp.h" -#include "x509.h" +#include +#include +#include +#include -int X509_CRL_get_ext_count(x) -X509_CRL *x; +int X509_CRL_get_ext_count(X509_CRL *x) { return(X509v3_get_ext_count(x->crl->extensions)); } -int X509_CRL_get_ext_by_NID(x,nid,lastpos) -X509_CRL *x; -int nid; -int lastpos; +int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos) { return(X509v3_get_ext_by_NID(x->crl->extensions,nid,lastpos)); } -int X509_CRL_get_ext_by_OBJ(x,obj,lastpos) -X509_CRL *x; -ASN1_OBJECT *obj; -int lastpos; +int X509_CRL_get_ext_by_OBJ(X509_CRL *x, ASN1_OBJECT *obj, int lastpos) { return(X509v3_get_ext_by_OBJ(x->crl->extensions,obj,lastpos)); } -int X509_CRL_get_ext_by_critical(x,crit,lastpos) -X509_CRL *x; -int crit; -int lastpos; +int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos) { return(X509v3_get_ext_by_critical(x->crl->extensions,crit,lastpos)); } -X509_EXTENSION *X509_CRL_get_ext(x,loc) -X509_CRL *x; -int loc; +X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc) { return(X509v3_get_ext(x->crl->extensions,loc)); } -X509_EXTENSION *X509_CRL_delete_ext(x,loc) -X509_CRL *x; -int loc; +X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc) { return(X509v3_delete_ext(x->crl->extensions,loc)); } -int X509_CRL_add_ext(x,ex,loc) -X509_CRL *x; -X509_EXTENSION *ex; -int loc; +int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc) { return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL); } -int X509_get_ext_count(x) -X509 *x; +int X509_get_ext_count(X509 *x) { return(X509v3_get_ext_count(x->cert_info->extensions)); } -int X509_get_ext_by_NID(x,nid,lastpos) -X509 *x; -int nid; -int lastpos; +int X509_get_ext_by_NID(X509 *x, int nid, int lastpos) { return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos)); } -int X509_get_ext_by_OBJ(x,obj,lastpos) -X509 *x; -ASN1_OBJECT *obj; -int lastpos; +int X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos) { return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos)); } -int X509_get_ext_by_critical(x,crit,lastpos) -X509 *x; -int crit; -int lastpos; +int X509_get_ext_by_critical(X509 *x, int crit, int lastpos) { return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos)); } -X509_EXTENSION *X509_get_ext(x,loc) -X509 *x; -int loc; +X509_EXTENSION *X509_get_ext(X509 *x, int loc) { return(X509v3_get_ext(x->cert_info->extensions,loc)); } -X509_EXTENSION *X509_delete_ext(x,loc) -X509 *x; -int loc; +X509_EXTENSION *X509_delete_ext(X509 *x, int loc) { return(X509v3_delete_ext(x->cert_info->extensions,loc)); } -int X509_add_ext(x,ex,loc) -X509 *x; -X509_EXTENSION *ex; -int loc; +int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc) { return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL); } -int X509_REVOKED_get_ext_count(x) -X509_REVOKED *x; +int X509_REVOKED_get_ext_count(X509_REVOKED *x) { return(X509v3_get_ext_count(x->extensions)); } -int X509_REVOKED_get_ext_by_NID(x,nid,lastpos) -X509_REVOKED *x; -int nid; -int lastpos; +int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos) { return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos)); } -int X509_REVOKED_get_ext_by_OBJ(x,obj,lastpos) -X509_REVOKED *x; -ASN1_OBJECT *obj; -int lastpos; +int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x, ASN1_OBJECT *obj, + int lastpos) { return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos)); } -int X509_REVOKED_get_ext_by_critical(x,crit,lastpos) -X509_REVOKED *x; -int crit; -int lastpos; +int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos) { return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos)); } -X509_EXTENSION *X509_REVOKED_get_ext(x,loc) -X509_REVOKED *x; -int loc; +X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc) { return(X509v3_get_ext(x->extensions,loc)); } -X509_EXTENSION *X509_REVOKED_delete_ext(x,loc) -X509_REVOKED *x; -int loc; +X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc) { return(X509v3_delete_ext(x->extensions,loc)); } -int X509_REVOKED_add_ext(x,ex,loc) -X509_REVOKED *x; -X509_EXTENSION *ex; -int loc; +int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc) { return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL); } +IMPLEMENT_STACK_OF(X509_EXTENSION) +IMPLEMENT_ASN1_SET_OF(X509_EXTENSION) diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c index 2c7e10a46e..18bfecb11e 100644 --- a/src/lib/libcrypto/x509/x509_lu.c +++ b/src/lib/libcrypto/x509/x509_lu.c @@ -58,14 +58,13 @@ #include #include "cryptlib.h" -#include "lhash.h" -#include "x509.h" +#include +#include static STACK *x509_store_meth=NULL; static STACK *x509_store_ctx_meth=NULL; -X509_LOOKUP *X509_LOOKUP_new(method) -X509_LOOKUP_METHOD *method; +X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method) { X509_LOOKUP *ret; @@ -85,8 +84,7 @@ X509_LOOKUP_METHOD *method; return(ret); } -void X509_LOOKUP_free(ctx) -X509_LOOKUP *ctx; +void X509_LOOKUP_free(X509_LOOKUP *ctx) { if (ctx == NULL) return; if ( (ctx->method != NULL) && @@ -95,8 +93,7 @@ X509_LOOKUP *ctx; Free(ctx); } -int X509_LOOKUP_init(ctx) -X509_LOOKUP *ctx; +int X509_LOOKUP_init(X509_LOOKUP *ctx) { if (ctx->method == NULL) return(0); if (ctx->method->init != NULL) @@ -105,22 +102,17 @@ X509_LOOKUP *ctx; return(1); } -int X509_LOOKUP_shutdown(ctx) -X509_LOOKUP *ctx; +int X509_LOOKUP_shutdown(X509_LOOKUP *ctx) { if (ctx->method == NULL) return(0); - if (ctx->method->init != NULL) + if (ctx->method->shutdown != NULL) return(ctx->method->shutdown(ctx)); else return(1); } -int X509_LOOKUP_ctrl(ctx,cmd,argc,argl,ret) -X509_LOOKUP *ctx; -int cmd; -char *argc; -long argl; -char **ret; +int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, + char **ret) { if (ctx->method == NULL) return(-1); if (ctx->method->ctrl != NULL) @@ -129,11 +121,8 @@ char **ret; return(1); } -int X509_LOOKUP_by_subject(ctx,type,name,ret) -X509_LOOKUP *ctx; -int type; -X509_NAME *name; -X509_OBJECT *ret; +int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name, + X509_OBJECT *ret) { if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL)) return(X509_LU_FAIL); @@ -141,12 +130,8 @@ X509_OBJECT *ret; return(ctx->method->get_by_subject(ctx,type,name,ret)); } -int X509_LOOKUP_by_issuer_serial(ctx,type,name,serial,ret) -X509_LOOKUP *ctx; -int type; -X509_NAME *name; -ASN1_INTEGER *serial; -X509_OBJECT *ret; +int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name, + ASN1_INTEGER *serial, X509_OBJECT *ret) { if ((ctx->method == NULL) || (ctx->method->get_by_issuer_serial == NULL)) @@ -154,32 +139,23 @@ X509_OBJECT *ret; return(ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret)); } -int X509_LOOKUP_by_fingerprint(ctx,type,bytes,len,ret) -X509_LOOKUP *ctx; -int type; -unsigned char *bytes; -int len; -X509_OBJECT *ret; +int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, + unsigned char *bytes, int len, X509_OBJECT *ret) { if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL)) return(X509_LU_FAIL); return(ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret)); } -int X509_LOOKUP_by_alias(ctx,type,str,len,ret) -X509_LOOKUP *ctx; -int type; -char *str; -int len; -X509_OBJECT *ret; +int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len, + X509_OBJECT *ret) { if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL)) return(X509_LU_FAIL); - return(ctx->method->get_by_alias(ctx,str,len,ret)); + return(ctx->method->get_by_alias(ctx,type,str,len,ret)); } -static unsigned long x509_object_hash(a) -X509_OBJECT *a; +static unsigned long x509_object_hash(X509_OBJECT *a) { unsigned long h; @@ -197,8 +173,7 @@ X509_OBJECT *a; return(h); } -static int x509_object_cmp(a,b) -X509_OBJECT *a,*b; +static int x509_object_cmp(X509_OBJECT *a, X509_OBJECT *b) { int ret; @@ -218,7 +193,7 @@ X509_OBJECT *a,*b; return(ret); } -X509_STORE *X509_STORE_new() +X509_STORE *X509_STORE_new(void) { X509_STORE *ret; @@ -226,16 +201,16 @@ X509_STORE *X509_STORE_new() return(NULL); ret->certs=lh_new(x509_object_hash,x509_object_cmp); ret->cache=1; - ret->get_cert_methods=sk_new_null(); + ret->get_cert_methods=sk_X509_LOOKUP_new_null(); ret->verify=NULL; ret->verify_cb=NULL; memset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA)); ret->references=1; + ret->depth=0; return(ret); } -static void cleanup(a) -X509_OBJECT *a; +static void cleanup(X509_OBJECT *a) { if (a->type == X509_LU_X509) { @@ -251,21 +226,23 @@ X509_OBJECT *a; Free(a); } -void X509_STORE_free(vfy) -X509_STORE *vfy; +void X509_STORE_free(X509_STORE *vfy) { int i; - STACK *sk; + STACK_OF(X509_LOOKUP) *sk; X509_LOOKUP *lu; + if(vfy == NULL) + return; + sk=vfy->get_cert_methods; - for (i=0; iex_data); lh_doall(vfy->certs,cleanup); @@ -273,18 +250,16 @@ X509_STORE *vfy; Free(vfy); } -X509_LOOKUP *X509_STORE_add_lookup(v,m) -X509_STORE *v; -X509_LOOKUP_METHOD *m; +X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m) { int i; - STACK *sk; + STACK_OF(X509_LOOKUP) *sk; X509_LOOKUP *lu; sk=v->get_cert_methods; - for (i=0; imethod) { return(lu); @@ -297,7 +272,7 @@ X509_LOOKUP_METHOD *m; else { lu->store_ctx=v; - if (sk_push(v->get_cert_methods,(char *)lu)) + if (sk_X509_LOOKUP_push(v->get_cert_methods,lu)) return(lu); else { @@ -307,24 +282,21 @@ X509_LOOKUP_METHOD *m; } } -int X509_STORE_get_by_subject(vs,type,name,ret) -X509_STORE_CTX *vs; -int type; -X509_NAME *name; -X509_OBJECT *ret; +int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name, + X509_OBJECT *ret) { X509_STORE *ctx=vs->ctx; X509_LOOKUP *lu; X509_OBJECT stmp,*tmp; int i,j; - tmp=X509_OBJECT_retrive_by_subject(ctx->certs,type,name); + tmp=X509_OBJECT_retrieve_by_subject(ctx->certs,type,name); if (tmp == NULL) { - for (i=vs->current_method; iget_cert_methods); i++) + for (i=vs->current_method; iget_cert_methods); i++) { - lu=(X509_LOOKUP *)sk_value(ctx->get_cert_methods,i); + lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i); j=X509_LOOKUP_by_subject(lu,type,name,&stmp); if (j < 0) { @@ -353,8 +325,7 @@ X509_OBJECT *ret; return(1); } -void X509_OBJECT_up_ref_count(a) -X509_OBJECT *a; +void X509_OBJECT_up_ref_count(X509_OBJECT *a) { switch (a->type) { @@ -367,8 +338,7 @@ X509_OBJECT *a; } } -void X509_OBJECT_free_contents(a) -X509_OBJECT *a; +void X509_OBJECT_free_contents(X509_OBJECT *a) { switch (a->type) { @@ -381,10 +351,8 @@ X509_OBJECT *a; } } -X509_OBJECT *X509_OBJECT_retrive_by_subject(h,type,name) -LHASH *h; -int type; -X509_NAME *name; +X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h, int type, + X509_NAME *name) { X509_OBJECT stmp,*tmp; X509 x509_s; @@ -413,11 +381,8 @@ X509_NAME *name; return(tmp); } -void X509_STORE_CTX_init(ctx,store,x509,chain) -X509_STORE_CTX *ctx; -X509_STORE *store; -X509 *x509; -STACK *chain; +void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, + STACK_OF(X509) *chain) { ctx->ctx=store; ctx->current_method=0; @@ -426,21 +391,21 @@ STACK *chain; ctx->last_untrusted=0; ctx->valid=0; ctx->chain=NULL; - ctx->depth=10; + ctx->depth=9; ctx->error=0; ctx->current_cert=NULL; memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA)); } -void X509_STORE_CTX_cleanup(ctx) -X509_STORE_CTX *ctx; +void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx) { if (ctx->chain != NULL) { - sk_pop_free(ctx->chain,X509_free); + sk_X509_pop_free(ctx->chain,X509_free); ctx->chain=NULL; } CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data)); memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA)); } +IMPLEMENT_STACK_OF(X509_LOOKUP) diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c index c0576fd6f6..691b71f031 100644 --- a/src/lib/libcrypto/x509/x509_obj.c +++ b/src/lib/libcrypto/x509/x509_obj.c @@ -58,27 +58,27 @@ #include #include "cryptlib.h" -#include "lhash.h" -#include "objects.h" -#include "x509.h" -#include "buffer.h" +#include +#include +#include +#include -char *X509_NAME_oneline(a,buf,len) -X509_NAME *a; -char *buf; -int len; +char *X509_NAME_oneline(X509_NAME *a, char *buf, int len) { X509_NAME_ENTRY *ne; - unsigned int i; +int i; int n,lold,l,l1,l2,num,j,type; - char *s,*p; + const char *s; + char *p; unsigned char *q; BUF_MEM *b=NULL; static char hex[17]="0123456789ABCDEF"; int gs_doit[4]; char tmp_buf[80]; +#ifdef CHARSET_EBCDIC + char ebcdic_buf[1024]; +#endif - if (a == NULL) return("NO X509_NAME"); if (buf == NULL) { if ((b=BUF_MEM_new()) == NULL) goto err; @@ -86,12 +86,22 @@ int len; b->data[0]='\0'; len=200; } + if (a == NULL) + { + if(b) + { + buf=b->data; + Free(b); + } + strncpy(buf,"NO X509_NAME",len); + return buf; + } len--; /* space for '\0' */ l=0; - for (i=0; (int)ientries); i++) + for (i=0; ientries); i++) { - ne=(X509_NAME_ENTRY *)sk_value(a->entries,i); + ne=sk_X509_NAME_ENTRY_value(a->entries,i); n=OBJ_obj2nid(ne->object); if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL)) { @@ -103,6 +113,19 @@ int len; type=ne->value->type; num=ne->value->length; q=ne->value->data; +#ifdef CHARSET_EBCDIC + if (type == V_ASN1_GENERALSTRING || + type == V_ASN1_VISIBLESTRING || + type == V_ASN1_PRINTABLESTRING || + type == V_ASN1_TELETEXSTRING || + type == V_ASN1_VISIBLESTRING || + type == V_ASN1_IA5STRING) { + ascii2ebcdic(ebcdic_buf, q, + (num > sizeof ebcdic_buf) + ? sizeof ebcdic_buf : num); + q=ebcdic_buf; + } +#endif if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0)) { @@ -125,7 +148,12 @@ int len; { if (!gs_doit[j&3]) continue; l2++; +#ifndef CHARSET_EBCDIC if ((q[j] < ' ') || (q[j] > '~')) l2+=3; +#else + if ((os_toascii[q[j]] < os_toascii[' ']) || + (os_toascii[q[j]] > os_toascii['~'])) l2+=3; +#endif } lold=l; @@ -145,11 +173,14 @@ int len; memcpy(p,s,(unsigned int)l1); p+=l1; *(p++)='='; +#ifndef CHARSET_EBCDIC /* q was assigned above already. */ q=ne->value->data; +#endif for (j=0; j '~')) { @@ -160,13 +191,26 @@ int len; } else *(p++)=n; +#else + n=os_toascii[q[j]]; + if ((n < os_toascii[' ']) || + (n > os_toascii['~'])) + { + *(p++)='\\'; + *(p++)='x'; + *(p++)=hex[(n>>4)&0x0f]; + *(p++)=hex[n&0x0f]; + } + else + *(p++)=q[j]; +#endif } *p='\0'; } if (b != NULL) { p=b->data; - Free((char *)b); + Free(b); } else p=buf; diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c index 6aec2427f7..bb4697ae60 100644 --- a/src/lib/libcrypto/x509/x509_r2x.c +++ b/src/lib/libcrypto/x509/x509_r2x.c @@ -58,22 +58,16 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "evp.h" -#include "asn1.h" -#include "x509.h" -#include "objects.h" -#include "buffer.h" -#include "pem.h" +#include +#include +#include +#include +#include +#include -X509 *X509_REQ_to_X509(r,days,pkey) -X509_REQ *r; -int days; -EVP_PKEY *pkey; +X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) { X509 *ret=NULL; - int er=1; - X509_REQ_INFO *ri=NULL; X509_CINF *xi=NULL; X509_NAME *xn; @@ -84,13 +78,9 @@ EVP_PKEY *pkey; } /* duplicate the request */ - ri=(X509_REQ_INFO *)ASN1_dup(i2d_X509_REQ_INFO, - (char *(*)())d2i_X509_REQ_INFO,(char *)r->req_info); - if (ri == NULL) goto err; - xi=ret->cert_info; - if (sk_num(ri->attributes) != 0) + if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0) { if ((xi->version=ASN1_INTEGER_new()) == NULL) goto err; if (!ASN1_INTEGER_set(xi->version,2)) goto err; @@ -109,13 +99,11 @@ EVP_PKEY *pkey; if (!X509_sign(ret,pkey,EVP_md5())) goto err; - er=0; -err: - if (er) + if (0) { +err: X509_free(ret); - X509_REQ_INFO_free(ri); - return(NULL); + ret=NULL; } return(ret); } diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c index 5004365bad..2ef94decd1 100644 --- a/src/lib/libcrypto/x509/x509_req.c +++ b/src/lib/libcrypto/x509/x509_req.c @@ -58,22 +58,20 @@ #include #include "cryptlib.h" -#include "bn.h" -#include "evp.h" -#include "asn1.h" -#include "x509.h" -#include "objects.h" -#include "buffer.h" -#include "pem.h" +#include +#include +#include +#include +#include +#include +#include -X509_REQ *X509_to_X509_REQ(x,pkey,md) -X509 *x; -EVP_PKEY *pkey; -EVP_MD *md; +X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md) { X509_REQ *ret; X509_REQ_INFO *ri; int i; + EVP_PKEY *pktmp; ret=X509_REQ_new(); if (ret == NULL) @@ -92,7 +90,9 @@ EVP_MD *md; if (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x))) goto err; - i=X509_REQ_set_pubkey(ret,X509_get_pubkey(x)); + pktmp = X509_get_pubkey(x); + i=X509_REQ_set_pubkey(ret,pktmp); + EVP_PKEY_free(pktmp); if (!i) goto err; if (pkey != NULL) @@ -106,8 +106,7 @@ err: return(NULL); } -EVP_PKEY *X509_REQ_get_pubkey(req) -X509_REQ *req; +EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req) { if ((req == NULL) || (req->req_info == NULL)) return(NULL); diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c index 5d0a3a0c0e..5a6f7b414f 100644 --- a/src/lib/libcrypto/x509/x509_set.c +++ b/src/lib/libcrypto/x509/x509_set.c @@ -58,14 +58,12 @@ #include #include "cryptlib.h" -#include "asn1.h" -#include "objects.h" -#include "evp.h" -#include "x509.h" +#include +#include +#include +#include -int X509_set_version(x,version) -X509 *x; -long version; +int X509_set_version(X509 *x, long version) { if (x == NULL) return(0); if (x->cert_info->version == NULL) @@ -76,9 +74,7 @@ long version; return(ASN1_INTEGER_set(x->cert_info->version,version)); } -int X509_set_serialNumber(x,serial) -X509 *x; -ASN1_INTEGER *serial; +int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial) { ASN1_INTEGER *in; @@ -96,25 +92,19 @@ ASN1_INTEGER *serial; return(in != NULL); } -int X509_set_issuer_name(x,name) -X509 *x; -X509_NAME *name; +int X509_set_issuer_name(X509 *x, X509_NAME *name) { if ((x == NULL) || (x->cert_info == NULL)) return(0); return(X509_NAME_set(&x->cert_info->issuer,name)); } -int X509_set_subject_name(x,name) -X509 *x; -X509_NAME *name; +int X509_set_subject_name(X509 *x, X509_NAME *name) { if ((x == NULL) || (x->cert_info == NULL)) return(0); return(X509_NAME_set(&x->cert_info->subject,name)); } -int X509_set_notBefore(x,tm) -X509 *x; -ASN1_UTCTIME *tm; +int X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm) { ASN1_UTCTIME *in; @@ -132,9 +122,7 @@ ASN1_UTCTIME *tm; return(in != NULL); } -int X509_set_notAfter(x,tm) -X509 *x; -ASN1_UTCTIME *tm; +int X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm) { ASN1_UTCTIME *in; @@ -152,9 +140,7 @@ ASN1_UTCTIME *tm; return(in != NULL); } -int X509_set_pubkey(x,pkey) -X509 *x; -EVP_PKEY *pkey; +int X509_set_pubkey(X509 *x, EVP_PKEY *pkey) { if ((x == NULL) || (x->cert_info == NULL)) return(0); return(X509_PUBKEY_set(&(x->cert_info->key),pkey)); diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c index 408d1c277c..11a3d2012f 100644 --- a/src/lib/libcrypto/x509/x509_txt.c +++ b/src/lib/libcrypto/x509/x509_txt.c @@ -62,16 +62,14 @@ #include #include "cryptlib.h" -#include "lhash.h" -#include "buffer.h" -#include "evp.h" -#include "asn1.h" -#include "x509.h" -#include "objects.h" -#include "pem.h" +#include +#include +#include +#include +#include +#include -char *X509_verify_cert_error_string(n) -long n; +const char *X509_verify_cert_error_string(long n) { static char buf[100]; @@ -121,6 +119,8 @@ long n; return("unable to verify the first certificate"); case X509_V_ERR_CERT_CHAIN_TOO_LONG: return("certificate chain too long"); + case X509_V_ERR_CERT_REVOKED: + return("certificate revoked"); case X509_V_ERR_APPLICATION_VERIFICATION: return("application verification failure"); default: diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c index 1c03602f0b..dd2f9f1b17 100644 --- a/src/lib/libcrypto/x509/x509_v3.c +++ b/src/lib/libcrypto/x509/x509_v3.c @@ -57,34 +57,21 @@ */ #include -#include "stack.h" +#include #include "cryptlib.h" -#include "asn1.h" -#include "objects.h" -#include "evp.h" -#include "x509.h" +#include +#include +#include +#include -#ifndef NOPROTO -static X509_EXTENSION_METHOD *find_by_nid(int nid); -static int xem_cmp(X509_EXTENSION_METHOD **a, X509_EXTENSION_METHOD **b); -#else -static X509_EXTENSION_METHOD *find_by_nid(); -static int xem_cmp(); -#endif - -static STACK *extensions=NULL; - -int X509v3_get_ext_count(x) -STACK *x; +int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x) { if (x == NULL) return(0); - return(sk_num(x)); + return(sk_X509_EXTENSION_num(x)); } -int X509v3_get_ext_by_NID(x,nid,lastpos) -STACK *x; -int nid; -int lastpos; +int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid, + int lastpos) { ASN1_OBJECT *obj; @@ -93,10 +80,8 @@ int lastpos; return(X509v3_get_ext_by_OBJ(x,obj,lastpos)); } -int X509v3_get_ext_by_OBJ(sk,obj,lastpos) -STACK *sk; -ASN1_OBJECT *obj; -int lastpos; +int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj, + int lastpos) { int n; X509_EXTENSION *ex; @@ -105,20 +90,18 @@ int lastpos; lastpos++; if (lastpos < 0) lastpos=0; - n=sk_num(sk); + n=sk_X509_EXTENSION_num(sk); for ( ; lastpos < n; lastpos++) { - ex=(X509_EXTENSION *)sk_value(sk,lastpos); + ex=sk_X509_EXTENSION_value(sk,lastpos); if (OBJ_cmp(ex->object,obj) == 0) return(lastpos); } return(-1); } -int X509v3_get_ext_by_critical(sk,crit,lastpos) -STACK *sk; -int crit; -int lastpos; +int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit, + int lastpos) { int n; X509_EXTENSION *ex; @@ -127,10 +110,10 @@ int lastpos; lastpos++; if (lastpos < 0) lastpos=0; - n=sk_num(sk); + n=sk_X509_EXTENSION_num(sk); for ( ; lastpos < n; lastpos++) { - ex=(X509_EXTENSION *)sk_value(sk,lastpos); + ex=sk_X509_EXTENSION_value(sk,lastpos); if ( (ex->critical && crit) || (!ex->critical && !crit)) return(lastpos); @@ -138,52 +121,46 @@ int lastpos; return(-1); } -X509_EXTENSION *X509v3_get_ext(x,loc) -STACK *x; -int loc; +X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc) { - if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0)) - return(NULL); + if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0) + return NULL; else - return((X509_EXTENSION *)sk_value(x,loc)); + return sk_X509_EXTENSION_value(x,loc); } -X509_EXTENSION *X509v3_delete_ext(x,loc) -STACK *x; -int loc; +X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc) { X509_EXTENSION *ret; - if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0)) + if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0) return(NULL); - ret=(X509_EXTENSION *)sk_delete(x,loc); + ret=sk_X509_EXTENSION_delete(x,loc); return(ret); } -STACK *X509v3_add_ext(x,ex,loc) -STACK **x; -X509_EXTENSION *ex; -int loc; +STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, + X509_EXTENSION *ex, int loc) { X509_EXTENSION *new_ex=NULL; int n; - STACK *sk=NULL; + STACK_OF(X509_EXTENSION) *sk=NULL; if ((x != NULL) && (*x == NULL)) { - if ((sk=sk_new_null()) == NULL) + if ((sk=sk_X509_EXTENSION_new_null()) == NULL) goto err; } else sk= *x; - n=sk_num(sk); + n=sk_X509_EXTENSION_num(sk); if (loc > n) loc=n; else if (loc < 0) loc=n; if ((new_ex=X509_EXTENSION_dup(ex)) == NULL) goto err2; - if (!sk_insert(sk,(char *)new_ex,loc)) + if (!sk_X509_EXTENSION_insert(sk,new_ex,loc)) goto err; if ((x != NULL) && (*x == NULL)) *x=sk; @@ -192,15 +169,12 @@ err: X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE); err2: if (new_ex != NULL) X509_EXTENSION_free(new_ex); - if (sk != NULL) sk_free(sk); + if (sk != NULL) sk_X509_EXTENSION_free(sk); return(NULL); } -X509_EXTENSION *X509_EXTENSION_create_by_NID(ex,nid,crit,data) -X509_EXTENSION **ex; -int nid; -int crit; -ASN1_OCTET_STRING *data; +X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid, + int crit, ASN1_OCTET_STRING *data) { ASN1_OBJECT *obj; X509_EXTENSION *ret; @@ -216,11 +190,8 @@ ASN1_OCTET_STRING *data; return(ret); } -X509_EXTENSION *X509_EXTENSION_create_by_OBJ(ex,obj,crit,data) -X509_EXTENSION **ex; -ASN1_OBJECT *obj; -int crit; -ASN1_OCTET_STRING *data; +X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, + ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data) { X509_EXTENSION *ret; @@ -250,9 +221,7 @@ err: return(NULL); } -int X509_EXTENSION_set_object(ex,obj) -X509_EXTENSION *ex; -ASN1_OBJECT *obj; +int X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj) { if ((ex == NULL) || (obj == NULL)) return(0); @@ -261,18 +230,14 @@ ASN1_OBJECT *obj; return(1); } -int X509_EXTENSION_set_critical(ex,crit) -X509_EXTENSION *ex; -int crit; +int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit) { if (ex == NULL) return(0); ex->critical=(crit)?0xFF:0; return(1); } -int X509_EXTENSION_set_data(ex,data) -X509_EXTENSION *ex; -ASN1_OCTET_STRING *data; +int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data) { int i; @@ -282,128 +247,20 @@ ASN1_OCTET_STRING *data; return(1); } -ASN1_OBJECT *X509_EXTENSION_get_object(ex) -X509_EXTENSION *ex; +ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex) { if (ex == NULL) return(NULL); return(ex->object); } -ASN1_OCTET_STRING *X509_EXTENSION_get_data(ex) -X509_EXTENSION *ex; +ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex) { if (ex == NULL) return(NULL); return(ex->value); } -int X509_EXTENSION_get_critical(ex) -X509_EXTENSION *ex; +int X509_EXTENSION_get_critical(X509_EXTENSION *ex) { if (ex == NULL) return(0); return(ex->critical); } - -int X509v3_data_type_by_OBJ(obj) -ASN1_OBJECT *obj; - { - int nid; - - nid=OBJ_obj2nid(obj); - if (nid == V_ASN1_UNDEF) return(V_ASN1_UNDEF); - return(X509v3_data_type_by_NID(nid)); - } - -int X509v3_data_type_by_NID(nid) -int nid; - { - X509_EXTENSION_METHOD *x; - - x=find_by_nid(nid); - if (x == NULL) - return(V_ASN1_UNDEF); - else - return(x->data_type); - } - -int X509v3_pack_type_by_OBJ(obj) -ASN1_OBJECT *obj; - { - int nid; - - nid=OBJ_obj2nid(obj); - if (nid == NID_undef) return(X509_EXT_PACK_UNKNOWN); - return(X509v3_pack_type_by_NID(nid)); - } - -int X509v3_pack_type_by_NID(nid) -int nid; - { - X509_EXTENSION_METHOD *x; - - x=find_by_nid(nid); - if (x == NULL) - return(X509_EXT_PACK_UNKNOWN); - else - return(x->pack_type); - } - -static X509_EXTENSION_METHOD *find_by_nid(nid) -int nid; - { - X509_EXTENSION_METHOD x; - int i; - - x.nid=nid; - if (extensions == NULL) return(NULL); - i=sk_find(extensions,(char *)&x); - if (i < 0) - return(NULL); - else - return((X509_EXTENSION_METHOD *)sk_value(extensions,i)); - } - -static int xem_cmp(a,b) -X509_EXTENSION_METHOD **a,**b; - { - return((*a)->nid-(*b)->nid); - } - -void X509v3_cleanup_extensions() - { - int i; - - if (extensions != NULL) - { - for (i=0; inid=x->nid; - newx->data_type=x->data_type; - newx->pack_type=x->pack_type; - if (!sk_push(extensions,(char *)newx)) - { - Free(newx); - goto err; - } - return(1); -err: - X509err(X509_F_X509V3_ADD_EXTENSION,ERR_R_MALLOC_FAILURE); - return(0); - } - diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c index c1be91edba..c72ee4a385 100644 --- a/src/lib/libcrypto/x509/x509_vfy.c +++ b/src/lib/libcrypto/x509/x509_vfy.c @@ -62,25 +62,19 @@ #include #include -#include "crypto.h" +#include #include "cryptlib.h" -#include "lhash.h" -#include "buffer.h" -#include "evp.h" -#include "asn1.h" -#include "x509.h" -#include "objects.h" -#include "pem.h" - -#ifndef NOPROTO +#include +#include +#include +#include +#include +#include + static int null_callback(int ok,X509_STORE_CTX *e); static int internal_verify(X509_STORE_CTX *ctx); -#else -static int null_callback(); -static int internal_verify(); -#endif +const char *X509_version="X.509" OPENSSL_VERSION_PTEXT; -char *X509_version="X509 part of SSLeay 0.9.0b 29-Jun-1998"; static STACK *x509_store_ctx_method=NULL; static int x509_store_ctx_num=0; #if 0 @@ -88,23 +82,19 @@ static int x509_store_num=1; static STACK *x509_store_method=NULL; #endif -static int null_callback(ok,e) -int ok; -X509_STORE_CTX *e; +static int null_callback(int ok, X509_STORE_CTX *e) { return(ok); } #if 0 -static int x509_subject_cmp(a,b) -X509 **a,**b; +static int x509_subject_cmp(X509 **a, X509 **b) { return(X509_subject_name_cmp(*a,*b)); } #endif -int X509_verify_cert(ctx) -X509_STORE_CTX *ctx; +int X509_verify_cert(X509_STORE_CTX *ctx) { X509 *x,*xtmp,*chain_ss=NULL; X509_NAME *xn; @@ -112,7 +102,7 @@ X509_STORE_CTX *ctx; int depth,i,ok=0; int num; int (*cb)(); - STACK *sktmp=NULL; + STACK_OF(X509) *sktmp=NULL; if (ctx->cert == NULL) { @@ -127,8 +117,8 @@ X509_STORE_CTX *ctx; * present and that the first entry is in place */ if (ctx->chain == NULL) { - if ( ((ctx->chain=sk_new_null()) == NULL) || - (!sk_push(ctx->chain,(char *)ctx->cert))) + if ( ((ctx->chain=sk_X509_new_null()) == NULL) || + (!sk_X509_push(ctx->chain,ctx->cert))) { X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); goto end; @@ -138,21 +128,26 @@ X509_STORE_CTX *ctx; } /* We use a temporary so we can chop and hack at it */ - if ((ctx->untrusted != NULL) && (sktmp=sk_dup(ctx->untrusted)) == NULL) + if (ctx->untrusted != NULL + && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL) { X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); goto end; } - num=sk_num(ctx->chain); - x=(X509 *)sk_value(ctx->chain,num-1); + num=sk_X509_num(ctx->chain); + x=sk_X509_value(ctx->chain,num-1); depth=ctx->depth; for (;;) { /* If we have enough, we break */ - if (depth <= num) break; + if (depth < num) break; /* FIXME: If this happens, we should take + * note of it and, if appropriate, use the + * X509_V_ERR_CERT_CHAIN_TOO_LONG error + * code later. + */ /* If we are self signed, we break */ xn=X509_get_issuer_name(x); @@ -165,13 +160,13 @@ X509_STORE_CTX *ctx; xtmp=X509_find_by_subject(sktmp,xn); if (xtmp != NULL) { - if (!sk_push(ctx->chain,(char *)xtmp)) + if (!sk_X509_push(ctx->chain,xtmp)) { X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); goto end; } CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509); - sk_delete_ptr(sktmp,(char *)xtmp); + sk_X509_delete_ptr(sktmp,xtmp); ctx->last_untrusted++; x=xtmp; num++; @@ -187,13 +182,13 @@ X509_STORE_CTX *ctx; * certificates. We now need to add at least one trusted one, * if possible, otherwise we complain. */ - i=sk_num(ctx->chain); - x=(X509 *)sk_value(ctx->chain,i-1); + i=sk_X509_num(ctx->chain); + x=sk_X509_value(ctx->chain,i-1); if (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x)) == 0) { /* we have a self signed certificate */ - if (sk_num(ctx->chain) == 1) + if (sk_X509_num(ctx->chain) == 1) { ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT; ctx->current_cert=x; @@ -204,10 +199,10 @@ X509_STORE_CTX *ctx; else { /* worry more about this one elsewhere */ - chain_ss=(X509 *)sk_pop(ctx->chain); + chain_ss=sk_X509_pop(ctx->chain); ctx->last_untrusted--; num--; - x=(X509 *)sk_value(ctx->chain,num-1); + x=sk_X509_value(ctx->chain,num-1); } } @@ -215,7 +210,7 @@ X509_STORE_CTX *ctx; for (;;) { /* If we have enough, we break */ - if (depth <= num) break; + if (depth < num) break; /* If we are self signed, we break */ xn=X509_get_issuer_name(x); @@ -240,7 +235,7 @@ X509_STORE_CTX *ctx; break; } x=obj.data.x509; - if (!sk_push(ctx->chain,(char *)obj.data.x509)) + if (!sk_X509_push(ctx->chain,obj.data.x509)) { X509_OBJECT_free_contents(&obj); X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); @@ -264,7 +259,7 @@ X509_STORE_CTX *ctx; else { - sk_push(ctx->chain,(char *)chain_ss); + sk_X509_push(ctx->chain,chain_ss); num++; ctx->last_untrusted=num; ctx->current_cert=chain_ss; @@ -285,14 +280,17 @@ X509_STORE_CTX *ctx; ok=ctx->ctx->verify(ctx); else ok=internal_verify(ctx); + if (0) + { end: - if (sktmp != NULL) sk_free(sktmp); + X509_get_pubkey_parameters(NULL,ctx->chain); + } + if (sktmp != NULL) sk_X509_free(sktmp); if (chain_ss != NULL) X509_free(chain_ss); return(ok); } -static int internal_verify(ctx) -X509_STORE_CTX *ctx; +static int internal_verify(X509_STORE_CTX *ctx) { int i,ok=0,n; X509 *xs,*xi; @@ -302,10 +300,10 @@ X509_STORE_CTX *ctx; cb=ctx->ctx->verify_cb; if (cb == NULL) cb=null_callback; - n=sk_num(ctx->chain); + n=sk_X509_num(ctx->chain); ctx->error_depth=n-1; n--; - xi=(X509 *)sk_value(ctx->chain,n); + xi=sk_X509_value(ctx->chain,n); if (X509_NAME_cmp(X509_get_subject_name(xi), X509_get_issuer_name(xi)) == 0) xs=xi; @@ -322,7 +320,7 @@ X509_STORE_CTX *ctx; { n--; ctx->error_depth=n; - xs=(X509 *)sk_value(ctx->chain,n); + xs=sk_X509_value(ctx->chain,n); } } @@ -341,11 +339,13 @@ X509_STORE_CTX *ctx; } if (X509_verify(xs,pkey) <= 0) { + EVP_PKEY_free(pkey); ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE; ctx->current_cert=xs; ok=(*cb)(0,ctx); if (!ok) goto end; } + EVP_PKEY_free(pkey); pkey=NULL; i=X509_cmp_current_time(X509_get_notBefore(xs)); @@ -394,7 +394,7 @@ X509_STORE_CTX *ctx; if (n >= 0) { xi=xs; - xs=(X509 *)sk_value(ctx->chain,n); + xs=sk_X509_value(ctx->chain,n); } } ok=1; @@ -402,8 +402,7 @@ end: return(ok); } -int X509_cmp_current_time(ctm) -ASN1_UTCTIME *ctm; +int X509_cmp_current_time(ASN1_UTCTIME *ctm) { char *str; ASN1_UTCTIME atm; @@ -434,7 +433,7 @@ ASN1_UTCTIME *ctm; offset=((str[1]-'0')*10+(str[2]-'0'))*60; offset+=(str[3]-'0')*10+(str[4]-'0'); if (*str == '-') - offset=-offset; + offset= -offset; } atm.type=V_ASN1_UTCTIME; atm.length=sizeof(buff2); @@ -443,9 +442,9 @@ ASN1_UTCTIME *ctm; X509_gmtime_adj(&atm,-offset); i=(buff1[0]-'0')*10+(buff1[1]-'0'); - if (i < 70) i+=100; + if (i < 50) i+=100; /* cf. RFC 2459 */ j=(buff2[0]-'0')*10+(buff2[1]-'0'); - if (j < 70) j+=100; + if (j < 50) j+=100; if (i < j) return (-1); if (i > j) return (1); @@ -456,9 +455,7 @@ ASN1_UTCTIME *ctm; return(i); } -ASN1_UTCTIME *X509_gmtime_adj(s, adj) -ASN1_UTCTIME *s; -long adj; +ASN1_UTCTIME *X509_gmtime_adj(ASN1_UTCTIME *s, long adj) { time_t t; @@ -467,18 +464,16 @@ long adj; return(ASN1_UTCTIME_set(s,t)); } -int X509_get_pubkey_parameters(pkey,chain) -EVP_PKEY *pkey; -STACK *chain; +int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain) { EVP_PKEY *ktmp=NULL,*ktmp2; int i,j; if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return(1); - for (i=0; i= 0; j--) { - ktmp2=X509_get_pubkey((X509 *)sk_value(chain,j)); + ktmp2=X509_get_pubkey(sk_X509_value(chain,j)); EVP_PKEY_copy_parameters(ktmp2,ktmp); + EVP_PKEY_free(ktmp2); } - if (pkey != NULL) - EVP_PKEY_copy_parameters(pkey,ktmp); + if (pkey != NULL) EVP_PKEY_copy_parameters(pkey,ktmp); + EVP_PKEY_free(ktmp); return(1); } -EVP_PKEY *X509_get_pubkey(x) -X509 *x; - { - if ((x == NULL) || (x->cert_info == NULL)) - return(NULL); - return(X509_PUBKEY_get(x->cert_info->key)); - } - -int X509_check_private_key(x,k) -X509 *x; -EVP_PKEY *k; - { - EVP_PKEY *xk=NULL; - int ok=0; - - xk=X509_get_pubkey(x); - if (xk->type != k->type) goto err; - switch (k->type) - { -#ifndef NO_RSA - case EVP_PKEY_RSA: - if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0) goto err; - if (BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0) goto err; - break; -#endif -#ifndef NO_DSA - case EVP_PKEY_DSA: - if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0) - goto err; - break; -#endif -#ifndef NO_DH - case EVP_PKEY_DH: - /* No idea */ - goto err; -#endif - default: - goto err; - } - - ok=1; -err: - return(ok); - } - -int X509_STORE_add_cert(ctx,x) -X509_STORE *ctx; -X509 *x; +int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) { X509_OBJECT *obj,*r; int ret=1; @@ -591,9 +541,7 @@ X509 *x; return(ret); } -int X509_STORE_add_crl(ctx,x) -X509_STORE *ctx; -X509_CRL *x; +int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) { X509_OBJECT *obj,*r; int ret=1; @@ -628,12 +576,8 @@ X509_CRL *x; return(ret); } -int X509_STORE_CTX_get_ex_new_index(argl,argp,new_func,dup_func,free_func) -long argl; -char *argp; -int (*new_func)(); -int (*dup_func)(); -void (*free_func)(); +int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(), + int (*dup_func)(), void (*free_func)()) { x509_store_ctx_num++; return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1, @@ -641,64 +585,55 @@ void (*free_func)(); argl,argp,new_func,dup_func,free_func)); } -int X509_STORE_CTX_set_ex_data(ctx,idx,data) -X509_STORE_CTX *ctx; -int idx; -char *data; +int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data) { return(CRYPTO_set_ex_data(&ctx->ex_data,idx,data)); } -char *X509_STORE_CTX_get_ex_data(ctx,idx) -X509_STORE_CTX *ctx; -int idx; +void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx) { return(CRYPTO_get_ex_data(&ctx->ex_data,idx)); } -int X509_STORE_CTX_get_error(ctx) -X509_STORE_CTX *ctx; +int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx) { return(ctx->error); } -void X509_STORE_CTX_set_error(ctx,err) -X509_STORE_CTX *ctx; -int err; +void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err) { ctx->error=err; } -int X509_STORE_CTX_get_error_depth(ctx) -X509_STORE_CTX *ctx; +int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx) { return(ctx->error_depth); } -X509 *X509_STORE_CTX_get_current_cert(ctx) -X509_STORE_CTX *ctx; +X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx) { return(ctx->current_cert); } -STACK *X509_STORE_CTX_get_chain(ctx) -X509_STORE_CTX *ctx; +STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx) { return(ctx->chain); } -void X509_STORE_CTX_set_cert(ctx,x) -X509_STORE_CTX *ctx; -X509 *x; +void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x) { ctx->cert=x; } -void X509_STORE_CTX_set_chain(ctx,sk) -X509_STORE_CTX *ctx; -STACK *sk; +void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) { ctx->untrusted=sk; } +IMPLEMENT_STACK_OF(X509) +IMPLEMENT_ASN1_SET_OF(X509) + +IMPLEMENT_STACK_OF(X509_NAME) +IMPLEMENT_STACK_OF(X509_ATTRIBUTE) +IMPLEMENT_ASN1_SET_OF(X509_ATTRIBUTE) diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h index dfc060f899..ecfd4cf9ed 100644 --- a/src/lib/libcrypto/x509/x509_vfy.h +++ b/src/lib/libcrypto/x509/x509_vfy.h @@ -56,6 +56,12 @@ * [including the GNU Public Licence.] */ +#ifndef HEADER_X509_H +#include +/* openssl/x509.h ends up #include-ing this file at about the only + * appropriate moment. */ +#endif + #ifndef HEADER_X509_VFY_H #define HEADER_X509_VFY_H @@ -63,8 +69,8 @@ extern "C" { #endif -#include "bio.h" -#include "crypto.h" +#include +#include /* Outer object */ typedef struct x509_hash_dir_st @@ -119,21 +125,33 @@ typedef struct x509_object_st } data; } X509_OBJECT; +typedef struct x509_lookup_st X509_LOOKUP; + +DECLARE_STACK_OF(X509_LOOKUP) + /* This is a static that defines the function interface */ typedef struct x509_lookup_method_st { - char *name; - int (*new_item)(); - void (*free)(); - int (*init)(/* meth, char ** */); - int (*shutdown)( /* meth, char ** */); - int (*ctrl)( /* meth, char **, int cmd, char *argp, int argi */); - int (*get_by_subject)(/* meth, char **, XNAME *, X509 **ret */); - int (*get_by_issuer_serial)(); - int (*get_by_fingerprint)(); - int (*get_by_alias)(); + const char *name; + int (*new_item)(X509_LOOKUP *ctx); + void (*free)(X509_LOOKUP *ctx); + int (*init)(X509_LOOKUP *ctx); + int (*shutdown)(X509_LOOKUP *ctx); + int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl, + char **ret); + int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name, + X509_OBJECT *ret); + int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name, + ASN1_INTEGER *serial,X509_OBJECT *ret); + int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type, + unsigned char *bytes,int len, + X509_OBJECT *ret); + int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len, + X509_OBJECT *ret); } X509_LOOKUP_METHOD; +typedef struct x509_store_state_st X509_STORE_CTX; + /* This is used to hold everything. It is used for all certificate * validation. Once we have a certificate chain, the 'verify' * function is then called to actually check the cert chain. */ @@ -148,13 +166,13 @@ typedef struct x509_store_st #endif /* These are external lookup methods */ - STACK *get_cert_methods;/* X509_LOOKUP */ - int (*verify)(); /* called to verify a certificate */ - int (*verify_cb)(); /* error callback */ + STACK_OF(X509_LOOKUP) *get_cert_methods; + int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */ + int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */ CRYPTO_EX_DATA ex_data; int references; - int depth; /* how deep to look */ + int depth; /* how deep to look (still unused -- X509_STORE_CTX's depth is used) */ } X509_STORE; #define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d)) @@ -163,7 +181,7 @@ typedef struct x509_store_st #define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func)) /* This is the functions plus an instance of the local variables. */ -typedef struct x509_lookup_st +struct x509_lookup_st { int init; /* have we been started */ int skip; /* don't use us. */ @@ -171,25 +189,25 @@ typedef struct x509_lookup_st char *method_data; /* method data */ X509_STORE *store_ctx; /* who owns us */ - } X509_LOOKUP; + }; /* This is a temporary used when processing cert chains. Since the * gathering of the cert chain can take some time (and have to be * 'retried', this needs to be kept and passed around. */ -typedef struct x509_store_state_st +struct x509_store_state_st /* X509_STORE_CTX */ { X509_STORE *ctx; int current_method; /* used when looking up certs */ /* The following are set by the caller */ X509 *cert; /* The cert to check */ - STACK *untrusted; /* chain of X509s - untrusted - passed in */ + STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */ /* The following is built up */ int depth; /* how far to go looking up certs */ int valid; /* if 0, rebuild chain */ int last_untrusted; /* index of last untrusted cert */ - STACK *chain; /* chain of X509s - built up and trusted */ + STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */ /* When something goes wrong, this is why */ int error_depth; @@ -197,7 +215,9 @@ typedef struct x509_store_state_st X509 *current_cert; CRYPTO_EX_DATA ex_data; - } X509_STORE_CTX; + }; + +#define X509_STORE_CTX_set_depth(ctx,d) ((ctx)->depth=(d)) #define X509_STORE_CTX_set_app_data(ctx,data) \ X509_STORE_CTX_set_ex_data(ctx,0,data) @@ -207,11 +227,9 @@ typedef struct x509_store_state_st #define X509_L_FILE_LOAD 1 #define X509_L_ADD_DIR 2 -X509_LOOKUP_METHOD *X509_LOOKUP_file(); #define X509_LOOKUP_load_file(x,name,type) \ X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) -X509_LOOKUP_METHOD *X509_LOOKUP_dir(); #define X509_LOOKUP_add_dir(x,name,type) \ X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) @@ -243,9 +261,23 @@ X509_LOOKUP_METHOD *X509_LOOKUP_dir(); /* The application is not happy */ #define X509_V_ERR_APPLICATION_VERIFICATION 50 -#ifndef NOPROTO + /* These functions are being redefined in another directory, + and clash when the linker is case-insensitive, so let's + hide them a little, by giving them an extra 'o' at the + beginning of the name... */ +#ifdef VMS +#undef X509v3_cleanup_extensions +#define X509v3_cleanup_extensions oX509v3_cleanup_extensions +#undef X509v3_add_extension +#define X509v3_add_extension oX509v3_add_extension +#undef X509v3_add_netscape_extensions +#define X509v3_add_netscape_extensions oX509v3_add_netscape_extensions +#undef X509v3_add_standard_extensions +#define X509v3_add_standard_extensions oX509v3_add_standard_extensions +#endif + #ifdef HEADER_LHASH_H -X509_OBJECT *X509_OBJECT_retrive_by_subject(LHASH *h,int type,X509_NAME *name); +X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h,int type,X509_NAME *name); #endif void X509_OBJECT_up_ref_count(X509_OBJECT *a); void X509_OBJECT_free_contents(X509_OBJECT *a); @@ -253,7 +285,7 @@ X509_STORE *X509_STORE_new(void ); void X509_STORE_free(X509_STORE *v); void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, - X509 *x509, STACK *chain); + X509 *x509, STACK_OF(X509) *chain); void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); @@ -267,17 +299,14 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name, X509_OBJECT *ret); -int X509_LOOKUP_ctrl(X509_LOOKUP *ctx,int cmd,char *argc,long argl,char **ret); +int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, + long argl, char **ret); #ifndef NO_STDIO -int X509_load_cert_file(X509_LOOKUP *ctx, char *file, int type); -int X509_load_crl_file(X509_LOOKUP *ctx, char *file, int type); +int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type); +int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type); #endif -void X509v3_cleanup_extensions(void ); -int X509v3_add_extension(X509_EXTENSION_METHOD *x); -int X509v3_add_netscape_extensions(void ); -int X509v3_add_standard_extensions(void ); X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); void X509_LOOKUP_free(X509_LOOKUP *ctx); @@ -294,82 +323,21 @@ int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); #ifndef NO_STDIO int X509_STORE_load_locations (X509_STORE *ctx, - char *file, char *dir); + const char *file, const char *dir); int X509_STORE_set_default_paths(X509_STORE *ctx); #endif int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(), int (*dup_func)(), void (*free_func)()); -int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,char *data); -char * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx); +int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data); +void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx); int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s); int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); -STACK * X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); +STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x); -void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK /* X509 */ *sk); - -#else - -#ifdef HEADER_LHASH_H -X509_OBJECT *X509_OBJECT_retrive_by_subject(); -#endif -void X509_OBJECT_up_ref_count(); -void X509_OBJECT_free_contents(); -X509_STORE *X509_STORE_new(); -void X509_STORE_free(); - -void X509_STORE_CTX_init(); -void X509_STORE_CTX_cleanup(); - -X509_LOOKUP *X509_STORE_add_lookup(); - -X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(); -X509_LOOKUP_METHOD *X509_LOOKUP_file(); - -int X509_STORE_add_cert(); -int X509_STORE_add_crl(); - -int X509_STORE_get_by_subject(); - -int X509_LOOKUP_ctrl(); - -#ifndef NO_STDIO -int X509_load_cert_file(); -int X509_load_crl_file(); -#endif - -void X509v3_cleanup_extensions(); -int X509v3_add_extension(); -int X509v3_add_netscape_extensions(); -int X509v3_add_standard_extensions(); - -X509_LOOKUP *X509_LOOKUP_new(); -void X509_LOOKUP_free(); -int X509_LOOKUP_init(); -int X509_LOOKUP_by_subject(); -int X509_LOOKUP_by_issuer_serial(); -int X509_LOOKUP_by_fingerprint(); -int X509_LOOKUP_by_alias(); -int X509_LOOKUP_shutdown(); - -#ifndef NO_STDIO -int X509_STORE_load_locations (); -int X509_STORE_set_default_paths(); -#endif - -int X509_STORE_CTX_set_ex_data(); -char * X509_STORE_CTX_get_ex_data(); -int X509_STORE_CTX_get_error(); -void X509_STORE_CTX_set_error(); -int X509_STORE_CTX_get_error_depth(); -X509 * X509_STORE_CTX_get_current_cert(); -STACK * X509_STORE_CTX_get_chain(); -void X509_STORE_CTX_set_cert(); -void X509_STORE_CTX_set_chain(); - -#endif +void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk); #ifdef __cplusplus } diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c index 650e71b1b5..2a422be350 100644 --- a/src/lib/libcrypto/x509/x509name.c +++ b/src/lib/libcrypto/x509/x509name.c @@ -57,18 +57,14 @@ */ #include -#include "stack.h" +#include #include "cryptlib.h" -#include "asn1.h" -#include "objects.h" -#include "evp.h" -#include "x509.h" +#include +#include +#include +#include -int X509_NAME_get_text_by_NID(name,nid,buf,len) -X509_NAME *name; -int nid; -char *buf; -int len; +int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) { ASN1_OBJECT *obj; @@ -77,11 +73,8 @@ int len; return(X509_NAME_get_text_by_OBJ(name,obj,buf,len)); } -int X509_NAME_get_text_by_OBJ(name,obj,buf,len) -X509_NAME *name; -ASN1_OBJECT *obj; -char *buf; -int len; +int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf, + int len) { int i; ASN1_STRING *data; @@ -96,17 +89,13 @@ int len; return(i); } -int X509_NAME_entry_count(name) -X509_NAME *name; +int X509_NAME_entry_count(X509_NAME *name) { if (name == NULL) return(0); - return(sk_num(name->entries)); + return(sk_X509_NAME_ENTRY_num(name->entries)); } -int X509_NAME_get_index_by_NID(name,nid,lastpos) -X509_NAME *name; -int nid; -int lastpos; +int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos) { ASN1_OBJECT *obj; @@ -116,61 +105,57 @@ int lastpos; } /* NOTE: you should be passsing -1, not 0 as lastpos */ -int X509_NAME_get_index_by_OBJ(name,obj,lastpos) -X509_NAME *name; -ASN1_OBJECT *obj; -int lastpos; +int X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, + int lastpos) { int n; X509_NAME_ENTRY *ne; - STACK *sk; + STACK_OF(X509_NAME_ENTRY) *sk; if (name == NULL) return(-1); if (lastpos < 0) lastpos= -1; sk=name->entries; - n=sk_num(sk); + n=sk_X509_NAME_ENTRY_num(sk); for (lastpos++; lastpos < n; lastpos++) { - ne=(X509_NAME_ENTRY *)sk_value(sk,lastpos); + ne=sk_X509_NAME_ENTRY_value(sk,lastpos); if (OBJ_cmp(ne->object,obj) == 0) return(lastpos); } return(-1); } -X509_NAME_ENTRY *X509_NAME_get_entry(name,loc) -X509_NAME *name; -int loc; +X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc) { - if ( (name == NULL) || (sk_num(name->entries) <= loc) || (loc < 0)) + if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc + || loc < 0) return(NULL); else - return((X509_NAME_ENTRY *)sk_value(name->entries,loc)); + return(sk_X509_NAME_ENTRY_value(name->entries,loc)); } -X509_NAME_ENTRY *X509_NAME_delete_entry(name,loc) -X509_NAME *name; -int loc; +X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc) { X509_NAME_ENTRY *ret; - int i,j,n,set_prev,set_next; - STACK *sk; + int i,n,set_prev,set_next; + STACK_OF(X509_NAME_ENTRY) *sk; - if ((name == NULL) || (sk_num(name->entries) <= loc) || (loc < 0)) + if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc + || loc < 0) return(NULL); sk=name->entries; - ret=(X509_NAME_ENTRY *)sk_delete(sk,loc); - n=sk_num(sk); + ret=sk_X509_NAME_ENTRY_delete(sk,loc); + n=sk_X509_NAME_ENTRY_num(sk); name->modified=1; if (loc == n) return(ret); /* else we need to fixup the set field */ if (loc != 0) - set_prev=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set; + set_prev=(sk_X509_NAME_ENTRY_value(sk,loc-1))->set; else set_prev=ret->set-1; - set_next=((X509_NAME_ENTRY *)sk_value(sk,loc))->set; + set_next=sk_X509_NAME_ENTRY_value(sk,loc)->set; /* set_prev is the previous set * set is the current set @@ -181,29 +166,23 @@ int loc; * so basically only if prev and next differ by 2, then * re-number down by 1 */ if (set_prev+1 < set_next) - { - j=set_next-set_prev-1; for (i=loc; iset-=j; - } + sk_X509_NAME_ENTRY_value(sk,i)->set--; return(ret); } /* if set is -1, append to previous set, 0 'a new one', and 1, * prepend to the guy we are about to stomp on. */ -int X509_NAME_add_entry(name,ne,loc,set) -X509_NAME *name; -X509_NAME_ENTRY *ne; -int loc; -int set; +int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, + int set) { X509_NAME_ENTRY *new_name=NULL; int n,i,inc; - STACK *sk; + STACK_OF(X509_NAME_ENTRY) *sk; if (name == NULL) return(0); sk=name->entries; - n=sk_num(sk); + n=sk_X509_NAME_ENTRY_num(sk); if (loc > n) loc=n; else if (loc < 0) loc=n; @@ -218,7 +197,7 @@ int set; } else { - set=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set; + set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set; inc=0; } } @@ -227,43 +206,38 @@ int set; if (loc >= n) { if (loc != 0) - set=((X509_NAME_ENTRY *) - sk_value(sk,loc-1))->set+1; + set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set+1; else set=0; } else - set=((X509_NAME_ENTRY *)sk_value(sk,loc))->set; + set=sk_X509_NAME_ENTRY_value(sk,loc)->set; inc=(set == 0)?1:0; } if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL) goto err; new_name->set=set; - if (!sk_insert(sk,(char *)new_name,loc)) + if (!sk_X509_NAME_ENTRY_insert(sk,new_name,loc)) { X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE); goto err; } if (inc) { - n=sk_num(sk); + n=sk_X509_NAME_ENTRY_num(sk); for (i=loc+1; iset+=1; + sk_X509_NAME_ENTRY_value(sk,i-1)->set+=1; } return(1); err: if (new_name != NULL) - X509_NAME_ENTRY_free(ne); + X509_NAME_ENTRY_free(new_name); return(0); } -X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(ne,nid,type,bytes,len) -X509_NAME_ENTRY **ne; -int nid; -int type; -unsigned char *bytes; -int len; +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, + int type, unsigned char *bytes, int len) { ASN1_OBJECT *obj; @@ -276,12 +250,8 @@ int len; return(X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len)); } -X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len) -X509_NAME_ENTRY **ne; -ASN1_OBJECT *obj; -int type; -unsigned char *bytes; -int len; +X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, + ASN1_OBJECT *obj, int type, unsigned char *bytes, int len) { X509_NAME_ENTRY *ret; @@ -306,9 +276,7 @@ err: return(NULL); } -int X509_NAME_ENTRY_set_object(ne,obj) -X509_NAME_ENTRY *ne; -ASN1_OBJECT *obj; +int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj) { if ((ne == NULL) || (obj == NULL)) { @@ -320,11 +288,8 @@ ASN1_OBJECT *obj; return((ne->object == NULL)?0:1); } -int X509_NAME_ENTRY_set_data(ne,type,bytes,len) -X509_NAME_ENTRY *ne; -int type; -unsigned char *bytes; -int len; +int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, + unsigned char *bytes, int len) { int i; @@ -342,15 +307,13 @@ int len; return(1); } -ASN1_OBJECT *X509_NAME_ENTRY_get_object(ne) -X509_NAME_ENTRY *ne; +ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne) { if (ne == NULL) return(NULL); return(ne->object); } -ASN1_STRING *X509_NAME_ENTRY_get_data(ne) -X509_NAME_ENTRY *ne; +ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne) { if (ne == NULL) return(NULL); return(ne->value); diff --git a/src/lib/libcrypto/x509/x509pack.c b/src/lib/libcrypto/x509/x509pack.c deleted file mode 100644 index 846f125859..0000000000 --- a/src/lib/libcrypto/x509/x509pack.c +++ /dev/null @@ -1,157 +0,0 @@ -/* crypto/x509/x509pack.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include "stack.h" -#include "cryptlib.h" -#include "asn1.h" -#include "objects.h" -#include "evp.h" -#include "x509.h" - -ASN1_OCTET_STRING *X509v3_pack_string(ex,type,bytes,len) -ASN1_OCTET_STRING **ex; -int type; -unsigned char *bytes; -int len; - { - ASN1_OCTET_STRING *os; - ASN1_STRING str; - unsigned char *p; - int i; - - if ((ex == NULL) || (*ex == NULL)) - os=ASN1_OCTET_STRING_new(); - else - os= *ex; - - if (len < 0) len=strlen((char *)bytes); - str.length=len; - str.type=type; - str.data=bytes; - - /* str now holds the data, we just have to copy it into ->value */ - - switch (type) - { - case V_ASN1_BIT_STRING: - i=i2d_ASN1_BIT_STRING((ASN1_BIT_STRING *)&str,NULL); - if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i)) - goto err; - p=(unsigned char *)os->data; - i2d_ASN1_BIT_STRING((ASN1_BIT_STRING *)&str,&p); - break; - case V_ASN1_OCTET_STRING: - i=i2d_ASN1_OCTET_STRING((ASN1_OCTET_STRING *)&str,NULL); - if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i)) - goto err; - p=(unsigned char *)os->data; - i2d_ASN1_OCTET_STRING((ASN1_OCTET_STRING *)&str,&p); - break; - case V_ASN1_IA5STRING: - case V_ASN1_PRINTABLESTRING: - case V_ASN1_T61STRING: - i=i2d_ASN1_bytes(&str,NULL,type,V_ASN1_UNIVERSAL); - if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i)) - goto err; - p=(unsigned char *)os->data; - i=i2d_ASN1_bytes(&str,&p,type,V_ASN1_UNIVERSAL); - break; - default: - X509err(X509_F_X509V3_PACK_STRING,X509_R_UNKNOWN_STRING_TYPE); - goto err; - } - os->length=i; - - if ((ex != NULL) && (os != *ex)) - *ex=os; - return(os); -err: - return(NULL); - } - -ASN1_STRING *X509v3_unpack_string(ex,type,os) -ASN1_STRING **ex; -int type; -ASN1_OCTET_STRING *os; - { - unsigned char *p; - ASN1_STRING *ret=NULL; - - p=os->data; - switch (type) - { - case V_ASN1_BIT_STRING: - ret=(ASN1_STRING *)d2i_ASN1_BIT_STRING( - (ASN1_BIT_STRING **)ex,&p,os->length); - break; - case V_ASN1_OCTET_STRING: - ret=(ASN1_STRING *)d2i_ASN1_OCTET_STRING( - (ASN1_BIT_STRING **)ex,&p,os->length); - break; - case V_ASN1_IA5STRING: - case V_ASN1_PRINTABLESTRING: - case V_ASN1_T61STRING: - ret=(ASN1_STRING *)d2i_ASN1_PRINTABLE(ex,&p,os->length); - break; - default: - X509err(X509_F_X509V3_UNPACK_STRING,X509_R_UNKNOWN_STRING_TYPE); - } - return(ret); - } - diff --git a/src/lib/libcrypto/x509/x509rset.c b/src/lib/libcrypto/x509/x509rset.c index 323b25470a..d9f6b57372 100644 --- a/src/lib/libcrypto/x509/x509rset.c +++ b/src/lib/libcrypto/x509/x509rset.c @@ -58,30 +58,24 @@ #include #include "cryptlib.h" -#include "asn1.h" -#include "objects.h" -#include "evp.h" -#include "x509.h" +#include +#include +#include +#include -int X509_REQ_set_version(x,version) -X509_REQ *x; -long version; +int X509_REQ_set_version(X509_REQ *x, long version) { if (x == NULL) return(0); return(ASN1_INTEGER_set(x->req_info->version,version)); } -int X509_REQ_set_subject_name(x,name) -X509_REQ *x; -X509_NAME *name; +int X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name) { if ((x == NULL) || (x->req_info == NULL)) return(0); return(X509_NAME_set(&x->req_info->subject,name)); } -int X509_REQ_set_pubkey(x,pkey) -X509_REQ *x; -EVP_PKEY *pkey; +int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) { if ((x == NULL) || (x->req_info == NULL)) return(0); return(X509_PUBKEY_set(&x->req_info->pubkey,pkey)); diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c index 42c23bcfca..8e78b34458 100644 --- a/src/lib/libcrypto/x509/x509type.c +++ b/src/lib/libcrypto/x509/x509type.c @@ -58,13 +58,11 @@ #include #include "cryptlib.h" -#include "evp.h" -#include "objects.h" -#include "x509.h" +#include +#include +#include -int X509_certificate_type(x,pkey) -X509 *x; -EVP_PKEY *pkey; +int X509_certificate_type(X509 *x, EVP_PKEY *pkey) { EVP_PKEY *pk; int ret=0,i; @@ -108,8 +106,9 @@ EVP_PKEY *pkey; break; } - if (EVP_PKEY_size(pkey) <= 512) + if (EVP_PKEY_size(pk) <= 512) ret|=EVP_PKT_EXP; + if(pkey==NULL) EVP_PKEY_free(pk); return(ret); } diff --git a/src/lib/libcrypto/x509/x509v3.doc b/src/lib/libcrypto/x509/x509v3.doc deleted file mode 100644 index 1e760a9469..0000000000 --- a/src/lib/libcrypto/x509/x509v3.doc +++ /dev/null @@ -1,24 +0,0 @@ -The 'new' system. - -The X509_EXTENSION_METHOD includes extensions and attributes and/or names. -Basically everthing that can be added to an X509 with an OID identifying it. - -It operates via 2 methods per object id. -int a2i_XXX(X509 *x,char *str,int len); -int i2a_XXX(BIO *bp,X509 *x); - -The a2i_XXX function will add the object with a value converted from the -string into the X509. Len can be -1 in which case the length is calculated -via strlen(str). Applications can always use direct knowledge to load and -unload the relevent objects themselves. - -i2a_XXX will print to the passed BIO, a text representation of the -relevet object. Use a memory BIO if you want it printed to a buffer :-). - -X509_add_by_NID(X509 *x,int nid,char *str,int len); -X509_add_by_OBJ(X509 *x,ASN1_OBJECT *obj,char *str,int len); - -X509_print_by_name(BIO *bp,X509 *x); -X509_print_by_NID(BIO *bp,X509 *x); -X509_print_by_OBJ(BIO *bp,X509 *x); - diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c index b7dde23e9a..f2af895df0 100644 --- a/src/lib/libcrypto/x509/x_all.c +++ b/src/lib/libcrypto/x509/x_all.c @@ -58,90 +58,74 @@ #include #undef SSLEAY_MACROS -#include "stack.h" +#include #include "cryptlib.h" -#include "buffer.h" -#include "asn1.h" -#include "evp.h" -#include "x509.h" +#include +#include +#include +#include -int X509_verify(a,r) -X509 *a; -EVP_PKEY *r; +int X509_verify(X509 *a, EVP_PKEY *r) { return(ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg, a->signature,(char *)a->cert_info,r)); } -int X509_REQ_verify(a,r) -X509_REQ *a; -EVP_PKEY *r; +int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r) { return( ASN1_verify((int (*)())i2d_X509_REQ_INFO, a->sig_alg,a->signature,(char *)a->req_info,r)); } -int X509_CRL_verify(a,r) -X509_CRL *a; -EVP_PKEY *r; +int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r) { return(ASN1_verify((int (*)())i2d_X509_CRL_INFO, a->sig_alg, a->signature,(char *)a->crl,r)); } -int NETSCAPE_SPKI_verify(a,r) -NETSCAPE_SPKI *a; -EVP_PKEY *r; +int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r) { return(ASN1_verify((int (*)())i2d_NETSCAPE_SPKAC, a->sig_algor,a->signature, (char *)a->spkac,r)); } -int X509_sign(x,pkey,md) -X509 *x; -EVP_PKEY *pkey; -EVP_MD *md; +int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) { return(ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)); } -int X509_REQ_sign(x,pkey,md) -X509_REQ *x; -EVP_PKEY *pkey; -EVP_MD *md; +int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) { return(ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, x->signature, (char *)x->req_info,pkey,md)); } -int X509_CRL_sign(x,pkey,md) -X509_CRL *x; -EVP_PKEY *pkey; -EVP_MD *md; +int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) { return(ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg, x->sig_alg, x->signature, (char *)x->crl,pkey,md)); } -int NETSCAPE_SPKI_sign(x,pkey,md) -NETSCAPE_SPKI *x; -EVP_PKEY *pkey; -EVP_MD *md; +int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) { return(ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, x->signature, (char *)x->spkac,pkey,md)); } -X509 *X509_dup(x509) -X509 *x509; +X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa) + { + return((X509_ATTRIBUTE *)ASN1_dup((int (*)())i2d_X509_ATTRIBUTE, + (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)); + } + +X509 *X509_dup(X509 *x509) { return((X509 *)ASN1_dup((int (*)())i2d_X509, (char *(*)())d2i_X509,(char *)x509)); } -X509_EXTENSION *X509_EXTENSION_dup(ex) -X509_EXTENSION *ex; +X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex) { return((X509_EXTENSION *)ASN1_dup( (int (*)())i2d_X509_EXTENSION, @@ -149,237 +133,184 @@ X509_EXTENSION *ex; } #ifndef NO_FP_API -X509 *d2i_X509_fp(fp,x509) -FILE *fp; -X509 *x509; +X509 *d2i_X509_fp(FILE *fp, X509 **x509) { return((X509 *)ASN1_d2i_fp((char *(*)())X509_new, (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))); } -int i2d_X509_fp(fp,x509) -FILE *fp; -X509 *x509; +int i2d_X509_fp(FILE *fp, X509 *x509) { return(ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)); } #endif -X509 *d2i_X509_bio(bp,x509) -BIO *bp; -X509 *x509; +X509 *d2i_X509_bio(BIO *bp, X509 **x509) { return((X509 *)ASN1_d2i_bio((char *(*)())X509_new, (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))); } -int i2d_X509_bio(bp,x509) -BIO *bp; -X509 *x509; +int i2d_X509_bio(BIO *bp, X509 *x509) { return(ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)); } -X509_CRL *X509_CRL_dup(crl) -X509_CRL *crl; +X509_CRL *X509_CRL_dup(X509_CRL *crl) { return((X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, (char *(*)())d2i_X509_CRL,(char *)crl)); } #ifndef NO_FP_API -X509_CRL *d2i_X509_CRL_fp(fp,crl) -FILE *fp; -X509_CRL *crl; +X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) { return((X509_CRL *)ASN1_d2i_fp((char *(*)()) X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp), (unsigned char **)(crl))); } -int i2d_X509_CRL_fp(fp,crl) -FILE *fp; -X509_CRL *crl; +int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl) { return(ASN1_i2d_fp(i2d_X509_CRL,fp,(unsigned char *)crl)); } #endif -X509_CRL *d2i_X509_CRL_bio(bp,crl) -BIO *bp; -X509_CRL *crl; +X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) { return((X509_CRL *)ASN1_d2i_bio((char *(*)()) X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp), (unsigned char **)(crl))); } -int i2d_X509_CRL_bio(bp,crl) -BIO *bp; -X509_CRL *crl; +int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl) { return(ASN1_i2d_bio(i2d_X509_CRL,bp,(unsigned char *)crl)); } -PKCS7 *PKCS7_dup(p7) -PKCS7 *p7; +PKCS7 *PKCS7_dup(PKCS7 *p7) { return((PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, (char *(*)())d2i_PKCS7,(char *)p7)); } #ifndef NO_FP_API -PKCS7 *d2i_PKCS7_fp(fp,p7) -FILE *fp; -PKCS7 *p7; +PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7) { return((PKCS7 *)ASN1_d2i_fp((char *(*)()) PKCS7_new,(char *(*)())d2i_PKCS7, (fp), (unsigned char **)(p7))); } -int i2d_PKCS7_fp(fp,p7) -FILE *fp; -PKCS7 *p7; +int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7) { return(ASN1_i2d_fp(i2d_PKCS7,fp,(unsigned char *)p7)); } #endif -PKCS7 *d2i_PKCS7_bio(bp,p7) -BIO *bp; -PKCS7 *p7; +PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7) { return((PKCS7 *)ASN1_d2i_bio((char *(*)()) PKCS7_new,(char *(*)())d2i_PKCS7, (bp), (unsigned char **)(p7))); } -int i2d_PKCS7_bio(bp,p7) -BIO *bp; -PKCS7 *p7; +int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7) { return(ASN1_i2d_bio(i2d_PKCS7,bp,(unsigned char *)p7)); } -X509_REQ *X509_REQ_dup(req) -X509_REQ *req; +X509_REQ *X509_REQ_dup(X509_REQ *req) { return((X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, (char *(*)())d2i_X509_REQ,(char *)req)); } #ifndef NO_FP_API -X509_REQ *d2i_X509_REQ_fp(fp,req) -FILE *fp; -X509_REQ *req; +X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) { return((X509_REQ *)ASN1_d2i_fp((char *(*)()) X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp), (unsigned char **)(req))); } -int i2d_X509_REQ_fp(fp,req) -FILE *fp; -X509_REQ *req; +int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req) { return(ASN1_i2d_fp(i2d_X509_REQ,fp,(unsigned char *)req)); } #endif -X509_REQ *d2i_X509_REQ_bio(bp,req) -BIO *bp; -X509_REQ *req; +X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) { return((X509_REQ *)ASN1_d2i_bio((char *(*)()) X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp), (unsigned char **)(req))); } -int i2d_X509_REQ_bio(bp,req) -BIO *bp; -X509_REQ *req; +int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req) { return(ASN1_i2d_bio(i2d_X509_REQ,bp,(unsigned char *)req)); } #ifndef NO_RSA -RSA *RSAPublicKey_dup(rsa) -RSA *rsa; +RSA *RSAPublicKey_dup(RSA *rsa) { return((RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, (char *(*)())d2i_RSAPublicKey,(char *)rsa)); } -RSA *RSAPrivateKey_dup(rsa) -RSA *rsa; +RSA *RSAPrivateKey_dup(RSA *rsa) { return((RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, (char *(*)())d2i_RSAPrivateKey,(char *)rsa)); } #ifndef NO_FP_API -RSA *d2i_RSAPrivateKey_fp(fp,rsa) -FILE *fp; -RSA *rsa; +RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa) { return((RSA *)ASN1_d2i_fp((char *(*)()) RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), (unsigned char **)(rsa))); } -int i2d_RSAPrivateKey_fp(fp,rsa) -FILE *fp; -RSA *rsa; +int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa) { return(ASN1_i2d_fp(i2d_RSAPrivateKey,fp,(unsigned char *)rsa)); } -RSA *d2i_RSAPublicKey_fp(fp,rsa) -FILE *fp; -RSA *rsa; +RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa) { return((RSA *)ASN1_d2i_fp((char *(*)()) RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), (unsigned char **)(rsa))); } -int i2d_RSAPublicKey_fp(fp,rsa) -FILE *fp; -RSA *rsa; +int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) { return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa)); } #endif -RSA *d2i_RSAPrivateKey_bio(bp,rsa) -BIO *bp; -RSA *rsa; +RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) { return((RSA *)ASN1_d2i_bio((char *(*)()) RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), (unsigned char **)(rsa))); } -int i2d_RSAPrivateKey_bio(bp,rsa) -BIO *bp; -RSA *rsa; +int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa) { return(ASN1_i2d_bio(i2d_RSAPrivateKey,bp,(unsigned char *)rsa)); } -RSA *d2i_RSAPublicKey_bio(bp,rsa) -BIO *bp; -RSA *rsa; +RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa) { return((RSA *)ASN1_d2i_bio((char *(*)()) RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), (unsigned char **)(rsa))); } -int i2d_RSAPublicKey_bio(bp,rsa) -BIO *bp; -RSA *rsa; +int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) { return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa)); } @@ -387,79 +318,120 @@ RSA *rsa; #ifndef NO_DSA #ifndef NO_FP_API -DSA *d2i_DSAPrivateKey_fp(fp,dsa) -FILE *fp; -DSA *dsa; +DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) { return((DSA *)ASN1_d2i_fp((char *(*)()) DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), (unsigned char **)(dsa))); } -int i2d_DSAPrivateKey_fp(fp,dsa) -FILE *fp; -DSA *dsa; +int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa) { return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa)); } #endif -DSA *d2i_DSAPrivateKey_bio(bp,dsa) -BIO *bp; -DSA *dsa; +DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) { return((DSA *)ASN1_d2i_bio((char *(*)()) DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), (unsigned char **)(dsa))); } -int i2d_DSAPrivateKey_bio(bp,dsa) -BIO *bp; -DSA *dsa; +int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa) { return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa)); } #endif -X509_NAME *X509_NAME_dup(xn) -X509_NAME *xn; +X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn) + { + return((X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR, + (char *(*)())d2i_X509_ALGOR,(char *)xn)); + } + +X509_NAME *X509_NAME_dup(X509_NAME *xn) { return((X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, (char *(*)())d2i_X509_NAME,(char *)xn)); } -X509_NAME_ENTRY *X509_NAME_ENTRY_dup(ne) -X509_NAME_ENTRY *ne; +X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne) { return((X509_NAME_ENTRY *)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY, (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne)); } -int X509_digest(data,type,md,len) -X509 *data; -EVP_MD *type; -unsigned char *md; -unsigned int *len; +int X509_digest(X509 *data, EVP_MD *type, unsigned char *md, + unsigned int *len) { return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)); } -int X509_NAME_digest(data,type,md,len) -X509_NAME *data; -EVP_MD *type; -unsigned char *md; -unsigned int *len; +int X509_NAME_digest(X509_NAME *data, EVP_MD *type, unsigned char *md, + unsigned int *len) { return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)); } -int PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) -PKCS7_ISSUER_AND_SERIAL *data; -EVP_MD *type; -unsigned char *md; -unsigned int *len; +int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, EVP_MD *type, + unsigned char *md, unsigned int *len) { return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type, (char *)data,md,len)); } + +#ifndef NO_FP_API +X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) + { + return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new, + (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8))); + } + +int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8) + { + return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8)); + } +#endif + +X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) + { + return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new, + (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8))); + } + +int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8) + { + return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8)); + } + +#ifndef NO_FP_API +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, + PKCS8_PRIV_KEY_INFO **p8inf) + { + return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp( + (char *(*)())PKCS8_PRIV_KEY_INFO_new, + (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp), + (unsigned char **)(p8inf))); + } + +int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf) + { + return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf)); + } +#endif + +PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, + PKCS8_PRIV_KEY_INFO **p8inf) + { + return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio( + (char *(*)())PKCS8_PRIV_KEY_INFO_new, + (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp), + (unsigned char **)(p8inf))); + } + +int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf) + { + return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf)); + } diff --git a/src/lib/libcrypto/x509v3/Makefile.ssl b/src/lib/libcrypto/x509v3/Makefile.ssl new file mode 100644 index 0000000000..57006e6875 --- /dev/null +++ b/src/lib/libcrypto/x509v3/Makefile.ssl @@ -0,0 +1,432 @@ +# +# SSLeay/crypto/x509v3/Makefile +# + +DIR= x509v3 +TOP= ../.. +CC= cc +INCLUDES= -I.. -I../../include +CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl +INSTALLTOP=/usr/local/ssl +MAKE= make -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) +MAKEFILE= Makefile.ssl +AR= ar r + +CFLAGS= $(INCLUDES) $(CFLAG) + +GENERAL=Makefile README +TEST= +APPS= + +LIB=$(TOP)/libcrypto.a +LIBSRC= v3_bcons.c v3_bitst.c v3_conf.c v3_extku.c v3_ia5.c \ +v3_lib.c v3_prn.c v3_utl.c v3err.c v3_genn.c v3_alt.c v3_skey.c v3_akey.c \ +v3_pku.c v3_int.c v3_enum.c v3_sxnet.c v3_cpols.c v3_crld.c +LIBOBJ= v3_bcons.o v3_bitst.o v3_conf.o v3_extku.o v3_ia5.o v3_lib.o \ +v3_prn.o v3_utl.o v3err.o v3_genn.o v3_alt.o v3_skey.o v3_akey.o v3_pku.o \ +v3_int.o v3_enum.o v3_sxnet.o v3_cpols.o v3_crld.o + +SRC= $(LIBSRC) + +EXHEADER= x509v3.h +HEADER= $(EXHEADER) + +ALL= $(GENERAL) $(SRC) $(HEADER) + +top: + (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) + +all: lib + +lib: $(LIBOBJ) + $(AR) $(LIB) $(LIBOBJ) + $(RANLIB) $(LIB) + @touch lib + +files: + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + +links: + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) + +install: + @for i in $(EXHEADER) ; \ + do \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ + done; + +tags: + ctags $(SRC) + +tests: + +lint: + lint -DLINT $(INCLUDES) $(SRC)>fluff + +depend: + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) + +dclean: + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + mv -f Makefile.new $(MAKEFILE) + +clean: + rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff + +# DO NOT DELETE THIS LINE -- make depend depends on it. + +v3_akey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +v3_akey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +v3_akey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +v3_akey.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +v3_akey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +v3_akey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +v3_akey.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +v3_akey.o: ../../include/openssl/err.h ../../include/openssl/evp.h +v3_akey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +v3_akey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +v3_akey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +v3_akey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +v3_akey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +v3_akey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +v3_akey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +v3_akey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +v3_akey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +v3_akey.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +v3_akey.o: ../cryptlib.h +v3_alt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_alt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_alt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_alt.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_alt.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_alt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_alt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_alt.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_alt.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_alt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_alt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_alt.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_alt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_alt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_alt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_alt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_alt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_alt.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_bcons.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +v3_bcons.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +v3_bcons.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +v3_bcons.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +v3_bcons.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +v3_bcons.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +v3_bcons.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +v3_bcons.o: ../../include/openssl/err.h ../../include/openssl/evp.h +v3_bcons.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +v3_bcons.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +v3_bcons.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +v3_bcons.o: ../../include/openssl/opensslconf.h +v3_bcons.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_bcons.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_bcons.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_bcons.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_bcons.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_bcons.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_bcons.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_bitst.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_bitst.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_bitst.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_bitst.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_bitst.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_bitst.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_bitst.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_bitst.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_bitst.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_bitst.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_bitst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_bitst.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_bitst.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_conf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_conf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_conf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_conf.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_conf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_conf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_conf.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_conf.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_conf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_conf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_conf.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_conf.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_conf.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_conf.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_conf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_conf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_conf.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_cpols.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +v3_cpols.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +v3_cpols.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +v3_cpols.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +v3_cpols.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +v3_cpols.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +v3_cpols.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +v3_cpols.o: ../../include/openssl/err.h ../../include/openssl/evp.h +v3_cpols.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +v3_cpols.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +v3_cpols.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +v3_cpols.o: ../../include/openssl/opensslconf.h +v3_cpols.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_cpols.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_cpols.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_cpols.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_cpols.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_cpols.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_cpols.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_crld.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +v3_crld.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +v3_crld.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +v3_crld.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +v3_crld.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +v3_crld.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +v3_crld.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +v3_crld.o: ../../include/openssl/err.h ../../include/openssl/evp.h +v3_crld.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +v3_crld.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +v3_crld.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +v3_crld.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +v3_crld.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +v3_crld.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +v3_crld.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +v3_crld.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +v3_crld.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +v3_crld.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +v3_crld.o: ../cryptlib.h +v3_enum.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_enum.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_enum.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_enum.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_enum.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_enum.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_enum.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_enum.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_enum.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_enum.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_enum.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_enum.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_enum.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_enum.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_enum.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_enum.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_enum.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_extku.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_extku.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_extku.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_extku.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_extku.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_extku.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_extku.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_extku.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_extku.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_extku.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_extku.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_extku.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_extku.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_extku.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_extku.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_extku.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_extku.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_extku.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_genn.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +v3_genn.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +v3_genn.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +v3_genn.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +v3_genn.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +v3_genn.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +v3_genn.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +v3_genn.o: ../../include/openssl/err.h ../../include/openssl/evp.h +v3_genn.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +v3_genn.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +v3_genn.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +v3_genn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +v3_genn.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +v3_genn.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +v3_genn.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +v3_genn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +v3_genn.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +v3_genn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +v3_genn.o: ../cryptlib.h +v3_ia5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_ia5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_ia5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_ia5.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_ia5.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_ia5.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_ia5.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_ia5.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_ia5.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_ia5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_ia5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_ia5.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_ia5.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_ia5.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_ia5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_ia5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_ia5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_ia5.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_int.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_int.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_int.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_int.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_int.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_int.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_int.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_int.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_int.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_int.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_int.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_int.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_int.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_int.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_int.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_int.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_int.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_lib.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_lib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_pku.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +v3_pku.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +v3_pku.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +v3_pku.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +v3_pku.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +v3_pku.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +v3_pku.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +v3_pku.o: ../../include/openssl/err.h ../../include/openssl/evp.h +v3_pku.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +v3_pku.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +v3_pku.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +v3_pku.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h +v3_pku.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h +v3_pku.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h +v3_pku.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h +v3_pku.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h +v3_pku.o: ../../include/openssl/stack.h ../../include/openssl/x509.h +v3_pku.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h +v3_pku.o: ../cryptlib.h +v3_prn.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_prn.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_prn.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_prn.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_prn.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_prn.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_prn.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_prn.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_prn.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_prn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_prn.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_prn.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_prn.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_prn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_prn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_prn.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_skey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_skey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_skey.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_skey.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_skey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_skey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_skey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_skey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_skey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_skey.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_skey.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_skey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_skey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_skey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_skey.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_sxnet.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h +v3_sxnet.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h +v3_sxnet.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h +v3_sxnet.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +v3_sxnet.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +v3_sxnet.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +v3_sxnet.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h +v3_sxnet.o: ../../include/openssl/err.h ../../include/openssl/evp.h +v3_sxnet.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h +v3_sxnet.o: ../../include/openssl/md2.h ../../include/openssl/md5.h +v3_sxnet.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h +v3_sxnet.o: ../../include/openssl/opensslconf.h +v3_sxnet.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_sxnet.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_sxnet.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_sxnet.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_sxnet.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_sxnet.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_sxnet.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3_utl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3_utl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3_utl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h +v3_utl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h +v3_utl.o: ../../include/openssl/des.h ../../include/openssl/dh.h +v3_utl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h +v3_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3_utl.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3_utl.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3_utl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3_utl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3_utl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3_utl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3_utl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3_utl.o: ../../include/openssl/x509v3.h ../cryptlib.h +v3err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h +v3err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h +v3err.o: ../../include/openssl/cast.h ../../include/openssl/conf.h +v3err.o: ../../include/openssl/crypto.h ../../include/openssl/des.h +v3err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h +v3err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h +v3err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h +v3err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h +v3err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h +v3err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h +v3err.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h +v3err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h +v3err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h +v3err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h +v3err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h +v3err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h +v3err.o: ../../include/openssl/x509v3.h diff --git a/src/lib/libcrypto/x509v3/README b/src/lib/libcrypto/x509v3/README new file mode 100644 index 0000000000..3b2cc047be --- /dev/null +++ b/src/lib/libcrypto/x509v3/README @@ -0,0 +1,4 @@ +WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING + +This is ***VERY*** new experimental code and is likely to change +considerably or vanish altogether. diff --git a/src/lib/libcrypto/x509v3/format b/src/lib/libcrypto/x509v3/format deleted file mode 100644 index 3307978121..0000000000 --- a/src/lib/libcrypto/x509v3/format +++ /dev/null @@ -1,92 +0,0 @@ -AuthorityKeyIdentifier - { - keyIdentifier [0] OCTET_STRING OPTIONAL - authorityCertIssuer [1] GeneralNames OPTIONAL - authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL - } - -SubjectKeyIdentifier OCTET_STRING - -KeyUsage - { - BIT_STRING - digitalSignature 0 - nonRepudiation 1 - keyEncipherment 2 - dataEncipherment 3 - keyAgreement 4 - keyCertSign 5 - cRLSign 6 - encipherOnly 7 - decipherOnly 8 - } - -extKeyUsage - { - SEQUENCE of OBJECT_IDENTIFIER - } - -privateKeyUsagePeriod - { - notBefore [0] GeneralizedTime OPTIONAL - notAfter [1] GeneralizedTime OPTIONAL - } - -certificatePoliciesSyntax - SEQUENCE of PoliciesInformation - -PoliciesInformation XXX -policyMappings XXX -supportedAlgorithms XXX - -subjectAltName - GeneralNames sequence of GeneralName - -GeneralName - { - otherName [0] INSTANCE OF OTHER-NAME - rfc882Name [1] IA5String - dNSName [2] IA5String - x400Address [3] ORAddress - directoryName [4] Name - ediPartyName [5] - { - nameAssigner [0] DirectoryString OPTIONAL - partyName [1] DirectoryString - } - uniformResourceIdentifier [6] IA5String - iPAddress [7] OCTET_STRING - registeredID [8] OBJECT_IDENTIFIER - } - -issuerAltName - GeneralNames sequence of GeneralName - -subjectDirectoryAttribute SEQUENCE of Attribute - -basicConstraints - { - cA BOOLEAN default FALSE - pathLenConstraint INTEGER OPTIONAL - } - -nameConstraints - { - permittedSubtrees [0] sequence of GeneralSubtree OPTIONAL - excludedSubtrees [1] sequence of GeneralSubtree OPTIONAL - } - -GeneralSubtree - { - base GeneralName - minimum [0] BaseDistance DEFAULT 0 - maximum [1] BaseDistance OPTIONAL - } - -PolicyConstraints - { - requiredExplicitPolicy [0] SkipCerts OPTIONAL - inhibitPolicyMapping [1] SkipCerts OPTIONAL - } -SkipCerts == INTEGER - diff --git a/src/lib/libcrypto/x509v3/header b/src/lib/libcrypto/x509v3/header deleted file mode 100644 index 3d791ca3dd..0000000000 --- a/src/lib/libcrypto/x509v3/header +++ /dev/null @@ -1,6 +0,0 @@ -int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size) -int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) -int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp) -ASN1_INTEGER * d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,long length) - - diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c new file mode 100644 index 0000000000..4099e6019e --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_akey.c @@ -0,0 +1,249 @@ +/* v3_akey.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include +#include +#include + +static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, + AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist); +static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values); + +X509V3_EXT_METHOD v3_akey_id = { +NID_authority_key_identifier, X509V3_EXT_MULTILINE, +(X509V3_EXT_NEW)AUTHORITY_KEYID_new, +(X509V3_EXT_FREE)AUTHORITY_KEYID_free, +(X509V3_EXT_D2I)d2i_AUTHORITY_KEYID, +(X509V3_EXT_I2D)i2d_AUTHORITY_KEYID, +NULL, NULL, +(X509V3_EXT_I2V)i2v_AUTHORITY_KEYID, +(X509V3_EXT_V2I)v2i_AUTHORITY_KEYID, +NULL,NULL, +NULL +}; + + +int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len_IMP_opt (a->keyid, i2d_ASN1_OCTET_STRING); + M_ASN1_I2D_len_IMP_opt (a->issuer, i2d_GENERAL_NAMES); + M_ASN1_I2D_len_IMP_opt (a->serial, i2d_ASN1_INTEGER); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put_IMP_opt (a->keyid, i2d_ASN1_OCTET_STRING, 0); + M_ASN1_I2D_put_IMP_opt (a->issuer, i2d_GENERAL_NAMES, 1); + M_ASN1_I2D_put_IMP_opt (a->serial, i2d_ASN1_INTEGER, 2); + + M_ASN1_I2D_finish(); +} + +AUTHORITY_KEYID *AUTHORITY_KEYID_new(void) +{ + AUTHORITY_KEYID *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, AUTHORITY_KEYID); + ret->keyid = NULL; + ret->issuer = NULL; + ret->serial = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_AUTHORITY_KEYID_NEW); +} + +AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp, + long length) +{ + M_ASN1_D2I_vars(a,AUTHORITY_KEYID *,AUTHORITY_KEYID_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get_IMP_opt (ret->keyid, d2i_ASN1_OCTET_STRING, 0, + V_ASN1_OCTET_STRING); + M_ASN1_D2I_get_IMP_opt (ret->issuer, d2i_GENERAL_NAMES, 1, + V_ASN1_SEQUENCE); + M_ASN1_D2I_get_IMP_opt (ret->serial, d2i_ASN1_INTEGER, 2, + V_ASN1_INTEGER); + M_ASN1_D2I_Finish(a, AUTHORITY_KEYID_free, ASN1_F_D2I_AUTHORITY_KEYID); +} + +void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a) +{ + if (a == NULL) return; + ASN1_OCTET_STRING_free(a->keyid); + sk_GENERAL_NAME_pop_free(a->issuer, GENERAL_NAME_free); + ASN1_INTEGER_free (a->serial); + Free ((char *)a); +} + +static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, + AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist) +{ + char *tmp; + if(akeyid->keyid) { + tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length); + X509V3_add_value("keyid", tmp, &extlist); + Free(tmp); + } + if(akeyid->issuer) + extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist); + if(akeyid->serial) { + tmp = hex_to_string(akeyid->serial->data, + akeyid->serial->length); + X509V3_add_value("serial", tmp, &extlist); + Free(tmp); + } + return extlist; +} + +/* Currently two options: + * keyid: use the issuers subject keyid, the value 'always' means its is + * an error if the issuer certificate doesn't have a key id. + * issuer: use the issuers cert issuer and serial number. The default is + * to only use this if keyid is not present. With the option 'always' + * this is always included. + */ + +static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values) +{ +char keyid=0, issuer=0; +int i; +CONF_VALUE *cnf; +ASN1_OCTET_STRING *ikeyid = NULL; +X509_NAME *isname = NULL; +STACK_OF(GENERAL_NAME) * gens = NULL; +GENERAL_NAME *gen = NULL; +ASN1_INTEGER *serial = NULL; +X509_EXTENSION *ext; +X509 *cert; +AUTHORITY_KEYID *akeyid; +for(i = 0; i < sk_CONF_VALUE_num(values); i++) { + cnf = sk_CONF_VALUE_value(values, i); + if(!strcmp(cnf->name, "keyid")) { + keyid = 1; + if(cnf->value && !strcmp(cnf->value, "always")) keyid = 2; + } else if(!strcmp(cnf->name, "issuer")) { + issuer = 1; + if(cnf->value && !strcmp(cnf->value, "always")) issuer = 2; + } else { + X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION); + ERR_add_error_data(2, "name=", cnf->name); + return NULL; + } +} + + + +if(!ctx || !ctx->issuer_cert) { + if(ctx && (ctx->flags==CTX_TEST)) return AUTHORITY_KEYID_new(); + X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE); + return NULL; +} + +cert = ctx->issuer_cert; + +if(keyid) { + i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1); + if((i >= 0) && (ext = X509_get_ext(cert, i))) + ikeyid = X509V3_EXT_d2i(ext); + if(keyid==2 && !ikeyid) { + X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID); + return NULL; + } +} + +if((issuer && !ikeyid) || (issuer == 2)) { + isname = X509_NAME_dup(X509_get_issuer_name(cert)); + serial = ASN1_INTEGER_dup(X509_get_serialNumber(cert)); + if(!isname || !serial) { + X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS); + goto err; + } +} + +if(!(akeyid = AUTHORITY_KEYID_new())) goto err; + +if(isname) { + if(!(gens = sk_GENERAL_NAME_new(NULL)) || !(gen = GENERAL_NAME_new()) + || !sk_GENERAL_NAME_push(gens, gen)) { + X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE); + goto err; + } + gen->type = GEN_DIRNAME; + gen->d.dirn = isname; +} + +akeyid->issuer = gens; +akeyid->serial = serial; +akeyid->keyid = ikeyid; + +return akeyid; + +err: +X509_NAME_free(isname); +ASN1_INTEGER_free(serial); +ASN1_OCTET_STRING_free(ikeyid); +return NULL; + +} + diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c new file mode 100644 index 0000000000..b5e1f8af96 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_alt.c @@ -0,0 +1,402 @@ +/* v3_alt.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include + +static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); +static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); +static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens); +static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens); +X509V3_EXT_METHOD v3_alt[] = { +{ NID_subject_alt_name, 0, +(X509V3_EXT_NEW)GENERAL_NAMES_new, +(X509V3_EXT_FREE)GENERAL_NAMES_free, +(X509V3_EXT_D2I)d2i_GENERAL_NAMES, +(X509V3_EXT_I2D)i2d_GENERAL_NAMES, +NULL, NULL, +(X509V3_EXT_I2V)i2v_GENERAL_NAMES, +(X509V3_EXT_V2I)v2i_subject_alt, +NULL, NULL, NULL}, +{ NID_issuer_alt_name, 0, +(X509V3_EXT_NEW)GENERAL_NAMES_new, +(X509V3_EXT_FREE)GENERAL_NAMES_free, +(X509V3_EXT_D2I)d2i_GENERAL_NAMES, +(X509V3_EXT_I2D)i2d_GENERAL_NAMES, +NULL, NULL, +(X509V3_EXT_I2V)i2v_GENERAL_NAMES, +(X509V3_EXT_V2I)v2i_issuer_alt, +NULL, NULL, NULL}, +EXT_END +}; + +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, + STACK_OF(GENERAL_NAME) *gens, STACK_OF(CONF_VALUE) *ret) +{ + int i; + GENERAL_NAME *gen; + for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) { + gen = sk_GENERAL_NAME_value(gens, i); + ret = i2v_GENERAL_NAME(method, gen, ret); + } + if(!ret) return sk_CONF_VALUE_new_null(); + return ret; +} + +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, + GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret) +{ + char oline[256]; + unsigned char *p; + switch (gen->type) + { + case GEN_OTHERNAME: + X509V3_add_value("othername","", &ret); + break; + + case GEN_X400: + X509V3_add_value("X400Name","", &ret); + break; + + case GEN_EDIPARTY: + X509V3_add_value("EdiPartyName","", &ret); + break; + + case GEN_EMAIL: + X509V3_add_value_uchar("email",gen->d.ia5->data, &ret); + break; + + case GEN_DNS: + X509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret); + break; + + case GEN_URI: + X509V3_add_value_uchar("URI",gen->d.ia5->data, &ret); + break; + + case GEN_DIRNAME: + X509_NAME_oneline(gen->d.dirn, oline, 256); + X509V3_add_value("DirName",oline, &ret); + break; + + case GEN_IPADD: + p = gen->d.ip->data; + /* BUG: doesn't support IPV6 */ + if(gen->d.ip->length != 4) { + X509V3_add_value("IP Address","", &ret); + break; + } + sprintf(oline, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); + X509V3_add_value("IP Address",oline, &ret); + break; + + case GEN_RID: + i2t_ASN1_OBJECT(oline, 256, gen->d.rid); + X509V3_add_value("Registered ID",oline, &ret); + break; + } + return ret; +} + +static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) +{ + STACK_OF(GENERAL_NAME) *gens = NULL; + CONF_VALUE *cnf; + int i; + if(!(gens = sk_GENERAL_NAME_new(NULL))) { + X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE); + return NULL; + } + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + cnf = sk_CONF_VALUE_value(nval, i); + if(!name_cmp(cnf->name, "issuer") && cnf->value && + !strcmp(cnf->value, "copy")) { + if(!copy_issuer(ctx, gens)) goto err; + } else { + GENERAL_NAME *gen; + if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) + goto err; + sk_GENERAL_NAME_push(gens, gen); + } + } + return gens; + err: + sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); + return NULL; +} + +/* Append subject altname of issuer to issuer alt name of subject */ + +static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens) +{ + STACK_OF(GENERAL_NAME) *ialt; + GENERAL_NAME *gen; + X509_EXTENSION *ext; + int i; + if(ctx && (ctx->flags == CTX_TEST)) return 1; + if(!ctx || !ctx->issuer_cert) { + X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_NO_ISSUER_DETAILS); + goto err; + } + i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1); + if(i < 0) return 1; + if(!(ext = X509_get_ext(ctx->issuer_cert, i)) || + !(ialt = X509V3_EXT_d2i(ext)) ) { + X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR); + goto err; + } + + for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) { + gen = sk_GENERAL_NAME_value(ialt, i); + if(!sk_GENERAL_NAME_push(gens, gen)) { + X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE); + goto err; + } + } + sk_GENERAL_NAME_free(ialt); + + return 1; + + err: + return 0; + +} + +static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) +{ + STACK_OF(GENERAL_NAME) *gens = NULL; + CONF_VALUE *cnf; + int i; + if(!(gens = sk_GENERAL_NAME_new(NULL))) { + X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE); + return NULL; + } + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + cnf = sk_CONF_VALUE_value(nval, i); + if(!name_cmp(cnf->name, "email") && cnf->value && + !strcmp(cnf->value, "copy")) { + if(!copy_email(ctx, gens)) goto err; + } else { + GENERAL_NAME *gen; + if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) + goto err; + sk_GENERAL_NAME_push(gens, gen); + } + } + return gens; + err: + sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); + return NULL; +} + +/* Copy any email addresses in a certificate or request to + * GENERAL_NAMES + */ + +static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens) +{ + X509_NAME *nm; + ASN1_IA5STRING *email = NULL; + X509_NAME_ENTRY *ne; + GENERAL_NAME *gen = NULL; + int i; + if(ctx->flags == CTX_TEST) return 1; + if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) { + X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS); + goto err; + } + /* Find the subject name */ + if(ctx->subject_cert) nm = X509_get_subject_name(ctx->subject_cert); + else nm = X509_REQ_get_subject_name(ctx->subject_req); + + /* Now add any email address(es) to STACK */ + i = -1; + while((i = X509_NAME_get_index_by_NID(nm, + NID_pkcs9_emailAddress, i)) > 0) { + ne = X509_NAME_get_entry(nm, i); + email = ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne)); + if(!email || !(gen = GENERAL_NAME_new())) { + X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE); + goto err; + } + gen->d.ia5 = email; + email = NULL; + gen->type = GEN_EMAIL; + if(!sk_GENERAL_NAME_push(gens, gen)) { + X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE); + goto err; + } + gen = NULL; + } + + + return 1; + + err: + GENERAL_NAME_free(gen); + ASN1_IA5STRING_free(email); + return 0; + +} + +STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) +{ + GENERAL_NAME *gen; + STACK_OF(GENERAL_NAME) *gens = NULL; + CONF_VALUE *cnf; + int i; + if(!(gens = sk_GENERAL_NAME_new(NULL))) { + X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE); + return NULL; + } + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + cnf = sk_CONF_VALUE_value(nval, i); + if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err; + sk_GENERAL_NAME_push(gens, gen); + } + return gens; + err: + sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free); + return NULL; +} + +GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, + CONF_VALUE *cnf) +{ +char is_string = 0; +int type; +GENERAL_NAME *gen = NULL; + +char *name, *value; + +name = cnf->name; +value = cnf->value; + +if(!value) { + X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE); + return NULL; +} + +if(!(gen = GENERAL_NAME_new())) { + X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE); + return NULL; +} + +if(!name_cmp(name, "email")) { + is_string = 1; + type = GEN_EMAIL; +} else if(!name_cmp(name, "URI")) { + is_string = 1; + type = GEN_URI; +} else if(!name_cmp(name, "DNS")) { + is_string = 1; + type = GEN_DNS; +} else if(!name_cmp(name, "RID")) { + ASN1_OBJECT *obj; + if(!(obj = OBJ_txt2obj(value,0))) { + X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT); + ERR_add_error_data(2, "value=", value); + goto err; + } + gen->d.rid = obj; + type = GEN_RID; +} else if(!name_cmp(name, "IP")) { + int i1,i2,i3,i4; + unsigned char ip[4]; + if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) || + (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) || + (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) { + X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS); + ERR_add_error_data(2, "value=", value); + goto err; + } + ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4; + if(!(gen->d.ip = ASN1_OCTET_STRING_new()) || + !ASN1_STRING_set(gen->d.ip, ip, 4)) { + X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE); + goto err; + } + type = GEN_IPADD; +} else { + X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION); + ERR_add_error_data(2, "name=", name); + goto err; +} + +if(is_string) { + if(!(gen->d.ia5 = ASN1_IA5STRING_new()) || + !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value, + strlen(value))) { + X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE); + goto err; + } +} + +gen->type = type; + +return gen; + +err: +GENERAL_NAME_free(gen); +return NULL; +} diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c new file mode 100644 index 0000000000..de2f855c35 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_bcons.c @@ -0,0 +1,164 @@ +/* v3_bcons.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + +#include +#include "cryptlib.h" +#include +#include +#include +#include + +static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist); +static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values); + +X509V3_EXT_METHOD v3_bcons = { +NID_basic_constraints, 0, +(X509V3_EXT_NEW)BASIC_CONSTRAINTS_new, +(X509V3_EXT_FREE)BASIC_CONSTRAINTS_free, +(X509V3_EXT_D2I)d2i_BASIC_CONSTRAINTS, +(X509V3_EXT_I2D)i2d_BASIC_CONSTRAINTS, +NULL, NULL, +(X509V3_EXT_I2V)i2v_BASIC_CONSTRAINTS, +(X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS, +NULL,NULL, +NULL +}; + + +int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + if(a->ca) M_ASN1_I2D_len (a->ca, i2d_ASN1_BOOLEAN); + M_ASN1_I2D_len (a->pathlen, i2d_ASN1_INTEGER); + + M_ASN1_I2D_seq_total(); + + if (a->ca) M_ASN1_I2D_put (a->ca, i2d_ASN1_BOOLEAN); + M_ASN1_I2D_put (a->pathlen, i2d_ASN1_INTEGER); + M_ASN1_I2D_finish(); +} + +BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void) +{ + BASIC_CONSTRAINTS *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, BASIC_CONSTRAINTS); + ret->ca = 0; + ret->pathlen = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_BASIC_CONSTRAINTS_NEW); +} + +BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, + unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,BASIC_CONSTRAINTS *,BASIC_CONSTRAINTS_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + if((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == + (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN) ) { + M_ASN1_D2I_get_int (ret->ca, d2i_ASN1_BOOLEAN); + } + M_ASN1_D2I_get_opt (ret->pathlen, d2i_ASN1_INTEGER, V_ASN1_INTEGER); + M_ASN1_D2I_Finish(a, BASIC_CONSTRAINTS_free, ASN1_F_D2I_BASIC_CONSTRAINTS); +} + +void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a) +{ + if (a == NULL) return; + ASN1_INTEGER_free (a->pathlen); + Free ((char *)a); +} + +static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, + BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist) +{ + X509V3_add_value_bool("CA", bcons->ca, &extlist); + X509V3_add_value_int("pathlen", bcons->pathlen, &extlist); + return extlist; +} + +static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values) +{ + BASIC_CONSTRAINTS *bcons=NULL; + CONF_VALUE *val; + int i; + if(!(bcons = BASIC_CONSTRAINTS_new())) { + X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE); + return NULL; + } + for(i = 0; i < sk_CONF_VALUE_num(values); i++) { + val = sk_CONF_VALUE_value(values, i); + if(!strcmp(val->name, "CA")) { + if(!X509V3_get_value_bool(val, &bcons->ca)) goto err; + } else if(!strcmp(val->name, "pathlen")) { + if(!X509V3_get_value_int(val, &bcons->pathlen)) goto err; + } else { + X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME); + X509V3_conf_err(val); + goto err; + } + } + return bcons; + err: + BASIC_CONSTRAINTS_free(bcons); + return NULL; +} + diff --git a/src/lib/libcrypto/x509v3/v3_bitst.c b/src/lib/libcrypto/x509v3/v3_bitst.c new file mode 100644 index 0000000000..9828ba15b3 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_bitst.c @@ -0,0 +1,147 @@ +/* v3_bitst.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include + +static ASN1_BIT_STRING *asn1_bit_string_new(void); +static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); +static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + ASN1_BIT_STRING *bits, + STACK_OF(CONF_VALUE) *extlist); +static BIT_STRING_BITNAME ns_cert_type_table[] = { +{0, "SSL Client", "client"}, +{1, "SSL Server", "server"}, +{2, "S/MIME", "email"}, +{3, "Object Signing", "objsign"}, +{4, "Unused", "reserved"}, +{5, "SSL CA", "sslCA"}, +{6, "S/MIME CA", "emailCA"}, +{7, "Object Signing CA", "objCA"}, +{-1, NULL, NULL} +}; + +static BIT_STRING_BITNAME key_usage_type_table[] = { +{0, "Digital Signature", "digitalSignature"}, +{1, "Non Repudiation", "nonRepudiation"}, +{2, "Key Encipherment", "keyEncipherment"}, +{3, "Data Encipherment", "dataEncipherment"}, +{4, "Key Agreement", "keyAgreement"}, +{5, "Certificate Sign", "keyCertSign"}, +{6, "CRL Sign", "cRLSign"}, +{7, "Encipher Only", "encipherOnly"}, +{8, "Decipher Only", "decipherOnly"}, +{-1, NULL, NULL} +}; + + + +X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table); +X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table); + +static ASN1_BIT_STRING *asn1_bit_string_new(void) +{ + return ASN1_BIT_STRING_new(); +} + +static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret) +{ + BIT_STRING_BITNAME *bnam; + for(bnam =method->usr_data; bnam->lname; bnam++) { + if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum)) + X509V3_add_value(bnam->lname, NULL, &ret); + } + return ret; +} + +static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) +{ + CONF_VALUE *val; + ASN1_BIT_STRING *bs; + int i; + BIT_STRING_BITNAME *bnam; + if(!(bs = ASN1_BIT_STRING_new())) { + X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE); + return NULL; + } + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + val = sk_CONF_VALUE_value(nval, i); + for(bnam = method->usr_data; bnam->lname; bnam++) { + if(!strcmp(bnam->sname, val->name) || + !strcmp(bnam->lname, val->name) ) { + ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1); + break; + } + } + if(!bnam->lname) { + X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, + X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT); + X509V3_conf_err(val); + ASN1_BIT_STRING_free(bs); + return NULL; + } + } + return bs; +} + + diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c new file mode 100644 index 0000000000..f19bb3ad84 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_conf.c @@ -0,0 +1,366 @@ +/* v3_conf.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* extension creation utilities */ + + + +#include +#include +#include "cryptlib.h" +#include +#include +#include + +static int v3_check_critical(char **value); +static int v3_check_generic(char **value); +static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value); +static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type); +static char *conf_lhash_get_string(void *db, char *section, char *value); +static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section); +static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid, + int crit, void *ext_struc); +/* LHASH *conf: Config file */ +/* char *name: Name */ +/* char *value: Value */ +X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, + char *value) +{ + int crit; + int ext_type; + X509_EXTENSION *ret; + crit = v3_check_critical(&value); + if((ext_type = v3_check_generic(&value))) + return v3_generic_extension(name, value, crit, ext_type); + ret = do_ext_conf(conf, ctx, OBJ_sn2nid(name), crit, value); + if(!ret) { + X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_ERROR_IN_EXTENSION); + ERR_add_error_data(4,"name=", name, ", value=", value); + } + return ret; +} + +/* LHASH *conf: Config file */ +/* char *value: Value */ +X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, + char *value) +{ + int crit; + int ext_type; + crit = v3_check_critical(&value); + if((ext_type = v3_check_generic(&value))) + return v3_generic_extension(OBJ_nid2sn(ext_nid), + value, crit, ext_type); + return do_ext_conf(conf, ctx, ext_nid, crit, value); +} + +/* LHASH *conf: Config file */ +/* char *value: Value */ +static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid, + int crit, char *value) +{ + X509V3_EXT_METHOD *method; + X509_EXTENSION *ext; + STACK_OF(CONF_VALUE) *nval; + void *ext_struc; + if(ext_nid == NID_undef) { + X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION_NAME); + return NULL; + } + if(!(method = X509V3_EXT_get_nid(ext_nid))) { + X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION); + return NULL; + } + /* Now get internal extension representation based on type */ + if(method->v2i) { + if(*value == '@') nval = CONF_get_section(conf, value + 1); + else nval = X509V3_parse_list(value); + if(!nval) { + X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_INVALID_EXTENSION_STRING); + ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value); + return NULL; + } + ext_struc = method->v2i(method, ctx, nval); + if(*value != '@') sk_CONF_VALUE_pop_free(nval, + X509V3_conf_free); + if(!ext_struc) return NULL; + } else if(method->s2i) { + if(!(ext_struc = method->s2i(method, ctx, value))) return NULL; + } else if(method->r2i) { + if(!ctx->db) { + X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_NO_CONFIG_DATABASE); + return NULL; + } + if(!(ext_struc = method->r2i(method, ctx, value))) return NULL; + } else { + X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED); + ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid)); + return NULL; + } + + ext = do_ext_i2d(method, ext_nid, crit, ext_struc); + method->ext_free(ext_struc); + return ext; + +} + +static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid, + int crit, void *ext_struc) +{ + unsigned char *ext_der, *p; + int ext_len; + ASN1_OCTET_STRING *ext_oct; + X509_EXTENSION *ext; + /* Convert internal representation to DER */ + ext_len = method->i2d(ext_struc, NULL); + if(!(ext_der = Malloc(ext_len))) goto merr; + p = ext_der; + method->i2d(ext_struc, &p); + if(!(ext_oct = ASN1_OCTET_STRING_new())) goto merr; + ext_oct->data = ext_der; + ext_oct->length = ext_len; + + ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct); + if(!ext) goto merr; + ASN1_OCTET_STRING_free(ext_oct); + + return ext; + + merr: + X509V3err(X509V3_F_DO_EXT_I2D,ERR_R_MALLOC_FAILURE); + return NULL; + +} + +/* Given an internal structure, nid and critical flag create an extension */ + +X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc) +{ + X509V3_EXT_METHOD *method; + if(!(method = X509V3_EXT_get_nid(ext_nid))) { + X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION); + return NULL; + } + return do_ext_i2d(method, ext_nid, crit, ext_struc); +} + +/* Check the extension string for critical flag */ +static int v3_check_critical(char **value) +{ + char *p = *value; + if((strlen(p) < 9) || strncmp(p, "critical,", 9)) return 0; + p+=9; + while(isspace((unsigned char)*p)) p++; + *value = p; + return 1; +} + +/* Check extension string for generic extension and return the type */ +static int v3_check_generic(char **value) +{ + char *p = *value; + if((strlen(p) < 4) || strncmp(p, "DER:,", 4)) return 0; + p+=4; + while(isspace((unsigned char)*p)) p++; + *value = p; + return 1; +} + +/* Create a generic extension: for now just handle RAW type */ +static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, + int crit, int type) +{ +unsigned char *ext_der=NULL; +long ext_len; +ASN1_OBJECT *obj=NULL; +ASN1_OCTET_STRING *oct=NULL; +X509_EXTENSION *extension=NULL; +if(!(obj = OBJ_txt2obj(ext, 0))) { + X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_NAME_ERROR); + ERR_add_error_data(2, "name=", ext); + goto err; +} + +if(!(ext_der = string_to_hex(value, &ext_len))) { + X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR); + ERR_add_error_data(2, "value=", value); + goto err; +} + +if(!(oct = ASN1_OCTET_STRING_new())) { + X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE); + goto err; +} + +oct->data = ext_der; +oct->length = ext_len; +ext_der = NULL; + +extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct); + +err: +ASN1_OBJECT_free(obj); +ASN1_OCTET_STRING_free(oct); +if(ext_der) Free(ext_der); +return extension; +} + + +/* This is the main function: add a bunch of extensions based on a config file + * section + */ + +int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, + X509 *cert) +{ + X509_EXTENSION *ext; + STACK_OF(CONF_VALUE) *nval; + CONF_VALUE *val; + int i; + if(!(nval = CONF_get_section(conf, section))) return 0; + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + val = sk_CONF_VALUE_value(nval, i); + if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value))) + return 0; + if(cert) X509_add_ext(cert, ext, -1); + X509_EXTENSION_free(ext); + } + return 1; +} + +/* Same as above but for a CRL */ + +int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, + X509_CRL *crl) +{ + X509_EXTENSION *ext; + STACK_OF(CONF_VALUE) *nval; + CONF_VALUE *val; + int i; + if(!(nval = CONF_get_section(conf, section))) return 0; + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + val = sk_CONF_VALUE_value(nval, i); + if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value))) + return 0; + if(crl) X509_CRL_add_ext(crl, ext, -1); + X509_EXTENSION_free(ext); + } + return 1; +} + +/* Config database functions */ + +char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section) +{ + if(ctx->db_meth->get_string) + return ctx->db_meth->get_string(ctx->db, name, section); + return NULL; +} + +STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section) +{ + if(ctx->db_meth->get_section) + return ctx->db_meth->get_section(ctx->db, section); + return NULL; +} + +void X509V3_string_free(X509V3_CTX *ctx, char *str) +{ + if(!str) return; + if(ctx->db_meth->free_string) + ctx->db_meth->free_string(ctx->db, str); +} + +void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section) +{ + if(!section) return; + if(ctx->db_meth->free_section) + ctx->db_meth->free_section(ctx->db, section); +} + +static char *conf_lhash_get_string(void *db, char *section, char *value) +{ + return CONF_get_string(db, section, value); +} + +static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section) +{ + return CONF_get_section(db, section); +} + +static X509V3_CONF_METHOD conf_lhash_method = { +conf_lhash_get_string, +conf_lhash_get_section, +NULL, +NULL +}; + +void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash) +{ + ctx->db_meth = &conf_lhash_method; + ctx->db = lhash; +} + +void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req, + X509_CRL *crl, int flags) +{ + ctx->issuer_cert = issuer; + ctx->subject_cert = subj; + ctx->crl = crl; + ctx->subject_req = req; + ctx->flags = flags; +} diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c new file mode 100644 index 0000000000..b4d4883545 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_cpols.c @@ -0,0 +1,655 @@ +/* v3_cpols.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include +#include +#include + +/* Certificate policies extension support: this one is a bit complex... */ + +static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent); +static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value); +static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent); +static void print_notice(BIO *out, USERNOTICE *notice, int indent); +static POLICYINFO *policy_section(X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *polstrs, int ia5org); +static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *unot, int ia5org); +static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos); + +X509V3_EXT_METHOD v3_cpols = { +NID_certificate_policies, 0, +(X509V3_EXT_NEW)CERTIFICATEPOLICIES_new, +(X509V3_EXT_FREE)CERTIFICATEPOLICIES_free, +(X509V3_EXT_D2I)d2i_CERTIFICATEPOLICIES, +(X509V3_EXT_I2D)i2d_CERTIFICATEPOLICIES, +NULL, NULL, +NULL, NULL, +(X509V3_EXT_I2R)i2r_certpol, +(X509V3_EXT_R2I)r2i_certpol, +NULL +}; + + +static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, char *value) +{ + STACK_OF(POLICYINFO) *pols = NULL; + char *pstr; + POLICYINFO *pol; + ASN1_OBJECT *pobj; + STACK_OF(CONF_VALUE) *vals; + CONF_VALUE *cnf; + int i, ia5org; + pols = sk_POLICYINFO_new_null(); + vals = X509V3_parse_list(value); + ia5org = 0; + for(i = 0; i < sk_CONF_VALUE_num(vals); i++) { + cnf = sk_CONF_VALUE_value(vals, i); + if(cnf->value || !cnf->name ) { + X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER); + X509V3_conf_err(cnf); + goto err; + } + pstr = cnf->name; + if(!strcmp(pstr,"ia5org")) { + ia5org = 1; + continue; + } else if(*pstr == '@') { + STACK_OF(CONF_VALUE) *polsect; + polsect = X509V3_get_section(ctx, pstr + 1); + if(!polsect) { + X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION); + + X509V3_conf_err(cnf); + goto err; + } + pol = policy_section(ctx, polsect, ia5org); + X509V3_section_free(ctx, polsect); + if(!pol) goto err; + } else { + if(!(pobj = OBJ_txt2obj(cnf->name, 0))) { + X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER); + X509V3_conf_err(cnf); + goto err; + } + pol = POLICYINFO_new(); + pol->policyid = pobj; + } + sk_POLICYINFO_push(pols, pol); + } + sk_CONF_VALUE_pop_free(vals, X509V3_conf_free); + return pols; + err: + sk_POLICYINFO_pop_free(pols, POLICYINFO_free); + return NULL; +} + +static POLICYINFO *policy_section(X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *polstrs, int ia5org) +{ + int i; + CONF_VALUE *cnf; + POLICYINFO *pol; + POLICYQUALINFO *qual; + if(!(pol = POLICYINFO_new())) goto merr; + for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) { + cnf = sk_CONF_VALUE_value(polstrs, i); + if(!strcmp(cnf->name, "policyIdentifier")) { + ASN1_OBJECT *pobj; + if(!(pobj = OBJ_txt2obj(cnf->value, 0))) { + X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER); + X509V3_conf_err(cnf); + goto err; + } + pol->policyid = pobj; + + } else if(!name_cmp(cnf->name, "CPS")) { + if(!pol->qualifiers) pol->qualifiers = + sk_POLICYQUALINFO_new_null(); + if(!(qual = POLICYQUALINFO_new())) goto merr; + if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) + goto merr; + qual->pqualid = OBJ_nid2obj(NID_id_qt_cps); + qual->d.cpsuri = ASN1_IA5STRING_new(); + if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value, + strlen(cnf->value))) goto merr; + } else if(!name_cmp(cnf->name, "userNotice")) { + STACK_OF(CONF_VALUE) *unot; + if(*cnf->value != '@') { + X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME); + X509V3_conf_err(cnf); + goto err; + } + unot = X509V3_get_section(ctx, cnf->value + 1); + if(!unot) { + X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION); + + X509V3_conf_err(cnf); + goto err; + } + qual = notice_section(ctx, unot, ia5org); + X509V3_section_free(ctx, unot); + if(!qual) goto err; + if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) + goto merr; + } else { + X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION); + + X509V3_conf_err(cnf); + goto err; + } + } + if(!pol->policyid) { + X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER); + goto err; + } + + return pol; + + merr: + X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE); + + err: + POLICYINFO_free(pol); + return NULL; + + +} + +static POLICYQUALINFO *notice_section(X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *unot, int ia5org) +{ + int i; + CONF_VALUE *cnf; + USERNOTICE *not; + POLICYQUALINFO *qual; + if(!(qual = POLICYQUALINFO_new())) goto merr; + qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice); + if(!(not = USERNOTICE_new())) goto merr; + qual->d.usernotice = not; + for(i = 0; i < sk_CONF_VALUE_num(unot); i++) { + cnf = sk_CONF_VALUE_value(unot, i); + if(!strcmp(cnf->name, "explicitText")) { + not->exptext = ASN1_VISIBLESTRING_new(); + if(!ASN1_STRING_set(not->exptext, cnf->value, + strlen(cnf->value))) goto merr; + } else if(!strcmp(cnf->name, "organization")) { + NOTICEREF *nref; + if(!not->noticeref) { + if(!(nref = NOTICEREF_new())) goto merr; + not->noticeref = nref; + } else nref = not->noticeref; + if(ia5org) nref->organization = ASN1_IA5STRING_new(); + else nref->organization = ASN1_VISIBLESTRING_new(); + if(!ASN1_STRING_set(nref->organization, cnf->value, + strlen(cnf->value))) goto merr; + } else if(!strcmp(cnf->name, "noticeNumbers")) { + NOTICEREF *nref; + STACK_OF(CONF_VALUE) *nos; + if(!not->noticeref) { + if(!(nref = NOTICEREF_new())) goto merr; + not->noticeref = nref; + } else nref = not->noticeref; + nos = X509V3_parse_list(cnf->value); + if(!nos || !sk_CONF_VALUE_num(nos)) { + X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS); + X509V3_conf_err(cnf); + goto err; + } + nref->noticenos = nref_nos(nos); + sk_CONF_VALUE_pop_free(nos, X509V3_conf_free); + if(!nref->noticenos) goto err; + } else { + X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION); + + X509V3_conf_err(cnf); + goto err; + } + } + + if(not->noticeref && + (!not->noticeref->noticenos || !not->noticeref->organization)) { + X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS); + goto err; + } + + return qual; + + merr: + X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE); + + err: + POLICYQUALINFO_free(qual); + return NULL; +} + +static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos) +{ + STACK *nnums; + CONF_VALUE *cnf; + ASN1_INTEGER *aint; + int i; + if(!(nnums = sk_new_null())) goto merr; + for(i = 0; i < sk_CONF_VALUE_num(nos); i++) { + cnf = sk_CONF_VALUE_value(nos, i); + if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) { + X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER); + goto err; + } + if(!sk_push(nnums, (char *)aint)) goto merr; + } + return nnums; + + merr: + X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE); + + err: + sk_pop_free(nnums, ASN1_STRING_free); + return NULL; +} + + +static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, + BIO *out, int indent) +{ + int i; + POLICYINFO *pinfo; + /* First print out the policy OIDs */ + for(i = 0; i < sk_POLICYINFO_num(pol); i++) { + pinfo = sk_POLICYINFO_value(pol, i); + BIO_printf(out, "%*sPolicy: ", indent, ""); + i2a_ASN1_OBJECT(out, pinfo->policyid); + BIO_puts(out, "\n"); + if(pinfo->qualifiers) + print_qualifiers(out, pinfo->qualifiers, indent + 2); + } + return 1; +} + + +int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp) +{ + +return i2d_ASN1_SET_OF_POLICYINFO(a, pp, i2d_POLICYINFO, V_ASN1_SEQUENCE, + V_ASN1_UNIVERSAL, IS_SEQUENCE);} + +STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void) +{ + return sk_POLICYINFO_new_null(); +} + +void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a) +{ + sk_POLICYINFO_pop_free(a, POLICYINFO_free); +} + +STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a, + unsigned char **pp,long length) +{ +return d2i_ASN1_SET_OF_POLICYINFO(a, pp, length, d2i_POLICYINFO, + POLICYINFO_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); + +} + +IMPLEMENT_STACK_OF(POLICYINFO) +IMPLEMENT_ASN1_SET_OF(POLICYINFO) + +int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len (a->policyid, i2d_ASN1_OBJECT); + M_ASN1_I2D_len_SEQUENCE_type(POLICYQUALINFO, a->qualifiers, + i2d_POLICYQUALINFO); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->policyid, i2d_ASN1_OBJECT); + M_ASN1_I2D_put_SEQUENCE_type(POLICYQUALINFO, a->qualifiers, + i2d_POLICYQUALINFO); + + M_ASN1_I2D_finish(); +} + +POLICYINFO *POLICYINFO_new(void) +{ + POLICYINFO *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, POLICYINFO); + ret->policyid = NULL; + ret->qualifiers = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_POLICYINFO_NEW); +} + +POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp,long length) +{ + M_ASN1_D2I_vars(a,POLICYINFO *,POLICYINFO_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->policyid, d2i_ASN1_OBJECT); + if(!M_ASN1_D2I_end_sequence()) { + M_ASN1_D2I_get_seq_type (POLICYQUALINFO, ret->qualifiers, + d2i_POLICYQUALINFO, POLICYQUALINFO_free); + } + M_ASN1_D2I_Finish(a, POLICYINFO_free, ASN1_F_D2I_POLICYINFO); +} + +void POLICYINFO_free(POLICYINFO *a) +{ + if (a == NULL) return; + ASN1_OBJECT_free(a->policyid); + sk_POLICYQUALINFO_pop_free(a->qualifiers, POLICYQUALINFO_free); + Free (a); +} + +static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, + int indent) +{ + POLICYQUALINFO *qualinfo; + int i; + for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) { + qualinfo = sk_POLICYQUALINFO_value(quals, i); + switch(OBJ_obj2nid(qualinfo->pqualid)) + { + case NID_id_qt_cps: + BIO_printf(out, "%*sCPS: %s\n", indent, "", + qualinfo->d.cpsuri->data); + break; + + case NID_id_qt_unotice: + BIO_printf(out, "%*sUser Notice:\n", indent, ""); + print_notice(out, qualinfo->d.usernotice, indent + 2); + break; + + default: + BIO_printf(out, "%*sUnknown Qualifier: ", + indent + 2, ""); + + i2a_ASN1_OBJECT(out, qualinfo->pqualid); + BIO_puts(out, "\n"); + break; + } + } +} + +static void print_notice(BIO *out, USERNOTICE *notice, int indent) +{ + int i; + if(notice->noticeref) { + NOTICEREF *ref; + ref = notice->noticeref; + BIO_printf(out, "%*sOrganization: %s\n", indent, "", + ref->organization->data); + BIO_printf(out, "%*sNumber%s: ", indent, "", + (sk_num(ref->noticenos) > 1) ? "s" : ""); + for(i = 0; i < sk_num(ref->noticenos); i++) { + ASN1_INTEGER *num; + char *tmp; + num = (ASN1_INTEGER *)sk_value(ref->noticenos, i); + if(i) BIO_puts(out, ", "); + tmp = i2s_ASN1_INTEGER(NULL, num); + BIO_puts(out, tmp); + Free(tmp); + } + BIO_puts(out, "\n"); + } + if(notice->exptext) + BIO_printf(out, "%*sExplicit Text: %s\n", indent, "", + notice->exptext->data); +} + + + +int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len (a->pqualid, i2d_ASN1_OBJECT); + switch(OBJ_obj2nid(a->pqualid)) { + case NID_id_qt_cps: + M_ASN1_I2D_len(a->d.cpsuri, i2d_ASN1_IA5STRING); + break; + + case NID_id_qt_unotice: + M_ASN1_I2D_len(a->d.usernotice, i2d_USERNOTICE); + break; + + default: + M_ASN1_I2D_len(a->d.other, i2d_ASN1_TYPE); + break; + } + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->pqualid, i2d_ASN1_OBJECT); + switch(OBJ_obj2nid(a->pqualid)) { + case NID_id_qt_cps: + M_ASN1_I2D_put(a->d.cpsuri, i2d_ASN1_IA5STRING); + break; + + case NID_id_qt_unotice: + M_ASN1_I2D_put(a->d.usernotice, i2d_USERNOTICE); + break; + + default: + M_ASN1_I2D_put(a->d.other, i2d_ASN1_TYPE); + break; + } + + M_ASN1_I2D_finish(); +} + +POLICYQUALINFO *POLICYQUALINFO_new(void) +{ + POLICYQUALINFO *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, POLICYQUALINFO); + ret->pqualid = NULL; + ret->d.other = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_POLICYQUALINFO_NEW); +} + +POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp, + long length) +{ + M_ASN1_D2I_vars(a,POLICYQUALINFO *,POLICYQUALINFO_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->pqualid, d2i_ASN1_OBJECT); + switch(OBJ_obj2nid(ret->pqualid)) { + case NID_id_qt_cps: + M_ASN1_D2I_get(ret->d.cpsuri, d2i_ASN1_IA5STRING); + break; + + case NID_id_qt_unotice: + M_ASN1_D2I_get(ret->d.usernotice, d2i_USERNOTICE); + break; + + default: + M_ASN1_D2I_get(ret->d.other, d2i_ASN1_TYPE); + break; + } + M_ASN1_D2I_Finish(a, POLICYQUALINFO_free, ASN1_F_D2I_POLICYQUALINFO); +} + +void POLICYQUALINFO_free(POLICYQUALINFO *a) +{ + if (a == NULL) return; + switch(OBJ_obj2nid(a->pqualid)) { + case NID_id_qt_cps: + ASN1_IA5STRING_free(a->d.cpsuri); + break; + + case NID_id_qt_unotice: + USERNOTICE_free(a->d.usernotice); + break; + + default: + ASN1_TYPE_free(a->d.other); + break; + } + + ASN1_OBJECT_free(a->pqualid); + Free (a); +} + +int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len (a->noticeref, i2d_NOTICEREF); + M_ASN1_I2D_len (a->exptext, i2d_DISPLAYTEXT); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->noticeref, i2d_NOTICEREF); + M_ASN1_I2D_put (a->exptext, i2d_DISPLAYTEXT); + + M_ASN1_I2D_finish(); +} + +USERNOTICE *USERNOTICE_new(void) +{ + USERNOTICE *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, USERNOTICE); + ret->noticeref = NULL; + ret->exptext = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_USERNOTICE_NEW); +} + +USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp,long length) +{ + M_ASN1_D2I_vars(a,USERNOTICE *,USERNOTICE_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get_opt(ret->noticeref, d2i_NOTICEREF, V_ASN1_SEQUENCE); + if (!M_ASN1_D2I_end_sequence()) { + M_ASN1_D2I_get(ret->exptext, d2i_DISPLAYTEXT); + } + M_ASN1_D2I_Finish(a, USERNOTICE_free, ASN1_F_D2I_USERNOTICE); +} + +void USERNOTICE_free(USERNOTICE *a) +{ + if (a == NULL) return; + NOTICEREF_free(a->noticeref); + DISPLAYTEXT_free(a->exptext); + Free (a); +} + +int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len (a->organization, i2d_DISPLAYTEXT); + M_ASN1_I2D_len_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->organization, i2d_DISPLAYTEXT); + M_ASN1_I2D_put_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER); + + M_ASN1_I2D_finish(); +} + +NOTICEREF *NOTICEREF_new(void) +{ + NOTICEREF *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, NOTICEREF); + ret->organization = NULL; + ret->noticenos = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_NOTICEREF_NEW); +} + +NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp,long length) +{ + M_ASN1_D2I_vars(a,NOTICEREF *,NOTICEREF_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + /* This is to cope with some broken encodings that use IA5STRING for + * the organization field + */ + M_ASN1_D2I_get_opt(ret->organization, d2i_ASN1_IA5STRING, + V_ASN1_IA5STRING); + if(!ret->organization) { + M_ASN1_D2I_get(ret->organization, d2i_DISPLAYTEXT); + } + M_ASN1_D2I_get_seq(ret->noticenos, d2i_ASN1_INTEGER, ASN1_STRING_free); + M_ASN1_D2I_Finish(a, NOTICEREF_free, ASN1_F_D2I_NOTICEREF); +} + +void NOTICEREF_free(NOTICEREF *a) +{ + if (a == NULL) return; + DISPLAYTEXT_free(a->organization); + sk_pop_free(a->noticenos, ASN1_STRING_free); + Free (a); +} + +IMPLEMENT_STACK_OF(POLICYQUALINFO) +IMPLEMENT_ASN1_SET_OF(POLICYQUALINFO) diff --git a/src/lib/libcrypto/x509v3/v3_crld.c b/src/lib/libcrypto/x509v3/v3_crld.c new file mode 100644 index 0000000000..897ffb63e4 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_crld.c @@ -0,0 +1,283 @@ +/* v3_crld.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include +#include +#include + +static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method, + STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *extlist); +static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); + +X509V3_EXT_METHOD v3_crld = { +NID_crl_distribution_points, X509V3_EXT_MULTILINE, +(X509V3_EXT_NEW)CRL_DIST_POINTS_new, +(X509V3_EXT_FREE)CRL_DIST_POINTS_free, +(X509V3_EXT_D2I)d2i_CRL_DIST_POINTS, +(X509V3_EXT_I2D)i2d_CRL_DIST_POINTS, +NULL, NULL, +(X509V3_EXT_I2V)i2v_crld, +(X509V3_EXT_V2I)v2i_crld, +NULL, NULL, NULL +}; + +static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method, + STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts) +{ + DIST_POINT *point; + int i; + for(i = 0; i < sk_DIST_POINT_num(crld); i++) { + point = sk_DIST_POINT_value(crld, i); + if(point->distpoint->fullname) { + exts = i2v_GENERAL_NAMES(NULL, + point->distpoint->fullname, exts); + } + if(point->reasons) + X509V3_add_value("reasons","", &exts); + if(point->CRLissuer) + X509V3_add_value("CRLissuer","", &exts); + if(point->distpoint->relativename) + X509V3_add_value("RelativeName","", &exts); + } + return exts; +} + +static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) +{ + STACK_OF(DIST_POINT) *crld = NULL; + STACK_OF(GENERAL_NAME) *gens = NULL; + GENERAL_NAME *gen = NULL; + CONF_VALUE *cnf; + int i; + if(!(crld = sk_DIST_POINT_new(NULL))) goto merr; + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + DIST_POINT *point; + cnf = sk_CONF_VALUE_value(nval, i); + if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err; + if(!(gens = GENERAL_NAMES_new())) goto merr; + if(!sk_GENERAL_NAME_push(gens, gen)) goto merr; + gen = NULL; + if(!(point = DIST_POINT_new())) goto merr; + if(!sk_DIST_POINT_push(crld, point)) { + DIST_POINT_free(point); + goto merr; + } + if(!(point->distpoint = DIST_POINT_NAME_new())) goto merr; + point->distpoint->fullname = gens; + gens = NULL; + } + return crld; + + merr: + X509V3err(X509V3_F_V2I_CRLD,ERR_R_MALLOC_FAILURE); + err: + GENERAL_NAME_free(gen); + GENERAL_NAMES_free(gens); + sk_DIST_POINT_pop_free(crld, DIST_POINT_free); + return NULL; +} + +int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp) +{ + +return i2d_ASN1_SET_OF_DIST_POINT(a, pp, i2d_DIST_POINT, V_ASN1_SEQUENCE, + V_ASN1_UNIVERSAL, IS_SEQUENCE);} + +STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void) +{ + return sk_DIST_POINT_new_null(); +} + +void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a) +{ + sk_DIST_POINT_pop_free(a, DIST_POINT_free); +} + +STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a, + unsigned char **pp,long length) +{ +return d2i_ASN1_SET_OF_DIST_POINT(a, pp, length, d2i_DIST_POINT, + DIST_POINT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); + +} + +IMPLEMENT_STACK_OF(DIST_POINT) +IMPLEMENT_ASN1_SET_OF(DIST_POINT) + +int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp) +{ + int v = 0; + M_ASN1_I2D_vars(a); + /* NB: underlying type is a CHOICE so need EXPLICIT tagging */ + M_ASN1_I2D_len_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v); + M_ASN1_I2D_len_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING); + M_ASN1_I2D_len_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v); + M_ASN1_I2D_put_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING, 1); + M_ASN1_I2D_put_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES, 2); + + M_ASN1_I2D_finish(); +} + +DIST_POINT *DIST_POINT_new(void) +{ + DIST_POINT *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, DIST_POINT); + ret->distpoint = NULL; + ret->reasons = NULL; + ret->CRLissuer = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_DIST_POINT_NEW); +} + +DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,DIST_POINT *,DIST_POINT_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get_EXP_opt (ret->distpoint, d2i_DIST_POINT_NAME, 0); + M_ASN1_D2I_get_IMP_opt (ret->reasons, d2i_ASN1_BIT_STRING, 1, + V_ASN1_BIT_STRING); + M_ASN1_D2I_get_IMP_opt (ret->CRLissuer, d2i_GENERAL_NAMES, 2, + V_ASN1_SEQUENCE); + M_ASN1_D2I_Finish(a, DIST_POINT_free, ASN1_F_D2I_DIST_POINT); +} + +void DIST_POINT_free(DIST_POINT *a) +{ + if (a == NULL) return; + DIST_POINT_NAME_free(a->distpoint); + ASN1_BIT_STRING_free(a->reasons); + sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free); + Free ((char *)a); +} + +int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp) +{ + int v = 0; + M_ASN1_I2D_vars(a); + + if(a->fullname) { + M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES); + } else { + M_ASN1_I2D_len_EXP_opt (a->relativename, i2d_X509_NAME, 1, v); + } + + /* Don't want a SEQUENCE so... */ + if(pp == NULL) return ret; + p = *pp; + + if(a->fullname) { + M_ASN1_I2D_put_IMP_opt (a->fullname, i2d_GENERAL_NAMES, 0); + } else { + M_ASN1_I2D_put_EXP_opt (a->relativename, i2d_X509_NAME, 1, v); + } + M_ASN1_I2D_finish(); +} + +DIST_POINT_NAME *DIST_POINT_NAME_new(void) +{ + DIST_POINT_NAME *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, DIST_POINT_NAME); + ret->fullname = NULL; + ret->relativename = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_DIST_POINT_NAME_NEW); +} + +void DIST_POINT_NAME_free(DIST_POINT_NAME *a) +{ + if (a == NULL) return; + X509_NAME_free(a->relativename); + sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free); + Free ((char *)a); +} + +DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp, + long length) +{ + unsigned char _tmp, tag; + M_ASN1_D2I_vars(a,DIST_POINT_NAME *,DIST_POINT_NAME_new); + M_ASN1_D2I_Init(); + c.slen = length; + + _tmp = M_ASN1_next; + tag = _tmp & ~V_ASN1_CONSTRUCTED; + + if(tag == (0|V_ASN1_CONTEXT_SPECIFIC)) { + M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES, + V_ASN1_SEQUENCE); + } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) { + M_ASN1_D2I_get_EXP_opt (ret->relativename, d2i_X509_NAME, 1); + } else { + c.error = ASN1_R_BAD_TAG; + goto err; + } + + M_ASN1_D2I_Finish(a, DIST_POINT_NAME_free, ASN1_F_D2I_DIST_POINT_NAME); +} diff --git a/src/lib/libcrypto/x509v3/v3_enum.c b/src/lib/libcrypto/x509v3/v3_enum.c new file mode 100644 index 0000000000..db423548ff --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_enum.c @@ -0,0 +1,103 @@ +/* v3_enum.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include + +static ASN1_ENUMERATED *asn1_enumerated_new(void); + +static ENUMERATED_NAMES crl_reasons[] = { +{0, "Unspecified", "unspecified"}, +{1, "Key Compromise", "keyCompromise"}, +{2, "CA Compromise", "CACompromise"}, +{3, "Affiliation Changed", "affiliationChanged"}, +{4, "Superseded", "superseded"}, +{5, "Cessation Of Operation", "cessationOfOperation"}, +{6, "Certificate Hold", "certificateHold"}, +{8, "Remove From CRL", "removeFromCRL"}, +{-1, NULL, NULL} +}; + +X509V3_EXT_METHOD v3_crl_reason = { +NID_crl_reason, 0, +(X509V3_EXT_NEW)asn1_enumerated_new, +(X509V3_EXT_FREE)ASN1_STRING_free, +(X509V3_EXT_D2I)d2i_ASN1_ENUMERATED, +(X509V3_EXT_I2D)i2d_ASN1_ENUMERATED, +(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE, +(X509V3_EXT_S2I)NULL, +NULL, NULL, NULL, NULL, crl_reasons}; + + +static ASN1_ENUMERATED *asn1_enumerated_new(void) +{ + return ASN1_ENUMERATED_new(); +} + +char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method, + ASN1_ENUMERATED *e) +{ + ENUMERATED_NAMES *enam; + long strval; + strval = ASN1_ENUMERATED_get(e); + for(enam = method->usr_data; enam->lname; enam++) { + if(strval == enam->bitnum) return BUF_strdup(enam->lname); + } + return i2s_ASN1_ENUMERATED(method, e); +} diff --git a/src/lib/libcrypto/x509v3/v3_extku.c b/src/lib/libcrypto/x509v3/v3_extku.c new file mode 100644 index 0000000000..e039d21cbf --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_extku.c @@ -0,0 +1,150 @@ +/* v3_extku.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + +#include +#include "cryptlib.h" +#include +#include +#include + +static STACK_OF(ASN1_OBJECT) *v2i_ext_ku(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); +static STACK_OF(CONF_VALUE) *i2v_ext_ku(X509V3_EXT_METHOD *method, + STACK_OF(ASN1_OBJECT) *eku, STACK_OF(CONF_VALUE) *extlist); +X509V3_EXT_METHOD v3_ext_ku = { +NID_ext_key_usage, 0, +(X509V3_EXT_NEW)ext_ku_new, +(X509V3_EXT_FREE)ext_ku_free, +(X509V3_EXT_D2I)d2i_ext_ku, +(X509V3_EXT_I2D)i2d_ext_ku, +NULL, NULL, +(X509V3_EXT_I2V)i2v_ext_ku, +(X509V3_EXT_V2I)v2i_ext_ku, +NULL,NULL, +NULL +}; + +STACK_OF(ASN1_OBJECT) *ext_ku_new(void) +{ + return sk_ASN1_OBJECT_new_null(); +} + +void ext_ku_free(STACK_OF(ASN1_OBJECT) *eku) +{ + sk_ASN1_OBJECT_pop_free(eku, ASN1_OBJECT_free); + return; +} + +int i2d_ext_ku(STACK_OF(ASN1_OBJECT) *a, unsigned char **pp) +{ + return i2d_ASN1_SET_OF_ASN1_OBJECT(a, pp, i2d_ASN1_OBJECT, + V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE); +} + +STACK_OF(ASN1_OBJECT) *d2i_ext_ku(STACK_OF(ASN1_OBJECT) **a, + unsigned char **pp, long length) +{ + return d2i_ASN1_SET_OF_ASN1_OBJECT(a, pp, length, d2i_ASN1_OBJECT, + ASN1_OBJECT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); +} + + + +static STACK_OF(CONF_VALUE) *i2v_ext_ku(X509V3_EXT_METHOD *method, + STACK_OF(ASN1_OBJECT) *eku, STACK_OF(CONF_VALUE) *ext_list) +{ +int i; +ASN1_OBJECT *obj; +char obj_tmp[80]; +for(i = 0; i < sk_ASN1_OBJECT_num(eku); i++) { + obj = sk_ASN1_OBJECT_value(eku, i); + i2t_ASN1_OBJECT(obj_tmp, 80, obj); + X509V3_add_value(NULL, obj_tmp, &ext_list); +} +return ext_list; +} + +static STACK_OF(ASN1_OBJECT) *v2i_ext_ku(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) +{ +STACK_OF(ASN1_OBJECT) *extku; +char *extval; +ASN1_OBJECT *objtmp; +CONF_VALUE *val; +int i; + +if(!(extku = sk_ASN1_OBJECT_new(NULL))) { + X509V3err(X509V3_F_V2I_EXT_KU,ERR_R_MALLOC_FAILURE); + return NULL; +} + +for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + val = sk_CONF_VALUE_value(nval, i); + if(val->value) extval = val->value; + else extval = val->name; + if(!(objtmp = OBJ_txt2obj(extval, 0))) { + sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free); + X509V3err(X509V3_F_V2I_EXT_KU,X509V3_R_INVALID_OBJECT_IDENTIFIER); + X509V3_conf_err(val); + return NULL; + } + sk_ASN1_OBJECT_push(extku, objtmp); +} +return extku; +} diff --git a/src/lib/libcrypto/x509v3/v3_genn.c b/src/lib/libcrypto/x509v3/v3_genn.c new file mode 100644 index 0000000000..af716232f8 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_genn.c @@ -0,0 +1,237 @@ +/* v3_genn.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + +#include +#include "cryptlib.h" +#include +#include +#include +#include + +int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp) +{ + unsigned char *p; + int ret; + + ret = 0; + + /* Save the location of initial TAG */ + if(pp) p = *pp; + else p = NULL; + + /* GEN_DNAME needs special treatment because of EXPLICIT tag */ + + if(a->type == GEN_DIRNAME) { + int v = 0; + M_ASN1_I2D_len_EXP_opt(a->d.dirn, i2d_X509_NAME, 4, v); + if(!p) return ret; + M_ASN1_I2D_put_EXP_opt(a->d.dirn, i2d_X509_NAME, 4, v); + *pp = p; + return ret; + } + + switch(a->type) { + + case GEN_OTHERNAME: + case GEN_X400: + case GEN_EDIPARTY: + ret = i2d_ASN1_TYPE(a->d.other, pp); + break; + + case GEN_EMAIL: + case GEN_DNS: + case GEN_URI: + ret = i2d_ASN1_IA5STRING(a->d.ia5, pp); + break; + + case GEN_IPADD: + ret = i2d_ASN1_OCTET_STRING(a->d.ip, pp); + break; + + case GEN_RID: + ret = i2d_ASN1_OBJECT(a->d.rid, pp); + break; + } + /* Replace TAG with IMPLICIT value */ + if(p) *p = (*p & V_ASN1_CONSTRUCTED) | a->type; + return ret; +} + +GENERAL_NAME *GENERAL_NAME_new() +{ + GENERAL_NAME *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, GENERAL_NAME); + ret->type = -1; + ret->d.ptr = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_GENERAL_NAME_NEW); +} + +GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp, + long length) +{ + unsigned char _tmp; + M_ASN1_D2I_vars(a,GENERAL_NAME *,GENERAL_NAME_new); + M_ASN1_D2I_Init(); + c.slen = length; + + _tmp = M_ASN1_next; + ret->type = _tmp & ~V_ASN1_CONSTRUCTED; + + switch(ret->type) { + /* Just put these in a "blob" for now */ + case GEN_OTHERNAME: + case GEN_X400: + case GEN_EDIPARTY: + M_ASN1_D2I_get_imp(ret->d.other, d2i_ASN1_TYPE,V_ASN1_SEQUENCE); + break; + + case GEN_EMAIL: + case GEN_DNS: + case GEN_URI: + M_ASN1_D2I_get_imp(ret->d.ia5, d2i_ASN1_IA5STRING, + V_ASN1_IA5STRING); + break; + + case GEN_DIRNAME: + M_ASN1_D2I_get_EXP_opt(ret->d.dirn, d2i_X509_NAME, 4); + break; + + case GEN_IPADD: + M_ASN1_D2I_get_imp(ret->d.ip, d2i_ASN1_OCTET_STRING, + V_ASN1_OCTET_STRING); + break; + + case GEN_RID: + M_ASN1_D2I_get_imp(ret->d.rid, d2i_ASN1_OBJECT,V_ASN1_OBJECT); + break; + + default: + c.error = ASN1_R_BAD_TAG; + goto err; + } + + c.slen = 0; + M_ASN1_D2I_Finish(a, GENERAL_NAME_free, ASN1_F_D2I_GENERAL_NAME); +} + +void GENERAL_NAME_free(GENERAL_NAME *a) +{ + if (a == NULL) return; + switch(a->type) { + case GEN_OTHERNAME: + case GEN_X400: + case GEN_EDIPARTY: + ASN1_TYPE_free(a->d.other); + break; + + case GEN_EMAIL: + case GEN_DNS: + case GEN_URI: + + ASN1_IA5STRING_free(a->d.ia5); + break; + + case GEN_DIRNAME: + X509_NAME_free(a->d.dirn); + break; + + case GEN_IPADD: + ASN1_OCTET_STRING_free(a->d.ip); + break; + + case GEN_RID: + ASN1_OBJECT_free(a->d.rid); + break; + + } + Free ((char *)a); +} + +/* Now the GeneralNames versions: a SEQUENCE OF GeneralName These are needed as + * an explicit functions. + */ + +STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new() +{ + return sk_GENERAL_NAME_new(NULL); +} + +void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a) +{ + sk_GENERAL_NAME_pop_free(a, GENERAL_NAME_free); +} + +STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a, + unsigned char **pp, long length) +{ +return d2i_ASN1_SET_OF_GENERAL_NAME(a, pp, length, d2i_GENERAL_NAME, + GENERAL_NAME_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); +} + +int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp) +{ +return i2d_ASN1_SET_OF_GENERAL_NAME(a, pp, i2d_GENERAL_NAME, V_ASN1_SEQUENCE, + V_ASN1_UNIVERSAL, IS_SEQUENCE); +} + +IMPLEMENT_STACK_OF(GENERAL_NAME) +IMPLEMENT_ASN1_SET_OF(GENERAL_NAME) + diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c new file mode 100644 index 0000000000..3446c5cd6a --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_ia5.c @@ -0,0 +1,116 @@ +/* v3_ia5.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + +#include +#include "cryptlib.h" +#include +#include +#include + +static ASN1_IA5STRING *ia5string_new(void); +static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5); +static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); +X509V3_EXT_METHOD v3_ns_ia5_list[] = { +EXT_IA5STRING(NID_netscape_base_url), +EXT_IA5STRING(NID_netscape_revocation_url), +EXT_IA5STRING(NID_netscape_ca_revocation_url), +EXT_IA5STRING(NID_netscape_renewal_url), +EXT_IA5STRING(NID_netscape_ca_policy_url), +EXT_IA5STRING(NID_netscape_ssl_server_name), +EXT_IA5STRING(NID_netscape_comment), +EXT_END +}; + + +static ASN1_IA5STRING *ia5string_new(void) +{ + return ASN1_IA5STRING_new(); +} + +static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, + ASN1_IA5STRING *ia5) +{ + char *tmp; + if(!ia5 || !ia5->length) return NULL; + tmp = Malloc(ia5->length + 1); + memcpy(tmp, ia5->data, ia5->length); + tmp[ia5->length] = 0; + return tmp; +} + +static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, char *str) +{ + ASN1_IA5STRING *ia5; + if(!str) { + X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT); + return NULL; + } + if(!(ia5 = ASN1_IA5STRING_new())) goto err; + if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str, + strlen(str))) { + ASN1_IA5STRING_free(ia5); + goto err; + } + return ia5; + err: + X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE); + return NULL; +} + diff --git a/src/lib/libcrypto/x509v3/v3_int.c b/src/lib/libcrypto/x509v3/v3_int.c new file mode 100644 index 0000000000..637dd5e128 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_int.c @@ -0,0 +1,79 @@ +/* v3_int.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include + +static ASN1_INTEGER *asn1_integer_new(void); + +X509V3_EXT_METHOD v3_crl_num = { +NID_crl_number, 0, +(X509V3_EXT_NEW)asn1_integer_new, +(X509V3_EXT_FREE)ASN1_STRING_free, +(X509V3_EXT_D2I)d2i_ASN1_INTEGER, +(X509V3_EXT_I2D)i2d_ASN1_INTEGER, +(X509V3_EXT_I2S)i2s_ASN1_INTEGER, +(X509V3_EXT_S2I)NULL, +NULL, NULL, NULL, NULL, NULL}; + + +static ASN1_INTEGER *asn1_integer_new(void) +{ + return ASN1_INTEGER_new(); +} diff --git a/src/lib/libcrypto/x509v3/v3_ku.c b/src/lib/libcrypto/x509v3/v3_ku.c deleted file mode 100644 index 87c7402f43..0000000000 --- a/src/lib/libcrypto/x509v3/v3_ku.c +++ /dev/null @@ -1,318 +0,0 @@ -/* crypto/x509v3/v3_ku.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include "stack.h" -#include "cryptlib.h" -#include "bio.h" -#include "asn1.h" -#include "objects.h" -#include "x509.h" - -X509_EXTENSION_METHOD X509v3_key_usage_method= - { - NID_key_usage, - ku_clear, - ex_get_bool, - ex_set_bool, - NULL, - NULL, - NULL, - NULL, - ku_a2i, - ku_i2a, - }; - -static void ku_clear(a) -X509_EXTENSION *a; - { - } - -static int ku_expand(a) -X509_EXTENSION *a; - { - ASN1_BIT_STRING *bs; - - if (a->argp == NULL) - { - bs=X509v3_unpack_string(NULL,V_ASN1_BIT_STRING,value); - if (bs == NULL) return(0); - a->argp=(char *)bs; - a->ex_free=ASN1_STRING_free; - } - return(1); - } - -static int ku_get_bool(a,num) -X509_EXTENSION *a; -int num; - { - int ret; - ASN1_BIT_STRING *bs; - - if ((a->argp == NULL) && !ku_expand(a)) - return(-1); - bs=(ASN1_BIT_STRING *)a->argp; - ret=ASN1_BIT_STRING_get_bit(bs,num); - return(ret); - } - -static int ku_set_bool(a,num,value) -X509_EXTENSION *a; -int num; -int value; - { - ASN1_BIT_STRING *a; - - if ((a->argp == NULL) && !ku_expand(a)) - return(0); - bs=(ASN1_BIT_STRING *)a->argp; - ret=ASN1_BIT_STRING_set_bit(bs,num,value); - } - -static int ku_a2i(bio,a,buf,len) -BIO *bio; -X509_EXTENSION *a; -char *buf; -int len; - { - get token - } - -static char ku_names[X509v3_N_KU_NUM]={ - X509v3_S_KU_digitalSignature, - X509v3_S_KU_nonRepudiation, - X509v3_S_KU_keyEncipherment, - X509v3_S_KU_dataEncipherment, - X509v3_S_KU_keyAgreement, - X509v3_S_KU_keyCertSign, - X509v3_S_KU_cRLSign, - X509v3_S_KU_encipherOnly, - X509v3_S_KU_decipherOnly, - }; - -static int ku_i2a(bio,a); -BIO *bio; -X509_EXTENSION *a; - { - int i,first=1; - char *c; - - for (i=0; i 0) - { - BIO_printf(bio,"%s%s",((first)?"":" "),ku_names[i]); - first=0; - } - } - } - -/***********************/ - -int X509v3_get_key_usage(x,ret) -STACK *x; -unsigned long *ret; - { - X509_EXTENSION *ext; - ASN1_STRING *st; - char *p; - int i; - - i=X509_get_ext_by_NID(x,NID_key_usage,-1); - if (i < 0) return(X509v3_KU_UNDEF); - ext=X509_get_ext(x,i); - st=X509v3_unpack_string(NULL,V_ASN1_BIT_STRING, - X509_EXTENSION_get_data(X509_get_ext(x,i))); - - p=ASN1_STRING_data(st); - if (ASN1_STRING_length(st) == 1) - i=p[0]; - else if (ASN1_STRING_length(st) == 2) - i=p[0]|(p[1]<<8); - else - i=0; - return(i); - } - -static struct - { - char *name; - unsigned int value; - } key_usage_data[] ={ - {"digitalSignature", X509v3_KU_DIGITAL_SIGNATURE}, - {"nonRepudiation", X509v3_KU_NON_REPUDIATION}, - {"keyEncipherment", X509v3_KU_KEY_ENCIPHERMENT}, - {"dataEncipherment", X509v3_KU_DATA_ENCIPHERMENT}, - {"keyAgreement", X509v3_KU_KEY_AGREEMENT}, - {"keyCertSign", X509v3_KU_KEY_CERT_SIGN}, - {"cRLSign", X509v3_KU_CRL_SIGN}, - {"encipherOnly", X509v3_KU_ENCIPHER_ONLY}, - {"decipherOnly", X509v3_KU_DECIPHER_ONLY}, - {NULL,0}, - }; - -#if 0 -static int a2i_key_usage(x,str,len) -X509 *x; -char *str; -int len; - { - return(X509v3_set_key_usage(x,a2i_X509v3_key_usage(str))); - } - -static int i2a_key_usage(bp,x) -BIO *bp; -X509 *x; - { - return(i2a_X509v3_key_usage(bp,X509v3_get_key_usage(x))); - } -#endif - -int i2a_X509v3_key_usage(bp,use) -BIO *bp; -unsigned int use; - { - int i=0,first=1; - - for (;;) - { - if (use | key_usage_data[i].value) - { - BIO_printf(bp,"%s%s",((first)?"":" "), - key_usage_data[i].name); - first=0; - } - } - return(1); - } - -unsigned int a2i_X509v3_key_usage(p) -char *p; - { - unsigned int ret=0; - char *q,*s; - int i,n; - - q=p; - for (;;) - { - while ((*q != '\0') && isalnum(*q)) - q++; - if (*q == '\0') break; - s=q++; - while (isalnum(*q)) - q++; - n=q-s; - i=0; - for (;;) - { - if (strncmp(key_usage_data[i].name,s,n) == 0) - { - ret|=key_usage_data[i].value; - break; - } - i++; - if (key_usage_data[i].name == NULL) - return(X509v3_KU_UNDEF); - } - } - return(ret); - } - -int X509v3_set_key_usage(x,use) -X509 *x; -unsigned int use; - { - ASN1_OCTET_STRING *os; - X509_EXTENSION *ext; - int i; - unsigned char data[4]; - - i=X509_get_ext_by_NID(x,NID_key_usage,-1); - if (i < 0) - { - i=X509_get_ext_count(x)+1; - if ((ext=X509_EXTENSION_new()) == NULL) return(0); - if (!X509_add_ext(x,ext,i)) - { - X509_EXTENSION_free(ext); - return(0); - } - } - else - ext=X509_get_ext(x,i); - - /* fill in 'ext' */ - os=X509_EXTENSION_get_data(ext); - - i=0; - if (use > 0) - { - i=1; - data[0]=use&0xff; - } - if (use > 0xff) - { - i=2; - data[1]=(use>>8)&0xff; - } - return((X509v3_pack_string(&os,V_ASN1_BIT_STRING,data,i) == NULL)?0:1); - } - diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c new file mode 100644 index 0000000000..a0aa5de794 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_lib.c @@ -0,0 +1,177 @@ +/* v3_lib.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* X509 v3 extension utilities */ + +#include +#include "cryptlib.h" +#include +#include + +static STACK *ext_list = NULL; + +static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b); +static void ext_list_free(X509V3_EXT_METHOD *ext); + +int X509V3_EXT_add(X509V3_EXT_METHOD *ext) +{ + if(!ext_list && !(ext_list = sk_new(ext_cmp))) { + X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE); + return 0; + } + if(!sk_push(ext_list, (char *)ext)) { + X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE); + return 0; + } + return 1; +} + +static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b) +{ + return ((*a)->ext_nid - (*b)->ext_nid); +} + +X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid) +{ + X509V3_EXT_METHOD tmp; + int idx; + tmp.ext_nid = nid; + if(!ext_list || (tmp.ext_nid < 0) ) return NULL; + idx = sk_find(ext_list, (char *)&tmp); + if(idx == -1) return NULL; + return (X509V3_EXT_METHOD *)sk_value(ext_list, idx); +} + +X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext) +{ + int nid; + if((nid = OBJ_obj2nid(ext->object)) == NID_undef) return NULL; + return X509V3_EXT_get_nid(nid); +} + + +int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist) +{ + for(;extlist->ext_nid!=-1;extlist++) + if(!X509V3_EXT_add(extlist)) return 0; + return 1; +} + +int X509V3_EXT_add_alias(int nid_to, int nid_from) +{ + X509V3_EXT_METHOD *ext, *tmpext; + if(!(ext = X509V3_EXT_get_nid(nid_from))) { + X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND); + return 0; + } + if(!(tmpext = (X509V3_EXT_METHOD *)Malloc(sizeof(X509V3_EXT_METHOD)))) { + X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE); + return 0; + } + *tmpext = *ext; + tmpext->ext_nid = nid_to; + tmpext->ext_flags |= X509V3_EXT_DYNAMIC; + return 1; +} + +void X509V3_EXT_cleanup(void) +{ + sk_pop_free(ext_list, ext_list_free); + ext_list = NULL; +} + +static void ext_list_free(X509V3_EXT_METHOD *ext) +{ + if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext); +} + +extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku; +extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet; +extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id; + +extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld; + +int X509V3_add_standard_extensions(void) +{ + X509V3_EXT_add_list(v3_ns_ia5_list); + X509V3_EXT_add_list(v3_alt); + X509V3_EXT_add(&v3_bcons); + X509V3_EXT_add(&v3_nscert); + X509V3_EXT_add(&v3_key_usage); + X509V3_EXT_add(&v3_ext_ku); + X509V3_EXT_add(&v3_skey_id); + X509V3_EXT_add(&v3_akey_id); + X509V3_EXT_add(&v3_pkey_usage_period); + X509V3_EXT_add(&v3_crl_num); + X509V3_EXT_add(&v3_sxnet); + X509V3_EXT_add(&v3_crl_reason); + X509V3_EXT_add(&v3_cpols); + X509V3_EXT_add(&v3_crld); + return 1; +} + +/* Return an extension internal structure */ + +void *X509V3_EXT_d2i(X509_EXTENSION *ext) +{ + X509V3_EXT_METHOD *method; + unsigned char *p; + if(!(method = X509V3_EXT_get(ext)) || !method->d2i) return NULL; + p = ext->value->data; + return method->d2i(NULL, &p, ext->value->length); +} + diff --git a/src/lib/libcrypto/x509v3/v3_pku.c b/src/lib/libcrypto/x509v3/v3_pku.c new file mode 100644 index 0000000000..c13e7d8f45 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_pku.c @@ -0,0 +1,151 @@ +/* v3_pku.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include +#include + +static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, PKEY_USAGE_PERIOD *usage, BIO *out, int indent); +/* +static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values); +*/ +X509V3_EXT_METHOD v3_pkey_usage_period = { +NID_private_key_usage_period, 0, +(X509V3_EXT_NEW)PKEY_USAGE_PERIOD_new, +(X509V3_EXT_FREE)PKEY_USAGE_PERIOD_free, +(X509V3_EXT_D2I)d2i_PKEY_USAGE_PERIOD, +(X509V3_EXT_I2D)i2d_PKEY_USAGE_PERIOD, +NULL, NULL, NULL, NULL, +(X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD, NULL, +NULL +}; + +int i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len_IMP_opt (a->notBefore, i2d_ASN1_GENERALIZEDTIME); + M_ASN1_I2D_len_IMP_opt (a->notAfter, i2d_ASN1_GENERALIZEDTIME); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put_IMP_opt (a->notBefore, i2d_ASN1_GENERALIZEDTIME, 0); + M_ASN1_I2D_put_IMP_opt (a->notAfter, i2d_ASN1_GENERALIZEDTIME, 1); + + M_ASN1_I2D_finish(); +} + +PKEY_USAGE_PERIOD *PKEY_USAGE_PERIOD_new(void) +{ + PKEY_USAGE_PERIOD *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, PKEY_USAGE_PERIOD); + ret->notBefore = NULL; + ret->notAfter = NULL; + return (ret); + M_ASN1_New_Error(ASN1_F_PKEY_USAGE_PERIOD_NEW); +} + +PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a, + unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,PKEY_USAGE_PERIOD *,PKEY_USAGE_PERIOD_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get_IMP_opt (ret->notBefore, d2i_ASN1_GENERALIZEDTIME, 0, + V_ASN1_GENERALIZEDTIME); + M_ASN1_D2I_get_IMP_opt (ret->notAfter, d2i_ASN1_GENERALIZEDTIME, 1, + V_ASN1_GENERALIZEDTIME); + M_ASN1_D2I_Finish(a, PKEY_USAGE_PERIOD_free, ASN1_F_D2I_PKEY_USAGE_PERIOD); +} + +void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a) +{ + if (a == NULL) return; + ASN1_GENERALIZEDTIME_free(a->notBefore); + ASN1_GENERALIZEDTIME_free(a->notAfter); + Free ((char *)a); +} + +static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, + PKEY_USAGE_PERIOD *usage, BIO *out, int indent) +{ + BIO_printf(out, "%*s", indent, ""); + if(usage->notBefore) { + BIO_write(out, "Not Before: ", 12); + ASN1_GENERALIZEDTIME_print(out, usage->notBefore); + if(usage->notAfter) BIO_write(out, ", ", 2); + } + if(usage->notAfter) { + BIO_write(out, "Not After: ", 11); + ASN1_GENERALIZEDTIME_print(out, usage->notAfter); + } + return 1; +} + +/* +static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(method, ctx, values) +X509V3_EXT_METHOD *method; +X509V3_CTX *ctx; +STACK_OF(CONF_VALUE) *values; +{ +return NULL; +} +*/ diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c new file mode 100644 index 0000000000..dc20c6bdba --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_prn.c @@ -0,0 +1,135 @@ +/* v3_prn.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* X509 v3 extension utilities */ + +#include +#include "cryptlib.h" +#include +#include + +/* Extension printing routines */ + +/* Print out a name+value stack */ + +void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml) +{ + int i; + CONF_VALUE *nval; + if(!val) return; + if(!ml || !sk_CONF_VALUE_num(val)) { + BIO_printf(out, "%*s", indent, ""); + if(!sk_CONF_VALUE_num(val)) BIO_puts(out, "\n"); + } + for(i = 0; i < sk_CONF_VALUE_num(val); i++) { + if(ml) BIO_printf(out, "%*s", indent, ""); + else if(i > 0) BIO_printf(out, ", "); + nval = sk_CONF_VALUE_value(val, i); + if(!nval->name) BIO_puts(out, nval->value); + else if(!nval->value) BIO_puts(out, nval->name); + else BIO_printf(out, "%s:%s", nval->name, nval->value); + if(ml) BIO_puts(out, "\n"); + } +} + +/* Main routine: print out a general extension */ + +int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent) +{ + char *ext_str = NULL, *value = NULL; + unsigned char *p; + X509V3_EXT_METHOD *method; + STACK_OF(CONF_VALUE) *nval = NULL; + int ok = 1; + if(!(method = X509V3_EXT_get(ext))) return 0; + p = ext->value->data; + if(!(ext_str = method->d2i(NULL, &p, ext->value->length))) return 0; + if(method->i2s) { + if(!(value = method->i2s(method, ext_str))) { + ok = 0; + goto err; + } + BIO_printf(out, "%*s%s", indent, "", value); + } else if(method->i2v) { + if(!(nval = method->i2v(method, ext_str, NULL))) { + ok = 0; + goto err; + } + X509V3_EXT_val_prn(out, nval, indent, + method->ext_flags & X509V3_EXT_MULTILINE); + } else if(method->i2r) { + if(!method->i2r(method, ext_str, out, indent)) ok = 0; + } else ok = 0; + + err: + sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); + if(value) Free(value); + method->ext_free(ext_str); + return ok; +} + +#ifndef NO_FP_API +int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent) +{ + BIO *bio_tmp; + int ret; + if(!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) return 0; + ret = X509V3_EXT_print(bio_tmp, ext, flag, indent); + BIO_free(bio_tmp); + return ret; +} +#endif diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c new file mode 100644 index 0000000000..fb3e36014d --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_skey.c @@ -0,0 +1,156 @@ +/* v3_skey.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + +#include +#include "cryptlib.h" +#include + +static ASN1_OCTET_STRING *octet_string_new(void); +static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); +X509V3_EXT_METHOD v3_skey_id = { +NID_subject_key_identifier, 0, +(X509V3_EXT_NEW)octet_string_new, +(X509V3_EXT_FREE)ASN1_STRING_free, +(X509V3_EXT_D2I)d2i_ASN1_OCTET_STRING, +(X509V3_EXT_I2D)i2d_ASN1_OCTET_STRING, +(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING, +(X509V3_EXT_S2I)s2i_skey_id, +NULL, NULL, NULL, NULL, NULL}; + + +static ASN1_OCTET_STRING *octet_string_new(void) +{ + return ASN1_OCTET_STRING_new(); +} + +char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, + ASN1_OCTET_STRING *oct) +{ + return hex_to_string(oct->data, oct->length); +} + +ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, char *str) +{ + ASN1_OCTET_STRING *oct; + long length; + + if(!(oct = ASN1_OCTET_STRING_new())) { + X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); + return NULL; + } + + if(!(oct->data = string_to_hex(str, &length))) { + ASN1_OCTET_STRING_free(oct); + return NULL; + } + + oct->length = length; + + return oct; + +} + +static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, char *str) +{ + ASN1_OCTET_STRING *oct; + ASN1_BIT_STRING *pk; + unsigned char pkey_dig[EVP_MAX_MD_SIZE]; + EVP_MD_CTX md; + unsigned int diglen; + + if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str); + + if(!(oct = ASN1_OCTET_STRING_new())) { + X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE); + return NULL; + } + + if(ctx && (ctx->flags == CTX_TEST)) return oct; + + if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) { + X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY); + goto err; + } + + if(ctx->subject_req) + pk = ctx->subject_req->req_info->pubkey->public_key; + else pk = ctx->subject_cert->cert_info->key->public_key; + + if(!pk) { + X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY); + goto err; + } + + EVP_DigestInit(&md, EVP_sha1()); + EVP_DigestUpdate(&md, pk->data, pk->length); + EVP_DigestFinal(&md, pkey_dig, &diglen); + + if(!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) { + X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE); + goto err; + } + + return oct; + + err: + ASN1_OCTET_STRING_free(oct); + return NULL; +} diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c new file mode 100644 index 0000000000..0687bb4e3d --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_sxnet.c @@ -0,0 +1,340 @@ +/* v3_sxnet.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +#include +#include "cryptlib.h" +#include +#include +#include +#include + +/* Support for Thawte strong extranet extension */ + +#define SXNET_TEST + +static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent); +#ifdef SXNET_TEST +static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *nval); +#endif +X509V3_EXT_METHOD v3_sxnet = { +NID_sxnet, X509V3_EXT_MULTILINE, +(X509V3_EXT_NEW)SXNET_new, +(X509V3_EXT_FREE)SXNET_free, +(X509V3_EXT_D2I)d2i_SXNET, +(X509V3_EXT_I2D)i2d_SXNET, +NULL, NULL, +NULL, +#ifdef SXNET_TEST +(X509V3_EXT_V2I)sxnet_v2i, +#else +NULL, +#endif +(X509V3_EXT_I2R)sxnet_i2r, +NULL, +NULL +}; + + +int i2d_SXNET(SXNET *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER); + M_ASN1_I2D_len_SEQUENCE_type (SXNETID, a->ids, i2d_SXNETID); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER); + M_ASN1_I2D_put_SEQUENCE_type (SXNETID, a->ids, i2d_SXNETID); + + M_ASN1_I2D_finish(); +} + +SXNET *SXNET_new(void) +{ + SXNET *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, SXNET); + M_ASN1_New(ret->version,ASN1_INTEGER_new); + M_ASN1_New(ret->ids,sk_SXNETID_new_null); + return (ret); + M_ASN1_New_Error(ASN1_F_SXNET_NEW); +} + +SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,SXNET *,SXNET_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER); + M_ASN1_D2I_get_seq_type (SXNETID, ret->ids, d2i_SXNETID, SXNETID_free); + M_ASN1_D2I_Finish(a, SXNET_free, ASN1_F_D2I_SXNET); +} + +void SXNET_free(SXNET *a) +{ + if (a == NULL) return; + ASN1_INTEGER_free(a->version); + sk_SXNETID_pop_free(a->ids, SXNETID_free); + Free (a); +} + +int i2d_SXNETID(SXNETID *a, unsigned char **pp) +{ + M_ASN1_I2D_vars(a); + + M_ASN1_I2D_len (a->zone, i2d_ASN1_INTEGER); + M_ASN1_I2D_len (a->user, i2d_ASN1_OCTET_STRING); + + M_ASN1_I2D_seq_total(); + + M_ASN1_I2D_put (a->zone, i2d_ASN1_INTEGER); + M_ASN1_I2D_put (a->user, i2d_ASN1_OCTET_STRING); + + M_ASN1_I2D_finish(); +} + +SXNETID *SXNETID_new(void) +{ + SXNETID *ret=NULL; + ASN1_CTX c; + M_ASN1_New_Malloc(ret, SXNETID); + ret->zone = NULL; + M_ASN1_New(ret->user,ASN1_OCTET_STRING_new); + return (ret); + M_ASN1_New_Error(ASN1_F_SXNETID_NEW); +} + +SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length) +{ + M_ASN1_D2I_vars(a,SXNETID *,SXNETID_new); + M_ASN1_D2I_Init(); + M_ASN1_D2I_start_sequence(); + M_ASN1_D2I_get(ret->zone, d2i_ASN1_INTEGER); + M_ASN1_D2I_get(ret->user, d2i_ASN1_OCTET_STRING); + M_ASN1_D2I_Finish(a, SXNETID_free, ASN1_F_D2I_SXNETID); +} + +void SXNETID_free(SXNETID *a) +{ + if (a == NULL) return; + ASN1_INTEGER_free(a->zone); + ASN1_OCTET_STRING_free(a->user); + Free (a); +} + +static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, + int indent) +{ + long v; + char *tmp; + SXNETID *id; + int i; + v = ASN1_INTEGER_get(sx->version); + BIO_printf(out, "%*sVersion: %d (0x%X)", indent, "", v + 1, v); + for(i = 0; i < sk_SXNETID_num(sx->ids); i++) { + id = sk_SXNETID_value(sx->ids, i); + tmp = i2s_ASN1_INTEGER(NULL, id->zone); + BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp); + Free(tmp); + ASN1_OCTET_STRING_print(out, id->user); + } + return 1; +} + +#ifdef SXNET_TEST + +/* NBB: this is used for testing only. It should *not* be used for anything + * else because it will just take static IDs from the configuration file and + * they should really be separate values for each user. + */ + + +static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, + STACK_OF(CONF_VALUE) *nval) +{ + CONF_VALUE *cnf; + SXNET *sx = NULL; + int i; + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { + cnf = sk_CONF_VALUE_value(nval, i); + if(!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1)) + return NULL; + } + return sx; +} + + +#endif + +/* Strong Extranet utility functions */ + +/* Add an id given the zone as an ASCII number */ + +int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, + int userlen) +{ + ASN1_INTEGER *izone = NULL; + if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) { + X509V3err(X509V3_F_SXNET_ADD_ASC,X509V3_R_ERROR_CONVERTING_ZONE); + return 0; + } + return SXNET_add_id_INTEGER(psx, izone, user, userlen); +} + +/* Add an id given the zone as an unsigned long */ + +int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, + int userlen) +{ + ASN1_INTEGER *izone = NULL; + if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { + X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE); + ASN1_INTEGER_free(izone); + return 0; + } + return SXNET_add_id_INTEGER(psx, izone, user, userlen); + +} + +/* Add an id given the zone as an ASN1_INTEGER. + * Note this version uses the passed integer and doesn't make a copy so don't + * free it up afterwards. + */ + +int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, + int userlen) +{ + SXNET *sx = NULL; + SXNETID *id = NULL; + if(!psx || !zone || !user) { + X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT); + return 0; + } + if(userlen == -1) userlen = strlen(user); + if(userlen > 64) { + X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG); + return 0; + } + if(!*psx) { + if(!(sx = SXNET_new())) goto err; + if(!ASN1_INTEGER_set(sx->version, 0)) goto err; + *psx = sx; + } else sx = *psx; + if(SXNET_get_id_INTEGER(sx, zone)) { + X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID); + return 0; + } + + if(!(id = SXNETID_new())) goto err; + if(userlen == -1) userlen = strlen(user); + + if(!ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err; + if(!sk_SXNETID_push(sx->ids, id)) goto err; + id->zone = zone; + return 1; + + err: + X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE); + SXNETID_free(id); + SXNET_free(sx); + *psx = NULL; + return 0; +} + +ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone) +{ + ASN1_INTEGER *izone = NULL; + ASN1_OCTET_STRING *oct; + if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) { + X509V3err(X509V3_F_SXNET_GET_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE); + return NULL; + } + oct = SXNET_get_id_INTEGER(sx, izone); + ASN1_INTEGER_free(izone); + return oct; +} + +ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone) +{ + ASN1_INTEGER *izone = NULL; + ASN1_OCTET_STRING *oct; + if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { + X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE); + ASN1_INTEGER_free(izone); + return NULL; + } + oct = SXNET_get_id_INTEGER(sx, izone); + ASN1_INTEGER_free(izone); + return oct; +} + +ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone) +{ + SXNETID *id; + int i; + for(i = 0; i < sk_SXNETID_num(sx->ids); i++) { + id = sk_SXNETID_value(sx->ids, i); + if(!ASN1_INTEGER_cmp(id->zone, zone)) return id->user; + } + return NULL; +} + +IMPLEMENT_STACK_OF(SXNETID) +IMPLEMENT_ASN1_SET_OF(SXNETID) diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c new file mode 100644 index 0000000000..40f71c71b4 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3_utl.c @@ -0,0 +1,418 @@ +/* v3_utl.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ +/* X509 v3 extension utilities */ + + +#include +#include +#include "cryptlib.h" +#include +#include + +static char *strip_spaces(char *name); + +/* Add a CONF_VALUE name value pair to stack */ + +int X509V3_add_value(const char *name, const char *value, + STACK_OF(CONF_VALUE) **extlist) +{ + CONF_VALUE *vtmp = NULL; + char *tname = NULL, *tvalue = NULL; + if(name && !(tname = BUF_strdup(name))) goto err; + if(value && !(tvalue = BUF_strdup(value))) goto err;; + if(!(vtmp = (CONF_VALUE *)Malloc(sizeof(CONF_VALUE)))) goto err; + if(!*extlist && !(*extlist = sk_CONF_VALUE_new(NULL))) goto err; + vtmp->section = NULL; + vtmp->name = tname; + vtmp->value = tvalue; + if(!sk_CONF_VALUE_push(*extlist, vtmp)) goto err; + return 1; + err: + X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE); + if(vtmp) Free(vtmp); + if(tname) Free(tname); + if(tvalue) Free(tvalue); + return 0; +} + +int X509V3_add_value_uchar(const char *name, const unsigned char *value, + STACK_OF(CONF_VALUE) **extlist) + { + return X509V3_add_value(name,(const char *)value,extlist); + } + +/* Free function for STACK_OF(CONF_VALUE) */ + +void X509V3_conf_free(CONF_VALUE *conf) +{ + if(!conf) return; + if(conf->name) Free(conf->name); + if(conf->value) Free(conf->value); + if(conf->section) Free(conf->section); + Free((char *)conf); +} + +int X509V3_add_value_bool(const char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist) +{ + if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist); + return X509V3_add_value(name, "FALSE", extlist); +} + +int X509V3_add_value_bool_nf(char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist) +{ + if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist); + return 1; +} + + +char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *a) +{ + BIGNUM *bntmp = NULL; + char *strtmp = NULL; + if(!a) return NULL; + if(!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) || + !(strtmp = BN_bn2dec(bntmp)) ) + X509V3err(X509V3_F_I2S_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); + BN_free(bntmp); + return strtmp; +} + +char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a) +{ + BIGNUM *bntmp = NULL; + char *strtmp = NULL; + if(!a) return NULL; + if(!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) || + !(strtmp = BN_bn2dec(bntmp)) ) + X509V3err(X509V3_F_I2S_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); + BN_free(bntmp); + return strtmp; +} + +ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value) +{ + BIGNUM *bn = NULL; + ASN1_INTEGER *aint; + bn = BN_new(); + if(!value) { + X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE); + return 0; + } + if(!BN_dec2bn(&bn, value)) { + X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR); + return 0; + } + + if(!(aint = BN_to_ASN1_INTEGER(bn, NULL))) { + X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_TO_ASN1_INTEGER_ERROR); + return 0; + } + BN_free(bn); + return aint; +} + +int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint, + STACK_OF(CONF_VALUE) **extlist) +{ + char *strtmp; + int ret; + if(!aint) return 1; + if(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0; + ret = X509V3_add_value(name, strtmp, extlist); + Free(strtmp); + return ret; +} + +int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool) +{ + char *btmp; + if(!(btmp = value->value)) goto err; + if(!strcmp(btmp, "TRUE") || !strcmp(btmp, "true") + || !strcmp(btmp, "Y") || !strcmp(btmp, "y") + || !strcmp(btmp, "YES") || !strcmp(btmp, "yes")) { + *asn1_bool = 0xff; + return 1; + } else if(!strcmp(btmp, "FALSE") || !strcmp(btmp, "false") + || !strcmp(btmp, "N") || !strcmp(btmp, "n") + || !strcmp(btmp, "NO") || !strcmp(btmp, "no")) { + *asn1_bool = 0; + return 1; + } + err: + X509V3err(X509V3_F_X509V3_GET_VALUE_BOOL,X509V3_R_INVALID_BOOLEAN_STRING); + X509V3_conf_err(value); + return 0; +} + +int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint) +{ + ASN1_INTEGER *itmp; + if(!(itmp = s2i_ASN1_INTEGER(NULL, value->value))) { + X509V3_conf_err(value); + return 0; + } + *aint = itmp; + return 1; +} + +#define HDR_NAME 1 +#define HDR_VALUE 2 + +/*#define DEBUG*/ + +STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line) +{ + char *p, *q, c; + char *ntmp, *vtmp; + STACK_OF(CONF_VALUE) *values = NULL; + char *linebuf; + int state; + /* We are going to modify the line so copy it first */ + linebuf = BUF_strdup(line); + state = HDR_NAME; + ntmp = NULL; + /* Go through all characters */ + for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) { + + switch(state) { + case HDR_NAME: + if(c == ':') { + state = HDR_VALUE; + *p = 0; + ntmp = strip_spaces(q); + if(!ntmp) { + X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME); + goto err; + } + q = p + 1; + } else if(c == ',') { + *p = 0; + ntmp = strip_spaces(q); + q = p + 1; +#ifdef DEBUG + printf("%s\n", ntmp); +#endif + if(!ntmp) { + X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME); + goto err; + } + X509V3_add_value(ntmp, NULL, &values); + } + break ; + + case HDR_VALUE: + if(c == ',') { + state = HDR_NAME; + *p = 0; + vtmp = strip_spaces(q); +#ifdef DEBUG + printf("%s\n", ntmp); +#endif + if(!vtmp) { + X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE); + goto err; + } + X509V3_add_value(ntmp, vtmp, &values); + ntmp = NULL; + q = p + 1; + } + + } + } + + if(state == HDR_VALUE) { + vtmp = strip_spaces(q); +#ifdef DEBUG + printf("%s=%s\n", ntmp, vtmp); +#endif + if(!vtmp) { + X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE); + goto err; + } + X509V3_add_value(ntmp, vtmp, &values); + } else { + ntmp = strip_spaces(q); +#ifdef DEBUG + printf("%s\n", ntmp); +#endif + if(!ntmp) { + X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME); + goto err; + } + X509V3_add_value(ntmp, NULL, &values); + } +Free(linebuf); +return values; + +err: +Free(linebuf); +sk_CONF_VALUE_pop_free(values, X509V3_conf_free); +return NULL; + +} + +/* Delete leading and trailing spaces from a string */ +static char *strip_spaces(char *name) +{ + char *p, *q; + /* Skip over leading spaces */ + p = name; + while(*p && isspace((unsigned char)*p)) p++; + if(!*p) return NULL; + q = p + strlen(p) - 1; + while((q != p) && isspace((unsigned char)*q)) q--; + if(p != q) q[1] = 0; + if(!*p) return NULL; + return p; +} + +/* hex string utilities */ + +/* Given a buffer of length 'len' return a Malloc'ed string with its + * hex representation + */ + +char *hex_to_string(unsigned char *buffer, long len) +{ + char *tmp, *q; + unsigned char *p; + int i; + static char hexdig[] = "0123456789ABCDEF"; + if(!buffer || !len) return NULL; + if(!(tmp = Malloc(len * 3 + 1))) { + X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE); + return NULL; + } + q = tmp; + for(i = 0, p = buffer; i < len; i++,p++) { + *q++ = hexdig[(*p >> 4) & 0xf]; + *q++ = hexdig[*p & 0xf]; + *q++ = ':'; + } + q[-1] = 0; + return tmp; +} + +/* Give a string of hex digits convert to + * a buffer + */ + +unsigned char *string_to_hex(char *str, long *len) +{ + unsigned char *hexbuf, *q; + unsigned char ch, cl, *p; + if(!str) { + X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_INVALID_NULL_ARGUMENT); + return NULL; + } + if(!(hexbuf = Malloc(strlen(str) >> 1))) goto err; + for(p = (unsigned char *)str, q = hexbuf; *p;) { + ch = *p++; + if(ch == ':') continue; + cl = *p++; + if(!cl) { + X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ODD_NUMBER_OF_DIGITS); + Free(hexbuf); + return NULL; + } + if(isupper(ch)) ch = tolower(ch); + if(isupper(cl)) cl = tolower(cl); + + if((ch >= '0') && (ch <= '9')) ch -= '0'; + else if ((ch >= 'a') && (ch <= 'f')) ch -= 'a' - 10; + else goto badhex; + + if((cl >= '0') && (cl <= '9')) cl -= '0'; + else if ((cl >= 'a') && (cl <= 'f')) cl -= 'a' - 10; + else goto badhex; + + *q++ = (ch << 4) | cl; + } + + if(len) *len = q - hexbuf; + + return hexbuf; + + err: + if(hexbuf) Free(hexbuf); + X509V3err(X509V3_F_STRING_TO_HEX,ERR_R_MALLOC_FAILURE); + return NULL; + + badhex: + Free(hexbuf); + X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ILLEGAL_HEX_DIGIT); + return NULL; + +} + +/* V2I name comparison function: returns zero if 'name' matches + * cmp or cmp.* + */ + +int name_cmp(const char *name, const char *cmp) +{ + int len, ret; + char c; + len = strlen(cmp); + if((ret = strncmp(name, cmp, len))) return ret; + c = name[len]; + if(!c || (c=='.')) return 0; + return 1; +} diff --git a/src/lib/libcrypto/x509v3/v3conf.c b/src/lib/libcrypto/x509v3/v3conf.c new file mode 100644 index 0000000000..21cf746f45 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3conf.c @@ -0,0 +1,128 @@ +/* v3conf.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + +#include +#include "cryptlib.h" +#include +#include +#include +#include +#include + +/* Test application to add extensions from a config file */ + +int main(int argc, char **argv) +{ + LHASH *conf; + X509 *cert; + FILE *inf; + char *conf_file; + int i; + int count; + X509_EXTENSION *ext; + X509V3_add_standard_extensions(); + ERR_load_crypto_strings(); + if(!argv[1]) { + fprintf(stderr, "Usage: v3conf cert.pem [file.cnf]\n"); + exit(1); + } + conf_file = argv[2]; + if(!conf_file) conf_file = "test.cnf"; + conf = CONF_load(NULL, "test.cnf", NULL); + if(!conf) { + fprintf(stderr, "Error opening Config file %s\n", conf_file); + ERR_print_errors_fp(stderr); + exit(1); + } + + inf = fopen(argv[1], "r"); + if(!inf) { + fprintf(stderr, "Can't open certificate file %s\n", argv[1]); + exit(1); + } + cert = PEM_read_X509(inf, NULL, NULL); + if(!cert) { + fprintf(stderr, "Error reading certificate file %s\n", argv[1]); + exit(1); + } + fclose(inf); + + sk_pop_free(cert->cert_info->extensions, X509_EXTENSION_free); + cert->cert_info->extensions = NULL; + + if(!X509V3_EXT_add_conf(conf, NULL, "test_section", cert)) { + fprintf(stderr, "Error adding extensions\n"); + ERR_print_errors_fp(stderr); + exit(1); + } + + count = X509_get_ext_count(cert); + printf("%d extensions\n", count); + for(i = 0; i < count; i++) { + ext = X509_get_ext(cert, i); + printf("%s", OBJ_nid2ln(OBJ_obj2nid(ext->object))); + if(ext->critical) printf(",critical:\n"); + else printf(":\n"); + X509V3_EXT_print_fp(stdout, ext, 0); + printf("\n"); + + } + return 0; +} + diff --git a/src/lib/libcrypto/x509v3/v3err.c b/src/lib/libcrypto/x509v3/v3err.c new file mode 100644 index 0000000000..50efa8d99d --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3err.c @@ -0,0 +1,171 @@ +/* crypto/x509v3/v3err.c */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file. + */ + +#include +#include +#include + +/* BEGIN ERROR CODES */ +#ifndef NO_ERR +static ERR_STRING_DATA X509V3_str_functs[]= + { +{ERR_PACK(0,X509V3_F_COPY_EMAIL,0), "COPY_EMAIL"}, +{ERR_PACK(0,X509V3_F_COPY_ISSUER,0), "COPY_ISSUER"}, +{ERR_PACK(0,X509V3_F_DO_EXT_CONF,0), "DO_EXT_CONF"}, +{ERR_PACK(0,X509V3_F_DO_EXT_I2D,0), "DO_EXT_I2D"}, +{ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"}, +{ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"}, +{ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"}, +{ERR_PACK(0,X509V3_F_NOTICE_SECTION,0), "NOTICE_SECTION"}, +{ERR_PACK(0,X509V3_F_NREF_NOS,0), "NREF_NOS"}, +{ERR_PACK(0,X509V3_F_POLICY_SECTION,0), "POLICY_SECTION"}, +{ERR_PACK(0,X509V3_F_R2I_CERTPOL,0), "R2I_CERTPOL"}, +{ERR_PACK(0,X509V3_F_S2I_ASN1_IA5STRING,0), "S2I_ASN1_IA5STRING"}, +{ERR_PACK(0,X509V3_F_S2I_ASN1_INTEGER,0), "s2i_ASN1_INTEGER"}, +{ERR_PACK(0,X509V3_F_S2I_ASN1_OCTET_STRING,0), "s2i_ASN1_OCTET_STRING"}, +{ERR_PACK(0,X509V3_F_S2I_ASN1_SKEY_ID,0), "S2I_ASN1_SKEY_ID"}, +{ERR_PACK(0,X509V3_F_S2I_S2I_SKEY_ID,0), "S2I_S2I_SKEY_ID"}, +{ERR_PACK(0,X509V3_F_STRING_TO_HEX,0), "string_to_hex"}, +{ERR_PACK(0,X509V3_F_SXNET_ADD_ASC,0), "SXNET_ADD_ASC"}, +{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_INTEGER,0), "SXNET_add_id_INTEGER"}, +{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_ULONG,0), "SXNET_add_id_ulong"}, +{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ASC,0), "SXNET_get_id_asc"}, +{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ULONG,0), "SXNET_get_id_ulong"}, +{ERR_PACK(0,X509V3_F_V2I_ASN1_BIT_STRING,0), "V2I_ASN1_BIT_STRING"}, +{ERR_PACK(0,X509V3_F_V2I_AUTHORITY_KEYID,0), "V2I_AUTHORITY_KEYID"}, +{ERR_PACK(0,X509V3_F_V2I_BASIC_CONSTRAINTS,0), "V2I_BASIC_CONSTRAINTS"}, +{ERR_PACK(0,X509V3_F_V2I_CRLD,0), "V2I_CRLD"}, +{ERR_PACK(0,X509V3_F_V2I_EXT_KU,0), "V2I_EXT_KU"}, +{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAME,0), "v2i_GENERAL_NAME"}, +{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAMES,0), "v2i_GENERAL_NAMES"}, +{ERR_PACK(0,X509V3_F_V3_GENERIC_EXTENSION,0), "V3_GENERIC_EXTENSION"}, +{ERR_PACK(0,X509V3_F_X509V3_ADD_VALUE,0), "X509V3_add_value"}, +{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD,0), "X509V3_EXT_add"}, +{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD_ALIAS,0), "X509V3_EXT_add_alias"}, +{ERR_PACK(0,X509V3_F_X509V3_EXT_CONF,0), "X509V3_EXT_conf"}, +{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"}, +{ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"}, +{ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"}, +{0,NULL} + }; + +static ERR_STRING_DATA X509V3_str_reasons[]= + { +{X509V3_R_BAD_IP_ADDRESS ,"bad ip address"}, +{X509V3_R_BAD_OBJECT ,"bad object"}, +{X509V3_R_BN_DEC2BN_ERROR ,"bn dec2bn error"}, +{X509V3_R_BN_TO_ASN1_INTEGER_ERROR ,"bn to asn1 integer error"}, +{X509V3_R_DUPLICATE_ZONE_ID ,"duplicate zone id"}, +{X509V3_R_ERROR_CONVERTING_ZONE ,"error converting zone"}, +{X509V3_R_ERROR_IN_EXTENSION ,"error in extension"}, +{X509V3_R_EXPECTED_A_SECTION_NAME ,"expected a section name"}, +{X509V3_R_EXTENSION_NAME_ERROR ,"extension name error"}, +{X509V3_R_EXTENSION_NOT_FOUND ,"extension not found"}, +{X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED,"extension setting not supported"}, +{X509V3_R_EXTENSION_VALUE_ERROR ,"extension value error"}, +{X509V3_R_ILLEGAL_HEX_DIGIT ,"illegal hex digit"}, +{X509V3_R_INVALID_BOOLEAN_STRING ,"invalid boolean string"}, +{X509V3_R_INVALID_EXTENSION_STRING ,"invalid extension string"}, +{X509V3_R_INVALID_NAME ,"invalid name"}, +{X509V3_R_INVALID_NULL_ARGUMENT ,"invalid null argument"}, +{X509V3_R_INVALID_NULL_NAME ,"invalid null name"}, +{X509V3_R_INVALID_NULL_VALUE ,"invalid null value"}, +{X509V3_R_INVALID_NUMBER ,"invalid number"}, +{X509V3_R_INVALID_NUMBERS ,"invalid numbers"}, +{X509V3_R_INVALID_OBJECT_IDENTIFIER ,"invalid object identifier"}, +{X509V3_R_INVALID_OPTION ,"invalid option"}, +{X509V3_R_INVALID_POLICY_IDENTIFIER ,"invalid policy identifier"}, +{X509V3_R_INVALID_SECTION ,"invalid section"}, +{X509V3_R_ISSUER_DECODE_ERROR ,"issuer decode error"}, +{X509V3_R_MISSING_VALUE ,"missing value"}, +{X509V3_R_NEED_ORGANIZATION_AND_NUMBERS ,"need organization and numbers"}, +{X509V3_R_NO_CONFIG_DATABASE ,"no config database"}, +{X509V3_R_NO_ISSUER_CERTIFICATE ,"no issuer certificate"}, +{X509V3_R_NO_ISSUER_DETAILS ,"no issuer details"}, +{X509V3_R_NO_POLICY_IDENTIFIER ,"no policy identifier"}, +{X509V3_R_NO_PUBLIC_KEY ,"no public key"}, +{X509V3_R_NO_SUBJECT_DETAILS ,"no subject details"}, +{X509V3_R_ODD_NUMBER_OF_DIGITS ,"odd number of digits"}, +{X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS ,"unable to get issuer details"}, +{X509V3_R_UNABLE_TO_GET_ISSUER_KEYID ,"unable to get issuer keyid"}, +{X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT ,"unknown bit string argument"}, +{X509V3_R_UNKNOWN_EXTENSION ,"unknown extension"}, +{X509V3_R_UNKNOWN_EXTENSION_NAME ,"unknown extension name"}, +{X509V3_R_UNKNOWN_OPTION ,"unknown option"}, +{X509V3_R_UNSUPPORTED_OPTION ,"unsupported option"}, +{X509V3_R_USER_TOO_LONG ,"user too long"}, +{0,NULL} + }; + +#endif + +void ERR_load_X509V3_strings(void) + { + static int init=1; + + if (init) + { + init=0; +#ifndef NO_ERR + ERR_load_strings(ERR_LIB_X509V3,X509V3_str_functs); + ERR_load_strings(ERR_LIB_X509V3,X509V3_str_reasons); +#endif + + } + } diff --git a/src/lib/libcrypto/x509v3/v3prin.c b/src/lib/libcrypto/x509v3/v3prin.c new file mode 100644 index 0000000000..ee798859f0 --- /dev/null +++ b/src/lib/libcrypto/x509v3/v3prin.c @@ -0,0 +1,101 @@ +/* v3prin.c */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + + + +#include +#include "cryptlib.h" +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + X509 *cert; + FILE *inf; + int i, count; + X509_EXTENSION *ext; + X509V3_add_standard_extensions(); + ERR_load_crypto_strings(); + if(!argv[1]) { + fprintf(stderr, "Usage v3prin cert.pem\n"); + exit(1); + } + if(!(inf = fopen(argv[1], "r"))) { + fprintf(stderr, "Can't open %s\n", argv[1]); + exit(1); + } + if(!(cert = PEM_read_X509(inf, NULL, NULL))) { + fprintf(stderr, "Can't read certificate %s\n", argv[1]); + ERR_print_errors_fp(stderr); + exit(1); + } + fclose(inf); + count = X509_get_ext_count(cert); + printf("%d extensions\n", count); + for(i = 0; i < count; i++) { + ext = X509_get_ext(cert, i); + printf("%s\n", OBJ_nid2ln(OBJ_obj2nid(ext->object))); + if(!X509V3_EXT_print_fp(stdout, ext, 0, 0)) ERR_print_errors_fp(stderr); + printf("\n"); + + } + return 0; +} diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h index d7945bc9cd..4eb04a5a89 100644 --- a/src/lib/libcrypto/x509v3/x509v3.h +++ b/src/lib/libcrypto/x509v3/x509v3.h @@ -1,87 +1,532 @@ -/* crypto/x509v3/x509v3.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* x509v3.h */ +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL + * project 1999. + */ +/* ==================================================================== + * Copyright (c) 1999 The OpenSSL Project. All rights reserved. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * */ -#define X509v3_N_KU_digitalSignature 0 -#define X509v3_N_KU_nonRepudiation 1 -#define X509v3_N_KU_keyEncipherment 2 -#define X509v3_N_KU_dataEncipherment 3 -#define X509v3_N_KU_keyAgreement 4 -#define X509v3_N_KU_keyCertSign 5 -#define X509v3_N_KU_cRLSign 6 -#define X509v3_N_KU_encipherOnly 7 -#define X509v3_N_KU_decipherOnly 8 -#define X509v3_N_KU_NUM 9 -#define X509v3_S_KU_digitalSignature "digitalSignature" -#define X509v3_S_KU_nonRepudiation "nonRepudiation" -#define X509v3_S_KU_keyEncipherment "keyEncipherment" -#define X509v3_S_KU_dataEncipherment "dataEncipherment" -#define X509v3_S_KU_keyAgreement "keyAgreement" -#define X509v3_S_KU_keyCertSign "keyCertSign" -#define X509v3_S_KU_cRLSign "cRLSign" -#define X509v3_S_KU_encipherOnly "encipherOnly" -#define X509v3_S_KU_decipherOnly "decipherOnly" - - -void X509_ex_clear(X509_EXTENSION *a); -int X509_ex_get_bool(X509_EXTENSION *a,int num); -int X509_ex_set_bool(X509_EXTENSION *a,int num,int value); -int X509_ex_get_str(X509_EXTENSION *a,int index,char **p,int *len); -int X509_ex_set_str(X509_EXTENSION *a,int oid,int index,char *p,int len); -char *X509_ex_get_struct(X509_EXTENSION *a,int oid,int index,char **p); -int X509_ex_set_struct(X509_EXTENSION *a,int index,char *p); -int a2i_X509_EXTENSION(BIO *bp,X509_EXTENSION *a,char *buf,int len); -int i2a_X509_EXTENSION(BIO *bp,X509_EXTENSION *a); +#ifndef HEADER_X509V3_H +#define HEADER_X509V3_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/* Forward reference */ +struct v3_ext_method; +struct v3_ext_ctx; + +/* Useful typedefs */ + +typedef void * (*X509V3_EXT_NEW)(void); +typedef void (*X509V3_EXT_FREE)(void *); +typedef void * (*X509V3_EXT_D2I)(void *, unsigned char ** , long); +typedef int (*X509V3_EXT_I2D)(void *, unsigned char **); +typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist); +typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values); +typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext); +typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str); +typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent); +typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str); + +/* V3 extension structure */ + +struct v3_ext_method { +int ext_nid; +int ext_flags; +X509V3_EXT_NEW ext_new; +X509V3_EXT_FREE ext_free; +X509V3_EXT_D2I d2i; +X509V3_EXT_I2D i2d; + +/* The following pair is used for string extensions */ +X509V3_EXT_I2S i2s; +X509V3_EXT_S2I s2i; + +/* The following pair is used for multi-valued extensions */ +X509V3_EXT_I2V i2v; +X509V3_EXT_V2I v2i; + +/* The following are used for raw extensions */ +X509V3_EXT_I2R i2r; +X509V3_EXT_R2I r2i; + +void *usr_data; /* Any extension specific data */ +}; + +typedef struct X509V3_CONF_METHOD_st { +char * (*get_string)(void *db, char *section, char *value); +STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section); +void (*free_string)(void *db, char * string); +void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section); +} X509V3_CONF_METHOD; + +/* Context specific info */ +struct v3_ext_ctx { +#define CTX_TEST 0x1 +int flags; +X509 *issuer_cert; +X509 *subject_cert; +X509_REQ *subject_req; +X509_CRL *crl; +X509V3_CONF_METHOD *db_meth; +void *db; +/* Maybe more here */ +}; + +typedef struct v3_ext_method X509V3_EXT_METHOD; +typedef struct v3_ext_ctx X509V3_CTX; + +/* ext_flags values */ +#define X509V3_EXT_DYNAMIC 0x1 +#define X509V3_EXT_CTX_DEP 0x2 +#define X509V3_EXT_MULTILINE 0x4 + +typedef struct BIT_STRING_BITNAME_st { +int bitnum; +const char *lname; +const char *sname; +} BIT_STRING_BITNAME; + +typedef BIT_STRING_BITNAME ENUMERATED_NAMES; + +typedef struct BASIC_CONSTRAINTS_st { +int ca; +ASN1_INTEGER *pathlen; +} BASIC_CONSTRAINTS; + + +typedef struct PKEY_USAGE_PERIOD_st { +ASN1_GENERALIZEDTIME *notBefore; +ASN1_GENERALIZEDTIME *notAfter; +} PKEY_USAGE_PERIOD; + +typedef struct GENERAL_NAME_st { + +#define GEN_OTHERNAME (0|V_ASN1_CONTEXT_SPECIFIC) +#define GEN_EMAIL (1|V_ASN1_CONTEXT_SPECIFIC) +#define GEN_DNS (2|V_ASN1_CONTEXT_SPECIFIC) +#define GEN_X400 (3|V_ASN1_CONTEXT_SPECIFIC) +#define GEN_DIRNAME (4|V_ASN1_CONTEXT_SPECIFIC) +#define GEN_EDIPARTY (5|V_ASN1_CONTEXT_SPECIFIC) +#define GEN_URI (6|V_ASN1_CONTEXT_SPECIFIC) +#define GEN_IPADD (7|V_ASN1_CONTEXT_SPECIFIC) +#define GEN_RID (8|V_ASN1_CONTEXT_SPECIFIC) + +int type; +union { + char *ptr; + ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */ + ASN1_OCTET_STRING *ip; /* iPAddress */ + X509_NAME *dirn; /* dirn */ + ASN1_OBJECT *rid; /* registeredID */ + ASN1_TYPE *other; /* otherName, ediPartyName, x400Address */ +} d; +} GENERAL_NAME; + +DECLARE_STACK_OF(GENERAL_NAME) +DECLARE_ASN1_SET_OF(GENERAL_NAME) + +typedef struct DIST_POINT_NAME_st { +/* NB: this is a CHOICE type and only one of these should be set */ +STACK_OF(GENERAL_NAME) *fullname; +X509_NAME *relativename; +} DIST_POINT_NAME; + +typedef struct DIST_POINT_st { +DIST_POINT_NAME *distpoint; +ASN1_BIT_STRING *reasons; +STACK_OF(GENERAL_NAME) *CRLissuer; +} DIST_POINT; + +DECLARE_STACK_OF(DIST_POINT) +DECLARE_ASN1_SET_OF(DIST_POINT) + +typedef struct AUTHORITY_KEYID_st { +ASN1_OCTET_STRING *keyid; +STACK_OF(GENERAL_NAME) *issuer; +ASN1_INTEGER *serial; +} AUTHORITY_KEYID; + +/* Strong extranet structures */ + +typedef struct SXNET_ID_st { + ASN1_INTEGER *zone; + ASN1_OCTET_STRING *user; +} SXNETID; + +DECLARE_STACK_OF(SXNETID) +DECLARE_ASN1_SET_OF(SXNETID) + +typedef struct SXNET_st { + ASN1_INTEGER *version; + STACK_OF(SXNETID) *ids; +} SXNET; + +typedef struct NOTICEREF_st { + ASN1_STRING *organization; + STACK *noticenos; +} NOTICEREF; + +typedef struct USERNOTICE_st { + NOTICEREF *noticeref; + ASN1_STRING *exptext; +} USERNOTICE; + +typedef struct POLICYQUALINFO_st { + ASN1_OBJECT *pqualid; + union { + ASN1_IA5STRING *cpsuri; + USERNOTICE *usernotice; + ASN1_TYPE *other; + } d; +} POLICYQUALINFO; + +DECLARE_STACK_OF(POLICYQUALINFO) +DECLARE_ASN1_SET_OF(POLICYQUALINFO) + +typedef struct POLICYINFO_st { + ASN1_OBJECT *policyid; + STACK_OF(POLICYQUALINFO) *qualifiers; +} POLICYINFO; + +DECLARE_STACK_OF(POLICYINFO) +DECLARE_ASN1_SET_OF(POLICYINFO) + +#define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \ +",name:", val->name, ",value:", val->value); + +#define X509V3_set_ctx_test(ctx) \ + X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST) +#define X509V3_set_ctx_nodb(ctx) ctx->db = NULL; + +#define EXT_BITSTRING(nid, table) { nid, 0, \ + (X509V3_EXT_NEW)asn1_bit_string_new, \ + (X509V3_EXT_FREE)ASN1_STRING_free, \ + (X509V3_EXT_D2I)d2i_ASN1_BIT_STRING, \ + (X509V3_EXT_I2D)i2d_ASN1_BIT_STRING, \ + NULL, NULL, \ + (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \ + (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \ + NULL, NULL, \ + (char *)table} + +#define EXT_IA5STRING(nid) { nid, 0, \ + (X509V3_EXT_NEW)ia5string_new, \ + (X509V3_EXT_FREE)ASN1_STRING_free, \ + (X509V3_EXT_D2I)d2i_ASN1_IA5STRING, \ + (X509V3_EXT_I2D)i2d_ASN1_IA5STRING, \ + (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \ + (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \ + NULL, NULL, NULL, NULL, \ + NULL} + +#define EXT_END { -1, 0, NULL, NULL, NULL, NULL, NULL, NULL, \ + NULL, NULL, NULL, NULL, \ + NULL} + +void ERR_load_X509V3_strings(void); +int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp); +BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length); +BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void); +void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a); + +int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp); +GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp, long length); +GENERAL_NAME *GENERAL_NAME_new(void); +void GENERAL_NAME_free(GENERAL_NAME *a); +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret); + +int i2d_SXNET(SXNET *a, unsigned char **pp); +SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length); +SXNET *SXNET_new(void); +void SXNET_free(SXNET *a); + +int i2d_SXNETID(SXNETID *a, unsigned char **pp); +SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length); +SXNETID *SXNETID_new(void); +void SXNETID_free(SXNETID *a); + +int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen); +int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen); +int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, char *user, int userlen); + +ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone); +ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone); +ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone); + +int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *a, unsigned char **pp); +AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp, long length); +AUTHORITY_KEYID *AUTHORITY_KEYID_new(void); +void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a); + +int i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **pp); +PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a, unsigned char **pp, long length); +PKEY_USAGE_PERIOD *PKEY_USAGE_PERIOD_new(void); +void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a); + +STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new(void); +void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a); +STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a, unsigned char **pp, long length); +int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp); +STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, + STACK_OF(GENERAL_NAME) *gen, STACK_OF(CONF_VALUE) *extlist); +STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method, + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); + +char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5); +ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); + +int i2d_ext_ku(STACK_OF(ASN1_OBJECT) *a, unsigned char **pp); +STACK_OF(ASN1_OBJECT) *d2i_ext_ku(STACK_OF(ASN1_OBJECT) **a, + unsigned char **pp, long length); +void ext_ku_free(STACK_OF(ASN1_OBJECT) *a); +STACK_OF(ASN1_OBJECT) *ext_ku_new(void); + +int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp); +STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void); +void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a); +STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a, unsigned char **pp, long length); + +int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp); +POLICYINFO *POLICYINFO_new(void); +POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp, long length); +void POLICYINFO_free(POLICYINFO *a); + +int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp); +POLICYQUALINFO *POLICYQUALINFO_new(void); +POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp, + long length); +void POLICYQUALINFO_free(POLICYQUALINFO *a); + +int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp); +USERNOTICE *USERNOTICE_new(void); +USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp, long length); +void USERNOTICE_free(USERNOTICE *a); + +int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp); +NOTICEREF *NOTICEREF_new(void); +NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp, long length); +void NOTICEREF_free(NOTICEREF *a); + +int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp); +STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void); +void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a); +STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a, + unsigned char **pp,long length); + +int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp); +DIST_POINT *DIST_POINT_new(void); +DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length); +void DIST_POINT_free(DIST_POINT *a); + +int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp); +DIST_POINT_NAME *DIST_POINT_NAME_new(void); +void DIST_POINT_NAME_free(DIST_POINT_NAME *a); +DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp, + long length); + +#ifdef HEADER_CONF_H +GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf); +void X509V3_conf_free(CONF_VALUE *val); +X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value); +X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value); +int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert); +int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl); +int X509V3_add_value_bool_nf(char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool); +int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint); +void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash); +#endif + +char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section); +STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section); +void X509V3_string_free(X509V3_CTX *ctx, char *str); +void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section); +void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject, + X509_REQ *req, X509_CRL *crl, int flags); + +int X509V3_add_value(const char *name, const char *value, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_uchar(const char *name, const unsigned char *value, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_bool(const char *name, int asn1_bool, + STACK_OF(CONF_VALUE) **extlist); +int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint, + STACK_OF(CONF_VALUE) **extlist); +char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint); +ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value); +char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint); +char * i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint); +int X509V3_EXT_add(X509V3_EXT_METHOD *ext); +int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist); +int X509V3_EXT_add_alias(int nid_to, int nid_from); +void X509V3_EXT_cleanup(void); + +X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext); +X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); +int X509V3_add_standard_extensions(void); +STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line); +void *X509V3_EXT_d2i(X509_EXTENSION *ext); +X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); + +char *hex_to_string(unsigned char *buffer, long len); +unsigned char *string_to_hex(char *str, long *len); +int name_cmp(const char *name, const char *cmp); + +void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, + int ml); +int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent); +int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); + +/* BEGIN ERROR CODES */ +/* The following lines are auto generated by the script mkerr.pl. Any changes + * made after this point may be overwritten when the script is next run. + */ + +/* Error codes for the X509V3 functions. */ + +/* Function codes. */ +#define X509V3_F_COPY_EMAIL 122 +#define X509V3_F_COPY_ISSUER 123 +#define X509V3_F_DO_EXT_CONF 124 +#define X509V3_F_DO_EXT_I2D 135 +#define X509V3_F_HEX_TO_STRING 111 +#define X509V3_F_I2S_ASN1_ENUMERATED 121 +#define X509V3_F_I2S_ASN1_INTEGER 120 +#define X509V3_F_NOTICE_SECTION 132 +#define X509V3_F_NREF_NOS 133 +#define X509V3_F_POLICY_SECTION 131 +#define X509V3_F_R2I_CERTPOL 130 +#define X509V3_F_S2I_ASN1_IA5STRING 100 +#define X509V3_F_S2I_ASN1_INTEGER 108 +#define X509V3_F_S2I_ASN1_OCTET_STRING 112 +#define X509V3_F_S2I_ASN1_SKEY_ID 114 +#define X509V3_F_S2I_S2I_SKEY_ID 115 +#define X509V3_F_STRING_TO_HEX 113 +#define X509V3_F_SXNET_ADD_ASC 125 +#define X509V3_F_SXNET_ADD_ID_INTEGER 126 +#define X509V3_F_SXNET_ADD_ID_ULONG 127 +#define X509V3_F_SXNET_GET_ID_ASC 128 +#define X509V3_F_SXNET_GET_ID_ULONG 129 +#define X509V3_F_V2I_ASN1_BIT_STRING 101 +#define X509V3_F_V2I_AUTHORITY_KEYID 119 +#define X509V3_F_V2I_BASIC_CONSTRAINTS 102 +#define X509V3_F_V2I_CRLD 134 +#define X509V3_F_V2I_EXT_KU 103 +#define X509V3_F_V2I_GENERAL_NAME 117 +#define X509V3_F_V2I_GENERAL_NAMES 118 +#define X509V3_F_V3_GENERIC_EXTENSION 116 +#define X509V3_F_X509V3_ADD_VALUE 105 +#define X509V3_F_X509V3_EXT_ADD 104 +#define X509V3_F_X509V3_EXT_ADD_ALIAS 106 +#define X509V3_F_X509V3_EXT_CONF 107 +#define X509V3_F_X509V3_EXT_I2D 136 +#define X509V3_F_X509V3_GET_VALUE_BOOL 110 +#define X509V3_F_X509V3_PARSE_LIST 109 + +/* Reason codes. */ +#define X509V3_R_BAD_IP_ADDRESS 118 +#define X509V3_R_BAD_OBJECT 119 +#define X509V3_R_BN_DEC2BN_ERROR 100 +#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101 +#define X509V3_R_DUPLICATE_ZONE_ID 133 +#define X509V3_R_ERROR_CONVERTING_ZONE 131 +#define X509V3_R_ERROR_IN_EXTENSION 128 +#define X509V3_R_EXPECTED_A_SECTION_NAME 137 +#define X509V3_R_EXTENSION_NAME_ERROR 115 +#define X509V3_R_EXTENSION_NOT_FOUND 102 +#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103 +#define X509V3_R_EXTENSION_VALUE_ERROR 116 +#define X509V3_R_ILLEGAL_HEX_DIGIT 113 +#define X509V3_R_INVALID_BOOLEAN_STRING 104 +#define X509V3_R_INVALID_EXTENSION_STRING 105 +#define X509V3_R_INVALID_NAME 106 +#define X509V3_R_INVALID_NULL_ARGUMENT 107 +#define X509V3_R_INVALID_NULL_NAME 108 +#define X509V3_R_INVALID_NULL_VALUE 109 +#define X509V3_R_INVALID_NUMBER 140 +#define X509V3_R_INVALID_NUMBERS 141 +#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110 +#define X509V3_R_INVALID_OPTION 138 +#define X509V3_R_INVALID_POLICY_IDENTIFIER 134 +#define X509V3_R_INVALID_SECTION 135 +#define X509V3_R_ISSUER_DECODE_ERROR 126 +#define X509V3_R_MISSING_VALUE 124 +#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142 +#define X509V3_R_NO_CONFIG_DATABASE 136 +#define X509V3_R_NO_ISSUER_CERTIFICATE 121 +#define X509V3_R_NO_ISSUER_DETAILS 127 +#define X509V3_R_NO_POLICY_IDENTIFIER 139 +#define X509V3_R_NO_PUBLIC_KEY 114 +#define X509V3_R_NO_SUBJECT_DETAILS 125 +#define X509V3_R_ODD_NUMBER_OF_DIGITS 112 +#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122 +#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123 +#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111 +#define X509V3_R_UNKNOWN_EXTENSION 129 +#define X509V3_R_UNKNOWN_EXTENSION_NAME 130 +#define X509V3_R_UNKNOWN_OPTION 120 +#define X509V3_R_UNSUPPORTED_OPTION 117 +#define X509V3_R_USER_TOO_LONG 132 + +#ifdef __cplusplus +} +#endif +#endif + -- cgit v1.2.3-55-g6feb