summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r--src/lib/libcrypto/Attic/Makefile308
-rw-r--r--src/lib/libcrypto/Makefile.ssl140
-rw-r--r--src/lib/libcrypto/asn1/Makefile.ssl1038
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c78
-rw-r--r--src/lib/libcrypto/asn1/a_bmp.c19
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c15
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c44
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c18
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c14
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c7
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c326
-rw-r--r--src/lib/libcrypto/asn1/a_gentm.c224
-rw-r--r--src/lib/libcrypto/asn1/a_hdr.c27
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c14
-rw-r--r--src/lib/libcrypto/asn1/a_int.c215
-rw-r--r--src/lib/libcrypto/asn1/a_meth.c8
-rw-r--r--src/lib/libcrypto/asn1/a_object.c139
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c17
-rw-r--r--src/lib/libcrypto/asn1/a_print.c70
-rw-r--r--src/lib/libcrypto/asn1/a_set.c112
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c28
-rw-r--r--src/lib/libcrypto/asn1/a_time.c123
-rw-r--r--src/lib/libcrypto/asn1/a_type.c91
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c98
-rw-r--r--src/lib/libcrypto/asn1/a_utf8.c (renamed from src/lib/libcrypto/bn/bn_mod.c)46
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c23
-rw-r--r--src/lib/libcrypto/asn1/a_vis.c (renamed from src/lib/libcrypto/rc4/rc4_locl.org)37
-rw-r--r--src/lib/libcrypto/asn1/asn1.err182
-rw-r--r--src/lib/libcrypto/asn1/asn1.h606
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c357
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c121
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h355
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c84
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c145
-rw-r--r--src/lib/libcrypto/asn1/d2i_dhp.c23
-rw-r--r--src/lib/libcrypto/asn1/d2i_dsap.c25
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c17
-rw-r--r--src/lib/libcrypto/asn1/d2i_pu.c17
-rw-r--r--src/lib/libcrypto/asn1/d2i_r_pr.c24
-rw-r--r--src/lib/libcrypto/asn1/d2i_r_pu.c23
-rw-r--r--src/lib/libcrypto/asn1/d2i_s_pr.c24
-rw-r--r--src/lib/libcrypto/asn1/d2i_s_pu.c25
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c38
-rw-r--r--src/lib/libcrypto/asn1/f.c4
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c (renamed from src/lib/libcrypto/bn/bn_sub.c)223
-rw-r--r--src/lib/libcrypto/asn1/f_int.c25
-rw-r--r--src/lib/libcrypto/asn1/f_string.c26
-rw-r--r--src/lib/libcrypto/asn1/i2d_dhp.c24
-rw-r--r--src/lib/libcrypto/asn1/i2d_dsap.c16
-rw-r--r--src/lib/libcrypto/asn1/i2d_pr.c10
-rw-r--r--src/lib/libcrypto/asn1/i2d_pu.c10
-rw-r--r--src/lib/libcrypto/asn1/i2d_r_pr.c19
-rw-r--r--src/lib/libcrypto/asn1/i2d_r_pu.c20
-rw-r--r--src/lib/libcrypto/asn1/i2d_s_pr.c19
-rw-r--r--src/lib/libcrypto/asn1/i2d_s_pu.c22
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c66
-rw-r--r--src/lib/libcrypto/asn1/nsseq.c118
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c156
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c274
-rw-r--r--src/lib/libcrypto/asn1/p7_dgst.c25
-rw-r--r--src/lib/libcrypto/asn1/p7_enc.c25
-rw-r--r--src/lib/libcrypto/asn1/p7_enc_c.c28
-rw-r--r--src/lib/libcrypto/asn1/p7_evp.c38
-rw-r--r--src/lib/libcrypto/asn1/p7_i_s.c25
-rw-r--r--src/lib/libcrypto/asn1/p7_lib.c42
-rw-r--r--src/lib/libcrypto/asn1/p7_recip.c29
-rw-r--r--src/lib/libcrypto/asn1/p7_s_e.c81
-rw-r--r--src/lib/libcrypto/asn1/p7_signd.c69
-rw-r--r--src/lib/libcrypto/asn1/p7_signi.c51
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c129
-rw-r--r--src/lib/libcrypto/asn1/pkcs8.c23
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c166
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c71
-rw-r--r--src/lib/libcrypto/asn1/t_req.c36
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c150
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c28
-rw-r--r--src/lib/libcrypto/asn1/x_attrib.c59
-rw-r--r--src/lib/libcrypto/asn1/x_cinf.c56
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c175
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c28
-rw-r--r--src/lib/libcrypto/asn1/x_info.c14
-rw-r--r--src/lib/libcrypto/asn1/x_name.c96
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c27
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c44
-rw-r--r--src/lib/libcrypto/asn1/x_req.c61
-rw-r--r--src/lib/libcrypto/asn1/x_sig.c23
-rw-r--r--src/lib/libcrypto/asn1/x_spki.c43
-rw-r--r--src/lib/libcrypto/asn1/x_val.c43
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c33
-rw-r--r--src/lib/libcrypto/bf/Makefile.ssl45
-rw-r--r--src/lib/libcrypto/bf/Makefile.uni20
-rw-r--r--src/lib/libcrypto/bf/asm/bf-586.pl4
-rw-r--r--src/lib/libcrypto/bf/asm/bf-686.pl1
-rw-r--r--src/lib/libcrypto/bf/asm/bx86unix.cpp976
-rw-r--r--src/lib/libcrypto/bf/bf_cbc.c11
-rw-r--r--src/lib/libcrypto/bf/bf_cfb64.c12
-rw-r--r--src/lib/libcrypto/bf/bf_ecb.c14
-rw-r--r--src/lib/libcrypto/bf/bf_enc.c93
-rw-r--r--src/lib/libcrypto/bf/bf_locl.h (renamed from src/lib/libcrypto/bf/bf_locl.org)137
-rw-r--r--src/lib/libcrypto/bf/bf_ofb64.c11
-rw-r--r--src/lib/libcrypto/bf/bf_opts.c61
-rw-r--r--src/lib/libcrypto/bf/bf_skey.c7
-rw-r--r--src/lib/libcrypto/bf/bfs.cpp2
-rw-r--r--src/lib/libcrypto/bf/bfspeed.c59
-rw-r--r--src/lib/libcrypto/bf/bftest.c46
-rw-r--r--src/lib/libcrypto/bf/blowfish.h45
-rw-r--r--src/lib/libcrypto/bio/Makefile.ssl170
-rw-r--r--src/lib/libcrypto/bio/b_dump.c13
-rw-r--r--src/lib/libcrypto/bio/b_print.c19
-rw-r--r--src/lib/libcrypto/bio/b_sock.c319
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c49
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c50
-rw-r--r--src/lib/libcrypto/bio/bf_null.c48
-rw-r--r--src/lib/libcrypto/bio/bio.err46
-rw-r--r--src/lib/libcrypto/bio/bio.h343
-rw-r--r--src/lib/libcrypto/bio/bio_cb.c13
-rw-r--r--src/lib/libcrypto/bio/bio_err.c131
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c147
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c132
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c588
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c146
-rw-r--r--src/lib/libcrypto/bio/bss_file.c60
-rw-r--r--src/lib/libcrypto/bio/bss_log.c232
-rw-r--r--src/lib/libcrypto/bio/bss_mem.c59
-rw-r--r--src/lib/libcrypto/bio/bss_null.c46
-rw-r--r--src/lib/libcrypto/bio/bss_rtcp.c56
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c118
-rw-r--r--src/lib/libcrypto/bn/Makefile.ssl215
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.s1860
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.s.works533
-rw-r--r--src/lib/libcrypto/bn/asm/bn-586.pl84
-rw-r--r--src/lib/libcrypto/bn/asm/bn-alpha.pl571
-rw-r--r--src/lib/libcrypto/bn/asm/bn-win32.asm1441
-rw-r--r--src/lib/libcrypto/bn/asm/bn86unix.cpp752
-rw-r--r--src/lib/libcrypto/bn/asm/ca.pl33
-rw-r--r--src/lib/libcrypto/bn/asm/co-586.pl286
-rw-r--r--src/lib/libcrypto/bn/asm/co-alpha.pl116
-rw-r--r--src/lib/libcrypto/bn/asm/mips1.s539
-rw-r--r--src/lib/libcrypto/bn/asm/mips3.s2138
-rw-r--r--src/lib/libcrypto/bn/asm/sparc.s462
-rw-r--r--src/lib/libcrypto/bn/asm/sparcv8.S1458
-rw-r--r--src/lib/libcrypto/bn/asm/sparcv8plus.S1535
-rw-r--r--src/lib/libcrypto/bn/asm/vms.mar6695
-rw-r--r--src/lib/libcrypto/bn/asm/x86.pl28
-rw-r--r--src/lib/libcrypto/bn/asm/x86w16.asm6
-rw-r--r--src/lib/libcrypto/bn/asm/x86w32.asm34
-rw-r--r--src/lib/libcrypto/bn/bn.err27
-rw-r--r--src/lib/libcrypto/bn/bn.h (renamed from src/lib/libcrypto/bn/bn.org)337
-rw-r--r--src/lib/libcrypto/bn/bn.mul19
-rw-r--r--src/lib/libcrypto/bn/bn_add.c194
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c802
-rw-r--r--src/lib/libcrypto/bn/bn_blind.c43
-rw-r--r--src/lib/libcrypto/bn/bn_comba.c345
-rw-r--r--src/lib/libcrypto/bn/bn_div.c180
-rw-r--r--src/lib/libcrypto/bn/bn_err.c123
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c210
-rw-r--r--src/lib/libcrypto/bn/bn_exp2.c195
-rw-r--r--src/lib/libcrypto/bn/bn_gcd.c53
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h107
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c492
-rw-r--r--src/lib/libcrypto/bn/bn_m.c169
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c441
-rw-r--r--src/lib/libcrypto/bn/bn_mpi.c11
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c753
-rw-r--r--src/lib/libcrypto/bn/bn_mulw.c366
-rw-r--r--src/lib/libcrypto/bn/bn_opts.c324
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c126
-rw-r--r--src/lib/libcrypto/bn/bn_prime.pl2
-rw-r--r--src/lib/libcrypto/bn/bn_print.c30
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c10
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c178
-rw-r--r--src/lib/libcrypto/bn/bn_shift.c18
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c205
-rw-r--r--src/lib/libcrypto/bn/bn_word.c30
-rw-r--r--src/lib/libcrypto/bn/bnspeed.c67
-rw-r--r--src/lib/libcrypto/bn/bntest.c621
-rw-r--r--src/lib/libcrypto/bn/comba.pl285
-rw-r--r--src/lib/libcrypto/bn/d.c72
-rw-r--r--src/lib/libcrypto/bn/exp.c60
-rw-r--r--src/lib/libcrypto/bn/expspeed.c55
-rw-r--r--src/lib/libcrypto/bn/exptest.c60
-rw-r--r--src/lib/libcrypto/bn/new23
-rw-r--r--src/lib/libcrypto/bn/test.c241
-rw-r--r--src/lib/libcrypto/bn/todo3
-rw-r--r--src/lib/libcrypto/bn/vms-helper.c66
-rw-r--r--src/lib/libcrypto/buffer/Makefile.ssl44
-rw-r--r--src/lib/libcrypto/buffer/buf_err.c123
-rw-r--r--src/lib/libcrypto/buffer/buffer.c25
-rw-r--r--src/lib/libcrypto/buffer/buffer.err9
-rw-r--r--src/lib/libcrypto/buffer/buffer.h21
-rw-r--r--src/lib/libcrypto/cast/Makefile.ssl51
-rw-r--r--src/lib/libcrypto/cast/Makefile.uni3
-rw-r--r--src/lib/libcrypto/cast/asm/c-win32.asm117
-rw-r--r--src/lib/libcrypto/cast/asm/cast-586.pl267
-rw-r--r--src/lib/libcrypto/cast/asm/cx86unix.cpp1010
-rw-r--r--src/lib/libcrypto/cast/c_cfb64.c25
-rw-r--r--src/lib/libcrypto/cast/c_ecb.c14
-rw-r--r--src/lib/libcrypto/cast/c_enc.c43
-rw-r--r--src/lib/libcrypto/cast/c_ofb64.c16
-rw-r--r--src/lib/libcrypto/cast/c_skey.c11
-rw-r--r--src/lib/libcrypto/cast/cast.h36
-rw-r--r--src/lib/libcrypto/cast/cast_lcl.h20
-rw-r--r--src/lib/libcrypto/cast/cast_s.h16
-rw-r--r--src/lib/libcrypto/cast/cast_spd.c59
-rw-r--r--src/lib/libcrypto/cast/castopts.c61
-rw-r--r--src/lib/libcrypto/cast/casts.cpp2
-rw-r--r--src/lib/libcrypto/cast/casttest.c183
-rw-r--r--src/lib/libcrypto/conf/Makefile.ssl49
-rw-r--r--src/lib/libcrypto/conf/cnf_save.c7
-rw-r--r--src/lib/libcrypto/conf/conf.c211
-rw-r--r--src/lib/libcrypto/conf/conf.err12
-rw-r--r--src/lib/libcrypto/conf/conf.h32
-rw-r--r--src/lib/libcrypto/conf/conf_err.c120
-rw-r--r--src/lib/libcrypto/conf/conf_lcl.h14
-rw-r--r--src/lib/libcrypto/conf/keysets.pl2
-rw-r--r--src/lib/libcrypto/conf/test.c5
-rw-r--r--src/lib/libcrypto/cpt_err.c122
-rw-r--r--src/lib/libcrypto/cryptlib.c85
-rw-r--r--src/lib/libcrypto/cryptlib.h34
-rw-r--r--src/lib/libcrypto/crypto-lib.com1218
-rw-r--r--src/lib/libcrypto/crypto.c575
-rw-r--r--src/lib/libcrypto/crypto.err8
-rw-r--r--src/lib/libcrypto/crypto.h188
-rw-r--r--src/lib/libcrypto/cversion.c39
-rw-r--r--src/lib/libcrypto/date.h1
-rw-r--r--src/lib/libcrypto/des/Makefile.ssl126
-rw-r--r--src/lib/libcrypto/des/Makefile.uni20
-rw-r--r--src/lib/libcrypto/des/VERSION1
-rw-r--r--src/lib/libcrypto/des/asm/crypt586.pl4
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl4
-rw-r--r--src/lib/libcrypto/des/asm/des686.pl2
-rw-r--r--src/lib/libcrypto/des/asm/desboth.pl8
-rw-r--r--src/lib/libcrypto/des/asm/dx86unix.cpp3202
-rw-r--r--src/lib/libcrypto/des/asm/yx86unix.cpp976
-rw-r--r--src/lib/libcrypto/des/cbc3_enc.c12
-rw-r--r--src/lib/libcrypto/des/cbc_cksm.c16
-rw-r--r--src/lib/libcrypto/des/cbc_enc.c78
-rw-r--r--src/lib/libcrypto/des/cfb64ede.c36
-rw-r--r--src/lib/libcrypto/des/cfb64enc.c27
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c14
-rw-r--r--src/lib/libcrypto/des/des-lib.com1003
-rw-r--r--src/lib/libcrypto/des/des.c121
-rw-r--r--src/lib/libcrypto/des/des.h249
-rw-r--r--src/lib/libcrypto/des/des.org301
-rw-r--r--src/lib/libcrypto/des/des.pl2
-rw-r--r--src/lib/libcrypto/des/des3s.cpp2
-rw-r--r--src/lib/libcrypto/des/des_enc.c140
-rw-r--r--src/lib/libcrypto/des/des_locl.h (renamed from src/lib/libcrypto/des/des_locl.org)172
-rw-r--r--src/lib/libcrypto/des/des_opts.c62
-rw-r--r--src/lib/libcrypto/des/des_ver.h5
-rw-r--r--src/lib/libcrypto/des/dess.cpp2
-rw-r--r--src/lib/libcrypto/des/destest.c295
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c15
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c24
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c197
-rw-r--r--src/lib/libcrypto/des/ede_enc.c190
-rw-r--r--src/lib/libcrypto/des/enc_read.c84
-rw-r--r--src/lib/libcrypto/des/enc_writ.c62
-rw-r--r--src/lib/libcrypto/des/fcrypt_b.c9
-rw-r--r--src/lib/libcrypto/des/ncbc_enc.c41
-rw-r--r--src/lib/libcrypto/des/ofb64ede.c27
-rw-r--r--src/lib/libcrypto/des/ofb64enc.c22
-rw-r--r--src/lib/libcrypto/des/ofb_enc.c13
-rw-r--r--src/lib/libcrypto/des/pcbc_enc.c18
-rw-r--r--src/lib/libcrypto/des/qud_cksm.c16
-rw-r--r--src/lib/libcrypto/des/rand_key.c22
-rw-r--r--src/lib/libcrypto/des/ranlib.sh23
-rw-r--r--src/lib/libcrypto/des/read2pwd.c12
-rw-r--r--src/lib/libcrypto/des/read_pwd.c145
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c23
-rw-r--r--src/lib/libcrypto/des/rpw.c10
-rw-r--r--src/lib/libcrypto/des/set_key.c36
-rw-r--r--src/lib/libcrypto/des/shifts.pl2
-rw-r--r--src/lib/libcrypto/des/speed.c77
-rw-r--r--src/lib/libcrypto/des/spr.h2
-rw-r--r--src/lib/libcrypto/des/str2key.c34
-rw-r--r--src/lib/libcrypto/des/supp.c8
-rw-r--r--src/lib/libcrypto/des/testdes.pl2
-rw-r--r--src/lib/libcrypto/des/vms.com90
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c56
-rw-r--r--src/lib/libcrypto/dh/Makefile.ssl66
-rw-r--r--src/lib/libcrypto/dh/dh.err12
-rw-r--r--src/lib/libcrypto/dh/dh.h44
-rw-r--r--src/lib/libcrypto/dh/dh_check.c8
-rw-r--r--src/lib/libcrypto/dh/dh_err.c118
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c18
-rw-r--r--src/lib/libcrypto/dh/dh_key.c52
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c19
-rw-r--r--src/lib/libcrypto/dh/dhtest.c36
-rw-r--r--src/lib/libcrypto/dh/p1024.c8
-rw-r--r--src/lib/libcrypto/dh/p192.c8
-rw-r--r--src/lib/libcrypto/dh/p512.c8
-rw-r--r--src/lib/libcrypto/dsa/Makefile.ssl91
-rw-r--r--src/lib/libcrypto/dsa/dsa.err15
-rw-r--r--src/lib/libcrypto/dsa/dsa.h80
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c96
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c123
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c109
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c14
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c59
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c152
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c140
-rw-r--r--src/lib/libcrypto/dsa/dsagen.c5
-rw-r--r--src/lib/libcrypto/dsa/dsatest.c52
-rw-r--r--src/lib/libcrypto/ebcdic.h17
-rw-r--r--src/lib/libcrypto/err/Makefile.ssl60
-rw-r--r--src/lib/libcrypto/err/err.c185
-rw-r--r--src/lib/libcrypto/err/err.h82
-rw-r--r--src/lib/libcrypto/err/err_all.c34
-rw-r--r--src/lib/libcrypto/err/err_code.pl105
-rw-r--r--src/lib/libcrypto/err/err_genc.pl198
-rw-r--r--src/lib/libcrypto/err/err_prn.c20
-rw-r--r--src/lib/libcrypto/err/error.err13
-rw-r--r--src/lib/libcrypto/err/openssl.ec71
-rw-r--r--src/lib/libcrypto/err/ssleay.ec57
-rw-r--r--src/lib/libcrypto/evp/Makefile.ssl1034
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c39
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c58
-rw-r--r--src/lib/libcrypto/evp/bio_md.c48
-rw-r--r--src/lib/libcrypto/evp/bio_ok.c552
-rw-r--r--src/lib/libcrypto/evp/c_all.c77
-rw-r--r--src/lib/libcrypto/evp/digest.c29
-rw-r--r--src/lib/libcrypto/evp/e_cbc_3d.c64
-rw-r--r--src/lib/libcrypto/evp/e_cbc_bf.c31
-rw-r--r--src/lib/libcrypto/evp/e_cbc_c.c28
-rw-r--r--src/lib/libcrypto/evp/e_cbc_d.c40
-rw-r--r--src/lib/libcrypto/evp/e_cbc_i.c28
-rw-r--r--src/lib/libcrypto/evp/e_cbc_r2.c122
-rw-r--r--src/lib/libcrypto/evp/e_cbc_r5.c26
-rw-r--r--src/lib/libcrypto/evp/e_cfb_3d.c69
-rw-r--r--src/lib/libcrypto/evp/e_cfb_bf.c29
-rw-r--r--src/lib/libcrypto/evp/e_cfb_c.c26
-rw-r--r--src/lib/libcrypto/evp/e_cfb_d.c34
-rw-r--r--src/lib/libcrypto/evp/e_cfb_i.c26
-rw-r--r--src/lib/libcrypto/evp/e_cfb_r2.c30
-rw-r--r--src/lib/libcrypto/evp/e_cfb_r5.c26
-rw-r--r--src/lib/libcrypto/evp/e_dsa.c6
-rw-r--r--src/lib/libcrypto/evp/e_ecb_3d.c67
-rw-r--r--src/lib/libcrypto/evp/e_ecb_bf.c29
-rw-r--r--src/lib/libcrypto/evp/e_ecb_c.c26
-rw-r--r--src/lib/libcrypto/evp/e_ecb_d.c48
-rw-r--r--src/lib/libcrypto/evp/e_ecb_i.c26
-rw-r--r--src/lib/libcrypto/evp/e_ecb_r2.c30
-rw-r--r--src/lib/libcrypto/evp/e_ecb_r5.c26
-rw-r--r--src/lib/libcrypto/evp/e_null.c26
-rw-r--r--src/lib/libcrypto/evp/e_ofb_3d.c65
-rw-r--r--src/lib/libcrypto/evp/e_ofb_bf.c29
-rw-r--r--src/lib/libcrypto/evp/e_ofb_c.c26
-rw-r--r--src/lib/libcrypto/evp/e_ofb_d.c41
-rw-r--r--src/lib/libcrypto/evp/e_ofb_i.c26
-rw-r--r--src/lib/libcrypto/evp/e_ofb_r2.c30
-rw-r--r--src/lib/libcrypto/evp/e_ofb_r5.c26
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c28
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c42
-rw-r--r--src/lib/libcrypto/evp/encode.c57
-rw-r--r--src/lib/libcrypto/evp/evp.err24
-rw-r--r--src/lib/libcrypto/evp/evp.h347
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c71
-rw-r--r--src/lib/libcrypto/evp/evp_err.c144
-rw-r--r--src/lib/libcrypto/evp/evp_key.c31
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c51
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c134
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c298
-rw-r--r--src/lib/libcrypto/evp/m_dss.c11
-rw-r--r--src/lib/libcrypto/evp/m_dss1.c10
-rw-r--r--src/lib/libcrypto/evp/m_md2.c11
-rw-r--r--src/lib/libcrypto/evp/m_md5.c10
-rw-r--r--src/lib/libcrypto/evp/m_mdc2.c10
-rw-r--r--src/lib/libcrypto/evp/m_null.c10
-rw-r--r--src/lib/libcrypto/evp/m_ripemd.c11
-rw-r--r--src/lib/libcrypto/evp/m_sha.c11
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c10
-rw-r--r--src/lib/libcrypto/evp/names.c239
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c146
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c247
-rw-r--r--src/lib/libcrypto/evp/p_dec.c23
-rw-r--r--src/lib/libcrypto/evp/p_enc.c23
-rw-r--r--src/lib/libcrypto/evp/p_lib.c53
-rw-r--r--src/lib/libcrypto/evp/p_open.c22
-rw-r--r--src/lib/libcrypto/evp/p_seal.c27
-rw-r--r--src/lib/libcrypto/evp/p_sign.c25
-rw-r--r--src/lib/libcrypto/evp/p_verify.c15
-rw-r--r--src/lib/libcrypto/ex_data.c57
-rw-r--r--src/lib/libcrypto/hmac/Makefile.ssl44
-rw-r--r--src/lib/libcrypto/hmac/hmac.c33
-rw-r--r--src/lib/libcrypto/hmac/hmac.h28
-rw-r--r--src/lib/libcrypto/hmac/hmactest.c34
-rw-r--r--src/lib/libcrypto/idea/Makefile.ssl40
-rw-r--r--src/lib/libcrypto/idea/idea.h99
-rw-r--r--src/lib/libcrypto/install.com128
-rw-r--r--src/lib/libcrypto/lhash/Makefile.ssl38
-rw-r--r--src/lib/libcrypto/lhash/lh_stats.c38
-rw-r--r--src/lib/libcrypto/lhash/lh_test.c2
-rw-r--r--src/lib/libcrypto/lhash/lhash.c97
-rw-r--r--src/lib/libcrypto/lhash/lhash.h33
-rw-r--r--src/lib/libcrypto/lhash/num.pl2
-rw-r--r--src/lib/libcrypto/libvms.com31
-rw-r--r--src/lib/libcrypto/md2/Makefile.ssl40
-rw-r--r--src/lib/libcrypto/md2/md2.c20
-rw-r--r--src/lib/libcrypto/md2/md2.h (renamed from src/lib/libcrypto/md2/md2.org)29
-rw-r--r--src/lib/libcrypto/md2/md2_dgst.c28
-rw-r--r--src/lib/libcrypto/md2/md2_one.c23
-rw-r--r--src/lib/libcrypto/md2/md2test.c27
-rw-r--r--src/lib/libcrypto/md32_common.h594
-rw-r--r--src/lib/libcrypto/md5/Makefile.ssl58
-rw-r--r--src/lib/libcrypto/md5/Makefile.uni3
-rw-r--r--src/lib/libcrypto/md5/asm/m5-win32.asm55
-rw-r--r--src/lib/libcrypto/md5/asm/md5-586.pl40
-rw-r--r--src/lib/libcrypto/md5/asm/md5-sparcv9.S1029
-rw-r--r--src/lib/libcrypto/md5/asm/mx86unix.cpp730
-rw-r--r--src/lib/libcrypto/md5/md5.c18
-rw-r--r--src/lib/libcrypto/md5/md5.h51
-rw-r--r--src/lib/libcrypto/md5/md5_dgst.c395
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h160
-rw-r--r--src/lib/libcrypto/md5/md5_one.c28
-rw-r--r--src/lib/libcrypto/md5/md5s.cpp2
-rw-r--r--src/lib/libcrypto/md5/md5test.c23
-rw-r--r--src/lib/libcrypto/mdc2/Makefile.ssl39
-rw-r--r--src/lib/libcrypto/mdc2/mdc2.h16
-rw-r--r--src/lib/libcrypto/mem.c228
-rw-r--r--src/lib/libcrypto/objects/Makefile.ssl66
-rw-r--r--src/lib/libcrypto/objects/o_names.c243
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c269
-rw-r--r--src/lib/libcrypto/objects/obj_dat.h656
-rw-r--r--src/lib/libcrypto/objects/obj_dat.pl4
-rw-r--r--src/lib/libcrypto/objects/obj_err.c118
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c32
-rw-r--r--src/lib/libcrypto/objects/objects.err12
-rw-r--r--src/lib/libcrypto/objects/objects.h316
-rw-r--r--src/lib/libcrypto/opensslconf.h.in142
-rw-r--r--src/lib/libcrypto/opensslv.h21
-rw-r--r--src/lib/libcrypto/pem/Makefile.ssl162
-rw-r--r--src/lib/libcrypto/pem/ctx_size.c122
-rw-r--r--src/lib/libcrypto/pem/pem.err38
-rw-r--r--src/lib/libcrypto/pem/pem.h551
-rw-r--r--src/lib/libcrypto/pem/pem.org562
-rw-r--r--src/lib/libcrypto/pem/pem2.h60
-rw-r--r--src/lib/libcrypto/pem/pem_all.c429
-rw-r--r--src/lib/libcrypto/pem/pem_err.c121
-rw-r--r--src/lib/libcrypto/pem/pem_info.c60
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c273
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c41
-rw-r--r--src/lib/libcrypto/pem/pem_sign.c27
-rw-r--r--src/lib/libcrypto/perlasm/alpha.pl434
-rw-r--r--src/lib/libcrypto/perlasm/cbc.pl2
-rw-r--r--src/lib/libcrypto/perlasm/x86asm.pl11
-rw-r--r--src/lib/libcrypto/perlasm/x86ms.pl12
-rw-r--r--src/lib/libcrypto/perlasm/x86nasm.pl342
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl42
-rw-r--r--src/lib/libcrypto/pkcs7/Makefile.ssl97
-rw-r--r--src/lib/libcrypto/pkcs7/bio_ber.c450
-rw-r--r--src/lib/libcrypto/pkcs7/dec.c246
-rw-r--r--src/lib/libcrypto/pkcs7/des.pem15
-rw-r--r--src/lib/libcrypto/pkcs7/enc.c79
-rw-r--r--src/lib/libcrypto/pkcs7/es1.pem66
-rw-r--r--src/lib/libcrypto/pkcs7/example.c327
-rw-r--r--src/lib/libcrypto/pkcs7/example.h57
-rw-r--r--src/lib/libcrypto/pkcs7/info.pem57
-rw-r--r--src/lib/libcrypto/pkcs7/infokey.pem9
-rw-r--r--src/lib/libcrypto/pkcs7/mf.p718
-rw-r--r--src/lib/libcrypto/pkcs7/p7.tst33
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_dgst.c10
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c718
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_enc.c10
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c156
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.err26
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.h196
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7err.c129
-rw-r--r--src/lib/libcrypto/pkcs7/sign.c21
-rw-r--r--src/lib/libcrypto/pkcs7/verify.c55
-rw-r--r--src/lib/libcrypto/rand/Makefile.ssl41
-rw-r--r--src/lib/libcrypto/rand/md_rand.c102
-rw-r--r--src/lib/libcrypto/rand/rand.h31
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c (renamed from src/lib/libcrypto/cryptall.h)76
-rw-r--r--src/lib/libcrypto/rand/randfile.c39
-rw-r--r--src/lib/libcrypto/rand/randtest.c20
-rw-r--r--src/lib/libcrypto/ranlib.sh23
-rw-r--r--src/lib/libcrypto/rc2/Makefile.ssl40
-rw-r--r--src/lib/libcrypto/rc2/Makefile.uni3
-rw-r--r--src/lib/libcrypto/rc2/rc2.h (renamed from src/lib/libcrypto/rc2/rc2.org)31
-rw-r--r--src/lib/libcrypto/rc2/rc2_cbc.c19
-rw-r--r--src/lib/libcrypto/rc2/rc2_ecb.c12
-rw-r--r--src/lib/libcrypto/rc2/rc2_skey.c8
-rw-r--r--src/lib/libcrypto/rc2/rc2cfb64.c12
-rw-r--r--src/lib/libcrypto/rc2/rc2ofb64.c11
-rw-r--r--src/lib/libcrypto/rc2/rc2speed.c59
-rw-r--r--src/lib/libcrypto/rc2/rc2test.c27
-rw-r--r--src/lib/libcrypto/rc2/tab.c86
-rw-r--r--src/lib/libcrypto/rc4/Makefile.ssl41
-rw-r--r--src/lib/libcrypto/rc4/Makefile.uni3
-rw-r--r--src/lib/libcrypto/rc4/asm/rc4-586.pl2
-rw-r--r--src/lib/libcrypto/rc4/asm/rx86unix.cpp358
-rw-r--r--src/lib/libcrypto/rc4/rc4.c6
-rw-r--r--src/lib/libcrypto/rc4/rc4.h (renamed from src/lib/libcrypto/rc4/rc4.org)29
-rw-r--r--src/lib/libcrypto/rc4/rc4_enc.c10
-rw-r--r--src/lib/libcrypto/rc4/rc4_locl.h4
-rw-r--r--src/lib/libcrypto/rc4/rc4_skey.c12
-rw-r--r--src/lib/libcrypto/rc4/rc4s.cpp2
-rw-r--r--src/lib/libcrypto/rc4/rc4speed.c59
-rw-r--r--src/lib/libcrypto/rc4/rc4test.c16
-rw-r--r--src/lib/libcrypto/rc5/Makefile.ssl41
-rw-r--r--src/lib/libcrypto/rc5/Makefile.uni3
-rw-r--r--src/lib/libcrypto/rc5/asm/r586unix.cpp628
-rw-r--r--src/lib/libcrypto/rc5/asm/rc5-586.pl2
-rw-r--r--src/lib/libcrypto/rc5/rc5.h17
-rw-r--r--src/lib/libcrypto/ripemd/Makefile.ssl39
-rw-r--r--src/lib/libcrypto/ripemd/Makefile.uni2
-rw-r--r--src/lib/libcrypto/ripemd/asm/rips.cpp2
-rw-r--r--src/lib/libcrypto/ripemd/asm/rm86unix.cpp2016
-rw-r--r--src/lib/libcrypto/ripemd/asm/rmd-586.pl4
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.h13
-rw-r--r--src/lib/libcrypto/ripemd/rmd160.c18
-rw-r--r--src/lib/libcrypto/ripemd/rmd_dgst.c38
-rw-r--r--src/lib/libcrypto/ripemd/rmd_locl.h6
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c6
-rw-r--r--src/lib/libcrypto/ripemd/rmdtest.c31
-rw-r--r--src/lib/libcrypto/rsa/Makefile.ssl134
-rw-r--r--src/lib/libcrypto/rsa/rsa.err45
-rw-r--r--src/lib/libcrypto/rsa/rsa.h203
-rw-r--r--src/lib/libcrypto/rsa/rsa_chk.c184
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c164
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c133
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c14
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c167
-rw-r--r--src/lib/libcrypto/rsa/rsa_none.c47
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c162
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep_test.c309
-rw-r--r--src/lib/libcrypto/rsa/rsa_pk1.c53
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c27
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c28
-rw-r--r--src/lib/libcrypto/rsa/rsa_ssl.c22
-rw-r--r--src/lib/libcrypto/sha/Makefile.ssl42
-rw-r--r--src/lib/libcrypto/sha/Makefile.uni2
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl4
-rw-r--r--src/lib/libcrypto/sha/asm/sx86unix.cpp1948
-rw-r--r--src/lib/libcrypto/sha/sha.c19
-rw-r--r--src/lib/libcrypto/sha/sha.h58
-rw-r--r--src/lib/libcrypto/sha/sha1.c18
-rw-r--r--src/lib/libcrypto/sha/sha1_one.c9
-rw-r--r--src/lib/libcrypto/sha/sha1dgst.c244
-rw-r--r--src/lib/libcrypto/sha/sha1s.cpp2
-rw-r--r--src/lib/libcrypto/sha/sha1test.c35
-rw-r--r--src/lib/libcrypto/sha/sha_dgst.c250
-rw-r--r--src/lib/libcrypto/sha/sha_locl.h78
-rw-r--r--src/lib/libcrypto/sha/sha_one.c9
-rw-r--r--src/lib/libcrypto/sha/sha_sgst.c246
-rw-r--r--src/lib/libcrypto/sha/shatest.c35
-rw-r--r--src/lib/libcrypto/stack/Makefile.ssl37
-rw-r--r--src/lib/libcrypto/stack/safestack.h129
-rw-r--r--src/lib/libcrypto/stack/stack.c108
-rw-r--r--src/lib/libcrypto/stack/stack.h33
-rw-r--r--src/lib/libcrypto/threads/mttest.c119
-rw-r--r--src/lib/libcrypto/threads/th-lock.c79
-rw-r--r--src/lib/libcrypto/tmdiff.c106
-rw-r--r--src/lib/libcrypto/tmdiff.h (renamed from src/lib/libcrypto/evp/pk_lib.c)37
-rw-r--r--src/lib/libcrypto/txt_db/Makefile.ssl36
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.c39
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.h16
-rw-r--r--src/lib/libcrypto/util/add_cr.pl2
-rw-r--r--src/lib/libcrypto/util/ck_errf.pl3
-rw-r--r--src/lib/libcrypto/util/clean-depend.pl38
-rw-r--r--src/lib/libcrypto/util/deleof.pl2
-rw-r--r--src/lib/libcrypto/util/do_ms.sh8
-rw-r--r--src/lib/libcrypto/util/domd11
-rw-r--r--src/lib/libcrypto/util/err-ins.pl2
-rw-r--r--src/lib/libcrypto/util/files.pl2
-rw-r--r--src/lib/libcrypto/util/libeay.num789
-rw-r--r--src/lib/libcrypto/util/mk1mf.pl316
-rw-r--r--src/lib/libcrypto/util/mkdef.pl444
-rw-r--r--src/lib/libcrypto/util/mkdir-p.pl33
-rw-r--r--src/lib/libcrypto/util/mkerr.pl503
-rw-r--r--src/lib/libcrypto/util/mkfiles.pl110
-rw-r--r--src/lib/libcrypto/util/mklink.pl55
-rw-r--r--src/lib/libcrypto/util/mklink.sh35
-rw-r--r--src/lib/libcrypto/util/perlpath.pl9
-rw-r--r--src/lib/libcrypto/util/pl/BC-16.pl14
-rw-r--r--src/lib/libcrypto/util/pl/BC-32.pl153
-rw-r--r--src/lib/libcrypto/util/pl/Mingw32.pl79
-rw-r--r--src/lib/libcrypto/util/pl/Mingw32f.pl73
-rw-r--r--src/lib/libcrypto/util/pl/VC-16.pl14
-rw-r--r--src/lib/libcrypto/util/pl/VC-32.pl33
-rw-r--r--src/lib/libcrypto/util/pl/linux.pl16
-rw-r--r--src/lib/libcrypto/util/pl/ultrix.pl38
-rw-r--r--src/lib/libcrypto/util/pl/unix.pl23
-rw-r--r--src/lib/libcrypto/util/point.sh4
-rw-r--r--src/lib/libcrypto/util/ranlib.sh23
-rw-r--r--src/lib/libcrypto/util/sep_lib.sh3
-rw-r--r--src/lib/libcrypto/util/sp-diff.pl2
-rw-r--r--src/lib/libcrypto/util/src-dep.pl2
-rw-r--r--src/lib/libcrypto/util/ssldir.pl52
-rw-r--r--src/lib/libcrypto/util/ssleay.num61
-rw-r--r--src/lib/libcrypto/util/tab_num.pl2
-rw-r--r--src/lib/libcrypto/util/up_ver.pl79
-rw-r--r--src/lib/libcrypto/util/x86asm.sh4
-rw-r--r--src/lib/libcrypto/x509/Makefile.ssl374
-rw-r--r--src/lib/libcrypto/x509/attrib38
-rw-r--r--src/lib/libcrypto/x509/by_dir.c57
-rw-r--r--src/lib/libcrypto/x509/by_file.c41
-rw-r--r--src/lib/libcrypto/x509/v3_net.c87
-rw-r--r--src/lib/libcrypto/x509/v3_x509.c253
-rw-r--r--src/lib/libcrypto/x509/x509.doc27
-rw-r--r--src/lib/libcrypto/x509/x509.err46
-rw-r--r--src/lib/libcrypto/x509/x509.h627
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c138
-rw-r--r--src/lib/libcrypto/x509/x509_d2.c13
-rw-r--r--src/lib/libcrypto/x509/x509_def.c16
-rw-r--r--src/lib/libcrypto/x509/x509_err.c136
-rw-r--r--src/lib/libcrypto/x509/x509_ext.c106
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c139
-rw-r--r--src/lib/libcrypto/x509/x509_obj.c72
-rw-r--r--src/lib/libcrypto/x509/x509_r2x.c34
-rw-r--r--src/lib/libcrypto/x509/x509_req.c27
-rw-r--r--src/lib/libcrypto/x509/x509_set.c36
-rw-r--r--src/lib/libcrypto/x509/x509_txt.c18
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c225
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c221
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.h168
-rw-r--r--src/lib/libcrypto/x509/x509name.c137
-rw-r--r--src/lib/libcrypto/x509/x509pack.c157
-rw-r--r--src/lib/libcrypto/x509/x509rset.c20
-rw-r--r--src/lib/libcrypto/x509/x509type.c13
-rw-r--r--src/lib/libcrypto/x509/x509v3.doc24
-rw-r--r--src/lib/libcrypto/x509/x_all.c272
-rw-r--r--src/lib/libcrypto/x509v3/Makefile.ssl432
-rw-r--r--src/lib/libcrypto/x509v3/README4
-rw-r--r--src/lib/libcrypto/x509v3/format92
-rw-r--r--src/lib/libcrypto/x509v3/header6
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c249
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c402
-rw-r--r--src/lib/libcrypto/x509v3/v3_bcons.c164
-rw-r--r--src/lib/libcrypto/x509v3/v3_bitst.c147
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c366
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c655
-rw-r--r--src/lib/libcrypto/x509v3/v3_crld.c283
-rw-r--r--src/lib/libcrypto/x509v3/v3_enum.c103
-rw-r--r--src/lib/libcrypto/x509v3/v3_extku.c150
-rw-r--r--src/lib/libcrypto/x509v3/v3_genn.c237
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c116
-rw-r--r--src/lib/libcrypto/x509v3/v3_int.c79
-rw-r--r--src/lib/libcrypto/x509v3/v3_ku.c318
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c177
-rw-r--r--src/lib/libcrypto/x509v3/v3_pku.c151
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c135
-rw-r--r--src/lib/libcrypto/x509v3/v3_skey.c156
-rw-r--r--src/lib/libcrypto/x509v3/v3_sxnet.c340
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c418
-rw-r--r--src/lib/libcrypto/x509v3/v3conf.c128
-rw-r--r--src/lib/libcrypto/x509v3/v3err.c171
-rw-r--r--src/lib/libcrypto/x509v3/v3prin.c101
-rw-r--r--src/lib/libcrypto/x509v3/x509v3.h607
650 files changed, 58691 insertions, 34646 deletions
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 @@
1LIB= crypto 1#
2CFLAGS+= -DNO_IDEA -DTERMIOS -DL_ENDIAN -DANSI_SOURCE 2# SSLeay/crypto/Makefile
3CFLAGS+= -I${.CURDIR}/../include 3#
4SRCS+= cryptlib.c mem.c cversion.c ex_data.c cpt_err.c
5CFLAGS+= -I${.CURDIR}/md2
6SRCS+= md2_dgst.c md2_one.c
7CFLAGS+= -I${.CURDIR}/md5
8SRCS+= md5_dgst.c md5_one.c
9CFLAGS+= -I${.CURDIR}/sha
10SRCS+= sha_dgst.c sha1dgst.c sha_one.c sha1_one.c
11CFLAGS+= -I${.CURDIR}/mdc2
12SRCS+= mdc2dgst.c mdc2_one.c
13CFLAGS+= -I${.CURDIR}/hmac
14SRCS+= hmac.c
15CFLAGS+= -I${.CURDIR}/ripemd
16SRCS+= rmd_dgst.c rmd_one.c
17CFLAGS+= -I${.CURDIR}/des
18SRCS+= set_key.c ecb_enc.c cbc_enc.c ecb3_enc.c
19SRCS+= cfb64enc.c cfb64ede.c cfb_enc.c ofb64ede.c
20SRCS+= enc_read.c enc_writ.c ofb64enc.c ofb_enc.c
21SRCS+= str2key.c pcbc_enc.c qud_cksm.c rand_key.c
22SRCS+= read2pwd.c fcrypt.c xcbc_enc.c read_pwd.c
23SRCS+= rpc_enc.c cbc_cksm.c supp.c
24CFLAGS+= -I${.CURDIR}/rc2
25SRCS+= rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c
26SRCS+= rc2ofb64.c
27CFLAGS+= -I${.CURDIR}/rc4
28SRCS+= rc4_skey.c
29CFLAGS+= -I${.CURDIR}/rc5
30SRCS+= rc5_skey.c rc5_ecb.c rc5cfb64.c rc5cfb64.c
31SRCS+= rc5ofb64.c
32CFLAGS+= -I${.CURDIR}/idea
33SRCS+= i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c
34SRCS+= i_skey.c
35CFLAGS+= -I${.CURDIR}/bf
36SRCS+= bf_skey.c bf_ecb.c bf_cfb64.c bf_ofb64.c
37CFLAGS+= -I${.CURDIR}/cast
38SRCS+= c_skey.c c_ecb.c c_cfb64.c c_ofb64.c
39CFLAGS+= -I${.CURDIR}/bn
40SRCS+= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c
41SRCS+= bn_mul.c bn_print.c bn_rand.c bn_shift.c bn_sub.c
42SRCS+= bn_word.c bn_blind.c bn_gcd.c bn_prime.c bn_err.c
43SRCS+= bn_sqr.c bn_recp.c bn_mont.c bn_mpi.c
44CFLAGS+= -I${.CURDIR}/rsa
45SRCS+= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c
46SRCS+= rsa_saos.c rsa_err.c rsa_pk1.c rsa_ssl.c
47SRCS+= rsa_none.c
48CFLAGS+= -I${.CURDIR}/dsa
49SRCS+= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c
50SRCS+= dsa_sign.c dsa_err.c
51CFLAGS+= -I${.CURDIR}/dh
52SRCS+= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c
53CFLAGS+= -I${.CURDIR}/buffer
54SRCS+= buffer.c buf_err.c
55CFLAGS+= -I${.CURDIR}/bio
56SRCS+= bio_lib.c bio_cb.c bio_err.c bss_mem.c
57SRCS+= bss_null.c bss_fd.c bss_file.c bss_sock.c
58SRCS+= bss_conn.c bf_null.c bf_buff.c
59SRCS+= b_print.c b_dump.c b_sock.c bss_acpt.c
60SRCS+= bf_nbio.c
61CFLAGS+= -I${.CURDIR}/stack
62SRCS+= stack.c
63CFLAGS+= -I${.CURDIR}/lhash
64SRCS+= lhash.c lh_stats.c
65CFLAGS+= -I${.CURDIR}/rand
66SRCS+= md_rand.c randfile.c
67CFLAGS+= -I${.CURDIR}/err
68SRCS+= err.c err_all.c err_prn.c
69CFLAGS+= -I${.CURDIR}/objects
70SRCS+= obj_dat.c obj_lib.c obj_err.c
71CFLAGS+= -I${.CURDIR}/evp
72SRCS+= encode.c digest.c evp_enc.c evp_key.c
73SRCS+= e_ecb_d.c e_cbc_d.c e_cfb_d.c e_ofb_d.c
74SRCS+= e_ecb_i.c e_cbc_i.c e_cfb_i.c e_ofb_i.c
75SRCS+= e_ecb_3d.c e_cbc_3d.c e_rc4.c names.c
76SRCS+= e_cfb_3d.c e_ofb_3d.c e_xcbc_d.c e_ecb_r2.c
77SRCS+= e_cbc_r2.c e_cfb_r2.c e_ofb_r2.c e_ecb_bf.c
78SRCS+= e_cbc_bf.c e_cfb_bf.c e_ofb_bf.c e_ecb_c.c
79SRCS+= e_cbc_c.c e_cfb_c.c e_ofb_c.c e_ecb_r5.c
80SRCS+= e_cbc_r5.c e_cfb_r5.c e_ofb_r5.c m_null.c
81SRCS+= m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c
82SRCS+= m_dss1.c m_mdc2.c m_ripemd.c p_open.c
83SRCS+= p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c
84SRCS+= p_dec.c bio_md.c bio_b64.c bio_enc.c
85SRCS+= evp_err.c e_null.c c_all.c evp_lib.c
86CFLAGS+= -I${.CURDIR}/pem
87SRCS+= pem_sign.c pem_seal.c pem_info.c pem_lib.c
88SRCS+= pem_all.c pem_err.c
89CFLAGS+= -I${.CURDIR}/asn1
90SRCS+= a_object.c a_bitstr.c a_utctm.c a_int.c
91SRCS+= a_octet.c a_print.c a_type.c a_set.c
92SRCS+= a_dup.c a_d2i_fp.c a_i2d_fp.c a_sign.c
93SRCS+= a_digest.c a_verify.c x_algor.c x_val.c
94SRCS+= x_pubkey.c x_sig.c x_req.c x_attrib.c
95SRCS+= x_name.c x_cinf.c x_x509.c x_crl.c
96SRCS+= x_info.c x_spki.c d2i_r_pr.c i2d_r_pr.c
97SRCS+= d2i_r_pu.c i2d_r_pu.c d2i_s_pr.c i2d_s_pr.c
98SRCS+= d2i_s_pu.c i2d_s_pu.c d2i_pu.c d2i_pr.c
99SRCS+= i2d_pu.c i2d_pr.c t_req.c t_x509.c
100SRCS+= t_pkey.c p7_i_s.c p7_signi.c p7_signd.c
101SRCS+= p7_recip.c p7_enc_c.c p7_evp.c p7_dgst.c
102SRCS+= p7_s_e.c p7_enc.c p7_lib.c f_int.c
103SRCS+= f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c
104SRCS+= d2i_dsap.c n_pkey.c a_hdr.c x_pkey.c
105SRCS+= a_bool.c x_exten.c asn1_par.c asn1_lib.c
106SRCS+= asn1_err.c a_meth.c a_bytes.c evp_asn1.c
107CFLAGS+= -I${.CURDIR}/x509
108SRCS+= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c
109SRCS+= x509_obj.c x509_req.c x509_vfy.c x509_set.c
110SRCS+= x509rset.c x509_err.c x509name.c x509_v3.c
111SRCS+= x509_ext.c x509pack.c x509type.c x509_lu.c
112SRCS+= x_all.c x509_txt.c by_file.c by_dir.c
113SRCS+= v3_net.c v3_x509.c
114CFLAGS+= -I${.CURDIR}/conf
115SRCS+= conf.c conf_err.c
116CFLAGS+= -I${.CURDIR}/txt_db
117SRCS+= txt_db.c
118CFLAGS+= -I${.CURDIR}/pkcs7
119SRCS+= pk7_lib.c pkcs7err.c pk7_doit.c
120
121.PATH: ${.CURDIR}/md2 ${.CURDIR}/md5 ${.CURDIR}/sha ${.CURDIR}/mdc2 \
122 ${.CURDIR}/hmac ${.CURDIR}/ripemd ${.CURDIR}/des ${.CURDIR}/rc2 \
123 ${.CURDIR}/rc4 ${.CURDIR}/rc5 ${.CURDIR}/idea ${.CURDIR}/bf \
124 ${.CURDIR}/cast ${.CURDIR}/bn ${.CURDIR}/rsa ${.CURDIR}/dsa \
125 ${.CURDIR}/dh ${.CURDIR}/buffer ${.CURDIR}/bio ${.CURDIR}/stack \
126 ${.CURDIR}/lhash ${.CURDIR}/rand ${.CURDIR}/err ${.CURDIR}/objects \
127 ${.CURDIR}/evp ${.CURDIR}/pem ${.CURDIR}/asn1 ${.CURDIR}/asn1 \
128 ${.CURDIR}/x509 ${.CURDIR}/conf txt_db/txt_db.c ${.CURDIR}/pkcs7 \
129 ${.CURDIR}/txt_db
130
131.include <bsd.lib.mk>
132 4
5DIR= crypto
6TOP= ..
7CC= cc
8INCLUDE= -I. -I../include
9INCLUDES= -I.. -I../../include
10CFLAG= -g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP= /usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPEND= $(TOP)/util/domd $(TOP)
16MAKEFILE= Makefile.ssl
17RM= rm -f
18AR= ar r
133 19
20PEX_LIBS=
21EX_LIBS=
22
23CFLAGS= $(INCLUDE) $(CFLAG)
24
25
26LIBS=
27
28SDIRS= md2 md5 sha mdc2 hmac ripemd \
29 des rc2 rc4 rc5 idea bf cast \
30 bn rsa dsa dh \
31 buffer bio stack lhash rand err objects \
32 evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp
33
34GENERAL=Makefile README crypto-lib.com install.com
35
36LIB= $(TOP)/libcrypto.a
37LIBSRC= cryptlib.c mem.c cversion.c ex_data.c tmdiff.c cpt_err.c
38LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o tmdiff.o cpt_err.o
39
40SRC= $(LIBSRC)
41
42EXHEADER= crypto.h tmdiff.h opensslv.h opensslconf.h ebcdic.h
43HEADER= cryptlib.h buildinf.h $(EXHEADER)
44
45ALL= $(GENERAL) $(SRC) $(HEADER)
46
47top:
48 @(cd ..; $(MAKE) DIRS=$(DIR) all)
49
50all: buildinf.h lib subdirs
51
52buildinf.h: ../Makefile.ssl
53 ( echo "#ifndef MK1MF_BUILD"; \
54 echo " /* auto-generated by crypto/Makefile.ssl for crypto/cversion.c */"; \
55 echo " #define CFLAGS \"$(CC) $(CFLAG)\""; \
56 echo " #define PLATFORM \"$(PLATFORM)\""; \
57 echo " #define DATE \"`date`\""; \
58 echo "#endif" ) >buildinf.h
59
60subdirs:
61 @for i in $(SDIRS) ;\
62 do \
63 (cd $$i && echo "making all in crypto/$$i..." && \
64 $(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; \
65 done;
66
67files:
68 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
69 @for i in $(SDIRS) ;\
70 do \
71 (cd $$i; echo "making 'files' in crypto/$$i..."; \
72 $(MAKE) PERL='${PERL}' files ); \
73 done;
74
75links:
76 @$(TOP)/util/point.sh Makefile.ssl Makefile
77 @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER)
78 @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST)
79 @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS)
80 @$(TOP)/util/point.sh Makefile.ssl Makefile
81 @for i in $(SDIRS); do \
82 (cd $$i; echo "making links in crypto/$$i..."; \
83 $(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 ); \
84 done;
85
86lib: $(LIBOBJ)
87 $(AR) $(LIB) $(LIBOBJ)
88 $(RANLIB) $(LIB)
89 @touch lib
90
91libs:
92 @for i in $(SDIRS) ;\
93 do \
94 (cd $$i; echo "making libs in crypto/$$i..."; \
95 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \
96 done;
97
98tests:
99 @for i in $(SDIRS) ;\
100 do \
101 (cd $$i; echo "making tests in crypto/$$i..."; \
102 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' tests ); \
103 done;
104
105install:
106 @for i in $(EXHEADER) ;\
107 do \
108 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
109 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
110 done;
111 @for i in $(SDIRS) ;\
112 do \
113 (cd $$i; echo "making install in crypto/$$i..."; \
114 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \
115 done;
116
117lint:
118 @for i in $(SDIRS) ;\
119 do \
120 (cd $$i; echo "making lint in crypto/$$i..."; \
121 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' lint ); \
122 done;
123
124depend:
125 if [ ! -e buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist
126 $(MAKEDEPEND) $(INCLUDE) $(DEPFLAG) $(PROGS) $(LIBSRC)
127 if [ ! -s buildinf.h ]; then rm buildinf.h; fi
128 @for i in $(SDIRS) ;\
129 do \
130 (cd $$i; echo "making depend in crypto/$$i..."; \
131 $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' DEPFLAG='${DEPFLAG}' depend ); \
132 done;
133
134clean:
135 rm -f buildinf.h *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
136 @for i in $(SDIRS) ;\
137 do \
138 (cd $$i; echo "making clean in crypto/$$i..."; \
139 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' clean ); \
140 done;
141
142dclean:
143 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
144 mv -f Makefile.new $(MAKEFILE)
145 @for i in $(SDIRS) ;\
146 do \
147 (cd $$i; echo "making dclean in crypto/$$i..."; \
148 $(MAKE) PERL='${PERL}' CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \
149 done;
150
151# DO NOT DELETE THIS LINE -- make depend depends on it.
152
153cpt_err.o: ../include/openssl/crypto.h ../include/openssl/err.h
154cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/stack.h
155cryptlib.o: ../include/openssl/bio.h ../include/openssl/buffer.h
156cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
157cryptlib.o: ../include/openssl/e_os2.h ../include/openssl/err.h
158cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
159cryptlib.o: ../include/openssl/stack.h cryptlib.h
160cversion.o: ../include/openssl/bio.h ../include/openssl/buffer.h
161cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
162cversion.o: ../include/openssl/e_os2.h ../include/openssl/err.h
163cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
164cversion.o: ../include/openssl/stack.h buildinf.h cryptlib.h
165ex_data.o: ../include/openssl/bio.h ../include/openssl/buffer.h
166ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
167ex_data.o: ../include/openssl/e_os2.h ../include/openssl/err.h
168ex_data.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
169ex_data.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h
170mem.o: ../include/openssl/bio.h ../include/openssl/buffer.h
171mem.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
172mem.o: ../include/openssl/e_os2.h ../include/openssl/err.h
173mem.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
174mem.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h
175tmdiff.o: ../include/openssl/bio.h ../include/openssl/buffer.h
176tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
177tmdiff.o: ../include/openssl/e_os2.h ../include/openssl/err.h
178tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
179tmdiff.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
8INCLUDE= -I. -I../include 8INCLUDE= -I. -I../include
9INCLUDES= -I.. -I../../include 9INCLUDES= -I.. -I../../include
10CFLAG= -g 10CFLAG= -g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
11INSTALLTOP= /usr/local/ssl 13INSTALLTOP= /usr/local/ssl
12MAKE= make -f Makefile.ssl 14MAKE= make -f Makefile.ssl
13MAKEDEPEND= makedepend -f Makefile.ssl 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
14MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
15RM= /bin/rm -f 17RM= rm -f
16AR= ar r 18AR= ar r
17 19
18MAKE= make -f Makefile.ssl
19MAKEDEPEND= makedepend -f Makefile.ssl
20MAKEFILE= Makefile.ssl
21
22PEX_LIBS= 20PEX_LIBS=
23EX_LIBS= 21EX_LIBS=
24 22
25CFLAGS= $(INCLUDE) $(CFLAG) -DCFLAGS=" \"$(CC) $(CFLAG)\" " 23CFLAGS= $(INCLUDE) $(CFLAG)
26 24
27ERR=crypto
28ERRC=cpt_err
29 25
30LIBS= 26LIBS=
31 27
@@ -33,129 +29,151 @@ SDIRS= md2 md5 sha mdc2 hmac ripemd \
33 des rc2 rc4 rc5 idea bf cast \ 29 des rc2 rc4 rc5 idea bf cast \
34 bn rsa dsa dh \ 30 bn rsa dsa dh \
35 buffer bio stack lhash rand err objects \ 31 buffer bio stack lhash rand err objects \
36 evp pem x509 \ 32 evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp
37 asn1 conf txt_db pkcs7
38 33
39GENERAL=Makefile README 34GENERAL=Makefile README crypto-lib.com install.com
40 35
41LIB= $(TOP)/libcrypto.a 36LIB= $(TOP)/libcrypto.a
42LIBSRC= cryptlib.c mem.c cversion.c ex_data.c $(ERRC).c 37LIBSRC= cryptlib.c mem.c cversion.c ex_data.c tmdiff.c cpt_err.c
43LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o $(ERRC).o 38LIBOBJ= cryptlib.o mem.o cversion.o ex_data.o tmdiff.o cpt_err.o
44 39
45SRC= $(LIBSRC) 40SRC= $(LIBSRC)
46 41
47EXHEADER= crypto.h cryptall.h 42EXHEADER= crypto.h tmdiff.h opensslv.h opensslconf.h ebcdic.h
48HEADER= cryptlib.h date.h $(EXHEADER) 43HEADER= cryptlib.h buildinf.h $(EXHEADER)
49 44
50ALL= $(GENERAL) $(SRC) $(HEADER) 45ALL= $(GENERAL) $(SRC) $(HEADER)
51 46
52top: 47top:
53 @(cd ..; $(MAKE) DIRS=$(DIR) all) 48 @(cd ..; $(MAKE) DIRS=$(DIR) all)
54 49
55all: date.h lib subdirs 50all: buildinf.h lib subdirs
56 51
57date.h: ../Makefile.ssl ../VERSION 52buildinf.h: ../Makefile.ssl
58 echo "#define DATE \"`date`\"" >date.h 53 ( echo "#ifndef MK1MF_BUILD"; \
54 echo " /* auto-generated by crypto/Makefile.ssl for crypto/cversion.c */"; \
55 echo " #define CFLAGS \"$(CC) $(CFLAG)\""; \
56 echo " #define PLATFORM \"$(PLATFORM)\""; \
57 echo " #define DATE \"`date`\""; \
58 echo "#endif" ) >buildinf.h
59 59
60subdirs: 60subdirs:
61 @for i in $(SDIRS) ;\ 61 @for i in $(SDIRS) ;\
62 do \ 62 do \
63 (cd $$i; echo "making all in $$i..."; \ 63 (cd $$i && echo "making all in crypto/$$i..." && \
64 $(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 ); \ 64 $(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; \
65 done; 65 done;
66 66
67files: 67files:
68 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 68 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
69 @for i in $(SDIRS) ;\ 69 @for i in $(SDIRS) ;\
70 do \ 70 do \
71 (cd $$i; echo "making 'files' in $$i..."; \ 71 (cd $$i; echo "making 'files' in crypto/$$i..."; \
72 $(MAKE) files ); \ 72 $(MAKE) PERL='${PERL}' files ); \
73 done; 73 done;
74 74
75links: 75links:
76 /bin/rm -f Makefile 76 @$(TOP)/util/point.sh Makefile.ssl Makefile
77 $(TOP)/util/point.sh Makefile.ssl Makefile ; 77 @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER)
78 $(TOP)/util/mklink.sh ../include $(HEADER) ; 78 @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST)
79 $(TOP)/util/mklink.sh ../test $(TEST) ; 79 @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS)
80 $(TOP)/util/mklink.sh ../apps $(APPS) ; 80 @$(TOP)/util/point.sh Makefile.ssl Makefile
81 $(TOP)/util/point.sh Makefile.ssl Makefile; 81 @for i in $(SDIRS); do \
82 @for i in $(SDIRS) ;\ 82 (cd $$i; echo "making links in crypto/$$i..."; \
83 do \ 83 $(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 ); \
84 (cd $$i; echo "making links in $$i..."; \
85 $(MAKE) links ); \
86 done; 84 done;
87 85
88lib: $(LIBOBJ) 86lib: $(LIBOBJ)
89 $(AR) $(LIB) $(LIBOBJ) 87 $(AR) $(LIB) $(LIBOBJ)
90 sh $(TOP)/util/ranlib.sh $(LIB) 88 $(RANLIB) $(LIB)
91 @touch lib 89 @touch lib
92 90
93libs: 91libs:
94 @for i in $(SDIRS) ;\ 92 @for i in $(SDIRS) ;\
95 do \ 93 do \
96 (cd $$i; echo "making libs in $$i..."; \ 94 (cd $$i; echo "making libs in crypto/$$i..."; \
97 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \ 95 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \
98 done; 96 done;
99 97
100tests: 98tests:
101 @for i in $(SDIRS) ;\ 99 @for i in $(SDIRS) ;\
102 do \ 100 do \
103 (cd $$i; echo "making tests in $$i..."; \ 101 (cd $$i; echo "making tests in crypto/$$i..."; \
104 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' tests ); \ 102 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' tests ); \
105 done; 103 done;
106 104
107install: 105install:
108 @for i in $(EXHEADER) ;\ 106 @for i in $(EXHEADER) ;\
109 do \ 107 do \
110 (cp $$i $(INSTALLTOP)/include/$$i; \ 108 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
111 chmod 644 $(INSTALLTOP)/include/$$i ); \ 109 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
112 done; 110 done;
113 @for i in $(SDIRS) ;\ 111 @for i in $(SDIRS) ;\
114 do \ 112 do \
115 (cd $$i; echo "making install in $$i..."; \ 113 (cd $$i; echo "making install in crypto/$$i..."; \
116 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \ 114 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \
117 done; 115 done;
118 116
119lint: 117lint:
120 @for i in $(SDIRS) ;\ 118 @for i in $(SDIRS) ;\
121 do \ 119 do \
122 (cd $$i; echo "making lint in $$i..."; \ 120 (cd $$i; echo "making lint in crypto/$$i..."; \
123 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' lint ); \ 121 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' lint ); \
124 done; 122 done;
125 123
126depend: 124depend:
127 $(MAKEDEPEND) $(INCLUDE) $(PROGS) $(LIBSRC) 125 if [ ! -e buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist
126 $(MAKEDEPEND) $(INCLUDE) $(DEPFLAG) $(PROGS) $(LIBSRC)
127 if [ ! -s buildinf.h ]; then rm buildinf.h; fi
128 @for i in $(SDIRS) ;\ 128 @for i in $(SDIRS) ;\
129 do \ 129 do \
130 (cd $$i; echo "making depend in $$i..."; \ 130 (cd $$i; echo "making depend in crypto/$$i..."; \
131 $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' MAKEDEPEND='${MAKEDEPEND}' depend ); \ 131 $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' DEPFLAG='${DEPFLAG}' depend ); \
132 done; 132 done;
133 133
134clean: 134clean:
135 /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 135 rm -f buildinf.h *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
136 @for i in $(SDIRS) ;\ 136 @for i in $(SDIRS) ;\
137 do \ 137 do \
138 (cd $$i; echo "making clean in $$i..."; \ 138 (cd $$i; echo "making clean in crypto/$$i..."; \
139 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' clean ); \ 139 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' clean ); \
140 done; 140 done;
141 141
142dclean: 142dclean:
143 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 143 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
144 mv -f Makefile.new $(MAKEFILE) 144 mv -f Makefile.new $(MAKEFILE)
145 @for i in $(SDIRS) ;\ 145 @for i in $(SDIRS) ;\
146 do \ 146 do \
147 (cd $$i; echo "making dclean in $$i..."; \ 147 (cd $$i; echo "making dclean in crypto/$$i..."; \
148 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \ 148 $(MAKE) PERL='${PERL}' CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \
149 done;
150
151errors:
152 perl ./err/err_code.pl -conf err/ssleay.ec *.c */*.c ../ssl/*.c ../rsaref/*.c
153 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
154 perl err/err_genc.pl -s $(ERR).h $(ERRC).c
155 @for i in $(SDIRS) ;\
156 do \
157 (cd $$i; echo "making errors in $$i..."; \
158 $(MAKE) errors ); \
159 done; 149 done;
160 150
161# DO NOT DELETE THIS LINE -- make depend depends on it. 151# DO NOT DELETE THIS LINE -- make depend depends on it.
152
153cpt_err.o: ../include/openssl/crypto.h ../include/openssl/err.h
154cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/stack.h
155cryptlib.o: ../include/openssl/bio.h ../include/openssl/buffer.h
156cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
157cryptlib.o: ../include/openssl/e_os2.h ../include/openssl/err.h
158cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
159cryptlib.o: ../include/openssl/stack.h cryptlib.h
160cversion.o: ../include/openssl/bio.h ../include/openssl/buffer.h
161cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
162cversion.o: ../include/openssl/e_os2.h ../include/openssl/err.h
163cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
164cversion.o: ../include/openssl/stack.h buildinf.h cryptlib.h
165ex_data.o: ../include/openssl/bio.h ../include/openssl/buffer.h
166ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
167ex_data.o: ../include/openssl/e_os2.h ../include/openssl/err.h
168ex_data.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
169ex_data.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h
170mem.o: ../include/openssl/bio.h ../include/openssl/buffer.h
171mem.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
172mem.o: ../include/openssl/e_os2.h ../include/openssl/err.h
173mem.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
174mem.o: ../include/openssl/opensslv.h ../include/openssl/stack.h cryptlib.h
175tmdiff.o: ../include/openssl/bio.h ../include/openssl/buffer.h
176tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os.h
177tmdiff.o: ../include/openssl/e_os2.h ../include/openssl/err.h
178tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
179tmdiff.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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=asn1
19ERRC=asn1_err
20GENERAL=Makefile README 20GENERAL=Makefile README
21TEST= 21TEST=
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \ 25LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
26 a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \ 26 a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \
27 a_sign.c a_digest.c a_verify.c \ 27 a_enum.c a_vis.c a_utf8.c a_sign.c a_digest.c a_verify.c \
28 x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \ 28 x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \
29 x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c \ 29 x_name.c x_cinf.c x_x509.c x_crl.c x_info.c x_spki.c nsseq.c \
30 d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \ 30 d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \
31 d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \ 31 d2i_s_pr.c i2d_s_pr.c d2i_s_pu.c i2d_s_pu.c \
32 d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\ 32 d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\
33 t_req.c t_x509.c t_pkey.c \ 33 t_req.c t_x509.c t_crl.c t_pkey.c \
34 p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \ 34 p7_i_s.c p7_signi.c p7_signd.c p7_recip.c p7_enc_c.c p7_evp.c \
35 p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \ 35 p7_dgst.c p7_s_e.c p7_enc.c p7_lib.c \
36 f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \ 36 f_int.c f_string.c i2d_dhp.c i2d_dsap.c d2i_dhp.c d2i_dsap.c n_pkey.c \
37 a_hdr.c x_pkey.c a_bool.c x_exten.c \ 37 f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c \
38 asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c \ 38 asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c \
39 evp_asn1.c 39 evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c
40LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_int.o a_octet.o a_print.o \ 40LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
41 a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \ 41 a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \
42 a_sign.o a_digest.o a_verify.o \ 42 a_enum.o a_vis.o a_utf8.o a_sign.o a_digest.o a_verify.o \
43 x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \ 43 x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \
44 x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o \ 44 x_name.o x_cinf.o x_x509.o x_crl.o x_info.o x_spki.o nsseq.o \
45 d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \ 45 d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \
46 d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \ 46 d2i_s_pr.o i2d_s_pr.o d2i_s_pu.o i2d_s_pu.o \
47 d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \ 47 d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \
48 t_req.o t_x509.o t_pkey.o \ 48 t_req.o t_x509.o t_crl.o t_pkey.o \
49 p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \ 49 p7_i_s.o p7_signi.o p7_signd.o p7_recip.o p7_enc_c.o p7_evp.o \
50 p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \ 50 p7_dgst.o p7_s_e.o p7_enc.o p7_lib.o \
51 f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \ 51 f_int.o f_string.o i2d_dhp.o i2d_dsap.o d2i_dhp.o d2i_dsap.o n_pkey.o \
52 a_hdr.o x_pkey.o a_bool.o x_exten.o \ 52 f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o \
53 asn1_par.o asn1_lib.o $(ERRC).o a_meth.o a_bytes.o \ 53 asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o \
54 evp_asn1.o 54 evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o
55 55
56SRC= $(LIBSRC) 56SRC= $(LIBSRC)
57 57
@@ -75,24 +75,23 @@ all: lib
75 75
76lib: $(LIBOBJ) 76lib: $(LIBOBJ)
77 $(AR) $(LIB) $(LIBOBJ) 77 $(AR) $(LIB) $(LIBOBJ)
78 sh $(TOP)/util/ranlib.sh $(LIB) 78 $(RANLIB) $(LIB)
79 @touch lib 79 @touch lib
80 80
81files: 81files:
82 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 82 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
83 83
84links: 84links:
85 /bin/rm -f Makefile 85 @$(TOP)/util/point.sh Makefile.ssl Makefile
86 $(TOP)/util/point.sh Makefile.ssl Makefile ; 86 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
87 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 87 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
88 $(TOP)/util/mklink.sh ../../test $(TEST) 88 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
89 $(TOP)/util/mklink.sh ../../apps $(APPS)
90 89
91install: 90install:
92 @for i in $(EXHEADER) ; \ 91 @for i in $(EXHEADER) ; \
93 do \ 92 do \
94 (cp $$i $(INSTALLTOP)/include/$$i; \ 93 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
95 chmod 644 $(INSTALLTOP)/include/$$i ); \ 94 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
96 done; 95 done;
97 96
98tags: 97tags:
@@ -104,17 +103,988 @@ lint:
104 lint -DLINT $(INCLUDES) $(SRC)>fluff 103 lint -DLINT $(INCLUDES) $(SRC)>fluff
105 104
106depend: 105depend:
107 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 106 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
108 107
109dclean: 108dclean:
110 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 109 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
111 mv -f Makefile.new $(MAKEFILE) 110 mv -f Makefile.new $(MAKEFILE)
112 111
113clean: 112clean:
114 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 113 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
115 114
116errors:
117 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
118 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
119 115
120# DO NOT DELETE THIS LINE -- make depend depends on it. 116# DO NOT DELETE THIS LINE -- make depend depends on it.
117
118a_bitstr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
119a_bitstr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
120a_bitstr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
121a_bitstr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
122a_bitstr.o: ../../include/openssl/opensslconf.h
123a_bitstr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
124a_bitstr.o: ../../include/openssl/stack.h ../cryptlib.h
125a_bmp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
126a_bmp.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
127a_bmp.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
128a_bmp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
129a_bmp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
130a_bmp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
131a_bmp.o: ../cryptlib.h
132a_bool.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
133a_bool.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
134a_bool.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
135a_bool.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
136a_bool.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
137a_bool.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
138a_bool.o: ../cryptlib.h
139a_bytes.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
140a_bytes.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
141a_bytes.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
142a_bytes.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
143a_bytes.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
144a_bytes.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
145a_bytes.o: ../../include/openssl/stack.h ../cryptlib.h
146a_d2i_fp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
147a_d2i_fp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
148a_d2i_fp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
149a_d2i_fp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
150a_d2i_fp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
151a_d2i_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
152a_d2i_fp.o: ../../include/openssl/stack.h ../cryptlib.h
153a_digest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
154a_digest.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
155a_digest.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
156a_digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
157a_digest.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
158a_digest.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
159a_digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
160a_digest.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
161a_digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
162a_digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
163a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
164a_digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
165a_digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
166a_digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
167a_digest.o: ../../include/openssl/stack.h ../cryptlib.h
168a_dup.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
169a_dup.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
170a_dup.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
171a_dup.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
172a_dup.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
173a_dup.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
174a_dup.o: ../../include/openssl/stack.h ../cryptlib.h
175a_enum.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
176a_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
177a_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
178a_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
179a_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
180a_enum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
181a_enum.o: ../cryptlib.h
182a_gentm.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
183a_gentm.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
184a_gentm.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
185a_gentm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
186a_gentm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
187a_gentm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
188a_gentm.o: ../cryptlib.h
189a_hdr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
190a_hdr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
191a_hdr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
192a_hdr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
193a_hdr.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
194a_hdr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
195a_hdr.o: ../../include/openssl/stack.h ../cryptlib.h
196a_i2d_fp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
197a_i2d_fp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
198a_i2d_fp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
199a_i2d_fp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
200a_i2d_fp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
201a_i2d_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
202a_i2d_fp.o: ../../include/openssl/stack.h ../cryptlib.h
203a_int.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
204a_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
205a_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
206a_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
207a_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
208a_int.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
209a_int.o: ../cryptlib.h
210a_meth.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
211a_meth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
212a_meth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
213a_meth.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
214a_meth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
215a_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
216a_meth.o: ../cryptlib.h
217a_object.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
218a_object.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
219a_object.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
220a_object.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
221a_object.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
222a_object.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
223a_object.o: ../../include/openssl/stack.h ../cryptlib.h
224a_octet.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
225a_octet.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
226a_octet.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
227a_octet.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
228a_octet.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
229a_octet.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
230a_octet.o: ../cryptlib.h
231a_print.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
232a_print.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
233a_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
234a_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
235a_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
236a_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
237a_print.o: ../cryptlib.h
238a_set.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
239a_set.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
240a_set.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
241a_set.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
242a_set.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
243a_set.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
244a_set.o: ../../include/openssl/stack.h ../cryptlib.h
245a_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
246a_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
247a_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
248a_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
249a_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
250a_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
251a_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
252a_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
253a_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
254a_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
255a_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
256a_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
257a_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
258a_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
259a_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
260a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
261a_sign.o: ../cryptlib.h
262a_time.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
263a_time.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
264a_time.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
265a_time.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
266a_time.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
267a_time.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
268a_time.o: ../cryptlib.h
269a_type.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
270a_type.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
271a_type.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
272a_type.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
273a_type.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
274a_type.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
275a_type.o: ../../include/openssl/stack.h ../cryptlib.h
276a_utctm.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
277a_utctm.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
278a_utctm.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
279a_utctm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
280a_utctm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
281a_utctm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
282a_utctm.o: ../cryptlib.h
283a_utf8.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
284a_utf8.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
285a_utf8.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
286a_utf8.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
287a_utf8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
288a_utf8.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
289a_utf8.o: ../cryptlib.h
290a_verify.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
291a_verify.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
292a_verify.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
293a_verify.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
294a_verify.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
295a_verify.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
296a_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h
297a_verify.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
298a_verify.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
299a_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
300a_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
301a_verify.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
302a_verify.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
303a_verify.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
304a_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
305a_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
306a_verify.o: ../cryptlib.h
307a_vis.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
308a_vis.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
309a_vis.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
310a_vis.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
311a_vis.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
312a_vis.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
313a_vis.o: ../cryptlib.h
314asn1_err.o: ../../include/openssl/asn1.h ../../include/openssl/bn.h
315asn1_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
316asn1_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
317asn1_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
318asn1_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
319asn1_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
320asn1_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
321asn1_lib.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
322asn1_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
323asn1_lib.o: ../../include/openssl/stack.h ../cryptlib.h
324asn1_par.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
325asn1_par.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
326asn1_par.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
327asn1_par.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
328asn1_par.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
329asn1_par.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
330asn1_par.o: ../../include/openssl/stack.h ../cryptlib.h
331asn_pack.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
332asn_pack.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
333asn_pack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
334asn_pack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
335asn_pack.o: ../../include/openssl/opensslconf.h
336asn_pack.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
337asn_pack.o: ../../include/openssl/stack.h ../cryptlib.h
338d2i_dhp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
339d2i_dhp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
340d2i_dhp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
341d2i_dhp.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
342d2i_dhp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
343d2i_dhp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
344d2i_dhp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
345d2i_dhp.o: ../../include/openssl/stack.h ../cryptlib.h
346d2i_dsap.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
347d2i_dsap.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
348d2i_dsap.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
349d2i_dsap.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
350d2i_dsap.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
351d2i_dsap.o: ../../include/openssl/err.h ../../include/openssl/objects.h
352d2i_dsap.o: ../../include/openssl/opensslconf.h
353d2i_dsap.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
354d2i_dsap.o: ../../include/openssl/stack.h ../cryptlib.h
355d2i_pr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
356d2i_pr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
357d2i_pr.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
358d2i_pr.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
359d2i_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
360d2i_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
361d2i_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
362d2i_pr.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
363d2i_pr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
364d2i_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
365d2i_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
366d2i_pr.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
367d2i_pr.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
368d2i_pr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
369d2i_pr.o: ../../include/openssl/stack.h ../cryptlib.h
370d2i_pu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
371d2i_pu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
372d2i_pu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
373d2i_pu.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
374d2i_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
375d2i_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
376d2i_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
377d2i_pu.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
378d2i_pu.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
379d2i_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
380d2i_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
381d2i_pu.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
382d2i_pu.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
383d2i_pu.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
384d2i_pu.o: ../../include/openssl/stack.h ../cryptlib.h
385d2i_r_pr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
386d2i_r_pr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
387d2i_r_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
388d2i_r_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
389d2i_r_pr.o: ../../include/openssl/err.h ../../include/openssl/objects.h
390d2i_r_pr.o: ../../include/openssl/opensslconf.h
391d2i_r_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
392d2i_r_pr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
393d2i_r_pr.o: ../cryptlib.h
394d2i_r_pu.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
395d2i_r_pu.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
396d2i_r_pu.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
397d2i_r_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
398d2i_r_pu.o: ../../include/openssl/err.h ../../include/openssl/objects.h
399d2i_r_pu.o: ../../include/openssl/opensslconf.h
400d2i_r_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
401d2i_r_pu.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
402d2i_r_pu.o: ../cryptlib.h
403d2i_s_pr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
404d2i_s_pr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
405d2i_s_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
406d2i_s_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
407d2i_s_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
408d2i_s_pr.o: ../../include/openssl/err.h ../../include/openssl/objects.h
409d2i_s_pr.o: ../../include/openssl/opensslconf.h
410d2i_s_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
411d2i_s_pr.o: ../../include/openssl/stack.h ../cryptlib.h
412d2i_s_pu.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
413d2i_s_pu.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
414d2i_s_pu.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
415d2i_s_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
416d2i_s_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
417d2i_s_pu.o: ../../include/openssl/err.h ../../include/openssl/objects.h
418d2i_s_pu.o: ../../include/openssl/opensslconf.h
419d2i_s_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
420d2i_s_pu.o: ../../include/openssl/stack.h ../cryptlib.h
421evp_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
422evp_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
423evp_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
424evp_asn1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
425evp_asn1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
426evp_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
427evp_asn1.o: ../../include/openssl/stack.h ../cryptlib.h
428f_enum.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
429f_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
430f_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
431f_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
432f_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
433f_enum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
434f_enum.o: ../cryptlib.h
435f_int.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
436f_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
437f_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
438f_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
439f_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
440f_int.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
441f_int.o: ../cryptlib.h
442f_string.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
443f_string.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
444f_string.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
445f_string.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
446f_string.o: ../../include/openssl/opensslconf.h
447f_string.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
448f_string.o: ../../include/openssl/stack.h ../cryptlib.h
449i2d_dhp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
450i2d_dhp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
451i2d_dhp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
452i2d_dhp.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
453i2d_dhp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
454i2d_dhp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
455i2d_dhp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
456i2d_dhp.o: ../cryptlib.h
457i2d_dsap.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
458i2d_dsap.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
459i2d_dsap.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
460i2d_dsap.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
461i2d_dsap.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
462i2d_dsap.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
463i2d_dsap.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
464i2d_dsap.o: ../../include/openssl/stack.h ../cryptlib.h
465i2d_pr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
466i2d_pr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
467i2d_pr.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
468i2d_pr.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
469i2d_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
470i2d_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
471i2d_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
472i2d_pr.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
473i2d_pr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
474i2d_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
475i2d_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
476i2d_pr.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
477i2d_pr.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
478i2d_pr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
479i2d_pr.o: ../../include/openssl/stack.h ../cryptlib.h
480i2d_pu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
481i2d_pu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
482i2d_pu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
483i2d_pu.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
484i2d_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
485i2d_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
486i2d_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
487i2d_pu.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
488i2d_pu.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
489i2d_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
490i2d_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
491i2d_pu.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
492i2d_pu.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
493i2d_pu.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
494i2d_pu.o: ../../include/openssl/stack.h ../cryptlib.h
495i2d_r_pr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
496i2d_r_pr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
497i2d_r_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
498i2d_r_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
499i2d_r_pr.o: ../../include/openssl/err.h ../../include/openssl/objects.h
500i2d_r_pr.o: ../../include/openssl/opensslconf.h
501i2d_r_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
502i2d_r_pr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
503i2d_r_pr.o: ../cryptlib.h
504i2d_r_pu.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
505i2d_r_pu.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
506i2d_r_pu.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
507i2d_r_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
508i2d_r_pu.o: ../../include/openssl/err.h ../../include/openssl/objects.h
509i2d_r_pu.o: ../../include/openssl/opensslconf.h
510i2d_r_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
511i2d_r_pu.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
512i2d_r_pu.o: ../cryptlib.h
513i2d_s_pr.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
514i2d_s_pr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
515i2d_s_pr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
516i2d_s_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
517i2d_s_pr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
518i2d_s_pr.o: ../../include/openssl/err.h ../../include/openssl/objects.h
519i2d_s_pr.o: ../../include/openssl/opensslconf.h
520i2d_s_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
521i2d_s_pr.o: ../../include/openssl/stack.h ../cryptlib.h
522i2d_s_pu.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
523i2d_s_pu.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
524i2d_s_pu.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
525i2d_s_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
526i2d_s_pu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
527i2d_s_pu.o: ../../include/openssl/err.h ../../include/openssl/objects.h
528i2d_s_pu.o: ../../include/openssl/opensslconf.h
529i2d_s_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
530i2d_s_pu.o: ../../include/openssl/stack.h ../cryptlib.h
531n_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
532n_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
533n_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
534n_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
535n_pkey.o: ../../include/openssl/des.h ../../include/openssl/dh.h
536n_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
537n_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
538n_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
539n_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
540n_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
541n_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
542n_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
543n_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
544n_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
545n_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
546n_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
547n_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
548nsseq.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
549nsseq.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
550nsseq.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
551nsseq.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
552nsseq.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
553nsseq.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
554nsseq.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
555nsseq.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
556nsseq.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
557nsseq.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
558nsseq.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
559nsseq.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
560nsseq.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
561nsseq.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
562nsseq.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
563nsseq.o: ../../include/openssl/x509_vfy.h
564p5_pbe.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
565p5_pbe.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
566p5_pbe.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
567p5_pbe.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
568p5_pbe.o: ../../include/openssl/des.h ../../include/openssl/dh.h
569p5_pbe.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
570p5_pbe.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
571p5_pbe.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
572p5_pbe.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
573p5_pbe.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
574p5_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
575p5_pbe.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
576p5_pbe.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
577p5_pbe.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
578p5_pbe.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
579p5_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
580p5_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
581p5_pbe.o: ../cryptlib.h
582p5_pbev2.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
583p5_pbev2.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
584p5_pbev2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
585p5_pbev2.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
586p5_pbev2.o: ../../include/openssl/des.h ../../include/openssl/dh.h
587p5_pbev2.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
588p5_pbev2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
589p5_pbev2.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
590p5_pbev2.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
591p5_pbev2.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
592p5_pbev2.o: ../../include/openssl/opensslconf.h
593p5_pbev2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
594p5_pbev2.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
595p5_pbev2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
596p5_pbev2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
597p5_pbev2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
598p5_pbev2.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
599p5_pbev2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
600p7_dgst.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
601p7_dgst.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
602p7_dgst.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
603p7_dgst.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
604p7_dgst.o: ../../include/openssl/des.h ../../include/openssl/dh.h
605p7_dgst.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
606p7_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
607p7_dgst.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
608p7_dgst.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
609p7_dgst.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
610p7_dgst.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
611p7_dgst.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
612p7_dgst.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
613p7_dgst.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
614p7_dgst.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
615p7_dgst.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
616p7_dgst.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
617p7_enc.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
618p7_enc.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
619p7_enc.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
620p7_enc.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
621p7_enc.o: ../../include/openssl/des.h ../../include/openssl/dh.h
622p7_enc.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
623p7_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
624p7_enc.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
625p7_enc.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
626p7_enc.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
627p7_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
628p7_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
629p7_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
630p7_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
631p7_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
632p7_enc.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
633p7_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
634p7_enc_c.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
635p7_enc_c.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
636p7_enc_c.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
637p7_enc_c.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
638p7_enc_c.o: ../../include/openssl/des.h ../../include/openssl/dh.h
639p7_enc_c.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
640p7_enc_c.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
641p7_enc_c.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
642p7_enc_c.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
643p7_enc_c.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
644p7_enc_c.o: ../../include/openssl/opensslconf.h
645p7_enc_c.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
646p7_enc_c.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
647p7_enc_c.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
648p7_enc_c.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
649p7_enc_c.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
650p7_enc_c.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
651p7_enc_c.o: ../cryptlib.h
652p7_evp.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
653p7_evp.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
654p7_evp.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
655p7_evp.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
656p7_evp.o: ../../include/openssl/des.h ../../include/openssl/dh.h
657p7_evp.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
658p7_evp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
659p7_evp.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
660p7_evp.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
661p7_evp.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
662p7_evp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
663p7_evp.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
664p7_evp.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
665p7_evp.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
666p7_evp.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
667p7_evp.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
668p7_evp.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
669p7_i_s.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
670p7_i_s.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
671p7_i_s.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
672p7_i_s.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
673p7_i_s.o: ../../include/openssl/des.h ../../include/openssl/dh.h
674p7_i_s.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
675p7_i_s.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
676p7_i_s.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
677p7_i_s.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
678p7_i_s.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
679p7_i_s.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
680p7_i_s.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
681p7_i_s.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
682p7_i_s.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
683p7_i_s.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
684p7_i_s.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
685p7_i_s.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
686p7_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
687p7_lib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
688p7_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
689p7_lib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
690p7_lib.o: ../../include/openssl/des.h ../../include/openssl/dh.h
691p7_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
692p7_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
693p7_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
694p7_lib.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
695p7_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
696p7_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
697p7_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
698p7_lib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
699p7_lib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
700p7_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
701p7_lib.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
702p7_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
703p7_recip.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
704p7_recip.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
705p7_recip.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
706p7_recip.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
707p7_recip.o: ../../include/openssl/des.h ../../include/openssl/dh.h
708p7_recip.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
709p7_recip.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
710p7_recip.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
711p7_recip.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
712p7_recip.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
713p7_recip.o: ../../include/openssl/opensslconf.h
714p7_recip.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
715p7_recip.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
716p7_recip.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
717p7_recip.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
718p7_recip.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
719p7_recip.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
720p7_recip.o: ../cryptlib.h
721p7_s_e.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
722p7_s_e.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
723p7_s_e.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
724p7_s_e.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
725p7_s_e.o: ../../include/openssl/des.h ../../include/openssl/dh.h
726p7_s_e.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
727p7_s_e.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
728p7_s_e.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
729p7_s_e.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
730p7_s_e.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
731p7_s_e.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
732p7_s_e.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
733p7_s_e.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
734p7_s_e.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
735p7_s_e.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
736p7_s_e.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
737p7_s_e.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
738p7_signd.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
739p7_signd.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
740p7_signd.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
741p7_signd.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
742p7_signd.o: ../../include/openssl/des.h ../../include/openssl/dh.h
743p7_signd.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
744p7_signd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
745p7_signd.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
746p7_signd.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
747p7_signd.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
748p7_signd.o: ../../include/openssl/opensslconf.h
749p7_signd.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
750p7_signd.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
751p7_signd.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
752p7_signd.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
753p7_signd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
754p7_signd.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
755p7_signd.o: ../cryptlib.h
756p7_signi.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
757p7_signi.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
758p7_signi.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
759p7_signi.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
760p7_signi.o: ../../include/openssl/des.h ../../include/openssl/dh.h
761p7_signi.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
762p7_signi.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
763p7_signi.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
764p7_signi.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
765p7_signi.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
766p7_signi.o: ../../include/openssl/opensslconf.h
767p7_signi.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
768p7_signi.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
769p7_signi.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
770p7_signi.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
771p7_signi.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
772p7_signi.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
773p7_signi.o: ../cryptlib.h
774p8_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
775p8_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
776p8_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
777p8_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
778p8_pkey.o: ../../include/openssl/des.h ../../include/openssl/dh.h
779p8_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
780p8_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
781p8_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
782p8_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
783p8_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
784p8_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
785p8_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
786p8_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
787p8_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
788p8_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
789p8_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
790p8_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
791t_crl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
792t_crl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
793t_crl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
794t_crl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
795t_crl.o: ../../include/openssl/des.h ../../include/openssl/dh.h
796t_crl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
797t_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
798t_crl.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
799t_crl.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
800t_crl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
801t_crl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
802t_crl.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
803t_crl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
804t_crl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
805t_crl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
806t_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
807t_crl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
808t_crl.o: ../../include/openssl/x509v3.h ../cryptlib.h
809t_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
810t_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
811t_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
812t_pkey.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
813t_pkey.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
814t_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
815t_pkey.o: ../../include/openssl/stack.h ../cryptlib.h
816t_req.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
817t_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
818t_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
819t_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
820t_req.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
821t_req.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
822t_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
823t_req.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
824t_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
825t_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
826t_req.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
827t_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
828t_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
829t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
830t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
831t_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
832t_req.o: ../cryptlib.h
833t_x509.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
834t_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
835t_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
836t_x509.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
837t_x509.o: ../../include/openssl/des.h ../../include/openssl/dh.h
838t_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
839t_x509.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
840t_x509.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
841t_x509.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
842t_x509.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
843t_x509.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
844t_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
845t_x509.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
846t_x509.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
847t_x509.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
848t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
849t_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
850t_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h
851x_algor.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
852x_algor.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
853x_algor.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
854x_algor.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
855x_algor.o: ../../include/openssl/des.h ../../include/openssl/dh.h
856x_algor.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
857x_algor.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
858x_algor.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
859x_algor.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
860x_algor.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
861x_algor.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
862x_algor.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
863x_algor.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
864x_algor.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
865x_algor.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
866x_algor.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
867x_algor.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
868x_attrib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
869x_attrib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
870x_attrib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
871x_attrib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
872x_attrib.o: ../../include/openssl/des.h ../../include/openssl/dh.h
873x_attrib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
874x_attrib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
875x_attrib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
876x_attrib.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
877x_attrib.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
878x_attrib.o: ../../include/openssl/opensslconf.h
879x_attrib.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
880x_attrib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
881x_attrib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
882x_attrib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
883x_attrib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
884x_attrib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
885x_attrib.o: ../cryptlib.h
886x_cinf.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
887x_cinf.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
888x_cinf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
889x_cinf.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
890x_cinf.o: ../../include/openssl/des.h ../../include/openssl/dh.h
891x_cinf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
892x_cinf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
893x_cinf.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
894x_cinf.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
895x_cinf.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
896x_cinf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
897x_cinf.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
898x_cinf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
899x_cinf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
900x_cinf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
901x_cinf.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
902x_cinf.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
903x_crl.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
904x_crl.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
905x_crl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
906x_crl.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
907x_crl.o: ../../include/openssl/des.h ../../include/openssl/dh.h
908x_crl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
909x_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
910x_crl.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
911x_crl.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
912x_crl.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
913x_crl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
914x_crl.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
915x_crl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
916x_crl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
917x_crl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
918x_crl.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
919x_crl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
920x_exten.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
921x_exten.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
922x_exten.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
923x_exten.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
924x_exten.o: ../../include/openssl/des.h ../../include/openssl/dh.h
925x_exten.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
926x_exten.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
927x_exten.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
928x_exten.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
929x_exten.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
930x_exten.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
931x_exten.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
932x_exten.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
933x_exten.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
934x_exten.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
935x_exten.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
936x_exten.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
937x_info.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
938x_info.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
939x_info.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
940x_info.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
941x_info.o: ../../include/openssl/des.h ../../include/openssl/dh.h
942x_info.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
943x_info.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
944x_info.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
945x_info.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
946x_info.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
947x_info.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
948x_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
949x_info.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
950x_info.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
951x_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
952x_info.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
953x_info.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
954x_name.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
955x_name.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
956x_name.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
957x_name.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
958x_name.o: ../../include/openssl/des.h ../../include/openssl/dh.h
959x_name.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
960x_name.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
961x_name.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
962x_name.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
963x_name.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
964x_name.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
965x_name.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
966x_name.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
967x_name.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
968x_name.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
969x_name.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
970x_name.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
971x_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
972x_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
973x_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
974x_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
975x_pkey.o: ../../include/openssl/des.h ../../include/openssl/dh.h
976x_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
977x_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
978x_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
979x_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
980x_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
981x_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
982x_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
983x_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
984x_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
985x_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
986x_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
987x_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
988x_pubkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
989x_pubkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
990x_pubkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
991x_pubkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
992x_pubkey.o: ../../include/openssl/des.h ../../include/openssl/dh.h
993x_pubkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
994x_pubkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
995x_pubkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
996x_pubkey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
997x_pubkey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
998x_pubkey.o: ../../include/openssl/opensslconf.h
999x_pubkey.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
1000x_pubkey.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1001x_pubkey.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1002x_pubkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1003x_pubkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1004x_pubkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1005x_pubkey.o: ../cryptlib.h
1006x_req.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
1007x_req.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1008x_req.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1009x_req.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1010x_req.o: ../../include/openssl/des.h ../../include/openssl/dh.h
1011x_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
1012x_req.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1013x_req.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1014x_req.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
1015x_req.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
1016x_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1017x_req.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1018x_req.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1019x_req.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1020x_req.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1021x_req.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1022x_req.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
1023x_sig.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
1024x_sig.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1025x_sig.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1026x_sig.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1027x_sig.o: ../../include/openssl/des.h ../../include/openssl/dh.h
1028x_sig.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
1029x_sig.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1030x_sig.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1031x_sig.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
1032x_sig.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
1033x_sig.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1034x_sig.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1035x_sig.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1036x_sig.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1037x_sig.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1038x_sig.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1039x_sig.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
1040x_spki.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
1041x_spki.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1042x_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1043x_spki.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1044x_spki.o: ../../include/openssl/des.h ../../include/openssl/dh.h
1045x_spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
1046x_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1047x_spki.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1048x_spki.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
1049x_spki.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
1050x_spki.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1051x_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1052x_spki.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1053x_spki.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1054x_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1055x_spki.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1056x_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
1057x_val.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
1058x_val.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1059x_val.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1060x_val.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1061x_val.o: ../../include/openssl/des.h ../../include/openssl/dh.h
1062x_val.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
1063x_val.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1064x_val.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1065x_val.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
1066x_val.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
1067x_val.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1068x_val.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1069x_val.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1070x_val.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1071x_val.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1072x_val.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1073x_val.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
1074x_x509.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
1075x_x509.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1076x_x509.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1077x_x509.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1078x_x509.o: ../../include/openssl/des.h ../../include/openssl/dh.h
1079x_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
1080x_x509.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1081x_x509.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1082x_x509.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
1083x_x509.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
1084x_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1085x_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1086x_x509.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1087x_x509.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1088x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1089x_x509.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1090x_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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62 62
63/* ASN1err(ASN1_F_ASN1_STRING_NEW,ASN1_R_STRING_TOO_SHORT); 63int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
64 * ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,ASN1_R_EXPECTING_A_BIT_STRING);
65 */
66
67int i2d_ASN1_BIT_STRING(a,pp)
68ASN1_BIT_STRING *a;
69unsigned char **pp;
70 { 64 {
71 int ret,j,r,bits; 65 int ret,j,r,bits,len;
72 unsigned char *p,*d; 66 unsigned char *p,*d;
73 67
74 if (a == NULL) return(0); 68 if (a == NULL) return(0);
75 69
76 /* our bit strings are always a multiple of 8 :-) */ 70 len=a->length;
77 bits=0; 71
78 ret=1+a->length; 72 if (len > 0)
73 {
74 if (a->flags & ASN1_STRING_FLAG_BITS_LEFT)
75 {
76 bits=(int)a->flags&0x07;
77 }
78 else
79 {
80 for ( ; len > 0; len--)
81 {
82 if (a->data[len-1]) break;
83 }
84 j=a->data[len-1];
85 if (j & 0x01) bits=0;
86 else if (j & 0x02) bits=1;
87 else if (j & 0x04) bits=2;
88 else if (j & 0x08) bits=3;
89 else if (j & 0x10) bits=4;
90 else if (j & 0x20) bits=5;
91 else if (j & 0x40) bits=6;
92 else if (j & 0x80) bits=7;
93 else bits=0; /* should not happen */
94 }
95 }
96 else
97 bits=0;
98 ret=1+len;
79 r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING); 99 r=ASN1_object_size(0,ret,V_ASN1_BIT_STRING);
80 if (pp == NULL) return(r); 100 if (pp == NULL) return(r);
81 p= *pp; 101 p= *pp;
82 102
83 ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL); 103 ASN1_put_object(&p,0,ret,V_ASN1_BIT_STRING,V_ASN1_UNIVERSAL);
84 if (bits == 0) 104 *(p++)=(unsigned char)bits;
85 j=0;
86 else j=8-bits;
87 *(p++)=(unsigned char)j;
88 d=a->data; 105 d=a->data;
89 memcpy(p,d,a->length); 106 memcpy(p,d,len);
90 p+=a->length; 107 p+=len;
91 if (a->length > 0) p[-1]&=(0xff<<j); 108 if (len > 0) p[-1]&=(0xff<<bits);
92 *pp=p; 109 *pp=p;
93 return(r); 110 return(r);
94 } 111 }
95 112
96ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(a, pp, length) 113ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
97ASN1_BIT_STRING **a; 114 long length)
98unsigned char **pp;
99long length;
100 { 115 {
101 ASN1_BIT_STRING *ret=NULL; 116 ASN1_BIT_STRING *ret=NULL;
102 unsigned char *p,*s; 117 unsigned char *p,*s;
@@ -127,6 +142,12 @@ long length;
127 if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; } 142 if (len < 1) { i=ASN1_R_STRING_TOO_SHORT; goto err; }
128 143
129 i= *(p++); 144 i= *(p++);
145 /* We do this to preserve the settings. If we modify
146 * the settings, via the _set_bit function, we will recalculate
147 * on output */
148 ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */
149 ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */
150
130 if (len-- > 1) /* using one because of the bits left byte */ 151 if (len-- > 1) /* using one because of the bits left byte */
131 { 152 {
132 s=(unsigned char *)Malloc((int)len); 153 s=(unsigned char *)Malloc((int)len);
@@ -158,10 +179,7 @@ err:
158 179
159/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> 180/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de>
160 */ 181 */
161int ASN1_BIT_STRING_set_bit(a,n,value) 182int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
162ASN1_BIT_STRING *a;
163int n;
164int value;
165 { 183 {
166 int w,v,iv; 184 int w,v,iv;
167 unsigned char *c; 185 unsigned char *c;
@@ -170,6 +188,8 @@ int value;
170 v=1<<(7-(n&0x07)); 188 v=1<<(7-(n&0x07));
171 iv= ~v; 189 iv= ~v;
172 190
191 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
192
173 if (a == NULL) return(0); 193 if (a == NULL) return(0);
174 if ((a->length < (w+1)) || (a->data == NULL)) 194 if ((a->length < (w+1)) || (a->data == NULL))
175 { 195 {
@@ -189,9 +209,7 @@ int value;
189 return(1); 209 return(1);
190 } 210 }
191 211
192int ASN1_BIT_STRING_get_bit(a,n) 212int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n)
193ASN1_BIT_STRING *a;
194int n;
195 { 213 {
196 int w,v; 214 int w,v;
197 215
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62 62
63/* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER); 63int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp)
64 */
65
66int i2d_ASN1_BMPSTRING(a, pp)
67ASN1_BMPSTRING *a;
68unsigned char **pp;
69 { 64 {
70 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
71 V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL)); 66 V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL));
72 } 67 }
73 68
74ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(a, pp, length) 69ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp,
75ASN1_BMPSTRING **a; 70 long length)
76unsigned char **pp;
77long length;
78 { 71 {
79 ASN1_BMPSTRING *ret=NULL; 72 ASN1_BMPSTRING *ret=NULL;
80 73
81 ret=(ASN1_BMPSTRING *)d2i_ASN1_bytes((ASN1_STRING **)a, 74 ret=(ASN1_BMPSTRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
82 pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL); 75 pp,length,V_ASN1_BMPSTRING,V_ASN1_UNIVERSAL);
83 if (ret == NULL) 76 if (ret == NULL)
84 { 77 {
85 ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ASN1_R_ERROR_STACK); 78 ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ERR_R_NESTED_ASN1_ERROR);
86 return(NULL); 79 return(NULL);
87 } 80 }
88 return(ret); 81 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62 62
63/* ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,ASN1_R_EXPECTING_A_BOOLEAN); 63int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
64 * ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
65 */
66
67int i2d_ASN1_BOOLEAN(a,pp)
68int a;
69unsigned char **pp;
70 { 64 {
71 int r; 65 int r;
72 unsigned char *p; 66 unsigned char *p;
@@ -81,10 +75,7 @@ unsigned char **pp;
81 return(r); 75 return(r);
82 } 76 }
83 77
84int d2i_ASN1_BOOLEAN(a, pp, length) 78int d2i_ASN1_BOOLEAN(int *a, unsigned char **pp, long length)
85int *a;
86unsigned char **pp;
87long length;
88 { 79 {
89 int ret= -1; 80 int ret= -1;
90 unsigned char *p; 81 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62
63/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK);
64 * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_ERROR_STACK);
65 * ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,ASN1_R_WRONG_TYPE);
66 * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG);
67 */
68 62
69static unsigned long tag2bit[32]={ 63static unsigned long tag2bit[32]={
700, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */ 640, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
71B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */ 65B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
72B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */ 66B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
73B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 12-15 */ 67B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
740, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, 680, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING,
75B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0, 69B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0,
760,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, 700,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,
77B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, 71B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN,
78 }; 72 };
79 73
80#ifndef NOPROTO
81static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c); 74static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c);
82#else 75/* type is a 'bitmap' of acceptable string types.
83static int asn1_collate_primative();
84#endif
85
86/* type is a 'bitmap' of acceptable string types to be accepted.
87 */ 76 */
88ASN1_STRING *d2i_ASN1_type_bytes(a, pp, length, type) 77ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
89ASN1_STRING **a; 78 long length, int type)
90unsigned char **pp;
91long length;
92int type;
93 { 79 {
94 ASN1_STRING *ret=NULL; 80 ASN1_STRING *ret=NULL;
95 unsigned char *p,*s; 81 unsigned char *p,*s;
@@ -152,11 +138,7 @@ err:
152 return(NULL); 138 return(NULL);
153 } 139 }
154 140
155int i2d_ASN1_bytes(a, pp, tag, xclass) 141int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
156ASN1_STRING *a;
157unsigned char **pp;
158int tag;
159int xclass;
160 { 142 {
161 int ret,r,constructed; 143 int ret,r,constructed;
162 unsigned char *p; 144 unsigned char *p;
@@ -182,12 +164,8 @@ int xclass;
182 return(r); 164 return(r);
183 } 165 }
184 166
185ASN1_STRING *d2i_ASN1_bytes(a, pp, length, Ptag, Pclass) 167ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
186ASN1_STRING **a; 168 int Ptag, int Pclass)
187unsigned char **pp;
188long length;
189int Ptag;
190int Pclass;
191 { 169 {
192 ASN1_STRING *ret=NULL; 170 ASN1_STRING *ret=NULL;
193 unsigned char *p,*s; 171 unsigned char *p,*s;
@@ -279,9 +257,7 @@ err:
279 * them into the one struture that is then returned */ 257 * them into the one struture that is then returned */
280/* There have been a few bug fixes for this function from 258/* There have been a few bug fixes for this function from
281 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ 259 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
282static int asn1_collate_primative(a,c) 260static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c)
283ASN1_STRING *a;
284ASN1_CTX *c;
285 { 261 {
286 ASN1_STRING *os=NULL; 262 ASN1_STRING *os=NULL;
287 BUF_MEM b; 263 BUF_MEM b;
@@ -338,7 +314,7 @@ ASN1_CTX *c;
338 if (os != NULL) ASN1_STRING_free(os); 314 if (os != NULL) ASN1_STRING_free(os);
339 return(1); 315 return(1);
340err: 316err:
341 ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,c->error); 317 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
342 if (os != NULL) ASN1_STRING_free(os); 318 if (os != NULL) ASN1_STRING_free(os);
343 if (b.data != NULL) Free(b.data); 319 if (b.data != NULL) Free(b.data);
344 return(0); 320 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63 63
64#define HEADER_SIZE 8 64#define HEADER_SIZE 8
65 65
66#ifndef NO_FP_API 66#ifndef NO_FP_API
67char *ASN1_d2i_fp(xnew,d2i,in,x) 67char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
68char *(*xnew)(); 68 unsigned char **x)
69char *(*d2i)();
70FILE *in;
71unsigned char **x;
72 { 69 {
73 BIO *b; 70 BIO *b;
74 char *ret; 71 char *ret;
@@ -85,11 +82,8 @@ unsigned char **x;
85 } 82 }
86#endif 83#endif
87 84
88char *ASN1_d2i_bio(xnew,d2i,in,x) 85char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
89char *(*xnew)(); 86 unsigned char **x)
90char *(*d2i)();
91BIO *in;
92unsigned char **x;
93 { 87 {
94 BUF_MEM *b; 88 BUF_MEM *b;
95 unsigned char *p; 89 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 @@
62#include <sys/stat.h> 62#include <sys/stat.h>
63 63
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "evp.h" 65#include <openssl/evp.h>
66#include "x509.h" 66#include <openssl/buffer.h>
67#include "buffer.h" 67#include <openssl/x509.h>
68 68
69int ASN1_digest(i2d,type,data,md,len) 69int ASN1_digest(int (*i2d)(), EVP_MD *type, char *data, unsigned char *md,
70int (*i2d)(); 70 unsigned int *len)
71EVP_MD *type;
72char *data;
73unsigned char *md;
74unsigned int *len;
75 { 71 {
76 EVP_MD_CTX ctx; 72 EVP_MD_CTX ctx;
77 int i; 73 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62 62
63#define READ_CHUNK 2048 63#define READ_CHUNK 2048
64 64
65char *ASN1_dup(i2d,d2i,x) 65char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x)
66int (*i2d)();
67char *(*d2i)();
68char *x;
69 { 66 {
70 unsigned char *b,*p; 67 unsigned char *b,*p;
71 long i; 68 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 @@
1/* crypto/asn1/a_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/*
64 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
65 * for comments on encoding see a_int.c
66 */
67
68int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a, unsigned char **pp)
69 {
70 int pad=0,ret,r,i,t;
71 unsigned char *p,*n,pb=0;
72
73 if ((a == NULL) || (a->data == NULL)) return(0);
74 t=a->type;
75 if (a->length == 0)
76 ret=1;
77 else
78 {
79 ret=a->length;
80 i=a->data[0];
81 if ((t == V_ASN1_ENUMERATED) && (i > 127)) {
82 pad=1;
83 pb=0;
84 } else if(t == V_ASN1_NEG_ENUMERATED) {
85 if(i>128) {
86 pad=1;
87 pb=0xFF;
88 } else if(i == 128) {
89 for(i = 1; i < a->length; i++) if(a->data[i]) {
90 pad=1;
91 pb=0xFF;
92 break;
93 }
94 }
95 }
96 ret+=pad;
97 }
98 r=ASN1_object_size(0,ret,V_ASN1_ENUMERATED);
99 if (pp == NULL) return(r);
100 p= *pp;
101
102 ASN1_put_object(&p,0,ret,V_ASN1_ENUMERATED,V_ASN1_UNIVERSAL);
103 if (pad) *(p++)=pb;
104 if (a->length == 0)
105 *(p++)=0;
106 else if (t == V_ASN1_ENUMERATED)
107 {
108 memcpy(p,a->data,(unsigned int)a->length);
109 p+=a->length;
110 }
111 else {
112 /* Begin at the end of the encoding */
113 n=a->data + a->length - 1;
114 p += a->length - 1;
115 i = a->length;
116 /* Copy zeros to destination as long as source is zero */
117 while(!*n) {
118 *(p--) = 0;
119 n--;
120 i--;
121 }
122 /* Complement and increment next octet */
123 *(p--) = ((*(n--)) ^ 0xff) + 1;
124 i--;
125 /* Complement any octets left */
126 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
127 p += a->length;
128 }
129
130 *pp=p;
131 return(r);
132 }
133
134ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a, unsigned char **pp,
135 long length)
136 {
137 ASN1_ENUMERATED *ret=NULL;
138 unsigned char *p,*to,*s;
139 long len;
140 int inf,tag,xclass;
141 int i;
142
143 if ((a == NULL) || ((*a) == NULL))
144 {
145 if ((ret=ASN1_ENUMERATED_new()) == NULL) return(NULL);
146 ret->type=V_ASN1_ENUMERATED;
147 }
148 else
149 ret=(*a);
150
151 p= *pp;
152 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
153 if (inf & 0x80)
154 {
155 i=ASN1_R_BAD_OBJECT_HEADER;
156 goto err;
157 }
158
159 if (tag != V_ASN1_ENUMERATED)
160 {
161 i=ASN1_R_EXPECTING_AN_ENUMERATED;
162 goto err;
163 }
164
165 /* We must Malloc stuff, even for 0 bytes otherwise it
166 * signifies a missing NULL parameter. */
167 s=(unsigned char *)Malloc((int)len+1);
168 if (s == NULL)
169 {
170 i=ERR_R_MALLOC_FAILURE;
171 goto err;
172 }
173 to=s;
174 if (*p & 0x80) /* a negative number */
175 {
176 ret->type=V_ASN1_NEG_ENUMERATED;
177 if ((*p == 0xff) && (len != 1)) {
178 p++;
179 len--;
180 }
181 i = len;
182 p += i - 1;
183 to += i - 1;
184 while((!*p) && i) {
185 *(to--) = 0;
186 i--;
187 p--;
188 }
189 if(!i) {
190 *s = 1;
191 s[len] = 0;
192 p += len;
193 len++;
194 } else {
195 *(to--) = (*(p--) ^ 0xff) + 1;
196 i--;
197 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
198 p += len;
199 }
200 } else {
201 ret->type=V_ASN1_ENUMERATED;
202 if ((*p == 0) && (len != 1))
203 {
204 p++;
205 len--;
206 }
207 memcpy(s,p,(int)len);
208 p+=len;
209 }
210
211 if (ret->data != NULL) Free((char *)ret->data);
212 ret->data=s;
213 ret->length=(int)len;
214 if (a != NULL) (*a)=ret;
215 *pp=p;
216 return(ret);
217err:
218 ASN1err(ASN1_F_D2I_ASN1_ENUMERATED,i);
219 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
220 ASN1_ENUMERATED_free(ret);
221 return(NULL);
222 }
223
224int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
225 {
226 int i,j,k;
227 unsigned char buf[sizeof(long)+1];
228 long d;
229
230 a->type=V_ASN1_ENUMERATED;
231 if (a->length < (sizeof(long)+1))
232 {
233 if (a->data != NULL)
234 Free((char *)a->data);
235 if ((a->data=(unsigned char *)Malloc(sizeof(long)+1)) != NULL)
236 memset((char *)a->data,0,sizeof(long)+1);
237 }
238 if (a->data == NULL)
239 {
240 ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE);
241 return(0);
242 }
243 d=v;
244 if (d < 0)
245 {
246 d= -d;
247 a->type=V_ASN1_NEG_ENUMERATED;
248 }
249
250 for (i=0; i<sizeof(long); i++)
251 {
252 if (d == 0) break;
253 buf[i]=(int)d&0xff;
254 d>>=8;
255 }
256 j=0;
257 for (k=i-1; k >=0; k--)
258 a->data[j++]=buf[k];
259 a->length=j;
260 return(1);
261 }
262
263long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
264 {
265 int neg=0,i;
266 long r=0;
267
268 if (a == NULL) return(0L);
269 i=a->type;
270 if (i == V_ASN1_NEG_ENUMERATED)
271 neg=1;
272 else if (i != V_ASN1_ENUMERATED)
273 return(0);
274
275 if (a->length > sizeof(long))
276 {
277 /* hmm... a bit ugly */
278 return(0xffffffffL);
279 }
280 if (a->data == NULL)
281 return(0);
282
283 for (i=0; i<a->length; i++)
284 {
285 r<<=8;
286 r|=(unsigned char)a->data[i];
287 }
288 if (neg) r= -r;
289 return(r);
290 }
291
292ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
293 {
294 ASN1_ENUMERATED *ret;
295 int len,j;
296
297 if (ai == NULL)
298 ret=ASN1_ENUMERATED_new();
299 else
300 ret=ai;
301 if (ret == NULL)
302 {
303 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
304 goto err;
305 }
306 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
307 else ret->type=V_ASN1_ENUMERATED;
308 j=BN_num_bits(bn);
309 len=((j == 0)?0:((j/8)+1));
310 ret->data=(unsigned char *)Malloc(len+4);
311 ret->length=BN_bn2bin(bn,ret->data);
312 return(ret);
313err:
314 if (ret != ai) ASN1_ENUMERATED_free(ret);
315 return(NULL);
316 }
317
318BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
319 {
320 BIGNUM *ret;
321
322 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
323 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
324 if(ai->type == V_ASN1_NEG_ENUMERATED) bn->neg = 1;
325 return(ret);
326 }
diff --git a/src/lib/libcrypto/asn1/a_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 @@
1/* crypto/asn1/a_gentm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* GENERALIZEDTIME implementation, written by Steve Henson. Based on UTCTIME */
60
61#include <stdio.h>
62#include <time.h>
63#include "cryptlib.h"
64#include <openssl/asn1.h>
65
66int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
67 {
68#ifdef CHARSET_EBCDIC
69 /* KLUDGE! We convert to ascii before writing DER */
70 int len;
71 char tmp[24];
72 ASN1_STRING tmpstr = *(ASN1_STRING *)a;
73
74 len = tmpstr.length;
75 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
76 tmpstr.data = tmp;
77
78 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
79#endif
80 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
81 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL));
82 }
83
84
85ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
86 unsigned char **pp, long length)
87 {
88 ASN1_GENERALIZEDTIME *ret=NULL;
89
90 ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
91 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL);
92 if (ret == NULL)
93 {
94 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR);
95 return(NULL);
96 }
97#ifdef CHARSET_EBCDIC
98 ascii2ebcdic(ret->data, ret->data, ret->length);
99#endif
100 if (!ASN1_GENERALIZEDTIME_check(ret))
101 {
102 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
103 goto err;
104 }
105
106 return(ret);
107err:
108 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
109 ASN1_GENERALIZEDTIME_free(ret);
110 return(NULL);
111 }
112
113int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
114 {
115 static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
116 static int max[9]={99, 99,12,31,23,59,59,12,59};
117 char *a;
118 int n,i,l,o;
119
120 if (d->type != V_ASN1_GENERALIZEDTIME) return(0);
121 l=d->length;
122 a=(char *)d->data;
123 o=0;
124 /* GENERALIZEDTIME is similar to UTCTIME except the year is
125 * represented as YYYY. This stuff treats everything as a two digit
126 * field so make first two fields 00 to 99
127 */
128 if (l < 13) goto err;
129 for (i=0; i<7; i++)
130 {
131 if ((i == 6) && ((a[o] == 'Z') ||
132 (a[o] == '+') || (a[o] == '-')))
133 { i++; break; }
134 if ((a[o] < '0') || (a[o] > '9')) goto err;
135 n= a[o]-'0';
136 if (++o > l) goto err;
137
138 if ((a[o] < '0') || (a[o] > '9')) goto err;
139 n=(n*10)+ a[o]-'0';
140 if (++o > l) goto err;
141
142 if ((n < min[i]) || (n > max[i])) goto err;
143 }
144 if (a[o] == 'Z')
145 o++;
146 else if ((a[o] == '+') || (a[o] == '-'))
147 {
148 o++;
149 if (o+4 > l) goto err;
150 for (i=7; i<9; i++)
151 {
152 if ((a[o] < '0') || (a[o] > '9')) goto err;
153 n= a[o]-'0';
154 o++;
155 if ((a[o] < '0') || (a[o] > '9')) goto err;
156 n=(n*10)+ a[o]-'0';
157 if ((n < min[i]) || (n > max[i])) goto err;
158 o++;
159 }
160 }
161 return(o == l);
162err:
163 return(0);
164 }
165
166int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str)
167 {
168 ASN1_GENERALIZEDTIME t;
169
170 t.type=V_ASN1_GENERALIZEDTIME;
171 t.length=strlen(str);
172 t.data=(unsigned char *)str;
173 if (ASN1_GENERALIZEDTIME_check(&t))
174 {
175 if (s != NULL)
176 {
177 ASN1_STRING_set((ASN1_STRING *)s,
178 (unsigned char *)str,t.length);
179 }
180 return(1);
181 }
182 else
183 return(0);
184 }
185
186ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
187 time_t t)
188 {
189 char *p;
190 struct tm *ts;
191#if defined(THREADS) && !defined(WIN32)
192 struct tm data;
193#endif
194
195 if (s == NULL)
196 s=ASN1_GENERALIZEDTIME_new();
197 if (s == NULL)
198 return(NULL);
199
200#if defined(THREADS) && !defined(WIN32)
201 gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */
202 ts=&data;
203#else
204 ts=gmtime(&t);
205#endif
206 p=(char *)s->data;
207 if ((p == NULL) || (s->length < 16))
208 {
209 p=Malloc(20);
210 if (p == NULL) return(NULL);
211 if (s->data != NULL)
212 Free(s->data);
213 s->data=(unsigned char *)p;
214 }
215
216 sprintf(p,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
217 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
218 s->length=strlen(p);
219 s->type=V_ASN1_GENERALIZEDTIME;
220#ifdef CHARSET_EBCDIC_not
221 ebcdic2ascii(s->data, s->data, s->length);
222#endif
223 return(s);
224 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "asn1.h" 62#include <openssl/asn1.h>
63 63
64/* 64int i2d_ASN1_HEADER(ASN1_HEADER *a, unsigned char **pp)
65 * ASN1err(ASN1_F_D2I_ASN1_HEADER,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT);
67 * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT);
68 * ASN1err(ASN1_F_ASN1_HEADER_NEW,ASN1_R_BAD_GET_OBJECT);
69 */
70
71int i2d_ASN1_HEADER(a,pp)
72ASN1_HEADER *a;
73unsigned char **pp;
74 { 65 {
75 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
76 67
@@ -85,10 +76,8 @@ unsigned char **pp;
85 M_ASN1_I2D_finish(); 76 M_ASN1_I2D_finish();
86 } 77 }
87 78
88ASN1_HEADER *d2i_ASN1_HEADER(a,pp,length) 79ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a, unsigned char **pp,
89ASN1_HEADER **a; 80 long length)
90unsigned char **pp;
91long length;
92 { 81 {
93 M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new); 82 M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new);
94 83
@@ -107,9 +96,10 @@ long length;
107 M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER); 96 M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER);
108 } 97 }
109 98
110ASN1_HEADER *ASN1_HEADER_new() 99ASN1_HEADER *ASN1_HEADER_new(void)
111 { 100 {
112 ASN1_HEADER *ret=NULL; 101 ASN1_HEADER *ret=NULL;
102 ASN1_CTX c;
113 103
114 M_ASN1_New_Malloc(ret,ASN1_HEADER); 104 M_ASN1_New_Malloc(ret,ASN1_HEADER);
115 M_ASN1_New(ret->header,ASN1_OCTET_STRING_new); 105 M_ASN1_New(ret->header,ASN1_OCTET_STRING_new);
@@ -119,8 +109,7 @@ ASN1_HEADER *ASN1_HEADER_new()
119 M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW); 109 M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW);
120 } 110 }
121 111
122void ASN1_HEADER_free(a) 112void ASN1_HEADER_free(ASN1_HEADER *a)
123ASN1_HEADER *a;
124 { 113 {
125 if (a == NULL) return; 114 if (a == NULL) return;
126 ASN1_OCTET_STRING_free(a->header); 115 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63 63
64#ifndef NO_FP_API 64#ifndef NO_FP_API
65int ASN1_i2d_fp(i2d,out,x) 65int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x)
66int (*i2d)();
67FILE *out;
68unsigned char *x;
69 { 66 {
70 BIO *b; 67 BIO *b;
71 int ret; 68 int ret;
@@ -82,10 +79,7 @@ unsigned char *x;
82 } 79 }
83#endif 80#endif
84 81
85int ASN1_i2d_bio(i2d,out,x) 82int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x)
86int (*i2d)();
87BIO *out;
88unsigned char *x;
89 { 83 {
90 char *b; 84 char *b;
91 unsigned char *p; 85 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62 62
63/* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER); 63/*
64 * This converts an ASN1 INTEGER into its DER encoding.
65 * The internal representation is an ASN1_STRING whose data is a big endian
66 * representation of the value, ignoring the sign. The sign is determined by
67 * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
68 *
69 * Positive integers are no problem: they are almost the same as the DER
70 * encoding, except if the first byte is >= 0x80 we need to add a zero pad.
71 *
72 * Negative integers are a bit trickier...
73 * The DER representation of negative integers is in 2s complement form.
74 * The internal form is converted by complementing each octet and finally
75 * adding one to the result. This can be done less messily with a little trick.
76 * If the internal form has trailing zeroes then they will become FF by the
77 * complement and 0 by the add one (due to carry) so just copy as many trailing
78 * zeros to the destination as there are in the source. The carry will add one
79 * to the last none zero octet: so complement this octet and add one and finally
80 * complement any left over until you get to the start of the string.
81 *
82 * Padding is a little trickier too. If the first bytes is > 0x80 then we pad
83 * with 0xff. However if the first byte is 0x80 and one of the following bytes
84 * is non-zero we pad with 0xff. The reason for this distinction is that 0x80
85 * followed by optional zeros isn't padded.
64 */ 86 */
65 87
66int i2d_ASN1_INTEGER(a,pp) 88int i2d_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
67ASN1_INTEGER *a;
68unsigned char **pp;
69 { 89 {
70 int pad=0,ret,r,i,t; 90 int pad=0,ret,r,i,t;
71 unsigned char *p,*pt,*n,pb=0; 91 unsigned char *p,*n,pb=0;
72 92
73 if ((a == NULL) || (a->data == NULL)) return(0); 93 if ((a == NULL) || (a->data == NULL)) return(0);
74 t=a->type; 94 t=a->type;
@@ -78,16 +98,25 @@ unsigned char **pp;
78 { 98 {
79 ret=a->length; 99 ret=a->length;
80 i=a->data[0]; 100 i=a->data[0];
81 if ((t == V_ASN1_INTEGER) && (i > 127)) 101 if ((t == V_ASN1_INTEGER) && (i > 127)) {
82 {
83 pad=1; 102 pad=1;
84 pb=0; 103 pb=0;
104 } else if(t == V_ASN1_NEG_INTEGER) {
105 if(i>128) {
106 pad=1;
107 pb=0xFF;
108 } else if(i == 128) {
109 /*
110 * Special case: if any other bytes non zero we pad:
111 * otherwise we don't.
112 */
113 for(i = 1; i < a->length; i++) if(a->data[i]) {
114 pad=1;
115 pb=0xFF;
116 break;
117 }
85 } 118 }
86 else if ((t == V_ASN1_NEG_INTEGER) && (i>128)) 119 }
87 {
88 pad=1;
89 pb=0xFF;
90 }
91 ret+=pad; 120 ret+=pad;
92 } 121 }
93 r=ASN1_object_size(0,ret,V_ASN1_INTEGER); 122 r=ASN1_object_size(0,ret,V_ASN1_INTEGER);
@@ -96,33 +125,35 @@ unsigned char **pp;
96 125
97 ASN1_put_object(&p,0,ret,V_ASN1_INTEGER,V_ASN1_UNIVERSAL); 126 ASN1_put_object(&p,0,ret,V_ASN1_INTEGER,V_ASN1_UNIVERSAL);
98 if (pad) *(p++)=pb; 127 if (pad) *(p++)=pb;
99 if (a->length == 0) 128 if (a->length == 0) *(p++)=0;
100 *(p++)=0; 129 else if (t == V_ASN1_INTEGER) memcpy(p,a->data,(unsigned int)a->length);
101 else if (t == V_ASN1_INTEGER) 130 else {
102 { 131 /* Begin at the end of the encoding */
103 memcpy(p,a->data,(unsigned int)a->length); 132 n=a->data + a->length - 1;
104 p+=a->length; 133 p += a->length - 1;
105 } 134 i = a->length;
106 else 135 /* Copy zeros to destination as long as source is zero */
107 { 136 while(!*n) {
108 n=a->data; 137 *(p--) = 0;
109 pt=p; 138 n--;
110 for (i=a->length; i>0; i--) 139 i--;
111 *(p++)= (*(n++)^0xFF)+1;
112 if (!pad) *pt|=0x80;
113 } 140 }
141 /* Complement and increment next octet */
142 *(p--) = ((*(n--)) ^ 0xff) + 1;
143 i--;
144 /* Complement any octets left */
145 for(;i > 0; i--) *(p--) = *(n--) ^ 0xff;
146 }
114 147
115 *pp=p; 148 *pp+=r;
116 return(r); 149 return(r);
117 } 150 }
118 151
119ASN1_INTEGER *d2i_ASN1_INTEGER(a, pp, length) 152ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
120ASN1_INTEGER **a; 153 long length)
121unsigned char **pp;
122long length;
123 { 154 {
124 ASN1_INTEGER *ret=NULL; 155 ASN1_INTEGER *ret=NULL;
125 unsigned char *p,*to,*s; 156 unsigned char *p,*to,*s, *pend;
126 long len; 157 long len;
127 int inf,tag,xclass; 158 int inf,tag,xclass;
128 int i; 159 int i;
@@ -137,6 +168,7 @@ long length;
137 168
138 p= *pp; 169 p= *pp;
139 inf=ASN1_get_object(&p,&len,&tag,&xclass,length); 170 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
171 pend = p + len;
140 if (inf & 0x80) 172 if (inf & 0x80)
141 { 173 {
142 i=ASN1_R_BAD_OBJECT_HEADER; 174 i=ASN1_R_BAD_OBJECT_HEADER;
@@ -161,16 +193,102 @@ long length;
161 if (*p & 0x80) /* a negative number */ 193 if (*p & 0x80) /* a negative number */
162 { 194 {
163 ret->type=V_ASN1_NEG_INTEGER; 195 ret->type=V_ASN1_NEG_INTEGER;
164 if (*p == 0xff) 196 if ((*p == 0xff) && (len != 1)) {
197 p++;
198 len--;
199 }
200 i = len;
201 p += i - 1;
202 to += i - 1;
203 while((!*p) && i) {
204 *(to--) = 0;
205 i--;
206 p--;
207 }
208 /* Special case: if all zeros then the number will be of
209 * the form FF followed by n zero bytes: this corresponds to
210 * 1 followed by n zero bytes. We've already written n zeros
211 * so we just append an extra one and set the first byte to
212 * a 1. This is treated separately because it is the only case
213 * where the number of bytes is larger than len.
214 */
215 if(!i) {
216 *s = 1;
217 s[len] = 0;
218 len++;
219 } else {
220 *(to--) = (*(p--) ^ 0xff) + 1;
221 i--;
222 for(;i > 0; i--) *(to--) = *(p--) ^ 0xff;
223 }
224 } else {
225 ret->type=V_ASN1_INTEGER;
226 if ((*p == 0) && (len != 1))
165 { 227 {
166 p++; 228 p++;
167 len--; 229 len--;
168 } 230 }
169 for (i=(int)len; i>0; i--) 231 memcpy(s,p,(int)len);
170 *(to++)= (*(p++)^0xFF)+1; 232 }
233
234 if (ret->data != NULL) Free((char *)ret->data);
235 ret->data=s;
236 ret->length=(int)len;
237 if (a != NULL) (*a)=ret;
238 *pp=pend;
239 return(ret);
240err:
241 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
242 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
243 ASN1_INTEGER_free(ret);
244 return(NULL);
245 }
246
247/* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of
248 * ASN1 integers: some broken software can encode a positive INTEGER
249 * with its MSB set as negative (it doesn't add a padding zero).
250 */
251
252ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
253 long length)
254 {
255 ASN1_INTEGER *ret=NULL;
256 unsigned char *p,*to,*s;
257 long len;
258 int inf,tag,xclass;
259 int i;
260
261 if ((a == NULL) || ((*a) == NULL))
262 {
263 if ((ret=ASN1_INTEGER_new()) == NULL) return(NULL);
264 ret->type=V_ASN1_INTEGER;
171 } 265 }
172 else 266 else
267 ret=(*a);
268
269 p= *pp;
270 inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
271 if (inf & 0x80)
272 {
273 i=ASN1_R_BAD_OBJECT_HEADER;
274 goto err;
275 }
276
277 if (tag != V_ASN1_INTEGER)
173 { 278 {
279 i=ASN1_R_EXPECTING_AN_INTEGER;
280 goto err;
281 }
282
283 /* We must Malloc stuff, even for 0 bytes otherwise it
284 * signifies a missing NULL parameter. */
285 s=(unsigned char *)Malloc((int)len+1);
286 if (s == NULL)
287 {
288 i=ERR_R_MALLOC_FAILURE;
289 goto err;
290 }
291 to=s;
174 ret->type=V_ASN1_INTEGER; 292 ret->type=V_ASN1_INTEGER;
175 if ((*p == 0) && (len != 1)) 293 if ((*p == 0) && (len != 1))
176 { 294 {
@@ -179,7 +297,6 @@ long length;
179 } 297 }
180 memcpy(s,p,(int)len); 298 memcpy(s,p,(int)len);
181 p+=len; 299 p+=len;
182 }
183 300
184 if (ret->data != NULL) Free((char *)ret->data); 301 if (ret->data != NULL) Free((char *)ret->data);
185 ret->data=s; 302 ret->data=s;
@@ -188,15 +305,13 @@ long length;
188 *pp=p; 305 *pp=p;
189 return(ret); 306 return(ret);
190err: 307err:
191 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i); 308 ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i);
192 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 309 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
193 ASN1_INTEGER_free(ret); 310 ASN1_INTEGER_free(ret);
194 return(NULL); 311 return(NULL);
195 } 312 }
196 313
197int ASN1_INTEGER_set(a,v) 314int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
198ASN1_INTEGER *a;
199long v;
200 { 315 {
201 int i,j,k; 316 int i,j,k;
202 unsigned char buf[sizeof(long)+1]; 317 unsigned char buf[sizeof(long)+1];
@@ -229,15 +344,13 @@ long v;
229 d>>=8; 344 d>>=8;
230 } 345 }
231 j=0; 346 j=0;
232 if (v < 0) a->data[j++]=0;
233 for (k=i-1; k >=0; k--) 347 for (k=i-1; k >=0; k--)
234 a->data[j++]=buf[k]; 348 a->data[j++]=buf[k];
235 a->length=j; 349 a->length=j;
236 return(1); 350 return(1);
237 } 351 }
238 352
239long ASN1_INTEGER_get(a) 353long ASN1_INTEGER_get(ASN1_INTEGER *a)
240ASN1_INTEGER *a;
241 { 354 {
242 int neg=0,i; 355 int neg=0,i;
243 long r=0; 356 long r=0;
@@ -266,9 +379,7 @@ ASN1_INTEGER *a;
266 return(r); 379 return(r);
267 } 380 }
268 381
269ASN1_INTEGER *BN_to_ASN1_INTEGER(bn,ai) 382ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
270BIGNUM *bn;
271ASN1_INTEGER *ai;
272 { 383 {
273 ASN1_INTEGER *ret; 384 ASN1_INTEGER *ret;
274 int len,j; 385 int len,j;
@@ -279,10 +390,11 @@ ASN1_INTEGER *ai;
279 ret=ai; 390 ret=ai;
280 if (ret == NULL) 391 if (ret == NULL)
281 { 392 {
282 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ASN1_R_ERROR_STACK); 393 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
283 goto err; 394 goto err;
284 } 395 }
285 ret->type=V_ASN1_INTEGER; 396 if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
397 else ret->type=V_ASN1_INTEGER;
286 j=BN_num_bits(bn); 398 j=BN_num_bits(bn);
287 len=((j == 0)?0:((j/8)+1)); 399 len=((j == 0)?0:((j/8)+1));
288 ret->data=(unsigned char *)Malloc(len+4); 400 ret->data=(unsigned char *)Malloc(len+4);
@@ -293,13 +405,12 @@ err:
293 return(NULL); 405 return(NULL);
294 } 406 }
295 407
296BIGNUM *ASN1_INTEGER_to_BN(ai,bn) 408BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
297ASN1_INTEGER *ai;
298BIGNUM *bn;
299 { 409 {
300 BIGNUM *ret; 410 BIGNUM *ret;
301 411
302 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) 412 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
303 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB); 413 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
414 if(ai->type == V_ASN1_NEG_INTEGER) bn->neg = 1;
304 return(ret); 415 return(ret);
305 } 416 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "x509.h" 62#include <openssl/asn1.h>
63 63
64static ASN1_METHOD ia5string_meth={ 64static ASN1_METHOD ia5string_meth={
65 (int (*)()) i2d_ASN1_IA5STRING, 65 (int (*)()) i2d_ASN1_IA5STRING,
@@ -73,12 +73,12 @@ static ASN1_METHOD bit_string_meth={
73 (char *(*)()) ASN1_STRING_new, 73 (char *(*)()) ASN1_STRING_new,
74 (void (*)()) ASN1_STRING_free}; 74 (void (*)()) ASN1_STRING_free};
75 75
76ASN1_METHOD *ASN1_IA5STRING_asn1_meth() 76ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void)
77 { 77 {
78 return(&ia5string_meth); 78 return(&ia5string_meth);
79 } 79 }
80 80
81ASN1_METHOD *ASN1_BIT_STRING_asn1_meth() 81ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void)
82 { 82 {
83 return(&bit_string_meth); 83 return(&bit_string_meth);
84 } 84 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "asn1.h" 62#include <openssl/asn1.h>
63#include "objects.h" 63#include <openssl/objects.h>
64 64
65/* ASN1err(ASN1_F_ASN1_OBJECT_NEW,ASN1_R_EXPECTING_AN_OBJECT); 65int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
66 * ASN1err(ASN1_F_D2I_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER);
67 * ASN1err(ASN1_F_I2T_ASN1_OBJECT,ASN1_R_BAD_OBJECT_HEADER);
68 */
69
70int i2d_ASN1_OBJECT(a, pp)
71ASN1_OBJECT *a;
72unsigned char **pp;
73 { 66 {
74 unsigned char *p; 67 unsigned char *p;
75 68
@@ -87,14 +80,11 @@ unsigned char **pp;
87 return(a->length); 80 return(a->length);
88 } 81 }
89 82
90int a2d_ASN1_OBJECT(out,olen,buf,num) 83int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
91unsigned char *out;
92int olen;
93char *buf;
94int num;
95 { 84 {
96 int i,first,len=0,c; 85 int i,first,len=0,c;
97 char tmp[24],*p; 86 char tmp[24];
87 const char *p;
98 unsigned long l; 88 unsigned long l;
99 89
100 if (num == 0) 90 if (num == 0)
@@ -180,85 +170,12 @@ err:
180 return(0); 170 return(0);
181 } 171 }
182 172
183int i2t_ASN1_OBJECT(buf,buf_len,a) 173int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
184char *buf; 174{
185int buf_len; 175 return OBJ_obj2txt(buf, buf_len, a, 0);
186ASN1_OBJECT *a; 176}
187 {
188 int i,idx=0,n=0,len,nid;
189 unsigned long l;
190 unsigned char *p;
191 char *s;
192 char tbuf[32];
193
194 if (buf_len <= 0) return(0);
195
196 if ((a == NULL) || (a->data == NULL))
197 {
198 buf[0]='\0';
199 return(0);
200 }
201
202 nid=OBJ_obj2nid(a);
203 if (nid == NID_undef)
204 {
205 len=a->length;
206 p=a->data;
207
208 idx=0;
209 l=0;
210 while (idx < a->length)
211 {
212 l|=(p[idx]&0x7f);
213 if (!(p[idx] & 0x80)) break;
214 l<<=7L;
215 idx++;
216 }
217 idx++;
218 i=(int)(l/40);
219 if (i > 2) i=2;
220 l-=(long)(i*40);
221
222 sprintf(tbuf,"%d.%ld",i,l);
223 i=strlen(tbuf);
224 strncpy(buf,tbuf,buf_len);
225 buf_len-=i;
226 buf+=i;
227 n+=i;
228
229 l=0;
230 for (; idx<len; idx++)
231 {
232 l|=p[idx]&0x7f;
233 if (!(p[idx] & 0x80))
234 {
235 sprintf(tbuf,".%ld",l);
236 i=strlen(tbuf);
237 if (buf_len > 0)
238 strncpy(buf,tbuf,buf_len);
239 buf_len-=i;
240 buf+=i;
241 n+=i;
242 l=0;
243 }
244 l<<=7L;
245 }
246 }
247 else
248 {
249 s=(char *)OBJ_nid2ln(nid);
250 if (s == NULL)
251 s=(char *)OBJ_nid2sn(nid);
252 strncpy(buf,s,buf_len);
253 n=strlen(s);
254 }
255 buf[buf_len-1]='\0';
256 return(n);
257 }
258 177
259int i2a_ASN1_OBJECT(bp,a) 178int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
260BIO *bp;
261ASN1_OBJECT *a;
262 { 179 {
263 char buf[80]; 180 char buf[80];
264 int i; 181 int i;
@@ -271,10 +188,8 @@ ASN1_OBJECT *a;
271 return(i); 188 return(i);
272 } 189 }
273 190
274ASN1_OBJECT *d2i_ASN1_OBJECT(a, pp, length) 191ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
275ASN1_OBJECT **a; 192 long length)
276unsigned char **pp;
277long length;
278 { 193 {
279 ASN1_OBJECT *ret=NULL; 194 ASN1_OBJECT *ret=NULL;
280 unsigned char *p; 195 unsigned char *p;
@@ -330,7 +245,7 @@ err:
330 return(NULL); 245 return(NULL);
331 } 246 }
332 247
333ASN1_OBJECT *ASN1_OBJECT_new() 248ASN1_OBJECT *ASN1_OBJECT_new(void)
334 { 249 {
335 ASN1_OBJECT *ret; 250 ASN1_OBJECT *ret;
336 251
@@ -349,14 +264,15 @@ ASN1_OBJECT *ASN1_OBJECT_new()
349 return(ret); 264 return(ret);
350 } 265 }
351 266
352void ASN1_OBJECT_free(a) 267void ASN1_OBJECT_free(ASN1_OBJECT *a)
353ASN1_OBJECT *a;
354 { 268 {
355 if (a == NULL) return; 269 if (a == NULL) return;
356 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) 270 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
357 { 271 {
358 if (a->sn != NULL) Free(a->sn); 272#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause mempory leaks */
359 if (a->ln != NULL) Free(a->ln); 273 if (a->sn != NULL) Free((void *)a->sn);
274 if (a->ln != NULL) Free((void *)a->ln);
275#endif
360 a->sn=a->ln=NULL; 276 a->sn=a->ln=NULL;
361 } 277 }
362 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) 278 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
@@ -366,14 +282,11 @@ ASN1_OBJECT *a;
366 a->length=0; 282 a->length=0;
367 } 283 }
368 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) 284 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
369 Free((char *)a); 285 Free(a);
370 } 286 }
371 287
372ASN1_OBJECT *ASN1_OBJECT_create(nid,data,len,sn,ln) 288ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
373int nid; 289 char *sn, char *ln)
374unsigned char *data;
375int len;
376char *sn,*ln;
377 { 290 {
378 ASN1_OBJECT o; 291 ASN1_OBJECT o;
379 292
@@ -382,8 +295,10 @@ char *sn,*ln;
382 o.data=data; 295 o.data=data;
383 o.nid=nid; 296 o.nid=nid;
384 o.length=len; 297 o.length=len;
385 o.flags=ASN1_OBJECT_FLAG_DYNAMIC| 298 o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
386 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA; 299 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
387 return(OBJ_dup(&o)); 300 return(OBJ_dup(&o));
388 } 301 }
389 302
303IMPLEMENT_STACK_OF(ASN1_OBJECT)
304IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT)
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c
index be3f172a8c..7659a13bd3 100644
--- a/src/lib/libcrypto/asn1/a_octet.c
+++ b/src/lib/libcrypto/asn1/a_octet.c
@@ -58,23 +58,16 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62 62
63/* ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ASN1_R_EXPECTING_AN_OCTET_STRING); 63int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)
64 */
65
66int i2d_ASN1_OCTET_STRING(a, pp)
67ASN1_OCTET_STRING *a;
68unsigned char **pp;
69 { 64 {
70 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
71 V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL)); 66 V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL));
72 } 67 }
73 68
74ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(a, pp, length) 69ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
75ASN1_OCTET_STRING **a; 70 unsigned char **pp, long length)
76unsigned char **pp;
77long length;
78 { 71 {
79 ASN1_OCTET_STRING *ret=NULL; 72 ASN1_OCTET_STRING *ret=NULL;
80 73
@@ -82,7 +75,7 @@ long length;
82 pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL); 75 pp,length,V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL);
83 if (ret == NULL) 76 if (ret == NULL)
84 { 77 {
85 ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ASN1_R_ERROR_STACK); 78 ASN1err(ASN1_F_D2I_ASN1_OCTET_STRING,ERR_R_NESTED_ASN1_ERROR);
86 return(NULL); 79 return(NULL);
87 } 80 }
88 return(ret); 81 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62 62
63/* ASN1err(ASN1_F_D2I_ASN1_PRINT_TYPE,ASN1_R_WRONG_PRINTABLE_TYPE); 63int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a, unsigned char **pp)
64 * ASN1err(ASN1_F_D2I_ASN1_PRINT_TYPE,ASN1_R_TAG_VALUE_TOO_HIGH);
65 */
66
67int i2d_ASN1_IA5STRING(a,pp)
68ASN1_IA5STRING *a;
69unsigned char **pp;
70 { return(M_i2d_ASN1_IA5STRING(a,pp)); } 64 { return(M_i2d_ASN1_IA5STRING(a,pp)); }
71 65
72ASN1_IA5STRING *d2i_ASN1_IA5STRING(a,pp,l) 66ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **a, unsigned char **pp,
73ASN1_IA5STRING **a; 67 long l)
74unsigned char **pp;
75long l;
76 { return(M_d2i_ASN1_IA5STRING(a,pp,l)); } 68 { return(M_d2i_ASN1_IA5STRING(a,pp,l)); }
77 69
78ASN1_T61STRING *d2i_ASN1_T61STRING(a,pp,l) 70ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, unsigned char **pp,
79ASN1_T61STRING **a; 71 long l)
80unsigned char **pp;
81long l;
82 { return(M_d2i_ASN1_T61STRING(a,pp,l)); } 72 { return(M_d2i_ASN1_T61STRING(a,pp,l)); }
83 73
84ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(a,pp,l) 74ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
85ASN1_PRINTABLESTRING **a; 75 unsigned char **pp, long l)
86unsigned char **pp; 76 { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,
87long l; 77 l)); }
88 { return(M_d2i_ASN1_PRINTABLESTRING(a,pp,l)); }
89 78
90int i2d_ASN1_PRINTABLE(a,pp) 79int i2d_ASN1_PRINTABLE(ASN1_STRING *a, unsigned char **pp)
91ASN1_STRING *a;
92unsigned char **pp;
93 { return(M_i2d_ASN1_PRINTABLE(a,pp)); } 80 { return(M_i2d_ASN1_PRINTABLE(a,pp)); }
94 81
95ASN1_STRING *d2i_ASN1_PRINTABLE(a,pp,l) 82ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, unsigned char **pp,
96ASN1_STRING **a; 83 long l)
97unsigned char **pp;
98long l;
99 { return(M_d2i_ASN1_PRINTABLE(a,pp,l)); } 84 { return(M_d2i_ASN1_PRINTABLE(a,pp,l)); }
100 85
101int ASN1_PRINTABLE_type(s,len) 86int ASN1_PRINTABLE_type(unsigned char *s, int len)
102unsigned char *s;
103int len;
104 { 87 {
105 int c; 88 int c;
106 int ia5=0; 89 int ia5=0;
@@ -112,6 +95,7 @@ int len;
112 while ((*s) && (len-- != 0)) 95 while ((*s) && (len-- != 0))
113 { 96 {
114 c= *(s++); 97 c= *(s++);
98#ifndef CHARSET_EBCDIC
115 if (!( ((c >= 'a') && (c <= 'z')) || 99 if (!( ((c >= 'a') && (c <= 'z')) ||
116 ((c >= 'A') && (c <= 'Z')) || 100 ((c >= 'A') && (c <= 'Z')) ||
117 (c == ' ') || 101 (c == ' ') ||
@@ -125,14 +109,20 @@ int len;
125 ia5=1; 109 ia5=1;
126 if (c&0x80) 110 if (c&0x80)
127 t61=1; 111 t61=1;
112#else
113 if (!isalnum(c) && (c != ' ') &&
114 strchr("'()+,-./:=?", c) == NULL)
115 ia5=1;
116 if (os_toascii[c] & 0x80)
117 t61=1;
118#endif
128 } 119 }
129 if (t61) return(V_ASN1_T61STRING); 120 if (t61) return(V_ASN1_T61STRING);
130 if (ia5) return(V_ASN1_IA5STRING); 121 if (ia5) return(V_ASN1_IA5STRING);
131 return(V_ASN1_PRINTABLESTRING); 122 return(V_ASN1_PRINTABLESTRING);
132 } 123 }
133 124
134int ASN1_UNIVERSALSTRING_to_string(s) 125int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s)
135ASN1_UNIVERSALSTRING *s;
136 { 126 {
137 int i; 127 int i;
138 unsigned char *p; 128 unsigned char *p;
@@ -159,3 +149,17 @@ ASN1_UNIVERSALSTRING *s;
159 return(1); 149 return(1);
160 } 150 }
161 151
152
153int i2d_DIRECTORYSTRING(ASN1_STRING *a, unsigned char **pp)
154 { return(M_i2d_DIRECTORYSTRING(a,pp)); }
155
156ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
157 long l)
158 { return(M_d2i_DIRECTORYSTRING(a,pp,l)); }
159
160int i2d_DISPLAYTEXT(ASN1_STRING *a, unsigned char **pp)
161 { return(M_i2d_DISPLAYTEXT(a,pp)); }
162
163ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp,
164 long l)
165 { return(M_d2i_DISPLAYTEXT(a,pp,l)); }
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
index 17c49946cf..c2481e7597 100644
--- a/src/lib/libcrypto/asn1/a_set.c
+++ b/src/lib/libcrypto/asn1/a_set.c
@@ -58,21 +58,40 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62 62
63/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ERR_R_MALLOC_FAILURE); 63typedef struct
64 {
65 unsigned char *pbData;
66 int cbData;
67 } MYBLOB;
68
69/* SetBlobCmp
70 * This function compares two elements of SET_OF block
64 */ 71 */
72static int SetBlobCmp(const void *elem1, const void *elem2 )
73 {
74 const MYBLOB *b1 = (const MYBLOB *)elem1;
75 const MYBLOB *b2 = (const MYBLOB *)elem2;
76 int r;
77
78 r = memcmp(b1->pbData, b2->pbData,
79 b1->cbData < b2->cbData ? b1->cbData : b2->cbData);
80 if(r != 0)
81 return r;
82 return b1->cbData-b2->cbData;
83 }
65 84
66int i2d_ASN1_SET(a,pp,func,ex_tag,ex_class) 85/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
67STACK *a; 86int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,
68unsigned char **pp; 87 int ex_class, int is_set)
69int (*func)();
70int ex_tag;
71int ex_class;
72 { 88 {
73 int ret=0,r; 89 int ret=0,r;
74 int i; 90 int i;
75 unsigned char *p; 91 unsigned char *p;
92 unsigned char *pStart, *pTempMem;
93 MYBLOB *rgSetBlob;
94 int totSize;
76 95
77 if (a == NULL) return(0); 96 if (a == NULL) return(0);
78 for (i=sk_num(a)-1; i>=0; i--) 97 for (i=sk_num(a)-1; i>=0; i--)
@@ -82,20 +101,58 @@ int ex_class;
82 101
83 p= *pp; 102 p= *pp;
84 ASN1_put_object(&p,1,ret,ex_tag,ex_class); 103 ASN1_put_object(&p,1,ret,ex_tag,ex_class);
85 for (i=0; i<sk_num(a); i++)
86 func(sk_value(a,i),&p);
87 104
88 *pp=p; 105/* Modified by gp@nsj.co.jp */
89 return(r); 106 /* And then again by Ben */
90 } 107 /* And again by Steve */
108
109 if(!is_set || (sk_num(a) < 2))
110 {
111 for (i=0; i<sk_num(a); i++)
112 func(sk_value(a,i),&p);
113
114 *pp=p;
115 return(r);
116 }
117
118 pStart = p; /* Catch the beg of Setblobs*/
119 rgSetBlob = (MYBLOB *)Malloc( sk_num(a) * sizeof(MYBLOB)); /* In this array
120we will store the SET blobs */
121
122 for (i=0; i<sk_num(a); i++)
123 {
124 rgSetBlob[i].pbData = p; /* catch each set encode blob */
125 func(sk_value(a,i),&p);
126 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
127SetBlob
128*/
129 }
130 *pp=p;
131 totSize = p - pStart; /* This is the total size of all set blobs */
132
133 /* Now we have to sort the blobs. I am using a simple algo.
134 *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/
135 qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp);
136 pTempMem = Malloc(totSize);
137
138/* Copy to temp mem */
139 p = pTempMem;
140 for(i=0; i<sk_num(a); ++i)
141 {
142 memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData);
143 p += rgSetBlob[i].cbData;
144 }
91 145
92STACK *d2i_ASN1_SET(a,pp,length,func,ex_tag,ex_class) 146/* Copy back to user mem*/
93STACK **a; 147 memcpy(pStart, pTempMem, totSize);
94unsigned char **pp; 148 Free(pTempMem);
95long length; 149 Free(rgSetBlob);
96char *(*func)(); 150
97int ex_tag; 151 return(r);
98int ex_class; 152 }
153
154STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
155 char *(*func)(), void (*free_func)(), int ex_tag, int ex_class)
99 { 156 {
100 ASN1_CTX c; 157 ASN1_CTX c;
101 STACK *ret=NULL; 158 STACK *ret=NULL;
@@ -136,14 +193,25 @@ int ex_class;
136 char *s; 193 char *s;
137 194
138 if (M_ASN1_D2I_end_sequence()) break; 195 if (M_ASN1_D2I_end_sequence()) break;
139 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) goto err; 196 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
197 {
198 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
199 asn1_add_error(*pp,(int)(c.q- *pp));
200 goto err;
201 }
140 if (!sk_push(ret,s)) goto err; 202 if (!sk_push(ret,s)) goto err;
141 } 203 }
142 if (a != NULL) (*a)=ret; 204 if (a != NULL) (*a)=ret;
143 *pp=c.p; 205 *pp=c.p;
144 return(ret); 206 return(ret);
145err: 207err:
146 if ((ret != NULL) && ((a == NULL) || (*a != ret))) sk_free(ret); 208 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
209 {
210 if (free_func != NULL)
211 sk_pop_free(ret,free_func);
212 else
213 sk_free(ret);
214 }
147 return(NULL); 215 return(NULL);
148 } 216 }
149 217
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
index 02188e68c4..57595692e5 100644
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -62,21 +62,15 @@
62#include <sys/stat.h> 62#include <sys/stat.h>
63 63
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bn.h" 65#include <openssl/bn.h>
66#include "evp.h" 66#include <openssl/evp.h>
67#include "x509.h" 67#include <openssl/x509.h>
68#include "objects.h" 68#include <openssl/objects.h>
69#include "buffer.h" 69#include <openssl/buffer.h>
70#include "pem.h"
71 70
72int ASN1_sign(i2d,algor1,algor2,signature,data,pkey,type) 71int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
73int (*i2d)(); 72 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
74X509_ALGOR *algor1; 73 const EVP_MD *type)
75X509_ALGOR *algor2;
76ASN1_BIT_STRING *signature;
77char *data;
78EVP_PKEY *pkey;
79EVP_MD *type;
80 { 74 {
81 EVP_MD_CTX ctx; 75 EVP_MD_CTX ctx;
82 unsigned char *p,*buf_in=NULL,*buf_out=NULL; 76 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
@@ -136,7 +130,11 @@ EVP_MD *type;
136 signature->data=buf_out; 130 signature->data=buf_out;
137 buf_out=NULL; 131 buf_out=NULL;
138 signature->length=outl; 132 signature->length=outl;
139 133 /* In the interests of compatability, I'll make sure that
134 * the bit string has a 'not-used bits' value of 0
135 */
136 signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
137 signature->flags|=ASN1_STRING_FLAG_BITS_LEFT;
140err: 138err:
141 memset(&ctx,0,sizeof(ctx)); 139 memset(&ctx,0,sizeof(ctx));
142 if (buf_in != NULL) 140 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 @@
1/* crypto/asn1/a_time.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56
57/* This is an implementation of the ASN1 Time structure which is:
58 * Time ::= CHOICE {
59 * utcTime UTCTime,
60 * generalTime GeneralizedTime }
61 * written by Steve Henson.
62 */
63
64#include <stdio.h>
65#include <time.h>
66#include "cryptlib.h"
67#include <openssl/asn1.h>
68
69int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp)
70 {
71#ifdef CHARSET_EBCDIC
72 /* KLUDGE! We convert to ascii before writing DER */
73 char tmp[24];
74 ASN1_STRING tmpstr;
75
76 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) {
77 int len;
78
79 tmpstr = *(ASN1_STRING *)a;
80 len = tmpstr.length;
81 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
82 tmpstr.data = tmp;
83 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
84 }
85#endif
86 if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
87 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
88 a->type ,V_ASN1_UNIVERSAL));
89 ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
90 return -1;
91 }
92
93
94ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **a, unsigned char **pp, long length)
95 {
96 unsigned char tag;
97 tag = **pp & ~V_ASN1_CONSTRUCTED;
98 if(tag == (V_ASN1_UTCTIME|V_ASN1_UNIVERSAL))
99 return d2i_ASN1_UTCTIME(a, pp, length);
100 if(tag == (V_ASN1_GENERALIZEDTIME|V_ASN1_UNIVERSAL))
101 return d2i_ASN1_GENERALIZEDTIME(a, pp, length);
102 ASN1err(ASN1_F_D2I_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
103 return(NULL);
104 }
105
106
107ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
108 {
109 struct tm *ts;
110#if defined(THREADS) && !defined(WIN32)
111 struct tm data;
112#endif
113
114#if defined(THREADS) && !defined(WIN32)
115 gmtime_r(&t,&data);
116 ts=&data; /* should return &data, but doesn't on some systems, so we don't even look at the return value */
117#else
118 ts=gmtime(&t);
119#endif
120 if((ts->tm_year >= 50) && (ts->tm_year < 150))
121 return ASN1_UTCTIME_set(s, t);
122 return ASN1_GENERALIZEDTIME_set(s,t);
123 }
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
index 7c0004084c..3f2ecee5c2 100644
--- a/src/lib/libcrypto/asn1/a_type.c
+++ b/src/lib/libcrypto/asn1/a_type.c
@@ -58,23 +58,10 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62 62
63/* ASN1err(ASN1_F_ASN1_TYPE_NEW,ASN1_R_ERROR_STACK);
64 * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_ERROR_STACK);
65 * ASN1err(ASN1_F_D2I_ASN1_BYTES,ASN1_R_WRONG_TAG);
66 * ASN1err(ASN1_F_ASN1_COLLATE_PRIMATIVE,ASN1_R_WRONG_TAG);
67 */
68
69#ifndef NOPROTO
70static void ASN1_TYPE_component_free(ASN1_TYPE *a); 63static void ASN1_TYPE_component_free(ASN1_TYPE *a);
71#else 64int i2d_ASN1_TYPE(ASN1_TYPE *a, unsigned char **pp)
72static void ASN1_TYPE_component_free();
73#endif
74
75int i2d_ASN1_TYPE(a,pp)
76ASN1_TYPE *a;
77unsigned char **pp;
78 { 65 {
79 int r=0; 66 int r=0;
80 67
@@ -91,6 +78,10 @@ unsigned char **pp;
91 case V_ASN1_NEG_INTEGER: 78 case V_ASN1_NEG_INTEGER:
92 r=i2d_ASN1_INTEGER(a->value.integer,pp); 79 r=i2d_ASN1_INTEGER(a->value.integer,pp);
93 break; 80 break;
81 case V_ASN1_ENUMERATED:
82 case V_ASN1_NEG_ENUMERATED:
83 r=i2d_ASN1_ENUMERATED(a->value.enumerated,pp);
84 break;
94 case V_ASN1_BIT_STRING: 85 case V_ASN1_BIT_STRING:
95 r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp); 86 r=i2d_ASN1_BIT_STRING(a->value.bit_string,pp);
96 break; 87 break;
@@ -115,12 +106,21 @@ unsigned char **pp;
115 case V_ASN1_UNIVERSALSTRING: 106 case V_ASN1_UNIVERSALSTRING:
116 r=M_i2d_ASN1_UNIVERSALSTRING(a->value.universalstring,pp); 107 r=M_i2d_ASN1_UNIVERSALSTRING(a->value.universalstring,pp);
117 break; 108 break;
109 case V_ASN1_UTF8STRING:
110 r=M_i2d_ASN1_UTF8STRING(a->value.utf8string,pp);
111 break;
112 case V_ASN1_VISIBLESTRING:
113 r=M_i2d_ASN1_VISIBLESTRING(a->value.visiblestring,pp);
114 break;
118 case V_ASN1_BMPSTRING: 115 case V_ASN1_BMPSTRING:
119 r=M_i2d_ASN1_BMPSTRING(a->value.bmpstring,pp); 116 r=M_i2d_ASN1_BMPSTRING(a->value.bmpstring,pp);
120 break; 117 break;
121 case V_ASN1_UTCTIME: 118 case V_ASN1_UTCTIME:
122 r=i2d_ASN1_UTCTIME(a->value.utctime,pp); 119 r=i2d_ASN1_UTCTIME(a->value.utctime,pp);
123 break; 120 break;
121 case V_ASN1_GENERALIZEDTIME:
122 r=i2d_ASN1_GENERALIZEDTIME(a->value.generalizedtime,pp);
123 break;
124 case V_ASN1_SET: 124 case V_ASN1_SET:
125 case V_ASN1_SEQUENCE: 125 case V_ASN1_SEQUENCE:
126 if (a->value.set == NULL) 126 if (a->value.set == NULL)
@@ -139,10 +139,7 @@ unsigned char **pp;
139 return(r); 139 return(r);
140 } 140 }
141 141
142ASN1_TYPE *d2i_ASN1_TYPE(a,pp,length) 142ASN1_TYPE *d2i_ASN1_TYPE(ASN1_TYPE **a, unsigned char **pp, long length)
143ASN1_TYPE **a;
144unsigned char **pp;
145long length;
146 { 143 {
147 ASN1_TYPE *ret=NULL; 144 ASN1_TYPE *ret=NULL;
148 unsigned char *q,*p,*max; 145 unsigned char *q,*p,*max;
@@ -176,6 +173,11 @@ long length;
176 d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL) 173 d2i_ASN1_INTEGER(NULL,&p,max-p)) == NULL)
177 goto err; 174 goto err;
178 break; 175 break;
176 case V_ASN1_ENUMERATED:
177 if ((ret->value.enumerated=
178 d2i_ASN1_ENUMERATED(NULL,&p,max-p)) == NULL)
179 goto err;
180 break;
179 case V_ASN1_BIT_STRING: 181 case V_ASN1_BIT_STRING:
180 if ((ret->value.bit_string= 182 if ((ret->value.bit_string=
181 d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL) 183 d2i_ASN1_BIT_STRING(NULL,&p,max-p)) == NULL)
@@ -186,6 +188,16 @@ long length;
186 d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL) 188 d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL)
187 goto err; 189 goto err;
188 break; 190 break;
191 case V_ASN1_VISIBLESTRING:
192 if ((ret->value.visiblestring=
193 d2i_ASN1_VISIBLESTRING(NULL,&p,max-p)) == NULL)
194 goto err;
195 break;
196 case V_ASN1_UTF8STRING:
197 if ((ret->value.utf8string=
198 d2i_ASN1_UTF8STRING(NULL,&p,max-p)) == NULL)
199 goto err;
200 break;
189 case V_ASN1_OBJECT: 201 case V_ASN1_OBJECT:
190 if ((ret->value.object= 202 if ((ret->value.object=
191 d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL) 203 d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL)
@@ -226,6 +238,11 @@ long length;
226 d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL) 238 d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL)
227 goto err; 239 goto err;
228 break; 240 break;
241 case V_ASN1_GENERALIZEDTIME:
242 if ((ret->value.generalizedtime=
243 d2i_ASN1_GENERALIZEDTIME(NULL,&p,max-p)) == NULL)
244 goto err;
245 break;
229 case V_ASN1_SET: 246 case V_ASN1_SET:
230 case V_ASN1_SEQUENCE: 247 case V_ASN1_SEQUENCE:
231 /* Sets and sequences are left complete */ 248 /* Sets and sequences are left complete */
@@ -249,9 +266,10 @@ err:
249 return(NULL); 266 return(NULL);
250 } 267 }
251 268
252ASN1_TYPE *ASN1_TYPE_new() 269ASN1_TYPE *ASN1_TYPE_new(void)
253 { 270 {
254 ASN1_TYPE *ret=NULL; 271 ASN1_TYPE *ret=NULL;
272 ASN1_CTX c;
255 273
256 M_ASN1_New_Malloc(ret,ASN1_TYPE); 274 M_ASN1_New_Malloc(ret,ASN1_TYPE);
257 ret->type= -1; 275 ret->type= -1;
@@ -260,16 +278,14 @@ ASN1_TYPE *ASN1_TYPE_new()
260 M_ASN1_New_Error(ASN1_F_ASN1_TYPE_NEW); 278 M_ASN1_New_Error(ASN1_F_ASN1_TYPE_NEW);
261 } 279 }
262 280
263void ASN1_TYPE_free(a) 281void ASN1_TYPE_free(ASN1_TYPE *a)
264ASN1_TYPE *a;
265 { 282 {
266 if (a == NULL) return; 283 if (a == NULL) return;
267 ASN1_TYPE_component_free(a); 284 ASN1_TYPE_component_free(a);
268 Free((char *)(char *)a); 285 Free((char *)(char *)a);
269 } 286 }
270 287
271int ASN1_TYPE_get(a) 288int ASN1_TYPE_get(ASN1_TYPE *a)
272ASN1_TYPE *a;
273 { 289 {
274 if (a->value.ptr != NULL) 290 if (a->value.ptr != NULL)
275 return(a->type); 291 return(a->type);
@@ -277,10 +293,7 @@ ASN1_TYPE *a;
277 return(0); 293 return(0);
278 } 294 }
279 295
280void ASN1_TYPE_set(a,type,value) 296void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
281ASN1_TYPE *a;
282int type;
283char *value;
284 { 297 {
285 if (a->value.ptr != NULL) 298 if (a->value.ptr != NULL)
286 ASN1_TYPE_component_free(a); 299 ASN1_TYPE_component_free(a);
@@ -288,8 +301,7 @@ char *value;
288 a->value.ptr=value; 301 a->value.ptr=value;
289 } 302 }
290 303
291static void ASN1_TYPE_component_free(a) 304static void ASN1_TYPE_component_free(ASN1_TYPE *a)
292ASN1_TYPE *a;
293 { 305 {
294 if (a == NULL) return; 306 if (a == NULL) return;
295 307
@@ -302,16 +314,25 @@ ASN1_TYPE *a;
302 break; 314 break;
303 case V_ASN1_INTEGER: 315 case V_ASN1_INTEGER:
304 case V_ASN1_NEG_INTEGER: 316 case V_ASN1_NEG_INTEGER:
317 case V_ASN1_ENUMERATED:
318 case V_ASN1_NEG_ENUMERATED:
305 case V_ASN1_BIT_STRING: 319 case V_ASN1_BIT_STRING:
306 case V_ASN1_OCTET_STRING: 320 case V_ASN1_OCTET_STRING:
321 case V_ASN1_SEQUENCE:
322 case V_ASN1_SET:
323 case V_ASN1_NUMERICSTRING:
307 case V_ASN1_PRINTABLESTRING: 324 case V_ASN1_PRINTABLESTRING:
308 case V_ASN1_T61STRING: 325 case V_ASN1_T61STRING:
326 case V_ASN1_VIDEOTEXSTRING:
309 case V_ASN1_IA5STRING: 327 case V_ASN1_IA5STRING:
310 case V_ASN1_UNIVERSALSTRING:
311 case V_ASN1_GENERALSTRING:
312 case V_ASN1_UTCTIME: 328 case V_ASN1_UTCTIME:
313 case V_ASN1_SET: 329 case V_ASN1_GENERALIZEDTIME:
314 case V_ASN1_SEQUENCE: 330 case V_ASN1_GRAPHICSTRING:
331 case V_ASN1_VISIBLESTRING:
332 case V_ASN1_GENERALSTRING:
333 case V_ASN1_UNIVERSALSTRING:
334 case V_ASN1_BMPSTRING:
335 case V_ASN1_UTF8STRING:
315 ASN1_STRING_free((ASN1_STRING *)a->value.ptr); 336 ASN1_STRING_free((ASN1_STRING *)a->value.ptr);
316 break; 337 break;
317 default: 338 default:
@@ -323,3 +344,5 @@ ASN1_TYPE *a;
323 } 344 }
324 } 345 }
325 346
347IMPLEMENT_STACK_OF(ASN1_TYPE)
348IMPLEMENT_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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#ifdef VMS
62#include <descrip.h>
63#include <lnmdef.h>
64#include <starlet.h>
65#endif
61#include "cryptlib.h" 66#include "cryptlib.h"
62#include "asn1.h" 67#include <openssl/asn1.h>
63
64/* ASN1err(ASN1_F_ASN1_UTCTIME_NEW,ASN1_R_UTCTIME_TOO_LONG);
65 * ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_EXPECTING_A_UTCTIME);
66 */
67 68
68int i2d_ASN1_UTCTIME(a,pp) 69int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
69ASN1_UTCTIME *a;
70unsigned char **pp;
71 { 70 {
71#ifndef CHARSET_EBCDIC
72 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 72 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
73 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); 73 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL));
74#else
75 /* KLUDGE! We convert to ascii before writing DER */
76 int len;
77 char tmp[24];
78 ASN1_STRING x = *(ASN1_STRING *)a;
79
80 len = x.length;
81 ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len);
82 x.data = tmp;
83 return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
84#endif
74 } 85 }
75 86
76 87
77ASN1_UTCTIME *d2i_ASN1_UTCTIME(a, pp, length) 88ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
78ASN1_UTCTIME **a; 89 long length)
79unsigned char **pp;
80long length;
81 { 90 {
82 ASN1_UTCTIME *ret=NULL; 91 ASN1_UTCTIME *ret=NULL;
83 92
@@ -85,9 +94,12 @@ long length;
85 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); 94 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
86 if (ret == NULL) 95 if (ret == NULL)
87 { 96 {
88 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_ERROR_STACK); 97 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR);
89 return(NULL); 98 return(NULL);
90 } 99 }
100#ifdef CHARSET_EBCDIC
101 ascii2ebcdic(ret->data, ret->data, ret->length);
102#endif
91 if (!ASN1_UTCTIME_check(ret)) 103 if (!ASN1_UTCTIME_check(ret))
92 { 104 {
93 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); 105 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
@@ -101,8 +113,7 @@ err:
101 return(NULL); 113 return(NULL);
102 } 114 }
103 115
104int ASN1_UTCTIME_check(d) 116int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
105ASN1_UTCTIME *d;
106 { 117 {
107 static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; 118 static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
108 static int max[8]={99,12,31,23,59,59,12,59}; 119 static int max[8]={99,12,31,23,59,59,12,59};
@@ -152,9 +163,7 @@ err:
152 return(0); 163 return(0);
153 } 164 }
154 165
155int ASN1_UTCTIME_set_string(s,str) 166int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str)
156ASN1_UTCTIME *s;
157char *str;
158 { 167 {
159 ASN1_UTCTIME t; 168 ASN1_UTCTIME t;
160 169
@@ -174,13 +183,11 @@ char *str;
174 return(0); 183 return(0);
175 } 184 }
176 185
177ASN1_UTCTIME *ASN1_UTCTIME_set(s, t) 186ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
178ASN1_UTCTIME *s;
179time_t t;
180 { 187 {
181 char *p; 188 char *p;
182 struct tm *ts; 189 struct tm *ts;
183#if defined(THREADS) 190#if defined(THREADS) && !defined(WIN32)
184 struct tm data; 191 struct tm data;
185#endif 192#endif
186 193
@@ -189,10 +196,48 @@ time_t t;
189 if (s == NULL) 196 if (s == NULL)
190 return(NULL); 197 return(NULL);
191 198
192#if defined(THREADS) 199#if defined(THREADS) && !defined(WIN32)
193 ts=(struct tm *)gmtime_r(&t,&data); 200 gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */
201 ts=&data;
194#else 202#else
195 ts=(struct tm *)gmtime(&t); 203 ts=gmtime(&t);
204#endif
205#ifdef VMS
206 if (ts == NULL)
207 {
208 static $DESCRIPTOR(tabnam,"LNM$DCL_LOGICAL");
209 static $DESCRIPTOR(lognam,"SYS$TIMEZONE_DIFFERENTIAL");
210 char result[256];
211 unsigned int reslen = 0;
212 struct {
213 short buflen;
214 short code;
215 void *bufaddr;
216 unsigned int *reslen;
217 } itemlist[] = {
218 { 0, LNM$_STRING, 0, 0 },
219 { 0, 0, 0, 0 },
220 };
221 int status;
222
223 /* Get the value for SYS$TIMEZONE_DIFFERENTIAL */
224 itemlist[0].buflen = sizeof(result);
225 itemlist[0].bufaddr = result;
226 itemlist[0].reslen = &reslen;
227 status = sys$trnlnm(0, &tabnam, &lognam, 0, itemlist);
228 if (!(status & 1))
229 return NULL;
230 result[reslen] = '\0';
231
232 /* Get the numerical value of the equivalence string */
233 status = atoi(result);
234
235 /* and use it to move time to GMT */
236 t -= status;
237
238 /* then convert the result to the time structure */
239 ts=(struct tm *)localtime(&t);
240 }
196#endif 241#endif
197 p=(char *)s->data; 242 p=(char *)s->data;
198 if ((p == NULL) || (s->length < 14)) 243 if ((p == NULL) || (s->length < 14))
@@ -208,5 +253,8 @@ time_t t;
208 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); 253 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
209 s->length=strlen(p); 254 s->length=strlen(p);
210 s->type=V_ASN1_UTCTIME; 255 s->type=V_ASN1_UTCTIME;
256#ifdef CHARSET_EBCDIC_not
257 ebcdic2ascii(s->data, s->data, s->length);
258#endif
211 return(s); 259 return(s);
212 } 260 }
diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/asn1/a_utf8.c
index c351aac14f..4a8a92e9e4 100644
--- a/src/lib/libcrypto/bn/bn_mod.c
+++ b/src/lib/libcrypto/asn1/a_utf8.c
@@ -1,4 +1,4 @@
1/* crypto/bn/bn_mod.c */ 1/* crypto/asn1/a_utf8.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -58,40 +58,26 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include <openssl/asn1.h>
62 62
63/* rem != m */ 63int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a, unsigned char **pp)
64int BN_mod(rem, m, d,ctx)
65BIGNUM *rem;
66BIGNUM *m;
67BIGNUM *d;
68BN_CTX *ctx;
69 { 64 {
70#if 0 /* The old slow way */ 65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
71 int i,nm,nd; 66 V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL));
72 BIGNUM *dv; 67 }
73
74 if (BN_ucmp(m,d) < 0)
75 return((BN_copy(rem,m) == NULL)?0:1);
76
77 dv=ctx->bn[ctx->tos];
78 68
79 if (!BN_copy(rem,m)) return(0); 69ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a, unsigned char **pp,
70 long length)
71 {
72 ASN1_UTF8STRING *ret=NULL;
80 73
81 nm=BN_num_bits(rem); 74 ret=(ASN1_UTF8STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
82 nd=BN_num_bits(d); 75 pp,length,V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL);
83 if (!BN_lshift(dv,d,nm-nd)) return(0); 76 if (ret == NULL)
84 for (i=nm-nd; i>=0; i--)
85 { 77 {
86 if (BN_cmp(rem,dv) >= 0) 78 ASN1err(ASN1_F_D2I_ASN1_UTF8STRING,ERR_R_NESTED_ASN1_ERROR);
87 { 79 return(NULL);
88 if (!BN_sub(rem,rem,dv)) return(0);
89 }
90 if (!BN_rshift1(dv,dv)) return(0);
91 } 80 }
92 return(1); 81 return(ret);
93#else
94 return(BN_div(NULL,rem,m,d,ctx));
95#endif
96 } 82 }
97 83
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 @@
62#include <sys/stat.h> 62#include <sys/stat.h>
63 63
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bn.h" 65#include <openssl/bn.h>
66#include "x509.h" 66#include <openssl/x509.h>
67#include "objects.h" 67#include <openssl/objects.h>
68#include "buffer.h" 68#include <openssl/buffer.h>
69#include "evp.h" 69#include <openssl/evp.h>
70#include "pem.h"
71 70
72int ASN1_verify(i2d,a,signature,data,pkey) 71int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
73int (*i2d)(); 72 char *data, EVP_PKEY *pkey)
74X509_ALGOR *a;
75ASN1_BIT_STRING *signature;
76char *data;
77EVP_PKEY *pkey;
78 { 73 {
79 EVP_MD_CTX ctx; 74 EVP_MD_CTX ctx;
80 EVP_MD *type; 75 const EVP_MD *type;
81 unsigned char *p,*buf_in=NULL; 76 unsigned char *p,*buf_in=NULL;
82 int ret= -1,i,inl; 77 int ret= -1,i,inl;
83 78
@@ -90,7 +85,7 @@ EVP_PKEY *pkey;
90 } 85 }
91 86
92 inl=i2d(data,NULL); 87 inl=i2d(data,NULL);
93 buf_in=(unsigned char *)Malloc((unsigned int)inl); 88 buf_in=Malloc((unsigned int)inl);
94 if (buf_in == NULL) 89 if (buf_in == NULL)
95 { 90 {
96 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE); 91 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/rc4/rc4_locl.org b/src/lib/libcrypto/asn1/a_vis.c
index 1ef4455fb7..2072be780d 100644
--- a/src/lib/libcrypto/rc4/rc4_locl.org
+++ b/src/lib/libcrypto/asn1/a_vis.c
@@ -1,5 +1,5 @@
1/* crypto/rc4/rc4_locl.org */ 1/* crypto/asn1/a_vis.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
@@ -56,15 +56,28 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 59#include <stdio.h>
60 * 60#include "cryptlib.h"
61 * Always modify bf_locl.org since bf_locl.h is automatically generated from 61#include <openssl/asn1.h>
62 * it during SSLeay configuration. 62
63 * 63int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a, unsigned char **pp)
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 64 {
65 */ 65 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
66 V_ASN1_VISIBLESTRING,V_ASN1_UNIVERSAL));
67 }
68
69ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a,
70 unsigned char **pp, long length)
71 {
72 ASN1_VISIBLESTRING *ret=NULL;
66 73
67/* if this is defined data[i] is used instead of *data, this is a %20 74 ret=(ASN1_VISIBLESTRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
68 * speedup on x86 */ 75 pp,length,V_ASN1_VISIBLESTRING,V_ASN1_UNIVERSAL);
69#undef RC4_INDEX 76 if (ret == NULL)
77 {
78 ASN1err(ASN1_F_D2I_ASN1_VISIBLESTRING,ERR_R_NESTED_ASN1_ERROR);
79 return(NULL);
80 }
81 return(ret);
82 }
70 83
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 @@
1/* Error codes for the ASN1 functions. */
2
3/* Function codes. */
4#define ASN1_F_A2D_ASN1_OBJECT 100
5#define ASN1_F_A2I_ASN1_INTEGER 101
6#define ASN1_F_A2I_ASN1_STRING 102
7#define ASN1_F_ASN1_COLLATE_PRIMATIVE 103
8#define ASN1_F_ASN1_D2I_BIO 104
9#define ASN1_F_ASN1_D2I_FP 105
10#define ASN1_F_ASN1_DUP 106
11#define ASN1_F_ASN1_GET_OBJECT 107
12#define ASN1_F_ASN1_HEADER_NEW 108
13#define ASN1_F_ASN1_I2D_BIO 109
14#define ASN1_F_ASN1_I2D_FP 110
15#define ASN1_F_ASN1_INTEGER_SET 111
16#define ASN1_F_ASN1_INTEGER_TO_BN 112
17#define ASN1_F_ASN1_OBJECT_NEW 113
18#define ASN1_F_ASN1_SIGN 114
19#define ASN1_F_ASN1_STRING_NEW 115
20#define ASN1_F_ASN1_STRING_TYPE_NEW 116
21#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117
22#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118
23#define ASN1_F_ASN1_TYPE_NEW 119
24#define ASN1_F_ASN1_UTCTIME_NEW 120
25#define ASN1_F_ASN1_VERIFY 121
26#define ASN1_F_BN_TO_ASN1_INTEGER 122
27#define ASN1_F_D2I_ASN1_BIT_STRING 123
28#define ASN1_F_D2I_ASN1_BMPSTRING 124
29#define ASN1_F_D2I_ASN1_BOOLEAN 125
30#define ASN1_F_D2I_ASN1_BYTES 126
31#define ASN1_F_D2I_ASN1_HEADER 127
32#define ASN1_F_D2I_ASN1_INTEGER 128
33#define ASN1_F_D2I_ASN1_OBJECT 129
34#define ASN1_F_D2I_ASN1_OCTET_STRING 130
35#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
36#define ASN1_F_D2I_ASN1_SET 132
37#define ASN1_F_D2I_ASN1_TYPE 133
38#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
39#define ASN1_F_D2I_ASN1_UTCTIME 135
40#define ASN1_F_D2I_DHPARAMS 136
41#define ASN1_F_D2I_DSAPARAMS 137
42#define ASN1_F_D2I_DSAPRIVATEKEY 138
43#define ASN1_F_D2I_DSAPUBLICKEY 139
44#define ASN1_F_D2I_NETSCAPE_PKEY 140
45#define ASN1_F_D2I_NETSCAPE_RSA 141
46#define ASN1_F_D2I_NETSCAPE_RSA_2 142
47#define ASN1_F_D2I_NETSCAPE_SPKAC 143
48#define ASN1_F_D2I_NETSCAPE_SPKI 144
49#define ASN1_F_D2I_PKCS7 145
50#define ASN1_F_D2I_PKCS7_DIGEST 146
51#define ASN1_F_D2I_PKCS7_ENCRYPT 147
52#define ASN1_F_D2I_PKCS7_ENC_CONTENT 148
53#define ASN1_F_D2I_PKCS7_ENVELOPE 149
54#define ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL 150
55#define ASN1_F_D2I_PKCS7_RECIP_INFO 151
56#define ASN1_F_D2I_PKCS7_SIGNED 152
57#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153
58#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154
59#define ASN1_F_D2I_PRIVATEKEY 155
60#define ASN1_F_D2I_PUBLICKEY 156
61#define ASN1_F_D2I_RSAPRIVATEKEY 157
62#define ASN1_F_D2I_RSAPUBLICKEY 158
63#define ASN1_F_D2I_X509 159
64#define ASN1_F_D2I_X509_ALGOR 160
65#define ASN1_F_D2I_X509_ATTRIBUTE 161
66#define ASN1_F_D2I_X509_CINF 162
67#define ASN1_F_D2I_X509_CRL 163
68#define ASN1_F_D2I_X509_CRL_INFO 164
69#define ASN1_F_D2I_X509_EXTENSION 165
70#define ASN1_F_D2I_X509_KEY 166
71#define ASN1_F_D2I_X509_NAME 167
72#define ASN1_F_D2I_X509_NAME_ENTRY 168
73#define ASN1_F_D2I_X509_PKEY 169
74#define ASN1_F_D2I_X509_PUBKEY 170
75#define ASN1_F_D2I_X509_REQ 171
76#define ASN1_F_D2I_X509_REQ_INFO 172
77#define ASN1_F_D2I_X509_REVOKED 173
78#define ASN1_F_D2I_X509_SIG 174
79#define ASN1_F_D2I_X509_VAL 175
80#define ASN1_F_I2D_ASN1_HEADER 176
81#define ASN1_F_I2D_DHPARAMS 177
82#define ASN1_F_I2D_DSAPARAMS 178
83#define ASN1_F_I2D_DSAPRIVATEKEY 179
84#define ASN1_F_I2D_DSAPUBLICKEY 180
85#define ASN1_F_I2D_NETSCAPE_RSA 181
86#define ASN1_F_I2D_PKCS7 182
87#define ASN1_F_I2D_PRIVATEKEY 183
88#define ASN1_F_I2D_PUBLICKEY 184
89#define ASN1_F_I2D_RSAPRIVATEKEY 185
90#define ASN1_F_I2D_RSAPUBLICKEY 186
91#define ASN1_F_I2D_X509_ATTRIBUTE 187
92#define ASN1_F_I2T_ASN1_OBJECT 188
93#define ASN1_F_NETSCAPE_PKEY_NEW 189
94#define ASN1_F_NETSCAPE_SPKAC_NEW 190
95#define ASN1_F_NETSCAPE_SPKI_NEW 191
96#define ASN1_F_PKCS7_DIGEST_NEW 192
97#define ASN1_F_PKCS7_ENCRYPT_NEW 193
98#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194
99#define ASN1_F_PKCS7_ENVELOPE_NEW 195
100#define ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW 196
101#define ASN1_F_PKCS7_NEW 197
102#define ASN1_F_PKCS7_RECIP_INFO_NEW 198
103#define ASN1_F_PKCS7_SIGNED_NEW 199
104#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200
105#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201
106#define ASN1_F_X509_ALGOR_NEW 202
107#define ASN1_F_X509_ATTRIBUTE_NEW 203
108#define ASN1_F_X509_CINF_NEW 204
109#define ASN1_F_X509_CRL_INFO_NEW 205
110#define ASN1_F_X509_CRL_NEW 206
111#define ASN1_F_X509_DHPARAMS_NEW 207
112#define ASN1_F_X509_EXTENSION_NEW 208
113#define ASN1_F_X509_INFO_NEW 209
114#define ASN1_F_X509_KEY_NEW 210
115#define ASN1_F_X509_NAME_ENTRY_NEW 211
116#define ASN1_F_X509_NAME_NEW 212
117#define ASN1_F_X509_NEW 213
118#define ASN1_F_X509_PKEY_NEW 214
119#define ASN1_F_X509_PUBKEY_NEW 215
120#define ASN1_F_X509_REQ_INFO_NEW 216
121#define ASN1_F_X509_REQ_NEW 217
122#define ASN1_F_X509_REVOKED_NEW 218
123#define ASN1_F_X509_SIG_NEW 219
124#define ASN1_F_X509_VAL_FREE 220
125#define ASN1_F_X509_VAL_NEW 221
126
127/* Reason codes. */
128#define ASN1_R_BAD_CLASS 100
129#define ASN1_R_BAD_GET_OBJECT 101
130#define ASN1_R_BAD_OBJECT_HEADER 102
131#define ASN1_R_BAD_PASSWORD_READ 103
132#define ASN1_R_BAD_PKCS7_CONTENT 104
133#define ASN1_R_BAD_PKCS7_TYPE 105
134#define ASN1_R_BAD_TAG 106
135#define ASN1_R_BAD_TYPE 107
136#define ASN1_R_BN_LIB 108
137#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109
138#define ASN1_R_BUFFER_TOO_SMALL 110
139#define ASN1_R_DATA_IS_WRONG 111
140#define ASN1_R_DECODING_ERROR 112
141#define ASN1_R_ERROR_STACK 113
142#define ASN1_R_EXPECTING_AN_INTEGER 114
143#define ASN1_R_EXPECTING_AN_OBJECT 115
144#define ASN1_R_EXPECTING_AN_OCTET_STRING 116
145#define ASN1_R_EXPECTING_A_BIT_STRING 117
146#define ASN1_R_EXPECTING_A_BOOLEAN 118
147#define ASN1_R_EXPECTING_A_SEQUENCE 119
148#define ASN1_R_EXPECTING_A_UTCTIME 120
149#define ASN1_R_FIRST_NUM_TOO_LARGE 121
150#define ASN1_R_HEADER_TOO_LONG 122
151#define ASN1_R_INVALID_DIGIT 123
152#define ASN1_R_INVALID_SEPARATOR 124
153#define ASN1_R_INVALID_TIME_FORMAT 125
154#define ASN1_R_IV_TOO_LARGE 126
155#define ASN1_R_LENGTH_ERROR 127
156#define ASN1_R_LENGTH_MISMATCH 128
157#define ASN1_R_MISSING_EOS 129
158#define ASN1_R_MISSING_SECOND_NUMBER 130
159#define ASN1_R_NON_HEX_CHARACTERS 131
160#define ASN1_R_NOT_ENOUGH_DATA 132
161#define ASN1_R_ODD_NUMBER_OF_CHARS 133
162#define ASN1_R_PARSING 134
163#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135
164#define ASN1_R_SECOND_NUMBER_TOO_LARGE 136
165#define ASN1_R_SHORT_LINE 137
166#define ASN1_R_STRING_TOO_SHORT 138
167#define ASN1_R_TAG_VALUE_TOO_HIGH 139
168#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140
169#define ASN1_R_TOO_LONG 141
170#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142
171#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143
172#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144
173#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145
174#define ASN1_R_UNKNOWN_OBJECT_TYPE 146
175#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147
176#define ASN1_R_UNSUPPORTED_CIPHER 148
177#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149
178#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150
179#define ASN1_R_UTCTIME_TOO_LONG 151
180#define ASN1_R_WRONG_PRINTABLE_TYPE 152
181#define ASN1_R_WRONG_TAG 153
182#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" {
64#endif 64#endif
65 65
66#include <time.h> 66#include <time.h>
67#include "bn.h" 67#include <openssl/bn.h>
68#include "stack.h" 68#include <openssl/stack.h>
69#include <openssl/safestack.h>
69 70
70#define V_ASN1_UNIVERSAL 0x00 71#define V_ASN1_UNIVERSAL 0x00
71#define V_ASN1_APPLICATION 0x40 72#define V_ASN1_APPLICATION 0x40
@@ -73,6 +74,7 @@ extern "C" {
73#define V_ASN1_PRIVATE 0xc0 74#define V_ASN1_PRIVATE 0xc0
74 75
75#define V_ASN1_CONSTRUCTED 0x20 76#define V_ASN1_CONSTRUCTED 0x20
77#define V_ASN1_PRIMITIVE_TAG 0x1f
76#define V_ASN1_PRIMATIVE_TAG 0x1f 78#define V_ASN1_PRIMATIVE_TAG 0x1f
77 79
78#define V_ASN1_APP_CHOOSE -2 /* let the recipent choose */ 80#define V_ASN1_APP_CHOOSE -2 /* let the recipent choose */
@@ -89,7 +91,9 @@ extern "C" {
89#define V_ASN1_OBJECT_DESCRIPTOR 7 91#define V_ASN1_OBJECT_DESCRIPTOR 7
90#define V_ASN1_EXTERNAL 8 92#define V_ASN1_EXTERNAL 8
91#define V_ASN1_REAL 9 93#define V_ASN1_REAL 9
92#define V_ASN1_ENUMERATED 10 /* microsoft weirdness */ 94#define V_ASN1_ENUMERATED 10
95#define V_ASN1_NEG_ENUMERATED (10+0x100)
96#define V_ASN1_UTF8STRING 12
93#define V_ASN1_SEQUENCE 16 97#define V_ASN1_SEQUENCE 16
94#define V_ASN1_SET 17 98#define V_ASN1_SET 17
95#define V_ASN1_NUMERICSTRING 18 /**/ 99#define V_ASN1_NUMERICSTRING 18 /**/
@@ -111,111 +115,46 @@ extern "C" {
111#define B_ASN1_NUMERICSTRING 0x0001 115#define B_ASN1_NUMERICSTRING 0x0001
112#define B_ASN1_PRINTABLESTRING 0x0002 116#define B_ASN1_PRINTABLESTRING 0x0002
113#define B_ASN1_T61STRING 0x0004 117#define B_ASN1_T61STRING 0x0004
118#define B_ASN1_TELETEXSTRING 0x0008
114#define B_ASN1_VIDEOTEXSTRING 0x0008 119#define B_ASN1_VIDEOTEXSTRING 0x0008
115#define B_ASN1_IA5STRING 0x0010 120#define B_ASN1_IA5STRING 0x0010
116#define B_ASN1_GRAPHICSTRING 0x0020 121#define B_ASN1_GRAPHICSTRING 0x0020
117#define B_ASN1_ISO64STRING 0x0040 122#define B_ASN1_ISO64STRING 0x0040
123#define B_ASN1_VISIBLESTRING 0x0040
118#define B_ASN1_GENERALSTRING 0x0080 124#define B_ASN1_GENERALSTRING 0x0080
119#define B_ASN1_UNIVERSALSTRING 0x0100 125#define B_ASN1_UNIVERSALSTRING 0x0100
120#define B_ASN1_OCTET_STRING 0x0200 126#define B_ASN1_OCTET_STRING 0x0200
121#define B_ASN1_BIT_STRING 0x0400 127#define B_ASN1_BIT_STRING 0x0400
122#define B_ASN1_BMPSTRING 0x0800 128#define B_ASN1_BMPSTRING 0x0800
123#define B_ASN1_UNKNOWN 0x1000 129#define B_ASN1_UNKNOWN 0x1000
124 130#define B_ASN1_UTF8STRING 0x2000
125#ifndef DEBUG 131
126 132#define DECLARE_ASN1_SET_OF(type) \
127#define ASN1_INTEGER ASN1_STRING 133int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
128#define ASN1_BIT_STRING ASN1_STRING 134 int (*func)(type *,unsigned char **), int ex_tag, \
129#define ASN1_OCTET_STRING ASN1_STRING 135 int ex_class, int is_set); \
130#define ASN1_PRINTABLESTRING ASN1_STRING 136STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
131#define ASN1_T61STRING ASN1_STRING 137 long length, \
132#define ASN1_IA5STRING ASN1_STRING 138 type *(*func)(type **, \
133#define ASN1_UTCTIME ASN1_STRING 139 unsigned char **,long), \
134#define ASN1_GENERALIZEDTIME ASN1_STRING 140 void (*free_func)(type *), \
135#define ASN1_GENERALSTRING ASN1_STRING 141 int ex_tag,int ex_class);
136#define ASN1_UNIVERSALSTRING ASN1_STRING 142
137#define ASN1_BMPSTRING ASN1_STRING 143#define IMPLEMENT_ASN1_SET_OF(type) \
138 144int i2d_ASN1_SET_OF_##type(STACK_OF(type) *a,unsigned char **pp, \
139#else 145 int (*func)(type *,unsigned char **), int ex_tag, \
140 146 int ex_class, int is_set) \
141typedef struct asn1_integer_st 147 { return i2d_ASN1_SET((STACK *)a,pp,func,ex_tag,ex_class,is_set); } \
142 { 148STACK_OF(type) *d2i_ASN1_SET_OF_##type(STACK_OF(type) **a,unsigned char **pp, \
143 int length; 149 long length, \
144 int type; 150 type *(*func)(type **, \
145 unsigned char *data; 151 unsigned char **,long), \
146 } ASN1_INTEGER; 152 void (*free_func)(type *), \
147 153 int ex_tag,int ex_class) \
148typedef struct asn1_bit_string_st 154 { return (STACK_OF(type) *)d2i_ASN1_SET((STACK **)a,pp,length, \
149 { 155 (char *(*)())func, \
150 int length; 156 (void (*)())free_func, \
151 int type; 157 ex_tag,ex_class); }
152 unsigned char *data;
153 } ASN1_BIT_STRING;
154
155typedef struct asn1_octet_string_st
156 {
157 int length;
158 int type;
159 unsigned char *data;
160 } ASN1_OCTET_STRING;
161
162typedef struct asn1_printablestring_st
163 {
164 int length;
165 int type;
166 unsigned char *data;
167 } ASN1_PRINTABLESTRING;
168
169typedef struct asn1_t61string_st
170 {
171 int length;
172 int type;
173 unsigned char *data;
174 } ASN1_T61STRING;
175
176typedef struct asn1_ia5string_st
177 {
178 int length;
179 int type;
180 unsigned char *data;
181 } ASN1_IA5STRING;
182
183typedef struct asn1_generalstring_st
184 {
185 int length;
186 int type;
187 unsigned char *data;
188 } ASN1_GENERALSTRING;
189
190typedef struct asn1_universalstring_st
191 {
192 int length;
193 int type;
194 unsigned char *data;
195 } ASN1_UNIVERSALSTRING;
196
197typedef struct asn1_bmpstring_st
198 {
199 int length;
200 int type;
201 unsigned char *data;
202 } ASN1_BMPSTRING;
203
204typedef struct asn1_utctime_st
205 {
206 int length;
207 int type;
208 unsigned char *data;
209 } ASN1_UTCTIME;
210
211typedef struct asn1_generalizedtime_st
212 {
213 int length;
214 int type;
215 unsigned char *data;
216 } ASN1_GENERALIZEDTIME;
217
218#endif
219 158
220typedef struct asn1_ctx_st 159typedef struct asn1_ctx_st
221 { 160 {
@@ -229,6 +168,7 @@ typedef struct asn1_ctx_st
229 unsigned char *max; /* largest value of p alowed */ 168 unsigned char *max; /* largest value of p alowed */
230 unsigned char *q;/* temporary variable */ 169 unsigned char *q;/* temporary variable */
231 unsigned char **pp;/* variable */ 170 unsigned char **pp;/* variable */
171 int line; /* used in error processing */
232 } ASN1_CTX; 172 } ASN1_CTX;
233 173
234/* These are used internally in the ASN1_OBJECT to keep track of 174/* These are used internally in the ASN1_OBJECT to keep track of
@@ -239,21 +179,61 @@ typedef struct asn1_ctx_st
239#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */ 179#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
240typedef struct asn1_object_st 180typedef struct asn1_object_st
241 { 181 {
242 char *sn,*ln; 182 const char *sn,*ln;
243 int nid; 183 int nid;
244 int length; 184 int length;
245 unsigned char *data; 185 unsigned char *data;
246 int flags; /* Should we free this one */ 186 int flags; /* Should we free this one */
247 } ASN1_OBJECT; 187 } ASN1_OBJECT;
248 188
189#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
249/* This is the base type that holds just about everything :-) */ 190/* This is the base type that holds just about everything :-) */
250typedef struct asn1_string_st 191typedef struct asn1_string_st
251 { 192 {
252 int length; 193 int length;
253 int type; 194 int type;
254 unsigned char *data; 195 unsigned char *data;
196 /* The value of the following field depends on the type being
197 * held. It is mostly being used for BIT_STRING so if the
198 * input data has a non-zero 'unused bits' value, it will be
199 * handled correctly */
200 long flags;
255 } ASN1_STRING; 201 } ASN1_STRING;
256 202
203#ifndef DEBUG
204#define ASN1_INTEGER ASN1_STRING
205#define ASN1_ENUMERATED ASN1_STRING
206#define ASN1_BIT_STRING ASN1_STRING
207#define ASN1_OCTET_STRING ASN1_STRING
208#define ASN1_PRINTABLESTRING ASN1_STRING
209#define ASN1_T61STRING ASN1_STRING
210#define ASN1_IA5STRING ASN1_STRING
211#define ASN1_UTCTIME ASN1_STRING
212#define ASN1_GENERALIZEDTIME ASN1_STRING
213#define ASN1_TIME ASN1_STRING
214#define ASN1_GENERALSTRING ASN1_STRING
215#define ASN1_UNIVERSALSTRING ASN1_STRING
216#define ASN1_BMPSTRING ASN1_STRING
217#define ASN1_VISIBLESTRING ASN1_STRING
218#define ASN1_UTF8STRING ASN1_STRING
219#else
220typedef struct asn1_string_st ASN1_INTEGER;
221typedef struct asn1_string_st ASN1_ENUMERATED;
222typedef struct asn1_string_st ASN1_BIT_STRING;
223typedef struct asn1_string_st ASN1_OCTET_STRING;
224typedef struct asn1_string_st ASN1_PRINTABLESTRING;
225typedef struct asn1_string_st ASN1_T61STRING;
226typedef struct asn1_string_st ASN1_IA5STRING;
227typedef struct asn1_string_st ASN1_GENERALSTRING;
228typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
229typedef struct asn1_string_st ASN1_BMPSTRING;
230typedef struct asn1_string_st ASN1_UTCTIME;
231typedef struct asn1_string_st ASN1_TIME;
232typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
233typedef struct asn1_string_st ASN1_VISIBLESTRING;
234typedef struct asn1_string_st ASN1_UTF8STRING;
235#endif
236
257typedef struct asn1_type_st 237typedef struct asn1_type_st
258 { 238 {
259 int type; 239 int type;
@@ -262,6 +242,7 @@ typedef struct asn1_type_st
262 ASN1_STRING * asn1_string; 242 ASN1_STRING * asn1_string;
263 ASN1_OBJECT * object; 243 ASN1_OBJECT * object;
264 ASN1_INTEGER * integer; 244 ASN1_INTEGER * integer;
245 ASN1_ENUMERATED * enumerated;
265 ASN1_BIT_STRING * bit_string; 246 ASN1_BIT_STRING * bit_string;
266 ASN1_OCTET_STRING * octet_string; 247 ASN1_OCTET_STRING * octet_string;
267 ASN1_PRINTABLESTRING * printablestring; 248 ASN1_PRINTABLESTRING * printablestring;
@@ -272,6 +253,8 @@ typedef struct asn1_type_st
272 ASN1_UNIVERSALSTRING * universalstring; 253 ASN1_UNIVERSALSTRING * universalstring;
273 ASN1_UTCTIME * utctime; 254 ASN1_UTCTIME * utctime;
274 ASN1_GENERALIZEDTIME * generalizedtime; 255 ASN1_GENERALIZEDTIME * generalizedtime;
256 ASN1_VISIBLESTRING * visiblestring;
257 ASN1_UTF8STRING * utf8string;
275 /* set and sequence are left complete and still 258 /* set and sequence are left complete and still
276 * contain the set or sequence bytes */ 259 * contain the set or sequence bytes */
277 ASN1_STRING * set; 260 ASN1_STRING * set;
@@ -279,6 +262,9 @@ typedef struct asn1_type_st
279 } value; 262 } value;
280 } ASN1_TYPE; 263 } ASN1_TYPE;
281 264
265DECLARE_STACK_OF(ASN1_TYPE)
266DECLARE_ASN1_SET_OF(ASN1_TYPE)
267
282typedef struct asn1_method_st 268typedef struct asn1_method_st
283 { 269 {
284 int (*i2d)(); 270 int (*i2d)();
@@ -322,6 +308,17 @@ typedef struct asn1_header_st
322/* i2d_ASN1_INTEGER() is a function */ 308/* i2d_ASN1_INTEGER() is a function */
323/* d2i_ASN1_INTEGER() is a function */ 309/* d2i_ASN1_INTEGER() is a function */
324 310
311#define ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
312 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
313#define ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
314#define ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a)
315#define ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
316 (ASN1_STRING *)a,(ASN1_STRING *)b)
317/* ASN1_ENUMERATED_set() is a function, also see BN_to_ASN1_ENUMERATED() */
318/* ASN1_ENUMERATED_get() is a function, also see ASN1_ENUMERATED_to_BN() */
319/* i2d_ASN1_ENUMERATED() is a function */
320/* d2i_ASN1_ENUMERATED() is a function */
321
325#define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\ 322#define ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
326 ASN1_STRING_type_new(V_ASN1_OCTET_STRING) 323 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
327#define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 324#define ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
@@ -350,7 +347,29 @@ typedef struct asn1_header_st
350 B_ASN1_BMPSTRING|\ 347 B_ASN1_BMPSTRING|\
351 B_ASN1_UNKNOWN) 348 B_ASN1_UNKNOWN)
352 349
353#define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING_STRING *)\ 350#define DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
351#define DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
352#define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
353 pp,a->type,V_ASN1_UNIVERSAL)
354#define M_d2i_DIRECTORYSTRING(a,pp,l) \
355 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
356 B_ASN1_PRINTABLESTRING| \
357 B_ASN1_TELETEXSTRING|\
358 B_ASN1_BMPSTRING|\
359 B_ASN1_UNIVERSALSTRING|\
360 B_ASN1_UTF8STRING)
361
362#define DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
363#define DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
364#define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\
365 pp,a->type,V_ASN1_UNIVERSAL)
366#define M_d2i_DISPLAYTEXT(a,pp,l) \
367 d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \
368 B_ASN1_VISIBLESTRING| \
369 B_ASN1_BMPSTRING|\
370 B_ASN1_UTF8STRING)
371
372#define ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
354 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) 373 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
355#define ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 374#define ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
356#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \ 375#define M_i2d_ASN1_PRINTABLESTRING(a,pp) \
@@ -373,6 +392,8 @@ typedef struct asn1_header_st
373#define ASN1_IA5STRING_new() (ASN1_IA5STRING *)\ 392#define ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
374 ASN1_STRING_type_new(V_ASN1_IA5STRING) 393 ASN1_STRING_type_new(V_ASN1_IA5STRING)
375#define ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) 394#define ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
395#define ASN1_IA5STRING_dup(a) \
396 (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a)
376#define M_i2d_ASN1_IA5STRING(a,pp) \ 397#define M_i2d_ASN1_IA5STRING(a,pp) \
377 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\ 398 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\
378 V_ASN1_UNIVERSAL) 399 V_ASN1_UNIVERSAL)
@@ -392,12 +413,22 @@ typedef struct asn1_header_st
392#define ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\ 413#define ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
393 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME) 414 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
394#define ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) 415#define ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
395#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup(\ 416#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
396 (ASN1_STRING *)a) 417 (ASN1_STRING *)a)
397/* DOES NOT EXIST YET i2d_ASN1_GENERALIZEDTIME() is a function */ 418/* i2d_ASN1_GENERALIZEDTIME() is a function */
398/* DOES NOT EXIST YET d2i_ASN1_GENERALIZEDTIME() is a function */ 419/* d2i_ASN1_GENERALIZEDTIME() is a function */
399/* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_set() is a function */ 420/* ASN1_GENERALIZEDTIME_set() is a function */
400/* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_check() is a function */ 421/* ASN1_GENERALIZEDTIME_check() is a function */
422
423#define ASN1_TIME_new() (ASN1_TIME *)\
424 ASN1_STRING_type_new(V_ASN1_UTCTIME)
425#define ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
426#define ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
427
428/* i2d_ASN1_TIME() is a function */
429/* d2i_ASN1_TIME() is a function */
430/* ASN1_TIME_set() is a function */
431/* ASN1_TIME_check() is a function */
401 432
402#define ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\ 433#define ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
403 ASN1_STRING_type_new(V_ASN1_GENERALSTRING) 434 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
@@ -429,13 +460,36 @@ typedef struct asn1_header_st
429 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\ 460 (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
430 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING) 461 ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
431 462
432#ifndef NOPROTO 463#define ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
464 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
465#define ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
466#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
467 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
468 V_ASN1_UNIVERSAL)
469#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
470 (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
471 ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
472
473#define ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
474 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
475#define ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
476#define M_i2d_ASN1_UTF8STRING(a,pp) \
477 i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
478 V_ASN1_UNIVERSAL)
479#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
480 (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
481 ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
482
483 /* for the is_set parameter to i2d_ASN1_SET */
484#define IS_SEQUENCE 0
485#define IS_SET 1
486
433ASN1_TYPE * ASN1_TYPE_new(void ); 487ASN1_TYPE * ASN1_TYPE_new(void );
434void ASN1_TYPE_free(ASN1_TYPE *a); 488void ASN1_TYPE_free(ASN1_TYPE *a);
435int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp); 489int i2d_ASN1_TYPE(ASN1_TYPE *a,unsigned char **pp);
436ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length); 490ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **a,unsigned char **pp,long length);
437int ASN1_TYPE_get(ASN1_TYPE *a); 491int ASN1_TYPE_get(ASN1_TYPE *a);
438void ASN1_TYPE_set(ASN1_TYPE *a, int type, char *value); 492void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
439 493
440ASN1_OBJECT * ASN1_OBJECT_new(void ); 494ASN1_OBJECT * ASN1_OBJECT_new(void );
441void ASN1_OBJECT_free(ASN1_OBJECT *a); 495void ASN1_OBJECT_free(ASN1_OBJECT *a);
@@ -443,12 +497,17 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
443ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp, 497ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
444 long length); 498 long length);
445 499
500DECLARE_STACK_OF(ASN1_OBJECT)
501DECLARE_ASN1_SET_OF(ASN1_OBJECT)
502
446ASN1_STRING * ASN1_STRING_new(void ); 503ASN1_STRING * ASN1_STRING_new(void );
447void ASN1_STRING_free(ASN1_STRING *a); 504void ASN1_STRING_free(ASN1_STRING *a);
448ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a); 505ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a);
449ASN1_STRING * ASN1_STRING_type_new(int type ); 506ASN1_STRING * ASN1_STRING_type_new(int type );
450int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b); 507int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
451int ASN1_STRING_set(ASN1_STRING *str,unsigned char *data, int len); 508 /* Since this is used to store all sorts of things, via macros, for now, make
509 its data void * */
510int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
452 511
453int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp); 512int i2d_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
454ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp, 513ASN1_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);
463int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); 522int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
464ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp, 523ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
465 long length); 524 long length);
525ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
526 long length);
527
528int i2d_ASN1_ENUMERATED(ASN1_ENUMERATED *a,unsigned char **pp);
529ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **a,unsigned char **pp,
530 long length);
466 531
467int ASN1_UTCTIME_check(ASN1_UTCTIME *a); 532int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
468ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t); 533ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
469int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str); 534int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
470 535
536int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
537ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
538int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
539
471int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp); 540int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
472ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a, 541ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
473 unsigned char **pp,long length); 542 unsigned char **pp,long length);
474 543
544int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp);
545ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a,
546 unsigned char **pp,long length);
547
548int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
549ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
550 unsigned char **pp,long length);
551
552int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
553ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp,
554 long length);
555
475int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp); 556int i2d_ASN1_PRINTABLE(ASN1_STRING *a,unsigned char **pp);
476ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a, 557ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **a,
477 unsigned char **pp, long l); 558 unsigned char **pp, long l);
478ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a, 559ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING(ASN1_PRINTABLESTRING **a,
479 unsigned char **pp, long l); 560 unsigned char **pp, long l);
480 561
562int i2d_DIRECTORYSTRING(ASN1_STRING *a,unsigned char **pp);
563ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **a, unsigned char **pp,
564 long length);
565
566int i2d_DISPLAYTEXT(ASN1_STRING *a,unsigned char **pp);
567ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **a, unsigned char **pp, long length);
568
481ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a, 569ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **a,
482 unsigned char **pp, long l); 570 unsigned char **pp, long l);
483int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp); 571int i2d_ASN1_IA5STRING(ASN1_IA5STRING *a,unsigned char **pp);
@@ -488,21 +576,32 @@ int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
488ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp, 576ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
489 long length); 577 long length);
490 578
579int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp);
580ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp,
581 long length);
582
583int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp);
584ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length);
585ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
586
491int i2d_ASN1_SET(STACK *a, unsigned char **pp, 587int i2d_ASN1_SET(STACK *a, unsigned char **pp,
492 int (*func)(), int ex_tag, int ex_class); 588 int (*func)(), int ex_tag, int ex_class, int is_set);
493STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length, 589STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
494 char *(*func)(), int ex_tag, int ex_class); 590 char *(*func)(), void (*free_func)(),
591 int ex_tag, int ex_class);
495 592
496#ifdef HEADER_BIO_H 593#ifdef HEADER_BIO_H
497int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); 594int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
498int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size); 595int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size);
596int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
597int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size);
499int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a); 598int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
500int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size); 599int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size);
501int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type); 600int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
502#endif 601#endif
503int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a); 602int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
504 603
505int a2d_ASN1_OBJECT(unsigned char *out,int olen, char *buf, int num); 604int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
506ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len, 605ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len,
507 char *sn, char *ln); 606 char *sn, char *ln);
508 607
@@ -511,6 +610,11 @@ long ASN1_INTEGER_get(ASN1_INTEGER *a);
511ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai); 610ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai);
512BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn); 611BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn);
513 612
613int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
614long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
615ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
616BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
617
514/* General */ 618/* General */
515/* given a string, return the correct type, max is the maximum length */ 619/* given a string, return the correct type, max is the maximum length */
516int ASN1_PRINTABLE_type(unsigned char *s, int max); 620int ASN1_PRINTABLE_type(unsigned char *s, int max);
@@ -545,6 +649,8 @@ int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
545char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x); 649char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
546int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x); 650int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
547int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a); 651int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
652int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
653int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
548int ASN1_STRING_print(BIO *bp,ASN1_STRING *v); 654int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
549int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent); 655int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
550#endif 656#endif
@@ -574,111 +680,32 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
574int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, 680int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
575 unsigned char *data, int max_len); 681 unsigned char *data, int max_len);
576 682
577#else 683STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
578 684 void (*free_func)() );
579ASN1_TYPE * ASN1_TYPE_new(); 685unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
580void ASN1_TYPE_free(); 686 int *len );
581int i2d_ASN1_TYPE(); 687void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
582ASN1_TYPE * d2i_ASN1_TYPE(); 688ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
583int ASN1_TYPE_get();
584void ASN1_TYPE_set();
585
586ASN1_OBJECT * ASN1_OBJECT_new();
587void ASN1_OBJECT_free();
588int i2d_ASN1_OBJECT();
589ASN1_OBJECT * d2i_ASN1_OBJECT();
590ASN1_STRING * ASN1_STRING_new();
591void ASN1_STRING_free();
592ASN1_STRING * ASN1_STRING_dup();
593ASN1_STRING * ASN1_STRING_type_new();
594int ASN1_STRING_cmp();
595int ASN1_STRING_set();
596int i2d_ASN1_BIT_STRING();
597ASN1_BIT_STRING *d2i_ASN1_BIT_STRING();
598int ASN1_BIT_STRING_set_bit();
599int ASN1_BIT_STRING_get_bit();
600int i2d_ASN1_BOOLEAN();
601int d2i_ASN1_BOOLEAN();
602int i2d_ASN1_INTEGER();
603ASN1_INTEGER *d2i_ASN1_INTEGER();
604int ASN1_UTCTIME_check();
605ASN1_UTCTIME *ASN1_UTCTIME_set();
606int ASN1_UTCTIME_set_string();
607int i2d_ASN1_OCTET_STRING();
608ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING();
609int i2d_ASN1_PRINTABLE();
610ASN1_STRING *d2i_ASN1_PRINTABLE();
611ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING();
612ASN1_T61STRING *d2i_ASN1_T61STRING();
613int i2d_ASN1_IA5STRING();
614ASN1_IA5STRING *d2i_ASN1_IA5STRING();
615int i2d_ASN1_UTCTIME();
616ASN1_UTCTIME * d2i_ASN1_UTCTIME();
617int i2d_ASN1_SET();
618STACK * d2i_ASN1_SET();
619int a2d_ASN1_OBJECT();
620ASN1_OBJECT *ASN1_OBJECT_create();
621int ASN1_INTEGER_set();
622long ASN1_INTEGER_get();
623ASN1_INTEGER *BN_to_ASN1_INTEGER();
624BIGNUM *ASN1_INTEGER_to_BN();
625int ASN1_PRINTABLE_type();
626int i2d_ASN1_bytes();
627ASN1_STRING *d2i_ASN1_bytes();
628ASN1_STRING *d2i_ASN1_type_bytes();
629int asn1_Finish();
630int ASN1_get_object();
631int ASN1_check_infinite_end();
632void ASN1_put_object();
633int ASN1_object_size();
634char *ASN1_dup();
635#ifndef NO_FP_API
636char *ASN1_d2i_fp();
637int ASN1_i2d_fp();
638#endif
639
640char *ASN1_d2i_bio();
641int ASN1_i2d_bio();
642int ASN1_UTCTIME_print();
643int ASN1_STRING_print();
644int ASN1_parse();
645int i2a_ASN1_INTEGER();
646int a2i_ASN1_INTEGER();
647int i2a_ASN1_OBJECT();
648int i2t_ASN1_OBJECT();
649int a2i_ASN1_STRING();
650int i2a_ASN1_STRING();
651
652int i2d_ASN1_HEADER();
653ASN1_HEADER *d2i_ASN1_HEADER();
654ASN1_HEADER *ASN1_HEADER_new();
655void ASN1_HEADER_free();
656void ERR_load_ASN1_strings();
657ASN1_METHOD *X509_asn1_meth();
658ASN1_METHOD *RSAPrivateKey_asn1_meth();
659ASN1_METHOD *ASN1_IA5STRING_asn1_meth();
660ASN1_METHOD *ASN1_BIT_STRING_asn1_meth();
661
662int ASN1_UNIVERSALSTRING_to_string();
663
664int ASN1_TYPE_set_octetstring();
665int ASN1_TYPE_get_octetstring();
666int ASN1_TYPE_set_int_octetstring();
667int ASN1_TYPE_get_int_octetstring();
668
669#endif
670 689
671/* BEGIN ERROR CODES */ 690/* BEGIN ERROR CODES */
691/* The following lines are auto generated by the script mkerr.pl. Any changes
692 * made after this point may be overwritten when the script is next run.
693 */
694
672/* Error codes for the ASN1 functions. */ 695/* Error codes for the ASN1 functions. */
673 696
674/* Function codes. */ 697/* Function codes. */
675#define ASN1_F_A2D_ASN1_OBJECT 100 698#define ASN1_F_A2D_ASN1_OBJECT 100
699#define ASN1_F_A2I_ASN1_ENUMERATED 236
676#define ASN1_F_A2I_ASN1_INTEGER 101 700#define ASN1_F_A2I_ASN1_INTEGER 101
677#define ASN1_F_A2I_ASN1_STRING 102 701#define ASN1_F_A2I_ASN1_STRING 102
678#define ASN1_F_ASN1_COLLATE_PRIMATIVE 103 702#define ASN1_F_ASN1_COLLATE_PRIMITIVE 103
679#define ASN1_F_ASN1_D2I_BIO 104 703#define ASN1_F_ASN1_D2I_BIO 104
680#define ASN1_F_ASN1_D2I_FP 105 704#define ASN1_F_ASN1_D2I_FP 105
681#define ASN1_F_ASN1_DUP 106 705#define ASN1_F_ASN1_DUP 106
706#define ASN1_F_ASN1_ENUMERATED_SET 232
707#define ASN1_F_ASN1_ENUMERATED_TO_BN 233
708#define ASN1_F_ASN1_GENERALIZEDTIME_NEW 222
682#define ASN1_F_ASN1_GET_OBJECT 107 709#define ASN1_F_ASN1_GET_OBJECT 107
683#define ASN1_F_ASN1_HEADER_NEW 108 710#define ASN1_F_ASN1_HEADER_NEW 108
684#define ASN1_F_ASN1_I2D_BIO 109 711#define ASN1_F_ASN1_I2D_BIO 109
@@ -686,37 +713,65 @@ int ASN1_TYPE_get_int_octetstring();
686#define ASN1_F_ASN1_INTEGER_SET 111 713#define ASN1_F_ASN1_INTEGER_SET 111
687#define ASN1_F_ASN1_INTEGER_TO_BN 112 714#define ASN1_F_ASN1_INTEGER_TO_BN 112
688#define ASN1_F_ASN1_OBJECT_NEW 113 715#define ASN1_F_ASN1_OBJECT_NEW 113
716#define ASN1_F_ASN1_PACK_STRING 245
717#define ASN1_F_ASN1_PBE_SET 253
718#define ASN1_F_ASN1_SEQ_PACK 246
719#define ASN1_F_ASN1_SEQ_UNPACK 247
689#define ASN1_F_ASN1_SIGN 114 720#define ASN1_F_ASN1_SIGN 114
690#define ASN1_F_ASN1_STRING_NEW 115 721#define ASN1_F_ASN1_STRING_NEW 115
691#define ASN1_F_ASN1_STRING_TYPE_NEW 116 722#define ASN1_F_ASN1_STRING_TYPE_NEW 116
692#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117 723#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 117
693#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118 724#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 118
694#define ASN1_F_ASN1_TYPE_NEW 119 725#define ASN1_F_ASN1_TYPE_NEW 119
726#define ASN1_F_ASN1_UNPACK_STRING 248
695#define ASN1_F_ASN1_UTCTIME_NEW 120 727#define ASN1_F_ASN1_UTCTIME_NEW 120
696#define ASN1_F_ASN1_VERIFY 121 728#define ASN1_F_ASN1_VERIFY 121
729#define ASN1_F_AUTHORITY_KEYID_NEW 237
730#define ASN1_F_BASIC_CONSTRAINTS_NEW 226
731#define ASN1_F_BN_TO_ASN1_ENUMERATED 234
697#define ASN1_F_BN_TO_ASN1_INTEGER 122 732#define ASN1_F_BN_TO_ASN1_INTEGER 122
698#define ASN1_F_D2I_ASN1_BIT_STRING 123 733#define ASN1_F_D2I_ASN1_BIT_STRING 123
699#define ASN1_F_D2I_ASN1_BMPSTRING 124 734#define ASN1_F_D2I_ASN1_BMPSTRING 124
700#define ASN1_F_D2I_ASN1_BOOLEAN 125 735#define ASN1_F_D2I_ASN1_BOOLEAN 125
701#define ASN1_F_D2I_ASN1_BYTES 126 736#define ASN1_F_D2I_ASN1_BYTES 126
737#define ASN1_F_D2I_ASN1_ENUMERATED 235
738#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
702#define ASN1_F_D2I_ASN1_HEADER 127 739#define ASN1_F_D2I_ASN1_HEADER 127
703#define ASN1_F_D2I_ASN1_INTEGER 128 740#define ASN1_F_D2I_ASN1_INTEGER 128
704#define ASN1_F_D2I_ASN1_OBJECT 129 741#define ASN1_F_D2I_ASN1_OBJECT 129
705#define ASN1_F_D2I_ASN1_OCTET_STRING 130 742#define ASN1_F_D2I_ASN1_OCTET_STRING 130
706#define ASN1_F_D2I_ASN1_PRINT_TYPE 131 743#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
707#define ASN1_F_D2I_ASN1_SET 132 744#define ASN1_F_D2I_ASN1_SET 132
745#define ASN1_F_D2I_ASN1_TIME 224
708#define ASN1_F_D2I_ASN1_TYPE 133 746#define ASN1_F_D2I_ASN1_TYPE 133
709#define ASN1_F_D2I_ASN1_TYPE_BYTES 134 747#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
748#define ASN1_F_D2I_ASN1_UINTEGER 280
710#define ASN1_F_D2I_ASN1_UTCTIME 135 749#define ASN1_F_D2I_ASN1_UTCTIME 135
750#define ASN1_F_D2I_ASN1_UTF8STRING 266
751#define ASN1_F_D2I_ASN1_VISIBLESTRING 267
752#define ASN1_F_D2I_AUTHORITY_KEYID 238
753#define ASN1_F_D2I_BASIC_CONSTRAINTS 227
711#define ASN1_F_D2I_DHPARAMS 136 754#define ASN1_F_D2I_DHPARAMS 136
755#define ASN1_F_D2I_DIST_POINT 276
756#define ASN1_F_D2I_DIST_POINT_NAME 277
712#define ASN1_F_D2I_DSAPARAMS 137 757#define ASN1_F_D2I_DSAPARAMS 137
713#define ASN1_F_D2I_DSAPRIVATEKEY 138 758#define ASN1_F_D2I_DSAPRIVATEKEY 138
714#define ASN1_F_D2I_DSAPUBLICKEY 139 759#define ASN1_F_D2I_DSAPUBLICKEY 139
760#define ASN1_F_D2I_GENERAL_NAME 230
761#define ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE 228
715#define ASN1_F_D2I_NETSCAPE_PKEY 140 762#define ASN1_F_D2I_NETSCAPE_PKEY 140
716#define ASN1_F_D2I_NETSCAPE_RSA 141 763#define ASN1_F_D2I_NETSCAPE_RSA 141
717#define ASN1_F_D2I_NETSCAPE_RSA_2 142 764#define ASN1_F_D2I_NETSCAPE_RSA_2 142
718#define ASN1_F_D2I_NETSCAPE_SPKAC 143 765#define ASN1_F_D2I_NETSCAPE_SPKAC 143
719#define ASN1_F_D2I_NETSCAPE_SPKI 144 766#define ASN1_F_D2I_NETSCAPE_SPKI 144
767#define ASN1_F_D2I_NOTICEREF 268
768#define ASN1_F_D2I_PBE2PARAM 262
769#define ASN1_F_D2I_PBEPARAM 249
770#define ASN1_F_D2I_PBKDF2PARAM 263
771#define ASN1_F_D2I_PKCS12 254
772#define ASN1_F_D2I_PKCS12_BAGS 255
773#define ASN1_F_D2I_PKCS12_MAC_DATA 256
774#define ASN1_F_D2I_PKCS12_SAFEBAG 257
720#define ASN1_F_D2I_PKCS7 145 775#define ASN1_F_D2I_PKCS7 145
721#define ASN1_F_D2I_PKCS7_DIGEST 146 776#define ASN1_F_D2I_PKCS7_DIGEST 146
722#define ASN1_F_D2I_PKCS7_ENCRYPT 147 777#define ASN1_F_D2I_PKCS7_ENCRYPT 147
@@ -727,10 +782,17 @@ int ASN1_TYPE_get_int_octetstring();
727#define ASN1_F_D2I_PKCS7_SIGNED 152 782#define ASN1_F_D2I_PKCS7_SIGNED 152
728#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153 783#define ASN1_F_D2I_PKCS7_SIGNER_INFO 153
729#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154 784#define ASN1_F_D2I_PKCS7_SIGN_ENVELOPE 154
785#define ASN1_F_D2I_PKCS8_PRIV_KEY_INFO 250
786#define ASN1_F_D2I_PKEY_USAGE_PERIOD 239
787#define ASN1_F_D2I_POLICYINFO 269
788#define ASN1_F_D2I_POLICYQUALINFO 270
730#define ASN1_F_D2I_PRIVATEKEY 155 789#define ASN1_F_D2I_PRIVATEKEY 155
731#define ASN1_F_D2I_PUBLICKEY 156 790#define ASN1_F_D2I_PUBLICKEY 156
732#define ASN1_F_D2I_RSAPRIVATEKEY 157 791#define ASN1_F_D2I_RSAPRIVATEKEY 157
733#define ASN1_F_D2I_RSAPUBLICKEY 158 792#define ASN1_F_D2I_RSAPUBLICKEY 158
793#define ASN1_F_D2I_SXNET 241
794#define ASN1_F_D2I_SXNETID 243
795#define ASN1_F_D2I_USERNOTICE 271
734#define ASN1_F_D2I_X509 159 796#define ASN1_F_D2I_X509 159
735#define ASN1_F_D2I_X509_ALGOR 160 797#define ASN1_F_D2I_X509_ALGOR 160
736#define ASN1_F_D2I_X509_ATTRIBUTE 161 798#define ASN1_F_D2I_X509_ATTRIBUTE 161
@@ -748,7 +810,11 @@ int ASN1_TYPE_get_int_octetstring();
748#define ASN1_F_D2I_X509_REVOKED 173 810#define ASN1_F_D2I_X509_REVOKED 173
749#define ASN1_F_D2I_X509_SIG 174 811#define ASN1_F_D2I_X509_SIG 174
750#define ASN1_F_D2I_X509_VAL 175 812#define ASN1_F_D2I_X509_VAL 175
813#define ASN1_F_DIST_POINT_NAME_NEW 278
814#define ASN1_F_DIST_POINT_NEW 279
815#define ASN1_F_GENERAL_NAME_NEW 231
751#define ASN1_F_I2D_ASN1_HEADER 176 816#define ASN1_F_I2D_ASN1_HEADER 176
817#define ASN1_F_I2D_ASN1_TIME 225
752#define ASN1_F_I2D_DHPARAMS 177 818#define ASN1_F_I2D_DHPARAMS 177
753#define ASN1_F_I2D_DSAPARAMS 178 819#define ASN1_F_I2D_DSAPARAMS 178
754#define ASN1_F_I2D_DSAPRIVATEKEY 179 820#define ASN1_F_I2D_DSAPRIVATEKEY 179
@@ -761,9 +827,19 @@ int ASN1_TYPE_get_int_octetstring();
761#define ASN1_F_I2D_RSAPUBLICKEY 186 827#define ASN1_F_I2D_RSAPUBLICKEY 186
762#define ASN1_F_I2D_X509_ATTRIBUTE 187 828#define ASN1_F_I2D_X509_ATTRIBUTE 187
763#define ASN1_F_I2T_ASN1_OBJECT 188 829#define ASN1_F_I2T_ASN1_OBJECT 188
830#define ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW 229
764#define ASN1_F_NETSCAPE_PKEY_NEW 189 831#define ASN1_F_NETSCAPE_PKEY_NEW 189
765#define ASN1_F_NETSCAPE_SPKAC_NEW 190 832#define ASN1_F_NETSCAPE_SPKAC_NEW 190
766#define ASN1_F_NETSCAPE_SPKI_NEW 191 833#define ASN1_F_NETSCAPE_SPKI_NEW 191
834#define ASN1_F_NOTICEREF_NEW 272
835#define ASN1_F_PBE2PARAM_NEW 264
836#define ASN1_F_PBEPARAM_NEW 251
837#define ASN1_F_PBKDF2PARAM_NEW 265
838#define ASN1_F_PKCS12_BAGS_NEW 258
839#define ASN1_F_PKCS12_MAC_DATA_NEW 259
840#define ASN1_F_PKCS12_NEW 260
841#define ASN1_F_PKCS12_SAFEBAG_NEW 261
842#define ASN1_F_PKCS5_PBE2_SET 281
767#define ASN1_F_PKCS7_DIGEST_NEW 192 843#define ASN1_F_PKCS7_DIGEST_NEW 192
768#define ASN1_F_PKCS7_ENCRYPT_NEW 193 844#define ASN1_F_PKCS7_ENCRYPT_NEW 193
769#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194 845#define ASN1_F_PKCS7_ENC_CONTENT_NEW 194
@@ -774,6 +850,13 @@ int ASN1_TYPE_get_int_octetstring();
774#define ASN1_F_PKCS7_SIGNED_NEW 199 850#define ASN1_F_PKCS7_SIGNED_NEW 199
775#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200 851#define ASN1_F_PKCS7_SIGNER_INFO_NEW 200
776#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201 852#define ASN1_F_PKCS7_SIGN_ENVELOPE_NEW 201
853#define ASN1_F_PKCS8_PRIV_KEY_INFO_NEW 252
854#define ASN1_F_PKEY_USAGE_PERIOD_NEW 240
855#define ASN1_F_POLICYINFO_NEW 273
856#define ASN1_F_POLICYQUALINFO_NEW 274
857#define ASN1_F_SXNETID_NEW 244
858#define ASN1_F_SXNET_NEW 242
859#define ASN1_F_USERNOTICE_NEW 275
777#define ASN1_F_X509_ALGOR_NEW 202 860#define ASN1_F_X509_ALGOR_NEW 202
778#define ASN1_F_X509_ATTRIBUTE_NEW 203 861#define ASN1_F_X509_ATTRIBUTE_NEW 203
779#define ASN1_F_X509_CINF_NEW 204 862#define ASN1_F_X509_CINF_NEW 204
@@ -797,61 +880,64 @@ int ASN1_TYPE_get_int_octetstring();
797 880
798/* Reason codes. */ 881/* Reason codes. */
799#define ASN1_R_BAD_CLASS 100 882#define ASN1_R_BAD_CLASS 100
800#define ASN1_R_BAD_GET_OBJECT 101 883#define ASN1_R_BAD_OBJECT_HEADER 101
801#define ASN1_R_BAD_OBJECT_HEADER 102 884#define ASN1_R_BAD_PASSWORD_READ 102
802#define ASN1_R_BAD_PASSWORD_READ 103 885#define ASN1_R_BAD_PKCS7_CONTENT 103
803#define ASN1_R_BAD_PKCS7_CONTENT 104 886#define ASN1_R_BAD_PKCS7_TYPE 104
804#define ASN1_R_BAD_PKCS7_TYPE 105 887#define ASN1_R_BAD_TAG 105
805#define ASN1_R_BAD_TAG 106 888#define ASN1_R_BAD_TYPE 106
806#define ASN1_R_BAD_TYPE 107 889#define ASN1_R_BN_LIB 107
807#define ASN1_R_BN_LIB 108 890#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 108
808#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 109 891#define ASN1_R_BUFFER_TOO_SMALL 109
809#define ASN1_R_BUFFER_TOO_SMALL 110 892#define ASN1_R_DATA_IS_WRONG 110
810#define ASN1_R_DATA_IS_WRONG 111 893#define ASN1_R_DECODE_ERROR 155
811#define ASN1_R_DECODING_ERROR 112 894#define ASN1_R_DECODING_ERROR 111
812#define ASN1_R_ERROR_STACK 113 895#define ASN1_R_ENCODE_ERROR 156
813#define ASN1_R_EXPECTING_AN_INTEGER 114 896#define ASN1_R_ERROR_PARSING_SET_ELEMENT 112
814#define ASN1_R_EXPECTING_AN_OBJECT 115 897#define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 157
815#define ASN1_R_EXPECTING_AN_OCTET_STRING 116 898#define ASN1_R_EXPECTING_AN_ENUMERATED 154
816#define ASN1_R_EXPECTING_A_BIT_STRING 117 899#define ASN1_R_EXPECTING_AN_INTEGER 113
817#define ASN1_R_EXPECTING_A_BOOLEAN 118 900#define ASN1_R_EXPECTING_AN_OBJECT 114
818#define ASN1_R_EXPECTING_A_SEQUENCE 119 901#define ASN1_R_EXPECTING_AN_OCTET_STRING 115
819#define ASN1_R_EXPECTING_A_UTCTIME 120 902#define ASN1_R_EXPECTING_A_BIT_STRING 116
820#define ASN1_R_FIRST_NUM_TOO_LARGE 121 903#define ASN1_R_EXPECTING_A_BOOLEAN 117
821#define ASN1_R_HEADER_TOO_LONG 122 904#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151
822#define ASN1_R_INVALID_DIGIT 123 905#define ASN1_R_EXPECTING_A_TIME 152
823#define ASN1_R_INVALID_SEPARATOR 124 906#define ASN1_R_EXPECTING_A_UTCTIME 118
824#define ASN1_R_INVALID_TIME_FORMAT 125 907#define ASN1_R_FIRST_NUM_TOO_LARGE 119
825#define ASN1_R_IV_TOO_LARGE 126 908#define ASN1_R_GENERALIZEDTIME_TOO_LONG 153
826#define ASN1_R_LENGTH_ERROR 127 909#define ASN1_R_HEADER_TOO_LONG 120
827#define ASN1_R_LENGTH_MISMATCH 128 910#define ASN1_R_INVALID_DIGIT 121
828#define ASN1_R_MISSING_EOS 129 911#define ASN1_R_INVALID_SEPARATOR 122
829#define ASN1_R_MISSING_SECOND_NUMBER 130 912#define ASN1_R_INVALID_TIME_FORMAT 123
830#define ASN1_R_NON_HEX_CHARACTERS 131 913#define ASN1_R_IV_TOO_LARGE 124
831#define ASN1_R_NOT_ENOUGH_DATA 132 914#define ASN1_R_LENGTH_ERROR 125
832#define ASN1_R_ODD_NUMBER_OF_CHARS 133 915#define ASN1_R_MISSING_SECOND_NUMBER 126
833#define ASN1_R_PARSING 134 916#define ASN1_R_NON_HEX_CHARACTERS 127
834#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 135 917#define ASN1_R_NOT_ENOUGH_DATA 128
835#define ASN1_R_SECOND_NUMBER_TOO_LARGE 136 918#define ASN1_R_ODD_NUMBER_OF_CHARS 129
836#define ASN1_R_SHORT_LINE 137 919#define ASN1_R_PARSING 130
837#define ASN1_R_STRING_TOO_SHORT 138 920#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131
838#define ASN1_R_TAG_VALUE_TOO_HIGH 139 921#define ASN1_R_SECOND_NUMBER_TOO_LARGE 132
839#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 140 922#define ASN1_R_SHORT_LINE 133
840#define ASN1_R_TOO_LONG 141 923#define ASN1_R_STRING_TOO_SHORT 134
841#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 142 924#define ASN1_R_TAG_VALUE_TOO_HIGH 135
842#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 143 925#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 136
843#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 144 926#define ASN1_R_TOO_LONG 137
844#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 145 927#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 138
845#define ASN1_R_UNKNOWN_OBJECT_TYPE 146 928#define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 139
846#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 147 929#define ASN1_R_UNKNOWN_ATTRIBUTE_TYPE 140
847#define ASN1_R_UNSUPPORTED_CIPHER 148 930#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 141
848#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 149 931#define ASN1_R_UNKNOWN_OBJECT_TYPE 142
849#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 150 932#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 143
850#define ASN1_R_UTCTIME_TOO_LONG 151 933#define ASN1_R_UNSUPPORTED_CIPHER 144
851#define ASN1_R_WRONG_PRINTABLE_TYPE 152 934#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 145
852#define ASN1_R_WRONG_TAG 153 935#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 146
853#define ASN1_R_WRONG_TYPE 154 936#define ASN1_R_UTCTIME_TOO_LONG 147
854 937#define ASN1_R_WRONG_PRINTABLE_TYPE 148
938#define ASN1_R_WRONG_TAG 149
939#define ASN1_R_WRONG_TYPE 150
940
855#ifdef __cplusplus 941#ifdef __cplusplus
856} 942}
857#endif 943#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 @@
1/* lib/asn1/asn1_err.c */ 1/* crypto/asn1/asn1_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "asn1.h" 62#include <openssl/asn1.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
64static ERR_STRING_DATA ASN1_str_functs[]= 66static ERR_STRING_DATA ASN1_str_functs[]=
65 { 67 {
66{ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"}, 68{ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"},
69{ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"},
67{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"}, 70{ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"},
68{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"}, 71{ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"},
69{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMATIVE,0), "ASN1_COLLATE_PRIMATIVE"}, 72{ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"},
70{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"}, 73{ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"},
71{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"}, 74{ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"},
72{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"}, 75{ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"},
76{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"},
77{ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"},
78{ERR_PACK(0,ASN1_F_ASN1_GENERALIZEDTIME_NEW,0), "ASN1_GENERALIZEDTIME_NEW"},
73{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"}, 79{ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"},
74{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"}, 80{ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"},
75{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"}, 81{ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"},
@@ -77,121 +83,176 @@ static ERR_STRING_DATA ASN1_str_functs[]=
77{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"}, 83{ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"},
78{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"}, 84{ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"},
79{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"}, 85{ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"},
80{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_SIGN"}, 86{ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"},
87{ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"},
88{ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"},
89{ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"},
90{ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"},
81{ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"}, 91{ERR_PACK(0,ASN1_F_ASN1_STRING_NEW,0), "ASN1_STRING_new"},
82{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"}, 92{ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"},
83{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"}, 93{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"},
84{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"}, 94{ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"},
85{ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"}, 95{ERR_PACK(0,ASN1_F_ASN1_TYPE_NEW,0), "ASN1_TYPE_new"},
96{ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"},
86{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"}, 97{ERR_PACK(0,ASN1_F_ASN1_UTCTIME_NEW,0), "ASN1_UTCTIME_NEW"},
87{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_VERIFY"}, 98{ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"},
99{ERR_PACK(0,ASN1_F_AUTHORITY_KEYID_NEW,0), "AUTHORITY_KEYID_new"},
100{ERR_PACK(0,ASN1_F_BASIC_CONSTRAINTS_NEW,0), "BASIC_CONSTRAINTS_new"},
101{ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"},
88{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"}, 102{ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"},
89{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"}, 103{ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "d2i_ASN1_BIT_STRING"},
90{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "D2I_ASN1_BMPSTRING"}, 104{ERR_PACK(0,ASN1_F_D2I_ASN1_BMPSTRING,0), "d2i_ASN1_BMPSTRING"},
91{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"}, 105{ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"},
92{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"}, 106{ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"},
107{ERR_PACK(0,ASN1_F_D2I_ASN1_ENUMERATED,0), "d2i_ASN1_ENUMERATED"},
108{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"},
93{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"}, 109{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
94{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"}, 110{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"},
95{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"}, 111{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
96{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"}, 112{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"},
97{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"}, 113{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"},
98{ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"}, 114{ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"},
115{ERR_PACK(0,ASN1_F_D2I_ASN1_TIME,0), "d2i_ASN1_TIME"},
99{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"}, 116{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"},
100{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"}, 117{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"},
118{ERR_PACK(0,ASN1_F_D2I_ASN1_UINTEGER,0), "d2i_ASN1_UINTEGER"},
101{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"}, 119{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"},
102{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "D2I_DHPARAMS"}, 120{ERR_PACK(0,ASN1_F_D2I_ASN1_UTF8STRING,0), "d2i_ASN1_UTF8STRING"},
103{ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "D2I_DSAPARAMS"}, 121{ERR_PACK(0,ASN1_F_D2I_ASN1_VISIBLESTRING,0), "d2i_ASN1_VISIBLESTRING"},
104{ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "D2I_DSAPRIVATEKEY"}, 122{ERR_PACK(0,ASN1_F_D2I_AUTHORITY_KEYID,0), "d2i_AUTHORITY_KEYID"},
105{ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "D2I_DSAPUBLICKEY"}, 123{ERR_PACK(0,ASN1_F_D2I_BASIC_CONSTRAINTS,0), "d2i_BASIC_CONSTRAINTS"},
124{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "d2i_DHparams"},
125{ERR_PACK(0,ASN1_F_D2I_DIST_POINT,0), "d2i_DIST_POINT"},
126{ERR_PACK(0,ASN1_F_D2I_DIST_POINT_NAME,0), "d2i_DIST_POINT_NAME"},
127{ERR_PACK(0,ASN1_F_D2I_DSAPARAMS,0), "d2i_DSAparams"},
128{ERR_PACK(0,ASN1_F_D2I_DSAPRIVATEKEY,0), "d2i_DSAPrivateKey"},
129{ERR_PACK(0,ASN1_F_D2I_DSAPUBLICKEY,0), "d2i_DSAPublicKey"},
130{ERR_PACK(0,ASN1_F_D2I_GENERAL_NAME,0), "d2i_GENERAL_NAME"},
131{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE,0), "d2i_NETSCAPE_CERT_SEQUENCE"},
106{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_PKEY,0), "D2I_NETSCAPE_PKEY"}, 132{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_PKEY,0), "D2I_NETSCAPE_PKEY"},
107{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "D2I_NETSCAPE_RSA"}, 133{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "d2i_Netscape_RSA"},
108{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "D2I_NETSCAPE_RSA_2"}, 134{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "d2i_Netscape_RSA_2"},
109{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "D2I_NETSCAPE_SPKAC"}, 135{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKAC,0), "d2i_NETSCAPE_SPKAC"},
110{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "D2I_NETSCAPE_SPKI"}, 136{ERR_PACK(0,ASN1_F_D2I_NETSCAPE_SPKI,0), "d2i_NETSCAPE_SPKI"},
111{ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "D2I_PKCS7"}, 137{ERR_PACK(0,ASN1_F_D2I_NOTICEREF,0), "d2i_NOTICEREF"},
112{ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "D2I_PKCS7_DIGEST"}, 138{ERR_PACK(0,ASN1_F_D2I_PBE2PARAM,0), "d2i_PBE2PARAM"},
113{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "D2I_PKCS7_ENCRYPT"}, 139{ERR_PACK(0,ASN1_F_D2I_PBEPARAM,0), "d2i_PBEPARAM"},
114{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "D2I_PKCS7_ENC_CONTENT"}, 140{ERR_PACK(0,ASN1_F_D2I_PBKDF2PARAM,0), "d2i_PBKDF2PARAM"},
115{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "D2I_PKCS7_ENVELOPE"}, 141{ERR_PACK(0,ASN1_F_D2I_PKCS12,0), "d2i_PKCS12"},
116{ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "D2I_PKCS7_ISSUER_AND_SERIAL"}, 142{ERR_PACK(0,ASN1_F_D2I_PKCS12_BAGS,0), "d2i_PKCS12_BAGS"},
117{ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "D2I_PKCS7_RECIP_INFO"}, 143{ERR_PACK(0,ASN1_F_D2I_PKCS12_MAC_DATA,0), "d2i_PKCS12_MAC_DATA"},
118{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "D2I_PKCS7_SIGNED"}, 144{ERR_PACK(0,ASN1_F_D2I_PKCS12_SAFEBAG,0), "d2i_PKCS12_SAFEBAG"},
119{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "D2I_PKCS7_SIGNER_INFO"}, 145{ERR_PACK(0,ASN1_F_D2I_PKCS7,0), "d2i_PKCS7"},
120{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "D2I_PKCS7_SIGN_ENVELOPE"}, 146{ERR_PACK(0,ASN1_F_D2I_PKCS7_DIGEST,0), "d2i_PKCS7_DIGEST"},
121{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "D2I_PRIVATEKEY"}, 147{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENCRYPT,0), "d2i_PKCS7_ENCRYPT"},
122{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "D2I_PUBLICKEY"}, 148{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENC_CONTENT,0), "d2i_PKCS7_ENC_CONTENT"},
123{ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "D2I_RSAPRIVATEKEY"}, 149{ERR_PACK(0,ASN1_F_D2I_PKCS7_ENVELOPE,0), "d2i_PKCS7_ENVELOPE"},
124{ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "D2I_RSAPUBLICKEY"}, 150{ERR_PACK(0,ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,0), "d2i_PKCS7_ISSUER_AND_SERIAL"},
125{ERR_PACK(0,ASN1_F_D2I_X509,0), "D2I_X509"}, 151{ERR_PACK(0,ASN1_F_D2I_PKCS7_RECIP_INFO,0), "d2i_PKCS7_RECIP_INFO"},
126{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "D2I_X509_ALGOR"}, 152{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNED,0), "d2i_PKCS7_SIGNED"},
127{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "D2I_X509_ATTRIBUTE"}, 153{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGNER_INFO,0), "d2i_PKCS7_SIGNER_INFO"},
128{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "D2I_X509_CINF"}, 154{ERR_PACK(0,ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,0), "d2i_PKCS7_SIGN_ENVELOPE"},
129{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "D2I_X509_CRL"}, 155{ERR_PACK(0,ASN1_F_D2I_PKCS8_PRIV_KEY_INFO,0), "d2i_PKCS8_PRIV_KEY_INFO"},
130{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "D2I_X509_CRL_INFO"}, 156{ERR_PACK(0,ASN1_F_D2I_PKEY_USAGE_PERIOD,0), "d2i_PKEY_USAGE_PERIOD"},
131{ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "D2I_X509_EXTENSION"}, 157{ERR_PACK(0,ASN1_F_D2I_POLICYINFO,0), "d2i_POLICYINFO"},
158{ERR_PACK(0,ASN1_F_D2I_POLICYQUALINFO,0), "d2i_POLICYQUALINFO"},
159{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"},
160{ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"},
161{ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "d2i_RSAPrivateKey"},
162{ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "d2i_RSAPublicKey"},
163{ERR_PACK(0,ASN1_F_D2I_SXNET,0), "d2i_SXNET"},
164{ERR_PACK(0,ASN1_F_D2I_SXNETID,0), "d2i_SXNETID"},
165{ERR_PACK(0,ASN1_F_D2I_USERNOTICE,0), "d2i_USERNOTICE"},
166{ERR_PACK(0,ASN1_F_D2I_X509,0), "d2i_X509"},
167{ERR_PACK(0,ASN1_F_D2I_X509_ALGOR,0), "d2i_X509_ALGOR"},
168{ERR_PACK(0,ASN1_F_D2I_X509_ATTRIBUTE,0), "d2i_X509_ATTRIBUTE"},
169{ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "d2i_X509_CINF"},
170{ERR_PACK(0,ASN1_F_D2I_X509_CRL,0), "d2i_X509_CRL"},
171{ERR_PACK(0,ASN1_F_D2I_X509_CRL_INFO,0), "d2i_X509_CRL_INFO"},
172{ERR_PACK(0,ASN1_F_D2I_X509_EXTENSION,0), "d2i_X509_EXTENSION"},
132{ERR_PACK(0,ASN1_F_D2I_X509_KEY,0), "D2I_X509_KEY"}, 173{ERR_PACK(0,ASN1_F_D2I_X509_KEY,0), "D2I_X509_KEY"},
133{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "D2I_X509_NAME"}, 174{ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "d2i_X509_NAME"},
134{ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "D2I_X509_NAME_ENTRY"}, 175{ERR_PACK(0,ASN1_F_D2I_X509_NAME_ENTRY,0), "d2i_X509_NAME_ENTRY"},
135{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "D2I_X509_PKEY"}, 176{ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"},
136{ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "D2I_X509_PUBKEY"}, 177{ERR_PACK(0,ASN1_F_D2I_X509_PUBKEY,0), "d2i_X509_PUBKEY"},
137{ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "D2I_X509_REQ"}, 178{ERR_PACK(0,ASN1_F_D2I_X509_REQ,0), "d2i_X509_REQ"},
138{ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "D2I_X509_REQ_INFO"}, 179{ERR_PACK(0,ASN1_F_D2I_X509_REQ_INFO,0), "d2i_X509_REQ_INFO"},
139{ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "D2I_X509_REVOKED"}, 180{ERR_PACK(0,ASN1_F_D2I_X509_REVOKED,0), "d2i_X509_REVOKED"},
140{ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "D2I_X509_SIG"}, 181{ERR_PACK(0,ASN1_F_D2I_X509_SIG,0), "d2i_X509_SIG"},
141{ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "D2I_X509_VAL"}, 182{ERR_PACK(0,ASN1_F_D2I_X509_VAL,0), "d2i_X509_VAL"},
183{ERR_PACK(0,ASN1_F_DIST_POINT_NAME_NEW,0), "DIST_POINT_NAME_new"},
184{ERR_PACK(0,ASN1_F_DIST_POINT_NEW,0), "DIST_POINT_new"},
185{ERR_PACK(0,ASN1_F_GENERAL_NAME_NEW,0), "GENERAL_NAME_new"},
142{ERR_PACK(0,ASN1_F_I2D_ASN1_HEADER,0), "i2d_ASN1_HEADER"}, 186{ERR_PACK(0,ASN1_F_I2D_ASN1_HEADER,0), "i2d_ASN1_HEADER"},
143{ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "I2D_DHPARAMS"}, 187{ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "i2d_ASN1_TIME"},
144{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "I2D_DSAPARAMS"}, 188{ERR_PACK(0,ASN1_F_I2D_DHPARAMS,0), "i2d_DHparams"},
145{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "I2D_DSAPRIVATEKEY"}, 189{ERR_PACK(0,ASN1_F_I2D_DSAPARAMS,0), "i2d_DSAparams"},
146{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "I2D_DSAPUBLICKEY"}, 190{ERR_PACK(0,ASN1_F_I2D_DSAPRIVATEKEY,0), "i2d_DSAPrivateKey"},
147{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "I2D_NETSCAPE_RSA"}, 191{ERR_PACK(0,ASN1_F_I2D_DSAPUBLICKEY,0), "i2d_DSAPublicKey"},
148{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "I2D_PKCS7"}, 192{ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"},
149{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "I2D_PRIVATEKEY"}, 193{ERR_PACK(0,ASN1_F_I2D_PKCS7,0), "i2d_PKCS7"},
150{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "I2D_PUBLICKEY"}, 194{ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"},
151{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "I2D_RSAPRIVATEKEY"}, 195{ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"},
152{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "I2D_RSAPUBLICKEY"}, 196{ERR_PACK(0,ASN1_F_I2D_RSAPRIVATEKEY,0), "i2d_RSAPrivateKey"},
153{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "I2D_X509_ATTRIBUTE"}, 197{ERR_PACK(0,ASN1_F_I2D_RSAPUBLICKEY,0), "i2d_RSAPublicKey"},
198{ERR_PACK(0,ASN1_F_I2D_X509_ATTRIBUTE,0), "i2d_X509_ATTRIBUTE"},
154{ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"}, 199{ERR_PACK(0,ASN1_F_I2T_ASN1_OBJECT,0), "i2t_ASN1_OBJECT"},
200{ERR_PACK(0,ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW,0), "NETSCAPE_CERT_SEQUENCE_new"},
155{ERR_PACK(0,ASN1_F_NETSCAPE_PKEY_NEW,0), "NETSCAPE_PKEY_NEW"}, 201{ERR_PACK(0,ASN1_F_NETSCAPE_PKEY_NEW,0), "NETSCAPE_PKEY_NEW"},
156{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_NEW"}, 202{ERR_PACK(0,ASN1_F_NETSCAPE_SPKAC_NEW,0), "NETSCAPE_SPKAC_new"},
157{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_NEW"}, 203{ERR_PACK(0,ASN1_F_NETSCAPE_SPKI_NEW,0), "NETSCAPE_SPKI_new"},
158{ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_NEW"}, 204{ERR_PACK(0,ASN1_F_NOTICEREF_NEW,0), "NOTICEREF_new"},
159{ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_NEW"}, 205{ERR_PACK(0,ASN1_F_PBE2PARAM_NEW,0), "PBE2PARAM_new"},
160{ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_NEW"}, 206{ERR_PACK(0,ASN1_F_PBEPARAM_NEW,0), "PBEPARAM_new"},
161{ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_NEW"}, 207{ERR_PACK(0,ASN1_F_PBKDF2PARAM_NEW,0), "PBKDF2PARAM_new"},
162{ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_NEW"}, 208{ERR_PACK(0,ASN1_F_PKCS12_BAGS_NEW,0), "PKCS12_BAGS_new"},
163{ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_NEW"}, 209{ERR_PACK(0,ASN1_F_PKCS12_MAC_DATA_NEW,0), "PKCS12_MAC_DATA_new"},
164{ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_NEW"}, 210{ERR_PACK(0,ASN1_F_PKCS12_NEW,0), "PKCS12_new"},
165{ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_NEW"}, 211{ERR_PACK(0,ASN1_F_PKCS12_SAFEBAG_NEW,0), "PKCS12_SAFEBAG_new"},
166{ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_NEW"}, 212{ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"},
167{ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_NEW"}, 213{ERR_PACK(0,ASN1_F_PKCS7_DIGEST_NEW,0), "PKCS7_DIGEST_new"},
168{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_NEW"}, 214{ERR_PACK(0,ASN1_F_PKCS7_ENCRYPT_NEW,0), "PKCS7_ENCRYPT_new"},
169{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_NEW"}, 215{ERR_PACK(0,ASN1_F_PKCS7_ENC_CONTENT_NEW,0), "PKCS7_ENC_CONTENT_new"},
170{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_NEW"}, 216{ERR_PACK(0,ASN1_F_PKCS7_ENVELOPE_NEW,0), "PKCS7_ENVELOPE_new"},
171{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_NEW"}, 217{ERR_PACK(0,ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,0), "PKCS7_ISSUER_AND_SERIAL_new"},
172{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_NEW"}, 218{ERR_PACK(0,ASN1_F_PKCS7_NEW,0), "PKCS7_new"},
219{ERR_PACK(0,ASN1_F_PKCS7_RECIP_INFO_NEW,0), "PKCS7_RECIP_INFO_new"},
220{ERR_PACK(0,ASN1_F_PKCS7_SIGNED_NEW,0), "PKCS7_SIGNED_new"},
221{ERR_PACK(0,ASN1_F_PKCS7_SIGNER_INFO_NEW,0), "PKCS7_SIGNER_INFO_new"},
222{ERR_PACK(0,ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,0), "PKCS7_SIGN_ENVELOPE_new"},
223{ERR_PACK(0,ASN1_F_PKCS8_PRIV_KEY_INFO_NEW,0), "PKCS8_PRIV_KEY_INFO_new"},
224{ERR_PACK(0,ASN1_F_PKEY_USAGE_PERIOD_NEW,0), "PKEY_USAGE_PERIOD_new"},
225{ERR_PACK(0,ASN1_F_POLICYINFO_NEW,0), "POLICYINFO_new"},
226{ERR_PACK(0,ASN1_F_POLICYQUALINFO_NEW,0), "POLICYQUALINFO_new"},
227{ERR_PACK(0,ASN1_F_SXNETID_NEW,0), "SXNETID_new"},
228{ERR_PACK(0,ASN1_F_SXNET_NEW,0), "SXNET_new"},
229{ERR_PACK(0,ASN1_F_USERNOTICE_NEW,0), "USERNOTICE_new"},
230{ERR_PACK(0,ASN1_F_X509_ALGOR_NEW,0), "X509_ALGOR_new"},
231{ERR_PACK(0,ASN1_F_X509_ATTRIBUTE_NEW,0), "X509_ATTRIBUTE_new"},
232{ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_new"},
233{ERR_PACK(0,ASN1_F_X509_CRL_INFO_NEW,0), "X509_CRL_INFO_new"},
234{ERR_PACK(0,ASN1_F_X509_CRL_NEW,0), "X509_CRL_new"},
173{ERR_PACK(0,ASN1_F_X509_DHPARAMS_NEW,0), "X509_DHPARAMS_NEW"}, 235{ERR_PACK(0,ASN1_F_X509_DHPARAMS_NEW,0), "X509_DHPARAMS_NEW"},
174{ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_NEW"}, 236{ERR_PACK(0,ASN1_F_X509_EXTENSION_NEW,0), "X509_EXTENSION_new"},
175{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_NEW"}, 237{ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_new"},
176{ERR_PACK(0,ASN1_F_X509_KEY_NEW,0), "X509_KEY_NEW"}, 238{ERR_PACK(0,ASN1_F_X509_KEY_NEW,0), "X509_KEY_NEW"},
177{ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_NEW"}, 239{ERR_PACK(0,ASN1_F_X509_NAME_ENTRY_NEW,0), "X509_NAME_ENTRY_new"},
178{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_NEW"}, 240{ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_new"},
179{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_NEW"}, 241{ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_new"},
180{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_NEW"}, 242{ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_new"},
181{ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_NEW"}, 243{ERR_PACK(0,ASN1_F_X509_PUBKEY_NEW,0), "X509_PUBKEY_new"},
182{ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_NEW"}, 244{ERR_PACK(0,ASN1_F_X509_REQ_INFO_NEW,0), "X509_REQ_INFO_new"},
183{ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_NEW"}, 245{ERR_PACK(0,ASN1_F_X509_REQ_NEW,0), "X509_REQ_new"},
184{ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_NEW"}, 246{ERR_PACK(0,ASN1_F_X509_REVOKED_NEW,0), "X509_REVOKED_new"},
185{ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_NEW"}, 247{ERR_PACK(0,ASN1_F_X509_SIG_NEW,0), "X509_SIG_new"},
186{ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_FREE"}, 248{ERR_PACK(0,ASN1_F_X509_VAL_FREE,0), "X509_VAL_free"},
187{ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_NEW"}, 249{ERR_PACK(0,ASN1_F_X509_VAL_NEW,0), "X509_VAL_new"},
188{0,NULL}, 250{0,NULL}
189 }; 251 };
190 252
191static ERR_STRING_DATA ASN1_str_reasons[]= 253static ERR_STRING_DATA ASN1_str_reasons[]=
192 { 254 {
193{ASN1_R_BAD_CLASS ,"bad class"}, 255{ASN1_R_BAD_CLASS ,"bad class"},
194{ASN1_R_BAD_GET_OBJECT ,"bad get object"},
195{ASN1_R_BAD_OBJECT_HEADER ,"bad object header"}, 256{ASN1_R_BAD_OBJECT_HEADER ,"bad object header"},
196{ASN1_R_BAD_PASSWORD_READ ,"bad password read"}, 257{ASN1_R_BAD_PASSWORD_READ ,"bad password read"},
197{ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"}, 258{ASN1_R_BAD_PKCS7_CONTENT ,"bad pkcs7 content"},
@@ -202,24 +263,28 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
202{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"}, 263{ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"},
203{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"}, 264{ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"},
204{ASN1_R_DATA_IS_WRONG ,"data is wrong"}, 265{ASN1_R_DATA_IS_WRONG ,"data is wrong"},
266{ASN1_R_DECODE_ERROR ,"decode error"},
205{ASN1_R_DECODING_ERROR ,"decoding error"}, 267{ASN1_R_DECODING_ERROR ,"decoding error"},
206{ASN1_R_ERROR_STACK ,"error stack"}, 268{ASN1_R_ENCODE_ERROR ,"encode error"},
269{ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"},
270{ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"},
271{ASN1_R_EXPECTING_AN_ENUMERATED ,"expecting an enumerated"},
207{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"}, 272{ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"},
208{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"}, 273{ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"},
209{ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"}, 274{ASN1_R_EXPECTING_AN_OCTET_STRING ,"expecting an octet string"},
210{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"}, 275{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"},
211{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"}, 276{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
212{ASN1_R_EXPECTING_A_SEQUENCE ,"expecting a sequence"}, 277{ASN1_R_EXPECTING_A_GENERALIZEDTIME ,"expecting a generalizedtime"},
278{ASN1_R_EXPECTING_A_TIME ,"expecting a time"},
213{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"}, 279{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"},
214{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"}, 280{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
281{ASN1_R_GENERALIZEDTIME_TOO_LONG ,"generalizedtime too long"},
215{ASN1_R_HEADER_TOO_LONG ,"header too long"}, 282{ASN1_R_HEADER_TOO_LONG ,"header too long"},
216{ASN1_R_INVALID_DIGIT ,"invalid digit"}, 283{ASN1_R_INVALID_DIGIT ,"invalid digit"},
217{ASN1_R_INVALID_SEPARATOR ,"invalid separator"}, 284{ASN1_R_INVALID_SEPARATOR ,"invalid separator"},
218{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"}, 285{ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"},
219{ASN1_R_IV_TOO_LARGE ,"iv too large"}, 286{ASN1_R_IV_TOO_LARGE ,"iv too large"},
220{ASN1_R_LENGTH_ERROR ,"length error"}, 287{ASN1_R_LENGTH_ERROR ,"length error"},
221{ASN1_R_LENGTH_MISMATCH ,"length mismatch"},
222{ASN1_R_MISSING_EOS ,"missing eos"},
223{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"}, 288{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
224{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"}, 289{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
225{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"}, 290{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
@@ -245,17 +310,17 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
245{ASN1_R_WRONG_PRINTABLE_TYPE ,"wrong printable type"}, 310{ASN1_R_WRONG_PRINTABLE_TYPE ,"wrong printable type"},
246{ASN1_R_WRONG_TAG ,"wrong tag"}, 311{ASN1_R_WRONG_TAG ,"wrong tag"},
247{ASN1_R_WRONG_TYPE ,"wrong type"}, 312{ASN1_R_WRONG_TYPE ,"wrong type"},
248{0,NULL}, 313{0,NULL}
249 }; 314 };
250 315
251#endif 316#endif
252 317
253void ERR_load_ASN1_strings() 318void ERR_load_ASN1_strings(void)
254 { 319 {
255 static int init=1; 320 static int init=1;
256 321
257 if (init); 322 if (init)
258 {; 323 {
259 init=0; 324 init=0;
260#ifndef NO_ERR 325#ifndef NO_ERR
261 ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs); 326 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63 63
64#ifndef NOPROTO
65static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max); 64static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
66static void asn1_put_length(unsigned char **pp, int length); 65static void asn1_put_length(unsigned char **pp, int length);
67#else 66const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
68static int asn1_get_length();
69static void asn1_put_length();
70#endif
71
72char *ASN1_version="ASN1 part of SSLeay 0.9.0b 29-Jun-1998";
73 67
74int ASN1_check_infinite_end(p,len) 68int ASN1_check_infinite_end(unsigned char **p, long len)
75unsigned char **p;
76long len;
77 { 69 {
78 /* If there is 0 or 1 byte left, the length check should pick 70 /* If there is 0 or 1 byte left, the length check should pick
79 * things up */ 71 * things up */
@@ -88,12 +80,8 @@ long len;
88 } 80 }
89 81
90 82
91int ASN1_get_object(pp, plength, ptag, pclass, omax) 83int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
92unsigned char **pp; 84 long omax)
93long *plength;
94int *ptag;
95int *pclass;
96long omax;
97 { 85 {
98 int i,ret; 86 int i,ret;
99 long l; 87 long l;
@@ -104,8 +92,8 @@ long omax;
104 if (!max) goto err; 92 if (!max) goto err;
105 ret=(*p&V_ASN1_CONSTRUCTED); 93 ret=(*p&V_ASN1_CONSTRUCTED);
106 xclass=(*p&V_ASN1_PRIVATE); 94 xclass=(*p&V_ASN1_PRIVATE);
107 i= *p&V_ASN1_PRIMATIVE_TAG; 95 i= *p&V_ASN1_PRIMITIVE_TAG;
108 if (i == V_ASN1_PRIMATIVE_TAG) 96 if (i == V_ASN1_PRIMITIVE_TAG)
109 { /* high-tag */ 97 { /* high-tag */
110 p++; 98 p++;
111 if (--max == 0) goto err; 99 if (--max == 0) goto err;
@@ -130,11 +118,13 @@ long omax;
130 *pclass=xclass; 118 *pclass=xclass;
131 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; 119 if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
132 120
133#ifdef undef 121#if 0
134 fprintf(stderr,"p=%d + *plength=%d > omax=%d + *pp=%d (%d > %d)\n", 122 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
135 p,*plength,omax,*pp,(p+ *plength),omax+ *pp); 123 (int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
124 (int)(omax+ *pp));
136 125
137#endif 126#endif
127#if 0
138 if ((p+ *plength) > (omax+ *pp)) 128 if ((p+ *plength) > (omax+ *pp))
139 { 129 {
140 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); 130 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
@@ -142,18 +132,15 @@ long omax;
142 * the values are set correctly */ 132 * the values are set correctly */
143 ret|=0x80; 133 ret|=0x80;
144 } 134 }
135#endif
145 *pp=p; 136 *pp=p;
146 return(ret+inf); 137 return(ret|inf);
147err: 138err:
148 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); 139 ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
149 return(0x80); 140 return(0x80);
150 } 141 }
151 142
152static int asn1_get_length(pp,inf,rl,max) 143static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
153unsigned char **pp;
154int *inf;
155long *rl;
156int max;
157 { 144 {
158 unsigned char *p= *pp; 145 unsigned char *p= *pp;
159 long ret=0; 146 long ret=0;
@@ -190,12 +177,8 @@ int max;
190 177
191/* class 0 is constructed 178/* class 0 is constructed
192 * constructed == 2 for indefinitle length constructed */ 179 * constructed == 2 for indefinitle length constructed */
193void ASN1_put_object(pp,constructed,length,tag,xclass) 180void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
194unsigned char **pp; 181 int xclass)
195int constructed;
196int length;
197int tag;
198int xclass;
199 { 182 {
200 unsigned char *p= *pp; 183 unsigned char *p= *pp;
201 int i; 184 int i;
@@ -203,10 +186,10 @@ int xclass;
203 i=(constructed)?V_ASN1_CONSTRUCTED:0; 186 i=(constructed)?V_ASN1_CONSTRUCTED:0;
204 i|=(xclass&V_ASN1_PRIVATE); 187 i|=(xclass&V_ASN1_PRIVATE);
205 if (tag < 31) 188 if (tag < 31)
206 *(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG); 189 *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
207 else 190 else
208 { 191 {
209 *(p++)=i|V_ASN1_PRIMATIVE_TAG; 192 *(p++)=i|V_ASN1_PRIMITIVE_TAG;
210 while (tag > 0x7f) 193 while (tag > 0x7f)
211 { 194 {
212 *(p++)=(tag&0x7f)|0x80; 195 *(p++)=(tag&0x7f)|0x80;
@@ -221,9 +204,7 @@ int xclass;
221 *pp=p; 204 *pp=p;
222 } 205 }
223 206
224static void asn1_put_length(pp, length) 207static void asn1_put_length(unsigned char **pp, int length)
225unsigned char **pp;
226int length;
227 { 208 {
228 unsigned char *p= *pp; 209 unsigned char *p= *pp;
229 int i,l; 210 int i,l;
@@ -246,10 +227,7 @@ int length;
246 *pp=p; 227 *pp=p;
247 } 228 }
248 229
249int ASN1_object_size(constructed, length, tag) 230int ASN1_object_size(int constructed, int length, int tag)
250int constructed;
251int length;
252int tag;
253 { 231 {
254 int ret; 232 int ret;
255 233
@@ -277,29 +255,26 @@ int tag;
277 return(ret); 255 return(ret);
278 } 256 }
279 257
280int asn1_Finish(c) 258int asn1_Finish(ASN1_CTX *c)
281ASN1_CTX *c;
282 { 259 {
283 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) 260 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
284 { 261 {
285 if (!ASN1_check_infinite_end(&c->p,c->slen)) 262 if (!ASN1_check_infinite_end(&c->p,c->slen))
286 { 263 {
287 c->error=ASN1_R_MISSING_EOS; 264 c->error=ERR_R_MISSING_ASN1_EOS;
288 return(0); 265 return(0);
289 } 266 }
290 } 267 }
291 if ( ((c->slen != 0) && !(c->inf & 1)) || 268 if ( ((c->slen != 0) && !(c->inf & 1)) ||
292 ((c->slen < 0) && (c->inf & 1))) 269 ((c->slen < 0) && (c->inf & 1)))
293 { 270 {
294 c->error=ASN1_R_LENGTH_MISMATCH; 271 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
295 return(0); 272 return(0);
296 } 273 }
297 return(1); 274 return(1);
298 } 275 }
299 276
300int asn1_GetSequence(c,length) 277int asn1_GetSequence(ASN1_CTX *c, long *length)
301ASN1_CTX *c;
302long *length;
303 { 278 {
304 unsigned char *q; 279 unsigned char *q;
305 280
@@ -308,18 +283,18 @@ long *length;
308 *length); 283 *length);
309 if (c->inf & 0x80) 284 if (c->inf & 0x80)
310 { 285 {
311 c->error=ASN1_R_BAD_GET_OBJECT; 286 c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;
312 return(0); 287 return(0);
313 } 288 }
314 if (c->tag != V_ASN1_SEQUENCE) 289 if (c->tag != V_ASN1_SEQUENCE)
315 { 290 {
316 c->error=ASN1_R_EXPECTING_A_SEQUENCE; 291 c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;
317 return(0); 292 return(0);
318 } 293 }
319 (*length)-=(c->p-q); 294 (*length)-=(c->p-q);
320 if (c->max && (*length < 0)) 295 if (c->max && (*length < 0))
321 { 296 {
322 c->error=ASN1_R_LENGTH_MISMATCH; 297 c->error=ERR_R_ASN1_LENGTH_MISMATCH;
323 return(0); 298 return(0);
324 } 299 }
325 if (c->inf == (1|V_ASN1_CONSTRUCTED)) 300 if (c->inf == (1|V_ASN1_CONSTRUCTED))
@@ -328,8 +303,7 @@ long *length;
328 return(1); 303 return(1);
329 } 304 }
330 305
331ASN1_STRING *ASN1_STRING_dup(str) 306ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str)
332ASN1_STRING *str;
333 { 307 {
334 ASN1_STRING *ret; 308 ASN1_STRING *ret;
335 309
@@ -341,34 +315,33 @@ ASN1_STRING *str;
341 ASN1_STRING_free(ret); 315 ASN1_STRING_free(ret);
342 return(NULL); 316 return(NULL);
343 } 317 }
318 ret->flags = str->flags;
344 return(ret); 319 return(ret);
345 } 320 }
346 321
347int ASN1_STRING_set(str,data,len) 322int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
348ASN1_STRING *str;
349unsigned char *data;
350int len;
351 { 323 {
352 char *c; 324 unsigned char *c;
325 const char *data=_data;
353 326
354 if (len < 0) 327 if (len < 0)
355 { 328 {
356 if (data == NULL) 329 if (data == NULL)
357 return(0); 330 return(0);
358 else 331 else
359 len=strlen((char *)data); 332 len=strlen(data);
360 } 333 }
361 if ((str->length < len) || (str->data == NULL)) 334 if ((str->length < len) || (str->data == NULL))
362 { 335 {
363 c=(char *)str->data; 336 c=str->data;
364 if (c == NULL) 337 if (c == NULL)
365 str->data=(unsigned char *)Malloc(len+1); 338 str->data=Malloc(len+1);
366 else 339 else
367 str->data=(unsigned char *)Realloc(c,len+1); 340 str->data=Realloc(c,len+1);
368 341
369 if (str->data == NULL) 342 if (str->data == NULL)
370 { 343 {
371 str->data=(unsigned char *)c; 344 str->data=c;
372 return(0); 345 return(0);
373 } 346 }
374 } 347 }
@@ -382,14 +355,13 @@ int len;
382 return(1); 355 return(1);
383 } 356 }
384 357
385ASN1_STRING *ASN1_STRING_new() 358ASN1_STRING *ASN1_STRING_new(void)
386 { 359 {
387 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); 360 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
388 } 361 }
389 362
390 363
391ASN1_STRING *ASN1_STRING_type_new(type) 364ASN1_STRING *ASN1_STRING_type_new(int type)
392int type;
393 { 365 {
394 ASN1_STRING *ret; 366 ASN1_STRING *ret;
395 367
@@ -402,19 +374,18 @@ int type;
402 ret->length=0; 374 ret->length=0;
403 ret->type=type; 375 ret->type=type;
404 ret->data=NULL; 376 ret->data=NULL;
377 ret->flags=0;
405 return(ret); 378 return(ret);
406 } 379 }
407 380
408void ASN1_STRING_free(a) 381void ASN1_STRING_free(ASN1_STRING *a)
409ASN1_STRING *a;
410 { 382 {
411 if (a == NULL) return; 383 if (a == NULL) return;
412 if (a->data != NULL) Free((char *)a->data); 384 if (a->data != NULL) Free((char *)a->data);
413 Free((char *)a); 385 Free((char *)a);
414 } 386 }
415 387
416int ASN1_STRING_cmp(a,b) 388int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
417ASN1_STRING *a,*b;
418 { 389 {
419 int i; 390 int i;
420 391
@@ -431,9 +402,7 @@ ASN1_STRING *a,*b;
431 return(i); 402 return(i);
432 } 403 }
433 404
434void asn1_add_error(address,offset) 405void asn1_add_error(unsigned char *address, int offset)
435unsigned char *address;
436int offset;
437 { 406 {
438 char buf1[16],buf2[16]; 407 char buf1[16],buf2[16];
439 408
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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "asn1.h" 66#include <openssl/asn1.h>
67#include "x509.h" 67
68#include "pkcs7.h" 68#ifndef ASN1_MAC_ERR_LIB
69#define ASN1_MAC_ERR_LIB ERR_LIB_ASN1
70#endif
71
72#define ASN1_MAC_H_err(f,r,line) \
73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),ERR_file_name,(line))
69 74
70#define M_ASN1_D2I_vars(a,type,func) \ 75#define M_ASN1_D2I_vars(a,type,func) \
71 ASN1_CTX c; \ 76 ASN1_CTX c; \
72 type ret=NULL; \ 77 type ret=NULL; \
73 \ 78 \
74 c.pp=pp; \ 79 c.pp=pp; \
75 c.error=ASN1_R_ERROR_STACK; \ 80 c.q= *pp; \
81 c.error=ERR_R_NESTED_ASN1_ERROR; \
76 if ((a == NULL) || ((*a) == NULL)) \ 82 if ((a == NULL) || ((*a) == NULL)) \
77 { if ((ret=(type)func()) == NULL) goto err; } \ 83 { if ((ret=(type)func()) == NULL) \
84 { c.line=__LINE__; goto err; } } \
78 else ret=(*a); 85 else ret=(*a);
79 86
80#define M_ASN1_D2I_Init() \ 87#define M_ASN1_D2I_Init() \
@@ -82,7 +89,8 @@ extern "C" {
82 c.max=(length == 0)?0:(c.p+length); 89 c.max=(length == 0)?0:(c.p+length);
83 90
84#define M_ASN1_D2I_Finish_2(a) \ 91#define M_ASN1_D2I_Finish_2(a) \
85 if (!asn1_Finish(&c)) goto err; \ 92 if (!asn1_Finish(&c)) \
93 { c.line=__LINE__; goto err; } \
86 *pp=c.p; \ 94 *pp=c.p; \
87 if (a != NULL) (*a)=ret; \ 95 if (a != NULL) (*a)=ret; \
88 return(ret); 96 return(ret);
@@ -90,21 +98,31 @@ extern "C" {
90#define M_ASN1_D2I_Finish(a,func,e) \ 98#define M_ASN1_D2I_Finish(a,func,e) \
91 M_ASN1_D2I_Finish_2(a); \ 99 M_ASN1_D2I_Finish_2(a); \
92err:\ 100err:\
93 ASN1err((e),c.error); \ 101 ASN1_MAC_H_err((e),c.error,c.line); \
94 asn1_add_error(*pp,(int)(c.q- *pp)); \ 102 asn1_add_error(*pp,(int)(c.q- *pp)); \
95 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ 103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
96 return(NULL) 104 return(NULL)
97 105
98#define M_ASN1_D2I_start_sequence() \ 106#define M_ASN1_D2I_start_sequence() \
99 if (!asn1_GetSequence(&c,&length)) goto err; 107 if (!asn1_GetSequence(&c,&length)) \
108 { c.line=__LINE__; goto err; }
100 109
101#define M_ASN1_D2I_end_sequence() \ 110#define M_ASN1_D2I_end_sequence() \
102 (((c.inf&1) == 0)?(c.slen <= 0): \ 111 (((c.inf&1) == 0)?(c.slen <= 0): \
103 (c.eos=ASN1_check_infinite_end(&c.p,c.slen))) 112 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
104 113
114/* Don't use this with d2i_ASN1_BOOLEAN() */
105#define M_ASN1_D2I_get(b,func) \ 115#define M_ASN1_D2I_get(b,func) \
106 c.q=c.p; \ 116 c.q=c.p; \
107 if (func(&(b),&c.p,c.slen) == NULL) goto err; \ 117 if (func(&(b),&c.p,c.slen) == NULL) \
118 {c.line=__LINE__; goto err; } \
119 c.slen-=(c.p-c.q);
120
121/* use this instead () */
122#define M_ASN1_D2I_get_int(b,func) \
123 c.q=c.p; \
124 if (func(&(b),&c.p,c.slen) < 0) \
125 {c.line=__LINE__; goto err; } \
108 c.slen-=(c.p-c.q); 126 c.slen-=(c.p-c.q);
109 127
110#define M_ASN1_D2I_get_opt(b,func,type) \ 128#define M_ASN1_D2I_get_opt(b,func,type) \
@@ -114,49 +132,118 @@ err:\
114 M_ASN1_D2I_get(b,func); \ 132 M_ASN1_D2I_get(b,func); \
115 } 133 }
116 134
135#define M_ASN1_D2I_get_imp(b,func, type) \
136 M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \
137 c.q=c.p; \
138 if (func(&(b),&c.p,c.slen) == NULL) \
139 {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \
140 c.slen-=(c.p-c.q);\
141 M_ASN1_next_prev=_tmp;
142
117#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ 143#define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \
118 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ 144 if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \
119 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ 145 (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \
120 { \ 146 { \
121 unsigned char tmp; \ 147 unsigned char _tmp = M_ASN1_next; \
122 tmp=M_ASN1_next; \ 148 M_ASN1_D2I_get_imp(b,func, type);\
123 M_ASN1_next=(tmp& ~V_ASN1_PRIMATIVE_TAG)|type; \
124 M_ASN1_D2I_get(b,func); \
125 M_ASN1_next_prev=tmp; \
126 } 149 }
127 150
128#define M_ASN1_D2I_get_set(r,func) \ 151#define M_ASN1_D2I_get_set(r,func,free_func) \
129 M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SET,V_ASN1_UNIVERSAL); 152 M_ASN1_D2I_get_imp_set(r,func,free_func, \
153 V_ASN1_SET,V_ASN1_UNIVERSAL);
154
155#define M_ASN1_D2I_get_set_type(type,r,func,free_func) \
156 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \
157 V_ASN1_SET,V_ASN1_UNIVERSAL);
158
159#define M_ASN1_D2I_get_set_opt(r,func,free_func) \
160 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
161 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
162 { M_ASN1_D2I_get_set(r,func,free_func); }
163
164#define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \
165 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
166 V_ASN1_CONSTRUCTED|V_ASN1_SET)))\
167 { M_ASN1_D2I_get_set_type(type,r,func,free_func); }
168
169#define M_ASN1_I2D_len_SET_opt(a,f) \
170 if ((a != NULL) && (sk_num(a) != 0)) \
171 M_ASN1_I2D_len_SET(a,f);
172
173#define M_ASN1_I2D_put_SET_opt(a,f) \
174 if ((a != NULL) && (sk_num(a) != 0)) \
175 M_ASN1_I2D_put_SET(a,f);
176
177#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
178 if ((a != NULL) && (sk_num(a) != 0)) \
179 M_ASN1_I2D_put_SEQUENCE(a,f);
180
181#define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \
182 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
183 M_ASN1_I2D_put_SEQUENCE_type(type,a,f);
184
185#define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \
186 if ((c.slen != 0) && \
187 (M_ASN1_next == \
188 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
189 { \
190 M_ASN1_D2I_get_imp_set(b,func,free_func,\
191 tag,V_ASN1_CONTEXT_SPECIFIC); \
192 }
130 193
131#define M_ASN1_D2I_get_IMP_set_opt(b,func,tag) \ 194#define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \
132 if ((c.slen != 0) && \ 195 if ((c.slen != 0) && \
133 (M_ASN1_next == \ 196 (M_ASN1_next == \
134 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ 197 (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\
135 { \ 198 { \
136 M_ASN1_D2I_get_imp_set(b,func,tag,V_ASN1_CONTEXT_SPECIFIC); \ 199 M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\
200 tag,V_ASN1_CONTEXT_SPECIFIC); \
137 } 201 }
138 202
139#define M_ASN1_D2I_get_seq(r,func) \ 203#define M_ASN1_D2I_get_seq(r,func,free_func) \
140 M_ASN1_D2I_get_imp_set(r,func,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); 204 M_ASN1_D2I_get_imp_set(r,func,free_func,\
205 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
206
207#define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \
208 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
209 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL)
141 210
142#define M_ASN1_D2I_get_seq_opt(r,func) \ 211#define M_ASN1_D2I_get_seq_opt(r,func,free_func) \
143 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ 212 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
144 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ 213 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
145 { M_ASN1_D2I_get_seq(r,func); } 214 { M_ASN1_D2I_get_seq(r,func,free_func); }
146 215
147#define M_ASN1_D2I_get_IMP_set(r,func,x) \ 216#define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \
148 M_ASN1_D2I_get_imp_set(r,func,x,V_ASN1_CONTEXT_SPECIFIC); 217 if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \
218 V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\
219 { M_ASN1_D2I_get_seq_type(type,r,func,free_func); }
220
221#define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \
222 M_ASN1_D2I_get_imp_set(r,func,free_func,\
223 x,V_ASN1_CONTEXT_SPECIFIC);
149 224
150#define M_ASN1_D2I_get_imp_set(r,func,a,b) \ 225#define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \
226 M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\
227 x,V_ASN1_CONTEXT_SPECIFIC);
228
229#define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \
151 c.q=c.p; \ 230 c.q=c.p; \
152 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,a,b) == NULL) \ 231 if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\
153 goto err; \ 232 (void (*)())free_func,a,b) == NULL) \
233 { c.line=__LINE__; goto err; } \
234 c.slen-=(c.p-c.q);
235
236#define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \
237 c.q=c.p; \
238 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\
239 free_func,a,b) == NULL) \
240 { c.line=__LINE__; goto err; } \
154 c.slen-=(c.p-c.q); 241 c.slen-=(c.p-c.q);
155 242
156#define M_ASN1_D2I_get_set_strings(r,func,a,b) \ 243#define M_ASN1_D2I_get_set_strings(r,func,a,b) \
157 c.q=c.p; \ 244 c.q=c.p; \
158 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ 245 if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \
159 goto err; \ 246 { c.line=__LINE__; goto err; } \
160 c.slen-=(c.p-c.q); 247 c.slen-=(c.p-c.q);
161 248
162#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ 249#define M_ASN1_D2I_get_EXP_opt(r,func,tag) \
@@ -169,13 +256,22 @@ err:\
169 c.q=c.p; \ 256 c.q=c.p; \
170 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ 257 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
171 if (Tinf & 0x80) \ 258 if (Tinf & 0x80) \
172 { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \ 259 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
260 c.line=__LINE__; goto err; } \
261 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
262 Tlen = c.slen - (c.p - c.q) - 2; \
173 if (func(&(r),&c.p,Tlen) == NULL) \ 263 if (func(&(r),&c.p,Tlen) == NULL) \
174 goto err; \ 264 { c.line=__LINE__; goto err; } \
265 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
266 Tlen = c.slen - (c.p - c.q); \
267 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
268 { c.error=ERR_R_MISSING_ASN1_EOS; \
269 c.line=__LINE__; goto err; } \
270 }\
175 c.slen-=(c.p-c.q); \ 271 c.slen-=(c.p-c.q); \
176 } 272 }
177 273
178#define M_ASN1_D2I_get_EXP_set_opt(r,func,tag,b) \ 274#define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \
179 if ((c.slen != 0) && (M_ASN1_next == \ 275 if ((c.slen != 0) && (M_ASN1_next == \
180 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ 276 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
181 { \ 277 { \
@@ -185,24 +281,61 @@ err:\
185 c.q=c.p; \ 281 c.q=c.p; \
186 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ 282 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
187 if (Tinf & 0x80) \ 283 if (Tinf & 0x80) \
188 { c.error=ASN1_R_BAD_OBJECT_HEADER; goto err; } \ 284 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
285 c.line=__LINE__; goto err; } \
286 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
287 Tlen = c.slen - (c.p - c.q) - 2; \
189 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ 288 if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \
289 (void (*)())free_func, \
190 b,V_ASN1_UNIVERSAL) == NULL) \ 290 b,V_ASN1_UNIVERSAL) == NULL) \
191 goto err; \ 291 { c.line=__LINE__; goto err; } \
292 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
293 Tlen = c.slen - (c.p - c.q); \
294 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
295 { c.error=ERR_R_MISSING_ASN1_EOS; \
296 c.line=__LINE__; goto err; } \
297 }\
298 c.slen-=(c.p-c.q); \
299 }
300
301#define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \
302 if ((c.slen != 0) && (M_ASN1_next == \
303 (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \
304 { \
305 int Tinf,Ttag,Tclass; \
306 long Tlen; \
307 \
308 c.q=c.p; \
309 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \
310 if (Tinf & 0x80) \
311 { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \
312 c.line=__LINE__; goto err; } \
313 if (Tinf == (V_ASN1_CONSTRUCTED+1)) \
314 Tlen = c.slen - (c.p - c.q) - 2; \
315 if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \
316 free_func,b,V_ASN1_UNIVERSAL) == NULL) \
317 { c.line=__LINE__; goto err; } \
318 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
319 Tlen = c.slen - (c.p - c.q); \
320 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
321 { c.error=ERR_R_MISSING_ASN1_EOS; \
322 c.line=__LINE__; goto err; } \
323 }\
192 c.slen-=(c.p-c.q); \ 324 c.slen-=(c.p-c.q); \
193 } 325 }
194 326
195/* New macros */ 327/* New macros */
196#define M_ASN1_New_Malloc(ret,type) \ 328#define M_ASN1_New_Malloc(ret,type) \
197 if ((ret=(type *)Malloc(sizeof(type))) == NULL) goto err2; 329 if ((ret=(type *)Malloc(sizeof(type))) == NULL) \
330 { c.line=__LINE__; goto err2; }
198 331
199#define M_ASN1_New(arg,func) \ 332#define M_ASN1_New(arg,func) \
200 if (((arg)=func()) == NULL) return(NULL) 333 if (((arg)=func()) == NULL) return(NULL)
201 334
202#define M_ASN1_New_Error(a) \ 335#define M_ASN1_New_Error(a) \
203/* err: ASN1err((a),ASN1_R_ERROR_STACK); \ 336/* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \
204 return(NULL);*/ \ 337 return(NULL);*/ \
205 err2: ASN1err((a),ERR_R_MALLOC_FAILURE); \ 338 err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \
206 return(NULL) 339 return(NULL)
207 340
208 341
@@ -220,21 +353,59 @@ err:\
220#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) 353#define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f)
221 354
222#define M_ASN1_I2D_len_SET(a,f) \ 355#define M_ASN1_I2D_len_SET(a,f) \
223 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL); 356 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
224 357
225#define M_ASN1_I2D_len_SEQ(a,f) \ 358#define M_ASN1_I2D_len_SET_type(type,a,f) \
226 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); 359 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \
360 V_ASN1_UNIVERSAL,IS_SET);
227 361
228#define M_ASN1_I2D_len_SEQ_opt(a,f) \ 362#define M_ASN1_I2D_len_SEQUENCE(a,f) \
363 ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
364 IS_SEQUENCE);
365
366#define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \
367 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \
368 V_ASN1_UNIVERSAL,IS_SEQUENCE)
369
370#define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \
229 if ((a != NULL) && (sk_num(a) != 0)) \ 371 if ((a != NULL) && (sk_num(a) != 0)) \
230 M_ASN1_I2D_len_SEQ(a,f); 372 M_ASN1_I2D_len_SEQUENCE(a,f);
373
374#define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \
375 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
376 M_ASN1_I2D_len_SEQUENCE_type(type,a,f);
231 377
232#define M_ASN1_I2D_len_IMP_set(a,f,x) \ 378#define M_ASN1_I2D_len_IMP_SET(a,f,x) \
233 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC); 379 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET);
234 380
235#define M_ASN1_I2D_len_IMP_set_opt(a,f,x) \ 381#define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \
382 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
383 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
384
385#define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \
236 if ((a != NULL) && (sk_num(a) != 0)) \ 386 if ((a != NULL) && (sk_num(a) != 0)) \
237 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC); 387 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
388 IS_SET);
389
390#define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \
391 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
392 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
393 V_ASN1_CONTEXT_SPECIFIC,IS_SET);
394
395#define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \
396 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
397 IS_SEQUENCE);
398
399#define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \
400 if ((a != NULL) && (sk_num(a) != 0)) \
401 ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \
402 IS_SEQUENCE);
403
404#define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \
405 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
406 ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \
407 V_ASN1_CONTEXT_SPECIFIC, \
408 IS_SEQUENCE);
238 409
239#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ 410#define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \
240 if (a != NULL)\ 411 if (a != NULL)\
@@ -243,10 +414,27 @@ err:\
243 ret+=ASN1_object_size(1,v,mtag); \ 414 ret+=ASN1_object_size(1,v,mtag); \
244 } 415 }
245 416
246#define M_ASN1_I2D_len_EXP_set_opt(a,f,mtag,tag,v) \ 417#define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \
418 if ((a != NULL) && (sk_num(a) != 0))\
419 { \
420 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
421 ret+=ASN1_object_size(1,v,mtag); \
422 }
423
424#define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
247 if ((a != NULL) && (sk_num(a) != 0))\ 425 if ((a != NULL) && (sk_num(a) != 0))\
248 { \ 426 { \
249 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL); \ 427 v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \
428 IS_SEQUENCE); \
429 ret+=ASN1_object_size(1,v,mtag); \
430 }
431
432#define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
433 if ((a != NULL) && (sk_##type##_num(a) != 0))\
434 { \
435 v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \
436 V_ASN1_UNIVERSAL, \
437 IS_SEQUENCE); \
250 ret+=ASN1_object_size(1,v,mtag); \ 438 ret+=ASN1_object_size(1,v,mtag); \
251 } 439 }
252 440
@@ -262,20 +450,48 @@ err:\
262 } 450 }
263 451
264#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ 452#define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\
265 V_ASN1_UNIVERSAL) 453 V_ASN1_UNIVERSAL,IS_SET)
266#define M_ASN1_I2D_put_IMP_set(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ 454#define M_ASN1_I2D_put_SET_type(type,a,f) \
267 V_ASN1_CONTEXT_SPECIFIC) 455 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET)
268 456#define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
269#define M_ASN1_I2D_put_SEQ(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ 457 V_ASN1_CONTEXT_SPECIFIC,IS_SET)
270 V_ASN1_UNIVERSAL) 458#define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \
459 i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET)
460#define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\
461 V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE)
462
463#define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\
464 V_ASN1_UNIVERSAL,IS_SEQUENCE)
465
466#define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \
467 i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \
468 IS_SEQUENCE)
469
470#define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \
471 if ((a != NULL) && (sk_num(a) != 0)) \
472 M_ASN1_I2D_put_SEQUENCE(a,f);
271 473
272#define M_ASN1_I2D_put_SEQ_opt(a,f) \ 474#define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \
273 if ((a != NULL) && (sk_num(a) != 0)) \ 475 if ((a != NULL) && (sk_num(a) != 0)) \
274 M_ASN1_I2D_put_SEQ(a,f); 476 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
477 IS_SET); }
478
479#define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \
480 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
481 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
482 V_ASN1_CONTEXT_SPECIFIC, \
483 IS_SET); }
275 484
276#define M_ASN1_I2D_put_IMP_set_opt(a,f,x) \ 485#define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \
277 if ((a != NULL) && (sk_num(a) != 0)) \ 486 if ((a != NULL) && (sk_num(a) != 0)) \
278 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC); } 487 { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \
488 IS_SEQUENCE); }
489
490#define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \
491 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
492 { i2d_ASN1_SET_OF_##type(a,&p,f,x, \
493 V_ASN1_CONTEXT_SPECIFIC, \
494 IS_SEQUENCE); }
279 495
280#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ 496#define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \
281 if (a != NULL) \ 497 if (a != NULL) \
@@ -284,11 +500,26 @@ err:\
284 f(a,&p); \ 500 f(a,&p); \
285 } 501 }
286 502
287#define M_ASN1_I2D_put_EXP_set_opt(a,f,mtag,tag,v) \ 503#define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \
288 if ((a != NULL) && (sk_num(a) != 0)) \ 504 if ((a != NULL) && (sk_num(a) != 0)) \
289 { \ 505 { \
290 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ 506 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
291 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL); \ 507 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \
508 }
509
510#define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \
511 if ((a != NULL) && (sk_num(a) != 0)) \
512 { \
513 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
514 i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \
515 }
516
517#define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \
518 if ((a != NULL) && (sk_##type##_num(a) != 0)) \
519 { \
520 ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \
521 i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \
522 IS_SEQUENCE); \
292 } 523 }
293 524
294#define M_ASN1_I2D_seq_total() \ 525#define M_ASN1_I2D_seq_total() \
@@ -306,14 +537,8 @@ err:\
306#define M_ASN1_I2D_finish() *pp=p; \ 537#define M_ASN1_I2D_finish() *pp=p; \
307 return(r); 538 return(r);
308 539
309#ifndef NOPROTO
310int asn1_GetSequence(ASN1_CTX *c, long *length); 540int asn1_GetSequence(ASN1_CTX *c, long *length);
311void asn1_add_error(unsigned char *address,int offset); 541void asn1_add_error(unsigned char *address,int offset);
312#else
313int asn1_GetSequence();
314void asn1_add_error();
315#endif
316
317#ifdef __cplusplus 542#ifdef __cplusplus
318} 543}
319#endif 544#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/asn1.h>
64 64
65#ifndef NOPROTO
66static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, 65static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed,
67 int indent); 66 int indent);
68static int asn1_parse2(BIO *bp, unsigned char **pp, long length, 67static int asn1_parse2(BIO *bp, unsigned char **pp, long length,
69 int offset, int depth, int indent); 68 int offset, int depth, int indent);
70#else 69static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
71static int asn1_print_info(); 70 int indent)
72static int asn1_parse2();
73#endif
74
75static int asn1_print_info(bp, tag, xclass, constructed,indent)
76BIO *bp;
77int tag;
78int xclass;
79int constructed;
80int indent;
81 { 71 {
82 static char *fmt="%-18s"; 72 static const char fmt[]="%-18s";
83 static char *fmt2="%2d %-15s"; 73 static const char fmt2[]="%2d %-15s";
84 char *p,str[128],*p2=NULL; 74 char str[128];
75 const char *p,*p2=NULL;
85 76
86 if (constructed & V_ASN1_CONSTRUCTED) 77 if (constructed & V_ASN1_CONSTRUCTED)
87 p="cons: "; 78 p="cons: ";
@@ -108,6 +99,8 @@ int indent;
108 p="BOOLEAN"; 99 p="BOOLEAN";
109 else if (tag == V_ASN1_INTEGER) 100 else if (tag == V_ASN1_INTEGER)
110 p="INTEGER"; 101 p="INTEGER";
102 else if (tag == V_ASN1_ENUMERATED)
103 p="ENUMERATED";
111 else if (tag == V_ASN1_BIT_STRING) 104 else if (tag == V_ASN1_BIT_STRING)
112 p="BIT STRING"; 105 p="BIT STRING";
113 else if (tag == V_ASN1_OCTET_STRING) 106 else if (tag == V_ASN1_OCTET_STRING)
@@ -138,8 +131,8 @@ int indent;
138 p="GENERALIZEDTIME"; 131 p="GENERALIZEDTIME";
139 else if (tag == V_ASN1_GRAPHICSTRING) 132 else if (tag == V_ASN1_GRAPHICSTRING)
140 p="GRAPHICSTRING"; 133 p="GRAPHICSTRING";
141 else if (tag == V_ASN1_ISO64STRING) 134 else if (tag == V_ASN1_VISIBLESTRING)
142 p="ISO64STRING"; 135 p="VISIBLESTRING";
143 else if (tag == V_ASN1_GENERALSTRING) 136 else if (tag == V_ASN1_GENERALSTRING)
144 p="GENERALSTRING"; 137 p="GENERALSTRING";
145 else if (tag == V_ASN1_UNIVERSALSTRING) 138 else if (tag == V_ASN1_UNIVERSALSTRING)
@@ -162,22 +155,13 @@ err:
162 return(0); 155 return(0);
163 } 156 }
164 157
165int ASN1_parse(bp, pp, len, indent) 158int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent)
166BIO *bp;
167unsigned char *pp;
168long len;
169int indent;
170 { 159 {
171 return(asn1_parse2(bp,&pp,len,0,0,indent)); 160 return(asn1_parse2(bp,&pp,len,0,0,indent));
172 } 161 }
173 162
174static int asn1_parse2(bp, pp, length, offset, depth, indent) 163static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
175BIO *bp; 164 int depth, int indent)
176unsigned char **pp;
177long length;
178int offset;
179int depth;
180int indent;
181 { 165 {
182 unsigned char *p,*ep,*tot,*op,*opp; 166 unsigned char *p,*ep,*tot,*op,*opp;
183 long len; 167 long len;
@@ -266,7 +250,9 @@ int indent;
266 if ( (tag == V_ASN1_PRINTABLESTRING) || 250 if ( (tag == V_ASN1_PRINTABLESTRING) ||
267 (tag == V_ASN1_T61STRING) || 251 (tag == V_ASN1_T61STRING) ||
268 (tag == V_ASN1_IA5STRING) || 252 (tag == V_ASN1_IA5STRING) ||
269 (tag == V_ASN1_UTCTIME)) 253 (tag == V_ASN1_VISIBLESTRING) ||
254 (tag == V_ASN1_UTCTIME) ||
255 (tag == V_ASN1_GENERALIZEDTIME))
270 { 256 {
271 if (BIO_write(bp,":",1) <= 0) goto end; 257 if (BIO_write(bp,":",1) <= 0) goto end;
272 if ((len > 0) && 258 if ((len > 0) &&
@@ -370,6 +356,38 @@ int indent;
370 } 356 }
371 ASN1_INTEGER_free(bs); 357 ASN1_INTEGER_free(bs);
372 } 358 }
359 else if (tag == V_ASN1_ENUMERATED)
360 {
361 ASN1_ENUMERATED *bs;
362 int i;
363
364 opp=op;
365 bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl);
366 if (bs != NULL)
367 {
368 if (BIO_write(bp,":",1) <= 0) goto end;
369 if (bs->type == V_ASN1_NEG_ENUMERATED)
370 if (BIO_write(bp,"-",1) <= 0)
371 goto end;
372 for (i=0; i<bs->length; i++)
373 {
374 if (BIO_printf(bp,"%02X",
375 bs->data[i]) <= 0)
376 goto end;
377 }
378 if (bs->length == 0)
379 {
380 if (BIO_write(bp,"00",2) <= 0)
381 goto end;
382 }
383 }
384 else
385 {
386 if (BIO_write(bp,"BAD ENUMERATED",11) <= 0)
387 goto end;
388 }
389 ASN1_ENUMERATED_free(bs);
390 }
373 391
374 if (!nl) 392 if (!nl)
375 { 393 {
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 @@
1/* asn_pack.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62
63/* ASN1 packing and unpacking functions */
64
65/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
66
67STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
68 void (*free_func)())
69{
70 STACK *sk;
71 unsigned char *pbuf;
72 pbuf = buf;
73 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
74 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
75 ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR);
76 return sk;
77}
78
79/* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a
80 * Malloc'ed buffer
81 */
82
83unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
84 int *len)
85{
86 int safelen;
87 unsigned char *safe, *p;
88 if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE,
89 V_ASN1_UNIVERSAL, IS_SEQUENCE))) {
90 ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR);
91 return NULL;
92 }
93 if (!(safe = Malloc (safelen))) {
94 ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE);
95 return NULL;
96 }
97 p = safe;
98 i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL,
99 IS_SEQUENCE);
100 if (len) *len = safelen;
101 if (buf) *buf = safe;
102 return safe;
103}
104
105/* Extract an ASN1 object from an ASN1_STRING */
106
107void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)())
108{
109 unsigned char *p;
110 char *ret;
111
112 p = oct->data;
113 if(!(ret = d2i(NULL, &p, oct->length)))
114 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
115 return ret;
116}
117
118/* Pack an ASN1 object into an ASN1_STRING */
119
120ASN1_STRING *ASN1_pack_string (void *obj, int (*i2d)(), ASN1_STRING **oct)
121{
122 unsigned char *p;
123 ASN1_STRING *octmp;
124
125 if (!oct || !*oct) {
126 if (!(octmp = ASN1_STRING_new ())) {
127 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
128 return NULL;
129 }
130 if (oct) *oct = octmp;
131 } else octmp = *oct;
132
133 if (!(octmp->length = i2d(obj, NULL))) {
134 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
135 return NULL;
136 }
137 if (!(p = Malloc (octmp->length))) {
138 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
139 return NULL;
140 }
141 octmp->data = p;
142 i2d (obj, &p);
143 return octmp;
144}
145
diff --git a/src/lib/libcrypto/asn1/d2i_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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DH
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "dh.h" 63#include <openssl/dh.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "asn1_mac.h" 65#include <openssl/asn1_mac.h>
65 66
66/* 67DH *d2i_DHparams(DH **a, unsigned char **pp, long length)
67 * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_I2D_DHPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
69 */
70
71DH *d2i_DHparams(a,pp,length)
72DH **a;
73unsigned char **pp;
74long length;
75 { 68 {
76 int i=ASN1_R_ERROR_STACK; 69 int i=ERR_R_NESTED_ASN1_ERROR;
77 ASN1_INTEGER *bs=NULL; 70 ASN1_INTEGER *bs=NULL;
78 long v=0; 71 long v=0;
79 M_ASN1_D2I_vars(a,DH *,DH_new); 72 M_ASN1_D2I_vars(a,DH *,DH_new);
@@ -105,4 +98,4 @@ err:
105 if (bs != NULL) ASN1_BIT_STRING_free(bs); 98 if (bs != NULL) ASN1_BIT_STRING_free(bs);
106 return(NULL); 99 return(NULL);
107 } 100 }
108 101#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "dsa.h" 63#include <openssl/dsa.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "asn1_mac.h" 65#include <openssl/asn1_mac.h>
65 66
66/* 67#ifdef NEG_PUBKEY_BUG
67 * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH); 68#define d2i_ASN1_INTEGER d2i_ASN1_UINTEGER
68 * ASN1err(ASN1_F_I2D_DSAPARAMS,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); 69#endif
69 */
70 70
71DSA *d2i_DSAparams(a,pp,length) 71DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)
72DSA **a;
73unsigned char **pp;
74long length;
75 { 72 {
76 int i=ASN1_R_ERROR_STACK; 73 int i=ERR_R_NESTED_ASN1_ERROR;
77 ASN1_INTEGER *bs=NULL; 74 ASN1_INTEGER *bs=NULL;
78 M_ASN1_D2I_vars(a,DSA *,DSA_new); 75 M_ASN1_D2I_vars(a,DSA *,DSA_new);
79 76
@@ -98,4 +95,4 @@ err:
98 if (bs != NULL) ASN1_BIT_STRING_free(bs); 95 if (bs != NULL) ASN1_BIT_STRING_free(bs);
99 return(NULL); 96 return(NULL);
100 } 97 }
101 98#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/asn1.h>
65 65
66EVP_PKEY *d2i_PrivateKey(type,a,pp,length) 66EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
67int type; 67 long length)
68EVP_PKEY **a;
69unsigned char **pp;
70long length;
71 { 68 {
72 EVP_PKEY *ret; 69 EVP_PKEY *ret;
73 70
@@ -106,7 +103,7 @@ long length;
106 default: 103 default:
107 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); 104 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
108 goto err; 105 goto err;
109 break; 106 /* break; */
110 } 107 }
111 if (a != NULL) (*a)=ret; 108 if (a != NULL) (*a)=ret;
112 return(ret); 109 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/asn1.h>
65 65
66EVP_PKEY *d2i_PublicKey(type,a,pp,length) 66EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
67int type; 67 long length)
68EVP_PKEY **a;
69unsigned char **pp;
70long length;
71 { 68 {
72 EVP_PKEY *ret; 69 EVP_PKEY *ret;
73 70
@@ -106,7 +103,7 @@ long length;
106 default: 103 default:
107 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); 104 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
108 goto err; 105 goto err;
109 break; 106 /* break; */
110 } 107 }
111 if (a != NULL) (*a)=ret; 108 if (a != NULL) (*a)=ret;
112 return(ret); 109 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "rsa.h" 63#include <openssl/rsa.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "asn1_mac.h" 65#include <openssl/asn1_mac.h>
65
66/*
67 * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
69 * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_PARSING);
70 */
71 66
72static ASN1_METHOD method={ 67static ASN1_METHOD method={
73 (int (*)()) i2d_RSAPrivateKey, 68 (int (*)()) i2d_RSAPrivateKey,
@@ -75,15 +70,12 @@ static ASN1_METHOD method={
75 (char *(*)())RSA_new, 70 (char *(*)())RSA_new,
76 (void (*)()) RSA_free}; 71 (void (*)()) RSA_free};
77 72
78ASN1_METHOD *RSAPrivateKey_asn1_meth() 73ASN1_METHOD *RSAPrivateKey_asn1_meth(void)
79 { 74 {
80 return(&method); 75 return(&method);
81 } 76 }
82 77
83RSA *d2i_RSAPrivateKey(a,pp,length) 78RSA *d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length)
84RSA **a;
85unsigned char **pp;
86long length;
87 { 79 {
88 int i=ASN1_R_PARSING; 80 int i=ASN1_R_PARSING;
89 ASN1_INTEGER *bs=NULL; 81 ASN1_INTEGER *bs=NULL;
@@ -126,4 +118,4 @@ err:
126 if (bs != NULL) ASN1_INTEGER_free(bs); 118 if (bs != NULL) ASN1_INTEGER_free(bs);
127 return(NULL); 119 return(NULL);
128 } 120 }
129 121#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "rsa.h" 63#include <openssl/rsa.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "asn1_mac.h" 65#include <openssl/asn1_mac.h>
65 66
66/* 67#ifdef NEG_PUBKEY_BUG
67 * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); 68#define d2i_ASN1_INTEGER d2i_ASN1_UINTEGER
68 * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); 69#endif
69 */
70 70
71RSA *d2i_RSAPublicKey(a,pp,length) 71RSA *d2i_RSAPublicKey(RSA **a, unsigned char **pp, long length)
72RSA **a;
73unsigned char **pp;
74long length;
75 { 72 {
76 int i=ASN1_R_PARSING; 73 int i=ASN1_R_PARSING;
77 ASN1_INTEGER *bs=NULL; 74 ASN1_INTEGER *bs=NULL;
@@ -97,4 +94,4 @@ err:
97 if (bs != NULL) ASN1_INTEGER_free(bs); 94 if (bs != NULL) ASN1_INTEGER_free(bs);
98 return(NULL); 95 return(NULL);
99 } 96 }
100 97#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ 59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60 60
61#ifndef NO_DSA
61#include <stdio.h> 62#include <stdio.h>
62#include "cryptlib.h" 63#include "cryptlib.h"
63#include "bn.h" 64#include <openssl/bn.h>
64#include "dsa.h" 65#include <openssl/dsa.h>
65#include "objects.h" 66#include <openssl/objects.h>
66#include "asn1_mac.h" 67#include <openssl/asn1_mac.h>
67 68
68/* 69DSA *d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length)
69 * ASN1err(ASN1_F_D2I_DSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH);
70 * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
71 * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_PARSING);
72 */
73
74DSA *d2i_DSAPrivateKey(a,pp,length)
75DSA **a;
76unsigned char **pp;
77long length;
78 { 70 {
79 int i=ASN1_R_PARSING; 71 int i=ASN1_R_PARSING;
80 ASN1_INTEGER *bs=NULL; 72 ASN1_INTEGER *bs=NULL;
@@ -110,4 +102,4 @@ err:
110 if (bs != NULL) ASN1_INTEGER_free(bs); 102 if (bs != NULL) ASN1_INTEGER_free(bs);
111 return(NULL); 103 return(NULL);
112 } 104 }
113 105#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ 59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60 60
61#ifndef NO_DSA
61#include <stdio.h> 62#include <stdio.h>
62#include "cryptlib.h" 63#include "cryptlib.h"
63#include "bn.h" 64#include <openssl/bn.h>
64#include "dsa.h" 65#include <openssl/dsa.h>
65#include "objects.h" 66#include <openssl/objects.h>
66#include "asn1_mac.h" 67#include <openssl/asn1_mac.h>
67 68
68/* 69#ifdef NEG_PUBKEY_BUG
69 * ASN1err(ASN1_F_D2I_DSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH); 70#define d2i_ASN1_INTEGER d2i_ASN1_UINTEGER
70 * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE); 71#endif
71 */
72 72
73DSA *d2i_DSAPublicKey(a,pp,length) 73DSA *d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length)
74DSA **a;
75unsigned char **pp;
76long length;
77 { 74 {
78 int i=ASN1_R_PARSING; 75 int i=ASN1_R_PARSING;
79 ASN1_INTEGER *bs=NULL; 76 ASN1_INTEGER *bs=NULL;
@@ -121,4 +118,4 @@ err:
121 if (bs != NULL) ASN1_INTEGER_free(bs); 118 if (bs != NULL) ASN1_INTEGER_free(bs);
122 return(NULL); 119 return(NULL);
123 } 120 }
124 121#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63 63
64int ASN1_TYPE_set_octetstring(a,data,len) 64int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len)
65ASN1_TYPE *a;
66unsigned char *data;
67int len;
68 { 65 {
69 ASN1_STRING *os; 66 ASN1_STRING *os;
70 67
71 if ((os=ASN1_OCTET_STRING_new()) == NULL) return(0); 68 if ((os=ASN1_OCTET_STRING_new()) == NULL) return(0);
72 if (!ASN1_OCTET_STRING_set(os,data,len)) return(0); 69 if (!ASN1_OCTET_STRING_set(os,data,len)) return(0);
73 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,(char *)os); 70 ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os);
74 return(1); 71 return(1);
75 } 72 }
76 73
77int ASN1_TYPE_get_octetstring(a,data,max_len) 74/* int max_len: for returned value */
78ASN1_TYPE *a; 75int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data,
79unsigned char *data; 76 int max_len)
80int max_len; /* for returned value */
81 { 77 {
82 int ret,num; 78 int ret,num;
83 unsigned char *p; 79 unsigned char *p;
@@ -97,11 +93,8 @@ int max_len; /* for returned value */
97 return(ret); 93 return(ret);
98 } 94 }
99 95
100int ASN1_TYPE_set_int_octetstring(a,num,data,len) 96int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data,
101ASN1_TYPE *a; 97 int len)
102long num;
103unsigned char *data;
104int len;
105 { 98 {
106 int n,size; 99 int n,size;
107 ASN1_OCTET_STRING os,*osp; 100 ASN1_OCTET_STRING os,*osp;
@@ -131,16 +124,15 @@ int len;
131 i2d_ASN1_INTEGER(&in,&p); 124 i2d_ASN1_INTEGER(&in,&p);
132 M_i2d_ASN1_OCTET_STRING(&os,&p); 125 M_i2d_ASN1_OCTET_STRING(&os,&p);
133 126
134 ASN1_TYPE_set(a,V_ASN1_SEQUENCE,(char *)osp); 127 ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp);
135 return(1); 128 return(1);
136 } 129 }
137 130
138/* we return the actual length... */ 131/* we return the actual length..., num may be missing, in which
139int ASN1_TYPE_get_int_octetstring(a,num,data,max_len) 132 * case, set it to zero */
140ASN1_TYPE *a; 133/* int max_len: for returned value */
141long *num; 134int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
142unsigned char *data; 135 int max_len)
143int max_len; /* for returned value */
144 { 136 {
145 int ret= -1,n; 137 int ret= -1,n;
146 ASN1_INTEGER *ai=NULL; 138 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include "asn1.h" 59#include <openssl/asn1.h>
60#include "err.h" 60#include <openssl/err.h>
61 61
62main() 62main()
63 { 63 {
diff --git a/src/lib/libcrypto/bn/bn_sub.c b/src/lib/libcrypto/asn1/f_enum.c
index bba80f8afb..3bcceecdb8 100644
--- a/src/lib/libcrypto/bn/bn_sub.c
+++ b/src/lib/libcrypto/asn1/f_enum.c
@@ -1,4 +1,4 @@
1/* crypto/bn/bn_sub.c */ 1/* crypto/asn1/f_enum.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -58,123 +58,150 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
62 63
63/* unsigned subtraction of b from a, a must be larger than b. */ 64/* Based on a_int.c: equivalent ENUMERATED functions */
64void bn_qsub(r, a, b) 65
65BIGNUM *r; 66int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a)
66BIGNUM *a;
67BIGNUM *b;
68 { 67 {
69 int max,min; 68 int i,n=0;
70 register BN_ULONG t1,t2,*ap,*bp,*rp; 69 static const char *h="0123456789ABCDEF";
71 int i,carry; 70 char buf[2];
72#if defined(IRIX_CC_BUG) && !defined(LINT)
73 int dummy;
74#endif
75 71
76 max=a->top; 72 if (a == NULL) return(0);
77 min=b->top;
78 ap=a->d;
79 bp=b->d;
80 rp=r->d;
81 73
82 carry=0; 74 if (a->length == 0)
83 for (i=0; i<min; i++)
84 { 75 {
85 t1= *(ap++); 76 if (BIO_write(bp,"00",2) != 2) goto err;
86 t2= *(bp++); 77 n=2;
87 if (carry)
88 {
89 carry=(t1 <= t2);
90 t1=(t1-t2-1)&BN_MASK2;
91 }
92 else
93 {
94 carry=(t1 < t2);
95 t1=(t1-t2)&BN_MASK2;
96 }
97#if defined(IRIX_CC_BUG) && !defined(LINT)
98 dummy=t1;
99#endif
100 *(rp++)=t1&BN_MASK2;
101 } 78 }
102 if (carry) /* subtracted */ 79 else
103 { 80 {
104 while (i < max) 81 for (i=0; i<a->length; i++)
105 { 82 {
106 i++; 83 if ((i != 0) && (i%35 == 0))
107 t1= *(ap++); 84 {
108 t2=(t1-1)&BN_MASK2; 85 if (BIO_write(bp,"\\\n",2) != 2) goto err;
109 *(rp++)=t2; 86 n+=2;
110 if (t1 > t2) break; 87 }
88 buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f];
89 buf[1]=h[((unsigned char)a->data[i] )&0x0f];
90 if (BIO_write(bp,buf,2) != 2) goto err;
91 n+=2;
111 } 92 }
112 } 93 }
113#if 0 94 return(n);
114 memcpy(rp,ap,sizeof(*rp)*(max-i)); 95err:
115#else 96 return(-1);
116 for (; i<max; i++)
117 *(rp++)= *(ap++);
118#endif
119
120 r->top=max;
121 bn_fix_top(r);
122 } 97 }
123 98
124int BN_sub(r, a, b) 99int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
125BIGNUM *r;
126BIGNUM *a;
127BIGNUM *b;
128 { 100 {
129 int max,i; 101 int ret=0;
130 int add=0,neg=0; 102 int i,j,k,m,n,again,bufsize;
131 BIGNUM *tmp; 103 unsigned char *s=NULL,*sp;
104 unsigned char *bufp;
105 int num=0,slen=0,first=1;
132 106
133 /* a - b a-b 107 bs->type=V_ASN1_ENUMERATED;
134 * a - -b a+b
135 * -a - b -(a+b)
136 * -a - -b b-a
137 */
138 if (a->neg)
139 {
140 if (b->neg)
141 { tmp=a; a=b; b=tmp; }
142 else
143 { add=1; neg=1; }
144 }
145 else
146 {
147 if (b->neg) { add=1; neg=0; }
148 }
149 108
150 if (add) 109 bufsize=BIO_gets(bp,buf,size);
110 for (;;)
151 { 111 {
152 /* As a fast max size, do a a->top | b->top */ 112 if (bufsize < 1) goto err_sl;
153 i=(a->top | b->top)+1; 113 i=bufsize;
154 if (bn_wexpand(r,i) == NULL) 114 if (buf[i-1] == '\n') buf[--i]='\0';
155 return(0); 115 if (i == 0) goto err_sl;
156 if (i) 116 if (buf[i-1] == '\r') buf[--i]='\0';
157 bn_qadd(r,a,b); 117 if (i == 0) goto err_sl;
158 else 118 again=(buf[i-1] == '\\');
159 bn_qadd(r,b,a);
160 r->neg=neg;
161 return(1);
162 }
163 119
164 /* We are actually doing a - b :-) */ 120 for (j=0; j<i; j++)
121 {
122 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
123 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
124 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
125 {
126 i=j;
127 break;
128 }
129 }
130 buf[i]='\0';
131 /* We have now cleared all the crap off the end of the
132 * line */
133 if (i < 2) goto err_sl;
165 134
166 max=(a->top > b->top)?a->top:b->top; 135 bufp=(unsigned char *)buf;
167 if (bn_wexpand(r,max) == NULL) return(0); 136 if (first)
168 if (BN_ucmp(a,b) < 0) 137 {
169 { 138 first=0;
170 bn_qsub(r,b,a); 139 if ((bufp[0] == '0') && (buf[1] == '0'))
171 r->neg=1; 140 {
141 bufp+=2;
142 i-=2;
143 }
144 }
145 k=0;
146 i-=again;
147 if (i%2 != 0)
148 {
149 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS);
150 goto err;
151 }
152 i/=2;
153 if (num+i > slen)
154 {
155 if (s == NULL)
156 sp=(unsigned char *)Malloc(
157 (unsigned int)num+i*2);
158 else
159 sp=(unsigned char *)Realloc(s,
160 (unsigned int)num+i*2);
161 if (sp == NULL)
162 {
163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
164 if (s != NULL) Free((char *)s);
165 goto err;
166 }
167 s=sp;
168 slen=num+i*2;
169 }
170 for (j=0; j<i; j++,k+=2)
171 {
172 for (n=0; n<2; n++)
173 {
174 m=bufp[k+n];
175 if ((m >= '0') && (m <= '9'))
176 m-='0';
177 else if ((m >= 'a') && (m <= 'f'))
178 m=m-'a'+10;
179 else if ((m >= 'A') && (m <= 'F'))
180 m=m-'A'+10;
181 else
182 {
183 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS);
184 goto err;
185 }
186 s[num+j]<<=4;
187 s[num+j]|=m;
188 }
189 }
190 num+=i;
191 if (again)
192 bufsize=BIO_gets(bp,buf,size);
193 else
194 break;
172 } 195 }
173 else 196 bs->length=num;
197 bs->data=s;
198 ret=1;
199err:
200 if (0)
174 { 201 {
175 bn_qsub(r,a,b); 202err_sl:
176 r->neg=0; 203 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE);
177 } 204 }
178 return(1); 205 return(ret);
179 } 206 }
180 207
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "x509.h" 62#include <openssl/asn1.h>
63 63
64int i2a_ASN1_INTEGER(bp, a) 64int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)
65BIO *bp;
66ASN1_INTEGER *a;
67 { 65 {
68 int i,n=0; 66 int i,n=0;
69 static char *h="0123456789ABCDEF"; 67 static const char *h="0123456789ABCDEF";
70 char buf[2]; 68 char buf[2];
71 69
72 if (a == NULL) return(0); 70 if (a == NULL) return(0);
@@ -96,11 +94,7 @@ err:
96 return(-1); 94 return(-1);
97 } 95 }
98 96
99int a2i_ASN1_INTEGER(bp,bs,buf,size) 97int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
100BIO *bp;
101ASN1_INTEGER *bs;
102char *buf;
103int size;
104 { 98 {
105 int ret=0; 99 int ret=0;
106 int i,j,k,m,n,again,bufsize; 100 int i,j,k,m,n,again,bufsize;
@@ -123,9 +117,18 @@ int size;
123 117
124 for (j=0; j<i; j++) 118 for (j=0; j<i; j++)
125 { 119 {
120#ifndef CHARSET_EBCDIC
126 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || 121 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
127 ((buf[j] >= 'a') && (buf[j] <= 'f')) || 122 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
128 ((buf[j] >= 'A') && (buf[j] <= 'F')))) 123 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
124#else
125 /* This #ifdef is not strictly necessary, since
126 * the characters A...F a...f 0...9 are contiguous
127 * (yes, even in EBCDIC - but not the whole alphabet).
128 * Nevertheless, isxdigit() is faster.
129 */
130 if (!isxdigit(buf[j]))
131#endif
129 { 132 {
130 i=j; 133 i=j;
131 break; 134 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "x509.h" 62#include <openssl/asn1.h>
63 63
64int i2a_ASN1_STRING(bp, a, type) 64int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type)
65BIO *bp;
66ASN1_STRING *a;
67int type;
68 { 65 {
69 int i,n=0; 66 int i,n=0;
70 static char *h="0123456789ABCDEF"; 67 static const char *h="0123456789ABCDEF";
71 char buf[2]; 68 char buf[2];
72 69
73 if (a == NULL) return(0); 70 if (a == NULL) return(0);
@@ -97,11 +94,7 @@ err:
97 return(-1); 94 return(-1);
98 } 95 }
99 96
100int a2i_ASN1_STRING(bp,bs,buf,size) 97int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
101BIO *bp;
102ASN1_STRING *bs;
103char *buf;
104int size;
105 { 98 {
106 int ret=0; 99 int ret=0;
107 int i,j,k,m,n,again,bufsize; 100 int i,j,k,m,n,again,bufsize;
@@ -130,9 +123,18 @@ int size;
130 123
131 for (j=i-1; j>0; j--) 124 for (j=i-1; j>0; j--)
132 { 125 {
126#ifndef CHARSET_EBCDIC
133 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || 127 if (!( ((buf[j] >= '0') && (buf[j] <= '9')) ||
134 ((buf[j] >= 'a') && (buf[j] <= 'f')) || 128 ((buf[j] >= 'a') && (buf[j] <= 'f')) ||
135 ((buf[j] >= 'A') && (buf[j] <= 'F')))) 129 ((buf[j] >= 'A') && (buf[j] <= 'F'))))
130#else
131 /* This #ifdef is not strictly necessary, since
132 * the characters A...F a...f 0...9 are contiguous
133 * (yes, even in EBCDIC - but not the whole alphabet).
134 * Nevertheless, isxdigit() is faster.
135 */
136 if (!isxdigit(buf[j]))
137#endif
136 { 138 {
137 i=j; 139 i=j;
138 break; 140 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DH
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "asn1_mac.h" 63#include <openssl/asn1_mac.h>
63#include "dh.h" 64#include <openssl/dh.h>
64 65
65/* 66int i2d_DHparams(DH *a, unsigned char **pp)
66 * ASN1err(ASN1_F_D2I_DHPARAMS,ASN1_R_LENGTH_MISMATCH);
67 * ASN1err(ASN1_F_X509_DHPARAMS_NEW,ASN1_R_LENGTH_MISMATCH);
68 */
69
70int i2d_DHparams(a,pp)
71DH *a;
72unsigned char **pp;
73 { 67 {
74 BIGNUM *num[3]; 68 BIGNUM *num[3];
75 ASN1_INTEGER bs; 69 ASN1_INTEGER bs;
@@ -100,7 +94,12 @@ unsigned char **pp;
100 } 94 }
101 95
102 t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE); 96 t=ASN1_object_size(1,tot,V_ASN1_SEQUENCE);
103 if (pp == NULL) return(t); 97 if (pp == NULL)
98 {
99 if (num[2] != NULL)
100 BN_free(num[2]);
101 return(t);
102 }
104 103
105 p= *pp; 104 p= *pp;
106 ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); 105 ASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
@@ -126,3 +125,4 @@ err:
126 *pp=p; 125 *pp=p;
127 return(ret); 126 return(ret);
128 } 127 }
128#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "asn1_mac.h" 63#include <openssl/asn1_mac.h>
63#include "dsa.h" 64#include <openssl/dsa.h>
64 65
65/* 66int i2d_DSAparams(DSA *a, unsigned char **pp)
66 * ASN1err(ASN1_F_D2I_DSAPARAMS,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_DSAparams(a,pp)
70DSA *a;
71unsigned char **pp;
72 { 67 {
73 BIGNUM *num[3]; 68 BIGNUM *num[3];
74 ASN1_INTEGER bs; 69 ASN1_INTEGER bs;
@@ -118,4 +113,5 @@ err:
118 *pp=p; 113 *pp=p;
119 return(ret); 114 return(ret);
120 } 115 }
116#endif
121 117
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "objects.h" 63#include <openssl/objects.h>
64 64
65int i2d_PrivateKey(a,pp) 65int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
66EVP_PKEY *a;
67unsigned char **pp;
68 { 66 {
69#ifndef NO_RSA 67#ifndef NO_RSA
70 if (a->type == EVP_PKEY_RSA) 68 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "objects.h" 63#include <openssl/objects.h>
64 64
65int i2d_PublicKey(a,pp) 65int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
66EVP_PKEY *a;
67unsigned char **pp;
68 { 66 {
69 switch (a->type) 67 switch (a->type)
70 { 68 {
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "rsa.h" 63#include <openssl/rsa.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "asn1_mac.h" 65#include <openssl/asn1_mac.h>
65 66
66/* 67int i2d_RSAPrivateKey(RSA *a, unsigned char **pp)
67 * ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_I2D_RSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
69 */
70
71int i2d_RSAPrivateKey(a,pp)
72RSA *a;
73unsigned char **pp;
74 { 68 {
75 BIGNUM *num[9]; 69 BIGNUM *num[9];
76 unsigned char data[1]; 70 unsigned char data[1];
@@ -129,4 +123,5 @@ unsigned char **pp;
129 *pp=p; 123 *pp=p;
130 return(t); 124 return(t);
131 } 125 }
126#endif
132 127
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "rsa.h" 63#include <openssl/rsa.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "asn1_mac.h" 65#include <openssl/asn1_mac.h>
65 66
66/* 67int i2d_RSAPublicKey(RSA *a, unsigned char **pp)
67 * ASN1err(ASN1_F_D2I_RSAPUBLICKEY,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_I2D_RSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
69 */
70
71int i2d_RSAPublicKey(a,pp)
72RSA *a;
73unsigned char **pp;
74 { 68 {
75 BIGNUM *num[2]; 69 BIGNUM *num[2];
76 ASN1_INTEGER bs; 70 ASN1_INTEGER bs;
@@ -115,4 +109,4 @@ unsigned char **pp;
115 *pp=p; 109 *pp=p;
116 return(t); 110 return(t);
117 } 111 }
118 112#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "dsa.h" 63#include <openssl/dsa.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "asn1_mac.h" 65#include <openssl/asn1_mac.h>
65 66
66/* 67int i2d_DSAPrivateKey(DSA *a, unsigned char **pp)
67 * ASN1err(ASN1_F_I2D_DSAPRIVATEKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
68 */
69
70int i2d_DSAPrivateKey(a,pp)
71DSA *a;
72unsigned char **pp;
73 { 68 {
74 BIGNUM *num[6]; 69 BIGNUM *num[6];
75 unsigned char data[1]; 70 unsigned char data[1];
@@ -125,4 +120,4 @@ unsigned char **pp;
125 *pp=p; 120 *pp=p;
126 return(t); 121 return(t);
127 } 122 }
128 123#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn.h" 62#include <openssl/bn.h>
62#include "dsa.h" 63#include <openssl/dsa.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "asn1_mac.h" 65#include <openssl/asn1_mac.h>
65 66
66/* 67int i2d_DSAPublicKey(DSA *a, unsigned char **pp)
67 * ASN1err(ASN1_F_I2D_DSAPUBLICKEY,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
68 */
69
70int i2d_DSAPublicKey(a,pp)
71DSA *a;
72unsigned char **pp;
73 { 68 {
74 BIGNUM *num[4]; 69 BIGNUM *num[4];
75 ASN1_INTEGER bs; 70 ASN1_INTEGER bs;
@@ -128,6 +123,7 @@ unsigned char **pp;
128 } 123 }
129 Free((char *)bs.data); 124 Free((char *)bs.data);
130 *pp=p; 125 *pp=p;
131 return(t); 126 if(all) return(t);
127 else return(tot);
132 } 128 }
133 129#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "rsa.h" 62#include <openssl/rsa.h>
62#include "objects.h" 63#include <openssl/objects.h>
63#include "asn1_mac.h" 64#include <openssl/asn1_mac.h>
64#include "evp.h" 65#include <openssl/evp.h>
65#include "x509.h" 66#include <openssl/x509.h>
66 67
67 68
68#ifndef NO_RC4 69#ifndef NO_RC4
@@ -74,28 +75,12 @@ typedef struct netscape_pkey_st
74 ASN1_OCTET_STRING *private_key; 75 ASN1_OCTET_STRING *private_key;
75 } NETSCAPE_PKEY; 76 } NETSCAPE_PKEY;
76 77
77/*
78 * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_LENGTH_MISMATCH);
79 * ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR);
80 * ASN1err(ASN1_F_D2I_NETSCAPE_PKEY,ASN1_R_DECODING_ERROR);
81 * ASN1err(ASN1_F_NETSCAPE_PKEY_NEW,ASN1_R_DECODING_ERROR);
82 */
83#ifndef NOPROTO
84static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp); 78static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp);
85static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a,unsigned char **pp, long length); 79static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a,unsigned char **pp, long length);
86static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void); 80static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void);
87static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *); 81static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *);
88#else
89static int i2d_NETSCAPE_PKEY();
90static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY();
91static NETSCAPE_PKEY *NETSCAPE_PKEY_new();
92static void NETSCAPE_PKEY_free();
93#endif
94 82
95int i2d_Netscape_RSA(a,pp,cb) 83int i2d_Netscape_RSA(RSA *a, unsigned char **pp, int (*cb)())
96RSA *a;
97unsigned char **pp;
98int (*cb)();
99 { 84 {
100 int i,j,l[6]; 85 int i,j,l[6];
101 NETSCAPE_PKEY *pkey; 86 NETSCAPE_PKEY *pkey;
@@ -138,7 +123,9 @@ int (*cb)();
138 l[2]=i2d_X509_ALGOR(alg,NULL); 123 l[2]=i2d_X509_ALGOR(alg,NULL);
139 l[3]=ASN1_object_size(1,l[2]+l[1],V_ASN1_SEQUENCE); 124 l[3]=ASN1_object_size(1,l[2]+l[1],V_ASN1_SEQUENCE);
140 125
126#ifndef CONST_STRICT
141 os.data=(unsigned char *)"private-key"; 127 os.data=(unsigned char *)"private-key";
128#endif
142 os.length=11; 129 os.length=11;
143 l[4]=i2d_ASN1_OCTET_STRING(&os,NULL); 130 l[4]=i2d_ASN1_OCTET_STRING(&os,NULL);
144 131
@@ -195,18 +182,14 @@ int (*cb)();
195 i2d_ASN1_OCTET_STRING(&os2,&p); 182 i2d_ASN1_OCTET_STRING(&os2,&p);
196 ret=l[5]; 183 ret=l[5];
197err: 184err:
198 if (os2.data != NULL) Free((char *)os2.data); 185 if (os2.data != NULL) Free(os2.data);
199 if (alg != NULL) X509_ALGOR_free(alg); 186 if (alg != NULL) X509_ALGOR_free(alg);
200 if (pkey != NULL) NETSCAPE_PKEY_free(pkey); 187 if (pkey != NULL) NETSCAPE_PKEY_free(pkey);
201 r=r; 188 r=r;
202 return(ret); 189 return(ret);
203 } 190 }
204 191
205RSA *d2i_Netscape_RSA(a,pp,length,cb) 192RSA *d2i_Netscape_RSA(RSA **a, unsigned char **pp, long length, int (*cb)())
206RSA **a;
207unsigned char **pp;
208long length;
209int (*cb)();
210 { 193 {
211 RSA *ret=NULL; 194 RSA *ret=NULL;
212 ASN1_OCTET_STRING *os=NULL; 195 ASN1_OCTET_STRING *os=NULL;
@@ -233,11 +216,8 @@ int (*cb)();
233 M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA); 216 M_ASN1_D2I_Finish(a,RSA_free,ASN1_F_D2I_NETSCAPE_RSA);
234 } 217 }
235 218
236RSA *d2i_Netscape_RSA_2(a,pp,length,cb) 219RSA *d2i_Netscape_RSA_2(RSA **a, unsigned char **pp, long length,
237RSA **a; 220 int (*cb)())
238unsigned char **pp;
239long length;
240int (*cb)();
241 { 221 {
242 NETSCAPE_PKEY *pkey=NULL; 222 NETSCAPE_PKEY *pkey=NULL;
243 RSA *ret=NULL; 223 RSA *ret=NULL;
@@ -249,7 +229,7 @@ int (*cb)();
249 ASN1_OCTET_STRING *os=NULL; 229 ASN1_OCTET_STRING *os=NULL;
250 ASN1_CTX c; 230 ASN1_CTX c;
251 231
252 c.error=ASN1_R_ERROR_STACK; 232 c.error=ERR_R_NESTED_ASN1_ERROR;
253 c.pp=pp; 233 c.pp=pp;
254 234
255 M_ASN1_D2I_Init(); 235 M_ASN1_D2I_Init();
@@ -304,9 +284,7 @@ err:
304 return(ret); 284 return(ret);
305 } 285 }
306 286
307static int i2d_NETSCAPE_PKEY(a,pp) 287static int i2d_NETSCAPE_PKEY(NETSCAPE_PKEY *a, unsigned char **pp)
308NETSCAPE_PKEY *a;
309unsigned char **pp;
310 { 288 {
311 M_ASN1_I2D_vars(a); 289 M_ASN1_I2D_vars(a);
312 290
@@ -324,10 +302,8 @@ unsigned char **pp;
324 M_ASN1_I2D_finish(); 302 M_ASN1_I2D_finish();
325 } 303 }
326 304
327static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(a,pp,length) 305static NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a, unsigned char **pp,
328NETSCAPE_PKEY **a; 306 long length)
329unsigned char **pp;
330long length;
331 { 307 {
332 M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new); 308 M_ASN1_D2I_vars(a,NETSCAPE_PKEY *,NETSCAPE_PKEY_new);
333 309
@@ -339,9 +315,10 @@ long length;
339 M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY); 315 M_ASN1_D2I_Finish(a,NETSCAPE_PKEY_free,ASN1_F_D2I_NETSCAPE_PKEY);
340 } 316 }
341 317
342static NETSCAPE_PKEY *NETSCAPE_PKEY_new() 318static NETSCAPE_PKEY *NETSCAPE_PKEY_new(void)
343 { 319 {
344 NETSCAPE_PKEY *ret=NULL; 320 NETSCAPE_PKEY *ret=NULL;
321 ASN1_CTX c;
345 322
346 M_ASN1_New_Malloc(ret,NETSCAPE_PKEY); 323 M_ASN1_New_Malloc(ret,NETSCAPE_PKEY);
347 M_ASN1_New(ret->version,ASN1_INTEGER_new); 324 M_ASN1_New(ret->version,ASN1_INTEGER_new);
@@ -351,8 +328,7 @@ static NETSCAPE_PKEY *NETSCAPE_PKEY_new()
351 M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW); 328 M_ASN1_New_Error(ASN1_F_NETSCAPE_PKEY_NEW);
352 } 329 }
353 330
354static void NETSCAPE_PKEY_free(a) 331static void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a)
355NETSCAPE_PKEY *a;
356 { 332 {
357 if (a == NULL) return; 333 if (a == NULL) return;
358 ASN1_INTEGER_free(a->version); 334 ASN1_INTEGER_free(a->version);
@@ -362,4 +338,4 @@ NETSCAPE_PKEY *a;
362 } 338 }
363 339
364#endif /* NO_RC4 */ 340#endif /* NO_RC4 */
365 341#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 @@
1/* nsseq.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/asn1_mac.h>
62#include <openssl/err.h>
63#include <openssl/x509.h>
64#include <openssl/objects.h>
65
66/* Netscape certificate sequence structure */
67
68int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp)
69{
70 int v = 0;
71 M_ASN1_I2D_vars(a);
72 M_ASN1_I2D_len (a->type, i2d_ASN1_OBJECT);
73 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
74 V_ASN1_SEQUENCE,v);
75
76 M_ASN1_I2D_seq_total();
77
78 M_ASN1_I2D_put (a->type, i2d_ASN1_OBJECT);
79 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509,a->certs,i2d_X509,0,
80 V_ASN1_SEQUENCE,v);
81
82 M_ASN1_I2D_finish();
83}
84
85NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void)
86{
87 NETSCAPE_CERT_SEQUENCE *ret=NULL;
88 ASN1_CTX c;
89 M_ASN1_New_Malloc(ret, NETSCAPE_CERT_SEQUENCE);
90 /* Note hardcoded object type */
91 ret->type = OBJ_nid2obj(NID_netscape_cert_sequence);
92 ret->certs = NULL;
93 return (ret);
94 M_ASN1_New_Error(ASN1_F_NETSCAPE_CERT_SEQUENCE_NEW);
95}
96
97NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a,
98 unsigned char **pp, long length)
99{
100 M_ASN1_D2I_vars(a,NETSCAPE_CERT_SEQUENCE *,
101 NETSCAPE_CERT_SEQUENCE_new);
102 M_ASN1_D2I_Init();
103 M_ASN1_D2I_start_sequence();
104 M_ASN1_D2I_get (ret->type, d2i_ASN1_OBJECT);
105 M_ASN1_D2I_get_EXP_set_opt_type(X509,ret->certs,d2i_X509,X509_free,0,
106 V_ASN1_SEQUENCE);
107 M_ASN1_D2I_Finish(a, NETSCAPE_CERT_SEQUENCE_free,
108 ASN1_F_D2I_NETSCAPE_CERT_SEQUENCE);
109}
110
111void NETSCAPE_CERT_SEQUENCE_free (NETSCAPE_CERT_SEQUENCE *a)
112{
113 if (a == NULL) return;
114 ASN1_OBJECT_free(a->type);
115 if(a->certs)
116 sk_X509_pop_free(a->certs, X509_free);
117 Free (a);
118}
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
new file mode 100644
index 0000000000..b831836e7b
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p5_pbe.c
@@ -0,0 +1,156 @@
1/* p5_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 password based encryption structure */
66
67int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp)
68{
69 M_ASN1_I2D_vars(a);
70 M_ASN1_I2D_len (a->salt, i2d_ASN1_OCTET_STRING);
71 M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);
72
73 M_ASN1_I2D_seq_total ();
74
75 M_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING);
76 M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
77 M_ASN1_I2D_finish();
78}
79
80PBEPARAM *PBEPARAM_new(void)
81{
82 PBEPARAM *ret=NULL;
83 ASN1_CTX c;
84 M_ASN1_New_Malloc(ret, PBEPARAM);
85 M_ASN1_New(ret->iter,ASN1_INTEGER_new);
86 M_ASN1_New(ret->salt,ASN1_OCTET_STRING_new);
87 return (ret);
88 M_ASN1_New_Error(ASN1_F_PBEPARAM_NEW);
89}
90
91PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length)
92{
93 M_ASN1_D2I_vars(a,PBEPARAM *,PBEPARAM_new);
94 M_ASN1_D2I_Init();
95 M_ASN1_D2I_start_sequence();
96 M_ASN1_D2I_get (ret->salt, d2i_ASN1_OCTET_STRING);
97 M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
98 M_ASN1_D2I_Finish(a, PBEPARAM_free, ASN1_F_D2I_PBEPARAM);
99}
100
101void PBEPARAM_free (PBEPARAM *a)
102{
103 if(a==NULL) return;
104 ASN1_OCTET_STRING_free(a->salt);
105 ASN1_INTEGER_free (a->iter);
106 Free ((char *)a);
107}
108
109/* Return an algorithm identifier for a PKCS#5 PBE algorithm */
110
111X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
112 int saltlen)
113{
114 PBEPARAM *pbe;
115 ASN1_OBJECT *al;
116 X509_ALGOR *algor;
117 ASN1_TYPE *astype;
118
119 if (!(pbe = PBEPARAM_new ())) {
120 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
121 return NULL;
122 }
123 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
124 ASN1_INTEGER_set (pbe->iter, iter);
125 if (!saltlen) saltlen = PKCS5_SALT_LEN;
126 if (!(pbe->salt->data = Malloc (saltlen))) {
127 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
128 return NULL;
129 }
130 pbe->salt->length = saltlen;
131 if (salt) memcpy (pbe->salt->data, salt, saltlen);
132 else RAND_bytes (pbe->salt->data, saltlen);
133
134 if (!(astype = ASN1_TYPE_new())) {
135 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
136 return NULL;
137 }
138
139 astype->type = V_ASN1_SEQUENCE;
140 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
141 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
142 return NULL;
143 }
144 PBEPARAM_free (pbe);
145
146 al = OBJ_nid2obj(alg); /* never need to free al */
147 if (!(algor = X509_ALGOR_new())) {
148 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
149 return NULL;
150 }
151 ASN1_OBJECT_free(algor->algorithm);
152 algor->algorithm = al;
153 algor->parameter = astype;
154
155 return (algor);
156}
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
new file mode 100644
index 0000000000..09f4bf6112
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p5_pbev2.c
@@ -0,0 +1,274 @@
1/* p5_pbev2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* PKCS#5 v2.0 password based encryption structures */
66
67int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp)
68{
69 M_ASN1_I2D_vars(a);
70 M_ASN1_I2D_len (a->keyfunc, i2d_X509_ALGOR);
71 M_ASN1_I2D_len (a->encryption, i2d_X509_ALGOR);
72
73 M_ASN1_I2D_seq_total ();
74
75 M_ASN1_I2D_put (a->keyfunc, i2d_X509_ALGOR);
76 M_ASN1_I2D_put (a->encryption, i2d_X509_ALGOR);
77
78 M_ASN1_I2D_finish();
79}
80
81PBE2PARAM *PBE2PARAM_new(void)
82{
83 PBE2PARAM *ret=NULL;
84 ASN1_CTX c;
85 M_ASN1_New_Malloc(ret, PBE2PARAM);
86 M_ASN1_New(ret->keyfunc,X509_ALGOR_new);
87 M_ASN1_New(ret->encryption,X509_ALGOR_new);
88 return (ret);
89 M_ASN1_New_Error(ASN1_F_PBE2PARAM_NEW);
90}
91
92PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length)
93{
94 M_ASN1_D2I_vars(a,PBE2PARAM *,PBE2PARAM_new);
95 M_ASN1_D2I_Init();
96 M_ASN1_D2I_start_sequence();
97 M_ASN1_D2I_get (ret->keyfunc, d2i_X509_ALGOR);
98 M_ASN1_D2I_get (ret->encryption, d2i_X509_ALGOR);
99 M_ASN1_D2I_Finish(a, PBE2PARAM_free, ASN1_F_D2I_PBE2PARAM);
100}
101
102void PBE2PARAM_free (PBE2PARAM *a)
103{
104 if(a==NULL) return;
105 X509_ALGOR_free(a->keyfunc);
106 X509_ALGOR_free(a->encryption);
107 Free ((char *)a);
108}
109
110int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp)
111{
112 M_ASN1_I2D_vars(a);
113 M_ASN1_I2D_len (a->salt, i2d_ASN1_TYPE);
114 M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);
115 M_ASN1_I2D_len (a->keylength, i2d_ASN1_INTEGER);
116 M_ASN1_I2D_len (a->prf, i2d_X509_ALGOR);
117
118 M_ASN1_I2D_seq_total ();
119
120 M_ASN1_I2D_put (a->salt, i2d_ASN1_TYPE);
121 M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
122 M_ASN1_I2D_put (a->keylength, i2d_ASN1_INTEGER);
123 M_ASN1_I2D_put (a->prf, i2d_X509_ALGOR);
124
125 M_ASN1_I2D_finish();
126}
127
128PBKDF2PARAM *PBKDF2PARAM_new(void)
129{
130 PBKDF2PARAM *ret=NULL;
131 ASN1_CTX c;
132 M_ASN1_New_Malloc(ret, PBKDF2PARAM);
133 M_ASN1_New(ret->salt, ASN1_TYPE_new);
134 M_ASN1_New(ret->iter, ASN1_INTEGER_new);
135 ret->keylength = NULL;
136 ret->prf = NULL;
137 return (ret);
138 M_ASN1_New_Error(ASN1_F_PBKDF2PARAM_NEW);
139}
140
141PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp,
142 long length)
143{
144 M_ASN1_D2I_vars(a,PBKDF2PARAM *,PBKDF2PARAM_new);
145 M_ASN1_D2I_Init();
146 M_ASN1_D2I_start_sequence();
147 M_ASN1_D2I_get (ret->salt, d2i_ASN1_TYPE);
148 M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER);
149 M_ASN1_D2I_get_opt (ret->keylength, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
150 M_ASN1_D2I_get_opt (ret->prf, d2i_X509_ALGOR, V_ASN1_SEQUENCE);
151 M_ASN1_D2I_Finish(a, PBKDF2PARAM_free, ASN1_F_D2I_PBKDF2PARAM);
152}
153
154void PBKDF2PARAM_free (PBKDF2PARAM *a)
155{
156 if(a==NULL) return;
157 ASN1_TYPE_free(a->salt);
158 ASN1_INTEGER_free(a->iter);
159 ASN1_INTEGER_free(a->keylength);
160 X509_ALGOR_free(a->prf);
161 Free ((char *)a);
162}
163
164/* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm:
165 * yes I know this is horrible!
166 */
167
168X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
169 unsigned char *salt, int saltlen)
170{
171 X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL;
172 int alg_nid;
173 EVP_CIPHER_CTX ctx;
174 unsigned char iv[EVP_MAX_IV_LENGTH];
175 PBKDF2PARAM *kdf = NULL;
176 PBE2PARAM *pbe2 = NULL;
177 ASN1_OCTET_STRING *osalt = NULL;
178
179 if(!(pbe2 = PBE2PARAM_new())) goto merr;
180
181 /* Setup the AlgorithmIdentifier for the encryption scheme */
182 scheme = pbe2->encryption;
183
184 alg_nid = EVP_CIPHER_type(cipher);
185
186 scheme->algorithm = OBJ_nid2obj(alg_nid);
187 if(!(scheme->parameter = ASN1_TYPE_new())) goto merr;
188
189 /* Create random IV */
190 RAND_bytes(iv, EVP_CIPHER_iv_length(cipher));
191
192 /* Dummy cipherinit to just setup the IV */
193 EVP_CipherInit(&ctx, cipher, NULL, iv, 0);
194 if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) {
195 ASN1err(ASN1_F_PKCS5_PBE2_SET,
196 ASN1_R_ERROR_SETTING_CIPHER_PARAMS);
197 goto err;
198 }
199 EVP_CIPHER_CTX_cleanup(&ctx);
200
201 if(!(kdf = PBKDF2PARAM_new())) goto merr;
202 if(!(osalt = ASN1_OCTET_STRING_new())) goto merr;
203
204 if (!saltlen) saltlen = PKCS5_SALT_LEN;
205 if (!(osalt->data = Malloc (saltlen))) goto merr;
206 osalt->length = saltlen;
207 if (salt) memcpy (osalt->data, salt, saltlen);
208 else RAND_bytes (osalt->data, saltlen);
209
210 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
211 if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr;
212
213 /* Now include salt in kdf structure */
214 kdf->salt->value.octet_string = osalt;
215 kdf->salt->type = V_ASN1_OCTET_STRING;
216 osalt = NULL;
217
218 /* If its RC2 then we'd better setup the key length */
219
220 if(alg_nid == NID_rc2_cbc) {
221 if(!(kdf->keylength = ASN1_INTEGER_new())) goto merr;
222 if(!ASN1_INTEGER_set (kdf->keylength,
223 EVP_CIPHER_key_length(cipher))) goto merr;
224 }
225
226 /* prf can stay NULL because we are using hmacWithSHA1 */
227
228 /* Now setup the PBE2PARAM keyfunc structure */
229
230 pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2);
231
232 /* Encode PBKDF2PARAM into parameter of pbe2 */
233
234 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
235
236 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
237 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
238 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
239
240 PBKDF2PARAM_free(kdf);
241 kdf = NULL;
242
243 /* Now set up top level AlgorithmIdentifier */
244
245 if(!(ret = X509_ALGOR_new())) goto merr;
246 if(!(ret->parameter = ASN1_TYPE_new())) goto merr;
247
248 ret->algorithm = OBJ_nid2obj(NID_pbes2);
249
250 /* Encode PBE2PARAM into parameter */
251
252 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
253 &ret->parameter->value.sequence)) goto merr;
254 ret->parameter->type = V_ASN1_SEQUENCE;
255
256 PBE2PARAM_free(pbe2);
257 pbe2 = NULL;
258
259 return ret;
260
261 merr:
262 ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE);
263
264 err:
265 PBE2PARAM_free(pbe2);
266 /* Note 'scheme' is freed as part of pbe2 */
267 ASN1_OCTET_STRING_free(osalt);
268 PBKDF2PARAM_free(kdf);
269 X509_ALGOR_free(kalg);
270 X509_ALGOR_free(ret);
271
272 return NULL;
273
274}
diff --git a/src/lib/libcrypto/asn1/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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_DIGEST(PKCS7_DIGEST *a, unsigned char **pp)
65 * ASN1err(ASN1_F_PKCS7_DIGEST_NEW,ASN1_R_MISSING_EOS);
66 * ASN1err(ASN1_F_D2I_PKCS7_DIGEST,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_DIGEST(a,pp)
70PKCS7_DIGEST *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
@@ -87,10 +80,8 @@ unsigned char **pp;
87 M_ASN1_I2D_finish(); 80 M_ASN1_I2D_finish();
88 } 81 }
89 82
90PKCS7_DIGEST *d2i_PKCS7_DIGEST(a,pp,length) 83PKCS7_DIGEST *d2i_PKCS7_DIGEST(PKCS7_DIGEST **a, unsigned char **pp,
91PKCS7_DIGEST **a; 84 long length)
92unsigned char **pp;
93long length;
94 { 85 {
95 M_ASN1_D2I_vars(a,PKCS7_DIGEST *,PKCS7_DIGEST_new); 86 M_ASN1_D2I_vars(a,PKCS7_DIGEST *,PKCS7_DIGEST_new);
96 87
@@ -104,9 +95,10 @@ long length;
104 M_ASN1_D2I_Finish(a,PKCS7_DIGEST_free,ASN1_F_D2I_PKCS7_DIGEST); 95 M_ASN1_D2I_Finish(a,PKCS7_DIGEST_free,ASN1_F_D2I_PKCS7_DIGEST);
105 } 96 }
106 97
107PKCS7_DIGEST *PKCS7_DIGEST_new() 98PKCS7_DIGEST *PKCS7_DIGEST_new(void)
108 { 99 {
109 PKCS7_DIGEST *ret=NULL; 100 PKCS7_DIGEST *ret=NULL;
101 ASN1_CTX c;
110 102
111 M_ASN1_New_Malloc(ret,PKCS7_DIGEST); 103 M_ASN1_New_Malloc(ret,PKCS7_DIGEST);
112 M_ASN1_New(ret->version,ASN1_INTEGER_new); 104 M_ASN1_New(ret->version,ASN1_INTEGER_new);
@@ -117,8 +109,7 @@ PKCS7_DIGEST *PKCS7_DIGEST_new()
117 M_ASN1_New_Error(ASN1_F_PKCS7_DIGEST_NEW); 109 M_ASN1_New_Error(ASN1_F_PKCS7_DIGEST_NEW);
118 } 110 }
119 111
120void PKCS7_DIGEST_free(a) 112void PKCS7_DIGEST_free(PKCS7_DIGEST *a)
121PKCS7_DIGEST *a;
122 { 113 {
123 if (a == NULL) return; 114 if (a == NULL) return;
124 ASN1_INTEGER_free(a->version); 115 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT *a, unsigned char **pp)
65 * ASN1err(ASN1_F_PKCS7_ENCRYPT_NEW,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_PKCS7_ENCRYPT,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_ENCRYPT(a,pp)
70PKCS7_ENCRYPT *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
@@ -83,10 +76,8 @@ unsigned char **pp;
83 M_ASN1_I2D_finish(); 76 M_ASN1_I2D_finish();
84 } 77 }
85 78
86PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(a,pp,length) 79PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a, unsigned char **pp,
87PKCS7_ENCRYPT **a; 80 long length)
88unsigned char **pp;
89long length;
90 { 81 {
91 M_ASN1_D2I_vars(a,PKCS7_ENCRYPT *,PKCS7_ENCRYPT_new); 82 M_ASN1_D2I_vars(a,PKCS7_ENCRYPT *,PKCS7_ENCRYPT_new);
92 83
@@ -98,9 +89,10 @@ long length;
98 M_ASN1_D2I_Finish(a,PKCS7_ENCRYPT_free,ASN1_F_D2I_PKCS7_ENCRYPT); 89 M_ASN1_D2I_Finish(a,PKCS7_ENCRYPT_free,ASN1_F_D2I_PKCS7_ENCRYPT);
99 } 90 }
100 91
101PKCS7_ENCRYPT *PKCS7_ENCRYPT_new() 92PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void)
102 { 93 {
103 PKCS7_ENCRYPT *ret=NULL; 94 PKCS7_ENCRYPT *ret=NULL;
95 ASN1_CTX c;
104 96
105 M_ASN1_New_Malloc(ret,PKCS7_ENCRYPT); 97 M_ASN1_New_Malloc(ret,PKCS7_ENCRYPT);
106 M_ASN1_New(ret->version,ASN1_INTEGER_new); 98 M_ASN1_New(ret->version,ASN1_INTEGER_new);
@@ -109,8 +101,7 @@ PKCS7_ENCRYPT *PKCS7_ENCRYPT_new()
109 M_ASN1_New_Error(ASN1_F_PKCS7_ENCRYPT_NEW); 101 M_ASN1_New_Error(ASN1_F_PKCS7_ENCRYPT_NEW);
110 } 102 }
111 103
112void PKCS7_ENCRYPT_free(a) 104void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a)
113PKCS7_ENCRYPT *a;
114 { 105 {
115 if (a == NULL) return; 106 if (a == NULL) return;
116 ASN1_INTEGER_free(a->version); 107 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT *a, unsigned char **pp)
65 * ASN1err(ASN1_F_PKCS7_ENC_CONTENT_NEW,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_PKCS7_ENC_CONTENT,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_ENC_CONTENT(a,pp)
70PKCS7_ENC_CONTENT *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
@@ -85,10 +78,8 @@ unsigned char **pp;
85 M_ASN1_I2D_finish(); 78 M_ASN1_I2D_finish();
86 } 79 }
87 80
88PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(a,pp,length) 81PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT **a,
89PKCS7_ENC_CONTENT **a; 82 unsigned char **pp, long length)
90unsigned char **pp;
91long length;
92 { 83 {
93 M_ASN1_D2I_vars(a,PKCS7_ENC_CONTENT *,PKCS7_ENC_CONTENT_new); 84 M_ASN1_D2I_vars(a,PKCS7_ENC_CONTENT *,PKCS7_ENC_CONTENT_new);
94 85
@@ -103,20 +94,21 @@ long length;
103 ASN1_F_D2I_PKCS7_ENC_CONTENT); 94 ASN1_F_D2I_PKCS7_ENC_CONTENT);
104 } 95 }
105 96
106PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new() 97PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(void)
107 { 98 {
108 PKCS7_ENC_CONTENT *ret=NULL; 99 PKCS7_ENC_CONTENT *ret=NULL;
100 ASN1_CTX c;
109 101
110 M_ASN1_New_Malloc(ret,PKCS7_ENC_CONTENT); 102 M_ASN1_New_Malloc(ret,PKCS7_ENC_CONTENT);
111 M_ASN1_New(ret->content_type,ASN1_OBJECT_new); 103 /* M_ASN1_New(ret->content_type,ASN1_OBJECT_new); */
104 ret->content_type=OBJ_nid2obj(NID_pkcs7_encrypted);
112 M_ASN1_New(ret->algorithm,X509_ALGOR_new); 105 M_ASN1_New(ret->algorithm,X509_ALGOR_new);
113 ret->enc_data=NULL; 106 ret->enc_data=NULL;
114 return(ret); 107 return(ret);
115 M_ASN1_New_Error(ASN1_F_PKCS7_ENC_CONTENT_NEW); 108 M_ASN1_New_Error(ASN1_F_PKCS7_ENC_CONTENT_NEW);
116 } 109 }
117 110
118void PKCS7_ENC_CONTENT_free(a) 111void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a)
119PKCS7_ENC_CONTENT *a;
120 { 112 {
121 if (a == NULL) return; 113 if (a == NULL) return;
122 ASN1_OBJECT_free(a->content_type); 114 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE *a, unsigned char **pp)
65 * ASN1err(ASN1_F_PKCS7_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_PKCS7_ENVELOPE,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_ENVELOPE(a,pp)
70PKCS7_ENVELOPE *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
75 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); 68 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
76 M_ASN1_I2D_len_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); 69 M_ASN1_I2D_len_SET_type(PKCS7_RECIP_INFO,a->recipientinfo,
70 i2d_PKCS7_RECIP_INFO);
77 M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); 71 M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT);
78 72
79 M_ASN1_I2D_seq_total(); 73 M_ASN1_I2D_seq_total();
80 74
81 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); 75 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
82 M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); 76 M_ASN1_I2D_put_SET_type(PKCS7_RECIP_INFO,a->recipientinfo,
77 i2d_PKCS7_RECIP_INFO);
83 M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); 78 M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT);
84 79
85 M_ASN1_I2D_finish(); 80 M_ASN1_I2D_finish();
86 } 81 }
87 82
88PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(a,pp,length) 83PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE **a, unsigned char **pp,
89PKCS7_ENVELOPE **a; 84 long length)
90unsigned char **pp;
91long length;
92 { 85 {
93 M_ASN1_D2I_vars(a,PKCS7_ENVELOPE *,PKCS7_ENVELOPE_new); 86 M_ASN1_D2I_vars(a,PKCS7_ENVELOPE *,PKCS7_ENVELOPE_new);
94 87
95 M_ASN1_D2I_Init(); 88 M_ASN1_D2I_Init();
96 M_ASN1_D2I_start_sequence(); 89 M_ASN1_D2I_start_sequence();
97 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); 90 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
98 M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); 91 M_ASN1_D2I_get_set_type(PKCS7_RECIP_INFO,ret->recipientinfo,
92 d2i_PKCS7_RECIP_INFO,PKCS7_RECIP_INFO_free);
99 M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); 93 M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT);
100 94
101 M_ASN1_D2I_Finish(a,PKCS7_ENVELOPE_free,ASN1_F_D2I_PKCS7_ENVELOPE); 95 M_ASN1_D2I_Finish(a,PKCS7_ENVELOPE_free,ASN1_F_D2I_PKCS7_ENVELOPE);
102 } 96 }
103 97
104PKCS7_ENVELOPE *PKCS7_ENVELOPE_new() 98PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void)
105 { 99 {
106 PKCS7_ENVELOPE *ret=NULL; 100 PKCS7_ENVELOPE *ret=NULL;
101 ASN1_CTX c;
107 102
108 M_ASN1_New_Malloc(ret,PKCS7_ENVELOPE); 103 M_ASN1_New_Malloc(ret,PKCS7_ENVELOPE);
109 M_ASN1_New(ret->version,ASN1_INTEGER_new); 104 M_ASN1_New(ret->version,ASN1_INTEGER_new);
110 M_ASN1_New(ret->recipientinfo,sk_new_null); 105 M_ASN1_New(ret->recipientinfo,sk_PKCS7_RECIP_INFO_new_null);
111 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); 106 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new);
112 return(ret); 107 return(ret);
113 M_ASN1_New_Error(ASN1_F_PKCS7_ENVELOPE_NEW); 108 M_ASN1_New_Error(ASN1_F_PKCS7_ENVELOPE_NEW);
114 } 109 }
115 110
116void PKCS7_ENVELOPE_free(a) 111void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a)
117PKCS7_ENVELOPE *a;
118 { 112 {
119 if (a == NULL) return; 113 if (a == NULL) return;
120 ASN1_INTEGER_free(a->version); 114 ASN1_INTEGER_free(a->version);
121 sk_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); 115 sk_PKCS7_RECIP_INFO_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free);
122 PKCS7_ENC_CONTENT_free(a->enc_data); 116 PKCS7_ENC_CONTENT_free(a->enc_data);
123 Free((char *)a); 117 Free((char *)a);
124 } 118 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_ISSUER_AND_SERIAL(PKCS7_ISSUER_AND_SERIAL *a,
65 * ASN1err(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW,ASN1_R_LENGTH_MISMATCH); 65 unsigned char **pp)
66 * ASN1err(ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_ISSUER_AND_SERIAL(a,pp)
70PKCS7_ISSUER_AND_SERIAL *a;
71unsigned char **pp;
72 { 66 {
73 M_ASN1_I2D_vars(a); 67 M_ASN1_I2D_vars(a);
74 68
@@ -83,10 +77,7 @@ unsigned char **pp;
83 M_ASN1_I2D_finish(); 77 M_ASN1_I2D_finish();
84 } 78 }
85 79
86PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(a,pp,length) 80PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(PKCS7_ISSUER_AND_SERIAL **a, unsigned char **pp, long length)
87PKCS7_ISSUER_AND_SERIAL **a;
88unsigned char **pp;
89long length;
90 { 81 {
91 M_ASN1_D2I_vars(a,PKCS7_ISSUER_AND_SERIAL *,PKCS7_ISSUER_AND_SERIAL_new); 82 M_ASN1_D2I_vars(a,PKCS7_ISSUER_AND_SERIAL *,PKCS7_ISSUER_AND_SERIAL_new);
92 83
@@ -98,9 +89,10 @@ long length;
98 ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL); 89 ASN1_F_D2I_PKCS7_ISSUER_AND_SERIAL);
99 } 90 }
100 91
101PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new() 92PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void)
102 { 93 {
103 PKCS7_ISSUER_AND_SERIAL *ret=NULL; 94 PKCS7_ISSUER_AND_SERIAL *ret=NULL;
95 ASN1_CTX c;
104 96
105 M_ASN1_New_Malloc(ret,PKCS7_ISSUER_AND_SERIAL); 97 M_ASN1_New_Malloc(ret,PKCS7_ISSUER_AND_SERIAL);
106 M_ASN1_New(ret->issuer,X509_NAME_new); 98 M_ASN1_New(ret->issuer,X509_NAME_new);
@@ -109,8 +101,7 @@ PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new()
109 M_ASN1_New_Error(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW); 101 M_ASN1_New_Error(ASN1_F_PKCS7_ISSUER_AND_SERIAL_NEW);
110 } 102 }
111 103
112void PKCS7_ISSUER_AND_SERIAL_free(a) 104void PKCS7_ISSUER_AND_SERIAL_free(PKCS7_ISSUER_AND_SERIAL *a)
113PKCS7_ISSUER_AND_SERIAL *a;
114 { 105 {
115 if (a == NULL) return; 106 if (a == NULL) return;
116 X509_NAME_free(a->issuer); 107 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "objects.h" 62#include <openssl/pkcs7.h>
63#include <openssl/objects.h>
63 64
64/* ASN1err(ASN1_F_D2I_PKCS7,ASN1_R_BAD_PKCS7_CONTENT); 65int i2d_PKCS7(PKCS7 *a, unsigned char **pp)
65 * ASN1err(ASN1_F_I2D_PKCS7,ASN1_R_BAD_PKCS7_TYPE);
66 * ASN1err(ASN1_F_PKCS7_NEW,ASN1_R_BAD_PKCS7_TYPE);
67 */
68
69int i2d_PKCS7(a,pp)
70PKCS7 *a;
71unsigned char **pp;
72 { 66 {
73 M_ASN1_I2D_vars(a); 67 M_ASN1_I2D_vars(a);
74 68
@@ -150,10 +144,7 @@ unsigned char **pp;
150 M_ASN1_I2D_finish(); 144 M_ASN1_I2D_finish();
151 } 145 }
152 146
153PKCS7 *d2i_PKCS7(a,pp,length) 147PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length)
154PKCS7 **a;
155unsigned char **pp;
156long length;
157 { 148 {
158 M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new); 149 M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new);
159 150
@@ -179,6 +170,7 @@ long length;
179 V_ASN1_CONTEXT_SPECIFIC|0)) 170 V_ASN1_CONTEXT_SPECIFIC|0))
180 { 171 {
181 c.error=ASN1_R_BAD_PKCS7_CONTENT; 172 c.error=ASN1_R_BAD_PKCS7_CONTENT;
173 c.line=__LINE__;
182 goto err; 174 goto err;
183 } 175 }
184 176
@@ -187,7 +179,7 @@ long length;
187 c.q=c.p; 179 c.q=c.p;
188 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass, 180 Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,
189 (c.inf & 1)?(length+ *pp-c.q):c.slen); 181 (c.inf & 1)?(length+ *pp-c.q):c.slen);
190 if (Tinf & 0x80) goto err; 182 if (Tinf & 0x80) { c.line=__LINE__; goto err; }
191 c.slen-=(c.p-c.q); 183 c.slen-=(c.p-c.q);
192 184
193 switch (OBJ_obj2nid(ret->type)) 185 switch (OBJ_obj2nid(ret->type))
@@ -215,14 +207,16 @@ long length;
215 break; 207 break;
216 default: 208 default:
217 c.error=ASN1_R_BAD_PKCS7_TYPE; 209 c.error=ASN1_R_BAD_PKCS7_TYPE;
210 c.line=__LINE__;
218 goto err; 211 goto err;
219 break; 212 /* break; */
220 } 213 }
221 if (Tinf == (1|V_ASN1_CONSTRUCTED)) 214 if (Tinf == (1|V_ASN1_CONSTRUCTED))
222 { 215 {
223 if (!ASN1_check_infinite_end(&c.p,c.slen)) 216 if (!ASN1_check_infinite_end(&c.p,c.slen))
224 { 217 {
225 c.error=ASN1_R_MISSING_EOS; 218 c.error=ERR_R_MISSING_ASN1_EOS;
219 c.line=__LINE__;
226 goto err; 220 goto err;
227 } 221 }
228 } 222 }
@@ -233,12 +227,13 @@ long length;
233 M_ASN1_D2I_Finish(a,PKCS7_free,ASN1_F_D2I_PKCS7); 227 M_ASN1_D2I_Finish(a,PKCS7_free,ASN1_F_D2I_PKCS7);
234 } 228 }
235 229
236PKCS7 *PKCS7_new() 230PKCS7 *PKCS7_new(void)
237 { 231 {
238 PKCS7 *ret=NULL; 232 PKCS7 *ret=NULL;
233 ASN1_CTX c;
239 234
240 M_ASN1_New_Malloc(ret,PKCS7); 235 M_ASN1_New_Malloc(ret,PKCS7);
241 ret->type=ASN1_OBJECT_new(); 236 ret->type=OBJ_nid2obj(NID_undef);
242 ret->asn1=NULL; 237 ret->asn1=NULL;
243 ret->length=0; 238 ret->length=0;
244 ret->detached=0; 239 ret->detached=0;
@@ -247,8 +242,7 @@ PKCS7 *PKCS7_new()
247 M_ASN1_New_Error(ASN1_F_PKCS7_NEW); 242 M_ASN1_New_Error(ASN1_F_PKCS7_NEW);
248 } 243 }
249 244
250void PKCS7_free(a) 245void PKCS7_free(PKCS7 *a)
251PKCS7 *a;
252 { 246 {
253 if (a == NULL) return; 247 if (a == NULL) return;
254 248
@@ -260,9 +254,11 @@ PKCS7 *a;
260 Free((char *)(char *)a); 254 Free((char *)(char *)a);
261 } 255 }
262 256
263void PKCS7_content_free(a) 257void PKCS7_content_free(PKCS7 *a)
264PKCS7 *a;
265 { 258 {
259 if(a == NULL)
260 return;
261
266 if (a->asn1 != NULL) Free((char *)a->asn1); 262 if (a->asn1 != NULL) Free((char *)a->asn1);
267 263
268 if (a->d.ptr != NULL) 264 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO *a, unsigned char **pp)
65 * ASN1err(ASN1_F_PKCS7_RECIP_INFO_NEW,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_PKCS7_RECIP_INFO,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_RECIP_INFO(a,pp)
70PKCS7_RECIP_INFO *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
@@ -87,10 +80,8 @@ unsigned char **pp;
87 M_ASN1_I2D_finish(); 80 M_ASN1_I2D_finish();
88 } 81 }
89 82
90PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(a,pp,length) 83PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO **a,
91PKCS7_RECIP_INFO **a; 84 unsigned char **pp, long length)
92unsigned char **pp;
93long length;
94 { 85 {
95 M_ASN1_D2I_vars(a,PKCS7_RECIP_INFO *,PKCS7_RECIP_INFO_new); 86 M_ASN1_D2I_vars(a,PKCS7_RECIP_INFO *,PKCS7_RECIP_INFO_new);
96 87
@@ -104,9 +95,10 @@ long length;
104 M_ASN1_D2I_Finish(a,PKCS7_RECIP_INFO_free,ASN1_F_D2I_PKCS7_RECIP_INFO); 95 M_ASN1_D2I_Finish(a,PKCS7_RECIP_INFO_free,ASN1_F_D2I_PKCS7_RECIP_INFO);
105 } 96 }
106 97
107PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new() 98PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void)
108 { 99 {
109 PKCS7_RECIP_INFO *ret=NULL; 100 PKCS7_RECIP_INFO *ret=NULL;
101 ASN1_CTX c;
110 102
111 M_ASN1_New_Malloc(ret,PKCS7_RECIP_INFO); 103 M_ASN1_New_Malloc(ret,PKCS7_RECIP_INFO);
112 M_ASN1_New(ret->version,ASN1_INTEGER_new); 104 M_ASN1_New(ret->version,ASN1_INTEGER_new);
@@ -118,8 +110,7 @@ PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new()
118 M_ASN1_New_Error(ASN1_F_PKCS7_RECIP_INFO_NEW); 110 M_ASN1_New_Error(ASN1_F_PKCS7_RECIP_INFO_NEW);
119 } 111 }
120 112
121void PKCS7_RECIP_INFO_free(a) 113void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a)
122PKCS7_RECIP_INFO *a;
123 { 114 {
124 if (a == NULL) return; 115 if (a == NULL) return;
125 ASN1_INTEGER_free(a->version); 116 ASN1_INTEGER_free(a->version);
@@ -127,6 +118,8 @@ PKCS7_RECIP_INFO *a;
127 X509_ALGOR_free(a->key_enc_algor); 118 X509_ALGOR_free(a->key_enc_algor);
128 ASN1_OCTET_STRING_free(a->enc_key); 119 ASN1_OCTET_STRING_free(a->enc_key);
129 if (a->cert != NULL) X509_free(a->cert); 120 if (a->cert != NULL) X509_free(a->cert);
130 Free((char *)a); 121 Free(a);
131 } 122 }
132 123
124IMPLEMENT_STACK_OF(PKCS7_RECIP_INFO)
125IMPLEMENT_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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE *a, unsigned char **pp)
65 * ASN1err(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_PKCS7_SIGN_ENVELOPE,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_SIGN_ENVELOPE(a,pp)
70PKCS7_SIGN_ENVELOPE *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
75 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); 68 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
76 M_ASN1_I2D_len_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); 69 M_ASN1_I2D_len_SET_type(PKCS7_RECIP_INFO,a->recipientinfo,
77 M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); 70 i2d_PKCS7_RECIP_INFO);
71 M_ASN1_I2D_len_SET_type(X509_ALGOR,a->md_algs,i2d_X509_ALGOR);
78 M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT); 72 M_ASN1_I2D_len(a->enc_data,i2d_PKCS7_ENC_CONTENT);
79 M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); 73 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(X509,a->cert,i2d_X509,0);
80 M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); 74 M_ASN1_I2D_len_IMP_SET_opt_type(X509_CRL,a->crl,i2d_X509_CRL,1);
81 M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); 75 M_ASN1_I2D_len_SET_type(PKCS7_SIGNER_INFO,a->signer_info,
76 i2d_PKCS7_SIGNER_INFO);
82 77
83 M_ASN1_I2D_seq_total(); 78 M_ASN1_I2D_seq_total();
84 79
85 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); 80 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
86 M_ASN1_I2D_put_SET(a->recipientinfo,i2d_PKCS7_RECIP_INFO); 81 M_ASN1_I2D_put_SET_type(PKCS7_RECIP_INFO,a->recipientinfo,
87 M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); 82 i2d_PKCS7_RECIP_INFO);
83 M_ASN1_I2D_put_SET_type(X509_ALGOR,a->md_algs,i2d_X509_ALGOR);
88 M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT); 84 M_ASN1_I2D_put(a->enc_data,i2d_PKCS7_ENC_CONTENT);
89 M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); 85 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(X509,a->cert,i2d_X509,0);
90 M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); 86 M_ASN1_I2D_put_IMP_SET_opt_type(X509_CRL,a->crl,i2d_X509_CRL,1);
91 M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); 87 M_ASN1_I2D_put_SET_type(PKCS7_SIGNER_INFO,a->signer_info,
88 i2d_PKCS7_SIGNER_INFO);
92 89
93 M_ASN1_I2D_finish(); 90 M_ASN1_I2D_finish();
94 } 91 }
95 92
96PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(a,pp,length) 93PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE **a,
97PKCS7_SIGN_ENVELOPE **a; 94 unsigned char **pp, long length)
98unsigned char **pp;
99long length;
100 { 95 {
101 M_ASN1_D2I_vars(a,PKCS7_SIGN_ENVELOPE *,PKCS7_SIGN_ENVELOPE_new); 96 M_ASN1_D2I_vars(a,PKCS7_SIGN_ENVELOPE *,PKCS7_SIGN_ENVELOPE_new);
102 97
103 M_ASN1_D2I_Init(); 98 M_ASN1_D2I_Init();
104 M_ASN1_D2I_start_sequence(); 99 M_ASN1_D2I_start_sequence();
105 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); 100 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
106 M_ASN1_D2I_get_set(ret->recipientinfo,d2i_PKCS7_RECIP_INFO); 101 M_ASN1_D2I_get_set_type(PKCS7_RECIP_INFO,ret->recipientinfo,
107 M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); 102 d2i_PKCS7_RECIP_INFO,PKCS7_RECIP_INFO_free);
103 M_ASN1_D2I_get_set_type(X509_ALGOR,ret->md_algs,d2i_X509_ALGOR,
104 X509_ALGOR_free);
108 M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT); 105 M_ASN1_D2I_get(ret->enc_data,d2i_PKCS7_ENC_CONTENT);
109 M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); 106 M_ASN1_D2I_get_IMP_set_opt_type(X509,ret->cert,d2i_X509,X509_free,0);
110 M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); 107 M_ASN1_D2I_get_IMP_set_opt_type(X509_CRL,ret->crl,d2i_X509_CRL,
111 M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); 108 X509_CRL_free,1);
109 M_ASN1_D2I_get_set_type(PKCS7_SIGNER_INFO,ret->signer_info,
110 d2i_PKCS7_SIGNER_INFO,PKCS7_SIGNER_INFO_free);
112 111
113 M_ASN1_D2I_Finish(a,PKCS7_SIGN_ENVELOPE_free, 112 M_ASN1_D2I_Finish(a,PKCS7_SIGN_ENVELOPE_free,
114 ASN1_F_D2I_PKCS7_SIGN_ENVELOPE); 113 ASN1_F_D2I_PKCS7_SIGN_ENVELOPE);
115 } 114 }
116 115
117PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new() 116PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void)
118 { 117 {
119 PKCS7_SIGN_ENVELOPE *ret=NULL; 118 PKCS7_SIGN_ENVELOPE *ret=NULL;
119 ASN1_CTX c;
120 120
121 M_ASN1_New_Malloc(ret,PKCS7_SIGN_ENVELOPE); 121 M_ASN1_New_Malloc(ret,PKCS7_SIGN_ENVELOPE);
122 M_ASN1_New(ret->version,ASN1_INTEGER_new); 122 M_ASN1_New(ret->version,ASN1_INTEGER_new);
123 M_ASN1_New(ret->recipientinfo,sk_new_null); 123 M_ASN1_New(ret->recipientinfo,sk_PKCS7_RECIP_INFO_new_null);
124 M_ASN1_New(ret->md_algs,sk_new_null); 124 M_ASN1_New(ret->md_algs,sk_X509_ALGOR_new_null);
125 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new); 125 M_ASN1_New(ret->enc_data,PKCS7_ENC_CONTENT_new);
126 ret->cert=NULL; 126 ret->cert=NULL;
127 ret->crl=NULL; 127 ret->crl=NULL;
128 M_ASN1_New(ret->signer_info,sk_new_null); 128 M_ASN1_New(ret->signer_info,sk_PKCS7_SIGNER_INFO_new_null);
129 return(ret); 129 return(ret);
130 M_ASN1_New_Error(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW); 130 M_ASN1_New_Error(ASN1_F_PKCS7_SIGN_ENVELOPE_NEW);
131 } 131 }
132 132
133void PKCS7_SIGN_ENVELOPE_free(a) 133void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a)
134PKCS7_SIGN_ENVELOPE *a;
135 { 134 {
136 if (a == NULL) return; 135 if (a == NULL) return;
137 ASN1_INTEGER_free(a->version); 136 ASN1_INTEGER_free(a->version);
138 sk_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free); 137 sk_PKCS7_RECIP_INFO_pop_free(a->recipientinfo,PKCS7_RECIP_INFO_free);
139 sk_pop_free(a->md_algs,X509_ALGOR_free); 138 sk_X509_ALGOR_pop_free(a->md_algs,X509_ALGOR_free);
140 PKCS7_ENC_CONTENT_free(a->enc_data); 139 PKCS7_ENC_CONTENT_free(a->enc_data);
141 sk_pop_free(a->cert,X509_free); 140 sk_X509_pop_free(a->cert,X509_free);
142 sk_pop_free(a->crl,X509_CRL_free); 141 sk_X509_CRL_pop_free(a->crl,X509_CRL_free);
143 sk_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); 142 sk_PKCS7_SIGNER_INFO_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free);
144 Free((char *)a); 143 Free(a);
145 } 144 }
146 145
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_SIGNED(PKCS7_SIGNED *a, unsigned char **pp)
65 * ASN1err(ASN1_F_PKCS7_SIGNED_NEW,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_PKCS7_SIGNED,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_SIGNED(a,pp)
70PKCS7_SIGNED *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
75 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); 68 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
76 M_ASN1_I2D_len_SET(a->md_algs,i2d_X509_ALGOR); 69 M_ASN1_I2D_len_SET_type(X509_ALGOR,a->md_algs,i2d_X509_ALGOR);
77 M_ASN1_I2D_len(a->contents,i2d_PKCS7); 70 M_ASN1_I2D_len(a->contents,i2d_PKCS7);
78 M_ASN1_I2D_len_IMP_set_opt(a->cert,i2d_X509,0); 71 M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(X509,a->cert,i2d_X509,0);
79 M_ASN1_I2D_len_IMP_set_opt(a->crl,i2d_X509_CRL,1); 72 M_ASN1_I2D_len_IMP_SET_opt_type(X509_CRL,a->crl,i2d_X509_CRL,1);
80 M_ASN1_I2D_len_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); 73 M_ASN1_I2D_len_SET_type(PKCS7_SIGNER_INFO,a->signer_info,
74 i2d_PKCS7_SIGNER_INFO);
81 75
82 M_ASN1_I2D_seq_total(); 76 M_ASN1_I2D_seq_total();
83 77
84 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); 78 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
85 M_ASN1_I2D_put_SET(a->md_algs,i2d_X509_ALGOR); 79 M_ASN1_I2D_put_SET_type(X509_ALGOR,a->md_algs,i2d_X509_ALGOR);
86 M_ASN1_I2D_put(a->contents,i2d_PKCS7); 80 M_ASN1_I2D_put(a->contents,i2d_PKCS7);
87 M_ASN1_I2D_put_IMP_set_opt(a->cert,i2d_X509,0); 81 M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(X509,a->cert,i2d_X509,0);
88 M_ASN1_I2D_put_IMP_set_opt(a->crl,i2d_X509_CRL,1); 82 M_ASN1_I2D_put_IMP_SET_opt_type(X509_CRL,a->crl,i2d_X509_CRL,1);
89 M_ASN1_I2D_put_SET(a->signer_info,i2d_PKCS7_SIGNER_INFO); 83 M_ASN1_I2D_put_SET_type(PKCS7_SIGNER_INFO,a->signer_info,
84 i2d_PKCS7_SIGNER_INFO);
90 85
91 M_ASN1_I2D_finish(); 86 M_ASN1_I2D_finish();
92 } 87 }
93 88
94PKCS7_SIGNED *d2i_PKCS7_SIGNED(a,pp,length) 89PKCS7_SIGNED *d2i_PKCS7_SIGNED(PKCS7_SIGNED **a, unsigned char **pp,
95PKCS7_SIGNED **a; 90 long length)
96unsigned char **pp;
97long length;
98 { 91 {
99 M_ASN1_D2I_vars(a,PKCS7_SIGNED *,PKCS7_SIGNED_new); 92 M_ASN1_D2I_vars(a,PKCS7_SIGNED *,PKCS7_SIGNED_new);
100 93
101 M_ASN1_D2I_Init(); 94 M_ASN1_D2I_Init();
102 M_ASN1_D2I_start_sequence(); 95 M_ASN1_D2I_start_sequence();
103 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); 96 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
104 M_ASN1_D2I_get_set(ret->md_algs,d2i_X509_ALGOR); 97 M_ASN1_D2I_get_set_type(X509_ALGOR,ret->md_algs,d2i_X509_ALGOR,
98 X509_ALGOR_free);
105 M_ASN1_D2I_get(ret->contents,d2i_PKCS7); 99 M_ASN1_D2I_get(ret->contents,d2i_PKCS7);
106 M_ASN1_D2I_get_IMP_set_opt(ret->cert,d2i_X509,0); 100 M_ASN1_D2I_get_IMP_set_opt_type(X509,ret->cert,d2i_X509,X509_free,0);
107 M_ASN1_D2I_get_IMP_set_opt(ret->crl,d2i_X509_CRL,1); 101 M_ASN1_D2I_get_IMP_set_opt_type(X509_CRL,ret->crl,d2i_X509_CRL,
108 M_ASN1_D2I_get_set(ret->signer_info,d2i_PKCS7_SIGNER_INFO); 102 X509_CRL_free,1);
103 M_ASN1_D2I_get_set_type(PKCS7_SIGNER_INFO,ret->signer_info,
104 d2i_PKCS7_SIGNER_INFO,PKCS7_SIGNER_INFO_free);
109 105
110 M_ASN1_D2I_Finish(a,PKCS7_SIGNED_free,ASN1_F_D2I_PKCS7_SIGNED); 106 M_ASN1_D2I_Finish(a,PKCS7_SIGNED_free,ASN1_F_D2I_PKCS7_SIGNED);
111 } 107 }
112 108
113PKCS7_SIGNED *PKCS7_SIGNED_new() 109PKCS7_SIGNED *PKCS7_SIGNED_new(void)
114 { 110 {
115 PKCS7_SIGNED *ret=NULL; 111 PKCS7_SIGNED *ret=NULL;
112 ASN1_CTX c;
116 113
117 M_ASN1_New_Malloc(ret,PKCS7_SIGNED); 114 M_ASN1_New_Malloc(ret,PKCS7_SIGNED);
118 M_ASN1_New(ret->version,ASN1_INTEGER_new); 115 M_ASN1_New(ret->version,ASN1_INTEGER_new);
119 M_ASN1_New(ret->md_algs,sk_new_null); 116 M_ASN1_New(ret->md_algs,sk_X509_ALGOR_new_null);
120 M_ASN1_New(ret->contents,PKCS7_new); 117 M_ASN1_New(ret->contents,PKCS7_new);
121 ret->cert=NULL; 118 ret->cert=NULL;
122 ret->crl=NULL; 119 ret->crl=NULL;
123 M_ASN1_New(ret->signer_info,sk_new_null); 120 M_ASN1_New(ret->signer_info,sk_PKCS7_SIGNER_INFO_new_null);
124 return(ret); 121 return(ret);
125 M_ASN1_New_Error(ASN1_F_PKCS7_SIGNED_NEW); 122 M_ASN1_New_Error(ASN1_F_PKCS7_SIGNED_NEW);
126 } 123 }
127 124
128void PKCS7_SIGNED_free(a) 125void PKCS7_SIGNED_free(PKCS7_SIGNED *a)
129PKCS7_SIGNED *a;
130 { 126 {
131 if (a == NULL) return; 127 if (a == NULL) return;
132 ASN1_INTEGER_free(a->version); 128 ASN1_INTEGER_free(a->version);
133 sk_pop_free(a->md_algs,X509_ALGOR_free); 129 sk_X509_ALGOR_pop_free(a->md_algs,X509_ALGOR_free);
134 PKCS7_free(a->contents); 130 PKCS7_free(a->contents);
135 sk_pop_free(a->cert,X509_free); 131 sk_X509_pop_free(a->cert,X509_free);
136 sk_pop_free(a->crl,X509_CRL_free); 132 sk_X509_CRL_pop_free(a->crl,X509_CRL_free);
137 sk_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free); 133 sk_PKCS7_SIGNER_INFO_pop_free(a->signer_info,PKCS7_SIGNER_INFO_free);
138 Free((char *)a); 134 Free(a);
139 } 135 }
140
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64/* 64int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a, unsigned char **pp)
65 * ASN1err(ASN1_F_PKCS7_SIGNER_INFO_NEW,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_PKCS7_SIGNER_INFO,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_PKCS7_SIGNER_INFO(a,pp)
70PKCS7_SIGNER_INFO *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
75 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); 68 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
76 M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); 69 M_ASN1_I2D_len(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL);
77 M_ASN1_I2D_len(a->digest_alg,i2d_X509_ALGOR); 70 M_ASN1_I2D_len(a->digest_alg,i2d_X509_ALGOR);
78 M_ASN1_I2D_len_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); 71 M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->auth_attr,
72 i2d_X509_ATTRIBUTE,0);
79 M_ASN1_I2D_len(a->digest_enc_alg,i2d_X509_ALGOR); 73 M_ASN1_I2D_len(a->digest_enc_alg,i2d_X509_ALGOR);
80 M_ASN1_I2D_len(a->enc_digest,i2d_ASN1_OCTET_STRING); 74 M_ASN1_I2D_len(a->enc_digest,i2d_ASN1_OCTET_STRING);
81 M_ASN1_I2D_len_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); 75 M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->unauth_attr,
76 i2d_X509_ATTRIBUTE,1);
82 77
83 M_ASN1_I2D_seq_total(); 78 M_ASN1_I2D_seq_total();
84 79
85 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER); 80 M_ASN1_I2D_put(a->version,i2d_ASN1_INTEGER);
86 M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL); 81 M_ASN1_I2D_put(a->issuer_and_serial,i2d_PKCS7_ISSUER_AND_SERIAL);
87 M_ASN1_I2D_put(a->digest_alg,i2d_X509_ALGOR); 82 M_ASN1_I2D_put(a->digest_alg,i2d_X509_ALGOR);
88 M_ASN1_I2D_put_IMP_set_opt(a->auth_attr,i2d_X509_ATTRIBUTE,0); 83 M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->auth_attr,
84 i2d_X509_ATTRIBUTE,0);
89 M_ASN1_I2D_put(a->digest_enc_alg,i2d_X509_ALGOR); 85 M_ASN1_I2D_put(a->digest_enc_alg,i2d_X509_ALGOR);
90 M_ASN1_I2D_put(a->enc_digest,i2d_ASN1_OCTET_STRING); 86 M_ASN1_I2D_put(a->enc_digest,i2d_ASN1_OCTET_STRING);
91 M_ASN1_I2D_put_IMP_set_opt(a->unauth_attr,i2d_X509_ATTRIBUTE,1); 87 M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->unauth_attr,
88 i2d_X509_ATTRIBUTE,1);
92 89
93 M_ASN1_I2D_finish(); 90 M_ASN1_I2D_finish();
94 } 91 }
95 92
96PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(a,pp,length) 93PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a,
97PKCS7_SIGNER_INFO **a; 94 unsigned char **pp, long length)
98unsigned char **pp;
99long length;
100 { 95 {
101 M_ASN1_D2I_vars(a,PKCS7_SIGNER_INFO *,PKCS7_SIGNER_INFO_new); 96 M_ASN1_D2I_vars(a,PKCS7_SIGNER_INFO *,PKCS7_SIGNER_INFO_new);
102 97
@@ -105,18 +100,23 @@ long length;
105 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER); 100 M_ASN1_D2I_get(ret->version,d2i_ASN1_INTEGER);
106 M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL); 101 M_ASN1_D2I_get(ret->issuer_and_serial,d2i_PKCS7_ISSUER_AND_SERIAL);
107 M_ASN1_D2I_get(ret->digest_alg,d2i_X509_ALGOR); 102 M_ASN1_D2I_get(ret->digest_alg,d2i_X509_ALGOR);
108 M_ASN1_D2I_get_IMP_set_opt(ret->auth_attr,d2i_X509_ATTRIBUTE,0); 103 M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE,ret->auth_attr,
104 d2i_X509_ATTRIBUTE,X509_ATTRIBUTE_free,
105 0);
109 M_ASN1_D2I_get(ret->digest_enc_alg,d2i_X509_ALGOR); 106 M_ASN1_D2I_get(ret->digest_enc_alg,d2i_X509_ALGOR);
110 M_ASN1_D2I_get(ret->enc_digest,d2i_ASN1_OCTET_STRING); 107 M_ASN1_D2I_get(ret->enc_digest,d2i_ASN1_OCTET_STRING);
111 M_ASN1_D2I_get_IMP_set_opt(ret->unauth_attr,d2i_X509_ATTRIBUTE,1); 108 M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE,ret->unauth_attr,
109 d2i_X509_ATTRIBUTE,
110 X509_ATTRIBUTE_free,1);
112 111
113 M_ASN1_D2I_Finish(a,PKCS7_SIGNER_INFO_free, 112 M_ASN1_D2I_Finish(a,PKCS7_SIGNER_INFO_free,
114 ASN1_F_D2I_PKCS7_SIGNER_INFO); 113 ASN1_F_D2I_PKCS7_SIGNER_INFO);
115 } 114 }
116 115
117PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new() 116PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void)
118 { 117 {
119 PKCS7_SIGNER_INFO *ret=NULL; 118 PKCS7_SIGNER_INFO *ret=NULL;
119 ASN1_CTX c;
120 120
121 M_ASN1_New_Malloc(ret,PKCS7_SIGNER_INFO); 121 M_ASN1_New_Malloc(ret,PKCS7_SIGNER_INFO);
122 M_ASN1_New(ret->version,ASN1_INTEGER_new); 122 M_ASN1_New(ret->version,ASN1_INTEGER_new);
@@ -131,19 +131,20 @@ PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new()
131 M_ASN1_New_Error(ASN1_F_PKCS7_SIGNER_INFO_NEW); 131 M_ASN1_New_Error(ASN1_F_PKCS7_SIGNER_INFO_NEW);
132 } 132 }
133 133
134void PKCS7_SIGNER_INFO_free(a) 134void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a)
135PKCS7_SIGNER_INFO *a;
136 { 135 {
137 if (a == NULL) return; 136 if (a == NULL) return;
138 ASN1_INTEGER_free(a->version); 137 ASN1_INTEGER_free(a->version);
139 PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial); 138 PKCS7_ISSUER_AND_SERIAL_free(a->issuer_and_serial);
140 X509_ALGOR_free(a->digest_alg); 139 X509_ALGOR_free(a->digest_alg);
141 sk_pop_free(a->auth_attr,X509_ATTRIBUTE_free); 140 sk_X509_ATTRIBUTE_pop_free(a->auth_attr,X509_ATTRIBUTE_free);
142 X509_ALGOR_free(a->digest_enc_alg); 141 X509_ALGOR_free(a->digest_enc_alg);
143 ASN1_OCTET_STRING_free(a->enc_digest); 142 ASN1_OCTET_STRING_free(a->enc_digest);
144 sk_pop_free(a->unauth_attr,X509_ATTRIBUTE_free); 143 sk_X509_ATTRIBUTE_pop_free(a->unauth_attr,X509_ATTRIBUTE_free);
145 if (a->pkey != NULL) 144 if (a->pkey != NULL)
146 EVP_PKEY_free(a->pkey); 145 EVP_PKEY_free(a->pkey);
147 Free((char *)a); 146 Free((char *)a);
148 } 147 }
149 148
149IMPLEMENT_STACK_OF(PKCS7_SIGNER_INFO)
150IMPLEMENT_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 @@
1/* p8_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_PKCS8_PRIV_KEY_INFO (PKCS8_PRIV_KEY_INFO *a, unsigned char **pp)
65{
66
67 M_ASN1_I2D_vars(a);
68
69 M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER);
70 M_ASN1_I2D_len (a->pkeyalg, i2d_X509_ALGOR);
71 M_ASN1_I2D_len (a->pkey, i2d_ASN1_TYPE);
72 M_ASN1_I2D_len_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes,
73 i2d_X509_ATTRIBUTE, 0);
74
75 M_ASN1_I2D_seq_total ();
76
77 M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER);
78 M_ASN1_I2D_put (a->pkeyalg, i2d_X509_ALGOR);
79 M_ASN1_I2D_put (a->pkey, i2d_ASN1_TYPE);
80 M_ASN1_I2D_put_IMP_SET_opt_type (X509_ATTRIBUTE, a->attributes,
81 i2d_X509_ATTRIBUTE, 0);
82
83 M_ASN1_I2D_finish();
84}
85
86PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void)
87{
88 PKCS8_PRIV_KEY_INFO *ret=NULL;
89 ASN1_CTX c;
90 M_ASN1_New_Malloc(ret, PKCS8_PRIV_KEY_INFO);
91 M_ASN1_New (ret->version, ASN1_INTEGER_new);
92 M_ASN1_New (ret->pkeyalg, X509_ALGOR_new);
93 M_ASN1_New (ret->pkey, ASN1_TYPE_new);
94 ret->attributes = NULL;
95 ret->broken = PKCS8_OK;
96 return (ret);
97 M_ASN1_New_Error(ASN1_F_PKCS8_PRIV_KEY_INFO_NEW);
98}
99
100PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
101 unsigned char **pp, long length)
102{
103 M_ASN1_D2I_vars(a,PKCS8_PRIV_KEY_INFO *,PKCS8_PRIV_KEY_INFO_new);
104 M_ASN1_D2I_Init();
105 M_ASN1_D2I_start_sequence();
106 M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);
107 M_ASN1_D2I_get (ret->pkeyalg, d2i_X509_ALGOR);
108 M_ASN1_D2I_get (ret->pkey, d2i_ASN1_TYPE);
109 M_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes,
110 d2i_X509_ATTRIBUTE,
111 X509_ATTRIBUTE_free, 0);
112 if (ASN1_TYPE_get(ret->pkey) == V_ASN1_SEQUENCE)
113 ret->broken = PKCS8_NO_OCTET;
114 M_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO);
115}
116
117void PKCS8_PRIV_KEY_INFO_free (PKCS8_PRIV_KEY_INFO *a)
118{
119 if (a == NULL) return;
120 ASN1_INTEGER_free (a->version);
121 X509_ALGOR_free(a->pkeyalg);
122 /* Clear sensitive data */
123 if (a->pkey->value.octet_string)
124 memset (a->pkey->value.octet_string->data,
125 0, a->pkey->value.octet_string->length);
126 ASN1_TYPE_free (a->pkey);
127 sk_X509_ATTRIBUTE_pop_free (a->attributes, X509_ATTRIBUTE_free);
128 Free (a);
129}
diff --git a/src/lib/libcrypto/asn1/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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "objects.h" 62#include <openssl/objects.h>
63 63
64/* 64int i2d_X509_KEY(X509 *a, unsigned char **pp)
65 * ASN1err(ASN1_F_D2I_X509_KEY,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_KEY_NEW,ASN1_R_BAD_GET_OBJECT);
67 */
68
69int i2d_X509_KEY(a,pp)
70X509 *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
@@ -85,10 +78,7 @@ unsigned char **pp;
85 M_ASN1_I2D_finish(); 78 M_ASN1_I2D_finish();
86 } 79 }
87 80
88X509 *d2i_X509_KEY(a,pp,length) 81X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length)
89X509 **a;
90unsigned char **pp;
91long length;
92 { 82 {
93 M_ASN1_D2I_vars(a,X509 *,X509_new); 83 M_ASN1_D2I_vars(a,X509 *,X509_new);
94 84
@@ -100,7 +90,7 @@ long length;
100 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); 90 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
101 } 91 }
102 92
103X509 *X509_KEY_new() 93X509 *X509_KEY_new(void)
104 { 94 {
105 X509_KEY *ret=NULL; 95 X509_KEY *ret=NULL;
106 96
@@ -114,8 +104,7 @@ X509 *X509_KEY_new()
114 M_ASN1_New_Error(ASN1_F_X509_NEW); 104 M_ASN1_New_Error(ASN1_F_X509_NEW);
115 } 105 }
116 106
117void X509_KEY_free(a) 107void X509_KEY_free(X509 *a)
118X509 *a;
119 { 108 {
120 int i; 109 int i;
121 110
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 @@
1/* t_crl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/bn.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67static void ext_print(BIO *out, X509_EXTENSION *ex);
68#ifndef NO_FP_API
69int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
70 {
71 BIO *b;
72 int ret;
73
74 if ((b=BIO_new(BIO_s_file())) == NULL)
75 {
76 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
77 return(0);
78 }
79 BIO_set_fp(b,fp,BIO_NOCLOSE);
80 ret=X509_CRL_print(b, x);
81 BIO_free(b);
82 return(ret);
83 }
84#endif
85
86int X509_CRL_print(BIO *out, X509_CRL *x)
87{
88 char buf[256];
89 unsigned char *s;
90 STACK_OF(X509_REVOKED) *rev;
91 X509_REVOKED *r;
92 long l;
93 int i, j, n;
94
95 BIO_printf(out, "Certificate Revocation List (CRL):\n");
96 l = X509_CRL_get_version(x);
97 BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l);
98 i = OBJ_obj2nid(x->sig_alg->algorithm);
99 BIO_printf(out, "%8sSignature Algorithm: %s\n", "",
100 (i == NID_undef) ? "NONE" : OBJ_nid2ln(i));
101 X509_NAME_oneline(X509_CRL_get_issuer(x),buf,256);
102 BIO_printf(out,"%8sIssuer: %s\n","",buf);
103 BIO_printf(out,"%8sLast Update: ","");
104 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
105 BIO_printf(out,"\n%8sNext Update: ","");
106 if (X509_CRL_get_nextUpdate(x))
107 ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x));
108 else BIO_printf(out,"NONE");
109 BIO_printf(out,"\n");
110
111 n=X509_CRL_get_ext_count(x);
112 if (n > 0) {
113 BIO_printf(out,"%8sCRL extensions:\n","");
114 for (i=0; i<n; i++) ext_print(out, X509_CRL_get_ext(x, i));
115 }
116
117
118 rev = X509_CRL_get_REVOKED(x);
119
120 if(sk_X509_REVOKED_num(rev))
121 BIO_printf(out, "Revoked Certificates:\n");
122 else BIO_printf(out, "No Revoked Certificates.\n");
123
124 for(i = 0; i < sk_X509_REVOKED_num(rev); i++) {
125 r = sk_X509_REVOKED_value(rev, i);
126 BIO_printf(out," Serial Number: ");
127 i2a_ASN1_INTEGER(out,r->serialNumber);
128 BIO_printf(out,"\n Revocation Date: ","");
129 ASN1_TIME_print(out,r->revocationDate);
130 BIO_printf(out,"\n");
131 for(j = 0; j < X509_REVOKED_get_ext_count(r); j++)
132 ext_print(out, X509_REVOKED_get_ext(r, j));
133 }
134
135 i=OBJ_obj2nid(x->sig_alg->algorithm);
136 BIO_printf(out," Signature Algorithm: %s",
137 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i));
138
139 s = x->signature->data;
140 n = x->signature->length;
141 for (i=0; i<n; i++, s++)
142 {
143 if ((i%18) == 0) BIO_write(out,"\n ",9);
144 BIO_printf(out,"%02x%s",*s, ((i+1) == n)?"":":");
145 }
146 BIO_write(out,"\n",1);
147
148 return 1;
149
150}
151
152static void ext_print(BIO *out, X509_EXTENSION *ex)
153{
154 ASN1_OBJECT *obj;
155 int j;
156 BIO_printf(out,"%12s","");
157 obj=X509_EXTENSION_get_object(ex);
158 i2a_ASN1_OBJECT(out,obj);
159 j=X509_EXTENSION_get_critical(ex);
160 BIO_printf(out, ": %s\n", j ? "critical":"","");
161 if(!X509V3_EXT_print(out, ex, 0, 16)) {
162 BIO_printf(out, "%16s", "");
163 ASN1_OCTET_STRING_print(out,ex->value);
164 }
165 BIO_write(out,"\n",1);
166}
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
index bc518d59a2..0dc6e30c3d 100644
--- a/src/lib/libcrypto/asn1/t_pkey.c
+++ b/src/lib/libcrypto/asn1/t_pkey.c
@@ -58,35 +58,23 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "bn.h" 62#include <openssl/bn.h>
63#ifndef NO_RSA 63#ifndef NO_RSA
64#include "rsa.h" 64#include <openssl/rsa.h>
65#endif 65#endif
66#ifndef NO_DH 66#ifndef NO_DH
67#include "dh.h" 67#include <openssl/dh.h>
68#endif 68#endif
69#ifndef NO_DSA 69#ifndef NO_DSA
70#include "dsa.h" 70#include <openssl/dsa.h>
71#endif 71#endif
72 72
73/* DHerr(DH_F_DHPARAMS_PRINT,ERR_R_MALLOC_FAILURE); 73static int print(BIO *fp,const char *str,BIGNUM *num,
74 * DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE);
75 */
76
77#ifndef NOPROTO
78static int print(BIO *fp,char *str,BIGNUM *num,
79 unsigned char *buf,int off); 74 unsigned char *buf,int off);
80#else
81static int print();
82#endif
83
84#ifndef NO_RSA 75#ifndef NO_RSA
85#ifndef NO_FP_API 76#ifndef NO_FP_API
86int RSA_print_fp(fp,x,off) 77int RSA_print_fp(FILE *fp, RSA *x, int off)
87FILE *fp;
88RSA *x;
89int off;
90 { 78 {
91 BIO *b; 79 BIO *b;
92 int ret; 80 int ret;
@@ -103,12 +91,10 @@ int off;
103 } 91 }
104#endif 92#endif
105 93
106int RSA_print(bp,x,off) 94int RSA_print(BIO *bp, RSA *x, int off)
107BIO *bp;
108RSA *x;
109int off;
110 { 95 {
111 char str[128],*s; 96 char str[128];
97 const char *s;
112 unsigned char *m=NULL; 98 unsigned char *m=NULL;
113 int i,ret=0; 99 int i,ret=0;
114 100
@@ -154,10 +140,7 @@ err:
154 140
155#ifndef NO_DSA 141#ifndef NO_DSA
156#ifndef NO_FP_API 142#ifndef NO_FP_API
157int DSA_print_fp(fp,x,off) 143int DSA_print_fp(FILE *fp, DSA *x, int off)
158FILE *fp;
159DSA *x;
160int off;
161 { 144 {
162 BIO *b; 145 BIO *b;
163 int ret; 146 int ret;
@@ -174,10 +157,7 @@ int off;
174 } 157 }
175#endif 158#endif
176 159
177int DSA_print(bp,x,off) 160int DSA_print(BIO *bp, DSA *x, int off)
178BIO *bp;
179DSA *x;
180int off;
181 { 161 {
182 char str[128]; 162 char str[128];
183 unsigned char *m=NULL; 163 unsigned char *m=NULL;
@@ -229,15 +209,12 @@ err:
229 } 209 }
230#endif /* !NO_DSA */ 210#endif /* !NO_DSA */
231 211
232static int print(bp,number,num,buf,off) 212static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
233BIO *bp; 213 int off)
234char *number;
235BIGNUM *num;
236unsigned char *buf;
237int off;
238 { 214 {
239 int n,i; 215 int n,i;
240 char str[128],*neg; 216 char str[128];
217 const char *neg;
241 218
242 if (num == NULL) return(1); 219 if (num == NULL) return(1);
243 neg=(num->neg)?"-":""; 220 neg=(num->neg)?"-":"";
@@ -284,9 +261,7 @@ int off;
284 261
285#ifndef NO_DH 262#ifndef NO_DH
286#ifndef NO_FP_API 263#ifndef NO_FP_API
287int DHparams_print_fp(fp,x) 264int DHparams_print_fp(FILE *fp, DH *x)
288FILE *fp;
289DH *x;
290 { 265 {
291 BIO *b; 266 BIO *b;
292 int ret; 267 int ret;
@@ -303,9 +278,7 @@ DH *x;
303 } 278 }
304#endif 279#endif
305 280
306int DHparams_print(bp,x) 281int DHparams_print(BIO *bp, DH *x)
307BIO *bp;
308DH *x;
309 { 282 {
310 unsigned char *m=NULL; 283 unsigned char *m=NULL;
311 int reason=ERR_R_BUF_LIB,i,ret=0; 284 int reason=ERR_R_BUF_LIB,i,ret=0;
@@ -341,9 +314,7 @@ err:
341 314
342#ifndef NO_DSA 315#ifndef NO_DSA
343#ifndef NO_FP_API 316#ifndef NO_FP_API
344int DSAparams_print_fp(fp,x) 317int DSAparams_print_fp(FILE *fp, DSA *x)
345FILE *fp;
346DSA *x;
347 { 318 {
348 BIO *b; 319 BIO *b;
349 int ret; 320 int ret;
@@ -360,9 +331,7 @@ DSA *x;
360 } 331 }
361#endif 332#endif
362 333
363int DSAparams_print(bp,x) 334int DSAparams_print(BIO *bp, DSA *x)
364BIO *bp;
365DSA *x;
366 { 335 {
367 unsigned char *m=NULL; 336 unsigned char *m=NULL;
368 int reason=ERR_R_BUF_LIB,i,ret=0; 337 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "bn.h" 62#include <openssl/bn.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66#ifndef NO_FP_API 66#ifndef NO_FP_API
67int X509_REQ_print_fp(fp,x) 67int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
68FILE *fp;
69X509_REQ *x;
70 { 68 {
71 BIO *b; 69 BIO *b;
72 int ret; 70 int ret;
@@ -83,16 +81,15 @@ X509_REQ *x;
83 } 81 }
84#endif 82#endif
85 83
86int X509_REQ_print(bp,x) 84int X509_REQ_print(BIO *bp, X509_REQ *x)
87BIO *bp;
88X509_REQ *x;
89 { 85 {
90 unsigned long l; 86 unsigned long l;
91 int i,n; 87 int i,n;
92 char *s,*neg; 88 char *s;
89 const char *neg;
93 X509_REQ_INFO *ri; 90 X509_REQ_INFO *ri;
94 EVP_PKEY *pkey; 91 EVP_PKEY *pkey;
95 STACK *sk; 92 STACK_OF(X509_ATTRIBUTE) *sk;
96 char str[128]; 93 char str[128];
97 94
98 ri=x->req_info; 95 ri=x->req_info;
@@ -138,12 +135,14 @@ X509_REQ *x;
138#endif 135#endif
139 BIO_printf(bp,"%12sUnknown Public Key:\n",""); 136 BIO_printf(bp,"%12sUnknown Public Key:\n","");
140 137
138 EVP_PKEY_free(pkey);
139
141 /* may not be */ 140 /* may not be */
142 sprintf(str,"%8sAttributes:\n",""); 141 sprintf(str,"%8sAttributes:\n","");
143 if (BIO_puts(bp,str) <= 0) goto err; 142 if (BIO_puts(bp,str) <= 0) goto err;
144 143
145 sk=x->req_info->attributes; 144 sk=x->req_info->attributes;
146 if ((sk == NULL) || (sk_num(sk) == 0)) 145 if ((sk == NULL) || (sk_X509_ATTRIBUTE_num(sk) == 0))
147 { 146 {
148 if (!x->req_info->req_kludge) 147 if (!x->req_info->req_kludge)
149 { 148 {
@@ -153,7 +152,7 @@ X509_REQ *x;
153 } 152 }
154 else 153 else
155 { 154 {
156 for (i=0; i<sk_num(sk); i++) 155 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
157 { 156 {
158 ASN1_TYPE *at; 157 ASN1_TYPE *at;
159 X509_ATTRIBUTE *a; 158 X509_ATTRIBUTE *a;
@@ -161,17 +160,17 @@ X509_REQ *x;
161 ASN1_TYPE *t; 160 ASN1_TYPE *t;
162 int j,type=0,count=1,ii=0; 161 int j,type=0,count=1,ii=0;
163 162
164 a=(X509_ATTRIBUTE *)sk_value(sk,i); 163 a=sk_X509_ATTRIBUTE_value(sk,i);
165 sprintf(str,"%12s",""); 164 sprintf(str,"%12s","");
166 if (BIO_puts(bp,str) <= 0) goto err; 165 if (BIO_puts(bp,str) <= 0) goto err;
167 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) 166 if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0)
168 167 {
169 if (a->set) 168 if (a->set)
170 { 169 {
171 ii=0; 170 ii=0;
172 count=sk_num(a->value.set); 171 count=sk_ASN1_TYPE_num(a->value.set);
173get_next: 172get_next:
174 at=(ASN1_TYPE *)sk_value(a->value.set,ii); 173 at=sk_ASN1_TYPE_value(a->value.set,ii);
175 type=at->type; 174 type=at->type;
176 bs=at->value.asn1_string; 175 bs=at->value.asn1_string;
177 } 176 }
@@ -181,6 +180,7 @@ get_next:
181 type=t->type; 180 type=t->type;
182 bs=t->value.bit_string; 181 bs=t->value.bit_string;
183 } 182 }
183 }
184 for (j=25-j; j>0; j--) 184 for (j=25-j; j>0; j--)
185 if (BIO_write(bp," ",1) != 1) goto err; 185 if (BIO_write(bp," ",1) != 1) goto err;
186 if (BIO_puts(bp,":") <= 0) goto err; 186 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "bn.h" 62#include <openssl/bn.h>
63#ifndef NO_RSA 63#ifndef NO_RSA
64#include "rsa.h" 64#include <openssl/rsa.h>
65#endif 65#endif
66#ifndef NO_DSA 66#ifndef NO_DSA
67#include "dsa.h" 67#include <openssl/dsa.h>
68#endif 68#endif
69#include "objects.h" 69#include <openssl/objects.h>
70#include "x509.h" 70#include <openssl/x509.h>
71#include <openssl/x509v3.h>
71 72
72#ifndef NO_FP_API 73#ifndef NO_FP_API
73int X509_print_fp(fp,x) 74int X509_print_fp(FILE *fp, X509 *x)
74FILE *fp;
75X509 *x;
76 { 75 {
77 BIO *b; 76 BIO *b;
78 int ret; 77 int ret;
@@ -89,9 +88,7 @@ X509 *x;
89 } 88 }
90#endif 89#endif
91 90
92int X509_print(bp,x) 91int X509_print(BIO *bp, X509 *x)
93BIO *bp;
94X509 *x;
95 { 92 {
96 long l; 93 long l;
97 int ret=0,i,j,n; 94 int ret=0,i,j,n;
@@ -99,7 +96,7 @@ X509 *x;
99 X509_CINF *ci; 96 X509_CINF *ci;
100 ASN1_INTEGER *bs; 97 ASN1_INTEGER *bs;
101 EVP_PKEY *pkey=NULL; 98 EVP_PKEY *pkey=NULL;
102 char *neg; 99 const char *neg;
103 X509_EXTENSION *ex; 100 X509_EXTENSION *ex;
104 ASN1_STRING *str=NULL; 101 ASN1_STRING *str=NULL;
105 102
@@ -146,9 +143,9 @@ X509 *x;
146 if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err; 143 if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err;
147 if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err; 144 if (BIO_write(bp,"\n Validity\n",18) <= 0) goto err;
148 if (BIO_write(bp," Not Before: ",24) <= 0) goto err; 145 if (BIO_write(bp," Not Before: ",24) <= 0) goto err;
149 if (!ASN1_UTCTIME_print(bp,X509_get_notBefore(x))) goto err; 146 if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
150 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; 147 if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err;
151 if (!ASN1_UTCTIME_print(bp,X509_get_notAfter(x))) goto err; 148 if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
152 if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err; 149 if (BIO_write(bp,"\n Subject: ",18) <= 0) goto err;
153 if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err; 150 if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err;
154 if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0) 151 if (BIO_write(bp,"\n Subject Public Key Info:\n",34) <= 0)
@@ -158,6 +155,12 @@ X509 *x;
158 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err; 155 (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
159 156
160 pkey=X509_get_pubkey(x); 157 pkey=X509_get_pubkey(x);
158 if (pkey == NULL)
159 {
160 BIO_printf(bp,"%12sUnable to load Public Key\n","");
161 ERR_print_errors(bp);
162 }
163 else
161#ifndef NO_RSA 164#ifndef NO_RSA
162 if (pkey->type == EVP_PKEY_RSA) 165 if (pkey->type == EVP_PKEY_RSA)
163 { 166 {
@@ -175,7 +178,9 @@ X509 *x;
175 } 178 }
176 else 179 else
177#endif 180#endif
178 BIO_printf(bp,"%12sDSA Public Key:\n",""); 181 BIO_printf(bp,"%12sUnknown Public Key:\n","");
182
183 EVP_PKEY_free(pkey);
179 184
180 n=X509_get_ext_count(x); 185 n=X509_get_ext_count(x);
181 if (n > 0) 186 if (n > 0)
@@ -183,7 +188,9 @@ X509 *x;
183 BIO_printf(bp,"%8sX509v3 extensions:\n",""); 188 BIO_printf(bp,"%8sX509v3 extensions:\n","");
184 for (i=0; i<n; i++) 189 for (i=0; i<n; i++)
185 { 190 {
191#if 0
186 int data_type,pack_type; 192 int data_type,pack_type;
193#endif
187 ASN1_OBJECT *obj; 194 ASN1_OBJECT *obj;
188 195
189 ex=X509_get_ext(x,i); 196 ex=X509_get_ext(x,i);
@@ -191,41 +198,11 @@ X509 *x;
191 obj=X509_EXTENSION_get_object(ex); 198 obj=X509_EXTENSION_get_object(ex);
192 i2a_ASN1_OBJECT(bp,obj); 199 i2a_ASN1_OBJECT(bp,obj);
193 j=X509_EXTENSION_get_critical(ex); 200 j=X509_EXTENSION_get_critical(ex);
194 if (BIO_printf(bp,": %s\n%16s",j?"critical":"","") <= 0) 201 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
195 goto err; 202 goto err;
196 203 if(!X509V3_EXT_print(bp, ex, 0, 16))
197 pack_type=X509v3_pack_type_by_OBJ(obj);
198 data_type=X509v3_data_type_by_OBJ(obj);
199
200 if (pack_type == X509_EXT_PACK_STRING)
201 {
202 if (X509v3_unpack_string(
203 &str,data_type,
204 X509_EXTENSION_get_data(ex)) == NULL)
205 {
206 /* hmm... */
207 goto err;
208 }
209 if ( (data_type == V_ASN1_IA5STRING) ||
210 (data_type == V_ASN1_PRINTABLESTRING) ||
211 (data_type == V_ASN1_T61STRING))
212 {
213 if (BIO_write(bp,(char *)str->data,
214 str->length) <= 0)
215 goto err;
216 }
217 else if (data_type == V_ASN1_BIT_STRING)
218 {
219 BIO_printf(bp,"0x");
220 for (j=0; j<str->length; j++)
221 {
222 BIO_printf(bp,"%02X",
223 str->data[j]);
224 }
225 }
226 }
227 else
228 { 204 {
205 BIO_printf(bp, "%16s", "");
229 ASN1_OCTET_STRING_print(bp,ex->value); 206 ASN1_OCTET_STRING_print(bp,ex->value);
230 } 207 }
231 if (BIO_write(bp,"\n",1) <= 0) goto err; 208 if (BIO_write(bp,"\n",1) <= 0) goto err;
@@ -253,9 +230,7 @@ err:
253 return(ret); 230 return(ret);
254 } 231 }
255 232
256int ASN1_STRING_print(bp,v) 233int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
257BIO *bp;
258ASN1_STRING *v;
259 { 234 {
260 int i,n; 235 int i,n;
261 char buf[80],*p;; 236 char buf[80],*p;;
@@ -284,15 +259,59 @@ ASN1_STRING *v;
284 return(1); 259 return(1);
285 } 260 }
286 261
287int ASN1_UTCTIME_print(bp,tm) 262int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm)
288BIO *bp; 263{
289ASN1_UTCTIME *tm; 264 if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
265 if(tm->type == V_ASN1_GENERALIZEDTIME)
266 return ASN1_GENERALIZEDTIME_print(bp, tm);
267 BIO_write(bp,"Bad time value",14);
268 return(0);
269}
270
271static const char *mon[12]=
272 {
273 "Jan","Feb","Mar","Apr","May","Jun",
274 "Jul","Aug","Sep","Oct","Nov","Dec"
275 };
276
277int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)
278 {
279 char *v;
280 int gmt=0;
281 int i;
282 int y=0,M=0,d=0,h=0,m=0,s=0;
283
284 i=tm->length;
285 v=(char *)tm->data;
286
287 if (i < 12) goto err;
288 if (v[i-1] == 'Z') gmt=1;
289 for (i=0; i<12; i++)
290 if ((v[i] > '9') || (v[i] < '0')) goto err;
291 y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
292 M= (v[4]-'0')*10+(v[5]-'0');
293 if ((M > 12) || (M < 1)) goto err;
294 d= (v[6]-'0')*10+(v[7]-'0');
295 h= (v[8]-'0')*10+(v[9]-'0');
296 m= (v[10]-'0')*10+(v[11]-'0');
297 if ( (v[12] >= '0') && (v[12] <= '9') &&
298 (v[13] >= '0') && (v[13] <= '9'))
299 s= (v[12]-'0')*10+(v[13]-'0');
300
301 if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
302 mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
303 return(0);
304 else
305 return(1);
306err:
307 BIO_write(bp,"Bad time value",14);
308 return(0);
309 }
310
311int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm)
290 { 312 {
291 char *v; 313 char *v;
292 int gmt=0; 314 int gmt=0;
293 static char *mon[12]={
294 "Jan","Feb","Mar","Apr","May","Jun",
295 "Jul","Aug","Sep","Oct","Nov","Dec"};
296 int i; 315 int i;
297 int y=0,M=0,d=0,h=0,m=0,s=0; 316 int y=0,M=0,d=0,h=0,m=0,s=0;
298 317
@@ -324,10 +343,7 @@ err:
324 return(0); 343 return(0);
325 } 344 }
326 345
327int X509_NAME_print(bp,name,obase) 346int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
328BIO *bp;
329X509_NAME *name;
330int obase;
331 { 347 {
332 char *s,*c; 348 char *s,*c;
333 int ret=0,l,ll,i,first=1; 349 int ret=0,l,ll,i,first=1;
@@ -342,6 +358,7 @@ int obase;
342 c=s; 358 c=s;
343 for (;;) 359 for (;;)
344 { 360 {
361#ifndef CHARSET_EBCDIC
345 if ( ((*s == '/') && 362 if ( ((*s == '/') &&
346 ((s[1] >= 'A') && (s[1] <= 'Z') && ( 363 ((s[1] >= 'A') && (s[1] <= 'Z') && (
347 (s[2] == '=') || 364 (s[2] == '=') ||
@@ -349,6 +366,15 @@ int obase;
349 (s[3] == '=')) 366 (s[3] == '='))
350 ))) || 367 ))) ||
351 (*s == '\0')) 368 (*s == '\0'))
369#else
370 if ( ((*s == '/') &&
371 (isupper(s[1]) && (
372 (s[2] == '=') ||
373 (isupper(s[2]) &&
374 (s[3] == '='))
375 ))) ||
376 (*s == '\0'))
377#endif
352 { 378 {
353 if ((l <= 0) && !first) 379 if ((l <= 0) && !first)
354 { 380 {
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
62 63
63/* 64int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **pp)
64 * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH);
65 * ASN1err(ASN1_F_X509_ALGOR_NEW,ASN1_R_EXPECTING_A_SEQUENCE);
66 * ASN1err(ASN1_F_D2I_X509_ALGOR,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_X509_ALGOR(a,pp)
70X509_ALGOR *a;
71unsigned char **pp;
72 { 65 {
73 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
74 67
@@ -84,10 +77,7 @@ unsigned char **pp;
84 M_ASN1_I2D_finish(); 77 M_ASN1_I2D_finish();
85 } 78 }
86 79
87X509_ALGOR *d2i_X509_ALGOR(a,pp,length) 80X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length)
88X509_ALGOR **a;
89unsigned char **pp;
90long length;
91 { 81 {
92 M_ASN1_D2I_vars(a,X509_ALGOR *,X509_ALGOR_new); 82 M_ASN1_D2I_vars(a,X509_ALGOR *,X509_ALGOR_new);
93 83
@@ -104,19 +94,19 @@ long length;
104 M_ASN1_D2I_Finish(a,X509_ALGOR_free,ASN1_F_D2I_X509_ALGOR); 94 M_ASN1_D2I_Finish(a,X509_ALGOR_free,ASN1_F_D2I_X509_ALGOR);
105 } 95 }
106 96
107X509_ALGOR *X509_ALGOR_new() 97X509_ALGOR *X509_ALGOR_new(void)
108 { 98 {
109 X509_ALGOR *ret=NULL; 99 X509_ALGOR *ret=NULL;
100 ASN1_CTX c;
110 101
111 M_ASN1_New_Malloc(ret,X509_ALGOR); 102 M_ASN1_New_Malloc(ret,X509_ALGOR);
112 M_ASN1_New(ret->algorithm,ASN1_OBJECT_new); 103 ret->algorithm=OBJ_nid2obj(NID_undef);
113 ret->parameter=NULL; 104 ret->parameter=NULL;
114 return(ret); 105 return(ret);
115 M_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW); 106 M_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW);
116 } 107 }
117 108
118void X509_ALGOR_free(a) 109void X509_ALGOR_free(X509_ALGOR *a)
119X509_ALGOR *a;
120 { 110 {
121 if (a == NULL) return; 111 if (a == NULL) return;
122 ASN1_OBJECT_free(a->algorithm); 112 ASN1_OBJECT_free(a->algorithm);
@@ -124,3 +114,5 @@ X509_ALGOR *a;
124 Free((char *)a); 114 Free((char *)a);
125 } 115 }
126 116
117IMPLEMENT_STACK_OF(X509_ALGOR)
118IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c
index e52ced8627..a1cbebf5a5 100644
--- a/src/lib/libcrypto/asn1/x_attrib.c
+++ b/src/lib/libcrypto/asn1/x_attrib.c
@@ -58,19 +58,12 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "objects.h" 61#include <openssl/objects.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63 63#include <openssl/x509.h>
64/*
65 * ASN1err(ASN1_F_D2I_X509_ATTRIBUTE,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_ATTRIBUTE_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
67 * ASN1err(ASN1_F_I2D_X509_ATTRIBUTE,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
68 */
69 64
70/* sequence */ 65/* sequence */
71int i2d_X509_ATTRIBUTE(a,pp) 66int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a, unsigned char **pp)
72X509_ATTRIBUTE *a;
73unsigned char **pp;
74 { 67 {
75 int k=0; 68 int k=0;
76 int r=0,ret=0; 69 int r=0,ret=0;
@@ -92,18 +85,16 @@ unsigned char **pp;
92 85
93 ret+=i2d_ASN1_OBJECT(a->object,p); 86 ret+=i2d_ASN1_OBJECT(a->object,p);
94 if (a->set) 87 if (a->set)
95 ret+=i2d_ASN1_SET(a->value.set,p,i2d_ASN1_TYPE, 88 ret+=i2d_ASN1_SET_OF_ASN1_TYPE(a->value.set,p,i2d_ASN1_TYPE,
96 V_ASN1_SET,V_ASN1_UNIVERSAL); 89 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
97 else 90 else
98 ret+=i2d_ASN1_TYPE(a->value.single,p); 91 ret+=i2d_ASN1_TYPE(a->value.single,p);
99 if (k++) return(r); 92 if (k++) return(r);
100 } 93 }
101 } 94 }
102 95
103X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(a,pp,length) 96X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a, unsigned char **pp,
104X509_ATTRIBUTE **a; 97 long length)
105unsigned char **pp;
106long length;
107 { 98 {
108 M_ASN1_D2I_vars(a,X509_ATTRIBUTE *,X509_ATTRIBUTE_new); 99 M_ASN1_D2I_vars(a,X509_ATTRIBUTE *,X509_ATTRIBUTE_new);
109 100
@@ -115,7 +106,8 @@ long length;
115 (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET))) 106 (M_ASN1_next == (V_ASN1_CONSTRUCTED|V_ASN1_UNIVERSAL|V_ASN1_SET)))
116 { 107 {
117 ret->set=1; 108 ret->set=1;
118 M_ASN1_D2I_get_set(ret->value.set,d2i_ASN1_TYPE); 109 M_ASN1_D2I_get_set_type(ASN1_TYPE,ret->value.set,d2i_ASN1_TYPE,
110 ASN1_TYPE_free);
119 } 111 }
120 else 112 else
121 { 113 {
@@ -126,25 +118,46 @@ long length;
126 M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE); 118 M_ASN1_D2I_Finish(a,X509_ATTRIBUTE_free,ASN1_F_D2I_X509_ATTRIBUTE);
127 } 119 }
128 120
129X509_ATTRIBUTE *X509_ATTRIBUTE_new() 121X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
122 {
123 X509_ATTRIBUTE *ret=NULL;
124 ASN1_TYPE *val=NULL;
125
126 if ((ret=X509_ATTRIBUTE_new()) == NULL)
127 return(NULL);
128 ret->object=OBJ_nid2obj(nid);
129 ret->set=1;
130 if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err;
131 if ((val=ASN1_TYPE_new()) == NULL) goto err;
132 if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err;
133
134 ASN1_TYPE_set(val,atrtype,value);
135 return(ret);
136err:
137 if (ret != NULL) X509_ATTRIBUTE_free(ret);
138 if (val != NULL) ASN1_TYPE_free(val);
139 return(NULL);
140 }
141
142X509_ATTRIBUTE *X509_ATTRIBUTE_new(void)
130 { 143 {
131 X509_ATTRIBUTE *ret=NULL; 144 X509_ATTRIBUTE *ret=NULL;
145 ASN1_CTX c;
132 146
133 M_ASN1_New_Malloc(ret,X509_ATTRIBUTE); 147 M_ASN1_New_Malloc(ret,X509_ATTRIBUTE);
134 M_ASN1_New(ret->object,ASN1_OBJECT_new); 148 ret->object=OBJ_nid2obj(NID_undef);
135 ret->set=0; 149 ret->set=0;
136 ret->value.ptr=NULL; 150 ret->value.ptr=NULL;
137 return(ret); 151 return(ret);
138 M_ASN1_New_Error(ASN1_F_X509_ATTRIBUTE_NEW); 152 M_ASN1_New_Error(ASN1_F_X509_ATTRIBUTE_NEW);
139 } 153 }
140 154
141void X509_ATTRIBUTE_free(a) 155void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a)
142X509_ATTRIBUTE *a;
143 { 156 {
144 if (a == NULL) return; 157 if (a == NULL) return;
145 ASN1_OBJECT_free(a->object); 158 ASN1_OBJECT_free(a->object);
146 if (a->set) 159 if (a->set)
147 sk_pop_free(a->value.set,ASN1_TYPE_free); 160 sk_ASN1_TYPE_pop_free(a->value.set,ASN1_TYPE_free);
148 else 161 else
149 ASN1_TYPE_free(a->value.single); 162 ASN1_TYPE_free(a->value.single);
150 Free((char *)a); 163 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
62 63
63/* 64int i2d_X509_CINF(X509_CINF *a, unsigned char **pp)
64 * ASN1err(ASN1_F_D2I_X509_CINF,ASN1_R_LENGTH_MISMATCH);
65 * ASN1err(ASN1_F_X509_CINF_NEW,ASN1_R_LENGTH_MISMATCH);
66 */
67
68int i2d_X509_CINF(a,pp)
69X509_CINF *a;
70unsigned char **pp;
71 { 65 {
72 int v1=0,v2=0; 66 int v1=0,v2=0;
73 M_ASN1_I2D_vars(a); 67 M_ASN1_I2D_vars(a);
@@ -81,7 +75,9 @@ unsigned char **pp;
81 M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY); 75 M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY);
82 M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING); 76 M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING);
83 M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING); 77 M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING);
84 M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); 78 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
79 i2d_X509_EXTENSION,3,
80 V_ASN1_SEQUENCE,v2);
85 81
86 M_ASN1_I2D_seq_total(); 82 M_ASN1_I2D_seq_total();
87 83
@@ -94,15 +90,14 @@ unsigned char **pp;
94 M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY); 90 M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY);
95 M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1); 91 M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1);
96 M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2); 92 M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2);
97 M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,3,V_ASN1_SEQUENCE,v2); 93 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
94 i2d_X509_EXTENSION,3,
95 V_ASN1_SEQUENCE,v2);
98 96
99 M_ASN1_I2D_finish(); 97 M_ASN1_I2D_finish();
100 } 98 }
101 99
102X509_CINF *d2i_X509_CINF(a,pp,length) 100X509_CINF *d2i_X509_CINF(X509_CINF **a, unsigned char **pp, long length)
103X509_CINF **a;
104unsigned char **pp;
105long length;
106 { 101 {
107 int ver=0; 102 int ver=0;
108 M_ASN1_D2I_vars(a,X509_CINF *,X509_CINF_new); 103 M_ASN1_D2I_vars(a,X509_CINF *,X509_CINF_new);
@@ -140,28 +135,38 @@ long length;
140 if (ret->subjectUID != NULL) 135 if (ret->subjectUID != NULL)
141 { 136 {
142 ASN1_BIT_STRING_free(ret->subjectUID); 137 ASN1_BIT_STRING_free(ret->subjectUID);
143 ret->issuerUID=NULL; 138 ret->subjectUID=NULL;
144 } 139 }
145 M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1, 140 M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1,
146 V_ASN1_BIT_STRING); 141 V_ASN1_BIT_STRING);
147 M_ASN1_D2I_get_IMP_opt(ret->subjectUID,d2i_ASN1_BIT_STRING, 2, 142 M_ASN1_D2I_get_IMP_opt(ret->subjectUID,d2i_ASN1_BIT_STRING, 2,
148 V_ASN1_BIT_STRING); 143 V_ASN1_BIT_STRING);
149 } 144 }
145/* Note: some broken certificates include extensions but don't set
146 * the version number properly. By bypassing this check they can
147 * be parsed.
148 */
149
150#ifdef VERSION_EXT_CHECK
150 if (ver >= 2) /* version 3 extensions */ 151 if (ver >= 2) /* version 3 extensions */
152#endif
151 { 153 {
152 if (ret->extensions != NULL) 154 if (ret->extensions != NULL)
153 while (sk_num(ret->extensions)) 155 while (sk_X509_EXTENSION_num(ret->extensions))
154 X509_EXTENSION_free((X509_EXTENSION *) 156 X509_EXTENSION_free(
155 sk_pop(ret->extensions)); 157 sk_X509_EXTENSION_pop(ret->extensions));
156 M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION,3, 158 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
157 V_ASN1_SEQUENCE); 159 d2i_X509_EXTENSION,
160 X509_EXTENSION_free,3,
161 V_ASN1_SEQUENCE);
158 } 162 }
159 M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF); 163 M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF);
160 } 164 }
161 165
162X509_CINF *X509_CINF_new() 166X509_CINF *X509_CINF_new(void)
163 { 167 {
164 X509_CINF *ret=NULL; 168 X509_CINF *ret=NULL;
169 ASN1_CTX c;
165 170
166 M_ASN1_New_Malloc(ret,X509_CINF); 171 M_ASN1_New_Malloc(ret,X509_CINF);
167 ret->version=NULL; 172 ret->version=NULL;
@@ -178,8 +183,7 @@ X509_CINF *X509_CINF_new()
178 M_ASN1_New_Error(ASN1_F_X509_CINF_NEW); 183 M_ASN1_New_Error(ASN1_F_X509_CINF_NEW);
179 } 184 }
180 185
181void X509_CINF_free(a) 186void X509_CINF_free(X509_CINF *a)
182X509_CINF *a;
183 { 187 {
184 if (a == NULL) return; 188 if (a == NULL) return;
185 ASN1_INTEGER_free(a->version); 189 ASN1_INTEGER_free(a->version);
@@ -191,7 +195,7 @@ X509_CINF *a;
191 X509_PUBKEY_free(a->key); 195 X509_PUBKEY_free(a->key);
192 ASN1_BIT_STRING_free(a->issuerUID); 196 ASN1_BIT_STRING_free(a->issuerUID);
193 ASN1_BIT_STRING_free(a->subjectUID); 197 ASN1_BIT_STRING_free(a->subjectUID);
194 sk_pop_free(a->extensions,X509_EXTENSION_free); 198 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
195 Free((char *)a); 199 Free(a);
196 } 200 }
197 201
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63
64/*
65 * ASN1err(ASN1_F_D2I_X509_CRL,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_X509_CRL_INFO,ASN1_R_EXPECTING_A_SEQUENCE);
67 * ASN1err(ASN1_F_D2I_X509_REVOKED,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_X509_CRL_NEW,ASN1_R_LENGTH_MISMATCH);
69 * ASN1err(ASN1_F_X509_CRL_INFO_NEW,ASN1_R_EXPECTING_A_SEQUENCE);
70 * ASN1err(ASN1_F_X509_REVOKED_NEW,ASN1_R_LENGTH_MISMATCH);
71 */
72 63
73#ifndef NOPROTO
74static int X509_REVOKED_cmp(X509_REVOKED **a,X509_REVOKED **b); 64static int X509_REVOKED_cmp(X509_REVOKED **a,X509_REVOKED **b);
75static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b); 65static int X509_REVOKED_seq_cmp(X509_REVOKED **a,X509_REVOKED **b);
76#else 66int i2d_X509_REVOKED(X509_REVOKED *a, unsigned char **pp)
77static int X509_REVOKED_cmp();
78static int X509_REVOKED_seq_cmp();
79#endif
80
81int i2d_X509_REVOKED(a,pp)
82X509_REVOKED *a;
83unsigned char **pp;
84 { 67 {
85 M_ASN1_I2D_vars(a); 68 M_ASN1_I2D_vars(a);
86 69
87 M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER); 70 M_ASN1_I2D_len(a->serialNumber,i2d_ASN1_INTEGER);
88 M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_UTCTIME); 71 M_ASN1_I2D_len(a->revocationDate,i2d_ASN1_TIME);
89 M_ASN1_I2D_len_SEQ_opt(a->extensions,i2d_X509_EXTENSION); 72 M_ASN1_I2D_len_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
73 i2d_X509_EXTENSION);
90 74
91 M_ASN1_I2D_seq_total(); 75 M_ASN1_I2D_seq_total();
92 76
93 M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER); 77 M_ASN1_I2D_put(a->serialNumber,i2d_ASN1_INTEGER);
94 M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_UTCTIME); 78 M_ASN1_I2D_put(a->revocationDate,i2d_ASN1_TIME);
95 M_ASN1_I2D_put_SEQ_opt(a->extensions,i2d_X509_EXTENSION); 79 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
80 i2d_X509_EXTENSION);
96 81
97 M_ASN1_I2D_finish(); 82 M_ASN1_I2D_finish();
98 } 83 }
99 84
100X509_REVOKED *d2i_X509_REVOKED(a,pp,length) 85X509_REVOKED *d2i_X509_REVOKED(X509_REVOKED **a, unsigned char **pp,
101X509_REVOKED **a; 86 long length)
102unsigned char **pp;
103long length;
104 { 87 {
105 M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new); 88 M_ASN1_D2I_vars(a,X509_REVOKED *,X509_REVOKED_new);
106 89
107 M_ASN1_D2I_Init(); 90 M_ASN1_D2I_Init();
108 M_ASN1_D2I_start_sequence(); 91 M_ASN1_D2I_start_sequence();
109 M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER); 92 M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER);
110 M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_UTCTIME); 93 M_ASN1_D2I_get(ret->revocationDate,d2i_ASN1_TIME);
111 M_ASN1_D2I_get_seq_opt(ret->extensions,d2i_X509_EXTENSION); 94 M_ASN1_D2I_get_seq_opt_type(X509_EXTENSION,ret->extensions,
95 d2i_X509_EXTENSION,X509_EXTENSION_free);
112 M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED); 96 M_ASN1_D2I_Finish(a,X509_REVOKED_free,ASN1_F_D2I_X509_REVOKED);
113 } 97 }
114 98
115int i2d_X509_CRL_INFO(a,pp) 99int i2d_X509_CRL_INFO(X509_CRL_INFO *a, unsigned char **pp)
116X509_CRL_INFO *a;
117unsigned char **pp;
118 { 100 {
119 int v1=0; 101 int v1=0;
120 long l=0; 102 long l=0;
103 int (*old_cmp)(X509_REVOKED **,X509_REVOKED **);
121 M_ASN1_I2D_vars(a); 104 M_ASN1_I2D_vars(a);
105
106 old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp);
107 sk_X509_REVOKED_sort(a->revoked);
108 sk_X509_REVOKED_set_cmp_func(a->revoked,old_cmp);
122 109
123 if (sk_num(a->revoked) != 0)
124 qsort((char *)a->revoked->data,sk_num(a->revoked),
125 sizeof(X509_REVOKED *),(int (*)(P_CC_CC))X509_REVOKED_seq_cmp);
126 if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0)) 110 if ((a->version != NULL) && ((l=ASN1_INTEGER_get(a->version)) != 0))
127 { 111 {
128 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER); 112 M_ASN1_I2D_len(a->version,i2d_ASN1_INTEGER);
129 } 113 }
130 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR); 114 M_ASN1_I2D_len(a->sig_alg,i2d_X509_ALGOR);
131 M_ASN1_I2D_len(a->issuer,i2d_X509_NAME); 115 M_ASN1_I2D_len(a->issuer,i2d_X509_NAME);
132 M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_UTCTIME); 116 M_ASN1_I2D_len(a->lastUpdate,i2d_ASN1_TIME);
133 if (a->nextUpdate != NULL) 117 if (a->nextUpdate != NULL)
134 { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_UTCTIME); } 118 { M_ASN1_I2D_len(a->nextUpdate,i2d_ASN1_TIME); }
135 M_ASN1_I2D_len_SEQ_opt(a->revoked,i2d_X509_REVOKED); 119 M_ASN1_I2D_len_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
136 M_ASN1_I2D_len_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, 120 i2d_X509_REVOKED);
137 V_ASN1_SEQUENCE,v1); 121 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
122 i2d_X509_EXTENSION,0,
123 V_ASN1_SEQUENCE,v1);
138 124
139 M_ASN1_I2D_seq_total(); 125 M_ASN1_I2D_seq_total();
140 126
@@ -147,17 +133,17 @@ unsigned char **pp;
147 M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME); 133 M_ASN1_I2D_put(a->lastUpdate,i2d_ASN1_UTCTIME);
148 if (a->nextUpdate != NULL) 134 if (a->nextUpdate != NULL)
149 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); } 135 { M_ASN1_I2D_put(a->nextUpdate,i2d_ASN1_UTCTIME); }
150 M_ASN1_I2D_put_SEQ_opt(a->revoked,i2d_X509_REVOKED); 136 M_ASN1_I2D_put_SEQUENCE_opt_type(X509_REVOKED,a->revoked,
151 M_ASN1_I2D_put_EXP_set_opt(a->extensions,i2d_X509_EXTENSION,0, 137 i2d_X509_REVOKED);
152 V_ASN1_SEQUENCE,v1); 138 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
139 i2d_X509_EXTENSION,0,
140 V_ASN1_SEQUENCE,v1);
153 141
154 M_ASN1_I2D_finish(); 142 M_ASN1_I2D_finish();
155 } 143 }
156 144
157X509_CRL_INFO *d2i_X509_CRL_INFO(a,pp,length) 145X509_CRL_INFO *d2i_X509_CRL_INFO(X509_CRL_INFO **a, unsigned char **pp,
158X509_CRL_INFO **a; 146 long length)
159unsigned char **pp;
160long length;
161 { 147 {
162 int i,ver=0; 148 int i,ver=0;
163 M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new); 149 M_ASN1_D2I_vars(a,X509_CRL_INFO *,X509_CRL_INFO_new);
@@ -176,20 +162,31 @@ long length;
176 } 162 }
177 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); 163 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
178 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME); 164 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
179 M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_UTCTIME); 165 M_ASN1_D2I_get(ret->lastUpdate,d2i_ASN1_TIME);
180 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_UTCTIME,V_ASN1_UTCTIME); 166 /* Manually handle the OPTIONAL ASN1_TIME stuff */
167 if(c.slen != 0
168 && ( (M_ASN1_next & ~V_ASN1_CONSTRUCTED) ==
169 (V_ASN1_UNIVERSAL|V_ASN1_UTCTIME)
170 || (M_ASN1_next & ~V_ASN1_CONSTRUCTED) ==
171 (V_ASN1_UNIVERSAL|V_ASN1_GENERALIZEDTIME) ) ) {
172 M_ASN1_D2I_get(ret->nextUpdate,d2i_ASN1_TIME);
173 }
174 if(!ret->nextUpdate)
175 M_ASN1_D2I_get_opt(ret->nextUpdate,d2i_ASN1_GENERALIZEDTIME,
176 V_ASN1_GENERALIZEDTIME);
181 if (ret->revoked != NULL) 177 if (ret->revoked != NULL)
182 { 178 {
183 while (sk_num(ret->revoked)) 179 while (sk_X509_REVOKED_num(ret->revoked))
184 X509_REVOKED_free((X509_REVOKED *)sk_pop(ret->revoked)); 180 X509_REVOKED_free(sk_X509_REVOKED_pop(ret->revoked));
185 } 181 }
186 M_ASN1_D2I_get_seq_opt(ret->revoked,d2i_X509_REVOKED); 182 M_ASN1_D2I_get_seq_opt_type(X509_REVOKED,ret->revoked,d2i_X509_REVOKED,
183 X509_REVOKED_free);
187 184
188 if (ret->revoked != NULL) 185 if (ret->revoked != NULL)
189 { 186 {
190 for (i=0; i<sk_num(ret->revoked); i++) 187 for (i=0; i<sk_X509_REVOKED_num(ret->revoked); i++)
191 { 188 {
192 ((X509_REVOKED *)sk_value(ret->revoked,i))->sequence=i; 189 sk_X509_REVOKED_value(ret->revoked,i)->sequence=i;
193 } 190 }
194 } 191 }
195 192
@@ -197,21 +194,21 @@ long length;
197 { 194 {
198 if (ret->extensions != NULL) 195 if (ret->extensions != NULL)
199 { 196 {
200 while (sk_num(ret->extensions)) 197 while (sk_X509_EXTENSION_num(ret->extensions))
201 X509_EXTENSION_free((X509_EXTENSION *) 198 X509_EXTENSION_free(
202 sk_pop(ret->extensions)); 199 sk_X509_EXTENSION_pop(ret->extensions));
203 } 200 }
204 201
205 M_ASN1_D2I_get_EXP_set_opt(ret->extensions,d2i_X509_EXTENSION, 202 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
206 0,V_ASN1_SEQUENCE); 203 d2i_X509_EXTENSION,
204 X509_EXTENSION_free,0,
205 V_ASN1_SEQUENCE);
207 } 206 }
208 207
209 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO); 208 M_ASN1_D2I_Finish(a,X509_CRL_INFO_free,ASN1_F_D2I_X509_CRL_INFO);
210 } 209 }
211 210
212int i2d_X509_CRL(a,pp) 211int i2d_X509_CRL(X509_CRL *a, unsigned char **pp)
213X509_CRL *a;
214unsigned char **pp;
215 { 212 {
216 M_ASN1_I2D_vars(a); 213 M_ASN1_I2D_vars(a);
217 214
@@ -228,10 +225,7 @@ unsigned char **pp;
228 M_ASN1_I2D_finish(); 225 M_ASN1_I2D_finish();
229 } 226 }
230 227
231X509_CRL *d2i_X509_CRL(a,pp,length) 228X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length)
232X509_CRL **a;
233unsigned char **pp;
234long length;
235 { 229 {
236 M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new); 230 M_ASN1_D2I_vars(a,X509_CRL *,X509_CRL_new);
237 231
@@ -245,9 +239,10 @@ long length;
245 } 239 }
246 240
247 241
248X509_REVOKED *X509_REVOKED_new() 242X509_REVOKED *X509_REVOKED_new(void)
249 { 243 {
250 X509_REVOKED *ret=NULL; 244 X509_REVOKED *ret=NULL;
245 ASN1_CTX c;
251 246
252 M_ASN1_New_Malloc(ret,X509_REVOKED); 247 M_ASN1_New_Malloc(ret,X509_REVOKED);
253 M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new); 248 M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new);
@@ -257,9 +252,10 @@ X509_REVOKED *X509_REVOKED_new()
257 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW); 252 M_ASN1_New_Error(ASN1_F_X509_REVOKED_NEW);
258 } 253 }
259 254
260X509_CRL_INFO *X509_CRL_INFO_new() 255X509_CRL_INFO *X509_CRL_INFO_new(void)
261 { 256 {
262 X509_CRL_INFO *ret=NULL; 257 X509_CRL_INFO *ret=NULL;
258 ASN1_CTX c;
263 259
264 M_ASN1_New_Malloc(ret,X509_CRL_INFO); 260 M_ASN1_New_Malloc(ret,X509_CRL_INFO);
265 ret->version=NULL; 261 ret->version=NULL;
@@ -267,16 +263,17 @@ X509_CRL_INFO *X509_CRL_INFO_new()
267 M_ASN1_New(ret->issuer,X509_NAME_new); 263 M_ASN1_New(ret->issuer,X509_NAME_new);
268 M_ASN1_New(ret->lastUpdate,ASN1_UTCTIME_new); 264 M_ASN1_New(ret->lastUpdate,ASN1_UTCTIME_new);
269 ret->nextUpdate=NULL; 265 ret->nextUpdate=NULL;
270 M_ASN1_New(ret->revoked,sk_new_null); 266 M_ASN1_New(ret->revoked,sk_X509_REVOKED_new_null);
271 M_ASN1_New(ret->extensions,sk_new_null); 267 M_ASN1_New(ret->extensions,sk_X509_EXTENSION_new_null);
272 ret->revoked->comp=(int (*)())X509_REVOKED_cmp; 268 sk_X509_REVOKED_set_cmp_func(ret->revoked,X509_REVOKED_cmp);
273 return(ret); 269 return(ret);
274 M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW); 270 M_ASN1_New_Error(ASN1_F_X509_CRL_INFO_NEW);
275 } 271 }
276 272
277X509_CRL *X509_CRL_new() 273X509_CRL *X509_CRL_new(void)
278 { 274 {
279 X509_CRL *ret=NULL; 275 X509_CRL *ret=NULL;
276 ASN1_CTX c;
280 277
281 M_ASN1_New_Malloc(ret,X509_CRL); 278 M_ASN1_New_Malloc(ret,X509_CRL);
282 ret->references=1; 279 ret->references=1;
@@ -287,18 +284,16 @@ X509_CRL *X509_CRL_new()
287 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW); 284 M_ASN1_New_Error(ASN1_F_X509_CRL_NEW);
288 } 285 }
289 286
290void X509_REVOKED_free(a) 287void X509_REVOKED_free(X509_REVOKED *a)
291X509_REVOKED *a;
292 { 288 {
293 if (a == NULL) return; 289 if (a == NULL) return;
294 ASN1_INTEGER_free(a->serialNumber); 290 ASN1_INTEGER_free(a->serialNumber);
295 ASN1_UTCTIME_free(a->revocationDate); 291 ASN1_UTCTIME_free(a->revocationDate);
296 sk_pop_free(a->extensions,X509_EXTENSION_free); 292 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
297 Free((char *)a); 293 Free(a);
298 } 294 }
299 295
300void X509_CRL_INFO_free(a) 296void X509_CRL_INFO_free(X509_CRL_INFO *a)
301X509_CRL_INFO *a;
302 { 297 {
303 if (a == NULL) return; 298 if (a == NULL) return;
304 ASN1_INTEGER_free(a->version); 299 ASN1_INTEGER_free(a->version);
@@ -307,13 +302,12 @@ X509_CRL_INFO *a;
307 ASN1_UTCTIME_free(a->lastUpdate); 302 ASN1_UTCTIME_free(a->lastUpdate);
308 if (a->nextUpdate) 303 if (a->nextUpdate)
309 ASN1_UTCTIME_free(a->nextUpdate); 304 ASN1_UTCTIME_free(a->nextUpdate);
310 sk_pop_free(a->revoked,X509_REVOKED_free); 305 sk_X509_REVOKED_pop_free(a->revoked,X509_REVOKED_free);
311 sk_pop_free(a->extensions,X509_EXTENSION_free); 306 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
312 Free((char *)a); 307 Free(a);
313 } 308 }
314 309
315void X509_CRL_free(a) 310void X509_CRL_free(X509_CRL *a)
316X509_CRL *a;
317 { 311 {
318 int i; 312 int i;
319 313
@@ -335,19 +329,22 @@ X509_CRL *a;
335 X509_CRL_INFO_free(a->crl); 329 X509_CRL_INFO_free(a->crl);
336 X509_ALGOR_free(a->sig_alg); 330 X509_ALGOR_free(a->sig_alg);
337 ASN1_BIT_STRING_free(a->signature); 331 ASN1_BIT_STRING_free(a->signature);
338 Free((char *)a); 332 Free(a);
339 } 333 }
340 334
341static int X509_REVOKED_cmp(a,b) 335static int X509_REVOKED_cmp(X509_REVOKED **a, X509_REVOKED **b)
342X509_REVOKED **a,**b;
343 { 336 {
344 return(ASN1_STRING_cmp( 337 return(ASN1_STRING_cmp(
345 (ASN1_STRING *)(*a)->serialNumber, 338 (ASN1_STRING *)(*a)->serialNumber,
346 (ASN1_STRING *)(*b)->serialNumber)); 339 (ASN1_STRING *)(*b)->serialNumber));
347 } 340 }
348 341
349static int X509_REVOKED_seq_cmp(a,b) 342static int X509_REVOKED_seq_cmp(X509_REVOKED **a, X509_REVOKED **b)
350X509_REVOKED **a,**b;
351 { 343 {
352 return((*a)->sequence-(*b)->sequence); 344 return((*a)->sequence-(*b)->sequence);
353 } 345 }
346
347IMPLEMENT_STACK_OF(X509_REVOKED)
348IMPLEMENT_ASN1_SET_OF(X509_REVOKED)
349IMPLEMENT_STACK_OF(X509_CRL)
350IMPLEMENT_ASN1_SET_OF(X509_CRL)
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
index 54ffe2f00b..d5f9e1df9e 100644
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ b/src/lib/libcrypto/asn1/x_exten.c
@@ -58,17 +58,11 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "objects.h" 61#include <openssl/objects.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63#include <openssl/x509.h>
63 64
64/* 65int i2d_X509_EXTENSION(X509_EXTENSION *a, unsigned char **pp)
65 * ASN1err(ASN1_F_D2I_X509_EXTENSION,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_EXTENSION_NEW,ASN1_R_LENGTH_MISMATCH);
67 */
68
69int i2d_X509_EXTENSION(a,pp)
70X509_EXTENSION *a;
71unsigned char **pp;
72 { 66 {
73 int k=0; 67 int k=0;
74 int r=0,ret=0; 68 int r=0,ret=0;
@@ -96,10 +90,8 @@ unsigned char **pp;
96 } 90 }
97 } 91 }
98 92
99X509_EXTENSION *d2i_X509_EXTENSION(a,pp,length) 93X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **a, unsigned char **pp,
100X509_EXTENSION **a; 94 long length)
101unsigned char **pp;
102long length;
103 { 95 {
104 int i; 96 int i;
105 M_ASN1_D2I_vars(a,X509_EXTENSION *,X509_EXTENSION_new); 97 M_ASN1_D2I_vars(a,X509_EXTENSION *,X509_EXTENSION_new);
@@ -127,12 +119,13 @@ long length;
127 M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION); 119 M_ASN1_D2I_Finish(a,X509_EXTENSION_free,ASN1_F_D2I_X509_EXTENSION);
128 } 120 }
129 121
130X509_EXTENSION *X509_EXTENSION_new() 122X509_EXTENSION *X509_EXTENSION_new(void)
131 { 123 {
132 X509_EXTENSION *ret=NULL; 124 X509_EXTENSION *ret=NULL;
125 ASN1_CTX c;
133 126
134 M_ASN1_New_Malloc(ret,X509_EXTENSION); 127 M_ASN1_New_Malloc(ret,X509_EXTENSION);
135 M_ASN1_New(ret->object,ASN1_OBJECT_new); 128 ret->object=OBJ_nid2obj(NID_undef);
136 M_ASN1_New(ret->value,ASN1_OCTET_STRING_new); 129 M_ASN1_New(ret->value,ASN1_OCTET_STRING_new);
137 ret->critical=0; 130 ret->critical=0;
138 ret->netscape_hack=0; 131 ret->netscape_hack=0;
@@ -143,8 +136,7 @@ X509_EXTENSION *X509_EXTENSION_new()
143 M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW); 136 M_ASN1_New_Error(ASN1_F_X509_EXTENSION_NEW);
144 } 137 }
145 138
146void X509_EXTENSION_free(a) 139void X509_EXTENSION_free(X509_EXTENSION *a)
147X509_EXTENSION *a;
148 { 140 {
149 if (a == NULL) return; 141 if (a == NULL) return;
150 if ((a->argp != NULL) && (a->ex_free != NULL)) 142 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63#include "x509.h" 63#include <openssl/x509.h>
64 64
65X509_INFO *X509_INFO_new() 65X509_INFO *X509_INFO_new(void)
66 { 66 {
67 X509_INFO *ret=NULL; 67 X509_INFO *ret=NULL;
68 68
@@ -84,8 +84,7 @@ X509_INFO *X509_INFO_new()
84 return(ret); 84 return(ret);
85 } 85 }
86 86
87void X509_INFO_free(x) 87void X509_INFO_free(X509_INFO *x)
88X509_INFO *x;
89 { 88 {
90 int i; 89 int i;
91 90
@@ -109,3 +108,6 @@ X509_INFO *x;
109 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); 108 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey);
110 Free((char *)x); 109 Free((char *)x);
111 } 110 }
111
112IMPLEMENT_STACK_OF(X509_INFO)
113
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
index 28b9c34b58..b09fba33fb 100644
--- a/src/lib/libcrypto/asn1/x_name.c
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -58,25 +58,12 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "objects.h" 61#include <openssl/objects.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63 63#include <openssl/x509.h>
64/*
65 * ASN1err(ASN1_F_D2I_X509_NAME,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_NAME_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
67 * ASN1err(ASN1_F_D2I_X509_NAME_ENTRY,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_X509_NAME_ENTRY_NEW,ASN1_R_UNKNOWN_ATTRIBUTE_TYPE);
69 */
70 64
71#ifndef NOPROTO
72static int i2d_X509_NAME_entries(X509_NAME *a); 65static int i2d_X509_NAME_entries(X509_NAME *a);
73#else 66int i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a, unsigned char **pp)
74static int i2d_X509_NAME_entries();
75#endif
76
77int i2d_X509_NAME_ENTRY(a,pp)
78X509_NAME_ENTRY *a;
79unsigned char **pp;
80 { 67 {
81 M_ASN1_I2D_vars(a); 68 M_ASN1_I2D_vars(a);
82 69
@@ -91,10 +78,8 @@ unsigned char **pp;
91 M_ASN1_I2D_finish(); 78 M_ASN1_I2D_finish();
92 } 79 }
93 80
94X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(a,pp,length) 81X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a, unsigned char **pp,
95X509_NAME_ENTRY **a; 82 long length)
96unsigned char **pp;
97long length;
98 { 83 {
99 M_ASN1_D2I_vars(a,X509_NAME_ENTRY *,X509_NAME_ENTRY_new); 84 M_ASN1_D2I_vars(a,X509_NAME_ENTRY *,X509_NAME_ENTRY_new);
100 85
@@ -106,9 +91,7 @@ long length;
106 M_ASN1_D2I_Finish(a,X509_NAME_ENTRY_free,ASN1_F_D2I_X509_NAME_ENTRY); 91 M_ASN1_D2I_Finish(a,X509_NAME_ENTRY_free,ASN1_F_D2I_X509_NAME_ENTRY);
107 } 92 }
108 93
109int i2d_X509_NAME(a,pp) 94int i2d_X509_NAME(X509_NAME *a, unsigned char **pp)
110X509_NAME *a;
111unsigned char **pp;
112 { 95 {
113 int ret; 96 int ret;
114 97
@@ -128,11 +111,10 @@ unsigned char **pp;
128 return(ret); 111 return(ret);
129 } 112 }
130 113
131static int i2d_X509_NAME_entries(a) 114static int i2d_X509_NAME_entries(X509_NAME *a)
132X509_NAME *a;
133 { 115 {
134 X509_NAME_ENTRY *ne,*fe=NULL; 116 X509_NAME_ENTRY *ne,*fe=NULL;
135 STACK *sk; 117 STACK_OF(X509_NAME_ENTRY) *sk;
136 BUF_MEM *buf=NULL; 118 BUF_MEM *buf=NULL;
137 int set=0,r,ret=0; 119 int set=0,r,ret=0;
138 int i; 120 int i;
@@ -140,9 +122,9 @@ X509_NAME *a;
140 int size=0; 122 int size=0;
141 123
142 sk=a->entries; 124 sk=a->entries;
143 for (i=0; i<sk_num(sk); i++) 125 for (i=0; i<sk_X509_NAME_ENTRY_num(sk); i++)
144 { 126 {
145 ne=(X509_NAME_ENTRY *)sk_value(sk,i); 127 ne=sk_X509_NAME_ENTRY_value(sk,i);
146 if (fe == NULL) 128 if (fe == NULL)
147 { 129 {
148 fe=ne; 130 fe=ne;
@@ -173,9 +155,9 @@ X509_NAME *a;
173 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); 155 ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
174 156
175 set= -1; 157 set= -1;
176 for (i=0; i<sk_num(sk); i++) 158 for (i=0; i<sk_X509_NAME_ENTRY_num(sk); i++)
177 { 159 {
178 ne=(X509_NAME_ENTRY *)sk_value(sk,i); 160 ne=sk_X509_NAME_ENTRY_value(sk,i);
179 if (set != ne->set) 161 if (set != ne->set)
180 { 162 {
181 set=ne->set; 163 set=ne->set;
@@ -190,10 +172,7 @@ err:
190 return(-1); 172 return(-1);
191 } 173 }
192 174
193X509_NAME *d2i_X509_NAME(a,pp,length) 175X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length)
194X509_NAME **a;
195unsigned char **pp;
196long length;
197 { 176 {
198 int set=0,i; 177 int set=0,i;
199 int idx=0; 178 int idx=0;
@@ -201,11 +180,11 @@ long length;
201 M_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new); 180 M_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new);
202 181
203 orig= *pp; 182 orig= *pp;
204 if (sk_num(ret->entries) > 0) 183 if (sk_X509_NAME_ENTRY_num(ret->entries) > 0)
205 { 184 {
206 while (sk_num(ret->entries) > 0) 185 while (sk_X509_NAME_ENTRY_num(ret->entries) > 0)
207 X509_NAME_ENTRY_free((X509_NAME_ENTRY *) 186 X509_NAME_ENTRY_free(
208 sk_pop(ret->entries)); 187 sk_X509_NAME_ENTRY_pop(ret->entries));
209 } 188 }
210 189
211 M_ASN1_D2I_Init(); 190 M_ASN1_D2I_Init();
@@ -213,11 +192,12 @@ long length;
213 for (;;) 192 for (;;)
214 { 193 {
215 if (M_ASN1_D2I_end_sequence()) break; 194 if (M_ASN1_D2I_end_sequence()) break;
216 M_ASN1_D2I_get_set(ret->entries,d2i_X509_NAME_ENTRY); 195 M_ASN1_D2I_get_set_type(X509_NAME_ENTRY,ret->entries,
217 for (; idx < sk_num(ret->entries); idx++) 196 d2i_X509_NAME_ENTRY,
197 X509_NAME_ENTRY_free);
198 for (; idx < sk_X509_NAME_ENTRY_num(ret->entries); idx++)
218 { 199 {
219 ((X509_NAME_ENTRY *)sk_value(ret->entries,idx))->set= 200 sk_X509_NAME_ENTRY_value(ret->entries,idx)->set=set;
220 set;
221 } 201 }
222 set++; 202 set++;
223 } 203 }
@@ -231,21 +211,24 @@ long length;
231 M_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME); 211 M_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME);
232 } 212 }
233 213
234X509_NAME *X509_NAME_new() 214X509_NAME *X509_NAME_new(void)
235 { 215 {
236 X509_NAME *ret=NULL; 216 X509_NAME *ret=NULL;
217 ASN1_CTX c;
237 218
238 M_ASN1_New_Malloc(ret,X509_NAME); 219 M_ASN1_New_Malloc(ret,X509_NAME);
239 if ((ret->entries=sk_new(NULL)) == NULL) goto err2; 220 if ((ret->entries=sk_X509_NAME_ENTRY_new(NULL)) == NULL)
221 { c.line=__LINE__; goto err2; }
240 M_ASN1_New(ret->bytes,BUF_MEM_new); 222 M_ASN1_New(ret->bytes,BUF_MEM_new);
241 ret->modified=1; 223 ret->modified=1;
242 return(ret); 224 return(ret);
243 M_ASN1_New_Error(ASN1_F_X509_NAME_NEW); 225 M_ASN1_New_Error(ASN1_F_X509_NAME_NEW);
244 } 226 }
245 227
246X509_NAME_ENTRY *X509_NAME_ENTRY_new() 228X509_NAME_ENTRY *X509_NAME_ENTRY_new(void)
247 { 229 {
248 X509_NAME_ENTRY *ret=NULL; 230 X509_NAME_ENTRY *ret=NULL;
231 ASN1_CTX c;
249 232
250 M_ASN1_New_Malloc(ret,X509_NAME_ENTRY); 233 M_ASN1_New_Malloc(ret,X509_NAME_ENTRY);
251/* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/ 234/* M_ASN1_New(ret->object,ASN1_OBJECT_new);*/
@@ -256,26 +239,25 @@ X509_NAME_ENTRY *X509_NAME_ENTRY_new()
256 M_ASN1_New_Error(ASN1_F_X509_NAME_ENTRY_NEW); 239 M_ASN1_New_Error(ASN1_F_X509_NAME_ENTRY_NEW);
257 } 240 }
258 241
259void X509_NAME_free(a) 242void X509_NAME_free(X509_NAME *a)
260X509_NAME *a;
261 { 243 {
244 if(a == NULL)
245 return;
246
262 BUF_MEM_free(a->bytes); 247 BUF_MEM_free(a->bytes);
263 sk_pop_free(a->entries,X509_NAME_ENTRY_free); 248 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
264 Free((char *)a); 249 Free(a);
265 } 250 }
266 251
267void X509_NAME_ENTRY_free(a) 252void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a)
268X509_NAME_ENTRY *a;
269 { 253 {
270 if (a == NULL) return; 254 if (a == NULL) return;
271 ASN1_OBJECT_free(a->object); 255 ASN1_OBJECT_free(a->object);
272 ASN1_BIT_STRING_free(a->value); 256 ASN1_BIT_STRING_free(a->value);
273 Free((char *)a); 257 Free(a);
274 } 258 }
275 259
276int X509_NAME_set(xn,name) 260int X509_NAME_set(X509_NAME **xn, X509_NAME *name)
277X509_NAME **xn;
278X509_NAME *name;
279 { 261 {
280 X509_NAME *in; 262 X509_NAME *in;
281 263
@@ -293,3 +275,5 @@ X509_NAME *name;
293 return(*xn != NULL); 275 return(*xn != NULL);
294 } 276 }
295 277
278IMPLEMENT_STACK_OF(X509_NAME_ENTRY)
279IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY)
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
index 1d4d926129..b0057eb212 100644
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -58,25 +58,18 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "asn1_mac.h" 63#include <openssl/asn1_mac.h>
64 64#include <openssl/x509.h>
65/* ASN1err(ASN1_F_D2I_X509_PKEY,ASN1_R_UNSUPPORTED_CIPHER); */
66/* ASN1err(ASN1_F_X509_PKEY_NEW,ASN1_R_IV_TOO_LARGE); */
67 65
68/* need to implement */ 66/* need to implement */
69int i2d_X509_PKEY(a,pp) 67int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
70X509_PKEY *a;
71unsigned char **pp;
72 { 68 {
73 return(0); 69 return(0);
74 } 70 }
75 71
76X509_PKEY *d2i_X509_PKEY(a,pp,length) 72X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, unsigned char **pp, long length)
77X509_PKEY **a;
78unsigned char **pp;
79long length;
80 { 73 {
81 int i; 74 int i;
82 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); 75 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new);
@@ -91,6 +84,7 @@ long length;
91 if (ret->cipher.cipher == NULL) 84 if (ret->cipher.cipher == NULL)
92 { 85 {
93 c.error=ASN1_R_UNSUPPORTED_CIPHER; 86 c.error=ASN1_R_UNSUPPORTED_CIPHER;
87 c.line=__LINE__;
94 goto err; 88 goto err;
95 } 89 }
96 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) 90 if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING)
@@ -99,6 +93,7 @@ long length;
99 if (i > EVP_MAX_IV_LENGTH) 93 if (i > EVP_MAX_IV_LENGTH)
100 { 94 {
101 c.error=ASN1_R_IV_TOO_LARGE; 95 c.error=ASN1_R_IV_TOO_LARGE;
96 c.line=__LINE__;
102 goto err; 97 goto err;
103 } 98 }
104 memcpy(ret->cipher.iv, 99 memcpy(ret->cipher.iv,
@@ -109,9 +104,10 @@ long length;
109 M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); 104 M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY);
110 } 105 }
111 106
112X509_PKEY *X509_PKEY_new() 107X509_PKEY *X509_PKEY_new(void)
113 { 108 {
114 X509_PKEY *ret=NULL; 109 X509_PKEY *ret=NULL;
110 ASN1_CTX c;
115 111
116 M_ASN1_New_Malloc(ret,X509_PKEY); 112 M_ASN1_New_Malloc(ret,X509_PKEY);
117 ret->version=0; 113 ret->version=0;
@@ -128,8 +124,7 @@ X509_PKEY *X509_PKEY_new()
128 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); 124 M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW);
129 } 125 }
130 126
131void X509_PKEY_free(x) 127void X509_PKEY_free(X509_PKEY *x)
132X509_PKEY *x;
133 { 128 {
134 int i; 129 int i;
135 130
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
62 63
63/* 64int i2d_X509_PUBKEY(X509_PUBKEY *a, unsigned char **pp)
64 * ASN1err(ASN1_F_D2I_X509_PUBKEY,ASN1_R_LENGTH_MISMATCH);
65 * ASN1err(ASN1_F_X509_PUBKEY_NEW,ASN1_R_LENGTH_MISMATCH);
66 */
67
68int i2d_X509_PUBKEY(a,pp)
69X509_PUBKEY *a;
70unsigned char **pp;
71 { 65 {
72 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
73 67
@@ -82,10 +76,8 @@ unsigned char **pp;
82 M_ASN1_I2D_finish(); 76 M_ASN1_I2D_finish();
83 } 77 }
84 78
85X509_PUBKEY *d2i_X509_PUBKEY(a,pp,length) 79X509_PUBKEY *d2i_X509_PUBKEY(X509_PUBKEY **a, unsigned char **pp,
86X509_PUBKEY **a; 80 long length)
87unsigned char **pp;
88long length;
89 { 81 {
90 M_ASN1_D2I_vars(a,X509_PUBKEY *,X509_PUBKEY_new); 82 M_ASN1_D2I_vars(a,X509_PUBKEY *,X509_PUBKEY_new);
91 83
@@ -101,9 +93,10 @@ long length;
101 M_ASN1_D2I_Finish(a,X509_PUBKEY_free,ASN1_F_D2I_X509_PUBKEY); 93 M_ASN1_D2I_Finish(a,X509_PUBKEY_free,ASN1_F_D2I_X509_PUBKEY);
102 } 94 }
103 95
104X509_PUBKEY *X509_PUBKEY_new() 96X509_PUBKEY *X509_PUBKEY_new(void)
105 { 97 {
106 X509_PUBKEY *ret=NULL; 98 X509_PUBKEY *ret=NULL;
99 ASN1_CTX c;
107 100
108 M_ASN1_New_Malloc(ret,X509_PUBKEY); 101 M_ASN1_New_Malloc(ret,X509_PUBKEY);
109 M_ASN1_New(ret->algor,X509_ALGOR_new); 102 M_ASN1_New(ret->algor,X509_ALGOR_new);
@@ -113,8 +106,7 @@ X509_PUBKEY *X509_PUBKEY_new()
113 M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW); 106 M_ASN1_New_Error(ASN1_F_X509_PUBKEY_NEW);
114 } 107 }
115 108
116void X509_PUBKEY_free(a) 109void X509_PUBKEY_free(X509_PUBKEY *a)
117X509_PUBKEY *a;
118 { 110 {
119 if (a == NULL) return; 111 if (a == NULL) return;
120 X509_ALGOR_free(a->algor); 112 X509_ALGOR_free(a->algor);
@@ -123,9 +115,7 @@ X509_PUBKEY *a;
123 Free((char *)a); 115 Free((char *)a);
124 } 116 }
125 117
126int X509_PUBKEY_set(x,pkey) 118int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
127X509_PUBKEY **x;
128EVP_PKEY *pkey;
129 { 119 {
130 int ok=0; 120 int ok=0;
131 X509_PUBKEY *pk; 121 X509_PUBKEY *pk;
@@ -182,11 +172,15 @@ EVP_PKEY *pkey;
182 goto err; 172 goto err;
183 } 173 }
184 174
185 i=i2d_PublicKey(pkey,NULL); 175 if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
186 if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err; 176 if ((s=(unsigned char *)Malloc(i+1)) == NULL) goto err;
187 p=s; 177 p=s;
188 i2d_PublicKey(pkey,&p); 178 i2d_PublicKey(pkey,&p);
189 if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err; 179 if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
180 /* Set number of unused bits to zero */
181 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
182 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
183
190 Free(s); 184 Free(s);
191 185
192 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); 186 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
@@ -204,8 +198,7 @@ err:
204 return(ok); 198 return(ok);
205 } 199 }
206 200
207EVP_PKEY *X509_PUBKEY_get(key) 201EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
208X509_PUBKEY *key;
209 { 202 {
210 EVP_PKEY *ret=NULL; 203 EVP_PKEY *ret=NULL;
211 long j; 204 long j;
@@ -217,7 +210,11 @@ X509_PUBKEY *key;
217 210
218 if (key == NULL) goto err; 211 if (key == NULL) goto err;
219 212
220 if (key->pkey != NULL) return(key->pkey); 213 if (key->pkey != NULL)
214 {
215 CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
216 return(key->pkey);
217 }
221 218
222 if (key->public_key == NULL) goto err; 219 if (key->public_key == NULL) goto err;
223 220
@@ -247,6 +244,7 @@ X509_PUBKEY *key;
247 } 244 }
248#endif 245#endif
249 key->pkey=ret; 246 key->pkey=ret;
247 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
250 return(ret); 248 return(ret);
251err: 249err:
252 if (ret != NULL) 250 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "x509.h" 62#include <openssl/x509.h>
63
64/*
65 * ASN1err(ASN1_F_D2I_X509_REQ,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_D2I_X509_REQ_INFO,ASN1_R_LENGTH_MISMATCH);
67 * ASN1err(ASN1_F_X509_REQ_NEW,ASN1_R_LENGTH_MISMATCH);
68 * ASN1err(ASN1_F_X509_REQ_INFO_NEW,ASN1_R_LENGTH_MISMATCH);
69 */
70 63
71int i2d_X509_REQ_INFO(a,pp) 64int i2d_X509_REQ_INFO(X509_REQ_INFO *a, unsigned char **pp)
72X509_REQ_INFO *a;
73unsigned char **pp;
74 { 65 {
75 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
76 67
@@ -87,11 +78,12 @@ unsigned char **pp;
87 */ 78 */
88 if (a->req_kludge) 79 if (a->req_kludge)
89 { 80 {
90 M_ASN1_I2D_len_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0); 81 M_ASN1_I2D_len_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,i2d_X509_ATTRIBUTE,0);
91 } 82 }
92 else 83 else
93 { 84 {
94 M_ASN1_I2D_len_IMP_set(a->attributes, i2d_X509_ATTRIBUTE,0); 85 M_ASN1_I2D_len_IMP_SET_type(X509_ATTRIBUTE,a->attributes,
86 i2d_X509_ATTRIBUTE,0);
95 } 87 }
96 88
97 M_ASN1_I2D_seq_total(); 89 M_ASN1_I2D_seq_total();
@@ -107,20 +99,20 @@ unsigned char **pp;
107 */ 99 */
108 if (a->req_kludge) 100 if (a->req_kludge)
109 { 101 {
110 M_ASN1_I2D_put_IMP_set_opt(a->attributes,i2d_X509_ATTRIBUTE,0); 102 M_ASN1_I2D_put_IMP_SET_opt_type(X509_ATTRIBUTE,a->attributes,
103 i2d_X509_ATTRIBUTE,0);
111 } 104 }
112 else 105 else
113 { 106 {
114 M_ASN1_I2D_put_IMP_set(a->attributes,i2d_X509_ATTRIBUTE,0); 107 M_ASN1_I2D_put_IMP_SET_type(X509_ATTRIBUTE,a->attributes,
108 i2d_X509_ATTRIBUTE,0);
115 } 109 }
116 110
117 M_ASN1_I2D_finish(); 111 M_ASN1_I2D_finish();
118 } 112 }
119 113
120X509_REQ_INFO *d2i_X509_REQ_INFO(a,pp,length) 114X509_REQ_INFO *d2i_X509_REQ_INFO(X509_REQ_INFO **a, unsigned char **pp,
121X509_REQ_INFO **a; 115 long length)
122unsigned char **pp;
123long length;
124 { 116 {
125 M_ASN1_D2I_vars(a,X509_REQ_INFO *,X509_REQ_INFO_new); 117 M_ASN1_D2I_vars(a,X509_REQ_INFO *,X509_REQ_INFO_new);
126 118
@@ -141,40 +133,40 @@ long length;
141 ret->req_kludge=1; 133 ret->req_kludge=1;
142 else 134 else
143 { 135 {
144 M_ASN1_D2I_get_IMP_set(ret->attributes,d2i_X509_ATTRIBUTE,0); 136 M_ASN1_D2I_get_IMP_set_type(X509_ATTRIBUTE,ret->attributes,
137 d2i_X509_ATTRIBUTE,
138 X509_ATTRIBUTE_free,0);
145 } 139 }
146 140
147 M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO); 141 M_ASN1_D2I_Finish(a,X509_REQ_INFO_free,ASN1_F_D2I_X509_REQ_INFO);
148 } 142 }
149 143
150X509_REQ_INFO *X509_REQ_INFO_new() 144X509_REQ_INFO *X509_REQ_INFO_new(void)
151 { 145 {
152 X509_REQ_INFO *ret=NULL; 146 X509_REQ_INFO *ret=NULL;
147 ASN1_CTX c;
153 148
154 M_ASN1_New_Malloc(ret,X509_REQ_INFO); 149 M_ASN1_New_Malloc(ret,X509_REQ_INFO);
155 M_ASN1_New(ret->version,ASN1_INTEGER_new); 150 M_ASN1_New(ret->version,ASN1_INTEGER_new);
156 M_ASN1_New(ret->subject,X509_NAME_new); 151 M_ASN1_New(ret->subject,X509_NAME_new);
157 M_ASN1_New(ret->pubkey,X509_PUBKEY_new); 152 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
158 M_ASN1_New(ret->attributes,sk_new_null); 153 M_ASN1_New(ret->attributes,sk_X509_ATTRIBUTE_new_null);
159 ret->req_kludge=0; 154 ret->req_kludge=0;
160 return(ret); 155 return(ret);
161 M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW); 156 M_ASN1_New_Error(ASN1_F_X509_REQ_INFO_NEW);
162 } 157 }
163 158
164void X509_REQ_INFO_free(a) 159void X509_REQ_INFO_free(X509_REQ_INFO *a)
165X509_REQ_INFO *a;
166 { 160 {
167 if (a == NULL) return; 161 if (a == NULL) return;
168 ASN1_INTEGER_free(a->version); 162 ASN1_INTEGER_free(a->version);
169 X509_NAME_free(a->subject); 163 X509_NAME_free(a->subject);
170 X509_PUBKEY_free(a->pubkey); 164 X509_PUBKEY_free(a->pubkey);
171 sk_pop_free(a->attributes,X509_ATTRIBUTE_free); 165 sk_X509_ATTRIBUTE_pop_free(a->attributes,X509_ATTRIBUTE_free);
172 Free((char *)a); 166 Free((char *)a);
173 } 167 }
174 168
175int i2d_X509_REQ(a,pp) 169int i2d_X509_REQ(X509_REQ *a, unsigned char **pp)
176X509_REQ *a;
177unsigned char **pp;
178 { 170 {
179 M_ASN1_I2D_vars(a); 171 M_ASN1_I2D_vars(a);
180 M_ASN1_I2D_len(a->req_info, i2d_X509_REQ_INFO); 172 M_ASN1_I2D_len(a->req_info, i2d_X509_REQ_INFO);
@@ -190,10 +182,7 @@ unsigned char **pp;
190 M_ASN1_I2D_finish(); 182 M_ASN1_I2D_finish();
191 } 183 }
192 184
193X509_REQ *d2i_X509_REQ(a,pp,length) 185X509_REQ *d2i_X509_REQ(X509_REQ **a, unsigned char **pp, long length)
194X509_REQ **a;
195unsigned char **pp;
196long length;
197 { 186 {
198 M_ASN1_D2I_vars(a,X509_REQ *,X509_REQ_new); 187 M_ASN1_D2I_vars(a,X509_REQ *,X509_REQ_new);
199 188
@@ -205,9 +194,10 @@ long length;
205 M_ASN1_D2I_Finish(a,X509_REQ_free,ASN1_F_D2I_X509_REQ); 194 M_ASN1_D2I_Finish(a,X509_REQ_free,ASN1_F_D2I_X509_REQ);
206 } 195 }
207 196
208X509_REQ *X509_REQ_new() 197X509_REQ *X509_REQ_new(void)
209 { 198 {
210 X509_REQ *ret=NULL; 199 X509_REQ *ret=NULL;
200 ASN1_CTX c;
211 201
212 M_ASN1_New_Malloc(ret,X509_REQ); 202 M_ASN1_New_Malloc(ret,X509_REQ);
213 ret->references=1; 203 ret->references=1;
@@ -218,8 +208,7 @@ X509_REQ *X509_REQ_new()
218 M_ASN1_New_Error(ASN1_F_X509_REQ_NEW); 208 M_ASN1_New_Error(ASN1_F_X509_REQ_NEW);
219 } 209 }
220 210
221void X509_REQ_free(a) 211void X509_REQ_free(X509_REQ *a)
222X509_REQ *a;
223 { 212 {
224 int i; 213 int i;
225 214
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
62 63
63/* 64int i2d_X509_SIG(X509_SIG *a, unsigned char **pp)
64 * ASN1err(ASN1_F_D2I_X509_SIG,ASN1_R_LENGTH_MISMATCH);
65 * ASN1err(ASN1_F_X509_SIG_NEW,ASN1_R_LENGTH_MISMATCH);
66 */
67
68int i2d_X509_SIG(a,pp)
69X509_SIG *a;
70unsigned char **pp;
71 { 65 {
72 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
73 67
@@ -82,10 +76,7 @@ unsigned char **pp;
82 M_ASN1_I2D_finish(); 76 M_ASN1_I2D_finish();
83 } 77 }
84 78
85X509_SIG *d2i_X509_SIG(a,pp,length) 79X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length)
86X509_SIG **a;
87unsigned char **pp;
88long length;
89 { 80 {
90 M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new); 81 M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new);
91 82
@@ -96,9 +87,10 @@ long length;
96 M_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG); 87 M_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG);
97 } 88 }
98 89
99X509_SIG *X509_SIG_new() 90X509_SIG *X509_SIG_new(void)
100 { 91 {
101 X509_SIG *ret=NULL; 92 X509_SIG *ret=NULL;
93 ASN1_CTX c;
102 94
103 M_ASN1_New_Malloc(ret,X509_SIG); 95 M_ASN1_New_Malloc(ret,X509_SIG);
104 M_ASN1_New(ret->algor,X509_ALGOR_new); 96 M_ASN1_New(ret->algor,X509_ALGOR_new);
@@ -107,8 +99,7 @@ X509_SIG *X509_SIG_new()
107 M_ASN1_New_Error(ASN1_F_X509_SIG_NEW); 99 M_ASN1_New_Error(ASN1_F_X509_SIG_NEW);
108 } 100 }
109 101
110void X509_SIG_free(a) 102void X509_SIG_free(X509_SIG *a)
111X509_SIG *a;
112 { 103 {
113 if (a == NULL) return; 104 if (a == NULL) return;
114 X509_ALGOR_free(a->algor); 105 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 @@
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "x509.h" 65#include <openssl/x509.h>
66#include "asn1_mac.h" 66#include <openssl/asn1_mac.h>
67
68/*
69 * ASN1err(ASN1_F_D2I_NETSCAPE_SPKAC,ASN1_R_LENGTH_MISMATCH);
70 * ASN1err(ASN1_F_NETSCAPE_SPKAC_NEW,ASN1_R_LENGTH_MISMATCH);
71 * ASN1err(ASN1_F_D2I_NETSCAPE_SPKI,ASN1_R_LENGTH_MISMATCH);
72 * ASN1err(ASN1_F_NETSCAPE_SPKI_NEW,ASN1_R_LENGTH_MISMATCH);
73 */
74 67
75int i2d_NETSCAPE_SPKAC(a,pp) 68int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a, unsigned char **pp)
76NETSCAPE_SPKAC *a;
77unsigned char **pp;
78 { 69 {
79 M_ASN1_I2D_vars(a); 70 M_ASN1_I2D_vars(a);
80 71
@@ -89,10 +80,8 @@ unsigned char **pp;
89 M_ASN1_I2D_finish(); 80 M_ASN1_I2D_finish();
90 } 81 }
91 82
92NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(a,pp,length) 83NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a, unsigned char **pp,
93NETSCAPE_SPKAC **a; 84 long length)
94unsigned char **pp;
95long length;
96 { 85 {
97 M_ASN1_D2I_vars(a,NETSCAPE_SPKAC *,NETSCAPE_SPKAC_new); 86 M_ASN1_D2I_vars(a,NETSCAPE_SPKAC *,NETSCAPE_SPKAC_new);
98 87
@@ -103,9 +92,10 @@ long length;
103 M_ASN1_D2I_Finish(a,NETSCAPE_SPKAC_free,ASN1_F_D2I_NETSCAPE_SPKAC); 92 M_ASN1_D2I_Finish(a,NETSCAPE_SPKAC_free,ASN1_F_D2I_NETSCAPE_SPKAC);
104 } 93 }
105 94
106NETSCAPE_SPKAC *NETSCAPE_SPKAC_new() 95NETSCAPE_SPKAC *NETSCAPE_SPKAC_new(void)
107 { 96 {
108 NETSCAPE_SPKAC *ret=NULL; 97 NETSCAPE_SPKAC *ret=NULL;
98 ASN1_CTX c;
109 99
110 M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC); 100 M_ASN1_New_Malloc(ret,NETSCAPE_SPKAC);
111 M_ASN1_New(ret->pubkey,X509_PUBKEY_new); 101 M_ASN1_New(ret->pubkey,X509_PUBKEY_new);
@@ -114,8 +104,7 @@ NETSCAPE_SPKAC *NETSCAPE_SPKAC_new()
114 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW); 104 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKAC_NEW);
115 } 105 }
116 106
117void NETSCAPE_SPKAC_free(a) 107void NETSCAPE_SPKAC_free(NETSCAPE_SPKAC *a)
118NETSCAPE_SPKAC *a;
119 { 108 {
120 if (a == NULL) return; 109 if (a == NULL) return;
121 X509_PUBKEY_free(a->pubkey); 110 X509_PUBKEY_free(a->pubkey);
@@ -123,9 +112,7 @@ NETSCAPE_SPKAC *a;
123 Free((char *)a); 112 Free((char *)a);
124 } 113 }
125 114
126int i2d_NETSCAPE_SPKI(a,pp) 115int i2d_NETSCAPE_SPKI(NETSCAPE_SPKI *a, unsigned char **pp)
127NETSCAPE_SPKI *a;
128unsigned char **pp;
129 { 116 {
130 M_ASN1_I2D_vars(a); 117 M_ASN1_I2D_vars(a);
131 118
@@ -142,10 +129,8 @@ unsigned char **pp;
142 M_ASN1_I2D_finish(); 129 M_ASN1_I2D_finish();
143 } 130 }
144 131
145NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(a,pp,length) 132NETSCAPE_SPKI *d2i_NETSCAPE_SPKI(NETSCAPE_SPKI **a, unsigned char **pp,
146NETSCAPE_SPKI **a; 133 long length)
147unsigned char **pp;
148long length;
149 { 134 {
150 M_ASN1_D2I_vars(a,NETSCAPE_SPKI *,NETSCAPE_SPKI_new); 135 M_ASN1_D2I_vars(a,NETSCAPE_SPKI *,NETSCAPE_SPKI_new);
151 136
@@ -157,9 +142,10 @@ long length;
157 M_ASN1_D2I_Finish(a,NETSCAPE_SPKI_free,ASN1_F_D2I_NETSCAPE_SPKI); 142 M_ASN1_D2I_Finish(a,NETSCAPE_SPKI_free,ASN1_F_D2I_NETSCAPE_SPKI);
158 } 143 }
159 144
160NETSCAPE_SPKI *NETSCAPE_SPKI_new() 145NETSCAPE_SPKI *NETSCAPE_SPKI_new(void)
161 { 146 {
162 NETSCAPE_SPKI *ret=NULL; 147 NETSCAPE_SPKI *ret=NULL;
148 ASN1_CTX c;
163 149
164 M_ASN1_New_Malloc(ret,NETSCAPE_SPKI); 150 M_ASN1_New_Malloc(ret,NETSCAPE_SPKI);
165 M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new); 151 M_ASN1_New(ret->spkac,NETSCAPE_SPKAC_new);
@@ -169,8 +155,7 @@ NETSCAPE_SPKI *NETSCAPE_SPKI_new()
169 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW); 155 M_ASN1_New_Error(ASN1_F_NETSCAPE_SPKI_NEW);
170 } 156 }
171 157
172void NETSCAPE_SPKI_free(a) 158void NETSCAPE_SPKI_free(NETSCAPE_SPKI *a)
173NETSCAPE_SPKI *a;
174 { 159 {
175 if (a == NULL) return; 160 if (a == NULL) return;
176 NETSCAPE_SPKAC_free(a->spkac); 161 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
62 63
63/* ASN1err(ASN1_F_X509_VAL_NEW,ERR_R_MALLOC_FAILURE); 64int i2d_X509_VAL(X509_VAL *a, unsigned char **pp)
64 * ASN1err(ASN1_F_X509_VAL_FREE,ERR_R_MALLOC_FAILURE);
65 * ASN1err(ASN1_F_D2I_X509_VAL,ERR_R_MALLOC_FAILURE);
66 */
67
68int i2d_X509_VAL(a,pp)
69X509_VAL *a;
70unsigned char **pp;
71 { 65 {
72 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
73 67
74 M_ASN1_I2D_len(a->notBefore,i2d_ASN1_UTCTIME); 68 M_ASN1_I2D_len(a->notBefore,i2d_ASN1_TIME);
75 M_ASN1_I2D_len(a->notAfter,i2d_ASN1_UTCTIME); 69 M_ASN1_I2D_len(a->notAfter,i2d_ASN1_TIME);
76 70
77 M_ASN1_I2D_seq_total(); 71 M_ASN1_I2D_seq_total();
78 72
79 M_ASN1_I2D_put(a->notBefore,i2d_ASN1_UTCTIME); 73 M_ASN1_I2D_put(a->notBefore,i2d_ASN1_TIME);
80 M_ASN1_I2D_put(a->notAfter,i2d_ASN1_UTCTIME); 74 M_ASN1_I2D_put(a->notAfter,i2d_ASN1_TIME);
81 75
82 M_ASN1_I2D_finish(); 76 M_ASN1_I2D_finish();
83 } 77 }
84 78
85X509_VAL *d2i_X509_VAL(a,pp,length) 79X509_VAL *d2i_X509_VAL(X509_VAL **a, unsigned char **pp, long length)
86X509_VAL **a;
87unsigned char **pp;
88long length;
89 { 80 {
90 M_ASN1_D2I_vars(a,X509_VAL *,X509_VAL_new); 81 M_ASN1_D2I_vars(a,X509_VAL *,X509_VAL_new);
91 82
92 M_ASN1_D2I_Init(); 83 M_ASN1_D2I_Init();
93 M_ASN1_D2I_start_sequence(); 84 M_ASN1_D2I_start_sequence();
94 M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_UTCTIME); 85 M_ASN1_D2I_get(ret->notBefore,d2i_ASN1_TIME);
95 M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_UTCTIME); 86 M_ASN1_D2I_get(ret->notAfter,d2i_ASN1_TIME);
96 M_ASN1_D2I_Finish(a,X509_VAL_free,ASN1_F_D2I_X509_VAL); 87 M_ASN1_D2I_Finish(a,X509_VAL_free,ASN1_F_D2I_X509_VAL);
97 } 88 }
98 89
99X509_VAL *X509_VAL_new() 90X509_VAL *X509_VAL_new(void)
100 { 91 {
101 X509_VAL *ret=NULL; 92 X509_VAL *ret=NULL;
93 ASN1_CTX c;
102 94
103 M_ASN1_New_Malloc(ret,X509_VAL); 95 M_ASN1_New_Malloc(ret,X509_VAL);
104 M_ASN1_New(ret->notBefore,ASN1_UTCTIME_new); 96 M_ASN1_New(ret->notBefore,ASN1_TIME_new);
105 M_ASN1_New(ret->notAfter,ASN1_UTCTIME_new); 97 M_ASN1_New(ret->notAfter,ASN1_TIME_new);
106 return(ret); 98 return(ret);
107 M_ASN1_New_Error(ASN1_F_X509_VAL_NEW); 99 M_ASN1_New_Error(ASN1_F_X509_VAL_NEW);
108 } 100 }
109 101
110void X509_VAL_free(a) 102void X509_VAL_free(X509_VAL *a)
111X509_VAL *a;
112 { 103 {
113 if (a == NULL) return; 104 if (a == NULL) return;
114 ASN1_UTCTIME_free(a->notBefore); 105 ASN1_TIME_free(a->notBefore);
115 ASN1_UTCTIME_free(a->notAfter); 106 ASN1_TIME_free(a->notAfter);
116 Free((char *)a); 107 Free((char *)a);
117 } 108 }
118 109
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "asn1_mac.h" 62#include <openssl/asn1_mac.h>
63 63#include <openssl/x509.h>
64/*
65 * ASN1err(ASN1_F_D2I_X509,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_X509_NEW,ASN1_R_BAD_GET_OBJECT);
67 */
68 64
69static ASN1_METHOD meth={ 65static ASN1_METHOD meth={
70 (int (*)()) i2d_X509, 66 (int (*)()) i2d_X509,
@@ -72,14 +68,12 @@ static ASN1_METHOD meth={
72 (char *(*)())X509_new, 68 (char *(*)())X509_new,
73 (void (*)()) X509_free}; 69 (void (*)()) X509_free};
74 70
75ASN1_METHOD *X509_asn1_meth() 71ASN1_METHOD *X509_asn1_meth(void)
76 { 72 {
77 return(&meth); 73 return(&meth);
78 } 74 }
79 75
80int i2d_X509(a,pp) 76int i2d_X509(X509 *a, unsigned char **pp)
81X509 *a;
82unsigned char **pp;
83 { 77 {
84 M_ASN1_I2D_vars(a); 78 M_ASN1_I2D_vars(a);
85 79
@@ -96,10 +90,7 @@ unsigned char **pp;
96 M_ASN1_I2D_finish(); 90 M_ASN1_I2D_finish();
97 } 91 }
98 92
99X509 *d2i_X509(a,pp,length) 93X509 *d2i_X509(X509 **a, unsigned char **pp, long length)
100X509 **a;
101unsigned char **pp;
102long length;
103 { 94 {
104 M_ASN1_D2I_vars(a,X509 *,X509_new); 95 M_ASN1_D2I_vars(a,X509 *,X509_new);
105 96
@@ -108,15 +99,16 @@ long length;
108 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF); 99 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
109 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR); 100 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
110 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING); 101 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
111if (ret->name != NULL) Free(ret->name); 102 if (ret->name != NULL) Free(ret->name);
112ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); 103 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
113 104
114 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509); 105 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
115 } 106 }
116 107
117X509 *X509_new() 108X509 *X509_new(void)
118 { 109 {
119 X509 *ret=NULL; 110 X509 *ret=NULL;
111 ASN1_CTX c;
120 112
121 M_ASN1_New_Malloc(ret,X509); 113 M_ASN1_New_Malloc(ret,X509);
122 ret->references=1; 114 ret->references=1;
@@ -129,8 +121,7 @@ X509 *X509_new()
129 M_ASN1_New_Error(ASN1_F_X509_NEW); 121 M_ASN1_New_Error(ASN1_F_X509_NEW);
130 } 122 }
131 123
132void X509_free(a) 124void X509_free(X509 *a)
133X509 *a;
134 { 125 {
135 int i; 126 int i;
136 127
@@ -149,9 +140,11 @@ X509 *a;
149 } 140 }
150#endif 141#endif
151 142
143 /* CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); */
152 X509_CINF_free(a->cert_info); 144 X509_CINF_free(a->cert_info);
153 X509_ALGOR_free(a->sig_alg); 145 X509_ALGOR_free(a->sig_alg);
154 ASN1_BIT_STRING_free(a->signature); 146 ASN1_BIT_STRING_free(a->signature);
147
155 if (a->name != NULL) Free(a->name); 148 if (a->name != NULL) Free(a->name);
156 Free((char *)a); 149 Free((char *)a);
157 } 150 }
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
8CPP= $(CC) -E 8CPP= $(CC) -E
9INCLUDES= 9INCLUDES=
10CFLAG=-g 10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
11INSTALLTOP=/usr/local/ssl 13INSTALLTOP=/usr/local/ssl
12MAKE= make -f Makefile.ssl 14MAKE= make -f Makefile.ssl
13MAKEDEPEND= makedepend -f Makefile.ssl 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
14MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
15AR= ar r 17AR= ar r
16 18
@@ -42,7 +44,7 @@ all: lib
42 44
43lib: $(LIBOBJ) 45lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ) 46 $(AR) $(LIB) $(LIBOBJ)
45 sh $(TOP)/util/ranlib.sh $(LIB) 47 $(RANLIB) $(LIB)
46 @touch lib 48 @touch lib
47 49
48# elf 50# elf
@@ -61,27 +63,25 @@ asm/bx86-out.o: asm/bx86unix.cpp
61 63
62# bsdi 64# bsdi
63asm/bx86bsdi.o: asm/bx86unix.cpp 65asm/bx86bsdi.o: asm/bx86unix.cpp
64 $(CPP) -DBSDI asm/bx86unix.cpp | as -o asm/bx86bsdi.o 66 $(CPP) -DBSDI asm/bx86unix.cpp | sed 's/ :/:/' | as -o asm/bx86bsdi.o
65 67
66asm/bx86unix.cpp: 68asm/bx86unix.cpp:
67 (cd asm; perl bf-586.pl cpp >bx86unix.cpp) 69 (cd asm; $(PERL) bf-586.pl cpp $(PROCESSOR) >bx86unix.cpp)
68 70
69files: 71files:
70 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 72 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
71 73
72links: 74links:
73 /bin/rm -f Makefile 75 @$(TOP)/util/point.sh Makefile.ssl Makefile
74 $(TOP)/util/point.sh Makefile.ssl Makefile ; 76 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
75 $(TOP)/util/point.sh ../../doc/blowfish.doc blowfish.doc ; 77 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
76 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 78 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
77 $(TOP)/util/mklink.sh ../../test $(TEST)
78 $(TOP)/util/mklink.sh ../../apps $(APPS)
79 79
80install: 80install:
81 @for i in $(EXHEADER) ; \ 81 @for i in $(EXHEADER) ; \
82 do \ 82 do \
83 (cp $$i $(INSTALLTOP)/include/$$i; \ 83 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
84 chmod 644 $(INSTALLTOP)/include/$$i ); \ 84 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
85 done; 85 done;
86 86
87tags: 87tags:
@@ -93,15 +93,24 @@ lint:
93 lint -DLINT $(INCLUDES) $(SRC)>fluff 93 lint -DLINT $(INCLUDES) $(SRC)>fluff
94 94
95depend: 95depend:
96 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 96 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
97 97
98dclean: 98dclean:
99 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 99 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
100 mv -f Makefile.new $(MAKEFILE) 100 mv -f Makefile.new $(MAKEFILE)
101 101
102clean: 102clean:
103 /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 103 rm -f asm/bx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
104
105errors:
106 104
107# DO NOT DELETE THIS LINE -- make depend depends on it. 105# DO NOT DELETE THIS LINE -- make depend depends on it.
106
107bf_cfb64.o: ../../include/openssl/blowfish.h
108bf_cfb64.o: ../../include/openssl/opensslconf.h bf_locl.h
109bf_ecb.o: ../../include/openssl/blowfish.h ../../include/openssl/opensslconf.h
110bf_ecb.o: ../../include/openssl/opensslv.h bf_locl.h
111bf_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/opensslconf.h
112bf_enc.o: bf_locl.h
113bf_ofb64.o: ../../include/openssl/blowfish.h
114bf_ofb64.o: ../../include/openssl/opensslconf.h bf_locl.h
115bf_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/opensslconf.h
116bf_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
29CFLAGS=$(OPTS) $(CFLAG) 29CFLAGS=$(OPTS) $(CFLAG)
30CPP=$(CC) -E 30CPP=$(CC) -E
31AS=as 31AS=as
32RANLIB=ranlib
32 33
33# Assember version of bf_encrypt(). 34# Assember version of bf_encrypt().
34BF_ENC=bf_enc.o # normal C version 35BF_ENC=bf_enc.o # normal C version
@@ -105,9 +106,7 @@ test: all
105$(BLIB): $(LIBOBJ) 106$(BLIB): $(LIBOBJ)
106 /bin/rm -f $(BLIB) 107 /bin/rm -f $(BLIB)
107 ar cr $(BLIB) $(LIBOBJ) 108 ar cr $(BLIB) $(LIBOBJ)
108 -if test -s /bin/ranlib; then /bin/ranlib $(BLIB); \ 109 $(RANLIB) $(BLIB)
109 else if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(BLIB); \
110 else exit 0; fi; fi
111 110
112bftest: bftest.o $(BLIB) 111bftest: bftest.o $(BLIB)
113 $(CC) $(CFLAGS) -o bftest bftest.o $(BLIB) 112 $(CC) $(CFLAGS) -o bftest bftest.o $(BLIB)
@@ -142,25 +141,14 @@ install: $(BLIB)
142 if test $(INSTALLTOP); then \ 141 if test $(INSTALLTOP); then \
143 echo SSL style install; \ 142 echo SSL style install; \
144 cp $(BLIB) $(INSTALLTOP)/lib; \ 143 cp $(BLIB) $(INSTALLTOP)/lib; \
145 if test -s /bin/ranlib; then \ 144 $(RANLIB) $(BLIB); \
146 /bin/ranlib $(INSTALLTOP)/lib/$(BLIB); \
147 else \
148 if test -s /usr/bin/ranlib; then \
149 /usr/bin/ranlib $(INSTALLTOP)/lib/$(BLIB); \
150 fi; fi; \
151 chmod 644 $(INSTALLTOP)/lib/$(BLIB); \ 145 chmod 644 $(INSTALLTOP)/lib/$(BLIB); \
152 cp blowfish.h $(INSTALLTOP)/include; \ 146 cp blowfish.h $(INSTALLTOP)/include; \
153 chmod 644 $(INSTALLTOP)/include/blowfish.h; \ 147 chmod 644 $(INSTALLTOP)/include/blowfish.h; \
154 else \ 148 else \
155 echo Standalone install; \ 149 echo Standalone install; \
156 cp $(BLIB) $(LIBDIR)/$(BLIB); \ 150 cp $(BLIB) $(LIBDIR)/$(BLIB); \
157 if test -s /bin/ranlib; then \ 151 $(RANLIB) $(BLIB); \
158 /bin/ranlib $(LIBDIR)/$(BLIB); \
159 else \
160 if test -s /usr/bin/ranlib; then \
161 /usr/bin/ranlib $(LIBDIR)/$(BLIB); \
162 fi; \
163 fi; \
164 chmod 644 $(LIBDIR)/$(BLIB); \ 152 chmod 644 $(LIBDIR)/$(BLIB); \
165 cp blowfish.h $(INCDIR)/blowfish.h; \ 153 cp blowfish.h $(INCDIR)/blowfish.h; \
166 chmod 644 $(INCDIR)/blowfish.h; \ 154 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3push(@INC,"perlasm","../../perlasm"); 3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl"; 4require "x86asm.pl";
5require "cbc.pl"; 5require "cbc.pl";
6 6
7&asm_init($ARGV[0],"bf-586.pl"); 7&asm_init($ARGV[0],"bf-586.pl",$ARGV[$#ARGV] eq "386");
8 8
9$BF_ROUNDS=16; 9$BF_ROUNDS=16;
10$BF_OFF=($BF_ROUNDS+2)*4; 10$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 @@
1#!/usr/bin/perl
2#!/usr/local/bin/perl 1#!/usr/local/bin/perl
3 2
4push(@INC,"perlasm","../../perlasm"); 3push(@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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define BF_encrypt _BF_encrypt
13#define BF_decrypt _BF_decrypt
14#define BF_cbc_encrypt _BF_cbc_encrypt
15
16#endif
17
18#ifdef OUT
19#define OK 1
20#define ALIGN 4
21#endif
22
23#ifdef BSDI
24#define OK 1
25#define ALIGN 4
26#undef SIZE
27#undef TYPE
28#define SIZE(a,b)
29#define TYPE(a,b)
30#endif
31
32#if defined(ELF) || defined(SOL)
33#define OK 1
34#define ALIGN 16
35#endif
36
37#ifndef OK
38You need to define one of
39ELF - elf systems - linux-elf, NetBSD and DG-UX
40OUT - a.out systems - linux-a.out and FreeBSD
41SOL - solaris systems, which are elf with strange comment lines
42BSDI - a.out with a very primative version of as.
43#endif
44
45/* Let the Assembler begin :-) */
46 /* Don't even think of reading this code */
47 /* It was automatically generated by bf-586.pl */
48 /* Which is a perl program used to generate the x86 assember for */
49 /* any of elf, a.out, BSDI,Win32, or Solaris */
50 /* eric <eay@cryptsoft.com> */
51
52 .file "bf-586.s"
53 .version "01.01"
54gcc2_compiled.:
55.text
56 .align ALIGN
57.globl BF_encrypt
58 TYPE(BF_encrypt,@function)
59BF_encrypt:
60
61 pushl %ebp
62 pushl %ebx
63 movl 12(%esp), %ebx
64 movl 16(%esp), %ebp
65 pushl %esi
66 pushl %edi
67 /* Load the 2 words */
68 movl (%ebx), %edi
69 movl 4(%ebx), %esi
70 xorl %eax, %eax
71 movl (%ebp), %ebx
72 xorl %ecx, %ecx
73 xorl %ebx, %edi
74
75 /* Round 0 */
76 movl 4(%ebp), %edx
77 movl %edi, %ebx
78 xorl %edx, %esi
79 shrl $16, %ebx
80 movl %edi, %edx
81 movb %bh, %al
82 andl $255, %ebx
83 movb %dh, %cl
84 andl $255, %edx
85 movl 72(%ebp,%eax,4),%eax
86 movl 1096(%ebp,%ebx,4),%ebx
87 addl %eax, %ebx
88 movl 2120(%ebp,%ecx,4),%eax
89 xorl %eax, %ebx
90 movl 3144(%ebp,%edx,4),%edx
91 addl %edx, %ebx
92 xorl %eax, %eax
93 xorl %ebx, %esi
94
95 /* Round 1 */
96 movl 8(%ebp), %edx
97 movl %esi, %ebx
98 xorl %edx, %edi
99 shrl $16, %ebx
100 movl %esi, %edx
101 movb %bh, %al
102 andl $255, %ebx
103 movb %dh, %cl
104 andl $255, %edx
105 movl 72(%ebp,%eax,4),%eax
106 movl 1096(%ebp,%ebx,4),%ebx
107 addl %eax, %ebx
108 movl 2120(%ebp,%ecx,4),%eax
109 xorl %eax, %ebx
110 movl 3144(%ebp,%edx,4),%edx
111 addl %edx, %ebx
112 xorl %eax, %eax
113 xorl %ebx, %edi
114
115 /* Round 2 */
116 movl 12(%ebp), %edx
117 movl %edi, %ebx
118 xorl %edx, %esi
119 shrl $16, %ebx
120 movl %edi, %edx
121 movb %bh, %al
122 andl $255, %ebx
123 movb %dh, %cl
124 andl $255, %edx
125 movl 72(%ebp,%eax,4),%eax
126 movl 1096(%ebp,%ebx,4),%ebx
127 addl %eax, %ebx
128 movl 2120(%ebp,%ecx,4),%eax
129 xorl %eax, %ebx
130 movl 3144(%ebp,%edx,4),%edx
131 addl %edx, %ebx
132 xorl %eax, %eax
133 xorl %ebx, %esi
134
135 /* Round 3 */
136 movl 16(%ebp), %edx
137 movl %esi, %ebx
138 xorl %edx, %edi
139 shrl $16, %ebx
140 movl %esi, %edx
141 movb %bh, %al
142 andl $255, %ebx
143 movb %dh, %cl
144 andl $255, %edx
145 movl 72(%ebp,%eax,4),%eax
146 movl 1096(%ebp,%ebx,4),%ebx
147 addl %eax, %ebx
148 movl 2120(%ebp,%ecx,4),%eax
149 xorl %eax, %ebx
150 movl 3144(%ebp,%edx,4),%edx
151 addl %edx, %ebx
152 xorl %eax, %eax
153 xorl %ebx, %edi
154
155 /* Round 4 */
156 movl 20(%ebp), %edx
157 movl %edi, %ebx
158 xorl %edx, %esi
159 shrl $16, %ebx
160 movl %edi, %edx
161 movb %bh, %al
162 andl $255, %ebx
163 movb %dh, %cl
164 andl $255, %edx
165 movl 72(%ebp,%eax,4),%eax
166 movl 1096(%ebp,%ebx,4),%ebx
167 addl %eax, %ebx
168 movl 2120(%ebp,%ecx,4),%eax
169 xorl %eax, %ebx
170 movl 3144(%ebp,%edx,4),%edx
171 addl %edx, %ebx
172 xorl %eax, %eax
173 xorl %ebx, %esi
174
175 /* Round 5 */
176 movl 24(%ebp), %edx
177 movl %esi, %ebx
178 xorl %edx, %edi
179 shrl $16, %ebx
180 movl %esi, %edx
181 movb %bh, %al
182 andl $255, %ebx
183 movb %dh, %cl
184 andl $255, %edx
185 movl 72(%ebp,%eax,4),%eax
186 movl 1096(%ebp,%ebx,4),%ebx
187 addl %eax, %ebx
188 movl 2120(%ebp,%ecx,4),%eax
189 xorl %eax, %ebx
190 movl 3144(%ebp,%edx,4),%edx
191 addl %edx, %ebx
192 xorl %eax, %eax
193 xorl %ebx, %edi
194
195 /* Round 6 */
196 movl 28(%ebp), %edx
197 movl %edi, %ebx
198 xorl %edx, %esi
199 shrl $16, %ebx
200 movl %edi, %edx
201 movb %bh, %al
202 andl $255, %ebx
203 movb %dh, %cl
204 andl $255, %edx
205 movl 72(%ebp,%eax,4),%eax
206 movl 1096(%ebp,%ebx,4),%ebx
207 addl %eax, %ebx
208 movl 2120(%ebp,%ecx,4),%eax
209 xorl %eax, %ebx
210 movl 3144(%ebp,%edx,4),%edx
211 addl %edx, %ebx
212 xorl %eax, %eax
213 xorl %ebx, %esi
214
215 /* Round 7 */
216 movl 32(%ebp), %edx
217 movl %esi, %ebx
218 xorl %edx, %edi
219 shrl $16, %ebx
220 movl %esi, %edx
221 movb %bh, %al
222 andl $255, %ebx
223 movb %dh, %cl
224 andl $255, %edx
225 movl 72(%ebp,%eax,4),%eax
226 movl 1096(%ebp,%ebx,4),%ebx
227 addl %eax, %ebx
228 movl 2120(%ebp,%ecx,4),%eax
229 xorl %eax, %ebx
230 movl 3144(%ebp,%edx,4),%edx
231 addl %edx, %ebx
232 xorl %eax, %eax
233 xorl %ebx, %edi
234
235 /* Round 8 */
236 movl 36(%ebp), %edx
237 movl %edi, %ebx
238 xorl %edx, %esi
239 shrl $16, %ebx
240 movl %edi, %edx
241 movb %bh, %al
242 andl $255, %ebx
243 movb %dh, %cl
244 andl $255, %edx
245 movl 72(%ebp,%eax,4),%eax
246 movl 1096(%ebp,%ebx,4),%ebx
247 addl %eax, %ebx
248 movl 2120(%ebp,%ecx,4),%eax
249 xorl %eax, %ebx
250 movl 3144(%ebp,%edx,4),%edx
251 addl %edx, %ebx
252 xorl %eax, %eax
253 xorl %ebx, %esi
254
255 /* Round 9 */
256 movl 40(%ebp), %edx
257 movl %esi, %ebx
258 xorl %edx, %edi
259 shrl $16, %ebx
260 movl %esi, %edx
261 movb %bh, %al
262 andl $255, %ebx
263 movb %dh, %cl
264 andl $255, %edx
265 movl 72(%ebp,%eax,4),%eax
266 movl 1096(%ebp,%ebx,4),%ebx
267 addl %eax, %ebx
268 movl 2120(%ebp,%ecx,4),%eax
269 xorl %eax, %ebx
270 movl 3144(%ebp,%edx,4),%edx
271 addl %edx, %ebx
272 xorl %eax, %eax
273 xorl %ebx, %edi
274
275 /* Round 10 */
276 movl 44(%ebp), %edx
277 movl %edi, %ebx
278 xorl %edx, %esi
279 shrl $16, %ebx
280 movl %edi, %edx
281 movb %bh, %al
282 andl $255, %ebx
283 movb %dh, %cl
284 andl $255, %edx
285 movl 72(%ebp,%eax,4),%eax
286 movl 1096(%ebp,%ebx,4),%ebx
287 addl %eax, %ebx
288 movl 2120(%ebp,%ecx,4),%eax
289 xorl %eax, %ebx
290 movl 3144(%ebp,%edx,4),%edx
291 addl %edx, %ebx
292 xorl %eax, %eax
293 xorl %ebx, %esi
294
295 /* Round 11 */
296 movl 48(%ebp), %edx
297 movl %esi, %ebx
298 xorl %edx, %edi
299 shrl $16, %ebx
300 movl %esi, %edx
301 movb %bh, %al
302 andl $255, %ebx
303 movb %dh, %cl
304 andl $255, %edx
305 movl 72(%ebp,%eax,4),%eax
306 movl 1096(%ebp,%ebx,4),%ebx
307 addl %eax, %ebx
308 movl 2120(%ebp,%ecx,4),%eax
309 xorl %eax, %ebx
310 movl 3144(%ebp,%edx,4),%edx
311 addl %edx, %ebx
312 xorl %eax, %eax
313 xorl %ebx, %edi
314
315 /* Round 12 */
316 movl 52(%ebp), %edx
317 movl %edi, %ebx
318 xorl %edx, %esi
319 shrl $16, %ebx
320 movl %edi, %edx
321 movb %bh, %al
322 andl $255, %ebx
323 movb %dh, %cl
324 andl $255, %edx
325 movl 72(%ebp,%eax,4),%eax
326 movl 1096(%ebp,%ebx,4),%ebx
327 addl %eax, %ebx
328 movl 2120(%ebp,%ecx,4),%eax
329 xorl %eax, %ebx
330 movl 3144(%ebp,%edx,4),%edx
331 addl %edx, %ebx
332 xorl %eax, %eax
333 xorl %ebx, %esi
334
335 /* Round 13 */
336 movl 56(%ebp), %edx
337 movl %esi, %ebx
338 xorl %edx, %edi
339 shrl $16, %ebx
340 movl %esi, %edx
341 movb %bh, %al
342 andl $255, %ebx
343 movb %dh, %cl
344 andl $255, %edx
345 movl 72(%ebp,%eax,4),%eax
346 movl 1096(%ebp,%ebx,4),%ebx
347 addl %eax, %ebx
348 movl 2120(%ebp,%ecx,4),%eax
349 xorl %eax, %ebx
350 movl 3144(%ebp,%edx,4),%edx
351 addl %edx, %ebx
352 xorl %eax, %eax
353 xorl %ebx, %edi
354
355 /* Round 14 */
356 movl 60(%ebp), %edx
357 movl %edi, %ebx
358 xorl %edx, %esi
359 shrl $16, %ebx
360 movl %edi, %edx
361 movb %bh, %al
362 andl $255, %ebx
363 movb %dh, %cl
364 andl $255, %edx
365 movl 72(%ebp,%eax,4),%eax
366 movl 1096(%ebp,%ebx,4),%ebx
367 addl %eax, %ebx
368 movl 2120(%ebp,%ecx,4),%eax
369 xorl %eax, %ebx
370 movl 3144(%ebp,%edx,4),%edx
371 addl %edx, %ebx
372 xorl %eax, %eax
373 xorl %ebx, %esi
374
375 /* Round 15 */
376 movl 64(%ebp), %edx
377 movl %esi, %ebx
378 xorl %edx, %edi
379 shrl $16, %ebx
380 movl %esi, %edx
381 movb %bh, %al
382 andl $255, %ebx
383 movb %dh, %cl
384 andl $255, %edx
385 movl 72(%ebp,%eax,4),%eax
386 movl 1096(%ebp,%ebx,4),%ebx
387 addl %eax, %ebx
388 movl 2120(%ebp,%ecx,4),%eax
389 xorl %eax, %ebx
390 movl 3144(%ebp,%edx,4),%edx
391 addl %edx, %ebx
392 /* Load parameter 0 (16) enc=1 */
393 movl 20(%esp), %eax
394 xorl %ebx, %edi
395 movl 68(%ebp), %edx
396 xorl %edx, %esi
397 movl %edi, 4(%eax)
398 movl %esi, (%eax)
399 popl %edi
400 popl %esi
401 popl %ebx
402 popl %ebp
403 ret
404.BF_encrypt_end:
405 SIZE(BF_encrypt,.BF_encrypt_end-BF_encrypt)
406.ident "BF_encrypt"
407.text
408 .align ALIGN
409.globl BF_decrypt
410 TYPE(BF_decrypt,@function)
411BF_decrypt:
412
413 pushl %ebp
414 pushl %ebx
415 movl 12(%esp), %ebx
416 movl 16(%esp), %ebp
417 pushl %esi
418 pushl %edi
419 /* Load the 2 words */
420 movl (%ebx), %edi
421 movl 4(%ebx), %esi
422 xorl %eax, %eax
423 movl 68(%ebp), %ebx
424 xorl %ecx, %ecx
425 xorl %ebx, %edi
426
427 /* Round 16 */
428 movl 64(%ebp), %edx
429 movl %edi, %ebx
430 xorl %edx, %esi
431 shrl $16, %ebx
432 movl %edi, %edx
433 movb %bh, %al
434 andl $255, %ebx
435 movb %dh, %cl
436 andl $255, %edx
437 movl 72(%ebp,%eax,4),%eax
438 movl 1096(%ebp,%ebx,4),%ebx
439 addl %eax, %ebx
440 movl 2120(%ebp,%ecx,4),%eax
441 xorl %eax, %ebx
442 movl 3144(%ebp,%edx,4),%edx
443 addl %edx, %ebx
444 xorl %eax, %eax
445 xorl %ebx, %esi
446
447 /* Round 15 */
448 movl 60(%ebp), %edx
449 movl %esi, %ebx
450 xorl %edx, %edi
451 shrl $16, %ebx
452 movl %esi, %edx
453 movb %bh, %al
454 andl $255, %ebx
455 movb %dh, %cl
456 andl $255, %edx
457 movl 72(%ebp,%eax,4),%eax
458 movl 1096(%ebp,%ebx,4),%ebx
459 addl %eax, %ebx
460 movl 2120(%ebp,%ecx,4),%eax
461 xorl %eax, %ebx
462 movl 3144(%ebp,%edx,4),%edx
463 addl %edx, %ebx
464 xorl %eax, %eax
465 xorl %ebx, %edi
466
467 /* Round 14 */
468 movl 56(%ebp), %edx
469 movl %edi, %ebx
470 xorl %edx, %esi
471 shrl $16, %ebx
472 movl %edi, %edx
473 movb %bh, %al
474 andl $255, %ebx
475 movb %dh, %cl
476 andl $255, %edx
477 movl 72(%ebp,%eax,4),%eax
478 movl 1096(%ebp,%ebx,4),%ebx
479 addl %eax, %ebx
480 movl 2120(%ebp,%ecx,4),%eax
481 xorl %eax, %ebx
482 movl 3144(%ebp,%edx,4),%edx
483 addl %edx, %ebx
484 xorl %eax, %eax
485 xorl %ebx, %esi
486
487 /* Round 13 */
488 movl 52(%ebp), %edx
489 movl %esi, %ebx
490 xorl %edx, %edi
491 shrl $16, %ebx
492 movl %esi, %edx
493 movb %bh, %al
494 andl $255, %ebx
495 movb %dh, %cl
496 andl $255, %edx
497 movl 72(%ebp,%eax,4),%eax
498 movl 1096(%ebp,%ebx,4),%ebx
499 addl %eax, %ebx
500 movl 2120(%ebp,%ecx,4),%eax
501 xorl %eax, %ebx
502 movl 3144(%ebp,%edx,4),%edx
503 addl %edx, %ebx
504 xorl %eax, %eax
505 xorl %ebx, %edi
506
507 /* Round 12 */
508 movl 48(%ebp), %edx
509 movl %edi, %ebx
510 xorl %edx, %esi
511 shrl $16, %ebx
512 movl %edi, %edx
513 movb %bh, %al
514 andl $255, %ebx
515 movb %dh, %cl
516 andl $255, %edx
517 movl 72(%ebp,%eax,4),%eax
518 movl 1096(%ebp,%ebx,4),%ebx
519 addl %eax, %ebx
520 movl 2120(%ebp,%ecx,4),%eax
521 xorl %eax, %ebx
522 movl 3144(%ebp,%edx,4),%edx
523 addl %edx, %ebx
524 xorl %eax, %eax
525 xorl %ebx, %esi
526
527 /* Round 11 */
528 movl 44(%ebp), %edx
529 movl %esi, %ebx
530 xorl %edx, %edi
531 shrl $16, %ebx
532 movl %esi, %edx
533 movb %bh, %al
534 andl $255, %ebx
535 movb %dh, %cl
536 andl $255, %edx
537 movl 72(%ebp,%eax,4),%eax
538 movl 1096(%ebp,%ebx,4),%ebx
539 addl %eax, %ebx
540 movl 2120(%ebp,%ecx,4),%eax
541 xorl %eax, %ebx
542 movl 3144(%ebp,%edx,4),%edx
543 addl %edx, %ebx
544 xorl %eax, %eax
545 xorl %ebx, %edi
546
547 /* Round 10 */
548 movl 40(%ebp), %edx
549 movl %edi, %ebx
550 xorl %edx, %esi
551 shrl $16, %ebx
552 movl %edi, %edx
553 movb %bh, %al
554 andl $255, %ebx
555 movb %dh, %cl
556 andl $255, %edx
557 movl 72(%ebp,%eax,4),%eax
558 movl 1096(%ebp,%ebx,4),%ebx
559 addl %eax, %ebx
560 movl 2120(%ebp,%ecx,4),%eax
561 xorl %eax, %ebx
562 movl 3144(%ebp,%edx,4),%edx
563 addl %edx, %ebx
564 xorl %eax, %eax
565 xorl %ebx, %esi
566
567 /* Round 9 */
568 movl 36(%ebp), %edx
569 movl %esi, %ebx
570 xorl %edx, %edi
571 shrl $16, %ebx
572 movl %esi, %edx
573 movb %bh, %al
574 andl $255, %ebx
575 movb %dh, %cl
576 andl $255, %edx
577 movl 72(%ebp,%eax,4),%eax
578 movl 1096(%ebp,%ebx,4),%ebx
579 addl %eax, %ebx
580 movl 2120(%ebp,%ecx,4),%eax
581 xorl %eax, %ebx
582 movl 3144(%ebp,%edx,4),%edx
583 addl %edx, %ebx
584 xorl %eax, %eax
585 xorl %ebx, %edi
586
587 /* Round 8 */
588 movl 32(%ebp), %edx
589 movl %edi, %ebx
590 xorl %edx, %esi
591 shrl $16, %ebx
592 movl %edi, %edx
593 movb %bh, %al
594 andl $255, %ebx
595 movb %dh, %cl
596 andl $255, %edx
597 movl 72(%ebp,%eax,4),%eax
598 movl 1096(%ebp,%ebx,4),%ebx
599 addl %eax, %ebx
600 movl 2120(%ebp,%ecx,4),%eax
601 xorl %eax, %ebx
602 movl 3144(%ebp,%edx,4),%edx
603 addl %edx, %ebx
604 xorl %eax, %eax
605 xorl %ebx, %esi
606
607 /* Round 7 */
608 movl 28(%ebp), %edx
609 movl %esi, %ebx
610 xorl %edx, %edi
611 shrl $16, %ebx
612 movl %esi, %edx
613 movb %bh, %al
614 andl $255, %ebx
615 movb %dh, %cl
616 andl $255, %edx
617 movl 72(%ebp,%eax,4),%eax
618 movl 1096(%ebp,%ebx,4),%ebx
619 addl %eax, %ebx
620 movl 2120(%ebp,%ecx,4),%eax
621 xorl %eax, %ebx
622 movl 3144(%ebp,%edx,4),%edx
623 addl %edx, %ebx
624 xorl %eax, %eax
625 xorl %ebx, %edi
626
627 /* Round 6 */
628 movl 24(%ebp), %edx
629 movl %edi, %ebx
630 xorl %edx, %esi
631 shrl $16, %ebx
632 movl %edi, %edx
633 movb %bh, %al
634 andl $255, %ebx
635 movb %dh, %cl
636 andl $255, %edx
637 movl 72(%ebp,%eax,4),%eax
638 movl 1096(%ebp,%ebx,4),%ebx
639 addl %eax, %ebx
640 movl 2120(%ebp,%ecx,4),%eax
641 xorl %eax, %ebx
642 movl 3144(%ebp,%edx,4),%edx
643 addl %edx, %ebx
644 xorl %eax, %eax
645 xorl %ebx, %esi
646
647 /* Round 5 */
648 movl 20(%ebp), %edx
649 movl %esi, %ebx
650 xorl %edx, %edi
651 shrl $16, %ebx
652 movl %esi, %edx
653 movb %bh, %al
654 andl $255, %ebx
655 movb %dh, %cl
656 andl $255, %edx
657 movl 72(%ebp,%eax,4),%eax
658 movl 1096(%ebp,%ebx,4),%ebx
659 addl %eax, %ebx
660 movl 2120(%ebp,%ecx,4),%eax
661 xorl %eax, %ebx
662 movl 3144(%ebp,%edx,4),%edx
663 addl %edx, %ebx
664 xorl %eax, %eax
665 xorl %ebx, %edi
666
667 /* Round 4 */
668 movl 16(%ebp), %edx
669 movl %edi, %ebx
670 xorl %edx, %esi
671 shrl $16, %ebx
672 movl %edi, %edx
673 movb %bh, %al
674 andl $255, %ebx
675 movb %dh, %cl
676 andl $255, %edx
677 movl 72(%ebp,%eax,4),%eax
678 movl 1096(%ebp,%ebx,4),%ebx
679 addl %eax, %ebx
680 movl 2120(%ebp,%ecx,4),%eax
681 xorl %eax, %ebx
682 movl 3144(%ebp,%edx,4),%edx
683 addl %edx, %ebx
684 xorl %eax, %eax
685 xorl %ebx, %esi
686
687 /* Round 3 */
688 movl 12(%ebp), %edx
689 movl %esi, %ebx
690 xorl %edx, %edi
691 shrl $16, %ebx
692 movl %esi, %edx
693 movb %bh, %al
694 andl $255, %ebx
695 movb %dh, %cl
696 andl $255, %edx
697 movl 72(%ebp,%eax,4),%eax
698 movl 1096(%ebp,%ebx,4),%ebx
699 addl %eax, %ebx
700 movl 2120(%ebp,%ecx,4),%eax
701 xorl %eax, %ebx
702 movl 3144(%ebp,%edx,4),%edx
703 addl %edx, %ebx
704 xorl %eax, %eax
705 xorl %ebx, %edi
706
707 /* Round 2 */
708 movl 8(%ebp), %edx
709 movl %edi, %ebx
710 xorl %edx, %esi
711 shrl $16, %ebx
712 movl %edi, %edx
713 movb %bh, %al
714 andl $255, %ebx
715 movb %dh, %cl
716 andl $255, %edx
717 movl 72(%ebp,%eax,4),%eax
718 movl 1096(%ebp,%ebx,4),%ebx
719 addl %eax, %ebx
720 movl 2120(%ebp,%ecx,4),%eax
721 xorl %eax, %ebx
722 movl 3144(%ebp,%edx,4),%edx
723 addl %edx, %ebx
724 xorl %eax, %eax
725 xorl %ebx, %esi
726
727 /* Round 1 */
728 movl 4(%ebp), %edx
729 movl %esi, %ebx
730 xorl %edx, %edi
731 shrl $16, %ebx
732 movl %esi, %edx
733 movb %bh, %al
734 andl $255, %ebx
735 movb %dh, %cl
736 andl $255, %edx
737 movl 72(%ebp,%eax,4),%eax
738 movl 1096(%ebp,%ebx,4),%ebx
739 addl %eax, %ebx
740 movl 2120(%ebp,%ecx,4),%eax
741 xorl %eax, %ebx
742 movl 3144(%ebp,%edx,4),%edx
743 addl %edx, %ebx
744 /* Load parameter 0 (1) enc=0 */
745 movl 20(%esp), %eax
746 xorl %ebx, %edi
747 movl (%ebp), %edx
748 xorl %edx, %esi
749 movl %edi, 4(%eax)
750 movl %esi, (%eax)
751 popl %edi
752 popl %esi
753 popl %ebx
754 popl %ebp
755 ret
756.BF_decrypt_end:
757 SIZE(BF_decrypt,.BF_decrypt_end-BF_decrypt)
758.ident "BF_decrypt"
759.text
760 .align ALIGN
761.globl BF_cbc_encrypt
762 TYPE(BF_cbc_encrypt,@function)
763BF_cbc_encrypt:
764
765 pushl %ebp
766 pushl %ebx
767 pushl %esi
768 pushl %edi
769 movl 28(%esp), %ebp
770 /* getting iv ptr from parameter 4 */
771 movl 36(%esp), %ebx
772 movl (%ebx), %esi
773 movl 4(%ebx), %edi
774 pushl %edi
775 pushl %esi
776 pushl %edi
777 pushl %esi
778 movl %esp, %ebx
779 movl 36(%esp), %esi
780 movl 40(%esp), %edi
781 /* getting encrypt flag from parameter 5 */
782 movl 56(%esp), %ecx
783 /* get and push parameter 3 */
784 movl 48(%esp), %eax
785 pushl %eax
786 pushl %ebx
787 cmpl $0, %ecx
788 jz .L000decrypt
789 andl $4294967288, %ebp
790 movl 8(%esp), %eax
791 movl 12(%esp), %ebx
792 jz .L001encrypt_finish
793.L002encrypt_loop:
794 movl (%esi), %ecx
795 movl 4(%esi), %edx
796 xorl %ecx, %eax
797 xorl %edx, %ebx
798.byte 15
799.byte 200 /* bswapl %eax */
800.byte 15
801.byte 203 /* bswapl %ebx */
802 movl %eax, 8(%esp)
803 movl %ebx, 12(%esp)
804 call BF_encrypt
805 movl 8(%esp), %eax
806 movl 12(%esp), %ebx
807.byte 15
808.byte 200 /* bswapl %eax */
809.byte 15
810.byte 203 /* bswapl %ebx */
811 movl %eax, (%edi)
812 movl %ebx, 4(%edi)
813 addl $8, %esi
814 addl $8, %edi
815 subl $8, %ebp
816 jnz .L002encrypt_loop
817.L001encrypt_finish:
818 movl 52(%esp), %ebp
819 andl $7, %ebp
820 jz .L003finish
821 xorl %ecx, %ecx
822 xorl %edx, %edx
823 movl .L004cbc_enc_jmp_table(,%ebp,4),%ebp
824 jmp *%ebp
825.L005ej7:
826 movb 6(%esi), %dh
827 sall $8, %edx
828.L006ej6:
829 movb 5(%esi), %dh
830.L007ej5:
831 movb 4(%esi), %dl
832.L008ej4:
833 movl (%esi), %ecx
834 jmp .L009ejend
835.L010ej3:
836 movb 2(%esi), %ch
837 sall $8, %ecx
838.L011ej2:
839 movb 1(%esi), %ch
840.L012ej1:
841 movb (%esi), %cl
842.L009ejend:
843 xorl %ecx, %eax
844 xorl %edx, %ebx
845.byte 15
846.byte 200 /* bswapl %eax */
847.byte 15
848.byte 203 /* bswapl %ebx */
849 movl %eax, 8(%esp)
850 movl %ebx, 12(%esp)
851 call BF_encrypt
852 movl 8(%esp), %eax
853 movl 12(%esp), %ebx
854.byte 15
855.byte 200 /* bswapl %eax */
856.byte 15
857.byte 203 /* bswapl %ebx */
858 movl %eax, (%edi)
859 movl %ebx, 4(%edi)
860 jmp .L003finish
861.align ALIGN
862.L000decrypt:
863 andl $4294967288, %ebp
864 movl 16(%esp), %eax
865 movl 20(%esp), %ebx
866 jz .L013decrypt_finish
867.L014decrypt_loop:
868 movl (%esi), %eax
869 movl 4(%esi), %ebx
870.byte 15
871.byte 200 /* bswapl %eax */
872.byte 15
873.byte 203 /* bswapl %ebx */
874 movl %eax, 8(%esp)
875 movl %ebx, 12(%esp)
876 call BF_decrypt
877 movl 8(%esp), %eax
878 movl 12(%esp), %ebx
879.byte 15
880.byte 200 /* bswapl %eax */
881.byte 15
882.byte 203 /* bswapl %ebx */
883 movl 16(%esp), %ecx
884 movl 20(%esp), %edx
885 xorl %eax, %ecx
886 xorl %ebx, %edx
887 movl (%esi), %eax
888 movl 4(%esi), %ebx
889 movl %ecx, (%edi)
890 movl %edx, 4(%edi)
891 movl %eax, 16(%esp)
892 movl %ebx, 20(%esp)
893 addl $8, %esi
894 addl $8, %edi
895 subl $8, %ebp
896 jnz .L014decrypt_loop
897.L013decrypt_finish:
898 movl 52(%esp), %ebp
899 andl $7, %ebp
900 jz .L003finish
901 movl (%esi), %eax
902 movl 4(%esi), %ebx
903.byte 15
904.byte 200 /* bswapl %eax */
905.byte 15
906.byte 203 /* bswapl %ebx */
907 movl %eax, 8(%esp)
908 movl %ebx, 12(%esp)
909 call BF_decrypt
910 movl 8(%esp), %eax
911 movl 12(%esp), %ebx
912.byte 15
913.byte 200 /* bswapl %eax */
914.byte 15
915.byte 203 /* bswapl %ebx */
916 movl 16(%esp), %ecx
917 movl 20(%esp), %edx
918 xorl %eax, %ecx
919 xorl %ebx, %edx
920 movl (%esi), %eax
921 movl 4(%esi), %ebx
922.L015dj7:
923 rorl $16, %edx
924 movb %dl, 6(%edi)
925 shrl $16, %edx
926.L016dj6:
927 movb %dh, 5(%edi)
928.L017dj5:
929 movb %dl, 4(%edi)
930.L018dj4:
931 movl %ecx, (%edi)
932 jmp .L019djend
933.L020dj3:
934 rorl $16, %ecx
935 movb %cl, 2(%edi)
936 sall $16, %ecx
937.L021dj2:
938 movb %ch, 1(%esi)
939.L022dj1:
940 movb %cl, (%esi)
941.L019djend:
942 jmp .L003finish
943.align ALIGN
944.L003finish:
945 movl 60(%esp), %ecx
946 addl $24, %esp
947 movl %eax, (%ecx)
948 movl %ebx, 4(%ecx)
949 popl %edi
950 popl %esi
951 popl %ebx
952 popl %ebp
953 ret
954.align ALIGN
955.L004cbc_enc_jmp_table:
956 .long 0
957 .long .L012ej1
958 .long .L011ej2
959 .long .L010ej3
960 .long .L008ej4
961 .long .L007ej5
962 .long .L006ej6
963 .long .L005ej7
964.align ALIGN
965.L023cbc_dec_jmp_table:
966 .long 0
967 .long .L022dj1
968 .long .L021dj2
969 .long .L020dj3
970 .long .L018dj4
971 .long .L017dj5
972 .long .L016dj6
973 .long .L015dj7
974.BF_cbc_encrypt_end:
975 SIZE(BF_cbc_encrypt,.BF_cbc_encrypt_end-BF_cbc_encrypt)
976.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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61 61
62void BF_cbc_encrypt(in, out, length, ks, iv, encrypt) 62void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
63unsigned char *in; 63 BF_KEY *ks, unsigned char *iv, int encrypt)
64unsigned char *out;
65long length;
66BF_KEY *ks;
67unsigned char *iv;
68int encrypt;
69 { 64 {
70 register BF_LONG tin0,tin1; 65 register BF_LONG tin0,tin1;
71 register BF_LONG tout0,tout1,xor0,xor1; 66 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61 61
62/* The input and output encrypted as though 64bit cfb mode is being 62/* The input and output encrypted as though 64bit cfb mode is being
@@ -64,14 +64,8 @@
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66 66
67void BF_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) 67void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
68unsigned char *in; 68 BF_KEY *schedule, unsigned char *ivec, int *num, int encrypt)
69unsigned char *out;
70long length;
71BF_KEY *schedule;
72unsigned char *ivec;
73int *num;
74int encrypt;
75 { 69 {
76 register BF_LONG v0,v1,t; 70 register BF_LONG v0,v1,t;
77 register int n= *num; 71 register int n= *num;
diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c
index 6d16360bd9..9f8a24cdff 100644
--- a/src/lib/libcrypto/bf/bf_ecb.c
+++ b/src/lib/libcrypto/bf/bf_ecb.c
@@ -56,17 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61#include <openssl/opensslv.h>
61 62
62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' 63/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
63 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, 64 * (From LECTURE NOTES IN COIMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
64 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) 65 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
65 */ 66 */
66 67
67char *BF_version="BlowFish part of SSLeay 0.9.0b 29-Jun-1998"; 68const char *BF_version="BlowFish" OPENSSL_VERSION_PTEXT;
68 69
69char *BF_options() 70const char *BF_options(void)
70 { 71 {
71#ifdef BF_PTR 72#ifdef BF_PTR
72 return("blowfish(ptr)"); 73 return("blowfish(ptr)");
@@ -77,11 +78,8 @@ char *BF_options()
77#endif 78#endif
78 } 79 }
79 80
80void BF_ecb_encrypt(in, out, ks, encrypt) 81void BF_ecb_encrypt(unsigned char *in, unsigned char *out, BF_KEY *ks,
81unsigned char *in; 82 int encrypt)
82unsigned char *out;
83BF_KEY *ks;
84int encrypt;
85 { 83 {
86 BF_LONG l,d[2]; 84 BF_LONG l,d[2];
87 85
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61 61
62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' 62/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
@@ -65,14 +65,13 @@
65 */ 65 */
66 66
67#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20) 67#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20)
68If you set BF_ROUNDS to some value other than 16 or 20, you will have 68#error If you set BF_ROUNDS to some value other than 16 or 20, you will have \
69to modify the code. 69to modify the code.
70#endif 70#endif
71 71
72void BF_encrypt(data,key) 72void BF_encrypt(BF_LONG *data, BF_KEY *key)
73BF_LONG *data;
74BF_KEY *key;
75 { 73 {
74#ifndef BF_PTR2
76 register BF_LONG l,r,*p,*s; 75 register BF_LONG l,r,*p,*s;
77 76
78 p=key->P; 77 p=key->P;
@@ -107,14 +106,48 @@ BF_KEY *key;
107 106
108 data[1]=l&0xffffffffL; 107 data[1]=l&0xffffffffL;
109 data[0]=r&0xffffffffL; 108 data[0]=r&0xffffffffL;
109#else
110 register BF_LONG l,r,t,*k;
111
112 l=data[0];
113 r=data[1];
114 k=(BF_LONG*)key;
115
116 l^=k[0];
117 BF_ENC(r,l,k, 1);
118 BF_ENC(l,r,k, 2);
119 BF_ENC(r,l,k, 3);
120 BF_ENC(l,r,k, 4);
121 BF_ENC(r,l,k, 5);
122 BF_ENC(l,r,k, 6);
123 BF_ENC(r,l,k, 7);
124 BF_ENC(l,r,k, 8);
125 BF_ENC(r,l,k, 9);
126 BF_ENC(l,r,k,10);
127 BF_ENC(r,l,k,11);
128 BF_ENC(l,r,k,12);
129 BF_ENC(r,l,k,13);
130 BF_ENC(l,r,k,14);
131 BF_ENC(r,l,k,15);
132 BF_ENC(l,r,k,16);
133#if BF_ROUNDS == 20
134 BF_ENC(r,l,k,17);
135 BF_ENC(l,r,k,18);
136 BF_ENC(r,l,k,19);
137 BF_ENC(l,r,k,20);
138#endif
139 r^=k[BF_ROUNDS+1];
140
141 data[1]=l&0xffffffffL;
142 data[0]=r&0xffffffffL;
143#endif
110 } 144 }
111 145
112#ifndef BF_DEFAULT_OPTIONS 146#ifndef BF_DEFAULT_OPTIONS
113 147
114void BF_decrypt(data,key) 148void BF_decrypt(BF_LONG *data, BF_KEY *key)
115BF_LONG *data;
116BF_KEY *key;
117 { 149 {
150#ifndef BF_PTR2
118 register BF_LONG l,r,*p,*s; 151 register BF_LONG l,r,*p,*s;
119 152
120 p=key->P; 153 p=key->P;
@@ -149,15 +182,45 @@ BF_KEY *key;
149 182
150 data[1]=l&0xffffffffL; 183 data[1]=l&0xffffffffL;
151 data[0]=r&0xffffffffL; 184 data[0]=r&0xffffffffL;
185#else
186 register BF_LONG l,r,t,*k;
187
188 l=data[0];
189 r=data[1];
190 k=(BF_LONG *)key;
191
192 l^=k[BF_ROUNDS+1];
193#if BF_ROUNDS == 20
194 BF_ENC(r,l,k,20);
195 BF_ENC(l,r,k,19);
196 BF_ENC(r,l,k,18);
197 BF_ENC(l,r,k,17);
198#endif
199 BF_ENC(r,l,k,16);
200 BF_ENC(l,r,k,15);
201 BF_ENC(r,l,k,14);
202 BF_ENC(l,r,k,13);
203 BF_ENC(r,l,k,12);
204 BF_ENC(l,r,k,11);
205 BF_ENC(r,l,k,10);
206 BF_ENC(l,r,k, 9);
207 BF_ENC(r,l,k, 8);
208 BF_ENC(l,r,k, 7);
209 BF_ENC(r,l,k, 6);
210 BF_ENC(l,r,k, 5);
211 BF_ENC(r,l,k, 4);
212 BF_ENC(l,r,k, 3);
213 BF_ENC(r,l,k, 2);
214 BF_ENC(l,r,k, 1);
215 r^=k[0];
216
217 data[1]=l&0xffffffffL;
218 data[0]=r&0xffffffffL;
219#endif
152 } 220 }
153 221
154void BF_cbc_encrypt(in, out, length, ks, iv, encrypt) 222void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
155unsigned char *in; 223 BF_KEY *ks, unsigned char *iv, int encrypt)
156unsigned char *out;
157long length;
158BF_KEY *ks;
159unsigned char *iv;
160int encrypt;
161 { 224 {
162 register BF_LONG tin0,tin1; 225 register BF_LONG tin0,tin1;
163 register BF_LONG tout0,tout1,xor0,xor1; 226 register BF_LONG tout0,tout1,xor0,xor1;
diff --git a/src/lib/libcrypto/bf/bf_locl.org b/src/lib/libcrypto/bf/bf_locl.h
index a5663de8ca..05756b5d3b 100644
--- a/src/lib/libcrypto/bf/bf_locl.org
+++ b/src/lib/libcrypto/bf/bf_locl.h
@@ -1,4 +1,4 @@
1/* crypto/bf/bf_locl.org */ 1/* crypto/bf/bf_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,39 +56,9 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 59#ifndef HEADER_BF_LOCL_H
60 * 60#define HEADER_BF_LOCL_H
61 * Always modify bf_locl.org since bf_locl.h is automatically generated from 61#include <openssl/opensslconf.h> /* BF_PTR, BF_PTR2 */
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67/* Special defines which change the way the code is built depending on the
68 CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
69 even newer MIPS CPU's, but at the moment one size fits all for
70 optimization options. Older Sparc's work better with only UNROLL, but
71 there's no way to tell at compile time what it is you're running on */
72
73#if defined( sun ) /* Newer Sparc's */
74# define BF_PTR
75#elif defined( __ultrix ) /* Older MIPS */
76# define BF_PTR
77#elif defined( __osf1__ ) /* Alpha */
78 /* None */
79#elif defined ( _AIX ) /* RS6000 */
80 /* Unknown */
81#elif defined( __hpux ) /* HP-PA */
82 /* None */
83#elif defined( __aux ) /* 68K */
84 /* Unknown */
85#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */
86 /* Unknown */
87#elif defined( __sgi ) /* Newer MIPS */
88# define BF_PTR
89#elif defined( i386 ) /* x86 boxes, should be gcc */
90#elif defined( _MSC_VER ) /* x86 boxes, Visual C */
91#endif /* Systems-specific speed defines */
92 62
93#undef c2l 63#undef c2l
94#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ 64#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
@@ -181,62 +151,69 @@
181/* This is actually a big endian algorithm, the most significate byte 151/* This is actually a big endian algorithm, the most significate byte
182 * is used to lookup array 0 */ 152 * is used to lookup array 0 */
183 153
184/* use BF_PTR2 for intel boxes,
185 * BF_PTR for sparc and MIPS/SGI
186 * use nothing for Alpha and HP.
187 */
188#if !defined(BF_PTR) && !defined(BF_PTR2)
189#undef BF_PTR
190#endif
191
192#define BF_M 0x3fc
193#define BF_0 22L
194#define BF_1 14L
195#define BF_2 6L
196#define BF_3 2L /* left shift */
197
198#if defined(BF_PTR2) 154#if defined(BF_PTR2)
199 155
200/* This is basically a special pentium verson */ 156/*
201#define BF_ENC(LL,R,S,P) \ 157 * This is basically a special Intel version. Point is that Intel
202 { \ 158 * doesn't have many registers, but offers a reach choice of addressing
203 BF_LONG t,u,v; \ 159 * modes. So we spare some registers by directly traversing BF_KEY
204 u=R>>BF_0; \ 160 * structure and hiring the most decorated addressing mode. The code
205 v=R>>BF_1; \ 161 * generated by EGCS is *perfectly* competitive with assembler
206 u&=BF_M; \ 162 * implementation!
207 v&=BF_M; \ 163 */
208 t= *(BF_LONG *)((unsigned char *)&(S[ 0])+u); \ 164#define BF_ENC(LL,R,KEY,Pi) (\
209 u=R>>BF_2; \ 165 LL^=KEY[Pi], \
210 t+= *(BF_LONG *)((unsigned char *)&(S[256])+v); \ 166 t= KEY[BF_ROUNDS+2 + 0 + ((R>>24)&0xFF)], \
211 v=R<<BF_3; \ 167 t+= KEY[BF_ROUNDS+2 + 256 + ((R>>16)&0xFF)], \
212 u&=BF_M; \ 168 t^= KEY[BF_ROUNDS+2 + 512 + ((R>>8 )&0xFF)], \
213 v&=BF_M; \ 169 t+= KEY[BF_ROUNDS+2 + 768 + ((R )&0xFF)], \
214 t^= *(BF_LONG *)((unsigned char *)&(S[512])+u); \ 170 LL^=t \
215 LL^=P; \ 171 )
216 t+= *(BF_LONG *)((unsigned char *)&(S[768])+v); \
217 LL^=t; \
218 }
219 172
220#elif defined(BF_PTR) 173#elif defined(BF_PTR)
221 174
222/* This is normally very good */ 175#ifndef BF_LONG_LOG2
176#define BF_LONG_LOG2 2 /* default to BF_LONG being 32 bits */
177#endif
178#define BF_M (0xFF<<BF_LONG_LOG2)
179#define BF_0 (24-BF_LONG_LOG2)
180#define BF_1 (16-BF_LONG_LOG2)
181#define BF_2 ( 8-BF_LONG_LOG2)
182#define BF_3 BF_LONG_LOG2 /* left shift */
183
184/*
185 * This is normally very good on RISC platforms where normally you
186 * have to explicitely "multiplicate" array index by sizeof(BF_LONG)
187 * in order to caclulate the effective address. This implementation
188 * excuses CPU from this extra work. Power[PC] uses should have most
189 * fun as (R>>BF_i)&BF_M gets folded into a single instruction, namely
190 * rlwinm. So let'em double-check if their compiler does it.
191 */
223 192
224#define BF_ENC(LL,R,S,P) \ 193#define BF_ENC(LL,R,S,P) ( \
225 LL^=P; \ 194 LL^=P, \
226 LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \ 195 LL^= (((*(BF_LONG *)((unsigned char *)&(S[ 0])+((R>>BF_0)&BF_M))+ \
227 *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \ 196 *(BF_LONG *)((unsigned char *)&(S[256])+((R>>BF_1)&BF_M)))^ \
228 *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \ 197 *(BF_LONG *)((unsigned char *)&(S[512])+((R>>BF_2)&BF_M)))+ \
229 *(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M))); 198 *(BF_LONG *)((unsigned char *)&(S[768])+((R<<BF_3)&BF_M))) \
199 )
230#else 200#else
231 201
232/* This will always work, even on 64 bit machines and strangly enough, 202/*
233 * on the Alpha it is faster than the pointer versions (both 32 and 64 203 * This is a *generic* version. Seem to perform best on platforms that
234 * versions of BF_LONG) */ 204 * offer explicit support for extraction of 8-bit nibbles preferably
205 * complemented with "multiplying" of array index by sizeof(BF_LONG).
206 * For the moment of this writing the list comprises Alpha CPU featuring
207 * extbl and s[48]addq instructions.
208 */
209
210#define BF_ENC(LL,R,S,P) ( \
211 LL^=P, \
212 LL^=((( S[ ((int)(R>>24)&0xff)] + \
213 S[0x0100+((int)(R>>16)&0xff)])^ \
214 S[0x0200+((int)(R>> 8)&0xff)])+ \
215 S[0x0300+((int)(R )&0xff)])&0xffffffffL \
216 )
217#endif
235 218
236#define BF_ENC(LL,R,S,P) \
237 LL^=P; \
238 LL^=((( S[ (int)(R>>24L) ] + \
239 S[0x0100+((int)(R>>16L)&0xff)])^ \
240 S[0x0200+((int)(R>> 8L)&0xff)])+ \
241 S[0x0300+((int)(R )&0xff)])&0xffffffffL;
242#endif 219#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "blowfish.h" 59#include <openssl/blowfish.h>
60#include "bf_locl.h" 60#include "bf_locl.h"
61 61
62/* The input and output encrypted as though 64bit ofb mode is being 62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the 63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66void BF_ofb64_encrypt(in, out, length, schedule, ivec, num) 66void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
67unsigned char *in; 67 BF_KEY *schedule, unsigned char *ivec, int *num)
68unsigned char *out;
69long length;
70BF_KEY *schedule;
71unsigned char *ivec;
72int *num;
73 { 68 {
74 register BF_LONG v0,v1,t; 69 register BF_LONG v0,v1,t;
75 register int n= *num; 70 register int n= *num;
diff --git a/src/lib/libcrypto/bf/bf_opts.c b/src/lib/libcrypto/bf/bf_opts.c
index 5cfa60c537..5f330cc53c 100644
--- a/src/lib/libcrypto/bf/bf_opts.c
+++ b/src/lib/libcrypto/bf/bf_opts.c
@@ -59,19 +59,17 @@
59/* define PART1, PART2, PART3 or PART4 to build only with a few of the options. 59/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */ 60 * This is for machines with 64k code segment size restrictions. */
61 61
62#ifndef MSDOS 62#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
63#define TIMES 63#define TIMES
64#endif 64#endif
65 65
66#include <stdio.h> 66#include <stdio.h>
67#ifndef MSDOS 67
68#include <unistd.h> 68#include <openssl/e_os2.h>
69#else 69#include OPENSSL_UNISTD_IO
70#include <io.h> 70OPENSSL_DECLARE_EXIT
71extern void exit(); 71
72#endif
73#include <signal.h> 72#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX 73#ifndef _IRIX
76#include <time.h> 74#include <time.h>
77#endif 75#endif
@@ -79,25 +77,26 @@ extern void exit();
79#include <sys/types.h> 77#include <sys/types.h>
80#include <sys/times.h> 78#include <sys/times.h>
81#endif 79#endif
82#else /* VMS */ 80
83#include <types.h> 81/* Depending on the VMS version, the tms structure is perhaps defined.
84struct tms { 82 The __TMS macro will show if it was. If it wasn't defined, we should
85 time_t tms_utime; 83 undefine TIMES, since that tells the rest of the program how things
86 time_t tms_stime; 84 should be handled. -- Richard Levitte */
87 time_t tms_uchild; /* I dunno... */ 85#if defined(VMS) && defined(__DECC) && !defined(__TMS)
88 time_t tms_uchildsys; /* so these names are a guess :-) */ 86#undef TIMES
89 }
90#endif 87#endif
88
91#ifndef TIMES 89#ifndef TIMES
92#include <sys/timeb.h> 90#include <sys/timeb.h>
93#endif 91#endif
94 92
95#ifdef sun 93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
96#include <limits.h> 95#include <limits.h>
97#include <sys/param.h> 96#include <sys/param.h>
98#endif 97#endif
99 98
100#include "blowfish.h" 99#include <openssl/blowfish.h>
101 100
102#define BF_DEFAULT_OPTIONS 101#define BF_DEFAULT_OPTIONS
103 102
@@ -126,11 +125,7 @@ struct tms {
126#ifndef HZ 125#ifndef HZ
127# ifndef CLK_TCK 126# ifndef CLK_TCK
128# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ 127# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
129# ifndef VMS 128# define HZ 100.0
130# define HZ 100.0
131# else /* VMS */
132# define HZ 100.0
133# endif
134# else /* _BSD_CLK_TCK_ */ 129# else /* _BSD_CLK_TCK_ */
135# define HZ ((double)_BSD_CLK_TCK_) 130# define HZ ((double)_BSD_CLK_TCK_)
136# endif 131# endif
@@ -142,12 +137,7 @@ struct tms {
142#define BUFSIZE ((long)1024) 137#define BUFSIZE ((long)1024)
143long run=0; 138long run=0;
144 139
145#ifndef NOPROTO
146double Time_F(int s); 140double Time_F(int s);
147#else
148double Time_F();
149#endif
150
151#ifdef SIGALRM 141#ifdef SIGALRM
152#if defined(__STDC__) || defined(sgi) 142#if defined(__STDC__) || defined(sgi)
153#define SIGRETTYPE void 143#define SIGRETTYPE void
@@ -155,14 +145,8 @@ double Time_F();
155#define SIGRETTYPE int 145#define SIGRETTYPE int
156#endif 146#endif
157 147
158#ifndef NOPROTO
159SIGRETTYPE sig_done(int sig); 148SIGRETTYPE sig_done(int sig);
160#else 149SIGRETTYPE sig_done(int sig)
161SIGRETTYPE sig_done();
162#endif
163
164SIGRETTYPE sig_done(sig)
165int sig;
166 { 150 {
167 signal(SIGALRM,sig_done); 151 signal(SIGALRM,sig_done);
168 run=0; 152 run=0;
@@ -175,8 +159,7 @@ int sig;
175#define START 0 159#define START 0
176#define STOP 1 160#define STOP 1
177 161
178double Time_F(s) 162double Time_F(int s)
179int s;
180 { 163 {
181 double ret; 164 double ret;
182#ifdef TIMES 165#ifdef TIMES
@@ -237,9 +220,7 @@ int s;
237 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ 220 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
238 tm[index]*8,1.0e6/tm[index]); 221 tm[index]*8,1.0e6/tm[index]);
239 222
240int main(argc,argv) 223int main(int argc, char **argv)
241int argc;
242char **argv;
243 { 224 {
244 long count; 225 long count;
245 static unsigned char buf[BUFSIZE]; 226 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "blowfish.h" 61#include <openssl/blowfish.h>
62#include "bf_locl.h" 62#include "bf_locl.h"
63#include "bf_pi.h" 63#include "bf_pi.h"
64 64
65void BF_set_key(key,len,data) 65void BF_set_key(BF_KEY *key, int len, unsigned char *data)
66BF_KEY *key;
67int len;
68unsigned char *data;
69 { 66 {
70 int i; 67 int i;
71 BF_LONG *p,ri,in[2]; 68 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)
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <stdlib.h> 34#include <stdlib.h>
35#include "blowfish.h" 35#include <openssl/blowfish.h>
36 36
37void main(int argc,char *argv[]) 37void main(int argc,char *argv[])
38 { 38 {
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 @@
59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ 59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ 60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61 61
62#ifndef MSDOS 62#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
63#define TIMES 63#define TIMES
64#endif 64#endif
65 65
66#include <stdio.h> 66#include <stdio.h>
67#ifndef MSDOS 67
68#include <unistd.h> 68#include <openssl/e_os2.h>
69#else 69#include OPENSSL_UNISTD_IO
70#include <io.h> 70OPENSSL_DECLARE_EXIT
71extern int exit(); 71
72#endif
73#include <signal.h> 72#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX 73#ifndef _IRIX
76#include <time.h> 74#include <time.h>
77#endif 75#endif
@@ -79,34 +77,31 @@ extern int exit();
79#include <sys/types.h> 77#include <sys/types.h>
80#include <sys/times.h> 78#include <sys/times.h>
81#endif 79#endif
82#else /* VMS */ 80
83#include <types.h> 81/* Depending on the VMS version, the tms structure is perhaps defined.
84struct tms { 82 The __TMS macro will show if it was. If it wasn't defined, we should
85 time_t tms_utime; 83 undefine TIMES, since that tells the rest of the program how things
86 time_t tms_stime; 84 should be handled. -- Richard Levitte */
87 time_t tms_uchild; /* I dunno... */ 85#if defined(VMS) && defined(__DECC) && !defined(__TMS)
88 time_t tms_uchildsys; /* so these names are a guess :-) */ 86#undef TIMES
89 }
90#endif 87#endif
88
91#ifndef TIMES 89#ifndef TIMES
92#include <sys/timeb.h> 90#include <sys/timeb.h>
93#endif 91#endif
94 92
95#ifdef sun 93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
96#include <limits.h> 95#include <limits.h>
97#include <sys/param.h> 96#include <sys/param.h>
98#endif 97#endif
99 98
100#include "blowfish.h" 99#include <openssl/blowfish.h>
101 100
102/* The following if from times(3) man page. It may need to be changed */ 101/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ 102#ifndef HZ
104#ifndef CLK_TCK 103#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0 104#define HZ 100.0
109#endif
110#else /* CLK_TCK */ 105#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK) 106#define HZ ((double)CLK_TCK)
112#endif 107#endif
@@ -115,12 +110,7 @@ struct tms {
115#define BUFSIZE ((long)1024) 110#define BUFSIZE ((long)1024)
116long run=0; 111long run=0;
117 112
118#ifndef NOPROTO
119double Time_F(int s); 113double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM 114#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX) 115#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void 116#define SIGRETTYPE void
@@ -128,14 +118,8 @@ double Time_F();
128#define SIGRETTYPE int 118#define SIGRETTYPE int
129#endif 119#endif
130 120
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig); 121SIGRETTYPE sig_done(int sig);
133#else 122SIGRETTYPE sig_done(int sig)
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 { 123 {
140 signal(SIGALRM,sig_done); 124 signal(SIGALRM,sig_done);
141 run=0; 125 run=0;
@@ -148,8 +132,7 @@ int sig;
148#define START 0 132#define START 0
149#define STOP 1 133#define STOP 1
150 134
151double Time_F(s) 135double Time_F(int s)
152int s;
153 { 136 {
154 double ret; 137 double ret;
155#ifdef TIMES 138#ifdef TIMES
@@ -185,9 +168,7 @@ int s;
185#endif 168#endif
186 } 169 }
187 170
188int main(argc,argv) 171int main(int argc, char **argv)
189int argc;
190char **argv;
191 { 172 {
192 long count; 173 long count;
193 static unsigned char buf[BUFSIZE]; 174 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 @@
62#include <stdio.h> 62#include <stdio.h>
63#include <string.h> 63#include <string.h>
64#include <stdlib.h> 64#include <stdlib.h>
65#include "blowfish.h" 65
66#ifdef NO_BF
67int main(int argc, char *argv[])
68{
69 printf("No BF support\n");
70 return(0);
71}
72#else
73#include <openssl/blowfish.h>
74
75#ifdef CHARSET_EBCDIC
76#include <openssl/ebcdic.h>
77#endif
66 78
67char *bf_key[2]={ 79char *bf_key[2]={
68 "abcdefghijklmnopqrstuvwxyz", 80 "abcdefghijklmnopqrstuvwxyz",
@@ -252,17 +264,9 @@ unsigned char key_out[KEY_TEST_NUM][8]={
252 {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80}, 264 {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80},
253 }; 265 };
254 266
255#ifndef NOPROTO
256static int test(void ); 267static int test(void );
257static int print_test_data(void ); 268static int print_test_data(void );
258#else 269int main(int argc, char *argv[])
259static int test();
260static int print_test_data();
261#endif
262
263int main(argc,argv)
264int argc;
265char *argv[];
266 { 270 {
267 int ret; 271 int ret;
268 272
@@ -275,7 +279,7 @@ char *argv[];
275 return(0); 279 return(0);
276 } 280 }
277 281
278static int print_test_data() 282static int print_test_data(void)
279 { 283 {
280 unsigned int i,j; 284 unsigned int i,j;
281 285
@@ -304,7 +308,7 @@ static int print_test_data()
304 printf("c="); 308 printf("c=");
305 for (j=0; j<8; j++) 309 for (j=0; j<8; j++)
306 printf("%02X",key_out[i][j]); 310 printf("%02X",key_out[i][j]);
307 printf(" k[%2d]=",i+1); 311 printf(" k[%2u]=",i+1);
308 for (j=0; j<i+1; j++) 312 for (j=0; j<i+1; j++)
309 printf("%02X",key_test[j]); 313 printf("%02X",key_test[j]);
310 printf("\n"); 314 printf("\n");
@@ -342,7 +346,7 @@ static int print_test_data()
342 return(0); 346 return(0);
343 } 347 }
344 348
345static int test() 349static int test(void)
346 { 350 {
347 unsigned char cbc_in[40],cbc_out[40],iv[8]; 351 unsigned char cbc_in[40],cbc_out[40],iv[8];
348 int i,n,err=0; 352 int i,n,err=0;
@@ -351,9 +355,16 @@ static int test()
351 unsigned char out[8]; 355 unsigned char out[8];
352 BF_LONG len; 356 BF_LONG len;
353 357
358#ifdef CHARSET_EBCDIC
359 ebcdic2ascii(cbc_data, cbc_data, strlen(cbc_data));
360#endif
361
354 printf("testing blowfish in raw ecb mode\n"); 362 printf("testing blowfish in raw ecb mode\n");
355 for (n=0; n<2; n++) 363 for (n=0; n<2; n++)
356 { 364 {
365#ifdef CHARSET_EBCDIC
366 ebcdic2ascii(bf_key[n], bf_key[n], strlen(bf_key[n]));
367#endif
357 BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]); 368 BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]);
358 369
359 data[0]=bf_plain[n][0]; 370 data[0]=bf_plain[n][0];
@@ -364,11 +375,11 @@ static int test()
364 printf("BF_encrypt error encrypting\n"); 375 printf("BF_encrypt error encrypting\n");
365 printf("got :"); 376 printf("got :");
366 for (i=0; i<2; i++) 377 for (i=0; i<2; i++)
367 printf("%08lX ",data[i]); 378 printf("%08lX ",(unsigned long)data[i]);
368 printf("\n"); 379 printf("\n");
369 printf("expected:"); 380 printf("expected:");
370 for (i=0; i<2; i++) 381 for (i=0; i<2; i++)
371 printf("%08lX ",bf_cipher[n][i]); 382 printf("%08lX ",(unsigned long)bf_cipher[n][i]);
372 err=1; 383 err=1;
373 printf("\n"); 384 printf("\n");
374 } 385 }
@@ -379,11 +390,11 @@ static int test()
379 printf("BF_encrypt error decrypting\n"); 390 printf("BF_encrypt error decrypting\n");
380 printf("got :"); 391 printf("got :");
381 for (i=0; i<2; i++) 392 for (i=0; i<2; i++)
382 printf("%08lX ",data[i]); 393 printf("%08lX ",(unsigned long)data[i]);
383 printf("\n"); 394 printf("\n");
384 printf("expected:"); 395 printf("expected:");
385 for (i=0; i<2; i++) 396 for (i=0; i<2; i++)
386 printf("%08lX ",bf_plain[n][i]); 397 printf("%08lX ",(unsigned long)bf_plain[n][i]);
387 printf("\n"); 398 printf("\n");
388 err=1; 399 err=1;
389 } 400 }
@@ -519,3 +530,4 @@ static int test()
519 530
520 return(err); 531 return(err);
521 } 532 }
533#endif
diff --git a/src/lib/libcrypto/bf/blowfish.h b/src/lib/libcrypto/bf/blowfish.h
index c4a8085a29..02f73b2f30 100644
--- a/src/lib/libcrypto/bf/blowfish.h
+++ b/src/lib/libcrypto/bf/blowfish.h
@@ -63,14 +63,35 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifdef NO_BF
67#error BF is disabled.
68#endif
69
66#define BF_ENCRYPT 1 70#define BF_ENCRYPT 1
67#define BF_DECRYPT 0 71#define BF_DECRYPT 0
68 72
69/* If you make this 'unsigned int' the pointer variants will work on 73/*
70 * the Alpha, otherwise they will not. Strangly using the '8 byte' 74 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
71 * BF_LONG and the default 'non-pointer' inner loop is the best configuration 75 * ! BF_LONG has to be at least 32 bits wide. If it's wider, then !
72 * for the Alpha */ 76 * ! BF_LONG_LOG2 has to be defined along. !
77 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 */
79
80#if defined(WIN16) || defined(__LP32__)
73#define BF_LONG unsigned long 81#define BF_LONG unsigned long
82#elif defined(_CRAY) || defined(__ILP64__)
83#define BF_LONG unsigned long
84#define BF_LONG_LOG2 3
85/*
86 * _CRAY note. I could declare short, but I have no idea what impact
87 * does it have on performance on none-T3E machines. I could declare
88 * int, but at least on C90 sizeof(int) can be chosen at compile time.
89 * So I've chosen long...
90 * <appro@fy.chalmers.se>
91 */
92#else
93#define BF_LONG unsigned int
94#endif
74 95
75#define BF_ROUNDS 16 96#define BF_ROUNDS 16
76#define BF_BLOCK 8 97#define BF_BLOCK 8
@@ -81,7 +102,6 @@ typedef struct bf_key_st
81 BF_LONG S[4*256]; 102 BF_LONG S[4*256];
82 } BF_KEY; 103 } BF_KEY;
83 104
84#ifndef NOPROTO
85 105
86void BF_set_key(BF_KEY *key, int len, unsigned char *data); 106void BF_set_key(BF_KEY *key, int len, unsigned char *data);
87void BF_ecb_encrypt(unsigned char *in,unsigned char *out,BF_KEY *key, 107void 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,
94 BF_KEY *schedule, unsigned char *ivec, int *num, int enc); 114 BF_KEY *schedule, unsigned char *ivec, int *num, int enc);
95void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, 115void BF_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
96 BF_KEY *schedule, unsigned char *ivec, int *num); 116 BF_KEY *schedule, unsigned char *ivec, int *num);
97char *BF_options(void); 117const char *BF_options(void);
98
99#else
100
101void BF_set_key();
102void BF_ecb_encrypt();
103void BF_encrypt();
104void BF_decrypt();
105void BF_cbc_encrypt();
106void BF_cfb64_encrypt();
107void BF_ofb64_encrypt();
108char *BF_options();
109
110#endif
111 118
112#ifdef __cplusplus 119#ifdef __cplusplus
113} 120}
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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=bio
19ERRC=bio_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= 21TEST=
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= bio_lib.c bio_cb.c $(ERRC).c \ 25LIBSRC= bio_lib.c bio_cb.c bio_err.c \
26 bss_mem.c bss_null.c bss_fd.c \ 26 bss_mem.c bss_null.c bss_fd.c \
27 bss_file.c bss_sock.c bss_conn.c \ 27 bss_file.c bss_sock.c bss_conn.c \
28 bf_null.c bf_buff.c b_print.c b_dump.c \ 28 bf_null.c bf_buff.c b_print.c b_dump.c \
29 b_sock.c bss_acpt.c bf_nbio.c 29 b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c
30LIBOBJ= bio_lib.o bio_cb.o $(ERRC).o \ 30LIBOBJ= bio_lib.o bio_cb.o bio_err.o \
31 bss_mem.o bss_null.o bss_fd.o \ 31 bss_mem.o bss_null.o bss_fd.o \
32 bss_file.o bss_sock.o bss_conn.o \ 32 bss_file.o bss_sock.o bss_conn.o \
33 bf_null.o bf_buff.o b_print.o b_dump.o \ 33 bf_null.o bf_buff.o b_print.o b_dump.o \
34 b_sock.o bss_acpt.o bf_nbio.o 34 b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o
35 35
36SRC= $(LIBSRC) 36SRC= $(LIBSRC)
37 37
38EXHEADER= bio.h bss_file.c 38EXHEADER= bio.h
39HEADER= $(EXHEADER) 39HEADER= bss_file.c $(EXHEADER)
40 40
41ALL= $(GENERAL) $(SRC) $(HEADER) 41ALL= $(GENERAL) $(SRC) $(HEADER)
42 42
@@ -47,24 +47,23 @@ all: lib
47 47
48lib: $(LIBOBJ) 48lib: $(LIBOBJ)
49 $(AR) $(LIB) $(LIBOBJ) 49 $(AR) $(LIB) $(LIBOBJ)
50 sh $(TOP)/util/ranlib.sh $(LIB) 50 $(RANLIB) $(LIB)
51 @touch lib 51 @touch lib
52 52
53files: 53files:
54 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 54 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
55 55
56links: 56links:
57 /bin/rm -f Makefile 57 @$(TOP)/util/point.sh Makefile.ssl Makefile
58 $(TOP)/util/point.sh Makefile.ssl Makefile; 58 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
59 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 59 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
60 $(TOP)/util/mklink.sh ../../test $(TEST) 60 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
61 $(TOP)/util/mklink.sh ../../apps $(APPS)
62 61
63install: 62install:
64 @for i in $(EXHEADER) bss_file.c ; \ 63 @for i in $(EXHEADER); \
65 do \ 64 do \
66 (cp $$i $(INSTALLTOP)/include/$$i; \ 65 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
67 chmod 644 $(INSTALLTOP)/include/$$i ); \ 66 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
68 done; 67 done;
69 68
70tags: 69tags:
@@ -76,17 +75,136 @@ lint:
76 lint -DLINT $(INCLUDES) $(SRC)>fluff 75 lint -DLINT $(INCLUDES) $(SRC)>fluff
77 76
78depend: 77depend:
79 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 78 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
80 79
81dclean: 80dclean:
82 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 81 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
83 mv -f Makefile.new $(MAKEFILE) 82 mv -f Makefile.new $(MAKEFILE)
84 83
85clean: 84clean:
86 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 85 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
87
88errors:
89 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
90 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
91 86
92# DO NOT DELETE THIS LINE -- make depend depends on it. 87# DO NOT DELETE THIS LINE -- make depend depends on it.
88
89b_dump.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
90b_dump.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
91b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
92b_dump.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
93b_dump.o: ../../include/openssl/stack.h ../cryptlib.h
94b_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
95b_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
96b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
97b_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
98b_print.o: ../../include/openssl/stack.h ../cryptlib.h
99b_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
100b_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
101b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
102b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
103b_sock.o: ../../include/openssl/stack.h ../cryptlib.h
104bf_buff.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
105bf_buff.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
106bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
107bf_buff.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
108bf_buff.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
109bf_buff.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
110bf_buff.o: ../../include/openssl/err.h ../../include/openssl/evp.h
111bf_buff.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
112bf_buff.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
113bf_buff.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
114bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
115bf_buff.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
116bf_buff.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
117bf_buff.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
118bf_buff.o: ../../include/openssl/stack.h ../cryptlib.h
119bf_nbio.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
120bf_nbio.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
121bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
122bf_nbio.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
123bf_nbio.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
124bf_nbio.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
125bf_nbio.o: ../../include/openssl/err.h ../../include/openssl/evp.h
126bf_nbio.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
127bf_nbio.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
128bf_nbio.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
129bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
130bf_nbio.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
131bf_nbio.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
132bf_nbio.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
133bf_nbio.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
134bf_nbio.o: ../cryptlib.h
135bf_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
136bf_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
137bf_null.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
138bf_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
139bf_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
140bf_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
141bf_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
142bf_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
143bf_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
144bf_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
145bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
146bf_null.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
147bf_null.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
148bf_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
149bf_null.o: ../../include/openssl/stack.h ../cryptlib.h
150bio_cb.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
151bio_cb.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
152bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
153bio_cb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
154bio_cb.o: ../../include/openssl/stack.h ../cryptlib.h
155bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
156bio_err.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h
157bio_err.o: ../../include/openssl/stack.h
158bio_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
159bio_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
160bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
161bio_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
162bio_lib.o: ../../include/openssl/stack.h ../cryptlib.h
163bss_acpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
164bss_acpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
165bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
166bss_acpt.o: ../../include/openssl/opensslconf.h
167bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
168bss_acpt.o: ../cryptlib.h
169bss_bio.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
170bss_bio.o: ../../include/openssl/err.h ../../include/openssl/opensslv.h
171bss_bio.o: ../../include/openssl/stack.h
172bss_conn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
173bss_conn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
174bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
175bss_conn.o: ../../include/openssl/opensslconf.h
176bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
177bss_conn.o: ../cryptlib.h
178bss_fd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
179bss_fd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
180bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
181bss_fd.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
182bss_fd.o: ../../include/openssl/stack.h ../cryptlib.h bss_sock.c
183bss_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
184bss_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
185bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
186bss_file.o: ../../include/openssl/opensslconf.h
187bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
188bss_file.o: ../cryptlib.h
189bss_log.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
190bss_log.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
191bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
192bss_log.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
193bss_log.o: ../../include/openssl/stack.h ../cryptlib.h
194bss_mem.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
195bss_mem.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
196bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
197bss_mem.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
198bss_mem.o: ../../include/openssl/stack.h ../cryptlib.h
199bss_null.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
200bss_null.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
201bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
202bss_null.o: ../../include/openssl/opensslconf.h
203bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
204bss_null.o: ../cryptlib.h
205bss_sock.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
206bss_sock.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
207bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
208bss_sock.o: ../../include/openssl/opensslconf.h
209bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
210bss_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 @@
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio.h" 65#include <openssl/bio.h>
66 66
67#define TRUNCATE 67#define TRUNCATE
68#define DUMP_WIDTH 16 68#define DUMP_WIDTH 16
69 69
70int BIO_dump(bio,s,len) 70int BIO_dump(BIO *bio, const char *s, int len)
71BIO *bio;
72char *s;
73int len;
74{ 71{
75 int ret=0; 72 int ret=0;
76 char buf[160+1],tmp[20]; 73 char buf[160+1],tmp[20];
@@ -105,7 +102,13 @@ int len;
105 if (((i*DUMP_WIDTH)+j)>=len) 102 if (((i*DUMP_WIDTH)+j)>=len)
106 break; 103 break;
107 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff; 104 ch=((unsigned char)*((char *)(s)+i*DUMP_WIDTH+j)) & 0xff;
105#ifndef CHARSET_EBCDIC
108 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.'); 106 sprintf(tmp,"%c",((ch>=' ')&&(ch<='~'))?ch:'.');
107#else
108 sprintf(tmp,"%c",((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
109 ? os_toebcdic[ch]
110 : '.');
111#endif
109 strcat(buf,tmp); 112 strcat(buf,tmp);
110 } 113 }
111 strcat(buf,"\n"); 114 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 @@
61 */ 61 */
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include <stdarg.h>
64#include "cryptlib.h" 65#include "cryptlib.h"
65#include "bio.h" 66#include <openssl/bio.h>
66 67
67int BIO_printf ( VAR_PLIST( BIO *, bio ) ) 68int BIO_printf (BIO *bio, ...)
68VAR_ALIST
69 { 69 {
70 VAR_BDEFN(args, BIO *, bio); 70 va_list args;
71 char *format; 71 char *format;
72 int ret; 72 int ret;
73 MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */ 73 MS_STATIC char hugebuf[1024*2]; /* 10k in one chunk is the limit */
74 74
75 VAR_INIT(args, BIO *, bio); 75 va_start(args, bio);
76 VAR_ARG(args, char *, format); 76 format=va_arg(args, char *);
77 77
78 hugebuf[0]='\0'; 78 hugebuf[0]='\0';
79 79
80/* no-one uses _doprnt anymore and it appears to be broken under SunOS 4.1.4 */
81#if 0 && defined(sun) && !defined(VAR_ANSI) /**/
82 _doprnt(hugebuf,format,args);
83#else /* !sun */
84 vsprintf(hugebuf,format,args); 80 vsprintf(hugebuf,format,args);
85#endif /* sun */
86 81
87 ret=BIO_write(bio,hugebuf,strlen(hugebuf)); 82 ret=BIO_write(bio,hugebuf,strlen(hugebuf));
88 83
89 VAR_END( args ); 84 va_end(args);
90 return(ret); 85 return(ret);
91 } 86 }
92 87
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 @@
63#include <errno.h> 63#include <errno.h>
64#define USE_SOCKETS 64#define USE_SOCKETS
65#include "cryptlib.h" 65#include "cryptlib.h"
66#include "bio.h" 66#include <openssl/bio.h>
67
68/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */
69 67
70#ifdef WIN16 68#ifdef WIN16
71#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ 69#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
@@ -96,21 +94,14 @@ static struct ghbn_cache_st
96 unsigned long order; 94 unsigned long order;
97 } ghbn_cache[GHBN_NUM]; 95 } ghbn_cache[GHBN_NUM];
98 96
99#ifndef NOPROTO 97static int get_ip(const char *str,unsigned char *ip);
100static int get_ip(char *str,unsigned char *ip);
101static void ghbn_free(struct hostent *a); 98static void ghbn_free(struct hostent *a);
102static struct hostent *ghbn_dup(struct hostent *a); 99static struct hostent *ghbn_dup(struct hostent *a);
103#else 100int BIO_get_host_ip(const char *str, unsigned char *ip)
104static int get_ip();
105static void ghbn_free();
106static struct hostent *ghbn_dup();
107#endif
108
109int BIO_get_host_ip(str,ip)
110char *str;
111unsigned char *ip;
112 { 101 {
113 int i; 102 int i;
103 int err = 1;
104 int locked = 0;
114 struct hostent *he; 105 struct hostent *he;
115 106
116 i=get_ip(str,ip); 107 i=get_ip(str,ip);
@@ -118,37 +109,45 @@ unsigned char *ip;
118 if (i < 0) 109 if (i < 0)
119 { 110 {
120 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS); 111 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
121 ERR_add_error_data(2,"host=",str); 112 goto err;
122 return(0);
123 } 113 }
124 else
125 { /* do a gethostbyname */
126 if (!BIO_sock_init()) return(0);
127 114
128 he=BIO_gethostbyname(str); 115 /* do a gethostbyname */
129 if (he == NULL) 116 if (!BIO_sock_init())
130 { 117 return(0); /* don't generate another error code here */
131 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
132 ERR_add_error_data(2,"host=",str);
133 return(0);
134 }
135 118
136 /* cast to short because of win16 winsock definition */ 119 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
137 if ((short)he->h_addrtype != AF_INET) 120 locked = 1;
138 { 121 he=BIO_gethostbyname(str);
139 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET); 122 if (he == NULL)
140 ERR_add_error_data(2,"host=",str); 123 {
141 return(0); 124 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
142 } 125 goto err;
143 for (i=0; i<4; i++)
144 ip[i]=he->h_addr_list[0][i];
145 } 126 }
146 return(1); 127
128 /* cast to short because of win16 winsock definition */
129 if ((short)he->h_addrtype != AF_INET)
130 {
131 BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
132 goto err;
133 }
134 for (i=0; i<4; i++)
135 ip[i]=he->h_addr_list[0][i];
136 err = 0;
137
138 err:
139 if (locked)
140 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
141 if (err)
142 {
143 ERR_add_error_data(2,"host=",str);
144 return 0;
145 }
146 else
147 return 1;
147 } 148 }
148 149
149int BIO_get_port(str,port_ptr) 150int BIO_get_port(const char *str, unsigned short *port_ptr)
150char *str;
151short *port_ptr;
152 { 151 {
153 int i; 152 int i;
154 struct servent *s; 153 struct servent *s;
@@ -163,8 +162,12 @@ short *port_ptr;
163 *port_ptr=(unsigned short)i; 162 *port_ptr=(unsigned short)i;
164 else 163 else
165 { 164 {
166 s=getservbyname(str,"tcp"); 165 CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
167 if (s == NULL) 166 s=getservbyname(str,"tcp");
167 if(s != NULL)
168 *port_ptr=ntohs((unsigned short)s->s_port);
169 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
170 if(s == NULL)
168 { 171 {
169 if (strcmp(str,"http") == 0) 172 if (strcmp(str,"http") == 0)
170 *port_ptr=80; 173 *port_ptr=80;
@@ -190,31 +193,30 @@ short *port_ptr;
190 ERR_add_error_data(3,"service='",str,"'"); 193 ERR_add_error_data(3,"service='",str,"'");
191 return(0); 194 return(0);
192 } 195 }
193 return(1);
194 } 196 }
195 *port_ptr=htons((unsigned short)s->s_port);
196 } 197 }
197 return(1); 198 return(1);
198 } 199 }
199 200
200int BIO_sock_error(sock) 201int BIO_sock_error(int sock)
201int sock;
202 { 202 {
203 int j,i,size; 203 int j,i;
204 int size;
204 205
205 size=sizeof(int); 206 size=sizeof(int);
206 207 /* Note: under Windows the third parameter is of type (char *)
207 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(char *)&j,&size); 208 * whereas under other systems it is (void *) if you don't have
209 * a cast it will choke the compiler: if you do have a cast then
210 * you can either go for (char *) or (void *).
211 */
212 i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size);
208 if (i < 0) 213 if (i < 0)
209 return(1); 214 return(1);
210 else 215 else
211 return(j); 216 return(j);
212 } 217 }
213 218
214long BIO_ghbn_ctrl(cmd,iarg,parg) 219long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
215int cmd;
216int iarg;
217char *parg;
218 { 220 {
219 int i; 221 int i;
220 char **p; 222 char **p;
@@ -223,13 +225,13 @@ char *parg;
223 { 225 {
224 case BIO_GHBN_CTRL_HITS: 226 case BIO_GHBN_CTRL_HITS:
225 return(BIO_ghbn_hits); 227 return(BIO_ghbn_hits);
226 break; 228 /* break; */
227 case BIO_GHBN_CTRL_MISSES: 229 case BIO_GHBN_CTRL_MISSES:
228 return(BIO_ghbn_miss); 230 return(BIO_ghbn_miss);
229 break; 231 /* break; */
230 case BIO_GHBN_CTRL_CACHE_SIZE: 232 case BIO_GHBN_CTRL_CACHE_SIZE:
231 return(GHBN_NUM); 233 return(GHBN_NUM);
232 break; 234 /* break; */
233 case BIO_GHBN_CTRL_GET_ENTRY: 235 case BIO_GHBN_CTRL_GET_ENTRY:
234 if ((iarg >= 0) && (iarg <GHBN_NUM) && 236 if ((iarg >= 0) && (iarg <GHBN_NUM) &&
235 (ghbn_cache[iarg].order > 0)) 237 (ghbn_cache[iarg].order > 0))
@@ -241,7 +243,7 @@ char *parg;
241 return(1); 243 return(1);
242 } 244 }
243 return(0); 245 return(0);
244 break; 246 /* break; */
245 case BIO_GHBN_CTRL_FLUSH: 247 case BIO_GHBN_CTRL_FLUSH:
246 for (i=0; i<GHBN_NUM; i++) 248 for (i=0; i<GHBN_NUM; i++)
247 ghbn_cache[i].order=0; 249 ghbn_cache[i].order=0;
@@ -252,77 +254,84 @@ char *parg;
252 return(1); 254 return(1);
253 } 255 }
254 256
255static struct hostent *ghbn_dup(a) 257static struct hostent *ghbn_dup(struct hostent *a)
256struct hostent *a;
257 { 258 {
258 struct hostent *ret; 259 struct hostent *ret;
259 int i,j; 260 int i,j;
260 261
261 ret=(struct hostent *)malloc(sizeof(struct hostent)); 262 MemCheck_off();
263 ret=(struct hostent *)Malloc(sizeof(struct hostent));
262 if (ret == NULL) return(NULL); 264 if (ret == NULL) return(NULL);
263 memset(ret,0,sizeof(struct hostent)); 265 memset(ret,0,sizeof(struct hostent));
264 266
265 for (i=0; a->h_aliases[i] != NULL; i++) 267 for (i=0; a->h_aliases[i] != NULL; i++)
266 ; 268 ;
267 i++; 269 i++;
268 ret->h_aliases=(char **)malloc(sizeof(char *)*i); 270 ret->h_aliases = (char **)Malloc(i*sizeof(char *));
269 memset(ret->h_aliases,0,sizeof(char *)*i); 271 if (ret->h_aliases == NULL)
270 if (ret == NULL) goto err; 272 goto err;
273 memset(ret->h_aliases, 0, i*sizeof(char *));
271 274
272 for (i=0; a->h_addr_list[i] != NULL; i++) 275 for (i=0; a->h_addr_list[i] != NULL; i++)
273 ; 276 ;
274 i++; 277 i++;
275 ret->h_addr_list=(char **)malloc(sizeof(char *)*i); 278 ret->h_addr_list=(char **)Malloc(i*sizeof(char *));
276 memset(ret->h_addr_list,0,sizeof(char *)*i); 279 if (ret->h_addr_list == NULL)
277 if (ret->h_addr_list == NULL) goto err; 280 goto err;
281 memset(ret->h_addr_list, 0, i*sizeof(char *));
278 282
279 j=strlen(a->h_name)+1; 283 j=strlen(a->h_name)+1;
280 if ((ret->h_name=malloc(j)) == NULL) goto err; 284 if ((ret->h_name=Malloc(j)) == NULL) goto err;
281 memcpy((char *)ret->h_name,a->h_name,j); 285 memcpy((char *)ret->h_name,a->h_name,j+1);
282 for (i=0; a->h_aliases[i] != NULL; i++) 286 for (i=0; a->h_aliases[i] != NULL; i++)
283 { 287 {
284 j=strlen(a->h_aliases[i])+1; 288 j=strlen(a->h_aliases[i])+1;
285 if ((ret->h_aliases[i]=malloc(j)) == NULL) goto err; 289 if ((ret->h_aliases[i]=Malloc(j)) == NULL) goto err;
286 memcpy(ret->h_aliases[i],a->h_aliases[i],j); 290 memcpy(ret->h_aliases[i],a->h_aliases[i],j+1);
287 } 291 }
288 ret->h_length=a->h_length; 292 ret->h_length=a->h_length;
289 ret->h_addrtype=a->h_addrtype; 293 ret->h_addrtype=a->h_addrtype;
290 for (i=0; a->h_addr_list[i] != NULL; i++) 294 for (i=0; a->h_addr_list[i] != NULL; i++)
291 { 295 {
292 if ((ret->h_addr_list[i]=malloc(a->h_length)) == NULL) 296 if ((ret->h_addr_list[i]=Malloc(a->h_length)) == NULL)
293 goto err; 297 goto err;
294 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length); 298 memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
295 } 299 }
296 return(ret); 300 if (0)
301 {
297err: 302err:
298 if (ret != NULL) 303 if (ret != NULL)
299 ghbn_free(ret); 304 ghbn_free(ret);
300 return(NULL); 305 ret=NULL;
306 }
307 MemCheck_on();
308 return(ret);
301 } 309 }
302 310
303static void ghbn_free(a) 311static void ghbn_free(struct hostent *a)
304struct hostent *a;
305 { 312 {
306 int i; 313 int i;
307 314
315 if(a == NULL)
316 return;
317
308 if (a->h_aliases != NULL) 318 if (a->h_aliases != NULL)
309 { 319 {
310 for (i=0; a->h_aliases[i] != NULL; i++) 320 for (i=0; a->h_aliases[i] != NULL; i++)
311 free(a->h_aliases[i]); 321 Free(a->h_aliases[i]);
312 free(a->h_aliases); 322 Free(a->h_aliases);
313 } 323 }
314 if (a->h_addr_list != NULL) 324 if (a->h_addr_list != NULL)
315 { 325 {
316 for (i=0; a->h_addr_list[i] != NULL; i++) 326 for (i=0; a->h_addr_list[i] != NULL; i++)
317 free(a->h_addr_list[i]); 327 Free(a->h_addr_list[i]);
318 free(a->h_addr_list); 328 Free(a->h_addr_list);
319 } 329 }
320 if (a->h_name != NULL) free((char *)a->h_name); 330 if (a->h_name != NULL) Free((char *)a->h_name);
321 free(a); 331 Free(a);
322 } 332 }
323 333
324struct hostent *BIO_gethostbyname(name) 334struct hostent *BIO_gethostbyname(const char *name)
325char *name;
326 { 335 {
327 struct hostent *ret; 336 struct hostent *ret;
328 int i,lowi=0,j; 337 int i,lowi=0,j;
@@ -330,7 +339,12 @@ char *name;
330 339
331/* return(gethostbyname(name)); */ 340/* return(gethostbyname(name)); */
332 341
333 CRYPTO_w_lock(CRYPTO_LOCK_BIO_GETHOSTBYNAME); 342#if 0 /* It doesn't make sense to use locking here: The function interface
343 * is not thread-safe, because threads can never be sure when
344 * some other thread destroys the data they were given a pointer to.
345 */
346 CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
347#endif
334 j=strlen(name); 348 j=strlen(name);
335 if (j < 128) 349 if (j < 128)
336 { 350 {
@@ -356,15 +370,29 @@ char *name;
356 BIO_ghbn_miss++; 370 BIO_ghbn_miss++;
357 ret=gethostbyname(name); 371 ret=gethostbyname(name);
358 372
359 if (ret == NULL) return(NULL); 373 if (ret == NULL)
360 if (j > 128) return(ret); /* too big to cache */ 374 goto end;
375 if (j > 128) /* too big to cache */
376 {
377#if 0 /* If we were trying to make this function thread-safe (which
378 * is bound to fail), we'd have to give up in this case
379 * (or allocate more memory). */
380 ret = NULL;
381#endif
382 goto end;
383 }
361 384
362 /* else add to cache */ 385 /* else add to cache */
363 if (ghbn_cache[lowi].ent != NULL) 386 if (ghbn_cache[lowi].ent != NULL)
364 ghbn_free(ghbn_cache[lowi].ent); 387 ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
388 ghbn_cache[lowi].name[0] = '\0';
365 389
390 if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
391 {
392 BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE);
393 goto end;
394 }
366 strncpy(ghbn_cache[lowi].name,name,128); 395 strncpy(ghbn_cache[lowi].name,name,128);
367 ghbn_cache[lowi].ent=ghbn_dup(ret);
368 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits; 396 ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
369 } 397 }
370 else 398 else
@@ -373,11 +401,14 @@ char *name;
373 ret= ghbn_cache[i].ent; 401 ret= ghbn_cache[i].ent;
374 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; 402 ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
375 } 403 }
376 CRYPTO_w_unlock(CRYPTO_LOCK_BIO_GETHOSTBYNAME); 404end:
405#if 0
406 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
407#endif
377 return(ret); 408 return(ret);
378 } 409 }
379 410
380int BIO_sock_init() 411int BIO_sock_init(void)
381 { 412 {
382#ifdef WINDOWS 413#ifdef WINDOWS
383 static struct WSAData wsa_state; 414 static struct WSAData wsa_state;
@@ -403,7 +434,7 @@ int BIO_sock_init()
403 return(1); 434 return(1);
404 } 435 }
405 436
406void BIO_sock_cleanup() 437void BIO_sock_cleanup(void)
407 { 438 {
408#ifdef WINDOWS 439#ifdef WINDOWS
409 if (wsa_init_done) 440 if (wsa_init_done)
@@ -415,10 +446,9 @@ void BIO_sock_cleanup()
415#endif 446#endif
416 } 447 }
417 448
418int BIO_socket_ioctl(fd,type,arg) 449#if !defined(VMS) || __VMS_VER >= 70000000
419int fd; 450
420long type; 451int BIO_socket_ioctl(int fd, long type, unsigned long *arg)
421unsigned long *arg;
422 { 452 {
423 int i; 453 int i;
424 454
@@ -427,12 +457,11 @@ unsigned long *arg;
427 SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error()); 457 SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error());
428 return(i); 458 return(i);
429 } 459 }
460#endif /* __VMS_VER */
430 461
431/* The reason I have implemented this instead of using sscanf is because 462/* The reason I have implemented this instead of using sscanf is because
432 * Visual C 1.52c gives an unresolved external when linking a DLL :-( */ 463 * Visual C 1.52c gives an unresolved external when linking a DLL :-( */
433static int get_ip(str,ip) 464static int get_ip(const char *str, unsigned char ip[4])
434char *str;
435unsigned char ip[4];
436 { 465 {
437 unsigned int tmp[4]; 466 unsigned int tmp[4];
438 int num=0,c,ok=0; 467 int num=0,c,ok=0;
@@ -467,16 +496,17 @@ unsigned char ip[4];
467 return(1); 496 return(1);
468 } 497 }
469 498
470int BIO_get_accept_socket(host) 499int BIO_get_accept_socket(char *host, int bind_mode)
471char *host;
472 { 500 {
473 int ret=0; 501 int ret=0;
474 struct sockaddr_in server; 502 struct sockaddr_in server,client;
475 int s= -1; 503 int s= -1,cs;
476 unsigned char ip[4]; 504 unsigned char ip[4];
477 short port; 505 unsigned short port;
478 char *str,*h,*p,*e; 506 char *str,*e;
507 const char *h,*p;
479 unsigned long l; 508 unsigned long l;
509 int err_num;
480 510
481 if (!BIO_sock_init()) return(INVALID_SOCKET); 511 if (!BIO_sock_init()) return(INVALID_SOCKET);
482 512
@@ -508,7 +538,7 @@ char *host;
508 538
509 memset((char *)&server,0,sizeof(server)); 539 memset((char *)&server,0,sizeof(server));
510 server.sin_family=AF_INET; 540 server.sin_family=AF_INET;
511 server.sin_port=htons((unsigned short)port); 541 server.sin_port=htons(port);
512 542
513 if (strcmp(h,"*") == 0) 543 if (strcmp(h,"*") == 0)
514 server.sin_addr.s_addr=INADDR_ANY; 544 server.sin_addr.s_addr=INADDR_ANY;
@@ -517,12 +547,13 @@ char *host;
517 if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET); 547 if (!BIO_get_host_ip(h,&(ip[0]))) return(INVALID_SOCKET);
518 l=(unsigned long) 548 l=(unsigned long)
519 ((unsigned long)ip[0]<<24L)| 549 ((unsigned long)ip[0]<<24L)|
520 ((unsigned long)ip[0]<<16L)| 550 ((unsigned long)ip[1]<<16L)|
521 ((unsigned long)ip[0]<< 8L)| 551 ((unsigned long)ip[2]<< 8L)|
522 ((unsigned long)ip[0]); 552 ((unsigned long)ip[3]);
523 server.sin_addr.s_addr=htonl(l); 553 server.sin_addr.s_addr=htonl(l);
524 } 554 }
525 555
556again:
526 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); 557 s=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
527 if (s == INVALID_SOCKET) 558 if (s == INVALID_SOCKET)
528 { 559 {
@@ -531,9 +562,45 @@ char *host;
531 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET); 562 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
532 goto err; 563 goto err;
533 } 564 }
565
566#ifdef SO_REUSEADDR
567 if (bind_mode == BIO_BIND_REUSEADDR)
568 {
569 int i=1;
570
571 ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
572 bind_mode=BIO_BIND_NORMAL;
573 }
574#endif
534 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) 575 if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
535 { 576 {
536 SYSerr(SYS_F_BIND,get_last_socket_error()); 577#ifdef SO_REUSEADDR
578 err_num=get_last_socket_error();
579 if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
580 (err_num == EADDRINUSE))
581 {
582 memcpy((char *)&client,(char *)&server,sizeof(server));
583 if (strcmp(h,"*") == 0)
584 client.sin_addr.s_addr=htonl(0x7F000001);
585 cs=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
586 if (cs != INVALID_SOCKET)
587 {
588 int ii;
589 ii=connect(cs,(struct sockaddr *)&client,
590 sizeof(client));
591 closesocket(cs);
592 if (ii == INVALID_SOCKET)
593 {
594 bind_mode=BIO_BIND_REUSEADDR;
595 closesocket(s);
596 goto again;
597 }
598 /* else error */
599 }
600 /* else error */
601 }
602#endif
603 SYSerr(SYS_F_BIND,err_num);
537 ERR_add_error_data(3,"port='",host,"'"); 604 ERR_add_error_data(3,"port='",host,"'");
538 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET); 605 BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
539 goto err; 606 goto err;
@@ -550,30 +617,29 @@ err:
550 if (str != NULL) Free(str); 617 if (str != NULL) Free(str);
551 if ((ret == 0) && (s != INVALID_SOCKET)) 618 if ((ret == 0) && (s != INVALID_SOCKET))
552 { 619 {
553#ifdef WINDOWS
554 closesocket(s); 620 closesocket(s);
555#else
556 close(s);
557#endif
558 s= INVALID_SOCKET; 621 s= INVALID_SOCKET;
559 } 622 }
560 return(s); 623 return(s);
561 } 624 }
562 625
563int BIO_accept(sock,addr) 626int BIO_accept(int sock, char **addr)
564int sock;
565char **addr;
566 { 627 {
567 int ret=INVALID_SOCKET; 628 int ret=INVALID_SOCKET;
568 static struct sockaddr_in from; 629 static struct sockaddr_in from;
569 unsigned long l; 630 unsigned long l;
570 short port; 631 unsigned short port;
571 int len; 632 int len;
572 char *p; 633 char *p;
573 634
574 memset((char *)&from,0,sizeof(from)); 635 memset((char *)&from,0,sizeof(from));
575 len=sizeof(from); 636 len=sizeof(from);
576 ret=accept(sock,(struct sockaddr *)&from,&len); 637 /* Note: under VMS with SOCKETSHR the fourth parameter is currently
638 * of type (int *) whereas under other systems it is (void *) if
639 * you don't have a cast it will choke the compiler: if you do
640 * have a cast then you can either go for (int *) or (void *).
641 */
642 ret=accept(sock,(struct sockaddr *)&from,(void *)&len);
577 if (ret == INVALID_SOCKET) 643 if (ret == INVALID_SOCKET)
578 { 644 {
579 SYSerr(SYS_F_ACCEPT,get_last_socket_error()); 645 SYSerr(SYS_F_ACCEPT,get_last_socket_error());
@@ -604,9 +670,7 @@ end:
604 return(ret); 670 return(ret);
605 } 671 }
606 672
607int BIO_set_tcp_ndelay(s,on) 673int BIO_set_tcp_ndelay(int s, int on)
608int s;
609int on;
610 { 674 {
611 int ret=0; 675 int ret=0;
612#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP)) 676#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
@@ -626,3 +690,14 @@ int on;
626 } 690 }
627#endif 691#endif
628 692
693int BIO_socket_nbio(int s, int mode)
694 {
695 int ret= -1;
696 unsigned long l;
697
698 l=mode;
699#ifdef FIONBIO
700 ret=BIO_socket_ioctl(s,FIONBIO,&l);
701#endif
702 return(ret == 0);
703 }
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
index 7912b88473..acd8148138 100644
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ b/src/lib/libcrypto/bio/bf_buff.c
@@ -59,10 +59,9 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bio.h" 62#include <openssl/bio.h>
63#include "evp.h" 63#include <openssl/evp.h>
64 64
65#ifndef NOPROTO
66static int buffer_write(BIO *h,char *buf,int num); 65static int buffer_write(BIO *h,char *buf,int num);
67static int buffer_read(BIO *h,char *buf,int size); 66static int buffer_read(BIO *h,char *buf,int size);
68static int buffer_puts(BIO *h,char *str); 67static int buffer_puts(BIO *h,char *str);
@@ -70,16 +69,6 @@ static int buffer_gets(BIO *h,char *str,int size);
70static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long buffer_ctrl(BIO *h,int cmd,long arg1,char *arg2);
71static int buffer_new(BIO *h); 70static int buffer_new(BIO *h);
72static int buffer_free(BIO *data); 71static int buffer_free(BIO *data);
73#else
74static int buffer_write();
75static int buffer_read();
76static int buffer_puts();
77static int buffer_gets();
78static long buffer_ctrl();
79static int buffer_new();
80static int buffer_free();
81#endif
82
83#define DEFAULT_BUFFER_SIZE 1024 72#define DEFAULT_BUFFER_SIZE 1024
84 73
85static BIO_METHOD methods_buffer= 74static BIO_METHOD methods_buffer=
@@ -95,13 +84,12 @@ static BIO_METHOD methods_buffer=
95 buffer_free, 84 buffer_free,
96 }; 85 };
97 86
98BIO_METHOD *BIO_f_buffer() 87BIO_METHOD *BIO_f_buffer(void)
99 { 88 {
100 return(&methods_buffer); 89 return(&methods_buffer);
101 } 90 }
102 91
103static int buffer_new(bi) 92static int buffer_new(BIO *bi)
104BIO *bi;
105 { 93 {
106 BIO_F_BUFFER_CTX *ctx; 94 BIO_F_BUFFER_CTX *ctx;
107 95
@@ -124,8 +112,7 @@ BIO *bi;
124 return(1); 112 return(1);
125 } 113 }
126 114
127static int buffer_free(a) 115static int buffer_free(BIO *a)
128BIO *a;
129 { 116 {
130 BIO_F_BUFFER_CTX *b; 117 BIO_F_BUFFER_CTX *b;
131 118
@@ -140,10 +127,7 @@ BIO *a;
140 return(1); 127 return(1);
141 } 128 }
142 129
143static int buffer_read(b,out,outl) 130static int buffer_read(BIO *b, char *out, int outl)
144BIO *b;
145char *out;
146int outl;
147 { 131 {
148 int i,num=0; 132 int i,num=0;
149 BIO_F_BUFFER_CTX *ctx; 133 BIO_F_BUFFER_CTX *ctx;
@@ -209,10 +193,7 @@ start:
209 goto start; 193 goto start;
210 } 194 }
211 195
212static int buffer_write(b,in,inl) 196static int buffer_write(BIO *b, char *in, int inl)
213BIO *b;
214char *in;
215int inl;
216 { 197 {
217 int i,num=0; 198 int i,num=0;
218 BIO_F_BUFFER_CTX *ctx; 199 BIO_F_BUFFER_CTX *ctx;
@@ -285,11 +266,7 @@ start:
285 goto start; 266 goto start;
286 } 267 }
287 268
288static long buffer_ctrl(b,cmd,num,ptr) 269static long buffer_ctrl(BIO *b, int cmd, long num, char *ptr)
289BIO *b;
290int cmd;
291long num;
292char *ptr;
293 { 270 {
294 BIO *dbio; 271 BIO *dbio;
295 BIO_F_BUFFER_CTX *ctx; 272 BIO_F_BUFFER_CTX *ctx;
@@ -432,6 +409,7 @@ fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len-ctx->obuf_
432 break; 409 break;
433 } 410 }
434 } 411 }
412 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
435 break; 413 break;
436 case BIO_CTRL_DUP: 414 case BIO_CTRL_DUP:
437 dbio=(BIO *)ptr; 415 dbio=(BIO *)ptr;
@@ -449,10 +427,7 @@ malloc_error:
449 return(0); 427 return(0);
450 } 428 }
451 429
452static int buffer_gets(b,buf,size) 430static int buffer_gets(BIO *b, char *buf, int size)
453BIO *b;
454char *buf;
455int size;
456 { 431 {
457 BIO_F_BUFFER_CTX *ctx; 432 BIO_F_BUFFER_CTX *ctx;
458 int num=0,i,flag; 433 int num=0,i,flag;
@@ -503,9 +478,7 @@ int size;
503 } 478 }
504 } 479 }
505 480
506static int buffer_puts(b,str) 481static int buffer_puts(BIO *b, char *str)
507BIO *b;
508char *str;
509 { 482 {
510 return(BIO_write(b,str,strlen(str))); 483 return(BIO_write(b,str,strlen(str)));
511 } 484 }
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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "rand.h" 62#include <openssl/rand.h>
63#include "bio.h" 63#include <openssl/bio.h>
64#include "evp.h" 64#include <openssl/evp.h>
65 65
66/* BIO_put and BIO_get both add to the digest, 66/* BIO_put and BIO_get both add to the digest,
67 * BIO_gets returns the digest */ 67 * BIO_gets returns the digest */
68 68
69#ifndef NOPROTO
70static int nbiof_write(BIO *h,char *buf,int num); 69static int nbiof_write(BIO *h,char *buf,int num);
71static int nbiof_read(BIO *h,char *buf,int size); 70static int nbiof_read(BIO *h,char *buf,int size);
72static int nbiof_puts(BIO *h,char *str); 71static int nbiof_puts(BIO *h,char *str);
@@ -74,16 +73,6 @@ static int nbiof_gets(BIO *h,char *str,int size);
74static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2); 73static long nbiof_ctrl(BIO *h,int cmd,long arg1,char *arg2);
75static int nbiof_new(BIO *h); 74static int nbiof_new(BIO *h);
76static int nbiof_free(BIO *data); 75static int nbiof_free(BIO *data);
77#else
78static int nbiof_write();
79static int nbiof_read();
80static int nbiof_puts();
81static int nbiof_gets();
82static long nbiof_ctrl();
83static int nbiof_new();
84static int nbiof_free();
85#endif
86
87typedef struct nbio_test_st 76typedef struct nbio_test_st
88 { 77 {
89 /* only set if we sent a 'should retry' error */ 78 /* only set if we sent a 'should retry' error */
@@ -104,13 +93,12 @@ static BIO_METHOD methods_nbiof=
104 nbiof_free, 93 nbiof_free,
105 }; 94 };
106 95
107BIO_METHOD *BIO_f_nbio_test() 96BIO_METHOD *BIO_f_nbio_test(void)
108 { 97 {
109 return(&methods_nbiof); 98 return(&methods_nbiof);
110 } 99 }
111 100
112static int nbiof_new(bi) 101static int nbiof_new(BIO *bi)
113BIO *bi;
114 { 102 {
115 NBIO_TEST *nt; 103 NBIO_TEST *nt;
116 104
@@ -123,8 +111,7 @@ BIO *bi;
123 return(1); 111 return(1);
124 } 112 }
125 113
126static int nbiof_free(a) 114static int nbiof_free(BIO *a)
127BIO *a;
128 { 115 {
129 if (a == NULL) return(0); 116 if (a == NULL) return(0);
130 if (a->ptr != NULL) 117 if (a->ptr != NULL)
@@ -135,10 +122,7 @@ BIO *a;
135 return(1); 122 return(1);
136 } 123 }
137 124
138static int nbiof_read(b,out,outl) 125static int nbiof_read(BIO *b, char *out, int outl)
139BIO *b;
140char *out;
141int outl;
142 { 126 {
143 NBIO_TEST *nt; 127 NBIO_TEST *nt;
144 int ret=0; 128 int ret=0;
@@ -173,10 +157,7 @@ int outl;
173 return(ret); 157 return(ret);
174 } 158 }
175 159
176static int nbiof_write(b,in,inl) 160static int nbiof_write(BIO *b, char *in, int inl)
177BIO *b;
178char *in;
179int inl;
180 { 161 {
181 NBIO_TEST *nt; 162 NBIO_TEST *nt;
182 int ret=0; 163 int ret=0;
@@ -221,11 +202,7 @@ int inl;
221 return(ret); 202 return(ret);
222 } 203 }
223 204
224static long nbiof_ctrl(b,cmd,num,ptr) 205static long nbiof_ctrl(BIO *b, int cmd, long num, char *ptr)
225BIO *b;
226int cmd;
227long num;
228char *ptr;
229 { 206 {
230 long ret; 207 long ret;
231 208
@@ -247,19 +224,14 @@ char *ptr;
247 return(ret); 224 return(ret);
248 } 225 }
249 226
250static int nbiof_gets(bp,buf,size) 227static int nbiof_gets(BIO *bp, char *buf, int size)
251BIO *bp;
252char *buf;
253int size;
254 { 228 {
255 if (bp->next_bio == NULL) return(0); 229 if (bp->next_bio == NULL) return(0);
256 return(BIO_gets(bp->next_bio,buf,size)); 230 return(BIO_gets(bp->next_bio,buf,size));
257 } 231 }
258 232
259 233
260static int nbiof_puts(bp,str) 234static int nbiof_puts(BIO *bp, char *str)
261BIO *bp;
262char *str;
263 { 235 {
264 if (bp->next_bio == NULL) return(0); 236 if (bp->next_bio == NULL) return(0);
265 return(BIO_puts(bp->next_bio,str)); 237 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bio.h" 62#include <openssl/bio.h>
63#include "evp.h" 63#include <openssl/evp.h>
64 64
65/* BIO_put and BIO_get both add to the digest, 65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */ 66 * BIO_gets returns the digest */
67 67
68#ifndef NOPROTO
69static int nullf_write(BIO *h,char *buf,int num); 68static int nullf_write(BIO *h,char *buf,int num);
70static int nullf_read(BIO *h,char *buf,int size); 69static int nullf_read(BIO *h,char *buf,int size);
71static int nullf_puts(BIO *h,char *str); 70static int nullf_puts(BIO *h,char *str);
@@ -73,16 +72,6 @@ static int nullf_gets(BIO *h,char *str,int size);
73static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2); 72static long nullf_ctrl(BIO *h,int cmd,long arg1,char *arg2);
74static int nullf_new(BIO *h); 73static int nullf_new(BIO *h);
75static int nullf_free(BIO *data); 74static int nullf_free(BIO *data);
76#else
77static int nullf_write();
78static int nullf_read();
79static int nullf_puts();
80static int nullf_gets();
81static long nullf_ctrl();
82static int nullf_new();
83static int nullf_free();
84#endif
85
86static BIO_METHOD methods_nullf= 75static BIO_METHOD methods_nullf=
87 { 76 {
88 BIO_TYPE_NULL_FILTER, 77 BIO_TYPE_NULL_FILTER,
@@ -96,13 +85,12 @@ static BIO_METHOD methods_nullf=
96 nullf_free, 85 nullf_free,
97 }; 86 };
98 87
99BIO_METHOD *BIO_f_null() 88BIO_METHOD *BIO_f_null(void)
100 { 89 {
101 return(&methods_nullf); 90 return(&methods_nullf);
102 } 91 }
103 92
104static int nullf_new(bi) 93static int nullf_new(BIO *bi)
105BIO *bi;
106 { 94 {
107 bi->init=1; 95 bi->init=1;
108 bi->ptr=NULL; 96 bi->ptr=NULL;
@@ -110,8 +98,7 @@ BIO *bi;
110 return(1); 98 return(1);
111 } 99 }
112 100
113static int nullf_free(a) 101static int nullf_free(BIO *a)
114BIO *a;
115 { 102 {
116 if (a == NULL) return(0); 103 if (a == NULL) return(0);
117/* a->ptr=NULL; 104/* a->ptr=NULL;
@@ -120,10 +107,7 @@ BIO *a;
120 return(1); 107 return(1);
121 } 108 }
122 109
123static int nullf_read(b,out,outl) 110static int nullf_read(BIO *b, char *out, int outl)
124BIO *b;
125char *out;
126int outl;
127 { 111 {
128 int ret=0; 112 int ret=0;
129 113
@@ -135,10 +119,7 @@ int outl;
135 return(ret); 119 return(ret);
136 } 120 }
137 121
138static int nullf_write(b,in,inl) 122static int nullf_write(BIO *b, char *in, int inl)
139BIO *b;
140char *in;
141int inl;
142 { 123 {
143 int ret=0; 124 int ret=0;
144 125
@@ -150,11 +131,7 @@ int inl;
150 return(ret); 131 return(ret);
151 } 132 }
152 133
153static long nullf_ctrl(b,cmd,num,ptr) 134static long nullf_ctrl(BIO *b, int cmd, long num, char *ptr)
154BIO *b;
155int cmd;
156long num;
157char *ptr;
158 { 135 {
159 long ret; 136 long ret;
160 137
@@ -175,19 +152,14 @@ char *ptr;
175 return(ret); 152 return(ret);
176 } 153 }
177 154
178static int nullf_gets(bp,buf,size) 155static int nullf_gets(BIO *bp, char *buf, int size)
179BIO *bp;
180char *buf;
181int size;
182 { 156 {
183 if (bp->next_bio == NULL) return(0); 157 if (bp->next_bio == NULL) return(0);
184 return(BIO_gets(bp->next_bio,buf,size)); 158 return(BIO_gets(bp->next_bio,buf,size));
185 } 159 }
186 160
187 161
188static int nullf_puts(bp,str) 162static int nullf_puts(BIO *bp, char *str)
189BIO *bp;
190char *str;
191 { 163 {
192 if (bp->next_bio == NULL) return(0); 164 if (bp->next_bio == NULL) return(0);
193 return(BIO_puts(bp->next_bio,str)); 165 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 @@
1/* Error codes for the BIO functions. */
2
3/* Function codes. */
4#define BIO_F_ACPT_STATE 100
5#define BIO_F_BIO_ACCEPT 101
6#define BIO_F_BIO_CTRL 102
7#define BIO_F_BIO_GETS 103
8#define BIO_F_BIO_GET_ACCEPT_SOCKET 104
9#define BIO_F_BIO_GET_HOST_IP 105
10#define BIO_F_BIO_GET_PORT 106
11#define BIO_F_BIO_NEW 107
12#define BIO_F_BIO_NEW_FILE 108
13#define BIO_F_BIO_PUTS 109
14#define BIO_F_BIO_READ 110
15#define BIO_F_BIO_SOCK_INIT 111
16#define BIO_F_BIO_WRITE 112
17#define BIO_F_BUFFER_CTRL 113
18#define BIO_F_CONN_STATE 114
19#define BIO_F_FILE_CTRL 115
20#define BIO_F_MEM_WRITE 116
21#define BIO_F_SSL_NEW 117
22#define BIO_F_WSASTARTUP 118
23
24/* Reason codes. */
25#define BIO_R_ACCEPT_ERROR 100
26#define BIO_R_BAD_FOPEN_MODE 101
27#define BIO_R_BAD_HOSTNAME_LOOKUP 102
28#define BIO_R_CONNECT_ERROR 103
29#define BIO_R_ERROR_SETTING_NBIO 104
30#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
31#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
32#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
33#define BIO_R_INVALID_IP_ADDRESS 108
34#define BIO_R_KEEPALIVE 109
35#define BIO_R_NBIO_CONNECT_ERROR 110
36#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
37#define BIO_R_NO_HOSTHNAME_SPECIFIED 112
38#define BIO_R_NO_PORT_DEFINED 113
39#define BIO_R_NO_PORT_SPECIFIED 114
40#define BIO_R_NULL_PARAMETER 115
41#define BIO_R_UNABLE_TO_BIND_SOCKET 116
42#define BIO_R_UNABLE_TO_CREATE_SOCKET 117
43#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118
44#define BIO_R_UNINITALISED 119
45#define BIO_R_UNSUPPORTED_METHOD 120
46#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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "crypto.h" 66#include <stdio.h>
67#include <stdlib.h>
68#include <openssl/crypto.h>
67 69
68/* These are the 'types' of BIOs */ 70/* These are the 'types' of BIOs */
69#define BIO_TYPE_NONE 0 71#define BIO_TYPE_NONE 0
@@ -84,6 +86,8 @@ extern "C" {
84#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ 86#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */
85#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ 87#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */
86#define BIO_TYPE_NULL_FILTER (17|0x0200) 88#define BIO_TYPE_NULL_FILTER (17|0x0200)
89#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */
90#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
87 91
88#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ 92#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
89#define BIO_TYPE_FILTER 0x0200 93#define BIO_TYPE_FILTER 0x0200
@@ -202,7 +206,7 @@ extern "C" {
202typedef struct bio_method_st 206typedef struct bio_method_st
203 { 207 {
204 int type; 208 int type;
205 char *name; 209 const char *name;
206 int (*bwrite)(); 210 int (*bwrite)();
207 int (*bread)(); 211 int (*bread)();
208 int (*bputs)(); 212 int (*bputs)();
@@ -215,7 +219,7 @@ typedef struct bio_method_st
215typedef struct bio_method_st 219typedef struct bio_method_st
216 { 220 {
217 int type; 221 int type;
218 char *name; 222 const char *name;
219 int (_far *bwrite)(); 223 int (_far *bwrite)();
220 int (_far *bread)(); 224 int (_far *bread)();
221 int (_far *bputs)(); 225 int (_far *bputs)();
@@ -229,12 +233,8 @@ typedef struct bio_method_st
229typedef struct bio_st 233typedef struct bio_st
230 { 234 {
231 BIO_METHOD *method; 235 BIO_METHOD *method;
232#ifndef NOPROTO
233 /* bio, mode, argp, argi, argl, ret */ 236 /* bio, mode, argp, argi, argl, ret */
234 long (*callback)(struct bio_st *,int,char *,int, long,long); 237 long (*callback)(struct bio_st *,int,const char *,int, long,long);
235#else
236 long (*callback)();
237#endif
238 char *cb_arg; /* first argument for the callback */ 238 char *cb_arg; /* first argument for the callback */
239 239
240 int init; 240 int init;
@@ -242,7 +242,7 @@ typedef struct bio_st
242 int flags; /* extra storage */ 242 int flags; /* extra storage */
243 int retry_reason; 243 int retry_reason;
244 int num; 244 int num;
245 char *ptr; 245 void *ptr;
246 struct bio_st *next_bio; /* used by filter BIOs */ 246 struct bio_st *next_bio; /* used by filter BIOs */
247 struct bio_st *prev_bio; /* used by filter BIOs */ 247 struct bio_st *prev_bio; /* used by filter BIOs */
248 int references; 248 int references;
@@ -276,7 +276,7 @@ typedef struct bio_f_buffer_ctx_struct
276#define BIO_CONN_S_OK 6 276#define BIO_CONN_S_OK 6
277#define BIO_CONN_S_BLOCKED_CONNECT 7 277#define BIO_CONN_S_BLOCKED_CONNECT 7
278#define BIO_CONN_S_NBIO 8 278#define BIO_CONN_S_NBIO 8
279#define BIO_CONN_get_param_hostname BIO_ctrl 279/*#define BIO_CONN_get_param_hostname BIO_ctrl */
280 280
281#define BIO_number_read(b) ((b)->num_read) 281#define BIO_number_read(b) ((b)->num_read)
282#define BIO_number_written(b) ((b)->num_write) 282#define BIO_number_written(b) ((b)->num_write)
@@ -309,18 +309,28 @@ typedef struct bio_f_buffer_ctx_struct
309#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 309#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125
310#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 310#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126
311#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 311#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127
312#define BIO_C_FILE_SEEK 128
313#define BIO_C_GET_CIPHER_CTX 129
314#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/
315#define BIO_C_SET_BIND_MODE 131
316#define BIO_C_GET_BIND_MODE 132
317#define BIO_C_FILE_TELL 133
318#define BIO_C_GET_SOCKS 134
319#define BIO_C_SET_SOCKS 135
320
321#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */
322#define BIO_C_GET_WRITE_BUF_SIZE 137
323#define BIO_C_MAKE_BIO_PAIR 138
324#define BIO_C_DESTROY_BIO_PAIR 139
325#define BIO_C_GET_WRITE_GUARANTEE 140
326#define BIO_C_GET_READ_REQUEST 141
327#define BIO_C_SHUTDOWN_WR 142
328
312 329
313#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) 330#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg)
314#define BIO_get_app_data(s) BIO_get_ex_data(s,0) 331#define BIO_get_app_data(s) BIO_get_ex_data(s,0)
315 332
316int BIO_get_ex_num(BIO *bio); 333/* BIO_s_connect() and BIO_s_socks4a_connect() */
317int BIO_set_ex_data(BIO *bio,int idx,char *data);
318char *BIO_get_ex_data(BIO *bio,int idx);
319void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)());
320int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(),
321 int (*dup_func)(), void (*free_func)());
322
323/* BIO_s_connect_socket() */
324#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) 334#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
325#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) 335#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
326#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) 336#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)(),
328#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) 338#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
329#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) 339#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
330#define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2) 340#define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2)
331#define BIO_get_conn_int port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) 341#define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port)
342
332 343
333#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) 344#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
334 345
@@ -339,6 +350,12 @@ int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(),
339#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) 350#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL)
340#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) 351#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
341 352
353#define BIO_BIND_NORMAL 0
354#define BIO_BIND_REUSEADDR_IF_UNUSED 1
355#define BIO_BIND_REUSEADDR 2
356#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
357#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
358
342#define BIO_do_connect(b) BIO_do_handshake(b) 359#define BIO_do_connect(b) BIO_do_handshake(b)
343#define BIO_do_accept(b) BIO_do_handshake(b) 360#define BIO_do_accept(b) BIO_do_handshake(b)
344#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) 361#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)(),
364#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) 381#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
365#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) 382#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
366 383
384#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
385#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
386
387/* name is cast to lose const, but might be better to route through a function
388 so we can do it safely */
389#ifdef CONST_STRICT
390/* If you are wondering why this isn't defined, its because CONST_STRICT is
391 * purely a compile-time kludge to allow const to be checked.
392 */
393int BIO_read_filename(BIO *b,const char *name);
394#else
367#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 395#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
368 BIO_CLOSE|BIO_FP_READ,name) 396 BIO_CLOSE|BIO_FP_READ,(char *)name)
397#endif
369#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 398#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
370 BIO_CLOSE|BIO_FP_WRITE,name) 399 BIO_CLOSE|BIO_FP_WRITE,name)
371#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 400#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
372 BIO_CLOSE|BIO_FP_APPEND,name) 401 BIO_CLOSE|BIO_FP_APPEND,name)
402#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
403 BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
373 404
374/* WARNING WARNING, this ups the reference count on the read bio of the 405/* WARNING WARNING, this ups the reference count on the read bio of the
375 * SSL structure. This is because the ssl read BIO is now pointed to by 406 * 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)(),
388/* defined in evp.h */ 419/* defined in evp.h */
389/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ 420/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
390 421
422#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
391#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) 423#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
392#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) 424#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
425#define BIO_set_mem_eof_return(b,v) \
426 BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
393 427
394/* For the BIO_f_buffer() type */ 428/* For the BIO_f_buffer() type */
395#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) 429#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)(),
407#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) 441#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
408#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) 442#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
409#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) 443#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
444/* ...pending macros have inappropriate return type */
445size_t BIO_ctrl_pending(BIO *b);
446size_t BIO_ctrl_wpending(BIO *b);
410#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) 447#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
411#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp) 448#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp)
412#define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb) 449#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)(),
414/* For the BIO_f_buffer() type */ 451/* For the BIO_f_buffer() type */
415#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) 452#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
416 453
454/* For BIO_s_bio() */
455#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
456#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
457#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
458#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
459/* macros with inappropriate type -- but ...pending macros use int too: */
460#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
461#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
462size_t BIO_ctrl_get_write_guarantee(BIO *b);
463size_t BIO_ctrl_get_read_request(BIO *b);
464
465
466
417#ifdef NO_STDIO 467#ifdef NO_STDIO
418#define NO_FP_API 468#define NO_FP_API
419#endif 469#endif
420 470
421#ifndef NOPROTO 471
472/* These two aren't currently implemented */
473/* int BIO_get_ex_num(BIO *bio); */
474/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
475int BIO_set_ex_data(BIO *bio,int idx,char *data);
476char *BIO_get_ex_data(BIO *bio,int idx);
477int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(),
478 int (*dup_func)(), void (*free_func)());
479
422# if defined(WIN16) && defined(_WINDLL) 480# if defined(WIN16) && defined(_WINDLL)
423BIO_METHOD *BIO_s_file_internal(void); 481BIO_METHOD *BIO_s_file_internal(void);
424BIO *BIO_new_file_internal(char *filename, char *mode); 482BIO *BIO_new_file_internal(char *filename, char *mode);
@@ -428,39 +486,20 @@ BIO *BIO_new_fp_internal(FILE *stream, int close_flag);
428# define BIO_new_fp BIO_new_fp_internal 486# define BIO_new_fp BIO_new_fp_internal
429# else /* FP_API */ 487# else /* FP_API */
430BIO_METHOD *BIO_s_file(void ); 488BIO_METHOD *BIO_s_file(void );
431BIO *BIO_new_file(char *filename, char *mode); 489BIO *BIO_new_file(const char *filename, const char *mode);
432BIO *BIO_new_fp(FILE *stream, int close_flag); 490BIO *BIO_new_fp(FILE *stream, int close_flag);
433# define BIO_s_file_internal BIO_s_file 491# define BIO_s_file_internal BIO_s_file
434# define BIO_new_file_internal BIO_new_file 492# define BIO_new_file_internal BIO_new_file
435# define BIO_new_fp_internal BIO_s_file 493# define BIO_new_fp_internal BIO_s_file
436# endif /* FP_API */ 494# endif /* FP_API */
437#else
438# if defined(WIN16) && defined(_WINDLL)
439BIO_METHOD *BIO_s_file_internal();
440BIO *BIO_new_file_internal();
441BIO *BIO_new_fp_internal();
442# define BIO_s_file BIO_s_file_internal
443# define BIO_new_file BIO_new_file_internal
444# define BIO_new_fp BIO_new_fp_internal
445# else /* FP_API */
446BIO_METHOD *BIO_s_file();
447BIO *BIO_new_file();
448BIO *BIO_new_fp();
449# define BIO_s_file_internal BIO_s_file
450# define BIO_new_file_internal BIO_new_file
451# define BIO_new_fp_internal BIO_s_file
452# endif /* FP_API */
453#endif
454
455#ifndef NOPROTO
456BIO * BIO_new(BIO_METHOD *type); 495BIO * BIO_new(BIO_METHOD *type);
457int BIO_set(BIO *a,BIO_METHOD *type); 496int BIO_set(BIO *a,BIO_METHOD *type);
458int BIO_free(BIO *a); 497int BIO_free(BIO *a);
459int BIO_read(BIO *b, char *data, int len); 498int BIO_read(BIO *b, void *data, int len);
460int BIO_gets(BIO *bp,char *buf, int size); 499int BIO_gets(BIO *bp,char *buf, int size);
461int BIO_write(BIO *b, char *data, int len); 500int BIO_write(BIO *b, const char *data, int len);
462int BIO_puts(BIO *bp,char *buf); 501int BIO_puts(BIO *bp,const char *buf);
463long BIO_ctrl(BIO *bp,int cmd,long larg,char *parg); 502long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
464char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); 503char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
465long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); 504long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
466BIO * BIO_push(BIO *b,BIO *append); 505BIO * BIO_push(BIO *b,BIO *append);
@@ -472,10 +511,10 @@ int BIO_get_retry_reason(BIO *bio);
472BIO * BIO_dup_chain(BIO *in); 511BIO * BIO_dup_chain(BIO *in);
473 512
474#ifndef WIN16 513#ifndef WIN16
475long BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi, 514long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
476 long argl,long ret); 515 long argl,long ret);
477#else 516#else
478long _far _loadds BIO_debug_callback(BIO *bio,int cmd,char *argp,int argi, 517long _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
479 long argl,long ret); 518 long argl,long ret);
480#endif 519#endif
481 520
@@ -484,23 +523,35 @@ BIO_METHOD *BIO_s_socket(void);
484BIO_METHOD *BIO_s_connect(void); 523BIO_METHOD *BIO_s_connect(void);
485BIO_METHOD *BIO_s_accept(void); 524BIO_METHOD *BIO_s_accept(void);
486BIO_METHOD *BIO_s_fd(void); 525BIO_METHOD *BIO_s_fd(void);
526BIO_METHOD *BIO_s_log(void);
527BIO_METHOD *BIO_s_bio(void);
487BIO_METHOD *BIO_s_null(void); 528BIO_METHOD *BIO_s_null(void);
488BIO_METHOD *BIO_f_null(void); 529BIO_METHOD *BIO_f_null(void);
489BIO_METHOD *BIO_f_nbio_test(void);
490BIO_METHOD *BIO_f_buffer(void); 530BIO_METHOD *BIO_f_buffer(void);
531BIO_METHOD *BIO_f_nbio_test(void);
532/* BIO_METHOD *BIO_f_ber(void); */
491 533
492int BIO_sock_should_retry(int i); 534int BIO_sock_should_retry(int i);
493int BIO_sock_non_fatal_error(int error); 535int BIO_sock_non_fatal_error(int error);
494int BIO_fd_should_retry(int i); 536int BIO_fd_should_retry(int i);
495int BIO_fd_non_fatal_error(int error); 537int BIO_fd_non_fatal_error(int error);
496int BIO_dump(BIO *b,char *bytes,int len); 538int BIO_dump(BIO *b,const char *bytes,int len);
497 539
498struct hostent *BIO_gethostbyname(char *name); 540struct hostent *BIO_gethostbyname(const char *name);
541/* We might want a thread-safe interface too:
542 * struct hostent *BIO_gethostbyname_r(const char *name,
543 * struct hostent *result, void *buffer, size_t buflen);
544 * or something similar (caller allocates a struct hostent,
545 * pointed to by "result", and additional buffer space for the various
546 * substructures; if the buffer does not suffice, NULL is returned
547 * and an appropriate error code is set).
548 */
499int BIO_sock_error(int sock); 549int BIO_sock_error(int sock);
500int BIO_socket_ioctl(int fd, long type, unsigned long *arg); 550int BIO_socket_ioctl(int fd, long type, unsigned long *arg);
501int BIO_get_port(char *str, short *port_ptr); 551int BIO_socket_nbio(int fd,int mode);
502int BIO_get_host_ip(char *str, unsigned char *ip); 552int BIO_get_port(const char *str, unsigned short *port_ptr);
503int BIO_get_accept_socket(char *host_port); 553int BIO_get_host_ip(const char *str, unsigned char *ip);
554int BIO_get_accept_socket(char *host_port,int mode);
504int BIO_accept(int sock,char **ip_port); 555int BIO_accept(int sock,char **ip_port);
505int BIO_sock_init(void ); 556int BIO_sock_init(void );
506void BIO_sock_cleanup(void); 557void BIO_sock_cleanup(void);
@@ -513,174 +564,78 @@ BIO *BIO_new_fd(int fd, int close_flag);
513BIO *BIO_new_connect(char *host_port); 564BIO *BIO_new_connect(char *host_port);
514BIO *BIO_new_accept(char *host_port); 565BIO *BIO_new_accept(char *host_port);
515 566
567int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
568 BIO **bio2, size_t writebuf2);
569/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
570 * Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
571 * Size 0 uses default value.
572 */
573
516void BIO_copy_next_retry(BIO *b); 574void BIO_copy_next_retry(BIO *b);
517 575
518long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); 576long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
519 577
520#else 578int BIO_printf(BIO *bio, ...);
521
522BIO * BIO_new();
523int BIO_set();
524int BIO_free();
525int BIO_read();
526int BIO_gets();
527int BIO_write();
528int BIO_puts();
529char * BIO_ptr_ctrl();
530long BIO_ctrl();
531long BIO_int_ctrl();
532BIO * BIO_push();
533BIO * BIO_pop();
534void BIO_free_all();
535BIO * BIO_find_type();
536BIO * BIO_get_retry_BIO();
537int BIO_get_retry_reason();
538BIO * BIO_dup_chain();
539
540#ifndef WIN16
541long BIO_debug_callback();
542#else
543long _far _loadds BIO_debug_callback();
544#endif
545
546BIO_METHOD *BIO_s_mem();
547BIO_METHOD *BIO_s_socket();
548BIO_METHOD *BIO_s_connect();
549BIO_METHOD *BIO_s_accept();
550BIO_METHOD *BIO_s_fd();
551BIO_METHOD *BIO_s_null();
552BIO_METHOD *BIO_f_null();
553BIO_METHOD *BIO_f_buffer();
554BIO_METHOD *BIO_f_nbio_test();
555
556int BIO_sock_should_retry();
557int BIO_sock_non_fatal_error();
558int BIO_fd_should_retry();
559int BIO_fd_non_fatal_error();
560int BIO_dump();
561
562struct hostent *BIO_gethostbyname();
563int BIO_sock_error();
564int BIO_socket_ioctl();
565int BIO_get_port();
566int BIO_get_host_ip();
567int BIO_get_accept_socket();
568int BIO_accept();
569int BIO_sock_init();
570void BIO_sock_cleanup();
571int BIO_set_tcp_ndelay();
572
573void ERR_load_BIO_strings();
574
575BIO *BIO_new_socket();
576BIO *BIO_new_fd();
577BIO *BIO_new_connect();
578BIO *BIO_new_accept();
579
580void BIO_copy_next_retry();
581
582int BIO_ghbn_ctrl();
583
584#endif
585
586/* Tim Hudson's portable varargs stuff */
587
588#ifndef NOPROTO
589#define VAR_ANSI /* select ANSI version by default */
590#endif
591
592#ifdef VAR_ANSI
593/* ANSI version of a "portable" macro set for variable length args */
594#ifndef __STDARG_H__ /**/
595#include <stdarg.h>
596#endif /**/
597
598#define VAR_PLIST(arg1type,arg1) arg1type arg1, ...
599#define VAR_PLIST2(arg1type,arg1,arg2type,arg2) arg1type arg1,arg2type arg2,...
600#define VAR_ALIST
601#define VAR_BDEFN(args,arg1type,arg1) va_list args
602#define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args
603#define VAR_INIT(args,arg1type,arg1) va_start(args,arg1);
604#define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args,arg2);
605#define VAR_ARG(args,type,arg) arg=va_arg(args,type)
606#define VAR_END(args) va_end(args);
607
608#else
609
610/* K&R version of a "portable" macro set for variable length args */
611#ifndef __VARARGS_H__
612#include <varargs.h>
613#endif
614
615#define VAR_PLIST(arg1type,arg1) va_alist
616#define VAR_PLIST2(arg1type,arg1,arg2type,arg2) va_alist
617#define VAR_ALIST va_dcl
618#define VAR_BDEFN(args,arg1type,arg1) va_list args; arg1type arg1
619#define VAR_BDEFN2(args,arg1type,arg1,arg2type,arg2) va_list args; \
620 arg1type arg1; arg2type arg2
621#define VAR_INIT(args,arg1type,arg1) va_start(args); \
622 arg1=va_arg(args,arg1type);
623#define VAR_INIT2(args,arg1type,arg1,arg2type,arg2) va_start(args); \
624 arg1=va_arg(args,arg1type); arg2=va_arg(args,arg2type);
625#define VAR_ARG(args,type,arg) arg=va_arg(args,type)
626#define VAR_END(args) va_end(args);
627
628#endif
629
630#ifndef NOPROTO
631int BIO_printf( VAR_PLIST( BIO *, bio ) );
632#else
633int BIO_printf();
634#endif
635 579
636/* BEGIN ERROR CODES */ 580/* BEGIN ERROR CODES */
581/* The following lines are auto generated by the script mkerr.pl. Any changes
582 * made after this point may be overwritten when the script is next run.
583 */
584
637/* Error codes for the BIO functions. */ 585/* Error codes for the BIO functions. */
638 586
639/* Function codes. */ 587/* Function codes. */
640#define BIO_F_ACPT_STATE 100 588#define BIO_F_ACPT_STATE 100
641#define BIO_F_BIO_ACCEPT 101 589#define BIO_F_BIO_ACCEPT 101
642#define BIO_F_BIO_CTRL 102 590#define BIO_F_BIO_BER_GET_HEADER 102
643#define BIO_F_BIO_GETS 103 591#define BIO_F_BIO_CTRL 103
644#define BIO_F_BIO_GET_ACCEPT_SOCKET 104 592#define BIO_F_BIO_GETHOSTBYNAME 120
645#define BIO_F_BIO_GET_HOST_IP 105 593#define BIO_F_BIO_GETS 104
646#define BIO_F_BIO_GET_PORT 106 594#define BIO_F_BIO_GET_ACCEPT_SOCKET 105
647#define BIO_F_BIO_NEW 107 595#define BIO_F_BIO_GET_HOST_IP 106
648#define BIO_F_BIO_NEW_FILE 108 596#define BIO_F_BIO_GET_PORT 107
649#define BIO_F_BIO_PUTS 109 597#define BIO_F_BIO_MAKE_PAIR 121
650#define BIO_F_BIO_READ 110 598#define BIO_F_BIO_NEW 108
651#define BIO_F_BIO_SOCK_INIT 111 599#define BIO_F_BIO_NEW_FILE 109
652#define BIO_F_BIO_WRITE 112 600#define BIO_F_BIO_PUTS 110
653#define BIO_F_BUFFER_CTRL 113 601#define BIO_F_BIO_READ 111
654#define BIO_F_CONN_STATE 114 602#define BIO_F_BIO_SOCK_INIT 112
655#define BIO_F_FILE_CTRL 115 603#define BIO_F_BIO_WRITE 113
656#define BIO_F_MEM_WRITE 116 604#define BIO_F_BUFFER_CTRL 114
657#define BIO_F_SSL_NEW 117 605#define BIO_F_CONN_STATE 115
658#define BIO_F_WSASTARTUP 118 606#define BIO_F_FILE_CTRL 116
607#define BIO_F_MEM_WRITE 117
608#define BIO_F_SSL_NEW 118
609#define BIO_F_WSASTARTUP 119
659 610
660/* Reason codes. */ 611/* Reason codes. */
661#define BIO_R_ACCEPT_ERROR 100 612#define BIO_R_ACCEPT_ERROR 100
662#define BIO_R_BAD_FOPEN_MODE 101 613#define BIO_R_BAD_FOPEN_MODE 101
663#define BIO_R_BAD_HOSTNAME_LOOKUP 102 614#define BIO_R_BAD_HOSTNAME_LOOKUP 102
615#define BIO_R_BROKEN_PIPE 124
664#define BIO_R_CONNECT_ERROR 103 616#define BIO_R_CONNECT_ERROR 103
665#define BIO_R_ERROR_SETTING_NBIO 104 617#define BIO_R_ERROR_SETTING_NBIO 104
666#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 618#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105
667#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 619#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106
668#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 620#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107
621#define BIO_R_INVALID_ARGUMENT 125
669#define BIO_R_INVALID_IP_ADDRESS 108 622#define BIO_R_INVALID_IP_ADDRESS 108
623#define BIO_R_IN_USE 123
670#define BIO_R_KEEPALIVE 109 624#define BIO_R_KEEPALIVE 109
671#define BIO_R_NBIO_CONNECT_ERROR 110 625#define BIO_R_NBIO_CONNECT_ERROR 110
672#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 626#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111
673#define BIO_R_NO_HOSTHNAME_SPECIFIED 112 627#define BIO_R_NO_HOSTNAME_SPECIFIED 112
674#define BIO_R_NO_PORT_DEFINED 113 628#define BIO_R_NO_PORT_DEFINED 113
675#define BIO_R_NO_PORT_SPECIFIED 114 629#define BIO_R_NO_PORT_SPECIFIED 114
676#define BIO_R_NULL_PARAMETER 115 630#define BIO_R_NULL_PARAMETER 115
677#define BIO_R_UNABLE_TO_BIND_SOCKET 116 631#define BIO_R_TAG_MISMATCH 116
678#define BIO_R_UNABLE_TO_CREATE_SOCKET 117 632#define BIO_R_UNABLE_TO_BIND_SOCKET 117
679#define BIO_R_UNABLE_TO_LISTEN_SOCKET 118 633#define BIO_R_UNABLE_TO_CREATE_SOCKET 118
680#define BIO_R_UNINITALISED 119 634#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119
681#define BIO_R_UNSUPPORTED_METHOD 120 635#define BIO_R_UNINITIALIZED 120
682#define BIO_R_WSASTARTUP 121 636#define BIO_R_UNSUPPORTED_METHOD 121
683 637#define BIO_R_WSASTARTUP 122
638
684#ifdef __cplusplus 639#ifdef __cplusplus
685} 640}
686#endif 641#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 @@
60#include <string.h> 60#include <string.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "bio.h" 63#include <openssl/bio.h>
64#include "err.h" 64#include <openssl/err.h>
65 65
66long MS_CALLBACK BIO_debug_callback(bio,cmd,argp,argi,argl,ret) 66long MS_CALLBACK BIO_debug_callback(BIO *bio, int cmd, const char *argp,
67BIO *bio; 67 int argi, long argl, long ret)
68int cmd;
69char *argp;
70int argi;
71long argl;
72long ret;
73 { 68 {
74 BIO *b; 69 BIO *b;
75 MS_STATIC char buf[256]; 70 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 @@
1/* lib/bio/bio_err.c */ 1/* crypto/bio/bio_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "bio.h" 62#include <openssl/bio.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -65,11 +67,14 @@ static ERR_STRING_DATA BIO_str_functs[]=
65 { 67 {
66{ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"}, 68{ERR_PACK(0,BIO_F_ACPT_STATE,0), "ACPT_STATE"},
67{ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"}, 69{ERR_PACK(0,BIO_F_BIO_ACCEPT,0), "BIO_accept"},
70{ERR_PACK(0,BIO_F_BIO_BER_GET_HEADER,0), "BIO_BER_GET_HEADER"},
68{ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"}, 71{ERR_PACK(0,BIO_F_BIO_CTRL,0), "BIO_ctrl"},
72{ERR_PACK(0,BIO_F_BIO_GETHOSTBYNAME,0), "BIO_gethostbyname"},
69{ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"}, 73{ERR_PACK(0,BIO_F_BIO_GETS,0), "BIO_gets"},
70{ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"}, 74{ERR_PACK(0,BIO_F_BIO_GET_ACCEPT_SOCKET,0), "BIO_get_accept_socket"},
71{ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"}, 75{ERR_PACK(0,BIO_F_BIO_GET_HOST_IP,0), "BIO_get_host_ip"},
72{ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"}, 76{ERR_PACK(0,BIO_F_BIO_GET_PORT,0), "BIO_get_port"},
77{ERR_PACK(0,BIO_F_BIO_MAKE_PAIR,0), "BIO_MAKE_PAIR"},
73{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"}, 78{ERR_PACK(0,BIO_F_BIO_NEW,0), "BIO_new"},
74{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"}, 79{ERR_PACK(0,BIO_F_BIO_NEW_FILE,0), "BIO_new_file"},
75{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"}, 80{ERR_PACK(0,BIO_F_BIO_PUTS,0), "BIO_puts"},
@@ -80,9 +85,9 @@ static ERR_STRING_DATA BIO_str_functs[]=
80{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"}, 85{ERR_PACK(0,BIO_F_CONN_STATE,0), "CONN_STATE"},
81{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"}, 86{ERR_PACK(0,BIO_F_FILE_CTRL,0), "FILE_CTRL"},
82{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"}, 87{ERR_PACK(0,BIO_F_MEM_WRITE,0), "MEM_WRITE"},
83{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_NEW"}, 88{ERR_PACK(0,BIO_F_SSL_NEW,0), "SSL_new"},
84{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"}, 89{ERR_PACK(0,BIO_F_WSASTARTUP,0), "WSASTARTUP"},
85{0,NULL}, 90{0,NULL}
86 }; 91 };
87 92
88static ERR_STRING_DATA BIO_str_reasons[]= 93static ERR_STRING_DATA BIO_str_reasons[]=
@@ -90,36 +95,40 @@ static ERR_STRING_DATA BIO_str_reasons[]=
90{BIO_R_ACCEPT_ERROR ,"accept error"}, 95{BIO_R_ACCEPT_ERROR ,"accept error"},
91{BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"}, 96{BIO_R_BAD_FOPEN_MODE ,"bad fopen mode"},
92{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"}, 97{BIO_R_BAD_HOSTNAME_LOOKUP ,"bad hostname lookup"},
98{BIO_R_BROKEN_PIPE ,"broken pipe"},
93{BIO_R_CONNECT_ERROR ,"connect error"}, 99{BIO_R_CONNECT_ERROR ,"connect error"},
94{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"}, 100{BIO_R_ERROR_SETTING_NBIO ,"error setting nbio"},
95{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"}, 101{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET,"error setting nbio on accepted socket"},
96{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"}, 102{BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET,"error setting nbio on accept socket"},
97{BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"}, 103{BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET ,"gethostbyname addr is not af inet"},
104{BIO_R_INVALID_ARGUMENT ,"invalid argument"},
98{BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"}, 105{BIO_R_INVALID_IP_ADDRESS ,"invalid ip address"},
106{BIO_R_IN_USE ,"in use"},
99{BIO_R_KEEPALIVE ,"keepalive"}, 107{BIO_R_KEEPALIVE ,"keepalive"},
100{BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"}, 108{BIO_R_NBIO_CONNECT_ERROR ,"nbio connect error"},
101{BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"}, 109{BIO_R_NO_ACCEPT_PORT_SPECIFIED ,"no accept port specified"},
102{BIO_R_NO_HOSTHNAME_SPECIFIED ,"no hosthname specified"}, 110{BIO_R_NO_HOSTNAME_SPECIFIED ,"no hostname specified"},
103{BIO_R_NO_PORT_DEFINED ,"no port defined"}, 111{BIO_R_NO_PORT_DEFINED ,"no port defined"},
104{BIO_R_NO_PORT_SPECIFIED ,"no port specified"}, 112{BIO_R_NO_PORT_SPECIFIED ,"no port specified"},
105{BIO_R_NULL_PARAMETER ,"null parameter"}, 113{BIO_R_NULL_PARAMETER ,"null parameter"},
114{BIO_R_TAG_MISMATCH ,"tag mismatch"},
106{BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"}, 115{BIO_R_UNABLE_TO_BIND_SOCKET ,"unable to bind socket"},
107{BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"}, 116{BIO_R_UNABLE_TO_CREATE_SOCKET ,"unable to create socket"},
108{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"}, 117{BIO_R_UNABLE_TO_LISTEN_SOCKET ,"unable to listen socket"},
109{BIO_R_UNINITALISED ,"uninitalised"}, 118{BIO_R_UNINITIALIZED ,"uninitialized"},
110{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"}, 119{BIO_R_UNSUPPORTED_METHOD ,"unsupported method"},
111{BIO_R_WSASTARTUP ,"wsastartup"}, 120{BIO_R_WSASTARTUP ,"wsastartup"},
112{0,NULL}, 121{0,NULL}
113 }; 122 };
114 123
115#endif 124#endif
116 125
117void ERR_load_BIO_strings() 126void ERR_load_BIO_strings(void)
118 { 127 {
119 static int init=1; 128 static int init=1;
120 129
121 if (init); 130 if (init)
122 {; 131 {
123 init=0; 132 init=0;
124#ifndef NO_ERR 133#ifndef NO_ERR
125 ERR_load_strings(ERR_LIB_BIO,BIO_str_functs); 134 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "crypto.h" 61#include <openssl/crypto.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "bio.h" 63#include <openssl/bio.h>
64#include "stack.h" 64#include <openssl/stack.h>
65 65
66static STACK *bio_meth=NULL; 66static STACK *bio_meth=NULL;
67static int bio_meth_num=0; 67static int bio_meth_num=0;
68 68
69BIO *BIO_new(method) 69BIO *BIO_new(BIO_METHOD *method)
70BIO_METHOD *method;
71 { 70 {
72 BIO *ret=NULL; 71 BIO *ret=NULL;
73 72
@@ -85,9 +84,7 @@ BIO_METHOD *method;
85 return(ret); 84 return(ret);
86 } 85 }
87 86
88int BIO_set(bio,method) 87int BIO_set(BIO *bio, BIO_METHOD *method)
89BIO *bio;
90BIO_METHOD *method;
91 { 88 {
92 bio->method=method; 89 bio->method=method;
93 bio->callback=NULL; 90 bio->callback=NULL;
@@ -110,8 +107,7 @@ BIO_METHOD *method;
110 return(1); 107 return(1);
111 } 108 }
112 109
113int BIO_free(a) 110int BIO_free(BIO *a)
114BIO *a;
115 { 111 {
116 int ret=0,i; 112 int ret=0,i;
117 113
@@ -121,7 +117,7 @@ BIO *a;
121#ifdef REF_PRINT 117#ifdef REF_PRINT
122 REF_PRINT("BIO",a); 118 REF_PRINT("BIO",a);
123#endif 119#endif
124 if (i > 0) return(1); 120 if (i > 0) return(1);
125#ifdef REF_CHECK 121#ifdef REF_CHECK
126 if (i < 0) 122 if (i < 0)
127 { 123 {
@@ -141,10 +137,7 @@ BIO *a;
141 return(1); 137 return(1);
142 } 138 }
143 139
144int BIO_read(b,out,outl) 140int BIO_read(BIO *b, void *out, int outl)
145BIO *b;
146char *out;
147int outl;
148 { 141 {
149 int i; 142 int i;
150 long (*cb)(); 143 long (*cb)();
@@ -162,11 +155,12 @@ int outl;
162 155
163 if (!b->init) 156 if (!b->init)
164 { 157 {
165 BIOerr(BIO_F_BIO_READ,BIO_R_UNINITALISED); 158 BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED);
166 return(-2); 159 return(-2);
167 } 160 }
168 161
169 i=b->method->bread(b,out,outl); 162 i=b->method->bread(b,out,outl);
163
170 if (i > 0) b->num_read+=(unsigned long)i; 164 if (i > 0) b->num_read+=(unsigned long)i;
171 165
172 if (cb != NULL) 166 if (cb != NULL)
@@ -175,10 +169,7 @@ int outl;
175 return(i); 169 return(i);
176 } 170 }
177 171
178int BIO_write(b,in,inl) 172int BIO_write(BIO *b, const char *in, int inl)
179BIO *b;
180char *in;
181int inl;
182 { 173 {
183 int i; 174 int i;
184 long (*cb)(); 175 long (*cb)();
@@ -199,22 +190,27 @@ int inl;
199 190
200 if (!b->init) 191 if (!b->init)
201 { 192 {
202 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITALISED); 193 BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED);
203 return(-2); 194 return(-2);
204 } 195 }
205 196
206 i=b->method->bwrite(b,in,inl); 197 i=b->method->bwrite(b,in,inl);
198
207 if (i > 0) b->num_write+=(unsigned long)i; 199 if (i > 0) b->num_write+=(unsigned long)i;
208 200
209 if (cb != NULL) 201 /* This is evil and not thread safe. If the BIO has been freed,
202 * we must not call the callback. The only way to be able to
203 * determine this is the reference count which is now invalid since
204 * the memory has been free()ed.
205 */
206 if (b->references <= 0) abort();
207 if (cb != NULL) /* && (b->references >= 1)) */
210 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, 208 i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
211 0L,(long)i); 209 0L,(long)i);
212 return(i); 210 return(i);
213 } 211 }
214 212
215int BIO_puts(b,in) 213int BIO_puts(BIO *b, const char *in)
216BIO *b;
217char *in;
218 { 214 {
219 int i; 215 int i;
220 long (*cb)(); 216 long (*cb)();
@@ -233,7 +229,7 @@ char *in;
233 229
234 if (!b->init) 230 if (!b->init)
235 { 231 {
236 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITALISED); 232 BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED);
237 return(-2); 233 return(-2);
238 } 234 }
239 235
@@ -245,10 +241,7 @@ char *in;
245 return(i); 241 return(i);
246 } 242 }
247 243
248int BIO_gets(b,in,inl) 244int BIO_gets(BIO *b, char *in, int inl)
249BIO *b;
250char *in;
251int inl;
252 { 245 {
253 int i; 246 int i;
254 long (*cb)(); 247 long (*cb)();
@@ -267,7 +260,7 @@ int inl;
267 260
268 if (!b->init) 261 if (!b->init)
269 { 262 {
270 BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITALISED); 263 BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED);
271 return(-2); 264 return(-2);
272 } 265 }
273 266
@@ -279,11 +272,7 @@ int inl;
279 return(i); 272 return(i);
280 } 273 }
281 274
282long BIO_int_ctrl(b,cmd,larg,iarg) 275long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
283BIO *b;
284int cmd;
285long larg;
286int iarg;
287 { 276 {
288 int i; 277 int i;
289 278
@@ -291,10 +280,7 @@ int iarg;
291 return(BIO_ctrl(b,cmd,larg,(char *)&i)); 280 return(BIO_ctrl(b,cmd,larg,(char *)&i));
292 } 281 }
293 282
294char *BIO_ptr_ctrl(b,cmd,larg) 283char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
295BIO *b;
296int cmd;
297long larg;
298 { 284 {
299 char *p=NULL; 285 char *p=NULL;
300 286
@@ -304,11 +290,7 @@ long larg;
304 return(p); 290 return(p);
305 } 291 }
306 292
307long BIO_ctrl(b,cmd,larg,parg) 293long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
308BIO *b;
309int cmd;
310long larg;
311char *parg;
312 { 294 {
313 long ret; 295 long ret;
314 long (*cb)(); 296 long (*cb)();
@@ -335,9 +317,22 @@ char *parg;
335 return(ret); 317 return(ret);
336 } 318 }
337 319
320/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
321 * do; but those macros have inappropriate return type, and for interfacing
322 * from other programming languages, C macros aren't much of a help anyway. */
323size_t BIO_ctrl_pending(BIO *bio)
324 {
325 return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
326 }
327
328size_t BIO_ctrl_wpending(BIO *bio)
329 {
330 return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
331 }
332
333
338/* put the 'bio' on the end of b's list of operators */ 334/* put the 'bio' on the end of b's list of operators */
339BIO *BIO_push(b,bio) 335BIO *BIO_push(BIO *b, BIO *bio)
340BIO *b,*bio;
341 { 336 {
342 BIO *lb; 337 BIO *lb;
343 338
@@ -354,8 +349,7 @@ BIO *b,*bio;
354 } 349 }
355 350
356/* Remove the first and return the rest */ 351/* Remove the first and return the rest */
357BIO *BIO_pop(b) 352BIO *BIO_pop(BIO *b)
358BIO *b;
359 { 353 {
360 BIO *ret; 354 BIO *ret;
361 355
@@ -373,9 +367,7 @@ BIO *b;
373 return(ret); 367 return(ret);
374 } 368 }
375 369
376BIO *BIO_get_retry_BIO(bio,reason) 370BIO *BIO_get_retry_BIO(BIO *bio, int *reason)
377BIO *bio;
378int *reason;
379 { 371 {
380 BIO *b,*last; 372 BIO *b,*last;
381 373
@@ -391,15 +383,12 @@ int *reason;
391 return(last); 383 return(last);
392 } 384 }
393 385
394int BIO_get_retry_reason(bio) 386int BIO_get_retry_reason(BIO *bio)
395BIO *bio;
396 { 387 {
397 return(bio->retry_reason); 388 return(bio->retry_reason);
398 } 389 }
399 390
400BIO *BIO_find_type(bio,type) 391BIO *BIO_find_type(BIO *bio, int type)
401BIO *bio;
402int type;
403 { 392 {
404 int mt,mask; 393 int mt,mask;
405 394
@@ -421,8 +410,7 @@ int type;
421 return(NULL); 410 return(NULL);
422 } 411 }
423 412
424void BIO_free_all(bio) 413void BIO_free_all(BIO *bio)
425BIO *bio;
426 { 414 {
427 BIO *b; 415 BIO *b;
428 int ref; 416 int ref;
@@ -438,8 +426,7 @@ BIO *bio;
438 } 426 }
439 } 427 }
440 428
441BIO *BIO_dup_chain(in) 429BIO *BIO_dup_chain(BIO *in)
442BIO *in;
443 { 430 {
444 BIO *ret=NULL,*eoc=NULL,*bio,*new; 431 BIO *ret=NULL,*eoc=NULL,*bio,*new;
445 432
@@ -461,9 +448,9 @@ BIO *in;
461 goto err; 448 goto err;
462 } 449 }
463 450
464 /* copy app data */ 451 /* copy app data */
465 if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data)) 452 if (!CRYPTO_dup_ex_data(bio_meth,&new->ex_data,&bio->ex_data))
466 goto err; 453 goto err;
467 454
468 if (ret == NULL) 455 if (ret == NULL)
469 { 456 {
@@ -483,36 +470,26 @@ err:
483 return(NULL); 470 return(NULL);
484 } 471 }
485 472
486void BIO_copy_next_retry(b) 473void BIO_copy_next_retry(BIO *b)
487BIO *b;
488 { 474 {
489 BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); 475 BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
490 b->retry_reason=b->next_bio->retry_reason; 476 b->retry_reason=b->next_bio->retry_reason;
491 } 477 }
492 478
493int BIO_get_ex_new_index(argl,argp,new_func,dup_func,free_func) 479int BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(),
494long argl; 480 int (*dup_func)(), void (*free_func)())
495char *argp; 481 {
496int (*new_func)(); 482 bio_meth_num++;
497int (*dup_func)(); 483 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth,
498void (*free_func)(); 484 argl,argp,new_func,dup_func,free_func));
499 { 485 }
500 bio_meth_num++; 486
501 return(CRYPTO_get_ex_new_index(bio_meth_num-1,&bio_meth, 487int BIO_set_ex_data(BIO *bio, int idx, char *data)
502 argl,argp,new_func,dup_func,free_func));
503 }
504
505int BIO_set_ex_data(bio,idx,data)
506BIO *bio;
507int idx;
508char *data;
509 { 488 {
510 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); 489 return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
511 } 490 }
512 491
513char *BIO_get_ex_data(bio,idx) 492char *BIO_get_ex_data(BIO *bio, int idx)
514BIO *bio;
515int idx;
516 { 493 {
517 return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); 494 return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
518 } 495 }
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 @@
62#include <errno.h> 62#include <errno.h>
63#define USE_SOCKETS 63#define USE_SOCKETS
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio.h" 65#include <openssl/bio.h>
66
67/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */
68 66
69#ifdef WIN16 67#ifdef WIN16
70#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ 68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
@@ -72,6 +70,11 @@
72#define SOCKET_PROTOCOL IPPROTO_TCP 70#define SOCKET_PROTOCOL IPPROTO_TCP
73#endif 71#endif
74 72
73#if (defined(VMS) && __VMS_VER < 70000000)
74/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
75#undef FIONBIO
76#endif
77
75typedef struct bio_accept_st 78typedef struct bio_accept_st
76 { 79 {
77 int state; 80 int state;
@@ -82,39 +85,24 @@ typedef struct bio_accept_st
82 85
83 char *addr; 86 char *addr;
84 int nbio; 87 int nbio;
88 /* If 0, it means normal, if 1, do a connect on bind failure,
89 * and if there is no-one listening, bind with SO_REUSEADDR.
90 * If 2, always use SO_REUSEADDR. */
91 int bind_mode;
85 BIO *bio_chain; 92 BIO *bio_chain;
86 } BIO_ACCEPT; 93 } BIO_ACCEPT;
87 94
88#ifndef NOPROTO
89static int acpt_write(BIO *h,char *buf,int num); 95static int acpt_write(BIO *h,char *buf,int num);
90static int acpt_read(BIO *h,char *buf,int size); 96static int acpt_read(BIO *h,char *buf,int size);
91static int acpt_puts(BIO *h,char *str); 97static int acpt_puts(BIO *h,char *str);
92static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2); 98static long acpt_ctrl(BIO *h,int cmd,long arg1,char *arg2);
93static int acpt_new(BIO *h); 99static int acpt_new(BIO *h);
94static int acpt_free(BIO *data); 100static int acpt_free(BIO *data);
95#else
96static int acpt_write();
97static int acpt_read();
98static int acpt_puts();
99static long acpt_ctrl();
100static int acpt_new();
101static int acpt_free();
102#endif
103
104#ifndef NOPROTO
105static int acpt_state(BIO *b, BIO_ACCEPT *c); 101static int acpt_state(BIO *b, BIO_ACCEPT *c);
106static void acpt_close_socket(BIO *data); 102static void acpt_close_socket(BIO *data);
107BIO_ACCEPT *BIO_ACCEPT_new(void ); 103BIO_ACCEPT *BIO_ACCEPT_new(void );
108void BIO_ACCEPT_free(BIO_ACCEPT *a); 104void BIO_ACCEPT_free(BIO_ACCEPT *a);
109 105
110#else
111
112static int acpt_state();
113static void acpt_close_socket();
114BIO_ACCEPT *BIO_ACCEPT_new();
115void BIO_ACCEPT_free();
116#endif
117
118#define ACPT_S_BEFORE 1 106#define ACPT_S_BEFORE 1
119#define ACPT_S_GET_ACCEPT_SOCKET 2 107#define ACPT_S_GET_ACCEPT_SOCKET 2
120#define ACPT_S_OK 3 108#define ACPT_S_OK 3
@@ -132,13 +120,12 @@ static BIO_METHOD methods_acceptp=
132 acpt_free, 120 acpt_free,
133 }; 121 };
134 122
135BIO_METHOD *BIO_s_accept() 123BIO_METHOD *BIO_s_accept(void)
136 { 124 {
137 return(&methods_acceptp); 125 return(&methods_acceptp);
138 } 126 }
139 127
140static int acpt_new(bi) 128static int acpt_new(BIO *bi)
141BIO *bi;
142 { 129 {
143 BIO_ACCEPT *ba; 130 BIO_ACCEPT *ba;
144 131
@@ -153,7 +140,7 @@ BIO *bi;
153 return(1); 140 return(1);
154 } 141 }
155 142
156BIO_ACCEPT *BIO_ACCEPT_new() 143BIO_ACCEPT *BIO_ACCEPT_new(void)
157 { 144 {
158 BIO_ACCEPT *ret; 145 BIO_ACCEPT *ret;
159 146
@@ -162,20 +149,22 @@ BIO_ACCEPT *BIO_ACCEPT_new()
162 149
163 memset(ret,0,sizeof(BIO_ACCEPT)); 150 memset(ret,0,sizeof(BIO_ACCEPT));
164 ret->accept_sock=INVALID_SOCKET; 151 ret->accept_sock=INVALID_SOCKET;
152 ret->bind_mode=BIO_BIND_NORMAL;
165 return(ret); 153 return(ret);
166 } 154 }
167 155
168void BIO_ACCEPT_free(a) 156void BIO_ACCEPT_free(BIO_ACCEPT *a)
169BIO_ACCEPT *a;
170 { 157 {
158 if(a == NULL)
159 return;
160
171 if (a->param_addr != NULL) Free(a->param_addr); 161 if (a->param_addr != NULL) Free(a->param_addr);
172 if (a->addr != NULL) Free(a->addr); 162 if (a->addr != NULL) Free(a->addr);
173 if (a->bio_chain != NULL) BIO_free(a->bio_chain); 163 if (a->bio_chain != NULL) BIO_free(a->bio_chain);
174 Free(a); 164 Free(a);
175 } 165 }
176 166
177static void acpt_close_socket(bio) 167static void acpt_close_socket(BIO *bio)
178BIO *bio;
179 { 168 {
180 BIO_ACCEPT *c; 169 BIO_ACCEPT *c;
181 170
@@ -183,18 +172,13 @@ BIO *bio;
183 if (c->accept_sock != INVALID_SOCKET) 172 if (c->accept_sock != INVALID_SOCKET)
184 { 173 {
185 shutdown(c->accept_sock,2); 174 shutdown(c->accept_sock,2);
186# ifdef WINDOWS
187 closesocket(c->accept_sock); 175 closesocket(c->accept_sock);
188# else
189 close(c->accept_sock);
190# endif
191 c->accept_sock=INVALID_SOCKET; 176 c->accept_sock=INVALID_SOCKET;
192 bio->num=INVALID_SOCKET; 177 bio->num=INVALID_SOCKET;
193 } 178 }
194 } 179 }
195 180
196static int acpt_free(a) 181static int acpt_free(BIO *a)
197BIO *a;
198 { 182 {
199 BIO_ACCEPT *data; 183 BIO_ACCEPT *data;
200 184
@@ -212,12 +196,9 @@ BIO *a;
212 return(1); 196 return(1);
213 } 197 }
214 198
215static int acpt_state(b,c) 199static int acpt_state(BIO *b, BIO_ACCEPT *c)
216BIO *b;
217BIO_ACCEPT *c;
218 { 200 {
219 BIO *bio=NULL,*dbio; 201 BIO *bio=NULL,*dbio;
220 unsigned long l=1;
221 int s= -1; 202 int s= -1;
222 int i; 203 int i;
223 204
@@ -230,31 +211,24 @@ again:
230 BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED); 211 BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
231 return(-1); 212 return(-1);
232 } 213 }
233 s=BIO_get_accept_socket(c->param_addr); 214 s=BIO_get_accept_socket(c->param_addr,c->bind_mode);
234 if (s == INVALID_SOCKET) 215 if (s == INVALID_SOCKET)
235 return(-1); 216 return(-1);
236 217
237#ifdef FIONBIO
238 if (c->accept_nbio) 218 if (c->accept_nbio)
239 { 219 {
240 i=BIO_socket_ioctl(b->num,FIONBIO,&l); 220 if (!BIO_socket_nbio(s,1))
241 if (i < 0)
242 { 221 {
243#ifdef WINDOWS
244 closesocket(s); 222 closesocket(s);
245#else
246 close(s);
247# endif
248 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET); 223 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
249 return(-1); 224 return(-1);
250 } 225 }
251 } 226 }
252#endif
253 c->accept_sock=s; 227 c->accept_sock=s;
254 b->num=s; 228 b->num=s;
255 c->state=ACPT_S_GET_ACCEPT_SOCKET; 229 c->state=ACPT_S_GET_ACCEPT_SOCKET;
256 return(1); 230 return(1);
257 break; 231 /* break; */
258 case ACPT_S_GET_ACCEPT_SOCKET: 232 case ACPT_S_GET_ACCEPT_SOCKET:
259 if (b->next_bio != NULL) 233 if (b->next_bio != NULL)
260 { 234 {
@@ -269,17 +243,14 @@ again:
269 BIO_set_callback(bio,BIO_get_callback(b)); 243 BIO_set_callback(bio,BIO_get_callback(b));
270 BIO_set_callback_arg(bio,BIO_get_callback_arg(b)); 244 BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
271 245
272#ifdef FIONBIO
273 if (c->nbio) 246 if (c->nbio)
274 { 247 {
275 i=BIO_socket_ioctl(i,FIONBIO,&l); 248 if (!BIO_socket_nbio(i,1))
276 if (i < 0)
277 { 249 {
278 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET); 250 BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
279 goto err; 251 goto err;
280 } 252 }
281 } 253 }
282#endif
283 254
284 /* If the accept BIO has an bio_chain, we dup it and 255 /* If the accept BIO has an bio_chain, we dup it and
285 * put the new socket at the end. */ 256 * put the new socket at the end. */
@@ -298,15 +269,9 @@ err:
298 if (bio != NULL) 269 if (bio != NULL)
299 BIO_free(bio); 270 BIO_free(bio);
300 else if (s >= 0) 271 else if (s >= 0)
301 {
302#ifdef WINDOWS
303 closesocket(s); 272 closesocket(s);
304#else
305 close(s);
306# endif
307 }
308 return(0); 273 return(0);
309 break; 274 /* break; */
310 case ACPT_S_OK: 275 case ACPT_S_OK:
311 if (b->next_bio == NULL) 276 if (b->next_bio == NULL)
312 { 277 {
@@ -314,23 +279,20 @@ err:
314 goto again; 279 goto again;
315 } 280 }
316 return(1); 281 return(1);
317 break; 282 /* break; */
318 default: 283 default:
319 return(0); 284 return(0);
320 break; 285 /* break; */
321 } 286 }
322 287
323 } 288 }
324 289
325static int acpt_read(b,out,outl) 290static int acpt_read(BIO *b, char *out, int outl)
326BIO *b;
327char *out;
328int outl;
329 { 291 {
330 int ret=0; 292 int ret=0;
331 BIO_ACCEPT *data; 293 BIO_ACCEPT *data;
332 294
333 BIO_clear_retry_flags(b); 295 BIO_clear_retry_flags(b);
334 data=(BIO_ACCEPT *)b->ptr; 296 data=(BIO_ACCEPT *)b->ptr;
335 297
336 while (b->next_bio == NULL) 298 while (b->next_bio == NULL)
@@ -344,10 +306,7 @@ int outl;
344 return(ret); 306 return(ret);
345 } 307 }
346 308
347static int acpt_write(b,in,inl) 309static int acpt_write(BIO *b, char *in, int inl)
348BIO *b;
349char *in;
350int inl;
351 { 310 {
352 int ret; 311 int ret;
353 BIO_ACCEPT *data; 312 BIO_ACCEPT *data;
@@ -366,11 +325,7 @@ int inl;
366 return(ret); 325 return(ret);
367 } 326 }
368 327
369static long acpt_ctrl(b,cmd,num,ptr) 328static long acpt_ctrl(BIO *b, int cmd, long num, char *ptr)
370BIO *b;
371int cmd;
372long num;
373char *ptr;
374 { 329 {
375 BIO *dbio; 330 BIO *dbio;
376 int *ip; 331 int *ip;
@@ -417,13 +372,21 @@ char *ptr;
417 case BIO_C_SET_NBIO: 372 case BIO_C_SET_NBIO:
418 data->nbio=(int)num; 373 data->nbio=(int)num;
419 break; 374 break;
375 case BIO_C_SET_FD:
376 b->init=1;
377 b->num= *((int *)ptr);
378 data->accept_sock=b->num;
379 data->state=ACPT_S_GET_ACCEPT_SOCKET;
380 b->shutdown=(int)num;
381 b->init=1;
382 break;
420 case BIO_C_GET_FD: 383 case BIO_C_GET_FD:
421 if (b->init) 384 if (b->init)
422 { 385 {
423 ip=(int *)ptr; 386 ip=(int *)ptr;
424 if (ip != NULL) 387 if (ip != NULL)
425 *ip=data->accept_sock; 388 *ip=data->accept_sock;
426 ret=b->num; 389 ret=data->accept_sock;
427 } 390 }
428 else 391 else
429 ret= -1; 392 ret= -1;
@@ -454,6 +417,12 @@ char *ptr;
454 break; 417 break;
455 case BIO_CTRL_FLUSH: 418 case BIO_CTRL_FLUSH:
456 break; 419 break;
420 case BIO_C_SET_BIND_MODE:
421 data->bind_mode=(int)num;
422 break;
423 case BIO_C_GET_BIND_MODE:
424 ret=(long)data->bind_mode;
425 break;
457 case BIO_CTRL_DUP: 426 case BIO_CTRL_DUP:
458 dbio=(BIO *)ptr; 427 dbio=(BIO *)ptr;
459/* if (data->param_port) EAY EAY 428/* if (data->param_port) EAY EAY
@@ -470,9 +439,7 @@ char *ptr;
470 return(ret); 439 return(ret);
471 } 440 }
472 441
473static int acpt_puts(bp,str) 442static int acpt_puts(BIO *bp, char *str)
474BIO *bp;
475char *str;
476 { 443 {
477 int n,ret; 444 int n,ret;
478 445
@@ -481,8 +448,7 @@ char *str;
481 return(ret); 448 return(ret);
482 } 449 }
483 450
484BIO *BIO_new_accept(str) 451BIO *BIO_new_accept(char *str)
485char *str;
486 { 452 {
487 BIO *ret; 453 BIO *ret;
488 454
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 @@
1/* crypto/bio/bss_bio.c -*- Mode: C; c-file-style: "eay" -*- */
2
3/* Special method for a BIO where the other endpoint is also a BIO
4 * of this kind, handled by the same thread (i.e. the "peer" is actually
5 * ourselves, wearing a different hat).
6 * Such "BIO pairs" are mainly for using the SSL library with I/O interfaces
7 * for which no specific BIO method is available.
8 * See ssl/ssltest.c for some hints on how this can be used. */
9
10#ifndef BIO_PAIR_DEBUG
11# undef NDEBUG /* avoid conflicting definitions */
12# define NDEBUG
13#endif
14
15#include <assert.h>
16#include <stdlib.h>
17#include <string.h>
18
19#include <openssl/bio.h>
20#include <openssl/err.h>
21#include <openssl/crypto.h>
22
23static int bio_new(BIO *bio);
24static int bio_free(BIO *bio);
25static int bio_read(BIO *bio, char *buf, int size);
26static int bio_write(BIO *bio, char *buf, int num);
27static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
28static int bio_puts(BIO *bio, char *str);
29
30static int bio_make_pair(BIO *bio1, BIO *bio2);
31static void bio_destroy_pair(BIO *bio);
32
33static BIO_METHOD methods_biop =
34{
35 BIO_TYPE_BIO,
36 "BIO pair",
37 bio_write,
38 bio_read,
39 bio_puts,
40 NULL /* no bio_gets */,
41 bio_ctrl,
42 bio_new,
43 bio_free
44};
45
46BIO_METHOD *BIO_s_bio(void)
47 {
48 return &methods_biop;
49 }
50
51struct bio_bio_st
52{
53 BIO *peer; /* NULL if buf == NULL.
54 * If peer != NULL, then peer->ptr is also a bio_bio_st,
55 * and its "peer" member points back to us.
56 * peer != NULL iff init != 0 in the BIO. */
57
58 /* This is for what we write (i.e. reading uses peer's struct): */
59 int closed; /* valid iff peer != NULL */
60 size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
61 size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
62 size_t size;
63 char *buf; /* "size" elements (if != NULL) */
64
65 size_t request; /* valid iff peer != NULL; 0 if len != 0,
66 * otherwise set by peer to number of bytes
67 * it (unsuccesfully) tried to read,
68 * never more than buffer space (size-len) warrants. */
69};
70
71static int bio_new(BIO *bio)
72 {
73 struct bio_bio_st *b;
74
75 b = Malloc(sizeof *b);
76 if (b == NULL)
77 return 0;
78
79 b->peer = NULL;
80 b->size = 17*1024; /* enough for one TLS record (just a default) */
81 b->buf = NULL;
82
83 bio->ptr = b;
84 return 1;
85 }
86
87
88static int bio_free(BIO *bio)
89 {
90 struct bio_bio_st *b;
91
92 if (bio == NULL)
93 return 0;
94 b = bio->ptr;
95
96 assert(b != NULL);
97
98 if (b->peer)
99 bio_destroy_pair(bio);
100
101 if (b->buf != NULL)
102 {
103 Free(b->buf);
104 }
105
106 Free(b);
107
108 return 1;
109 }
110
111
112
113static int bio_read(BIO *bio, char *buf, int size_)
114 {
115 size_t size = size_;
116 size_t rest;
117 struct bio_bio_st *b, *peer_b;
118
119 BIO_clear_retry_flags(bio);
120
121 if (!bio->init)
122 return 0;
123
124 b = bio->ptr;
125 assert(b != NULL);
126 assert(b->peer != NULL);
127 peer_b = b->peer->ptr;
128 assert(peer_b != NULL);
129 assert(peer_b->buf != NULL);
130
131 peer_b->request = 0; /* will be set in "retry_read" situation */
132
133 if (buf == NULL || size == 0)
134 return 0;
135
136 if (peer_b->len == 0)
137 {
138 if (peer_b->closed)
139 return 0; /* writer has closed, and no data is left */
140 else
141 {
142 BIO_set_retry_read(bio); /* buffer is empty */
143 if (size <= peer_b->size)
144 peer_b->request = size;
145 else
146 /* don't ask for more than the peer can
147 * deliver in one write */
148 peer_b->request = peer_b->size;
149 return -1;
150 }
151 }
152
153 /* we can read */
154 if (peer_b->len < size)
155 size = peer_b->len;
156
157 /* now read "size" bytes */
158
159 rest = size;
160
161 assert(rest > 0);
162 do /* one or two iterations */
163 {
164 size_t chunk;
165
166 assert(rest <= peer_b->len);
167 if (peer_b->offset + rest <= peer_b->size)
168 chunk = rest;
169 else
170 /* wrap around ring buffer */
171 chunk = peer_b->size - peer_b->offset;
172 assert(peer_b->offset + chunk <= peer_b->size);
173
174 memcpy(buf, peer_b->buf + peer_b->offset, chunk);
175
176 peer_b->len -= chunk;
177 if (peer_b->len)
178 {
179 peer_b->offset += chunk;
180 assert(peer_b->offset <= peer_b->size);
181 if (peer_b->offset == peer_b->size)
182 peer_b->offset = 0;
183 buf += chunk;
184 }
185 else
186 {
187 /* buffer now empty, no need to advance "buf" */
188 assert(chunk == rest);
189 peer_b->offset = 0;
190 }
191 rest -= chunk;
192 }
193 while (rest);
194
195 return size;
196 }
197
198static int bio_write(BIO *bio, char *buf, int num_)
199 {
200 size_t num = num_;
201 size_t rest;
202 struct bio_bio_st *b;
203
204 BIO_clear_retry_flags(bio);
205
206 if (!bio->init || buf == NULL || num == 0)
207 return 0;
208
209 b = bio->ptr;
210 assert(b != NULL);
211 assert(b->peer != NULL);
212 assert(b->buf != NULL);
213
214 b->request = 0;
215 if (b->closed)
216 {
217 /* we already closed */
218 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
219 return -1;
220 }
221
222 assert(b->len <= b->size);
223
224 if (b->len == b->size)
225 {
226 BIO_set_retry_write(bio); /* buffer is full */
227 return -1;
228 }
229
230 /* we can write */
231 if (num > b->size - b->len)
232 num = b->size - b->len;
233
234 /* now write "num" bytes */
235
236 rest = num;
237
238 assert(rest > 0);
239 do /* one or two iterations */
240 {
241 size_t write_offset;
242 size_t chunk;
243
244 assert(b->len + rest <= b->size);
245
246 write_offset = b->offset + b->len;
247 if (write_offset >= b->size)
248 write_offset -= b->size;
249 /* b->buf[write_offset] is the first byte we can write to. */
250
251 if (write_offset + rest <= b->size)
252 chunk = rest;
253 else
254 /* wrap around ring buffer */
255 chunk = b->size - write_offset;
256
257 memcpy(b->buf + write_offset, buf, chunk);
258
259 b->len += chunk;
260
261 assert(b->len <= b->size);
262
263 rest -= chunk;
264 buf += chunk;
265 }
266 while (rest);
267
268 return num;
269 }
270
271
272static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
273 {
274 long ret;
275 struct bio_bio_st *b = bio->ptr;
276
277 assert(b != NULL);
278
279 switch (cmd)
280 {
281 /* specific CTRL codes */
282
283 case BIO_C_SET_WRITE_BUF_SIZE:
284 if (b->peer)
285 {
286 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
287 ret = 0;
288 }
289 else if (num == 0)
290 {
291 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
292 ret = 0;
293 }
294 else
295 {
296 size_t new_size = num;
297
298 if (b->size != new_size)
299 {
300 if (b->buf)
301 {
302 Free(b->buf);
303 b->buf = NULL;
304 }
305 b->size = new_size;
306 }
307 ret = 1;
308 }
309 break;
310
311 case BIO_C_GET_WRITE_BUF_SIZE:
312 num = (long) b->size;
313
314 case BIO_C_MAKE_BIO_PAIR:
315 {
316 BIO *other_bio = ptr;
317
318 if (bio_make_pair(bio, other_bio))
319 ret = 1;
320 else
321 ret = 0;
322 }
323 break;
324
325 case BIO_C_DESTROY_BIO_PAIR:
326 /* Effects both BIOs in the pair -- call just once!
327 * Or let BIO_free(bio1); BIO_free(bio2); do the job. */
328 bio_destroy_pair(bio);
329 ret = 1;
330 break;
331
332 case BIO_C_GET_WRITE_GUARANTEE:
333 /* How many bytes can the caller feed to the next write
334 * withouth having to keep any? */
335 if (b->peer == NULL || b->closed)
336 ret = 0;
337 else
338 ret = (long) b->size - b->len;
339 break;
340
341 case BIO_C_GET_READ_REQUEST:
342 /* If the peer unsuccesfully tried to read, how many bytes
343 * were requested? (As with BIO_CTRL_PENDING, that number
344 * can usually be treated as boolean.) */
345 ret = (long) b->request;
346 break;
347
348 case BIO_C_SHUTDOWN_WR:
349 /* similar to shutdown(..., SHUT_WR) */
350 b->closed = 1;
351 ret = 1;
352 break;
353
354
355 /* standard CTRL codes follow */
356
357 case BIO_CTRL_RESET:
358 if (b->buf != NULL)
359 {
360 b->len = 0;
361 b->offset = 0;
362 }
363 ret = 0;
364 break;
365
366 case BIO_CTRL_GET_CLOSE:
367 ret = bio->shutdown;
368 break;
369
370 case BIO_CTRL_SET_CLOSE:
371 bio->shutdown = (int) num;
372 ret = 1;
373 break;
374
375 case BIO_CTRL_PENDING:
376 if (b->peer != NULL)
377 {
378 struct bio_bio_st *peer_b = b->peer->ptr;
379
380 ret = (long) peer_b->len;
381 }
382 else
383 ret = 0;
384 break;
385
386 case BIO_CTRL_WPENDING:
387 if (b->buf != NULL)
388 ret = (long) b->len;
389 else
390 ret = 0;
391 break;
392
393 case BIO_CTRL_DUP:
394 /* See BIO_dup_chain for circumstances we have to expect. */
395 {
396 BIO *other_bio = ptr;
397 struct bio_bio_st *other_b;
398
399 assert(other_bio != NULL);
400 other_b = other_bio->ptr;
401 assert(other_b != NULL);
402
403 assert(other_b->buf == NULL); /* other_bio is always fresh */
404
405 other_b->size = b->size;
406 }
407
408 ret = 1;
409 break;
410
411 case BIO_CTRL_FLUSH:
412 ret = 1;
413 break;
414
415 case BIO_CTRL_EOF:
416 {
417 BIO *other_bio = ptr;
418
419 if (other_bio)
420 {
421 struct bio_bio_st *other_b = other_bio->ptr;
422
423 assert(other_b != NULL);
424 ret = other_b->len == 0 && other_b->closed;
425 }
426 else
427 ret = 1;
428 }
429 break;
430
431 default:
432 ret = 0;
433 }
434 return ret;
435 }
436
437static int bio_puts(BIO *bio, char *str)
438 {
439 return bio_write(bio, str, strlen(str));
440 }
441
442
443static int bio_make_pair(BIO *bio1, BIO *bio2)
444 {
445 struct bio_bio_st *b1, *b2;
446
447 assert(bio1 != NULL);
448 assert(bio2 != NULL);
449
450 b1 = bio1->ptr;
451 b2 = bio2->ptr;
452
453 if (b1->peer != NULL || b2->peer != NULL)
454 {
455 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
456 return 0;
457 }
458
459 if (b1->buf == NULL)
460 {
461 b1->buf = Malloc(b1->size);
462 if (b1->buf == NULL)
463 {
464 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
465 return 0;
466 }
467 b1->len = 0;
468 b1->offset = 0;
469 }
470
471 if (b2->buf == NULL)
472 {
473 b2->buf = Malloc(b2->size);
474 if (b2->buf == NULL)
475 {
476 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
477 return 0;
478 }
479 b2->len = 0;
480 b2->offset = 0;
481 }
482
483 b1->peer = bio2;
484 b1->closed = 0;
485 b1->request = 0;
486 b2->peer = bio1;
487 b2->closed = 0;
488 b2->request = 0;
489
490 bio1->init = 1;
491 bio2->init = 1;
492
493 return 1;
494 }
495
496static void bio_destroy_pair(BIO *bio)
497 {
498 struct bio_bio_st *b = bio->ptr;
499
500 if (b != NULL)
501 {
502 BIO *peer_bio = b->peer;
503
504 if (peer_bio != NULL)
505 {
506 struct bio_bio_st *peer_b = peer_bio->ptr;
507
508 assert(peer_b != NULL);
509 assert(peer_b->peer == bio);
510
511 peer_b->peer = NULL;
512 peer_bio->init = 0;
513 assert(peer_b->buf != NULL);
514 peer_b->len = 0;
515 peer_b->offset = 0;
516
517 b->peer = NULL;
518 bio->init = 0;
519 assert(b->buf != NULL);
520 b->len = 0;
521 b->offset = 0;
522 }
523 }
524 }
525
526
527/* Exported convenience functions */
528int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
529 BIO **bio2_p, size_t writebuf2)
530 {
531 BIO *bio1 = NULL, *bio2 = NULL;
532 long r;
533 int ret = 0;
534
535 bio1 = BIO_new(BIO_s_bio());
536 if (bio1 == NULL)
537 goto err;
538 bio2 = BIO_new(BIO_s_bio());
539 if (bio2 == NULL)
540 goto err;
541
542 if (writebuf1)
543 {
544 r = BIO_set_write_buf_size(bio1, writebuf1);
545 if (!r)
546 goto err;
547 }
548 if (writebuf2)
549 {
550 r = BIO_set_write_buf_size(bio2, writebuf2);
551 if (!r)
552 goto err;
553 }
554
555 r = BIO_make_bio_pair(bio1, bio2);
556 if (!r)
557 goto err;
558 ret = 1;
559
560 err:
561 if (ret == 0)
562 {
563 if (bio1)
564 {
565 BIO_free(bio1);
566 bio1 = NULL;
567 }
568 if (bio2)
569 {
570 BIO_free(bio2);
571 bio2 = NULL;
572 }
573 }
574
575 *bio1_p = bio1;
576 *bio2_p = bio2;
577 return ret;
578 }
579
580size_t BIO_ctrl_get_write_guarantee(BIO *bio)
581 {
582 return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
583 }
584
585size_t BIO_ctrl_get_read_request(BIO *bio)
586 {
587 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
588 }
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
index 6e547bf866..68c46e3d69 100644
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ b/src/lib/libcrypto/bio/bss_conn.c
@@ -62,9 +62,7 @@
62#include <errno.h> 62#include <errno.h>
63#define USE_SOCKETS 63#define USE_SOCKETS
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio.h" 65#include <openssl/bio.h>
66
67/* BIOerr(BIO_F_WSASTARTUP,BIO_R_WSASTARTUP ); */
68 66
69#ifdef WIN16 67#ifdef WIN16
70#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ 68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
@@ -72,6 +70,12 @@
72#define SOCKET_PROTOCOL IPPROTO_TCP 70#define SOCKET_PROTOCOL IPPROTO_TCP
73#endif 71#endif
74 72
73#if (defined(VMS) && __VMS_VER < 70000000)
74/* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */
75#undef FIONBIO
76#endif
77
78
75typedef struct bio_connect_st 79typedef struct bio_connect_st
76 { 80 {
77 int state; 81 int state;
@@ -81,13 +85,12 @@ typedef struct bio_connect_st
81 int nbio; 85 int nbio;
82 86
83 unsigned char ip[4]; 87 unsigned char ip[4];
84 short port; 88 unsigned short port;
85 89
86 struct sockaddr_in them; 90 struct sockaddr_in them;
87 91
88 /* int socket; this will be kept in bio->num so that it is 92 /* int socket; this will be kept in bio->num so that it is
89 * compatable with the bss_sock bio */ 93 * compatable with the bss_sock bio */
90 int error;
91 94
92 /* called when the connection is initially made 95 /* called when the connection is initially made
93 * callback(BIO,state,ret); The callback should return 96 * callback(BIO,state,ret); The callback should return
@@ -95,38 +98,18 @@ typedef struct bio_connect_st
95 int (*info_callback)(); 98 int (*info_callback)();
96 } BIO_CONNECT; 99 } BIO_CONNECT;
97 100
98#ifndef NOPROTO
99static int conn_write(BIO *h,char *buf,int num); 101static int conn_write(BIO *h,char *buf,int num);
100static int conn_read(BIO *h,char *buf,int size); 102static int conn_read(BIO *h,char *buf,int size);
101static int conn_puts(BIO *h,char *str); 103static int conn_puts(BIO *h,char *str);
102static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2); 104static long conn_ctrl(BIO *h,int cmd,long arg1,char *arg2);
103static int conn_new(BIO *h); 105static int conn_new(BIO *h);
104static int conn_free(BIO *data); 106static int conn_free(BIO *data);
105#else
106static int conn_write();
107static int conn_read();
108static int conn_puts();
109static long conn_ctrl();
110static int conn_new();
111static int conn_free();
112#endif
113
114#ifndef NOPROTO
115 107
116static int conn_state(BIO *b, BIO_CONNECT *c); 108static int conn_state(BIO *b, BIO_CONNECT *c);
117static void conn_close_socket(BIO *data); 109static void conn_close_socket(BIO *data);
118BIO_CONNECT *BIO_CONNECT_new(void ); 110BIO_CONNECT *BIO_CONNECT_new(void );
119void BIO_CONNECT_free(BIO_CONNECT *a); 111void BIO_CONNECT_free(BIO_CONNECT *a);
120 112
121#else
122
123static int conn_state();
124static void conn_close_socket();
125BIO_CONNECT *BIO_CONNECT_new();
126void BIO_CONNECT_free();
127
128#endif
129
130static BIO_METHOD methods_connectp= 113static BIO_METHOD methods_connectp=
131 { 114 {
132 BIO_TYPE_CONNECT, 115 BIO_TYPE_CONNECT,
@@ -140,9 +123,7 @@ static BIO_METHOD methods_connectp=
140 conn_free, 123 conn_free,
141 }; 124 };
142 125
143static int conn_state(b,c) 126static int conn_state(BIO *b, BIO_CONNECT *c)
144BIO *b;
145BIO_CONNECT *c;
146 { 127 {
147 int ret= -1,i; 128 int ret= -1,i;
148 unsigned long l; 129 unsigned long l;
@@ -160,7 +141,7 @@ BIO_CONNECT *c;
160 p=c->param_hostname; 141 p=c->param_hostname;
161 if (p == NULL) 142 if (p == NULL)
162 { 143 {
163 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTHNAME_SPECIFIED); 144 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED);
164 goto exit_loop; 145 goto exit_loop;
165 } 146 }
166 for ( ; *p != '\0'; p++) 147 for ( ; *p != '\0'; p++)
@@ -187,7 +168,7 @@ BIO_CONNECT *c;
187 } 168 }
188 } 169 }
189 170
190 if (p == NULL) 171 if (c->param_port == NULL)
191 { 172 {
192 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); 173 BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);
193 ERR_add_error_data(2,"host=",c->param_hostname); 174 ERR_add_error_data(2,"host=",c->param_hostname);
@@ -203,7 +184,12 @@ BIO_CONNECT *c;
203 break; 184 break;
204 185
205 case BIO_CONN_S_GET_PORT: 186 case BIO_CONN_S_GET_PORT:
206 if (BIO_get_port(c->param_port,&c->port) <= 0) 187 if (c->param_port == NULL)
188 {
189 abort();
190 goto exit_loop;
191 }
192 else if (BIO_get_port(c->param_port,&c->port) <= 0)
207 goto exit_loop; 193 goto exit_loop;
208 c->state=BIO_CONN_S_CREATE_SOCKET; 194 c->state=BIO_CONN_S_CREATE_SOCKET;
209 break; 195 break;
@@ -235,12 +221,9 @@ BIO_CONNECT *c;
235 break; 221 break;
236 222
237 case BIO_CONN_S_NBIO: 223 case BIO_CONN_S_NBIO:
238#ifdef FIONBIO
239 if (c->nbio) 224 if (c->nbio)
240 { 225 {
241 l=1; 226 if (!BIO_socket_nbio(b->num,1))
242 ret=BIO_socket_ioctl(b->num,FIONBIO,&l);
243 if (ret < 0)
244 { 227 {
245 BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); 228 BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);
246 ERR_add_error_data(4,"host=", 229 ERR_add_error_data(4,"host=",
@@ -249,7 +232,6 @@ BIO_CONNECT *c;
249 goto exit_loop; 232 goto exit_loop;
250 } 233 }
251 } 234 }
252#endif
253 c->state=BIO_CONN_S_CONNECT; 235 c->state=BIO_CONN_S_CONNECT;
254 236
255#ifdef SO_KEEPALIVE 237#ifdef SO_KEEPALIVE
@@ -326,17 +308,15 @@ BIO_CONNECT *c;
326 } 308 }
327 } 309 }
328 310
329 if (1) 311 /* Loop does not exit */
330 {
331exit_loop: 312exit_loop:
332 if (cb != NULL) 313 if (cb != NULL)
333 ret=cb((BIO *)b,c->state,ret); 314 ret=cb((BIO *)b,c->state,ret);
334 }
335end: 315end:
336 return(ret); 316 return(ret);
337 } 317 }
338 318
339BIO_CONNECT *BIO_CONNECT_new() 319BIO_CONNECT *BIO_CONNECT_new(void)
340 { 320 {
341 BIO_CONNECT *ret; 321 BIO_CONNECT *ret;
342 322
@@ -353,13 +333,14 @@ BIO_CONNECT *BIO_CONNECT_new()
353 ret->ip[3]=0; 333 ret->ip[3]=0;
354 ret->port=0; 334 ret->port=0;
355 memset((char *)&ret->them,0,sizeof(ret->them)); 335 memset((char *)&ret->them,0,sizeof(ret->them));
356 ret->error=0;
357 return(ret); 336 return(ret);
358 } 337 }
359 338
360void BIO_CONNECT_free(a) 339void BIO_CONNECT_free(BIO_CONNECT *a)
361BIO_CONNECT *a;
362 { 340 {
341 if(a == NULL)
342 return;
343
363 if (a->param_hostname != NULL) 344 if (a->param_hostname != NULL)
364 Free(a->param_hostname); 345 Free(a->param_hostname);
365 if (a->param_port != NULL) 346 if (a->param_port != NULL)
@@ -367,13 +348,12 @@ BIO_CONNECT *a;
367 Free(a); 348 Free(a);
368 } 349 }
369 350
370BIO_METHOD *BIO_s_connect() 351BIO_METHOD *BIO_s_connect(void)
371 { 352 {
372 return(&methods_connectp); 353 return(&methods_connectp);
373 } 354 }
374 355
375static int conn_new(bi) 356static int conn_new(BIO *bi)
376BIO *bi;
377 { 357 {
378 bi->init=0; 358 bi->init=0;
379 bi->num=INVALID_SOCKET; 359 bi->num=INVALID_SOCKET;
@@ -384,8 +364,7 @@ BIO *bi;
384 return(1); 364 return(1);
385 } 365 }
386 366
387static void conn_close_socket(bio) 367static void conn_close_socket(BIO *bio)
388BIO *bio;
389 { 368 {
390 BIO_CONNECT *c; 369 BIO_CONNECT *c;
391 370
@@ -395,17 +374,12 @@ BIO *bio;
395 /* Only do a shutdown if things were established */ 374 /* Only do a shutdown if things were established */
396 if (c->state == BIO_CONN_S_OK) 375 if (c->state == BIO_CONN_S_OK)
397 shutdown(bio->num,2); 376 shutdown(bio->num,2);
398# ifdef WINDOWS
399 closesocket(bio->num); 377 closesocket(bio->num);
400# else
401 close(bio->num);
402# endif
403 bio->num=INVALID_SOCKET; 378 bio->num=INVALID_SOCKET;
404 } 379 }
405 } 380 }
406 381
407static int conn_free(a) 382static int conn_free(BIO *a)
408BIO *a;
409 { 383 {
410 BIO_CONNECT *data; 384 BIO_CONNECT *data;
411 385
@@ -423,10 +397,7 @@ BIO *a;
423 return(1); 397 return(1);
424 } 398 }
425 399
426static int conn_read(b,out,outl) 400static int conn_read(BIO *b, char *out, int outl)
427BIO *b;
428char *out;
429int outl;
430 { 401 {
431 int ret=0; 402 int ret=0;
432 BIO_CONNECT *data; 403 BIO_CONNECT *data;
@@ -442,11 +413,7 @@ int outl;
442 if (out != NULL) 413 if (out != NULL)
443 { 414 {
444 clear_socket_error(); 415 clear_socket_error();
445#if defined(WINDOWS) 416 ret=readsocket(b->num,out,outl);
446 ret=recv(b->num,out,outl,0);
447#else
448 ret=read(b->num,out,outl);
449#endif
450 BIO_clear_retry_flags(b); 417 BIO_clear_retry_flags(b);
451 if (ret <= 0) 418 if (ret <= 0)
452 { 419 {
@@ -457,10 +424,7 @@ int outl;
457 return(ret); 424 return(ret);
458 } 425 }
459 426
460static int conn_write(b,in,inl) 427static int conn_write(BIO *b, char *in, int inl)
461BIO *b;
462char *in;
463int inl;
464 { 428 {
465 int ret; 429 int ret;
466 BIO_CONNECT *data; 430 BIO_CONNECT *data;
@@ -473,11 +437,7 @@ int inl;
473 } 437 }
474 438
475 clear_socket_error(); 439 clear_socket_error();
476#if defined(WINDOWS) 440 ret=writesocket(b->num,in,inl);
477 ret=send(b->num,in,inl,0);
478#else
479 ret=write(b->num,in,inl);
480#endif
481 BIO_clear_retry_flags(b); 441 BIO_clear_retry_flags(b);
482 if (ret <= 0) 442 if (ret <= 0)
483 { 443 {
@@ -487,15 +447,11 @@ int inl;
487 return(ret); 447 return(ret);
488 } 448 }
489 449
490static long conn_ctrl(b,cmd,num,ptr) 450static long conn_ctrl(BIO *b, int cmd, long num, char *ptr)
491BIO *b;
492int cmd;
493long num;
494char *ptr;
495 { 451 {
496 BIO *dbio; 452 BIO *dbio;
497 int *ip; 453 int *ip;
498 char **pptr; 454 const char **pptr;
499 long ret=1; 455 long ret=1;
500 BIO_CONNECT *data; 456 BIO_CONNECT *data;
501 457
@@ -519,7 +475,7 @@ char *ptr;
519 case BIO_C_GET_CONNECT: 475 case BIO_C_GET_CONNECT:
520 if (ptr != NULL) 476 if (ptr != NULL)
521 { 477 {
522 pptr=(char **)ptr; 478 pptr=(const char **)ptr;
523 if (num == 0) 479 if (num == 0)
524 { 480 {
525 *pptr=data->param_hostname; 481 *pptr=data->param_hostname;
@@ -559,9 +515,26 @@ char *ptr;
559 data->param_port=BUF_strdup(ptr); 515 data->param_port=BUF_strdup(ptr);
560 } 516 }
561 else if (num == 2) 517 else if (num == 2)
562 memcpy(data->ip,ptr,4); 518 {
519 char buf[16];
520
521 sprintf(buf,"%d.%d.%d.%d",
522 ptr[0],ptr[1],ptr[2],ptr[3]);
523 if (data->param_hostname != NULL)
524 Free(data->param_hostname);
525 data->param_hostname=BUF_strdup(buf);
526 memcpy(&(data->ip[0]),ptr,4);
527 }
563 else if (num == 3) 528 else if (num == 3)
529 {
530 char buf[16];
531
532 sprintf(buf,"%d",*(int *)ptr);
533 if (data->param_port != NULL)
534 Free(data->param_port);
535 data->param_port=BUF_strdup(buf);
564 data->port= *(int *)ptr; 536 data->port= *(int *)ptr;
537 }
565 } 538 }
566 break; 539 break;
567 case BIO_C_SET_NBIO: 540 case BIO_C_SET_NBIO:
@@ -597,7 +570,7 @@ char *ptr;
597 if (data->param_hostname) 570 if (data->param_hostname)
598 BIO_set_conn_hostname(dbio,data->param_hostname); 571 BIO_set_conn_hostname(dbio,data->param_hostname);
599 BIO_set_nbio(dbio,data->nbio); 572 BIO_set_nbio(dbio,data->nbio);
600 BIO_set_info_callback(dbio,data->info_callback); 573 (void)BIO_set_info_callback(dbio,data->info_callback);
601 break; 574 break;
602 case BIO_CTRL_SET_CALLBACK: 575 case BIO_CTRL_SET_CALLBACK:
603 data->info_callback=(int (*)())ptr; 576 data->info_callback=(int (*)())ptr;
@@ -617,9 +590,7 @@ char *ptr;
617 return(ret); 590 return(ret);
618 } 591 }
619 592
620static int conn_puts(bp,str) 593static int conn_puts(BIO *bp, char *str)
621BIO *bp;
622char *str;
623 { 594 {
624 int n,ret; 595 int n,ret;
625 596
@@ -628,8 +599,7 @@ char *str;
628 return(ret); 599 return(ret);
629 } 600 }
630 601
631BIO *BIO_new_connect(str) 602BIO *BIO_new_connect(char *str)
632char *str;
633 { 603 {
634 BIO *ret; 604 BIO *ret;
635 605
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 @@
68#include <stdio.h> 68#include <stdio.h>
69#include <errno.h> 69#include <errno.h>
70#include "cryptlib.h" 70#include "cryptlib.h"
71#include "bio.h" 71#include <openssl/bio.h>
72#include "err.h" 72#include <openssl/err.h>
73 73
74#if !defined(NO_STDIO) 74#if !defined(NO_STDIO)
75 75
76#ifndef NOPROTO
77static int MS_CALLBACK file_write(BIO *h,char *buf,int num); 76static int MS_CALLBACK file_write(BIO *h,char *buf,int num);
78static int MS_CALLBACK file_read(BIO *h,char *buf,int size); 77static int MS_CALLBACK file_read(BIO *h,char *buf,int size);
79static int MS_CALLBACK file_puts(BIO *h,char *str); 78static 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);
81static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2); 80static long MS_CALLBACK file_ctrl(BIO *h,int cmd,long arg1,char *arg2);
82static int MS_CALLBACK file_new(BIO *h); 81static int MS_CALLBACK file_new(BIO *h);
83static int MS_CALLBACK file_free(BIO *data); 82static int MS_CALLBACK file_free(BIO *data);
84#else
85static int MS_CALLBACK file_write();
86static int MS_CALLBACK file_read();
87static int MS_CALLBACK file_puts();
88static int MS_CALLBACK file_gets();
89static long MS_CALLBACK file_ctrl();
90static int MS_CALLBACK file_new();
91static int MS_CALLBACK file_free();
92#endif
93
94static BIO_METHOD methods_filep= 83static BIO_METHOD methods_filep=
95 { 84 {
96 BIO_TYPE_FILE, 85 BIO_TYPE_FILE,
@@ -104,9 +93,7 @@ static BIO_METHOD methods_filep=
104 file_free, 93 file_free,
105 }; 94 };
106 95
107BIO *BIO_new_file(filename,mode) 96BIO *BIO_new_file(const char *filename, const char *mode)
108char *filename;
109char *mode;
110 { 97 {
111 BIO *ret; 98 BIO *ret;
112 FILE *file; 99 FILE *file;
@@ -125,9 +112,7 @@ char *mode;
125 return(ret); 112 return(ret);
126 } 113 }
127 114
128BIO *BIO_new_fp(stream,close_flag) 115BIO *BIO_new_fp(FILE *stream, int close_flag)
129FILE *stream;
130int close_flag;
131 { 116 {
132 BIO *ret; 117 BIO *ret;
133 118
@@ -138,13 +123,12 @@ int close_flag;
138 return(ret); 123 return(ret);
139 } 124 }
140 125
141BIO_METHOD *BIO_s_file() 126BIO_METHOD *BIO_s_file(void)
142 { 127 {
143 return(&methods_filep); 128 return(&methods_filep);
144 } 129 }
145 130
146static int MS_CALLBACK file_new(bi) 131static int MS_CALLBACK file_new(BIO *bi)
147BIO *bi;
148 { 132 {
149 bi->init=0; 133 bi->init=0;
150 bi->num=0; 134 bi->num=0;
@@ -152,8 +136,7 @@ BIO *bi;
152 return(1); 136 return(1);
153 } 137 }
154 138
155static int MS_CALLBACK file_free(a) 139static int MS_CALLBACK file_free(BIO *a)
156BIO *a;
157 { 140 {
158 if (a == NULL) return(0); 141 if (a == NULL) return(0);
159 if (a->shutdown) 142 if (a->shutdown)
@@ -168,10 +151,7 @@ BIO *a;
168 return(1); 151 return(1);
169 } 152 }
170 153
171static int MS_CALLBACK file_read(b,out,outl) 154static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
172BIO *b;
173char *out;
174int outl;
175 { 155 {
176 int ret=0; 156 int ret=0;
177 157
@@ -182,10 +162,7 @@ int outl;
182 return(ret); 162 return(ret);
183 } 163 }
184 164
185static int MS_CALLBACK file_write(b,in,inl) 165static int MS_CALLBACK file_write(BIO *b, char *in, int inl)
186BIO *b;
187char *in;
188int inl;
189 { 166 {
190 int ret=0; 167 int ret=0;
191 168
@@ -201,11 +178,7 @@ int inl;
201 return(ret); 178 return(ret);
202 } 179 }
203 180
204static long MS_CALLBACK file_ctrl(b,cmd,num,ptr) 181static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, char *ptr)
205BIO *b;
206int cmd;
207long num;
208char *ptr;
209 { 182 {
210 long ret=1; 183 long ret=1;
211 FILE *fp=(FILE *)b->ptr; 184 FILE *fp=(FILE *)b->ptr;
@@ -214,18 +187,20 @@ char *ptr;
214 187
215 switch (cmd) 188 switch (cmd)
216 { 189 {
190 case BIO_C_FILE_SEEK:
217 case BIO_CTRL_RESET: 191 case BIO_CTRL_RESET:
218 ret=(long)fseek(fp,num,0); 192 ret=(long)fseek(fp,num,0);
219 break; 193 break;
220 case BIO_CTRL_EOF: 194 case BIO_CTRL_EOF:
221 ret=(long)feof(fp); 195 ret=(long)feof(fp);
222 break; 196 break;
197 case BIO_C_FILE_TELL:
223 case BIO_CTRL_INFO: 198 case BIO_CTRL_INFO:
224 ret=ftell(fp); 199 ret=ftell(fp);
225 break; 200 break;
226 case BIO_C_SET_FILE_PTR: 201 case BIO_C_SET_FILE_PTR:
227 file_free(b); 202 file_free(b);
228 b->shutdown=(int)num; 203 b->shutdown=(int)num&BIO_CLOSE;
229 b->ptr=(char *)ptr; 204 b->ptr=(char *)ptr;
230 b->init=1; 205 b->init=1;
231#if defined(MSDOS) || defined(WINDOWS) 206#if defined(MSDOS) || defined(WINDOWS)
@@ -307,10 +282,7 @@ char *ptr;
307 return(ret); 282 return(ret);
308 } 283 }
309 284
310static int MS_CALLBACK file_gets(bp,buf,size) 285static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
311BIO *bp;
312char *buf;
313int size;
314 { 286 {
315 int ret=0; 287 int ret=0;
316 288
@@ -321,9 +293,7 @@ int size;
321 return(ret); 293 return(ret);
322 } 294 }
323 295
324static int MS_CALLBACK file_puts(bp,str) 296static int MS_CALLBACK file_puts(BIO *bp, char *str)
325BIO *bp;
326char *str;
327 { 297 {
328 int n,ret; 298 int n,ret;
329 299
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 @@
1/* crypto/bio/bss_log.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 Why BIO_s_log?
58
59 BIO_s_log is useful for system daemons (or services under NT).
60 It is one-way BIO, it sends all stuff to syslogd (or event log
61 under NT).
62
63*/
64
65
66#include <stdio.h>
67#include <errno.h>
68
69#ifndef WIN32
70#ifdef __ultrix
71#include <sys/syslog.h>
72#else
73#include <syslog.h>
74#endif
75#endif
76
77#include "cryptlib.h"
78#include <openssl/buffer.h>
79#include <openssl/err.h>
80#ifndef NO_SYSLOG
81
82
83static int MS_CALLBACK slg_write(BIO *h,char *buf,int num);
84static int MS_CALLBACK slg_puts(BIO *h,char *str);
85static long MS_CALLBACK slg_ctrl(BIO *h,int cmd,long arg1,char *arg2);
86static int MS_CALLBACK slg_new(BIO *h);
87static int MS_CALLBACK slg_free(BIO *data);
88static int xopenlog(BIO* bp, const char* name, int level);
89static int xcloselog(BIO* bp);
90
91static BIO_METHOD methods_slg=
92 {
93 BIO_TYPE_MEM,"syslog",
94 slg_write,
95 NULL,
96 slg_puts,
97 NULL,
98 slg_ctrl,
99 slg_new,
100 slg_free,
101 };
102
103BIO_METHOD *BIO_s_log(void)
104 {
105 return(&methods_slg);
106 }
107
108static int MS_CALLBACK slg_new(BIO *bi)
109 {
110 bi->init=1;
111 bi->num=0;
112 bi->ptr=NULL;
113#ifndef WIN32
114 xopenlog(bi, "application", LOG_DAEMON);
115#else
116 xopenlog(bi, "application", 0);
117#endif
118 return(1);
119 }
120
121static int MS_CALLBACK slg_free(BIO *a)
122 {
123 if (a == NULL) return(0);
124 xcloselog(a);
125 return(1);
126 }
127
128static int MS_CALLBACK slg_write(BIO *b, char *in, int inl)
129 {
130 int ret= inl;
131 char* buf= in;
132 char* pp;
133#if defined(WIN32)
134 LPTSTR lpszStrings[1];
135 WORD evtype= EVENTLOG_ERROR_TYPE;
136#else
137 int priority;
138#endif
139
140 if((buf= (char *)Malloc(inl+ 1)) == NULL){
141 return(0);
142 }
143 strncpy(buf, in, inl);
144 buf[inl]= '\0';
145#if defined(WIN32)
146 if(strncmp(buf, "ERR ", 4) == 0){
147 evtype= EVENTLOG_ERROR_TYPE;
148 pp= buf+ 4;
149 }else if(strncmp(buf, "WAR ", 4) == 0){
150 evtype= EVENTLOG_WARNING_TYPE;
151 pp= buf+ 4;
152 }else if(strncmp(buf, "INF ", 4) == 0){
153 evtype= EVENTLOG_INFORMATION_TYPE;
154 pp= buf+ 4;
155 }else{
156 evtype= EVENTLOG_ERROR_TYPE;
157 pp= buf;
158 }
159 lpszStrings[0]= pp;
160
161 if(b->ptr)
162 ReportEvent(b->ptr, evtype, 0, 1024, NULL, 1, 0,
163 lpszStrings, NULL);
164#else
165 if(strncmp(buf, "ERR ", 4) == 0){
166 priority= LOG_ERR;
167 pp= buf+ 4;
168 }else if(strncmp(buf, "WAR ", 4) == 0){
169 priority= LOG_WARNING;
170 pp= buf+ 4;
171 }else if(strncmp(buf, "INF ", 4) == 0){
172 priority= LOG_INFO;
173 pp= buf+ 4;
174 }else{
175 priority= LOG_ERR;
176 pp= buf;
177 }
178
179 syslog(priority, "%s", pp);
180#endif
181 Free(buf);
182 return(ret);
183 }
184
185static long MS_CALLBACK slg_ctrl(BIO *b, int cmd, long num, char *ptr)
186 {
187 switch (cmd)
188 {
189 case BIO_CTRL_SET:
190 xcloselog(b);
191 xopenlog(b, ptr, num);
192 break;
193 default:
194 break;
195 }
196 return(0);
197 }
198
199static int MS_CALLBACK slg_puts(BIO *bp, char *str)
200 {
201 int n,ret;
202
203 n=strlen(str);
204 ret=slg_write(bp,str,n);
205 return(ret);
206 }
207
208static int xopenlog(BIO* bp, const char* name, int level)
209{
210#if defined(WIN32)
211 if((bp->ptr= (char *)RegisterEventSource(NULL, name)) == NULL){
212 return(0);
213 }
214#else
215 openlog(name, LOG_PID|LOG_CONS, level);
216#endif
217 return(1);
218}
219
220static int xcloselog(BIO* bp)
221{
222#if defined(WIN32)
223 if(bp->ptr)
224 DeregisterEventSource((HANDLE)(bp->ptr));
225 bp->ptr= NULL;
226#else
227 closelog();
228#endif
229 return(1);
230}
231
232#endif
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c
index 40c4e39f02..7e749a503e 100644
--- a/src/lib/libcrypto/bio/bss_mem.c
+++ b/src/lib/libcrypto/bio/bss_mem.c
@@ -59,9 +59,8 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bio.h" 62#include <openssl/bio.h>
63 63
64#ifndef NOPROTO
65static int mem_write(BIO *h,char *buf,int num); 64static int mem_write(BIO *h,char *buf,int num);
66static int mem_read(BIO *h,char *buf,int size); 65static int mem_read(BIO *h,char *buf,int size);
67static int mem_puts(BIO *h,char *str); 66static int mem_puts(BIO *h,char *str);
@@ -69,16 +68,6 @@ static int mem_gets(BIO *h,char *str,int size);
69static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2); 68static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int mem_new(BIO *h); 69static int mem_new(BIO *h);
71static int mem_free(BIO *data); 70static int mem_free(BIO *data);
72#else
73static int mem_write();
74static int mem_read();
75static int mem_puts();
76static int mem_gets();
77static long mem_ctrl();
78static int mem_new();
79static int mem_free();
80#endif
81
82static BIO_METHOD mem_method= 71static BIO_METHOD mem_method=
83 { 72 {
84 BIO_TYPE_MEM, 73 BIO_TYPE_MEM,
@@ -92,13 +81,15 @@ static BIO_METHOD mem_method=
92 mem_free, 81 mem_free,
93 }; 82 };
94 83
95BIO_METHOD *BIO_s_mem() 84/* bio->num is used to hold the value to return on 'empty', if it is
85 * 0, should_retry is not set */
86
87BIO_METHOD *BIO_s_mem(void)
96 { 88 {
97 return(&mem_method); 89 return(&mem_method);
98 } 90 }
99 91
100static int mem_new(bi) 92static int mem_new(BIO *bi)
101BIO *bi;
102 { 93 {
103 BUF_MEM *b; 94 BUF_MEM *b;
104 95
@@ -106,13 +97,12 @@ BIO *bi;
106 return(0); 97 return(0);
107 bi->shutdown=1; 98 bi->shutdown=1;
108 bi->init=1; 99 bi->init=1;
109 bi->num=0; 100 bi->num= -1;
110 bi->ptr=(char *)b; 101 bi->ptr=(char *)b;
111 return(1); 102 return(1);
112 } 103 }
113 104
114static int mem_free(a) 105static int mem_free(BIO *a)
115BIO *a;
116 { 106 {
117 if (a == NULL) return(0); 107 if (a == NULL) return(0);
118 if (a->shutdown) 108 if (a->shutdown)
@@ -126,10 +116,7 @@ BIO *a;
126 return(1); 116 return(1);
127 } 117 }
128 118
129static int mem_read(b,out,outl) 119static int mem_read(BIO *b, char *out, int outl)
130BIO *b;
131char *out;
132int outl;
133 { 120 {
134 int ret= -1; 121 int ret= -1;
135 BUF_MEM *bm; 122 BUF_MEM *bm;
@@ -151,16 +138,14 @@ int outl;
151 } 138 }
152 else if (bm->length == 0) 139 else if (bm->length == 0)
153 { 140 {
154 BIO_set_retry_read(b); 141 if (b->num != 0)
155 ret= -1; 142 BIO_set_retry_read(b);
143 ret= b->num;
156 } 144 }
157 return(ret); 145 return(ret);
158 } 146 }
159 147
160static int mem_write(b,in,inl) 148static int mem_write(BIO *b, char *in, int inl)
161BIO *b;
162char *in;
163int inl;
164 { 149 {
165 int ret= -1; 150 int ret= -1;
166 int blen; 151 int blen;
@@ -183,11 +168,7 @@ end:
183 return(ret); 168 return(ret);
184 } 169 }
185 170
186static long mem_ctrl(b,cmd,num,ptr) 171static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
187BIO *b;
188int cmd;
189long num;
190char *ptr;
191 { 172 {
192 long ret=1; 173 long ret=1;
193 char **pptr; 174 char **pptr;
@@ -204,6 +185,9 @@ char *ptr;
204 case BIO_CTRL_EOF: 185 case BIO_CTRL_EOF:
205 ret=(long)(bm->length == 0); 186 ret=(long)(bm->length == 0);
206 break; 187 break;
188 case BIO_C_SET_BUF_MEM_EOF_RETURN:
189 b->num=(int)num;
190 break;
207 case BIO_CTRL_INFO: 191 case BIO_CTRL_INFO:
208 ret=(long)bm->length; 192 ret=(long)bm->length;
209 if (ptr != NULL) 193 if (ptr != NULL)
@@ -250,10 +234,7 @@ char *ptr;
250 return(ret); 234 return(ret);
251 } 235 }
252 236
253static int mem_gets(bp,buf,size) 237static int mem_gets(BIO *bp, char *buf, int size)
254BIO *bp;
255char *buf;
256int size;
257 { 238 {
258 int i,j; 239 int i,j;
259 int ret= -1; 240 int ret= -1;
@@ -283,9 +264,7 @@ int size;
283 return(ret); 264 return(ret);
284 } 265 }
285 266
286static int mem_puts(bp,str) 267static int mem_puts(BIO *bp, char *str)
287BIO *bp;
288char *str;
289 { 268 {
290 int n,ret; 269 int n,ret;
291 270
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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bio.h" 62#include <openssl/bio.h>
63 63
64#ifndef NOPROTO
65static int null_write(BIO *h,char *buf,int num); 64static int null_write(BIO *h,char *buf,int num);
66static int null_read(BIO *h,char *buf,int size); 65static int null_read(BIO *h,char *buf,int size);
67static int null_puts(BIO *h,char *str); 66static int null_puts(BIO *h,char *str);
@@ -69,16 +68,6 @@ static int null_gets(BIO *h,char *str,int size);
69static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2); 68static long null_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int null_new(BIO *h); 69static int null_new(BIO *h);
71static int null_free(BIO *data); 70static int null_free(BIO *data);
72#else
73static int null_write();
74static int null_read();
75static int null_puts();
76static int null_gets();
77static long null_ctrl();
78static int null_new();
79static int null_free();
80#endif
81
82static BIO_METHOD null_method= 71static BIO_METHOD null_method=
83 { 72 {
84 BIO_TYPE_NULL, 73 BIO_TYPE_NULL,
@@ -92,13 +81,12 @@ static BIO_METHOD null_method=
92 null_free, 81 null_free,
93 }; 82 };
94 83
95BIO_METHOD *BIO_s_null() 84BIO_METHOD *BIO_s_null(void)
96 { 85 {
97 return(&null_method); 86 return(&null_method);
98 } 87 }
99 88
100static int null_new(bi) 89static int null_new(BIO *bi)
101BIO *bi;
102 { 90 {
103 bi->init=1; 91 bi->init=1;
104 bi->num=0; 92 bi->num=0;
@@ -106,34 +94,23 @@ BIO *bi;
106 return(1); 94 return(1);
107 } 95 }
108 96
109static int null_free(a) 97static int null_free(BIO *a)
110BIO *a;
111 { 98 {
112 if (a == NULL) return(0); 99 if (a == NULL) return(0);
113 return(1); 100 return(1);
114 } 101 }
115 102
116static int null_read(b,out,outl) 103static int null_read(BIO *b, char *out, int outl)
117BIO *b;
118char *out;
119int outl;
120 { 104 {
121 return(0); 105 return(0);
122 } 106 }
123 107
124static int null_write(b,in,inl) 108static int null_write(BIO *b, char *in, int inl)
125BIO *b;
126char *in;
127int inl;
128 { 109 {
129 return(inl); 110 return(inl);
130 } 111 }
131 112
132static long null_ctrl(b,cmd,num,ptr) 113static long null_ctrl(BIO *b, int cmd, long num, char *ptr)
133BIO *b;
134int cmd;
135long num;
136char *ptr;
137 { 114 {
138 long ret=1; 115 long ret=1;
139 116
@@ -159,17 +136,12 @@ char *ptr;
159 return(ret); 136 return(ret);
160 } 137 }
161 138
162static int null_gets(bp,buf,size) 139static int null_gets(BIO *bp, char *buf, int size)
163BIO *bp;
164char *buf;
165int size;
166 { 140 {
167 return(0); 141 return(0);
168 } 142 }
169 143
170static int null_puts(bp,str) 144static int null_puts(BIO *bp, char *str)
171BIO *bp;
172char *str;
173 { 145 {
174 if (str == NULL) return(0); 146 if (str == NULL) return(0);
175 return(strlen(str)); 147 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 @@
58 58
59/* Written by David L. Jones <jonesd@kcgl1.eng.ohio-state.edu> 59/* Written by David L. Jones <jonesd@kcgl1.eng.ohio-state.edu>
60 * Date: 22-JUL-1996 60 * Date: 22-JUL-1996
61 * Revised: 25-SEP-1997 Update for 0.8.1, BIO_CTRL_SET -> BIO_C_SET_FD
61 */ 62 */
62/* VMS */ 63/* VMS */
63#include <stdio.h> 64#include <stdio.h>
@@ -65,10 +66,11 @@
65#include <string.h> 66#include <string.h>
66#include <errno.h> 67#include <errno.h>
67#include "cryptlib.h" 68#include "cryptlib.h"
68#include "bio.h" 69#include <openssl/bio.h>
69 70
70#include <iodef.h> /* VMS IO$_ definitions */ 71#include <iodef.h> /* VMS IO$_ definitions */
71extern int SYS$QIOW(); 72#include <starlet.h>
73
72typedef unsigned short io_channel; 74typedef unsigned short io_channel;
73/*************************************************************************/ 75/*************************************************************************/
74struct io_status { short status, count; long flags; }; 76struct io_status { short status, count; long flags; };
@@ -107,18 +109,24 @@ static BIO_METHOD rtcp_method=
107 rtcp_free, 109 rtcp_free,
108 }; 110 };
109 111
110BIO_METHOD *BIO_s_rtcp() 112BIO_METHOD *BIO_s_rtcp(void)
111 { 113 {
112 return(&rtcp_method); 114 return(&rtcp_method);
113 } 115 }
114/*****************************************************************************/ 116/*****************************************************************************/
115/* Decnet I/O routines. 117/* Decnet I/O routines.
116 */ 118 */
119
120#ifdef __DECC
121#pragma message save
122#pragma message disable DOLLARID
123#endif
124
117static int get ( io_channel chan, char *buffer, int maxlen, int *length ) 125static int get ( io_channel chan, char *buffer, int maxlen, int *length )
118{ 126{
119 int status; 127 int status;
120 struct io_status iosb; 128 struct io_status iosb;
121 status = SYS$QIOW ( 0, chan, IO$_READVBLK, &iosb, 0, 0, 129 status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0,
122 buffer, maxlen, 0, 0, 0, 0 ); 130 buffer, maxlen, 0, 0, 0, 0 );
123 if ( (status&1) == 1 ) status = iosb.status; 131 if ( (status&1) == 1 ) status = iosb.status;
124 if ( (status&1) == 1 ) *length = iosb.count; 132 if ( (status&1) == 1 ) *length = iosb.count;
@@ -129,15 +137,19 @@ static int put ( io_channel chan, char *buffer, int length )
129{ 137{
130 int status; 138 int status;
131 struct io_status iosb; 139 struct io_status iosb;
132 status = SYS$QIOW ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, 140 status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
133 buffer, length, 0, 0, 0, 0 ); 141 buffer, length, 0, 0, 0, 0 );
134 if ( (status&1) == 1 ) status = iosb.status; 142 if ( (status&1) == 1 ) status = iosb.status;
135 return status; 143 return status;
136} 144}
145
146#ifdef __DECC
147#pragma message restore
148#endif
149
137/***************************************************************************/ 150/***************************************************************************/
138 151
139static int rtcp_new(bi) 152static int rtcp_new(BIO *bi)
140BIO *bi;
141{ 153{
142 struct rpc_ctx *ctx; 154 struct rpc_ctx *ctx;
143 bi->init=1; 155 bi->init=1;
@@ -150,8 +162,7 @@ BIO *bi;
150 return(1); 162 return(1);
151} 163}
152 164
153static int rtcp_free(a) 165static int rtcp_free(BIO *a)
154BIO *a;
155{ 166{
156 if (a == NULL) return(0); 167 if (a == NULL) return(0);
157 if ( a->ptr ) Free ( a->ptr ); 168 if ( a->ptr ) Free ( a->ptr );
@@ -159,10 +170,7 @@ BIO *a;
159 return(1); 170 return(1);
160} 171}
161 172
162static int rtcp_read(b,out,outl) 173static int rtcp_read(BIO *b, char *out, int outl)
163BIO *b;
164char *out;
165int outl;
166{ 174{
167 int status, length; 175 int status, length;
168 struct rpc_ctx *ctx; 176 struct rpc_ctx *ctx;
@@ -209,10 +217,7 @@ int outl;
209 return length; 217 return length;
210} 218}
211 219
212static int rtcp_write(b,in,inl) 220static int rtcp_write(BIO *b, char *in, int inl)
213BIO *b;
214char *in;
215int inl;
216{ 221{
217 int status, i, segment, length; 222 int status, i, segment, length;
218 struct rpc_ctx *ctx; 223 struct rpc_ctx *ctx;
@@ -241,11 +246,7 @@ int inl;
241 return(i); 246 return(i);
242} 247}
243 248
244static long rtcp_ctrl(b,cmd,num,ptr) 249static long rtcp_ctrl(BIO *b, int cmd, long num, char *ptr)
245BIO *b;
246int cmd;
247long num;
248char *ptr;
249 { 250 {
250 long ret=1; 251 long ret=1;
251 252
@@ -255,7 +256,7 @@ char *ptr;
255 case BIO_CTRL_EOF: 256 case BIO_CTRL_EOF:
256 ret = 1; 257 ret = 1;
257 break; 258 break;
258 case BIO_CTRL_SET: 259 case BIO_C_SET_FD:
259 b->num = num; 260 b->num = num;
260 ret = 1; 261 ret = 1;
261 break; 262 break;
@@ -276,17 +277,12 @@ char *ptr;
276 return(ret); 277 return(ret);
277 } 278 }
278 279
279static int rtcp_gets(bp,buf,size) 280static int rtcp_gets(BIO *bp, char *buf, int size)
280BIO *bp;
281char *buf;
282int size;
283 { 281 {
284 return(0); 282 return(0);
285 } 283 }
286 284
287static int rtcp_puts(bp,str) 285static int rtcp_puts(BIO *bp, char *str)
288BIO *bp;
289char *str;
290{ 286{
291 int length; 287 int length;
292 if (str == NULL) return(0); 288 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 @@
62#include <errno.h> 62#include <errno.h>
63#define USE_SOCKETS 63#define USE_SOCKETS
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio.h" 65#include <openssl/bio.h>
66 66
67#ifndef BIO_FD 67#ifndef BIO_FD
68#ifndef NOPROTO
69static int sock_write(BIO *h,char *buf,int num); 68static int sock_write(BIO *h,char *buf,int num);
70static int sock_read(BIO *h,char *buf,int size); 69static int sock_read(BIO *h,char *buf,int size);
71static int sock_puts(BIO *h,char *str); 70static int sock_puts(BIO *h,char *str);
@@ -74,18 +73,7 @@ static int sock_new(BIO *h);
74static int sock_free(BIO *data); 73static int sock_free(BIO *data);
75int BIO_sock_should_retry(int s); 74int BIO_sock_should_retry(int s);
76#else 75#else
77static int sock_write();
78static int sock_read();
79static int sock_puts();
80static long sock_ctrl();
81static int sock_new();
82static int sock_free();
83int BIO_sock_should_retry();
84#endif
85
86#else
87 76
88#ifndef NOPROTO
89static int fd_write(BIO *h,char *buf,int num); 77static int fd_write(BIO *h,char *buf,int num);
90static int fd_read(BIO *h,char *buf,int size); 78static int fd_read(BIO *h,char *buf,int size);
91static int fd_puts(BIO *h,char *str); 79static int fd_puts(BIO *h,char *str);
@@ -93,15 +81,6 @@ static long fd_ctrl(BIO *h,int cmd,long arg1,char *arg2);
93static int fd_new(BIO *h); 81static int fd_new(BIO *h);
94static int fd_free(BIO *data); 82static int fd_free(BIO *data);
95int BIO_fd_should_retry(int s); 83int BIO_fd_should_retry(int s);
96#else
97static int fd_write();
98static int fd_read();
99static int fd_puts();
100static long fd_ctrl();
101static int fd_new();
102static int fd_free();
103int BIO_fd_should_retry();
104#endif
105#endif 84#endif
106 85
107#ifndef BIO_FD 86#ifndef BIO_FD
@@ -118,7 +97,7 @@ static BIO_METHOD methods_sockp=
118 sock_free, 97 sock_free,
119 }; 98 };
120 99
121BIO_METHOD *BIO_s_socket() 100BIO_METHOD *BIO_s_socket(void)
122 { 101 {
123 return(&methods_sockp); 102 return(&methods_sockp);
124 } 103 }
@@ -135,19 +114,17 @@ static BIO_METHOD methods_fdp=
135 fd_free, 114 fd_free,
136 }; 115 };
137 116
138BIO_METHOD *BIO_s_fd() 117BIO_METHOD *BIO_s_fd(void)
139 { 118 {
140 return(&methods_fdp); 119 return(&methods_fdp);
141 } 120 }
142#endif 121#endif
143 122
144#ifndef BIO_FD 123#ifndef BIO_FD
145BIO *BIO_new_socket(fd,close_flag) 124BIO *BIO_new_socket(int fd, int close_flag)
146#else 125#else
147BIO *BIO_new_fd(fd,close_flag) 126BIO *BIO_new_fd(int fd,int close_flag)
148#endif 127#endif
149int fd;
150int close_flag;
151 { 128 {
152 BIO *ret; 129 BIO *ret;
153 130
@@ -162,11 +139,10 @@ int close_flag;
162 } 139 }
163 140
164#ifndef BIO_FD 141#ifndef BIO_FD
165static int sock_new(bi) 142static int sock_new(BIO *bi)
166#else 143#else
167static int fd_new(bi) 144static int fd_new(BIO *bi)
168#endif 145#endif
169BIO *bi;
170 { 146 {
171 bi->init=0; 147 bi->init=0;
172 bi->num=0; 148 bi->num=0;
@@ -176,11 +152,10 @@ BIO *bi;
176 } 152 }
177 153
178#ifndef BIO_FD 154#ifndef BIO_FD
179static int sock_free(a) 155static int sock_free(BIO *a)
180#else 156#else
181static int fd_free(a) 157static int fd_free(BIO *a)
182#endif 158#endif
183BIO *a;
184 { 159 {
185 if (a == NULL) return(0); 160 if (a == NULL) return(0);
186 if (a->shutdown) 161 if (a->shutdown)
@@ -189,11 +164,7 @@ BIO *a;
189 { 164 {
190#ifndef BIO_FD 165#ifndef BIO_FD
191 shutdown(a->num,2); 166 shutdown(a->num,2);
192# ifdef WINDOWS
193 closesocket(a->num); 167 closesocket(a->num);
194# else
195 close(a->num);
196# endif
197#else /* BIO_FD */ 168#else /* BIO_FD */
198 close(a->num); 169 close(a->num);
199#endif 170#endif
@@ -206,21 +177,18 @@ BIO *a;
206 } 177 }
207 178
208#ifndef BIO_FD 179#ifndef BIO_FD
209static int sock_read(b,out,outl) 180static int sock_read(BIO *b, char *out, int outl)
210#else 181#else
211static int fd_read(b,out,outl) 182static int fd_read(BIO *b, char *out,int outl)
212#endif 183#endif
213BIO *b;
214char *out;
215int outl;
216 { 184 {
217 int ret=0; 185 int ret=0;
218 186
219 if (out != NULL) 187 if (out != NULL)
220 { 188 {
221#if defined(WINDOWS) && !defined(BIO_FD) 189#ifndef BIO_FD
222 clear_socket_error(); 190 clear_socket_error();
223 ret=recv(b->num,out,outl,0); 191 ret=readsocket(b->num,out,outl);
224#else 192#else
225 clear_sys_error(); 193 clear_sys_error();
226 ret=read(b->num,out,outl); 194 ret=read(b->num,out,outl);
@@ -240,19 +208,16 @@ int outl;
240 } 208 }
241 209
242#ifndef BIO_FD 210#ifndef BIO_FD
243static int sock_write(b,in,inl) 211static int sock_write(BIO *b, char *in, int inl)
244#else 212#else
245static int fd_write(b,in,inl) 213static int fd_write(BIO *b, char *in, int inl)
246#endif 214#endif
247BIO *b;
248char *in;
249int inl;
250 { 215 {
251 int ret; 216 int ret;
252 217
253#if defined(WINDOWS) && !defined(BIO_FD) 218#ifndef BIO_FD
254 clear_socket_error(); 219 clear_socket_error();
255 ret=send(b->num,in,inl,0); 220 ret=writesocket(b->num,in,inl);
256#else 221#else
257 clear_sys_error(); 222 clear_sys_error();
258 ret=write(b->num,in,inl); 223 ret=write(b->num,in,inl);
@@ -271,14 +236,10 @@ int inl;
271 } 236 }
272 237
273#ifndef BIO_FD 238#ifndef BIO_FD
274static long sock_ctrl(b,cmd,num,ptr) 239static long sock_ctrl(BIO *b, int cmd, long num, char *ptr)
275#else 240#else
276static long fd_ctrl(b,cmd,num,ptr) 241static long fd_ctrl(BIO *b, int cmd, long num, char *ptr)
277#endif 242#endif
278BIO *b;
279int cmd;
280long num;
281char *ptr;
282 { 243 {
283 long ret=1; 244 long ret=1;
284 int *ip; 245 int *ip;
@@ -286,14 +247,21 @@ char *ptr;
286 switch (cmd) 247 switch (cmd)
287 { 248 {
288 case BIO_CTRL_RESET: 249 case BIO_CTRL_RESET:
250 num=0;
251 case BIO_C_FILE_SEEK:
289#ifdef BIO_FD 252#ifdef BIO_FD
290 ret=(long)lseek(b->num,0,0); 253 ret=(long)lseek(b->num,num,0);
291#else 254#else
292 ret=0; 255 ret=0;
293#endif 256#endif
294 break; 257 break;
258 case BIO_C_FILE_TELL:
295 case BIO_CTRL_INFO: 259 case BIO_CTRL_INFO:
260#ifdef BIO_FD
261 ret=(long)lseek(b->num,0,1);
262#else
296 ret=0; 263 ret=0;
264#endif
297 break; 265 break;
298 case BIO_C_SET_FD: 266 case BIO_C_SET_FD:
299#ifndef BIO_FD 267#ifndef BIO_FD
@@ -329,7 +297,6 @@ char *ptr;
329 case BIO_CTRL_FLUSH: 297 case BIO_CTRL_FLUSH:
330 ret=1; 298 ret=1;
331 break; 299 break;
332 break;
333 default: 300 default:
334 ret=0; 301 ret=0;
335 break; 302 break;
@@ -338,22 +305,17 @@ char *ptr;
338 } 305 }
339 306
340#ifdef undef 307#ifdef undef
341static int sock_gets(bp,buf,size) 308static int sock_gets(BIO *bp, char *buf,int size)
342BIO *bp;
343char *buf;
344int size;
345 { 309 {
346 return(-1); 310 return(-1);
347 } 311 }
348#endif 312#endif
349 313
350#ifndef BIO_FD 314#ifndef BIO_FD
351static int sock_puts(bp,str) 315static int sock_puts(BIO *bp, char *str)
352#else 316#else
353static int fd_puts(bp,str) 317static int fd_puts(BIO *bp, char *str)
354#endif 318#endif
355BIO *bp;
356char *str;
357 { 319 {
358 int n,ret; 320 int n,ret;
359 321
@@ -367,23 +329,22 @@ char *str;
367 } 329 }
368 330
369#ifndef BIO_FD 331#ifndef BIO_FD
370int BIO_sock_should_retry(i) 332int BIO_sock_should_retry(int i)
371#else 333#else
372int BIO_fd_should_retry(i) 334int BIO_fd_should_retry(int i)
373#endif 335#endif
374int i;
375 { 336 {
376 int err; 337 int err;
377 338
378 if ((i == 0) || (i == -1)) 339 if ((i == 0) || (i == -1))
379 { 340 {
380#if !defined(BIO_FD) && defined(WINDOWS) 341#ifndef BIO_FD
381 err=get_last_socket_error(); 342 err=get_last_socket_error();
382#else 343#else
383 err=get_last_sys_error(); 344 err=get_last_sys_error();
384#endif 345#endif
385 346
386#if defined(WINDOWS) /* more microsoft stupidity */ 347#if defined(WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
387 if ((i == -1) && (err == 0)) 348 if ((i == -1) && (err == 0))
388 return(1); 349 return(1);
389#endif 350#endif
@@ -398,11 +359,10 @@ int i;
398 } 359 }
399 360
400#ifndef BIO_FD 361#ifndef BIO_FD
401int BIO_sock_non_fatal_error(err) 362int BIO_sock_non_fatal_error(int err)
402#else 363#else
403int BIO_fd_non_fatal_error(err) 364int BIO_fd_non_fatal_error(int err)
404#endif 365#endif
405int err;
406 { 366 {
407 switch (err) 367 switch (err)
408 { 368 {
@@ -411,8 +371,10 @@ int err;
411 case WSAEWOULDBLOCK: 371 case WSAEWOULDBLOCK:
412# endif 372# endif
413 373
414# if defined(WSAENOTCONN) 374# if 0 /* This appears to always be an error */
375# if defined(WSAENOTCONN)
415 case WSAENOTCONN: 376 case WSAENOTCONN:
377# endif
416# endif 378# endif
417#endif 379#endif
418 380
@@ -452,7 +414,7 @@ int err;
452 case EALREADY: 414 case EALREADY:
453#endif 415#endif
454 return(1); 416 return(1);
455 break; 417 /* break; */
456 default: 418 default:
457 break; 419 break;
458 } 420 }
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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16BN_MULW= bn_mulw.o 18BN_ASM= bn_asm.o
17# or use 19# or use
18#BN_MULW= bn86-elf.o 20#BN_ASM= bn86-elf.o
19 21
20CFLAGS= $(INCLUDES) $(CFLAG) 22CFLAGS= $(INCLUDES) $(CFLAG)
23ASFLAGS=$(CFLAGS)
21 24
22ERR=bn
23ERRC=bn_err
24GENERAL=Makefile 25GENERAL=Makefile
25TEST=bntest.c exptest.c 26TEST=bntest.c exptest.c
26APPS= 27APPS=
27 28
28LIB=$(TOP)/libcrypto.a 29LIB=$(TOP)/libcrypto.a
29LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mod.c bn_mul.c \ 30LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_mul.c \
30 bn_print.c bn_rand.c bn_shift.c bn_sub.c bn_word.c bn_blind.c \ 31 bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
31 bn_gcd.c bn_prime.c $(ERRC).c bn_sqr.c bn_mulw.c bn_recp.c bn_mont.c \ 32 bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c bn_recp.c bn_mont.c \
32 bn_mpi.c 33 bn_mpi.c bn_exp2.c
33
34LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_mod.o bn_mul.o \
35 bn_print.o bn_rand.o bn_shift.o bn_sub.o bn_word.o bn_blind.o \
36 bn_gcd.o bn_prime.o $(ERRC).o bn_sqr.o $(BN_MULW) bn_recp.o bn_mont.o \
37 bn_mpi.o
38 34
35LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_mul.o \
36 bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \
37 bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) bn_recp.o bn_mont.o \
38 bn_mpi.o bn_exp2.o
39 39
40SRC= $(LIBSRC) 40SRC= $(LIBSRC)
41 41
@@ -58,53 +58,90 @@ knuth.fast: bn_knuth.c
58 58
59lib: $(LIBOBJ) 59lib: $(LIBOBJ)
60 $(AR) $(LIB) $(LIBOBJ) 60 $(AR) $(LIB) $(LIBOBJ)
61 sh $(TOP)/util/ranlib.sh $(LIB) 61 $(RANLIB) $(LIB)
62 @touch lib 62 @touch lib
63 63
64# elf 64# elf
65asm/bn86-elf.o: asm/bn86unix.cpp 65asm/bn86-elf.o: asm/bn86unix.cpp
66 $(CPP) -DELF asm/bn86unix.cpp | as -o asm/bn86-elf.o 66 $(CPP) -DELF asm/bn86unix.cpp | as -o asm/bn86-elf.o
67 67
68asm/co86-elf.o: asm/co86unix.cpp
69 $(CPP) -DELF asm/co86unix.cpp | as -o asm/co86-elf.o
70
68# solaris 71# solaris
69asm/bn86-sol.o: asm/bn86unix.cpp 72asm/bn86-sol.o: asm/bn86unix.cpp
70 $(CC) -E -DSOL asm/bn86unix.cpp | sed 's/^#.*//' > asm/bn86-sol.s 73 $(CC) -E -DSOL asm/bn86unix.cpp | sed 's/^#.*//' > asm/bn86-sol.s
71 as -o asm/bn86-sol.o asm/bn86-sol.s 74 as -o asm/bn86-sol.o asm/bn86-sol.s
72 rm -f asm/bn86-sol.s 75 rm -f asm/bn86-sol.s
73 76
77asm/co86-sol.o: asm/co86unix.cpp
78 $(CC) -E -DSOL asm/co86unix.cpp | sed 's/^#.*//' > asm/co86-sol.s
79 as -o asm/co86-sol.o asm/co86-sol.s
80 rm -f asm/co86-sol.s
81
74# a.out 82# a.out
75asm/bn86-out.o: asm/bn86unix.cpp 83asm/bn86-out.o: asm/bn86unix.cpp
76 $(CPP) -DOUT asm/bn86unix.cpp | as -o asm/bn86-out.o 84 $(CPP) -DOUT asm/bn86unix.cpp | as -o asm/bn86-out.o
77 85
86asm/co86-out.o: asm/co86unix.cpp
87 $(CPP) -DOUT asm/co86unix.cpp | as -o asm/co86-out.o
88
78# bsdi 89# bsdi
79asm/bn86bsdi.o: asm/bn86unix.cpp 90asm/bn86bsdi.o: asm/bn86unix.cpp
80 $(CPP) -DBSDI asm/bn86unix.cpp | as -o asm/bn86bsdi.o 91 $(CPP) -DBSDI asm/bn86unix.cpp | sed 's/ :/:/' | as -o asm/bn86bsdi.o
92
93asm/co86bsdi.o: asm/co86unix.cpp
94 $(CPP) -DBSDI asm/co86unix.cpp | sed 's/ :/:/' | as -o asm/co86bsdi.o
95
96asm/bn86unix.cpp: asm/bn-586.pl
97 (cd asm; $(PERL) bn-586.pl cpp >bn86unix.cpp )
98
99asm/co86unix.cpp: asm/co-586.pl
100 (cd asm; $(PERL) co-586.pl cpp >co86unix.cpp )
81 101
82asm/bn86unix.cpp: 102asm/sparcv8.o: asm/sparcv8.S
83 (cd asm; perl bn-586.pl cpp >bn86unix.cpp ) 103
104asm/sparcv8plus.o: asm/sparcv8plus.S
105
106# Old GNU assembler doesn't understand V9 instructions, so we
107# hire /usr/ccs/bin/as to do the job. Note that option is called
108# *-gcc27, but even gcc 2>=8 users may experience similar problem
109# if they didn't bother to upgrade GNU assembler. Such users should
110# not choose this option, but be adviced to *remove* GNU assembler
111# or upgrade it.
112asm/sparcv8plus-gcc27.o: asm/sparcv8plus.S
113 $(CC) $(ASFLAGS) -E asm/sparcv8plus.S | \
114 /usr/ccs/bin/as -xarch=v8plus - -o asm/sparcv8plus-gcc27.o
115
116# MIPS 64 bit assember
117asm/mips3.o: asm/mips3.s
118
119# MIPS 32 bit assember
120asm/mips1.o: asm/mips1.s
121 /usr/bin/as -O2 -o asm/mips1.o asm/mips1.s
84 122
85files: 123files:
86 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 124 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
87 125
88links: 126links:
89 /bin/rm -f Makefile 127 @$(TOP)/util/point.sh Makefile.ssl Makefile
90 $(TOP)/util/point.sh Makefile.ssl Makefile ; 128 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
91 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 129 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
92 $(TOP)/util/mklink.sh ../../test $(TEST) 130 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
93 $(TOP)/util/mklink.sh ../../apps $(APPS)
94 131
95install: 132install:
96 @for i in $(EXHEADER) ; \ 133 @for i in $(EXHEADER) ; \
97 do \ 134 do \
98 (cp $$i $(INSTALLTOP)/include/$$i; \ 135 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
99 chmod 644 $(INSTALLTOP)/include/$$i ); \ 136 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
100 done; 137 done;
101 138
102exptest: 139exptest:
103 /bin/rm -f exptest 140 rm -f exptest
104 gcc -I../../include -g2 -ggdb -o exptest exptest.c ../../libcrypto.a 141 gcc -I../../include -g2 -ggdb -o exptest exptest.c ../../libcrypto.a
105 142
106div: 143div:
107 /bin/rm -f a.out 144 rm -f a.out
108 gcc -I.. -g div.c ../../libcrypto.a 145 gcc -I.. -g div.c ../../libcrypto.a
109 146
110tags: 147tags:
@@ -116,18 +153,124 @@ lint:
116 lint -DLINT $(INCLUDES) $(SRC)>fluff 153 lint -DLINT $(INCLUDES) $(SRC)>fluff
117 154
118depend: 155depend:
119 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 156 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
120 157
121dclean: 158dclean:
122 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 159 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
123 mv -f Makefile.new $(MAKEFILE) 160 mv -f Makefile.new $(MAKEFILE)
124 161
125clean: 162clean:
126 /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff bn_mulw.s 163 rm -f asm/co86unix.cpp asm/bn86unix.cpp *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff bn_asm.s
127
128errors:
129 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # special case .org
130 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
131 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
132 164
133# DO NOT DELETE THIS LINE -- make depend depends on it. 165# DO NOT DELETE THIS LINE -- make depend depends on it.
166
167bn_add.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
168bn_add.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
169bn_add.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
170bn_add.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
171bn_add.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
172bn_add.o: ../cryptlib.h bn_lcl.h
173bn_asm.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
174bn_asm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
175bn_asm.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
176bn_asm.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
177bn_asm.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
178bn_asm.o: ../cryptlib.h bn_lcl.h
179bn_blind.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
180bn_blind.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
181bn_blind.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
182bn_blind.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
183bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
184bn_blind.o: ../cryptlib.h bn_lcl.h
185bn_div.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
186bn_div.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
187bn_div.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
188bn_div.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
189bn_div.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
190bn_div.o: ../cryptlib.h bn_lcl.h
191bn_err.o: ../../include/openssl/bn.h ../../include/openssl/err.h
192bn_err.o: ../../include/openssl/opensslconf.h
193bn_exp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
194bn_exp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
195bn_exp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
196bn_exp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
197bn_exp.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
198bn_exp.o: ../cryptlib.h bn_lcl.h
199bn_exp2.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
200bn_exp2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
201bn_exp2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
202bn_exp2.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
203bn_exp2.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
204bn_exp2.o: ../cryptlib.h bn_lcl.h
205bn_gcd.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
206bn_gcd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
207bn_gcd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
208bn_gcd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
209bn_gcd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
210bn_gcd.o: ../cryptlib.h bn_lcl.h
211bn_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
212bn_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
213bn_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
214bn_lib.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
215bn_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
216bn_lib.o: ../cryptlib.h bn_lcl.h
217bn_mont.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
218bn_mont.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
219bn_mont.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
220bn_mont.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
221bn_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
222bn_mont.o: ../cryptlib.h bn_lcl.h
223bn_mpi.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
224bn_mpi.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
225bn_mpi.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
226bn_mpi.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
227bn_mpi.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
228bn_mpi.o: ../cryptlib.h bn_lcl.h
229bn_mul.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
230bn_mul.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
231bn_mul.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
232bn_mul.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
233bn_mul.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
234bn_mul.o: ../cryptlib.h bn_lcl.h
235bn_prime.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
236bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
237bn_prime.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
238bn_prime.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
239bn_prime.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
240bn_prime.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h bn_prime.h
241bn_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
242bn_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
243bn_print.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
244bn_print.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
245bn_print.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
246bn_print.o: ../cryptlib.h bn_lcl.h
247bn_rand.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
248bn_rand.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
249bn_rand.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
250bn_rand.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
251bn_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
252bn_rand.o: ../../include/openssl/stack.h ../cryptlib.h bn_lcl.h
253bn_recp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
254bn_recp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
255bn_recp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
256bn_recp.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
257bn_recp.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
258bn_recp.o: ../cryptlib.h bn_lcl.h
259bn_shift.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
260bn_shift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
261bn_shift.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
262bn_shift.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
263bn_shift.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
264bn_shift.o: ../cryptlib.h bn_lcl.h
265bn_sqr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
266bn_sqr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
267bn_sqr.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
268bn_sqr.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
269bn_sqr.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
270bn_sqr.o: ../cryptlib.h bn_lcl.h
271bn_word.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
272bn_word.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
273bn_word.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
274bn_word.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
275bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
276bn_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 @@
1 # DEC Alpha assember 1 # DEC Alpha assember
2 # The bn_div64 is actually gcc output but the other parts are hand done. 2 # The bn_div_words is actually gcc output but the other parts are hand done.
3 # Thanks to tzeruch@ceddec.com for sending me the gcc output for 3 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
4 # bn_div64. 4 # bn_div_words.
5 .file 1 "bn_mulw.c" 5 # I've gone back and re-done most of routines.
6 # The key thing to remeber for the 164 CPU is that while a
7 # multiply operation takes 8 cycles, another one can only be issued
8 # after 4 cycles have elapsed. I've done modification to help
9 # improve this. Also, normally, a ld instruction will not be available
10 # for about 3 cycles.
11 .file 1 "bn_asm.c"
6 .set noat 12 .set noat
7gcc2_compiled.: 13gcc2_compiled.:
8__gnu_compiled_c: 14__gnu_compiled_c:
@@ -14,65 +20,91 @@ bn_mul_add_words:
14bn_mul_add_words..ng: 20bn_mul_add_words..ng:
15 .frame $30,0,$26,0 21 .frame $30,0,$26,0
16 .prologue 0 22 .prologue 0
17 subq $18,2,$25 # num=-2
18 bis $31,$31,$0
19 blt $25,$42
20 .align 5 23 .align 5
21$142: 24 subq $18,4,$18
22 subq $18,2,$18 # num-=2 25 bis $31,$31,$0
23 subq $25,2,$25 # num-=2 26 blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code
24 27 ldq $20,0($17) # 1 1
25 ldq $1,0($17) # a[0] 28 ldq $1,0($16) # 1 1
26 ldq $2,8($17) # a[1] 29 .align 3
27 30$42:
28 mulq $19,$1,$3 # a[0]*w low part r3 31 mulq $20,$19,$5 # 1 2 1 ######
29 umulh $19,$1,$1 # a[0]*w high part r1 32 ldq $21,8($17) # 2 1
30 mulq $19,$2,$4 # a[1]*w low part r4 33 ldq $2,8($16) # 2 1
31 umulh $19,$2,$2 # a[1]*w high part r2 34 umulh $20,$19,$20 # 1 2 ######
32 35 ldq $27,16($17) # 3 1
33 ldq $22,0($16) # r[0] r22 36 ldq $3,16($16) # 3 1
34 ldq $23,8($16) # r[1] r23 37 mulq $21,$19,$6 # 2 2 1 ######
35 38 ldq $28,24($17) # 4 1
36 addq $3,$22,$3 # a0 low part + r[0] 39 addq $1,$5,$1 # 1 2 2
37 addq $4,$23,$4 # a1 low part + r[1] 40 ldq $4,24($16) # 4 1
38 cmpult $3,$22,$5 # overflow? 41 umulh $21,$19,$21 # 2 2 ######
39 cmpult $4,$23,$6 # overflow? 42 cmpult $1,$5,$22 # 1 2 3 1
40 addq $5,$1,$1 # high part + overflow 43 addq $20,$22,$20 # 1 3 1
41 addq $6,$2,$2 # high part + overflow 44 addq $1,$0,$1 # 1 2 3 1
42 45 mulq $27,$19,$7 # 3 2 1 ######
43 addq $3,$0,$3 # add c 46 cmpult $1,$0,$0 # 1 2 3 2
44 cmpult $3,$0,$5 # overflow? 47 addq $2,$6,$2 # 2 2 2
45 stq $3,0($16) 48 addq $20,$0,$0 # 1 3 2
46 addq $5,$1,$0 # c=high part + overflow 49 cmpult $2,$6,$23 # 2 2 3 1
47 50 addq $21,$23,$21 # 2 3 1
48 addq $4,$0,$4 # add c 51 umulh $27,$19,$27 # 3 2 ######
49 cmpult $4,$0,$5 # overflow? 52 addq $2,$0,$2 # 2 2 3 1
50 stq $4,8($16) 53 cmpult $2,$0,$0 # 2 2 3 2
51 addq $5,$2,$0 # c=high part + overflow 54 subq $18,4,$18
55 mulq $28,$19,$8 # 4 2 1 ######
56 addq $21,$0,$0 # 2 3 2
57 addq $3,$7,$3 # 3 2 2
58 addq $16,32,$16
59 cmpult $3,$7,$24 # 3 2 3 1
60 stq $1,-32($16) # 1 2 4
61 umulh $28,$19,$28 # 4 2 ######
62 addq $27,$24,$27 # 3 3 1
63 addq $3,$0,$3 # 3 2 3 1
64 stq $2,-24($16) # 2 2 4
65 cmpult $3,$0,$0 # 3 2 3 2
66 stq $3,-16($16) # 3 2 4
67 addq $4,$8,$4 # 4 2 2
68 addq $27,$0,$0 # 3 3 2
69 cmpult $4,$8,$25 # 4 2 3 1
70 addq $17,32,$17
71 addq $28,$25,$28 # 4 3 1
72 addq $4,$0,$4 # 4 2 3 1
73 cmpult $4,$0,$0 # 4 2 3 2
74 stq $4,-8($16) # 4 2 4
75 addq $28,$0,$0 # 4 3 2
76 blt $18,$43
52 77
53 ble $18,$43 78 ldq $20,0($17) # 1 1
79 ldq $1,0($16) # 1 1
54 80
55 addq $16,16,$16 81 br $42
56 addq $17,16,$17
57 blt $25,$42
58 82
59 br $31,$142 83 .align 4
60$42: 84$45:
61 ldq $1,0($17) # a[0] 85 ldq $20,0($17) # 4 1
62 umulh $19,$1,$3 # a[0]*w high part 86 ldq $1,0($16) # 4 1
63 mulq $19,$1,$1 # a[0]*w low part 87 mulq $20,$19,$5 # 4 2 1
64 ldq $2,0($16) # r[0] 88 subq $18,1,$18
65 addq $1,$2,$1 # low part + r[0] 89 addq $16,8,$16
66 cmpult $1,$2,$4 # overflow? 90 addq $17,8,$17
67 addq $4,$3,$3 # high part + overflow 91 umulh $20,$19,$20 # 4 2
68 addq $1,$0,$1 # add c 92 addq $1,$5,$1 # 4 2 2
69 cmpult $1,$0,$4 # overflow? 93 cmpult $1,$5,$22 # 4 2 3 1
70 addq $4,$3,$0 # c=high part + overflow 94 addq $20,$22,$20 # 4 3 1
71 stq $1,0($16) 95 addq $1,$0,$1 # 4 2 3 1
96 cmpult $1,$0,$0 # 4 2 3 2
97 addq $20,$0,$0 # 4 3 2
98 stq $1,-8($16) # 4 2 4
99 bgt $18,$45
100 ret $31,($26),1 # else exit
72 101
73 .align 4 102 .align 4
74$43: 103$43:
75 ret $31,($26),1 104 addq $18,4,$18
105 bgt $18,$45 # goto tail code
106 ret $31,($26),1 # else exit
107
76 .end bn_mul_add_words 108 .end bn_mul_add_words
77 .align 3 109 .align 3
78 .globl bn_mul_words 110 .globl bn_mul_words
@@ -81,49 +113,75 @@ bn_mul_words:
81bn_mul_words..ng: 113bn_mul_words..ng:
82 .frame $30,0,$26,0 114 .frame $30,0,$26,0
83 .prologue 0 115 .prologue 0
84 subq $18,2,$25 # num=-2
85 bis $31,$31,$0
86 blt $25,$242
87 .align 5 116 .align 5
88$342: 117 subq $18,4,$18
89 subq $18,2,$18 # num-=2 118 bis $31,$31,$0
90 subq $25,2,$25 # num-=2 119 blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code
91 120 ldq $20,0($17) # 1 1
92 ldq $1,0($17) # a[0] 121 .align 3
93 ldq $2,8($17) # a[1] 122$142:
94 123
95 mulq $19,$1,$3 # a[0]*w low part r3 124 mulq $20,$19,$5 # 1 2 1 #####
96 umulh $19,$1,$1 # a[0]*w high part r1 125 ldq $21,8($17) # 2 1
97 mulq $19,$2,$4 # a[1]*w low part r4 126 ldq $27,16($17) # 3 1
98 umulh $19,$2,$2 # a[1]*w high part r2 127 umulh $20,$19,$20 # 1 2 #####
99 128 ldq $28,24($17) # 4 1
100 addq $3,$0,$3 # add c 129 mulq $21,$19,$6 # 2 2 1 #####
101 cmpult $3,$0,$5 # overflow? 130 addq $5,$0,$5 # 1 2 3 1
102 stq $3,0($16) 131 subq $18,4,$18
103 addq $5,$1,$0 # c=high part + overflow 132 cmpult $5,$0,$0 # 1 2 3 2
104 133 umulh $21,$19,$21 # 2 2 #####
105 addq $4,$0,$4 # add c 134 addq $20,$0,$0 # 1 3 2
106 cmpult $4,$0,$5 # overflow? 135 addq $17,32,$17
107 stq $4,8($16) 136 addq $6,$0,$6 # 2 2 3 1
108 addq $5,$2,$0 # c=high part + overflow 137 mulq $27,$19,$7 # 3 2 1 #####
109 138 cmpult $6,$0,$0 # 2 2 3 2
110 ble $18,$243 139 addq $21,$0,$0 # 2 3 2
111 140 addq $16,32,$16
112 addq $16,16,$16 141 umulh $27,$19,$27 # 3 2 #####
113 addq $17,16,$17 142 stq $5,-32($16) # 1 2 4
114 blt $25,$242 143 mulq $28,$19,$8 # 4 2 1 #####
115 144 addq $7,$0,$7 # 3 2 3 1
116 br $31,$342 145 stq $6,-24($16) # 2 2 4
117$242: 146 cmpult $7,$0,$0 # 3 2 3 2
118 ldq $1,0($17) # a[0] 147 umulh $28,$19,$28 # 4 2 #####
119 umulh $19,$1,$3 # a[0]*w high part 148 addq $27,$0,$0 # 3 3 2
120 mulq $19,$1,$1 # a[0]*w low part 149 stq $7,-16($16) # 3 2 4
121 addq $1,$0,$1 # add c 150 addq $8,$0,$8 # 4 2 3 1
122 cmpult $1,$0,$4 # overflow? 151 cmpult $8,$0,$0 # 4 2 3 2
123 addq $4,$3,$0 # c=high part + overflow 152
124 stq $1,0($16) 153 addq $28,$0,$0 # 4 3 2
125$243: 154
126 ret $31,($26),1 155 stq $8,-8($16) # 4 2 4
156
157 blt $18,$143
158
159 ldq $20,0($17) # 1 1
160
161 br $142
162
163 .align 4
164$145:
165 ldq $20,0($17) # 4 1
166 mulq $20,$19,$5 # 4 2 1
167 subq $18,1,$18
168 umulh $20,$19,$20 # 4 2
169 addq $5,$0,$5 # 4 2 3 1
170 addq $16,8,$16
171 cmpult $5,$0,$0 # 4 2 3 2
172 addq $17,8,$17
173 addq $20,$0,$0 # 4 3 2
174 stq $5,-8($16) # 4 2 4
175
176 bgt $18,$145
177 ret $31,($26),1 # else exit
178
179 .align 4
180$143:
181 addq $18,4,$18
182 bgt $18,$145 # goto tail code
183 ret $31,($26),1 # else exit
184
127 .end bn_mul_words 185 .end bn_mul_words
128 .align 3 186 .align 3
129 .globl bn_sqr_words 187 .globl bn_sqr_words
@@ -132,44 +190,58 @@ bn_sqr_words:
132bn_sqr_words..ng: 190bn_sqr_words..ng:
133 .frame $30,0,$26,0 191 .frame $30,0,$26,0
134 .prologue 0 192 .prologue 0
135
136 subq $18,2,$25 # num=-2
137 blt $25,$442
138 .align 5
139$542:
140 subq $18,2,$18 # num-=2
141 subq $25,2,$25 # num-=2
142
143 ldq $1,0($17) # a[0]
144 ldq $4,8($17) # a[1]
145 193
146 mulq $1,$1,$2 # a[0]*w low part r2 194 subq $18,4,$18
147 umulh $1,$1,$3 # a[0]*w high part r3 195 blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code
148 mulq $4,$4,$5 # a[1]*w low part r5 196 ldq $20,0($17) # 1 1
149 umulh $4,$4,$6 # a[1]*w high part r6 197 .align 3
150 198$542:
151 stq $2,0($16) # r[0] 199 mulq $20,$20,$5 ######
152 stq $3,8($16) # r[1] 200 ldq $21,8($17) # 1 1
153 stq $5,16($16) # r[3] 201 subq $18,4
154 stq $6,24($16) # r[4] 202 umulh $20,$20,$1 ######
203 ldq $27,16($17) # 1 1
204 mulq $21,$21,$6 ######
205 ldq $28,24($17) # 1 1
206 stq $5,0($16) # r[0]
207 umulh $21,$21,$2 ######
208 stq $1,8($16) # r[1]
209 mulq $27,$27,$7 ######
210 stq $6,16($16) # r[0]
211 umulh $27,$27,$3 ######
212 stq $2,24($16) # r[1]
213 mulq $28,$28,$8 ######
214 stq $7,32($16) # r[0]
215 umulh $28,$28,$4 ######
216 stq $3,40($16) # r[1]
155 217
156 ble $18,$443 218 addq $16,64,$16
219 addq $17,32,$17
220 stq $8,-16($16) # r[0]
221 stq $4,-8($16) # r[1]
157 222
158 addq $16,32,$16 223 blt $18,$543
159 addq $17,16,$17 224 ldq $20,0($17) # 1 1
160 blt $25,$442 225 br $542
161 br $31,$542
162 226
163$442: 227$442:
164 ldq $1,0($17) # a[0] 228 ldq $20,0($17) # a[0]
165 mulq $1,$1,$2 # a[0]*w low part r2 229 mulq $20,$20,$5 # a[0]*w low part r2
166 umulh $1,$1,$3 # a[0]*w high part r3 230 addq $16,16,$16
167 stq $2,0($16) # r[0] 231 addq $17,8,$17
168 stq $3,8($16) # r[1] 232 subq $18,1,$18
233 umulh $20,$20,$1 # a[0]*w high part r3
234 stq $5,-16($16) # r[0]
235 stq $1,-8($16) # r[1]
236
237 bgt $18,$442
238 ret $31,($26),1 # else exit
169 239
170 .align 4 240 .align 4
171$443: 241$543:
172 ret $31,($26),1 242 addq $18,4,$18
243 bgt $18,$442 # goto tail code
244 ret $31,($26),1 # else exit
173 .end bn_sqr_words 245 .end bn_sqr_words
174 246
175 .align 3 247 .align 3
@@ -180,31 +252,74 @@ bn_add_words..ng:
180 .frame $30,0,$26,0 252 .frame $30,0,$26,0
181 .prologue 0 253 .prologue 0
182 254
183 bis $31,$31,$8 # carry = 0 255 subq $19,4,$19
184 ble $19,$900 256 bis $31,$31,$0 # carry = 0
257 blt $19,$900
258 ldq $5,0($17) # a[0]
259 ldq $1,0($18) # b[1]
260 .align 3
185$901: 261$901:
186 ldq $0,0($17) # a[0] 262 addq $1,$5,$1 # r=a+b;
187 ldq $1,0($18) # a[1] 263 ldq $6,8($17) # a[1]
264 cmpult $1,$5,$22 # did we overflow?
265 ldq $2,8($18) # b[1]
266 addq $1,$0,$1 # c+= overflow
267 ldq $7,16($17) # a[2]
268 cmpult $1,$0,$0 # overflow?
269 ldq $3,16($18) # b[2]
270 addq $0,$22,$0
271 ldq $8,24($17) # a[3]
272 addq $2,$6,$2 # r=a+b;
273 ldq $4,24($18) # b[3]
274 cmpult $2,$6,$23 # did we overflow?
275 addq $3,$7,$3 # r=a+b;
276 addq $2,$0,$2 # c+= overflow
277 cmpult $3,$7,$24 # did we overflow?
278 cmpult $2,$0,$0 # overflow?
279 addq $4,$8,$4 # r=a+b;
280 addq $0,$23,$0
281 cmpult $4,$8,$25 # did we overflow?
282 addq $3,$0,$3 # c+= overflow
283 stq $1,0($16) # r[0]=c
284 cmpult $3,$0,$0 # overflow?
285 stq $2,8($16) # r[1]=c
286 addq $0,$24,$0
287 stq $3,16($16) # r[2]=c
288 addq $4,$0,$4 # c+= overflow
289 subq $19,4,$19 # loop--
290 cmpult $4,$0,$0 # overflow?
291 addq $17,32,$17 # a++
292 addq $0,$25,$0
293 stq $4,24($16) # r[3]=c
294 addq $18,32,$18 # b++
295 addq $16,32,$16 # r++
188 296
189 addq $0,$1,$3 # c=a+b; 297 blt $19,$900
298 ldq $5,0($17) # a[0]
299 ldq $1,0($18) # b[1]
300 br $901
301 .align 4
302$945:
303 ldq $5,0($17) # a[0]
304 ldq $1,0($18) # b[1]
305 addq $1,$5,$1 # r=a+b;
306 subq $19,1,$19 # loop--
307 addq $1,$0,$1 # c+= overflow
190 addq $17,8,$17 # a++ 308 addq $17,8,$17 # a++
309 cmpult $1,$5,$22 # did we overflow?
310 cmpult $1,$0,$0 # overflow?
311 addq $18,8,$18 # b++
312 stq $1,0($16) # r[0]=c
313 addq $0,$22,$0
314 addq $16,8,$16 # r++
191 315
192 cmpult $3,$1,$7 # did we overflow? 316 bgt $19,$945
193 addq $18,8,$18 # b++ 317 ret $31,($26),1 # else exit
194
195 addq $8,$3,$3 # c+=carry
196 318
197 cmpult $3,$8,$8 # did we overflow?
198 stq $3,($16) # r[0]=c
199
200 addq $7,$8,$8 # add into overflow
201 subq $19,1,$19 # loop--
202
203 addq $16,8,$16 # r++
204 bgt $19,$901
205$900: 319$900:
206 bis $8,$8,$0 # return carry 320 addq $19,4,$19
207 ret $31,($26),1 321 bgt $19,$945 # goto tail code
322 ret $31,($26),1 # else exit
208 .end bn_add_words 323 .end bn_add_words
209 324
210 # 325 #
@@ -213,11 +328,11 @@ $900:
213 # 328 #
214.text 329.text
215 .align 3 330 .align 3
216 .globl bn_div64 331 .globl bn_div_words
217 .ent bn_div64 332 .ent bn_div_words
218bn_div64: 333bn_div_words:
219 ldgp $29,0($27) 334 ldgp $29,0($27)
220bn_div64..ng: 335bn_div_words..ng:
221 lda $30,-48($30) 336 lda $30,-48($30)
222 .frame $30,48,$26,0 337 .frame $30,48,$26,0
223 stq $26,0($30) 338 stq $26,0($30)
@@ -338,7 +453,1446 @@ $136:
338 ldq $13,40($30) 453 ldq $13,40($30)
339 addq $30,48,$30 454 addq $30,48,$30
340 ret $31,($26),1 455 ret $31,($26),1
341 .end bn_div64 456 .end bn_div_words
342 .ident "GCC: (GNU) 2.7.2.1" 457
458 .set noat
459 .text
460 .align 3
461 .globl bn_sub_words
462 .ent bn_sub_words
463bn_sub_words:
464bn_sub_words..ng:
465 .frame $30,0,$26,0
466 .prologue 0
467
468 subq $19, 4, $19
469 bis $31, $31, $0
470 blt $19, $100
471 ldq $1, 0($17)
472 ldq $2, 0($18)
473$101:
474 ldq $3, 8($17)
475 cmpult $1, $2, $4
476 ldq $5, 8($18)
477 subq $1, $2, $1
478 ldq $6, 16($17)
479 cmpult $1, $0, $2
480 ldq $7, 16($18)
481 subq $1, $0, $23
482 ldq $8, 24($17)
483 addq $2, $4, $0
484 cmpult $3, $5, $24
485 subq $3, $5, $3
486 ldq $22, 24($18)
487 cmpult $3, $0, $5
488 subq $3, $0, $25
489 addq $5, $24, $0
490 cmpult $6, $7, $27
491 subq $6, $7, $6
492 stq $23, 0($16)
493 cmpult $6, $0, $7
494 subq $6, $0, $28
495 addq $7, $27, $0
496 cmpult $8, $22, $21
497 subq $8, $22, $8
498 stq $25, 8($16)
499 cmpult $8, $0, $22
500 subq $8, $0, $20
501 addq $22, $21, $0
502 stq $28, 16($16)
503 subq $19, 4, $19
504 stq $20, 24($16)
505 addq $17, 32, $17
506 addq $18, 32, $18
507 addq $16, 32, $16
508 blt $19, $100
509 ldq $1, 0($17)
510 ldq $2, 0($18)
511 br $101
512$102:
513 ldq $1, 0($17)
514 ldq $2, 0($18)
515 cmpult $1, $2, $27
516 subq $1, $2, $1
517 cmpult $1, $0, $2
518 subq $1, $0, $1
519 stq $1, 0($16)
520 addq $2, $27, $0
521 addq $17, 8, $17
522 addq $18, 8, $18
523 addq $16, 8, $16
524 subq $19, 1, $19
525 bgt $19, $102
526 ret $31,($26),1
527$100:
528 addq $19, 4, $19
529 bgt $19, $102
530$103:
531 ret $31,($26),1
532 .end bn_sub_words
533 .text
534 .align 3
535 .globl bn_mul_comba4
536 .ent bn_mul_comba4
537bn_mul_comba4:
538bn_mul_comba4..ng:
539 .frame $30,0,$26,0
540 .prologue 0
343 541
542 ldq $0, 0($17)
543 ldq $1, 0($18)
544 ldq $2, 8($17)
545 ldq $3, 8($18)
546 ldq $4, 16($17)
547 ldq $5, 16($18)
548 ldq $6, 24($17)
549 ldq $7, 24($18)
550 bis $31, $31, $23
551 mulq $0, $1, $8
552 umulh $0, $1, $22
553 stq $8, 0($16)
554 bis $31, $31, $8
555 mulq $0, $3, $24
556 umulh $0, $3, $25
557 addq $22, $24, $22
558 cmpult $22, $24, $27
559 addq $27, $25, $25
560 addq $23, $25, $23
561 cmpult $23, $25, $28
562 addq $8, $28, $8
563 mulq $2, $1, $21
564 umulh $2, $1, $20
565 addq $22, $21, $22
566 cmpult $22, $21, $19
567 addq $19, $20, $20
568 addq $23, $20, $23
569 cmpult $23, $20, $17
570 addq $8, $17, $8
571 stq $22, 8($16)
572 bis $31, $31, $22
573 mulq $2, $3, $18
574 umulh $2, $3, $24
575 addq $23, $18, $23
576 cmpult $23, $18, $27
577 addq $27, $24, $24
578 addq $8, $24, $8
579 cmpult $8, $24, $25
580 addq $22, $25, $22
581 mulq $0, $5, $28
582 umulh $0, $5, $21
583 addq $23, $28, $23
584 cmpult $23, $28, $19
585 addq $19, $21, $21
586 addq $8, $21, $8
587 cmpult $8, $21, $20
588 addq $22, $20, $22
589 mulq $4, $1, $17
590 umulh $4, $1, $18
591 addq $23, $17, $23
592 cmpult $23, $17, $27
593 addq $27, $18, $18
594 addq $8, $18, $8
595 cmpult $8, $18, $24
596 addq $22, $24, $22
597 stq $23, 16($16)
598 bis $31, $31, $23
599 mulq $0, $7, $25
600 umulh $0, $7, $28
601 addq $8, $25, $8
602 cmpult $8, $25, $19
603 addq $19, $28, $28
604 addq $22, $28, $22
605 cmpult $22, $28, $21
606 addq $23, $21, $23
607 mulq $2, $5, $20
608 umulh $2, $5, $17
609 addq $8, $20, $8
610 cmpult $8, $20, $27
611 addq $27, $17, $17
612 addq $22, $17, $22
613 cmpult $22, $17, $18
614 addq $23, $18, $23
615 mulq $4, $3, $24
616 umulh $4, $3, $25
617 addq $8, $24, $8
618 cmpult $8, $24, $19
619 addq $19, $25, $25
620 addq $22, $25, $22
621 cmpult $22, $25, $28
622 addq $23, $28, $23
623 mulq $6, $1, $21
624 umulh $6, $1, $0
625 addq $8, $21, $8
626 cmpult $8, $21, $20
627 addq $20, $0, $0
628 addq $22, $0, $22
629 cmpult $22, $0, $27
630 addq $23, $27, $23
631 stq $8, 24($16)
632 bis $31, $31, $8
633 mulq $2, $7, $17
634 umulh $2, $7, $18
635 addq $22, $17, $22
636 cmpult $22, $17, $24
637 addq $24, $18, $18
638 addq $23, $18, $23
639 cmpult $23, $18, $19
640 addq $8, $19, $8
641 mulq $4, $5, $25
642 umulh $4, $5, $28
643 addq $22, $25, $22
644 cmpult $22, $25, $21
645 addq $21, $28, $28
646 addq $23, $28, $23
647 cmpult $23, $28, $20
648 addq $8, $20, $8
649 mulq $6, $3, $0
650 umulh $6, $3, $27
651 addq $22, $0, $22
652 cmpult $22, $0, $1
653 addq $1, $27, $27
654 addq $23, $27, $23
655 cmpult $23, $27, $17
656 addq $8, $17, $8
657 stq $22, 32($16)
658 bis $31, $31, $22
659 mulq $4, $7, $24
660 umulh $4, $7, $18
661 addq $23, $24, $23
662 cmpult $23, $24, $19
663 addq $19, $18, $18
664 addq $8, $18, $8
665 cmpult $8, $18, $2
666 addq $22, $2, $22
667 mulq $6, $5, $25
668 umulh $6, $5, $21
669 addq $23, $25, $23
670 cmpult $23, $25, $28
671 addq $28, $21, $21
672 addq $8, $21, $8
673 cmpult $8, $21, $20
674 addq $22, $20, $22
675 stq $23, 40($16)
676 bis $31, $31, $23
677 mulq $6, $7, $0
678 umulh $6, $7, $1
679 addq $8, $0, $8
680 cmpult $8, $0, $27
681 addq $27, $1, $1
682 addq $22, $1, $22
683 cmpult $22, $1, $17
684 addq $23, $17, $23
685 stq $8, 48($16)
686 stq $22, 56($16)
687 ret $31,($26),1
688 .end bn_mul_comba4
689 .text
690 .align 3
691 .globl bn_mul_comba8
692 .ent bn_mul_comba8
693bn_mul_comba8:
694bn_mul_comba8..ng:
695 .frame $30,0,$26,0
696 .prologue 0
697
698 subq $30, 16, $30
699 ldq $0, 0($17)
700 ldq $1, 0($18)
701 stq $9, 0($30)
702 stq $10, 8($30)
703 ldq $2, 8($17)
704 ldq $3, 8($18)
705 ldq $4, 16($17)
706 ldq $5, 16($18)
707 ldq $6, 24($17)
708 ldq $7, 24($18)
709 ldq $8, 8($17)
710 ldq $22, 8($18)
711 ldq $23, 8($17)
712 ldq $24, 8($18)
713 ldq $25, 8($17)
714 ldq $27, 8($18)
715 ldq $28, 8($17)
716 ldq $21, 8($18)
717 bis $31, $31, $9
718 mulq $0, $1, $20
719 umulh $0, $1, $19
720 stq $20, 0($16)
721 bis $31, $31, $20
722 mulq $0, $3, $10
723 umulh $0, $3, $17
724 addq $19, $10, $19
725 cmpult $19, $10, $18
726 addq $18, $17, $17
727 addq $9, $17, $9
728 cmpult $9, $17, $10
729 addq $20, $10, $20
730 mulq $2, $1, $18
731 umulh $2, $1, $17
732 addq $19, $18, $19
733 cmpult $19, $18, $10
734 addq $10, $17, $17
735 addq $9, $17, $9
736 cmpult $9, $17, $18
737 addq $20, $18, $20
738 stq $19, 8($16)
739 bis $31, $31, $19
740 mulq $0, $5, $10
741 umulh $0, $5, $17
742 addq $9, $10, $9
743 cmpult $9, $10, $18
744 addq $18, $17, $17
745 addq $20, $17, $20
746 cmpult $20, $17, $10
747 addq $19, $10, $19
748 mulq $2, $3, $18
749 umulh $2, $3, $17
750 addq $9, $18, $9
751 cmpult $9, $18, $10
752 addq $10, $17, $17
753 addq $20, $17, $20
754 cmpult $20, $17, $18
755 addq $19, $18, $19
756 mulq $4, $1, $10
757 umulh $4, $1, $17
758 addq $9, $10, $9
759 cmpult $9, $10, $18
760 addq $18, $17, $17
761 addq $20, $17, $20
762 cmpult $20, $17, $10
763 addq $19, $10, $19
764 stq $9, 16($16)
765 bis $31, $31, $9
766 mulq $0, $7, $18
767 umulh $0, $7, $17
768 addq $20, $18, $20
769 cmpult $20, $18, $10
770 addq $10, $17, $17
771 addq $19, $17, $19
772 cmpult $19, $17, $18
773 addq $9, $18, $9
774 mulq $2, $5, $10
775 umulh $2, $5, $17
776 addq $20, $10, $20
777 cmpult $20, $10, $18
778 addq $18, $17, $17
779 addq $19, $17, $19
780 cmpult $19, $17, $10
781 addq $9, $10, $9
782 mulq $4, $3, $18
783 umulh $4, $3, $17
784 addq $20, $18, $20
785 cmpult $20, $18, $10
786 addq $10, $17, $17
787 addq $19, $17, $19
788 cmpult $19, $17, $18
789 addq $9, $18, $9
790 mulq $6, $1, $10
791 umulh $6, $1, $17
792 addq $20, $10, $20
793 cmpult $20, $10, $18
794 addq $18, $17, $17
795 addq $19, $17, $19
796 cmpult $19, $17, $10
797 addq $9, $10, $9
798 stq $20, 24($16)
799 bis $31, $31, $20
800 mulq $0, $22, $18
801 umulh $0, $22, $17
802 addq $19, $18, $19
803 cmpult $19, $18, $10
804 addq $10, $17, $17
805 addq $9, $17, $9
806 cmpult $9, $17, $18
807 addq $20, $18, $20
808 mulq $2, $7, $10
809 umulh $2, $7, $17
810 addq $19, $10, $19
811 cmpult $19, $10, $18
812 addq $18, $17, $17
813 addq $9, $17, $9
814 cmpult $9, $17, $10
815 addq $20, $10, $20
816 mulq $4, $5, $18
817 umulh $4, $5, $17
818 addq $19, $18, $19
819 cmpult $19, $18, $10
820 addq $10, $17, $17
821 addq $9, $17, $9
822 cmpult $9, $17, $18
823 addq $20, $18, $20
824 mulq $6, $3, $10
825 umulh $6, $3, $17
826 addq $19, $10, $19
827 cmpult $19, $10, $18
828 addq $18, $17, $17
829 addq $9, $17, $9
830 cmpult $9, $17, $10
831 addq $20, $10, $20
832 mulq $8, $1, $18
833 umulh $8, $1, $17
834 addq $19, $18, $19
835 cmpult $19, $18, $10
836 addq $10, $17, $17
837 addq $9, $17, $9
838 cmpult $9, $17, $18
839 addq $20, $18, $20
840 stq $19, 32($16)
841 bis $31, $31, $19
842 mulq $0, $24, $10
843 umulh $0, $24, $17
844 addq $9, $10, $9
845 cmpult $9, $10, $18
846 addq $18, $17, $17
847 addq $20, $17, $20
848 cmpult $20, $17, $10
849 addq $19, $10, $19
850 mulq $2, $22, $18
851 umulh $2, $22, $17
852 addq $9, $18, $9
853 cmpult $9, $18, $10
854 addq $10, $17, $17
855 addq $20, $17, $20
856 cmpult $20, $17, $18
857 addq $19, $18, $19
858 mulq $4, $7, $10
859 umulh $4, $7, $17
860 addq $9, $10, $9
861 cmpult $9, $10, $18
862 addq $18, $17, $17
863 addq $20, $17, $20
864 cmpult $20, $17, $10
865 addq $19, $10, $19
866 mulq $6, $5, $18
867 umulh $6, $5, $17
868 addq $9, $18, $9
869 cmpult $9, $18, $10
870 addq $10, $17, $17
871 addq $20, $17, $20
872 cmpult $20, $17, $18
873 addq $19, $18, $19
874 mulq $8, $3, $10
875 umulh $8, $3, $17
876 addq $9, $10, $9
877 cmpult $9, $10, $18
878 addq $18, $17, $17
879 addq $20, $17, $20
880 cmpult $20, $17, $10
881 addq $19, $10, $19
882 mulq $23, $1, $18
883 umulh $23, $1, $17
884 addq $9, $18, $9
885 cmpult $9, $18, $10
886 addq $10, $17, $17
887 addq $20, $17, $20
888 cmpult $20, $17, $18
889 addq $19, $18, $19
890 stq $9, 40($16)
891 bis $31, $31, $9
892 mulq $0, $27, $10
893 umulh $0, $27, $17
894 addq $20, $10, $20
895 cmpult $20, $10, $18
896 addq $18, $17, $17
897 addq $19, $17, $19
898 cmpult $19, $17, $10
899 addq $9, $10, $9
900 mulq $2, $24, $18
901 umulh $2, $24, $17
902 addq $20, $18, $20
903 cmpult $20, $18, $10
904 addq $10, $17, $17
905 addq $19, $17, $19
906 cmpult $19, $17, $18
907 addq $9, $18, $9
908 mulq $4, $22, $10
909 umulh $4, $22, $17
910 addq $20, $10, $20
911 cmpult $20, $10, $18
912 addq $18, $17, $17
913 addq $19, $17, $19
914 cmpult $19, $17, $10
915 addq $9, $10, $9
916 mulq $6, $7, $18
917 umulh $6, $7, $17
918 addq $20, $18, $20
919 cmpult $20, $18, $10
920 addq $10, $17, $17
921 addq $19, $17, $19
922 cmpult $19, $17, $18
923 addq $9, $18, $9
924 mulq $8, $5, $10
925 umulh $8, $5, $17
926 addq $20, $10, $20
927 cmpult $20, $10, $18
928 addq $18, $17, $17
929 addq $19, $17, $19
930 cmpult $19, $17, $10
931 addq $9, $10, $9
932 mulq $23, $3, $18
933 umulh $23, $3, $17
934 addq $20, $18, $20
935 cmpult $20, $18, $10
936 addq $10, $17, $17
937 addq $19, $17, $19
938 cmpult $19, $17, $18
939 addq $9, $18, $9
940 mulq $25, $1, $10
941 umulh $25, $1, $17
942 addq $20, $10, $20
943 cmpult $20, $10, $18
944 addq $18, $17, $17
945 addq $19, $17, $19
946 cmpult $19, $17, $10
947 addq $9, $10, $9
948 stq $20, 48($16)
949 bis $31, $31, $20
950 mulq $0, $21, $18
951 umulh $0, $21, $17
952 addq $19, $18, $19
953 cmpult $19, $18, $10
954 addq $10, $17, $17
955 addq $9, $17, $9
956 cmpult $9, $17, $18
957 addq $20, $18, $20
958 mulq $2, $27, $10
959 umulh $2, $27, $17
960 addq $19, $10, $19
961 cmpult $19, $10, $18
962 addq $18, $17, $17
963 addq $9, $17, $9
964 cmpult $9, $17, $0
965 addq $20, $0, $20
966 mulq $4, $24, $10
967 umulh $4, $24, $18
968 addq $19, $10, $19
969 cmpult $19, $10, $17
970 addq $17, $18, $18
971 addq $9, $18, $9
972 cmpult $9, $18, $0
973 addq $20, $0, $20
974 mulq $6, $22, $10
975 umulh $6, $22, $17
976 addq $19, $10, $19
977 cmpult $19, $10, $18
978 addq $18, $17, $17
979 addq $9, $17, $9
980 cmpult $9, $17, $0
981 addq $20, $0, $20
982 mulq $8, $7, $10
983 umulh $8, $7, $18
984 addq $19, $10, $19
985 cmpult $19, $10, $17
986 addq $17, $18, $18
987 addq $9, $18, $9
988 cmpult $9, $18, $0
989 addq $20, $0, $20
990 mulq $23, $5, $10
991 umulh $23, $5, $17
992 addq $19, $10, $19
993 cmpult $19, $10, $18
994 addq $18, $17, $17
995 addq $9, $17, $9
996 cmpult $9, $17, $0
997 addq $20, $0, $20
998 mulq $25, $3, $10
999 umulh $25, $3, $18
1000 addq $19, $10, $19
1001 cmpult $19, $10, $17
1002 addq $17, $18, $18
1003 addq $9, $18, $9
1004 cmpult $9, $18, $0
1005 addq $20, $0, $20
1006 mulq $28, $1, $10
1007 umulh $28, $1, $17
1008 addq $19, $10, $19
1009 cmpult $19, $10, $18
1010 addq $18, $17, $17
1011 addq $9, $17, $9
1012 cmpult $9, $17, $0
1013 addq $20, $0, $20
1014 stq $19, 56($16)
1015 bis $31, $31, $19
1016 mulq $2, $21, $10
1017 umulh $2, $21, $18
1018 addq $9, $10, $9
1019 cmpult $9, $10, $17
1020 addq $17, $18, $18
1021 addq $20, $18, $20
1022 cmpult $20, $18, $0
1023 addq $19, $0, $19
1024 mulq $4, $27, $1
1025 umulh $4, $27, $10
1026 addq $9, $1, $9
1027 cmpult $9, $1, $17
1028 addq $17, $10, $10
1029 addq $20, $10, $20
1030 cmpult $20, $10, $18
1031 addq $19, $18, $19
1032 mulq $6, $24, $0
1033 umulh $6, $24, $2
1034 addq $9, $0, $9
1035 cmpult $9, $0, $1
1036 addq $1, $2, $2
1037 addq $20, $2, $20
1038 cmpult $20, $2, $17
1039 addq $19, $17, $19
1040 mulq $8, $22, $10
1041 umulh $8, $22, $18
1042 addq $9, $10, $9
1043 cmpult $9, $10, $0
1044 addq $0, $18, $18
1045 addq $20, $18, $20
1046 cmpult $20, $18, $1
1047 addq $19, $1, $19
1048 mulq $23, $7, $2
1049 umulh $23, $7, $17
1050 addq $9, $2, $9
1051 cmpult $9, $2, $10
1052 addq $10, $17, $17
1053 addq $20, $17, $20
1054 cmpult $20, $17, $0
1055 addq $19, $0, $19
1056 mulq $25, $5, $18
1057 umulh $25, $5, $1
1058 addq $9, $18, $9
1059 cmpult $9, $18, $2
1060 addq $2, $1, $1
1061 addq $20, $1, $20
1062 cmpult $20, $1, $10
1063 addq $19, $10, $19
1064 mulq $28, $3, $17
1065 umulh $28, $3, $0
1066 addq $9, $17, $9
1067 cmpult $9, $17, $18
1068 addq $18, $0, $0
1069 addq $20, $0, $20
1070 cmpult $20, $0, $2
1071 addq $19, $2, $19
1072 stq $9, 64($16)
1073 bis $31, $31, $9
1074 mulq $4, $21, $1
1075 umulh $4, $21, $10
1076 addq $20, $1, $20
1077 cmpult $20, $1, $17
1078 addq $17, $10, $10
1079 addq $19, $10, $19
1080 cmpult $19, $10, $18
1081 addq $9, $18, $9
1082 mulq $6, $27, $0
1083 umulh $6, $27, $2
1084 addq $20, $0, $20
1085 cmpult $20, $0, $3
1086 addq $3, $2, $2
1087 addq $19, $2, $19
1088 cmpult $19, $2, $1
1089 addq $9, $1, $9
1090 mulq $8, $24, $17
1091 umulh $8, $24, $10
1092 addq $20, $17, $20
1093 cmpult $20, $17, $18
1094 addq $18, $10, $10
1095 addq $19, $10, $19
1096 cmpult $19, $10, $4
1097 addq $9, $4, $9
1098 mulq $23, $22, $0
1099 umulh $23, $22, $3
1100 addq $20, $0, $20
1101 cmpult $20, $0, $2
1102 addq $2, $3, $3
1103 addq $19, $3, $19
1104 cmpult $19, $3, $1
1105 addq $9, $1, $9
1106 mulq $25, $7, $17
1107 umulh $25, $7, $18
1108 addq $20, $17, $20
1109 cmpult $20, $17, $10
1110 addq $10, $18, $18
1111 addq $19, $18, $19
1112 cmpult $19, $18, $4
1113 addq $9, $4, $9
1114 mulq $28, $5, $0
1115 umulh $28, $5, $2
1116 addq $20, $0, $20
1117 cmpult $20, $0, $3
1118 addq $3, $2, $2
1119 addq $19, $2, $19
1120 cmpult $19, $2, $1
1121 addq $9, $1, $9
1122 stq $20, 72($16)
1123 bis $31, $31, $20
1124 mulq $6, $21, $17
1125 umulh $6, $21, $10
1126 addq $19, $17, $19
1127 cmpult $19, $17, $18
1128 addq $18, $10, $10
1129 addq $9, $10, $9
1130 cmpult $9, $10, $4
1131 addq $20, $4, $20
1132 mulq $8, $27, $0
1133 umulh $8, $27, $3
1134 addq $19, $0, $19
1135 cmpult $19, $0, $2
1136 addq $2, $3, $3
1137 addq $9, $3, $9
1138 cmpult $9, $3, $1
1139 addq $20, $1, $20
1140 mulq $23, $24, $5
1141 umulh $23, $24, $17
1142 addq $19, $5, $19
1143 cmpult $19, $5, $18
1144 addq $18, $17, $17
1145 addq $9, $17, $9
1146 cmpult $9, $17, $10
1147 addq $20, $10, $20
1148 mulq $25, $22, $4
1149 umulh $25, $22, $6
1150 addq $19, $4, $19
1151 cmpult $19, $4, $0
1152 addq $0, $6, $6
1153 addq $9, $6, $9
1154 cmpult $9, $6, $2
1155 addq $20, $2, $20
1156 mulq $28, $7, $3
1157 umulh $28, $7, $1
1158 addq $19, $3, $19
1159 cmpult $19, $3, $5
1160 addq $5, $1, $1
1161 addq $9, $1, $9
1162 cmpult $9, $1, $18
1163 addq $20, $18, $20
1164 stq $19, 80($16)
1165 bis $31, $31, $19
1166 mulq $8, $21, $17
1167 umulh $8, $21, $10
1168 addq $9, $17, $9
1169 cmpult $9, $17, $4
1170 addq $4, $10, $10
1171 addq $20, $10, $20
1172 cmpult $20, $10, $0
1173 addq $19, $0, $19
1174 mulq $23, $27, $6
1175 umulh $23, $27, $2
1176 addq $9, $6, $9
1177 cmpult $9, $6, $3
1178 addq $3, $2, $2
1179 addq $20, $2, $20
1180 cmpult $20, $2, $5
1181 addq $19, $5, $19
1182 mulq $25, $24, $1
1183 umulh $25, $24, $18
1184 addq $9, $1, $9
1185 cmpult $9, $1, $7
1186 addq $7, $18, $18
1187 addq $20, $18, $20
1188 cmpult $20, $18, $17
1189 addq $19, $17, $19
1190 mulq $28, $22, $4
1191 umulh $28, $22, $10
1192 addq $9, $4, $9
1193 cmpult $9, $4, $0
1194 addq $0, $10, $10
1195 addq $20, $10, $20
1196 cmpult $20, $10, $8
1197 addq $19, $8, $19
1198 stq $9, 88($16)
1199 bis $31, $31, $9
1200 mulq $23, $21, $6
1201 umulh $23, $21, $3
1202 addq $20, $6, $20
1203 cmpult $20, $6, $2
1204 addq $2, $3, $3
1205 addq $19, $3, $19
1206 cmpult $19, $3, $5
1207 addq $9, $5, $9
1208 mulq $25, $27, $1
1209 umulh $25, $27, $7
1210 addq $20, $1, $20
1211 cmpult $20, $1, $18
1212 addq $18, $7, $7
1213 addq $19, $7, $19
1214 cmpult $19, $7, $17
1215 addq $9, $17, $9
1216 mulq $28, $24, $4
1217 umulh $28, $24, $0
1218 addq $20, $4, $20
1219 cmpult $20, $4, $10
1220 addq $10, $0, $0
1221 addq $19, $0, $19
1222 cmpult $19, $0, $8
1223 addq $9, $8, $9
1224 stq $20, 96($16)
1225 bis $31, $31, $20
1226 mulq $25, $21, $22
1227 umulh $25, $21, $6
1228 addq $19, $22, $19
1229 cmpult $19, $22, $2
1230 addq $2, $6, $6
1231 addq $9, $6, $9
1232 cmpult $9, $6, $3
1233 addq $20, $3, $20
1234 mulq $28, $27, $5
1235 umulh $28, $27, $23
1236 addq $19, $5, $19
1237 cmpult $19, $5, $1
1238 addq $1, $23, $23
1239 addq $9, $23, $9
1240 cmpult $9, $23, $18
1241 addq $20, $18, $20
1242 stq $19, 104($16)
1243 bis $31, $31, $19
1244 mulq $28, $21, $7
1245 umulh $28, $21, $17
1246 addq $9, $7, $9
1247 cmpult $9, $7, $4
1248 addq $4, $17, $17
1249 addq $20, $17, $20
1250 cmpult $20, $17, $10
1251 addq $19, $10, $19
1252 stq $9, 112($16)
1253 stq $20, 120($16)
1254 ldq $9, 0($30)
1255 ldq $10, 8($30)
1256 addq $30, 16, $30
1257 ret $31,($26),1
1258 .end bn_mul_comba8
1259 .text
1260 .align 3
1261 .globl bn_sqr_comba4
1262 .ent bn_sqr_comba4
1263bn_sqr_comba4:
1264bn_sqr_comba4..ng:
1265 .frame $30,0,$26,0
1266 .prologue 0
1267
1268 ldq $0, 0($17)
1269 ldq $1, 8($17)
1270 ldq $2, 16($17)
1271 ldq $3, 24($17)
1272 bis $31, $31, $6
1273 mulq $0, $0, $4
1274 umulh $0, $0, $5
1275 stq $4, 0($16)
1276 bis $31, $31, $4
1277 mulq $0, $1, $7
1278 umulh $0, $1, $8
1279 cmplt $7, $31, $22
1280 cmplt $8, $31, $23
1281 addq $7, $7, $7
1282 addq $8, $8, $8
1283 addq $8, $22, $8
1284 addq $4, $23, $4
1285 addq $5, $7, $5
1286 addq $6, $8, $6
1287 cmpult $5, $7, $24
1288 cmpult $6, $8, $25
1289 addq $6, $24, $6
1290 addq $4, $25, $4
1291 stq $5, 8($16)
1292 bis $31, $31, $5
1293 mulq $1, $1, $27
1294 umulh $1, $1, $28
1295 addq $6, $27, $6
1296 addq $4, $28, $4
1297 cmpult $6, $27, $21
1298 cmpult $4, $28, $20
1299 addq $4, $21, $4
1300 addq $5, $20, $5
1301 mulq $2, $0, $19
1302 umulh $2, $0, $18
1303 cmplt $19, $31, $17
1304 cmplt $18, $31, $22
1305 addq $19, $19, $19
1306 addq $18, $18, $18
1307 addq $18, $17, $18
1308 addq $5, $22, $5
1309 addq $6, $19, $6
1310 addq $4, $18, $4
1311 cmpult $6, $19, $23
1312 cmpult $4, $18, $7
1313 addq $4, $23, $4
1314 addq $5, $7, $5
1315 stq $6, 16($16)
1316 bis $31, $31, $6
1317 mulq $3, $0, $8
1318 umulh $3, $0, $24
1319 cmplt $8, $31, $25
1320 cmplt $24, $31, $27
1321 addq $8, $8, $8
1322 addq $24, $24, $24
1323 addq $24, $25, $24
1324 addq $6, $27, $6
1325 addq $4, $8, $4
1326 addq $5, $24, $5
1327 cmpult $4, $8, $28
1328 cmpult $5, $24, $21
1329 addq $5, $28, $5
1330 addq $6, $21, $6
1331 mulq $2, $1, $20
1332 umulh $2, $1, $17
1333 cmplt $20, $31, $22
1334 cmplt $17, $31, $19
1335 addq $20, $20, $20
1336 addq $17, $17, $17
1337 addq $17, $22, $17
1338 addq $6, $19, $6
1339 addq $4, $20, $4
1340 addq $5, $17, $5
1341 cmpult $4, $20, $18
1342 cmpult $5, $17, $23
1343 addq $5, $18, $5
1344 addq $6, $23, $6
1345 stq $4, 24($16)
1346 bis $31, $31, $4
1347 mulq $2, $2, $7
1348 umulh $2, $2, $25
1349 addq $5, $7, $5
1350 addq $6, $25, $6
1351 cmpult $5, $7, $27
1352 cmpult $6, $25, $8
1353 addq $6, $27, $6
1354 addq $4, $8, $4
1355 mulq $3, $1, $24
1356 umulh $3, $1, $28
1357 cmplt $24, $31, $21
1358 cmplt $28, $31, $22
1359 addq $24, $24, $24
1360 addq $28, $28, $28
1361 addq $28, $21, $28
1362 addq $4, $22, $4
1363 addq $5, $24, $5
1364 addq $6, $28, $6
1365 cmpult $5, $24, $19
1366 cmpult $6, $28, $20
1367 addq $6, $19, $6
1368 addq $4, $20, $4
1369 stq $5, 32($16)
1370 bis $31, $31, $5
1371 mulq $3, $2, $17
1372 umulh $3, $2, $18
1373 cmplt $17, $31, $23
1374 cmplt $18, $31, $7
1375 addq $17, $17, $17
1376 addq $18, $18, $18
1377 addq $18, $23, $18
1378 addq $5, $7, $5
1379 addq $6, $17, $6
1380 addq $4, $18, $4
1381 cmpult $6, $17, $25
1382 cmpult $4, $18, $27
1383 addq $4, $25, $4
1384 addq $5, $27, $5
1385 stq $6, 40($16)
1386 bis $31, $31, $6
1387 mulq $3, $3, $8
1388 umulh $3, $3, $21
1389 addq $4, $8, $4
1390 addq $5, $21, $5
1391 cmpult $4, $8, $22
1392 cmpult $5, $21, $24
1393 addq $5, $22, $5
1394 addq $6, $24, $6
1395 stq $4, 48($16)
1396 stq $5, 56($16)
1397 ret $31,($26),1
1398 .end bn_sqr_comba4
1399 .text
1400 .align 3
1401 .globl bn_sqr_comba8
1402 .ent bn_sqr_comba8
1403bn_sqr_comba8:
1404bn_sqr_comba8..ng:
1405 .frame $30,0,$26,0
1406 .prologue 0
344 1407
1408 ldq $0, 0($17)
1409 ldq $1, 8($17)
1410 ldq $2, 16($17)
1411 ldq $3, 24($17)
1412 ldq $4, 32($17)
1413 ldq $5, 40($17)
1414 ldq $6, 48($17)
1415 ldq $7, 56($17)
1416 bis $31, $31, $23
1417 mulq $0, $0, $8
1418 umulh $0, $0, $22
1419 stq $8, 0($16)
1420 bis $31, $31, $8
1421 mulq $1, $0, $24
1422 umulh $1, $0, $25
1423 cmplt $24, $31, $27
1424 cmplt $25, $31, $28
1425 addq $24, $24, $24
1426 addq $25, $25, $25
1427 addq $25, $27, $25
1428 addq $8, $28, $8
1429 addq $22, $24, $22
1430 addq $23, $25, $23
1431 cmpult $22, $24, $21
1432 cmpult $23, $25, $20
1433 addq $23, $21, $23
1434 addq $8, $20, $8
1435 stq $22, 8($16)
1436 bis $31, $31, $22
1437 mulq $1, $1, $19
1438 umulh $1, $1, $18
1439 addq $23, $19, $23
1440 addq $8, $18, $8
1441 cmpult $23, $19, $17
1442 cmpult $8, $18, $27
1443 addq $8, $17, $8
1444 addq $22, $27, $22
1445 mulq $2, $0, $28
1446 umulh $2, $0, $24
1447 cmplt $28, $31, $25
1448 cmplt $24, $31, $21
1449 addq $28, $28, $28
1450 addq $24, $24, $24
1451 addq $24, $25, $24
1452 addq $22, $21, $22
1453 addq $23, $28, $23
1454 addq $8, $24, $8
1455 cmpult $23, $28, $20
1456 cmpult $8, $24, $19
1457 addq $8, $20, $8
1458 addq $22, $19, $22
1459 stq $23, 16($16)
1460 bis $31, $31, $23
1461 mulq $2, $1, $18
1462 umulh $2, $1, $17
1463 cmplt $18, $31, $27
1464 cmplt $17, $31, $25
1465 addq $18, $18, $18
1466 addq $17, $17, $17
1467 addq $17, $27, $17
1468 addq $23, $25, $23
1469 addq $8, $18, $8
1470 addq $22, $17, $22
1471 cmpult $8, $18, $21
1472 cmpult $22, $17, $28
1473 addq $22, $21, $22
1474 addq $23, $28, $23
1475 mulq $3, $0, $24
1476 umulh $3, $0, $20
1477 cmplt $24, $31, $19
1478 cmplt $20, $31, $27
1479 addq $24, $24, $24
1480 addq $20, $20, $20
1481 addq $20, $19, $20
1482 addq $23, $27, $23
1483 addq $8, $24, $8
1484 addq $22, $20, $22
1485 cmpult $8, $24, $25
1486 cmpult $22, $20, $18
1487 addq $22, $25, $22
1488 addq $23, $18, $23
1489 stq $8, 24($16)
1490 bis $31, $31, $8
1491 mulq $2, $2, $17
1492 umulh $2, $2, $21
1493 addq $22, $17, $22
1494 addq $23, $21, $23
1495 cmpult $22, $17, $28
1496 cmpult $23, $21, $19
1497 addq $23, $28, $23
1498 addq $8, $19, $8
1499 mulq $3, $1, $27
1500 umulh $3, $1, $24
1501 cmplt $27, $31, $20
1502 cmplt $24, $31, $25
1503 addq $27, $27, $27
1504 addq $24, $24, $24
1505 addq $24, $20, $24
1506 addq $8, $25, $8
1507 addq $22, $27, $22
1508 addq $23, $24, $23
1509 cmpult $22, $27, $18
1510 cmpult $23, $24, $17
1511 addq $23, $18, $23
1512 addq $8, $17, $8
1513 mulq $4, $0, $21
1514 umulh $4, $0, $28
1515 cmplt $21, $31, $19
1516 cmplt $28, $31, $20
1517 addq $21, $21, $21
1518 addq $28, $28, $28
1519 addq $28, $19, $28
1520 addq $8, $20, $8
1521 addq $22, $21, $22
1522 addq $23, $28, $23
1523 cmpult $22, $21, $25
1524 cmpult $23, $28, $27
1525 addq $23, $25, $23
1526 addq $8, $27, $8
1527 stq $22, 32($16)
1528 bis $31, $31, $22
1529 mulq $3, $2, $24
1530 umulh $3, $2, $18
1531 cmplt $24, $31, $17
1532 cmplt $18, $31, $19
1533 addq $24, $24, $24
1534 addq $18, $18, $18
1535 addq $18, $17, $18
1536 addq $22, $19, $22
1537 addq $23, $24, $23
1538 addq $8, $18, $8
1539 cmpult $23, $24, $20
1540 cmpult $8, $18, $21
1541 addq $8, $20, $8
1542 addq $22, $21, $22
1543 mulq $4, $1, $28
1544 umulh $4, $1, $25
1545 cmplt $28, $31, $27
1546 cmplt $25, $31, $17
1547 addq $28, $28, $28
1548 addq $25, $25, $25
1549 addq $25, $27, $25
1550 addq $22, $17, $22
1551 addq $23, $28, $23
1552 addq $8, $25, $8
1553 cmpult $23, $28, $19
1554 cmpult $8, $25, $24
1555 addq $8, $19, $8
1556 addq $22, $24, $22
1557 mulq $5, $0, $18
1558 umulh $5, $0, $20
1559 cmplt $18, $31, $21
1560 cmplt $20, $31, $27
1561 addq $18, $18, $18
1562 addq $20, $20, $20
1563 addq $20, $21, $20
1564 addq $22, $27, $22
1565 addq $23, $18, $23
1566 addq $8, $20, $8
1567 cmpult $23, $18, $17
1568 cmpult $8, $20, $28
1569 addq $8, $17, $8
1570 addq $22, $28, $22
1571 stq $23, 40($16)
1572 bis $31, $31, $23
1573 mulq $3, $3, $25
1574 umulh $3, $3, $19
1575 addq $8, $25, $8
1576 addq $22, $19, $22
1577 cmpult $8, $25, $24
1578 cmpult $22, $19, $21
1579 addq $22, $24, $22
1580 addq $23, $21, $23
1581 mulq $4, $2, $27
1582 umulh $4, $2, $18
1583 cmplt $27, $31, $20
1584 cmplt $18, $31, $17
1585 addq $27, $27, $27
1586 addq $18, $18, $18
1587 addq $18, $20, $18
1588 addq $23, $17, $23
1589 addq $8, $27, $8
1590 addq $22, $18, $22
1591 cmpult $8, $27, $28
1592 cmpult $22, $18, $25
1593 addq $22, $28, $22
1594 addq $23, $25, $23
1595 mulq $5, $1, $19
1596 umulh $5, $1, $24
1597 cmplt $19, $31, $21
1598 cmplt $24, $31, $20
1599 addq $19, $19, $19
1600 addq $24, $24, $24
1601 addq $24, $21, $24
1602 addq $23, $20, $23
1603 addq $8, $19, $8
1604 addq $22, $24, $22
1605 cmpult $8, $19, $17
1606 cmpult $22, $24, $27
1607 addq $22, $17, $22
1608 addq $23, $27, $23
1609 mulq $6, $0, $18
1610 umulh $6, $0, $28
1611 cmplt $18, $31, $25
1612 cmplt $28, $31, $21
1613 addq $18, $18, $18
1614 addq $28, $28, $28
1615 addq $28, $25, $28
1616 addq $23, $21, $23
1617 addq $8, $18, $8
1618 addq $22, $28, $22
1619 cmpult $8, $18, $20
1620 cmpult $22, $28, $19
1621 addq $22, $20, $22
1622 addq $23, $19, $23
1623 stq $8, 48($16)
1624 bis $31, $31, $8
1625 mulq $4, $3, $24
1626 umulh $4, $3, $17
1627 cmplt $24, $31, $27
1628 cmplt $17, $31, $25
1629 addq $24, $24, $24
1630 addq $17, $17, $17
1631 addq $17, $27, $17
1632 addq $8, $25, $8
1633 addq $22, $24, $22
1634 addq $23, $17, $23
1635 cmpult $22, $24, $21
1636 cmpult $23, $17, $18
1637 addq $23, $21, $23
1638 addq $8, $18, $8
1639 mulq $5, $2, $28
1640 umulh $5, $2, $20
1641 cmplt $28, $31, $19
1642 cmplt $20, $31, $27
1643 addq $28, $28, $28
1644 addq $20, $20, $20
1645 addq $20, $19, $20
1646 addq $8, $27, $8
1647 addq $22, $28, $22
1648 addq $23, $20, $23
1649 cmpult $22, $28, $25
1650 cmpult $23, $20, $24
1651 addq $23, $25, $23
1652 addq $8, $24, $8
1653 mulq $6, $1, $17
1654 umulh $6, $1, $21
1655 cmplt $17, $31, $18
1656 cmplt $21, $31, $19
1657 addq $17, $17, $17
1658 addq $21, $21, $21
1659 addq $21, $18, $21
1660 addq $8, $19, $8
1661 addq $22, $17, $22
1662 addq $23, $21, $23
1663 cmpult $22, $17, $27
1664 cmpult $23, $21, $28
1665 addq $23, $27, $23
1666 addq $8, $28, $8
1667 mulq $7, $0, $20
1668 umulh $7, $0, $25
1669 cmplt $20, $31, $24
1670 cmplt $25, $31, $18
1671 addq $20, $20, $20
1672 addq $25, $25, $25
1673 addq $25, $24, $25
1674 addq $8, $18, $8
1675 addq $22, $20, $22
1676 addq $23, $25, $23
1677 cmpult $22, $20, $19
1678 cmpult $23, $25, $17
1679 addq $23, $19, $23
1680 addq $8, $17, $8
1681 stq $22, 56($16)
1682 bis $31, $31, $22
1683 mulq $4, $4, $21
1684 umulh $4, $4, $27
1685 addq $23, $21, $23
1686 addq $8, $27, $8
1687 cmpult $23, $21, $28
1688 cmpult $8, $27, $24
1689 addq $8, $28, $8
1690 addq $22, $24, $22
1691 mulq $5, $3, $18
1692 umulh $5, $3, $20
1693 cmplt $18, $31, $25
1694 cmplt $20, $31, $19
1695 addq $18, $18, $18
1696 addq $20, $20, $20
1697 addq $20, $25, $20
1698 addq $22, $19, $22
1699 addq $23, $18, $23
1700 addq $8, $20, $8
1701 cmpult $23, $18, $17
1702 cmpult $8, $20, $21
1703 addq $8, $17, $8
1704 addq $22, $21, $22
1705 mulq $6, $2, $27
1706 umulh $6, $2, $28
1707 cmplt $27, $31, $24
1708 cmplt $28, $31, $25
1709 addq $27, $27, $27
1710 addq $28, $28, $28
1711 addq $28, $24, $28
1712 addq $22, $25, $22
1713 addq $23, $27, $23
1714 addq $8, $28, $8
1715 cmpult $23, $27, $19
1716 cmpult $8, $28, $18
1717 addq $8, $19, $8
1718 addq $22, $18, $22
1719 mulq $7, $1, $20
1720 umulh $7, $1, $17
1721 cmplt $20, $31, $21
1722 cmplt $17, $31, $24
1723 addq $20, $20, $20
1724 addq $17, $17, $17
1725 addq $17, $21, $17
1726 addq $22, $24, $22
1727 addq $23, $20, $23
1728 addq $8, $17, $8
1729 cmpult $23, $20, $25
1730 cmpult $8, $17, $27
1731 addq $8, $25, $8
1732 addq $22, $27, $22
1733 stq $23, 64($16)
1734 bis $31, $31, $23
1735 mulq $5, $4, $28
1736 umulh $5, $4, $19
1737 cmplt $28, $31, $18
1738 cmplt $19, $31, $21
1739 addq $28, $28, $28
1740 addq $19, $19, $19
1741 addq $19, $18, $19
1742 addq $23, $21, $23
1743 addq $8, $28, $8
1744 addq $22, $19, $22
1745 cmpult $8, $28, $24
1746 cmpult $22, $19, $20
1747 addq $22, $24, $22
1748 addq $23, $20, $23
1749 mulq $6, $3, $17
1750 umulh $6, $3, $25
1751 cmplt $17, $31, $27
1752 cmplt $25, $31, $18
1753 addq $17, $17, $17
1754 addq $25, $25, $25
1755 addq $25, $27, $25
1756 addq $23, $18, $23
1757 addq $8, $17, $8
1758 addq $22, $25, $22
1759 cmpult $8, $17, $21
1760 cmpult $22, $25, $28
1761 addq $22, $21, $22
1762 addq $23, $28, $23
1763 mulq $7, $2, $19
1764 umulh $7, $2, $24
1765 cmplt $19, $31, $20
1766 cmplt $24, $31, $27
1767 addq $19, $19, $19
1768 addq $24, $24, $24
1769 addq $24, $20, $24
1770 addq $23, $27, $23
1771 addq $8, $19, $8
1772 addq $22, $24, $22
1773 cmpult $8, $19, $18
1774 cmpult $22, $24, $17
1775 addq $22, $18, $22
1776 addq $23, $17, $23
1777 stq $8, 72($16)
1778 bis $31, $31, $8
1779 mulq $5, $5, $25
1780 umulh $5, $5, $21
1781 addq $22, $25, $22
1782 addq $23, $21, $23
1783 cmpult $22, $25, $28
1784 cmpult $23, $21, $20
1785 addq $23, $28, $23
1786 addq $8, $20, $8
1787 mulq $6, $4, $27
1788 umulh $6, $4, $19
1789 cmplt $27, $31, $24
1790 cmplt $19, $31, $18
1791 addq $27, $27, $27
1792 addq $19, $19, $19
1793 addq $19, $24, $19
1794 addq $8, $18, $8
1795 addq $22, $27, $22
1796 addq $23, $19, $23
1797 cmpult $22, $27, $17
1798 cmpult $23, $19, $25
1799 addq $23, $17, $23
1800 addq $8, $25, $8
1801 mulq $7, $3, $21
1802 umulh $7, $3, $28
1803 cmplt $21, $31, $20
1804 cmplt $28, $31, $24
1805 addq $21, $21, $21
1806 addq $28, $28, $28
1807 addq $28, $20, $28
1808 addq $8, $24, $8
1809 addq $22, $21, $22
1810 addq $23, $28, $23
1811 cmpult $22, $21, $18
1812 cmpult $23, $28, $27
1813 addq $23, $18, $23
1814 addq $8, $27, $8
1815 stq $22, 80($16)
1816 bis $31, $31, $22
1817 mulq $6, $5, $19
1818 umulh $6, $5, $17
1819 cmplt $19, $31, $25
1820 cmplt $17, $31, $20
1821 addq $19, $19, $19
1822 addq $17, $17, $17
1823 addq $17, $25, $17
1824 addq $22, $20, $22
1825 addq $23, $19, $23
1826 addq $8, $17, $8
1827 cmpult $23, $19, $24
1828 cmpult $8, $17, $21
1829 addq $8, $24, $8
1830 addq $22, $21, $22
1831 mulq $7, $4, $28
1832 umulh $7, $4, $18
1833 cmplt $28, $31, $27
1834 cmplt $18, $31, $25
1835 addq $28, $28, $28
1836 addq $18, $18, $18
1837 addq $18, $27, $18
1838 addq $22, $25, $22
1839 addq $23, $28, $23
1840 addq $8, $18, $8
1841 cmpult $23, $28, $20
1842 cmpult $8, $18, $19
1843 addq $8, $20, $8
1844 addq $22, $19, $22
1845 stq $23, 88($16)
1846 bis $31, $31, $23
1847 mulq $6, $6, $17
1848 umulh $6, $6, $24
1849 addq $8, $17, $8
1850 addq $22, $24, $22
1851 cmpult $8, $17, $21
1852 cmpult $22, $24, $27
1853 addq $22, $21, $22
1854 addq $23, $27, $23
1855 mulq $7, $5, $25
1856 umulh $7, $5, $28
1857 cmplt $25, $31, $18
1858 cmplt $28, $31, $20
1859 addq $25, $25, $25
1860 addq $28, $28, $28
1861 addq $28, $18, $28
1862 addq $23, $20, $23
1863 addq $8, $25, $8
1864 addq $22, $28, $22
1865 cmpult $8, $25, $19
1866 cmpult $22, $28, $17
1867 addq $22, $19, $22
1868 addq $23, $17, $23
1869 stq $8, 96($16)
1870 bis $31, $31, $8
1871 mulq $7, $6, $24
1872 umulh $7, $6, $21
1873 cmplt $24, $31, $27
1874 cmplt $21, $31, $18
1875 addq $24, $24, $24
1876 addq $21, $21, $21
1877 addq $21, $27, $21
1878 addq $8, $18, $8
1879 addq $22, $24, $22
1880 addq $23, $21, $23
1881 cmpult $22, $24, $20
1882 cmpult $23, $21, $25
1883 addq $23, $20, $23
1884 addq $8, $25, $8
1885 stq $22, 104($16)
1886 bis $31, $31, $22
1887 mulq $7, $7, $28
1888 umulh $7, $7, $19
1889 addq $23, $28, $23
1890 addq $8, $19, $8
1891 cmpult $23, $28, $17
1892 cmpult $8, $19, $27
1893 addq $8, $17, $8
1894 addq $22, $27, $22
1895 stq $23, 112($16)
1896 stq $8, 120($16)
1897 ret $31,($26),1
1898 .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 @@
1
2 # DEC Alpha assember
3 # The bn_div64 is actually gcc output but the other parts are hand done.
4 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
5 # bn_div64.
6 # I've gone back and re-done most of routines.
7 # The key thing to remeber for the 164 CPU is that while a
8 # multiply operation takes 8 cycles, another one can only be issued
9 # after 4 cycles have elapsed. I've done modification to help
10 # improve this. Also, normally, a ld instruction will not be available
11 # for about 3 cycles.
12 .file 1 "bn_asm.c"
13 .set noat
14gcc2_compiled.:
15__gnu_compiled_c:
16 .text
17 .align 3
18 .globl bn_mul_add_words
19 .ent bn_mul_add_words
20bn_mul_add_words:
21bn_mul_add_words..ng:
22 .frame $30,0,$26,0
23 .prologue 0
24 .align 5
25 subq $18,4,$18
26 bis $31,$31,$0
27 blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code
28 ldq $20,0($17) # 1 1
29 ldq $1,0($16) # 1 1
30 .align 3
31$42:
32 mulq $20,$19,$5 # 1 2 1 ######
33 ldq $21,8($17) # 2 1
34 ldq $2,8($16) # 2 1
35 umulh $20,$19,$20 # 1 2 ######
36 ldq $27,16($17) # 3 1
37 ldq $3,16($16) # 3 1
38 mulq $21,$19,$6 # 2 2 1 ######
39 ldq $28,24($17) # 4 1
40 addq $1,$5,$1 # 1 2 2
41 ldq $4,24($16) # 4 1
42 umulh $21,$19,$21 # 2 2 ######
43 cmpult $1,$5,$22 # 1 2 3 1
44 addq $20,$22,$20 # 1 3 1
45 addq $1,$0,$1 # 1 2 3 1
46 mulq $27,$19,$7 # 3 2 1 ######
47 cmpult $1,$0,$0 # 1 2 3 2
48 addq $2,$6,$2 # 2 2 2
49 addq $20,$0,$0 # 1 3 2
50 cmpult $2,$6,$23 # 2 2 3 1
51 addq $21,$23,$21 # 2 3 1
52 umulh $27,$19,$27 # 3 2 ######
53 addq $2,$0,$2 # 2 2 3 1
54 cmpult $2,$0,$0 # 2 2 3 2
55 subq $18,4,$18
56 mulq $28,$19,$8 # 4 2 1 ######
57 addq $21,$0,$0 # 2 3 2
58 addq $3,$7,$3 # 3 2 2
59 addq $16,32,$16
60 cmpult $3,$7,$24 # 3 2 3 1
61 stq $1,-32($16) # 1 2 4
62 umulh $28,$19,$28 # 4 2 ######
63 addq $27,$24,$27 # 3 3 1
64 addq $3,$0,$3 # 3 2 3 1
65 stq $2,-24($16) # 2 2 4
66 cmpult $3,$0,$0 # 3 2 3 2
67 stq $3,-16($16) # 3 2 4
68 addq $4,$8,$4 # 4 2 2
69 addq $27,$0,$0 # 3 3 2
70 cmpult $4,$8,$25 # 4 2 3 1
71 addq $17,32,$17
72 addq $28,$25,$28 # 4 3 1
73 addq $4,$0,$4 # 4 2 3 1
74 cmpult $4,$0,$0 # 4 2 3 2
75 stq $4,-8($16) # 4 2 4
76 addq $28,$0,$0 # 4 3 2
77 blt $18,$43
78
79 ldq $20,0($17) # 1 1
80 ldq $1,0($16) # 1 1
81
82 br $42
83
84 .align 4
85$45:
86 ldq $20,0($17) # 4 1
87 ldq $1,0($16) # 4 1
88 mulq $20,$19,$5 # 4 2 1
89 subq $18,1,$18
90 addq $16,8,$16
91 addq $17,8,$17
92 umulh $20,$19,$20 # 4 2
93 addq $1,$5,$1 # 4 2 2
94 cmpult $1,$5,$22 # 4 2 3 1
95 addq $20,$22,$20 # 4 3 1
96 addq $1,$0,$1 # 4 2 3 1
97 cmpult $1,$0,$0 # 4 2 3 2
98 addq $20,$0,$0 # 4 3 2
99 stq $1,-8($16) # 4 2 4
100 bgt $18,$45
101 ret $31,($26),1 # else exit
102
103 .align 4
104$43:
105 addq $18,4,$18
106 bgt $18,$45 # goto tail code
107 ret $31,($26),1 # else exit
108
109 .end bn_mul_add_words
110 .align 3
111 .globl bn_mul_words
112 .ent bn_mul_words
113bn_mul_words:
114bn_mul_words..ng:
115 .frame $30,0,$26,0
116 .prologue 0
117 .align 5
118 subq $18,4,$18
119 bis $31,$31,$0
120 blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code
121 ldq $20,0($17) # 1 1
122 .align 3
123$142:
124
125 mulq $20,$19,$5 # 1 2 1 #####
126 ldq $21,8($17) # 2 1
127 ldq $27,16($17) # 3 1
128 umulh $20,$19,$20 # 1 2 #####
129 ldq $28,24($17) # 4 1
130 mulq $21,$19,$6 # 2 2 1 #####
131 addq $5,$0,$5 # 1 2 3 1
132 subq $18,4,$18
133 cmpult $5,$0,$0 # 1 2 3 2
134 umulh $21,$19,$21 # 2 2 #####
135 addq $20,$0,$0 # 1 3 2
136 addq $17,32,$17
137 addq $6,$0,$6 # 2 2 3 1
138 mulq $27,$19,$7 # 3 2 1 #####
139 cmpult $6,$0,$0 # 2 2 3 2
140 addq $21,$0,$0 # 2 3 2
141 addq $16,32,$16
142 umulh $27,$19,$27 # 3 2 #####
143 stq $5,-32($16) # 1 2 4
144 mulq $28,$19,$8 # 4 2 1 #####
145 addq $7,$0,$7 # 3 2 3 1
146 stq $6,-24($16) # 2 2 4
147 cmpult $7,$0,$0 # 3 2 3 2
148 umulh $28,$19,$28 # 4 2 #####
149 addq $27,$0,$0 # 3 3 2
150 stq $7,-16($16) # 3 2 4
151 addq $8,$0,$8 # 4 2 3 1
152 cmpult $8,$0,$0 # 4 2 3 2
153
154 addq $28,$0,$0 # 4 3 2
155
156 stq $8,-8($16) # 4 2 4
157
158 blt $18,$143
159
160 ldq $20,0($17) # 1 1
161
162 br $142
163
164 .align 4
165$145:
166 ldq $20,0($17) # 4 1
167 mulq $20,$19,$5 # 4 2 1
168 subq $18,1,$18
169 umulh $20,$19,$20 # 4 2
170 addq $5,$0,$5 # 4 2 3 1
171 addq $16,8,$16
172 cmpult $5,$0,$0 # 4 2 3 2
173 addq $17,8,$17
174 addq $20,$0,$0 # 4 3 2
175 stq $5,-8($16) # 4 2 4
176
177 bgt $18,$145
178 ret $31,($26),1 # else exit
179
180 .align 4
181$143:
182 addq $18,4,$18
183 bgt $18,$145 # goto tail code
184 ret $31,($26),1 # else exit
185
186 .end bn_mul_words
187 .align 3
188 .globl bn_sqr_words
189 .ent bn_sqr_words
190bn_sqr_words:
191bn_sqr_words..ng:
192 .frame $30,0,$26,0
193 .prologue 0
194
195 subq $18,4,$18
196 blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code
197 ldq $20,0($17) # 1 1
198 .align 3
199$542:
200 mulq $20,$20,$5 ######
201 ldq $21,8($17) # 1 1
202 subq $18,4
203 umulh $20,$20,$1 ######
204 ldq $27,16($17) # 1 1
205 mulq $21,$21,$6 ######
206 ldq $28,24($17) # 1 1
207 stq $5,0($16) # r[0]
208 umulh $21,$21,$2 ######
209 stq $1,8($16) # r[1]
210 mulq $27,$27,$7 ######
211 stq $6,16($16) # r[0]
212 umulh $27,$27,$3 ######
213 stq $2,24($16) # r[1]
214 mulq $28,$28,$8 ######
215 stq $7,32($16) # r[0]
216 umulh $28,$28,$4 ######
217 stq $3,40($16) # r[1]
218
219 addq $16,64,$16
220 addq $17,32,$17
221 stq $8,-16($16) # r[0]
222 stq $4,-8($16) # r[1]
223
224 blt $18,$543
225 ldq $20,0($17) # 1 1
226 br $542
227
228$442:
229 ldq $20,0($17) # a[0]
230 mulq $20,$20,$5 # a[0]*w low part r2
231 addq $16,16,$16
232 addq $17,8,$17
233 subq $18,1,$18
234 umulh $20,$20,$1 # a[0]*w high part r3
235 stq $5,-16($16) # r[0]
236 stq $1,-8($16) # r[1]
237
238 bgt $18,$442
239 ret $31,($26),1 # else exit
240
241 .align 4
242$543:
243 addq $18,4,$18
244 bgt $18,$442 # goto tail code
245 ret $31,($26),1 # else exit
246 .end bn_sqr_words
247
248 .align 3
249 .globl bn_add_words
250 .ent bn_add_words
251bn_add_words:
252bn_add_words..ng:
253 .frame $30,0,$26,0
254 .prologue 0
255
256 subq $19,4,$19
257 bis $31,$31,$0 # carry = 0
258 blt $19,$900
259 ldq $5,0($17) # a[0]
260 ldq $1,0($18) # b[1]
261 .align 3
262$901:
263 addq $1,$5,$1 # r=a+b;
264 ldq $6,8($17) # a[1]
265 cmpult $1,$5,$22 # did we overflow?
266 ldq $2,8($18) # b[1]
267 addq $1,$0,$1 # c+= overflow
268 ldq $7,16($17) # a[2]
269 cmpult $1,$0,$0 # overflow?
270 ldq $3,16($18) # b[2]
271 addq $0,$22,$0
272 ldq $8,24($17) # a[3]
273 addq $2,$6,$2 # r=a+b;
274 ldq $4,24($18) # b[3]
275 cmpult $2,$6,$23 # did we overflow?
276 addq $3,$7,$3 # r=a+b;
277 addq $2,$0,$2 # c+= overflow
278 cmpult $3,$7,$24 # did we overflow?
279 cmpult $2,$0,$0 # overflow?
280 addq $4,$8,$4 # r=a+b;
281 addq $0,$23,$0
282 cmpult $4,$8,$25 # did we overflow?
283 addq $3,$0,$3 # c+= overflow
284 stq $1,0($16) # r[0]=c
285 cmpult $3,$0,$0 # overflow?
286 stq $2,8($16) # r[1]=c
287 addq $0,$24,$0
288 stq $3,16($16) # r[2]=c
289 addq $4,$0,$4 # c+= overflow
290 subq $19,4,$19 # loop--
291 cmpult $4,$0,$0 # overflow?
292 addq $17,32,$17 # a++
293 addq $0,$25,$0
294 stq $4,24($16) # r[3]=c
295 addq $18,32,$18 # b++
296 addq $16,32,$16 # r++
297
298 blt $19,$900
299 ldq $5,0($17) # a[0]
300 ldq $1,0($18) # b[1]
301 br $901
302 .align 4
303$945:
304 ldq $5,0($17) # a[0]
305 ldq $1,0($18) # b[1]
306 addq $1,$5,$1 # r=a+b;
307 subq $19,1,$19 # loop--
308 addq $1,$0,$1 # c+= overflow
309 addq $17,8,$17 # a++
310 cmpult $1,$5,$22 # did we overflow?
311 cmpult $1,$0,$0 # overflow?
312 addq $18,8,$18 # b++
313 stq $1,0($16) # r[0]=c
314 addq $0,$22,$0
315 addq $16,8,$16 # r++
316
317 bgt $19,$945
318 ret $31,($26),1 # else exit
319
320$900:
321 addq $19,4,$19
322 bgt $19,$945 # goto tail code
323 ret $31,($26),1 # else exit
324 .end bn_add_words
325
326 #
327 # What follows was taken directly from the C compiler with a few
328 # hacks to redo the lables.
329 #
330.text
331 .align 3
332 .globl bn_div64
333 .ent bn_div64
334bn_div64:
335 ldgp $29,0($27)
336bn_div64..ng:
337 lda $30,-48($30)
338 .frame $30,48,$26,0
339 stq $26,0($30)
340 stq $9,8($30)
341 stq $10,16($30)
342 stq $11,24($30)
343 stq $12,32($30)
344 stq $13,40($30)
345 .mask 0x4003e00,-48
346 .prologue 1
347 bis $16,$16,$9
348 bis $17,$17,$10
349 bis $18,$18,$11
350 bis $31,$31,$13
351 bis $31,2,$12
352 bne $11,$119
353 lda $0,-1
354 br $31,$136
355 .align 4
356$119:
357 bis $11,$11,$16
358 jsr $26,BN_num_bits_word
359 ldgp $29,0($26)
360 subq $0,64,$1
361 beq $1,$120
362 bis $31,1,$1
363 sll $1,$0,$1
364 cmpule $9,$1,$1
365 bne $1,$120
366 # lda $16,_IO_stderr_
367 # lda $17,$C32
368 # bis $0,$0,$18
369 # jsr $26,fprintf
370 # ldgp $29,0($26)
371 jsr $26,abort
372 ldgp $29,0($26)
373 .align 4
374$120:
375 bis $31,64,$3
376 cmpult $9,$11,$2
377 subq $3,$0,$1
378 addl $1,$31,$0
379 subq $9,$11,$1
380 cmoveq $2,$1,$9
381 beq $0,$122
382 zapnot $0,15,$2
383 subq $3,$0,$1
384 sll $11,$2,$11
385 sll $9,$2,$3
386 srl $10,$1,$1
387 sll $10,$2,$10
388 bis $3,$1,$9
389$122:
390 srl $11,32,$5
391 zapnot $11,15,$6
392 lda $7,-1
393 .align 5
394$123:
395 srl $9,32,$1
396 subq $1,$5,$1
397 bne $1,$126
398 zapnot $7,15,$27
399 br $31,$127
400 .align 4
401$126:
402 bis $9,$9,$24
403 bis $5,$5,$25
404 divqu $24,$25,$27
405$127:
406 srl $10,32,$4
407 .align 5
408$128:
409 mulq $27,$5,$1
410 subq $9,$1,$3
411 zapnot $3,240,$1
412 bne $1,$129
413 mulq $6,$27,$2
414 sll $3,32,$1
415 addq $1,$4,$1
416 cmpule $2,$1,$2
417 bne $2,$129
418 subq $27,1,$27
419 br $31,$128
420 .align 4
421$129:
422 mulq $27,$6,$1
423 mulq $27,$5,$4
424 srl $1,32,$3
425 sll $1,32,$1
426 addq $4,$3,$4
427 cmpult $10,$1,$2
428 subq $10,$1,$10
429 addq $2,$4,$2
430 cmpult $9,$2,$1
431 bis $2,$2,$4
432 beq $1,$134
433 addq $9,$11,$9
434 subq $27,1,$27
435$134:
436 subl $12,1,$12
437 subq $9,$4,$9
438 beq $12,$124
439 sll $27,32,$13
440 sll $9,32,$2
441 srl $10,32,$1
442 sll $10,32,$10
443 bis $2,$1,$9
444 br $31,$123
445 .align 4
446$124:
447 bis $13,$27,$0
448$136:
449 ldq $26,0($30)
450 ldq $9,8($30)
451 ldq $10,16($30)
452 ldq $11,24($30)
453 ldq $12,32($30)
454 ldq $13,40($30)
455 addq $30,48,$30
456 ret $31,($26),1
457 .end bn_div64
458
459 .set noat
460 .text
461 .align 3
462 .globl bn_sub_words
463 .ent bn_sub_words
464bn_sub_words:
465bn_sub_words..ng:
466 .frame $30,0,$26,0
467 .prologue 0
468
469 subq $19, 4, $19
470 bis $31, $31, $0
471 blt $19, $100
472 ldq $1, 0($17)
473 ldq $2, 0($18)
474$101:
475 ldq $3, 8($17)
476 cmpult $1, $2, $4
477 ldq $5, 8($18)
478 subq $1, $2, $1
479 ldq $6, 16($17)
480 cmpult $1, $0, $2
481 ldq $7, 16($18)
482 subq $1, $0, $23
483 ldq $8, 24($17)
484 addq $2, $4, $0
485 cmpult $3, $5, $24
486 subq $3, $5, $3
487 ldq $22, 24($18)
488 cmpult $3, $0, $5
489 subq $3, $0, $25
490 addq $5, $24, $0
491 cmpult $6, $7, $27
492 subq $6, $7, $6
493 stq $23, 0($16)
494 cmpult $6, $0, $7
495 subq $6, $0, $28
496 addq $7, $27, $0
497 cmpult $8, $22, $21
498 subq $8, $22, $8
499 stq $25, 8($16)
500 cmpult $8, $0, $22
501 subq $8, $0, $20
502 addq $22, $21, $0
503 stq $28, 16($16)
504 subq $19, 4, $19
505 stq $20, 24($16)
506 addq $17, 32, $17
507 addq $18, 32, $18
508 addq $16, 32, $16
509 blt $19, $100
510 ldq $1, 0($17)
511 ldq $2, 0($18)
512 br $101
513$102:
514 ldq $1, 0($17)
515 ldq $2, 0($18)
516 cmpult $1, $2, $27
517 subq $1, $2, $1
518 cmpult $1, $0, $2
519 subq $1, $0, $1
520 stq $1, 0($16)
521 addq $2, $27, $0
522 addq $17, 8, $17
523 addq $18, 8, $18
524 addq $16, 8, $16
525 subq $19, 1, $19
526 bgt $19, $102
527 ret $31,($26),1
528$100:
529 addq $19, 4, $19
530 bgt $19, $102
531$103:
532 ret $31,($26),1
533 .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 @@
1#!/usr/bin/perl
2#
3
4#!/usr/local/bin/perl 1#!/usr/local/bin/perl
5 2
6push(@INC,"perlasm","../../perlasm"); 3push(@INC,"perlasm","../../perlasm");
7require "x86asm.pl"; 4require "x86asm.pl";
8 5
9&asm_init($ARGV[0],"bn-586.pl"); 6&asm_init($ARGV[0],$0);
10 7
11&bn_mul_add_words("bn_mul_add_words"); 8&bn_mul_add_words("bn_mul_add_words");
12&bn_mul_words("bn_mul_words"); 9&bn_mul_words("bn_mul_words");
13&bn_sqr_words("bn_sqr_words"); 10&bn_sqr_words("bn_sqr_words");
14&bn_div64("bn_div64"); 11&bn_div_words("bn_div_words");
15&bn_add_words("bn_add_words"); 12&bn_add_words("bn_add_words");
13&bn_sub_words("bn_sub_words");
16 14
17&asm_finish(); 15&asm_finish();
18 16
@@ -228,7 +226,7 @@ sub bn_sqr_words
228 &function_end($name); 226 &function_end($name);
229 } 227 }
230 228
231sub bn_div64 229sub bn_div_words
232 { 230 {
233 local($name)=@_; 231 local($name)=@_;
234 232
@@ -307,7 +305,79 @@ sub bn_add_words
307 } 305 }
308 &set_label("aw_end",0); 306 &set_label("aw_end",0);
309 307
310 &mov("eax",$c); 308# &mov("eax",$c); # $c is "eax"
309
310 &function_end($name);
311 }
312
313sub bn_sub_words
314 {
315 local($name)=@_;
316
317 &function_begin($name,"");
318
319 &comment("");
320 $a="esi";
321 $b="edi";
322 $c="eax";
323 $r="ebx";
324 $tmp1="ecx";
325 $tmp2="edx";
326 $num="ebp";
327
328 &mov($r,&wparam(0)); # get r
329 &mov($a,&wparam(1)); # get a
330 &mov($b,&wparam(2)); # get b
331 &mov($num,&wparam(3)); # get num
332 &xor($c,$c); # clear carry
333 &and($num,0xfffffff8); # num / 8
334
335 &jz(&label("aw_finish"));
336
337 &set_label("aw_loop",0);
338 for ($i=0; $i<8; $i++)
339 {
340 &comment("Round $i");
341
342 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
343 &mov($tmp2,&DWP($i*4,$b,"",0)); # *b
344 &sub($tmp1,$c);
345 &mov($c,0);
346 &adc($c,$c);
347 &sub($tmp1,$tmp2);
348 &adc($c,0);
349 &mov(&DWP($i*4,$r,"",0),$tmp1); # *r
350 }
351
352 &comment("");
353 &add($a,32);
354 &add($b,32);
355 &add($r,32);
356 &sub($num,8);
357 &jnz(&label("aw_loop"));
358
359 &set_label("aw_finish",0);
360 &mov($num,&wparam(3)); # get num
361 &and($num,7);
362 &jz(&label("aw_end"));
363
364 for ($i=0; $i<7; $i++)
365 {
366 &comment("Tail Round $i");
367 &mov($tmp1,&DWP($i*4,$a,"",0)); # *a
368 &mov($tmp2,&DWP($i*4,$b,"",0));# *b
369 &sub($tmp1,$c);
370 &mov($c,0);
371 &adc($c,$c);
372 &sub($tmp1,$tmp2);
373 &adc($c,0);
374 &dec($num) if ($i != 6);
375 &mov(&DWP($i*4,$r,"",0),$tmp1); # *a
376 &jz(&label("aw_end")) if ($i != 6);
377 }
378 &set_label("aw_end",0);
379
380# &mov("eax",$c); # $c is "eax"
311 381
312 &function_end($name); 382 &function_end($name);
313 } 383 }
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 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6$d=&data();
7$d =~ s/CC/0/g;
8$d =~ s/R1/1/g;
9$d =~ s/R2/2/g;
10$d =~ s/R3/3/g;
11$d =~ s/R4/4/g;
12$d =~ s/L1/5/g;
13$d =~ s/L2/6/g;
14$d =~ s/L3/7/g;
15$d =~ s/L4/8/g;
16$d =~ s/O1/22/g;
17$d =~ s/O2/23/g;
18$d =~ s/O3/24/g;
19$d =~ s/O4/25/g;
20$d =~ s/A1/20/g;
21$d =~ s/A2/21/g;
22$d =~ s/A3/27/g;
23$d =~ s/A4/28/g;
24if (0){
25}
26
27print $d;
28
29sub data
30 {
31 local($data)=<<'EOF';
32
33 # DEC Alpha assember
34 # The bn_div_words is actually gcc output but the other parts are hand done.
35 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
36 # bn_div_words.
37 # I've gone back and re-done most of routines.
38 # The key thing to remeber for the 164 CPU is that while a
39 # multiply operation takes 8 cycles, another one can only be issued
40 # after 4 cycles have elapsed. I've done modification to help
41 # improve this. Also, normally, a ld instruction will not be available
42 # for about 3 cycles.
43 .file 1 "bn_asm.c"
44 .set noat
45gcc2_compiled.:
46__gnu_compiled_c:
47 .text
48 .align 3
49 .globl bn_mul_add_words
50 .ent bn_mul_add_words
51bn_mul_add_words:
52bn_mul_add_words..ng:
53 .frame $30,0,$26,0
54 .prologue 0
55 .align 5
56 subq $18,4,$18
57 bis $31,$31,$CC
58 blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code
59 ldq $A1,0($17) # 1 1
60 ldq $R1,0($16) # 1 1
61 .align 3
62$42:
63 mulq $A1,$19,$L1 # 1 2 1 ######
64 ldq $A2,8($17) # 2 1
65 ldq $R2,8($16) # 2 1
66 umulh $A1,$19,$A1 # 1 2 ######
67 ldq $A3,16($17) # 3 1
68 ldq $R3,16($16) # 3 1
69 mulq $A2,$19,$L2 # 2 2 1 ######
70 ldq $A4,24($17) # 4 1
71 addq $R1,$L1,$R1 # 1 2 2
72 ldq $R4,24($16) # 4 1
73 umulh $A2,$19,$A2 # 2 2 ######
74 cmpult $R1,$L1,$O1 # 1 2 3 1
75 addq $A1,$O1,$A1 # 1 3 1
76 addq $R1,$CC,$R1 # 1 2 3 1
77 mulq $A3,$19,$L3 # 3 2 1 ######
78 cmpult $R1,$CC,$CC # 1 2 3 2
79 addq $R2,$L2,$R2 # 2 2 2
80 addq $A1,$CC,$CC # 1 3 2
81 cmpult $R2,$L2,$O2 # 2 2 3 1
82 addq $A2,$O2,$A2 # 2 3 1
83 umulh $A3,$19,$A3 # 3 2 ######
84 addq $R2,$CC,$R2 # 2 2 3 1
85 cmpult $R2,$CC,$CC # 2 2 3 2
86 subq $18,4,$18
87 mulq $A4,$19,$L4 # 4 2 1 ######
88 addq $A2,$CC,$CC # 2 3 2
89 addq $R3,$L3,$R3 # 3 2 2
90 addq $16,32,$16
91 cmpult $R3,$L3,$O3 # 3 2 3 1
92 stq $R1,-32($16) # 1 2 4
93 umulh $A4,$19,$A4 # 4 2 ######
94 addq $A3,$O3,$A3 # 3 3 1
95 addq $R3,$CC,$R3 # 3 2 3 1
96 stq $R2,-24($16) # 2 2 4
97 cmpult $R3,$CC,$CC # 3 2 3 2
98 stq $R3,-16($16) # 3 2 4
99 addq $R4,$L4,$R4 # 4 2 2
100 addq $A3,$CC,$CC # 3 3 2
101 cmpult $R4,$L4,$O4 # 4 2 3 1
102 addq $17,32,$17
103 addq $A4,$O4,$A4 # 4 3 1
104 addq $R4,$CC,$R4 # 4 2 3 1
105 cmpult $R4,$CC,$CC # 4 2 3 2
106 stq $R4,-8($16) # 4 2 4
107 addq $A4,$CC,$CC # 4 3 2
108 blt $18,$43
109
110 ldq $A1,0($17) # 1 1
111 ldq $R1,0($16) # 1 1
112
113 br $42
114
115 .align 4
116$45:
117 ldq $A1,0($17) # 4 1
118 ldq $R1,0($16) # 4 1
119 mulq $A1,$19,$L1 # 4 2 1
120 subq $18,1,$18
121 addq $16,8,$16
122 addq $17,8,$17
123 umulh $A1,$19,$A1 # 4 2
124 addq $R1,$L1,$R1 # 4 2 2
125 cmpult $R1,$L1,$O1 # 4 2 3 1
126 addq $A1,$O1,$A1 # 4 3 1
127 addq $R1,$CC,$R1 # 4 2 3 1
128 cmpult $R1,$CC,$CC # 4 2 3 2
129 addq $A1,$CC,$CC # 4 3 2
130 stq $R1,-8($16) # 4 2 4
131 bgt $18,$45
132 ret $31,($26),1 # else exit
133
134 .align 4
135$43:
136 addq $18,4,$18
137 bgt $18,$45 # goto tail code
138 ret $31,($26),1 # else exit
139
140 .end bn_mul_add_words
141 .align 3
142 .globl bn_mul_words
143 .ent bn_mul_words
144bn_mul_words:
145bn_mul_words..ng:
146 .frame $30,0,$26,0
147 .prologue 0
148 .align 5
149 subq $18,4,$18
150 bis $31,$31,$CC
151 blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code
152 ldq $A1,0($17) # 1 1
153 .align 3
154$142:
155
156 mulq $A1,$19,$L1 # 1 2 1 #####
157 ldq $A2,8($17) # 2 1
158 ldq $A3,16($17) # 3 1
159 umulh $A1,$19,$A1 # 1 2 #####
160 ldq $A4,24($17) # 4 1
161 mulq $A2,$19,$L2 # 2 2 1 #####
162 addq $L1,$CC,$L1 # 1 2 3 1
163 subq $18,4,$18
164 cmpult $L1,$CC,$CC # 1 2 3 2
165 umulh $A2,$19,$A2 # 2 2 #####
166 addq $A1,$CC,$CC # 1 3 2
167 addq $17,32,$17
168 addq $L2,$CC,$L2 # 2 2 3 1
169 mulq $A3,$19,$L3 # 3 2 1 #####
170 cmpult $L2,$CC,$CC # 2 2 3 2
171 addq $A2,$CC,$CC # 2 3 2
172 addq $16,32,$16
173 umulh $A3,$19,$A3 # 3 2 #####
174 stq $L1,-32($16) # 1 2 4
175 mulq $A4,$19,$L4 # 4 2 1 #####
176 addq $L3,$CC,$L3 # 3 2 3 1
177 stq $L2,-24($16) # 2 2 4
178 cmpult $L3,$CC,$CC # 3 2 3 2
179 umulh $A4,$19,$A4 # 4 2 #####
180 addq $A3,$CC,$CC # 3 3 2
181 stq $L3,-16($16) # 3 2 4
182 addq $L4,$CC,$L4 # 4 2 3 1
183 cmpult $L4,$CC,$CC # 4 2 3 2
184
185 addq $A4,$CC,$CC # 4 3 2
186
187 stq $L4,-8($16) # 4 2 4
188
189 blt $18,$143
190
191 ldq $A1,0($17) # 1 1
192
193 br $142
194
195 .align 4
196$145:
197 ldq $A1,0($17) # 4 1
198 mulq $A1,$19,$L1 # 4 2 1
199 subq $18,1,$18
200 umulh $A1,$19,$A1 # 4 2
201 addq $L1,$CC,$L1 # 4 2 3 1
202 addq $16,8,$16
203 cmpult $L1,$CC,$CC # 4 2 3 2
204 addq $17,8,$17
205 addq $A1,$CC,$CC # 4 3 2
206 stq $L1,-8($16) # 4 2 4
207
208 bgt $18,$145
209 ret $31,($26),1 # else exit
210
211 .align 4
212$143:
213 addq $18,4,$18
214 bgt $18,$145 # goto tail code
215 ret $31,($26),1 # else exit
216
217 .end bn_mul_words
218 .align 3
219 .globl bn_sqr_words
220 .ent bn_sqr_words
221bn_sqr_words:
222bn_sqr_words..ng:
223 .frame $30,0,$26,0
224 .prologue 0
225
226 subq $18,4,$18
227 blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code
228 ldq $A1,0($17) # 1 1
229 .align 3
230$542:
231 mulq $A1,$A1,$L1 ######
232 ldq $A2,8($17) # 1 1
233 subq $18,4
234 umulh $A1,$A1,$R1 ######
235 ldq $A3,16($17) # 1 1
236 mulq $A2,$A2,$L2 ######
237 ldq $A4,24($17) # 1 1
238 stq $L1,0($16) # r[0]
239 umulh $A2,$A2,$R2 ######
240 stq $R1,8($16) # r[1]
241 mulq $A3,$A3,$L3 ######
242 stq $L2,16($16) # r[0]
243 umulh $A3,$A3,$R3 ######
244 stq $R2,24($16) # r[1]
245 mulq $A4,$A4,$L4 ######
246 stq $L3,32($16) # r[0]
247 umulh $A4,$A4,$R4 ######
248 stq $R3,40($16) # r[1]
249
250 addq $16,64,$16
251 addq $17,32,$17
252 stq $L4,-16($16) # r[0]
253 stq $R4,-8($16) # r[1]
254
255 blt $18,$543
256 ldq $A1,0($17) # 1 1
257 br $542
258
259$442:
260 ldq $A1,0($17) # a[0]
261 mulq $A1,$A1,$L1 # a[0]*w low part r2
262 addq $16,16,$16
263 addq $17,8,$17
264 subq $18,1,$18
265 umulh $A1,$A1,$R1 # a[0]*w high part r3
266 stq $L1,-16($16) # r[0]
267 stq $R1,-8($16) # r[1]
268
269 bgt $18,$442
270 ret $31,($26),1 # else exit
271
272 .align 4
273$543:
274 addq $18,4,$18
275 bgt $18,$442 # goto tail code
276 ret $31,($26),1 # else exit
277 .end bn_sqr_words
278
279 .align 3
280 .globl bn_add_words
281 .ent bn_add_words
282bn_add_words:
283bn_add_words..ng:
284 .frame $30,0,$26,0
285 .prologue 0
286
287 subq $19,4,$19
288 bis $31,$31,$CC # carry = 0
289 blt $19,$900
290 ldq $L1,0($17) # a[0]
291 ldq $R1,0($18) # b[1]
292 .align 3
293$901:
294 addq $R1,$L1,$R1 # r=a+b;
295 ldq $L2,8($17) # a[1]
296 cmpult $R1,$L1,$O1 # did we overflow?
297 ldq $R2,8($18) # b[1]
298 addq $R1,$CC,$R1 # c+= overflow
299 ldq $L3,16($17) # a[2]
300 cmpult $R1,$CC,$CC # overflow?
301 ldq $R3,16($18) # b[2]
302 addq $CC,$O1,$CC
303 ldq $L4,24($17) # a[3]
304 addq $R2,$L2,$R2 # r=a+b;
305 ldq $R4,24($18) # b[3]
306 cmpult $R2,$L2,$O2 # did we overflow?
307 addq $R3,$L3,$R3 # r=a+b;
308 addq $R2,$CC,$R2 # c+= overflow
309 cmpult $R3,$L3,$O3 # did we overflow?
310 cmpult $R2,$CC,$CC # overflow?
311 addq $R4,$L4,$R4 # r=a+b;
312 addq $CC,$O2,$CC
313 cmpult $R4,$L4,$O4 # did we overflow?
314 addq $R3,$CC,$R3 # c+= overflow
315 stq $R1,0($16) # r[0]=c
316 cmpult $R3,$CC,$CC # overflow?
317 stq $R2,8($16) # r[1]=c
318 addq $CC,$O3,$CC
319 stq $R3,16($16) # r[2]=c
320 addq $R4,$CC,$R4 # c+= overflow
321 subq $19,4,$19 # loop--
322 cmpult $R4,$CC,$CC # overflow?
323 addq $17,32,$17 # a++
324 addq $CC,$O4,$CC
325 stq $R4,24($16) # r[3]=c
326 addq $18,32,$18 # b++
327 addq $16,32,$16 # r++
328
329 blt $19,$900
330 ldq $L1,0($17) # a[0]
331 ldq $R1,0($18) # b[1]
332 br $901
333 .align 4
334$945:
335 ldq $L1,0($17) # a[0]
336 ldq $R1,0($18) # b[1]
337 addq $R1,$L1,$R1 # r=a+b;
338 subq $19,1,$19 # loop--
339 addq $R1,$CC,$R1 # c+= overflow
340 addq $17,8,$17 # a++
341 cmpult $R1,$L1,$O1 # did we overflow?
342 cmpult $R1,$CC,$CC # overflow?
343 addq $18,8,$18 # b++
344 stq $R1,0($16) # r[0]=c
345 addq $CC,$O1,$CC
346 addq $16,8,$16 # r++
347
348 bgt $19,$945
349 ret $31,($26),1 # else exit
350
351$900:
352 addq $19,4,$19
353 bgt $19,$945 # goto tail code
354 ret $31,($26),1 # else exit
355 .end bn_add_words
356
357 .align 3
358 .globl bn_sub_words
359 .ent bn_sub_words
360bn_sub_words:
361bn_sub_words..ng:
362 .frame $30,0,$26,0
363 .prologue 0
364
365 subq $19,4,$19
366 bis $31,$31,$CC # carry = 0
367 br $800
368 blt $19,$800
369 ldq $L1,0($17) # a[0]
370 ldq $R1,0($18) # b[1]
371 .align 3
372$801:
373 addq $R1,$L1,$R1 # r=a+b;
374 ldq $L2,8($17) # a[1]
375 cmpult $R1,$L1,$O1 # did we overflow?
376 ldq $R2,8($18) # b[1]
377 addq $R1,$CC,$R1 # c+= overflow
378 ldq $L3,16($17) # a[2]
379 cmpult $R1,$CC,$CC # overflow?
380 ldq $R3,16($18) # b[2]
381 addq $CC,$O1,$CC
382 ldq $L4,24($17) # a[3]
383 addq $R2,$L2,$R2 # r=a+b;
384 ldq $R4,24($18) # b[3]
385 cmpult $R2,$L2,$O2 # did we overflow?
386 addq $R3,$L3,$R3 # r=a+b;
387 addq $R2,$CC,$R2 # c+= overflow
388 cmpult $R3,$L3,$O3 # did we overflow?
389 cmpult $R2,$CC,$CC # overflow?
390 addq $R4,$L4,$R4 # r=a+b;
391 addq $CC,$O2,$CC
392 cmpult $R4,$L4,$O4 # did we overflow?
393 addq $R3,$CC,$R3 # c+= overflow
394 stq $R1,0($16) # r[0]=c
395 cmpult $R3,$CC,$CC # overflow?
396 stq $R2,8($16) # r[1]=c
397 addq $CC,$O3,$CC
398 stq $R3,16($16) # r[2]=c
399 addq $R4,$CC,$R4 # c+= overflow
400 subq $19,4,$19 # loop--
401 cmpult $R4,$CC,$CC # overflow?
402 addq $17,32,$17 # a++
403 addq $CC,$O4,$CC
404 stq $R4,24($16) # r[3]=c
405 addq $18,32,$18 # b++
406 addq $16,32,$16 # r++
407
408 blt $19,$800
409 ldq $L1,0($17) # a[0]
410 ldq $R1,0($18) # b[1]
411 br $801
412 .align 4
413$845:
414 ldq $L1,0($17) # a[0]
415 ldq $R1,0($18) # b[1]
416 cmpult $L1,$R1,$O1 # will we borrow?
417 subq $L1,$R1,$R1 # r=a-b;
418 subq $19,1,$19 # loop--
419 cmpult $R1,$CC,$O2 # will we borrow?
420 subq $R1,$CC,$R1 # c+= overflow
421 addq $17,8,$17 # a++
422 addq $18,8,$18 # b++
423 stq $R1,0($16) # r[0]=c
424 addq $O2,$O1,$CC
425 addq $16,8,$16 # r++
426
427 bgt $19,$845
428 ret $31,($26),1 # else exit
429
430$800:
431 addq $19,4,$19
432 bgt $19,$845 # goto tail code
433 ret $31,($26),1 # else exit
434 .end bn_sub_words
435
436 #
437 # What follows was taken directly from the C compiler with a few
438 # hacks to redo the lables.
439 #
440.text
441 .align 3
442 .globl bn_div_words
443 .ent bn_div_words
444bn_div_words:
445 ldgp $29,0($27)
446bn_div_words..ng:
447 lda $30,-48($30)
448 .frame $30,48,$26,0
449 stq $26,0($30)
450 stq $9,8($30)
451 stq $10,16($30)
452 stq $11,24($30)
453 stq $12,32($30)
454 stq $13,40($30)
455 .mask 0x4003e00,-48
456 .prologue 1
457 bis $16,$16,$9
458 bis $17,$17,$10
459 bis $18,$18,$11
460 bis $31,$31,$13
461 bis $31,2,$12
462 bne $11,$119
463 lda $0,-1
464 br $31,$136
465 .align 4
466$119:
467 bis $11,$11,$16
468 jsr $26,BN_num_bits_word
469 ldgp $29,0($26)
470 subq $0,64,$1
471 beq $1,$120
472 bis $31,1,$1
473 sll $1,$0,$1
474 cmpule $9,$1,$1
475 bne $1,$120
476 # lda $16,_IO_stderr_
477 # lda $17,$C32
478 # bis $0,$0,$18
479 # jsr $26,fprintf
480 # ldgp $29,0($26)
481 jsr $26,abort
482 ldgp $29,0($26)
483 .align 4
484$120:
485 bis $31,64,$3
486 cmpult $9,$11,$2
487 subq $3,$0,$1
488 addl $1,$31,$0
489 subq $9,$11,$1
490 cmoveq $2,$1,$9
491 beq $0,$122
492 zapnot $0,15,$2
493 subq $3,$0,$1
494 sll $11,$2,$11
495 sll $9,$2,$3
496 srl $10,$1,$1
497 sll $10,$2,$10
498 bis $3,$1,$9
499$122:
500 srl $11,32,$5
501 zapnot $11,15,$6
502 lda $7,-1
503 .align 5
504$123:
505 srl $9,32,$1
506 subq $1,$5,$1
507 bne $1,$126
508 zapnot $7,15,$27
509 br $31,$127
510 .align 4
511$126:
512 bis $9,$9,$24
513 bis $5,$5,$25
514 divqu $24,$25,$27
515$127:
516 srl $10,32,$4
517 .align 5
518$128:
519 mulq $27,$5,$1
520 subq $9,$1,$3
521 zapnot $3,240,$1
522 bne $1,$129
523 mulq $6,$27,$2
524 sll $3,32,$1
525 addq $1,$4,$1
526 cmpule $2,$1,$2
527 bne $2,$129
528 subq $27,1,$27
529 br $31,$128
530 .align 4
531$129:
532 mulq $27,$6,$1
533 mulq $27,$5,$4
534 srl $1,32,$3
535 sll $1,32,$1
536 addq $4,$3,$4
537 cmpult $10,$1,$2
538 subq $10,$1,$10
539 addq $2,$4,$2
540 cmpult $9,$2,$1
541 bis $2,$2,$4
542 beq $1,$134
543 addq $9,$11,$9
544 subq $27,1,$27
545$134:
546 subl $12,1,$12
547 subq $9,$4,$9
548 beq $12,$124
549 sll $27,32,$13
550 sll $9,32,$2
551 srl $10,32,$1
552 sll $10,32,$10
553 bis $2,$1,$9
554 br $31,$123
555 .align 4
556$124:
557 bis $13,$27,$0
558$136:
559 ldq $26,0($30)
560 ldq $9,8($30)
561 ldq $10,16($30)
562 ldq $11,24($30)
563 ldq $12,32($30)
564 ldq $13,40($30)
565 addq $30,48,$30
566 ret $31,($26),1
567 .end bn_div_words
568EOF
569 return($data);
570 }
571
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:
485_bn_sqr_words ENDP 485_bn_sqr_words ENDP
486_TEXT ENDS 486_TEXT ENDS
487_TEXT SEGMENT 487_TEXT SEGMENT
488PUBLIC _bn_div64 488PUBLIC _bn_div_words
489 489
490_bn_div64 PROC NEAR 490_bn_div_words PROC NEAR
491 push ebp 491 push ebp
492 push ebx 492 push ebx
493 push esi 493 push esi
@@ -501,7 +501,7 @@ _bn_div64 PROC NEAR
501 pop ebx 501 pop ebx
502 pop ebp 502 pop ebp
503 ret 503 ret
504_bn_div64 ENDP 504_bn_div_words ENDP
505_TEXT ENDS 505_TEXT ENDS
506_TEXT SEGMENT 506_TEXT SEGMENT
507PUBLIC _bn_add_words 507PUBLIC _bn_add_words
@@ -678,7 +678,6 @@ $L011aw_finish:
678 adc eax, 0 678 adc eax, 0
679 mov DWORD PTR 24[ebx],ecx 679 mov DWORD PTR 24[ebx],ecx
680$L013aw_end: 680$L013aw_end:
681 mov eax, eax
682 pop edi 681 pop edi
683 pop esi 682 pop esi
684 pop ebx 683 pop ebx
@@ -686,4 +685,1438 @@ $L013aw_end:
686 ret 685 ret
687_bn_add_words ENDP 686_bn_add_words ENDP
688_TEXT ENDS 687_TEXT ENDS
688_TEXT SEGMENT
689PUBLIC _bn_sub_words
690
691_bn_sub_words PROC NEAR
692 push ebp
693 push ebx
694 push esi
695 push edi
696 ;
697 mov ebx, DWORD PTR 20[esp]
698 mov esi, DWORD PTR 24[esp]
699 mov edi, DWORD PTR 28[esp]
700 mov ebp, DWORD PTR 32[esp]
701 xor eax, eax
702 and ebp, 4294967288
703 jz $L014aw_finish
704L015aw_loop:
705 ; Round 0
706 mov ecx, DWORD PTR [esi]
707 mov edx, DWORD PTR [edi]
708 sub ecx, eax
709 mov eax, 0
710 adc eax, eax
711 sub ecx, edx
712 adc eax, 0
713 mov DWORD PTR [ebx],ecx
714 ; Round 1
715 mov ecx, DWORD PTR 4[esi]
716 mov edx, DWORD PTR 4[edi]
717 sub ecx, eax
718 mov eax, 0
719 adc eax, eax
720 sub ecx, edx
721 adc eax, 0
722 mov DWORD PTR 4[ebx],ecx
723 ; Round 2
724 mov ecx, DWORD PTR 8[esi]
725 mov edx, DWORD PTR 8[edi]
726 sub ecx, eax
727 mov eax, 0
728 adc eax, eax
729 sub ecx, edx
730 adc eax, 0
731 mov DWORD PTR 8[ebx],ecx
732 ; Round 3
733 mov ecx, DWORD PTR 12[esi]
734 mov edx, DWORD PTR 12[edi]
735 sub ecx, eax
736 mov eax, 0
737 adc eax, eax
738 sub ecx, edx
739 adc eax, 0
740 mov DWORD PTR 12[ebx],ecx
741 ; Round 4
742 mov ecx, DWORD PTR 16[esi]
743 mov edx, DWORD PTR 16[edi]
744 sub ecx, eax
745 mov eax, 0
746 adc eax, eax
747 sub ecx, edx
748 adc eax, 0
749 mov DWORD PTR 16[ebx],ecx
750 ; Round 5
751 mov ecx, DWORD PTR 20[esi]
752 mov edx, DWORD PTR 20[edi]
753 sub ecx, eax
754 mov eax, 0
755 adc eax, eax
756 sub ecx, edx
757 adc eax, 0
758 mov DWORD PTR 20[ebx],ecx
759 ; Round 6
760 mov ecx, DWORD PTR 24[esi]
761 mov edx, DWORD PTR 24[edi]
762 sub ecx, eax
763 mov eax, 0
764 adc eax, eax
765 sub ecx, edx
766 adc eax, 0
767 mov DWORD PTR 24[ebx],ecx
768 ; Round 7
769 mov ecx, DWORD PTR 28[esi]
770 mov edx, DWORD PTR 28[edi]
771 sub ecx, eax
772 mov eax, 0
773 adc eax, eax
774 sub ecx, edx
775 adc eax, 0
776 mov DWORD PTR 28[ebx],ecx
777 ;
778 add esi, 32
779 add edi, 32
780 add ebx, 32
781 sub ebp, 8
782 jnz L015aw_loop
783$L014aw_finish:
784 mov ebp, DWORD PTR 32[esp]
785 and ebp, 7
786 jz $L016aw_end
787 ; Tail Round 0
788 mov ecx, DWORD PTR [esi]
789 mov edx, DWORD PTR [edi]
790 sub ecx, eax
791 mov eax, 0
792 adc eax, eax
793 sub ecx, edx
794 adc eax, 0
795 dec ebp
796 mov DWORD PTR [ebx],ecx
797 jz $L016aw_end
798 ; Tail Round 1
799 mov ecx, DWORD PTR 4[esi]
800 mov edx, DWORD PTR 4[edi]
801 sub ecx, eax
802 mov eax, 0
803 adc eax, eax
804 sub ecx, edx
805 adc eax, 0
806 dec ebp
807 mov DWORD PTR 4[ebx],ecx
808 jz $L016aw_end
809 ; Tail Round 2
810 mov ecx, DWORD PTR 8[esi]
811 mov edx, DWORD PTR 8[edi]
812 sub ecx, eax
813 mov eax, 0
814 adc eax, eax
815 sub ecx, edx
816 adc eax, 0
817 dec ebp
818 mov DWORD PTR 8[ebx],ecx
819 jz $L016aw_end
820 ; Tail Round 3
821 mov ecx, DWORD PTR 12[esi]
822 mov edx, DWORD PTR 12[edi]
823 sub ecx, eax
824 mov eax, 0
825 adc eax, eax
826 sub ecx, edx
827 adc eax, 0
828 dec ebp
829 mov DWORD PTR 12[ebx],ecx
830 jz $L016aw_end
831 ; Tail Round 4
832 mov ecx, DWORD PTR 16[esi]
833 mov edx, DWORD PTR 16[edi]
834 sub ecx, eax
835 mov eax, 0
836 adc eax, eax
837 sub ecx, edx
838 adc eax, 0
839 dec ebp
840 mov DWORD PTR 16[ebx],ecx
841 jz $L016aw_end
842 ; Tail Round 5
843 mov ecx, DWORD PTR 20[esi]
844 mov edx, DWORD PTR 20[edi]
845 sub ecx, eax
846 mov eax, 0
847 adc eax, eax
848 sub ecx, edx
849 adc eax, 0
850 dec ebp
851 mov DWORD PTR 20[ebx],ecx
852 jz $L016aw_end
853 ; Tail Round 6
854 mov ecx, DWORD PTR 24[esi]
855 mov edx, DWORD PTR 24[edi]
856 sub ecx, eax
857 mov eax, 0
858 adc eax, eax
859 sub ecx, edx
860 adc eax, 0
861 mov DWORD PTR 24[ebx],ecx
862$L016aw_end:
863 pop edi
864 pop esi
865 pop ebx
866 pop ebp
867 ret
868_bn_sub_words ENDP
869_TEXT ENDS
870_TEXT SEGMENT
871PUBLIC _bn_mul_comba8
872
873_bn_mul_comba8 PROC NEAR
874 push esi
875 mov esi, DWORD PTR 12[esp]
876 push edi
877 mov edi, DWORD PTR 20[esp]
878 push ebp
879 push ebx
880 xor ebx, ebx
881 mov eax, DWORD PTR [esi]
882 xor ecx, ecx
883 mov edx, DWORD PTR [edi]
884 ; ################## Calculate word 0
885 xor ebp, ebp
886 ; mul a[0]*b[0]
887 mul edx
888 add ebx, eax
889 mov eax, DWORD PTR 20[esp]
890 adc ecx, edx
891 mov edx, DWORD PTR [edi]
892 adc ebp, 0
893 mov DWORD PTR [eax],ebx
894 mov eax, DWORD PTR 4[esi]
895 ; saved r[0]
896 ; ################## Calculate word 1
897 xor ebx, ebx
898 ; mul a[1]*b[0]
899 mul edx
900 add ecx, eax
901 mov eax, DWORD PTR [esi]
902 adc ebp, edx
903 mov edx, DWORD PTR 4[edi]
904 adc ebx, 0
905 ; mul a[0]*b[1]
906 mul edx
907 add ecx, eax
908 mov eax, DWORD PTR 20[esp]
909 adc ebp, edx
910 mov edx, DWORD PTR [edi]
911 adc ebx, 0
912 mov DWORD PTR 4[eax],ecx
913 mov eax, DWORD PTR 8[esi]
914 ; saved r[1]
915 ; ################## Calculate word 2
916 xor ecx, ecx
917 ; mul a[2]*b[0]
918 mul edx
919 add ebp, eax
920 mov eax, DWORD PTR 4[esi]
921 adc ebx, edx
922 mov edx, DWORD PTR 4[edi]
923 adc ecx, 0
924 ; mul a[1]*b[1]
925 mul edx
926 add ebp, eax
927 mov eax, DWORD PTR [esi]
928 adc ebx, edx
929 mov edx, DWORD PTR 8[edi]
930 adc ecx, 0
931 ; mul a[0]*b[2]
932 mul edx
933 add ebp, eax
934 mov eax, DWORD PTR 20[esp]
935 adc ebx, edx
936 mov edx, DWORD PTR [edi]
937 adc ecx, 0
938 mov DWORD PTR 8[eax],ebp
939 mov eax, DWORD PTR 12[esi]
940 ; saved r[2]
941 ; ################## Calculate word 3
942 xor ebp, ebp
943 ; mul a[3]*b[0]
944 mul edx
945 add ebx, eax
946 mov eax, DWORD PTR 8[esi]
947 adc ecx, edx
948 mov edx, DWORD PTR 4[edi]
949 adc ebp, 0
950 ; mul a[2]*b[1]
951 mul edx
952 add ebx, eax
953 mov eax, DWORD PTR 4[esi]
954 adc ecx, edx
955 mov edx, DWORD PTR 8[edi]
956 adc ebp, 0
957 ; mul a[1]*b[2]
958 mul edx
959 add ebx, eax
960 mov eax, DWORD PTR [esi]
961 adc ecx, edx
962 mov edx, DWORD PTR 12[edi]
963 adc ebp, 0
964 ; mul a[0]*b[3]
965 mul edx
966 add ebx, eax
967 mov eax, DWORD PTR 20[esp]
968 adc ecx, edx
969 mov edx, DWORD PTR [edi]
970 adc ebp, 0
971 mov DWORD PTR 12[eax],ebx
972 mov eax, DWORD PTR 16[esi]
973 ; saved r[3]
974 ; ################## Calculate word 4
975 xor ebx, ebx
976 ; mul a[4]*b[0]
977 mul edx
978 add ecx, eax
979 mov eax, DWORD PTR 12[esi]
980 adc ebp, edx
981 mov edx, DWORD PTR 4[edi]
982 adc ebx, 0
983 ; mul a[3]*b[1]
984 mul edx
985 add ecx, eax
986 mov eax, DWORD PTR 8[esi]
987 adc ebp, edx
988 mov edx, DWORD PTR 8[edi]
989 adc ebx, 0
990 ; mul a[2]*b[2]
991 mul edx
992 add ecx, eax
993 mov eax, DWORD PTR 4[esi]
994 adc ebp, edx
995 mov edx, DWORD PTR 12[edi]
996 adc ebx, 0
997 ; mul a[1]*b[3]
998 mul edx
999 add ecx, eax
1000 mov eax, DWORD PTR [esi]
1001 adc ebp, edx
1002 mov edx, DWORD PTR 16[edi]
1003 adc ebx, 0
1004 ; mul a[0]*b[4]
1005 mul edx
1006 add ecx, eax
1007 mov eax, DWORD PTR 20[esp]
1008 adc ebp, edx
1009 mov edx, DWORD PTR [edi]
1010 adc ebx, 0
1011 mov DWORD PTR 16[eax],ecx
1012 mov eax, DWORD PTR 20[esi]
1013 ; saved r[4]
1014 ; ################## Calculate word 5
1015 xor ecx, ecx
1016 ; mul a[5]*b[0]
1017 mul edx
1018 add ebp, eax
1019 mov eax, DWORD PTR 16[esi]
1020 adc ebx, edx
1021 mov edx, DWORD PTR 4[edi]
1022 adc ecx, 0
1023 ; mul a[4]*b[1]
1024 mul edx
1025 add ebp, eax
1026 mov eax, DWORD PTR 12[esi]
1027 adc ebx, edx
1028 mov edx, DWORD PTR 8[edi]
1029 adc ecx, 0
1030 ; mul a[3]*b[2]
1031 mul edx
1032 add ebp, eax
1033 mov eax, DWORD PTR 8[esi]
1034 adc ebx, edx
1035 mov edx, DWORD PTR 12[edi]
1036 adc ecx, 0
1037 ; mul a[2]*b[3]
1038 mul edx
1039 add ebp, eax
1040 mov eax, DWORD PTR 4[esi]
1041 adc ebx, edx
1042 mov edx, DWORD PTR 16[edi]
1043 adc ecx, 0
1044 ; mul a[1]*b[4]
1045 mul edx
1046 add ebp, eax
1047 mov eax, DWORD PTR [esi]
1048 adc ebx, edx
1049 mov edx, DWORD PTR 20[edi]
1050 adc ecx, 0
1051 ; mul a[0]*b[5]
1052 mul edx
1053 add ebp, eax
1054 mov eax, DWORD PTR 20[esp]
1055 adc ebx, edx
1056 mov edx, DWORD PTR [edi]
1057 adc ecx, 0
1058 mov DWORD PTR 20[eax],ebp
1059 mov eax, DWORD PTR 24[esi]
1060 ; saved r[5]
1061 ; ################## Calculate word 6
1062 xor ebp, ebp
1063 ; mul a[6]*b[0]
1064 mul edx
1065 add ebx, eax
1066 mov eax, DWORD PTR 20[esi]
1067 adc ecx, edx
1068 mov edx, DWORD PTR 4[edi]
1069 adc ebp, 0
1070 ; mul a[5]*b[1]
1071 mul edx
1072 add ebx, eax
1073 mov eax, DWORD PTR 16[esi]
1074 adc ecx, edx
1075 mov edx, DWORD PTR 8[edi]
1076 adc ebp, 0
1077 ; mul a[4]*b[2]
1078 mul edx
1079 add ebx, eax
1080 mov eax, DWORD PTR 12[esi]
1081 adc ecx, edx
1082 mov edx, DWORD PTR 12[edi]
1083 adc ebp, 0
1084 ; mul a[3]*b[3]
1085 mul edx
1086 add ebx, eax
1087 mov eax, DWORD PTR 8[esi]
1088 adc ecx, edx
1089 mov edx, DWORD PTR 16[edi]
1090 adc ebp, 0
1091 ; mul a[2]*b[4]
1092 mul edx
1093 add ebx, eax
1094 mov eax, DWORD PTR 4[esi]
1095 adc ecx, edx
1096 mov edx, DWORD PTR 20[edi]
1097 adc ebp, 0
1098 ; mul a[1]*b[5]
1099 mul edx
1100 add ebx, eax
1101 mov eax, DWORD PTR [esi]
1102 adc ecx, edx
1103 mov edx, DWORD PTR 24[edi]
1104 adc ebp, 0
1105 ; mul a[0]*b[6]
1106 mul edx
1107 add ebx, eax
1108 mov eax, DWORD PTR 20[esp]
1109 adc ecx, edx
1110 mov edx, DWORD PTR [edi]
1111 adc ebp, 0
1112 mov DWORD PTR 24[eax],ebx
1113 mov eax, DWORD PTR 28[esi]
1114 ; saved r[6]
1115 ; ################## Calculate word 7
1116 xor ebx, ebx
1117 ; mul a[7]*b[0]
1118 mul edx
1119 add ecx, eax
1120 mov eax, DWORD PTR 24[esi]
1121 adc ebp, edx
1122 mov edx, DWORD PTR 4[edi]
1123 adc ebx, 0
1124 ; mul a[6]*b[1]
1125 mul edx
1126 add ecx, eax
1127 mov eax, DWORD PTR 20[esi]
1128 adc ebp, edx
1129 mov edx, DWORD PTR 8[edi]
1130 adc ebx, 0
1131 ; mul a[5]*b[2]
1132 mul edx
1133 add ecx, eax
1134 mov eax, DWORD PTR 16[esi]
1135 adc ebp, edx
1136 mov edx, DWORD PTR 12[edi]
1137 adc ebx, 0
1138 ; mul a[4]*b[3]
1139 mul edx
1140 add ecx, eax
1141 mov eax, DWORD PTR 12[esi]
1142 adc ebp, edx
1143 mov edx, DWORD PTR 16[edi]
1144 adc ebx, 0
1145 ; mul a[3]*b[4]
1146 mul edx
1147 add ecx, eax
1148 mov eax, DWORD PTR 8[esi]
1149 adc ebp, edx
1150 mov edx, DWORD PTR 20[edi]
1151 adc ebx, 0
1152 ; mul a[2]*b[5]
1153 mul edx
1154 add ecx, eax
1155 mov eax, DWORD PTR 4[esi]
1156 adc ebp, edx
1157 mov edx, DWORD PTR 24[edi]
1158 adc ebx, 0
1159 ; mul a[1]*b[6]
1160 mul edx
1161 add ecx, eax
1162 mov eax, DWORD PTR [esi]
1163 adc ebp, edx
1164 mov edx, DWORD PTR 28[edi]
1165 adc ebx, 0
1166 ; mul a[0]*b[7]
1167 mul edx
1168 add ecx, eax
1169 mov eax, DWORD PTR 20[esp]
1170 adc ebp, edx
1171 mov edx, DWORD PTR 4[edi]
1172 adc ebx, 0
1173 mov DWORD PTR 28[eax],ecx
1174 mov eax, DWORD PTR 28[esi]
1175 ; saved r[7]
1176 ; ################## Calculate word 8
1177 xor ecx, ecx
1178 ; mul a[7]*b[1]
1179 mul edx
1180 add ebp, eax
1181 mov eax, DWORD PTR 24[esi]
1182 adc ebx, edx
1183 mov edx, DWORD PTR 8[edi]
1184 adc ecx, 0
1185 ; mul a[6]*b[2]
1186 mul edx
1187 add ebp, eax
1188 mov eax, DWORD PTR 20[esi]
1189 adc ebx, edx
1190 mov edx, DWORD PTR 12[edi]
1191 adc ecx, 0
1192 ; mul a[5]*b[3]
1193 mul edx
1194 add ebp, eax
1195 mov eax, DWORD PTR 16[esi]
1196 adc ebx, edx
1197 mov edx, DWORD PTR 16[edi]
1198 adc ecx, 0
1199 ; mul a[4]*b[4]
1200 mul edx
1201 add ebp, eax
1202 mov eax, DWORD PTR 12[esi]
1203 adc ebx, edx
1204 mov edx, DWORD PTR 20[edi]
1205 adc ecx, 0
1206 ; mul a[3]*b[5]
1207 mul edx
1208 add ebp, eax
1209 mov eax, DWORD PTR 8[esi]
1210 adc ebx, edx
1211 mov edx, DWORD PTR 24[edi]
1212 adc ecx, 0
1213 ; mul a[2]*b[6]
1214 mul edx
1215 add ebp, eax
1216 mov eax, DWORD PTR 4[esi]
1217 adc ebx, edx
1218 mov edx, DWORD PTR 28[edi]
1219 adc ecx, 0
1220 ; mul a[1]*b[7]
1221 mul edx
1222 add ebp, eax
1223 mov eax, DWORD PTR 20[esp]
1224 adc ebx, edx
1225 mov edx, DWORD PTR 8[edi]
1226 adc ecx, 0
1227 mov DWORD PTR 32[eax],ebp
1228 mov eax, DWORD PTR 28[esi]
1229 ; saved r[8]
1230 ; ################## Calculate word 9
1231 xor ebp, ebp
1232 ; mul a[7]*b[2]
1233 mul edx
1234 add ebx, eax
1235 mov eax, DWORD PTR 24[esi]
1236 adc ecx, edx
1237 mov edx, DWORD PTR 12[edi]
1238 adc ebp, 0
1239 ; mul a[6]*b[3]
1240 mul edx
1241 add ebx, eax
1242 mov eax, DWORD PTR 20[esi]
1243 adc ecx, edx
1244 mov edx, DWORD PTR 16[edi]
1245 adc ebp, 0
1246 ; mul a[5]*b[4]
1247 mul edx
1248 add ebx, eax
1249 mov eax, DWORD PTR 16[esi]
1250 adc ecx, edx
1251 mov edx, DWORD PTR 20[edi]
1252 adc ebp, 0
1253 ; mul a[4]*b[5]
1254 mul edx
1255 add ebx, eax
1256 mov eax, DWORD PTR 12[esi]
1257 adc ecx, edx
1258 mov edx, DWORD PTR 24[edi]
1259 adc ebp, 0
1260 ; mul a[3]*b[6]
1261 mul edx
1262 add ebx, eax
1263 mov eax, DWORD PTR 8[esi]
1264 adc ecx, edx
1265 mov edx, DWORD PTR 28[edi]
1266 adc ebp, 0
1267 ; mul a[2]*b[7]
1268 mul edx
1269 add ebx, eax
1270 mov eax, DWORD PTR 20[esp]
1271 adc ecx, edx
1272 mov edx, DWORD PTR 12[edi]
1273 adc ebp, 0
1274 mov DWORD PTR 36[eax],ebx
1275 mov eax, DWORD PTR 28[esi]
1276 ; saved r[9]
1277 ; ################## Calculate word 10
1278 xor ebx, ebx
1279 ; mul a[7]*b[3]
1280 mul edx
1281 add ecx, eax
1282 mov eax, DWORD PTR 24[esi]
1283 adc ebp, edx
1284 mov edx, DWORD PTR 16[edi]
1285 adc ebx, 0
1286 ; mul a[6]*b[4]
1287 mul edx
1288 add ecx, eax
1289 mov eax, DWORD PTR 20[esi]
1290 adc ebp, edx
1291 mov edx, DWORD PTR 20[edi]
1292 adc ebx, 0
1293 ; mul a[5]*b[5]
1294 mul edx
1295 add ecx, eax
1296 mov eax, DWORD PTR 16[esi]
1297 adc ebp, edx
1298 mov edx, DWORD PTR 24[edi]
1299 adc ebx, 0
1300 ; mul a[4]*b[6]
1301 mul edx
1302 add ecx, eax
1303 mov eax, DWORD PTR 12[esi]
1304 adc ebp, edx
1305 mov edx, DWORD PTR 28[edi]
1306 adc ebx, 0
1307 ; mul a[3]*b[7]
1308 mul edx
1309 add ecx, eax
1310 mov eax, DWORD PTR 20[esp]
1311 adc ebp, edx
1312 mov edx, DWORD PTR 16[edi]
1313 adc ebx, 0
1314 mov DWORD PTR 40[eax],ecx
1315 mov eax, DWORD PTR 28[esi]
1316 ; saved r[10]
1317 ; ################## Calculate word 11
1318 xor ecx, ecx
1319 ; mul a[7]*b[4]
1320 mul edx
1321 add ebp, eax
1322 mov eax, DWORD PTR 24[esi]
1323 adc ebx, edx
1324 mov edx, DWORD PTR 20[edi]
1325 adc ecx, 0
1326 ; mul a[6]*b[5]
1327 mul edx
1328 add ebp, eax
1329 mov eax, DWORD PTR 20[esi]
1330 adc ebx, edx
1331 mov edx, DWORD PTR 24[edi]
1332 adc ecx, 0
1333 ; mul a[5]*b[6]
1334 mul edx
1335 add ebp, eax
1336 mov eax, DWORD PTR 16[esi]
1337 adc ebx, edx
1338 mov edx, DWORD PTR 28[edi]
1339 adc ecx, 0
1340 ; mul a[4]*b[7]
1341 mul edx
1342 add ebp, eax
1343 mov eax, DWORD PTR 20[esp]
1344 adc ebx, edx
1345 mov edx, DWORD PTR 20[edi]
1346 adc ecx, 0
1347 mov DWORD PTR 44[eax],ebp
1348 mov eax, DWORD PTR 28[esi]
1349 ; saved r[11]
1350 ; ################## Calculate word 12
1351 xor ebp, ebp
1352 ; mul a[7]*b[5]
1353 mul edx
1354 add ebx, eax
1355 mov eax, DWORD PTR 24[esi]
1356 adc ecx, edx
1357 mov edx, DWORD PTR 24[edi]
1358 adc ebp, 0
1359 ; mul a[6]*b[6]
1360 mul edx
1361 add ebx, eax
1362 mov eax, DWORD PTR 20[esi]
1363 adc ecx, edx
1364 mov edx, DWORD PTR 28[edi]
1365 adc ebp, 0
1366 ; mul a[5]*b[7]
1367 mul edx
1368 add ebx, eax
1369 mov eax, DWORD PTR 20[esp]
1370 adc ecx, edx
1371 mov edx, DWORD PTR 24[edi]
1372 adc ebp, 0
1373 mov DWORD PTR 48[eax],ebx
1374 mov eax, DWORD PTR 28[esi]
1375 ; saved r[12]
1376 ; ################## Calculate word 13
1377 xor ebx, ebx
1378 ; mul a[7]*b[6]
1379 mul edx
1380 add ecx, eax
1381 mov eax, DWORD PTR 24[esi]
1382 adc ebp, edx
1383 mov edx, DWORD PTR 28[edi]
1384 adc ebx, 0
1385 ; mul a[6]*b[7]
1386 mul edx
1387 add ecx, eax
1388 mov eax, DWORD PTR 20[esp]
1389 adc ebp, edx
1390 mov edx, DWORD PTR 28[edi]
1391 adc ebx, 0
1392 mov DWORD PTR 52[eax],ecx
1393 mov eax, DWORD PTR 28[esi]
1394 ; saved r[13]
1395 ; ################## Calculate word 14
1396 xor ecx, ecx
1397 ; mul a[7]*b[7]
1398 mul edx
1399 add ebp, eax
1400 mov eax, DWORD PTR 20[esp]
1401 adc ebx, edx
1402 adc ecx, 0
1403 mov DWORD PTR 56[eax],ebp
1404 ; saved r[14]
1405 ; save r[15]
1406 mov DWORD PTR 60[eax],ebx
1407 pop ebx
1408 pop ebp
1409 pop edi
1410 pop esi
1411 ret
1412_bn_mul_comba8 ENDP
1413_TEXT ENDS
1414_TEXT SEGMENT
1415PUBLIC _bn_mul_comba4
1416
1417_bn_mul_comba4 PROC NEAR
1418 push esi
1419 mov esi, DWORD PTR 12[esp]
1420 push edi
1421 mov edi, DWORD PTR 20[esp]
1422 push ebp
1423 push ebx
1424 xor ebx, ebx
1425 mov eax, DWORD PTR [esi]
1426 xor ecx, ecx
1427 mov edx, DWORD PTR [edi]
1428 ; ################## Calculate word 0
1429 xor ebp, ebp
1430 ; mul a[0]*b[0]
1431 mul edx
1432 add ebx, eax
1433 mov eax, DWORD PTR 20[esp]
1434 adc ecx, edx
1435 mov edx, DWORD PTR [edi]
1436 adc ebp, 0
1437 mov DWORD PTR [eax],ebx
1438 mov eax, DWORD PTR 4[esi]
1439 ; saved r[0]
1440 ; ################## Calculate word 1
1441 xor ebx, ebx
1442 ; mul a[1]*b[0]
1443 mul edx
1444 add ecx, eax
1445 mov eax, DWORD PTR [esi]
1446 adc ebp, edx
1447 mov edx, DWORD PTR 4[edi]
1448 adc ebx, 0
1449 ; mul a[0]*b[1]
1450 mul edx
1451 add ecx, eax
1452 mov eax, DWORD PTR 20[esp]
1453 adc ebp, edx
1454 mov edx, DWORD PTR [edi]
1455 adc ebx, 0
1456 mov DWORD PTR 4[eax],ecx
1457 mov eax, DWORD PTR 8[esi]
1458 ; saved r[1]
1459 ; ################## Calculate word 2
1460 xor ecx, ecx
1461 ; mul a[2]*b[0]
1462 mul edx
1463 add ebp, eax
1464 mov eax, DWORD PTR 4[esi]
1465 adc ebx, edx
1466 mov edx, DWORD PTR 4[edi]
1467 adc ecx, 0
1468 ; mul a[1]*b[1]
1469 mul edx
1470 add ebp, eax
1471 mov eax, DWORD PTR [esi]
1472 adc ebx, edx
1473 mov edx, DWORD PTR 8[edi]
1474 adc ecx, 0
1475 ; mul a[0]*b[2]
1476 mul edx
1477 add ebp, eax
1478 mov eax, DWORD PTR 20[esp]
1479 adc ebx, edx
1480 mov edx, DWORD PTR [edi]
1481 adc ecx, 0
1482 mov DWORD PTR 8[eax],ebp
1483 mov eax, DWORD PTR 12[esi]
1484 ; saved r[2]
1485 ; ################## Calculate word 3
1486 xor ebp, ebp
1487 ; mul a[3]*b[0]
1488 mul edx
1489 add ebx, eax
1490 mov eax, DWORD PTR 8[esi]
1491 adc ecx, edx
1492 mov edx, DWORD PTR 4[edi]
1493 adc ebp, 0
1494 ; mul a[2]*b[1]
1495 mul edx
1496 add ebx, eax
1497 mov eax, DWORD PTR 4[esi]
1498 adc ecx, edx
1499 mov edx, DWORD PTR 8[edi]
1500 adc ebp, 0
1501 ; mul a[1]*b[2]
1502 mul edx
1503 add ebx, eax
1504 mov eax, DWORD PTR [esi]
1505 adc ecx, edx
1506 mov edx, DWORD PTR 12[edi]
1507 adc ebp, 0
1508 ; mul a[0]*b[3]
1509 mul edx
1510 add ebx, eax
1511 mov eax, DWORD PTR 20[esp]
1512 adc ecx, edx
1513 mov edx, DWORD PTR 4[edi]
1514 adc ebp, 0
1515 mov DWORD PTR 12[eax],ebx
1516 mov eax, DWORD PTR 12[esi]
1517 ; saved r[3]
1518 ; ################## Calculate word 4
1519 xor ebx, ebx
1520 ; mul a[3]*b[1]
1521 mul edx
1522 add ecx, eax
1523 mov eax, DWORD PTR 8[esi]
1524 adc ebp, edx
1525 mov edx, DWORD PTR 8[edi]
1526 adc ebx, 0
1527 ; mul a[2]*b[2]
1528 mul edx
1529 add ecx, eax
1530 mov eax, DWORD PTR 4[esi]
1531 adc ebp, edx
1532 mov edx, DWORD PTR 12[edi]
1533 adc ebx, 0
1534 ; mul a[1]*b[3]
1535 mul edx
1536 add ecx, eax
1537 mov eax, DWORD PTR 20[esp]
1538 adc ebp, edx
1539 mov edx, DWORD PTR 8[edi]
1540 adc ebx, 0
1541 mov DWORD PTR 16[eax],ecx
1542 mov eax, DWORD PTR 12[esi]
1543 ; saved r[4]
1544 ; ################## Calculate word 5
1545 xor ecx, ecx
1546 ; mul a[3]*b[2]
1547 mul edx
1548 add ebp, eax
1549 mov eax, DWORD PTR 8[esi]
1550 adc ebx, edx
1551 mov edx, DWORD PTR 12[edi]
1552 adc ecx, 0
1553 ; mul a[2]*b[3]
1554 mul edx
1555 add ebp, eax
1556 mov eax, DWORD PTR 20[esp]
1557 adc ebx, edx
1558 mov edx, DWORD PTR 12[edi]
1559 adc ecx, 0
1560 mov DWORD PTR 20[eax],ebp
1561 mov eax, DWORD PTR 12[esi]
1562 ; saved r[5]
1563 ; ################## Calculate word 6
1564 xor ebp, ebp
1565 ; mul a[3]*b[3]
1566 mul edx
1567 add ebx, eax
1568 mov eax, DWORD PTR 20[esp]
1569 adc ecx, edx
1570 adc ebp, 0
1571 mov DWORD PTR 24[eax],ebx
1572 ; saved r[6]
1573 ; save r[7]
1574 mov DWORD PTR 28[eax],ecx
1575 pop ebx
1576 pop ebp
1577 pop edi
1578 pop esi
1579 ret
1580_bn_mul_comba4 ENDP
1581_TEXT ENDS
1582_TEXT SEGMENT
1583PUBLIC _bn_sqr_comba8
1584
1585_bn_sqr_comba8 PROC NEAR
1586 push esi
1587 push edi
1588 push ebp
1589 push ebx
1590 mov edi, DWORD PTR 20[esp]
1591 mov esi, DWORD PTR 24[esp]
1592 xor ebx, ebx
1593 xor ecx, ecx
1594 mov eax, DWORD PTR [esi]
1595 ; ############### Calculate word 0
1596 xor ebp, ebp
1597 ; sqr a[0]*a[0]
1598 mul eax
1599 add ebx, eax
1600 adc ecx, edx
1601 mov edx, DWORD PTR [esi]
1602 adc ebp, 0
1603 mov DWORD PTR [edi],ebx
1604 mov eax, DWORD PTR 4[esi]
1605 ; saved r[0]
1606 ; ############### Calculate word 1
1607 xor ebx, ebx
1608 ; sqr a[1]*a[0]
1609 mul edx
1610 add eax, eax
1611 adc edx, edx
1612 adc ebx, 0
1613 add ecx, eax
1614 adc ebp, edx
1615 mov eax, DWORD PTR 8[esi]
1616 adc ebx, 0
1617 mov DWORD PTR 4[edi],ecx
1618 mov edx, DWORD PTR [esi]
1619 ; saved r[1]
1620 ; ############### Calculate word 2
1621 xor ecx, ecx
1622 ; sqr a[2]*a[0]
1623 mul edx
1624 add eax, eax
1625 adc edx, edx
1626 adc ecx, 0
1627 add ebp, eax
1628 adc ebx, edx
1629 mov eax, DWORD PTR 4[esi]
1630 adc ecx, 0
1631 ; sqr a[1]*a[1]
1632 mul eax
1633 add ebp, eax
1634 adc ebx, edx
1635 mov edx, DWORD PTR [esi]
1636 adc ecx, 0
1637 mov DWORD PTR 8[edi],ebp
1638 mov eax, DWORD PTR 12[esi]
1639 ; saved r[2]
1640 ; ############### Calculate word 3
1641 xor ebp, ebp
1642 ; sqr a[3]*a[0]
1643 mul edx
1644 add eax, eax
1645 adc edx, edx
1646 adc ebp, 0
1647 add ebx, eax
1648 adc ecx, edx
1649 mov eax, DWORD PTR 8[esi]
1650 adc ebp, 0
1651 mov edx, DWORD PTR 4[esi]
1652 ; sqr a[2]*a[1]
1653 mul edx
1654 add eax, eax
1655 adc edx, edx
1656 adc ebp, 0
1657 add ebx, eax
1658 adc ecx, edx
1659 mov eax, DWORD PTR 16[esi]
1660 adc ebp, 0
1661 mov DWORD PTR 12[edi],ebx
1662 mov edx, DWORD PTR [esi]
1663 ; saved r[3]
1664 ; ############### Calculate word 4
1665 xor ebx, ebx
1666 ; sqr a[4]*a[0]
1667 mul edx
1668 add eax, eax
1669 adc edx, edx
1670 adc ebx, 0
1671 add ecx, eax
1672 adc ebp, edx
1673 mov eax, DWORD PTR 12[esi]
1674 adc ebx, 0
1675 mov edx, DWORD PTR 4[esi]
1676 ; sqr a[3]*a[1]
1677 mul edx
1678 add eax, eax
1679 adc edx, edx
1680 adc ebx, 0
1681 add ecx, eax
1682 adc ebp, edx
1683 mov eax, DWORD PTR 8[esi]
1684 adc ebx, 0
1685 ; sqr a[2]*a[2]
1686 mul eax
1687 add ecx, eax
1688 adc ebp, edx
1689 mov edx, DWORD PTR [esi]
1690 adc ebx, 0
1691 mov DWORD PTR 16[edi],ecx
1692 mov eax, DWORD PTR 20[esi]
1693 ; saved r[4]
1694 ; ############### Calculate word 5
1695 xor ecx, ecx
1696 ; sqr a[5]*a[0]
1697 mul edx
1698 add eax, eax
1699 adc edx, edx
1700 adc ecx, 0
1701 add ebp, eax
1702 adc ebx, edx
1703 mov eax, DWORD PTR 16[esi]
1704 adc ecx, 0
1705 mov edx, DWORD PTR 4[esi]
1706 ; sqr a[4]*a[1]
1707 mul edx
1708 add eax, eax
1709 adc edx, edx
1710 adc ecx, 0
1711 add ebp, eax
1712 adc ebx, edx
1713 mov eax, DWORD PTR 12[esi]
1714 adc ecx, 0
1715 mov edx, DWORD PTR 8[esi]
1716 ; sqr a[3]*a[2]
1717 mul edx
1718 add eax, eax
1719 adc edx, edx
1720 adc ecx, 0
1721 add ebp, eax
1722 adc ebx, edx
1723 mov eax, DWORD PTR 24[esi]
1724 adc ecx, 0
1725 mov DWORD PTR 20[edi],ebp
1726 mov edx, DWORD PTR [esi]
1727 ; saved r[5]
1728 ; ############### Calculate word 6
1729 xor ebp, ebp
1730 ; sqr a[6]*a[0]
1731 mul edx
1732 add eax, eax
1733 adc edx, edx
1734 adc ebp, 0
1735 add ebx, eax
1736 adc ecx, edx
1737 mov eax, DWORD PTR 20[esi]
1738 adc ebp, 0
1739 mov edx, DWORD PTR 4[esi]
1740 ; sqr a[5]*a[1]
1741 mul edx
1742 add eax, eax
1743 adc edx, edx
1744 adc ebp, 0
1745 add ebx, eax
1746 adc ecx, edx
1747 mov eax, DWORD PTR 16[esi]
1748 adc ebp, 0
1749 mov edx, DWORD PTR 8[esi]
1750 ; sqr a[4]*a[2]
1751 mul edx
1752 add eax, eax
1753 adc edx, edx
1754 adc ebp, 0
1755 add ebx, eax
1756 adc ecx, edx
1757 mov eax, DWORD PTR 12[esi]
1758 adc ebp, 0
1759 ; sqr a[3]*a[3]
1760 mul eax
1761 add ebx, eax
1762 adc ecx, edx
1763 mov edx, DWORD PTR [esi]
1764 adc ebp, 0
1765 mov DWORD PTR 24[edi],ebx
1766 mov eax, DWORD PTR 28[esi]
1767 ; saved r[6]
1768 ; ############### Calculate word 7
1769 xor ebx, ebx
1770 ; sqr a[7]*a[0]
1771 mul edx
1772 add eax, eax
1773 adc edx, edx
1774 adc ebx, 0
1775 add ecx, eax
1776 adc ebp, edx
1777 mov eax, DWORD PTR 24[esi]
1778 adc ebx, 0
1779 mov edx, DWORD PTR 4[esi]
1780 ; sqr a[6]*a[1]
1781 mul edx
1782 add eax, eax
1783 adc edx, edx
1784 adc ebx, 0
1785 add ecx, eax
1786 adc ebp, edx
1787 mov eax, DWORD PTR 20[esi]
1788 adc ebx, 0
1789 mov edx, DWORD PTR 8[esi]
1790 ; sqr a[5]*a[2]
1791 mul edx
1792 add eax, eax
1793 adc edx, edx
1794 adc ebx, 0
1795 add ecx, eax
1796 adc ebp, edx
1797 mov eax, DWORD PTR 16[esi]
1798 adc ebx, 0
1799 mov edx, DWORD PTR 12[esi]
1800 ; sqr a[4]*a[3]
1801 mul edx
1802 add eax, eax
1803 adc edx, edx
1804 adc ebx, 0
1805 add ecx, eax
1806 adc ebp, edx
1807 mov eax, DWORD PTR 28[esi]
1808 adc ebx, 0
1809 mov DWORD PTR 28[edi],ecx
1810 mov edx, DWORD PTR 4[esi]
1811 ; saved r[7]
1812 ; ############### Calculate word 8
1813 xor ecx, ecx
1814 ; sqr a[7]*a[1]
1815 mul edx
1816 add eax, eax
1817 adc edx, edx
1818 adc ecx, 0
1819 add ebp, eax
1820 adc ebx, edx
1821 mov eax, DWORD PTR 24[esi]
1822 adc ecx, 0
1823 mov edx, DWORD PTR 8[esi]
1824 ; sqr a[6]*a[2]
1825 mul edx
1826 add eax, eax
1827 adc edx, edx
1828 adc ecx, 0
1829 add ebp, eax
1830 adc ebx, edx
1831 mov eax, DWORD PTR 20[esi]
1832 adc ecx, 0
1833 mov edx, DWORD PTR 12[esi]
1834 ; sqr a[5]*a[3]
1835 mul edx
1836 add eax, eax
1837 adc edx, edx
1838 adc ecx, 0
1839 add ebp, eax
1840 adc ebx, edx
1841 mov eax, DWORD PTR 16[esi]
1842 adc ecx, 0
1843 ; sqr a[4]*a[4]
1844 mul eax
1845 add ebp, eax
1846 adc ebx, edx
1847 mov edx, DWORD PTR 8[esi]
1848 adc ecx, 0
1849 mov DWORD PTR 32[edi],ebp
1850 mov eax, DWORD PTR 28[esi]
1851 ; saved r[8]
1852 ; ############### Calculate word 9
1853 xor ebp, ebp
1854 ; sqr a[7]*a[2]
1855 mul edx
1856 add eax, eax
1857 adc edx, edx
1858 adc ebp, 0
1859 add ebx, eax
1860 adc ecx, edx
1861 mov eax, DWORD PTR 24[esi]
1862 adc ebp, 0
1863 mov edx, DWORD PTR 12[esi]
1864 ; sqr a[6]*a[3]
1865 mul edx
1866 add eax, eax
1867 adc edx, edx
1868 adc ebp, 0
1869 add ebx, eax
1870 adc ecx, edx
1871 mov eax, DWORD PTR 20[esi]
1872 adc ebp, 0
1873 mov edx, DWORD PTR 16[esi]
1874 ; sqr a[5]*a[4]
1875 mul edx
1876 add eax, eax
1877 adc edx, edx
1878 adc ebp, 0
1879 add ebx, eax
1880 adc ecx, edx
1881 mov eax, DWORD PTR 28[esi]
1882 adc ebp, 0
1883 mov DWORD PTR 36[edi],ebx
1884 mov edx, DWORD PTR 12[esi]
1885 ; saved r[9]
1886 ; ############### Calculate word 10
1887 xor ebx, ebx
1888 ; sqr a[7]*a[3]
1889 mul edx
1890 add eax, eax
1891 adc edx, edx
1892 adc ebx, 0
1893 add ecx, eax
1894 adc ebp, edx
1895 mov eax, DWORD PTR 24[esi]
1896 adc ebx, 0
1897 mov edx, DWORD PTR 16[esi]
1898 ; sqr a[6]*a[4]
1899 mul edx
1900 add eax, eax
1901 adc edx, edx
1902 adc ebx, 0
1903 add ecx, eax
1904 adc ebp, edx
1905 mov eax, DWORD PTR 20[esi]
1906 adc ebx, 0
1907 ; sqr a[5]*a[5]
1908 mul eax
1909 add ecx, eax
1910 adc ebp, edx
1911 mov edx, DWORD PTR 16[esi]
1912 adc ebx, 0
1913 mov DWORD PTR 40[edi],ecx
1914 mov eax, DWORD PTR 28[esi]
1915 ; saved r[10]
1916 ; ############### Calculate word 11
1917 xor ecx, ecx
1918 ; sqr a[7]*a[4]
1919 mul edx
1920 add eax, eax
1921 adc edx, edx
1922 adc ecx, 0
1923 add ebp, eax
1924 adc ebx, edx
1925 mov eax, DWORD PTR 24[esi]
1926 adc ecx, 0
1927 mov edx, DWORD PTR 20[esi]
1928 ; sqr a[6]*a[5]
1929 mul edx
1930 add eax, eax
1931 adc edx, edx
1932 adc ecx, 0
1933 add ebp, eax
1934 adc ebx, edx
1935 mov eax, DWORD PTR 28[esi]
1936 adc ecx, 0
1937 mov DWORD PTR 44[edi],ebp
1938 mov edx, DWORD PTR 20[esi]
1939 ; saved r[11]
1940 ; ############### Calculate word 12
1941 xor ebp, ebp
1942 ; sqr a[7]*a[5]
1943 mul edx
1944 add eax, eax
1945 adc edx, edx
1946 adc ebp, 0
1947 add ebx, eax
1948 adc ecx, edx
1949 mov eax, DWORD PTR 24[esi]
1950 adc ebp, 0
1951 ; sqr a[6]*a[6]
1952 mul eax
1953 add ebx, eax
1954 adc ecx, edx
1955 mov edx, DWORD PTR 24[esi]
1956 adc ebp, 0
1957 mov DWORD PTR 48[edi],ebx
1958 mov eax, DWORD PTR 28[esi]
1959 ; saved r[12]
1960 ; ############### Calculate word 13
1961 xor ebx, ebx
1962 ; sqr a[7]*a[6]
1963 mul edx
1964 add eax, eax
1965 adc edx, edx
1966 adc ebx, 0
1967 add ecx, eax
1968 adc ebp, edx
1969 mov eax, DWORD PTR 28[esi]
1970 adc ebx, 0
1971 mov DWORD PTR 52[edi],ecx
1972 ; saved r[13]
1973 ; ############### Calculate word 14
1974 xor ecx, ecx
1975 ; sqr a[7]*a[7]
1976 mul eax
1977 add ebp, eax
1978 adc ebx, edx
1979 adc ecx, 0
1980 mov DWORD PTR 56[edi],ebp
1981 ; saved r[14]
1982 mov DWORD PTR 60[edi],ebx
1983 pop ebx
1984 pop ebp
1985 pop edi
1986 pop esi
1987 ret
1988_bn_sqr_comba8 ENDP
1989_TEXT ENDS
1990_TEXT SEGMENT
1991PUBLIC _bn_sqr_comba4
1992
1993_bn_sqr_comba4 PROC NEAR
1994 push esi
1995 push edi
1996 push ebp
1997 push ebx
1998 mov edi, DWORD PTR 20[esp]
1999 mov esi, DWORD PTR 24[esp]
2000 xor ebx, ebx
2001 xor ecx, ecx
2002 mov eax, DWORD PTR [esi]
2003 ; ############### Calculate word 0
2004 xor ebp, ebp
2005 ; sqr a[0]*a[0]
2006 mul eax
2007 add ebx, eax
2008 adc ecx, edx
2009 mov edx, DWORD PTR [esi]
2010 adc ebp, 0
2011 mov DWORD PTR [edi],ebx
2012 mov eax, DWORD PTR 4[esi]
2013 ; saved r[0]
2014 ; ############### Calculate word 1
2015 xor ebx, ebx
2016 ; sqr a[1]*a[0]
2017 mul edx
2018 add eax, eax
2019 adc edx, edx
2020 adc ebx, 0
2021 add ecx, eax
2022 adc ebp, edx
2023 mov eax, DWORD PTR 8[esi]
2024 adc ebx, 0
2025 mov DWORD PTR 4[edi],ecx
2026 mov edx, DWORD PTR [esi]
2027 ; saved r[1]
2028 ; ############### Calculate word 2
2029 xor ecx, ecx
2030 ; sqr a[2]*a[0]
2031 mul edx
2032 add eax, eax
2033 adc edx, edx
2034 adc ecx, 0
2035 add ebp, eax
2036 adc ebx, edx
2037 mov eax, DWORD PTR 4[esi]
2038 adc ecx, 0
2039 ; sqr a[1]*a[1]
2040 mul eax
2041 add ebp, eax
2042 adc ebx, edx
2043 mov edx, DWORD PTR [esi]
2044 adc ecx, 0
2045 mov DWORD PTR 8[edi],ebp
2046 mov eax, DWORD PTR 12[esi]
2047 ; saved r[2]
2048 ; ############### Calculate word 3
2049 xor ebp, ebp
2050 ; sqr a[3]*a[0]
2051 mul edx
2052 add eax, eax
2053 adc edx, edx
2054 adc ebp, 0
2055 add ebx, eax
2056 adc ecx, edx
2057 mov eax, DWORD PTR 8[esi]
2058 adc ebp, 0
2059 mov edx, DWORD PTR 4[esi]
2060 ; sqr a[2]*a[1]
2061 mul edx
2062 add eax, eax
2063 adc edx, edx
2064 adc ebp, 0
2065 add ebx, eax
2066 adc ecx, edx
2067 mov eax, DWORD PTR 12[esi]
2068 adc ebp, 0
2069 mov DWORD PTR 12[edi],ebx
2070 mov edx, DWORD PTR 4[esi]
2071 ; saved r[3]
2072 ; ############### Calculate word 4
2073 xor ebx, ebx
2074 ; sqr a[3]*a[1]
2075 mul edx
2076 add eax, eax
2077 adc edx, edx
2078 adc ebx, 0
2079 add ecx, eax
2080 adc ebp, edx
2081 mov eax, DWORD PTR 8[esi]
2082 adc ebx, 0
2083 ; sqr a[2]*a[2]
2084 mul eax
2085 add ecx, eax
2086 adc ebp, edx
2087 mov edx, DWORD PTR 8[esi]
2088 adc ebx, 0
2089 mov DWORD PTR 16[edi],ecx
2090 mov eax, DWORD PTR 12[esi]
2091 ; saved r[4]
2092 ; ############### Calculate word 5
2093 xor ecx, ecx
2094 ; sqr a[3]*a[2]
2095 mul edx
2096 add eax, eax
2097 adc edx, edx
2098 adc ecx, 0
2099 add ebp, eax
2100 adc ebx, edx
2101 mov eax, DWORD PTR 12[esi]
2102 adc ecx, 0
2103 mov DWORD PTR 20[edi],ebp
2104 ; saved r[5]
2105 ; ############### Calculate word 6
2106 xor ebp, ebp
2107 ; sqr a[3]*a[3]
2108 mul eax
2109 add ebx, eax
2110 adc ecx, edx
2111 adc ebp, 0
2112 mov DWORD PTR 24[edi],ebx
2113 ; saved r[6]
2114 mov DWORD PTR 28[edi],ecx
2115 pop ebx
2116 pop ebp
2117 pop edi
2118 pop esi
2119 ret
2120_bn_sqr_comba4 ENDP
2121_TEXT ENDS
689END 2122END
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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define bn_mul_add_words _bn_mul_add_words
13#define bn_mul_words _bn_mul_words
14#define bn_sqr_words _bn_sqr_words
15#define bn_div64 _bn_div64
16#define bn_add_words _bn_add_words
17
18#endif
19
20#ifdef OUT
21#define OK 1
22#define ALIGN 4
23#endif
24
25#ifdef BSDI
26#define OK 1
27#define ALIGN 4
28#undef SIZE
29#undef TYPE
30#define SIZE(a,b)
31#define TYPE(a,b)
32#endif
33
34#if defined(ELF) || defined(SOL)
35#define OK 1
36#define ALIGN 16
37#endif
38
39#ifndef OK
40You need to define one of
41ELF - elf systems - linux-elf, NetBSD and DG-UX
42OUT - a.out systems - linux-a.out and FreeBSD
43SOL - solaris systems, which are elf with strange comment lines
44BSDI - a.out with a very primative version of as.
45#endif
46
47/* Let the Assembler begin :-) */
48 /* Don't even think of reading this code */
49 /* It was automatically generated by bn-586.pl */
50 /* Which is a perl program used to generate the x86 assember for */
51 /* any of elf, a.out, BSDI,Win32, or Solaris */
52 /* eric <eay@cryptsoft.com> */
53
54 .file "bn-586.s"
55 .version "01.01"
56gcc2_compiled.:
57.text
58 .align ALIGN
59.globl bn_mul_add_words
60 TYPE(bn_mul_add_words,@function)
61bn_mul_add_words:
62 pushl %ebp
63 pushl %ebx
64 pushl %esi
65 pushl %edi
66
67
68 xorl %esi, %esi
69 movl 20(%esp), %edi
70 movl 28(%esp), %ecx
71 movl 24(%esp), %ebx
72 andl $4294967288, %ecx
73 movl 32(%esp), %ebp
74 pushl %ecx
75 jz .L000maw_finish
76.L001maw_loop:
77 movl %ecx, (%esp)
78 /* Round 0 */
79 movl (%ebx), %eax
80 mull %ebp
81 addl %esi, %eax
82 movl (%edi), %esi
83 adcl $0, %edx
84 addl %esi, %eax
85 adcl $0, %edx
86 movl %eax, (%edi)
87 movl %edx, %esi
88 /* Round 4 */
89 movl 4(%ebx), %eax
90 mull %ebp
91 addl %esi, %eax
92 movl 4(%edi), %esi
93 adcl $0, %edx
94 addl %esi, %eax
95 adcl $0, %edx
96 movl %eax, 4(%edi)
97 movl %edx, %esi
98 /* Round 8 */
99 movl 8(%ebx), %eax
100 mull %ebp
101 addl %esi, %eax
102 movl 8(%edi), %esi
103 adcl $0, %edx
104 addl %esi, %eax
105 adcl $0, %edx
106 movl %eax, 8(%edi)
107 movl %edx, %esi
108 /* Round 12 */
109 movl 12(%ebx), %eax
110 mull %ebp
111 addl %esi, %eax
112 movl 12(%edi), %esi
113 adcl $0, %edx
114 addl %esi, %eax
115 adcl $0, %edx
116 movl %eax, 12(%edi)
117 movl %edx, %esi
118 /* Round 16 */
119 movl 16(%ebx), %eax
120 mull %ebp
121 addl %esi, %eax
122 movl 16(%edi), %esi
123 adcl $0, %edx
124 addl %esi, %eax
125 adcl $0, %edx
126 movl %eax, 16(%edi)
127 movl %edx, %esi
128 /* Round 20 */
129 movl 20(%ebx), %eax
130 mull %ebp
131 addl %esi, %eax
132 movl 20(%edi), %esi
133 adcl $0, %edx
134 addl %esi, %eax
135 adcl $0, %edx
136 movl %eax, 20(%edi)
137 movl %edx, %esi
138 /* Round 24 */
139 movl 24(%ebx), %eax
140 mull %ebp
141 addl %esi, %eax
142 movl 24(%edi), %esi
143 adcl $0, %edx
144 addl %esi, %eax
145 adcl $0, %edx
146 movl %eax, 24(%edi)
147 movl %edx, %esi
148 /* Round 28 */
149 movl 28(%ebx), %eax
150 mull %ebp
151 addl %esi, %eax
152 movl 28(%edi), %esi
153 adcl $0, %edx
154 addl %esi, %eax
155 adcl $0, %edx
156 movl %eax, 28(%edi)
157 movl %edx, %esi
158
159 movl (%esp), %ecx
160 addl $32, %ebx
161 addl $32, %edi
162 subl $8, %ecx
163 jnz .L001maw_loop
164.L000maw_finish:
165 movl 32(%esp), %ecx
166 andl $7, %ecx
167 jnz .L002maw_finish2
168 jmp .L003maw_end
169.align ALIGN
170.L002maw_finish2:
171 /* Tail Round 0 */
172 movl (%ebx), %eax
173 mull %ebp
174 addl %esi, %eax
175 movl (%edi), %esi
176 adcl $0, %edx
177 addl %esi, %eax
178 adcl $0, %edx
179 decl %ecx
180 movl %eax, (%edi)
181 movl %edx, %esi
182 jz .L003maw_end
183 /* Tail Round 1 */
184 movl 4(%ebx), %eax
185 mull %ebp
186 addl %esi, %eax
187 movl 4(%edi), %esi
188 adcl $0, %edx
189 addl %esi, %eax
190 adcl $0, %edx
191 decl %ecx
192 movl %eax, 4(%edi)
193 movl %edx, %esi
194 jz .L003maw_end
195 /* Tail Round 2 */
196 movl 8(%ebx), %eax
197 mull %ebp
198 addl %esi, %eax
199 movl 8(%edi), %esi
200 adcl $0, %edx
201 addl %esi, %eax
202 adcl $0, %edx
203 decl %ecx
204 movl %eax, 8(%edi)
205 movl %edx, %esi
206 jz .L003maw_end
207 /* Tail Round 3 */
208 movl 12(%ebx), %eax
209 mull %ebp
210 addl %esi, %eax
211 movl 12(%edi), %esi
212 adcl $0, %edx
213 addl %esi, %eax
214 adcl $0, %edx
215 decl %ecx
216 movl %eax, 12(%edi)
217 movl %edx, %esi
218 jz .L003maw_end
219 /* Tail Round 4 */
220 movl 16(%ebx), %eax
221 mull %ebp
222 addl %esi, %eax
223 movl 16(%edi), %esi
224 adcl $0, %edx
225 addl %esi, %eax
226 adcl $0, %edx
227 decl %ecx
228 movl %eax, 16(%edi)
229 movl %edx, %esi
230 jz .L003maw_end
231 /* Tail Round 5 */
232 movl 20(%ebx), %eax
233 mull %ebp
234 addl %esi, %eax
235 movl 20(%edi), %esi
236 adcl $0, %edx
237 addl %esi, %eax
238 adcl $0, %edx
239 decl %ecx
240 movl %eax, 20(%edi)
241 movl %edx, %esi
242 jz .L003maw_end
243 /* Tail Round 6 */
244 movl 24(%ebx), %eax
245 mull %ebp
246 addl %esi, %eax
247 movl 24(%edi), %esi
248 adcl $0, %edx
249 addl %esi, %eax
250 adcl $0, %edx
251 movl %eax, 24(%edi)
252 movl %edx, %esi
253.L003maw_end:
254 movl %esi, %eax
255 popl %ecx
256 popl %edi
257 popl %esi
258 popl %ebx
259 popl %ebp
260 ret
261.bn_mul_add_words_end:
262 SIZE(bn_mul_add_words,.bn_mul_add_words_end-bn_mul_add_words)
263.ident "bn_mul_add_words"
264.text
265 .align ALIGN
266.globl bn_mul_words
267 TYPE(bn_mul_words,@function)
268bn_mul_words:
269 pushl %ebp
270 pushl %ebx
271 pushl %esi
272 pushl %edi
273
274
275 xorl %esi, %esi
276 movl 20(%esp), %edi
277 movl 24(%esp), %ebx
278 movl 28(%esp), %ebp
279 movl 32(%esp), %ecx
280 andl $4294967288, %ebp
281 jz .L004mw_finish
282.L005mw_loop:
283 /* Round 0 */
284 movl (%ebx), %eax
285 mull %ecx
286 addl %esi, %eax
287 adcl $0, %edx
288 movl %eax, (%edi)
289 movl %edx, %esi
290 /* Round 4 */
291 movl 4(%ebx), %eax
292 mull %ecx
293 addl %esi, %eax
294 adcl $0, %edx
295 movl %eax, 4(%edi)
296 movl %edx, %esi
297 /* Round 8 */
298 movl 8(%ebx), %eax
299 mull %ecx
300 addl %esi, %eax
301 adcl $0, %edx
302 movl %eax, 8(%edi)
303 movl %edx, %esi
304 /* Round 12 */
305 movl 12(%ebx), %eax
306 mull %ecx
307 addl %esi, %eax
308 adcl $0, %edx
309 movl %eax, 12(%edi)
310 movl %edx, %esi
311 /* Round 16 */
312 movl 16(%ebx), %eax
313 mull %ecx
314 addl %esi, %eax
315 adcl $0, %edx
316 movl %eax, 16(%edi)
317 movl %edx, %esi
318 /* Round 20 */
319 movl 20(%ebx), %eax
320 mull %ecx
321 addl %esi, %eax
322 adcl $0, %edx
323 movl %eax, 20(%edi)
324 movl %edx, %esi
325 /* Round 24 */
326 movl 24(%ebx), %eax
327 mull %ecx
328 addl %esi, %eax
329 adcl $0, %edx
330 movl %eax, 24(%edi)
331 movl %edx, %esi
332 /* Round 28 */
333 movl 28(%ebx), %eax
334 mull %ecx
335 addl %esi, %eax
336 adcl $0, %edx
337 movl %eax, 28(%edi)
338 movl %edx, %esi
339
340 addl $32, %ebx
341 addl $32, %edi
342 subl $8, %ebp
343 jz .L004mw_finish
344 jmp .L005mw_loop
345.L004mw_finish:
346 movl 28(%esp), %ebp
347 andl $7, %ebp
348 jnz .L006mw_finish2
349 jmp .L007mw_end
350.align ALIGN
351.L006mw_finish2:
352 /* Tail Round 0 */
353 movl (%ebx), %eax
354 mull %ecx
355 addl %esi, %eax
356 adcl $0, %edx
357 movl %eax, (%edi)
358 movl %edx, %esi
359 decl %ebp
360 jz .L007mw_end
361 /* Tail Round 1 */
362 movl 4(%ebx), %eax
363 mull %ecx
364 addl %esi, %eax
365 adcl $0, %edx
366 movl %eax, 4(%edi)
367 movl %edx, %esi
368 decl %ebp
369 jz .L007mw_end
370 /* Tail Round 2 */
371 movl 8(%ebx), %eax
372 mull %ecx
373 addl %esi, %eax
374 adcl $0, %edx
375 movl %eax, 8(%edi)
376 movl %edx, %esi
377 decl %ebp
378 jz .L007mw_end
379 /* Tail Round 3 */
380 movl 12(%ebx), %eax
381 mull %ecx
382 addl %esi, %eax
383 adcl $0, %edx
384 movl %eax, 12(%edi)
385 movl %edx, %esi
386 decl %ebp
387 jz .L007mw_end
388 /* Tail Round 4 */
389 movl 16(%ebx), %eax
390 mull %ecx
391 addl %esi, %eax
392 adcl $0, %edx
393 movl %eax, 16(%edi)
394 movl %edx, %esi
395 decl %ebp
396 jz .L007mw_end
397 /* Tail Round 5 */
398 movl 20(%ebx), %eax
399 mull %ecx
400 addl %esi, %eax
401 adcl $0, %edx
402 movl %eax, 20(%edi)
403 movl %edx, %esi
404 decl %ebp
405 jz .L007mw_end
406 /* Tail Round 6 */
407 movl 24(%ebx), %eax
408 mull %ecx
409 addl %esi, %eax
410 adcl $0, %edx
411 movl %eax, 24(%edi)
412 movl %edx, %esi
413.L007mw_end:
414 movl %esi, %eax
415 popl %edi
416 popl %esi
417 popl %ebx
418 popl %ebp
419 ret
420.bn_mul_words_end:
421 SIZE(bn_mul_words,.bn_mul_words_end-bn_mul_words)
422.ident "bn_mul_words"
423.text
424 .align ALIGN
425.globl bn_sqr_words
426 TYPE(bn_sqr_words,@function)
427bn_sqr_words:
428 pushl %ebp
429 pushl %ebx
430 pushl %esi
431 pushl %edi
432
433
434 movl 20(%esp), %esi
435 movl 24(%esp), %edi
436 movl 28(%esp), %ebx
437 andl $4294967288, %ebx
438 jz .L008sw_finish
439.L009sw_loop:
440 /* Round 0 */
441 movl (%edi), %eax
442 mull %eax
443 movl %eax, (%esi)
444 movl %edx, 4(%esi)
445 /* Round 4 */
446 movl 4(%edi), %eax
447 mull %eax
448 movl %eax, 8(%esi)
449 movl %edx, 12(%esi)
450 /* Round 8 */
451 movl 8(%edi), %eax
452 mull %eax
453 movl %eax, 16(%esi)
454 movl %edx, 20(%esi)
455 /* Round 12 */
456 movl 12(%edi), %eax
457 mull %eax
458 movl %eax, 24(%esi)
459 movl %edx, 28(%esi)
460 /* Round 16 */
461 movl 16(%edi), %eax
462 mull %eax
463 movl %eax, 32(%esi)
464 movl %edx, 36(%esi)
465 /* Round 20 */
466 movl 20(%edi), %eax
467 mull %eax
468 movl %eax, 40(%esi)
469 movl %edx, 44(%esi)
470 /* Round 24 */
471 movl 24(%edi), %eax
472 mull %eax
473 movl %eax, 48(%esi)
474 movl %edx, 52(%esi)
475 /* Round 28 */
476 movl 28(%edi), %eax
477 mull %eax
478 movl %eax, 56(%esi)
479 movl %edx, 60(%esi)
480
481 addl $32, %edi
482 addl $64, %esi
483 subl $8, %ebx
484 jnz .L009sw_loop
485.L008sw_finish:
486 movl 28(%esp), %ebx
487 andl $7, %ebx
488 jz .L010sw_end
489 /* Tail Round 0 */
490 movl (%edi), %eax
491 mull %eax
492 movl %eax, (%esi)
493 decl %ebx
494 movl %edx, 4(%esi)
495 jz .L010sw_end
496 /* Tail Round 1 */
497 movl 4(%edi), %eax
498 mull %eax
499 movl %eax, 8(%esi)
500 decl %ebx
501 movl %edx, 12(%esi)
502 jz .L010sw_end
503 /* Tail Round 2 */
504 movl 8(%edi), %eax
505 mull %eax
506 movl %eax, 16(%esi)
507 decl %ebx
508 movl %edx, 20(%esi)
509 jz .L010sw_end
510 /* Tail Round 3 */
511 movl 12(%edi), %eax
512 mull %eax
513 movl %eax, 24(%esi)
514 decl %ebx
515 movl %edx, 28(%esi)
516 jz .L010sw_end
517 /* Tail Round 4 */
518 movl 16(%edi), %eax
519 mull %eax
520 movl %eax, 32(%esi)
521 decl %ebx
522 movl %edx, 36(%esi)
523 jz .L010sw_end
524 /* Tail Round 5 */
525 movl 20(%edi), %eax
526 mull %eax
527 movl %eax, 40(%esi)
528 decl %ebx
529 movl %edx, 44(%esi)
530 jz .L010sw_end
531 /* Tail Round 6 */
532 movl 24(%edi), %eax
533 mull %eax
534 movl %eax, 48(%esi)
535 movl %edx, 52(%esi)
536.L010sw_end:
537 popl %edi
538 popl %esi
539 popl %ebx
540 popl %ebp
541 ret
542.bn_sqr_words_end:
543 SIZE(bn_sqr_words,.bn_sqr_words_end-bn_sqr_words)
544.ident "bn_sqr_words"
545.text
546 .align ALIGN
547.globl bn_div64
548 TYPE(bn_div64,@function)
549bn_div64:
550 pushl %ebp
551 pushl %ebx
552 pushl %esi
553 pushl %edi
554
555 movl 20(%esp), %edx
556 movl 24(%esp), %eax
557 movl 28(%esp), %ebx
558 divl %ebx
559 popl %edi
560 popl %esi
561 popl %ebx
562 popl %ebp
563 ret
564.bn_div64_end:
565 SIZE(bn_div64,.bn_div64_end-bn_div64)
566.ident "bn_div64"
567.text
568 .align ALIGN
569.globl bn_add_words
570 TYPE(bn_add_words,@function)
571bn_add_words:
572 pushl %ebp
573 pushl %ebx
574 pushl %esi
575 pushl %edi
576
577
578 movl 20(%esp), %ebx
579 movl 24(%esp), %esi
580 movl 28(%esp), %edi
581 movl 32(%esp), %ebp
582 xorl %eax, %eax
583 andl $4294967288, %ebp
584 jz .L011aw_finish
585.L012aw_loop:
586 /* Round 0 */
587 movl (%esi), %ecx
588 movl (%edi), %edx
589 addl %eax, %ecx
590 movl $0, %eax
591 adcl %eax, %eax
592 addl %edx, %ecx
593 adcl $0, %eax
594 movl %ecx, (%ebx)
595 /* Round 1 */
596 movl 4(%esi), %ecx
597 movl 4(%edi), %edx
598 addl %eax, %ecx
599 movl $0, %eax
600 adcl %eax, %eax
601 addl %edx, %ecx
602 adcl $0, %eax
603 movl %ecx, 4(%ebx)
604 /* Round 2 */
605 movl 8(%esi), %ecx
606 movl 8(%edi), %edx
607 addl %eax, %ecx
608 movl $0, %eax
609 adcl %eax, %eax
610 addl %edx, %ecx
611 adcl $0, %eax
612 movl %ecx, 8(%ebx)
613 /* Round 3 */
614 movl 12(%esi), %ecx
615 movl 12(%edi), %edx
616 addl %eax, %ecx
617 movl $0, %eax
618 adcl %eax, %eax
619 addl %edx, %ecx
620 adcl $0, %eax
621 movl %ecx, 12(%ebx)
622 /* Round 4 */
623 movl 16(%esi), %ecx
624 movl 16(%edi), %edx
625 addl %eax, %ecx
626 movl $0, %eax
627 adcl %eax, %eax
628 addl %edx, %ecx
629 adcl $0, %eax
630 movl %ecx, 16(%ebx)
631 /* Round 5 */
632 movl 20(%esi), %ecx
633 movl 20(%edi), %edx
634 addl %eax, %ecx
635 movl $0, %eax
636 adcl %eax, %eax
637 addl %edx, %ecx
638 adcl $0, %eax
639 movl %ecx, 20(%ebx)
640 /* Round 6 */
641 movl 24(%esi), %ecx
642 movl 24(%edi), %edx
643 addl %eax, %ecx
644 movl $0, %eax
645 adcl %eax, %eax
646 addl %edx, %ecx
647 adcl $0, %eax
648 movl %ecx, 24(%ebx)
649 /* Round 7 */
650 movl 28(%esi), %ecx
651 movl 28(%edi), %edx
652 addl %eax, %ecx
653 movl $0, %eax
654 adcl %eax, %eax
655 addl %edx, %ecx
656 adcl $0, %eax
657 movl %ecx, 28(%ebx)
658
659 addl $32, %esi
660 addl $32, %edi
661 addl $32, %ebx
662 subl $8, %ebp
663 jnz .L012aw_loop
664.L011aw_finish:
665 movl 32(%esp), %ebp
666 andl $7, %ebp
667 jz .L013aw_end
668 /* Tail Round 0 */
669 movl (%esi), %ecx
670 movl (%edi), %edx
671 addl %eax, %ecx
672 movl $0, %eax
673 adcl %eax, %eax
674 addl %edx, %ecx
675 adcl $0, %eax
676 decl %ebp
677 movl %ecx, (%ebx)
678 jz .L013aw_end
679 /* Tail Round 1 */
680 movl 4(%esi), %ecx
681 movl 4(%edi), %edx
682 addl %eax, %ecx
683 movl $0, %eax
684 adcl %eax, %eax
685 addl %edx, %ecx
686 adcl $0, %eax
687 decl %ebp
688 movl %ecx, 4(%ebx)
689 jz .L013aw_end
690 /* Tail Round 2 */
691 movl 8(%esi), %ecx
692 movl 8(%edi), %edx
693 addl %eax, %ecx
694 movl $0, %eax
695 adcl %eax, %eax
696 addl %edx, %ecx
697 adcl $0, %eax
698 decl %ebp
699 movl %ecx, 8(%ebx)
700 jz .L013aw_end
701 /* Tail Round 3 */
702 movl 12(%esi), %ecx
703 movl 12(%edi), %edx
704 addl %eax, %ecx
705 movl $0, %eax
706 adcl %eax, %eax
707 addl %edx, %ecx
708 adcl $0, %eax
709 decl %ebp
710 movl %ecx, 12(%ebx)
711 jz .L013aw_end
712 /* Tail Round 4 */
713 movl 16(%esi), %ecx
714 movl 16(%edi), %edx
715 addl %eax, %ecx
716 movl $0, %eax
717 adcl %eax, %eax
718 addl %edx, %ecx
719 adcl $0, %eax
720 decl %ebp
721 movl %ecx, 16(%ebx)
722 jz .L013aw_end
723 /* Tail Round 5 */
724 movl 20(%esi), %ecx
725 movl 20(%edi), %edx
726 addl %eax, %ecx
727 movl $0, %eax
728 adcl %eax, %eax
729 addl %edx, %ecx
730 adcl $0, %eax
731 decl %ebp
732 movl %ecx, 20(%ebx)
733 jz .L013aw_end
734 /* Tail Round 6 */
735 movl 24(%esi), %ecx
736 movl 24(%edi), %edx
737 addl %eax, %ecx
738 movl $0, %eax
739 adcl %eax, %eax
740 addl %edx, %ecx
741 adcl $0, %eax
742 movl %ecx, 24(%ebx)
743.L013aw_end:
744 movl %eax, %eax
745 popl %edi
746 popl %esi
747 popl %ebx
748 popl %ebp
749 ret
750.bn_add_words_end:
751 SIZE(bn_add_words,.bn_add_words_end-bn_add_words)
752.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 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6push(@INC,"perlasm","../../perlasm");
7require "alpha.pl";
8require "alpha/mul_add.pl";
9require "alpha/mul.pl";
10require "alpha/sqr.pl";
11require "alpha/add.pl";
12require "alpha/sub.pl";
13require "alpha/mul_c8.pl";
14require "alpha/mul_c4.pl";
15require "alpha/sqr_c4.pl";
16require "alpha/sqr_c8.pl";
17require "alpha/div.pl";
18
19&asm_init($ARGV[0],$0);
20
21&bn_mul_words("bn_mul_words");
22&bn_sqr_words("bn_sqr_words");
23&bn_mul_add_words("bn_mul_add_words");
24&bn_add_words("bn_add_words");
25&bn_sub_words("bn_sub_words");
26&bn_div_words("bn_div_words");
27&bn_mul_comba8("bn_mul_comba8");
28&bn_mul_comba4("bn_mul_comba4");
29&bn_sqr_comba4("bn_sqr_comba4");
30&bn_sqr_comba8("bn_sqr_comba8");
31
32&asm_finish();
33
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 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6&asm_init($ARGV[0],$0);
7
8&bn_mul_comba("bn_mul_comba8",8);
9&bn_mul_comba("bn_mul_comba4",4);
10&bn_sqr_comba("bn_sqr_comba8",8);
11&bn_sqr_comba("bn_sqr_comba4",4);
12
13&asm_finish();
14
15sub mul_add_c
16 {
17 local($a,$ai,$b,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
18
19 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
20 # words, and 1 if load return value
21
22 &comment("mul a[$ai]*b[$bi]");
23
24 # "eax" and "edx" will always be pre-loaded.
25 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
26 # &mov("edx",&DWP($bi*4,$b,"",0));
27
28 &mul("edx");
29 &add($c0,"eax");
30 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # laod next a
31 &mov("eax",&wparam(0)) if $pos > 0; # load r[]
32 ###
33 &adc($c1,"edx");
34 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 0; # laod next b
35 &mov("edx",&DWP(($nb)*4,$b,"",0)) if $pos == 1; # laod next b
36 ###
37 &adc($c2,0);
38 # is pos > 1, it means it is the last loop
39 &mov(&DWP($i*4,"eax","",0),$c0) if $pos > 0; # save r[];
40 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # laod next a
41 }
42
43sub sqr_add_c
44 {
45 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
46
47 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
48 # words, and 1 if load return value
49
50 &comment("sqr a[$ai]*a[$bi]");
51
52 # "eax" and "edx" will always be pre-loaded.
53 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
54 # &mov("edx",&DWP($bi*4,$b,"",0));
55
56 if ($ai == $bi)
57 { &mul("eax");}
58 else
59 { &mul("edx");}
60 &add($c0,"eax");
61 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
62 ###
63 &adc($c1,"edx");
64 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos == 1) && ($na != $nb);
65 ###
66 &adc($c2,0);
67 # is pos > 1, it means it is the last loop
68 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
69 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
70 }
71
72sub sqr_add_c2
73 {
74 local($r,$a,$ai,$bi,$c0,$c1,$c2,$pos,$i,$na,$nb)=@_;
75
76 # pos == -1 if eax and edx are pre-loaded, 0 to load from next
77 # words, and 1 if load return value
78
79 &comment("sqr a[$ai]*a[$bi]");
80
81 # "eax" and "edx" will always be pre-loaded.
82 # &mov("eax",&DWP($ai*4,$a,"",0)) ;
83 # &mov("edx",&DWP($bi*4,$a,"",0));
84
85 if ($ai == $bi)
86 { &mul("eax");}
87 else
88 { &mul("edx");}
89 &add("eax","eax");
90 ###
91 &adc("edx","edx");
92 ###
93 &adc($c2,0);
94 &add($c0,"eax");
95 &adc($c1,"edx");
96 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 0; # load next a
97 &mov("eax",&DWP(($na)*4,$a,"",0)) if $pos == 1; # load next b
98 &adc($c2,0);
99 &mov(&DWP($i*4,$r,"",0),$c0) if $pos > 0; # save r[];
100 &mov("edx",&DWP(($nb)*4,$a,"",0)) if ($pos <= 1) && ($na != $nb);
101 ###
102 }
103
104sub bn_mul_comba
105 {
106 local($name,$num)=@_;
107 local($a,$b,$c0,$c1,$c2);
108 local($i,$as,$ae,$bs,$be,$ai,$bi);
109 local($tot,$end);
110
111 &function_begin_B($name,"");
112
113 $c0="ebx";
114 $c1="ecx";
115 $c2="ebp";
116 $a="esi";
117 $b="edi";
118
119 $as=0;
120 $ae=0;
121 $bs=0;
122 $be=0;
123 $tot=$num+$num-1;
124
125 &push("esi");
126 &mov($a,&wparam(1));
127 &push("edi");
128 &mov($b,&wparam(2));
129 &push("ebp");
130 &push("ebx");
131
132 &xor($c0,$c0);
133 &mov("eax",&DWP(0,$a,"",0)); # load the first word
134 &xor($c1,$c1);
135 &mov("edx",&DWP(0,$b,"",0)); # load the first second
136
137 for ($i=0; $i<$tot; $i++)
138 {
139 $ai=$as;
140 $bi=$bs;
141 $end=$be+1;
142
143 &comment("################## Calculate word $i");
144
145 for ($j=$bs; $j<$end; $j++)
146 {
147 &xor($c2,$c2) if ($j == $bs);
148 if (($j+1) == $end)
149 {
150 $v=1;
151 $v=2 if (($i+1) == $tot);
152 }
153 else
154 { $v=0; }
155 if (($j+1) != $end)
156 {
157 $na=($ai-1);
158 $nb=($bi+1);
159 }
160 else
161 {
162 $na=$as+($i < ($num-1));
163 $nb=$bs+($i >= ($num-1));
164 }
165#printf STDERR "[$ai,$bi] -> [$na,$nb]\n";
166 &mul_add_c($a,$ai,$b,$bi,$c0,$c1,$c2,$v,$i,$na,$nb);
167 if ($v)
168 {
169 &comment("saved r[$i]");
170 # &mov("eax",&wparam(0));
171 # &mov(&DWP($i*4,"eax","",0),$c0);
172 ($c0,$c1,$c2)=($c1,$c2,$c0);
173 }
174 $ai--;
175 $bi++;
176 }
177 $as++ if ($i < ($num-1));
178 $ae++ if ($i >= ($num-1));
179
180 $bs++ if ($i >= ($num-1));
181 $be++ if ($i < ($num-1));
182 }
183 &comment("save r[$i]");
184 # &mov("eax",&wparam(0));
185 &mov(&DWP($i*4,"eax","",0),$c0);
186
187 &pop("ebx");
188 &pop("ebp");
189 &pop("edi");
190 &pop("esi");
191 &ret();
192 &function_end_B($name);
193 }
194
195sub bn_sqr_comba
196 {
197 local($name,$num)=@_;
198 local($r,$a,$c0,$c1,$c2)=@_;
199 local($i,$as,$ae,$bs,$be,$ai,$bi);
200 local($b,$tot,$end,$half);
201
202 &function_begin_B($name,"");
203
204 $c0="ebx";
205 $c1="ecx";
206 $c2="ebp";
207 $a="esi";
208 $r="edi";
209
210 &push("esi");
211 &push("edi");
212 &push("ebp");
213 &push("ebx");
214 &mov($r,&wparam(0));
215 &mov($a,&wparam(1));
216 &xor($c0,$c0);
217 &xor($c1,$c1);
218 &mov("eax",&DWP(0,$a,"",0)); # load the first word
219
220 $as=0;
221 $ae=0;
222 $bs=0;
223 $be=0;
224 $tot=$num+$num-1;
225
226 for ($i=0; $i<$tot; $i++)
227 {
228 $ai=$as;
229 $bi=$bs;
230 $end=$be+1;
231
232 &comment("############### Calculate word $i");
233 for ($j=$bs; $j<$end; $j++)
234 {
235 &xor($c2,$c2) if ($j == $bs);
236 if (($ai-1) < ($bi+1))
237 {
238 $v=1;
239 $v=2 if ($i+1) == $tot;
240 }
241 else
242 { $v=0; }
243 if (!$v)
244 {
245 $na=$ai-1;
246 $nb=$bi+1;
247 }
248 else
249 {
250 $na=$as+($i < ($num-1));
251 $nb=$bs+($i >= ($num-1));
252 }
253 if ($ai == $bi)
254 {
255 &sqr_add_c($r,$a,$ai,$bi,
256 $c0,$c1,$c2,$v,$i,$na,$nb);
257 }
258 else
259 {
260 &sqr_add_c2($r,$a,$ai,$bi,
261 $c0,$c1,$c2,$v,$i,$na,$nb);
262 }
263 if ($v)
264 {
265 &comment("saved r[$i]");
266 #&mov(&DWP($i*4,$r,"",0),$c0);
267 ($c0,$c1,$c2)=($c1,$c2,$c0);
268 last;
269 }
270 $ai--;
271 $bi++;
272 }
273 $as++ if ($i < ($num-1));
274 $ae++ if ($i >= ($num-1));
275
276 $bs++ if ($i >= ($num-1));
277 $be++ if ($i < ($num-1));
278 }
279 &mov(&DWP($i*4,$r,"",0),$c0);
280 &pop("ebx");
281 &pop("ebp");
282 &pop("edi");
283 &pop("esi");
284 &ret();
285 &function_end_B($name);
286 }
diff --git a/src/lib/libcrypto/bn/asm/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 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6push(@INC,"perlasm","../../perlasm");
7require "alpha.pl";
8
9&asm_init($ARGV[0],$0);
10
11print &bn_sub_words("bn_sub_words");
12
13&asm_finish();
14
15sub bn_sub_words
16 {
17 local($name)=@_;
18 local($cc,$a,$b,$r);
19
20 $cc="r0";
21 $a0="r1"; $b0="r5"; $r0="r9"; $tmp="r13";
22 $a1="r2"; $b1="r6"; $r1="r10"; $t1="r14";
23 $a2="r3"; $b2="r7"; $r2="r11";
24 $a3="r4"; $b3="r8"; $r3="r12"; $t3="r15";
25
26 $rp=&wparam(0);
27 $ap=&wparam(1);
28 $bp=&wparam(2);
29 $count=&wparam(3);
30
31 &function_begin($name,"");
32
33 &comment("");
34 &sub($count,4,$count);
35 &mov("zero",$cc);
36 &blt($count,&label("finish"));
37
38 &ld($a0,&QWPw(0,$ap));
39 &ld($b0,&QWPw(0,$bp));
40
41##########################################################
42 &set_label("loop");
43
44 &ld($a1,&QWPw(1,$ap));
45 &cmpult($a0,$b0,$tmp); # will we borrow?
46 &ld($b1,&QWPw(1,$bp));
47 &sub($a0,$b0,$a0); # do the subtract
48 &ld($a2,&QWPw(2,$ap));
49 &cmpult($a0,$cc,$b0); # will we borrow?
50 &ld($b2,&QWPw(2,$bp));
51 &sub($a0,$cc,$a0); # will we borrow?
52 &ld($a3,&QWPw(3,$ap));
53 &add($b0,$tmp,$cc); # add the borrows
54
55 &cmpult($a1,$b1,$t1); # will we borrow?
56 &sub($a1,$b1,$a1); # do the subtract
57 &ld($b3,&QWPw(3,$bp));
58 &cmpult($a1,$cc,$b1); # will we borrow?
59 &sub($a1,$cc,$a1); # will we borrow?
60 &add($b1,$t1,$cc); # add the borrows
61
62 &cmpult($a2,$b2,$tmp); # will we borrow?
63 &sub($a2,$b2,$a2); # do the subtract
64 &st($a0,&QWPw(0,$rp)); # save
65 &cmpult($a2,$cc,$b2); # will we borrow?
66 &sub($a2,$cc,$a2); # will we borrow?
67 &add($b2,$tmp,$cc); # add the borrows
68
69 &cmpult($a3,$b3,$t3); # will we borrow?
70 &sub($a3,$b3,$a3); # do the subtract
71 &st($a1,&QWPw(1,$rp)); # save
72 &cmpult($a3,$cc,$b3); # will we borrow?
73 &sub($a3,$cc,$a3); # will we borrow?
74 &add($b3,$t3,$cc); # add the borrows
75
76 &st($a2,&QWPw(2,$rp)); # save
77 &sub($count,4,$count); # count-=4
78 &st($a3,&QWPw(3,$rp)); # save
79 &add($ap,4*$QWS,$ap); # count+=4
80 &add($bp,4*$QWS,$bp); # count+=4
81 &add($rp,4*$QWS,$rp); # count+=4
82
83 &blt($count,&label("finish"));
84 &ld($a0,&QWPw(0,$ap));
85 &ld($b0,&QWPw(0,$bp));
86 &br(&label("loop"));
87##################################################
88 # Do the last 0..3 words
89
90 &set_label("last_loop");
91
92 &ld($a0,&QWPw(0,$ap)); # get a
93 &ld($b0,&QWPw(0,$bp)); # get b
94 &cmpult($a0,$b0,$tmp); # will we borrow?
95 &sub($a0,$b0,$a0); # do the subtract
96 &cmpult($a0,$cc,$b0); # will we borrow?
97 &sub($a0,$cc,$a0); # will we borrow?
98 &st($a0,&QWPw(0,$rp)); # save
99 &add($b0,$tmp,$cc); # add the borrows
100
101 &add($ap,$QWS,$ap);
102 &add($bp,$QWS,$bp);
103 &add($rp,$QWS,$rp);
104 &sub($count,1,$count);
105 &bgt($count,&label("last_loop"));
106 &function_end_A($name);
107
108######################################################
109 &set_label("finish");
110 &add($count,4,$count);
111 &bgt($count,&label("last_loop"));
112
113 &set_label("end");
114 &function_end($name);
115 }
116
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 @@
1/* This assember is for R2000/R3000 machines, or higher ones that do
2 * no want to do any 64 bit arithmatic.
3 * Make sure that the SSLeay bignum library is compiled with
4 * THIRTY_TWO_BIT set.
5 * This must either be compiled with the system CC, or, if you use GNU gas,
6 * cc -E mips1.s|gas -o mips1.o
7 */
8 .set reorder
9 .set noat
10
11#define R1 $1
12#define CC $2
13#define R2 $3
14#define R3 $8
15#define R4 $9
16#define L1 $10
17#define L2 $11
18#define L3 $12
19#define L4 $13
20#define H1 $14
21#define H2 $15
22#define H3 $24
23#define H4 $25
24
25#define P1 $4
26#define P2 $5
27#define P3 $6
28#define P4 $7
29
30 .align 2
31 .ent bn_mul_add_words
32 .globl bn_mul_add_words
33.text
34bn_mul_add_words:
35 .frame $sp,0,$31
36 .mask 0x00000000,0
37 .fmask 0x00000000,0
38
39 #blt P3,4,$lab34
40
41 subu R1,P3,4
42 move CC,$0
43 bltz R1,$lab34
44$lab2:
45 lw R1,0(P1)
46 lw L1,0(P2)
47 lw R2,4(P1)
48 lw L2,4(P2)
49 lw R3,8(P1)
50 lw L3,8(P2)
51 lw R4,12(P1)
52 lw L4,12(P2)
53 multu L1,P4
54 addu R1,R1,CC
55 mflo L1
56 sltu CC,R1,CC
57 addu R1,R1,L1
58 mfhi H1
59 sltu L1,R1,L1
60 sw R1,0(P1)
61 addu CC,CC,L1
62 multu L2,P4
63 addu CC,H1,CC
64 mflo L2
65 addu R2,R2,CC
66 sltu CC,R2,CC
67 mfhi H2
68 addu R2,R2,L2
69 addu P2,P2,16
70 sltu L2,R2,L2
71 sw R2,4(P1)
72 addu CC,CC,L2
73 multu L3,P4
74 addu CC,H2,CC
75 mflo L3
76 addu R3,R3,CC
77 sltu CC,R3,CC
78 mfhi H3
79 addu R3,R3,L3
80 addu P1,P1,16
81 sltu L3,R3,L3
82 sw R3,-8(P1)
83 addu CC,CC,L3
84 multu L4,P4
85 addu CC,H3,CC
86 mflo L4
87 addu R4,R4,CC
88 sltu CC,R4,CC
89 mfhi H4
90 addu R4,R4,L4
91 subu P3,P3,4
92 sltu L4,R4,L4
93 addu CC,CC,L4
94 addu CC,H4,CC
95
96 subu R1,P3,4
97 sw R4,-4(P1) # delay slot
98 bgez R1,$lab2
99
100 bleu P3,0,$lab3
101 .align 2
102$lab33:
103 lw L1,0(P2)
104 lw R1,0(P1)
105 multu L1,P4
106 addu R1,R1,CC
107 sltu CC,R1,CC
108 addu P1,P1,4
109 mflo L1
110 mfhi H1
111 addu R1,R1,L1
112 addu P2,P2,4
113 sltu L1,R1,L1
114 subu P3,P3,1
115 addu CC,CC,L1
116 sw R1,-4(P1)
117 addu CC,H1,CC
118 bgtz P3,$lab33
119 j $31
120 .align 2
121$lab3:
122 j $31
123 .align 2
124$lab34:
125 bgt P3,0,$lab33
126 j $31
127 .end bn_mul_add_words
128
129 .align 2
130 # Program Unit: bn_mul_words
131 .ent bn_mul_words
132 .globl bn_mul_words
133.text
134bn_mul_words:
135 .frame $sp,0,$31
136 .mask 0x00000000,0
137 .fmask 0x00000000,0
138
139 subu P3,P3,4
140 move CC,$0
141 bltz P3,$lab45
142$lab44:
143 lw L1,0(P2)
144 lw L2,4(P2)
145 lw L3,8(P2)
146 lw L4,12(P2)
147 multu L1,P4
148 subu P3,P3,4
149 mflo L1
150 mfhi H1
151 addu L1,L1,CC
152 multu L2,P4
153 sltu CC,L1,CC
154 sw L1,0(P1)
155 addu CC,H1,CC
156 mflo L2
157 mfhi H2
158 addu L2,L2,CC
159 multu L3,P4
160 sltu CC,L2,CC
161 sw L2,4(P1)
162 addu CC,H2,CC
163 mflo L3
164 mfhi H3
165 addu L3,L3,CC
166 multu L4,P4
167 sltu CC,L3,CC
168 sw L3,8(P1)
169 addu CC,H3,CC
170 mflo L4
171 mfhi H4
172 addu L4,L4,CC
173 addu P1,P1,16
174 sltu CC,L4,CC
175 addu P2,P2,16
176 addu CC,H4,CC
177 sw L4,-4(P1)
178
179 bgez P3,$lab44
180 b $lab45
181$lab46:
182 lw L1,0(P2)
183 addu P1,P1,4
184 multu L1,P4
185 addu P2,P2,4
186 mflo L1
187 mfhi H1
188 addu L1,L1,CC
189 subu P3,P3,1
190 sltu CC,L1,CC
191 sw L1,-4(P1)
192 addu CC,H1,CC
193 bgtz P3,$lab46
194 j $31
195$lab45:
196 addu P3,P3,4
197 bgtz P3,$lab46
198 j $31
199 .align 2
200 .end bn_mul_words
201
202 # Program Unit: bn_sqr_words
203 .ent bn_sqr_words
204 .globl bn_sqr_words
205.text
206bn_sqr_words:
207 .frame $sp,0,$31
208 .mask 0x00000000,0
209 .fmask 0x00000000,0
210
211 subu P3,P3,4
212 bltz P3,$lab55
213$lab54:
214 lw L1,0(P2)
215 lw L2,4(P2)
216 lw L3,8(P2)
217 lw L4,12(P2)
218
219 multu L1,L1
220 subu P3,P3,4
221 mflo L1
222 mfhi H1
223 sw L1,0(P1)
224 sw H1,4(P1)
225
226 multu L2,L2
227 addu P1,P1,32
228 mflo L2
229 mfhi H2
230 sw L2,-24(P1)
231 sw H2,-20(P1)
232
233 multu L3,L3
234 addu P2,P2,16
235 mflo L3
236 mfhi H3
237 sw L3,-16(P1)
238 sw H3,-12(P1)
239
240 multu L4,L4
241
242 mflo L4
243 mfhi H4
244 sw L4,-8(P1)
245 sw H4,-4(P1)
246
247 bgtz P3,$lab54
248 b $lab55
249$lab56:
250 lw L1,0(P2)
251 addu P1,P1,8
252 multu L1,L1
253 addu P2,P2,4
254 subu P3,P3,1
255 mflo L1
256 mfhi H1
257 sw L1,-8(P1)
258 sw H1,-4(P1)
259
260 bgtz P3,$lab56
261 j $31
262$lab55:
263 addu P3,P3,4
264 bgtz P3,$lab56
265 j $31
266 .align 2
267 .end bn_sqr_words
268
269 # Program Unit: bn_add_words
270 .ent bn_add_words
271 .globl bn_add_words
272.text
273bn_add_words: # 0x590
274 .frame $sp,0,$31
275 .mask 0x00000000,0
276 .fmask 0x00000000,0
277
278 subu P4,P4,4
279 move CC,$0
280 bltz P4,$lab65
281$lab64:
282 lw L1,0(P2)
283 lw R1,0(P3)
284 lw L2,4(P2)
285 lw R2,4(P3)
286
287 addu L1,L1,CC
288 lw L3,8(P2)
289 sltu CC,L1,CC
290 addu L1,L1,R1
291 sltu R1,L1,R1
292 lw R3,8(P3)
293 addu CC,CC,R1
294 lw L4,12(P2)
295
296 addu L2,L2,CC
297 lw R4,12(P3)
298 sltu CC,L2,CC
299 addu L2,L2,R2
300 sltu R2,L2,R2
301 sw L1,0(P1)
302 addu CC,CC,R2
303 addu P1,P1,16
304 addu L3,L3,CC
305 sw L2,-12(P1)
306
307 sltu CC,L3,CC
308 addu L3,L3,R3
309 sltu R3,L3,R3
310 addu P2,P2,16
311 addu CC,CC,R3
312
313 addu L4,L4,CC
314 addu P3,P3,16
315 sltu CC,L4,CC
316 addu L4,L4,R4
317 subu P4,P4,4
318 sltu R4,L4,R4
319 sw L3,-8(P1)
320 addu CC,CC,R4
321 sw L4,-4(P1)
322
323 bgtz P4,$lab64
324 b $lab65
325$lab66:
326 lw L1,0(P2)
327 lw R1,0(P3)
328 addu L1,L1,CC
329 addu P1,P1,4
330 sltu CC,L1,CC
331 addu P2,P2,4
332 addu P3,P3,4
333 addu L1,L1,R1
334 subu P4,P4,1
335 sltu R1,L1,R1
336 sw L1,-4(P1)
337 addu CC,CC,R1
338
339 bgtz P4,$lab66
340 j $31
341$lab65:
342 addu P4,P4,4
343 bgtz P4,$lab66
344 j $31
345 .end bn_add_words
346
347 # Program Unit: bn_div64
348 .set at
349 .set reorder
350 .text
351 .align 2
352 .globl bn_div64
353 # 321 {
354 .ent bn_div64 2
355bn_div64:
356 subu $sp, 64
357 sw $31, 56($sp)
358 sw $16, 48($sp)
359 .mask 0x80010000, -56
360 .frame $sp, 64, $31
361 move $9, $4
362 move $12, $5
363 move $16, $6
364 # 322 BN_ULONG dh,dl,q,ret=0,th,tl,t;
365 move $31, $0
366 # 323 int i,count=2;
367 li $13, 2
368 # 324
369 # 325 if (d == 0) return(BN_MASK2);
370 bne $16, 0, $80
371 li $2, -1
372 b $93
373$80:
374 # 326
375 # 327 i=BN_num_bits_word(d);
376 move $4, $16
377 sw $31, 16($sp)
378 sw $9, 24($sp)
379 sw $12, 32($sp)
380 sw $13, 40($sp)
381 .livereg 0x800ff0e,0xfff
382 jal BN_num_bits_word
383 li $4, 32
384 lw $31, 16($sp)
385 lw $9, 24($sp)
386 lw $12, 32($sp)
387 lw $13, 40($sp)
388 move $3, $2
389 # 328 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i))
390 beq $2, $4, $81
391 li $14, 1
392 sll $15, $14, $2
393 bleu $9, $15, $81
394 # 329 {
395 # 330 #if !defined(NO_STDIO) && !defined(WIN16)
396 # 331 fprintf(stderr,"Division would overflow (%d)\n",i);
397 # 332 #endif
398 # 333 abort();
399 sw $3, 8($sp)
400 sw $9, 24($sp)
401 sw $12, 32($sp)
402 sw $13, 40($sp)
403 sw $31, 26($sp)
404 .livereg 0xff0e,0xfff
405 jal abort
406 lw $3, 8($sp)
407 li $4, 32
408 lw $9, 24($sp)
409 lw $12, 32($sp)
410 lw $13, 40($sp)
411 lw $31, 26($sp)
412 # 334 }
413$81:
414 # 335 i=BN_BITS2-i;
415 subu $3, $4, $3
416 # 336 if (h >= d) h-=d;
417 bltu $9, $16, $82
418 subu $9, $9, $16
419$82:
420 # 337
421 # 338 if (i)
422 beq $3, 0, $83
423 # 339 {
424 # 340 d<<=i;
425 sll $16, $16, $3
426 # 341 h=(h<<i)|(l>>(BN_BITS2-i));
427 sll $24, $9, $3
428 subu $25, $4, $3
429 srl $14, $12, $25
430 or $9, $24, $14
431 # 342 l<<=i;
432 sll $12, $12, $3
433 # 343 }
434$83:
435 # 344 dh=(d&BN_MASK2h)>>BN_BITS4;
436 # 345 dl=(d&BN_MASK2l);
437 and $8, $16, -65536
438 srl $8, $8, 16
439 and $10, $16, 65535
440 li $6, -65536
441$84:
442 # 346 for (;;)
443 # 347 {
444 # 348 if ((h>>BN_BITS4) == dh)
445 srl $15, $9, 16
446 bne $8, $15, $85
447 # 349 q=BN_MASK2l;
448 li $5, 65535
449 b $86
450$85:
451 # 350 else
452 # 351 q=h/dh;
453 divu $5, $9, $8
454$86:
455 # 352
456 # 353 for (;;)
457 # 354 {
458 # 355 t=(h-q*dh);
459 mul $4, $5, $8
460 subu $2, $9, $4
461 move $3, $2
462 # 356 if ((t&BN_MASK2h) ||
463 # 357 ((dl*q) <= (
464 # 358 (t<<BN_BITS4)+
465 # 359 ((l&BN_MASK2h)>>BN_BITS4))))
466 and $25, $2, $6
467 bne $25, $0, $87
468 mul $24, $10, $5
469 sll $14, $3, 16
470 and $15, $12, $6
471 srl $25, $15, 16
472 addu $15, $14, $25
473 bgtu $24, $15, $88
474$87:
475 # 360 break;
476 mul $3, $10, $5
477 b $89
478$88:
479 # 361 q--;
480 addu $5, $5, -1
481 # 362 }
482 b $86
483$89:
484 # 363 th=q*dh;
485 # 364 tl=q*dl;
486 # 365 t=(tl>>BN_BITS4);
487 # 366 tl=(tl<<BN_BITS4)&BN_MASK2h;
488 sll $14, $3, 16
489 and $2, $14, $6
490 move $11, $2
491 # 367 th+=t;
492 srl $25, $3, 16
493 addu $7, $4, $25
494 # 368
495 # 369 if (l < tl) th++;
496 bgeu $12, $2, $90
497 addu $7, $7, 1
498$90:
499 # 370 l-=tl;
500 subu $12, $12, $11
501 # 371 if (h < th)
502 bgeu $9, $7, $91
503 # 372 {
504 # 373 h+=d;
505 addu $9, $9, $16
506 # 374 q--;
507 addu $5, $5, -1
508 # 375 }
509$91:
510 # 376 h-=th;
511 subu $9, $9, $7
512 # 377
513 # 378 if (--count == 0) break;
514 addu $13, $13, -1
515 beq $13, 0, $92
516 # 379
517 # 380 ret=q<<BN_BITS4;
518 sll $31, $5, 16
519 # 381 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
520 sll $24, $9, 16
521 srl $15, $12, 16
522 or $9, $24, $15
523 # 382 l=(l&BN_MASK2l)<<BN_BITS4;
524 and $12, $12, 65535
525 sll $12, $12, 16
526 # 383 }
527 b $84
528$92:
529 # 384 ret|=q;
530 or $31, $31, $5
531 # 385 return(ret);
532 move $2, $31
533$93:
534 lw $16, 48($sp)
535 lw $31, 56($sp)
536 addu $sp, 64
537 j $31
538 .end bn_div64
539
diff --git a/src/lib/libcrypto/bn/asm/mips3.s b/src/lib/libcrypto/bn/asm/mips3.s
new file mode 100644
index 0000000000..191345d920
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/mips3.s
@@ -0,0 +1,2138 @@
1.rdata
2.asciiz "mips3.s, Version 1.0"
3.asciiz "MIPS III/IV ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
4
5/*
6 * ====================================================================
7 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
8 * project.
9 *
10 * Rights for redistribution and usage in source and binary forms are
11 * granted according to the OpenSSL license. Warranty of any kind is
12 * disclaimed.
13 * ====================================================================
14 */
15
16/*
17 * This is my modest contributon to the OpenSSL project (see
18 * http://www.openssl.org/ for more information about it) and is
19 * a drop-in MIPS III/IV ISA replacement for crypto/bn/bn_asm.c
20 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
21 *
22 * The module is designed to work with either of the "new" MIPS ABI(5),
23 * namely N32 or N64, offered by IRIX 6.x. It's not ment to work under
24 * IRIX 5.x not only because it doesn't support new ABIs but also
25 * because 5.x kernels put R4x00 CPU into 32-bit mode and all those
26 * 64-bit instructions (daddu, dmultu, etc.) found below gonna only
27 * cause illegal instruction exception:-(
28 *
29 * In addition the code depends on preprocessor flags set up by MIPSpro
30 * compiler driver (either as or cc) and therefore (probably?) can't be
31 * compiled by the GNU assembler. GNU C driver manages fine though...
32 * I mean as long as -mmips-as is specified or is the default option,
33 * because then it simply invokes /usr/bin/as which in turn takes
34 * perfect care of the preprocessor definitions. Another neat feature
35 * offered by the MIPSpro assembler is an optimization pass. This gave
36 * me the opportunity to have the code looking more regular as all those
37 * architecture dependent instruction rescheduling details were left to
38 * the assembler. Cool, huh?
39 *
40 * Performance improvement is astonishing! 'apps/openssl speed rsa dsa'
41 * goes way over 3 times faster!
42 *
43 * <appro@fy.chalmers.se>
44 */
45#include <asm.h>
46#include <regdef.h>
47
48#if _MIPS_ISA>=4
49#define MOVNZ(cond,dst,src) \
50 movn dst,src,cond
51#else
52#define MOVNZ(cond,dst,src) \
53 .set noreorder; \
54 bnezl cond,.+8; \
55 move dst,src; \
56 .set reorder
57#endif
58
59.text
60
61.set noat
62.set reorder
63
64#define MINUS4 v1
65
66.align 5
67LEAF(bn_mul_add_words)
68 .set noreorder
69 bgtzl a2,.L_bn_mul_add_words_proceed
70 ld t0,0(a1)
71 jr ra
72 move v0,zero
73 .set reorder
74
75.L_bn_mul_add_words_proceed:
76 li MINUS4,-4
77 and ta0,a2,MINUS4
78 move v0,zero
79 beqz ta0,.L_bn_mul_add_words_tail
80
81.L_bn_mul_add_words_loop:
82 dmultu t0,a3
83 ld t1,0(a0)
84 ld t2,8(a1)
85 ld t3,8(a0)
86 ld ta0,16(a1)
87 ld ta1,16(a0)
88 daddu t1,v0
89 sltu v0,t1,v0 /* All manuals say it "compares 32-bit
90 * values", but it seems to work fine
91 * even on 64-bit registers. */
92 mflo AT
93 mfhi t0
94 daddu t1,AT
95 daddu v0,t0
96 sltu AT,t1,AT
97 sd t1,0(a0)
98 daddu v0,AT
99
100 dmultu t2,a3
101 ld ta2,24(a1)
102 ld ta3,24(a0)
103 daddu t3,v0
104 sltu v0,t3,v0
105 mflo AT
106 mfhi t2
107 daddu t3,AT
108 daddu v0,t2
109 sltu AT,t3,AT
110 sd t3,8(a0)
111 daddu v0,AT
112
113 dmultu ta0,a3
114 subu a2,4
115 PTR_ADD a0,32
116 PTR_ADD a1,32
117 daddu ta1,v0
118 sltu v0,ta1,v0
119 mflo AT
120 mfhi ta0
121 daddu ta1,AT
122 daddu v0,ta0
123 sltu AT,ta1,AT
124 sd ta1,-16(a0)
125 daddu v0,AT
126
127
128 dmultu ta2,a3
129 and ta0,a2,MINUS4
130 daddu ta3,v0
131 sltu v0,ta3,v0
132 mflo AT
133 mfhi ta2
134 daddu ta3,AT
135 daddu v0,ta2
136 sltu AT,ta3,AT
137 sd ta3,-8(a0)
138 daddu v0,AT
139 .set noreorder
140 bgtzl ta0,.L_bn_mul_add_words_loop
141 ld t0,0(a1)
142
143 bnezl a2,.L_bn_mul_add_words_tail
144 ld t0,0(a1)
145 .set reorder
146
147.L_bn_mul_add_words_return:
148 jr ra
149
150.L_bn_mul_add_words_tail:
151 dmultu t0,a3
152 ld t1,0(a0)
153 subu a2,1
154 daddu t1,v0
155 sltu v0,t1,v0
156 mflo AT
157 mfhi t0
158 daddu t1,AT
159 daddu v0,t0
160 sltu AT,t1,AT
161 sd t1,0(a0)
162 daddu v0,AT
163 beqz a2,.L_bn_mul_add_words_return
164
165 ld t0,8(a1)
166 dmultu t0,a3
167 ld t1,8(a0)
168 subu a2,1
169 daddu t1,v0
170 sltu v0,t1,v0
171 mflo AT
172 mfhi t0
173 daddu t1,AT
174 daddu v0,t0
175 sltu AT,t1,AT
176 sd t1,8(a0)
177 daddu v0,AT
178 beqz a2,.L_bn_mul_add_words_return
179
180 ld t0,16(a1)
181 dmultu t0,a3
182 ld t1,16(a0)
183 daddu t1,v0
184 sltu v0,t1,v0
185 mflo AT
186 mfhi t0
187 daddu t1,AT
188 daddu v0,t0
189 sltu AT,t1,AT
190 sd t1,16(a0)
191 daddu v0,AT
192 jr ra
193END(bn_mul_add_words)
194
195.align 5
196LEAF(bn_mul_words)
197 .set noreorder
198 bgtzl a2,.L_bn_mul_words_proceed
199 ld t0,0(a1)
200 jr ra
201 move v0,zero
202 .set reorder
203
204.L_bn_mul_words_proceed:
205 li MINUS4,-4
206 and ta0,a2,MINUS4
207 move v0,zero
208 beqz ta0,.L_bn_mul_words_tail
209
210.L_bn_mul_words_loop:
211 dmultu t0,a3
212 ld t2,8(a1)
213 ld ta0,16(a1)
214 ld ta2,24(a1)
215 mflo AT
216 mfhi t0
217 daddu v0,AT
218 sltu t1,v0,AT
219 sd v0,0(a0)
220 daddu v0,t1,t0
221
222 dmultu t2,a3
223 subu a2,4
224 PTR_ADD a0,32
225 PTR_ADD a1,32
226 mflo AT
227 mfhi t2
228 daddu v0,AT
229 sltu t3,v0,AT
230 sd v0,-24(a0)
231 daddu v0,t3,t2
232
233 dmultu ta0,a3
234 mflo AT
235 mfhi ta0
236 daddu v0,AT
237 sltu ta1,v0,AT
238 sd v0,-16(a0)
239 daddu v0,ta1,ta0
240
241
242 dmultu ta2,a3
243 and ta0,a2,MINUS4
244 mflo AT
245 mfhi ta2
246 daddu v0,AT
247 sltu ta3,v0,AT
248 sd v0,-8(a0)
249 daddu v0,ta3,ta2
250 .set noreorder
251 bgtzl ta0,.L_bn_mul_words_loop
252 ld t0,0(a1)
253
254 bnezl a2,.L_bn_mul_words_tail
255 ld t0,0(a1)
256 .set reorder
257
258.L_bn_mul_words_return:
259 jr ra
260
261.L_bn_mul_words_tail:
262 dmultu t0,a3
263 subu a2,1
264 mflo AT
265 mfhi t0
266 daddu v0,AT
267 sltu t1,v0,AT
268 sd v0,0(a0)
269 daddu v0,t1,t0
270 beqz a2,.L_bn_mul_words_return
271
272 ld t0,8(a1)
273 dmultu t0,a3
274 subu a2,1
275 mflo AT
276 mfhi t0
277 daddu v0,AT
278 sltu t1,v0,AT
279 sd v0,8(a0)
280 daddu v0,t1,t0
281 beqz a2,.L_bn_mul_words_return
282
283 ld t0,16(a1)
284 dmultu t0,a3
285 mflo AT
286 mfhi t0
287 daddu v0,AT
288 sltu t1,v0,AT
289 sd v0,16(a0)
290 daddu v0,t1,t0
291 jr ra
292END(bn_mul_words)
293
294.align 5
295LEAF(bn_sqr_words)
296 .set noreorder
297 bgtzl a2,.L_bn_sqr_words_proceed
298 ld t0,0(a1)
299 jr ra
300 move v0,zero
301 .set reorder
302
303.L_bn_sqr_words_proceed:
304 li MINUS4,-4
305 and ta0,a2,MINUS4
306 move v0,zero
307 beqz ta0,.L_bn_sqr_words_tail
308
309.L_bn_sqr_words_loop:
310 dmultu t0,t0
311 ld t2,8(a1)
312 ld ta0,16(a1)
313 ld ta2,24(a1)
314 mflo t1
315 mfhi t0
316 sd t1,0(a0)
317 sd t0,8(a0)
318
319 dmultu t2,t2
320 subu a2,4
321 PTR_ADD a0,64
322 PTR_ADD a1,32
323 mflo t3
324 mfhi t2
325 sd t3,-48(a0)
326 sd t2,-40(a0)
327
328 dmultu ta0,ta0
329 mflo ta1
330 mfhi ta0
331 sd ta1,-32(a0)
332 sd ta0,-24(a0)
333
334
335 dmultu ta2,ta2
336 and ta0,a2,MINUS4
337 mflo ta3
338 mfhi ta2
339 sd ta3,-16(a0)
340 sd ta2,-8(a0)
341
342 .set noreorder
343 bgtzl ta0,.L_bn_sqr_words_loop
344 ld t0,0(a1)
345
346 bnezl a2,.L_bn_sqr_words_tail
347 ld t0,0(a1)
348 .set reorder
349
350.L_bn_sqr_words_return:
351 move v0,zero
352 jr ra
353
354.L_bn_sqr_words_tail:
355 dmultu t0,t0
356 subu a2,1
357 mflo t1
358 mfhi t0
359 sd t1,0(a0)
360 sd t0,8(a0)
361 beqz a2,.L_bn_sqr_words_return
362
363 ld t0,8(a1)
364 dmultu t0,t0
365 subu a2,1
366 mflo t1
367 mfhi t0
368 sd t1,16(a0)
369 sd t0,24(a0)
370 beqz a2,.L_bn_sqr_words_return
371
372 ld t0,16(a1)
373 dmultu t0,t0
374 mflo t1
375 mfhi t0
376 sd t1,32(a0)
377 sd t0,40(a0)
378 jr ra
379END(bn_sqr_words)
380
381.align 5
382LEAF(bn_add_words)
383 .set noreorder
384 bgtzl a3,.L_bn_add_words_proceed
385 ld t0,0(a1)
386 jr ra
387 move v0,zero
388 .set reorder
389
390.L_bn_add_words_proceed:
391 li MINUS4,-4
392 and AT,a3,MINUS4
393 move v0,zero
394 beqz AT,.L_bn_add_words_tail
395
396.L_bn_add_words_loop:
397 ld ta0,0(a2)
398 ld t1,8(a1)
399 ld ta1,8(a2)
400 ld t2,16(a1)
401 ld ta2,16(a2)
402 ld t3,24(a1)
403 ld ta3,24(a2)
404 daddu ta0,t0
405 subu a3,4
406 sltu t8,ta0,t0
407 daddu t0,ta0,v0
408 PTR_ADD a0,32
409 sltu v0,t0,ta0
410 sd t0,-32(a0)
411 daddu v0,t8
412
413 daddu ta1,t1
414 PTR_ADD a1,32
415 sltu t9,ta1,t1
416 daddu t1,ta1,v0
417 PTR_ADD a2,32
418 sltu v0,t1,ta1
419 sd t1,-24(a0)
420 daddu v0,t9
421
422 daddu ta2,t2
423 and AT,a3,MINUS4
424 sltu t8,ta2,t2
425 daddu t2,ta2,v0
426 sltu v0,t2,ta2
427 sd t2,-16(a0)
428 daddu v0,t8
429
430 daddu ta3,t3
431 sltu t9,ta3,t3
432 daddu t3,ta3,v0
433 sltu v0,t3,ta3
434 sd t3,-8(a0)
435 daddu v0,t9
436
437 .set noreorder
438 bgtzl AT,.L_bn_add_words_loop
439 ld t0,0(a1)
440
441 bnezl a3,.L_bn_add_words_tail
442 ld t0,0(a1)
443 .set reorder
444
445.L_bn_add_words_return:
446 jr ra
447
448.L_bn_add_words_tail:
449 ld ta0,0(a2)
450 daddu ta0,t0
451 subu a3,1
452 sltu t8,ta0,t0
453 daddu t0,ta0,v0
454 sltu v0,t0,ta0
455 sd t0,0(a0)
456 daddu v0,t8
457 beqz a3,.L_bn_add_words_return
458
459 ld t1,8(a1)
460 ld ta1,8(a2)
461 daddu ta1,t1
462 subu a3,1
463 sltu t9,ta1,t1
464 daddu t1,ta1,v0
465 sltu v0,t1,ta1
466 sd t1,8(a0)
467 daddu v0,t9
468 beqz a3,.L_bn_add_words_return
469
470 ld t2,16(a1)
471 ld ta2,16(a2)
472 daddu ta2,t2
473 sltu t8,ta2,t2
474 daddu t2,ta2,v0
475 sltu v0,t2,ta2
476 sd t2,16(a0)
477 daddu v0,t8
478 jr ra
479END(bn_add_words)
480
481.align 5
482LEAF(bn_sub_words)
483 .set noreorder
484 bgtzl a3,.L_bn_sub_words_proceed
485 ld t0,0(a1)
486 jr ra
487 move v0,zero
488 .set reorder
489
490.L_bn_sub_words_proceed:
491 li MINUS4,-4
492 and AT,a3,MINUS4
493 move v0,zero
494 beqz AT,.L_bn_sub_words_tail
495
496.L_bn_sub_words_loop:
497 ld ta0,0(a2)
498 ld t1,8(a1)
499 ld ta1,8(a2)
500 ld t2,16(a1)
501 ld ta2,16(a2)
502 ld t3,24(a1)
503 ld ta3,24(a2)
504 sltu t8,t0,ta0
505 dsubu t0,ta0
506 subu a3,4
507 dsubu ta0,t0,v0
508 and AT,a3,MINUS4
509 sd ta0,0(a0)
510 MOVNZ (t0,v0,t8)
511
512 sltu t9,t1,ta1
513 dsubu t1,ta1
514 PTR_ADD a0,32
515 dsubu ta1,t1,v0
516 PTR_ADD a1,32
517 sd ta1,-24(a0)
518 MOVNZ (t1,v0,t9)
519
520
521 sltu t8,t2,ta2
522 dsubu t2,ta2
523 dsubu ta2,t2,v0
524 PTR_ADD a2,32
525 sd ta2,-16(a0)
526 MOVNZ (t2,v0,t8)
527
528 sltu t9,t3,ta3
529 dsubu t3,ta3
530 dsubu ta3,t3,v0
531 sd ta3,-8(a0)
532 MOVNZ (t3,v0,t9)
533
534 .set noreorder
535 bgtzl AT,.L_bn_sub_words_loop
536 ld t0,0(a1)
537
538 bnezl a3,.L_bn_sub_words_tail
539 ld t0,0(a1)
540 .set reorder
541
542.L_bn_sub_words_return:
543 jr ra
544
545.L_bn_sub_words_tail:
546 ld ta0,0(a2)
547 subu a3,1
548 sltu t8,t0,ta0
549 dsubu t0,ta0
550 dsubu ta0,t0,v0
551 MOVNZ (t0,v0,t8)
552 sd ta0,0(a0)
553 beqz a3,.L_bn_sub_words_return
554
555 ld t1,8(a1)
556 subu a3,1
557 ld ta1,8(a2)
558 sltu t9,t1,ta1
559 dsubu t1,ta1
560 dsubu ta1,t1,v0
561 MOVNZ (t1,v0,t9)
562 sd ta1,8(a0)
563 beqz a3,.L_bn_sub_words_return
564
565 ld t2,16(a1)
566 ld ta2,16(a2)
567 sltu t8,t2,ta2
568 dsubu t2,ta2
569 dsubu ta2,t2,v0
570 MOVNZ (t2,v0,t8)
571 sd ta2,16(a0)
572 jr ra
573END(bn_sub_words)
574
575#undef MINUS4
576
577.align 5
578LEAF(bn_div_words)
579 .set noreorder
580 bnezl a2,.L_bn_div_words_proceed
581 move v1,zero
582 jr ra
583 li v0,-1 /* I'd rather signal div-by-zero
584 * which can be done with 'break 7' */
585
586.L_bn_div_words_proceed:
587 bltz a2,.L_bn_div_words_body
588 move t9,v1
589 dsll a2,1
590 bgtz a2,.-4
591 addu t9,1
592
593 .set reorder
594 negu t1,t9
595 li t2,-1
596 dsll t2,t1
597 and t2,a0
598 dsrl AT,a1,t1
599 .set noreorder
600 bnezl t2,.+8
601 break 6 /* signal overflow */
602 .set reorder
603 dsll a0,t9
604 dsll a1,t9
605 or a0,AT
606
607#define QT ta0
608#define HH ta1
609#define DH v1
610.L_bn_div_words_body:
611 dsrl DH,a2,32
612 sgeu AT,a0,a2
613 .set noreorder
614 bnezl AT,.+8
615 dsubu a0,a2
616 .set reorder
617
618 li QT,-1
619 dsrl HH,a0,32
620 dsrl QT,32 /* q=0xffffffff */
621 beq DH,HH,.L_bn_div_words_skip_div1
622 ddivu zero,a0,DH
623 mflo QT
624.L_bn_div_words_skip_div1:
625 dmultu a2,QT
626 dsll t3,a0,32
627 dsrl AT,a1,32
628 or t3,AT
629 mflo t0
630 mfhi t1
631.L_bn_div_words_inner_loop1:
632 sltu t2,t3,t0
633 seq t8,HH,t1
634 sltu AT,HH,t1
635 and t2,t8
636 or AT,t2
637 .set noreorder
638 beqz AT,.L_bn_div_words_inner_loop1_done
639 sltu t2,t0,a2
640 .set reorder
641 dsubu QT,1
642 dsubu t0,a2
643 dsubu t1,t2
644 b .L_bn_div_words_inner_loop1
645.L_bn_div_words_inner_loop1_done:
646
647 dsll a1,32
648 dsubu a0,t3,t0
649 dsll v0,QT,32
650
651 li QT,-1
652 dsrl HH,a0,32
653 dsrl QT,32 /* q=0xffffffff */
654 beq DH,HH,.L_bn_div_words_skip_div2
655 ddivu zero,a0,DH
656 mflo QT
657.L_bn_div_words_skip_div2:
658 dmultu a2,QT
659 dsll t3,a0,32
660 dsrl AT,a1,32
661 or t3,AT
662 mflo t0
663 mfhi t1
664.L_bn_div_words_inner_loop2:
665 sltu t2,t3,t0
666 seq t8,HH,t1
667 sltu AT,HH,t1
668 and t2,t8
669 or AT,t2
670 .set noreorder
671 beqz AT,.L_bn_div_words_inner_loop2_done
672 sltu t2,t0,a2
673 .set reorder
674 dsubu QT,1
675 dsubu t0,a2
676 dsubu t1,t2
677 b .L_bn_div_words_inner_loop2
678.L_bn_div_words_inner_loop2_done:
679
680 dsubu a0,t3,t0
681 or v0,QT
682 dsrl v1,a0,t9 /* v1 contains remainder if anybody wants it */
683 dsrl a2,t9 /* restore a2 */
684 jr ra
685#undef HH
686#undef DH
687#undef QT
688END(bn_div_words)
689
690.align 5
691LEAF(bn_div_3_words)
692 .set reorder
693 move a3,a0 /* we know that bn_div_words doesn't
694 * touch a3, ta2, ta3 and preserves a2
695 * so that we can save two arguments
696 * and return address in registers
697 * instead of stack:-)
698 */
699 ld a0,(a3)
700 move ta2,a2
701 move a2,a1
702 ld a1,-8(a3)
703 move ta3,ra
704 move v1,zero
705 li v0,-1
706 beq a0,a2,.L_bn_div_3_words_skip_div
707 jal bn_div_words
708 move ra,ta3
709.L_bn_div_3_words_skip_div:
710 dmultu ta2,v0
711 ld t2,-16(a3)
712 mflo t0
713 mfhi t1
714.L_bn_div_3_words_inner_loop:
715 sgeu AT,t2,t0
716 seq t9,t1,v1
717 sltu t8,t1,v1
718 and AT,t9
719 or AT,t8
720 bnez AT,.L_bn_div_3_words_inner_loop_done
721 daddu v1,a2
722 sltu t3,t0,ta2
723 sltu AT,v1,a2
724 dsubu v0,1
725 dsubu t0,ta2
726 dsubu t1,t3
727 beqz AT,.L_bn_div_3_words_inner_loop
728.L_bn_div_3_words_inner_loop_done:
729 jr ra
730END(bn_div_3_words)
731
732#define a_0 t0
733#define a_1 t1
734#define a_2 t2
735#define a_3 t3
736#define b_0 ta0
737#define b_1 ta1
738#define b_2 ta2
739#define b_3 ta3
740
741#define a_4 s0
742#define a_5 s2
743#define a_6 s4
744#define a_7 a1 /* once we load a[7] we don't need a anymore */
745#define b_4 s1
746#define b_5 s3
747#define b_6 s5
748#define b_7 a2 /* once we load b[7] we don't need b anymore */
749
750#define t_1 t8
751#define t_2 t9
752
753#define c_1 v0
754#define c_2 v1
755#define c_3 a3
756
757#define FRAME_SIZE 48
758
759.align 5
760LEAF(bn_mul_comba8)
761 .set noreorder
762 PTR_SUB sp,FRAME_SIZE
763 .frame sp,64,ra
764 .set reorder
765 ld a_0,0(a1) /* If compiled with -mips3 option on
766 * R5000 box assembler barks on this
767 * line with "shouldn't have mult/div
768 * as last instruction in bb (R10K
769 * bug)" warning. If anybody out there
770 * has a clue about how to circumvent
771 * this do send me a note.
772 * <appro@fy.chalmers.se>
773 */
774 ld b_0,0(a2)
775 ld a_1,8(a1)
776 ld a_2,16(a1)
777 ld a_3,24(a1)
778 ld b_1,8(a2)
779 ld b_2,16(a2)
780 ld b_3,24(a2)
781 dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
782 sd s0,0(sp)
783 sd s1,8(sp)
784 sd s2,16(sp)
785 sd s3,24(sp)
786 sd s4,32(sp)
787 sd s5,40(sp)
788 mflo c_1
789 mfhi c_2
790
791 dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */
792 ld a_4,32(a1)
793 ld a_5,40(a1)
794 ld a_6,48(a1)
795 ld a_7,56(a1)
796 ld b_4,32(a2)
797 ld b_5,40(a2)
798 mflo t_1
799 mfhi t_2
800 daddu c_2,t_1
801 sltu AT,c_2,t_1
802 daddu c_3,t_2,AT
803 dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */
804 ld b_6,48(a2)
805 ld b_7,56(a2)
806 sd c_1,0(a0) /* r[0]=c1; */
807 mflo t_1
808 mfhi t_2
809 daddu c_2,t_1
810 sltu AT,c_2,t_1
811 daddu t_2,AT
812 daddu c_3,t_2
813 sltu c_1,c_3,t_2
814 sd c_2,8(a0) /* r[1]=c2; */
815
816 dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */
817 mflo t_1
818 mfhi t_2
819 daddu c_3,t_1
820 sltu AT,c_3,t_1
821 daddu t_2,AT
822 daddu c_1,t_2
823 dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
824 mflo t_1
825 mfhi t_2
826 daddu c_3,t_1
827 sltu AT,c_3,t_1
828 daddu t_2,AT
829 daddu c_1,t_2
830 sltu c_2,c_1,t_2
831 dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */
832 mflo t_1
833 mfhi t_2
834 daddu c_3,t_1
835 sltu AT,c_3,t_1
836 daddu t_2,AT
837 daddu c_1,t_2
838 sltu AT,c_1,t_2
839 daddu c_2,AT
840 sd c_3,16(a0) /* r[2]=c3; */
841
842 dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */
843 mflo t_1
844 mfhi t_2
845 daddu c_1,t_1
846 sltu AT,c_1,t_1
847 daddu t_2,AT
848 daddu c_2,t_2
849 dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */
850 mflo t_1
851 mfhi t_2
852 daddu c_1,t_1
853 sltu AT,c_1,t_1
854 daddu t_2,AT
855 daddu c_2,t_2
856 sltu c_3,c_2,t_2
857 dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */
858 mflo t_1
859 mfhi t_2
860 daddu c_1,t_1
861 sltu AT,c_1,t_1
862 daddu t_2,AT
863 daddu c_2,t_2
864 sltu AT,c_2,t_2
865 daddu c_3,AT
866 dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */
867 mflo t_1
868 mfhi t_2
869 daddu c_1,t_1
870 sltu AT,c_1,t_1
871 daddu t_2,AT
872 daddu c_2,t_2
873 sltu AT,c_2,t_2
874 daddu c_3,AT
875 sd c_1,24(a0) /* r[3]=c1; */
876
877 dmultu a_4,b_0 /* mul_add_c(a[4],b[0],c2,c3,c1); */
878 mflo t_1
879 mfhi t_2
880 daddu c_2,t_1
881 sltu AT,c_2,t_1
882 daddu t_2,AT
883 daddu c_3,t_2
884 dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */
885 mflo t_1
886 mfhi t_2
887 daddu c_2,t_1
888 sltu AT,c_2,t_1
889 daddu t_2,AT
890 daddu c_3,t_2
891 sltu c_1,c_3,t_2
892 dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
893 mflo t_1
894 mfhi t_2
895 daddu c_2,t_1
896 sltu AT,c_2,t_1
897 daddu t_2,AT
898 daddu c_3,t_2
899 sltu AT,c_3,t_2
900 daddu c_1,AT
901 dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */
902 mflo t_1
903 mfhi t_2
904 daddu c_2,t_1
905 sltu AT,c_2,t_1
906 daddu t_2,AT
907 daddu c_3,t_2
908 sltu AT,c_3,t_2
909 daddu c_1,AT
910 dmultu a_0,b_4 /* mul_add_c(a[0],b[4],c2,c3,c1); */
911 mflo t_1
912 mfhi t_2
913 daddu c_2,t_1
914 sltu AT,c_2,t_1
915 daddu t_2,AT
916 daddu c_3,t_2
917 sltu AT,c_3,t_2
918 daddu c_1,AT
919 sd c_2,32(a0) /* r[4]=c2; */
920
921 dmultu a_0,b_5 /* mul_add_c(a[0],b[5],c3,c1,c2); */
922 mflo t_1
923 mfhi t_2
924 daddu c_3,t_1
925 sltu AT,c_3,t_1
926 daddu t_2,AT
927 daddu c_1,t_2
928 dmultu a_1,b_4 /* mul_add_c(a[1],b[4],c3,c1,c2); */
929 mflo t_1
930 mfhi t_2
931 daddu c_3,t_1
932 sltu AT,c_3,t_1
933 daddu t_2,AT
934 daddu c_1,t_2
935 sltu c_2,c_1,t_2
936 dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */
937 mflo t_1
938 mfhi t_2
939 daddu c_3,t_1
940 sltu AT,c_3,t_1
941 daddu t_2,AT
942 daddu c_1,t_2
943 sltu AT,c_1,t_2
944 daddu c_2,AT
945 dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */
946 mflo t_1
947 mfhi t_2
948 daddu c_3,t_1
949 sltu AT,c_3,t_1
950 daddu t_2,AT
951 daddu c_1,t_2
952 sltu AT,c_1,t_2
953 daddu c_2,AT
954 dmultu a_4,b_1 /* mul_add_c(a[4],b[1],c3,c1,c2); */
955 mflo t_1
956 mfhi t_2
957 daddu c_3,t_1
958 sltu AT,c_3,t_1
959 daddu t_2,AT
960 daddu c_1,t_2
961 sltu AT,c_1,t_2
962 daddu c_2,AT
963 dmultu a_5,b_0 /* mul_add_c(a[5],b[0],c3,c1,c2); */
964 mflo t_1
965 mfhi t_2
966 daddu c_3,t_1
967 sltu AT,c_3,t_1
968 daddu t_2,AT
969 daddu c_1,t_2
970 sltu AT,c_1,t_2
971 daddu c_2,AT
972 sd c_3,40(a0) /* r[5]=c3; */
973
974 dmultu a_6,b_0 /* mul_add_c(a[6],b[0],c1,c2,c3); */
975 mflo t_1
976 mfhi t_2
977 daddu c_1,t_1
978 sltu AT,c_1,t_1
979 daddu t_2,AT
980 daddu c_2,t_2
981 dmultu a_5,b_1 /* mul_add_c(a[5],b[1],c1,c2,c3); */
982 mflo t_1
983 mfhi t_2
984 daddu c_1,t_1
985 sltu AT,c_1,t_1
986 daddu t_2,AT
987 daddu c_2,t_2
988 sltu c_3,c_2,t_2
989 dmultu a_4,b_2 /* mul_add_c(a[4],b[2],c1,c2,c3); */
990 mflo t_1
991 mfhi t_2
992 daddu c_1,t_1
993 sltu AT,c_1,t_1
994 daddu t_2,AT
995 daddu c_2,t_2
996 sltu AT,c_2,t_2
997 daddu c_3,AT
998 dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
999 mflo t_1
1000 mfhi t_2
1001 daddu c_1,t_1
1002 sltu AT,c_1,t_1
1003 daddu t_2,AT
1004 daddu c_2,t_2
1005 sltu AT,c_2,t_2
1006 daddu c_3,AT
1007 dmultu a_2,b_4 /* mul_add_c(a[2],b[4],c1,c2,c3); */
1008 mflo t_1
1009 mfhi t_2
1010 daddu c_1,t_1
1011 sltu AT,c_1,t_1
1012 daddu t_2,AT
1013 daddu c_2,t_2
1014 sltu AT,c_2,t_2
1015 daddu c_3,AT
1016 dmultu a_1,b_5 /* mul_add_c(a[1],b[5],c1,c2,c3); */
1017 mflo t_1
1018 mfhi t_2
1019 daddu c_1,t_1
1020 sltu AT,c_1,t_1
1021 daddu t_2,AT
1022 daddu c_2,t_2
1023 sltu AT,c_2,t_2
1024 daddu c_3,AT
1025 dmultu a_0,b_6 /* mul_add_c(a[0],b[6],c1,c2,c3); */
1026 mflo t_1
1027 mfhi t_2
1028 daddu c_1,t_1
1029 sltu AT,c_1,t_1
1030 daddu t_2,AT
1031 daddu c_2,t_2
1032 sltu AT,c_2,t_2
1033 daddu c_3,AT
1034 sd c_1,48(a0) /* r[6]=c1; */
1035
1036 dmultu a_0,b_7 /* mul_add_c(a[0],b[7],c2,c3,c1); */
1037 mflo t_1
1038 mfhi t_2
1039 daddu c_2,t_1
1040 sltu AT,c_2,t_1
1041 daddu t_2,AT
1042 daddu c_3,t_2
1043 dmultu a_1,b_6 /* mul_add_c(a[1],b[6],c2,c3,c1); */
1044 mflo t_1
1045 mfhi t_2
1046 daddu c_2,t_1
1047 sltu AT,c_2,t_1
1048 daddu t_2,AT
1049 daddu c_3,t_2
1050 sltu c_1,c_3,t_2
1051 dmultu a_2,b_5 /* mul_add_c(a[2],b[5],c2,c3,c1); */
1052 mflo t_1
1053 mfhi t_2
1054 daddu c_2,t_1
1055 sltu AT,c_2,t_1
1056 daddu t_2,AT
1057 daddu c_3,t_2
1058 sltu AT,c_3,t_2
1059 daddu c_1,AT
1060 dmultu a_3,b_4 /* mul_add_c(a[3],b[4],c2,c3,c1); */
1061 mflo t_1
1062 mfhi t_2
1063 daddu c_2,t_1
1064 sltu AT,c_2,t_1
1065 daddu t_2,AT
1066 daddu c_3,t_2
1067 sltu AT,c_3,t_2
1068 daddu c_1,AT
1069 dmultu a_4,b_3 /* mul_add_c(a[4],b[3],c2,c3,c1); */
1070 mflo t_1
1071 mfhi t_2
1072 daddu c_2,t_1
1073 sltu AT,c_2,t_1
1074 daddu t_2,AT
1075 daddu c_3,t_2
1076 sltu AT,c_3,t_2
1077 daddu c_1,AT
1078 dmultu a_5,b_2 /* mul_add_c(a[5],b[2],c2,c3,c1); */
1079 mflo t_1
1080 mfhi t_2
1081 daddu c_2,t_1
1082 sltu AT,c_2,t_1
1083 daddu t_2,AT
1084 daddu c_3,t_2
1085 sltu AT,c_3,t_2
1086 daddu c_1,AT
1087 dmultu a_6,b_1 /* mul_add_c(a[6],b[1],c2,c3,c1); */
1088 mflo t_1
1089 mfhi t_2
1090 daddu c_2,t_1
1091 sltu AT,c_2,t_1
1092 daddu t_2,AT
1093 daddu c_3,t_2
1094 sltu AT,c_3,t_2
1095 daddu c_1,AT
1096 dmultu a_7,b_0 /* mul_add_c(a[7],b[0],c2,c3,c1); */
1097 mflo t_1
1098 mfhi t_2
1099 daddu c_2,t_1
1100 sltu AT,c_2,t_1
1101 daddu t_2,AT
1102 daddu c_3,t_2
1103 sltu AT,c_3,t_2
1104 daddu c_1,AT
1105 sd c_2,56(a0) /* r[7]=c2; */
1106
1107 dmultu a_7,b_1 /* mul_add_c(a[7],b[1],c3,c1,c2); */
1108 mflo t_1
1109 mfhi t_2
1110 daddu c_3,t_1
1111 sltu AT,c_3,t_1
1112 daddu t_2,AT
1113 daddu c_1,t_2
1114 dmultu a_6,b_2 /* mul_add_c(a[6],b[2],c3,c1,c2); */
1115 mflo t_1
1116 mfhi t_2
1117 daddu c_3,t_1
1118 sltu AT,c_3,t_1
1119 daddu t_2,AT
1120 daddu c_1,t_2
1121 sltu c_2,c_1,t_2
1122 dmultu a_5,b_3 /* mul_add_c(a[5],b[3],c3,c1,c2); */
1123 mflo t_1
1124 mfhi t_2
1125 daddu c_3,t_1
1126 sltu AT,c_3,t_1
1127 daddu t_2,AT
1128 daddu c_1,t_2
1129 sltu AT,c_1,t_2
1130 daddu c_2,AT
1131 dmultu a_4,b_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
1132 mflo t_1
1133 mfhi t_2
1134 daddu c_3,t_1
1135 sltu AT,c_3,t_1
1136 daddu t_2,AT
1137 daddu c_1,t_2
1138 sltu AT,c_1,t_2
1139 daddu c_2,AT
1140 dmultu a_3,b_5 /* mul_add_c(a[3],b[5],c3,c1,c2); */
1141 mflo t_1
1142 mfhi t_2
1143 daddu c_3,t_1
1144 sltu AT,c_3,t_1
1145 daddu t_2,AT
1146 daddu c_1,t_2
1147 sltu AT,c_1,t_2
1148 daddu c_2,AT
1149 dmultu a_2,b_6 /* mul_add_c(a[2],b[6],c3,c1,c2); */
1150 mflo t_1
1151 mfhi t_2
1152 daddu c_3,t_1
1153 sltu AT,c_3,t_1
1154 daddu t_2,AT
1155 daddu c_1,t_2
1156 sltu AT,c_1,t_2
1157 daddu c_2,AT
1158 dmultu a_1,b_7 /* mul_add_c(a[1],b[7],c3,c1,c2); */
1159 mflo t_1
1160 mfhi t_2
1161 daddu c_3,t_1
1162 sltu AT,c_3,t_1
1163 daddu t_2,AT
1164 daddu c_1,t_2
1165 sltu AT,c_1,t_2
1166 daddu c_2,AT
1167 sd c_3,64(a0) /* r[8]=c3; */
1168
1169 dmultu a_2,b_7 /* mul_add_c(a[2],b[7],c1,c2,c3); */
1170 mflo t_1
1171 mfhi t_2
1172 daddu c_1,t_1
1173 sltu AT,c_1,t_1
1174 daddu t_2,AT
1175 daddu c_2,t_2
1176 dmultu a_3,b_6 /* mul_add_c(a[3],b[6],c1,c2,c3); */
1177 mflo t_1
1178 mfhi t_2
1179 daddu c_1,t_1
1180 sltu AT,c_1,t_1
1181 daddu t_2,AT
1182 daddu c_2,t_2
1183 sltu c_3,c_2,t_2
1184 dmultu a_4,b_5 /* mul_add_c(a[4],b[5],c1,c2,c3); */
1185 mflo t_1
1186 mfhi t_2
1187 daddu c_1,t_1
1188 sltu AT,c_1,t_1
1189 daddu t_2,AT
1190 daddu c_2,t_2
1191 sltu AT,c_2,t_2
1192 daddu c_3,AT
1193 dmultu a_5,b_4 /* mul_add_c(a[5],b[4],c1,c2,c3); */
1194 mflo t_1
1195 mfhi t_2
1196 daddu c_1,t_1
1197 sltu AT,c_1,t_1
1198 daddu t_2,AT
1199 daddu c_2,t_2
1200 sltu AT,c_2,t_2
1201 daddu c_3,AT
1202 dmultu a_6,b_3 /* mul_add_c(a[6],b[3],c1,c2,c3); */
1203 mflo t_1
1204 mfhi t_2
1205 daddu c_1,t_1
1206 sltu AT,c_1,t_1
1207 daddu t_2,AT
1208 daddu c_2,t_2
1209 sltu AT,c_2,t_2
1210 daddu c_3,AT
1211 dmultu a_7,b_2 /* mul_add_c(a[7],b[2],c1,c2,c3); */
1212 mflo t_1
1213 mfhi t_2
1214 daddu c_1,t_1
1215 sltu AT,c_1,t_1
1216 daddu t_2,AT
1217 daddu c_2,t_2
1218 sltu AT,c_2,t_2
1219 daddu c_3,AT
1220 sd c_1,72(a0) /* r[9]=c1; */
1221
1222 dmultu a_7,b_3 /* mul_add_c(a[7],b[3],c2,c3,c1); */
1223 mflo t_1
1224 mfhi t_2
1225 daddu c_2,t_1
1226 sltu AT,c_2,t_1
1227 daddu t_2,AT
1228 daddu c_3,t_2
1229 dmultu a_6,b_4 /* mul_add_c(a[6],b[4],c2,c3,c1); */
1230 mflo t_1
1231 mfhi t_2
1232 daddu c_2,t_1
1233 sltu AT,c_2,t_1
1234 daddu t_2,AT
1235 daddu c_3,t_2
1236 sltu c_1,c_3,t_2
1237 dmultu a_5,b_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
1238 mflo t_1
1239 mfhi t_2
1240 daddu c_2,t_1
1241 sltu AT,c_2,t_1
1242 daddu t_2,AT
1243 daddu c_3,t_2
1244 sltu AT,c_3,t_2
1245 daddu c_1,AT
1246 dmultu a_4,b_6 /* mul_add_c(a[4],b[6],c2,c3,c1); */
1247 mflo t_1
1248 mfhi t_2
1249 daddu c_2,t_1
1250 sltu AT,c_2,t_1
1251 daddu t_2,AT
1252 daddu c_3,t_2
1253 sltu AT,c_3,t_2
1254 daddu c_1,AT
1255 dmultu a_3,b_7 /* mul_add_c(a[3],b[7],c2,c3,c1); */
1256 mflo t_1
1257 mfhi t_2
1258 daddu c_2,t_1
1259 sltu AT,c_2,t_1
1260 daddu t_2,AT
1261 daddu c_3,t_2
1262 sltu AT,c_3,t_2
1263 daddu c_1,AT
1264 sd c_2,80(a0) /* r[10]=c2; */
1265
1266 dmultu a_4,b_7 /* mul_add_c(a[4],b[7],c3,c1,c2); */
1267 mflo t_1
1268 mfhi t_2
1269 daddu c_3,t_1
1270 sltu AT,c_3,t_1
1271 daddu t_2,AT
1272 daddu c_1,t_2
1273 dmultu a_5,b_6 /* mul_add_c(a[5],b[6],c3,c1,c2); */
1274 mflo t_1
1275 mfhi t_2
1276 daddu c_3,t_1
1277 sltu AT,c_3,t_1
1278 daddu t_2,AT
1279 daddu c_1,t_2
1280 sltu c_2,c_1,t_2
1281 dmultu a_6,b_5 /* mul_add_c(a[6],b[5],c3,c1,c2); */
1282 mflo t_1
1283 mfhi t_2
1284 daddu c_3,t_1
1285 sltu AT,c_3,t_1
1286 daddu t_2,AT
1287 daddu c_1,t_2
1288 sltu AT,c_1,t_2
1289 daddu c_2,AT
1290 dmultu a_7,b_4 /* mul_add_c(a[7],b[4],c3,c1,c2); */
1291 mflo t_1
1292 mfhi t_2
1293 daddu c_3,t_1
1294 sltu AT,c_3,t_1
1295 daddu t_2,AT
1296 daddu c_1,t_2
1297 sltu AT,c_1,t_2
1298 daddu c_2,AT
1299 sd c_3,88(a0) /* r[11]=c3; */
1300
1301 dmultu a_7,b_5 /* mul_add_c(a[7],b[5],c1,c2,c3); */
1302 mflo t_1
1303 mfhi t_2
1304 daddu c_1,t_1
1305 sltu AT,c_1,t_1
1306 daddu t_2,AT
1307 daddu c_2,t_2
1308 dmultu a_6,b_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
1309 mflo t_1
1310 mfhi t_2
1311 daddu c_1,t_1
1312 sltu AT,c_1,t_1
1313 daddu t_2,AT
1314 daddu c_2,t_2
1315 sltu c_3,c_2,t_2
1316 dmultu a_5,b_7 /* mul_add_c(a[5],b[7],c1,c2,c3); */
1317 mflo t_1
1318 mfhi t_2
1319 daddu c_1,t_1
1320 sltu AT,c_1,t_1
1321 daddu t_2,AT
1322 daddu c_2,t_2
1323 sltu AT,c_2,t_2
1324 daddu c_3,AT
1325 sd c_1,96(a0) /* r[12]=c1; */
1326
1327 dmultu a_6,b_7 /* mul_add_c(a[6],b[7],c2,c3,c1); */
1328 mflo t_1
1329 mfhi t_2
1330 daddu c_2,t_1
1331 sltu AT,c_2,t_1
1332 daddu t_2,AT
1333 daddu c_3,t_2
1334 dmultu a_7,b_6 /* mul_add_c(a[7],b[6],c2,c3,c1); */
1335 mflo t_1
1336 mfhi t_2
1337 daddu c_2,t_1
1338 sltu AT,c_2,t_1
1339 daddu t_2,AT
1340 daddu c_3,t_2
1341 sltu c_1,c_3,t_2
1342 sd c_2,104(a0) /* r[13]=c2; */
1343
1344 dmultu a_7,b_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
1345 ld s0,0(sp)
1346 ld s1,8(sp)
1347 ld s2,16(sp)
1348 ld s3,24(sp)
1349 ld s4,32(sp)
1350 ld s5,40(sp)
1351 mflo t_1
1352 mfhi t_2
1353 daddu c_3,t_1
1354 sltu AT,c_3,t_1
1355 daddu t_2,AT
1356 daddu c_1,t_2
1357 sd c_3,112(a0) /* r[14]=c3; */
1358 sd c_1,120(a0) /* r[15]=c1; */
1359
1360 PTR_ADD sp,FRAME_SIZE
1361
1362 jr ra
1363END(bn_mul_comba8)
1364
1365.align 5
1366LEAF(bn_mul_comba4)
1367 .set reorder
1368 ld a_0,0(a1)
1369 ld b_0,0(a2)
1370 ld a_1,8(a1)
1371 ld a_2,16(a1)
1372 dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
1373 ld a_3,24(a1)
1374 ld b_1,8(a2)
1375 ld b_2,16(a2)
1376 ld b_3,24(a2)
1377 mflo c_1
1378 mfhi c_2
1379 sd c_1,0(a0)
1380
1381 dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */
1382 mflo t_1
1383 mfhi t_2
1384 daddu c_2,t_1
1385 sltu AT,c_2,t_1
1386 daddu c_3,t_2,AT
1387 dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */
1388 mflo t_1
1389 mfhi t_2
1390 daddu c_2,t_1
1391 sltu AT,c_2,t_1
1392 daddu t_2,AT
1393 daddu c_3,t_2
1394 sltu c_1,c_3,t_2
1395 sd c_2,8(a0)
1396
1397 dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */
1398 mflo t_1
1399 mfhi t_2
1400 daddu c_3,t_1
1401 sltu AT,c_3,t_1
1402 daddu t_2,AT
1403 daddu c_1,t_2
1404 dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
1405 mflo t_1
1406 mfhi t_2
1407 daddu c_3,t_1
1408 sltu AT,c_3,t_1
1409 daddu t_2,AT
1410 daddu c_1,t_2
1411 sltu c_2,c_1,t_2
1412 dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */
1413 mflo t_1
1414 mfhi t_2
1415 daddu c_3,t_1
1416 sltu AT,c_3,t_1
1417 daddu t_2,AT
1418 daddu c_1,t_2
1419 sltu AT,c_1,t_2
1420 daddu c_2,AT
1421 sd c_3,16(a0)
1422
1423 dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */
1424 mflo t_1
1425 mfhi t_2
1426 daddu c_1,t_1
1427 sltu AT,c_1,t_1
1428 daddu t_2,AT
1429 daddu c_2,t_2
1430 dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */
1431 mflo t_1
1432 mfhi t_2
1433 daddu c_1,t_1
1434 sltu AT,c_1,t_1
1435 daddu t_2,AT
1436 daddu c_2,t_2
1437 sltu c_3,c_2,t_2
1438 dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */
1439 mflo t_1
1440 mfhi t_2
1441 daddu c_1,t_1
1442 sltu AT,c_1,t_1
1443 daddu t_2,AT
1444 daddu c_2,t_2
1445 sltu AT,c_2,t_2
1446 daddu c_3,AT
1447 dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */
1448 mflo t_1
1449 mfhi t_2
1450 daddu c_1,t_1
1451 sltu AT,c_1,t_1
1452 daddu t_2,AT
1453 daddu c_2,t_2
1454 sltu AT,c_2,t_2
1455 daddu c_3,AT
1456 sd c_1,24(a0)
1457
1458 dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */
1459 mflo t_1
1460 mfhi t_2
1461 daddu c_2,t_1
1462 sltu AT,c_2,t_1
1463 daddu t_2,AT
1464 daddu c_3,t_2
1465 dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
1466 mflo t_1
1467 mfhi t_2
1468 daddu c_2,t_1
1469 sltu AT,c_2,t_1
1470 daddu t_2,AT
1471 daddu c_3,t_2
1472 sltu c_1,c_3,t_2
1473 dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */
1474 mflo t_1
1475 mfhi t_2
1476 daddu c_2,t_1
1477 sltu AT,c_2,t_1
1478 daddu t_2,AT
1479 daddu c_3,t_2
1480 sltu AT,c_3,t_2
1481 daddu c_1,AT
1482 sd c_2,32(a0)
1483
1484 dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */
1485 mflo t_1
1486 mfhi t_2
1487 daddu c_3,t_1
1488 sltu AT,c_3,t_1
1489 daddu t_2,AT
1490 daddu c_1,t_2
1491 dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */
1492 mflo t_1
1493 mfhi t_2
1494 daddu c_3,t_1
1495 sltu AT,c_3,t_1
1496 daddu t_2,AT
1497 daddu c_1,t_2
1498 sltu c_2,c_1,t_2
1499 sd c_3,40(a0)
1500
1501 dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1502 mflo t_1
1503 mfhi t_2
1504 daddu c_1,t_1
1505 sltu AT,c_1,t_1
1506 daddu t_2,AT
1507 daddu c_2,t_2
1508 sd c_1,48(a0)
1509 sd c_2,56(a0)
1510
1511 jr ra
1512END(bn_mul_comba4)
1513
1514#undef a_4
1515#undef a_5
1516#undef a_6
1517#undef a_7
1518#define a_4 b_0
1519#define a_5 b_1
1520#define a_6 b_2
1521#define a_7 b_3
1522
1523.align 5
1524LEAF(bn_sqr_comba8)
1525 .set reorder
1526 ld a_0,0(a1)
1527 ld a_1,8(a1)
1528 ld a_2,16(a1)
1529 ld a_3,24(a1)
1530
1531 dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
1532 ld a_4,32(a1)
1533 ld a_5,40(a1)
1534 ld a_6,48(a1)
1535 ld a_7,56(a1)
1536 mflo c_1
1537 mfhi c_2
1538 sd c_1,0(a0)
1539
1540 dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */
1541 mflo t_1
1542 mfhi t_2
1543 daddu c_2,t_1
1544 sltu AT,c_2,t_1
1545 daddu c_3,t_2,AT
1546 daddu c_2,t_1
1547 sltu AT,c_2,t_1
1548 daddu t_2,AT
1549 daddu c_3,t_2
1550 sltu c_1,c_3,t_2
1551 sd c_2,8(a0)
1552
1553 dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
1554 mflo t_1
1555 mfhi t_2
1556 daddu c_3,t_1
1557 sltu AT,c_3,t_1
1558 daddu a2,t_2,AT
1559 daddu c_1,a2
1560 daddu c_3,t_1
1561 sltu AT,c_3,t_1
1562 daddu t_2,AT
1563 daddu c_1,t_2
1564 sltu c_2,c_1,t_2
1565 dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
1566 mflo t_1
1567 mfhi t_2
1568 daddu c_3,t_1
1569 sltu AT,c_3,t_1
1570 daddu t_2,AT
1571 daddu c_1,t_2
1572 sltu AT,c_1,t_2
1573 daddu c_2,AT
1574 sd c_3,16(a0)
1575
1576 dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
1577 mflo t_1
1578 mfhi t_2
1579 daddu c_1,t_1
1580 sltu AT,c_1,t_1
1581 daddu a2,t_2,AT
1582 daddu c_2,a2
1583 daddu c_1,t_1
1584 sltu AT,c_1,t_1
1585 daddu t_2,AT
1586 daddu c_2,t_2
1587 sltu c_3,c_2,t_2
1588 dmultu a_1,a_2 /* mul_add_c2(a[1],b[2],c1,c2,c3); */
1589 mflo t_1
1590 mfhi t_2
1591 daddu c_1,t_1
1592 sltu AT,c_1,t_1
1593 daddu a2,t_2,AT
1594 daddu c_2,a2
1595 sltu AT,c_2,a2
1596 daddu c_3,AT
1597 daddu c_1,t_1
1598 sltu AT,c_1,t_1
1599 daddu t_2,AT
1600 daddu c_2,t_2
1601 sltu AT,c_2,t_2
1602 daddu c_3,AT
1603 sd c_1,24(a0)
1604
1605 dmultu a_4,a_0 /* mul_add_c2(a[4],b[0],c2,c3,c1); */
1606 mflo t_1
1607 mfhi t_2
1608 daddu c_2,t_1
1609 sltu AT,c_2,t_1
1610 daddu a2,t_2,AT
1611 daddu c_3,a2
1612 daddu c_2,t_1
1613 sltu AT,c_2,t_1
1614 daddu t_2,AT
1615 daddu c_3,t_2
1616 sltu c_1,c_3,t_2
1617 dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
1618 mflo t_1
1619 mfhi t_2
1620 daddu c_2,t_1
1621 sltu AT,c_2,t_1
1622 daddu a2,t_2,AT
1623 daddu c_3,a2
1624 sltu AT,c_3,a2
1625 daddu c_1,AT
1626 daddu c_2,t_1
1627 sltu AT,c_2,t_1
1628 daddu t_2,AT
1629 daddu c_3,t_2
1630 sltu AT,c_3,t_2
1631 daddu c_1,AT
1632 dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
1633 mflo t_1
1634 mfhi t_2
1635 daddu c_2,t_1
1636 sltu AT,c_2,t_1
1637 daddu t_2,AT
1638 daddu c_3,t_2
1639 sltu AT,c_3,t_2
1640 daddu c_1,AT
1641 sd c_2,32(a0)
1642
1643 dmultu a_0,a_5 /* mul_add_c2(a[0],b[5],c3,c1,c2); */
1644 mflo t_1
1645 mfhi t_2
1646 daddu c_3,t_1
1647 sltu AT,c_3,t_1
1648 daddu a2,t_2,AT
1649 daddu c_1,a2
1650 daddu c_3,t_1
1651 sltu AT,c_3,t_1
1652 daddu t_2,AT
1653 daddu c_1,t_2
1654 sltu c_2,c_1,t_2
1655 dmultu a_1,a_4 /* mul_add_c2(a[1],b[4],c3,c1,c2); */
1656 mflo t_1
1657 mfhi t_2
1658 daddu c_3,t_1
1659 sltu AT,c_3,t_1
1660 daddu a2,t_2,AT
1661 daddu c_1,a2
1662 sltu AT,c_1,a2
1663 daddu c_2,AT
1664 daddu c_3,t_1
1665 sltu AT,c_3,t_1
1666 daddu t_2,AT
1667 daddu c_1,t_2
1668 sltu AT,c_1,t_2
1669 daddu c_2,AT
1670 dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
1671 mflo t_1
1672 mfhi t_2
1673 daddu c_3,t_1
1674 sltu AT,c_3,t_1
1675 daddu a2,t_2,AT
1676 daddu c_1,a2
1677 sltu AT,c_1,a2
1678 daddu c_2,AT
1679 daddu c_3,t_1
1680 sltu AT,c_3,t_1
1681 daddu t_2,AT
1682 daddu c_1,t_2
1683 sltu AT,c_1,t_2
1684 daddu c_2,AT
1685 sd c_3,40(a0)
1686
1687 dmultu a_6,a_0 /* mul_add_c2(a[6],b[0],c1,c2,c3); */
1688 mflo t_1
1689 mfhi t_2
1690 daddu c_1,t_1
1691 sltu AT,c_1,t_1
1692 daddu a2,t_2,AT
1693 daddu c_2,a2
1694 daddu c_1,t_1
1695 sltu AT,c_1,t_1
1696 daddu t_2,AT
1697 daddu c_2,t_2
1698 sltu c_3,c_2,t_2
1699 dmultu a_5,a_1 /* mul_add_c2(a[5],b[1],c1,c2,c3); */
1700 mflo t_1
1701 mfhi t_2
1702 daddu c_1,t_1
1703 sltu AT,c_1,t_1
1704 daddu a2,t_2,AT
1705 daddu c_2,a2
1706 sltu AT,c_2,a2
1707 daddu c_3,AT
1708 daddu c_1,t_1
1709 sltu AT,c_1,t_1
1710 daddu t_2,AT
1711 daddu c_2,t_2
1712 sltu AT,c_2,t_2
1713 daddu c_3,AT
1714 dmultu a_4,a_2 /* mul_add_c2(a[4],b[2],c1,c2,c3); */
1715 mflo t_1
1716 mfhi t_2
1717 daddu c_1,t_1
1718 sltu AT,c_1,t_1
1719 daddu a2,t_2,AT
1720 daddu c_2,a2
1721 sltu AT,c_2,a2
1722 daddu c_3,AT
1723 daddu c_1,t_1
1724 sltu AT,c_1,t_1
1725 daddu t_2,AT
1726 daddu c_2,t_2
1727 sltu AT,c_2,t_2
1728 daddu c_3,AT
1729 dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1730 mflo t_1
1731 mfhi t_2
1732 daddu c_1,t_1
1733 sltu AT,c_1,t_1
1734 daddu t_2,AT
1735 daddu c_2,t_2
1736 sltu AT,c_2,t_2
1737 daddu c_3,AT
1738 sd c_1,48(a0)
1739
1740 dmultu a_0,a_7 /* mul_add_c2(a[0],b[7],c2,c3,c1); */
1741 mflo t_1
1742 mfhi t_2
1743 daddu c_2,t_1
1744 sltu AT,c_2,t_1
1745 daddu a2,t_2,AT
1746 daddu c_3,a2
1747 daddu c_2,t_1
1748 sltu AT,c_2,t_1
1749 daddu t_2,AT
1750 daddu c_3,t_2
1751 sltu c_1,c_3,t_2
1752 dmultu a_1,a_6 /* mul_add_c2(a[1],b[6],c2,c3,c1); */
1753 mflo t_1
1754 mfhi t_2
1755 daddu c_2,t_1
1756 sltu AT,c_2,t_1
1757 daddu a2,t_2,AT
1758 daddu c_3,a2
1759 sltu AT,c_3,a2
1760 daddu c_1,AT
1761 daddu c_2,t_1
1762 sltu AT,c_2,t_1
1763 daddu t_2,AT
1764 daddu c_3,t_2
1765 sltu AT,c_3,t_2
1766 daddu c_1,AT
1767 dmultu a_2,a_5 /* mul_add_c2(a[2],b[5],c2,c3,c1); */
1768 mflo t_1
1769 mfhi t_2
1770 daddu c_2,t_1
1771 sltu AT,c_2,t_1
1772 daddu a2,t_2,AT
1773 daddu c_3,a2
1774 sltu AT,c_3,a2
1775 daddu c_1,AT
1776 daddu c_2,t_1
1777 sltu AT,c_2,t_1
1778 daddu t_2,AT
1779 daddu c_3,t_2
1780 sltu AT,c_3,t_2
1781 daddu c_1,AT
1782 dmultu a_3,a_4 /* mul_add_c2(a[3],b[4],c2,c3,c1); */
1783 mflo t_1
1784 mfhi t_2
1785 daddu c_2,t_1
1786 sltu AT,c_2,t_1
1787 daddu a2,t_2,AT
1788 daddu c_3,a2
1789 sltu AT,c_3,a2
1790 daddu c_1,AT
1791 daddu c_2,t_1
1792 sltu AT,c_2,t_1
1793 daddu t_2,AT
1794 daddu c_3,t_2
1795 sltu AT,c_3,t_2
1796 daddu c_1,AT
1797 sd c_2,56(a0)
1798
1799 dmultu a_7,a_1 /* mul_add_c2(a[7],b[1],c3,c1,c2); */
1800 mflo t_1
1801 mfhi t_2
1802 daddu c_3,t_1
1803 sltu AT,c_3,t_1
1804 daddu a2,t_2,AT
1805 daddu c_1,a2
1806 daddu c_3,t_1
1807 sltu AT,c_3,t_1
1808 daddu t_2,AT
1809 daddu c_1,t_2
1810 sltu c_2,c_1,t_2
1811 dmultu a_6,a_2 /* mul_add_c2(a[6],b[2],c3,c1,c2); */
1812 mflo t_1
1813 mfhi t_2
1814 daddu c_3,t_1
1815 sltu AT,c_3,t_1
1816 daddu a2,t_2,AT
1817 daddu c_1,a2
1818 sltu AT,c_1,a2
1819 daddu c_2,AT
1820 daddu c_3,t_1
1821 sltu AT,c_3,t_1
1822 daddu t_2,AT
1823 daddu c_1,t_2
1824 sltu AT,c_1,t_2
1825 daddu c_2,AT
1826 dmultu a_5,a_3 /* mul_add_c2(a[5],b[3],c3,c1,c2); */
1827 mflo t_1
1828 mfhi t_2
1829 daddu c_3,t_1
1830 sltu AT,c_3,t_1
1831 daddu a2,t_2,AT
1832 daddu c_1,a2
1833 sltu AT,c_1,a2
1834 daddu c_2,AT
1835 daddu c_3,t_1
1836 sltu AT,c_3,t_1
1837 daddu t_2,AT
1838 daddu c_1,t_2
1839 sltu AT,c_1,t_2
1840 daddu c_2,AT
1841 dmultu a_4,a_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
1842 mflo t_1
1843 mfhi t_2
1844 daddu c_3,t_1
1845 sltu AT,c_3,t_1
1846 daddu t_2,AT
1847 daddu c_1,t_2
1848 sltu AT,c_1,t_2
1849 daddu c_2,AT
1850 sd c_3,64(a0)
1851
1852 dmultu a_2,a_7 /* mul_add_c2(a[2],b[7],c1,c2,c3); */
1853 mflo t_1
1854 mfhi t_2
1855 daddu c_1,t_1
1856 sltu AT,c_1,t_1
1857 daddu a2,t_2,AT
1858 daddu c_2,a2
1859 daddu c_1,t_1
1860 sltu AT,c_1,t_1
1861 daddu t_2,AT
1862 daddu c_2,t_2
1863 sltu c_3,c_2,t_2
1864 dmultu a_3,a_6 /* mul_add_c2(a[3],b[6],c1,c2,c3); */
1865 mflo t_1
1866 mfhi t_2
1867 daddu c_1,t_1
1868 sltu AT,c_1,t_1
1869 daddu a2,t_2,AT
1870 daddu c_2,a2
1871 sltu AT,c_2,a2
1872 daddu c_3,AT
1873 daddu c_1,t_1
1874 sltu AT,c_1,t_1
1875 daddu t_2,AT
1876 daddu c_2,t_2
1877 sltu AT,c_2,t_2
1878 daddu c_3,AT
1879 dmultu a_4,a_5 /* mul_add_c2(a[4],b[5],c1,c2,c3); */
1880 mflo t_1
1881 mfhi t_2
1882 daddu c_1,t_1
1883 sltu AT,c_1,t_1
1884 daddu a2,t_2,AT
1885 daddu c_2,a2
1886 sltu AT,c_2,a2
1887 daddu c_3,AT
1888 daddu c_1,t_1
1889 sltu AT,c_1,t_1
1890 daddu t_2,AT
1891 daddu c_2,t_2
1892 sltu AT,c_2,t_2
1893 daddu c_3,AT
1894 sd c_1,72(a0)
1895
1896 dmultu a_7,a_3 /* mul_add_c2(a[7],b[3],c2,c3,c1); */
1897 mflo t_1
1898 mfhi t_2
1899 daddu c_2,t_1
1900 sltu AT,c_2,t_1
1901 daddu a2,t_2,AT
1902 daddu c_3,a2
1903 daddu c_2,t_1
1904 sltu AT,c_2,t_1
1905 daddu t_2,AT
1906 daddu c_3,t_2
1907 sltu c_1,c_3,t_2
1908 dmultu a_6,a_4 /* mul_add_c2(a[6],b[4],c2,c3,c1); */
1909 mflo t_1
1910 mfhi t_2
1911 daddu c_2,t_1
1912 sltu AT,c_2,t_1
1913 daddu a2,t_2,AT
1914 daddu c_3,a2
1915 sltu AT,c_3,a2
1916 daddu c_1,AT
1917 daddu c_2,t_1
1918 sltu AT,c_2,t_1
1919 daddu t_2,AT
1920 daddu c_3,t_2
1921 sltu AT,c_3,t_2
1922 daddu c_1,AT
1923 dmultu a_5,a_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
1924 mflo t_1
1925 mfhi t_2
1926 daddu c_2,t_1
1927 sltu AT,c_2,t_1
1928 daddu t_2,AT
1929 daddu c_3,t_2
1930 sltu AT,c_3,t_2
1931 daddu c_1,AT
1932 sd c_2,80(a0)
1933
1934 dmultu a_4,a_7 /* mul_add_c2(a[4],b[7],c3,c1,c2); */
1935 mflo t_1
1936 mfhi t_2
1937 daddu c_3,t_1
1938 sltu AT,c_3,t_1
1939 daddu a2,t_2,AT
1940 daddu c_1,a2
1941 daddu c_3,t_1
1942 sltu AT,c_3,t_1
1943 daddu t_2,AT
1944 daddu c_1,t_2
1945 sltu c_2,c_1,t_2
1946 dmultu a_5,a_6 /* mul_add_c2(a[5],b[6],c3,c1,c2); */
1947 mflo t_1
1948 mfhi t_2
1949 daddu c_3,t_1
1950 sltu AT,c_3,t_1
1951 daddu a2,t_2,AT
1952 daddu c_1,a2
1953 sltu AT,c_1,a2
1954 daddu c_2,AT
1955 daddu c_3,t_1
1956 sltu AT,c_3,t_1
1957 daddu t_2,AT
1958 daddu c_1,t_2
1959 sltu AT,c_1,t_2
1960 daddu c_2,AT
1961 sd c_3,88(a0)
1962
1963 dmultu a_7,a_5 /* mul_add_c2(a[7],b[5],c1,c2,c3); */
1964 mflo t_1
1965 mfhi t_2
1966 daddu c_1,t_1
1967 sltu AT,c_1,t_1
1968 daddu a2,t_2,AT
1969 daddu c_2,a2
1970 daddu c_1,t_1
1971 sltu AT,c_1,t_1
1972 daddu t_2,AT
1973 daddu c_2,t_2
1974 sltu c_3,c_2,t_2
1975 dmultu a_6,a_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
1976 mflo t_1
1977 mfhi t_2
1978 daddu c_1,t_1
1979 sltu AT,c_1,t_1
1980 daddu t_2,AT
1981 daddu c_2,t_2
1982 sltu AT,c_2,t_2
1983 daddu c_3,AT
1984 sd c_1,96(a0)
1985
1986 dmultu a_6,a_7 /* mul_add_c2(a[6],b[7],c2,c3,c1); */
1987 mflo t_1
1988 mfhi t_2
1989 daddu c_2,t_1
1990 sltu AT,c_2,t_1
1991 daddu a2,t_2,AT
1992 daddu c_3,a2
1993 daddu c_2,t_1
1994 sltu AT,c_2,t_1
1995 daddu t_2,AT
1996 daddu c_3,t_2
1997 sltu c_1,c_3,t_2
1998 sd c_2,104(a0)
1999
2000 dmultu a_7,a_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
2001 mflo t_1
2002 mfhi t_2
2003 daddu c_3,t_1
2004 sltu AT,c_3,t_1
2005 daddu t_2,AT
2006 daddu c_1,t_2
2007 sd c_3,112(a0)
2008 sd c_1,120(a0)
2009
2010 jr ra
2011END(bn_sqr_comba8)
2012
2013.align 5
2014LEAF(bn_sqr_comba4)
2015 .set reorder
2016 ld a_0,0(a1)
2017 ld a_1,8(a1)
2018 ld a_2,16(a1)
2019 ld a_3,24(a1)
2020 dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
2021 mflo c_1
2022 mfhi c_2
2023 sd c_1,0(a0)
2024
2025 dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */
2026 mflo t_1
2027 mfhi t_2
2028 daddu c_2,t_1
2029 sltu AT,c_2,t_1
2030 daddu c_3,t_2,AT
2031 daddu c_2,t_1
2032 sltu AT,c_2,t_1
2033 daddu t_2,AT
2034 daddu c_3,t_2
2035 sltu c_1,c_3,t_2
2036 sd c_2,8(a0)
2037
2038 dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
2039 mflo t_1
2040 mfhi t_2
2041 daddu c_3,t_1
2042 sltu AT,c_3,t_1
2043 daddu a2,t_2,AT
2044 daddu c_1,a2
2045 daddu c_3,t_1
2046 sltu AT,c_3,t_1
2047 daddu t_2,AT
2048 daddu c_1,t_2
2049 sltu c_2,c_1,t_2
2050 dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
2051 mflo t_1
2052 mfhi t_2
2053 daddu c_3,t_1
2054 sltu AT,c_3,t_1
2055 daddu t_2,AT
2056 daddu c_1,t_2
2057 sltu AT,c_1,t_2
2058 daddu c_2,AT
2059 sd c_3,16(a0)
2060
2061 dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
2062 mflo t_1
2063 mfhi t_2
2064 daddu c_1,t_1
2065 sltu AT,c_1,t_1
2066 daddu a2,t_2,AT
2067 daddu c_2,a2
2068 daddu c_1,t_1
2069 sltu AT,c_1,t_1
2070 daddu t_2,AT
2071 daddu c_2,t_2
2072 sltu c_3,c_2,t_2
2073 dmultu a_1,a_2 /* mul_add_c(a2[1],b[2],c1,c2,c3); */
2074 mflo t_1
2075 mfhi t_2
2076 daddu c_1,t_1
2077 sltu AT,c_1,t_1
2078 daddu a2,t_2,AT
2079 daddu c_2,a2
2080 sltu AT,c_2,a2
2081 daddu c_3,AT
2082 daddu c_1,t_1
2083 sltu AT,c_1,t_1
2084 daddu t_2,AT
2085 daddu c_2,t_2
2086 sltu AT,c_2,t_2
2087 daddu c_3,AT
2088 sd c_1,24(a0)
2089
2090 dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
2091 mflo t_1
2092 mfhi t_2
2093 daddu c_2,t_1
2094 sltu AT,c_2,t_1
2095 daddu a2,t_2,AT
2096 daddu c_3,a2
2097 daddu c_2,t_1
2098 sltu AT,c_2,t_1
2099 daddu t_2,AT
2100 daddu c_3,t_2
2101 sltu c_1,c_3,t_2
2102 dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
2103 mflo t_1
2104 mfhi t_2
2105 daddu c_2,t_1
2106 sltu AT,c_2,t_1
2107 daddu t_2,AT
2108 daddu c_3,t_2
2109 sltu AT,c_3,t_2
2110 daddu c_1,AT
2111 sd c_2,32(a0)
2112
2113 dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
2114 mflo t_1
2115 mfhi t_2
2116 daddu c_3,t_1
2117 sltu AT,c_3,t_1
2118 daddu a2,t_2,AT
2119 daddu c_1,a2
2120 daddu c_3,t_1
2121 sltu AT,c_3,t_1
2122 daddu t_2,AT
2123 daddu c_1,t_2
2124 sltu c_2,c_1,t_2
2125 sd c_3,40(a0)
2126
2127 dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
2128 mflo t_1
2129 mfhi t_2
2130 daddu c_1,t_1
2131 sltu AT,c_1,t_1
2132 daddu t_2,AT
2133 daddu c_2,t_2
2134 sd c_1,48(a0)
2135 sd c_2,56(a0)
2136
2137 jr ra
2138END(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 @@
1 .file "bn_mulw.c"
2gcc2_compiled.:
3.section ".text"
4 .align 4
5 .global bn_mul_add_words
6 .type bn_mul_add_words,#function
7 .proc 016
8bn_mul_add_words:
9 !#PROLOGUE# 0
10 save %sp,-112,%sp
11 !#PROLOGUE# 1
12 mov %i0,%o0
13 mov %i1,%o2
14 mov %i2,%g1
15 mov %i3,%o1
16 mov 0,%i4
17 add %o0,12,%g4
18 add %o2,12,%o7
19.LL2:
20 mov %i4,%i3
21 mov 0,%i2
22 ld [%o0],%g2
23 mov %g2,%i1
24 ld [%o2],%g2
25 mov 0,%i0
26 umul %o1,%g2,%g3
27 rd %y,%g2
28 addcc %g3,%i1,%g3
29 addx %g2,%i0,%g2
30 addcc %g3,%i3,%g3
31 addx %g2,%i2,%g2
32 st %g3,[%o0]
33 mov %g2,%i5
34 mov 0,%i4
35 addcc %g1,-1,%g1
36 be .LL3
37 mov %i5,%i4
38 mov %i4,%i3
39 mov 0,%i2
40 ld [%g4-8],%g2
41 mov %g2,%i1
42 ld [%o7-8],%g2
43 mov 0,%i0
44 umul %o1,%g2,%g3
45 rd %y,%g2
46 addcc %g3,%i1,%g3
47 addx %g2,%i0,%g2
48 addcc %g3,%i3,%g3
49 addx %g2,%i2,%g2
50 st %g3,[%g4-8]
51 mov %g2,%i5
52 mov 0,%i4
53 addcc %g1,-1,%g1
54 be .LL3
55 mov %i5,%i4
56 mov %i4,%i3
57 mov 0,%i2
58 ld [%g4-4],%g2
59 mov %g2,%i1
60 ld [%o7-4],%g2
61 mov 0,%i0
62 umul %o1,%g2,%g3
63 rd %y,%g2
64 addcc %g3,%i1,%g3
65 addx %g2,%i0,%g2
66 addcc %g3,%i3,%g3
67 addx %g2,%i2,%g2
68 st %g3,[%g4-4]
69 mov %g2,%i5
70 mov 0,%i4
71 addcc %g1,-1,%g1
72 be .LL3
73 mov %i5,%i4
74 mov %i4,%i3
75 mov 0,%i2
76 ld [%g4],%g2
77 mov %g2,%i1
78 ld [%o7],%g2
79 mov 0,%i0
80 umul %o1,%g2,%g3
81 rd %y,%g2
82 addcc %g3,%i1,%g3
83 addx %g2,%i0,%g2
84 addcc %g3,%i3,%g3
85 addx %g2,%i2,%g2
86 st %g3,[%g4]
87 mov %g2,%i5
88 mov 0,%i4
89 addcc %g1,-1,%g1
90 be .LL3
91 mov %i5,%i4
92 add %o7,16,%o7
93 add %o2,16,%o2
94 add %g4,16,%g4
95 b .LL2
96 add %o0,16,%o0
97.LL3:
98 ret
99 restore %g0,%i4,%o0
100.LLfe1:
101 .size bn_mul_add_words,.LLfe1-bn_mul_add_words
102 .align 4
103 .global bn_mul_words
104 .type bn_mul_words,#function
105 .proc 016
106bn_mul_words:
107 !#PROLOGUE# 0
108 save %sp,-112,%sp
109 !#PROLOGUE# 1
110 mov %i0,%o7
111 mov %i1,%o0
112 mov %i2,%i4
113 mov %i3,%g4
114 mov 0,%i0
115 add %o7,12,%g1
116 add %o0,12,%i5
117.LL18:
118 mov %i0,%g3
119 mov 0,%g2
120 ld [%o0],%i2
121 umul %g4,%i2,%i3
122 rd %y,%i2
123 addcc %i3,%g3,%i3
124 addx %i2,%g2,%i2
125 st %i3,[%o7]
126 mov %i2,%i1
127 mov 0,%i0
128 addcc %i4,-1,%i4
129 be .LL19
130 mov %i1,%i0
131 mov %i0,%g3
132 mov 0,%g2
133 ld [%i5-8],%i2
134 umul %g4,%i2,%i3
135 rd %y,%i2
136 addcc %i3,%g3,%i3
137 addx %i2,%g2,%i2
138 st %i3,[%g1-8]
139 mov %i2,%i1
140 mov 0,%i0
141 addcc %i4,-1,%i4
142 be .LL19
143 mov %i1,%i0
144 mov %i0,%g3
145 mov 0,%g2
146 ld [%i5-4],%i2
147 umul %g4,%i2,%i3
148 rd %y,%i2
149 addcc %i3,%g3,%i3
150 addx %i2,%g2,%i2
151 st %i3,[%g1-4]
152 mov %i2,%i1
153 mov 0,%i0
154 addcc %i4,-1,%i4
155 be .LL19
156 mov %i1,%i0
157 mov %i0,%g3
158 mov 0,%g2
159 ld [%i5],%i2
160 umul %g4,%i2,%i3
161 rd %y,%i2
162 addcc %i3,%g3,%i3
163 addx %i2,%g2,%i2
164 st %i3,[%g1]
165 mov %i2,%i1
166 mov 0,%i0
167 addcc %i4,-1,%i4
168 be .LL19
169 mov %i1,%i0
170 add %i5,16,%i5
171 add %o0,16,%o0
172 add %g1,16,%g1
173 b .LL18
174 add %o7,16,%o7
175.LL19:
176 ret
177 restore
178.LLfe2:
179 .size bn_mul_words,.LLfe2-bn_mul_words
180 .align 4
181 .global bn_sqr_words
182 .type bn_sqr_words,#function
183 .proc 020
184bn_sqr_words:
185 !#PROLOGUE# 0
186 !#PROLOGUE# 1
187 mov %o0,%g4
188 add %g4,28,%o3
189 add %o1,12,%g1
190.LL34:
191 ld [%o1],%o0
192 addcc %o2,-1,%o2
193 umul %o0,%o0,%o5
194 rd %y,%o4
195 st %o5,[%g4]
196 mov %o4,%g3
197 mov 0,%g2
198 be .LL35
199 st %g3,[%o3-24]
200 ld [%g1-8],%o0
201 addcc %o2,-1,%o2
202 umul %o0,%o0,%o5
203 rd %y,%o4
204 st %o5,[%o3-20]
205 mov %o4,%g3
206 mov 0,%g2
207 be .LL35
208 st %g3,[%o3-16]
209 ld [%g1-4],%o0
210 addcc %o2,-1,%o2
211 umul %o0,%o0,%o5
212 rd %y,%o4
213 st %o5,[%o3-12]
214 mov %o4,%g3
215 mov 0,%g2
216 be .LL35
217 st %g3,[%o3-8]
218 ld [%g1],%o0
219 addcc %o2,-1,%o2
220 umul %o0,%o0,%o5
221 rd %y,%o4
222 st %o5,[%o3-4]
223 mov %o4,%g3
224 mov 0,%g2
225 be .LL35
226 st %g3,[%o3]
227 add %g1,16,%g1
228 add %o1,16,%o1
229 add %o3,32,%o3
230 b .LL34
231 add %g4,32,%g4
232.LL35:
233 retl
234 nop
235.LLfe3:
236 .size bn_sqr_words,.LLfe3-bn_sqr_words
237 .align 4
238 .global bn_add_words
239 .type bn_add_words,#function
240 .proc 016
241bn_add_words:
242 !#PROLOGUE# 0
243 save %sp,-112,%sp
244 !#PROLOGUE# 1
245 mov %i0,%o2
246 mov %i1,%o3
247 mov %i2,%o4
248 mov %i3,%i5
249 mov 0,%o0
250 mov 0,%o1
251 add %o2,12,%o7
252 add %o4,12,%g4
253 b .LL42
254 add %o3,12,%g1
255.LL45:
256 add %i5,-1,%i5
257 mov %i4,%g3
258 ld [%g4-8],%i4
259 mov 0,%g2
260 mov %i4,%i1
261 mov 0,%i0
262 addcc %g3,%i1,%g3
263 addx %g2,%i0,%g2
264 addcc %o1,%g3,%o1
265 addx %o0,%g2,%o0
266 st %o1,[%o7-8]
267 mov %o0,%i3
268 mov 0,%i2
269 mov %i2,%o0
270 mov %i3,%o1
271 cmp %i5,0
272 ble .LL43
273 add %i5,-1,%i5
274 ld [%g1-4],%i4
275 mov %i4,%g3
276 ld [%g4-4],%i4
277 mov 0,%g2
278 mov %i4,%i1
279 mov 0,%i0
280 addcc %g3,%i1,%g3
281 addx %g2,%i0,%g2
282 addcc %o1,%g3,%o1
283 addx %o0,%g2,%o0
284 st %o1,[%o7-4]
285 mov %o0,%i3
286 mov 0,%i2
287 mov %i2,%o0
288 mov %i3,%o1
289 cmp %i5,0
290 ble .LL43
291 add %i5,-1,%i5
292 ld [%g1],%i4
293 mov %i4,%g3
294 ld [%g4],%i4
295 mov 0,%g2
296 mov %i4,%i1
297 mov 0,%i0
298 addcc %g3,%i1,%g3
299 addx %g2,%i0,%g2
300 addcc %o1,%g3,%o1
301 addx %o0,%g2,%o0
302 st %o1,[%o7]
303 mov %o0,%i3
304 mov 0,%i2
305 mov %i2,%o0
306 mov %i3,%o1
307 cmp %i5,0
308 ble .LL43
309 add %g1,16,%g1
310 add %o3,16,%o3
311 add %g4,16,%g4
312 add %o4,16,%o4
313 add %o7,16,%o7
314 add %o2,16,%o2
315.LL42:
316 ld [%o3],%i4
317 add %i5,-1,%i5
318 mov %i4,%g3
319 ld [%o4],%i4
320 mov 0,%g2
321 mov %i4,%i1
322 mov 0,%i0
323 addcc %g3,%i1,%g3
324 addx %g2,%i0,%g2
325 addcc %o1,%g3,%o1
326 addx %o0,%g2,%o0
327 st %o1,[%o2]
328 mov %o0,%i3
329 mov 0,%i2
330 mov %i2,%o0
331 mov %i3,%o1
332 cmp %i5,0
333 bg,a .LL45
334 ld [%g1-8],%i4
335.LL43:
336 ret
337 restore %g0,%o1,%o0
338.LLfe4:
339 .size bn_add_words,.LLfe4-bn_add_words
340.section ".rodata"
341 .align 8
342.LLC0:
343 .asciz "Division would overflow (%d)\n"
344.section ".text"
345 .align 4
346 .global bn_div64
347 .type bn_div64,#function
348 .proc 016
349bn_div64:
350 !#PROLOGUE# 0
351 save %sp,-112,%sp
352 !#PROLOGUE# 1
353 mov 0,%l1
354 cmp %i2,0
355 bne .LL51
356 mov 2,%l0
357 b .LL68
358 mov -1,%i0
359.LL51:
360 call BN_num_bits_word,0
361 mov %i2,%o0
362 mov %o0,%o2
363 cmp %o2,32
364 be .LL52
365 mov 1,%o0
366 sll %o0,%o2,%o0
367 cmp %i0,%o0
368 bleu .LL69
369 mov 32,%o0
370 sethi %hi(__iob+32),%o0
371 or %o0,%lo(__iob+32),%o0
372 sethi %hi(.LLC0),%o1
373 call fprintf,0
374 or %o1,%lo(.LLC0),%o1
375 call abort,0
376 nop
377.LL52:
378 mov 32,%o0
379.LL69:
380 cmp %i0,%i2
381 blu .LL53
382 sub %o0,%o2,%o2
383 sub %i0,%i2,%i0
384.LL53:
385 cmp %o2,0
386 be .LL54
387 sll %i0,%o2,%o1
388 sll %i2,%o2,%i2
389 sub %o0,%o2,%o0
390 srl %i1,%o0,%o0
391 or %o1,%o0,%i0
392 sll %i1,%o2,%i1
393.LL54:
394 srl %i2,16,%g2
395 sethi %hi(65535),%o0
396 or %o0,%lo(65535),%o1
397 and %i2,%o1,%g3
398 mov %o0,%g4
399 sethi %hi(-65536),%o7
400 mov %o1,%g1
401.LL55:
402 srl %i0,16,%o0
403 cmp %o0,%g2
404 be .LL59
405 or %g4,%lo(65535),%o3
406 wr %g0,%g0,%y
407 nop
408 nop
409 nop
410 udiv %i0,%g2,%o3
411.LL59:
412 and %i1,%o7,%o0
413 srl %o0,16,%o5
414 smul %o3,%g3,%o4
415 smul %o3,%g2,%o2
416.LL60:
417 sub %i0,%o2,%o1
418 andcc %o1,%o7,%g0
419 bne .LL61
420 sll %o1,16,%o0
421 add %o0,%o5,%o0
422 cmp %o4,%o0
423 bleu .LL61
424 sub %o4,%g3,%o4
425 sub %o2,%g2,%o2
426 b .LL60
427 add %o3,-1,%o3
428.LL61:
429 smul %o3,%g2,%o2
430 smul %o3,%g3,%o0
431 srl %o0,16,%o1
432 sll %o0,16,%o0
433 and %o0,%o7,%o0
434 cmp %i1,%o0
435 bgeu .LL65
436 add %o2,%o1,%o2
437 add %o2,1,%o2
438.LL65:
439 cmp %i0,%o2
440 bgeu .LL66
441 sub %i1,%o0,%i1
442 add %i0,%i2,%i0
443 add %o3,-1,%o3
444.LL66:
445 addcc %l0,-1,%l0
446 be .LL56
447 sub %i0,%o2,%i0
448 sll %o3,16,%l1
449 sll %i0,16,%o0
450 srl %i1,16,%o1
451 or %o0,%o1,%i0
452 and %i1,%g1,%o0
453 b .LL55
454 sll %o0,16,%i1
455.LL56:
456 or %l1,%o3,%i0
457.LL68:
458 ret
459 restore
460.LLfe5:
461 .size bn_div64,.LLfe5-bn_div64
462 .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 @@
1.ident "sparcv8.s, Version 1.4"
2.ident "SPARC v8 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4/*
5 * ====================================================================
6 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7 * project.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted according to the OpenSSL license. Warranty of any kind is
11 * disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contributon to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is
18 * a drop-in SuperSPARC ISA replacement for crypto/bn/bn_asm.c
19 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20 *
21 * See bn_asm.sparc.v8plus.S for more details.
22 */
23
24/*
25 * Revision history.
26 *
27 * 1.1 - new loop unrolling model(*);
28 * 1.2 - made gas friendly;
29 * 1.3 - fixed problem with /usr/ccs/lib/cpp;
30 * 1.4 - some retunes;
31 *
32 * (*) see bn_asm.sparc.v8plus.S for details
33 */
34
35.section ".text",#alloc,#execinstr
36.file "bn_asm.sparc.v8.S"
37
38.align 32
39
40.global bn_mul_add_words
41/*
42 * BN_ULONG bn_mul_add_words(rp,ap,num,w)
43 * BN_ULONG *rp,*ap;
44 * int num;
45 * BN_ULONG w;
46 */
47bn_mul_add_words:
48 cmp %o2,0
49 bg,a .L_bn_mul_add_words_proceed
50 ld [%o1],%g2
51 retl
52 clr %o0
53
54.L_bn_mul_add_words_proceed:
55 andcc %o2,-4,%g0
56 bz .L_bn_mul_add_words_tail
57 clr %o5
58
59.L_bn_mul_add_words_loop:
60 ld [%o0],%o4
61 ld [%o1+4],%g3
62 umul %o3,%g2,%g2
63 rd %y,%g1
64 addcc %o4,%o5,%o4
65 addx %g1,0,%g1
66 addcc %o4,%g2,%o4
67 st %o4,[%o0]
68 addx %g1,0,%o5
69
70 ld [%o0+4],%o4
71 ld [%o1+8],%g2
72 umul %o3,%g3,%g3
73 dec 4,%o2
74 rd %y,%g1
75 addcc %o4,%o5,%o4
76 addx %g1,0,%g1
77 addcc %o4,%g3,%o4
78 st %o4,[%o0+4]
79 addx %g1,0,%o5
80
81 ld [%o0+8],%o4
82 ld [%o1+12],%g3
83 umul %o3,%g2,%g2
84 inc 16,%o1
85 rd %y,%g1
86 addcc %o4,%o5,%o4
87 addx %g1,0,%g1
88 addcc %o4,%g2,%o4
89 st %o4,[%o0+8]
90 addx %g1,0,%o5
91
92 ld [%o0+12],%o4
93 umul %o3,%g3,%g3
94 inc 16,%o0
95 rd %y,%g1
96 addcc %o4,%o5,%o4
97 addx %g1,0,%g1
98 addcc %o4,%g3,%o4
99 st %o4,[%o0-4]
100 addx %g1,0,%o5
101 andcc %o2,-4,%g0
102 bnz,a .L_bn_mul_add_words_loop
103 ld [%o1],%g2
104
105 tst %o2
106 bnz,a .L_bn_mul_add_words_tail
107 ld [%o1],%g2
108.L_bn_mul_add_words_return:
109 retl
110 mov %o5,%o0
111 nop
112
113.L_bn_mul_add_words_tail:
114 ld [%o0],%o4
115 umul %o3,%g2,%g2
116 addcc %o4,%o5,%o4
117 rd %y,%g1
118 addx %g1,0,%g1
119 addcc %o4,%g2,%o4
120 addx %g1,0,%o5
121 deccc %o2
122 bz .L_bn_mul_add_words_return
123 st %o4,[%o0]
124
125 ld [%o1+4],%g2
126 ld [%o0+4],%o4
127 umul %o3,%g2,%g2
128 rd %y,%g1
129 addcc %o4,%o5,%o4
130 addx %g1,0,%g1
131 addcc %o4,%g2,%o4
132 addx %g1,0,%o5
133 deccc %o2
134 bz .L_bn_mul_add_words_return
135 st %o4,[%o0+4]
136
137 ld [%o1+8],%g2
138 ld [%o0+8],%o4
139 umul %o3,%g2,%g2
140 rd %y,%g1
141 addcc %o4,%o5,%o4
142 addx %g1,0,%g1
143 addcc %o4,%g2,%o4
144 st %o4,[%o0+8]
145 retl
146 addx %g1,0,%o0
147
148.type bn_mul_add_words,#function
149.size bn_mul_add_words,(.-bn_mul_add_words)
150
151.align 32
152
153.global bn_mul_words
154/*
155 * BN_ULONG bn_mul_words(rp,ap,num,w)
156 * BN_ULONG *rp,*ap;
157 * int num;
158 * BN_ULONG w;
159 */
160bn_mul_words:
161 cmp %o2,0
162 bg,a .L_bn_mul_words_proceeed
163 ld [%o1],%g2
164 retl
165 clr %o0
166
167.L_bn_mul_words_proceeed:
168 andcc %o2,-4,%g0
169 bz .L_bn_mul_words_tail
170 clr %o5
171
172.L_bn_mul_words_loop:
173 ld [%o1+4],%g3
174 umul %o3,%g2,%g2
175 addcc %g2,%o5,%g2
176 rd %y,%g1
177 addx %g1,0,%o5
178 st %g2,[%o0]
179
180 ld [%o1+8],%g2
181 umul %o3,%g3,%g3
182 addcc %g3,%o5,%g3
183 rd %y,%g1
184 dec 4,%o2
185 addx %g1,0,%o5
186 st %g3,[%o0+4]
187
188 ld [%o1+12],%g3
189 umul %o3,%g2,%g2
190 addcc %g2,%o5,%g2
191 rd %y,%g1
192 inc 16,%o1
193 st %g2,[%o0+8]
194 addx %g1,0,%o5
195
196 umul %o3,%g3,%g3
197 addcc %g3,%o5,%g3
198 rd %y,%g1
199 inc 16,%o0
200 addx %g1,0,%o5
201 st %g3,[%o0-4]
202 andcc %o2,-4,%g0
203 nop
204 bnz,a .L_bn_mul_words_loop
205 ld [%o1],%g2
206
207 tst %o2
208 bnz,a .L_bn_mul_words_tail
209 ld [%o1],%g2
210.L_bn_mul_words_return:
211 retl
212 mov %o5,%o0
213 nop
214
215.L_bn_mul_words_tail:
216 umul %o3,%g2,%g2
217 addcc %g2,%o5,%g2
218 rd %y,%g1
219 addx %g1,0,%o5
220 deccc %o2
221 bz .L_bn_mul_words_return
222 st %g2,[%o0]
223 nop
224
225 ld [%o1+4],%g2
226 umul %o3,%g2,%g2
227 addcc %g2,%o5,%g2
228 rd %y,%g1
229 addx %g1,0,%o5
230 deccc %o2
231 bz .L_bn_mul_words_return
232 st %g2,[%o0+4]
233
234 ld [%o1+8],%g2
235 umul %o3,%g2,%g2
236 addcc %g2,%o5,%g2
237 rd %y,%g1
238 st %g2,[%o0+8]
239 retl
240 addx %g1,0,%o0
241
242.type bn_mul_words,#function
243.size bn_mul_words,(.-bn_mul_words)
244
245.align 32
246.global bn_sqr_words
247/*
248 * void bn_sqr_words(r,a,n)
249 * BN_ULONG *r,*a;
250 * int n;
251 */
252bn_sqr_words:
253 cmp %o2,0
254 bg,a .L_bn_sqr_words_proceeed
255 ld [%o1],%g2
256 retl
257 clr %o0
258
259.L_bn_sqr_words_proceeed:
260 andcc %o2,-4,%g0
261 bz .L_bn_sqr_words_tail
262 clr %o5
263
264.L_bn_sqr_words_loop:
265 ld [%o1+4],%g3
266 umul %g2,%g2,%o4
267 st %o4,[%o0]
268 rd %y,%o5
269 st %o5,[%o0+4]
270
271 ld [%o1+8],%g2
272 umul %g3,%g3,%o4
273 dec 4,%o2
274 st %o4,[%o0+8]
275 rd %y,%o5
276 st %o5,[%o0+12]
277 nop
278
279 ld [%o1+12],%g3
280 umul %g2,%g2,%o4
281 st %o4,[%o0+16]
282 rd %y,%o5
283 inc 16,%o1
284 st %o5,[%o0+20]
285
286 umul %g3,%g3,%o4
287 inc 32,%o0
288 st %o4,[%o0-8]
289 rd %y,%o5
290 st %o5,[%o0-4]
291 andcc %o2,-4,%g2
292 bnz,a .L_bn_sqr_words_loop
293 ld [%o1],%g2
294
295 tst %o2
296 nop
297 bnz,a .L_bn_sqr_words_tail
298 ld [%o1],%g2
299.L_bn_sqr_words_return:
300 retl
301 clr %o0
302
303.L_bn_sqr_words_tail:
304 umul %g2,%g2,%o4
305 st %o4,[%o0]
306 deccc %o2
307 rd %y,%o5
308 bz .L_bn_sqr_words_return
309 st %o5,[%o0+4]
310
311 ld [%o1+4],%g2
312 umul %g2,%g2,%o4
313 st %o4,[%o0+8]
314 deccc %o2
315 rd %y,%o5
316 nop
317 bz .L_bn_sqr_words_return
318 st %o5,[%o0+12]
319
320 ld [%o1+8],%g2
321 umul %g2,%g2,%o4
322 st %o4,[%o0+16]
323 rd %y,%o5
324 st %o5,[%o0+20]
325 retl
326 clr %o0
327
328.type bn_sqr_words,#function
329.size bn_sqr_words,(.-bn_sqr_words)
330
331.align 32
332
333.global bn_div_words
334/*
335 * BN_ULONG bn_div_words(h,l,d)
336 * BN_ULONG h,l,d;
337 */
338bn_div_words:
339 wr %o0,%y
340 udiv %o1,%o2,%o0
341 retl
342 nop
343
344.type bn_div_words,#function
345.size bn_div_words,(.-bn_div_words)
346
347.align 32
348
349.global bn_add_words
350/*
351 * BN_ULONG bn_add_words(rp,ap,bp,n)
352 * BN_ULONG *rp,*ap,*bp;
353 * int n;
354 */
355bn_add_words:
356 cmp %o3,0
357 bg,a .L_bn_add_words_proceed
358 ld [%o1],%o4
359 retl
360 clr %o0
361
362.L_bn_add_words_proceed:
363 andcc %o3,-4,%g0
364 bz .L_bn_add_words_tail
365 clr %g1
366 ba .L_bn_add_words_warn_loop
367 addcc %g0,0,%g0 ! clear carry flag
368
369.L_bn_add_words_loop:
370 ld [%o1],%o4
371.L_bn_add_words_warn_loop:
372 ld [%o2],%o5
373 ld [%o1+4],%g3
374 ld [%o2+4],%g4
375 dec 4,%o3
376 addxcc %o5,%o4,%o5
377 st %o5,[%o0]
378
379 ld [%o1+8],%o4
380 ld [%o2+8],%o5
381 inc 16,%o1
382 addxcc %g3,%g4,%g3
383 st %g3,[%o0+4]
384
385 ld [%o1-4],%g3
386 ld [%o2+12],%g4
387 inc 16,%o2
388 addxcc %o5,%o4,%o5
389 st %o5,[%o0+8]
390
391 inc 16,%o0
392 addxcc %g3,%g4,%g3
393 st %g3,[%o0-4]
394 addx %g0,0,%g1
395 andcc %o3,-4,%g0
396 bnz,a .L_bn_add_words_loop
397 addcc %g1,-1,%g0
398
399 tst %o3
400 bnz,a .L_bn_add_words_tail
401 ld [%o1],%o4
402.L_bn_add_words_return:
403 retl
404 mov %g1,%o0
405
406.L_bn_add_words_tail:
407 addcc %g1,-1,%g0
408 ld [%o2],%o5
409 addxcc %o5,%o4,%o5
410 addx %g0,0,%g1
411 deccc %o3
412 bz .L_bn_add_words_return
413 st %o5,[%o0]
414
415 ld [%o1+4],%o4
416 addcc %g1,-1,%g0
417 ld [%o2+4],%o5
418 addxcc %o5,%o4,%o5
419 addx %g0,0,%g1
420 deccc %o3
421 bz .L_bn_add_words_return
422 st %o5,[%o0+4]
423
424 ld [%o1+8],%o4
425 addcc %g1,-1,%g0
426 ld [%o2+8],%o5
427 addxcc %o5,%o4,%o5
428 st %o5,[%o0+8]
429 retl
430 addx %g0,0,%o0
431
432.type bn_add_words,#function
433.size bn_add_words,(.-bn_add_words)
434
435.align 32
436
437.global bn_sub_words
438/*
439 * BN_ULONG bn_sub_words(rp,ap,bp,n)
440 * BN_ULONG *rp,*ap,*bp;
441 * int n;
442 */
443bn_sub_words:
444 cmp %o3,0
445 bg,a .L_bn_sub_words_proceed
446 ld [%o1],%o4
447 retl
448 clr %o0
449
450.L_bn_sub_words_proceed:
451 andcc %o3,-4,%g0
452 bz .L_bn_sub_words_tail
453 clr %g1
454 ba .L_bn_sub_words_warm_loop
455 addcc %g0,0,%g0 ! clear carry flag
456
457.L_bn_sub_words_loop:
458 ld [%o1],%o4
459.L_bn_sub_words_warm_loop:
460 ld [%o2],%o5
461 ld [%o1+4],%g3
462 ld [%o2+4],%g4
463 dec 4,%o3
464 subxcc %o4,%o5,%o5
465 st %o5,[%o0]
466
467 ld [%o1+8],%o4
468 ld [%o2+8],%o5
469 inc 16,%o1
470 subxcc %g3,%g4,%g4
471 st %g4,[%o0+4]
472
473 ld [%o1-4],%g3
474 ld [%o2+12],%g4
475 inc 16,%o2
476 subxcc %o4,%o5,%o5
477 st %o5,[%o0+8]
478
479 inc 16,%o0
480 subxcc %g3,%g4,%g4
481 st %g4,[%o0-4]
482 addx %g0,0,%g1
483 andcc %o3,-4,%g0
484 bnz,a .L_bn_sub_words_loop
485 addcc %g1,-1,%g0
486
487 tst %o3
488 nop
489 bnz,a .L_bn_sub_words_tail
490 ld [%o1],%o4
491.L_bn_sub_words_return:
492 retl
493 mov %g1,%o0
494
495.L_bn_sub_words_tail:
496 addcc %g1,-1,%g0
497 ld [%o2],%o5
498 subxcc %o4,%o5,%o5
499 addx %g0,0,%g1
500 deccc %o3
501 bz .L_bn_sub_words_return
502 st %o5,[%o0]
503 nop
504
505 ld [%o1+4],%o4
506 addcc %g1,-1,%g0
507 ld [%o2+4],%o5
508 subxcc %o4,%o5,%o5
509 addx %g0,0,%g1
510 deccc %o3
511 bz .L_bn_sub_words_return
512 st %o5,[%o0+4]
513
514 ld [%o1+8],%o4
515 addcc %g1,-1,%g0
516 ld [%o2+8],%o5
517 subxcc %o4,%o5,%o5
518 st %o5,[%o0+8]
519 retl
520 addx %g0,0,%o0
521
522.type bn_sub_words,#function
523.size bn_sub_words,(.-bn_sub_words)
524
525#define FRAME_SIZE -96
526
527/*
528 * Here is register usage map for *all* routines below.
529 */
530#define t_1 %o0
531#define t_2 %o1
532#define c_1 %o2
533#define c_2 %o3
534#define c_3 %o4
535
536#define ap(I) [%i1+4*I]
537#define bp(I) [%i2+4*I]
538#define rp(I) [%i0+4*I]
539
540#define a_0 %l0
541#define a_1 %l1
542#define a_2 %l2
543#define a_3 %l3
544#define a_4 %l4
545#define a_5 %l5
546#define a_6 %l6
547#define a_7 %l7
548
549#define b_0 %i3
550#define b_1 %i4
551#define b_2 %i5
552#define b_3 %o5
553#define b_4 %g1
554#define b_5 %g2
555#define b_6 %g3
556#define b_7 %g4
557
558.align 32
559.global bn_mul_comba8
560/*
561 * void bn_mul_comba8(r,a,b)
562 * BN_ULONG *r,*a,*b;
563 */
564bn_mul_comba8:
565 save %sp,FRAME_SIZE,%sp
566 ld ap(0),a_0
567 ld bp(0),b_0
568 umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3);
569 ld bp(1),b_1
570 rd %y,c_2
571 st c_1,rp(0) !r[0]=c1;
572
573 umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1);
574 ld ap(1),a_1
575 addcc c_2,t_1,c_2
576 rd %y,t_2
577 addxcc %g0,t_2,c_3 !=
578 addx %g0,%g0,c_1
579 ld ap(2),a_2
580 umul a_1,b_0,t_1 !mul_add_c(a[1],b[0],c2,c3,c1);
581 addcc c_2,t_1,c_2 !=
582 rd %y,t_2
583 addxcc c_3,t_2,c_3
584 st c_2,rp(1) !r[1]=c2;
585 addx c_1,%g0,c_1 !=
586
587 umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
588 addcc c_3,t_1,c_3
589 rd %y,t_2
590 addxcc c_1,t_2,c_1 !=
591 addx %g0,%g0,c_2
592 ld bp(2),b_2
593 umul a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
594 addcc c_3,t_1,c_3 !=
595 rd %y,t_2
596 addxcc c_1,t_2,c_1
597 ld bp(3),b_3
598 addx c_2,%g0,c_2 !=
599 umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
600 addcc c_3,t_1,c_3
601 rd %y,t_2
602 addxcc c_1,t_2,c_1 !=
603 addx c_2,%g0,c_2
604 st c_3,rp(2) !r[2]=c3;
605
606 umul a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
607 addcc c_1,t_1,c_1 !=
608 rd %y,t_2
609 addxcc c_2,t_2,c_2
610 addx %g0,%g0,c_3
611 umul a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
612 addcc c_1,t_1,c_1
613 rd %y,t_2
614 addxcc c_2,t_2,c_2
615 addx c_3,%g0,c_3 !=
616 ld ap(3),a_3
617 umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
618 addcc c_1,t_1,c_1
619 rd %y,t_2 !=
620 addxcc c_2,t_2,c_2
621 addx c_3,%g0,c_3
622 ld ap(4),a_4
623 umul a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
624 addcc c_1,t_1,c_1
625 rd %y,t_2
626 addxcc c_2,t_2,c_2
627 addx c_3,%g0,c_3 !=
628 st c_1,rp(3) !r[3]=c1;
629
630 umul a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
631 addcc c_2,t_1,c_2
632 rd %y,t_2 !=
633 addxcc c_3,t_2,c_3
634 addx %g0,%g0,c_1
635 umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
636 addcc c_2,t_1,c_2 !=
637 rd %y,t_2
638 addxcc c_3,t_2,c_3
639 addx c_1,%g0,c_1
640 umul a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
641 addcc c_2,t_1,c_2
642 rd %y,t_2
643 addxcc c_3,t_2,c_3
644 addx c_1,%g0,c_1 !=
645 ld bp(4),b_4
646 umul a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
647 addcc c_2,t_1,c_2
648 rd %y,t_2 !=
649 addxcc c_3,t_2,c_3
650 addx c_1,%g0,c_1
651 ld bp(5),b_5
652 umul a_0,b_4,t_1 !=!mul_add_c(a[0],b[4],c2,c3,c1);
653 addcc c_2,t_1,c_2
654 rd %y,t_2
655 addxcc c_3,t_2,c_3
656 addx c_1,%g0,c_1 !=
657 st c_2,rp(4) !r[4]=c2;
658
659 umul a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
660 addcc c_3,t_1,c_3
661 rd %y,t_2 !=
662 addxcc c_1,t_2,c_1
663 addx %g0,%g0,c_2
664 umul a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
665 addcc c_3,t_1,c_3 !=
666 rd %y,t_2
667 addxcc c_1,t_2,c_1
668 addx c_2,%g0,c_2
669 umul a_2,b_3,t_1 !=!mul_add_c(a[2],b[3],c3,c1,c2);
670 addcc c_3,t_1,c_3
671 rd %y,t_2
672 addxcc c_1,t_2,c_1
673 addx c_2,%g0,c_2 !=
674 umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
675 addcc c_3,t_1,c_3
676 rd %y,t_2
677 addxcc c_1,t_2,c_1 !=
678 addx c_2,%g0,c_2
679 ld ap(5),a_5
680 umul a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
681 addcc c_3,t_1,c_3 !=
682 rd %y,t_2
683 addxcc c_1,t_2,c_1
684 ld ap(6),a_6
685 addx c_2,%g0,c_2 !=
686 umul a_5,b_0,t_1 !mul_add_c(a[5],b[0],c3,c1,c2);
687 addcc c_3,t_1,c_3
688 rd %y,t_2
689 addxcc c_1,t_2,c_1 !=
690 addx c_2,%g0,c_2
691 st c_3,rp(5) !r[5]=c3;
692
693 umul a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
694 addcc c_1,t_1,c_1 !=
695 rd %y,t_2
696 addxcc c_2,t_2,c_2
697 addx %g0,%g0,c_3
698 umul a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3);
699 addcc c_1,t_1,c_1
700 rd %y,t_2
701 addxcc c_2,t_2,c_2
702 addx c_3,%g0,c_3 !=
703 umul a_4,b_2,t_1 !mul_add_c(a[4],b[2],c1,c2,c3);
704 addcc c_1,t_1,c_1
705 rd %y,t_2
706 addxcc c_2,t_2,c_2 !=
707 addx c_3,%g0,c_3
708 umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
709 addcc c_1,t_1,c_1
710 rd %y,t_2 !=
711 addxcc c_2,t_2,c_2
712 addx c_3,%g0,c_3
713 umul a_2,b_4,t_1 !mul_add_c(a[2],b[4],c1,c2,c3);
714 addcc c_1,t_1,c_1 !=
715 rd %y,t_2
716 addxcc c_2,t_2,c_2
717 ld bp(6),b_6
718 addx c_3,%g0,c_3 !=
719 umul a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
720 addcc c_1,t_1,c_1
721 rd %y,t_2
722 addxcc c_2,t_2,c_2 !=
723 addx c_3,%g0,c_3
724 ld bp(7),b_7
725 umul a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
726 addcc c_1,t_1,c_1 !=
727 rd %y,t_2
728 addxcc c_2,t_2,c_2
729 st c_1,rp(6) !r[6]=c1;
730 addx c_3,%g0,c_3 !=
731
732 umul a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
733 addcc c_2,t_1,c_2
734 rd %y,t_2
735 addxcc c_3,t_2,c_3 !=
736 addx %g0,%g0,c_1
737 umul a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1);
738 addcc c_2,t_1,c_2
739 rd %y,t_2 !=
740 addxcc c_3,t_2,c_3
741 addx c_1,%g0,c_1
742 umul a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1);
743 addcc c_2,t_1,c_2 !=
744 rd %y,t_2
745 addxcc c_3,t_2,c_3
746 addx c_1,%g0,c_1
747 umul a_3,b_4,t_1 !=!mul_add_c(a[3],b[4],c2,c3,c1);
748 addcc c_2,t_1,c_2
749 rd %y,t_2
750 addxcc c_3,t_2,c_3
751 addx c_1,%g0,c_1 !=
752 umul a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
753 addcc c_2,t_1,c_2
754 rd %y,t_2
755 addxcc c_3,t_2,c_3 !=
756 addx c_1,%g0,c_1
757 umul a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
758 addcc c_2,t_1,c_2
759 rd %y,t_2 !=
760 addxcc c_3,t_2,c_3
761 addx c_1,%g0,c_1
762 ld ap(7),a_7
763 umul a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
764 addcc c_2,t_1,c_2
765 rd %y,t_2
766 addxcc c_3,t_2,c_3
767 addx c_1,%g0,c_1 !=
768 umul a_7,b_0,t_1 !mul_add_c(a[7],b[0],c2,c3,c1);
769 addcc c_2,t_1,c_2
770 rd %y,t_2
771 addxcc c_3,t_2,c_3 !=
772 addx c_1,%g0,c_1
773 st c_2,rp(7) !r[7]=c2;
774
775 umul a_7,b_1,t_1 !mul_add_c(a[7],b[1],c3,c1,c2);
776 addcc c_3,t_1,c_3 !=
777 rd %y,t_2
778 addxcc c_1,t_2,c_1
779 addx %g0,%g0,c_2
780 umul a_6,b_2,t_1 !=!mul_add_c(a[6],b[2],c3,c1,c2);
781 addcc c_3,t_1,c_3
782 rd %y,t_2
783 addxcc c_1,t_2,c_1
784 addx c_2,%g0,c_2 !=
785 umul a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2);
786 addcc c_3,t_1,c_3
787 rd %y,t_2
788 addxcc c_1,t_2,c_1 !=
789 addx c_2,%g0,c_2
790 umul a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
791 addcc c_3,t_1,c_3
792 rd %y,t_2 !=
793 addxcc c_1,t_2,c_1
794 addx c_2,%g0,c_2
795 umul a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
796 addcc c_3,t_1,c_3 !=
797 rd %y,t_2
798 addxcc c_1,t_2,c_1
799 addx c_2,%g0,c_2
800 umul a_2,b_6,t_1 !=!mul_add_c(a[2],b[6],c3,c1,c2);
801 addcc c_3,t_1,c_3
802 rd %y,t_2
803 addxcc c_1,t_2,c_1
804 addx c_2,%g0,c_2 !=
805 umul a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
806 addcc c_3,t_1,c_3
807 rd %y,t_2
808 addxcc c_1,t_2,c_1 !
809 addx c_2,%g0,c_2
810 st c_3,rp(8) !r[8]=c3;
811
812 umul a_2,b_7,t_1 !mul_add_c(a[2],b[7],c1,c2,c3);
813 addcc c_1,t_1,c_1 !=
814 rd %y,t_2
815 addxcc c_2,t_2,c_2
816 addx %g0,%g0,c_3
817 umul a_3,b_6,t_1 !=!mul_add_c(a[3],b[6],c1,c2,c3);
818 addcc c_1,t_1,c_1
819 rd %y,t_2
820 addxcc c_2,t_2,c_2
821 addx c_3,%g0,c_3 !=
822 umul a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
823 addcc c_1,t_1,c_1
824 rd %y,t_2
825 addxcc c_2,t_2,c_2 !=
826 addx c_3,%g0,c_3
827 umul a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
828 addcc c_1,t_1,c_1
829 rd %y,t_2 !=
830 addxcc c_2,t_2,c_2
831 addx c_3,%g0,c_3
832 umul a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
833 addcc c_1,t_1,c_1 !=
834 rd %y,t_2
835 addxcc c_2,t_2,c_2
836 addx c_3,%g0,c_3
837 umul a_7,b_2,t_1 !=!mul_add_c(a[7],b[2],c1,c2,c3);
838 addcc c_1,t_1,c_1
839 rd %y,t_2
840 addxcc c_2,t_2,c_2
841 addx c_3,%g0,c_3 !=
842 st c_1,rp(9) !r[9]=c1;
843
844 umul a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
845 addcc c_2,t_1,c_2
846 rd %y,t_2 !=
847 addxcc c_3,t_2,c_3
848 addx %g0,%g0,c_1
849 umul a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
850 addcc c_2,t_1,c_2 !=
851 rd %y,t_2
852 addxcc c_3,t_2,c_3
853 addx c_1,%g0,c_1
854 umul a_5,b_5,t_1 !=!mul_add_c(a[5],b[5],c2,c3,c1);
855 addcc c_2,t_1,c_2
856 rd %y,t_2
857 addxcc c_3,t_2,c_3
858 addx c_1,%g0,c_1 !=
859 umul a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
860 addcc c_2,t_1,c_2
861 rd %y,t_2
862 addxcc c_3,t_2,c_3 !=
863 addx c_1,%g0,c_1
864 umul a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
865 addcc c_2,t_1,c_2
866 rd %y,t_2 !=
867 addxcc c_3,t_2,c_3
868 addx c_1,%g0,c_1
869 st c_2,rp(10) !r[10]=c2;
870
871 umul a_4,b_7,t_1 !=!mul_add_c(a[4],b[7],c3,c1,c2);
872 addcc c_3,t_1,c_3
873 rd %y,t_2
874 addxcc c_1,t_2,c_1
875 addx %g0,%g0,c_2 !=
876 umul a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
877 addcc c_3,t_1,c_3
878 rd %y,t_2
879 addxcc c_1,t_2,c_1 !=
880 addx c_2,%g0,c_2
881 umul a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
882 addcc c_3,t_1,c_3
883 rd %y,t_2 !=
884 addxcc c_1,t_2,c_1
885 addx c_2,%g0,c_2
886 umul a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
887 addcc c_3,t_1,c_3 !=
888 rd %y,t_2
889 addxcc c_1,t_2,c_1
890 st c_3,rp(11) !r[11]=c3;
891 addx c_2,%g0,c_2 !=
892
893 umul a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
894 addcc c_1,t_1,c_1
895 rd %y,t_2
896 addxcc c_2,t_2,c_2 !=
897 addx %g0,%g0,c_3
898 umul a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
899 addcc c_1,t_1,c_1
900 rd %y,t_2 !=
901 addxcc c_2,t_2,c_2
902 addx c_3,%g0,c_3
903 umul a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
904 addcc c_1,t_1,c_1 !=
905 rd %y,t_2
906 addxcc c_2,t_2,c_2
907 st c_1,rp(12) !r[12]=c1;
908 addx c_3,%g0,c_3 !=
909
910 umul a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
911 addcc c_2,t_1,c_2
912 rd %y,t_2
913 addxcc c_3,t_2,c_3 !=
914 addx %g0,%g0,c_1
915 umul a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
916 addcc c_2,t_1,c_2
917 rd %y,t_2 !=
918 addxcc c_3,t_2,c_3
919 addx c_1,%g0,c_1
920 st c_2,rp(13) !r[13]=c2;
921
922 umul a_7,b_7,t_1 !=!mul_add_c(a[7],b[7],c3,c1,c2);
923 addcc c_3,t_1,c_3
924 rd %y,t_2
925 addxcc c_1,t_2,c_1
926 nop !=
927 st c_3,rp(14) !r[14]=c3;
928 st c_1,rp(15) !r[15]=c1;
929
930 ret
931 restore %g0,%g0,%o0
932
933.type bn_mul_comba8,#function
934.size bn_mul_comba8,(.-bn_mul_comba8)
935
936.align 32
937
938.global bn_mul_comba4
939/*
940 * void bn_mul_comba4(r,a,b)
941 * BN_ULONG *r,*a,*b;
942 */
943bn_mul_comba4:
944 save %sp,FRAME_SIZE,%sp
945 ld ap(0),a_0
946 ld bp(0),b_0
947 umul a_0,b_0,c_1 !=!mul_add_c(a[0],b[0],c1,c2,c3);
948 ld bp(1),b_1
949 rd %y,c_2
950 st c_1,rp(0) !r[0]=c1;
951
952 umul a_0,b_1,t_1 !=!mul_add_c(a[0],b[1],c2,c3,c1);
953 ld ap(1),a_1
954 addcc c_2,t_1,c_2
955 rd %y,t_2 !=
956 addxcc %g0,t_2,c_3
957 addx %g0,%g0,c_1
958 ld ap(2),a_2
959 umul a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
960 addcc c_2,t_1,c_2
961 rd %y,t_2
962 addxcc c_3,t_2,c_3
963 addx c_1,%g0,c_1 !=
964 st c_2,rp(1) !r[1]=c2;
965
966 umul a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
967 addcc c_3,t_1,c_3
968 rd %y,t_2 !=
969 addxcc c_1,t_2,c_1
970 addx %g0,%g0,c_2
971 ld bp(2),b_2
972 umul a_1,b_1,t_1 !=!mul_add_c(a[1],b[1],c3,c1,c2);
973 addcc c_3,t_1,c_3
974 rd %y,t_2
975 addxcc c_1,t_2,c_1
976 addx c_2,%g0,c_2 !=
977 ld bp(3),b_3
978 umul a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
979 addcc c_3,t_1,c_3
980 rd %y,t_2 !=
981 addxcc c_1,t_2,c_1
982 addx c_2,%g0,c_2
983 st c_3,rp(2) !r[2]=c3;
984
985 umul a_0,b_3,t_1 !=!mul_add_c(a[0],b[3],c1,c2,c3);
986 addcc c_1,t_1,c_1
987 rd %y,t_2
988 addxcc c_2,t_2,c_2
989 addx %g0,%g0,c_3 !=
990 umul a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
991 addcc c_1,t_1,c_1
992 rd %y,t_2
993 addxcc c_2,t_2,c_2 !=
994 addx c_3,%g0,c_3
995 ld ap(3),a_3
996 umul a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
997 addcc c_1,t_1,c_1 !=
998 rd %y,t_2
999 addxcc c_2,t_2,c_2
1000 addx c_3,%g0,c_3
1001 umul a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);
1002 addcc c_1,t_1,c_1
1003 rd %y,t_2
1004 addxcc c_2,t_2,c_2
1005 addx c_3,%g0,c_3 !=
1006 st c_1,rp(3) !r[3]=c1;
1007
1008 umul a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1009 addcc c_2,t_1,c_2
1010 rd %y,t_2 !=
1011 addxcc c_3,t_2,c_3
1012 addx %g0,%g0,c_1
1013 umul a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1014 addcc c_2,t_1,c_2 !=
1015 rd %y,t_2
1016 addxcc c_3,t_2,c_3
1017 addx c_1,%g0,c_1
1018 umul a_1,b_3,t_1 !=!mul_add_c(a[1],b[3],c2,c3,c1);
1019 addcc c_2,t_1,c_2
1020 rd %y,t_2
1021 addxcc c_3,t_2,c_3
1022 addx c_1,%g0,c_1 !=
1023 st c_2,rp(4) !r[4]=c2;
1024
1025 umul a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1026 addcc c_3,t_1,c_3
1027 rd %y,t_2 !=
1028 addxcc c_1,t_2,c_1
1029 addx %g0,%g0,c_2
1030 umul a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1031 addcc c_3,t_1,c_3 !=
1032 rd %y,t_2
1033 addxcc c_1,t_2,c_1
1034 st c_3,rp(5) !r[5]=c3;
1035 addx c_2,%g0,c_2 !=
1036
1037 umul a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1038 addcc c_1,t_1,c_1
1039 rd %y,t_2
1040 addxcc c_2,t_2,c_2 !=
1041 st c_1,rp(6) !r[6]=c1;
1042 st c_2,rp(7) !r[7]=c2;
1043
1044 ret
1045 restore %g0,%g0,%o0
1046
1047.type bn_mul_comba4,#function
1048.size bn_mul_comba4,(.-bn_mul_comba4)
1049
1050.align 32
1051
1052.global bn_sqr_comba8
1053bn_sqr_comba8:
1054 save %sp,FRAME_SIZE,%sp
1055 ld ap(0),a_0
1056 ld ap(1),a_1
1057 umul a_0,a_0,c_1 !=!sqr_add_c(a,0,c1,c2,c3);
1058 rd %y,c_2
1059 st c_1,rp(0) !r[0]=c1;
1060
1061 ld ap(2),a_2
1062 umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1063 addcc c_2,t_1,c_2
1064 rd %y,t_2
1065 addxcc %g0,t_2,c_3
1066 addx %g0,%g0,c_1 !=
1067 addcc c_2,t_1,c_2
1068 addxcc c_3,t_2,c_3
1069 st c_2,rp(1) !r[1]=c2;
1070 addx c_1,%g0,c_1 !=
1071
1072 umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1073 addcc c_3,t_1,c_3
1074 rd %y,t_2
1075 addxcc c_1,t_2,c_1 !=
1076 addx %g0,%g0,c_2
1077 addcc c_3,t_1,c_3
1078 addxcc c_1,t_2,c_1
1079 addx c_2,%g0,c_2 !=
1080 ld ap(3),a_3
1081 umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1082 addcc c_3,t_1,c_3
1083 rd %y,t_2 !=
1084 addxcc c_1,t_2,c_1
1085 addx c_2,%g0,c_2
1086 st c_3,rp(2) !r[2]=c3;
1087
1088 umul a_0,a_3,t_1 !=!sqr_add_c2(a,3,0,c1,c2,c3);
1089 addcc c_1,t_1,c_1
1090 rd %y,t_2
1091 addxcc c_2,t_2,c_2
1092 addx %g0,%g0,c_3 !=
1093 addcc c_1,t_1,c_1
1094 addxcc c_2,t_2,c_2
1095 ld ap(4),a_4
1096 addx c_3,%g0,c_3 !=
1097 umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1098 addcc c_1,t_1,c_1
1099 rd %y,t_2
1100 addxcc c_2,t_2,c_2 !=
1101 addx c_3,%g0,c_3
1102 addcc c_1,t_1,c_1
1103 addxcc c_2,t_2,c_2
1104 addx c_3,%g0,c_3 !=
1105 st c_1,rp(3) !r[3]=c1;
1106
1107 umul a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1108 addcc c_2,t_1,c_2
1109 rd %y,t_2 !=
1110 addxcc c_3,t_2,c_3
1111 addx %g0,%g0,c_1
1112 addcc c_2,t_1,c_2
1113 addxcc c_3,t_2,c_3 !=
1114 addx c_1,%g0,c_1
1115 umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1116 addcc c_2,t_1,c_2
1117 rd %y,t_2 !=
1118 addxcc c_3,t_2,c_3
1119 addx c_1,%g0,c_1
1120 addcc c_2,t_1,c_2
1121 addxcc c_3,t_2,c_3 !=
1122 addx c_1,%g0,c_1
1123 ld ap(5),a_5
1124 umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1125 addcc c_2,t_1,c_2 !=
1126 rd %y,t_2
1127 addxcc c_3,t_2,c_3
1128 st c_2,rp(4) !r[4]=c2;
1129 addx c_1,%g0,c_1 !=
1130
1131 umul a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1132 addcc c_3,t_1,c_3
1133 rd %y,t_2
1134 addxcc c_1,t_2,c_1 !=
1135 addx %g0,%g0,c_2
1136 addcc c_3,t_1,c_3
1137 addxcc c_1,t_2,c_1
1138 addx c_2,%g0,c_2 !=
1139 umul a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1140 addcc c_3,t_1,c_3
1141 rd %y,t_2
1142 addxcc c_1,t_2,c_1 !=
1143 addx c_2,%g0,c_2
1144 addcc c_3,t_1,c_3
1145 addxcc c_1,t_2,c_1
1146 addx c_2,%g0,c_2 !=
1147 ld ap(6),a_6
1148 umul a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1149 addcc c_3,t_1,c_3
1150 rd %y,t_2 !=
1151 addxcc c_1,t_2,c_1
1152 addx c_2,%g0,c_2
1153 addcc c_3,t_1,c_3
1154 addxcc c_1,t_2,c_1 !=
1155 addx c_2,%g0,c_2
1156 st c_3,rp(5) !r[5]=c3;
1157
1158 umul a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1159 addcc c_1,t_1,c_1 !=
1160 rd %y,t_2
1161 addxcc c_2,t_2,c_2
1162 addx %g0,%g0,c_3
1163 addcc c_1,t_1,c_1 !=
1164 addxcc c_2,t_2,c_2
1165 addx c_3,%g0,c_3
1166 umul a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1167 addcc c_1,t_1,c_1 !=
1168 rd %y,t_2
1169 addxcc c_2,t_2,c_2
1170 addx c_3,%g0,c_3
1171 addcc c_1,t_1,c_1 !=
1172 addxcc c_2,t_2,c_2
1173 addx c_3,%g0,c_3
1174 umul a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1175 addcc c_1,t_1,c_1 !=
1176 rd %y,t_2
1177 addxcc c_2,t_2,c_2
1178 addx c_3,%g0,c_3
1179 addcc c_1,t_1,c_1 !=
1180 addxcc c_2,t_2,c_2
1181 addx c_3,%g0,c_3
1182 ld ap(7),a_7
1183 umul a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1184 addcc c_1,t_1,c_1
1185 rd %y,t_2
1186 addxcc c_2,t_2,c_2
1187 addx c_3,%g0,c_3 !=
1188 st c_1,rp(6) !r[6]=c1;
1189
1190 umul a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1191 addcc c_2,t_1,c_2
1192 rd %y,t_2 !=
1193 addxcc c_3,t_2,c_3
1194 addx %g0,%g0,c_1
1195 addcc c_2,t_1,c_2
1196 addxcc c_3,t_2,c_3 !=
1197 addx c_1,%g0,c_1
1198 umul a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1199 addcc c_2,t_1,c_2
1200 rd %y,t_2 !=
1201 addxcc c_3,t_2,c_3
1202 addx c_1,%g0,c_1
1203 addcc c_2,t_1,c_2
1204 addxcc c_3,t_2,c_3 !=
1205 addx c_1,%g0,c_1
1206 umul a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1207 addcc c_2,t_1,c_2
1208 rd %y,t_2 !=
1209 addxcc c_3,t_2,c_3
1210 addx c_1,%g0,c_1
1211 addcc c_2,t_1,c_2
1212 addxcc c_3,t_2,c_3 !=
1213 addx c_1,%g0,c_1
1214 umul a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1215 addcc c_2,t_1,c_2
1216 rd %y,t_2 !=
1217 addxcc c_3,t_2,c_3
1218 addx c_1,%g0,c_1
1219 addcc c_2,t_1,c_2
1220 addxcc c_3,t_2,c_3 !=
1221 addx c_1,%g0,c_1
1222 st c_2,rp(7) !r[7]=c2;
1223
1224 umul a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1225 addcc c_3,t_1,c_3 !=
1226 rd %y,t_2
1227 addxcc c_1,t_2,c_1
1228 addx %g0,%g0,c_2
1229 addcc c_3,t_1,c_3 !=
1230 addxcc c_1,t_2,c_1
1231 addx c_2,%g0,c_2
1232 umul a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1233 addcc c_3,t_1,c_3 !=
1234 rd %y,t_2
1235 addxcc c_1,t_2,c_1
1236 addx c_2,%g0,c_2
1237 addcc c_3,t_1,c_3 !=
1238 addxcc c_1,t_2,c_1
1239 addx c_2,%g0,c_2
1240 umul a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1241 addcc c_3,t_1,c_3 !=
1242 rd %y,t_2
1243 addxcc c_1,t_2,c_1
1244 addx c_2,%g0,c_2
1245 addcc c_3,t_1,c_3 !=
1246 addxcc c_1,t_2,c_1
1247 addx c_2,%g0,c_2
1248 umul a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1249 addcc c_3,t_1,c_3 !=
1250 rd %y,t_2
1251 addxcc c_1,t_2,c_1
1252 st c_3,rp(8) !r[8]=c3;
1253 addx c_2,%g0,c_2 !=
1254
1255 umul a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1256 addcc c_1,t_1,c_1
1257 rd %y,t_2
1258 addxcc c_2,t_2,c_2 !=
1259 addx %g0,%g0,c_3
1260 addcc c_1,t_1,c_1
1261 addxcc c_2,t_2,c_2
1262 addx c_3,%g0,c_3 !=
1263 umul a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1264 addcc c_1,t_1,c_1
1265 rd %y,t_2
1266 addxcc c_2,t_2,c_2 !=
1267 addx c_3,%g0,c_3
1268 addcc c_1,t_1,c_1
1269 addxcc c_2,t_2,c_2
1270 addx c_3,%g0,c_3 !=
1271 umul a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1272 addcc c_1,t_1,c_1
1273 rd %y,t_2
1274 addxcc c_2,t_2,c_2 !=
1275 addx c_3,%g0,c_3
1276 addcc c_1,t_1,c_1
1277 addxcc c_2,t_2,c_2
1278 addx c_3,%g0,c_3 !=
1279 st c_1,rp(9) !r[9]=c1;
1280
1281 umul a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1282 addcc c_2,t_1,c_2
1283 rd %y,t_2 !=
1284 addxcc c_3,t_2,c_3
1285 addx %g0,%g0,c_1
1286 addcc c_2,t_1,c_2
1287 addxcc c_3,t_2,c_3 !=
1288 addx c_1,%g0,c_1
1289 umul a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1290 addcc c_2,t_1,c_2
1291 rd %y,t_2 !=
1292 addxcc c_3,t_2,c_3
1293 addx c_1,%g0,c_1
1294 addcc c_2,t_1,c_2
1295 addxcc c_3,t_2,c_3 !=
1296 addx c_1,%g0,c_1
1297 umul a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1298 addcc c_2,t_1,c_2
1299 rd %y,t_2 !=
1300 addxcc c_3,t_2,c_3
1301 addx c_1,%g0,c_1
1302 st c_2,rp(10) !r[10]=c2;
1303
1304 umul a_4,a_7,t_1 !=!sqr_add_c2(a,7,4,c3,c1,c2);
1305 addcc c_3,t_1,c_3
1306 rd %y,t_2
1307 addxcc c_1,t_2,c_1
1308 addx %g0,%g0,c_2 !=
1309 addcc c_3,t_1,c_3
1310 addxcc c_1,t_2,c_1
1311 addx c_2,%g0,c_2
1312 umul a_5,a_6,t_1 !=!sqr_add_c2(a,6,5,c3,c1,c2);
1313 addcc c_3,t_1,c_3
1314 rd %y,t_2
1315 addxcc c_1,t_2,c_1
1316 addx c_2,%g0,c_2 !=
1317 addcc c_3,t_1,c_3
1318 addxcc c_1,t_2,c_1
1319 st c_3,rp(11) !r[11]=c3;
1320 addx c_2,%g0,c_2 !=
1321
1322 umul a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1323 addcc c_1,t_1,c_1
1324 rd %y,t_2
1325 addxcc c_2,t_2,c_2 !=
1326 addx %g0,%g0,c_3
1327 addcc c_1,t_1,c_1
1328 addxcc c_2,t_2,c_2
1329 addx c_3,%g0,c_3 !=
1330 umul a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
1331 addcc c_1,t_1,c_1
1332 rd %y,t_2
1333 addxcc c_2,t_2,c_2 !=
1334 addx c_3,%g0,c_3
1335 st c_1,rp(12) !r[12]=c1;
1336
1337 umul a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1338 addcc c_2,t_1,c_2 !=
1339 rd %y,t_2
1340 addxcc c_3,t_2,c_3
1341 addx %g0,%g0,c_1
1342 addcc c_2,t_1,c_2 !=
1343 addxcc c_3,t_2,c_3
1344 st c_2,rp(13) !r[13]=c2;
1345 addx c_1,%g0,c_1 !=
1346
1347 umul a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1348 addcc c_3,t_1,c_3
1349 rd %y,t_2
1350 addxcc c_1,t_2,c_1 !=
1351 st c_3,rp(14) !r[14]=c3;
1352 st c_1,rp(15) !r[15]=c1;
1353
1354 ret
1355 restore %g0,%g0,%o0
1356
1357.type bn_sqr_comba8,#function
1358.size bn_sqr_comba8,(.-bn_sqr_comba8)
1359
1360.align 32
1361
1362.global bn_sqr_comba4
1363/*
1364 * void bn_sqr_comba4(r,a)
1365 * BN_ULONG *r,*a;
1366 */
1367bn_sqr_comba4:
1368 save %sp,FRAME_SIZE,%sp
1369 ld ap(0),a_0
1370 umul a_0,a_0,c_1 !sqr_add_c(a,0,c1,c2,c3);
1371 ld ap(1),a_1 !=
1372 rd %y,c_2
1373 st c_1,rp(0) !r[0]=c1;
1374
1375 ld ap(2),a_2
1376 umul a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1377 addcc c_2,t_1,c_2
1378 rd %y,t_2
1379 addxcc %g0,t_2,c_3
1380 addx %g0,%g0,c_1 !=
1381 addcc c_2,t_1,c_2
1382 addxcc c_3,t_2,c_3
1383 addx c_1,%g0,c_1 !=
1384 st c_2,rp(1) !r[1]=c2;
1385
1386 umul a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1387 addcc c_3,t_1,c_3
1388 rd %y,t_2 !=
1389 addxcc c_1,t_2,c_1
1390 addx %g0,%g0,c_2
1391 addcc c_3,t_1,c_3
1392 addxcc c_1,t_2,c_1 !=
1393 addx c_2,%g0,c_2
1394 ld ap(3),a_3
1395 umul a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1396 addcc c_3,t_1,c_3 !=
1397 rd %y,t_2
1398 addxcc c_1,t_2,c_1
1399 st c_3,rp(2) !r[2]=c3;
1400 addx c_2,%g0,c_2 !=
1401
1402 umul a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1403 addcc c_1,t_1,c_1
1404 rd %y,t_2
1405 addxcc c_2,t_2,c_2 !=
1406 addx %g0,%g0,c_3
1407 addcc c_1,t_1,c_1
1408 addxcc c_2,t_2,c_2
1409 addx c_3,%g0,c_3 !=
1410 umul a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1411 addcc c_1,t_1,c_1
1412 rd %y,t_2
1413 addxcc c_2,t_2,c_2 !=
1414 addx c_3,%g0,c_3
1415 addcc c_1,t_1,c_1
1416 addxcc c_2,t_2,c_2
1417 addx c_3,%g0,c_3 !=
1418 st c_1,rp(3) !r[3]=c1;
1419
1420 umul a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1421 addcc c_2,t_1,c_2
1422 rd %y,t_2 !=
1423 addxcc c_3,t_2,c_3
1424 addx %g0,%g0,c_1
1425 addcc c_2,t_1,c_2
1426 addxcc c_3,t_2,c_3 !=
1427 addx c_1,%g0,c_1
1428 umul a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1429 addcc c_2,t_1,c_2
1430 rd %y,t_2 !=
1431 addxcc c_3,t_2,c_3
1432 addx c_1,%g0,c_1
1433 st c_2,rp(4) !r[4]=c2;
1434
1435 umul a_2,a_3,t_1 !=!sqr_add_c2(a,3,2,c3,c1,c2);
1436 addcc c_3,t_1,c_3
1437 rd %y,t_2
1438 addxcc c_1,t_2,c_1
1439 addx %g0,%g0,c_2 !=
1440 addcc c_3,t_1,c_3
1441 addxcc c_1,t_2,c_1
1442 st c_3,rp(5) !r[5]=c3;
1443 addx c_2,%g0,c_2 !=
1444
1445 umul a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1446 addcc c_1,t_1,c_1
1447 rd %y,t_2
1448 addxcc c_2,t_2,c_2 !=
1449 st c_1,rp(6) !r[6]=c1;
1450 st c_2,rp(7) !r[7]=c2;
1451
1452 ret
1453 restore %g0,%g0,%o0
1454
1455.type bn_sqr_comba4,#function
1456.size bn_sqr_comba4,(.-bn_sqr_comba4)
1457
1458.align 32
diff --git a/src/lib/libcrypto/bn/asm/sparcv8plus.S b/src/lib/libcrypto/bn/asm/sparcv8plus.S
new file mode 100644
index 0000000000..0074dfdb75
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/sparcv8plus.S
@@ -0,0 +1,1535 @@
1.ident "sparcv8plus.s, Version 1.4"
2.ident "SPARC v9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4/*
5 * ====================================================================
6 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7 * project.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted according to the OpenSSL license. Warranty of any kind is
11 * disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contributon to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is
18 * a drop-in UltraSPARC ISA replacement for crypto/bn/bn_asm.c
19 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20 *
21 * Questions-n-answers.
22 *
23 * Q. How to compile?
24 * A. With SC4.x/SC5.x:
25 *
26 * cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
27 *
28 * and with gcc:
29 *
30 * gcc -mcpu=ultrasparc -c bn_asm.sparc.v8plus.S -o bn_asm.o
31 *
32 * or if above fails (it does if you have gas installed):
33 *
34 * gcc -E bn_asm.sparc.v8plus.S | as -xarch=v8plus /dev/fd/0 -o bn_asm.o
35 *
36 * Quick-n-dirty way to fuse the module into the library.
37 * Provided that the library is already configured and built
38 * (in 0.9.2 case with no-asm option):
39 *
40 * # cd crypto/bn
41 * # cp /some/place/bn_asm.sparc.v8plus.S .
42 * # cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
43 * # make
44 * # cd ../..
45 * # make; make test
46 *
47 * Quick-n-dirty way to get rid of it:
48 *
49 * # cd crypto/bn
50 * # touch bn_asm.c
51 * # make
52 * # cd ../..
53 * # make; make test
54 *
55 * Q. V8plus achitecture? What kind of beast is that?
56 * A. Well, it's rather a programming model than an architecture...
57 * It's actually v9-compliant, i.e. *any* UltraSPARC, CPU under
58 * special conditions, namely when kernel doesn't preserve upper
59 * 32 bits of otherwise 64-bit registers during a context switch.
60 *
61 * Q. Why just UltraSPARC? What about SuperSPARC?
62 * A. Original release did target UltraSPARC only. Now SuperSPARC
63 * version is provided along. Both version share bn_*comba[48]
64 * implementations (see comment later in code for explanation).
65 * But what's so special about this UltraSPARC implementation?
66 * Why didn't I let compiler do the job? Trouble is that most of
67 * available compilers (well, SC5.0 is the only exception) don't
68 * attempt to take advantage of UltraSPARC's 64-bitness under
69 * 32-bit kernels even though it's perfectly possible (see next
70 * question).
71 *
72 * Q. 64-bit registers under 32-bit kernels? Didn't you just say it
73 * doesn't work?
74 * A. You can't adress *all* registers as 64-bit wide:-( The catch is
75 * that you actually may rely upon %o0-%o5 and %g1-%g4 being fully
76 * preserved if you're in a leaf function, i.e. such never calling
77 * any other functions. All functions in this module are leaf and
78 * 10 registers is a handful. And as a matter of fact none-"comba"
79 * routines don't require even that much and I could even afford to
80 * not allocate own stack frame for 'em:-)
81 *
82 * Q. What about 64-bit kernels?
83 * A. What about 'em? Just kidding:-) Pure 64-bit version is currently
84 * under evaluation and development...
85 *
86 * Q. What about shared libraries?
87 * A. What about 'em? Kidding again:-) Code does *not* contain any
88 * code position dependencies and it's safe to include it into
89 * shared library as is.
90 *
91 * Q. How much faster does it go?
92 * A. Do you have a good benchmark? In either case below is what I
93 * experience with crypto/bn/expspeed.c test program:
94 *
95 * v8plus module on U10/300MHz against bn_asm.c compiled with:
96 *
97 * cc-5.0 -xarch=v8plus -xO5 -xdepend +7-12%
98 * cc-4.2 -xarch=v8plus -xO5 -xdepend +25-35%
99 * egcs-1.1.2 -mcpu=ultrasparc -O3 +35-45%
100 *
101 * v8 module on SS10/60MHz against bn_asm.c compiled with:
102 *
103 * cc-5.0 -xarch=v8 -xO5 -xdepend +7-10%
104 * cc-4.2 -xarch=v8 -xO5 -xdepend +10%
105 * egcs-1.1.2 -mv8 -O3 +35-45%
106 *
107 * As you can see it's damn hard to beat the new Sun C compiler
108 * and it's in first place GNU C users who will appreciate this
109 * assembler implementation:-)
110 */
111
112/*
113 * Revision history.
114 *
115 * 1.0 - initial release;
116 * 1.1 - new loop unrolling model(*);
117 * - some more fine tuning;
118 * 1.2 - made gas friendly;
119 * - updates to documentation concerning v9;
120 * - new performance comparison matrix;
121 * 1.3 - fixed problem with /usr/ccs/lib/cpp;
122 * 1.4 - native V9 bn_*_comba[48] implementation (15% more efficient)
123 * resulting in slight overall performance kick;
124 * - some retunes;
125 * - support for GNU as added;
126 *
127 * (*) Originally unrolled loop looked like this:
128 * for (;;) {
129 * op(p+0); if (--n==0) break;
130 * op(p+1); if (--n==0) break;
131 * op(p+2); if (--n==0) break;
132 * op(p+3); if (--n==0) break;
133 * p+=4;
134 * }
135 * I unroll according to following:
136 * while (n&~3) {
137 * op(p+0); op(p+1); op(p+2); op(p+3);
138 * p+=4; n=-4;
139 * }
140 * if (n) {
141 * op(p+0); if (--n==0) return;
142 * op(p+2); if (--n==0) return;
143 * op(p+3); return;
144 * }
145 */
146
147/*
148 * GNU assembler can't stand stuw:-(
149 */
150#define stuw st
151
152.section ".text",#alloc,#execinstr
153.file "bn_asm.sparc.v8plus.S"
154
155.align 32
156
157.global bn_mul_add_words
158/*
159 * BN_ULONG bn_mul_add_words(rp,ap,num,w)
160 * BN_ULONG *rp,*ap;
161 * int num;
162 * BN_ULONG w;
163 */
164bn_mul_add_words:
165 brgz,a %o2,.L_bn_mul_add_words_proceed
166 lduw [%o1],%g2
167 retl
168 clr %o0
169
170.L_bn_mul_add_words_proceed:
171 srl %o3,%g0,%o3 ! clruw %o3
172 andcc %o2,-4,%g0
173 bz,pn %icc,.L_bn_mul_add_words_tail
174 clr %o5
175
176.L_bn_mul_add_words_loop: ! wow! 32 aligned!
177 lduw [%o0],%g1
178 lduw [%o1+4],%g3
179 mulx %o3,%g2,%g2
180 add %g1,%o5,%o4
181 nop
182 add %o4,%g2,%o4
183 stuw %o4,[%o0]
184 srlx %o4,32,%o5
185
186 lduw [%o0+4],%g1
187 lduw [%o1+8],%g2
188 mulx %o3,%g3,%g3
189 add %g1,%o5,%o4
190 dec 4,%o2
191 add %o4,%g3,%o4
192 stuw %o4,[%o0+4]
193 srlx %o4,32,%o5
194
195 lduw [%o0+8],%g1
196 lduw [%o1+12],%g3
197 mulx %o3,%g2,%g2
198 add %g1,%o5,%o4
199 inc 16,%o1
200 add %o4,%g2,%o4
201 stuw %o4,[%o0+8]
202 srlx %o4,32,%o5
203
204 lduw [%o0+12],%g1
205 mulx %o3,%g3,%g3
206 add %g1,%o5,%o4
207 inc 16,%o0
208 add %o4,%g3,%o4
209 andcc %o2,-4,%g0
210 stuw %o4,[%o0-4]
211 srlx %o4,32,%o5
212 bnz,a,pt %icc,.L_bn_mul_add_words_loop
213 lduw [%o1],%g2
214
215 brnz,a,pn %o2,.L_bn_mul_add_words_tail
216 lduw [%o1],%g2
217.L_bn_mul_add_words_return:
218 retl
219 mov %o5,%o0
220
221.L_bn_mul_add_words_tail:
222 lduw [%o0],%g1
223 mulx %o3,%g2,%g2
224 add %g1,%o5,%o4
225 dec %o2
226 add %o4,%g2,%o4
227 srlx %o4,32,%o5
228 brz,pt %o2,.L_bn_mul_add_words_return
229 stuw %o4,[%o0]
230
231 lduw [%o1+4],%g2
232 lduw [%o0+4],%g1
233 mulx %o3,%g2,%g2
234 add %g1,%o5,%o4
235 dec %o2
236 add %o4,%g2,%o4
237 srlx %o4,32,%o5
238 brz,pt %o2,.L_bn_mul_add_words_return
239 stuw %o4,[%o0+4]
240
241 lduw [%o1+8],%g2
242 lduw [%o0+8],%g1
243 mulx %o3,%g2,%g2
244 add %g1,%o5,%o4
245 add %o4,%g2,%o4
246 stuw %o4,[%o0+8]
247 retl
248 srlx %o4,32,%o0
249
250.type bn_mul_add_words,#function
251.size bn_mul_add_words,(.-bn_mul_add_words)
252
253.align 32
254
255.global bn_mul_words
256/*
257 * BN_ULONG bn_mul_words(rp,ap,num,w)
258 * BN_ULONG *rp,*ap;
259 * int num;
260 * BN_ULONG w;
261 */
262bn_mul_words:
263 brgz,a %o2,.L_bn_mul_words_proceeed
264 lduw [%o1],%g2
265 retl
266 clr %o0
267
268.L_bn_mul_words_proceeed:
269 srl %o3,%g0,%o3 ! clruw %o3
270 andcc %o2,-4,%g0
271 bz,pn %icc,.L_bn_mul_words_tail
272 clr %o5
273
274.L_bn_mul_words_loop: ! wow! 32 aligned!
275 lduw [%o1+4],%g3
276 mulx %o3,%g2,%g2
277 add %g2,%o5,%o4
278 nop
279 stuw %o4,[%o0]
280 srlx %o4,32,%o5
281
282 lduw [%o1+8],%g2
283 mulx %o3,%g3,%g3
284 add %g3,%o5,%o4
285 dec 4,%o2
286 stuw %o4,[%o0+4]
287 srlx %o4,32,%o5
288
289 lduw [%o1+12],%g3
290 mulx %o3,%g2,%g2
291 add %g2,%o5,%o4
292 inc 16,%o1
293 stuw %o4,[%o0+8]
294 srlx %o4,32,%o5
295
296 mulx %o3,%g3,%g3
297 add %g3,%o5,%o4
298 inc 16,%o0
299 stuw %o4,[%o0-4]
300 srlx %o4,32,%o5
301 andcc %o2,-4,%g0
302 bnz,a,pt %icc,.L_bn_mul_words_loop
303 lduw [%o1],%g2
304 nop
305 nop
306
307 brnz,a,pn %o2,.L_bn_mul_words_tail
308 lduw [%o1],%g2
309.L_bn_mul_words_return:
310 retl
311 mov %o5,%o0
312
313.L_bn_mul_words_tail:
314 mulx %o3,%g2,%g2
315 add %g2,%o5,%o4
316 dec %o2
317 srlx %o4,32,%o5
318 brz,pt %o2,.L_bn_mul_words_return
319 stuw %o4,[%o0]
320
321 lduw [%o1+4],%g2
322 mulx %o3,%g2,%g2
323 add %g2,%o5,%o4
324 dec %o2
325 srlx %o4,32,%o5
326 brz,pt %o2,.L_bn_mul_words_return
327 stuw %o4,[%o0+4]
328
329 lduw [%o1+8],%g2
330 mulx %o3,%g2,%g2
331 add %g2,%o5,%o4
332 stuw %o4,[%o0+8]
333 retl
334 srlx %o4,32,%o0
335
336.type bn_mul_words,#function
337.size bn_mul_words,(.-bn_mul_words)
338
339.align 32
340.global bn_sqr_words
341/*
342 * void bn_sqr_words(r,a,n)
343 * BN_ULONG *r,*a;
344 * int n;
345 */
346bn_sqr_words:
347 brgz,a %o2,.L_bn_sqr_words_proceeed
348 lduw [%o1],%g2
349 retl
350 clr %o0
351
352.L_bn_sqr_words_proceeed:
353 andcc %o2,-4,%g0
354 nop
355 bz,pn %icc,.L_bn_sqr_words_tail
356 nop
357
358.L_bn_sqr_words_loop: ! wow! 32 aligned!
359 lduw [%o1+4],%g3
360 mulx %g2,%g2,%o4
361 stuw %o4,[%o0]
362 srlx %o4,32,%o5
363 stuw %o5,[%o0+4]
364 nop
365
366 lduw [%o1+8],%g2
367 mulx %g3,%g3,%o4
368 dec 4,%o2
369 stuw %o4,[%o0+8]
370 srlx %o4,32,%o5
371 stuw %o5,[%o0+12]
372
373 lduw [%o1+12],%g3
374 mulx %g2,%g2,%o4
375 srlx %o4,32,%o5
376 stuw %o4,[%o0+16]
377 inc 16,%o1
378 stuw %o5,[%o0+20]
379
380 mulx %g3,%g3,%o4
381 inc 32,%o0
382 stuw %o4,[%o0-8]
383 srlx %o4,32,%o5
384 andcc %o2,-4,%g2
385 stuw %o5,[%o0-4]
386 bnz,a,pt %icc,.L_bn_sqr_words_loop
387 lduw [%o1],%g2
388 nop
389
390 brnz,a,pn %o2,.L_bn_sqr_words_tail
391 lduw [%o1],%g2
392.L_bn_sqr_words_return:
393 retl
394 clr %o0
395
396.L_bn_sqr_words_tail:
397 mulx %g2,%g2,%o4
398 dec %o2
399 stuw %o4,[%o0]
400 srlx %o4,32,%o5
401 brz,pt %o2,.L_bn_sqr_words_return
402 stuw %o5,[%o0+4]
403
404 lduw [%o1+4],%g2
405 mulx %g2,%g2,%o4
406 dec %o2
407 stuw %o4,[%o0+8]
408 srlx %o4,32,%o5
409 brz,pt %o2,.L_bn_sqr_words_return
410 stuw %o5,[%o0+12]
411
412 lduw [%o1+8],%g2
413 mulx %g2,%g2,%o4
414 srlx %o4,32,%o5
415 stuw %o4,[%o0+16]
416 stuw %o5,[%o0+20]
417 retl
418 clr %o0
419
420.type bn_sqr_words,#function
421.size bn_sqr_words,(.-bn_sqr_words)
422
423.align 32
424.global bn_div_words
425/*
426 * BN_ULONG bn_div_words(h,l,d)
427 * BN_ULONG h,l,d;
428 */
429bn_div_words:
430 sllx %o0,32,%o0
431 or %o0,%o1,%o0
432 udivx %o0,%o2,%o0
433 retl
434 srl %o0,%g0,%o0 ! clruw %o0
435
436.type bn_div_words,#function
437.size bn_div_words,(.-bn_div_words)
438
439.align 32
440
441.global bn_add_words
442/*
443 * BN_ULONG bn_add_words(rp,ap,bp,n)
444 * BN_ULONG *rp,*ap,*bp;
445 * int n;
446 */
447bn_add_words:
448 brgz,a %o3,.L_bn_add_words_proceed
449 lduw [%o1],%o4
450 retl
451 clr %o0
452
453.L_bn_add_words_proceed:
454 andcc %o3,-4,%g0
455 bz,pn %icc,.L_bn_add_words_tail
456 addcc %g0,0,%g0 ! clear carry flag
457 nop
458
459.L_bn_add_words_loop: ! wow! 32 aligned!
460 dec 4,%o3
461 lduw [%o2],%o5
462 lduw [%o1+4],%g1
463 lduw [%o2+4],%g2
464 lduw [%o1+8],%g3
465 lduw [%o2+8],%g4
466 addccc %o5,%o4,%o5
467 stuw %o5,[%o0]
468
469 lduw [%o1+12],%o4
470 lduw [%o2+12],%o5
471 inc 16,%o1
472 addccc %g1,%g2,%g1
473 stuw %g1,[%o0+4]
474
475 inc 16,%o2
476 addccc %g3,%g4,%g3
477 stuw %g3,[%o0+8]
478
479 inc 16,%o0
480 addccc %o5,%o4,%o5
481 stuw %o5,[%o0-4]
482 and %o3,-4,%g1
483 brnz,a,pt %g1,.L_bn_add_words_loop
484 lduw [%o1],%o4
485
486 brnz,a,pn %o3,.L_bn_add_words_tail
487 lduw [%o1],%o4
488.L_bn_add_words_return:
489 clr %o0
490 retl
491 movcs %icc,1,%o0
492 nop
493
494.L_bn_add_words_tail:
495 lduw [%o2],%o5
496 dec %o3
497 addccc %o5,%o4,%o5
498 brz,pt %o3,.L_bn_add_words_return
499 stuw %o5,[%o0]
500
501 lduw [%o1+4],%o4
502 lduw [%o2+4],%o5
503 dec %o3
504 addccc %o5,%o4,%o5
505 brz,pt %o3,.L_bn_add_words_return
506 stuw %o5,[%o0+4]
507
508 lduw [%o1+8],%o4
509 lduw [%o2+8],%o5
510 addccc %o5,%o4,%o5
511 stuw %o5,[%o0+8]
512 clr %o0
513 retl
514 movcs %icc,1,%o0
515
516.type bn_add_words,#function
517.size bn_add_words,(.-bn_add_words)
518
519.global bn_sub_words
520/*
521 * BN_ULONG bn_sub_words(rp,ap,bp,n)
522 * BN_ULONG *rp,*ap,*bp;
523 * int n;
524 */
525bn_sub_words:
526 brgz,a %o3,.L_bn_sub_words_proceed
527 lduw [%o1],%o4
528 retl
529 clr %o0
530
531.L_bn_sub_words_proceed:
532 andcc %o3,-4,%g0
533 bz,pn %icc,.L_bn_sub_words_tail
534 addcc %g0,0,%g0 ! clear carry flag
535 nop
536
537.L_bn_sub_words_loop: ! wow! 32 aligned!
538 dec 4,%o3
539 lduw [%o2],%o5
540 lduw [%o1+4],%g1
541 lduw [%o2+4],%g2
542 lduw [%o1+8],%g3
543 lduw [%o2+8],%g4
544 subccc %o4,%o5,%o5
545 stuw %o5,[%o0]
546
547 lduw [%o1+12],%o4
548 lduw [%o2+12],%o5
549 inc 16,%o1
550 subccc %g1,%g2,%g2
551 stuw %g2,[%o0+4]
552
553 inc 16,%o2
554 subccc %g3,%g4,%g4
555 stuw %g4,[%o0+8]
556
557 inc 16,%o0
558 subccc %o4,%o5,%o5
559 stuw %o5,[%o0-4]
560 and %o3,-4,%g1
561 brnz,a,pt %g1,.L_bn_sub_words_loop
562 lduw [%o1],%o4
563
564 brnz,a,pn %o3,.L_bn_sub_words_tail
565 lduw [%o1],%o4
566.L_bn_sub_words_return:
567 clr %o0
568 retl
569 movcs %icc,1,%o0
570 nop
571
572.L_bn_sub_words_tail: ! wow! 32 aligned!
573 lduw [%o2],%o5
574 dec %o3
575 subccc %o4,%o5,%o5
576 brz,pt %o3,.L_bn_sub_words_return
577 stuw %o5,[%o0]
578
579 lduw [%o1+4],%o4
580 lduw [%o2+4],%o5
581 dec %o3
582 subccc %o4,%o5,%o5
583 brz,pt %o3,.L_bn_sub_words_return
584 stuw %o5,[%o0+4]
585
586 lduw [%o1+8],%o4
587 lduw [%o2+8],%o5
588 subccc %o4,%o5,%o5
589 stuw %o5,[%o0+8]
590 clr %o0
591 retl
592 movcs %icc,1,%o0
593
594.type bn_sub_words,#function
595.size bn_sub_words,(.-bn_sub_words)
596
597/*
598 * Code below depends on the fact that upper parts of the %l0-%l7
599 * and %i0-%i7 are zeroed by kernel after context switch. In
600 * previous versions this comment stated that "the trouble is that
601 * it's not feasible to implement the mumbo-jumbo in less V9
602 * instructions:-(" which apparently isn't true thanks to
603 * 'bcs,a %xcc,.+8; inc %rd' pair. But the performance improvement
604 * results not from the shorter code, but from elimination of
605 * multicycle none-pairable 'rd %y,%rd' instructions.
606 *
607 * Andy.
608 */
609
610#define FRAME_SIZE -96
611
612/*
613 * Here is register usage map for *all* routines below.
614 */
615#define t_1 %o0
616#define t_2 %o1
617#define c_12 %o2
618#define c_3 %o3
619
620#define ap(I) [%i1+4*I]
621#define bp(I) [%i2+4*I]
622#define rp(I) [%i0+4*I]
623
624#define a_0 %l0
625#define a_1 %l1
626#define a_2 %l2
627#define a_3 %l3
628#define a_4 %l4
629#define a_5 %l5
630#define a_6 %l6
631#define a_7 %l7
632
633#define b_0 %i3
634#define b_1 %i4
635#define b_2 %i5
636#define b_3 %o4
637#define b_4 %o5
638#define b_5 %o7
639#define b_6 %g1
640#define b_7 %g4
641
642.align 32
643.global bn_mul_comba8
644/*
645 * void bn_mul_comba8(r,a,b)
646 * BN_ULONG *r,*a,*b;
647 */
648bn_mul_comba8:
649 save %sp,FRAME_SIZE,%sp
650 mov 1,t_2
651 lduw ap(0),a_0
652 sllx t_2,32,t_2
653 lduw bp(0),b_0 !=
654 lduw bp(1),b_1
655 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
656 srlx t_1,32,c_12
657 stuw t_1,rp(0) !=!r[0]=c1;
658
659 lduw ap(1),a_1
660 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
661 addcc c_12,t_1,c_12
662 clr c_3 !=
663 bcs,a %xcc,.+8
664 add c_3,t_2,c_3
665 lduw ap(2),a_2
666 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
667 addcc c_12,t_1,t_1
668 bcs,a %xcc,.+8
669 add c_3,t_2,c_3
670 srlx t_1,32,c_12 !=
671 stuw t_1,rp(1) !r[1]=c2;
672 or c_12,c_3,c_12
673
674 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
675 addcc c_12,t_1,c_12 !=
676 clr c_3
677 bcs,a %xcc,.+8
678 add c_3,t_2,c_3
679 lduw bp(2),b_2 !=
680 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
681 addcc c_12,t_1,c_12
682 bcs,a %xcc,.+8
683 add c_3,t_2,c_3 !=
684 lduw bp(3),b_3
685 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
686 addcc c_12,t_1,t_1
687 bcs,a %xcc,.+8 !=
688 add c_3,t_2,c_3
689 srlx t_1,32,c_12
690 stuw t_1,rp(2) !r[2]=c3;
691 or c_12,c_3,c_12 !=
692
693 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
694 addcc c_12,t_1,c_12
695 clr c_3
696 bcs,a %xcc,.+8 !=
697 add c_3,t_2,c_3
698 mulx a_1,b_2,t_1 !=!mul_add_c(a[1],b[2],c1,c2,c3);
699 addcc c_12,t_1,c_12
700 bcs,a %xcc,.+8 !=
701 add c_3,t_2,c_3
702 lduw ap(3),a_3
703 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
704 addcc c_12,t_1,c_12 !=
705 bcs,a %xcc,.+8
706 add c_3,t_2,c_3
707 lduw ap(4),a_4
708 mulx a_3,b_0,t_1 !=!mul_add_c(a[3],b[0],c1,c2,c3);!=
709 addcc c_12,t_1,t_1
710 bcs,a %xcc,.+8
711 add c_3,t_2,c_3
712 srlx t_1,32,c_12 !=
713 stuw t_1,rp(3) !r[3]=c1;
714 or c_12,c_3,c_12
715
716 mulx a_4,b_0,t_1 !mul_add_c(a[4],b[0],c2,c3,c1);
717 addcc c_12,t_1,c_12 !=
718 clr c_3
719 bcs,a %xcc,.+8
720 add c_3,t_2,c_3
721 mulx a_3,b_1,t_1 !=!mul_add_c(a[3],b[1],c2,c3,c1);
722 addcc c_12,t_1,c_12
723 bcs,a %xcc,.+8
724 add c_3,t_2,c_3
725 mulx a_2,b_2,t_1 !=!mul_add_c(a[2],b[2],c2,c3,c1);
726 addcc c_12,t_1,c_12
727 bcs,a %xcc,.+8
728 add c_3,t_2,c_3
729 lduw bp(4),b_4 !=
730 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
731 addcc c_12,t_1,c_12
732 bcs,a %xcc,.+8
733 add c_3,t_2,c_3 !=
734 lduw bp(5),b_5
735 mulx a_0,b_4,t_1 !mul_add_c(a[0],b[4],c2,c3,c1);
736 addcc c_12,t_1,t_1
737 bcs,a %xcc,.+8 !=
738 add c_3,t_2,c_3
739 srlx t_1,32,c_12
740 stuw t_1,rp(4) !r[4]=c2;
741 or c_12,c_3,c_12 !=
742
743 mulx a_0,b_5,t_1 !mul_add_c(a[0],b[5],c3,c1,c2);
744 addcc c_12,t_1,c_12
745 clr c_3
746 bcs,a %xcc,.+8 !=
747 add c_3,t_2,c_3
748 mulx a_1,b_4,t_1 !mul_add_c(a[1],b[4],c3,c1,c2);
749 addcc c_12,t_1,c_12
750 bcs,a %xcc,.+8 !=
751 add c_3,t_2,c_3
752 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
753 addcc c_12,t_1,c_12
754 bcs,a %xcc,.+8 !=
755 add c_3,t_2,c_3
756 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
757 addcc c_12,t_1,c_12
758 bcs,a %xcc,.+8 !=
759 add c_3,t_2,c_3
760 lduw ap(5),a_5
761 mulx a_4,b_1,t_1 !mul_add_c(a[4],b[1],c3,c1,c2);
762 addcc c_12,t_1,c_12 !=
763 bcs,a %xcc,.+8
764 add c_3,t_2,c_3
765 lduw ap(6),a_6
766 mulx a_5,b_0,t_1 !=!mul_add_c(a[5],b[0],c3,c1,c2);
767 addcc c_12,t_1,t_1
768 bcs,a %xcc,.+8
769 add c_3,t_2,c_3
770 srlx t_1,32,c_12 !=
771 stuw t_1,rp(5) !r[5]=c3;
772 or c_12,c_3,c_12
773
774 mulx a_6,b_0,t_1 !mul_add_c(a[6],b[0],c1,c2,c3);
775 addcc c_12,t_1,c_12 !=
776 clr c_3
777 bcs,a %xcc,.+8
778 add c_3,t_2,c_3
779 mulx a_5,b_1,t_1 !=!mul_add_c(a[5],b[1],c1,c2,c3);
780 addcc c_12,t_1,c_12
781 bcs,a %xcc,.+8
782 add c_3,t_2,c_3
783 mulx a_4,b_2,t_1 !=!mul_add_c(a[4],b[2],c1,c2,c3);
784 addcc c_12,t_1,c_12
785 bcs,a %xcc,.+8
786 add c_3,t_2,c_3
787 mulx a_3,b_3,t_1 !=!mul_add_c(a[3],b[3],c1,c2,c3);
788 addcc c_12,t_1,c_12
789 bcs,a %xcc,.+8
790 add c_3,t_2,c_3
791 mulx a_2,b_4,t_1 !=!mul_add_c(a[2],b[4],c1,c2,c3);
792 addcc c_12,t_1,c_12
793 bcs,a %xcc,.+8
794 add c_3,t_2,c_3
795 lduw bp(6),b_6 !=
796 mulx a_1,b_5,t_1 !mul_add_c(a[1],b[5],c1,c2,c3);
797 addcc c_12,t_1,c_12
798 bcs,a %xcc,.+8
799 add c_3,t_2,c_3 !=
800 lduw bp(7),b_7
801 mulx a_0,b_6,t_1 !mul_add_c(a[0],b[6],c1,c2,c3);
802 addcc c_12,t_1,t_1
803 bcs,a %xcc,.+8 !=
804 add c_3,t_2,c_3
805 srlx t_1,32,c_12
806 stuw t_1,rp(6) !r[6]=c1;
807 or c_12,c_3,c_12 !=
808
809 mulx a_0,b_7,t_1 !mul_add_c(a[0],b[7],c2,c3,c1);
810 addcc c_12,t_1,c_12
811 clr c_3
812 bcs,a %xcc,.+8 !=
813 add c_3,t_2,c_3
814 mulx a_1,b_6,t_1 !mul_add_c(a[1],b[6],c2,c3,c1);
815 addcc c_12,t_1,c_12
816 bcs,a %xcc,.+8 !=
817 add c_3,t_2,c_3
818 mulx a_2,b_5,t_1 !mul_add_c(a[2],b[5],c2,c3,c1);
819 addcc c_12,t_1,c_12
820 bcs,a %xcc,.+8 !=
821 add c_3,t_2,c_3
822 mulx a_3,b_4,t_1 !mul_add_c(a[3],b[4],c2,c3,c1);
823 addcc c_12,t_1,c_12
824 bcs,a %xcc,.+8 !=
825 add c_3,t_2,c_3
826 mulx a_4,b_3,t_1 !mul_add_c(a[4],b[3],c2,c3,c1);
827 addcc c_12,t_1,c_12
828 bcs,a %xcc,.+8 !=
829 add c_3,t_2,c_3
830 mulx a_5,b_2,t_1 !mul_add_c(a[5],b[2],c2,c3,c1);
831 addcc c_12,t_1,c_12
832 bcs,a %xcc,.+8 !=
833 add c_3,t_2,c_3
834 lduw ap(7),a_7
835 mulx a_6,b_1,t_1 !=!mul_add_c(a[6],b[1],c2,c3,c1);
836 addcc c_12,t_1,c_12
837 bcs,a %xcc,.+8
838 add c_3,t_2,c_3
839 mulx a_7,b_0,t_1 !=!mul_add_c(a[7],b[0],c2,c3,c1);
840 addcc c_12,t_1,t_1
841 bcs,a %xcc,.+8
842 add c_3,t_2,c_3
843 srlx t_1,32,c_12 !=
844 stuw t_1,rp(7) !r[7]=c2;
845 or c_12,c_3,c_12
846
847 mulx a_7,b_1,t_1 !=!mul_add_c(a[7],b[1],c3,c1,c2);
848 addcc c_12,t_1,c_12
849 clr c_3
850 bcs,a %xcc,.+8
851 add c_3,t_2,c_3 !=
852 mulx a_6,b_2,t_1 !mul_add_c(a[6],b[2],c3,c1,c2);
853 addcc c_12,t_1,c_12
854 bcs,a %xcc,.+8
855 add c_3,t_2,c_3 !=
856 mulx a_5,b_3,t_1 !mul_add_c(a[5],b[3],c3,c1,c2);
857 addcc c_12,t_1,c_12
858 bcs,a %xcc,.+8
859 add c_3,t_2,c_3 !=
860 mulx a_4,b_4,t_1 !mul_add_c(a[4],b[4],c3,c1,c2);
861 addcc c_12,t_1,c_12
862 bcs,a %xcc,.+8
863 add c_3,t_2,c_3 !=
864 mulx a_3,b_5,t_1 !mul_add_c(a[3],b[5],c3,c1,c2);
865 addcc c_12,t_1,c_12
866 bcs,a %xcc,.+8
867 add c_3,t_2,c_3 !=
868 mulx a_2,b_6,t_1 !mul_add_c(a[2],b[6],c3,c1,c2);
869 addcc c_12,t_1,c_12
870 bcs,a %xcc,.+8
871 add c_3,t_2,c_3 !=
872 mulx a_1,b_7,t_1 !mul_add_c(a[1],b[7],c3,c1,c2);
873 addcc c_12,t_1,t_1
874 bcs,a %xcc,.+8
875 add c_3,t_2,c_3 !=
876 srlx t_1,32,c_12
877 stuw t_1,rp(8) !r[8]=c3;
878 or c_12,c_3,c_12
879
880 mulx a_2,b_7,t_1 !=!mul_add_c(a[2],b[7],c1,c2,c3);
881 addcc c_12,t_1,c_12
882 clr c_3
883 bcs,a %xcc,.+8
884 add c_3,t_2,c_3 !=
885 mulx a_3,b_6,t_1 !mul_add_c(a[3],b[6],c1,c2,c3);
886 addcc c_12,t_1,c_12
887 bcs,a %xcc,.+8 !=
888 add c_3,t_2,c_3
889 mulx a_4,b_5,t_1 !mul_add_c(a[4],b[5],c1,c2,c3);
890 addcc c_12,t_1,c_12
891 bcs,a %xcc,.+8 !=
892 add c_3,t_2,c_3
893 mulx a_5,b_4,t_1 !mul_add_c(a[5],b[4],c1,c2,c3);
894 addcc c_12,t_1,c_12
895 bcs,a %xcc,.+8 !=
896 add c_3,t_2,c_3
897 mulx a_6,b_3,t_1 !mul_add_c(a[6],b[3],c1,c2,c3);
898 addcc c_12,t_1,c_12
899 bcs,a %xcc,.+8 !=
900 add c_3,t_2,c_3
901 mulx a_7,b_2,t_1 !mul_add_c(a[7],b[2],c1,c2,c3);
902 addcc c_12,t_1,t_1
903 bcs,a %xcc,.+8 !=
904 add c_3,t_2,c_3
905 srlx t_1,32,c_12
906 stuw t_1,rp(9) !r[9]=c1;
907 or c_12,c_3,c_12 !=
908
909 mulx a_7,b_3,t_1 !mul_add_c(a[7],b[3],c2,c3,c1);
910 addcc c_12,t_1,c_12
911 clr c_3
912 bcs,a %xcc,.+8 !=
913 add c_3,t_2,c_3
914 mulx a_6,b_4,t_1 !mul_add_c(a[6],b[4],c2,c3,c1);
915 addcc c_12,t_1,c_12
916 bcs,a %xcc,.+8 !=
917 add c_3,t_2,c_3
918 mulx a_5,b_5,t_1 !mul_add_c(a[5],b[5],c2,c3,c1);
919 addcc c_12,t_1,c_12
920 bcs,a %xcc,.+8 !=
921 add c_3,t_2,c_3
922 mulx a_4,b_6,t_1 !mul_add_c(a[4],b[6],c2,c3,c1);
923 addcc c_12,t_1,c_12
924 bcs,a %xcc,.+8 !=
925 add c_3,t_2,c_3
926 mulx a_3,b_7,t_1 !mul_add_c(a[3],b[7],c2,c3,c1);
927 addcc c_12,t_1,t_1
928 bcs,a %xcc,.+8 !=
929 add c_3,t_2,c_3
930 srlx t_1,32,c_12
931 stuw t_1,rp(10) !r[10]=c2;
932 or c_12,c_3,c_12 !=
933
934 mulx a_4,b_7,t_1 !mul_add_c(a[4],b[7],c3,c1,c2);
935 addcc c_12,t_1,c_12
936 clr c_3
937 bcs,a %xcc,.+8 !=
938 add c_3,t_2,c_3
939 mulx a_5,b_6,t_1 !mul_add_c(a[5],b[6],c3,c1,c2);
940 addcc c_12,t_1,c_12
941 bcs,a %xcc,.+8 !=
942 add c_3,t_2,c_3
943 mulx a_6,b_5,t_1 !mul_add_c(a[6],b[5],c3,c1,c2);
944 addcc c_12,t_1,c_12
945 bcs,a %xcc,.+8 !=
946 add c_3,t_2,c_3
947 mulx a_7,b_4,t_1 !mul_add_c(a[7],b[4],c3,c1,c2);
948 addcc c_12,t_1,t_1
949 bcs,a %xcc,.+8 !=
950 add c_3,t_2,c_3
951 srlx t_1,32,c_12
952 stuw t_1,rp(11) !r[11]=c3;
953 or c_12,c_3,c_12 !=
954
955 mulx a_7,b_5,t_1 !mul_add_c(a[7],b[5],c1,c2,c3);
956 addcc c_12,t_1,c_12
957 clr c_3
958 bcs,a %xcc,.+8 !=
959 add c_3,t_2,c_3
960 mulx a_6,b_6,t_1 !mul_add_c(a[6],b[6],c1,c2,c3);
961 addcc c_12,t_1,c_12
962 bcs,a %xcc,.+8 !=
963 add c_3,t_2,c_3
964 mulx a_5,b_7,t_1 !mul_add_c(a[5],b[7],c1,c2,c3);
965 addcc c_12,t_1,t_1
966 bcs,a %xcc,.+8 !=
967 add c_3,t_2,c_3
968 srlx t_1,32,c_12
969 stuw t_1,rp(12) !r[12]=c1;
970 or c_12,c_3,c_12 !=
971
972 mulx a_6,b_7,t_1 !mul_add_c(a[6],b[7],c2,c3,c1);
973 addcc c_12,t_1,c_12
974 clr c_3
975 bcs,a %xcc,.+8 !=
976 add c_3,t_2,c_3
977 mulx a_7,b_6,t_1 !mul_add_c(a[7],b[6],c2,c3,c1);
978 addcc c_12,t_1,t_1
979 bcs,a %xcc,.+8 !=
980 add c_3,t_2,c_3
981 srlx t_1,32,c_12
982 st t_1,rp(13) !r[13]=c2;
983 or c_12,c_3,c_12 !=
984
985 mulx a_7,b_7,t_1 !mul_add_c(a[7],b[7],c3,c1,c2);
986 addcc c_12,t_1,t_1
987 srlx t_1,32,c_12 !=
988 stuw t_1,rp(14) !r[14]=c3;
989 stuw c_12,rp(15) !r[15]=c1;
990
991 ret
992 restore %g0,%g0,%o0 !=
993
994.type bn_mul_comba8,#function
995.size bn_mul_comba8,(.-bn_mul_comba8)
996
997.align 32
998
999.global bn_mul_comba4
1000/*
1001 * void bn_mul_comba4(r,a,b)
1002 * BN_ULONG *r,*a,*b;
1003 */
1004bn_mul_comba4:
1005 save %sp,FRAME_SIZE,%sp
1006 lduw ap(0),a_0
1007 mov 1,t_2
1008 lduw bp(0),b_0
1009 sllx t_2,32,t_2 !=
1010 lduw bp(1),b_1
1011 mulx a_0,b_0,t_1 !mul_add_c(a[0],b[0],c1,c2,c3);
1012 srlx t_1,32,c_12
1013 stuw t_1,rp(0) !=!r[0]=c1;
1014
1015 lduw ap(1),a_1
1016 mulx a_0,b_1,t_1 !mul_add_c(a[0],b[1],c2,c3,c1);
1017 addcc c_12,t_1,c_12
1018 clr c_3 !=
1019 bcs,a %xcc,.+8
1020 add c_3,t_2,c_3
1021 lduw ap(2),a_2
1022 mulx a_1,b_0,t_1 !=!mul_add_c(a[1],b[0],c2,c3,c1);
1023 addcc c_12,t_1,t_1
1024 bcs,a %xcc,.+8
1025 add c_3,t_2,c_3
1026 srlx t_1,32,c_12 !=
1027 stuw t_1,rp(1) !r[1]=c2;
1028 or c_12,c_3,c_12
1029
1030 mulx a_2,b_0,t_1 !mul_add_c(a[2],b[0],c3,c1,c2);
1031 addcc c_12,t_1,c_12 !=
1032 clr c_3
1033 bcs,a %xcc,.+8
1034 add c_3,t_2,c_3
1035 lduw bp(2),b_2 !=
1036 mulx a_1,b_1,t_1 !mul_add_c(a[1],b[1],c3,c1,c2);
1037 addcc c_12,t_1,c_12
1038 bcs,a %xcc,.+8
1039 add c_3,t_2,c_3 !=
1040 lduw bp(3),b_3
1041 mulx a_0,b_2,t_1 !mul_add_c(a[0],b[2],c3,c1,c2);
1042 addcc c_12,t_1,t_1
1043 bcs,a %xcc,.+8 !=
1044 add c_3,t_2,c_3
1045 srlx t_1,32,c_12
1046 stuw t_1,rp(2) !r[2]=c3;
1047 or c_12,c_3,c_12 !=
1048
1049 mulx a_0,b_3,t_1 !mul_add_c(a[0],b[3],c1,c2,c3);
1050 addcc c_12,t_1,c_12
1051 clr c_3
1052 bcs,a %xcc,.+8 !=
1053 add c_3,t_2,c_3
1054 mulx a_1,b_2,t_1 !mul_add_c(a[1],b[2],c1,c2,c3);
1055 addcc c_12,t_1,c_12
1056 bcs,a %xcc,.+8 !=
1057 add c_3,t_2,c_3
1058 lduw ap(3),a_3
1059 mulx a_2,b_1,t_1 !mul_add_c(a[2],b[1],c1,c2,c3);
1060 addcc c_12,t_1,c_12 !=
1061 bcs,a %xcc,.+8
1062 add c_3,t_2,c_3
1063 mulx a_3,b_0,t_1 !mul_add_c(a[3],b[0],c1,c2,c3);!=
1064 addcc c_12,t_1,t_1 !=
1065 bcs,a %xcc,.+8
1066 add c_3,t_2,c_3
1067 srlx t_1,32,c_12
1068 stuw t_1,rp(3) !=!r[3]=c1;
1069 or c_12,c_3,c_12
1070
1071 mulx a_3,b_1,t_1 !mul_add_c(a[3],b[1],c2,c3,c1);
1072 addcc c_12,t_1,c_12
1073 clr c_3 !=
1074 bcs,a %xcc,.+8
1075 add c_3,t_2,c_3
1076 mulx a_2,b_2,t_1 !mul_add_c(a[2],b[2],c2,c3,c1);
1077 addcc c_12,t_1,c_12 !=
1078 bcs,a %xcc,.+8
1079 add c_3,t_2,c_3
1080 mulx a_1,b_3,t_1 !mul_add_c(a[1],b[3],c2,c3,c1);
1081 addcc c_12,t_1,t_1 !=
1082 bcs,a %xcc,.+8
1083 add c_3,t_2,c_3
1084 srlx t_1,32,c_12
1085 stuw t_1,rp(4) !=!r[4]=c2;
1086 or c_12,c_3,c_12
1087
1088 mulx a_2,b_3,t_1 !mul_add_c(a[2],b[3],c3,c1,c2);
1089 addcc c_12,t_1,c_12
1090 clr c_3 !=
1091 bcs,a %xcc,.+8
1092 add c_3,t_2,c_3
1093 mulx a_3,b_2,t_1 !mul_add_c(a[3],b[2],c3,c1,c2);
1094 addcc c_12,t_1,t_1 !=
1095 bcs,a %xcc,.+8
1096 add c_3,t_2,c_3
1097 srlx t_1,32,c_12
1098 stuw t_1,rp(5) !=!r[5]=c3;
1099 or c_12,c_3,c_12
1100
1101 mulx a_3,b_3,t_1 !mul_add_c(a[3],b[3],c1,c2,c3);
1102 addcc c_12,t_1,t_1
1103 srlx t_1,32,c_12 !=
1104 stuw t_1,rp(6) !r[6]=c1;
1105 stuw c_12,rp(7) !r[7]=c2;
1106
1107 ret
1108 restore %g0,%g0,%o0
1109
1110.type bn_mul_comba4,#function
1111.size bn_mul_comba4,(.-bn_mul_comba4)
1112
1113.align 32
1114
1115.global bn_sqr_comba8
1116bn_sqr_comba8:
1117 save %sp,FRAME_SIZE,%sp
1118 mov 1,t_2
1119 lduw ap(0),a_0
1120 sllx t_2,32,t_2
1121 lduw ap(1),a_1
1122 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1123 srlx t_1,32,c_12
1124 stuw t_1,rp(0) !r[0]=c1;
1125
1126 lduw ap(2),a_2
1127 mulx a_0,a_1,t_1 !=!sqr_add_c2(a,1,0,c2,c3,c1);
1128 addcc c_12,t_1,c_12
1129 clr c_3
1130 bcs,a %xcc,.+8
1131 add c_3,t_2,c_3
1132 addcc c_12,t_1,t_1
1133 bcs,a %xcc,.+8
1134 add c_3,t_2,c_3
1135 srlx t_1,32,c_12
1136 stuw t_1,rp(1) !r[1]=c2;
1137 or c_12,c_3,c_12
1138
1139 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1140 addcc c_12,t_1,c_12
1141 clr c_3
1142 bcs,a %xcc,.+8
1143 add c_3,t_2,c_3
1144 addcc c_12,t_1,c_12
1145 bcs,a %xcc,.+8
1146 add c_3,t_2,c_3
1147 lduw ap(3),a_3
1148 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1149 addcc c_12,t_1,t_1
1150 bcs,a %xcc,.+8
1151 add c_3,t_2,c_3
1152 srlx t_1,32,c_12
1153 stuw t_1,rp(2) !r[2]=c3;
1154 or c_12,c_3,c_12
1155
1156 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1157 addcc c_12,t_1,c_12
1158 clr c_3
1159 bcs,a %xcc,.+8
1160 add c_3,t_2,c_3
1161 addcc c_12,t_1,c_12
1162 bcs,a %xcc,.+8
1163 add c_3,t_2,c_3
1164 lduw ap(4),a_4
1165 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1166 addcc c_12,t_1,c_12
1167 bcs,a %xcc,.+8
1168 add c_3,t_2,c_3
1169 addcc c_12,t_1,t_1
1170 bcs,a %xcc,.+8
1171 add c_3,t_2,c_3
1172 srlx t_1,32,c_12
1173 st t_1,rp(3) !r[3]=c1;
1174 or c_12,c_3,c_12
1175
1176 mulx a_4,a_0,t_1 !sqr_add_c2(a,4,0,c2,c3,c1);
1177 addcc c_12,t_1,c_12
1178 clr c_3
1179 bcs,a %xcc,.+8
1180 add c_3,t_2,c_3
1181 addcc c_12,t_1,c_12
1182 bcs,a %xcc,.+8
1183 add c_3,t_2,c_3
1184 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1185 addcc c_12,t_1,c_12
1186 bcs,a %xcc,.+8
1187 add c_3,t_2,c_3
1188 addcc c_12,t_1,c_12
1189 bcs,a %xcc,.+8
1190 add c_3,t_2,c_3
1191 lduw ap(5),a_5
1192 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1193 addcc c_12,t_1,t_1
1194 bcs,a %xcc,.+8
1195 add c_3,t_2,c_3
1196 srlx t_1,32,c_12
1197 stuw t_1,rp(4) !r[4]=c2;
1198 or c_12,c_3,c_12
1199
1200 mulx a_0,a_5,t_1 !sqr_add_c2(a,5,0,c3,c1,c2);
1201 addcc c_12,t_1,c_12
1202 clr c_3
1203 bcs,a %xcc,.+8
1204 add c_3,t_2,c_3
1205 addcc c_12,t_1,c_12
1206 bcs,a %xcc,.+8
1207 add c_3,t_2,c_3
1208 mulx a_1,a_4,t_1 !sqr_add_c2(a,4,1,c3,c1,c2);
1209 addcc c_12,t_1,c_12
1210 bcs,a %xcc,.+8
1211 add c_3,t_2,c_3
1212 addcc c_12,t_1,c_12
1213 bcs,a %xcc,.+8
1214 add c_3,t_2,c_3
1215 lduw ap(6),a_6
1216 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1217 addcc c_12,t_1,c_12
1218 bcs,a %xcc,.+8
1219 add c_3,t_2,c_3
1220 addcc c_12,t_1,t_1
1221 bcs,a %xcc,.+8
1222 add c_3,t_2,c_3
1223 srlx t_1,32,c_12
1224 stuw t_1,rp(5) !r[5]=c3;
1225 or c_12,c_3,c_12
1226
1227 mulx a_6,a_0,t_1 !sqr_add_c2(a,6,0,c1,c2,c3);
1228 addcc c_12,t_1,c_12
1229 clr c_3
1230 bcs,a %xcc,.+8
1231 add c_3,t_2,c_3
1232 addcc c_12,t_1,c_12
1233 bcs,a %xcc,.+8
1234 add c_3,t_2,c_3
1235 mulx a_5,a_1,t_1 !sqr_add_c2(a,5,1,c1,c2,c3);
1236 addcc c_12,t_1,c_12
1237 bcs,a %xcc,.+8
1238 add c_3,t_2,c_3
1239 addcc c_12,t_1,c_12
1240 bcs,a %xcc,.+8
1241 add c_3,t_2,c_3
1242 mulx a_4,a_2,t_1 !sqr_add_c2(a,4,2,c1,c2,c3);
1243 addcc c_12,t_1,c_12
1244 bcs,a %xcc,.+8
1245 add c_3,t_2,c_3
1246 addcc c_12,t_1,c_12
1247 bcs,a %xcc,.+8
1248 add c_3,t_2,c_3
1249 lduw ap(7),a_7
1250 mulx a_3,a_3,t_1 !=!sqr_add_c(a,3,c1,c2,c3);
1251 addcc c_12,t_1,t_1
1252 bcs,a %xcc,.+8
1253 add c_3,t_2,c_3
1254 srlx t_1,32,c_12
1255 stuw t_1,rp(6) !r[6]=c1;
1256 or c_12,c_3,c_12
1257
1258 mulx a_0,a_7,t_1 !sqr_add_c2(a,7,0,c2,c3,c1);
1259 addcc c_12,t_1,c_12
1260 clr c_3
1261 bcs,a %xcc,.+8
1262 add c_3,t_2,c_3
1263 addcc c_12,t_1,c_12
1264 bcs,a %xcc,.+8
1265 add c_3,t_2,c_3
1266 mulx a_1,a_6,t_1 !sqr_add_c2(a,6,1,c2,c3,c1);
1267 addcc c_12,t_1,c_12
1268 bcs,a %xcc,.+8
1269 add c_3,t_2,c_3
1270 addcc c_12,t_1,c_12
1271 bcs,a %xcc,.+8
1272 add c_3,t_2,c_3
1273 mulx a_2,a_5,t_1 !sqr_add_c2(a,5,2,c2,c3,c1);
1274 addcc c_12,t_1,c_12
1275 bcs,a %xcc,.+8
1276 add c_3,t_2,c_3
1277 addcc c_12,t_1,c_12
1278 bcs,a %xcc,.+8
1279 add c_3,t_2,c_3
1280 mulx a_3,a_4,t_1 !sqr_add_c2(a,4,3,c2,c3,c1);
1281 addcc c_12,t_1,c_12
1282 bcs,a %xcc,.+8
1283 add c_3,t_2,c_3
1284 addcc c_12,t_1,t_1
1285 bcs,a %xcc,.+8
1286 add c_3,t_2,c_3
1287 srlx t_1,32,c_12
1288 stuw t_1,rp(7) !r[7]=c2;
1289 or c_12,c_3,c_12
1290
1291 mulx a_7,a_1,t_1 !sqr_add_c2(a,7,1,c3,c1,c2);
1292 addcc c_12,t_1,c_12
1293 clr c_3
1294 bcs,a %xcc,.+8
1295 add c_3,t_2,c_3
1296 addcc c_12,t_1,c_12
1297 bcs,a %xcc,.+8
1298 add c_3,t_2,c_3
1299 mulx a_6,a_2,t_1 !sqr_add_c2(a,6,2,c3,c1,c2);
1300 addcc c_12,t_1,c_12
1301 bcs,a %xcc,.+8
1302 add c_3,t_2,c_3
1303 addcc c_12,t_1,c_12
1304 bcs,a %xcc,.+8
1305 add c_3,t_2,c_3
1306 mulx a_5,a_3,t_1 !sqr_add_c2(a,5,3,c3,c1,c2);
1307 addcc c_12,t_1,c_12
1308 bcs,a %xcc,.+8
1309 add c_3,t_2,c_3
1310 addcc c_12,t_1,c_12
1311 bcs,a %xcc,.+8
1312 add c_3,t_2,c_3
1313 mulx a_4,a_4,t_1 !sqr_add_c(a,4,c3,c1,c2);
1314 addcc c_12,t_1,t_1
1315 bcs,a %xcc,.+8
1316 add c_3,t_2,c_3
1317 srlx t_1,32,c_12
1318 stuw t_1,rp(8) !r[8]=c3;
1319 or c_12,c_3,c_12
1320
1321 mulx a_2,a_7,t_1 !sqr_add_c2(a,7,2,c1,c2,c3);
1322 addcc c_12,t_1,c_12
1323 clr c_3
1324 bcs,a %xcc,.+8
1325 add c_3,t_2,c_3
1326 addcc c_12,t_1,c_12
1327 bcs,a %xcc,.+8
1328 add c_3,t_2,c_3
1329 mulx a_3,a_6,t_1 !sqr_add_c2(a,6,3,c1,c2,c3);
1330 addcc c_12,t_1,c_12
1331 bcs,a %xcc,.+8
1332 add c_3,t_2,c_3
1333 addcc c_12,t_1,c_12
1334 bcs,a %xcc,.+8
1335 add c_3,t_2,c_3
1336 mulx a_4,a_5,t_1 !sqr_add_c2(a,5,4,c1,c2,c3);
1337 addcc c_12,t_1,c_12
1338 bcs,a %xcc,.+8
1339 add c_3,t_2,c_3
1340 addcc c_12,t_1,t_1
1341 bcs,a %xcc,.+8
1342 add c_3,t_2,c_3
1343 srlx t_1,32,c_12
1344 stuw t_1,rp(9) !r[9]=c1;
1345 or c_12,c_3,c_12
1346
1347 mulx a_7,a_3,t_1 !sqr_add_c2(a,7,3,c2,c3,c1);
1348 addcc c_12,t_1,c_12
1349 clr c_3
1350 bcs,a %xcc,.+8
1351 add c_3,t_2,c_3
1352 addcc c_12,t_1,c_12
1353 bcs,a %xcc,.+8
1354 add c_3,t_2,c_3
1355 mulx a_6,a_4,t_1 !sqr_add_c2(a,6,4,c2,c3,c1);
1356 addcc c_12,t_1,c_12
1357 bcs,a %xcc,.+8
1358 add c_3,t_2,c_3
1359 addcc c_12,t_1,c_12
1360 bcs,a %xcc,.+8
1361 add c_3,t_2,c_3
1362 mulx a_5,a_5,t_1 !sqr_add_c(a,5,c2,c3,c1);
1363 addcc c_12,t_1,t_1
1364 bcs,a %xcc,.+8
1365 add c_3,t_2,c_3
1366 srlx t_1,32,c_12
1367 stuw t_1,rp(10) !r[10]=c2;
1368 or c_12,c_3,c_12
1369
1370 mulx a_4,a_7,t_1 !sqr_add_c2(a,7,4,c3,c1,c2);
1371 addcc c_12,t_1,c_12
1372 clr c_3
1373 bcs,a %xcc,.+8
1374 add c_3,t_2,c_3
1375 addcc c_12,t_1,c_12
1376 bcs,a %xcc,.+8
1377 add c_3,t_2,c_3
1378 mulx a_5,a_6,t_1 !sqr_add_c2(a,6,5,c3,c1,c2);
1379 addcc c_12,t_1,c_12
1380 bcs,a %xcc,.+8
1381 add c_3,t_2,c_3
1382 addcc c_12,t_1,t_1
1383 bcs,a %xcc,.+8
1384 add c_3,t_2,c_3
1385 srlx t_1,32,c_12
1386 stuw t_1,rp(11) !r[11]=c3;
1387 or c_12,c_3,c_12
1388
1389 mulx a_7,a_5,t_1 !sqr_add_c2(a,7,5,c1,c2,c3);
1390 addcc c_12,t_1,c_12
1391 clr c_3
1392 bcs,a %xcc,.+8
1393 add c_3,t_2,c_3
1394 addcc c_12,t_1,c_12
1395 bcs,a %xcc,.+8
1396 add c_3,t_2,c_3
1397 mulx a_6,a_6,t_1 !sqr_add_c(a,6,c1,c2,c3);
1398 addcc c_12,t_1,t_1
1399 bcs,a %xcc,.+8
1400 add c_3,t_2,c_3
1401 srlx t_1,32,c_12
1402 stuw t_1,rp(12) !r[12]=c1;
1403 or c_12,c_3,c_12
1404
1405 mulx a_6,a_7,t_1 !sqr_add_c2(a,7,6,c2,c3,c1);
1406 addcc c_12,t_1,c_12
1407 clr c_3
1408 bcs,a %xcc,.+8
1409 add c_3,t_2,c_3
1410 addcc c_12,t_1,t_1
1411 bcs,a %xcc,.+8
1412 add c_3,t_2,c_3
1413 srlx t_1,32,c_12
1414 stuw t_1,rp(13) !r[13]=c2;
1415 or c_12,c_3,c_12
1416
1417 mulx a_7,a_7,t_1 !sqr_add_c(a,7,c3,c1,c2);
1418 addcc c_12,t_1,t_1
1419 srlx t_1,32,c_12
1420 stuw t_1,rp(14) !r[14]=c3;
1421 stuw c_12,rp(15) !r[15]=c1;
1422
1423 ret
1424 restore %g0,%g0,%o0
1425
1426.type bn_sqr_comba8,#function
1427.size bn_sqr_comba8,(.-bn_sqr_comba8)
1428
1429.align 32
1430
1431.global bn_sqr_comba4
1432/*
1433 * void bn_sqr_comba4(r,a)
1434 * BN_ULONG *r,*a;
1435 */
1436bn_sqr_comba4:
1437 save %sp,FRAME_SIZE,%sp
1438 mov 1,t_2
1439 lduw ap(0),a_0
1440 sllx t_2,32,t_2
1441 lduw ap(1),a_1
1442 mulx a_0,a_0,t_1 !sqr_add_c(a,0,c1,c2,c3);
1443 srlx t_1,32,c_12
1444 stuw t_1,rp(0) !r[0]=c1;
1445
1446 lduw ap(2),a_2
1447 mulx a_0,a_1,t_1 !sqr_add_c2(a,1,0,c2,c3,c1);
1448 addcc c_12,t_1,c_12
1449 clr c_3
1450 bcs,a %xcc,.+8
1451 add c_3,t_2,c_3
1452 addcc c_12,t_1,t_1
1453 bcs,a %xcc,.+8
1454 add c_3,t_2,c_3
1455 srlx t_1,32,c_12
1456 stuw t_1,rp(1) !r[1]=c2;
1457 or c_12,c_3,c_12
1458
1459 mulx a_2,a_0,t_1 !sqr_add_c2(a,2,0,c3,c1,c2);
1460 addcc c_12,t_1,c_12
1461 clr c_3
1462 bcs,a %xcc,.+8
1463 add c_3,t_2,c_3
1464 addcc c_12,t_1,c_12
1465 bcs,a %xcc,.+8
1466 add c_3,t_2,c_3
1467 lduw ap(3),a_3
1468 mulx a_1,a_1,t_1 !sqr_add_c(a,1,c3,c1,c2);
1469 addcc c_12,t_1,t_1
1470 bcs,a %xcc,.+8
1471 add c_3,t_2,c_3
1472 srlx t_1,32,c_12
1473 stuw t_1,rp(2) !r[2]=c3;
1474 or c_12,c_3,c_12
1475
1476 mulx a_0,a_3,t_1 !sqr_add_c2(a,3,0,c1,c2,c3);
1477 addcc c_12,t_1,c_12
1478 clr c_3
1479 bcs,a %xcc,.+8
1480 add c_3,t_2,c_3
1481 addcc c_12,t_1,c_12
1482 bcs,a %xcc,.+8
1483 add c_3,t_2,c_3
1484 mulx a_1,a_2,t_1 !sqr_add_c2(a,2,1,c1,c2,c3);
1485 addcc c_12,t_1,c_12
1486 bcs,a %xcc,.+8
1487 add c_3,t_2,c_3
1488 addcc c_12,t_1,t_1
1489 bcs,a %xcc,.+8
1490 add c_3,t_2,c_3
1491 srlx t_1,32,c_12
1492 stuw t_1,rp(3) !r[3]=c1;
1493 or c_12,c_3,c_12
1494
1495 mulx a_3,a_1,t_1 !sqr_add_c2(a,3,1,c2,c3,c1);
1496 addcc c_12,t_1,c_12
1497 clr c_3
1498 bcs,a %xcc,.+8
1499 add c_3,t_2,c_3
1500 addcc c_12,t_1,c_12
1501 bcs,a %xcc,.+8
1502 add c_3,t_2,c_3
1503 mulx a_2,a_2,t_1 !sqr_add_c(a,2,c2,c3,c1);
1504 addcc c_12,t_1,t_1
1505 bcs,a %xcc,.+8
1506 add c_3,t_2,c_3
1507 srlx t_1,32,c_12
1508 stuw t_1,rp(4) !r[4]=c2;
1509 or c_12,c_3,c_12
1510
1511 mulx a_2,a_3,t_1 !sqr_add_c2(a,3,2,c3,c1,c2);
1512 addcc c_12,t_1,c_12
1513 clr c_3
1514 bcs,a %xcc,.+8
1515 add c_3,t_2,c_3
1516 addcc c_12,t_1,t_1
1517 bcs,a %xcc,.+8
1518 add c_3,t_2,c_3
1519 srlx t_1,32,c_12
1520 stuw t_1,rp(5) !r[5]=c3;
1521 or c_12,c_3,c_12
1522
1523 mulx a_3,a_3,t_1 !sqr_add_c(a,3,c1,c2,c3);
1524 addcc c_12,t_1,t_1
1525 srlx t_1,32,c_12
1526 stuw t_1,rp(6) !r[6]=c1;
1527 stuw c_12,rp(7) !r[7]=c2;
1528
1529 ret
1530 restore %g0,%g0,%o0
1531
1532.type bn_sqr_comba4,#function
1533.size bn_sqr_comba4,(.-bn_sqr_comba4)
1534
1535.align 32
diff --git a/src/lib/libcrypto/bn/asm/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 @@
1 .title vax_bn_mul_add_word unsigned multiply & add, 32*32+32+32=>64
2;
3; w.j.m. 15-jan-1999
4;
5; it's magic ...
6;
7; ULONG bn_mul_add_words(ULONG r[],ULONG a[],int n,ULONG w) {
8; ULONG c = 0;
9; int i;
10; for(i = 0; i < n; i++) <c,r[i]> := r[i] + c + a[i] * w ;
11; return c;
12; }
13
14r=4 ;(AP)
15a=8 ;(AP)
16n=12 ;(AP) n by value (input)
17w=16 ;(AP) w by value (input)
18
19
20 .psect code,nowrt
21
22.entry bn_mul_add_words,^m<r2,r3,r4,r5,r6>
23
24 moval @r(ap),r2
25 moval @a(ap),r3
26 movl n(ap),r4 ; assumed >0 by C code
27 movl w(ap),r5
28 clrl r6 ; c
29
300$:
31 emul r5,(r3),(r2),r0 ; w, a[], r[] considered signed
32
33 ; fixup for "negative" r[]
34 tstl (r2)
35 bgeq 10$
36 incl r1
3710$:
38
39 ; add in c
40 addl2 r6,r0
41 adwc #0,r1
42
43 ; combined fixup for "negative" w, a[]
44 tstl r5
45 bgeq 20$
46 addl2 (r3),r1
4720$:
48 tstl (r3)
49 bgeq 30$
50 addl2 r5,r1
5130$:
52
53 movl r0,(r2)+ ; store lo result in r[] & advance
54 addl #4,r3 ; advance a[]
55 movl r1,r6 ; store hi result => c
56
57 sobgtr r4,0$
58
59 movl r6,r0 ; return c
60 ret
61
62 .title vax_bn_mul_word unsigned multiply & add, 32*32+32=>64
63;
64; w.j.m. 15-jan-1999
65;
66; it's magic ...
67;
68; ULONG bn_mul_words(ULONG r[],ULONG a[],int n,ULONG w) {
69; ULONG c = 0;
70; int i;
71; for(i = 0; i < num; i++) <c,r[i]> := a[i] * w + c ;
72; return(c);
73; }
74
75r=4 ;(AP)
76a=8 ;(AP)
77n=12 ;(AP) n by value (input)
78w=16 ;(AP) w by value (input)
79
80
81 .psect code,nowrt
82
83.entry bn_mul_words,^m<r2,r3,r4,r5,r6>
84
85 moval @r(ap),r2 ; r2 -> r[]
86 moval @a(ap),r3 ; r3 -> a[]
87 movl n(ap),r4 ; r4 = loop count (assumed >0 by C code)
88 movl w(ap),r5 ; r5 = w
89 clrl r6 ; r6 = c
90
910$:
92 ; <r1,r0> := w * a[] + c
93 emul r5,(r3),r6,r0 ; w, a[], c considered signed
94
95 ; fixup for "negative" c
96 tstl r6 ; c
97 bgeq 10$
98 incl r1
9910$:
100
101 ; combined fixup for "negative" w, a[]
102 tstl r5 ; w
103 bgeq 20$
104 addl2 (r3),r1 ; a[]
10520$:
106 tstl (r3) ; a[]
107 bgeq 30$
108 addl2 r5,r1 ; w
10930$:
110
111 movl r0,(r2)+ ; store lo result in r[] & advance
112 addl #4,r3 ; advance a[]
113 movl r1,r6 ; store hi result => c
114
115 sobgtr r4,0$
116
117 movl r6,r0 ; return c
118 ret
119
120 .title vax_bn_sqr_words unsigned square, 32*32=>64
121;
122; w.j.m. 15-jan-1999
123;
124; it's magic ...
125;
126; void bn_sqr_words(ULONG r[],ULONG a[],int n) {
127; int i;
128; for(i = 0; i < n; i++) <r[2*i+1],r[2*i]> := a[i] * a[i] ;
129; }
130
131r=4 ;(AP)
132a=8 ;(AP)
133n=12 ;(AP) n by value (input)
134
135
136 .psect code,nowrt
137
138.entry bn_sqr_words,^m<r2,r3,r4,r5>
139
140 moval @r(ap),r2 ; r2 -> r[]
141 moval @a(ap),r3 ; r3 -> a[]
142 movl n(ap),r4 ; r4 = n (assumed >0 by C code)
143
1440$:
145 movl (r3)+,r5 ; r5 = a[] & advance
146
147 ; <r1,r0> := a[] * a[]
148 emul r5,r5,#0,r0 ; a[] considered signed
149
150 ; fixup for "negative" a[]
151 tstl r5 ; a[]
152 bgeq 30$
153 addl2 r5,r1 ; a[]
154 addl2 r5,r1 ; a[]
15530$:
156
157 movl r0,(r2)+ ; store lo result in r[] & advance
158 movl r1,(r2)+ ; store hi result in r[] & advance
159
160 sobgtr r4,0$
161
162 movl #1,r0 ; return SS$_NORMAL
163 ret
164
165 .title (generated)
166
167 .psect code,nowrt
168
169.entry BN_DIV_WORDS,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10>
170 subl2 #4,sp
171
172 clrl r9
173 movl #2,r8
174
175 tstl 12(ap)
176 bneq noname.2
177 mnegl #1,r10
178 brw noname.3
179 tstl r0
180 nop
181noname.2:
182
183 pushl 12(ap)
184 calls #1,BN_NUM_BITS_WORD
185 movl r0,r7
186
187 cmpl r7,#32
188 beql noname.4
189 ashl r7,#1,r2
190 cmpl 4(ap),r2
191 blequ noname.4
192
193 pushl r7
194 calls #1,BN_DIV_WORDS_ABORT
195noname.4:
196
197 subl3 r7,#32,r7
198
199 movl 12(ap),r2
200 cmpl 4(ap),r2
201 blssu noname.5
202 subl2 r2,4(ap)
203noname.5:
204
205 tstl r7
206 beql noname.6
207
208 ashl r7,r2,12(ap)
209
210 ashl r7,4(ap),r4
211 subl3 r7,#32,r3
212 subl3 r3,#32,r2
213 extzv r3,r2,8(ap),r2
214 bisl3 r4,r2,4(ap)
215
216 ashl r7,8(ap),8(ap)
217noname.6:
218
219 bicl3 #65535,12(ap),r2
220 extzv #16,#16,r2,r5
221
222 bicl3 #-65536,12(ap),r6
223
224noname.7:
225
226 moval 4(ap),r2
227 movzwl 2(r2),r0
228 cmpl r0,r5
229 bneq noname.8
230
231 movzwl #65535,r4
232 brb noname.9
233noname.8:
234
235 clrl r1
236 movl (r2),r0
237 movl r5,r2
238 bgeq vcg.1
239 cmpl r2,r0
240 bgtru vcg.2
241 incl r1
242 brb vcg.2
243 nop
244vcg.1:
245 ediv r2,r0,r1,r0
246vcg.2:
247 movl r1,r4
248noname.9:
249
250noname.10:
251
252 mull3 r5,r4,r0
253 subl3 r0,4(ap),r3
254
255 bicl3 #65535,r3,r0
256 bneq noname.13
257 mull3 r6,r4,r2
258 ashl #16,r3,r1
259 bicl3 #65535,8(ap),r0
260 extzv #16,#16,r0,r0
261 addl2 r0,r1
262 cmpl r2,r1
263 bgtru noname.12
264noname.11:
265
266 brb noname.13
267 nop
268noname.12:
269
270 decl r4
271 brb noname.10
272noname.13:
273
274 mull3 r5,r4,r1
275
276 mull3 r6,r4,r0
277
278 extzv #16,#16,r0,r3
279
280 ashl #16,r0,r2
281 bicl3 #65535,r2,r0
282
283 addl2 r3,r1
284
285 moval 8(ap),r3
286 cmpl (r3),r0
287 bgequ noname.15
288 incl r1
289noname.15:
290
291 subl2 r0,(r3)
292
293 cmpl 4(ap),r1
294 bgequ noname.16
295
296 addl2 12(ap),4(ap)
297
298 decl r4
299noname.16:
300
301 subl2 r1,4(ap)
302
303 decl r8
304 beql noname.18
305noname.17:
306
307 ashl #16,r4,r9
308
309 ashl #16,4(ap),r2
310 movzwl 2(r3),r0
311 bisl2 r0,r2
312 bicl3 #0,r2,4(ap)
313
314 bicl3 #-65536,(r3),r0
315 ashl #16,r0,(r3)
316 brw noname.7
317 nop
318noname.18:
319
320 bisl2 r4,r9
321
322 movl r9,r10
323
324noname.3:
325 movl r10,r0
326 ret
327 tstl r0
328
329
330 .psect code,nowrt
331
332.entry BN_ADD_WORDS,^m<r2,r3,r4,r5,r6,r7>
333
334 tstl 16(ap)
335 bgtr noname.21
336 clrl r7
337 brw noname.22
338noname.21:
339
340 clrl r4
341
342 tstl r0
343noname.23:
344
345 movl 8(ap),r6
346 addl3 r4,(r6),r2
347
348 bicl2 #0,r2
349
350 clrl r0
351 cmpl r2,r4
352 bgequ vcg.3
353 incl r0
354vcg.3:
355 movl r0,r4
356
357 movl 12(ap),r5
358 addl3 (r5),r2,r1
359 bicl2 #0,r1
360
361 clrl r0
362 cmpl r1,r2
363 bgequ vcg.4
364 incl r0
365vcg.4:
366 addl2 r0,r4
367
368 movl 4(ap),r3
369 movl r1,(r3)
370
371 decl 16(ap)
372 bgtr gen.1
373 brw noname.25
374gen.1:
375noname.24:
376
377 addl3 r4,4(r6),r2
378
379 bicl2 #0,r2
380
381 clrl r0
382 cmpl r2,r4
383 bgequ vcg.5
384 incl r0
385vcg.5:
386 movl r0,r4
387
388 addl3 4(r5),r2,r1
389 bicl2 #0,r1
390
391 clrl r0
392 cmpl r1,r2
393 bgequ vcg.6
394 incl r0
395vcg.6:
396 addl2 r0,r4
397
398 movl r1,4(r3)
399
400 decl 16(ap)
401 bleq noname.25
402noname.26:
403
404 addl3 r4,8(r6),r2
405
406 bicl2 #0,r2
407
408 clrl r0
409 cmpl r2,r4
410 bgequ vcg.7
411 incl r0
412vcg.7:
413 movl r0,r4
414
415 addl3 8(r5),r2,r1
416 bicl2 #0,r1
417
418 clrl r0
419 cmpl r1,r2
420 bgequ vcg.8
421 incl r0
422vcg.8:
423 addl2 r0,r4
424
425 movl r1,8(r3)
426
427 decl 16(ap)
428 bleq noname.25
429noname.27:
430
431 addl3 r4,12(r6),r2
432
433 bicl2 #0,r2
434
435 clrl r0
436 cmpl r2,r4
437 bgequ vcg.9
438 incl r0
439vcg.9:
440 movl r0,r4
441
442 addl3 12(r5),r2,r1
443 bicl2 #0,r1
444
445 clrl r0
446 cmpl r1,r2
447 bgequ vcg.10
448 incl r0
449vcg.10:
450 addl2 r0,r4
451
452 movl r1,12(r3)
453
454 decl 16(ap)
455 bleq noname.25
456noname.28:
457
458 addl3 #16,r6,8(ap)
459
460 addl3 #16,r5,12(ap)
461
462 addl3 #16,r3,4(ap)
463 brw noname.23
464 tstl r0
465noname.25:
466
467 movl r4,r7
468
469noname.22:
470 movl r7,r0
471 ret
472 nop
473
474
475
476;r=4 ;(AP)
477;a=8 ;(AP)
478;b=12 ;(AP)
479;n=16 ;(AP) n by value (input)
480
481 .psect code,nowrt
482
483.entry BN_SUB_WORDS,^m<r2,r3,r4,r5,r6,r7>
484
485 clrl r6
486
487 tstl 16(ap)
488 bgtr noname.31
489 clrl r7
490 brw noname.32
491 tstl r0
492noname.31:
493
494noname.33:
495
496 movl 8(ap),r5
497 movl (r5),r1
498 movl 12(ap),r4
499 movl (r4),r2
500
501 movl 4(ap),r3
502 subl3 r2,r1,r0
503 subl2 r6,r0
504 bicl3 #0,r0,(r3)
505
506 cmpl r1,r2
507 beql noname.34
508 clrl r0
509 cmpl r1,r2
510 bgequ vcg.11
511 incl r0
512vcg.11:
513 movl r0,r6
514noname.34:
515
516 decl 16(ap)
517 bgtr gen.2
518 brw noname.36
519gen.2:
520noname.35:
521
522 movl 4(r5),r2
523 movl 4(r4),r1
524
525 subl3 r1,r2,r0
526 subl2 r6,r0
527 bicl3 #0,r0,4(r3)
528
529 cmpl r2,r1
530 beql noname.37
531 clrl r0
532 cmpl r2,r1
533 bgequ vcg.12
534 incl r0
535vcg.12:
536 movl r0,r6
537noname.37:
538
539 decl 16(ap)
540 bleq noname.36
541noname.38:
542
543 movl 8(r5),r1
544 movl 8(r4),r2
545
546 subl3 r2,r1,r0
547 subl2 r6,r0
548 bicl3 #0,r0,8(r3)
549
550 cmpl r1,r2
551 beql noname.39
552 clrl r0
553 cmpl r1,r2
554 bgequ vcg.13
555 incl r0
556vcg.13:
557 movl r0,r6
558noname.39:
559
560 decl 16(ap)
561 bleq noname.36
562noname.40:
563
564 movl 12(r5),r1
565 movl 12(r4),r2
566
567 subl3 r2,r1,r0
568 subl2 r6,r0
569 bicl3 #0,r0,12(r3)
570
571 cmpl r1,r2
572 beql noname.41
573 clrl r0
574 cmpl r1,r2
575 bgequ vcg.14
576 incl r0
577vcg.14:
578 movl r0,r6
579noname.41:
580
581 decl 16(ap)
582 bleq noname.36
583noname.42:
584
585 addl3 #16,r5,8(ap)
586
587 addl3 #16,r4,12(ap)
588
589 addl3 #16,r3,4(ap)
590 brw noname.33
591 tstl r0
592noname.36:
593
594 movl r6,r7
595
596noname.32:
597 movl r7,r0
598 ret
599 nop
600
601
602
603;r=4 ;(AP)
604;a=8 ;(AP)
605;b=12 ;(AP)
606;n=16 ;(AP) n by value (input)
607
608 .psect code,nowrt
609
610.entry BN_MUL_COMBA8,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
611 movab -924(sp),sp
612 clrq r8
613
614 clrl r10
615
616 movl 8(ap),r6
617 movzwl 2(r6),r3
618 movl 12(ap),r7
619 bicl3 #-65536,(r7),r2
620 movzwl 2(r7),r0
621 bicl2 #-65536,r0
622 bicl3 #-65536,(r6),-12(fp)
623 bicl3 #-65536,r3,-16(fp)
624 mull3 r0,-12(fp),-4(fp)
625 mull2 r2,-12(fp)
626 mull3 r2,-16(fp),-8(fp)
627 mull2 r0,-16(fp)
628 addl3 -4(fp),-8(fp),r0
629 bicl3 #0,r0,-4(fp)
630 cmpl -4(fp),-8(fp)
631 bgequ noname.45
632 addl2 #65536,-16(fp)
633noname.45:
634 movzwl -2(fp),r0
635 bicl2 #-65536,r0
636 addl2 r0,-16(fp)
637 bicl3 #-65536,-4(fp),r0
638 ashl #16,r0,-8(fp)
639 addl3 -8(fp),-12(fp),r0
640 bicl3 #0,r0,-12(fp)
641 cmpl -12(fp),-8(fp)
642 bgequ noname.46
643 incl -16(fp)
644noname.46:
645 movl -12(fp),r1
646 movl -16(fp),r2
647 addl2 r1,r9
648 bicl2 #0,r9
649 cmpl r9,r1
650 bgequ noname.47
651 incl r2
652noname.47:
653 addl2 r2,r8
654 bicl2 #0,r8
655 cmpl r8,r2
656 bgequ noname.48
657 incl r10
658noname.48:
659
660 movl 4(ap),r11
661 movl r9,(r11)
662
663 clrl r9
664
665 movzwl 2(r6),r2
666 bicl3 #-65536,4(r7),r3
667 movzwl 6(r7),r0
668 bicl2 #-65536,r0
669 bicl3 #-65536,(r6),-28(fp)
670 bicl3 #-65536,r2,-32(fp)
671 mull3 r0,-28(fp),-20(fp)
672 mull2 r3,-28(fp)
673 mull3 r3,-32(fp),-24(fp)
674 mull2 r0,-32(fp)
675 addl3 -20(fp),-24(fp),r0
676 bicl3 #0,r0,-20(fp)
677 cmpl -20(fp),-24(fp)
678 bgequ noname.49
679 addl2 #65536,-32(fp)
680noname.49:
681 movzwl -18(fp),r0
682 bicl2 #-65536,r0
683 addl2 r0,-32(fp)
684 bicl3 #-65536,-20(fp),r0
685 ashl #16,r0,-24(fp)
686 addl3 -24(fp),-28(fp),r0
687 bicl3 #0,r0,-28(fp)
688 cmpl -28(fp),-24(fp)
689 bgequ noname.50
690 incl -32(fp)
691noname.50:
692 movl -28(fp),r1
693 movl -32(fp),r2
694 addl2 r1,r8
695 bicl2 #0,r8
696 cmpl r8,r1
697 bgequ noname.51
698 incl r2
699noname.51:
700 addl2 r2,r10
701 bicl2 #0,r10
702 cmpl r10,r2
703 bgequ noname.52
704 incl r9
705noname.52:
706
707 movzwl 6(r6),r2
708 bicl3 #-65536,(r7),r3
709 movzwl 2(r7),r0
710 bicl2 #-65536,r0
711 bicl3 #-65536,4(r6),-44(fp)
712 bicl3 #-65536,r2,-48(fp)
713 mull3 r0,-44(fp),-36(fp)
714 mull2 r3,-44(fp)
715 mull3 r3,-48(fp),-40(fp)
716 mull2 r0,-48(fp)
717 addl3 -36(fp),-40(fp),r0
718 bicl3 #0,r0,-36(fp)
719 cmpl -36(fp),-40(fp)
720 bgequ noname.53
721 addl2 #65536,-48(fp)
722noname.53:
723 movzwl -34(fp),r0
724 bicl2 #-65536,r0
725 addl2 r0,-48(fp)
726 bicl3 #-65536,-36(fp),r0
727 ashl #16,r0,-40(fp)
728 addl3 -40(fp),-44(fp),r0
729 bicl3 #0,r0,-44(fp)
730 cmpl -44(fp),-40(fp)
731 bgequ noname.54
732 incl -48(fp)
733noname.54:
734 movl -44(fp),r1
735 movl -48(fp),r2
736 addl2 r1,r8
737 bicl2 #0,r8
738 cmpl r8,r1
739 bgequ noname.55
740 incl r2
741noname.55:
742 addl2 r2,r10
743 bicl2 #0,r10
744 cmpl r10,r2
745 bgequ noname.56
746 incl r9
747noname.56:
748
749 movl r8,4(r11)
750
751 clrl r8
752
753 movzwl 10(r6),r2
754 bicl3 #-65536,(r7),r3
755 movzwl 2(r7),r0
756 bicl2 #-65536,r0
757 bicl3 #-65536,8(r6),-60(fp)
758 bicl3 #-65536,r2,-64(fp)
759 mull3 r0,-60(fp),-52(fp)
760 mull2 r3,-60(fp)
761 mull3 r3,-64(fp),-56(fp)
762 mull2 r0,-64(fp)
763 addl3 -52(fp),-56(fp),r0
764 bicl3 #0,r0,-52(fp)
765 cmpl -52(fp),-56(fp)
766 bgequ noname.57
767 addl2 #65536,-64(fp)
768noname.57:
769 movzwl -50(fp),r0
770 bicl2 #-65536,r0
771 addl2 r0,-64(fp)
772 bicl3 #-65536,-52(fp),r0
773 ashl #16,r0,-56(fp)
774 addl3 -56(fp),-60(fp),r0
775 bicl3 #0,r0,-60(fp)
776 cmpl -60(fp),-56(fp)
777 bgequ noname.58
778 incl -64(fp)
779noname.58:
780 movl -60(fp),r1
781 movl -64(fp),r2
782 addl2 r1,r10
783 bicl2 #0,r10
784 cmpl r10,r1
785 bgequ noname.59
786 incl r2
787noname.59:
788 addl2 r2,r9
789 bicl2 #0,r9
790 cmpl r9,r2
791 bgequ noname.60
792 incl r8
793noname.60:
794
795 movzwl 6(r6),r2
796 bicl3 #-65536,4(r7),r3
797 movzwl 6(r7),r0
798 bicl2 #-65536,r0
799 bicl3 #-65536,4(r6),-76(fp)
800 bicl3 #-65536,r2,-80(fp)
801 mull3 r0,-76(fp),-68(fp)
802 mull2 r3,-76(fp)
803 mull3 r3,-80(fp),-72(fp)
804 mull2 r0,-80(fp)
805 addl3 -68(fp),-72(fp),r0
806 bicl3 #0,r0,-68(fp)
807 cmpl -68(fp),-72(fp)
808 bgequ noname.61
809 addl2 #65536,-80(fp)
810noname.61:
811 movzwl -66(fp),r0
812 bicl2 #-65536,r0
813 addl2 r0,-80(fp)
814 bicl3 #-65536,-68(fp),r0
815 ashl #16,r0,-72(fp)
816 addl3 -72(fp),-76(fp),r0
817 bicl3 #0,r0,-76(fp)
818 cmpl -76(fp),-72(fp)
819 bgequ noname.62
820 incl -80(fp)
821noname.62:
822 movl -76(fp),r1
823 movl -80(fp),r2
824 addl2 r1,r10
825 bicl2 #0,r10
826 cmpl r10,r1
827 bgequ noname.63
828 incl r2
829noname.63:
830 addl2 r2,r9
831 bicl2 #0,r9
832 cmpl r9,r2
833 bgequ noname.64
834 incl r8
835noname.64:
836
837 movzwl 2(r6),r2
838 bicl3 #-65536,8(r7),r3
839 movzwl 10(r7),r0
840 bicl2 #-65536,r0
841 bicl3 #-65536,(r6),-92(fp)
842 bicl3 #-65536,r2,-96(fp)
843 mull3 r0,-92(fp),-84(fp)
844 mull2 r3,-92(fp)
845 mull3 r3,-96(fp),-88(fp)
846 mull2 r0,-96(fp)
847 addl3 -84(fp),-88(fp),r0
848 bicl3 #0,r0,-84(fp)
849 cmpl -84(fp),-88(fp)
850 bgequ noname.65
851 addl2 #65536,-96(fp)
852noname.65:
853 movzwl -82(fp),r0
854 bicl2 #-65536,r0
855 addl2 r0,-96(fp)
856 bicl3 #-65536,-84(fp),r0
857 ashl #16,r0,-88(fp)
858 addl3 -88(fp),-92(fp),r0
859 bicl3 #0,r0,-92(fp)
860 cmpl -92(fp),-88(fp)
861 bgequ noname.66
862 incl -96(fp)
863noname.66:
864 movl -92(fp),r1
865 movl -96(fp),r2
866 addl2 r1,r10
867 bicl2 #0,r10
868 cmpl r10,r1
869 bgequ noname.67
870 incl r2
871noname.67:
872 addl2 r2,r9
873 bicl2 #0,r9
874 cmpl r9,r2
875 bgequ noname.68
876 incl r8
877noname.68:
878
879 movl r10,8(r11)
880
881 clrl r10
882
883 movzwl 2(r6),r2
884 bicl3 #-65536,12(r7),r3
885 movzwl 14(r7),r0
886 bicl2 #-65536,r0
887 bicl3 #-65536,(r6),-108(fp)
888 bicl3 #-65536,r2,-112(fp)
889 mull3 r0,-108(fp),-100(fp)
890 mull2 r3,-108(fp)
891 mull3 r3,-112(fp),-104(fp)
892 mull2 r0,-112(fp)
893 addl3 -100(fp),-104(fp),r0
894 bicl3 #0,r0,-100(fp)
895 cmpl -100(fp),-104(fp)
896 bgequ noname.69
897 addl2 #65536,-112(fp)
898noname.69:
899 movzwl -98(fp),r0
900 bicl2 #-65536,r0
901 addl2 r0,-112(fp)
902 bicl3 #-65536,-100(fp),r0
903 ashl #16,r0,-104(fp)
904 addl3 -104(fp),-108(fp),r0
905 bicl3 #0,r0,-108(fp)
906 cmpl -108(fp),-104(fp)
907 bgequ noname.70
908 incl -112(fp)
909noname.70:
910 movl -108(fp),r1
911 movl -112(fp),r2
912 addl2 r1,r9
913 bicl2 #0,r9
914 cmpl r9,r1
915 bgequ noname.71
916 incl r2
917noname.71:
918 addl2 r2,r8
919 bicl2 #0,r8
920 cmpl r8,r2
921 bgequ noname.72
922 incl r10
923noname.72:
924
925 movzwl 6(r6),r2
926 bicl3 #-65536,8(r7),r3
927 movzwl 10(r7),r0
928 bicl2 #-65536,r0
929 bicl3 #-65536,4(r6),-124(fp)
930 bicl3 #-65536,r2,-128(fp)
931 mull3 r0,-124(fp),-116(fp)
932 mull2 r3,-124(fp)
933 mull3 r3,-128(fp),-120(fp)
934 mull2 r0,-128(fp)
935 addl3 -116(fp),-120(fp),r0
936 bicl3 #0,r0,-116(fp)
937 cmpl -116(fp),-120(fp)
938 bgequ noname.73
939 addl2 #65536,-128(fp)
940noname.73:
941 movzwl -114(fp),r0
942 bicl2 #-65536,r0
943 addl2 r0,-128(fp)
944 bicl3 #-65536,-116(fp),r0
945 ashl #16,r0,-120(fp)
946 addl3 -120(fp),-124(fp),r0
947 bicl3 #0,r0,-124(fp)
948 cmpl -124(fp),-120(fp)
949 bgequ noname.74
950 incl -128(fp)
951noname.74:
952 movl -124(fp),r1
953 movl -128(fp),r2
954 addl2 r1,r9
955 bicl2 #0,r9
956 cmpl r9,r1
957 bgequ noname.75
958 incl r2
959noname.75:
960 addl2 r2,r8
961 bicl2 #0,r8
962 cmpl r8,r2
963 bgequ noname.76
964 incl r10
965noname.76:
966
967 movzwl 10(r6),r2
968 bicl3 #-65536,4(r7),r3
969 movzwl 6(r7),r0
970 bicl2 #-65536,r0
971 bicl3 #-65536,8(r6),-140(fp)
972 bicl3 #-65536,r2,-144(fp)
973 mull3 r0,-140(fp),-132(fp)
974 mull2 r3,-140(fp)
975 mull3 r3,-144(fp),-136(fp)
976 mull2 r0,-144(fp)
977 addl3 -132(fp),-136(fp),r0
978 bicl3 #0,r0,-132(fp)
979 cmpl -132(fp),-136(fp)
980 bgequ noname.77
981 addl2 #65536,-144(fp)
982noname.77:
983 movzwl -130(fp),r0
984 bicl2 #-65536,r0
985 addl2 r0,-144(fp)
986 bicl3 #-65536,-132(fp),r0
987 ashl #16,r0,-136(fp)
988 addl3 -136(fp),-140(fp),r0
989 bicl3 #0,r0,-140(fp)
990 cmpl -140(fp),-136(fp)
991 bgequ noname.78
992 incl -144(fp)
993noname.78:
994 movl -140(fp),r1
995 movl -144(fp),r2
996 addl2 r1,r9
997 bicl2 #0,r9
998 cmpl r9,r1
999 bgequ noname.79
1000 incl r2
1001noname.79:
1002 addl2 r2,r8
1003 bicl2 #0,r8
1004 cmpl r8,r2
1005 bgequ noname.80
1006 incl r10
1007noname.80:
1008
1009 movzwl 14(r6),r2
1010 bicl3 #-65536,(r7),r3
1011 movzwl 2(r7),r0
1012 bicl2 #-65536,r0
1013 bicl3 #-65536,12(r6),-156(fp)
1014 bicl3 #-65536,r2,-160(fp)
1015 mull3 r0,-156(fp),-148(fp)
1016 mull2 r3,-156(fp)
1017 mull3 r3,-160(fp),-152(fp)
1018 mull2 r0,-160(fp)
1019 addl3 -148(fp),-152(fp),r0
1020 bicl3 #0,r0,-148(fp)
1021 cmpl -148(fp),-152(fp)
1022 bgequ noname.81
1023 addl2 #65536,-160(fp)
1024noname.81:
1025 movzwl -146(fp),r0
1026 bicl2 #-65536,r0
1027 addl2 r0,-160(fp)
1028 bicl3 #-65536,-148(fp),r0
1029 ashl #16,r0,-152(fp)
1030 addl3 -152(fp),-156(fp),r0
1031 bicl3 #0,r0,-156(fp)
1032 cmpl -156(fp),-152(fp)
1033 bgequ noname.82
1034 incl -160(fp)
1035noname.82:
1036 movl -156(fp),r1
1037 movl -160(fp),r2
1038 addl2 r1,r9
1039 bicl2 #0,r9
1040 cmpl r9,r1
1041 bgequ noname.83
1042 incl r2
1043noname.83:
1044 addl2 r2,r8
1045 bicl2 #0,r8
1046 cmpl r8,r2
1047 bgequ noname.84
1048 incl r10
1049noname.84:
1050
1051 movl r9,12(r11)
1052
1053 clrl r9
1054
1055 movzwl 18(r6),r2
1056 bicl3 #-65536,(r7),r3
1057 movzwl 2(r7),r0
1058 bicl2 #-65536,r0
1059 bicl3 #-65536,16(r6),-172(fp)
1060 bicl3 #-65536,r2,-176(fp)
1061 mull3 r0,-172(fp),-164(fp)
1062 mull2 r3,-172(fp)
1063 mull3 r3,-176(fp),-168(fp)
1064 mull2 r0,-176(fp)
1065 addl3 -164(fp),-168(fp),r0
1066 bicl3 #0,r0,-164(fp)
1067 cmpl -164(fp),-168(fp)
1068 bgequ noname.85
1069 addl2 #65536,-176(fp)
1070noname.85:
1071 movzwl -162(fp),r0
1072 bicl2 #-65536,r0
1073 addl2 r0,-176(fp)
1074 bicl3 #-65536,-164(fp),r0
1075 ashl #16,r0,-168(fp)
1076 addl3 -168(fp),-172(fp),r0
1077 bicl3 #0,r0,-172(fp)
1078 cmpl -172(fp),-168(fp)
1079 bgequ noname.86
1080 incl -176(fp)
1081noname.86:
1082 movl -172(fp),r1
1083 movl -176(fp),r2
1084 addl2 r1,r8
1085 bicl2 #0,r8
1086 cmpl r8,r1
1087 bgequ noname.87
1088 incl r2
1089noname.87:
1090 addl2 r2,r10
1091 bicl2 #0,r10
1092 cmpl r10,r2
1093 bgequ noname.88
1094 incl r9
1095noname.88:
1096
1097 movzwl 14(r6),r2
1098 bicl3 #-65536,4(r7),r3
1099 movzwl 6(r7),r0
1100 bicl2 #-65536,r0
1101 bicl3 #-65536,12(r6),-188(fp)
1102 bicl3 #-65536,r2,-192(fp)
1103 mull3 r0,-188(fp),-180(fp)
1104 mull2 r3,-188(fp)
1105 mull3 r3,-192(fp),-184(fp)
1106 mull2 r0,-192(fp)
1107 addl3 -180(fp),-184(fp),r0
1108 bicl3 #0,r0,-180(fp)
1109 cmpl -180(fp),-184(fp)
1110 bgequ noname.89
1111 addl2 #65536,-192(fp)
1112noname.89:
1113 movzwl -178(fp),r0
1114 bicl2 #-65536,r0
1115 addl2 r0,-192(fp)
1116 bicl3 #-65536,-180(fp),r0
1117 ashl #16,r0,-184(fp)
1118 addl3 -184(fp),-188(fp),r0
1119 bicl3 #0,r0,-188(fp)
1120 cmpl -188(fp),-184(fp)
1121 bgequ noname.90
1122 incl -192(fp)
1123noname.90:
1124 movl -188(fp),r1
1125 movl -192(fp),r2
1126 addl2 r1,r8
1127 bicl2 #0,r8
1128 cmpl r8,r1
1129 bgequ noname.91
1130 incl r2
1131noname.91:
1132 addl2 r2,r10
1133 bicl2 #0,r10
1134 cmpl r10,r2
1135 bgequ noname.92
1136 incl r9
1137noname.92:
1138
1139 movzwl 10(r6),r2
1140 bicl3 #-65536,8(r7),r3
1141 movzwl 10(r7),r0
1142 bicl2 #-65536,r0
1143 bicl3 #-65536,8(r6),-204(fp)
1144 bicl3 #-65536,r2,-208(fp)
1145 mull3 r0,-204(fp),-196(fp)
1146 mull2 r3,-204(fp)
1147 mull3 r3,-208(fp),-200(fp)
1148 mull2 r0,-208(fp)
1149 addl3 -196(fp),-200(fp),r0
1150 bicl3 #0,r0,-196(fp)
1151 cmpl -196(fp),-200(fp)
1152 bgequ noname.93
1153 addl2 #65536,-208(fp)
1154noname.93:
1155 movzwl -194(fp),r0
1156 bicl2 #-65536,r0
1157 addl2 r0,-208(fp)
1158 bicl3 #-65536,-196(fp),r0
1159 ashl #16,r0,-200(fp)
1160 addl3 -200(fp),-204(fp),r0
1161 bicl3 #0,r0,-204(fp)
1162 cmpl -204(fp),-200(fp)
1163 bgequ noname.94
1164 incl -208(fp)
1165noname.94:
1166 movl -204(fp),r1
1167 movl -208(fp),r2
1168 addl2 r1,r8
1169 bicl2 #0,r8
1170 cmpl r8,r1
1171 bgequ noname.95
1172 incl r2
1173noname.95:
1174 addl2 r2,r10
1175 bicl2 #0,r10
1176 cmpl r10,r2
1177 bgequ noname.96
1178 incl r9
1179noname.96:
1180
1181 movzwl 6(r6),r2
1182 bicl3 #-65536,12(r7),r3
1183 movzwl 14(r7),r0
1184 bicl2 #-65536,r0
1185 bicl3 #-65536,4(r6),-220(fp)
1186 bicl3 #-65536,r2,-224(fp)
1187 mull3 r0,-220(fp),-212(fp)
1188 mull2 r3,-220(fp)
1189 mull3 r3,-224(fp),-216(fp)
1190 mull2 r0,-224(fp)
1191 addl3 -212(fp),-216(fp),r0
1192 bicl3 #0,r0,-212(fp)
1193 cmpl -212(fp),-216(fp)
1194 bgequ noname.97
1195 addl2 #65536,-224(fp)
1196noname.97:
1197 movzwl -210(fp),r0
1198 bicl2 #-65536,r0
1199 addl2 r0,-224(fp)
1200 bicl3 #-65536,-212(fp),r0
1201 ashl #16,r0,-216(fp)
1202 addl3 -216(fp),-220(fp),r0
1203 bicl3 #0,r0,-220(fp)
1204 cmpl -220(fp),-216(fp)
1205 bgequ noname.98
1206 incl -224(fp)
1207noname.98:
1208 movl -220(fp),r1
1209 movl -224(fp),r2
1210 addl2 r1,r8
1211 bicl2 #0,r8
1212 cmpl r8,r1
1213 bgequ noname.99
1214 incl r2
1215noname.99:
1216 addl2 r2,r10
1217 bicl2 #0,r10
1218 cmpl r10,r2
1219 bgequ noname.100
1220 incl r9
1221noname.100:
1222
1223 movzwl 2(r6),r2
1224 bicl3 #-65536,16(r7),r3
1225 movzwl 18(r7),r0
1226 bicl2 #-65536,r0
1227 bicl3 #-65536,(r6),-236(fp)
1228 bicl3 #-65536,r2,-240(fp)
1229 mull3 r0,-236(fp),-228(fp)
1230 mull2 r3,-236(fp)
1231 mull3 r3,-240(fp),-232(fp)
1232 mull2 r0,-240(fp)
1233 addl3 -228(fp),-232(fp),r0
1234 bicl3 #0,r0,-228(fp)
1235 cmpl -228(fp),-232(fp)
1236 bgequ noname.101
1237 addl2 #65536,-240(fp)
1238noname.101:
1239 movzwl -226(fp),r0
1240 bicl2 #-65536,r0
1241 addl2 r0,-240(fp)
1242 bicl3 #-65536,-228(fp),r0
1243 ashl #16,r0,-232(fp)
1244 addl3 -232(fp),-236(fp),r0
1245 bicl3 #0,r0,-236(fp)
1246 cmpl -236(fp),-232(fp)
1247 bgequ noname.102
1248 incl -240(fp)
1249noname.102:
1250 movl -236(fp),r1
1251 movl -240(fp),r2
1252 addl2 r1,r8
1253 bicl2 #0,r8
1254 cmpl r8,r1
1255 bgequ noname.103
1256 incl r2
1257noname.103:
1258 addl2 r2,r10
1259 bicl2 #0,r10
1260 cmpl r10,r2
1261 bgequ noname.104
1262 incl r9
1263noname.104:
1264
1265 movl r8,16(r11)
1266
1267 clrl r8
1268
1269 movzwl 2(r6),r2
1270 bicl3 #-65536,20(r7),r3
1271 movzwl 22(r7),r0
1272 bicl2 #-65536,r0
1273 bicl3 #-65536,(r6),-252(fp)
1274 bicl3 #-65536,r2,-256(fp)
1275 mull3 r0,-252(fp),-244(fp)
1276 mull2 r3,-252(fp)
1277 mull3 r3,-256(fp),-248(fp)
1278 mull2 r0,-256(fp)
1279 addl3 -244(fp),-248(fp),r0
1280 bicl3 #0,r0,-244(fp)
1281 cmpl -244(fp),-248(fp)
1282 bgequ noname.105
1283 addl2 #65536,-256(fp)
1284noname.105:
1285 movzwl -242(fp),r0
1286 bicl2 #-65536,r0
1287 addl2 r0,-256(fp)
1288 bicl3 #-65536,-244(fp),r0
1289 ashl #16,r0,-248(fp)
1290 addl3 -248(fp),-252(fp),r0
1291 bicl3 #0,r0,-252(fp)
1292 cmpl -252(fp),-248(fp)
1293 bgequ noname.106
1294 incl -256(fp)
1295noname.106:
1296 movl -252(fp),r1
1297 movl -256(fp),r2
1298 addl2 r1,r10
1299 bicl2 #0,r10
1300 cmpl r10,r1
1301 bgequ noname.107
1302 incl r2
1303noname.107:
1304 addl2 r2,r9
1305 bicl2 #0,r9
1306 cmpl r9,r2
1307 bgequ noname.108
1308 incl r8
1309noname.108:
1310
1311 movzwl 6(r6),r2
1312 bicl3 #-65536,16(r7),r3
1313 movzwl 18(r7),r0
1314 bicl2 #-65536,r0
1315 bicl3 #-65536,4(r6),-268(fp)
1316 bicl3 #-65536,r2,-272(fp)
1317 mull3 r0,-268(fp),-260(fp)
1318 mull2 r3,-268(fp)
1319 mull3 r3,-272(fp),-264(fp)
1320 mull2 r0,-272(fp)
1321 addl3 -260(fp),-264(fp),r0
1322 bicl3 #0,r0,-260(fp)
1323 cmpl -260(fp),-264(fp)
1324 bgequ noname.109
1325 addl2 #65536,-272(fp)
1326noname.109:
1327 movzwl -258(fp),r0
1328 bicl2 #-65536,r0
1329 addl2 r0,-272(fp)
1330 bicl3 #-65536,-260(fp),r0
1331 ashl #16,r0,-264(fp)
1332 addl3 -264(fp),-268(fp),r0
1333 bicl3 #0,r0,-268(fp)
1334 cmpl -268(fp),-264(fp)
1335 bgequ noname.110
1336 incl -272(fp)
1337noname.110:
1338 movl -268(fp),r1
1339 movl -272(fp),r2
1340 addl2 r1,r10
1341 bicl2 #0,r10
1342 cmpl r10,r1
1343 bgequ noname.111
1344 incl r2
1345noname.111:
1346 addl2 r2,r9
1347 bicl2 #0,r9
1348 cmpl r9,r2
1349 bgequ noname.112
1350 incl r8
1351noname.112:
1352
1353 movzwl 10(r6),r2
1354 bicl3 #-65536,12(r7),r3
1355 movzwl 14(r7),r0
1356 bicl2 #-65536,r0
1357 bicl3 #-65536,8(r6),-284(fp)
1358 bicl3 #-65536,r2,-288(fp)
1359 mull3 r0,-284(fp),-276(fp)
1360 mull2 r3,-284(fp)
1361 mull3 r3,-288(fp),-280(fp)
1362 mull2 r0,-288(fp)
1363 addl3 -276(fp),-280(fp),r0
1364 bicl3 #0,r0,-276(fp)
1365 cmpl -276(fp),-280(fp)
1366 bgequ noname.113
1367 addl2 #65536,-288(fp)
1368noname.113:
1369 movzwl -274(fp),r0
1370 bicl2 #-65536,r0
1371 addl2 r0,-288(fp)
1372 bicl3 #-65536,-276(fp),r0
1373 ashl #16,r0,-280(fp)
1374 addl3 -280(fp),-284(fp),r0
1375 bicl3 #0,r0,-284(fp)
1376 cmpl -284(fp),-280(fp)
1377 bgequ noname.114
1378 incl -288(fp)
1379noname.114:
1380 movl -284(fp),r1
1381 movl -288(fp),r2
1382 addl2 r1,r10
1383 bicl2 #0,r10
1384 cmpl r10,r1
1385 bgequ noname.115
1386 incl r2
1387noname.115:
1388 addl2 r2,r9
1389 bicl2 #0,r9
1390 cmpl r9,r2
1391 bgequ noname.116
1392 incl r8
1393noname.116:
1394
1395 movzwl 14(r6),r2
1396 bicl3 #-65536,8(r7),r3
1397 movzwl 10(r7),r0
1398 bicl2 #-65536,r0
1399 bicl3 #-65536,12(r6),-300(fp)
1400 bicl3 #-65536,r2,-304(fp)
1401 mull3 r0,-300(fp),-292(fp)
1402 mull2 r3,-300(fp)
1403 mull3 r3,-304(fp),-296(fp)
1404 mull2 r0,-304(fp)
1405 addl3 -292(fp),-296(fp),r0
1406 bicl3 #0,r0,-292(fp)
1407 cmpl -292(fp),-296(fp)
1408 bgequ noname.117
1409 addl2 #65536,-304(fp)
1410noname.117:
1411 movzwl -290(fp),r0
1412 bicl2 #-65536,r0
1413 addl2 r0,-304(fp)
1414 bicl3 #-65536,-292(fp),r0
1415 ashl #16,r0,-296(fp)
1416 addl3 -296(fp),-300(fp),r0
1417 bicl3 #0,r0,-300(fp)
1418 cmpl -300(fp),-296(fp)
1419 bgequ noname.118
1420 incl -304(fp)
1421noname.118:
1422 movl -300(fp),r1
1423 movl -304(fp),r2
1424 addl2 r1,r10
1425 bicl2 #0,r10
1426 cmpl r10,r1
1427 bgequ noname.119
1428 incl r2
1429noname.119:
1430 addl2 r2,r9
1431 bicl2 #0,r9
1432 cmpl r9,r2
1433 bgequ noname.120
1434 incl r8
1435noname.120:
1436
1437 movzwl 18(r6),r2
1438 bicl3 #-65536,4(r7),r3
1439 movzwl 6(r7),r0
1440 bicl2 #-65536,r0
1441 bicl3 #-65536,16(r6),-316(fp)
1442 bicl3 #-65536,r2,-320(fp)
1443 mull3 r0,-316(fp),-308(fp)
1444 mull2 r3,-316(fp)
1445 mull3 r3,-320(fp),-312(fp)
1446 mull2 r0,-320(fp)
1447 addl3 -308(fp),-312(fp),r0
1448 bicl3 #0,r0,-308(fp)
1449 cmpl -308(fp),-312(fp)
1450 bgequ noname.121
1451 addl2 #65536,-320(fp)
1452noname.121:
1453 movzwl -306(fp),r0
1454 bicl2 #-65536,r0
1455 addl2 r0,-320(fp)
1456 bicl3 #-65536,-308(fp),r0
1457 ashl #16,r0,-312(fp)
1458 addl3 -312(fp),-316(fp),r0
1459 bicl3 #0,r0,-316(fp)
1460 cmpl -316(fp),-312(fp)
1461 bgequ noname.122
1462 incl -320(fp)
1463noname.122:
1464 movl -316(fp),r1
1465 movl -320(fp),r2
1466 addl2 r1,r10
1467 bicl2 #0,r10
1468 cmpl r10,r1
1469 bgequ noname.123
1470 incl r2
1471
1472noname.123:
1473 addl2 r2,r9
1474 bicl2 #0,r9
1475 cmpl r9,r2
1476 bgequ noname.124
1477 incl r8
1478noname.124:
1479
1480 movzwl 22(r6),r2
1481 bicl3 #-65536,(r7),r3
1482 movzwl 2(r7),r0
1483 bicl2 #-65536,r0
1484 bicl3 #-65536,20(r6),-332(fp)
1485 bicl3 #-65536,r2,-336(fp)
1486 mull3 r0,-332(fp),-324(fp)
1487 mull2 r3,-332(fp)
1488 mull3 r3,-336(fp),-328(fp)
1489 mull2 r0,-336(fp)
1490 addl3 -324(fp),-328(fp),r0
1491 bicl3 #0,r0,-324(fp)
1492 cmpl -324(fp),-328(fp)
1493 bgequ noname.125
1494 addl2 #65536,-336(fp)
1495noname.125:
1496 movzwl -322(fp),r0
1497 bicl2 #-65536,r0
1498 addl2 r0,-336(fp)
1499 bicl3 #-65536,-324(fp),r0
1500 ashl #16,r0,-328(fp)
1501 addl3 -328(fp),-332(fp),r0
1502 bicl3 #0,r0,-332(fp)
1503 cmpl -332(fp),-328(fp)
1504 bgequ noname.126
1505 incl -336(fp)
1506noname.126:
1507 movl -332(fp),r1
1508 movl -336(fp),r2
1509 addl2 r1,r10
1510 bicl2 #0,r10
1511 cmpl r10,r1
1512 bgequ noname.127
1513 incl r2
1514noname.127:
1515 addl2 r2,r9
1516 bicl2 #0,r9
1517 cmpl r9,r2
1518 bgequ noname.128
1519 incl r8
1520noname.128:
1521
1522 movl r10,20(r11)
1523
1524 clrl r10
1525
1526 movzwl 26(r6),r2
1527 bicl3 #-65536,(r7),r3
1528 movzwl 2(r7),r0
1529 bicl2 #-65536,r0
1530 bicl3 #-65536,24(r6),-348(fp)
1531 bicl3 #-65536,r2,-352(fp)
1532 mull3 r0,-348(fp),-340(fp)
1533 mull2 r3,-348(fp)
1534 mull3 r3,-352(fp),-344(fp)
1535 mull2 r0,-352(fp)
1536 addl3 -340(fp),-344(fp),r0
1537 bicl3 #0,r0,-340(fp)
1538 cmpl -340(fp),-344(fp)
1539 bgequ noname.129
1540 addl2 #65536,-352(fp)
1541noname.129:
1542 movzwl -338(fp),r0
1543 bicl2 #-65536,r0
1544 addl2 r0,-352(fp)
1545 bicl3 #-65536,-340(fp),r0
1546 ashl #16,r0,-344(fp)
1547 addl3 -344(fp),-348(fp),r0
1548 bicl3 #0,r0,-348(fp)
1549 cmpl -348(fp),-344(fp)
1550 bgequ noname.130
1551 incl -352(fp)
1552noname.130:
1553 movl -348(fp),r1
1554 movl -352(fp),r2
1555 addl2 r1,r9
1556 bicl2 #0,r9
1557 cmpl r9,r1
1558 bgequ noname.131
1559 incl r2
1560noname.131:
1561 addl2 r2,r8
1562 bicl2 #0,r8
1563 cmpl r8,r2
1564 bgequ noname.132
1565 incl r10
1566noname.132:
1567
1568 movzwl 22(r6),r2
1569 bicl3 #-65536,4(r7),r3
1570 movzwl 6(r7),r0
1571 bicl2 #-65536,r0
1572 bicl3 #-65536,20(r6),-364(fp)
1573 bicl3 #-65536,r2,-368(fp)
1574 mull3 r0,-364(fp),-356(fp)
1575 mull2 r3,-364(fp)
1576 mull3 r3,-368(fp),-360(fp)
1577 mull2 r0,-368(fp)
1578 addl3 -356(fp),-360(fp),r0
1579 bicl3 #0,r0,-356(fp)
1580 cmpl -356(fp),-360(fp)
1581 bgequ noname.133
1582 addl2 #65536,-368(fp)
1583noname.133:
1584 movzwl -354(fp),r0
1585 bicl2 #-65536,r0
1586 addl2 r0,-368(fp)
1587 bicl3 #-65536,-356(fp),r0
1588 ashl #16,r0,-360(fp)
1589 addl3 -360(fp),-364(fp),r0
1590 bicl3 #0,r0,-364(fp)
1591 cmpl -364(fp),-360(fp)
1592 bgequ noname.134
1593 incl -368(fp)
1594noname.134:
1595 movl -364(fp),r1
1596 movl -368(fp),r2
1597 addl2 r1,r9
1598 bicl2 #0,r9
1599 cmpl r9,r1
1600 bgequ noname.135
1601 incl r2
1602noname.135:
1603 addl2 r2,r8
1604 bicl2 #0,r8
1605 cmpl r8,r2
1606 bgequ noname.136
1607 incl r10
1608noname.136:
1609
1610 movzwl 18(r6),r2
1611 bicl3 #-65536,8(r7),r3
1612 movzwl 10(r7),r0
1613 bicl2 #-65536,r0
1614 bicl3 #-65536,16(r6),-380(fp)
1615 bicl3 #-65536,r2,-384(fp)
1616 mull3 r0,-380(fp),-372(fp)
1617 mull2 r3,-380(fp)
1618 mull3 r3,-384(fp),-376(fp)
1619 mull2 r0,-384(fp)
1620 addl3 -372(fp),-376(fp),r0
1621 bicl3 #0,r0,-372(fp)
1622 cmpl -372(fp),-376(fp)
1623 bgequ noname.137
1624 addl2 #65536,-384(fp)
1625noname.137:
1626 movzwl -370(fp),r0
1627 bicl2 #-65536,r0
1628 addl2 r0,-384(fp)
1629 bicl3 #-65536,-372(fp),r0
1630 ashl #16,r0,-376(fp)
1631 addl3 -376(fp),-380(fp),r0
1632 bicl3 #0,r0,-380(fp)
1633 cmpl -380(fp),-376(fp)
1634 bgequ noname.138
1635 incl -384(fp)
1636noname.138:
1637 movl -380(fp),r1
1638 movl -384(fp),r2
1639 addl2 r1,r9
1640 bicl2 #0,r9
1641 cmpl r9,r1
1642 bgequ noname.139
1643 incl r2
1644noname.139:
1645 addl2 r2,r8
1646 bicl2 #0,r8
1647 cmpl r8,r2
1648 bgequ noname.140
1649 incl r10
1650noname.140:
1651
1652 movzwl 14(r6),r2
1653 bicl3 #-65536,12(r7),r3
1654 movzwl 14(r7),r0
1655 bicl2 #-65536,r0
1656 bicl3 #-65536,12(r6),-396(fp)
1657 bicl3 #-65536,r2,-400(fp)
1658 mull3 r0,-396(fp),-388(fp)
1659 mull2 r3,-396(fp)
1660 mull3 r3,-400(fp),-392(fp)
1661 mull2 r0,-400(fp)
1662 addl3 -388(fp),-392(fp),r0
1663 bicl3 #0,r0,-388(fp)
1664 cmpl -388(fp),-392(fp)
1665 bgequ noname.141
1666 addl2 #65536,-400(fp)
1667noname.141:
1668 movzwl -386(fp),r0
1669 bicl2 #-65536,r0
1670 addl2 r0,-400(fp)
1671 bicl3 #-65536,-388(fp),r0
1672 ashl #16,r0,-392(fp)
1673 addl3 -392(fp),-396(fp),r0
1674 bicl3 #0,r0,-396(fp)
1675 cmpl -396(fp),-392(fp)
1676 bgequ noname.142
1677 incl -400(fp)
1678noname.142:
1679 movl -396(fp),r1
1680 movl -400(fp),r2
1681 addl2 r1,r9
1682 bicl2 #0,r9
1683 cmpl r9,r1
1684 bgequ noname.143
1685 incl r2
1686noname.143:
1687 addl2 r2,r8
1688 bicl2 #0,r8
1689 cmpl r8,r2
1690 bgequ noname.144
1691 incl r10
1692noname.144:
1693
1694 movzwl 10(r6),r2
1695 bicl3 #-65536,16(r7),r3
1696 movzwl 18(r7),r0
1697 bicl2 #-65536,r0
1698 bicl3 #-65536,8(r6),-412(fp)
1699 bicl3 #-65536,r2,-416(fp)
1700 mull3 r0,-412(fp),-404(fp)
1701 mull2 r3,-412(fp)
1702 mull3 r3,-416(fp),-408(fp)
1703 mull2 r0,-416(fp)
1704 addl3 -404(fp),-408(fp),r0
1705 bicl3 #0,r0,-404(fp)
1706 cmpl -404(fp),-408(fp)
1707 bgequ noname.145
1708 addl2 #65536,-416(fp)
1709noname.145:
1710 movzwl -402(fp),r0
1711 bicl2 #-65536,r0
1712 addl2 r0,-416(fp)
1713 bicl3 #-65536,-404(fp),r0
1714 ashl #16,r0,-408(fp)
1715 addl3 -408(fp),-412(fp),r0
1716 bicl3 #0,r0,-412(fp)
1717 cmpl -412(fp),-408(fp)
1718 bgequ noname.146
1719 incl -416(fp)
1720noname.146:
1721 movl -412(fp),r1
1722 movl -416(fp),r2
1723 addl2 r1,r9
1724 bicl2 #0,r9
1725 cmpl r9,r1
1726 bgequ noname.147
1727 incl r2
1728noname.147:
1729 addl2 r2,r8
1730 bicl2 #0,r8
1731 cmpl r8,r2
1732 bgequ noname.148
1733 incl r10
1734noname.148:
1735
1736 movzwl 6(r6),r2
1737 bicl3 #-65536,20(r7),r3
1738 movzwl 22(r7),r0
1739 bicl2 #-65536,r0
1740 bicl3 #-65536,4(r6),-428(fp)
1741 bicl3 #-65536,r2,-432(fp)
1742 mull3 r0,-428(fp),-420(fp)
1743 mull2 r3,-428(fp)
1744 mull3 r3,-432(fp),-424(fp)
1745 mull2 r0,-432(fp)
1746 addl3 -420(fp),-424(fp),r0
1747 bicl3 #0,r0,-420(fp)
1748 cmpl -420(fp),-424(fp)
1749 bgequ noname.149
1750 addl2 #65536,-432(fp)
1751noname.149:
1752 movzwl -418(fp),r0
1753 bicl2 #-65536,r0
1754 addl2 r0,-432(fp)
1755 bicl3 #-65536,-420(fp),r0
1756 ashl #16,r0,-424(fp)
1757 addl3 -424(fp),-428(fp),r0
1758 bicl3 #0,r0,-428(fp)
1759 cmpl -428(fp),-424(fp)
1760 bgequ noname.150
1761 incl -432(fp)
1762noname.150:
1763 movl -428(fp),r1
1764 movl -432(fp),r2
1765 addl2 r1,r9
1766 bicl2 #0,r9
1767 cmpl r9,r1
1768 bgequ noname.151
1769 incl r2
1770noname.151:
1771 addl2 r2,r8
1772 bicl2 #0,r8
1773 cmpl r8,r2
1774 bgequ noname.152
1775 incl r10
1776noname.152:
1777
1778 movzwl 2(r6),r2
1779 bicl3 #-65536,24(r7),r3
1780 movzwl 26(r7),r0
1781 bicl2 #-65536,r0
1782 bicl3 #-65536,(r6),-444(fp)
1783 bicl3 #-65536,r2,-448(fp)
1784 mull3 r0,-444(fp),-436(fp)
1785 mull2 r3,-444(fp)
1786 mull3 r3,-448(fp),-440(fp)
1787 mull2 r0,-448(fp)
1788 addl3 -436(fp),-440(fp),r0
1789 bicl3 #0,r0,-436(fp)
1790 cmpl -436(fp),-440(fp)
1791 bgequ noname.153
1792 addl2 #65536,-448(fp)
1793noname.153:
1794 movzwl -434(fp),r0
1795 bicl2 #-65536,r0
1796 addl2 r0,-448(fp)
1797 bicl3 #-65536,-436(fp),r0
1798 ashl #16,r0,-440(fp)
1799 addl3 -440(fp),-444(fp),r0
1800 bicl3 #0,r0,-444(fp)
1801 cmpl -444(fp),-440(fp)
1802 bgequ noname.154
1803 incl -448(fp)
1804noname.154:
1805 movl -444(fp),r1
1806 movl -448(fp),r2
1807 addl2 r1,r9
1808 bicl2 #0,r9
1809 cmpl r9,r1
1810 bgequ noname.155
1811 incl r2
1812noname.155:
1813 addl2 r2,r8
1814 bicl2 #0,r8
1815 cmpl r8,r2
1816 bgequ noname.156
1817 incl r10
1818noname.156:
1819
1820 movl r9,24(r11)
1821
1822 clrl r9
1823
1824 movzwl 2(r6),r2
1825 bicl3 #-65536,28(r7),r3
1826 movzwl 30(r7),r0
1827 bicl2 #-65536,r0
1828 bicl3 #-65536,(r6),-460(fp)
1829 bicl3 #-65536,r2,-464(fp)
1830 mull3 r0,-460(fp),-452(fp)
1831 mull2 r3,-460(fp)
1832 mull3 r3,-464(fp),-456(fp)
1833 mull2 r0,-464(fp)
1834 addl3 -452(fp),-456(fp),r0
1835 bicl3 #0,r0,-452(fp)
1836 cmpl -452(fp),-456(fp)
1837 bgequ noname.157
1838 addl2 #65536,-464(fp)
1839noname.157:
1840 movzwl -450(fp),r0
1841 bicl2 #-65536,r0
1842 addl2 r0,-464(fp)
1843 bicl3 #-65536,-452(fp),r0
1844 ashl #16,r0,-456(fp)
1845 addl3 -456(fp),-460(fp),r0
1846 bicl3 #0,r0,-460(fp)
1847 cmpl -460(fp),-456(fp)
1848 bgequ noname.158
1849 incl -464(fp)
1850noname.158:
1851 movl -460(fp),r1
1852 movl -464(fp),r2
1853 addl2 r1,r8
1854 bicl2 #0,r8
1855 cmpl r8,r1
1856 bgequ noname.159
1857 incl r2
1858noname.159:
1859 addl2 r2,r10
1860 bicl2 #0,r10
1861 cmpl r10,r2
1862 bgequ noname.160
1863 incl r9
1864noname.160:
1865
1866 movzwl 6(r6),r2
1867 bicl3 #-65536,24(r7),r3
1868 movzwl 26(r7),r0
1869 bicl2 #-65536,r0
1870 bicl3 #-65536,4(r6),-476(fp)
1871 bicl3 #-65536,r2,-480(fp)
1872 mull3 r0,-476(fp),-468(fp)
1873 mull2 r3,-476(fp)
1874 mull3 r3,-480(fp),-472(fp)
1875 mull2 r0,-480(fp)
1876 addl3 -468(fp),-472(fp),r0
1877 bicl3 #0,r0,-468(fp)
1878 cmpl -468(fp),-472(fp)
1879 bgequ noname.161
1880 addl2 #65536,-480(fp)
1881noname.161:
1882 movzwl -466(fp),r0
1883 bicl2 #-65536,r0
1884 addl2 r0,-480(fp)
1885 bicl3 #-65536,-468(fp),r0
1886 ashl #16,r0,-472(fp)
1887 addl3 -472(fp),-476(fp),r0
1888 bicl3 #0,r0,-476(fp)
1889 cmpl -476(fp),-472(fp)
1890 bgequ noname.162
1891 incl -480(fp)
1892noname.162:
1893 movl -476(fp),r1
1894 movl -480(fp),r2
1895 addl2 r1,r8
1896 bicl2 #0,r8
1897 cmpl r8,r1
1898 bgequ noname.163
1899 incl r2
1900noname.163:
1901 addl2 r2,r10
1902 bicl2 #0,r10
1903 cmpl r10,r2
1904 bgequ noname.164
1905 incl r9
1906noname.164:
1907
1908 movzwl 10(r6),r2
1909 bicl3 #-65536,20(r7),r3
1910 movzwl 22(r7),r0
1911 bicl2 #-65536,r0
1912 bicl3 #-65536,8(r6),-492(fp)
1913 bicl3 #-65536,r2,-496(fp)
1914 mull3 r0,-492(fp),-484(fp)
1915 mull2 r3,-492(fp)
1916 mull3 r3,-496(fp),-488(fp)
1917 mull2 r0,-496(fp)
1918 addl3 -484(fp),-488(fp),r0
1919 bicl3 #0,r0,-484(fp)
1920 cmpl -484(fp),-488(fp)
1921 bgequ noname.165
1922 addl2 #65536,-496(fp)
1923noname.165:
1924 movzwl -482(fp),r0
1925 bicl2 #-65536,r0
1926 addl2 r0,-496(fp)
1927 bicl3 #-65536,-484(fp),r0
1928 ashl #16,r0,-488(fp)
1929 addl3 -488(fp),-492(fp),r0
1930 bicl3 #0,r0,-492(fp)
1931 cmpl -492(fp),-488(fp)
1932 bgequ noname.166
1933 incl -496(fp)
1934noname.166:
1935 movl -492(fp),r1
1936 movl -496(fp),r2
1937 addl2 r1,r8
1938 bicl2 #0,r8
1939 cmpl r8,r1
1940 bgequ noname.167
1941 incl r2
1942noname.167:
1943 addl2 r2,r10
1944 bicl2 #0,r10
1945 cmpl r10,r2
1946 bgequ noname.168
1947 incl r9
1948noname.168:
1949
1950 movzwl 14(r6),r2
1951 bicl3 #-65536,16(r7),r3
1952 movzwl 18(r7),r0
1953 bicl2 #-65536,r0
1954 bicl3 #-65536,12(r6),-508(fp)
1955 bicl3 #-65536,r2,-512(fp)
1956 mull3 r0,-508(fp),-500(fp)
1957 mull2 r3,-508(fp)
1958 mull3 r3,-512(fp),-504(fp)
1959 mull2 r0,-512(fp)
1960 addl3 -500(fp),-504(fp),r0
1961 bicl3 #0,r0,-500(fp)
1962 cmpl -500(fp),-504(fp)
1963 bgequ noname.169
1964 addl2 #65536,-512(fp)
1965noname.169:
1966 movzwl -498(fp),r0
1967 bicl2 #-65536,r0
1968 addl2 r0,-512(fp)
1969 bicl3 #-65536,-500(fp),r0
1970 ashl #16,r0,-504(fp)
1971 addl3 -504(fp),-508(fp),r0
1972 bicl3 #0,r0,-508(fp)
1973 cmpl -508(fp),-504(fp)
1974 bgequ noname.170
1975 incl -512(fp)
1976noname.170:
1977 movl -508(fp),r1
1978 movl -512(fp),r2
1979 addl2 r1,r8
1980 bicl2 #0,r8
1981 cmpl r8,r1
1982 bgequ noname.171
1983 incl r2
1984noname.171:
1985 addl2 r2,r10
1986 bicl2 #0,r10
1987 cmpl r10,r2
1988 bgequ noname.172
1989 incl r9
1990noname.172:
1991
1992 movzwl 18(r6),r2
1993 bicl3 #-65536,12(r7),r3
1994 movzwl 14(r7),r0
1995 bicl2 #-65536,r0
1996 bicl3 #-65536,16(r6),-524(fp)
1997 bicl3 #-65536,r2,-528(fp)
1998 mull3 r0,-524(fp),-516(fp)
1999 mull2 r3,-524(fp)
2000 mull3 r3,-528(fp),-520(fp)
2001 mull2 r0,-528(fp)
2002 addl3 -516(fp),-520(fp),r0
2003 bicl3 #0,r0,-516(fp)
2004 cmpl -516(fp),-520(fp)
2005 bgequ noname.173
2006 addl2 #65536,-528(fp)
2007noname.173:
2008 movzwl -514(fp),r0
2009 bicl2 #-65536,r0
2010 addl2 r0,-528(fp)
2011 bicl3 #-65536,-516(fp),r0
2012 ashl #16,r0,-520(fp)
2013 addl3 -520(fp),-524(fp),r0
2014 bicl3 #0,r0,-524(fp)
2015 cmpl -524(fp),-520(fp)
2016 bgequ noname.174
2017 incl -528(fp)
2018noname.174:
2019 movl -524(fp),r1
2020 movl -528(fp),r2
2021 addl2 r1,r8
2022 bicl2 #0,r8
2023 cmpl r8,r1
2024 bgequ noname.175
2025 incl r2
2026noname.175:
2027 addl2 r2,r10
2028 bicl2 #0,r10
2029 cmpl r10,r2
2030 bgequ noname.176
2031 incl r9
2032noname.176:
2033
2034 movzwl 22(r6),r2
2035 bicl3 #-65536,8(r7),r3
2036 movzwl 10(r7),r0
2037 bicl2 #-65536,r0
2038 bicl3 #-65536,20(r6),-540(fp)
2039 bicl3 #-65536,r2,-544(fp)
2040 mull3 r0,-540(fp),-532(fp)
2041 mull2 r3,-540(fp)
2042 mull3 r3,-544(fp),-536(fp)
2043 mull2 r0,-544(fp)
2044 addl3 -532(fp),-536(fp),r0
2045 bicl3 #0,r0,-532(fp)
2046 cmpl -532(fp),-536(fp)
2047 bgequ noname.177
2048 addl2 #65536,-544(fp)
2049noname.177:
2050 movzwl -530(fp),r0
2051 bicl2 #-65536,r0
2052 addl2 r0,-544(fp)
2053 bicl3 #-65536,-532(fp),r0
2054 ashl #16,r0,-536(fp)
2055 addl3 -536(fp),-540(fp),r0
2056 bicl3 #0,r0,-540(fp)
2057 cmpl -540(fp),-536(fp)
2058 bgequ noname.178
2059 incl -544(fp)
2060noname.178:
2061 movl -540(fp),r1
2062 movl -544(fp),r2
2063 addl2 r1,r8
2064 bicl2 #0,r8
2065 cmpl r8,r1
2066 bgequ noname.179
2067 incl r2
2068noname.179:
2069 addl2 r2,r10
2070 bicl2 #0,r10
2071 cmpl r10,r2
2072 bgequ noname.180
2073 incl r9
2074noname.180:
2075
2076 movzwl 26(r6),r2
2077 bicl3 #-65536,4(r7),r3
2078 movzwl 6(r7),r0
2079 bicl2 #-65536,r0
2080 bicl3 #-65536,24(r6),-556(fp)
2081 bicl3 #-65536,r2,-560(fp)
2082 mull3 r0,-556(fp),-548(fp)
2083 mull2 r3,-556(fp)
2084 mull3 r3,-560(fp),-552(fp)
2085 mull2 r0,-560(fp)
2086 addl3 -548(fp),-552(fp),r0
2087 bicl3 #0,r0,-548(fp)
2088 cmpl -548(fp),-552(fp)
2089 bgequ noname.181
2090 addl2 #65536,-560(fp)
2091noname.181:
2092 movzwl -546(fp),r0
2093 bicl2 #-65536,r0
2094 addl2 r0,-560(fp)
2095 bicl3 #-65536,-548(fp),r0
2096 ashl #16,r0,-552(fp)
2097 addl3 -552(fp),-556(fp),r0
2098 bicl3 #0,r0,-556(fp)
2099 cmpl -556(fp),-552(fp)
2100 bgequ noname.182
2101 incl -560(fp)
2102noname.182:
2103 movl -556(fp),r1
2104 movl -560(fp),r2
2105 addl2 r1,r8
2106 bicl2 #0,r8
2107 cmpl r8,r1
2108 bgequ noname.183
2109 incl r2
2110noname.183:
2111 addl2 r2,r10
2112 bicl2 #0,r10
2113 cmpl r10,r2
2114 bgequ noname.184
2115 incl r9
2116noname.184:
2117
2118 movzwl 30(r6),r2
2119 bicl3 #-65536,(r7),r3
2120 movzwl 2(r7),r0
2121 bicl2 #-65536,r0
2122 bicl3 #-65536,28(r6),-572(fp)
2123 bicl3 #-65536,r2,-576(fp)
2124 mull3 r0,-572(fp),-564(fp)
2125 mull2 r3,-572(fp)
2126 mull3 r3,-576(fp),-568(fp)
2127 mull2 r0,-576(fp)
2128 addl3 -564(fp),-568(fp),r0
2129 bicl3 #0,r0,-564(fp)
2130 cmpl -564(fp),-568(fp)
2131 bgequ noname.185
2132 addl2 #65536,-576(fp)
2133noname.185:
2134 movzwl -562(fp),r0
2135 bicl2 #-65536,r0
2136 addl2 r0,-576(fp)
2137 bicl3 #-65536,-564(fp),r0
2138 ashl #16,r0,-568(fp)
2139 addl3 -568(fp),-572(fp),r0
2140 bicl3 #0,r0,-572(fp)
2141 cmpl -572(fp),-568(fp)
2142 bgequ noname.186
2143 incl -576(fp)
2144noname.186:
2145 movl -572(fp),r1
2146 movl -576(fp),r2
2147 addl2 r1,r8
2148 bicl2 #0,r8
2149 cmpl r8,r1
2150 bgequ noname.187
2151 incl r2
2152noname.187:
2153 addl2 r2,r10
2154 bicl2 #0,r10
2155 cmpl r10,r2
2156 bgequ noname.188
2157 incl r9
2158noname.188:
2159
2160 movl r8,28(r11)
2161
2162 clrl r8
2163
2164 movzwl 30(r6),r2
2165 bicl3 #-65536,4(r7),r3
2166 movzwl 6(r7),r0
2167 bicl2 #-65536,r0
2168 bicl3 #-65536,28(r6),-588(fp)
2169 bicl3 #-65536,r2,-592(fp)
2170 mull3 r0,-588(fp),-580(fp)
2171 mull2 r3,-588(fp)
2172 mull3 r3,-592(fp),-584(fp)
2173 mull2 r0,-592(fp)
2174 addl3 -580(fp),-584(fp),r0
2175 bicl3 #0,r0,-580(fp)
2176 cmpl -580(fp),-584(fp)
2177 bgequ noname.189
2178 addl2 #65536,-592(fp)
2179noname.189:
2180 movzwl -578(fp),r0
2181 bicl2 #-65536,r0
2182 addl2 r0,-592(fp)
2183 bicl3 #-65536,-580(fp),r0
2184 ashl #16,r0,-584(fp)
2185 addl3 -584(fp),-588(fp),r0
2186 bicl3 #0,r0,-588(fp)
2187 cmpl -588(fp),-584(fp)
2188 bgequ noname.190
2189 incl -592(fp)
2190noname.190:
2191 movl -588(fp),r1
2192 movl -592(fp),r2
2193 addl2 r1,r10
2194 bicl2 #0,r10
2195 cmpl r10,r1
2196 bgequ noname.191
2197 incl r2
2198noname.191:
2199 addl2 r2,r9
2200 bicl2 #0,r9
2201 cmpl r9,r2
2202 bgequ noname.192
2203 incl r8
2204noname.192:
2205
2206 movzwl 26(r6),r2
2207 bicl3 #-65536,8(r7),r3
2208 movzwl 10(r7),r0
2209 bicl2 #-65536,r0
2210 bicl3 #-65536,24(r6),-604(fp)
2211 bicl3 #-65536,r2,-608(fp)
2212 mull3 r0,-604(fp),-596(fp)
2213 mull2 r3,-604(fp)
2214 mull3 r3,-608(fp),-600(fp)
2215 mull2 r0,-608(fp)
2216 addl3 -596(fp),-600(fp),r0
2217 bicl3 #0,r0,-596(fp)
2218 cmpl -596(fp),-600(fp)
2219 bgequ noname.193
2220 addl2 #65536,-608(fp)
2221noname.193:
2222 movzwl -594(fp),r0
2223 bicl2 #-65536,r0
2224 addl2 r0,-608(fp)
2225 bicl3 #-65536,-596(fp),r0
2226 ashl #16,r0,-600(fp)
2227 addl3 -600(fp),-604(fp),r0
2228 bicl3 #0,r0,-604(fp)
2229 cmpl -604(fp),-600(fp)
2230 bgequ noname.194
2231 incl -608(fp)
2232noname.194:
2233 movl -604(fp),r1
2234 movl -608(fp),r2
2235 addl2 r1,r10
2236 bicl2 #0,r10
2237 cmpl r10,r1
2238 bgequ noname.195
2239 incl r2
2240noname.195:
2241 addl2 r2,r9
2242 bicl2 #0,r9
2243 cmpl r9,r2
2244 bgequ noname.196
2245 incl r8
2246noname.196:
2247
2248 movzwl 22(r6),r2
2249 bicl3 #-65536,12(r7),r3
2250 movzwl 14(r7),r0
2251 bicl2 #-65536,r0
2252 bicl3 #-65536,20(r6),-620(fp)
2253 bicl3 #-65536,r2,-624(fp)
2254 mull3 r0,-620(fp),-612(fp)
2255 mull2 r3,-620(fp)
2256 mull3 r3,-624(fp),-616(fp)
2257 mull2 r0,-624(fp)
2258 addl3 -612(fp),-616(fp),r0
2259 bicl3 #0,r0,-612(fp)
2260 cmpl -612(fp),-616(fp)
2261 bgequ noname.197
2262 addl2 #65536,-624(fp)
2263noname.197:
2264 movzwl -610(fp),r0
2265 bicl2 #-65536,r0
2266 addl2 r0,-624(fp)
2267 bicl3 #-65536,-612(fp),r0
2268 ashl #16,r0,-616(fp)
2269 addl3 -616(fp),-620(fp),r0
2270 bicl3 #0,r0,-620(fp)
2271 cmpl -620(fp),-616(fp)
2272 bgequ noname.198
2273 incl -624(fp)
2274noname.198:
2275 movl -620(fp),r1
2276 movl -624(fp),r2
2277 addl2 r1,r10
2278 bicl2 #0,r10
2279 cmpl r10,r1
2280 bgequ noname.199
2281 incl r2
2282noname.199:
2283 addl2 r2,r9
2284 bicl2 #0,r9
2285 cmpl r9,r2
2286 bgequ noname.200
2287 incl r8
2288noname.200:
2289
2290 movzwl 18(r6),r2
2291 bicl3 #-65536,16(r7),r3
2292 movzwl 18(r7),r0
2293 bicl2 #-65536,r0
2294 bicl3 #-65536,16(r6),-636(fp)
2295 bicl3 #-65536,r2,-640(fp)
2296 mull3 r0,-636(fp),-628(fp)
2297 mull2 r3,-636(fp)
2298 mull3 r3,-640(fp),-632(fp)
2299 mull2 r0,-640(fp)
2300 addl3 -628(fp),-632(fp),r0
2301 bicl3 #0,r0,-628(fp)
2302 cmpl -628(fp),-632(fp)
2303 bgequ noname.201
2304 addl2 #65536,-640(fp)
2305noname.201:
2306 movzwl -626(fp),r0
2307 bicl2 #-65536,r0
2308 addl2 r0,-640(fp)
2309 bicl3 #-65536,-628(fp),r0
2310 ashl #16,r0,-632(fp)
2311 addl3 -632(fp),-636(fp),r0
2312 bicl3 #0,r0,-636(fp)
2313 cmpl -636(fp),-632(fp)
2314 bgequ noname.202
2315 incl -640(fp)
2316noname.202:
2317 movl -636(fp),r1
2318 movl -640(fp),r2
2319 addl2 r1,r10
2320 bicl2 #0,r10
2321 cmpl r10,r1
2322 bgequ noname.203
2323 incl r2
2324noname.203:
2325 addl2 r2,r9
2326 bicl2 #0,r9
2327 cmpl r9,r2
2328 bgequ noname.204
2329 incl r8
2330noname.204:
2331
2332 movzwl 14(r6),r2
2333 bicl3 #-65536,20(r7),r3
2334 movzwl 22(r7),r0
2335 bicl2 #-65536,r0
2336 bicl3 #-65536,12(r6),-652(fp)
2337 bicl3 #-65536,r2,-656(fp)
2338 mull3 r0,-652(fp),-644(fp)
2339 mull2 r3,-652(fp)
2340 mull3 r3,-656(fp),-648(fp)
2341 mull2 r0,-656(fp)
2342 addl3 -644(fp),-648(fp),r0
2343 bicl3 #0,r0,-644(fp)
2344 cmpl -644(fp),-648(fp)
2345 bgequ noname.205
2346 addl2 #65536,-656(fp)
2347noname.205:
2348 movzwl -642(fp),r0
2349 bicl2 #-65536,r0
2350 addl2 r0,-656(fp)
2351 bicl3 #-65536,-644(fp),r0
2352 ashl #16,r0,-648(fp)
2353 addl3 -648(fp),-652(fp),r0
2354 bicl3 #0,r0,-652(fp)
2355 cmpl -652(fp),-648(fp)
2356 bgequ noname.206
2357 incl -656(fp)
2358noname.206:
2359 movl -652(fp),r1
2360 movl -656(fp),r2
2361 addl2 r1,r10
2362 bicl2 #0,r10
2363 cmpl r10,r1
2364 bgequ noname.207
2365 incl r2
2366noname.207:
2367 addl2 r2,r9
2368 bicl2 #0,r9
2369 cmpl r9,r2
2370 bgequ noname.208
2371 incl r8
2372noname.208:
2373
2374 movzwl 10(r6),r2
2375 bicl3 #-65536,24(r7),r3
2376 movzwl 26(r7),r0
2377 bicl2 #-65536,r0
2378 bicl3 #-65536,8(r6),-668(fp)
2379 bicl3 #-65536,r2,-672(fp)
2380 mull3 r0,-668(fp),-660(fp)
2381 mull2 r3,-668(fp)
2382 mull3 r3,-672(fp),-664(fp)
2383 mull2 r0,-672(fp)
2384 addl3 -660(fp),-664(fp),r0
2385 bicl3 #0,r0,-660(fp)
2386 cmpl -660(fp),-664(fp)
2387 bgequ noname.209
2388 addl2 #65536,-672(fp)
2389noname.209:
2390 movzwl -658(fp),r0
2391 bicl2 #-65536,r0
2392 addl2 r0,-672(fp)
2393 bicl3 #-65536,-660(fp),r0
2394 ashl #16,r0,-664(fp)
2395 addl3 -664(fp),-668(fp),r0
2396 bicl3 #0,r0,-668(fp)
2397 cmpl -668(fp),-664(fp)
2398 bgequ noname.210
2399 incl -672(fp)
2400noname.210:
2401 movl -668(fp),r1
2402 movl -672(fp),r2
2403 addl2 r1,r10
2404 bicl2 #0,r10
2405 cmpl r10,r1
2406 bgequ noname.211
2407 incl r2
2408noname.211:
2409 addl2 r2,r9
2410 bicl2 #0,r9
2411 cmpl r9,r2
2412 bgequ noname.212
2413 incl r8
2414noname.212:
2415
2416 movzwl 6(r6),r2
2417 bicl3 #-65536,28(r7),r3
2418 movzwl 30(r7),r0
2419 bicl2 #-65536,r0
2420 bicl3 #-65536,4(r6),-684(fp)
2421 bicl3 #-65536,r2,-688(fp)
2422 mull3 r0,-684(fp),-676(fp)
2423 mull2 r3,-684(fp)
2424 mull3 r3,-688(fp),-680(fp)
2425 mull2 r0,-688(fp)
2426 addl3 -676(fp),-680(fp),r0
2427 bicl3 #0,r0,-676(fp)
2428 cmpl -676(fp),-680(fp)
2429 bgequ noname.213
2430 addl2 #65536,-688(fp)
2431noname.213:
2432 movzwl -674(fp),r0
2433 bicl2 #-65536,r0
2434 addl2 r0,-688(fp)
2435 bicl3 #-65536,-676(fp),r0
2436 ashl #16,r0,-680(fp)
2437 addl3 -680(fp),-684(fp),r0
2438 bicl3 #0,r0,-684(fp)
2439 cmpl -684(fp),-680(fp)
2440 bgequ noname.214
2441 incl -688(fp)
2442noname.214:
2443 movl -684(fp),r1
2444 movl -688(fp),r2
2445 addl2 r1,r10
2446 bicl2 #0,r10
2447 cmpl r10,r1
2448 bgequ noname.215
2449 incl r2
2450noname.215:
2451 addl2 r2,r9
2452 bicl2 #0,r9
2453 cmpl r9,r2
2454 bgequ noname.216
2455 incl r8
2456noname.216:
2457
2458 movl r10,32(r11)
2459
2460 clrl r10
2461
2462 movzwl 10(r6),r2
2463 bicl3 #-65536,28(r7),r3
2464 movzwl 30(r7),r0
2465 bicl2 #-65536,r0
2466 bicl3 #-65536,8(r6),-700(fp)
2467 bicl3 #-65536,r2,-704(fp)
2468 mull3 r0,-700(fp),-692(fp)
2469 mull2 r3,-700(fp)
2470 mull3 r3,-704(fp),-696(fp)
2471 mull2 r0,-704(fp)
2472 addl3 -692(fp),-696(fp),r0
2473 bicl3 #0,r0,-692(fp)
2474 cmpl -692(fp),-696(fp)
2475 bgequ noname.217
2476 addl2 #65536,-704(fp)
2477noname.217:
2478 movzwl -690(fp),r0
2479 bicl2 #-65536,r0
2480 addl2 r0,-704(fp)
2481 bicl3 #-65536,-692(fp),r0
2482 ashl #16,r0,-696(fp)
2483 addl3 -696(fp),-700(fp),r0
2484 bicl3 #0,r0,-700(fp)
2485 cmpl -700(fp),-696(fp)
2486 bgequ noname.218
2487 incl -704(fp)
2488noname.218:
2489 movl -700(fp),r1
2490 movl -704(fp),r2
2491 addl2 r1,r9
2492 bicl2 #0,r9
2493 cmpl r9,r1
2494 bgequ noname.219
2495 incl r2
2496noname.219:
2497 addl2 r2,r8
2498 bicl2 #0,r8
2499 cmpl r8,r2
2500 bgequ noname.220
2501 incl r10
2502noname.220:
2503
2504 movzwl 14(r6),r2
2505 bicl3 #-65536,24(r7),r3
2506 movzwl 26(r7),r0
2507 bicl2 #-65536,r0
2508 bicl3 #-65536,12(r6),-716(fp)
2509 bicl3 #-65536,r2,-720(fp)
2510 mull3 r0,-716(fp),-708(fp)
2511 mull2 r3,-716(fp)
2512 mull3 r3,-720(fp),-712(fp)
2513 mull2 r0,-720(fp)
2514 addl3 -708(fp),-712(fp),r0
2515 bicl3 #0,r0,-708(fp)
2516 cmpl -708(fp),-712(fp)
2517 bgequ noname.221
2518 addl2 #65536,-720(fp)
2519noname.221:
2520 movzwl -706(fp),r0
2521 bicl2 #-65536,r0
2522 addl2 r0,-720(fp)
2523 bicl3 #-65536,-708(fp),r0
2524 ashl #16,r0,-712(fp)
2525 addl3 -712(fp),-716(fp),r0
2526 bicl3 #0,r0,-716(fp)
2527 cmpl -716(fp),-712(fp)
2528 bgequ noname.222
2529 incl -720(fp)
2530noname.222:
2531 movl -716(fp),r1
2532 movl -720(fp),r2
2533 addl2 r1,r9
2534 bicl2 #0,r9
2535 cmpl r9,r1
2536 bgequ noname.223
2537 incl r2
2538noname.223:
2539 addl2 r2,r8
2540 bicl2 #0,r8
2541 cmpl r8,r2
2542 bgequ noname.224
2543 incl r10
2544noname.224:
2545
2546 movzwl 18(r6),r2
2547 bicl3 #-65536,20(r7),r3
2548 movzwl 22(r7),r0
2549 bicl2 #-65536,r0
2550 bicl3 #-65536,16(r6),-732(fp)
2551 bicl3 #-65536,r2,-736(fp)
2552 mull3 r0,-732(fp),-724(fp)
2553 mull2 r3,-732(fp)
2554 mull3 r3,-736(fp),-728(fp)
2555 mull2 r0,-736(fp)
2556 addl3 -724(fp),-728(fp),r0
2557 bicl3 #0,r0,-724(fp)
2558 cmpl -724(fp),-728(fp)
2559 bgequ noname.225
2560 addl2 #65536,-736(fp)
2561noname.225:
2562 movzwl -722(fp),r0
2563 bicl2 #-65536,r0
2564 addl2 r0,-736(fp)
2565 bicl3 #-65536,-724(fp),r0
2566 ashl #16,r0,-728(fp)
2567 addl3 -728(fp),-732(fp),r0
2568 bicl3 #0,r0,-732(fp)
2569 cmpl -732(fp),-728(fp)
2570 bgequ noname.226
2571 incl -736(fp)
2572noname.226:
2573 movl -732(fp),r1
2574 movl -736(fp),r2
2575 addl2 r1,r9
2576 bicl2 #0,r9
2577 cmpl r9,r1
2578 bgequ noname.227
2579 incl r2
2580noname.227:
2581 addl2 r2,r8
2582 bicl2 #0,r8
2583 cmpl r8,r2
2584 bgequ noname.228
2585 incl r10
2586noname.228:
2587
2588 movzwl 22(r6),r2
2589 bicl3 #-65536,16(r7),r3
2590 movzwl 18(r7),r0
2591 bicl2 #-65536,r0
2592 bicl3 #-65536,20(r6),-748(fp)
2593 bicl3 #-65536,r2,-752(fp)
2594 mull3 r0,-748(fp),-740(fp)
2595 mull2 r3,-748(fp)
2596 mull3 r3,-752(fp),-744(fp)
2597 mull2 r0,-752(fp)
2598 addl3 -740(fp),-744(fp),r0
2599 bicl3 #0,r0,-740(fp)
2600 cmpl -740(fp),-744(fp)
2601 bgequ noname.229
2602 addl2 #65536,-752(fp)
2603noname.229:
2604 movzwl -738(fp),r0
2605 bicl2 #-65536,r0
2606 addl2 r0,-752(fp)
2607 bicl3 #-65536,-740(fp),r0
2608 ashl #16,r0,-744(fp)
2609 addl3 -744(fp),-748(fp),r0
2610 bicl3 #0,r0,-748(fp)
2611 cmpl -748(fp),-744(fp)
2612 bgequ noname.230
2613 incl -752(fp)
2614noname.230:
2615 movl -748(fp),r1
2616 movl -752(fp),r2
2617 addl2 r1,r9
2618 bicl2 #0,r9
2619 cmpl r9,r1
2620 bgequ noname.231
2621 incl r2
2622noname.231:
2623 addl2 r2,r8
2624 bicl2 #0,r8
2625 cmpl r8,r2
2626 bgequ noname.232
2627 incl r10
2628noname.232:
2629
2630 movzwl 26(r6),r2
2631 bicl3 #-65536,12(r7),r3
2632 movzwl 14(r7),r0
2633 bicl2 #-65536,r0
2634 bicl3 #-65536,24(r6),-764(fp)
2635 bicl3 #-65536,r2,-768(fp)
2636 mull3 r0,-764(fp),-756(fp)
2637 mull2 r3,-764(fp)
2638 mull3 r3,-768(fp),-760(fp)
2639 mull2 r0,-768(fp)
2640 addl3 -756(fp),-760(fp),r0
2641 bicl3 #0,r0,-756(fp)
2642 cmpl -756(fp),-760(fp)
2643 bgequ noname.233
2644 addl2 #65536,-768(fp)
2645noname.233:
2646 movzwl -754(fp),r0
2647 bicl2 #-65536,r0
2648 addl2 r0,-768(fp)
2649 bicl3 #-65536,-756(fp),r0
2650 ashl #16,r0,-760(fp)
2651 addl3 -760(fp),-764(fp),r0
2652 bicl3 #0,r0,-764(fp)
2653 cmpl -764(fp),-760(fp)
2654 bgequ noname.234
2655 incl -768(fp)
2656noname.234:
2657 movl -764(fp),r1
2658 movl -768(fp),r2
2659 addl2 r1,r9
2660 bicl2 #0,r9
2661 cmpl r9,r1
2662 bgequ noname.235
2663 incl r2
2664noname.235:
2665 addl2 r2,r8
2666 bicl2 #0,r8
2667 cmpl r8,r2
2668 bgequ noname.236
2669 incl r10
2670noname.236:
2671
2672 bicl3 #-65536,28(r6),r3
2673 movzwl 30(r6),r1
2674 bicl2 #-65536,r1
2675 bicl3 #-65536,8(r7),r2
2676 movzwl 10(r7),r0
2677 bicl2 #-65536,r0
2678 movl r3,r5
2679 movl r1,r4
2680 mull3 r0,r5,-772(fp)
2681 mull2 r2,r5
2682 mull3 r2,r4,-776(fp)
2683 mull2 r0,r4
2684 addl3 -772(fp),-776(fp),r0
2685 bicl3 #0,r0,-772(fp)
2686 cmpl -772(fp),-776(fp)
2687 bgequ noname.237
2688 addl2 #65536,r4
2689noname.237:
2690 movzwl -770(fp),r0
2691 bicl2 #-65536,r0
2692 addl2 r0,r4
2693 bicl3 #-65536,-772(fp),r0
2694 ashl #16,r0,-776(fp)
2695 addl2 -776(fp),r5
2696 bicl2 #0,r5
2697 cmpl r5,-776(fp)
2698 bgequ noname.238
2699 incl r4
2700noname.238:
2701 movl r5,r1
2702 movl r4,r2
2703 addl2 r1,r9
2704 bicl2 #0,r9
2705 cmpl r9,r1
2706 bgequ noname.239
2707 incl r2
2708noname.239:
2709 addl2 r2,r8
2710 bicl2 #0,r8
2711 cmpl r8,r2
2712 bgequ noname.240
2713 incl r10
2714noname.240:
2715
2716 movl r9,36(r11)
2717
2718 clrl r9
2719
2720 bicl3 #-65536,28(r6),r3
2721 movzwl 30(r6),r1
2722 bicl2 #-65536,r1
2723 bicl3 #-65536,12(r7),r2
2724 movzwl 14(r7),r0
2725 bicl2 #-65536,r0
2726 movl r3,r5
2727 movl r1,r4
2728 mull3 r0,r5,-780(fp)
2729 mull2 r2,r5
2730 mull3 r2,r4,-784(fp)
2731 mull2 r0,r4
2732 addl3 -780(fp),-784(fp),r0
2733 bicl3 #0,r0,-780(fp)
2734 cmpl -780(fp),-784(fp)
2735 bgequ noname.241
2736 addl2 #65536,r4
2737noname.241:
2738 movzwl -778(fp),r0
2739 bicl2 #-65536,r0
2740 addl2 r0,r4
2741 bicl3 #-65536,-780(fp),r0
2742 ashl #16,r0,-784(fp)
2743 addl2 -784(fp),r5
2744 bicl2 #0,r5
2745 cmpl r5,-784(fp)
2746 bgequ noname.242
2747 incl r4
2748noname.242:
2749 movl r5,r1
2750 movl r4,r2
2751 addl2 r1,r8
2752 bicl2 #0,r8
2753 cmpl r8,r1
2754 bgequ noname.243
2755 incl r2
2756noname.243:
2757 addl2 r2,r10
2758 bicl2 #0,r10
2759 cmpl r10,r2
2760 bgequ noname.244
2761 incl r9
2762noname.244:
2763
2764 bicl3 #-65536,24(r6),r3
2765 movzwl 26(r6),r1
2766 bicl2 #-65536,r1
2767 bicl3 #-65536,16(r7),r2
2768 movzwl 18(r7),r0
2769 bicl2 #-65536,r0
2770 movl r3,r5
2771 movl r1,r4
2772 mull3 r0,r5,-788(fp)
2773 mull2 r2,r5
2774 mull3 r2,r4,-792(fp)
2775 mull2 r0,r4
2776 addl3 -788(fp),-792(fp),r0
2777 bicl3 #0,r0,-788(fp)
2778 cmpl -788(fp),-792(fp)
2779 bgequ noname.245
2780 addl2 #65536,r4
2781noname.245:
2782 movzwl -786(fp),r0
2783 bicl2 #-65536,r0
2784 addl2 r0,r4
2785 bicl3 #-65536,-788(fp),r0
2786 ashl #16,r0,-792(fp)
2787 addl2 -792(fp),r5
2788 bicl2 #0,r5
2789 cmpl r5,-792(fp)
2790 bgequ noname.246
2791 incl r4
2792noname.246:
2793 movl r5,r1
2794 movl r4,r2
2795 addl2 r1,r8
2796 bicl2 #0,r8
2797 cmpl r8,r1
2798 bgequ noname.247
2799 incl r2
2800noname.247:
2801 addl2 r2,r10
2802 bicl2 #0,r10
2803 cmpl r10,r2
2804 bgequ noname.248
2805 incl r9
2806noname.248:
2807
2808 bicl3 #-65536,20(r6),r3
2809 movzwl 22(r6),r1
2810 bicl2 #-65536,r1
2811 bicl3 #-65536,20(r7),r2
2812 movzwl 22(r7),r0
2813 bicl2 #-65536,r0
2814 movl r3,r5
2815 movl r1,r4
2816 mull3 r0,r5,-796(fp)
2817 mull2 r2,r5
2818 mull3 r2,r4,-800(fp)
2819 mull2 r0,r4
2820 addl3 -796(fp),-800(fp),r0
2821 bicl3 #0,r0,-796(fp)
2822 cmpl -796(fp),-800(fp)
2823 bgequ noname.249
2824 addl2 #65536,r4
2825noname.249:
2826 movzwl -794(fp),r0
2827 bicl2 #-65536,r0
2828 addl2 r0,r4
2829 bicl3 #-65536,-796(fp),r0
2830 ashl #16,r0,-800(fp)
2831 addl2 -800(fp),r5
2832 bicl2 #0,r5
2833 cmpl r5,-800(fp)
2834 bgequ noname.250
2835 incl r4
2836noname.250:
2837 movl r5,r1
2838 movl r4,r2
2839 addl2 r1,r8
2840 bicl2 #0,r8
2841 cmpl r8,r1
2842 bgequ noname.251
2843 incl r2
2844noname.251:
2845 addl2 r2,r10
2846 bicl2 #0,r10
2847 cmpl r10,r2
2848 bgequ noname.252
2849 incl r9
2850noname.252:
2851
2852 bicl3 #-65536,16(r6),r3
2853 movzwl 18(r6),r1
2854 bicl2 #-65536,r1
2855 bicl3 #-65536,24(r7),r2
2856 movzwl 26(r7),r0
2857 bicl2 #-65536,r0
2858 movl r3,r5
2859 movl r1,r4
2860 mull3 r0,r5,-804(fp)
2861 mull2 r2,r5
2862 mull3 r2,r4,-808(fp)
2863 mull2 r0,r4
2864 addl3 -804(fp),-808(fp),r0
2865 bicl3 #0,r0,-804(fp)
2866 cmpl -804(fp),-808(fp)
2867 bgequ noname.253
2868 addl2 #65536,r4
2869noname.253:
2870 movzwl -802(fp),r0
2871 bicl2 #-65536,r0
2872 addl2 r0,r4
2873 bicl3 #-65536,-804(fp),r0
2874 ashl #16,r0,-808(fp)
2875 addl2 -808(fp),r5
2876 bicl2 #0,r5
2877 cmpl r5,-808(fp)
2878 bgequ noname.254
2879 incl r4
2880noname.254:
2881 movl r5,r1
2882 movl r4,r2
2883 addl2 r1,r8
2884 bicl2 #0,r8
2885 cmpl r8,r1
2886 bgequ noname.255
2887 incl r2
2888noname.255:
2889 addl2 r2,r10
2890 bicl2 #0,r10
2891 cmpl r10,r2
2892 bgequ noname.256
2893 incl r9
2894noname.256:
2895
2896 bicl3 #-65536,12(r6),r3
2897 movzwl 14(r6),r1
2898 bicl2 #-65536,r1
2899 bicl3 #-65536,28(r7),r2
2900 movzwl 30(r7),r0
2901 bicl2 #-65536,r0
2902 movl r3,r5
2903 movl r1,r4
2904 mull3 r0,r5,-812(fp)
2905 mull2 r2,r5
2906 mull3 r2,r4,-816(fp)
2907 mull2 r0,r4
2908 addl3 -812(fp),-816(fp),r0
2909 bicl3 #0,r0,-812(fp)
2910 cmpl -812(fp),-816(fp)
2911 bgequ noname.257
2912 addl2 #65536,r4
2913noname.257:
2914 movzwl -810(fp),r0
2915 bicl2 #-65536,r0
2916 addl2 r0,r4
2917 bicl3 #-65536,-812(fp),r0
2918 ashl #16,r0,-816(fp)
2919 addl2 -816(fp),r5
2920 bicl2 #0,r5
2921 cmpl r5,-816(fp)
2922 bgequ noname.258
2923 incl r4
2924noname.258:
2925 movl r5,r1
2926 movl r4,r2
2927 addl2 r1,r8
2928 bicl2 #0,r8
2929 cmpl r8,r1
2930 bgequ noname.259
2931 incl r2
2932noname.259:
2933 addl2 r2,r10
2934 bicl2 #0,r10
2935 cmpl r10,r2
2936 bgequ noname.260
2937 incl r9
2938noname.260:
2939
2940 movl r8,40(r11)
2941
2942 clrl r8
2943
2944 bicl3 #-65536,16(r6),r3
2945 movzwl 18(r6),r2
2946 bicl3 #-65536,28(r7),r1
2947 movzwl 30(r7),r0
2948 bicl2 #-65536,r0
2949 movl r3,r4
2950 bicl3 #-65536,r2,-828(fp)
2951 mull3 r0,r4,-820(fp)
2952 mull2 r1,r4
2953 mull3 r1,-828(fp),-824(fp)
2954 mull2 r0,-828(fp)
2955 addl3 -820(fp),-824(fp),r0
2956 bicl3 #0,r0,-820(fp)
2957 cmpl -820(fp),-824(fp)
2958 bgequ noname.261
2959 addl2 #65536,-828(fp)
2960noname.261:
2961 movzwl -818(fp),r0
2962 bicl2 #-65536,r0
2963 addl2 r0,-828(fp)
2964 bicl3 #-65536,-820(fp),r0
2965 ashl #16,r0,-824(fp)
2966 addl2 -824(fp),r4
2967 bicl2 #0,r4
2968 cmpl r4,-824(fp)
2969 bgequ noname.262
2970 incl -828(fp)
2971noname.262:
2972 movl r4,r1
2973 movl -828(fp),r2
2974 addl2 r1,r10
2975 bicl2 #0,r10
2976 cmpl r10,r1
2977 bgequ noname.263
2978 incl r2
2979noname.263:
2980 addl2 r2,r9
2981 bicl2 #0,r9
2982 cmpl r9,r2
2983 bgequ noname.264
2984 incl r8
2985noname.264:
2986
2987 movzwl 22(r6),r2
2988 bicl3 #-65536,24(r7),r3
2989 movzwl 26(r7),r0
2990 bicl2 #-65536,r0
2991 bicl3 #-65536,20(r6),-840(fp)
2992 bicl3 #-65536,r2,-844(fp)
2993 mull3 r0,-840(fp),-832(fp)
2994 mull2 r3,-840(fp)
2995 mull3 r3,-844(fp),-836(fp)
2996 mull2 r0,-844(fp)
2997 addl3 -832(fp),-836(fp),r0
2998 bicl3 #0,r0,-832(fp)
2999 cmpl -832(fp),-836(fp)
3000 bgequ noname.265
3001 addl2 #65536,-844(fp)
3002noname.265:
3003 movzwl -830(fp),r0
3004 bicl2 #-65536,r0
3005 addl2 r0,-844(fp)
3006 bicl3 #-65536,-832(fp),r0
3007 ashl #16,r0,-836(fp)
3008 addl3 -836(fp),-840(fp),r0
3009 bicl3 #0,r0,-840(fp)
3010 cmpl -840(fp),-836(fp)
3011 bgequ noname.266
3012 incl -844(fp)
3013noname.266:
3014 movl -840(fp),r1
3015 movl -844(fp),r2
3016 addl2 r1,r10
3017 bicl2 #0,r10
3018 cmpl r10,r1
3019 bgequ noname.267
3020 incl r2
3021noname.267:
3022 addl2 r2,r9
3023 bicl2 #0,r9
3024 cmpl r9,r2
3025 bgequ noname.268
3026 incl r8
3027noname.268:
3028
3029 bicl3 #-65536,24(r6),r3
3030 movzwl 26(r6),r1
3031 bicl2 #-65536,r1
3032 bicl3 #-65536,20(r7),r2
3033 movzwl 22(r7),r0
3034 bicl2 #-65536,r0
3035 movl r3,r5
3036 movl r1,r4
3037 mull3 r0,r5,-848(fp)
3038 mull2 r2,r5
3039 mull3 r2,r4,-852(fp)
3040 mull2 r0,r4
3041 addl3 -848(fp),-852(fp),r0
3042 bicl3 #0,r0,-848(fp)
3043 cmpl -848(fp),-852(fp)
3044 bgequ noname.269
3045 addl2 #65536,r4
3046noname.269:
3047 movzwl -846(fp),r0
3048 bicl2 #-65536,r0
3049 addl2 r0,r4
3050 bicl3 #-65536,-848(fp),r0
3051 ashl #16,r0,-852(fp)
3052 addl2 -852(fp),r5
3053 bicl2 #0,r5
3054 cmpl r5,-852(fp)
3055 bgequ noname.270
3056 incl r4
3057noname.270:
3058 movl r5,r1
3059 movl r4,r2
3060 addl2 r1,r10
3061 bicl2 #0,r10
3062 cmpl r10,r1
3063 bgequ noname.271
3064 incl r2
3065noname.271:
3066 addl2 r2,r9
3067 bicl2 #0,r9
3068 cmpl r9,r2
3069 bgequ noname.272
3070 incl r8
3071noname.272:
3072
3073 bicl3 #-65536,28(r6),r3
3074 movzwl 30(r6),r1
3075 bicl2 #-65536,r1
3076 bicl3 #-65536,16(r7),r2
3077 movzwl 18(r7),r0
3078 bicl2 #-65536,r0
3079 movl r3,r5
3080 movl r1,r4
3081 mull3 r0,r5,-856(fp)
3082 mull2 r2,r5
3083 mull3 r2,r4,-860(fp)
3084 mull2 r0,r4
3085 addl3 -856(fp),-860(fp),r0
3086 bicl3 #0,r0,-856(fp)
3087 cmpl -856(fp),-860(fp)
3088 bgequ noname.273
3089 addl2 #65536,r4
3090noname.273:
3091 movzwl -854(fp),r0
3092 bicl2 #-65536,r0
3093 addl2 r0,r4
3094 bicl3 #-65536,-856(fp),r0
3095 ashl #16,r0,-860(fp)
3096 addl2 -860(fp),r5
3097 bicl2 #0,r5
3098 cmpl r5,-860(fp)
3099 bgequ noname.274
3100 incl r4
3101noname.274:
3102 movl r5,r1
3103 movl r4,r2
3104 addl2 r1,r10
3105 bicl2 #0,r10
3106 cmpl r10,r1
3107 bgequ noname.275
3108 incl r2
3109noname.275:
3110 addl2 r2,r9
3111 bicl2 #0,r9
3112 cmpl r9,r2
3113 bgequ noname.276
3114 incl r8
3115noname.276:
3116
3117 movl r10,44(r11)
3118
3119 clrl r10
3120
3121 bicl3 #-65536,28(r6),r3
3122 movzwl 30(r6),r1
3123 bicl2 #-65536,r1
3124 bicl3 #-65536,20(r7),r2
3125 movzwl 22(r7),r0
3126 bicl2 #-65536,r0
3127 movl r3,r5
3128 movl r1,r4
3129 mull3 r0,r5,-864(fp)
3130 mull2 r2,r5
3131 mull3 r2,r4,-868(fp)
3132 mull2 r0,r4
3133 addl3 -864(fp),-868(fp),r0
3134 bicl3 #0,r0,-864(fp)
3135 cmpl -864(fp),-868(fp)
3136 bgequ noname.277
3137 addl2 #65536,r4
3138noname.277:
3139 movzwl -862(fp),r0
3140 bicl2 #-65536,r0
3141 addl2 r0,r4
3142 bicl3 #-65536,-864(fp),r0
3143 ashl #16,r0,-868(fp)
3144 addl2 -868(fp),r5
3145 bicl2 #0,r5
3146 cmpl r5,-868(fp)
3147 bgequ noname.278
3148 incl r4
3149noname.278:
3150 movl r5,r1
3151 movl r4,r2
3152 addl2 r1,r9
3153 bicl2 #0,r9
3154 cmpl r9,r1
3155 bgequ noname.279
3156 incl r2
3157noname.279:
3158 addl2 r2,r8
3159 bicl2 #0,r8
3160 cmpl r8,r2
3161 bgequ noname.280
3162 incl r10
3163noname.280:
3164
3165 bicl3 #-65536,24(r6),r3
3166 movzwl 26(r6),r1
3167 bicl2 #-65536,r1
3168 bicl3 #-65536,24(r7),r2
3169 movzwl 26(r7),r0
3170 bicl2 #-65536,r0
3171 movl r3,r5
3172 movl r1,r4
3173 mull3 r0,r5,-872(fp)
3174 mull2 r2,r5
3175 mull3 r2,r4,-876(fp)
3176 mull2 r0,r4
3177 addl3 -872(fp),-876(fp),r0
3178 bicl3 #0,r0,-872(fp)
3179 cmpl -872(fp),-876(fp)
3180 bgequ noname.281
3181 addl2 #65536,r4
3182noname.281:
3183 movzwl -870(fp),r0
3184 bicl2 #-65536,r0
3185 addl2 r0,r4
3186 bicl3 #-65536,-872(fp),r0
3187 ashl #16,r0,-876(fp)
3188 addl2 -876(fp),r5
3189 bicl2 #0,r5
3190 cmpl r5,-876(fp)
3191 bgequ noname.282
3192 incl r4
3193noname.282:
3194 movl r5,r1
3195 movl r4,r2
3196 addl2 r1,r9
3197 bicl2 #0,r9
3198 cmpl r9,r1
3199 bgequ noname.283
3200 incl r2
3201noname.283:
3202 addl2 r2,r8
3203 bicl2 #0,r8
3204 cmpl r8,r2
3205 bgequ noname.284
3206 incl r10
3207noname.284:
3208
3209 bicl3 #-65536,20(r6),r3
3210 movzwl 22(r6),r1
3211 bicl2 #-65536,r1
3212 bicl3 #-65536,28(r7),r2
3213 movzwl 30(r7),r0
3214 bicl2 #-65536,r0
3215 movl r3,r5
3216 movl r1,r4
3217 mull3 r0,r5,-880(fp)
3218 mull2 r2,r5
3219 mull3 r2,r4,-884(fp)
3220 mull2 r0,r4
3221 addl3 -880(fp),-884(fp),r0
3222 bicl3 #0,r0,-880(fp)
3223 cmpl -880(fp),-884(fp)
3224 bgequ noname.285
3225 addl2 #65536,r4
3226noname.285:
3227 movzwl -878(fp),r0
3228 bicl2 #-65536,r0
3229 addl2 r0,r4
3230 bicl3 #-65536,-880(fp),r0
3231 ashl #16,r0,-884(fp)
3232 addl2 -884(fp),r5
3233 bicl2 #0,r5
3234 cmpl r5,-884(fp)
3235 bgequ noname.286
3236 incl r4
3237noname.286:
3238 movl r5,r1
3239 movl r4,r2
3240 addl2 r1,r9
3241 bicl2 #0,r9
3242 cmpl r9,r1
3243 bgequ noname.287
3244 incl r2
3245noname.287:
3246 addl2 r2,r8
3247 bicl2 #0,r8
3248 cmpl r8,r2
3249 bgequ noname.288
3250 incl r10
3251noname.288:
3252
3253 movl r9,48(r11)
3254
3255 clrl r9
3256
3257 bicl3 #-65536,24(r6),r3
3258 movzwl 26(r6),r1
3259 bicl2 #-65536,r1
3260 bicl3 #-65536,28(r7),r2
3261 movzwl 30(r7),r0
3262 bicl2 #-65536,r0
3263 movl r3,r5
3264 movl r1,r4
3265 mull3 r0,r5,-888(fp)
3266 mull2 r2,r5
3267 mull3 r2,r4,-892(fp)
3268 mull2 r0,r4
3269 addl3 -888(fp),-892(fp),r0
3270 bicl3 #0,r0,-888(fp)
3271 cmpl -888(fp),-892(fp)
3272 bgequ noname.289
3273 addl2 #65536,r4
3274noname.289:
3275 movzwl -886(fp),r0
3276 bicl2 #-65536,r0
3277 addl2 r0,r4
3278 bicl3 #-65536,-888(fp),r0
3279 ashl #16,r0,-892(fp)
3280 addl2 -892(fp),r5
3281 bicl2 #0,r5
3282 cmpl r5,-892(fp)
3283 bgequ noname.290
3284 incl r4
3285noname.290:
3286 movl r5,r1
3287 movl r4,r2
3288 addl2 r1,r8
3289 bicl2 #0,r8
3290 cmpl r8,r1
3291 bgequ noname.291
3292 incl r2
3293noname.291:
3294 addl2 r2,r10
3295 bicl2 #0,r10
3296 cmpl r10,r2
3297 bgequ noname.292
3298 incl r9
3299noname.292:
3300
3301 movzwl 30(r6),r2
3302 bicl3 #-65536,24(r7),r3
3303 movzwl 26(r7),r0
3304 bicl2 #-65536,r0
3305 bicl3 #-65536,28(r6),-904(fp)
3306 bicl3 #-65536,r2,-908(fp)
3307 mull3 r0,-904(fp),-896(fp)
3308 mull2 r3,-904(fp)
3309 mull3 r3,-908(fp),-900(fp)
3310 mull2 r0,-908(fp)
3311 addl3 -896(fp),-900(fp),r0
3312 bicl3 #0,r0,-896(fp)
3313 cmpl -896(fp),-900(fp)
3314 bgequ noname.293
3315 addl2 #65536,-908(fp)
3316noname.293:
3317 movzwl -894(fp),r0
3318 bicl2 #-65536,r0
3319 addl2 r0,-908(fp)
3320 bicl3 #-65536,-896(fp),r0
3321 ashl #16,r0,-900(fp)
3322 addl3 -900(fp),-904(fp),r0
3323 bicl3 #0,r0,-904(fp)
3324 cmpl -904(fp),-900(fp)
3325 bgequ noname.294
3326 incl -908(fp)
3327noname.294:
3328 movl -904(fp),r1
3329 movl -908(fp),r2
3330 addl2 r1,r8
3331 bicl2 #0,r8
3332 cmpl r8,r1
3333 bgequ noname.295
3334 incl r2
3335noname.295:
3336 addl2 r2,r10
3337 bicl2 #0,r10
3338 cmpl r10,r2
3339 bgequ noname.296
3340 incl r9
3341noname.296:
3342
3343 movl r8,52(r11)
3344
3345 clrl r8
3346
3347 movzwl 30(r6),r2
3348 bicl3 #-65536,28(r7),r3
3349 movzwl 30(r7),r0
3350 bicl2 #-65536,r0
3351 bicl3 #-65536,28(r6),-920(fp)
3352 bicl3 #-65536,r2,-924(fp)
3353 mull3 r0,-920(fp),-912(fp)
3354 mull2 r3,-920(fp)
3355 mull3 r3,-924(fp),-916(fp)
3356 mull2 r0,-924(fp)
3357 addl3 -912(fp),-916(fp),r0
3358 bicl3 #0,r0,-912(fp)
3359 cmpl -912(fp),-916(fp)
3360 bgequ noname.297
3361 addl2 #65536,-924(fp)
3362noname.297:
3363 movzwl -910(fp),r0
3364 bicl2 #-65536,r0
3365 addl2 r0,-924(fp)
3366 bicl3 #-65536,-912(fp),r0
3367 ashl #16,r0,-916(fp)
3368 addl3 -916(fp),-920(fp),r0
3369 bicl3 #0,r0,-920(fp)
3370 cmpl -920(fp),-916(fp)
3371 bgequ noname.298
3372 incl -924(fp)
3373noname.298:
3374 movl -920(fp),r1
3375 movl -924(fp),r2
3376 addl2 r1,r10
3377 bicl2 #0,r10
3378 cmpl r10,r1
3379 bgequ noname.299
3380 incl r2
3381noname.299:
3382 addl2 r2,r9
3383 bicl2 #0,r9
3384 cmpl r9,r2
3385 bgequ noname.300
3386 incl r8
3387noname.300:
3388
3389 movl r10,56(r11)
3390
3391 movl r9,60(r11)
3392
3393 ret
3394
3395
3396
3397;r=4 ;(AP)
3398;a=8 ;(AP)
3399;b=12 ;(AP)
3400;n=16 ;(AP) n by value (input)
3401
3402 .psect code,nowrt
3403
3404.entry BN_MUL_COMBA4,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
3405 movab -156(sp),sp
3406
3407 clrq r9
3408
3409 clrl r8
3410
3411 movl 8(ap),r6
3412 bicl3 #-65536,(r6),r3
3413 movzwl 2(r6),r2
3414 bicl2 #-65536,r2
3415 movl 12(ap),r7
3416 bicl3 #-65536,(r7),r1
3417 movzwl 2(r7),r0
3418 bicl2 #-65536,r0
3419 movl r3,r5
3420 movl r2,r4
3421 mull3 r0,r5,-4(fp)
3422 mull2 r1,r5
3423 mull3 r1,r4,-8(fp)
3424 mull2 r0,r4
3425 addl3 -4(fp),-8(fp),r0
3426 bicl3 #0,r0,-4(fp)
3427 cmpl -4(fp),-8(fp)
3428 bgequ noname.303
3429 addl2 #65536,r4
3430noname.303:
3431 movzwl -2(fp),r0
3432 bicl2 #-65536,r0
3433 addl2 r0,r4
3434 bicl3 #-65536,-4(fp),r0
3435 ashl #16,r0,-8(fp)
3436 addl2 -8(fp),r5
3437 bicl2 #0,r5
3438 cmpl r5,-8(fp)
3439 bgequ noname.304
3440 incl r4
3441noname.304:
3442 movl r5,r1
3443 movl r4,r2
3444 addl2 r1,r10
3445 bicl2 #0,r10
3446 cmpl r10,r1
3447 bgequ noname.305
3448 incl r2
3449noname.305:
3450 addl2 r2,r9
3451 bicl2 #0,r9
3452 cmpl r9,r2
3453 bgequ noname.306
3454 incl r8
3455noname.306:
3456
3457 movl 4(ap),r11
3458 movl r10,(r11)
3459
3460 clrl r10
3461
3462 bicl3 #-65536,(r6),r3
3463 movzwl 2(r6),r1
3464 bicl2 #-65536,r1
3465 bicl3 #-65536,4(r7),r2
3466 movzwl 6(r7),r0
3467 bicl2 #-65536,r0
3468 movl r3,r5
3469 movl r1,r4
3470 mull3 r0,r5,-12(fp)
3471 mull2 r2,r5
3472 mull3 r2,r4,-16(fp)
3473 mull2 r0,r4
3474 addl3 -12(fp),-16(fp),r0
3475 bicl3 #0,r0,-12(fp)
3476 cmpl -12(fp),-16(fp)
3477 bgequ noname.307
3478 addl2 #65536,r4
3479noname.307:
3480 movzwl -10(fp),r0
3481 bicl2 #-65536,r0
3482 addl2 r0,r4
3483 bicl3 #-65536,-12(fp),r0
3484 ashl #16,r0,-16(fp)
3485 addl2 -16(fp),r5
3486 bicl2 #0,r5
3487 cmpl r5,-16(fp)
3488 bgequ noname.308
3489 incl r4
3490noname.308:
3491 movl r5,r1
3492 movl r4,r2
3493 addl2 r1,r9
3494 bicl2 #0,r9
3495 cmpl r9,r1
3496 bgequ noname.309
3497 incl r2
3498noname.309:
3499 addl2 r2,r8
3500 bicl2 #0,r8
3501 cmpl r8,r2
3502 bgequ noname.310
3503 incl r10
3504noname.310:
3505
3506 bicl3 #-65536,4(r6),r3
3507 movzwl 6(r6),r1
3508 bicl2 #-65536,r1
3509 bicl3 #-65536,(r7),r2
3510 movzwl 2(r7),r0
3511 bicl2 #-65536,r0
3512 movl r3,r5
3513 movl r1,r4
3514 mull3 r0,r5,-20(fp)
3515 mull2 r2,r5
3516 mull3 r2,r4,-24(fp)
3517 mull2 r0,r4
3518 addl3 -20(fp),-24(fp),r0
3519 bicl3 #0,r0,-20(fp)
3520 cmpl -20(fp),-24(fp)
3521 bgequ noname.311
3522 addl2 #65536,r4
3523noname.311:
3524 movzwl -18(fp),r0
3525 bicl2 #-65536,r0
3526 addl2 r0,r4
3527 bicl3 #-65536,-20(fp),r0
3528 ashl #16,r0,-24(fp)
3529 addl2 -24(fp),r5
3530 bicl2 #0,r5
3531 cmpl r5,-24(fp)
3532 bgequ noname.312
3533 incl r4
3534noname.312:
3535 movl r5,r1
3536 movl r4,r2
3537 addl2 r1,r9
3538 bicl2 #0,r9
3539 cmpl r9,r1
3540 bgequ noname.313
3541 incl r2
3542noname.313:
3543 addl2 r2,r8
3544 bicl2 #0,r8
3545 cmpl r8,r2
3546 bgequ noname.314
3547 incl r10
3548noname.314:
3549
3550 movl r9,4(r11)
3551
3552 clrl r9
3553
3554 bicl3 #-65536,8(r6),r3
3555 movzwl 10(r6),r1
3556 bicl2 #-65536,r1
3557 bicl3 #-65536,(r7),r2
3558 movzwl 2(r7),r0
3559 bicl2 #-65536,r0
3560 movl r3,r5
3561 movl r1,r4
3562 mull3 r0,r5,-28(fp)
3563 mull2 r2,r5
3564 mull3 r2,r4,-32(fp)
3565 mull2 r0,r4
3566 addl3 -28(fp),-32(fp),r0
3567 bicl3 #0,r0,-28(fp)
3568 cmpl -28(fp),-32(fp)
3569 bgequ noname.315
3570 addl2 #65536,r4
3571noname.315:
3572 movzwl -26(fp),r0
3573 bicl2 #-65536,r0
3574 addl2 r0,r4
3575 bicl3 #-65536,-28(fp),r0
3576 ashl #16,r0,-32(fp)
3577 addl2 -32(fp),r5
3578 bicl2 #0,r5
3579 cmpl r5,-32(fp)
3580 bgequ noname.316
3581 incl r4
3582noname.316:
3583 movl r5,r1
3584 movl r4,r2
3585 addl2 r1,r8
3586 bicl2 #0,r8
3587 cmpl r8,r1
3588 bgequ noname.317
3589 incl r2
3590noname.317:
3591 addl2 r2,r10
3592 bicl2 #0,r10
3593 cmpl r10,r2
3594 bgequ noname.318
3595 incl r9
3596noname.318:
3597
3598 bicl3 #-65536,4(r6),r3
3599 movzwl 6(r6),r1
3600 bicl2 #-65536,r1
3601 bicl3 #-65536,4(r7),r2
3602 movzwl 6(r7),r0
3603 bicl2 #-65536,r0
3604 movl r3,r5
3605 movl r1,r4
3606 mull3 r0,r5,-36(fp)
3607 mull2 r2,r5
3608 mull3 r2,r4,-40(fp)
3609 mull2 r0,r4
3610 addl3 -36(fp),-40(fp),r0
3611 bicl3 #0,r0,-36(fp)
3612 cmpl -36(fp),-40(fp)
3613 bgequ noname.319
3614 addl2 #65536,r4
3615noname.319:
3616 movzwl -34(fp),r0
3617 bicl2 #-65536,r0
3618 addl2 r0,r4
3619 bicl3 #-65536,-36(fp),r0
3620 ashl #16,r0,-40(fp)
3621 addl2 -40(fp),r5
3622 bicl2 #0,r5
3623 cmpl r5,-40(fp)
3624 bgequ noname.320
3625 incl r4
3626noname.320:
3627 movl r5,r1
3628 movl r4,r2
3629 addl2 r1,r8
3630 bicl2 #0,r8
3631 cmpl r8,r1
3632 bgequ noname.321
3633 incl r2
3634noname.321:
3635 addl2 r2,r10
3636 bicl2 #0,r10
3637 cmpl r10,r2
3638 bgequ noname.322
3639 incl r9
3640noname.322:
3641
3642 bicl3 #-65536,(r6),r3
3643 movzwl 2(r6),r1
3644 bicl2 #-65536,r1
3645 bicl3 #-65536,8(r7),r2
3646 movzwl 10(r7),r0
3647 bicl2 #-65536,r0
3648 movl r3,r5
3649 movl r1,r4
3650 mull3 r0,r5,-44(fp)
3651 mull2 r2,r5
3652 mull3 r2,r4,-48(fp)
3653 mull2 r0,r4
3654 addl3 -44(fp),-48(fp),r0
3655 bicl3 #0,r0,-44(fp)
3656 cmpl -44(fp),-48(fp)
3657 bgequ noname.323
3658 addl2 #65536,r4
3659noname.323:
3660 movzwl -42(fp),r0
3661 bicl2 #-65536,r0
3662 addl2 r0,r4
3663 bicl3 #-65536,-44(fp),r0
3664 ashl #16,r0,-48(fp)
3665 addl2 -48(fp),r5
3666 bicl2 #0,r5
3667 cmpl r5,-48(fp)
3668 bgequ noname.324
3669 incl r4
3670noname.324:
3671 movl r5,r1
3672 movl r4,r2
3673 addl2 r1,r8
3674 bicl2 #0,r8
3675 cmpl r8,r1
3676 bgequ noname.325
3677 incl r2
3678noname.325:
3679 addl2 r2,r10
3680 bicl2 #0,r10
3681 cmpl r10,r2
3682 bgequ noname.326
3683 incl r9
3684noname.326:
3685
3686 movl r8,8(r11)
3687
3688 clrl r8
3689
3690 bicl3 #-65536,(r6),r3
3691 movzwl 2(r6),r2
3692 bicl3 #-65536,12(r7),r1
3693 movzwl 14(r7),r0
3694 bicl2 #-65536,r0
3695 movl r3,r4
3696 bicl3 #-65536,r2,-60(fp)
3697 mull3 r0,r4,-52(fp)
3698 mull2 r1,r4
3699 mull3 r1,-60(fp),-56(fp)
3700 mull2 r0,-60(fp)
3701 addl3 -52(fp),-56(fp),r0
3702 bicl3 #0,r0,-52(fp)
3703 cmpl -52(fp),-56(fp)
3704 bgequ noname.327
3705 addl2 #65536,-60(fp)
3706noname.327:
3707 movzwl -50(fp),r0
3708 bicl2 #-65536,r0
3709 addl2 r0,-60(fp)
3710 bicl3 #-65536,-52(fp),r0
3711 ashl #16,r0,-56(fp)
3712 addl2 -56(fp),r4
3713 bicl2 #0,r4
3714 cmpl r4,-56(fp)
3715 bgequ noname.328
3716 incl -60(fp)
3717noname.328:
3718 movl r4,r1
3719 movl -60(fp),r2
3720 addl2 r1,r10
3721 bicl2 #0,r10
3722 cmpl r10,r1
3723 bgequ noname.329
3724 incl r2
3725noname.329:
3726 addl2 r2,r9
3727 bicl2 #0,r9
3728 cmpl r9,r2
3729 bgequ noname.330
3730 incl r8
3731noname.330:
3732
3733 movzwl 6(r6),r2
3734 bicl3 #-65536,8(r7),r3
3735 movzwl 10(r7),r0
3736 bicl2 #-65536,r0
3737 bicl3 #-65536,4(r6),-72(fp)
3738 bicl3 #-65536,r2,-76(fp)
3739 mull3 r0,-72(fp),-64(fp)
3740 mull2 r3,-72(fp)
3741 mull3 r3,-76(fp),-68(fp)
3742 mull2 r0,-76(fp)
3743 addl3 -64(fp),-68(fp),r0
3744 bicl3 #0,r0,-64(fp)
3745 cmpl -64(fp),-68(fp)
3746 bgequ noname.331
3747 addl2 #65536,-76(fp)
3748noname.331:
3749 movzwl -62(fp),r0
3750 bicl2 #-65536,r0
3751 addl2 r0,-76(fp)
3752 bicl3 #-65536,-64(fp),r0
3753 ashl #16,r0,-68(fp)
3754 addl3 -68(fp),-72(fp),r0
3755 bicl3 #0,r0,-72(fp)
3756 cmpl -72(fp),-68(fp)
3757 bgequ noname.332
3758 incl -76(fp)
3759noname.332:
3760 movl -72(fp),r1
3761 movl -76(fp),r2
3762 addl2 r1,r10
3763 bicl2 #0,r10
3764 cmpl r10,r1
3765 bgequ noname.333
3766 incl r2
3767noname.333:
3768 addl2 r2,r9
3769 bicl2 #0,r9
3770 cmpl r9,r2
3771 bgequ noname.334
3772 incl r8
3773noname.334:
3774
3775 bicl3 #-65536,8(r6),r3
3776 movzwl 10(r6),r1
3777 bicl2 #-65536,r1
3778 bicl3 #-65536,4(r7),r2
3779 movzwl 6(r7),r0
3780 bicl2 #-65536,r0
3781 movl r3,r5
3782 movl r1,r4
3783 mull3 r0,r5,-80(fp)
3784 mull2 r2,r5
3785 mull3 r2,r4,-84(fp)
3786 mull2 r0,r4
3787 addl3 -80(fp),-84(fp),r0
3788 bicl3 #0,r0,-80(fp)
3789 cmpl -80(fp),-84(fp)
3790 bgequ noname.335
3791 addl2 #65536,r4
3792noname.335:
3793 movzwl -78(fp),r0
3794 bicl2 #-65536,r0
3795 addl2 r0,r4
3796 bicl3 #-65536,-80(fp),r0
3797 ashl #16,r0,-84(fp)
3798 addl2 -84(fp),r5
3799 bicl2 #0,r5
3800 cmpl r5,-84(fp)
3801 bgequ noname.336
3802 incl r4
3803noname.336:
3804 movl r5,r1
3805 movl r4,r2
3806 addl2 r1,r10
3807 bicl2 #0,r10
3808 cmpl r10,r1
3809 bgequ noname.337
3810 incl r2
3811noname.337:
3812 addl2 r2,r9
3813 bicl2 #0,r9
3814 cmpl r9,r2
3815 bgequ noname.338
3816 incl r8
3817noname.338:
3818
3819 bicl3 #-65536,12(r6),r3
3820 movzwl 14(r6),r1
3821 bicl2 #-65536,r1
3822 bicl3 #-65536,(r7),r2
3823 movzwl 2(r7),r0
3824 bicl2 #-65536,r0
3825 movl r3,r5
3826 movl r1,r4
3827 mull3 r0,r5,-88(fp)
3828 mull2 r2,r5
3829 mull3 r2,r4,-92(fp)
3830 mull2 r0,r4
3831 addl3 -88(fp),-92(fp),r0
3832 bicl3 #0,r0,-88(fp)
3833 cmpl -88(fp),-92(fp)
3834 bgequ noname.339
3835 addl2 #65536,r4
3836noname.339:
3837 movzwl -86(fp),r0
3838 bicl2 #-65536,r0
3839 addl2 r0,r4
3840 bicl3 #-65536,-88(fp),r0
3841 ashl #16,r0,-92(fp)
3842 addl2 -92(fp),r5
3843 bicl2 #0,r5
3844 cmpl r5,-92(fp)
3845 bgequ noname.340
3846 incl r4
3847noname.340:
3848 movl r5,r1
3849 movl r4,r2
3850 addl2 r1,r10
3851 bicl2 #0,r10
3852 cmpl r10,r1
3853 bgequ noname.341
3854 incl r2
3855noname.341:
3856 addl2 r2,r9
3857 bicl2 #0,r9
3858 cmpl r9,r2
3859 bgequ noname.342
3860 incl r8
3861noname.342:
3862
3863 movl r10,12(r11)
3864
3865 clrl r10
3866
3867 bicl3 #-65536,12(r6),r3
3868 movzwl 14(r6),r1
3869 bicl2 #-65536,r1
3870 bicl3 #-65536,4(r7),r2
3871 movzwl 6(r7),r0
3872 bicl2 #-65536,r0
3873 movl r3,r5
3874 movl r1,r4
3875 mull3 r0,r5,-96(fp)
3876 mull2 r2,r5
3877 mull3 r2,r4,-100(fp)
3878 mull2 r0,r4
3879 addl3 -96(fp),-100(fp),r0
3880 bicl3 #0,r0,-96(fp)
3881 cmpl -96(fp),-100(fp)
3882 bgequ noname.343
3883 addl2 #65536,r4
3884noname.343:
3885 movzwl -94(fp),r0
3886 bicl2 #-65536,r0
3887 addl2 r0,r4
3888 bicl3 #-65536,-96(fp),r0
3889 ashl #16,r0,-100(fp)
3890 addl2 -100(fp),r5
3891 bicl2 #0,r5
3892 cmpl r5,-100(fp)
3893 bgequ noname.344
3894 incl r4
3895noname.344:
3896 movl r5,r1
3897 movl r4,r2
3898 addl2 r1,r9
3899 bicl2 #0,r9
3900 cmpl r9,r1
3901 bgequ noname.345
3902 incl r2
3903noname.345:
3904 addl2 r2,r8
3905 bicl2 #0,r8
3906 cmpl r8,r2
3907 bgequ noname.346
3908 incl r10
3909noname.346:
3910
3911 bicl3 #-65536,8(r6),r3
3912 movzwl 10(r6),r1
3913 bicl2 #-65536,r1
3914 bicl3 #-65536,8(r7),r2
3915 movzwl 10(r7),r0
3916 bicl2 #-65536,r0
3917 movl r3,r5
3918 movl r1,r4
3919 mull3 r0,r5,-104(fp)
3920 mull2 r2,r5
3921 mull3 r2,r4,-108(fp)
3922 mull2 r0,r4
3923 addl3 -104(fp),-108(fp),r0
3924 bicl3 #0,r0,-104(fp)
3925 cmpl -104(fp),-108(fp)
3926 bgequ noname.347
3927 addl2 #65536,r4
3928noname.347:
3929 movzwl -102(fp),r0
3930 bicl2 #-65536,r0
3931 addl2 r0,r4
3932 bicl3 #-65536,-104(fp),r0
3933 ashl #16,r0,-108(fp)
3934 addl2 -108(fp),r5
3935 bicl2 #0,r5
3936 cmpl r5,-108(fp)
3937 bgequ noname.348
3938 incl r4
3939noname.348:
3940 movl r5,r1
3941 movl r4,r2
3942 addl2 r1,r9
3943 bicl2 #0,r9
3944 cmpl r9,r1
3945 bgequ noname.349
3946 incl r2
3947noname.349:
3948 addl2 r2,r8
3949 bicl2 #0,r8
3950 cmpl r8,r2
3951 bgequ noname.350
3952 incl r10
3953noname.350:
3954
3955 bicl3 #-65536,4(r6),r3
3956 movzwl 6(r6),r1
3957 bicl2 #-65536,r1
3958 bicl3 #-65536,12(r7),r2
3959 movzwl 14(r7),r0
3960 bicl2 #-65536,r0
3961 movl r3,r5
3962 movl r1,r4
3963 mull3 r0,r5,-112(fp)
3964 mull2 r2,r5
3965 mull3 r2,r4,-116(fp)
3966 mull2 r0,r4
3967 addl3 -112(fp),-116(fp),r0
3968 bicl3 #0,r0,-112(fp)
3969 cmpl -112(fp),-116(fp)
3970 bgequ noname.351
3971 addl2 #65536,r4
3972noname.351:
3973 movzwl -110(fp),r0
3974 bicl2 #-65536,r0
3975 addl2 r0,r4
3976 bicl3 #-65536,-112(fp),r0
3977 ashl #16,r0,-116(fp)
3978 addl2 -116(fp),r5
3979 bicl2 #0,r5
3980 cmpl r5,-116(fp)
3981 bgequ noname.352
3982 incl r4
3983noname.352:
3984 movl r5,r1
3985 movl r4,r2
3986 addl2 r1,r9
3987 bicl2 #0,r9
3988 cmpl r9,r1
3989 bgequ noname.353
3990 incl r2
3991noname.353:
3992 addl2 r2,r8
3993 bicl2 #0,r8
3994 cmpl r8,r2
3995 bgequ noname.354
3996 incl r10
3997noname.354:
3998
3999 movl r9,16(r11)
4000
4001 clrl r9
4002
4003 bicl3 #-65536,8(r6),r3
4004 movzwl 10(r6),r1
4005 bicl2 #-65536,r1
4006 bicl3 #-65536,12(r7),r2
4007 movzwl 14(r7),r0
4008 bicl2 #-65536,r0
4009 movl r3,r5
4010 movl r1,r4
4011 mull3 r0,r5,-120(fp)
4012 mull2 r2,r5
4013 mull3 r2,r4,-124(fp)
4014 mull2 r0,r4
4015 addl3 -120(fp),-124(fp),r0
4016 bicl3 #0,r0,-120(fp)
4017 cmpl -120(fp),-124(fp)
4018 bgequ noname.355
4019 addl2 #65536,r4
4020noname.355:
4021 movzwl -118(fp),r0
4022 bicl2 #-65536,r0
4023 addl2 r0,r4
4024 bicl3 #-65536,-120(fp),r0
4025 ashl #16,r0,-124(fp)
4026 addl2 -124(fp),r5
4027 bicl2 #0,r5
4028 cmpl r5,-124(fp)
4029 bgequ noname.356
4030 incl r4
4031noname.356:
4032 movl r5,r1
4033 movl r4,r2
4034 addl2 r1,r8
4035 bicl2 #0,r8
4036 cmpl r8,r1
4037 bgequ noname.357
4038 incl r2
4039noname.357:
4040 addl2 r2,r10
4041 bicl2 #0,r10
4042 cmpl r10,r2
4043 bgequ noname.358
4044 incl r9
4045noname.358:
4046
4047 movzwl 14(r6),r2
4048 bicl3 #-65536,8(r7),r3
4049 movzwl 10(r7),r0
4050 bicl2 #-65536,r0
4051 bicl3 #-65536,12(r6),-136(fp)
4052 bicl3 #-65536,r2,-140(fp)
4053 mull3 r0,-136(fp),-128(fp)
4054 mull2 r3,-136(fp)
4055 mull3 r3,-140(fp),-132(fp)
4056 mull2 r0,-140(fp)
4057 addl3 -128(fp),-132(fp),r0
4058 bicl3 #0,r0,-128(fp)
4059 cmpl -128(fp),-132(fp)
4060 bgequ noname.359
4061 addl2 #65536,-140(fp)
4062noname.359:
4063 movzwl -126(fp),r0
4064 bicl2 #-65536,r0
4065 addl2 r0,-140(fp)
4066 bicl3 #-65536,-128(fp),r0
4067 ashl #16,r0,-132(fp)
4068 addl3 -132(fp),-136(fp),r0
4069 bicl3 #0,r0,-136(fp)
4070 cmpl -136(fp),-132(fp)
4071 bgequ noname.360
4072 incl -140(fp)
4073noname.360:
4074 movl -136(fp),r1
4075 movl -140(fp),r2
4076 addl2 r1,r8
4077 bicl2 #0,r8
4078 cmpl r8,r1
4079 bgequ noname.361
4080 incl r2
4081noname.361:
4082 addl2 r2,r10
4083 bicl2 #0,r10
4084 cmpl r10,r2
4085 bgequ noname.362
4086 incl r9
4087noname.362:
4088
4089 movl r8,20(r11)
4090
4091 clrl r8
4092
4093 movzwl 14(r6),r2
4094 bicl3 #-65536,12(r7),r3
4095 movzwl 14(r7),r0
4096 bicl2 #-65536,r0
4097 bicl3 #-65536,12(r6),-152(fp)
4098 bicl3 #-65536,r2,-156(fp)
4099 mull3 r0,-152(fp),-144(fp)
4100 mull2 r3,-152(fp)
4101 mull3 r3,-156(fp),-148(fp)
4102 mull2 r0,-156(fp)
4103 addl3 -144(fp),-148(fp),r0
4104 bicl3 #0,r0,-144(fp)
4105 cmpl -144(fp),-148(fp)
4106 bgequ noname.363
4107 addl2 #65536,-156(fp)
4108noname.363:
4109 movzwl -142(fp),r0
4110 bicl2 #-65536,r0
4111 addl2 r0,-156(fp)
4112 bicl3 #-65536,-144(fp),r0
4113 ashl #16,r0,-148(fp)
4114 addl3 -148(fp),-152(fp),r0
4115 bicl3 #0,r0,-152(fp)
4116 cmpl -152(fp),-148(fp)
4117 bgequ noname.364
4118 incl -156(fp)
4119noname.364:
4120 movl -152(fp),r1
4121 movl -156(fp),r2
4122 addl2 r1,r10
4123 bicl2 #0,r10
4124 cmpl r10,r1
4125 bgequ noname.365
4126 incl r2
4127noname.365:
4128 addl2 r2,r9
4129 bicl2 #0,r9
4130 cmpl r9,r2
4131 bgequ noname.366
4132 incl r8
4133noname.366:
4134
4135 movl r10,24(r11)
4136
4137 movl r9,28(r11)
4138
4139 ret
4140
4141
4142
4143;r=4 ;(AP)
4144;a=8 ;(AP)
4145;b=12 ;(AP)
4146;n=16 ;(AP) n by value (input)
4147
4148 .psect code,nowrt
4149
4150.entry BN_SQR_COMBA8,^m<r2,r3,r4,r5,r6,r7,r8,r9>
4151 movab -444(sp),sp
4152
4153 clrq r8
4154
4155 clrl r7
4156
4157 movl 8(ap),r4
4158 movl (r4),r3
4159 bicl3 #-65536,r3,-4(fp)
4160 extzv #16,#16,r3,r0
4161 bicl3 #-65536,r0,r3
4162 movl -4(fp),r0
4163 mull3 r0,r3,-8(fp)
4164 mull3 r0,r0,-4(fp)
4165 mull2 r3,r3
4166 bicl3 #32767,-8(fp),r0
4167 extzv #15,#17,r0,r0
4168 addl2 r0,r3
4169 bicl3 #-65536,-8(fp),r0
4170 ashl #17,r0,-8(fp)
4171 addl3 -4(fp),-8(fp),r0
4172 bicl3 #0,r0,-4(fp)
4173 cmpl -4(fp),-8(fp)
4174 bgequ noname.369
4175 incl r3
4176noname.369:
4177 movl -4(fp),r1
4178 movl r3,r2
4179 addl2 r1,r9
4180 bicl2 #0,r9
4181 cmpl r9,r1
4182 bgequ noname.370
4183 incl r2
4184noname.370:
4185 addl2 r2,r8
4186 bicl2 #0,r8
4187 cmpl r8,r2
4188 bgequ noname.371
4189 incl r7
4190noname.371:
4191
4192 movl r9,@4(ap)
4193
4194 clrl r9
4195
4196 movzwl 6(r4),r2
4197 bicl3 #-65536,(r4),r3
4198 movzwl 2(r4),r0
4199 bicl2 #-65536,r0
4200 bicl3 #-65536,4(r4),-20(fp)
4201 bicl3 #-65536,r2,-24(fp)
4202 mull3 r0,-20(fp),-12(fp)
4203 mull2 r3,-20(fp)
4204 mull3 r3,-24(fp),-16(fp)
4205 mull2 r0,-24(fp)
4206 addl3 -12(fp),-16(fp),r0
4207 bicl3 #0,r0,-12(fp)
4208 cmpl -12(fp),-16(fp)
4209 bgequ noname.372
4210 addl2 #65536,-24(fp)
4211noname.372:
4212 movzwl -10(fp),r0
4213 bicl2 #-65536,r0
4214 addl2 r0,-24(fp)
4215 bicl3 #-65536,-12(fp),r0
4216 ashl #16,r0,-16(fp)
4217 addl3 -16(fp),-20(fp),r0
4218 bicl3 #0,r0,-20(fp)
4219 cmpl -20(fp),-16(fp)
4220 bgequ noname.373
4221 incl -24(fp)
4222noname.373:
4223 movl -20(fp),r3
4224 movl -24(fp),r2
4225 bbc #31,r2,noname.374
4226 incl r9
4227noname.374:
4228 addl2 r2,r2
4229 bicl2 #0,r2
4230 bbc #31,r3,noname.375
4231 incl r2
4232noname.375:
4233 addl2 r3,r3
4234 bicl2 #0,r3
4235 addl2 r3,r8
4236 bicl2 #0,r8
4237 cmpl r8,r3
4238 bgequ noname.376
4239 incl r2
4240 bicl3 #0,r2,r0
4241 bneq noname.376
4242 incl r9
4243noname.376:
4244 addl2 r2,r7
4245 bicl2 #0,r7
4246 cmpl r7,r2
4247 bgequ noname.377
4248 incl r9
4249noname.377:
4250
4251 movl 4(ap),r0
4252 movl r8,4(r0)
4253
4254 clrl r8
4255
4256 movl 8(ap),r4
4257 movl 4(r4),r3
4258 bicl3 #-65536,r3,-28(fp)
4259 extzv #16,#16,r3,r0
4260 bicl3 #-65536,r0,r3
4261 movl -28(fp),r0
4262 mull3 r0,r3,-32(fp)
4263 mull3 r0,r0,-28(fp)
4264 mull2 r3,r3
4265 bicl3 #32767,-32(fp),r0
4266 extzv #15,#17,r0,r0
4267 addl2 r0,r3
4268 bicl3 #-65536,-32(fp),r0
4269 ashl #17,r0,-32(fp)
4270 addl3 -28(fp),-32(fp),r0
4271 bicl3 #0,r0,-28(fp)
4272 cmpl -28(fp),-32(fp)
4273 bgequ noname.378
4274 incl r3
4275noname.378:
4276 movl -28(fp),r1
4277 movl r3,r2
4278 addl2 r1,r7
4279 bicl2 #0,r7
4280 cmpl r7,r1
4281 bgequ noname.379
4282 incl r2
4283noname.379:
4284 addl2 r2,r9
4285 bicl2 #0,r9
4286 cmpl r9,r2
4287 bgequ noname.380
4288 incl r8
4289noname.380:
4290
4291 movzwl 10(r4),r2
4292 bicl3 #-65536,(r4),r3
4293 movzwl 2(r4),r0
4294 bicl2 #-65536,r0
4295 bicl3 #-65536,8(r4),-44(fp)
4296 bicl3 #-65536,r2,-48(fp)
4297 mull3 r0,-44(fp),-36(fp)
4298 mull2 r3,-44(fp)
4299 mull3 r3,-48(fp),-40(fp)
4300 mull2 r0,-48(fp)
4301 addl3 -36(fp),-40(fp),r0
4302 bicl3 #0,r0,-36(fp)
4303 cmpl -36(fp),-40(fp)
4304 bgequ noname.381
4305 addl2 #65536,-48(fp)
4306noname.381:
4307 movzwl -34(fp),r0
4308 bicl2 #-65536,r0
4309 addl2 r0,-48(fp)
4310 bicl3 #-65536,-36(fp),r0
4311 ashl #16,r0,-40(fp)
4312 addl3 -40(fp),-44(fp),r0
4313 bicl3 #0,r0,-44(fp)
4314 cmpl -44(fp),-40(fp)
4315 bgequ noname.382
4316 incl -48(fp)
4317noname.382:
4318 movl -44(fp),r3
4319 movl -48(fp),r2
4320 bbc #31,r2,noname.383
4321 incl r8
4322noname.383:
4323 addl2 r2,r2
4324 bicl2 #0,r2
4325 bbc #31,r3,noname.384
4326 incl r2
4327noname.384:
4328 addl2 r3,r3
4329 bicl2 #0,r3
4330 addl2 r3,r7
4331 bicl2 #0,r7
4332 cmpl r7,r3
4333 bgequ noname.385
4334 incl r2
4335 bicl3 #0,r2,r0
4336 bneq noname.385
4337 incl r8
4338noname.385:
4339 addl2 r2,r9
4340 bicl2 #0,r9
4341 cmpl r9,r2
4342 bgequ noname.386
4343 incl r8
4344noname.386:
4345
4346 movl 4(ap),r0
4347 movl r7,8(r0)
4348
4349 clrl r7
4350
4351 movl 8(ap),r0
4352 movzwl 14(r0),r2
4353 bicl3 #-65536,(r0),r3
4354 movzwl 2(r0),r1
4355 bicl2 #-65536,r1
4356 bicl3 #-65536,12(r0),-60(fp)
4357 bicl3 #-65536,r2,-64(fp)
4358 mull3 r1,-60(fp),-52(fp)
4359 mull2 r3,-60(fp)
4360 mull3 r3,-64(fp),-56(fp)
4361 mull2 r1,-64(fp)
4362 addl3 -52(fp),-56(fp),r0
4363 bicl3 #0,r0,-52(fp)
4364 cmpl -52(fp),-56(fp)
4365 bgequ noname.387
4366 addl2 #65536,-64(fp)
4367noname.387:
4368 movzwl -50(fp),r0
4369 bicl2 #-65536,r0
4370 addl2 r0,-64(fp)
4371 bicl3 #-65536,-52(fp),r0
4372 ashl #16,r0,-56(fp)
4373 addl3 -56(fp),-60(fp),r0
4374 bicl3 #0,r0,-60(fp)
4375 cmpl -60(fp),-56(fp)
4376 bgequ noname.388
4377 incl -64(fp)
4378noname.388:
4379 movl -60(fp),r3
4380 movl -64(fp),r2
4381 bbc #31,r2,noname.389
4382 incl r7
4383noname.389:
4384 addl2 r2,r2
4385 bicl2 #0,r2
4386 bbc #31,r3,noname.390
4387 incl r2
4388noname.390:
4389 addl2 r3,r3
4390 bicl2 #0,r3
4391 addl2 r3,r9
4392 bicl2 #0,r9
4393 cmpl r9,r3
4394 bgequ noname.391
4395 incl r2
4396 bicl3 #0,r2,r0
4397 bneq noname.391
4398 incl r7
4399noname.391:
4400 addl2 r2,r8
4401 bicl2 #0,r8
4402 cmpl r8,r2
4403 bgequ noname.392
4404 incl r7
4405noname.392:
4406
4407 movl 8(ap),r0
4408 movzwl 10(r0),r2
4409 bicl3 #-65536,4(r0),r3
4410 movzwl 6(r0),r1
4411 bicl2 #-65536,r1
4412 bicl3 #-65536,8(r0),-76(fp)
4413 bicl3 #-65536,r2,-80(fp)
4414 mull3 r1,-76(fp),-68(fp)
4415 mull2 r3,-76(fp)
4416 mull3 r3,-80(fp),-72(fp)
4417 mull2 r1,-80(fp)
4418 addl3 -68(fp),-72(fp),r0
4419 bicl3 #0,r0,-68(fp)
4420 cmpl -68(fp),-72(fp)
4421 bgequ noname.393
4422 addl2 #65536,-80(fp)
4423noname.393:
4424 movzwl -66(fp),r0
4425 bicl2 #-65536,r0
4426 addl2 r0,-80(fp)
4427 bicl3 #-65536,-68(fp),r0
4428 ashl #16,r0,-72(fp)
4429 addl3 -72(fp),-76(fp),r0
4430 bicl3 #0,r0,-76(fp)
4431 cmpl -76(fp),-72(fp)
4432 bgequ noname.394
4433 incl -80(fp)
4434noname.394:
4435 movl -76(fp),r3
4436 movl -80(fp),r2
4437 bbc #31,r2,noname.395
4438 incl r7
4439noname.395:
4440 addl2 r2,r2
4441 bicl2 #0,r2
4442 bbc #31,r3,noname.396
4443 incl r2
4444noname.396:
4445 addl2 r3,r3
4446 bicl2 #0,r3
4447 addl2 r3,r9
4448 bicl2 #0,r9
4449 cmpl r9,r3
4450 bgequ noname.397
4451 incl r2
4452 bicl3 #0,r2,r0
4453 bneq noname.397
4454 incl r7
4455noname.397:
4456 addl2 r2,r8
4457 bicl2 #0,r8
4458 cmpl r8,r2
4459 bgequ noname.398
4460 incl r7
4461noname.398:
4462
4463 movl 4(ap),r0
4464 movl r9,12(r0)
4465
4466 clrl r9
4467
4468 movl 8(ap),r2
4469 movl 8(r2),r4
4470 bicl3 #-65536,r4,-84(fp)
4471 extzv #16,#16,r4,r0
4472 bicl3 #-65536,r0,r4
4473 movl -84(fp),r0
4474 mull3 r0,r4,-88(fp)
4475 mull3 r0,r0,-84(fp)
4476 mull2 r4,r4
4477 bicl3 #32767,-88(fp),r0
4478 extzv #15,#17,r0,r0
4479 addl2 r0,r4
4480 bicl3 #-65536,-88(fp),r0
4481 ashl #17,r0,-88(fp)
4482 addl3 -84(fp),-88(fp),r0
4483 bicl3 #0,r0,-84(fp)
4484 cmpl -84(fp),-88(fp)
4485 bgequ noname.399
4486 incl r4
4487noname.399:
4488 movl -84(fp),r1
4489 movl r4,r3
4490 addl2 r1,r8
4491 bicl2 #0,r8
4492 cmpl r8,r1
4493 bgequ noname.400
4494 incl r3
4495noname.400:
4496 addl2 r3,r7
4497 bicl2 #0,r7
4498 cmpl r7,r3
4499 bgequ noname.401
4500 incl r9
4501noname.401:
4502
4503 movzwl 14(r2),r3
4504 bicl3 #-65536,4(r2),r1
4505 movzwl 6(r2),r0
4506 bicl2 #-65536,r0
4507 bicl3 #-65536,12(r2),-100(fp)
4508 bicl3 #-65536,r3,-104(fp)
4509 mull3 r0,-100(fp),-92(fp)
4510 mull2 r1,-100(fp)
4511 mull3 r1,-104(fp),-96(fp)
4512 mull2 r0,-104(fp)
4513 addl3 -92(fp),-96(fp),r0
4514 bicl3 #0,r0,-92(fp)
4515 cmpl -92(fp),-96(fp)
4516 bgequ noname.402
4517 addl2 #65536,-104(fp)
4518noname.402:
4519 movzwl -90(fp),r0
4520 bicl2 #-65536,r0
4521 addl2 r0,-104(fp)
4522 bicl3 #-65536,-92(fp),r0
4523 ashl #16,r0,-96(fp)
4524 addl3 -96(fp),-100(fp),r0
4525 bicl3 #0,r0,-100(fp)
4526 cmpl -100(fp),-96(fp)
4527 bgequ noname.403
4528 incl -104(fp)
4529noname.403:
4530 movl -100(fp),r3
4531 movl -104(fp),r2
4532 bbc #31,r2,noname.404
4533 incl r9
4534noname.404:
4535 addl2 r2,r2
4536 bicl2 #0,r2
4537 bbc #31,r3,noname.405
4538 incl r2
4539noname.405:
4540 addl2 r3,r3
4541 bicl2 #0,r3
4542 addl2 r3,r8
4543 bicl2 #0,r8
4544 cmpl r8,r3
4545 bgequ noname.406
4546 incl r2
4547 bicl3 #0,r2,r0
4548 bneq noname.406
4549 incl r9
4550noname.406:
4551 addl2 r2,r7
4552 bicl2 #0,r7
4553 cmpl r7,r2
4554 bgequ noname.407
4555 incl r9
4556noname.407:
4557
4558 movl 8(ap),r0
4559 movzwl 18(r0),r2
4560 bicl3 #-65536,(r0),r3
4561 movzwl 2(r0),r1
4562 bicl2 #-65536,r1
4563 bicl3 #-65536,16(r0),-116(fp)
4564 bicl3 #-65536,r2,-120(fp)
4565 mull3 r1,-116(fp),-108(fp)
4566 mull2 r3,-116(fp)
4567 mull3 r3,-120(fp),-112(fp)
4568 mull2 r1,-120(fp)
4569 addl3 -108(fp),-112(fp),r0
4570 bicl3 #0,r0,-108(fp)
4571 cmpl -108(fp),-112(fp)
4572 bgequ noname.408
4573 addl2 #65536,-120(fp)
4574noname.408:
4575 movzwl -106(fp),r0
4576 bicl2 #-65536,r0
4577 addl2 r0,-120(fp)
4578 bicl3 #-65536,-108(fp),r0
4579 ashl #16,r0,-112(fp)
4580 addl3 -112(fp),-116(fp),r0
4581 bicl3 #0,r0,-116(fp)
4582 cmpl -116(fp),-112(fp)
4583 bgequ noname.409
4584 incl -120(fp)
4585noname.409:
4586 movl -116(fp),r3
4587 movl -120(fp),r2
4588 bbc #31,r2,noname.410
4589 incl r9
4590noname.410:
4591 addl2 r2,r2
4592 bicl2 #0,r2
4593 bbc #31,r3,noname.411
4594 incl r2
4595noname.411:
4596 addl2 r3,r3
4597 bicl2 #0,r3
4598 addl2 r3,r8
4599 bicl2 #0,r8
4600 cmpl r8,r3
4601 bgequ noname.412
4602 incl r2
4603 bicl3 #0,r2,r0
4604 bneq noname.412
4605 incl r9
4606noname.412:
4607 addl2 r2,r7
4608 bicl2 #0,r7
4609 cmpl r7,r2
4610 bgequ noname.413
4611 incl r9
4612noname.413:
4613
4614 movl 4(ap),r0
4615 movl r8,16(r0)
4616
4617 clrl r8
4618
4619 movl 8(ap),r0
4620 movzwl 22(r0),r2
4621 bicl3 #-65536,(r0),r3
4622 movzwl 2(r0),r1
4623 bicl2 #-65536,r1
4624 bicl3 #-65536,20(r0),-132(fp)
4625 bicl3 #-65536,r2,-136(fp)
4626 mull3 r1,-132(fp),-124(fp)
4627 mull2 r3,-132(fp)
4628 mull3 r3,-136(fp),-128(fp)
4629 mull2 r1,-136(fp)
4630 addl3 -124(fp),-128(fp),r0
4631 bicl3 #0,r0,-124(fp)
4632 cmpl -124(fp),-128(fp)
4633 bgequ noname.414
4634 addl2 #65536,-136(fp)
4635noname.414:
4636 movzwl -122(fp),r0
4637 bicl2 #-65536,r0
4638 addl2 r0,-136(fp)
4639 bicl3 #-65536,-124(fp),r0
4640 ashl #16,r0,-128(fp)
4641 addl3 -128(fp),-132(fp),r0
4642 bicl3 #0,r0,-132(fp)
4643 cmpl -132(fp),-128(fp)
4644 bgequ noname.415
4645 incl -136(fp)
4646noname.415:
4647 movl -132(fp),r3
4648 movl -136(fp),r2
4649 bbc #31,r2,noname.416
4650 incl r8
4651noname.416:
4652 addl2 r2,r2
4653 bicl2 #0,r2
4654 bbc #31,r3,noname.417
4655 incl r2
4656noname.417:
4657 addl2 r3,r3
4658 bicl2 #0,r3
4659 addl2 r3,r7
4660 bicl2 #0,r7
4661 cmpl r7,r3
4662 bgequ noname.418
4663 incl r2
4664 bicl3 #0,r2,r0
4665 bneq noname.418
4666 incl r8
4667noname.418:
4668 addl2 r2,r9
4669 bicl2 #0,r9
4670 cmpl r9,r2
4671 bgequ noname.419
4672 incl r8
4673noname.419:
4674
4675 movl 8(ap),r0
4676 movzwl 18(r0),r2
4677 bicl3 #-65536,4(r0),r3
4678 movzwl 6(r0),r1
4679 bicl2 #-65536,r1
4680 bicl3 #-65536,16(r0),-148(fp)
4681 bicl3 #-65536,r2,-152(fp)
4682 mull3 r1,-148(fp),-140(fp)
4683 mull2 r3,-148(fp)
4684 mull3 r3,-152(fp),-144(fp)
4685 mull2 r1,-152(fp)
4686 addl3 -140(fp),-144(fp),r0
4687 bicl3 #0,r0,-140(fp)
4688 cmpl -140(fp),-144(fp)
4689 bgequ noname.420
4690 addl2 #65536,-152(fp)
4691noname.420:
4692 movzwl -138(fp),r0
4693 bicl2 #-65536,r0
4694 addl2 r0,-152(fp)
4695 bicl3 #-65536,-140(fp),r0
4696 ashl #16,r0,-144(fp)
4697 addl3 -144(fp),-148(fp),r0
4698 bicl3 #0,r0,-148(fp)
4699 cmpl -148(fp),-144(fp)
4700 bgequ noname.421
4701 incl -152(fp)
4702noname.421:
4703 movl -148(fp),r3
4704 movl -152(fp),r2
4705 bbc #31,r2,noname.422
4706 incl r8
4707noname.422:
4708 addl2 r2,r2
4709 bicl2 #0,r2
4710 bbc #31,r3,noname.423
4711 incl r2
4712noname.423:
4713 addl2 r3,r3
4714 bicl2 #0,r3
4715 addl2 r3,r7
4716 bicl2 #0,r7
4717 cmpl r7,r3
4718 bgequ noname.424
4719 incl r2
4720 bicl3 #0,r2,r0
4721 bneq noname.424
4722 incl r8
4723noname.424:
4724 addl2 r2,r9
4725 bicl2 #0,r9
4726 cmpl r9,r2
4727 bgequ noname.425
4728 incl r8
4729noname.425:
4730
4731 movl 8(ap),r0
4732 movzwl 14(r0),r2
4733 bicl3 #-65536,8(r0),r3
4734 movzwl 10(r0),r1
4735 bicl2 #-65536,r1
4736 bicl3 #-65536,12(r0),-164(fp)
4737 bicl3 #-65536,r2,-168(fp)
4738 mull3 r1,-164(fp),-156(fp)
4739 mull2 r3,-164(fp)
4740 mull3 r3,-168(fp),-160(fp)
4741 mull2 r1,-168(fp)
4742 addl3 -156(fp),-160(fp),r0
4743 bicl3 #0,r0,-156(fp)
4744 cmpl -156(fp),-160(fp)
4745 bgequ noname.426
4746 addl2 #65536,-168(fp)
4747noname.426:
4748 movzwl -154(fp),r0
4749 bicl2 #-65536,r0
4750 addl2 r0,-168(fp)
4751 bicl3 #-65536,-156(fp),r0
4752 ashl #16,r0,-160(fp)
4753 addl3 -160(fp),-164(fp),r0
4754 bicl3 #0,r0,-164(fp)
4755 cmpl -164(fp),-160(fp)
4756 bgequ noname.427
4757 incl -168(fp)
4758noname.427:
4759 movl -164(fp),r3
4760 movl -168(fp),r2
4761 bbc #31,r2,noname.428
4762 incl r8
4763noname.428:
4764 addl2 r2,r2
4765 bicl2 #0,r2
4766 bbc #31,r3,noname.429
4767 incl r2
4768noname.429:
4769 addl2 r3,r3
4770 bicl2 #0,r3
4771 addl2 r3,r7
4772 bicl2 #0,r7
4773 cmpl r7,r3
4774 bgequ noname.430
4775 incl r2
4776 bicl3 #0,r2,r0
4777 bneq noname.430
4778 incl r8
4779noname.430:
4780 addl2 r2,r9
4781 bicl2 #0,r9
4782 cmpl r9,r2
4783 bgequ noname.431
4784 incl r8
4785noname.431:
4786
4787 movl 4(ap),r0
4788 movl r7,20(r0)
4789
4790 clrl r7
4791
4792 movl 8(ap),r2
4793 movl 12(r2),r4
4794 bicl3 #-65536,r4,-172(fp)
4795 extzv #16,#16,r4,r0
4796 bicl3 #-65536,r0,r4
4797 movl -172(fp),r0
4798 mull3 r0,r4,-176(fp)
4799 mull3 r0,r0,-172(fp)
4800 mull2 r4,r4
4801 bicl3 #32767,-176(fp),r0
4802 extzv #15,#17,r0,r0
4803 addl2 r0,r4
4804 bicl3 #-65536,-176(fp),r0
4805 ashl #17,r0,-176(fp)
4806 addl3 -172(fp),-176(fp),r0
4807 bicl3 #0,r0,-172(fp)
4808 cmpl -172(fp),-176(fp)
4809 bgequ noname.432
4810 incl r4
4811noname.432:
4812 movl -172(fp),r1
4813 movl r4,r3
4814 addl2 r1,r9
4815 bicl2 #0,r9
4816 cmpl r9,r1
4817 bgequ noname.433
4818 incl r3
4819noname.433:
4820 addl2 r3,r8
4821 bicl2 #0,r8
4822 cmpl r8,r3
4823 bgequ noname.434
4824 incl r7
4825noname.434:
4826
4827 movzwl 18(r2),r3
4828 bicl3 #-65536,8(r2),r1
4829 movzwl 10(r2),r0
4830 bicl2 #-65536,r0
4831 bicl3 #-65536,16(r2),-188(fp)
4832 bicl3 #-65536,r3,-192(fp)
4833 mull3 r0,-188(fp),-180(fp)
4834 mull2 r1,-188(fp)
4835 mull3 r1,-192(fp),-184(fp)
4836 mull2 r0,-192(fp)
4837 addl3 -180(fp),-184(fp),r0
4838 bicl3 #0,r0,-180(fp)
4839 cmpl -180(fp),-184(fp)
4840 bgequ noname.435
4841 addl2 #65536,-192(fp)
4842noname.435:
4843 movzwl -178(fp),r0
4844 bicl2 #-65536,r0
4845 addl2 r0,-192(fp)
4846 bicl3 #-65536,-180(fp),r0
4847 ashl #16,r0,-184(fp)
4848 addl3 -184(fp),-188(fp),r0
4849 bicl3 #0,r0,-188(fp)
4850 cmpl -188(fp),-184(fp)
4851 bgequ noname.436
4852 incl -192(fp)
4853noname.436:
4854 movl -188(fp),r3
4855 movl -192(fp),r2
4856 bbc #31,r2,noname.437
4857 incl r7
4858noname.437:
4859 addl2 r2,r2
4860 bicl2 #0,r2
4861 bbc #31,r3,noname.438
4862 incl r2
4863noname.438:
4864 addl2 r3,r3
4865 bicl2 #0,r3
4866 addl2 r3,r9
4867 bicl2 #0,r9
4868 cmpl r9,r3
4869 bgequ noname.439
4870 incl r2
4871 bicl3 #0,r2,r0
4872 bneq noname.439
4873 incl r7
4874noname.439:
4875 addl2 r2,r8
4876 bicl2 #0,r8
4877 cmpl r8,r2
4878 bgequ noname.440
4879 incl r7
4880noname.440:
4881
4882 movl 8(ap),r0
4883 movzwl 22(r0),r2
4884 bicl3 #-65536,4(r0),r3
4885 movzwl 6(r0),r1
4886 bicl2 #-65536,r1
4887 bicl3 #-65536,20(r0),-204(fp)
4888 bicl3 #-65536,r2,-208(fp)
4889 mull3 r1,-204(fp),-196(fp)
4890 mull2 r3,-204(fp)
4891 mull3 r3,-208(fp),-200(fp)
4892 mull2 r1,-208(fp)
4893 addl3 -196(fp),-200(fp),r0
4894 bicl3 #0,r0,-196(fp)
4895 cmpl -196(fp),-200(fp)
4896 bgequ noname.441
4897 addl2 #65536,-208(fp)
4898noname.441:
4899 movzwl -194(fp),r0
4900 bicl2 #-65536,r0
4901 addl2 r0,-208(fp)
4902 bicl3 #-65536,-196(fp),r0
4903 ashl #16,r0,-200(fp)
4904 addl3 -200(fp),-204(fp),r0
4905 bicl3 #0,r0,-204(fp)
4906 cmpl -204(fp),-200(fp)
4907 bgequ noname.442
4908 incl -208(fp)
4909noname.442:
4910 movl -204(fp),r3
4911 movl -208(fp),r2
4912 bbc #31,r2,noname.443
4913 incl r7
4914noname.443:
4915 addl2 r2,r2
4916 bicl2 #0,r2
4917 bbc #31,r3,noname.444
4918 incl r2
4919noname.444:
4920 addl2 r3,r3
4921 bicl2 #0,r3
4922 addl2 r3,r9
4923 bicl2 #0,r9
4924 cmpl r9,r3
4925 bgequ noname.445
4926 incl r2
4927 bicl3 #0,r2,r0
4928 bneq noname.445
4929 incl r7
4930noname.445:
4931 addl2 r2,r8
4932 bicl2 #0,r8
4933 cmpl r8,r2
4934 bgequ noname.446
4935 incl r7
4936noname.446:
4937
4938 movl 8(ap),r0
4939 movzwl 26(r0),r2
4940 bicl3 #-65536,(r0),r3
4941 movzwl 2(r0),r1
4942 bicl2 #-65536,r1
4943 bicl3 #-65536,24(r0),-220(fp)
4944 bicl3 #-65536,r2,-224(fp)
4945 mull3 r1,-220(fp),-212(fp)
4946 mull2 r3,-220(fp)
4947 mull3 r3,-224(fp),-216(fp)
4948 mull2 r1,-224(fp)
4949 addl3 -212(fp),-216(fp),r0
4950 bicl3 #0,r0,-212(fp)
4951 cmpl -212(fp),-216(fp)
4952 bgequ noname.447
4953 addl2 #65536,-224(fp)
4954noname.447:
4955 movzwl -210(fp),r0
4956 bicl2 #-65536,r0
4957 addl2 r0,-224(fp)
4958 bicl3 #-65536,-212(fp),r0
4959 ashl #16,r0,-216(fp)
4960 addl3 -216(fp),-220(fp),r0
4961 bicl3 #0,r0,-220(fp)
4962 cmpl -220(fp),-216(fp)
4963 bgequ noname.448
4964 incl -224(fp)
4965noname.448:
4966 movl -220(fp),r3
4967 movl -224(fp),r2
4968 bbc #31,r2,noname.449
4969 incl r7
4970noname.449:
4971 addl2 r2,r2
4972 bicl2 #0,r2
4973 bbc #31,r3,noname.450
4974 incl r2
4975noname.450:
4976 addl2 r3,r3
4977 bicl2 #0,r3
4978 addl2 r3,r9
4979 bicl2 #0,r9
4980 cmpl r9,r3
4981 bgequ noname.451
4982 incl r2
4983 bicl3 #0,r2,r0
4984 bneq noname.451
4985 incl r7
4986noname.451:
4987 addl2 r2,r8
4988 bicl2 #0,r8
4989 cmpl r8,r2
4990 bgequ noname.452
4991 incl r7
4992noname.452:
4993
4994 movl 4(ap),r0
4995 movl r9,24(r0)
4996
4997 clrl r9
4998
4999 movl 8(ap),r0
5000 movzwl 30(r0),r2
5001 bicl3 #-65536,(r0),r3
5002 movzwl 2(r0),r1
5003 bicl2 #-65536,r1
5004 bicl3 #-65536,28(r0),-236(fp)
5005 bicl3 #-65536,r2,-240(fp)
5006 mull3 r1,-236(fp),-228(fp)
5007 mull2 r3,-236(fp)
5008 mull3 r3,-240(fp),-232(fp)
5009 mull2 r1,-240(fp)
5010 addl3 -228(fp),-232(fp),r0
5011 bicl3 #0,r0,-228(fp)
5012 cmpl -228(fp),-232(fp)
5013 bgequ noname.453
5014 addl2 #65536,-240(fp)
5015noname.453:
5016 movzwl -226(fp),r0
5017 bicl2 #-65536,r0
5018 addl2 r0,-240(fp)
5019 bicl3 #-65536,-228(fp),r0
5020 ashl #16,r0,-232(fp)
5021 addl3 -232(fp),-236(fp),r0
5022 bicl3 #0,r0,-236(fp)
5023 cmpl -236(fp),-232(fp)
5024 bgequ noname.454
5025 incl -240(fp)
5026noname.454:
5027 movl -236(fp),r3
5028 movl -240(fp),r2
5029 bbc #31,r2,noname.455
5030 incl r9
5031noname.455:
5032 addl2 r2,r2
5033 bicl2 #0,r2
5034 bbc #31,r3,noname.456
5035 incl r2
5036noname.456:
5037 addl2 r3,r3
5038 bicl2 #0,r3
5039 addl2 r3,r8
5040 bicl2 #0,r8
5041 cmpl r8,r3
5042 bgequ noname.457
5043 incl r2
5044 bicl3 #0,r2,r0
5045 bneq noname.457
5046 incl r9
5047noname.457:
5048 addl2 r2,r7
5049 bicl2 #0,r7
5050 cmpl r7,r2
5051 bgequ noname.458
5052 incl r9
5053noname.458:
5054
5055 movl 8(ap),r0
5056 movzwl 26(r0),r2
5057 bicl3 #-65536,4(r0),r3
5058 movzwl 6(r0),r1
5059 bicl2 #-65536,r1
5060 bicl3 #-65536,24(r0),-252(fp)
5061 bicl3 #-65536,r2,-256(fp)
5062 mull3 r1,-252(fp),-244(fp)
5063 mull2 r3,-252(fp)
5064 mull3 r3,-256(fp),-248(fp)
5065 mull2 r1,-256(fp)
5066 addl3 -244(fp),-248(fp),r0
5067 bicl3 #0,r0,-244(fp)
5068 cmpl -244(fp),-248(fp)
5069 bgequ noname.459
5070 addl2 #65536,-256(fp)
5071noname.459:
5072 movzwl -242(fp),r0
5073 bicl2 #-65536,r0
5074 addl2 r0,-256(fp)
5075 bicl3 #-65536,-244(fp),r0
5076 ashl #16,r0,-248(fp)
5077 addl3 -248(fp),-252(fp),r0
5078 bicl3 #0,r0,-252(fp)
5079 cmpl -252(fp),-248(fp)
5080 bgequ noname.460
5081 incl -256(fp)
5082noname.460:
5083 movl -252(fp),r3
5084 movl -256(fp),r2
5085 bbc #31,r2,noname.461
5086 incl r9
5087noname.461:
5088 addl2 r2,r2
5089 bicl2 #0,r2
5090 bbc #31,r3,noname.462
5091 incl r2
5092noname.462:
5093 addl2 r3,r3
5094 bicl2 #0,r3
5095 addl2 r3,r8
5096 bicl2 #0,r8
5097 cmpl r8,r3
5098 bgequ noname.463
5099 incl r2
5100 bicl3 #0,r2,r0
5101 bneq noname.463
5102 incl r9
5103noname.463:
5104 addl2 r2,r7
5105 bicl2 #0,r7
5106 cmpl r7,r2
5107 bgequ noname.464
5108 incl r9
5109noname.464:
5110
5111 movl 8(ap),r0
5112 movzwl 22(r0),r2
5113 bicl3 #-65536,8(r0),r3
5114 movzwl 10(r0),r1
5115 bicl2 #-65536,r1
5116 bicl3 #-65536,20(r0),-268(fp)
5117 bicl3 #-65536,r2,-272(fp)
5118 mull3 r1,-268(fp),-260(fp)
5119 mull2 r3,-268(fp)
5120 mull3 r3,-272(fp),-264(fp)
5121 mull2 r1,-272(fp)
5122 addl3 -260(fp),-264(fp),r0
5123 bicl3 #0,r0,-260(fp)
5124 cmpl -260(fp),-264(fp)
5125 bgequ noname.465
5126 addl2 #65536,-272(fp)
5127noname.465:
5128 movzwl -258(fp),r0
5129 bicl2 #-65536,r0
5130 addl2 r0,-272(fp)
5131 bicl3 #-65536,-260(fp),r0
5132 ashl #16,r0,-264(fp)
5133 addl3 -264(fp),-268(fp),r0
5134 bicl3 #0,r0,-268(fp)
5135 cmpl -268(fp),-264(fp)
5136 bgequ noname.466
5137 incl -272(fp)
5138noname.466:
5139 movl -268(fp),r3
5140 movl -272(fp),r2
5141 bbc #31,r2,noname.467
5142 incl r9
5143noname.467:
5144 addl2 r2,r2
5145 bicl2 #0,r2
5146 bbc #31,r3,noname.468
5147 incl r2
5148noname.468:
5149 addl2 r3,r3
5150 bicl2 #0,r3
5151 addl2 r3,r8
5152 bicl2 #0,r8
5153 cmpl r8,r3
5154 bgequ noname.469
5155 incl r2
5156 bicl3 #0,r2,r0
5157 bneq noname.469
5158 incl r9
5159noname.469:
5160 addl2 r2,r7
5161 bicl2 #0,r7
5162 cmpl r7,r2
5163 bgequ noname.470
5164 incl r9
5165noname.470:
5166
5167 movl 8(ap),r0
5168 movzwl 18(r0),r2
5169 bicl3 #-65536,12(r0),r3
5170 movzwl 14(r0),r1
5171 bicl2 #-65536,r1
5172 bicl3 #-65536,16(r0),-284(fp)
5173 bicl3 #-65536,r2,-288(fp)
5174 mull3 r1,-284(fp),-276(fp)
5175 mull2 r3,-284(fp)
5176 mull3 r3,-288(fp),-280(fp)
5177 mull2 r1,-288(fp)
5178 addl3 -276(fp),-280(fp),r0
5179 bicl3 #0,r0,-276(fp)
5180 cmpl -276(fp),-280(fp)
5181 bgequ noname.471
5182 addl2 #65536,-288(fp)
5183noname.471:
5184 movzwl -274(fp),r0
5185 bicl2 #-65536,r0
5186 addl2 r0,-288(fp)
5187 bicl3 #-65536,-276(fp),r0
5188 ashl #16,r0,-280(fp)
5189 addl3 -280(fp),-284(fp),r0
5190 bicl3 #0,r0,-284(fp)
5191 cmpl -284(fp),-280(fp)
5192 bgequ noname.472
5193 incl -288(fp)
5194noname.472:
5195 movl -284(fp),r3
5196 movl -288(fp),r2
5197 bbc #31,r2,noname.473
5198 incl r9
5199noname.473:
5200 addl2 r2,r2
5201 bicl2 #0,r2
5202 bbc #31,r3,noname.474
5203 incl r2
5204noname.474:
5205 addl2 r3,r3
5206 bicl2 #0,r3
5207 addl2 r3,r8
5208 bicl2 #0,r8
5209 cmpl r8,r3
5210 bgequ noname.475
5211 incl r2
5212 bicl3 #0,r2,r0
5213 bneq noname.475
5214 incl r9
5215noname.475:
5216 addl2 r2,r7
5217 bicl2 #0,r7
5218 cmpl r7,r2
5219 bgequ noname.476
5220 incl r9
5221noname.476:
5222
5223 movl 4(ap),r0
5224 movl r8,28(r0)
5225
5226 clrl r8
5227
5228 movl 8(ap),r3
5229 movl 16(r3),r4
5230 bicl3 #-65536,r4,r5
5231 extzv #16,#16,r4,r0
5232 bicl3 #-65536,r0,r4
5233 mull3 r5,r4,-292(fp)
5234 mull2 r5,r5
5235 mull2 r4,r4
5236 bicl3 #32767,-292(fp),r0
5237 extzv #15,#17,r0,r0
5238 addl2 r0,r4
5239 bicl3 #-65536,-292(fp),r0
5240 ashl #17,r0,-292(fp)
5241 addl2 -292(fp),r5
5242 bicl2 #0,r5
5243 cmpl r5,-292(fp)
5244 bgequ noname.477
5245 incl r4
5246noname.477:
5247 movl r5,r1
5248 movl r4,r2
5249 addl2 r1,r7
5250 bicl2 #0,r7
5251 cmpl r7,r1
5252 bgequ noname.478
5253 incl r2
5254noname.478:
5255 addl2 r2,r9
5256 bicl2 #0,r9
5257 cmpl r9,r2
5258 bgequ noname.479
5259 incl r8
5260noname.479:
5261
5262 bicl3 #-65536,20(r3),r4
5263 movzwl 22(r3),r1
5264 bicl2 #-65536,r1
5265 bicl3 #-65536,12(r3),r2
5266 movzwl 14(r3),r0
5267 bicl2 #-65536,r0
5268 movl r4,r6
5269 movl r1,r5
5270 mull3 r0,r6,-296(fp)
5271 mull2 r2,r6
5272 mull3 r2,r5,-300(fp)
5273 mull2 r0,r5
5274 addl3 -296(fp),-300(fp),r0
5275 bicl3 #0,r0,-296(fp)
5276 cmpl -296(fp),-300(fp)
5277 bgequ noname.480
5278 addl2 #65536,r5
5279noname.480:
5280 movzwl -294(fp),r0
5281 bicl2 #-65536,r0
5282 addl2 r0,r5
5283 bicl3 #-65536,-296(fp),r0
5284 ashl #16,r0,-300(fp)
5285 addl2 -300(fp),r6
5286 bicl2 #0,r6
5287 cmpl r6,-300(fp)
5288 bgequ noname.481
5289 incl r5
5290noname.481:
5291 movl r6,r3
5292 movl r5,r2
5293 bbc #31,r2,noname.482
5294 incl r8
5295noname.482:
5296 addl2 r2,r2
5297 bicl2 #0,r2
5298 bbc #31,r3,noname.483
5299 incl r2
5300noname.483:
5301 addl2 r3,r3
5302 bicl2 #0,r3
5303 addl2 r3,r7
5304 bicl2 #0,r7
5305 cmpl r7,r3
5306 bgequ noname.484
5307 incl r2
5308 bicl3 #0,r2,r0
5309 bneq noname.484
5310 incl r8
5311noname.484:
5312 addl2 r2,r9
5313 bicl2 #0,r9
5314 cmpl r9,r2
5315 bgequ noname.485
5316 incl r8
5317noname.485:
5318
5319 movl 8(ap),r0
5320 bicl3 #-65536,24(r0),r3
5321 movzwl 26(r0),r1
5322 bicl2 #-65536,r1
5323 bicl3 #-65536,8(r0),r2
5324 movzwl 10(r0),r0
5325 bicl2 #-65536,r0
5326 movl r3,r5
5327 movl r1,r4
5328 mull3 r0,r5,-304(fp)
5329 mull2 r2,r5
5330 mull3 r2,r4,-308(fp)
5331 mull2 r0,r4
5332 addl3 -304(fp),-308(fp),r0
5333 bicl3 #0,r0,-304(fp)
5334 cmpl -304(fp),-308(fp)
5335 bgequ noname.486
5336 addl2 #65536,r4
5337noname.486:
5338 movzwl -302(fp),r0
5339 bicl2 #-65536,r0
5340 addl2 r0,r4
5341 bicl3 #-65536,-304(fp),r0
5342 ashl #16,r0,-308(fp)
5343 addl2 -308(fp),r5
5344 bicl2 #0,r5
5345 cmpl r5,-308(fp)
5346 bgequ noname.487
5347 incl r4
5348noname.487:
5349 movl r5,r3
5350 movl r4,r2
5351 bbc #31,r2,noname.488
5352 incl r8
5353noname.488:
5354 addl2 r2,r2
5355 bicl2 #0,r2
5356 bbc #31,r3,noname.489
5357 incl r2
5358noname.489:
5359 addl2 r3,r3
5360 bicl2 #0,r3
5361 addl2 r3,r7
5362 bicl2 #0,r7
5363 cmpl r7,r3
5364 bgequ noname.490
5365 incl r2
5366 bicl3 #0,r2,r0
5367 bneq noname.490
5368 incl r8
5369noname.490:
5370 addl2 r2,r9
5371 bicl2 #0,r9
5372 cmpl r9,r2
5373 bgequ noname.491
5374 incl r8
5375noname.491:
5376
5377 movl 8(ap),r0
5378 bicl3 #-65536,28(r0),r3
5379 movzwl 30(r0),r1
5380 bicl2 #-65536,r1
5381 bicl3 #-65536,4(r0),r2
5382 movzwl 6(r0),r0
5383 bicl2 #-65536,r0
5384 movl r3,r5
5385 movl r1,r4
5386 mull3 r0,r5,-312(fp)
5387 mull2 r2,r5
5388 mull3 r2,r4,-316(fp)
5389 mull2 r0,r4
5390 addl3 -312(fp),-316(fp),r0
5391 bicl3 #0,r0,-312(fp)
5392 cmpl -312(fp),-316(fp)
5393 bgequ noname.492
5394 addl2 #65536,r4
5395noname.492:
5396 movzwl -310(fp),r0
5397 bicl2 #-65536,r0
5398 addl2 r0,r4
5399 bicl3 #-65536,-312(fp),r0
5400 ashl #16,r0,-316(fp)
5401 addl2 -316(fp),r5
5402 bicl2 #0,r5
5403 cmpl r5,-316(fp)
5404 bgequ noname.493
5405 incl r4
5406noname.493:
5407 movl r5,r3
5408 movl r4,r2
5409 bbc #31,r2,noname.494
5410 incl r8
5411noname.494:
5412 addl2 r2,r2
5413 bicl2 #0,r2
5414 bbc #31,r3,noname.495
5415 incl r2
5416noname.495:
5417 addl2 r3,r3
5418 bicl2 #0,r3
5419 addl2 r3,r7
5420 bicl2 #0,r7
5421 cmpl r7,r3
5422 bgequ noname.496
5423 incl r2
5424 bicl3 #0,r2,r0
5425 bneq noname.496
5426 incl r8
5427noname.496:
5428 addl2 r2,r9
5429 bicl2 #0,r9
5430 cmpl r9,r2
5431 bgequ noname.497
5432 incl r8
5433noname.497:
5434
5435 movl 4(ap),r0
5436 movl r7,32(r0)
5437
5438 clrl r7
5439
5440 movl 8(ap),r0
5441 bicl3 #-65536,28(r0),r3
5442 movzwl 30(r0),r2
5443 bicl3 #-65536,8(r0),r1
5444 movzwl 10(r0),r0
5445 bicl2 #-65536,r0
5446 movl r3,r4
5447 bicl3 #-65536,r2,-328(fp)
5448 mull3 r0,r4,-320(fp)
5449 mull2 r1,r4
5450 mull3 r1,-328(fp),-324(fp)
5451 mull2 r0,-328(fp)
5452 addl3 -320(fp),-324(fp),r0
5453 bicl3 #0,r0,-320(fp)
5454 cmpl -320(fp),-324(fp)
5455 bgequ noname.498
5456 addl2 #65536,-328(fp)
5457noname.498:
5458 movzwl -318(fp),r0
5459 bicl2 #-65536,r0
5460 addl2 r0,-328(fp)
5461 bicl3 #-65536,-320(fp),r0
5462 ashl #16,r0,-324(fp)
5463 addl2 -324(fp),r4
5464 bicl2 #0,r4
5465 cmpl r4,-324(fp)
5466 bgequ noname.499
5467 incl -328(fp)
5468noname.499:
5469 movl r4,r3
5470 movl -328(fp),r2
5471 bbc #31,r2,noname.500
5472 incl r7
5473noname.500:
5474 addl2 r2,r2
5475 bicl2 #0,r2
5476 bbc #31,r3,noname.501
5477 incl r2
5478noname.501:
5479 addl2 r3,r3
5480 bicl2 #0,r3
5481 addl2 r3,r9
5482 bicl2 #0,r9
5483 cmpl r9,r3
5484 bgequ noname.502
5485 incl r2
5486 bicl3 #0,r2,r0
5487 bneq noname.502
5488 incl r7
5489noname.502:
5490 addl2 r2,r8
5491 bicl2 #0,r8
5492 cmpl r8,r2
5493 bgequ noname.503
5494 incl r7
5495noname.503:
5496
5497 movl 8(ap),r0
5498 movzwl 26(r0),r2
5499 bicl3 #-65536,12(r0),r3
5500 movzwl 14(r0),r1
5501 bicl2 #-65536,r1
5502 bicl3 #-65536,24(r0),-340(fp)
5503 bicl3 #-65536,r2,-344(fp)
5504 mull3 r1,-340(fp),-332(fp)
5505 mull2 r3,-340(fp)
5506 mull3 r3,-344(fp),-336(fp)
5507 mull2 r1,-344(fp)
5508 addl3 -332(fp),-336(fp),r0
5509 bicl3 #0,r0,-332(fp)
5510 cmpl -332(fp),-336(fp)
5511 bgequ noname.504
5512 addl2 #65536,-344(fp)
5513noname.504:
5514 movzwl -330(fp),r0
5515 bicl2 #-65536,r0
5516 addl2 r0,-344(fp)
5517 bicl3 #-65536,-332(fp),r0
5518 ashl #16,r0,-336(fp)
5519 addl3 -336(fp),-340(fp),r0
5520 bicl3 #0,r0,-340(fp)
5521 cmpl -340(fp),-336(fp)
5522 bgequ noname.505
5523 incl -344(fp)
5524noname.505:
5525 movl -340(fp),r3
5526 movl -344(fp),r2
5527 bbc #31,r2,noname.506
5528 incl r7
5529noname.506:
5530 addl2 r2,r2
5531 bicl2 #0,r2
5532 bbc #31,r3,noname.507
5533 incl r2
5534noname.507:
5535 addl2 r3,r3
5536 bicl2 #0,r3
5537 addl2 r3,r9
5538 bicl2 #0,r9
5539 cmpl r9,r3
5540 bgequ noname.508
5541 incl r2
5542 bicl3 #0,r2,r0
5543 bneq noname.508
5544 incl r7
5545noname.508:
5546 addl2 r2,r8
5547 bicl2 #0,r8
5548 cmpl r8,r2
5549 bgequ noname.509
5550 incl r7
5551noname.509:
5552
5553 movl 8(ap),r0
5554 movzwl 22(r0),r2
5555 bicl3 #-65536,16(r0),r3
5556 movzwl 18(r0),r1
5557 bicl2 #-65536,r1
5558 bicl3 #-65536,20(r0),-356(fp)
5559 bicl3 #-65536,r2,-360(fp)
5560 mull3 r1,-356(fp),-348(fp)
5561 mull2 r3,-356(fp)
5562 mull3 r3,-360(fp),-352(fp)
5563 mull2 r1,-360(fp)
5564 addl3 -348(fp),-352(fp),r0
5565 bicl3 #0,r0,-348(fp)
5566 cmpl -348(fp),-352(fp)
5567 bgequ noname.510
5568 addl2 #65536,-360(fp)
5569noname.510:
5570 movzwl -346(fp),r0
5571 bicl2 #-65536,r0
5572 addl2 r0,-360(fp)
5573 bicl3 #-65536,-348(fp),r0
5574 ashl #16,r0,-352(fp)
5575 addl3 -352(fp),-356(fp),r0
5576 bicl3 #0,r0,-356(fp)
5577 cmpl -356(fp),-352(fp)
5578 bgequ noname.511
5579 incl -360(fp)
5580noname.511:
5581 movl -356(fp),r3
5582 movl -360(fp),r2
5583 bbc #31,r2,noname.512
5584 incl r7
5585noname.512:
5586 addl2 r2,r2
5587 bicl2 #0,r2
5588 bbc #31,r3,noname.513
5589 incl r2
5590noname.513:
5591 addl2 r3,r3
5592 bicl2 #0,r3
5593 addl2 r3,r9
5594 bicl2 #0,r9
5595 cmpl r9,r3
5596 bgequ noname.514
5597 incl r2
5598 bicl3 #0,r2,r0
5599 bneq noname.514
5600 incl r7
5601noname.514:
5602 addl2 r2,r8
5603 bicl2 #0,r8
5604 cmpl r8,r2
5605 bgequ noname.515
5606 incl r7
5607noname.515:
5608
5609 movl 4(ap),r0
5610 movl r9,36(r0)
5611
5612 clrl r9
5613
5614 movl 8(ap),r3
5615 movl 20(r3),r4
5616 bicl3 #-65536,r4,-364(fp)
5617 extzv #16,#16,r4,r0
5618 bicl3 #-65536,r0,r4
5619 movl -364(fp),r0
5620 mull3 r0,r4,-368(fp)
5621 mull3 r0,r0,-364(fp)
5622 mull2 r4,r4
5623 bicl3 #32767,-368(fp),r0
5624 extzv #15,#17,r0,r0
5625 addl2 r0,r4
5626 bicl3 #-65536,-368(fp),r0
5627 ashl #17,r0,-368(fp)
5628 addl3 -364(fp),-368(fp),r0
5629 bicl3 #0,r0,-364(fp)
5630 cmpl -364(fp),-368(fp)
5631 bgequ noname.516
5632 incl r4
5633noname.516:
5634 movl -364(fp),r1
5635 movl r4,r2
5636 addl2 r1,r8
5637 bicl2 #0,r8
5638 cmpl r8,r1
5639 bgequ noname.517
5640 incl r2
5641noname.517:
5642 addl2 r2,r7
5643 bicl2 #0,r7
5644 cmpl r7,r2
5645 bgequ noname.518
5646 incl r9
5647noname.518:
5648
5649 bicl3 #-65536,24(r3),r4
5650 movzwl 26(r3),r1
5651 bicl2 #-65536,r1
5652 bicl3 #-65536,16(r3),r2
5653 movzwl 18(r3),r0
5654 bicl2 #-65536,r0
5655 movl r4,r6
5656 movl r1,r5
5657 mull3 r0,r6,-372(fp)
5658 mull2 r2,r6
5659 mull3 r2,r5,-376(fp)
5660 mull2 r0,r5
5661 addl3 -372(fp),-376(fp),r0
5662 bicl3 #0,r0,-372(fp)
5663 cmpl -372(fp),-376(fp)
5664 bgequ noname.519
5665 addl2 #65536,r5
5666noname.519:
5667 movzwl -370(fp),r0
5668 bicl2 #-65536,r0
5669 addl2 r0,r5
5670 bicl3 #-65536,-372(fp),r0
5671 ashl #16,r0,-376(fp)
5672 addl2 -376(fp),r6
5673 bicl2 #0,r6
5674 cmpl r6,-376(fp)
5675 bgequ noname.520
5676 incl r5
5677noname.520:
5678 movl r6,r3
5679 movl r5,r2
5680 bbc #31,r2,noname.521
5681 incl r9
5682noname.521:
5683 addl2 r2,r2
5684 bicl2 #0,r2
5685 bbc #31,r3,noname.522
5686 incl r2
5687noname.522:
5688 addl2 r3,r3
5689 bicl2 #0,r3
5690 addl2 r3,r8
5691 bicl2 #0,r8
5692 cmpl r8,r3
5693 bgequ noname.523
5694 incl r2
5695 bicl3 #0,r2,r0
5696 bneq noname.523
5697 incl r9
5698noname.523:
5699 addl2 r2,r7
5700 bicl2 #0,r7
5701 cmpl r7,r2
5702 bgequ noname.524
5703 incl r9
5704noname.524:
5705
5706 movl 8(ap),r0
5707 bicl3 #-65536,28(r0),r3
5708 movzwl 30(r0),r1
5709 bicl2 #-65536,r1
5710 bicl3 #-65536,12(r0),r2
5711 movzwl 14(r0),r0
5712 bicl2 #-65536,r0
5713 movl r3,r5
5714 movl r1,r4
5715 mull3 r0,r5,-380(fp)
5716 mull2 r2,r5
5717 mull3 r2,r4,-384(fp)
5718 mull2 r0,r4
5719 addl3 -380(fp),-384(fp),r0
5720 bicl3 #0,r0,-380(fp)
5721 cmpl -380(fp),-384(fp)
5722 bgequ noname.525
5723 addl2 #65536,r4
5724noname.525:
5725 movzwl -378(fp),r0
5726 bicl2 #-65536,r0
5727 addl2 r0,r4
5728 bicl3 #-65536,-380(fp),r0
5729 ashl #16,r0,-384(fp)
5730 addl2 -384(fp),r5
5731 bicl2 #0,r5
5732 cmpl r5,-384(fp)
5733 bgequ noname.526
5734 incl r4
5735noname.526:
5736 movl r5,r3
5737 movl r4,r2
5738 bbc #31,r2,noname.527
5739 incl r9
5740noname.527:
5741 addl2 r2,r2
5742 bicl2 #0,r2
5743 bbc #31,r3,noname.528
5744 incl r2
5745noname.528:
5746 addl2 r3,r3
5747 bicl2 #0,r3
5748 addl2 r3,r8
5749 bicl2 #0,r8
5750 cmpl r8,r3
5751 bgequ noname.529
5752 incl r2
5753 bicl3 #0,r2,r0
5754 bneq noname.529
5755 incl r9
5756noname.529:
5757 addl2 r2,r7
5758 bicl2 #0,r7
5759 cmpl r7,r2
5760 bgequ noname.530
5761 incl r9
5762noname.530:
5763 movl 4(ap),r0
5764 movl r8,40(r0)
5765
5766 clrl r8
5767
5768 movl 8(ap),r0
5769 bicl3 #-65536,28(r0),r3
5770 movzwl 30(r0),r1
5771 bicl2 #-65536,r1
5772 bicl3 #-65536,16(r0),r2
5773 movzwl 18(r0),r0
5774 bicl2 #-65536,r0
5775 movl r3,r5
5776 movl r1,r4
5777 mull3 r0,r5,-388(fp)
5778 mull2 r2,r5
5779 mull3 r2,r4,-392(fp)
5780 mull2 r0,r4
5781 addl3 -388(fp),-392(fp),r0
5782 bicl3 #0,r0,-388(fp)
5783 cmpl -388(fp),-392(fp)
5784 bgequ noname.531
5785 addl2 #65536,r4
5786noname.531:
5787 movzwl -386(fp),r0
5788 bicl2 #-65536,r0
5789 addl2 r0,r4
5790 bicl3 #-65536,-388(fp),r0
5791 ashl #16,r0,-392(fp)
5792 addl2 -392(fp),r5
5793 bicl2 #0,r5
5794 cmpl r5,-392(fp)
5795 bgequ noname.532
5796 incl r4
5797noname.532:
5798 movl r5,r3
5799 movl r4,r2
5800 bbc #31,r2,noname.533
5801 incl r8
5802noname.533:
5803 addl2 r2,r2
5804 bicl2 #0,r2
5805 bbc #31,r3,noname.534
5806 incl r2
5807noname.534:
5808 addl2 r3,r3
5809 bicl2 #0,r3
5810 addl2 r3,r7
5811 bicl2 #0,r7
5812 cmpl r7,r3
5813 bgequ noname.535
5814 incl r2
5815 bicl3 #0,r2,r0
5816 bneq noname.535
5817 incl r8
5818noname.535:
5819 addl2 r2,r9
5820 bicl2 #0,r9
5821 cmpl r9,r2
5822 bgequ noname.536
5823 incl r8
5824noname.536:
5825
5826 movl 8(ap),r0
5827 bicl3 #-65536,24(r0),r3
5828 movzwl 26(r0),r1
5829 bicl2 #-65536,r1
5830 bicl3 #-65536,20(r0),r2
5831 movzwl 22(r0),r0
5832 bicl2 #-65536,r0
5833 movl r3,r5
5834 movl r1,r4
5835 mull3 r0,r5,-396(fp)
5836 mull2 r2,r5
5837 mull3 r2,r4,-400(fp)
5838 mull2 r0,r4
5839 addl3 -396(fp),-400(fp),r0
5840 bicl3 #0,r0,-396(fp)
5841 cmpl -396(fp),-400(fp)
5842 bgequ noname.537
5843 addl2 #65536,r4
5844noname.537:
5845 movzwl -394(fp),r0
5846 bicl2 #-65536,r0
5847 addl2 r0,r4
5848 bicl3 #-65536,-396(fp),r0
5849 ashl #16,r0,-400(fp)
5850 addl2 -400(fp),r5
5851 bicl2 #0,r5
5852 cmpl r5,-400(fp)
5853 bgequ noname.538
5854 incl r4
5855noname.538:
5856 movl r5,r3
5857 movl r4,r2
5858 bbc #31,r2,noname.539
5859 incl r8
5860noname.539:
5861 addl2 r2,r2
5862 bicl2 #0,r2
5863 bbc #31,r3,noname.540
5864 incl r2
5865noname.540:
5866 addl2 r3,r3
5867 bicl2 #0,r3
5868 addl2 r3,r7
5869 bicl2 #0,r7
5870 cmpl r7,r3
5871 bgequ noname.541
5872 incl r2
5873 bicl3 #0,r2,r0
5874 bneq noname.541
5875 incl r8
5876noname.541:
5877 addl2 r2,r9
5878 bicl2 #0,r9
5879 cmpl r9,r2
5880 bgequ noname.542
5881 incl r8
5882noname.542:
5883
5884 movl 4(ap),r0
5885 movl r7,44(r0)
5886
5887 clrl r7
5888
5889 movl 8(ap),r3
5890 movl 24(r3),r4
5891 bicl3 #-65536,r4,r5
5892 extzv #16,#16,r4,r0
5893 bicl3 #-65536,r0,r4
5894 mull3 r5,r4,-404(fp)
5895 mull2 r5,r5
5896 mull2 r4,r4
5897 bicl3 #32767,-404(fp),r0
5898 extzv #15,#17,r0,r0
5899 addl2 r0,r4
5900 bicl3 #-65536,-404(fp),r0
5901 ashl #17,r0,-404(fp)
5902 addl2 -404(fp),r5
5903 bicl2 #0,r5
5904 cmpl r5,-404(fp)
5905 bgequ noname.543
5906 incl r4
5907noname.543:
5908 movl r5,r1
5909 movl r4,r2
5910 addl2 r1,r9
5911 bicl2 #0,r9
5912 cmpl r9,r1
5913 bgequ noname.544
5914 incl r2
5915noname.544:
5916 addl2 r2,r8
5917 bicl2 #0,r8
5918 cmpl r8,r2
5919 bgequ noname.545
5920 incl r7
5921noname.545:
5922
5923 movzwl 30(r3),r2
5924 bicl3 #-65536,20(r3),r1
5925 movzwl 22(r3),r0
5926 bicl2 #-65536,r0
5927 bicl3 #-65536,28(r3),-416(fp)
5928 bicl3 #-65536,r2,-420(fp)
5929 mull3 r0,-416(fp),-408(fp)
5930 mull2 r1,-416(fp)
5931 mull3 r1,-420(fp),-412(fp)
5932 mull2 r0,-420(fp)
5933 addl3 -408(fp),-412(fp),r0
5934 bicl3 #0,r0,-408(fp)
5935 cmpl -408(fp),-412(fp)
5936 bgequ noname.546
5937 addl2 #65536,-420(fp)
5938noname.546:
5939 movzwl -406(fp),r0
5940 bicl2 #-65536,r0
5941 addl2 r0,-420(fp)
5942 bicl3 #-65536,-408(fp),r0
5943 ashl #16,r0,-412(fp)
5944 addl3 -412(fp),-416(fp),r0
5945 bicl3 #0,r0,-416(fp)
5946 cmpl -416(fp),-412(fp)
5947 bgequ noname.547
5948 incl -420(fp)
5949noname.547:
5950 movl -416(fp),r3
5951 movl -420(fp),r2
5952 bbc #31,r2,noname.548
5953 incl r7
5954noname.548:
5955 addl2 r2,r2
5956 bicl2 #0,r2
5957 bbc #31,r3,noname.549
5958 incl r2
5959noname.549:
5960 addl2 r3,r3
5961 bicl2 #0,r3
5962 addl2 r3,r9
5963 bicl2 #0,r9
5964 cmpl r9,r3
5965 bgequ noname.550
5966 incl r2
5967 bicl3 #0,r2,r0
5968 bneq noname.550
5969 incl r7
5970noname.550:
5971 addl2 r2,r8
5972 bicl2 #0,r8
5973 cmpl r8,r2
5974 bgequ noname.551
5975 incl r7
5976noname.551:
5977
5978 movl 4(ap),r0
5979 movl r9,48(r0)
5980
5981 clrl r9
5982
5983 movl 8(ap),r0
5984 movzwl 30(r0),r2
5985 bicl3 #-65536,24(r0),r3
5986 movzwl 26(r0),r1
5987 bicl2 #-65536,r1
5988 bicl3 #-65536,28(r0),-432(fp)
5989 bicl3 #-65536,r2,-436(fp)
5990 mull3 r1,-432(fp),-424(fp)
5991 mull2 r3,-432(fp)
5992 mull3 r3,-436(fp),-428(fp)
5993 mull2 r1,-436(fp)
5994 addl3 -424(fp),-428(fp),r0
5995 bicl3 #0,r0,-424(fp)
5996 cmpl -424(fp),-428(fp)
5997 bgequ noname.552
5998 addl2 #65536,-436(fp)
5999noname.552:
6000 movzwl -422(fp),r0
6001 bicl2 #-65536,r0
6002 addl2 r0,-436(fp)
6003 bicl3 #-65536,-424(fp),r0
6004 ashl #16,r0,-428(fp)
6005 addl3 -428(fp),-432(fp),r0
6006 bicl3 #0,r0,-432(fp)
6007 cmpl -432(fp),-428(fp)
6008 bgequ noname.553
6009 incl -436(fp)
6010noname.553:
6011 movl -432(fp),r3
6012 movl -436(fp),r2
6013 bbc #31,r2,noname.554
6014 incl r9
6015noname.554:
6016 addl2 r2,r2
6017 bicl2 #0,r2
6018 bbc #31,r3,noname.555
6019 incl r2
6020noname.555:
6021 addl2 r3,r3
6022 bicl2 #0,r3
6023 addl2 r3,r8
6024 bicl2 #0,r8
6025 cmpl r8,r3
6026 bgequ noname.556
6027 incl r2
6028 bicl3 #0,r2,r0
6029 bneq noname.556
6030 incl r9
6031noname.556:
6032 addl2 r2,r7
6033 bicl2 #0,r7
6034 cmpl r7,r2
6035 bgequ noname.557
6036 incl r9
6037noname.557:
6038
6039 movl 4(ap),r4
6040 movl r8,52(r4)
6041
6042 clrl r8
6043
6044 movl 8(ap),r0
6045 movl 28(r0),r3
6046 bicl3 #-65536,r3,-440(fp)
6047 extzv #16,#16,r3,r0
6048 bicl3 #-65536,r0,r3
6049 movl -440(fp),r0
6050 mull3 r0,r3,-444(fp)
6051 mull3 r0,r0,-440(fp)
6052 mull2 r3,r3
6053 bicl3 #32767,-444(fp),r0
6054 extzv #15,#17,r0,r0
6055 addl2 r0,r3
6056 bicl3 #-65536,-444(fp),r0
6057 ashl #17,r0,-444(fp)
6058 addl3 -440(fp),-444(fp),r0
6059 bicl3 #0,r0,-440(fp)
6060 cmpl -440(fp),-444(fp)
6061 bgequ noname.558
6062 incl r3
6063noname.558:
6064 movl -440(fp),r1
6065 movl r3,r2
6066 addl2 r1,r7
6067 bicl2 #0,r7
6068 cmpl r7,r1
6069 bgequ noname.559
6070 incl r2
6071noname.559:
6072 addl2 r2,r9
6073 bicl2 #0,r9
6074 cmpl r9,r2
6075 bgequ noname.560
6076 incl r8
6077noname.560:
6078
6079 movl r7,56(r4)
6080
6081 movl r9,60(r4)
6082
6083 ret
6084
6085
6086
6087;r=4 ;(AP)
6088;a=8 ;(AP)
6089;b=12 ;(AP)
6090;n=16 ;(AP) n by value (input)
6091
6092 .psect code,nowrt
6093
6094.entry BN_SQR_COMBA4,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10>
6095 subl2 #44,sp
6096
6097 clrq r8
6098
6099 clrl r10
6100
6101 movl 8(ap),r5
6102 movl (r5),r3
6103 bicl3 #-65536,r3,r4
6104 extzv #16,#16,r3,r0
6105 bicl3 #-65536,r0,r3
6106 mull3 r4,r3,-4(fp)
6107 mull2 r4,r4
6108 mull2 r3,r3
6109 bicl3 #32767,-4(fp),r0
6110 extzv #15,#17,r0,r0
6111 addl2 r0,r3
6112 bicl3 #-65536,-4(fp),r0
6113 ashl #17,r0,-4(fp)
6114 addl2 -4(fp),r4
6115 bicl2 #0,r4
6116 cmpl r4,-4(fp)
6117 bgequ noname.563
6118 incl r3
6119noname.563:
6120 movl r4,r1
6121 movl r3,r2
6122 addl2 r1,r9
6123 bicl2 #0,r9
6124 cmpl r9,r1
6125 bgequ noname.564
6126 incl r2
6127noname.564:
6128 addl2 r2,r8
6129 bicl2 #0,r8
6130 cmpl r8,r2
6131 bgequ noname.565
6132 incl r10
6133noname.565:
6134
6135 movl r9,@4(ap)
6136
6137 clrl r9
6138
6139 bicl3 #-65536,4(r5),r3
6140 movzwl 6(r5),r1
6141 bicl2 #-65536,r1
6142 bicl3 #-65536,(r5),r2
6143 movzwl 2(r5),r0
6144 bicl2 #-65536,r0
6145 movl r3,r6
6146 movl r1,r4
6147 mull3 r0,r6,-8(fp)
6148 mull2 r2,r6
6149 mull2 r4,r2
6150 mull2 r0,r4
6151 addl3 -8(fp),r2,r0
6152 bicl3 #0,r0,-8(fp)
6153 cmpl -8(fp),r2
6154 bgequ noname.566
6155 addl2 #65536,r4
6156noname.566:
6157 movzwl -6(fp),r0
6158 bicl2 #-65536,r0
6159 addl2 r0,r4
6160 bicl3 #-65536,-8(fp),r0
6161 ashl #16,r0,r1
6162 addl2 r1,r6
6163 bicl2 #0,r6
6164 cmpl r6,r1
6165 bgequ noname.567
6166 incl r4
6167noname.567:
6168 movl r6,r3
6169 movl r4,r2
6170 bbc #31,r2,noname.568
6171 incl r9
6172noname.568:
6173 addl2 r2,r2
6174 bicl2 #0,r2
6175 bbc #31,r3,noname.569
6176 incl r2
6177noname.569:
6178 addl2 r3,r3
6179 bicl2 #0,r3
6180 addl2 r3,r8
6181 bicl2 #0,r8
6182 cmpl r8,r3
6183 bgequ noname.570
6184 incl r2
6185 bicl3 #0,r2,r0
6186 bneq noname.570
6187 incl r9
6188noname.570:
6189 addl2 r2,r10
6190 bicl2 #0,r10
6191 cmpl r10,r2
6192 bgequ noname.571
6193 incl r9
6194noname.571:
6195
6196 movl 4(ap),r0
6197 movl r8,4(r0)
6198
6199 clrl r8
6200
6201 movl 8(ap),r4
6202 movl 4(r4),r3
6203 bicl3 #-65536,r3,r5
6204 extzv #16,#16,r3,r0
6205 bicl3 #-65536,r0,r3
6206 mull3 r5,r3,r1
6207 mull2 r5,r5
6208 mull2 r3,r3
6209 bicl3 #32767,r1,r0
6210 extzv #15,#17,r0,r0
6211 addl2 r0,r3
6212 bicl2 #-65536,r1
6213 ashl #17,r1,r1
6214 addl2 r1,r5
6215 bicl2 #0,r5
6216 cmpl r5,r1
6217 bgequ noname.572
6218 incl r3
6219noname.572:
6220 movl r5,r1
6221 movl r3,r2
6222 addl2 r1,r10
6223 bicl2 #0,r10
6224 cmpl r10,r1
6225 bgequ noname.573
6226 incl r2
6227noname.573:
6228 addl2 r2,r9
6229 bicl2 #0,r9
6230 cmpl r9,r2
6231 bgequ noname.574
6232 incl r8
6233noname.574:
6234
6235 bicl3 #-65536,8(r4),r3
6236 movzwl 10(r4),r1
6237 bicl2 #-65536,r1
6238 bicl3 #-65536,(r4),r2
6239 movzwl 2(r4),r0
6240 bicl2 #-65536,r0
6241 movl r3,r6
6242 movl r1,r5
6243 mull3 r0,r6,r7
6244 mull2 r2,r6
6245 mull2 r5,r2
6246 mull2 r0,r5
6247 addl2 r2,r7
6248 bicl2 #0,r7
6249 cmpl r7,r2
6250 bgequ noname.575
6251 addl2 #65536,r5
6252noname.575:
6253 extzv #16,#16,r7,r0
6254 bicl2 #-65536,r0
6255 addl2 r0,r5
6256 bicl3 #-65536,r7,r0
6257 ashl #16,r0,r1
6258 addl2 r1,r6
6259 bicl2 #0,r6
6260 cmpl r6,r1
6261 bgequ noname.576
6262 incl r5
6263noname.576:
6264 movl r6,r3
6265 movl r5,r2
6266 bbc #31,r2,noname.577
6267 incl r8
6268noname.577:
6269 addl2 r2,r2
6270 bicl2 #0,r2
6271 bbc #31,r3,noname.578
6272 incl r2
6273noname.578:
6274 addl2 r3,r3
6275 bicl2 #0,r3
6276 addl2 r3,r10
6277 bicl2 #0,r10
6278 cmpl r10,r3
6279 bgequ noname.579
6280 incl r2
6281 bicl3 #0,r2,r0
6282 bneq noname.579
6283 incl r8
6284noname.579:
6285 addl2 r2,r9
6286 bicl2 #0,r9
6287 cmpl r9,r2
6288 bgequ noname.580
6289 incl r8
6290noname.580:
6291
6292 movl 4(ap),r0
6293 movl r10,8(r0)
6294
6295 clrl r10
6296
6297 movl 8(ap),r0
6298 bicl3 #-65536,12(r0),r3
6299 movzwl 14(r0),r1
6300 bicl2 #-65536,r1
6301 bicl3 #-65536,(r0),r2
6302 movzwl 2(r0),r0
6303 bicl2 #-65536,r0
6304 movl r3,r5
6305 movl r1,r4
6306 mull3 r0,r5,r6
6307 mull2 r2,r5
6308 mull3 r2,r4,-12(fp)
6309 mull2 r0,r4
6310 addl2 -12(fp),r6
6311 bicl2 #0,r6
6312 cmpl r6,-12(fp)
6313 bgequ noname.581
6314 addl2 #65536,r4
6315noname.581:
6316 extzv #16,#16,r6,r0
6317 bicl2 #-65536,r0
6318 addl2 r0,r4
6319 bicl3 #-65536,r6,r0
6320 ashl #16,r0,-12(fp)
6321 addl2 -12(fp),r5
6322 bicl2 #0,r5
6323 cmpl r5,-12(fp)
6324 bgequ noname.582
6325 incl r4
6326noname.582:
6327 movl r5,r3
6328 movl r4,r2
6329 bbc #31,r2,noname.583
6330 incl r10
6331noname.583:
6332 addl2 r2,r2
6333 bicl2 #0,r2
6334 bbc #31,r3,noname.584
6335 incl r2
6336noname.584:
6337 addl2 r3,r3
6338 bicl2 #0,r3
6339 addl2 r3,r9
6340 bicl2 #0,r9
6341 cmpl r9,r3
6342 bgequ noname.585
6343 incl r2
6344 bicl3 #0,r2,r0
6345 bneq noname.585
6346 incl r10
6347noname.585:
6348 addl2 r2,r8
6349 bicl2 #0,r8
6350 cmpl r8,r2
6351 bgequ noname.586
6352 incl r10
6353noname.586:
6354
6355 movl 8(ap),r0
6356 bicl3 #-65536,8(r0),r3
6357 movzwl 10(r0),r1
6358 bicl2 #-65536,r1
6359 bicl3 #-65536,4(r0),r2
6360 movzwl 6(r0),r0
6361 bicl2 #-65536,r0
6362 movl r3,r5
6363 movl r1,r4
6364 mull3 r0,r5,-16(fp)
6365 mull2 r2,r5
6366 mull3 r2,r4,-20(fp)
6367 mull2 r0,r4
6368 addl3 -16(fp),-20(fp),r0
6369 bicl3 #0,r0,-16(fp)
6370 cmpl -16(fp),-20(fp)
6371 bgequ noname.587
6372 addl2 #65536,r4
6373noname.587:
6374 movzwl -14(fp),r0
6375 bicl2 #-65536,r0
6376 addl2 r0,r4
6377 bicl3 #-65536,-16(fp),r0
6378 ashl #16,r0,-20(fp)
6379 addl2 -20(fp),r5
6380 bicl2 #0,r5
6381 cmpl r5,-20(fp)
6382 bgequ noname.588
6383 incl r4
6384noname.588:
6385 movl r5,r3
6386 movl r4,r2
6387 bbc #31,r2,noname.589
6388 incl r10
6389noname.589:
6390 addl2 r2,r2
6391 bicl2 #0,r2
6392 bbc #31,r3,noname.590
6393 incl r2
6394noname.590:
6395 addl2 r3,r3
6396 bicl2 #0,r3
6397 addl2 r3,r9
6398 bicl2 #0,r9
6399 cmpl r9,r3
6400 bgequ noname.591
6401 incl r2
6402 bicl3 #0,r2,r0
6403 bneq noname.591
6404 incl r10
6405noname.591:
6406 addl2 r2,r8
6407 bicl2 #0,r8
6408 cmpl r8,r2
6409 bgequ noname.592
6410 incl r10
6411noname.592:
6412 movl 4(ap),r0
6413 movl r9,12(r0)
6414
6415 clrl r9
6416
6417 movl 8(ap),r3
6418 movl 8(r3),r4
6419 bicl3 #-65536,r4,r5
6420 extzv #16,#16,r4,r0
6421 bicl3 #-65536,r0,r4
6422 mull3 r5,r4,-24(fp)
6423 mull2 r5,r5
6424 mull2 r4,r4
6425 bicl3 #32767,-24(fp),r0
6426 extzv #15,#17,r0,r0
6427 addl2 r0,r4
6428 bicl3 #-65536,-24(fp),r0
6429 ashl #17,r0,-24(fp)
6430 addl2 -24(fp),r5
6431 bicl2 #0,r5
6432 cmpl r5,-24(fp)
6433 bgequ noname.593
6434 incl r4
6435noname.593:
6436 movl r5,r1
6437 movl r4,r2
6438 addl2 r1,r8
6439 bicl2 #0,r8
6440 cmpl r8,r1
6441 bgequ noname.594
6442 incl r2
6443noname.594:
6444 addl2 r2,r10
6445 bicl2 #0,r10
6446 cmpl r10,r2
6447 bgequ noname.595
6448 incl r9
6449noname.595:
6450
6451 bicl3 #-65536,12(r3),r4
6452 movzwl 14(r3),r1
6453 bicl2 #-65536,r1
6454 bicl3 #-65536,4(r3),r2
6455 movzwl 6(r3),r0
6456 bicl2 #-65536,r0
6457 movl r4,r6
6458 movl r1,r5
6459 mull3 r0,r6,-28(fp)
6460 mull2 r2,r6
6461 mull3 r2,r5,-32(fp)
6462 mull2 r0,r5
6463 addl3 -28(fp),-32(fp),r0
6464 bicl3 #0,r0,-28(fp)
6465 cmpl -28(fp),-32(fp)
6466 bgequ noname.596
6467 addl2 #65536,r5
6468noname.596:
6469 movzwl -26(fp),r0
6470 bicl2 #-65536,r0
6471 addl2 r0,r5
6472 bicl3 #-65536,-28(fp),r0
6473 ashl #16,r0,-32(fp)
6474 addl2 -32(fp),r6
6475 bicl2 #0,r6
6476 cmpl r6,-32(fp)
6477 bgequ noname.597
6478 incl r5
6479noname.597:
6480 movl r6,r3
6481 movl r5,r2
6482 bbc #31,r2,noname.598
6483 incl r9
6484noname.598:
6485 addl2 r2,r2
6486 bicl2 #0,r2
6487 bbc #31,r3,noname.599
6488 incl r2
6489noname.599:
6490 addl2 r3,r3
6491 bicl2 #0,r3
6492 addl2 r3,r8
6493 bicl2 #0,r8
6494 cmpl r8,r3
6495 bgequ noname.600
6496 incl r2
6497 bicl3 #0,r2,r0
6498 bneq noname.600
6499 incl r9
6500noname.600:
6501 addl2 r2,r10
6502 bicl2 #0,r10
6503 cmpl r10,r2
6504 bgequ noname.601
6505 incl r9
6506noname.601:
6507
6508 movl 4(ap),r0
6509 movl r8,16(r0)
6510
6511 clrl r8
6512
6513 movl 8(ap),r0
6514 bicl3 #-65536,12(r0),r3
6515 movzwl 14(r0),r1
6516 bicl2 #-65536,r1
6517 bicl3 #-65536,8(r0),r2
6518 movzwl 10(r0),r0
6519 bicl2 #-65536,r0
6520 movl r3,r5
6521 movl r1,r4
6522 mull3 r0,r5,-36(fp)
6523 mull2 r2,r5
6524 mull3 r2,r4,-40(fp)
6525 mull2 r0,r4
6526 addl3 -36(fp),-40(fp),r0
6527 bicl3 #0,r0,-36(fp)
6528 cmpl -36(fp),-40(fp)
6529 bgequ noname.602
6530 addl2 #65536,r4
6531noname.602:
6532 movzwl -34(fp),r0
6533 bicl2 #-65536,r0
6534 addl2 r0,r4
6535 bicl3 #-65536,-36(fp),r0
6536 ashl #16,r0,-40(fp)
6537 addl2 -40(fp),r5
6538 bicl2 #0,r5
6539 cmpl r5,-40(fp)
6540 bgequ noname.603
6541 incl r4
6542noname.603:
6543 movl r5,r3
6544 movl r4,r2
6545 bbc #31,r2,noname.604
6546 incl r8
6547noname.604:
6548 addl2 r2,r2
6549 bicl2 #0,r2
6550 bbc #31,r3,noname.605
6551 incl r2
6552noname.605:
6553 addl2 r3,r3
6554 bicl2 #0,r3
6555 addl2 r3,r10
6556 bicl2 #0,r10
6557 cmpl r10,r3
6558 bgequ noname.606
6559 incl r2
6560 bicl3 #0,r2,r0
6561 bneq noname.606
6562 incl r8
6563noname.606:
6564 addl2 r2,r9
6565 bicl2 #0,r9
6566 cmpl r9,r2
6567 bgequ noname.607
6568 incl r8
6569noname.607:
6570
6571 movl 4(ap),r4
6572 movl r10,20(r4)
6573
6574 clrl r10
6575
6576 movl 8(ap),r0
6577 movl 12(r0),r3
6578 bicl3 #-65536,r3,r5
6579 extzv #16,#16,r3,r0
6580 bicl3 #-65536,r0,r3
6581 mull3 r5,r3,-44(fp)
6582 mull2 r5,r5
6583 mull2 r3,r3
6584 bicl3 #32767,-44(fp),r0
6585 extzv #15,#17,r0,r0
6586 addl2 r0,r3
6587 bicl3 #-65536,-44(fp),r0
6588 ashl #17,r0,-44(fp)
6589 addl2 -44(fp),r5
6590 bicl2 #0,r5
6591 cmpl r5,-44(fp)
6592 bgequ noname.608
6593 incl r3
6594noname.608:
6595 movl r5,r1
6596 movl r3,r2
6597 addl2 r1,r9
6598 bicl2 #0,r9
6599 cmpl r9,r1
6600 bgequ noname.609
6601 incl r2
6602noname.609:
6603 addl2 r2,r8
6604 bicl2 #0,r8
6605 cmpl r8,r2
6606 bgequ noname.610
6607 incl r10
6608noname.610:
6609
6610 movl r9,24(r4)
6611
6612 movl r8,28(r4)
6613
6614 ret
6615
6616; For now, the code below doesn't work, so I end this prematurely.
6617.end
6618
6619 .title vax_bn_div64 division 64/32=>32
6620;
6621; r.l. 16-jan-1998
6622;
6623; unsigned int bn_div64(unsigned long h, unsigned long l, unsigned long d)
6624; return <h,l>/d;
6625;
6626
6627 .psect code,nowrt
6628
6629h=4 ;(AP) by value (input)
6630l=8 ;(AP) by value (input)
6631d=12 ;(AP) by value (input)
6632
6633.entry bn_div64,^m<r2,r3,r4,r5,r6,r7,r8,r9>
6634
6635 movl l(ap),r2 ; l
6636 movl h(ap),r3 ; h
6637 movl d(ap),r4 ; d
6638 clrl r5 ; q
6639 clrl r6 ; r
6640
6641 ; Treat "negative" specially
6642 tstl r3
6643 blss 30$
6644
6645 tstl r4
6646 beql 90$
6647
6648 ediv r4,r2,r5,r6
6649 bvs 666$
6650
6651 movl r5,r0
6652 ret
6653
665430$:
6655 ; The theory here is to do some harmless shifting and a little
6656 ; bit of rounding (brackets are to designate when decimals are
6657 ; cut off):
6658 ;
6659 ; result = 2 * [ ([<h,0>/2] + [d/2]) / d ] + [ l / d ]
6660
6661 movl #0,r7
6662 movl r3,r8 ; copy h
6663 ashq #-1,r7,r7 ; [<h,0>/2] => <r8,r7>
6664 bicl2 #^X80000000,r8 ; Remove "sign"
6665
6666 movl r4,r9 ; copy d
6667 ashl #-1,r9,r9 ; [d/2] => r9
6668 bicl2 #^X80000000,r9 ; Remove "sign"
6669
6670 addl2 r9,r7
6671 adwc #0,r8 ; [<h,0>/2] + [d/2] => <r8,r7>
6672
6673 ediv r4,r7,r5,r6 ; [ ([<h,0>/2] + [d/2]) / d ] => <r5,r6>
6674 bvs 666$
6675
6676 movl #0,r6
6677 ashq #1,r5,r5 ; 2 * [ ([<h,0>/2] + [d/2]) / d ] => r5
6678
6679 movl #0,r3
6680 ediv r4,r2,r8,r9 ; [ l / d ] => <r8,r9>
6681
6682 addl2 r8,r5 ;
6683 bcs 666$
6684
6685 movl r5,r0
6686 ret
6687
668890$:
6689 movl #-1,r0
6690 ret
6691
6692666$:
6693
6694
6695.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 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5
6require("x86/mul_add.pl");
7require("x86/mul.pl");
8require("x86/sqr.pl");
9require("x86/div.pl");
10require("x86/add.pl");
11require("x86/sub.pl");
12require("x86/comba.pl");
13
14&asm_init($ARGV[0],$0);
15
16&bn_mul_add_words("bn_mul_add_words");
17&bn_mul_words("bn_mul_words");
18&bn_sqr_words("bn_sqr_words");
19&bn_div_words("bn_div_words");
20&bn_add_words("bn_add_words");
21&bn_sub_words("bn_sub_words");
22&bn_mul_comba("bn_mul_comba8",8);
23&bn_mul_comba("bn_mul_comba4",4);
24&bn_sqr_comba("bn_sqr_comba8",8);
25&bn_sqr_comba("bn_sqr_comba4",4);
26
27&asm_finish();
28
diff --git a/src/lib/libcrypto/bn/asm/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'
6F_TEXT ENDS 6F_TEXT ENDS
7_DATA SEGMENT WORD PUBLIC 'DATA' 7_DATA SEGMENT WORD PUBLIC 'DATA'
8_DATA ENDS 8_DATA ENDS
9CONST SEGMENT WORD PUBLIC 'CONST' 9_CONST SEGMENT WORD PUBLIC 'CONST'
10CONST ENDS 10_CONST ENDS
11_BSS SEGMENT WORD PUBLIC 'BSS' 11_BSS SEGMENT WORD PUBLIC 'BSS'
12_BSS ENDS 12_BSS ENDS
13DGROUP GROUP CONST, _BSS, _DATA 13DGROUP GROUP _CONST, _BSS, _DATA
14 ASSUME DS: DGROUP, SS: DGROUP 14 ASSUME DS: DGROUP, SS: DGROUP
15F_TEXT SEGMENT 15F_TEXT SEGMENT
16 ASSUME CS: F_TEXT 16 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'
6F_TEXT ENDS 6F_TEXT ENDS
7_DATA SEGMENT WORD USE16 PUBLIC 'DATA' 7_DATA SEGMENT WORD USE16 PUBLIC 'DATA'
8_DATA ENDS 8_DATA ENDS
9CONST SEGMENT WORD USE16 PUBLIC 'CONST' 9_CONST SEGMENT WORD USE16 PUBLIC 'CONST'
10CONST ENDS 10_CONST ENDS
11_BSS SEGMENT WORD USE16 PUBLIC 'BSS' 11_BSS SEGMENT WORD USE16 PUBLIC 'BSS'
12_BSS ENDS 12_BSS ENDS
13DGROUP GROUP CONST, _BSS, _DATA 13DGROUP GROUP _CONST, _BSS, _DATA
14 ASSUME DS: DGROUP, SS: DGROUP 14 ASSUME DS: DGROUP, SS: DGROUP
15F_TEXT SEGMENT 15F_TEXT SEGMENT
16 ASSUME CS: F_TEXT 16 ASSUME CS: F_TEXT
@@ -89,7 +89,7 @@ $L555:
89 mov bp,WORD PTR [bp+26] ; load num 89 mov bp,WORD PTR [bp+26] ; load num
90 and bp,3 90 and bp,3
91 dec bp 91 dec bp
92 js $L547 92 js $L547m
93 93
94 mov eax,ecx 94 mov eax,ecx
95 mul DWORD PTR es:[bx] ; w* *a 95 mul DWORD PTR es:[bx] ; w* *a
@@ -100,7 +100,7 @@ $L555:
100 mov DWORD PTR ds:[di],eax 100 mov DWORD PTR ds:[di],eax
101 mov esi,edx 101 mov esi,edx
102 dec bp 102 dec bp
103 js $L547 ; Note that we are now testing for -1 103 js $L547m ; Note that we are now testing for -1
104 ; 104 ;
105 mov eax,ecx 105 mov eax,ecx
106 mul DWORD PTR es:[bx+4] ; w* *a 106 mul DWORD PTR es:[bx+4] ; w* *a
@@ -111,7 +111,7 @@ $L555:
111 mov DWORD PTR ds:[di+4],eax 111 mov DWORD PTR ds:[di+4],eax
112 mov esi,edx 112 mov esi,edx
113 dec bp 113 dec bp
114 js $L547 114 js $L547m
115 ; 115 ;
116 mov eax,ecx 116 mov eax,ecx
117 mul DWORD PTR es:[bx+8] ; w* *a 117 mul DWORD PTR es:[bx+8] ; w* *a
@@ -121,7 +121,7 @@ $L555:
121 adc edx,0 121 adc edx,0
122 mov DWORD PTR ds:[di+8],eax 122 mov DWORD PTR ds:[di+8],eax
123 mov esi,edx 123 mov esi,edx
124$L547: 124$L547m:
125 mov eax,esi 125 mov eax,esi
126 mov edx,esi 126 mov edx,esi
127 shr edx,16 127 shr edx,16
@@ -315,37 +315,35 @@ _bn_add_words PROC FAR
315; ap = 22 315; ap = 22
316; rp = 18 316; rp = 18
317 xor esi,esi ;c=0; 317 xor esi,esi ;c=0;
318 mov bx,WORD PTR [bp+18] ; load low r
318 mov si,WORD PTR [bp+22] ; load a 319 mov si,WORD PTR [bp+22] ; load a
319 mov es,WORD PTR [bp+24] ; load a 320 mov es,WORD PTR [bp+24] ; load a
320 mov di,WORD PTR [bp+26] ; load b 321 mov di,WORD PTR [bp+26] ; load b
321 mov ds,WORD PTR [bp+28] ; load b 322 mov ds,WORD PTR [bp+28] ; load b
322 323
323 mov dx,WORD PTR [bp+30] ; load num 324 mov dx,WORD PTR [bp+30] ; load num
324 dec dx
325 js $L547
326 xor ecx,ecx 325 xor ecx,ecx
326 dec dx
327 js $L547a
327 328
328$L5477: 329$L5477:
329 xor ebx,ebx
330 mov eax,DWORD PTR es:[si] ; *a 330 mov eax,DWORD PTR es:[si] ; *a
331 add eax,ecx 331 add eax,ecx
332 adc ebx,0 332 mov ecx,0
333 adc ecx,0
333 add si,4 ; a++ 334 add si,4 ; a++
334 add eax,DWORD PTR ds:[di] ; + *b 335 add eax,DWORD PTR ds:[di] ; + *b
335 mov ecx,ebx
336 adc ecx,0 336 adc ecx,0
337 add di,4
338 mov bx,WORD PTR [bp+18]
339 mov ds,WORD PTR [bp+20] 337 mov ds,WORD PTR [bp+20]
338 add di,4
340 mov DWORD PTR ds:[bx],eax 339 mov DWORD PTR ds:[bx],eax
341 add bx,4
342 mov ds,WORD PTR [bp+28] 340 mov ds,WORD PTR [bp+28]
343 mov WORD PTR [bp+18],bx 341 add bx,4
344 dec dx 342 dec dx
345 js $L547 ; Note that we are now testing for -1 343 js $L547a ; Note that we are now testing for -1
346 jmp $L5477 344 jmp $L5477
347 ; 345 ;
348$L547: 346$L547a:
349 mov eax,ecx 347 mov eax,ecx
350 mov edx,ecx 348 mov edx,ecx
351 shr edx,16 349 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 @@
1/* Error codes for the BN functions. */
2
3/* Function codes. */
4#define BN_F_BN_BLINDING_CONVERT 100
5#define BN_F_BN_BLINDING_INVERT 101
6#define BN_F_BN_BLINDING_NEW 102
7#define BN_F_BN_BLINDING_UPDATE 103
8#define BN_F_BN_BN2DEC 104
9#define BN_F_BN_BN2HEX 105
10#define BN_F_BN_CTX_NEW 106
11#define BN_F_BN_DIV 107
12#define BN_F_BN_EXPAND2 108
13#define BN_F_BN_MOD_EXP_MONT 109
14#define BN_F_BN_MOD_INVERSE 110
15#define BN_F_BN_MOD_MUL_RECIPROCAL 111
16#define BN_F_BN_MPI2BN 112
17#define BN_F_BN_NEW 113
18#define BN_F_BN_RAND 114
19
20/* Reason codes. */
21#define BN_R_BAD_RECIPROCAL 100
22#define BN_R_CALLED_WITH_EVEN_MODULUS 101
23#define BN_R_DIV_BY_ZERO 102
24#define BN_R_ENCODING_ERROR 103
25#define BN_R_INVALID_LENGTH 104
26#define BN_R_NOT_INITALISED 105
27#define BN_R_NO_INVERSE 106
diff --git a/src/lib/libcrypto/bn/bn.org b/src/lib/libcrypto/bn/bn.h
index 66dde285d6..f935e1ca79 100644
--- a/src/lib/libcrypto/bn/bn.org
+++ b/src/lib/libcrypto/bn/bn.h
@@ -1,4 +1,4 @@
1/* crypto/bn/bn.org */ 1/* crypto/bn/bn.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,27 +56,25 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify bn.org since bn.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_BN_H 59#ifndef HEADER_BN_H
68#define HEADER_BN_H 60#define HEADER_BN_H
69 61
62#ifndef WIN16
63#include <stdio.h> /* FILE */
64#endif
65#include <openssl/opensslconf.h>
66
70#ifdef __cplusplus 67#ifdef __cplusplus
71extern "C" { 68extern "C" {
72#endif 69#endif
73 70
74#undef BN_LLONG 71#ifdef VMS
75 72#undef BN_LLONG /* experimental, so far... */
76#ifdef WIN32
77#define BN_LLONG /* This comment stops Configure mutilating things */
78#endif 73#endif
79 74
75#define BN_MUL_COMBA
76#define BN_SQR_COMBA
77#define BN_RECURSION
80#define RECP_MUL_MOD 78#define RECP_MUL_MOD
81#define MONT_MUL_MOD 79#define MONT_MUL_MOD
82 80
@@ -95,16 +93,6 @@ extern "C" {
95#define BN_DIV2W 93#define BN_DIV2W
96#endif 94#endif
97 95
98/* Only one for the following should be defined */
99/* The prime number generation stuff may not work when
100 * EIGHT_BIT but I don't care since I've only used this mode
101 * for debuging the bignum libraries */
102#undef SIXTY_FOUR_BIT_LONG
103#undef SIXTY_FOUR_BIT
104#define THIRTY_TWO_BIT
105#undef SIXTEEN_BIT
106#undef EIGHT_BIT
107
108/* assuming long is 64bit - this is the DEC Alpha 96/* assuming long is 64bit - this is the DEC Alpha
109 * unsigned long long is only 64 bits :-(, don't define 97 * unsigned long long is only 64 bits :-(, don't define
110 * BN_LLONG for the DEC Alpha */ 98 * BN_LLONG for the DEC Alpha */
@@ -116,20 +104,26 @@ extern "C" {
116#define BN_BYTES 8 104#define BN_BYTES 8
117#define BN_BITS2 64 105#define BN_BITS2 64
118#define BN_BITS4 32 106#define BN_BITS4 32
107#define BN_MASK (0xffffffffffffffffffffffffffffffffLL)
119#define BN_MASK2 (0xffffffffffffffffL) 108#define BN_MASK2 (0xffffffffffffffffL)
120#define BN_MASK2l (0xffffffffL) 109#define BN_MASK2l (0xffffffffL)
121#define BN_MASK2h (0xffffffff00000000L) 110#define BN_MASK2h (0xffffffff00000000L)
122#define BN_MASK2h1 (0xffffffff80000000L) 111#define BN_MASK2h1 (0xffffffff80000000L)
123#define BN_TBIT (0x8000000000000000L) 112#define BN_TBIT (0x8000000000000000L)
124#define BN_DEC_CONV (10000000000000000000L) 113#define BN_DEC_CONV (10000000000000000000UL)
125#define BN_DEC_FMT1 "%lu" 114#define BN_DEC_FMT1 "%lu"
126#define BN_DEC_FMT2 "%019lu" 115#define BN_DEC_FMT2 "%019lu"
127#define BN_DEC_NUM 19 116#define BN_DEC_NUM 19
128#endif 117#endif
129 118
119/* This is where the long long data type is 64 bits, but long is 32.
120 * For machines where there are 64bit registers, this is the mode to use.
121 * IRIX, on R4000 and above should use this mode, along with the relevent
122 * assember code :-). Do NOT define BN_LLONG.
123 */
130#ifdef SIXTY_FOUR_BIT 124#ifdef SIXTY_FOUR_BIT
131#undef BN_LLONG 125#undef BN_LLONG
132/* #define BN_ULLONG unsigned long long */ 126#undef BN_ULLONG
133#define BN_ULONG unsigned long long 127#define BN_ULONG unsigned long long
134#define BN_LONG long long 128#define BN_LONG long long
135#define BN_BITS 128 129#define BN_BITS 128
@@ -141,14 +135,14 @@ extern "C" {
141#define BN_MASK2h (0xffffffff00000000LL) 135#define BN_MASK2h (0xffffffff00000000LL)
142#define BN_MASK2h1 (0xffffffff80000000LL) 136#define BN_MASK2h1 (0xffffffff80000000LL)
143#define BN_TBIT (0x8000000000000000LL) 137#define BN_TBIT (0x8000000000000000LL)
144#define BN_DEC_CONV (10000000000000000000L) 138#define BN_DEC_CONV (10000000000000000000LL)
145#define BN_DEC_FMT1 "%lu" 139#define BN_DEC_FMT1 "%llu"
146#define BN_DEC_FMT2 "%019lu" 140#define BN_DEC_FMT2 "%019llu"
147#define BN_DEC_NUM 19 141#define BN_DEC_NUM 19
148#endif 142#endif
149 143
150#ifdef THIRTY_TWO_BIT 144#ifdef THIRTY_TWO_BIT
151#ifdef WIN32 145#if defined(WIN32) && !defined(__GNUC__)
152#define BN_ULLONG unsigned _int64 146#define BN_ULLONG unsigned _int64
153#else 147#else
154#define BN_ULLONG unsigned long long 148#define BN_ULLONG unsigned long long
@@ -159,6 +153,12 @@ extern "C" {
159#define BN_BYTES 4 153#define BN_BYTES 4
160#define BN_BITS2 32 154#define BN_BITS2 32
161#define BN_BITS4 16 155#define BN_BITS4 16
156#ifdef WIN32
157/* VC++ doesn't like the LL suffix */
158#define BN_MASK (0xffffffffffffffffL)
159#else
160#define BN_MASK (0xffffffffffffffffLL)
161#endif
162#define BN_MASK2 (0xffffffffL) 162#define BN_MASK2 (0xffffffffL)
163#define BN_MASK2l (0xffff) 163#define BN_MASK2l (0xffff)
164#define BN_MASK2h1 (0xffff8000L) 164#define BN_MASK2h1 (0xffff8000L)
@@ -181,6 +181,7 @@ extern "C" {
181#define BN_BYTES 2 181#define BN_BYTES 2
182#define BN_BITS2 16 182#define BN_BITS2 16
183#define BN_BITS4 8 183#define BN_BITS4 8
184#define BN_MASK (0xffffffff)
184#define BN_MASK2 (0xffff) 185#define BN_MASK2 (0xffff)
185#define BN_MASK2l (0xff) 186#define BN_MASK2l (0xff)
186#define BN_MASK2h1 (0xff80) 187#define BN_MASK2h1 (0xff80)
@@ -203,6 +204,7 @@ extern "C" {
203#define BN_BYTES 1 204#define BN_BYTES 1
204#define BN_BITS2 8 205#define BN_BITS2 8
205#define BN_BITS4 4 206#define BN_BITS4 4
207#define BN_MASK (0xffff)
206#define BN_MASK2 (0xff) 208#define BN_MASK2 (0xff)
207#define BN_MASK2l (0xf) 209#define BN_MASK2l (0xf)
208#define BN_MASK2h1 (0xf8) 210#define BN_MASK2h1 (0xf8)
@@ -220,6 +222,12 @@ extern "C" {
220#undef BIGNUM 222#undef BIGNUM
221#endif 223#endif
222 224
225#define BN_FLG_MALLOCED 0x01
226#define BN_FLG_STATIC_DATA 0x02
227#define BN_FLG_FREE 0x8000 /* used for debuging */
228#define BN_set_flags(b,n) ((b)->flags|=(n))
229#define BN_get_flags(b,n) ((b)->flags&(n))
230
223typedef struct bignum_st 231typedef struct bignum_st
224 { 232 {
225 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ 233 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
@@ -227,6 +235,7 @@ typedef struct bignum_st
227 /* The next are internal book keeping for bn_expand. */ 235 /* The next are internal book keeping for bn_expand. */
228 int max; /* Size of the d array. */ 236 int max; /* Size of the d array. */
229 int neg; /* one if the number is negative */ 237 int neg; /* one if the number is negative */
238 int flags;
230 } BIGNUM; 239 } BIGNUM;
231 240
232/* Used for temp variables */ 241/* Used for temp variables */
@@ -234,7 +243,8 @@ typedef struct bignum_st
234typedef struct bignum_ctx 243typedef struct bignum_ctx
235 { 244 {
236 int tos; 245 int tos;
237 BIGNUM *bn[BN_CTX_NUM+1]; 246 BIGNUM bn[BN_CTX_NUM+1];
247 int flags;
238 } BN_CTX; 248 } BN_CTX;
239 249
240typedef struct bn_blinding_st 250typedef struct bn_blinding_st
@@ -248,130 +258,150 @@ typedef struct bn_blinding_st
248/* Used for montgomery multiplication */ 258/* Used for montgomery multiplication */
249typedef struct bn_mont_ctx_st 259typedef struct bn_mont_ctx_st
250 { 260 {
261 int use_word; /* 0 for word form, 1 for long form */
251 int ri; /* number of bits in R */ 262 int ri; /* number of bits in R */
252 BIGNUM *RR; /* used to convert to montgomery form */ 263 BIGNUM RR; /* used to convert to montgomery form */
253 BIGNUM *N; /* The modulus */ 264 BIGNUM N; /* The modulus */
254 BIGNUM *Ni; /* The inverse of N */ 265 BIGNUM Ni; /* The inverse of N */
255 BN_ULONG n0; /* word form of inverse, normally only one of 266 BN_ULONG n0; /* word form of inverse, normally only one of
256 * Ni or n0 is defined */ 267 * Ni or n0 is defined */
268 int flags;
257 } BN_MONT_CTX; 269 } BN_MONT_CTX;
258 270
271/* Used for reciprocal division/mod functions
272 * It cannot be shared between threads
273 */
274typedef struct bn_recp_ctx_st
275 {
276 BIGNUM N; /* the divisor */
277 BIGNUM Nr; /* the reciprocal */
278 int num_bits;
279 int shift;
280 int flags;
281 } BN_RECP_CTX;
282
259#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\ 283#define BN_to_montgomery(r,a,mont,ctx) BN_mod_mul_montgomery(\
260 r,a,(mont)->RR,(mont),ctx) 284 r,a,&((mont)->RR),(mont),ctx)
261 285
262#define BN_prime_checks (5) 286#define BN_prime_checks (5)
263 287
264#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) 288#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
265#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) 289#define BN_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
266#define BN_is_zero(a) (((a)->top <= 1) && ((a)->d[0] == (BN_ULONG)0)) 290#define BN_is_zero(a) (((a)->top == 0) || BN_is_word(a,0))
267#define BN_is_one(a) (BN_is_word((a),1)) 291#define BN_is_one(a) (BN_is_word((a),1))
268#define BN_is_odd(a) ((a)->d[0] & 1) 292#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))
269#define BN_one(a) (BN_set_word((a),1)) 293#define BN_one(a) (BN_set_word((a),1))
270#define BN_zero(a) (BN_set_word((a),0)) 294#define BN_zero(a) (BN_set_word((a),0))
271 295
272#define BN_ascii2bn(a) BN_hex2bn(a) 296/*#define BN_ascii2bn(a) BN_hex2bn(a) */
273#define BN_bn2ascii(a) BN_bn2hex(a) 297/*#define BN_bn2ascii(a) BN_bn2hex(a) */
274 298
275#define bn_fix_top(a) \ 299#define bn_expand(n,b) ((((((b+BN_BITS2-1))/BN_BITS2)) <= (n)->max)?\
276 { \ 300 (n):bn_expand2((n),(b)/BN_BITS2+1))
277 BN_ULONG *fix_top_l; \
278 for (fix_top_l= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
279 if (*(fix_top_l--)) break; \
280 }
281
282#define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?\
283 (n):bn_expand2((n),(b)/BN_BITS2))
284#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b))) 301#define bn_wexpand(n,b) (((b) <= (n)->max)?(n):bn_expand2((n),(b)))
285 302
303#define bn_fix_top(a) \
304 { \
305 BN_ULONG *ftl; \
306 if ((a)->top > 0) \
307 { \
308 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
309 if (*(ftl--)) break; \
310 } \
311 }
286 312
287#ifndef NOPROTO
288BIGNUM *BN_value_one(void); 313BIGNUM *BN_value_one(void);
289char * BN_options(void); 314char * BN_options(void);
290BN_CTX *BN_CTX_new(void); 315BN_CTX *BN_CTX_new(void);
316void BN_CTX_init(BN_CTX *c);
291void BN_CTX_free(BN_CTX *c); 317void BN_CTX_free(BN_CTX *c);
292int BN_rand(BIGNUM *rnd, int bits, int top,int bottom); 318int BN_rand(BIGNUM *rnd, int bits, int top,int bottom);
293int BN_num_bits(BIGNUM *a); 319int BN_num_bits(const BIGNUM *a);
294int BN_num_bits_word(BN_ULONG); 320int BN_num_bits_word(BN_ULONG);
295BIGNUM *BN_new(void); 321BIGNUM *BN_new(void);
322void BN_init(BIGNUM *);
296void BN_clear_free(BIGNUM *a); 323void BN_clear_free(BIGNUM *a);
297BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b); 324BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b);
298BIGNUM *BN_bin2bn(unsigned char *s,int len,BIGNUM *ret); 325BIGNUM *BN_bin2bn(const unsigned char *s,int len,BIGNUM *ret);
299int BN_bn2bin(BIGNUM *a, unsigned char *to); 326int BN_bn2bin(const BIGNUM *a, unsigned char *to);
300BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret); 327BIGNUM *BN_mpi2bn(unsigned char *s,int len,BIGNUM *ret);
301int BN_bn2mpi(BIGNUM *a, unsigned char *to); 328int BN_bn2mpi(const BIGNUM *a, unsigned char *to);
302int BN_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b); 329int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
303void bn_qsub(BIGNUM *r, BIGNUM *a, BIGNUM *b); 330int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
304void bn_qadd(BIGNUM *r, BIGNUM *a, BIGNUM *b); 331int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
305int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b); 332int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b);
306int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx); 333int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx);
307int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx); 334int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
308int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b); 335 BN_CTX *ctx);
336int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b,BN_CTX *ctx);
309int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx); 337int BN_sqr(BIGNUM *r, BIGNUM *a,BN_CTX *ctx);
310BN_ULONG BN_mod_word(BIGNUM *a, unsigned long w); 338BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w);
311BN_ULONG BN_div_word(BIGNUM *a, unsigned long w); 339BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w);
312int BN_mul_word(BIGNUM *a, unsigned long w); 340int BN_mul_word(BIGNUM *a, BN_ULONG w);
313int BN_add_word(BIGNUM *a, unsigned long w); 341int BN_add_word(BIGNUM *a, BN_ULONG w);
314int BN_sub_word(BIGNUM *a, unsigned long w); 342int BN_sub_word(BIGNUM *a, BN_ULONG w);
315int BN_set_word(BIGNUM *a, unsigned long w); 343int BN_set_word(BIGNUM *a, BN_ULONG w);
316unsigned long BN_get_word(BIGNUM *a); 344BN_ULONG BN_get_word(BIGNUM *a);
317int BN_cmp(BIGNUM *a, BIGNUM *b); 345int BN_cmp(const BIGNUM *a, const BIGNUM *b);
318void BN_free(BIGNUM *a); 346void BN_free(BIGNUM *a);
319int BN_is_bit_set(BIGNUM *a, int n); 347int BN_is_bit_set(const BIGNUM *a, int n);
320int BN_lshift(BIGNUM *r, BIGNUM *a, int n); 348int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
321int BN_lshift1(BIGNUM *r, BIGNUM *a); 349int BN_lshift1(BIGNUM *r, BIGNUM *a);
322int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx); 350int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p,BN_CTX *ctx);
323int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx); 351int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
324int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx, 352 const BIGNUM *m,BN_CTX *ctx);
325 BN_MONT_CTX *m_ctx); 353int BN_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
326int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,BN_CTX *ctx); 354 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
355int BN_mod_exp2_mont(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2,
356 BIGNUM *p2,BIGNUM *m,BN_CTX *ctx,BN_MONT_CTX *m_ctx);
327int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, 357int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p,
328 BIGNUM *m,BN_CTX *ctx); 358 BIGNUM *m,BN_CTX *ctx);
329int BN_mask_bits(BIGNUM *a,int n); 359int BN_mask_bits(BIGNUM *a,int n);
330int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BIGNUM *m, 360int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx);
331 BIGNUM *i, int nb, BN_CTX *ctx);
332int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m,
333 BN_CTX *ctx);
334#ifndef WIN16 361#ifndef WIN16
335int BN_print_fp(FILE *fp, BIGNUM *a); 362int BN_print_fp(FILE *fp, BIGNUM *a);
336#endif 363#endif
337#ifdef HEADER_BIO_H 364#ifdef HEADER_BIO_H
338int BN_print(BIO *fp, BIGNUM *a); 365int BN_print(BIO *fp, const BIGNUM *a);
339#else 366#else
340int BN_print(char *fp, BIGNUM *a); 367int BN_print(char *fp, const BIGNUM *a);
341#endif 368#endif
342int BN_reciprocal(BIGNUM *r, BIGNUM *m, BN_CTX *ctx); 369int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx);
343int BN_rshift(BIGNUM *r, BIGNUM *a, int n); 370int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
344int BN_rshift1(BIGNUM *r, BIGNUM *a); 371int BN_rshift1(BIGNUM *r, BIGNUM *a);
345void BN_clear(BIGNUM *a); 372void BN_clear(BIGNUM *a);
346BIGNUM *bn_expand2(BIGNUM *b, int bits); 373BIGNUM *bn_expand2(BIGNUM *b, int bits);
347BIGNUM *BN_dup(BIGNUM *a); 374BIGNUM *BN_dup(const BIGNUM *a);
348int BN_ucmp(BIGNUM *a, BIGNUM *b); 375int BN_ucmp(const BIGNUM *a, const BIGNUM *b);
349int BN_set_bit(BIGNUM *a, int n); 376int BN_set_bit(BIGNUM *a, int n);
350int BN_clear_bit(BIGNUM *a, int n); 377int BN_clear_bit(BIGNUM *a, int n);
351char * BN_bn2hex(BIGNUM *a); 378char * BN_bn2hex(const BIGNUM *a);
352char * BN_bn2dec(BIGNUM *a); 379char * BN_bn2dec(const BIGNUM *a);
353int BN_hex2bn(BIGNUM **a,char *str); 380int BN_hex2bn(BIGNUM **a, const char *str);
354int BN_dec2bn(BIGNUM **a,char *str); 381int BN_dec2bn(BIGNUM **a, const char *str);
355int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx); 382int BN_gcd(BIGNUM *r,BIGNUM *in_a,BIGNUM *in_b,BN_CTX *ctx);
356BIGNUM *BN_mod_inverse(BIGNUM *a, BIGNUM *n,BN_CTX *ctx); 383BIGNUM *BN_mod_inverse(BIGNUM *ret,BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
357BIGNUM *BN_generate_prime(int bits,int strong,BIGNUM *add, 384BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int strong,BIGNUM *add,
358 BIGNUM *rem,void (*callback)(int,int,char *),char *cb_arg); 385 BIGNUM *rem,void (*callback)(int,int,void *),void *cb_arg);
359int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,char *), 386int BN_is_prime(BIGNUM *p,int nchecks,void (*callback)(int,int,void *),
360 BN_CTX *ctx,char *cb_arg); 387 BN_CTX *ctx,void *cb_arg);
361void ERR_load_BN_strings(void ); 388void ERR_load_BN_strings(void );
362 389
363BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); 390BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
364BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w); 391BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w);
365void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num); 392void bn_sqr_words(BN_ULONG *rp, BN_ULONG *ap, int num);
366BN_ULONG bn_div64(BN_ULONG h, BN_ULONG l, BN_ULONG d); 393BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
367BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num); 394BN_ULONG bn_add_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
395BN_ULONG bn_sub_words(BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int num);
368 396
369BN_MONT_CTX *BN_MONT_CTX_new(void ); 397BN_MONT_CTX *BN_MONT_CTX_new(void );
398void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
370int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont, 399int BN_mod_mul_montgomery(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_MONT_CTX *mont,
371 BN_CTX *ctx); 400 BN_CTX *ctx);
372int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx); 401int BN_from_montgomery(BIGNUM *r,BIGNUM *a,BN_MONT_CTX *mont,BN_CTX *ctx);
373void BN_MONT_CTX_free(BN_MONT_CTX *mont); 402void BN_MONT_CTX_free(BN_MONT_CTX *mont);
374int BN_MONT_CTX_set(BN_MONT_CTX *mont,BIGNUM *modulus,BN_CTX *ctx); 403int BN_MONT_CTX_set(BN_MONT_CTX *mont,const BIGNUM *modulus,BN_CTX *ctx);
404BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);
375 405
376BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod); 406BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod);
377void BN_BLINDING_free(BN_BLINDING *b); 407void BN_BLINDING_free(BN_BLINDING *b);
@@ -379,94 +409,26 @@ int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
379int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx); 409int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx);
380int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); 410int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
381 411
382#else 412void BN_set_params(int mul,int high,int low,int mont);
413int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */
383 414
384BIGNUM *BN_value_one(); 415void BN_RECP_CTX_init(BN_RECP_CTX *recp);
385char * BN_options(); 416BN_RECP_CTX *BN_RECP_CTX_new(void);
386BN_CTX *BN_CTX_new(); 417void BN_RECP_CTX_free(BN_RECP_CTX *recp);
387void BN_CTX_free(); 418int BN_RECP_CTX_set(BN_RECP_CTX *recp,const BIGNUM *rdiv,BN_CTX *ctx);
388int BN_rand(); 419int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y,
389int BN_num_bits(); 420 BN_RECP_CTX *recp,BN_CTX *ctx);
390int BN_num_bits_word(); 421int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
391BIGNUM *BN_new(); 422 const BIGNUM *m, BN_CTX *ctx);
392void BN_clear_free(); 423int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m,
393BIGNUM *BN_copy(); 424 BN_RECP_CTX *recp, BN_CTX *ctx);
394BIGNUM *BN_bin2bn();
395int BN_bn2bin();
396BIGNUM *BN_mpi2bn();
397int BN_bn2mpi();
398int BN_sub();
399void bn_qsub();
400void bn_qadd();
401int BN_add();
402int BN_mod();
403int BN_div();
404int BN_mul();
405int BN_sqr();
406BN_ULONG BN_mod_word();
407BN_ULONG BN_div_word();
408int BN_add_word();
409int BN_sub_word();
410int BN_mul_word();
411int BN_set_word();
412unsigned long BN_get_word();
413int BN_cmp();
414void BN_free();
415int BN_is_bit_set();
416int BN_lshift();
417int BN_lshift1();
418int BN_exp();
419int BN_mod_exp();
420int BN_mod_exp_mont();
421int BN_mod_exp_recp();
422int BN_mod_exp_simple();
423int BN_mask_bits();
424int BN_mod_mul_reciprocal();
425int BN_mod_mul();
426#ifndef WIN16
427int BN_print_fp();
428#endif
429int BN_print();
430int BN_reciprocal();
431int BN_rshift();
432int BN_rshift1();
433void BN_clear();
434BIGNUM *bn_expand2();
435BIGNUM *BN_dup();
436int BN_ucmp();
437int BN_set_bit();
438int BN_clear_bit();
439char * BN_bn2hex();
440char * BN_bn2dec();
441int BN_hex2bn();
442int BN_dec2bn();
443int BN_gcd();
444BIGNUM *BN_mod_inverse();
445BIGNUM *BN_generate_prime();
446int BN_is_prime();
447void ERR_load_BN_strings();
448
449BN_ULONG bn_mul_add_words();
450BN_ULONG bn_mul_words();
451void bn_sqr_words();
452BN_ULONG bn_div64();
453BN_ULONG bn_add_words();
454
455int BN_mod_mul_montgomery();
456int BN_from_montgomery();
457BN_MONT_CTX *BN_MONT_CTX_new();
458void BN_MONT_CTX_free();
459int BN_MONT_CTX_set();
460
461BN_BLINDING *BN_BLINDING_new();
462void BN_BLINDING_free();
463int BN_BLINDING_update();
464int BN_BLINDING_convert();
465int BN_BLINDING_invert();
466 425
467#endif
468 426
469/* BEGIN ERROR CODES */ 427/* BEGIN ERROR CODES */
428/* The following lines are auto generated by the script mkerr.pl. Any changes
429 * made after this point may be overwritten when the script is next run.
430 */
431
470/* Error codes for the BN functions. */ 432/* Error codes for the BN functions. */
471 433
472/* Function codes. */ 434/* Function codes. */
@@ -485,16 +447,19 @@ int BN_BLINDING_invert();
485#define BN_F_BN_MPI2BN 112 447#define BN_F_BN_MPI2BN 112
486#define BN_F_BN_NEW 113 448#define BN_F_BN_NEW 113
487#define BN_F_BN_RAND 114 449#define BN_F_BN_RAND 114
450#define BN_F_BN_USUB 115
488 451
489/* Reason codes. */ 452/* Reason codes. */
490#define BN_R_BAD_RECIPROCAL 100 453#define BN_R_ARG2_LT_ARG3 100
491#define BN_R_CALLED_WITH_EVEN_MODULUS 101 454#define BN_R_BAD_RECIPROCAL 101
492#define BN_R_DIV_BY_ZERO 102 455#define BN_R_CALLED_WITH_EVEN_MODULUS 102
493#define BN_R_ENCODING_ERROR 103 456#define BN_R_DIV_BY_ZERO 103
494#define BN_R_INVALID_LENGTH 104 457#define BN_R_ENCODING_ERROR 104
495#define BN_R_NOT_INITALISED 105 458#define BN_R_EXPAND_ON_STATIC_BIGNUM_DATA 105
496#define BN_R_NO_INVERSE 106 459#define BN_R_INVALID_LENGTH 106
497 460#define BN_R_NOT_INITIALIZED 107
461#define BN_R_NO_INVERSE 108
462
498#ifdef __cplusplus 463#ifdef __cplusplus
499} 464}
500#endif 465#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 @@
1We need
2
3* bn_mul_comba8
4* bn_mul_comba4
5* bn_mul_normal
6* bn_mul_recursive
7
8* bn_sqr_comba8
9* bn_sqr_comba4
10bn_sqr_normal -> BN_sqr
11* bn_sqr_recursive
12
13* bn_mul_low_recursive
14* bn_mul_low_normal
15* bn_mul_high
16
17* bn_mul_part_recursive # symetric but not power of 2
18
19bn_mul_asymetric_recursive # uneven, but do the chop up.
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 @@
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63/* r can == a or b */ 63/* r can == a or b */
64int BN_add(r, a, b) 64int BN_add(BIGNUM *r, BIGNUM *a, BIGNUM *b)
65BIGNUM *r;
66BIGNUM *a;
67BIGNUM *b;
68 { 65 {
69 int i;
70 BIGNUM *tmp; 66 BIGNUM *tmp;
71 67
68 bn_check_top(a);
69 bn_check_top(b);
70
72 /* a + b a+b 71 /* a + b a+b
73 * a + -b a-b 72 * a + -b a-b
74 * -a + b b-a 73 * -a + b b-a
@@ -84,14 +83,12 @@ BIGNUM *b;
84 83
85 if (BN_ucmp(a,b) < 0) 84 if (BN_ucmp(a,b) < 0)
86 { 85 {
87 if (bn_wexpand(r,b->top) == NULL) return(0); 86 if (!BN_usub(r,b,a)) return(0);
88 bn_qsub(r,b,a);
89 r->neg=1; 87 r->neg=1;
90 } 88 }
91 else 89 else
92 { 90 {
93 if (bn_wexpand(r,a->top) == NULL) return(0); 91 if (!BN_usub(r,a,b)) return(0);
94 bn_qsub(r,a,b);
95 r->neg=0; 92 r->neg=0;
96 } 93 }
97 return(1); 94 return(1);
@@ -102,35 +99,32 @@ BIGNUM *b;
102 else 99 else
103 r->neg=0; 100 r->neg=0;
104 101
105 i=(a->top > b->top); 102 if (!BN_uadd(r,a,b)) return(0);
106
107 if (i)
108 {
109 if (bn_wexpand(r,a->top+1) == NULL) return(0);
110 bn_qadd(r,a,b);
111 }
112 else
113 {
114 if (bn_wexpand(r,b->top+1) == NULL) return(0);
115 bn_qadd(r,b,a);
116 }
117 return(1); 103 return(1);
118 } 104 }
119 105
120/* unsigned add of b to a, r must be large enough */ 106/* unsigned add of b to a, r must be large enough */
121void bn_qadd(r,a,b) 107int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
122BIGNUM *r;
123BIGNUM *a;
124BIGNUM *b;
125 { 108 {
126 register int i; 109 register int i;
127 int max,min; 110 int max,min;
128 BN_ULONG *ap,*bp,*rp,carry,t1; 111 BN_ULONG *ap,*bp,*rp,carry,t1;
112 const BIGNUM *tmp;
113
114 bn_check_top(a);
115 bn_check_top(b);
129 116
117 if (a->top < b->top)
118 { tmp=a; a=b; b=tmp; }
130 max=a->top; 119 max=a->top;
131 min=b->top; 120 min=b->top;
121
122 if (bn_wexpand(r,max+1) == NULL)
123 return(0);
124
132 r->top=max; 125 r->top=max;
133 126
127
134 ap=a->d; 128 ap=a->d;
135 bp=b->d; 129 bp=b->d;
136 rp=r->d; 130 rp=r->d;
@@ -160,8 +154,154 @@ BIGNUM *b;
160 r->top++; 154 r->top++;
161 } 155 }
162 } 156 }
163 for (; i<max; i++) 157 if (rp != ap)
164 *(rp++)= *(ap++); 158 {
159 for (; i<max; i++)
160 *(rp++)= *(ap++);
161 }
165 /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/ 162 /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/
163 return(1);
164 }
165
166/* unsigned subtraction of b from a, a must be larger than b. */
167int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
168 {
169 int max,min;
170 register BN_ULONG t1,t2,*ap,*bp,*rp;
171 int i,carry;
172#if defined(IRIX_CC_BUG) && !defined(LINT)
173 int dummy;
174#endif
175
176 bn_check_top(a);
177 bn_check_top(b);
178
179 if (a->top < b->top) /* hmm... should not be happening */
180 {
181 BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);
182 return(0);
183 }
184
185 max=a->top;
186 min=b->top;
187 if (bn_wexpand(r,max) == NULL) return(0);
188
189 ap=a->d;
190 bp=b->d;
191 rp=r->d;
192
193#if 1
194 carry=0;
195 for (i=0; i<min; i++)
196 {
197 t1= *(ap++);
198 t2= *(bp++);
199 if (carry)
200 {
201 carry=(t1 <= t2);
202 t1=(t1-t2-1)&BN_MASK2;
203 }
204 else
205 {
206 carry=(t1 < t2);
207 t1=(t1-t2)&BN_MASK2;
208 }
209#if defined(IRIX_CC_BUG) && !defined(LINT)
210 dummy=t1;
211#endif
212 *(rp++)=t1&BN_MASK2;
213 }
214#else
215 carry=bn_sub_words(rp,ap,bp,min);
216 ap+=min;
217 bp+=min;
218 rp+=min;
219 i=min;
220#endif
221 if (carry) /* subtracted */
222 {
223 while (i < max)
224 {
225 i++;
226 t1= *(ap++);
227 t2=(t1-1)&BN_MASK2;
228 *(rp++)=t2;
229 if (t1 > t2) break;
230 }
231 }
232#if 0
233 memcpy(rp,ap,sizeof(*rp)*(max-i));
234#else
235 if (rp != ap)
236 {
237 for (;;)
238 {
239 if (i++ >= max) break;
240 rp[0]=ap[0];
241 if (i++ >= max) break;
242 rp[1]=ap[1];
243 if (i++ >= max) break;
244 rp[2]=ap[2];
245 if (i++ >= max) break;
246 rp[3]=ap[3];
247 rp+=4;
248 ap+=4;
249 }
250 }
251#endif
252
253 r->top=max;
254 bn_fix_top(r);
255 return(1);
256 }
257
258int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
259 {
260 int max;
261 int add=0,neg=0;
262 const BIGNUM *tmp;
263
264 bn_check_top(a);
265 bn_check_top(b);
266
267 /* a - b a-b
268 * a - -b a+b
269 * -a - b -(a+b)
270 * -a - -b b-a
271 */
272 if (a->neg)
273 {
274 if (b->neg)
275 { tmp=a; a=b; b=tmp; }
276 else
277 { add=1; neg=1; }
278 }
279 else
280 {
281 if (b->neg) { add=1; neg=0; }
282 }
283
284 if (add)
285 {
286 if (!BN_uadd(r,a,b)) return(0);
287 r->neg=neg;
288 return(1);
289 }
290
291 /* We are actually doing a - b :-) */
292
293 max=(a->top > b->top)?a->top:b->top;
294 if (bn_wexpand(r,max) == NULL) return(0);
295 if (BN_ucmp(a,b) < 0)
296 {
297 if (!BN_usub(r,b,a)) return(0);
298 r->neg=1;
299 }
300 else
301 {
302 if (!BN_usub(r,a,b)) return(0);
303 r->neg=0;
304 }
305 return(1);
166 } 306 }
167 307
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 @@
1/* crypto/bn/bn_asm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63#ifdef BN_LLONG
64
65BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
66 {
67 BN_ULONG c1=0;
68
69 bn_check_num(num);
70 if (num <= 0) return(c1);
71
72 for (;;)
73 {
74 mul_add(rp[0],ap[0],w,c1);
75 if (--num == 0) break;
76 mul_add(rp[1],ap[1],w,c1);
77 if (--num == 0) break;
78 mul_add(rp[2],ap[2],w,c1);
79 if (--num == 0) break;
80 mul_add(rp[3],ap[3],w,c1);
81 if (--num == 0) break;
82 ap+=4;
83 rp+=4;
84 }
85
86 return(c1);
87 }
88
89BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
90 {
91 BN_ULONG c1=0;
92
93 bn_check_num(num);
94 if (num <= 0) return(c1);
95
96 /* for (;;) */
97 while (1) /* circumvent egcs-1.1.2 bug */
98 {
99 mul(rp[0],ap[0],w,c1);
100 if (--num == 0) break;
101 mul(rp[1],ap[1],w,c1);
102 if (--num == 0) break;
103 mul(rp[2],ap[2],w,c1);
104 if (--num == 0) break;
105 mul(rp[3],ap[3],w,c1);
106 if (--num == 0) break;
107 ap+=4;
108 rp+=4;
109 }
110 return(c1);
111 }
112
113void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
114 {
115 bn_check_num(n);
116 if (n <= 0) return;
117 for (;;)
118 {
119 BN_ULLONG t;
120
121 t=(BN_ULLONG)(a[0])*(a[0]);
122 r[0]=Lw(t); r[1]=Hw(t);
123 if (--n == 0) break;
124
125 t=(BN_ULLONG)(a[1])*(a[1]);
126 r[2]=Lw(t); r[3]=Hw(t);
127 if (--n == 0) break;
128
129 t=(BN_ULLONG)(a[2])*(a[2]);
130 r[4]=Lw(t); r[5]=Hw(t);
131 if (--n == 0) break;
132
133 t=(BN_ULLONG)(a[3])*(a[3]);
134 r[6]=Lw(t); r[7]=Hw(t);
135 if (--n == 0) break;
136
137 a+=4;
138 r+=8;
139 }
140 }
141
142#else
143
144BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
145 {
146 BN_ULONG c=0;
147 BN_ULONG bl,bh;
148
149 bn_check_num(num);
150 if (num <= 0) return((BN_ULONG)0);
151
152 bl=LBITS(w);
153 bh=HBITS(w);
154
155 for (;;)
156 {
157 mul_add(rp[0],ap[0],bl,bh,c);
158 if (--num == 0) break;
159 mul_add(rp[1],ap[1],bl,bh,c);
160 if (--num == 0) break;
161 mul_add(rp[2],ap[2],bl,bh,c);
162 if (--num == 0) break;
163 mul_add(rp[3],ap[3],bl,bh,c);
164 if (--num == 0) break;
165 ap+=4;
166 rp+=4;
167 }
168 return(c);
169 }
170
171BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
172 {
173 BN_ULONG carry=0;
174 BN_ULONG bl,bh;
175
176 bn_check_num(num);
177 if (num <= 0) return((BN_ULONG)0);
178
179 bl=LBITS(w);
180 bh=HBITS(w);
181
182 for (;;)
183 {
184 mul(rp[0],ap[0],bl,bh,carry);
185 if (--num == 0) break;
186 mul(rp[1],ap[1],bl,bh,carry);
187 if (--num == 0) break;
188 mul(rp[2],ap[2],bl,bh,carry);
189 if (--num == 0) break;
190 mul(rp[3],ap[3],bl,bh,carry);
191 if (--num == 0) break;
192 ap+=4;
193 rp+=4;
194 }
195 return(carry);
196 }
197
198void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
199 {
200 bn_check_num(n);
201 if (n <= 0) return;
202 for (;;)
203 {
204 sqr64(r[0],r[1],a[0]);
205 if (--n == 0) break;
206
207 sqr64(r[2],r[3],a[1]);
208 if (--n == 0) break;
209
210 sqr64(r[4],r[5],a[2]);
211 if (--n == 0) break;
212
213 sqr64(r[6],r[7],a[3]);
214 if (--n == 0) break;
215
216 a+=4;
217 r+=8;
218 }
219 }
220
221#endif
222
223#if defined(BN_LLONG) && defined(BN_DIV2W)
224
225BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
226 {
227 return((BN_ULONG)(((((BN_ULLONG)h)<<BN_BITS2)|l)/(BN_ULLONG)d));
228 }
229
230#else
231
232/* Divide h-l by d and return the result. */
233/* I need to test this some more :-( */
234BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
235 {
236 BN_ULONG dh,dl,q,ret=0,th,tl,t;
237 int i,count=2;
238
239 if (d == 0) return(BN_MASK2);
240
241 i=BN_num_bits_word(d);
242 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i))
243 {
244#if !defined(NO_STDIO) && !defined(WIN16)
245 fprintf(stderr,"Division would overflow (%d)\n",i);
246#endif
247 abort();
248 }
249 i=BN_BITS2-i;
250 if (h >= d) h-=d;
251
252 if (i)
253 {
254 d<<=i;
255 h=(h<<i)|(l>>(BN_BITS2-i));
256 l<<=i;
257 }
258 dh=(d&BN_MASK2h)>>BN_BITS4;
259 dl=(d&BN_MASK2l);
260 for (;;)
261 {
262 if ((h>>BN_BITS4) == dh)
263 q=BN_MASK2l;
264 else
265 q=h/dh;
266
267 th=q*dh;
268 tl=dl*q;
269 for (;;)
270 {
271 t=h-th;
272 if ((t&BN_MASK2h) ||
273 ((tl) <= (
274 (t<<BN_BITS4)|
275 ((l&BN_MASK2h)>>BN_BITS4))))
276 break;
277 q--;
278 th-=dh;
279 tl-=dl;
280 }
281 t=(tl>>BN_BITS4);
282 tl=(tl<<BN_BITS4)&BN_MASK2h;
283 th+=t;
284
285 if (l < tl) th++;
286 l-=tl;
287 if (h < th)
288 {
289 h+=d;
290 q--;
291 }
292 h-=th;
293
294 if (--count == 0) break;
295
296 ret=q<<BN_BITS4;
297 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
298 l=(l&BN_MASK2l)<<BN_BITS4;
299 }
300 ret|=q;
301 return(ret);
302 }
303#endif
304
305#ifdef BN_LLONG
306BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
307 {
308 BN_ULLONG ll=0;
309
310 bn_check_num(n);
311 if (n <= 0) return((BN_ULONG)0);
312
313 for (;;)
314 {
315 ll+=(BN_ULLONG)a[0]+b[0];
316 r[0]=(BN_ULONG)ll&BN_MASK2;
317 ll>>=BN_BITS2;
318 if (--n <= 0) break;
319
320 ll+=(BN_ULLONG)a[1]+b[1];
321 r[1]=(BN_ULONG)ll&BN_MASK2;
322 ll>>=BN_BITS2;
323 if (--n <= 0) break;
324
325 ll+=(BN_ULLONG)a[2]+b[2];
326 r[2]=(BN_ULONG)ll&BN_MASK2;
327 ll>>=BN_BITS2;
328 if (--n <= 0) break;
329
330 ll+=(BN_ULLONG)a[3]+b[3];
331 r[3]=(BN_ULONG)ll&BN_MASK2;
332 ll>>=BN_BITS2;
333 if (--n <= 0) break;
334
335 a+=4;
336 b+=4;
337 r+=4;
338 }
339 return((BN_ULONG)ll);
340 }
341#else
342BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
343 {
344 BN_ULONG c,l,t;
345
346 bn_check_num(n);
347 if (n <= 0) return((BN_ULONG)0);
348
349 c=0;
350 for (;;)
351 {
352 t=a[0];
353 t=(t+c)&BN_MASK2;
354 c=(t < c);
355 l=(t+b[0])&BN_MASK2;
356 c+=(l < t);
357 r[0]=l;
358 if (--n <= 0) break;
359
360 t=a[1];
361 t=(t+c)&BN_MASK2;
362 c=(t < c);
363 l=(t+b[1])&BN_MASK2;
364 c+=(l < t);
365 r[1]=l;
366 if (--n <= 0) break;
367
368 t=a[2];
369 t=(t+c)&BN_MASK2;
370 c=(t < c);
371 l=(t+b[2])&BN_MASK2;
372 c+=(l < t);
373 r[2]=l;
374 if (--n <= 0) break;
375
376 t=a[3];
377 t=(t+c)&BN_MASK2;
378 c=(t < c);
379 l=(t+b[3])&BN_MASK2;
380 c+=(l < t);
381 r[3]=l;
382 if (--n <= 0) break;
383
384 a+=4;
385 b+=4;
386 r+=4;
387 }
388 return((BN_ULONG)c);
389 }
390#endif
391
392BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
393 {
394 BN_ULONG t1,t2;
395 int c=0;
396
397 bn_check_num(n);
398 if (n <= 0) return((BN_ULONG)0);
399
400 for (;;)
401 {
402 t1=a[0]; t2=b[0];
403 r[0]=(t1-t2-c)&BN_MASK2;
404 if (t1 != t2) c=(t1 < t2);
405 if (--n <= 0) break;
406
407 t1=a[1]; t2=b[1];
408 r[1]=(t1-t2-c)&BN_MASK2;
409 if (t1 != t2) c=(t1 < t2);
410 if (--n <= 0) break;
411
412 t1=a[2]; t2=b[2];
413 r[2]=(t1-t2-c)&BN_MASK2;
414 if (t1 != t2) c=(t1 < t2);
415 if (--n <= 0) break;
416
417 t1=a[3]; t2=b[3];
418 r[3]=(t1-t2-c)&BN_MASK2;
419 if (t1 != t2) c=(t1 < t2);
420 if (--n <= 0) break;
421
422 a+=4;
423 b+=4;
424 r+=4;
425 }
426 return(c);
427 }
428
429#ifdef BN_MUL_COMBA
430
431#undef bn_mul_comba8
432#undef bn_mul_comba4
433#undef bn_sqr_comba8
434#undef bn_sqr_comba4
435
436#ifdef BN_LLONG
437#define mul_add_c(a,b,c0,c1,c2) \
438 t=(BN_ULLONG)a*b; \
439 t1=(BN_ULONG)Lw(t); \
440 t2=(BN_ULONG)Hw(t); \
441 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
442 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
443
444#define mul_add_c2(a,b,c0,c1,c2) \
445 t=(BN_ULLONG)a*b; \
446 tt=(t+t)&BN_MASK; \
447 if (tt < t) c2++; \
448 t1=(BN_ULONG)Lw(tt); \
449 t2=(BN_ULONG)Hw(tt); \
450 c0=(c0+t1)&BN_MASK2; \
451 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
452 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
453
454#define sqr_add_c(a,i,c0,c1,c2) \
455 t=(BN_ULLONG)a[i]*a[i]; \
456 t1=(BN_ULONG)Lw(t); \
457 t2=(BN_ULONG)Hw(t); \
458 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
459 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
460
461#define sqr_add_c2(a,i,j,c0,c1,c2) \
462 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
463#else
464#define mul_add_c(a,b,c0,c1,c2) \
465 t1=LBITS(a); t2=HBITS(a); \
466 bl=LBITS(b); bh=HBITS(b); \
467 mul64(t1,t2,bl,bh); \
468 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
469 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
470
471#define mul_add_c2(a,b,c0,c1,c2) \
472 t1=LBITS(a); t2=HBITS(a); \
473 bl=LBITS(b); bh=HBITS(b); \
474 mul64(t1,t2,bl,bh); \
475 if (t2 & BN_TBIT) c2++; \
476 t2=(t2+t2)&BN_MASK2; \
477 if (t1 & BN_TBIT) t2++; \
478 t1=(t1+t1)&BN_MASK2; \
479 c0=(c0+t1)&BN_MASK2; \
480 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
481 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
482
483#define sqr_add_c(a,i,c0,c1,c2) \
484 sqr64(t1,t2,(a)[i]); \
485 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
486 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
487
488#define sqr_add_c2(a,i,j,c0,c1,c2) \
489 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
490#endif
491
492void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
493 {
494#ifdef BN_LLONG
495 BN_ULLONG t;
496#else
497 BN_ULONG bl,bh;
498#endif
499 BN_ULONG t1,t2;
500 BN_ULONG c1,c2,c3;
501
502 c1=0;
503 c2=0;
504 c3=0;
505 mul_add_c(a[0],b[0],c1,c2,c3);
506 r[0]=c1;
507 c1=0;
508 mul_add_c(a[0],b[1],c2,c3,c1);
509 mul_add_c(a[1],b[0],c2,c3,c1);
510 r[1]=c2;
511 c2=0;
512 mul_add_c(a[2],b[0],c3,c1,c2);
513 mul_add_c(a[1],b[1],c3,c1,c2);
514 mul_add_c(a[0],b[2],c3,c1,c2);
515 r[2]=c3;
516 c3=0;
517 mul_add_c(a[0],b[3],c1,c2,c3);
518 mul_add_c(a[1],b[2],c1,c2,c3);
519 mul_add_c(a[2],b[1],c1,c2,c3);
520 mul_add_c(a[3],b[0],c1,c2,c3);
521 r[3]=c1;
522 c1=0;
523 mul_add_c(a[4],b[0],c2,c3,c1);
524 mul_add_c(a[3],b[1],c2,c3,c1);
525 mul_add_c(a[2],b[2],c2,c3,c1);
526 mul_add_c(a[1],b[3],c2,c3,c1);
527 mul_add_c(a[0],b[4],c2,c3,c1);
528 r[4]=c2;
529 c2=0;
530 mul_add_c(a[0],b[5],c3,c1,c2);
531 mul_add_c(a[1],b[4],c3,c1,c2);
532 mul_add_c(a[2],b[3],c3,c1,c2);
533 mul_add_c(a[3],b[2],c3,c1,c2);
534 mul_add_c(a[4],b[1],c3,c1,c2);
535 mul_add_c(a[5],b[0],c3,c1,c2);
536 r[5]=c3;
537 c3=0;
538 mul_add_c(a[6],b[0],c1,c2,c3);
539 mul_add_c(a[5],b[1],c1,c2,c3);
540 mul_add_c(a[4],b[2],c1,c2,c3);
541 mul_add_c(a[3],b[3],c1,c2,c3);
542 mul_add_c(a[2],b[4],c1,c2,c3);
543 mul_add_c(a[1],b[5],c1,c2,c3);
544 mul_add_c(a[0],b[6],c1,c2,c3);
545 r[6]=c1;
546 c1=0;
547 mul_add_c(a[0],b[7],c2,c3,c1);
548 mul_add_c(a[1],b[6],c2,c3,c1);
549 mul_add_c(a[2],b[5],c2,c3,c1);
550 mul_add_c(a[3],b[4],c2,c3,c1);
551 mul_add_c(a[4],b[3],c2,c3,c1);
552 mul_add_c(a[5],b[2],c2,c3,c1);
553 mul_add_c(a[6],b[1],c2,c3,c1);
554 mul_add_c(a[7],b[0],c2,c3,c1);
555 r[7]=c2;
556 c2=0;
557 mul_add_c(a[7],b[1],c3,c1,c2);
558 mul_add_c(a[6],b[2],c3,c1,c2);
559 mul_add_c(a[5],b[3],c3,c1,c2);
560 mul_add_c(a[4],b[4],c3,c1,c2);
561 mul_add_c(a[3],b[5],c3,c1,c2);
562 mul_add_c(a[2],b[6],c3,c1,c2);
563 mul_add_c(a[1],b[7],c3,c1,c2);
564 r[8]=c3;
565 c3=0;
566 mul_add_c(a[2],b[7],c1,c2,c3);
567 mul_add_c(a[3],b[6],c1,c2,c3);
568 mul_add_c(a[4],b[5],c1,c2,c3);
569 mul_add_c(a[5],b[4],c1,c2,c3);
570 mul_add_c(a[6],b[3],c1,c2,c3);
571 mul_add_c(a[7],b[2],c1,c2,c3);
572 r[9]=c1;
573 c1=0;
574 mul_add_c(a[7],b[3],c2,c3,c1);
575 mul_add_c(a[6],b[4],c2,c3,c1);
576 mul_add_c(a[5],b[5],c2,c3,c1);
577 mul_add_c(a[4],b[6],c2,c3,c1);
578 mul_add_c(a[3],b[7],c2,c3,c1);
579 r[10]=c2;
580 c2=0;
581 mul_add_c(a[4],b[7],c3,c1,c2);
582 mul_add_c(a[5],b[6],c3,c1,c2);
583 mul_add_c(a[6],b[5],c3,c1,c2);
584 mul_add_c(a[7],b[4],c3,c1,c2);
585 r[11]=c3;
586 c3=0;
587 mul_add_c(a[7],b[5],c1,c2,c3);
588 mul_add_c(a[6],b[6],c1,c2,c3);
589 mul_add_c(a[5],b[7],c1,c2,c3);
590 r[12]=c1;
591 c1=0;
592 mul_add_c(a[6],b[7],c2,c3,c1);
593 mul_add_c(a[7],b[6],c2,c3,c1);
594 r[13]=c2;
595 c2=0;
596 mul_add_c(a[7],b[7],c3,c1,c2);
597 r[14]=c3;
598 r[15]=c1;
599 }
600
601void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
602 {
603#ifdef BN_LLONG
604 BN_ULLONG t;
605#else
606 BN_ULONG bl,bh;
607#endif
608 BN_ULONG t1,t2;
609 BN_ULONG c1,c2,c3;
610
611 c1=0;
612 c2=0;
613 c3=0;
614 mul_add_c(a[0],b[0],c1,c2,c3);
615 r[0]=c1;
616 c1=0;
617 mul_add_c(a[0],b[1],c2,c3,c1);
618 mul_add_c(a[1],b[0],c2,c3,c1);
619 r[1]=c2;
620 c2=0;
621 mul_add_c(a[2],b[0],c3,c1,c2);
622 mul_add_c(a[1],b[1],c3,c1,c2);
623 mul_add_c(a[0],b[2],c3,c1,c2);
624 r[2]=c3;
625 c3=0;
626 mul_add_c(a[0],b[3],c1,c2,c3);
627 mul_add_c(a[1],b[2],c1,c2,c3);
628 mul_add_c(a[2],b[1],c1,c2,c3);
629 mul_add_c(a[3],b[0],c1,c2,c3);
630 r[3]=c1;
631 c1=0;
632 mul_add_c(a[3],b[1],c2,c3,c1);
633 mul_add_c(a[2],b[2],c2,c3,c1);
634 mul_add_c(a[1],b[3],c2,c3,c1);
635 r[4]=c2;
636 c2=0;
637 mul_add_c(a[2],b[3],c3,c1,c2);
638 mul_add_c(a[3],b[2],c3,c1,c2);
639 r[5]=c3;
640 c3=0;
641 mul_add_c(a[3],b[3],c1,c2,c3);
642 r[6]=c1;
643 r[7]=c2;
644 }
645
646void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
647 {
648#ifdef BN_LLONG
649 BN_ULLONG t,tt;
650#else
651 BN_ULONG bl,bh;
652#endif
653 BN_ULONG t1,t2;
654 BN_ULONG c1,c2,c3;
655
656 c1=0;
657 c2=0;
658 c3=0;
659 sqr_add_c(a,0,c1,c2,c3);
660 r[0]=c1;
661 c1=0;
662 sqr_add_c2(a,1,0,c2,c3,c1);
663 r[1]=c2;
664 c2=0;
665 sqr_add_c(a,1,c3,c1,c2);
666 sqr_add_c2(a,2,0,c3,c1,c2);
667 r[2]=c3;
668 c3=0;
669 sqr_add_c2(a,3,0,c1,c2,c3);
670 sqr_add_c2(a,2,1,c1,c2,c3);
671 r[3]=c1;
672 c1=0;
673 sqr_add_c(a,2,c2,c3,c1);
674 sqr_add_c2(a,3,1,c2,c3,c1);
675 sqr_add_c2(a,4,0,c2,c3,c1);
676 r[4]=c2;
677 c2=0;
678 sqr_add_c2(a,5,0,c3,c1,c2);
679 sqr_add_c2(a,4,1,c3,c1,c2);
680 sqr_add_c2(a,3,2,c3,c1,c2);
681 r[5]=c3;
682 c3=0;
683 sqr_add_c(a,3,c1,c2,c3);
684 sqr_add_c2(a,4,2,c1,c2,c3);
685 sqr_add_c2(a,5,1,c1,c2,c3);
686 sqr_add_c2(a,6,0,c1,c2,c3);
687 r[6]=c1;
688 c1=0;
689 sqr_add_c2(a,7,0,c2,c3,c1);
690 sqr_add_c2(a,6,1,c2,c3,c1);
691 sqr_add_c2(a,5,2,c2,c3,c1);
692 sqr_add_c2(a,4,3,c2,c3,c1);
693 r[7]=c2;
694 c2=0;
695 sqr_add_c(a,4,c3,c1,c2);
696 sqr_add_c2(a,5,3,c3,c1,c2);
697 sqr_add_c2(a,6,2,c3,c1,c2);
698 sqr_add_c2(a,7,1,c3,c1,c2);
699 r[8]=c3;
700 c3=0;
701 sqr_add_c2(a,7,2,c1,c2,c3);
702 sqr_add_c2(a,6,3,c1,c2,c3);
703 sqr_add_c2(a,5,4,c1,c2,c3);
704 r[9]=c1;
705 c1=0;
706 sqr_add_c(a,5,c2,c3,c1);
707 sqr_add_c2(a,6,4,c2,c3,c1);
708 sqr_add_c2(a,7,3,c2,c3,c1);
709 r[10]=c2;
710 c2=0;
711 sqr_add_c2(a,7,4,c3,c1,c2);
712 sqr_add_c2(a,6,5,c3,c1,c2);
713 r[11]=c3;
714 c3=0;
715 sqr_add_c(a,6,c1,c2,c3);
716 sqr_add_c2(a,7,5,c1,c2,c3);
717 r[12]=c1;
718 c1=0;
719 sqr_add_c2(a,7,6,c2,c3,c1);
720 r[13]=c2;
721 c2=0;
722 sqr_add_c(a,7,c3,c1,c2);
723 r[14]=c3;
724 r[15]=c1;
725 }
726
727void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
728 {
729#ifdef BN_LLONG
730 BN_ULLONG t,tt;
731#else
732 BN_ULONG bl,bh;
733#endif
734 BN_ULONG t1,t2;
735 BN_ULONG c1,c2,c3;
736
737 c1=0;
738 c2=0;
739 c3=0;
740 sqr_add_c(a,0,c1,c2,c3);
741 r[0]=c1;
742 c1=0;
743 sqr_add_c2(a,1,0,c2,c3,c1);
744 r[1]=c2;
745 c2=0;
746 sqr_add_c(a,1,c3,c1,c2);
747 sqr_add_c2(a,2,0,c3,c1,c2);
748 r[2]=c3;
749 c3=0;
750 sqr_add_c2(a,3,0,c1,c2,c3);
751 sqr_add_c2(a,2,1,c1,c2,c3);
752 r[3]=c1;
753 c1=0;
754 sqr_add_c(a,2,c2,c3,c1);
755 sqr_add_c2(a,3,1,c2,c3,c1);
756 r[4]=c2;
757 c2=0;
758 sqr_add_c2(a,3,2,c3,c1,c2);
759 r[5]=c3;
760 c3=0;
761 sqr_add_c(a,3,c1,c2,c3);
762 r[6]=c1;
763 r[7]=c2;
764 }
765#else
766
767/* hmm... is it faster just to do a multiply? */
768#undef bn_sqr_comba4
769void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
770 {
771 BN_ULONG t[8];
772 bn_sqr_normal(r,a,4,t);
773 }
774
775#undef bn_sqr_comba8
776void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
777 {
778 BN_ULONG t[16];
779 bn_sqr_normal(r,a,8,t);
780 }
781
782void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
783 {
784 r[4]=bn_mul_words( &(r[0]),a,4,b[0]);
785 r[5]=bn_mul_add_words(&(r[1]),a,4,b[1]);
786 r[6]=bn_mul_add_words(&(r[2]),a,4,b[2]);
787 r[7]=bn_mul_add_words(&(r[3]),a,4,b[3]);
788 }
789
790void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
791 {
792 r[ 8]=bn_mul_words( &(r[0]),a,8,b[0]);
793 r[ 9]=bn_mul_add_words(&(r[1]),a,8,b[1]);
794 r[10]=bn_mul_add_words(&(r[2]),a,8,b[2]);
795 r[11]=bn_mul_add_words(&(r[3]),a,8,b[3]);
796 r[12]=bn_mul_add_words(&(r[4]),a,8,b[4]);
797 r[13]=bn_mul_add_words(&(r[5]),a,8,b[5]);
798 r[14]=bn_mul_add_words(&(r[6]),a,8,b[6]);
799 r[15]=bn_mul_add_words(&(r[7]),a,8,b[7]);
800 }
801
802#endif /* BN_COMBA */
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c
index a7b34f0bf0..1b1bb06046 100644
--- a/src/lib/libcrypto/bn/bn_blind.c
+++ b/src/lib/libcrypto/bn/bn_blind.c
@@ -60,15 +60,18 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63BN_BLINDING *BN_BLINDING_new(A,Ai,mod) 63BN_BLINDING *BN_BLINDING_new(BIGNUM *A, BIGNUM *Ai, BIGNUM *mod)
64BIGNUM *A;
65BIGNUM *Ai;
66BIGNUM *mod;
67 { 64 {
68 BN_BLINDING *ret=NULL; 65 BN_BLINDING *ret=NULL;
69 66
67 bn_check_top(Ai);
68 bn_check_top(mod);
69
70 if ((ret=(BN_BLINDING *)Malloc(sizeof(BN_BLINDING))) == NULL) 70 if ((ret=(BN_BLINDING *)Malloc(sizeof(BN_BLINDING))) == NULL)
71 {
71 BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE); 72 BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE);
73 return(NULL);
74 }
72 memset(ret,0,sizeof(BN_BLINDING)); 75 memset(ret,0,sizeof(BN_BLINDING));
73 if ((ret->A=BN_new()) == NULL) goto err; 76 if ((ret->A=BN_new()) == NULL) goto err;
74 if ((ret->Ai=BN_new()) == NULL) goto err; 77 if ((ret->Ai=BN_new()) == NULL) goto err;
@@ -78,26 +81,26 @@ BIGNUM *mod;
78 return(ret); 81 return(ret);
79err: 82err:
80 if (ret != NULL) BN_BLINDING_free(ret); 83 if (ret != NULL) BN_BLINDING_free(ret);
81 return(ret); 84 return(NULL);
82 } 85 }
83 86
84void BN_BLINDING_free(r) 87void BN_BLINDING_free(BN_BLINDING *r)
85BN_BLINDING *r;
86 { 88 {
89 if(r == NULL)
90 return;
91
87 if (r->A != NULL) BN_free(r->A ); 92 if (r->A != NULL) BN_free(r->A );
88 if (r->Ai != NULL) BN_free(r->Ai); 93 if (r->Ai != NULL) BN_free(r->Ai);
89 Free(r); 94 Free(r);
90 } 95 }
91 96
92int BN_BLINDING_update(b,ctx) 97int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
93BN_BLINDING *b;
94BN_CTX *ctx;
95 { 98 {
96 int ret=0; 99 int ret=0;
97 100
98 if ((b->A == NULL) || (b->Ai == NULL)) 101 if ((b->A == NULL) || (b->Ai == NULL))
99 { 102 {
100 BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITALISED); 103 BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED);
101 goto err; 104 goto err;
102 } 105 }
103 106
@@ -109,28 +112,26 @@ err:
109 return(ret); 112 return(ret);
110 } 113 }
111 114
112int BN_BLINDING_convert(n,b,ctx) 115int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
113BIGNUM *n;
114BN_BLINDING *b;
115BN_CTX *ctx;
116 { 116 {
117 bn_check_top(n);
118
117 if ((b->A == NULL) || (b->Ai == NULL)) 119 if ((b->A == NULL) || (b->Ai == NULL))
118 { 120 {
119 BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITALISED); 121 BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITIALIZED);
120 return(0); 122 return(0);
121 } 123 }
122 return(BN_mod_mul(n,n,b->A,b->mod,ctx)); 124 return(BN_mod_mul(n,n,b->A,b->mod,ctx));
123 } 125 }
124 126
125int BN_BLINDING_invert(n,b,ctx) 127int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
126BIGNUM *n;
127BN_BLINDING *b;
128BN_CTX *ctx;
129 { 128 {
130 int ret; 129 int ret;
130
131 bn_check_top(n);
131 if ((b->A == NULL) || (b->Ai == NULL)) 132 if ((b->A == NULL) || (b->Ai == NULL))
132 { 133 {
133 BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITALISED); 134 BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED);
134 return(0); 135 return(0);
135 } 136 }
136 if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0) 137 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 @@
1/* crypto/bn/bn_comba.c */
2#include <stdio.h>
3#include "bn_lcl.h"
4/* Auto generated from crypto/bn/comba.pl
5 */
6
7#undef bn_mul_comba8
8#undef bn_mul_comba4
9#undef bn_sqr_comba8
10#undef bn_sqr_comba4
11
12#ifdef BN_LLONG
13#define mul_add_c(a,b,c0,c1,c2) \
14 t=(BN_ULLONG)a*b; \
15 t1=(BN_ULONG)Lw(t); \
16 t2=(BN_ULONG)Hw(t); \
17 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
18 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
19
20#define mul_add_c2(a,b,c0,c1,c2) \
21 t=(BN_ULLONG)a*b; \
22 tt=(t+t)&BN_MASK; \
23 if (tt < t) c2++; \
24 t1=(BN_ULONG)Lw(tt); \
25 t2=(BN_ULONG)Hw(tt); \
26 c0=(c0+t1)&BN_MASK2; \
27 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
28 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
29
30#define sqr_add_c(a,i,c0,c1,c2) \
31 t=(BN_ULLONG)a[i]*a[i]; \
32 t1=(BN_ULONG)Lw(t); \
33 t2=(BN_ULONG)Hw(t); \
34 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
35 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
36
37#define sqr_add_c2(a,i,j,c0,c1,c2) \
38 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
39#else
40#define mul_add_c(a,b,c0,c1,c2) \
41 t1=LBITS(a); t2=HBITS(a); \
42 bl=LBITS(b); bh=HBITS(b); \
43 mul64(t1,t2,bl,bh); \
44 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
45 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
46
47#define mul_add_c2(a,b,c0,c1,c2) \
48 t1=LBITS(a); t2=HBITS(a); \
49 bl=LBITS(b); bh=HBITS(b); \
50 mul64(t1,t2,bl,bh); \
51 if (t2 & BN_TBIT) c2++; \
52 t2=(t2+t2)&BN_MASK2; \
53 if (t1 & BN_TBIT) t2++; \
54 t1=(t1+t1)&BN_MASK2; \
55 c0=(c0+t1)&BN_MASK2; \
56 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \
57 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
58
59#define sqr_add_c(a,i,c0,c1,c2) \
60 sqr64(t1,t2,(a)[i]); \
61 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \
62 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
63
64#define sqr_add_c2(a,i,j,c0,c1,c2) \
65 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
66#endif
67
68void bn_mul_comba88(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
69void bn_mul_comba44(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
70void bn_sqr_comba88(BN_ULONG *r,BN_ULONG *a);
71void bn_sqr_comba44(BN_ULONG *r,BN_ULONG *a);
72
73void bn_mul_comba88(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
74 {
75#ifdef BN_LLONG
76 BN_ULLONG t;
77#else
78 BN_ULONG bl,bh;
79#endif
80 BN_ULONG t1,t2;
81 BN_ULONG c1,c2,c3;
82
83 c1=0;
84 c2=0;
85 c3=0;
86 mul_add_c(a[0],b[0],c1,c2,c3);
87 r[0]=c1;
88 c1=0;
89 mul_add_c(a[0],b[1],c2,c3,c1);
90 mul_add_c(a[1],b[0],c2,c3,c1);
91 r[1]=c2;
92 c2=0;
93 mul_add_c(a[2],b[0],c3,c1,c2);
94 mul_add_c(a[1],b[1],c3,c1,c2);
95 mul_add_c(a[0],b[2],c3,c1,c2);
96 r[2]=c3;
97 c3=0;
98 mul_add_c(a[0],b[3],c1,c2,c3);
99 mul_add_c(a[1],b[2],c1,c2,c3);
100 mul_add_c(a[2],b[1],c1,c2,c3);
101 mul_add_c(a[3],b[0],c1,c2,c3);
102 r[3]=c1;
103 c1=0;
104 mul_add_c(a[4],b[0],c2,c3,c1);
105 mul_add_c(a[3],b[1],c2,c3,c1);
106 mul_add_c(a[2],b[2],c2,c3,c1);
107 mul_add_c(a[1],b[3],c2,c3,c1);
108 mul_add_c(a[0],b[4],c2,c3,c1);
109 r[4]=c2;
110 c2=0;
111 mul_add_c(a[0],b[5],c3,c1,c2);
112 mul_add_c(a[1],b[4],c3,c1,c2);
113 mul_add_c(a[2],b[3],c3,c1,c2);
114 mul_add_c(a[3],b[2],c3,c1,c2);
115 mul_add_c(a[4],b[1],c3,c1,c2);
116 mul_add_c(a[5],b[0],c3,c1,c2);
117 r[5]=c3;
118 c3=0;
119 mul_add_c(a[6],b[0],c1,c2,c3);
120 mul_add_c(a[5],b[1],c1,c2,c3);
121 mul_add_c(a[4],b[2],c1,c2,c3);
122 mul_add_c(a[3],b[3],c1,c2,c3);
123 mul_add_c(a[2],b[4],c1,c2,c3);
124 mul_add_c(a[1],b[5],c1,c2,c3);
125 mul_add_c(a[0],b[6],c1,c2,c3);
126 r[6]=c1;
127 c1=0;
128 mul_add_c(a[0],b[7],c2,c3,c1);
129 mul_add_c(a[1],b[6],c2,c3,c1);
130 mul_add_c(a[2],b[5],c2,c3,c1);
131 mul_add_c(a[3],b[4],c2,c3,c1);
132 mul_add_c(a[4],b[3],c2,c3,c1);
133 mul_add_c(a[5],b[2],c2,c3,c1);
134 mul_add_c(a[6],b[1],c2,c3,c1);
135 mul_add_c(a[7],b[0],c2,c3,c1);
136 r[7]=c2;
137 c2=0;
138 mul_add_c(a[7],b[1],c3,c1,c2);
139 mul_add_c(a[6],b[2],c3,c1,c2);
140 mul_add_c(a[5],b[3],c3,c1,c2);
141 mul_add_c(a[4],b[4],c3,c1,c2);
142 mul_add_c(a[3],b[5],c3,c1,c2);
143 mul_add_c(a[2],b[6],c3,c1,c2);
144 mul_add_c(a[1],b[7],c3,c1,c2);
145 r[8]=c3;
146 c3=0;
147 mul_add_c(a[2],b[7],c1,c2,c3);
148 mul_add_c(a[3],b[6],c1,c2,c3);
149 mul_add_c(a[4],b[5],c1,c2,c3);
150 mul_add_c(a[5],b[4],c1,c2,c3);
151 mul_add_c(a[6],b[3],c1,c2,c3);
152 mul_add_c(a[7],b[2],c1,c2,c3);
153 r[9]=c1;
154 c1=0;
155 mul_add_c(a[7],b[3],c2,c3,c1);
156 mul_add_c(a[6],b[4],c2,c3,c1);
157 mul_add_c(a[5],b[5],c2,c3,c1);
158 mul_add_c(a[4],b[6],c2,c3,c1);
159 mul_add_c(a[3],b[7],c2,c3,c1);
160 r[10]=c2;
161 c2=0;
162 mul_add_c(a[4],b[7],c3,c1,c2);
163 mul_add_c(a[5],b[6],c3,c1,c2);
164 mul_add_c(a[6],b[5],c3,c1,c2);
165 mul_add_c(a[7],b[4],c3,c1,c2);
166 r[11]=c3;
167 c3=0;
168 mul_add_c(a[7],b[5],c1,c2,c3);
169 mul_add_c(a[6],b[6],c1,c2,c3);
170 mul_add_c(a[5],b[7],c1,c2,c3);
171 r[12]=c1;
172 c1=0;
173 mul_add_c(a[6],b[7],c2,c3,c1);
174 mul_add_c(a[7],b[6],c2,c3,c1);
175 r[13]=c2;
176 c2=0;
177 mul_add_c(a[7],b[7],c3,c1,c2);
178 r[14]=c3;
179 r[15]=c1;
180 }
181
182void bn_mul_comba44(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
183 {
184#ifdef BN_LLONG
185 BN_ULLONG t;
186#else
187 BN_ULONG bl,bh;
188#endif
189 BN_ULONG t1,t2;
190 BN_ULONG c1,c2,c3;
191
192 c1=0;
193 c2=0;
194 c3=0;
195 mul_add_c(a[0],b[0],c1,c2,c3);
196 r[0]=c1;
197 c1=0;
198 mul_add_c(a[0],b[1],c2,c3,c1);
199 mul_add_c(a[1],b[0],c2,c3,c1);
200 r[1]=c2;
201 c2=0;
202 mul_add_c(a[2],b[0],c3,c1,c2);
203 mul_add_c(a[1],b[1],c3,c1,c2);
204 mul_add_c(a[0],b[2],c3,c1,c2);
205 r[2]=c3;
206 c3=0;
207 mul_add_c(a[0],b[3],c1,c2,c3);
208 mul_add_c(a[1],b[2],c1,c2,c3);
209 mul_add_c(a[2],b[1],c1,c2,c3);
210 mul_add_c(a[3],b[0],c1,c2,c3);
211 r[3]=c1;
212 c1=0;
213 mul_add_c(a[3],b[1],c2,c3,c1);
214 mul_add_c(a[2],b[2],c2,c3,c1);
215 mul_add_c(a[1],b[3],c2,c3,c1);
216 r[4]=c2;
217 c2=0;
218 mul_add_c(a[2],b[3],c3,c1,c2);
219 mul_add_c(a[3],b[2],c3,c1,c2);
220 r[5]=c3;
221 c3=0;
222 mul_add_c(a[3],b[3],c1,c2,c3);
223 r[6]=c1;
224 r[7]=c2;
225 }
226
227void bn_sqr_comba88(BN_ULONG *r, BN_ULONG *a)
228 {
229#ifdef BN_LLONG
230 BN_ULLONG t,tt;
231#else
232 BN_ULONG bl,bh;
233#endif
234 BN_ULONG t1,t2;
235 BN_ULONG c1,c2,c3;
236
237 c1=0;
238 c2=0;
239 c3=0;
240 sqr_add_c(a,0,c1,c2,c3);
241 r[0]=c1;
242 c1=0;
243 sqr_add_c2(a,1,0,c2,c3,c1);
244 r[1]=c2;
245 c2=0;
246 sqr_add_c(a,1,c3,c1,c2);
247 sqr_add_c2(a,2,0,c3,c1,c2);
248 r[2]=c3;
249 c3=0;
250 sqr_add_c2(a,3,0,c1,c2,c3);
251 sqr_add_c2(a,2,1,c1,c2,c3);
252 r[3]=c1;
253 c1=0;
254 sqr_add_c(a,2,c2,c3,c1);
255 sqr_add_c2(a,3,1,c2,c3,c1);
256 sqr_add_c2(a,4,0,c2,c3,c1);
257 r[4]=c2;
258 c2=0;
259 sqr_add_c2(a,5,0,c3,c1,c2);
260 sqr_add_c2(a,4,1,c3,c1,c2);
261 sqr_add_c2(a,3,2,c3,c1,c2);
262 r[5]=c3;
263 c3=0;
264 sqr_add_c(a,3,c1,c2,c3);
265 sqr_add_c2(a,4,2,c1,c2,c3);
266 sqr_add_c2(a,5,1,c1,c2,c3);
267 sqr_add_c2(a,6,0,c1,c2,c3);
268 r[6]=c1;
269 c1=0;
270 sqr_add_c2(a,7,0,c2,c3,c1);
271 sqr_add_c2(a,6,1,c2,c3,c1);
272 sqr_add_c2(a,5,2,c2,c3,c1);
273 sqr_add_c2(a,4,3,c2,c3,c1);
274 r[7]=c2;
275 c2=0;
276 sqr_add_c(a,4,c3,c1,c2);
277 sqr_add_c2(a,5,3,c3,c1,c2);
278 sqr_add_c2(a,6,2,c3,c1,c2);
279 sqr_add_c2(a,7,1,c3,c1,c2);
280 r[8]=c3;
281 c3=0;
282 sqr_add_c2(a,7,2,c1,c2,c3);
283 sqr_add_c2(a,6,3,c1,c2,c3);
284 sqr_add_c2(a,5,4,c1,c2,c3);
285 r[9]=c1;
286 c1=0;
287 sqr_add_c(a,5,c2,c3,c1);
288 sqr_add_c2(a,6,4,c2,c3,c1);
289 sqr_add_c2(a,7,3,c2,c3,c1);
290 r[10]=c2;
291 c2=0;
292 sqr_add_c2(a,7,4,c3,c1,c2);
293 sqr_add_c2(a,6,5,c3,c1,c2);
294 r[11]=c3;
295 c3=0;
296 sqr_add_c(a,6,c1,c2,c3);
297 sqr_add_c2(a,7,5,c1,c2,c3);
298 r[12]=c1;
299 c1=0;
300 sqr_add_c2(a,7,6,c2,c3,c1);
301 r[13]=c2;
302 c2=0;
303 sqr_add_c(a,7,c3,c1,c2);
304 r[14]=c3;
305 r[15]=c1;
306 }
307
308void bn_sqr_comba44(BN_ULONG *r, BN_ULONG *a)
309 {
310#ifdef BN_LLONG
311 BN_ULLONG t,tt;
312#else
313 BN_ULONG bl,bh;
314#endif
315 BN_ULONG t1,t2;
316 BN_ULONG c1,c2,c3;
317
318 c1=0;
319 c2=0;
320 c3=0;
321 sqr_add_c(a,0,c1,c2,c3);
322 r[0]=c1;
323 c1=0;
324 sqr_add_c2(a,1,0,c2,c3,c1);
325 r[1]=c2;
326 c2=0;
327 sqr_add_c(a,1,c3,c1,c2);
328 sqr_add_c2(a,2,0,c3,c1,c2);
329 r[2]=c3;
330 c3=0;
331 sqr_add_c2(a,3,0,c1,c2,c3);
332 sqr_add_c2(a,2,1,c1,c2,c3);
333 r[3]=c1;
334 c1=0;
335 sqr_add_c(a,2,c2,c3,c1);
336 sqr_add_c2(a,3,1,c2,c3,c1);
337 r[4]=c2;
338 c2=0;
339 sqr_add_c2(a,3,2,c3,c1,c2);
340 r[5]=c3;
341 c3=0;
342 sqr_add_c(a,3,c1,c2,c3);
343 r[6]=c1;
344 r[7]=c2;
345 }
diff --git a/src/lib/libcrypto/bn/bn_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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <openssl/bn.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "bn_lcl.h" 62#include "bn_lcl.h"
62 63
63/* The old slow way */ 64/* The old slow way */
64#if 0 65#if 0
65int BN_div(dv, rem, m, d,ctx) 66int BN_div(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)
66BIGNUM *dv;
67BIGNUM *rem;
68BIGNUM *m;
69BIGNUM *d;
70BN_CTX *ctx;
71 { 67 {
72 int i,nm,nd; 68 int i,nm,nd;
73 BIGNUM *D; 69 BIGNUM *D;
74 70
71 bn_check_top(m);
72 bn_check_top(d);
75 if (BN_is_zero(d)) 73 if (BN_is_zero(d))
76 { 74 {
77 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); 75 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
@@ -86,9 +84,9 @@ BN_CTX *ctx;
86 return(1); 84 return(1);
87 } 85 }
88 86
89 D=ctx->bn[ctx->tos]; 87 D= &(ctx->bn[ctx->tos]);
90 if (dv == NULL) dv=ctx->bn[ctx->tos+1]; 88 if (dv == NULL) dv= &(ctx->bn[ctx->tos+1]);
91 if (rem == NULL) rem=ctx->bn[ctx->tos+2]; 89 if (rem == NULL) rem= &(ctx->bn[ctx->tos+2]);
92 90
93 nd=BN_num_bits(d); 91 nd=BN_num_bits(d);
94 nm=BN_num_bits(m); 92 nm=BN_num_bits(m);
@@ -98,6 +96,7 @@ BN_CTX *ctx;
98 /* The next 2 are needed so we can do a dv->d[0]|=1 later 96 /* The next 2 are needed so we can do a dv->d[0]|=1 later
99 * since BN_lshift1 will only work once there is a value :-) */ 97 * since BN_lshift1 will only work once there is a value :-) */
100 BN_zero(dv); 98 BN_zero(dv);
99 bn_wexpand(dv,1);
101 dv->top=1; 100 dv->top=1;
102 101
103 if (!BN_lshift(D,D,nm-nd)) return(0); 102 if (!BN_lshift(D,D,nm-nd)) return(0);
@@ -107,7 +106,7 @@ BN_CTX *ctx;
107 if (BN_ucmp(rem,D) >= 0) 106 if (BN_ucmp(rem,D) >= 0)
108 { 107 {
109 dv->d[0]|=1; 108 dv->d[0]|=1;
110 bn_qsub(rem,rem,D); 109 if (!BN_usub(rem,rem,D)) return(0);
111 } 110 }
112/* CAN IMPROVE (and have now :=) */ 111/* CAN IMPROVE (and have now :=) */
113 if (!BN_rshift1(D,D)) return(0); 112 if (!BN_rshift1(D,D)) return(0);
@@ -119,12 +118,8 @@ BN_CTX *ctx;
119 118
120#else 119#else
121 120
122int BN_div(dv, rm, num, divisor,ctx) 121int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
123BIGNUM *dv; 122 BN_CTX *ctx)
124BIGNUM *rm;
125BIGNUM *num;
126BIGNUM *divisor;
127BN_CTX *ctx;
128 { 123 {
129 int norm_shift,i,j,loop; 124 int norm_shift,i,j,loop;
130 BIGNUM *tmp,wnum,*snum,*sdiv,*res; 125 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
@@ -132,6 +127,9 @@ BN_CTX *ctx;
132 BN_ULONG d0,d1; 127 BN_ULONG d0,d1;
133 int num_n,div_n; 128 int num_n,div_n;
134 129
130 bn_check_top(num);
131 bn_check_top(divisor);
132
135 if (BN_is_zero(divisor)) 133 if (BN_is_zero(divisor))
136 { 134 {
137 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); 135 BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);
@@ -146,12 +144,12 @@ BN_CTX *ctx;
146 return(1); 144 return(1);
147 } 145 }
148 146
149 tmp=ctx->bn[ctx->tos]; 147 tmp= &(ctx->bn[ctx->tos]);
150 tmp->neg=0; 148 tmp->neg=0;
151 snum=ctx->bn[ctx->tos+1]; 149 snum= &(ctx->bn[ctx->tos+1]);
152 sdiv=ctx->bn[ctx->tos+2]; 150 sdiv= &(ctx->bn[ctx->tos+2]);
153 if (dv == NULL) 151 if (dv == NULL)
154 res=ctx->bn[ctx->tos+3]; 152 res= &(ctx->bn[ctx->tos+3]);
155 else res=dv; 153 else res=dv;
156 154
157 /* First we normalise the numbers */ 155 /* First we normalise the numbers */
@@ -168,10 +166,10 @@ BN_CTX *ctx;
168 /* Lets setup a 'window' into snum 166 /* Lets setup a 'window' into snum
169 * This is the part that corresponds to the current 167 * This is the part that corresponds to the current
170 * 'area' being divided */ 168 * 'area' being divided */
169 BN_init(&wnum);
171 wnum.d= &(snum->d[loop]); 170 wnum.d= &(snum->d[loop]);
172 wnum.top= div_n; 171 wnum.top= div_n;
173 wnum.max= snum->max; /* a bit of a lie */ 172 wnum.max= snum->max+1; /* a bit of a lie */
174 wnum.neg= 0;
175 173
176 /* Get the top 2 words of sdiv */ 174 /* Get the top 2 words of sdiv */
177 /* i=sdiv->top; */ 175 /* i=sdiv->top; */
@@ -183,8 +181,8 @@ BN_CTX *ctx;
183 181
184 /* Setup to 'res' */ 182 /* Setup to 'res' */
185 res->neg= (num->neg^divisor->neg); 183 res->neg= (num->neg^divisor->neg);
186 res->top=loop;
187 if (!bn_wexpand(res,(loop+1))) goto err; 184 if (!bn_wexpand(res,(loop+1))) goto err;
185 res->top=loop;
188 resp= &(res->d[loop-1]); 186 resp= &(res->d[loop-1]);
189 187
190 /* space for temp */ 188 /* space for temp */
@@ -192,7 +190,7 @@ BN_CTX *ctx;
192 190
193 if (BN_ucmp(&wnum,sdiv) >= 0) 191 if (BN_ucmp(&wnum,sdiv) >= 0)
194 { 192 {
195 bn_qsub(&wnum,&wnum,sdiv); 193 if (!BN_usub(&wnum,&wnum,sdiv)) goto err;
196 *resp=1; 194 *resp=1;
197 res->d[res->top-1]=1; 195 res->d[res->top-1]=1;
198 } 196 }
@@ -202,56 +200,98 @@ BN_CTX *ctx;
202 200
203 for (i=0; i<loop-1; i++) 201 for (i=0; i<loop-1; i++)
204 { 202 {
205 BN_ULONG q,n0,n1; 203 BN_ULONG q,l0;
206 BN_ULONG l0; 204#ifdef BN_DIV3W
205 q=bn_div_3_words(wnump,d0,d1);
206#else
207
208#if !defined(NO_ASM) && !defined(PEDANTIC)
209# if defined(__GNUC__) && __GNUC__>=2
210# if defined(__i386)
211 /*
212 * There were two reasons for implementing this template:
213 * - GNU C generates a call to a function (__udivdi3 to be exact)
214 * in reply to ((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0 (I fail to
215 * understand why...);
216 * - divl doesn't only calculate quotient, but also leaves
217 * remainder in %edx which we can definitely use here:-)
218 *
219 * <appro@fy.chalmers.se>
220 */
221# define bn_div_words(n0,n1,d0) \
222 ({ asm volatile ( \
223 "divl %4" \
224 : "=a"(q), "=d"(rem) \
225 : "a"(n1), "d"(n0), "g"(d0) \
226 : "cc"); \
227 q; \
228 })
229# define REMINDER_IS_ALREADY_CALCULATED
230# endif /* __<cpu> */
231# endif /* __GNUC__ */
232#endif /* NO_ASM */
233 BN_ULONG n0,n1,rem=0;
207 234
208 wnum.d--; wnum.top++;
209 n0=wnump[0]; 235 n0=wnump[0];
210 n1=wnump[-1]; 236 n1=wnump[-1];
211 if (n0 == d0) 237 if (n0 == d0)
212 q=BN_MASK2; 238 q=BN_MASK2;
213 else 239 else
214 q=bn_div64(n0,n1,d0); 240#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
241 q=((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0;
242#else
243 q=bn_div_words(n0,n1,d0);
244#endif
215 { 245 {
216#ifdef BN_LLONG 246#ifdef BN_LLONG
217 BN_ULLONG t1,t2,rem; 247 BN_ULLONG t2;
218 t1=((BN_ULLONG)n0<<BN_BITS2)|n1; 248
249#ifndef REMINDER_IS_ALREADY_CALCULATED
250 /*
251 * rem doesn't have to be BN_ULLONG. The least we
252 * know it's less that d0, isn't it?
253 */
254 rem=(n1-q*d0)&BN_MASK2;
255#endif
256 t2=(BN_ULLONG)d1*q;
257
219 for (;;) 258 for (;;)
220 { 259 {
221 t2=(BN_ULLONG)d1*q; 260 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
222 rem=t1-(BN_ULLONG)q*d0;
223 if ((rem>>BN_BITS2) ||
224 (t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))
225 break; 261 break;
226 q--; 262 q--;
263 rem += d0;
264 if (rem < d0) break; /* don't let rem overflow */
265 t2 -= d1;
227 } 266 }
228#else 267#else
229 BN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t; 268 BN_ULONG t2l,t2h,ql,qh;
230 t1h=n0; 269
231 t1l=n1; 270#ifndef REMINDER_IS_ALREADY_CALCULATED
271 /*
272 * It's more than enough with the only multiplication.
273 * See the comment above in BN_LLONG section...
274 */
275 rem=(n1-q*d0)&BN_MASK2;
276#endif
277 t2l=LBITS(d1); t2h=HBITS(d1);
278 ql =LBITS(q); qh =HBITS(q);
279 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
280
232 for (;;) 281 for (;;)
233 { 282 {
234 t2l=LBITS(d1); t2h=HBITS(d1); 283 if ((t2h < rem) ||
235 ql =LBITS(q); qh =HBITS(q); 284 ((t2h == rem) && (t2l <= wnump[-2])))
236 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */ 285 break;
237
238 t3t=LBITS(d0); t3h=HBITS(d0);
239 mul64(t3t,t3h,ql,qh); /* t3=t1-(BN_ULLONG)q*d0; */
240 t3l=(t1l-t3t)&BN_MASK2;
241 if (t3l > t1l) t3h++;
242 t3h=(t1h-t3h)&BN_MASK2;
243
244 /*if ((t3>>BN_BITS2) ||
245 (t2 <= ((t3<<BN_BITS2)+wnump[-2])))
246 break; */
247 if (t3h) break;
248 if (t2h < t3l) break;
249 if ((t2h == t3l) && (t2l <= wnump[-2])) break;
250
251 q--; 286 q--;
287 rem += d0;
288 if (rem < d0) break; /* don't let rem overflow */
289 if (t2l < d1) t2h--; t2l -= d1;
252 } 290 }
253#endif 291#endif
254 } 292 }
293#endif /* !BN_DIV3W */
294 wnum.d--; wnum.top++;
255 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q); 295 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
256 tmp->d[div_n]=l0; 296 tmp->d[div_n]=l0;
257 for (j=div_n+1; j>0; j--) 297 for (j=div_n+1; j>0; j--)
@@ -284,3 +324,35 @@ err:
284 } 324 }
285 325
286#endif 326#endif
327
328/* rem != m */
329int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
330 {
331#if 0 /* The old slow way */
332 int i,nm,nd;
333 BIGNUM *dv;
334
335 if (BN_ucmp(m,d) < 0)
336 return((BN_copy(rem,m) == NULL)?0:1);
337
338 dv= &(ctx->bn[ctx->tos]);
339
340 if (!BN_copy(rem,m)) return(0);
341
342 nm=BN_num_bits(rem);
343 nd=BN_num_bits(d);
344 if (!BN_lshift(dv,d,nm-nd)) return(0);
345 for (i=nm-nd; i>=0; i--)
346 {
347 if (BN_cmp(rem,dv) >= 0)
348 {
349 if (!BN_sub(rem,rem,dv)) return(0);
350 }
351 if (!BN_rshift1(dv,dv)) return(0);
352 }
353 return(1);
354#else
355 return(BN_div(NULL,rem,m,d,ctx));
356#endif
357 }
358
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c
index 029ae810d5..73e80774e5 100644
--- a/src/lib/libcrypto/bn/bn_err.c
+++ b/src/lib/libcrypto/bn/bn_err.c
@@ -1,63 +1,65 @@
1/* lib/bn/bn_err.c */ 1/* crypto/bn/bn_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "bn.h" 62#include <openssl/bn.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -78,29 +80,32 @@ static ERR_STRING_DATA BN_str_functs[]=
78{ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"}, 80{ERR_PACK(0,BN_F_BN_MPI2BN,0), "BN_mpi2bn"},
79{ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"}, 81{ERR_PACK(0,BN_F_BN_NEW,0), "BN_new"},
80{ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"}, 82{ERR_PACK(0,BN_F_BN_RAND,0), "BN_rand"},
81{0,NULL}, 83{ERR_PACK(0,BN_F_BN_USUB,0), "BN_usub"},
84{0,NULL}
82 }; 85 };
83 86
84static ERR_STRING_DATA BN_str_reasons[]= 87static ERR_STRING_DATA BN_str_reasons[]=
85 { 88 {
89{BN_R_ARG2_LT_ARG3 ,"arg2 lt arg3"},
86{BN_R_BAD_RECIPROCAL ,"bad reciprocal"}, 90{BN_R_BAD_RECIPROCAL ,"bad reciprocal"},
87{BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"}, 91{BN_R_CALLED_WITH_EVEN_MODULUS ,"called with even modulus"},
88{BN_R_DIV_BY_ZERO ,"div by zero"}, 92{BN_R_DIV_BY_ZERO ,"div by zero"},
89{BN_R_ENCODING_ERROR ,"encoding error"}, 93{BN_R_ENCODING_ERROR ,"encoding error"},
94{BN_R_EXPAND_ON_STATIC_BIGNUM_DATA ,"expand on static bignum data"},
90{BN_R_INVALID_LENGTH ,"invalid length"}, 95{BN_R_INVALID_LENGTH ,"invalid length"},
91{BN_R_NOT_INITALISED ,"not initalised"}, 96{BN_R_NOT_INITIALIZED ,"not initialized"},
92{BN_R_NO_INVERSE ,"no inverse"}, 97{BN_R_NO_INVERSE ,"no inverse"},
93{0,NULL}, 98{0,NULL}
94 }; 99 };
95 100
96#endif 101#endif
97 102
98void ERR_load_BN_strings() 103void ERR_load_BN_strings(void)
99 { 104 {
100 static int init=1; 105 static int init=1;
101 106
102 if (init); 107 if (init)
103 {; 108 {
104 init=0; 109 init=0;
105#ifndef NO_ERR 110#ifndef NO_ERR
106 ERR_load_strings(ERR_LIB_BN,BN_str_functs); 111 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 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63#define TABLE_SIZE 16
64
63/* slow but works */ 65/* slow but works */
64int BN_mod_mul(ret, a, b, m, ctx) 66int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
65BIGNUM *ret;
66BIGNUM *a;
67BIGNUM *b;
68BIGNUM *m;
69BN_CTX *ctx;
70 { 67 {
71 BIGNUM *t; 68 BIGNUM *t;
72 int r=0; 69 int r=0;
73 70
74 t=ctx->bn[ctx->tos++]; 71 bn_check_top(a);
72 bn_check_top(b);
73 bn_check_top(m);
74
75 t= &(ctx->bn[ctx->tos++]);
75 if (a == b) 76 if (a == b)
76 { if (!BN_sqr(t,a,ctx)) goto err; } 77 { if (!BN_sqr(t,a,ctx)) goto err; }
77 else 78 else
78 { if (!BN_mul(t,a,b)) goto err; } 79 { if (!BN_mul(t,a,b,ctx)) goto err; }
79 if (!BN_mod(ret,t,m,ctx)) goto err; 80 if (!BN_mod(ret,t,m,ctx)) goto err;
80 r=1; 81 r=1;
81err: 82err:
@@ -85,22 +86,20 @@ err:
85 86
86#if 0 87#if 0
87/* this one works - simple but works */ 88/* this one works - simple but works */
88int BN_mod_exp(r,a,p,m,ctx) 89int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)
89BIGNUM *r,*a,*p,*m;
90BN_CTX *ctx;
91 { 90 {
92 int i,bits,ret=0; 91 int i,bits,ret=0;
93 BIGNUM *v,*tmp; 92 BIGNUM *v,*tmp;
94 93
95 v=ctx->bn[ctx->tos++]; 94 v= &(ctx->bn[ctx->tos++]);
96 tmp=ctx->bn[ctx->tos++]; 95 tmp= &(ctx->bn[ctx->tos++]);
97 96
98 if (BN_copy(v,a) == NULL) goto err; 97 if (BN_copy(v,a) == NULL) goto err;
99 bits=BN_num_bits(p); 98 bits=BN_num_bits(p);
100 99
101 if (BN_is_odd(p)) 100 if (BN_is_odd(p))
102 { if (BN_copy(r,a) == NULL) goto err; } 101 { if (BN_copy(r,a) == NULL) goto err; }
103 else { if (BN_one(r)) goto err; } 102 else { if (!BN_one(r)) goto err; }
104 103
105 for (i=1; i<bits; i++) 104 for (i=1; i<bits; i++)
106 { 105 {
@@ -108,7 +107,7 @@ BN_CTX *ctx;
108 if (!BN_mod(v,tmp,m,ctx)) goto err; 107 if (!BN_mod(v,tmp,m,ctx)) goto err;
109 if (BN_is_bit_set(p,i)) 108 if (BN_is_bit_set(p,i))
110 { 109 {
111 if (!BN_mul(tmp,r,v)) goto err; 110 if (!BN_mul(tmp,r,v,ctx)) goto err;
112 if (!BN_mod(r,tmp,m,ctx)) goto err; 111 if (!BN_mod(r,tmp,m,ctx)) goto err;
113 } 112 }
114 } 113 }
@@ -121,46 +120,49 @@ err:
121#endif 120#endif
122 121
123/* this one works - simple but works */ 122/* this one works - simple but works */
124int BN_exp(r,a,p,ctx) 123int BN_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BN_CTX *ctx)
125BIGNUM *r,*a,*p;
126BN_CTX *ctx;
127 { 124 {
128 int i,bits,ret=0; 125 int i,bits,ret=0,tos;
129 BIGNUM *v,*tmp; 126 BIGNUM *v,*rr;
130 127
131 v=ctx->bn[ctx->tos++]; 128 tos=ctx->tos;
132 tmp=ctx->bn[ctx->tos++]; 129 v= &(ctx->bn[ctx->tos++]);
130 if ((r == a) || (r == p))
131 rr= &(ctx->bn[ctx->tos++]);
132 else
133 rr=r;
133 134
134 if (BN_copy(v,a) == NULL) goto err; 135 if (BN_copy(v,a) == NULL) goto err;
135 bits=BN_num_bits(p); 136 bits=BN_num_bits(p);
136 137
137 if (BN_is_odd(p)) 138 if (BN_is_odd(p))
138 { if (BN_copy(r,a) == NULL) goto err; } 139 { if (BN_copy(rr,a) == NULL) goto err; }
139 else { if (BN_one(r)) goto err; } 140 else { if (!BN_one(rr)) goto err; }
140 141
141 for (i=1; i<bits; i++) 142 for (i=1; i<bits; i++)
142 { 143 {
143 if (!BN_sqr(tmp,v,ctx)) goto err; 144 if (!BN_sqr(v,v,ctx)) goto err;
144 if (BN_is_bit_set(p,i)) 145 if (BN_is_bit_set(p,i))
145 { 146 {
146 if (!BN_mul(tmp,r,v)) goto err; 147 if (!BN_mul(rr,rr,v,ctx)) goto err;
147 } 148 }
148 } 149 }
149 ret=1; 150 ret=1;
150err: 151err:
151 ctx->tos-=2; 152 ctx->tos=tos;
153 if (r != rr) BN_copy(r,rr);
152 return(ret); 154 return(ret);
153 } 155 }
154 156
155int BN_mod_exp(r,a,p,m,ctx) 157int BN_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
156BIGNUM *r; 158 BN_CTX *ctx)
157BIGNUM *a;
158BIGNUM *p;
159BIGNUM *m;
160BN_CTX *ctx;
161 { 159 {
162 int ret; 160 int ret;
163 161
162 bn_check_top(a);
163 bn_check_top(p);
164 bn_check_top(m);
165
164#ifdef MONT_MUL_MOD 166#ifdef MONT_MUL_MOD
165 /* I have finally been able to take out this pre-condition of 167 /* I have finally been able to take out this pre-condition of
166 * the top bit being set. It was caused by an error in BN_div 168 * the top bit being set. It was caused by an error in BN_div
@@ -182,20 +184,16 @@ BN_CTX *ctx;
182 } 184 }
183 185
184/* #ifdef RECP_MUL_MOD */ 186/* #ifdef RECP_MUL_MOD */
185int BN_mod_exp_recp(r,a,p,m,ctx) 187int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
186BIGNUM *r; 188 const BIGNUM *m, BN_CTX *ctx)
187BIGNUM *a;
188BIGNUM *p;
189BIGNUM *m;
190BN_CTX *ctx;
191 { 189 {
192 int nb,i,j,bits,ret=0,wstart,wend,window,wvalue; 190 int i,j,bits,ret=0,wstart,wend,window,wvalue;
193 int start=1; 191 int start=1,ts=0;
194 BIGNUM *d,*aa; 192 BIGNUM *aa;
195 BIGNUM *val[16]; 193 BIGNUM val[TABLE_SIZE];
194 BN_RECP_CTX recp;
196 195
197 d=ctx->bn[ctx->tos++]; 196 aa= &(ctx->bn[ctx->tos++]);
198 aa=ctx->bn[ctx->tos++];
199 bits=BN_num_bits(p); 197 bits=BN_num_bits(p);
200 198
201 if (bits == 0) 199 if (bits == 0)
@@ -203,12 +201,14 @@ BN_CTX *ctx;
203 BN_one(r); 201 BN_one(r);
204 return(1); 202 return(1);
205 } 203 }
206 nb=BN_reciprocal(d,m,ctx); 204 BN_RECP_CTX_init(&recp);
207 if (nb == -1) goto err; 205 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;
208 206
209 val[0]=BN_new(); 207 BN_init(&(val[0]));
210 if (!BN_mod(val[0],a,m,ctx)) goto err; /* 1 */ 208 ts=1;
211 if (!BN_mod_mul_reciprocal(aa,val[0],val[0],m,d,nb,ctx)) 209
210 if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */
211 if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))
212 goto err; /* 2 */ 212 goto err; /* 2 */
213 213
214 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ 214 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */
@@ -223,12 +223,11 @@ BN_CTX *ctx;
223 j=1<<(window-1); 223 j=1<<(window-1);
224 for (i=1; i<j; i++) 224 for (i=1; i<j; i++)
225 { 225 {
226 val[i]=BN_new(); 226 BN_init(&val[i]);
227 if (!BN_mod_mul_reciprocal(val[i],val[i-1],aa,m,d,nb,ctx)) 227 if (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))
228 goto err; 228 goto err;
229 } 229 }
230 for (; i<16; i++) 230 ts=i;
231 val[i]=NULL;
232 231
233 start=1; /* This is used to avoid multiplication etc 232 start=1; /* This is used to avoid multiplication etc
234 * when there is only the value '1' in the 233 * when there is only the value '1' in the
@@ -244,7 +243,7 @@ BN_CTX *ctx;
244 if (BN_is_bit_set(p,wstart) == 0) 243 if (BN_is_bit_set(p,wstart) == 0)
245 { 244 {
246 if (!start) 245 if (!start)
247 if (!BN_mod_mul_reciprocal(r,r,r,m,d,nb,ctx)) 246 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
248 goto err; 247 goto err;
249 if (wstart == 0) break; 248 if (wstart == 0) break;
250 wstart--; 249 wstart--;
@@ -274,12 +273,12 @@ BN_CTX *ctx;
274 if (!start) 273 if (!start)
275 for (i=0; i<j; i++) 274 for (i=0; i<j; i++)
276 { 275 {
277 if (!BN_mod_mul_reciprocal(r,r,r,m,d,nb,ctx)) 276 if (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))
278 goto err; 277 goto err;
279 } 278 }
280 279
281 /* wvalue will be an odd number < 2^window */ 280 /* wvalue will be an odd number < 2^window */
282 if (!BN_mod_mul_reciprocal(r,r,val[wvalue>>1],m,d,nb,ctx)) 281 if (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))
283 goto err; 282 goto err;
284 283
285 /* move the 'window' down further */ 284 /* move the 'window' down further */
@@ -290,35 +289,36 @@ BN_CTX *ctx;
290 } 289 }
291 ret=1; 290 ret=1;
292err: 291err:
293 ctx->tos-=2; 292 ctx->tos--;
294 for (i=0; i<16; i++) 293 for (i=0; i<ts; i++)
295 if (val[i] != NULL) BN_clear_free(val[i]); 294 BN_clear_free(&(val[i]));
295 BN_RECP_CTX_free(&recp);
296 return(ret); 296 return(ret);
297 } 297 }
298/* #endif */ 298/* #endif */
299 299
300/* #ifdef MONT_MUL_MOD */ 300/* #ifdef MONT_MUL_MOD */
301int BN_mod_exp_mont(r,a,p,m,ctx,in_mont) 301int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, const BIGNUM *p,
302BIGNUM *r; 302 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
303BIGNUM *a;
304BIGNUM *p;
305BIGNUM *m;
306BN_CTX *ctx;
307BN_MONT_CTX *in_mont;
308 { 303 {
309#define TABLE_SIZE 16
310 int i,j,bits,ret=0,wstart,wend,window,wvalue; 304 int i,j,bits,ret=0,wstart,wend,window,wvalue;
311 int start=1; 305 int start=1,ts=0;
312 BIGNUM *d,*aa; 306 BIGNUM *d,*r;
313 BIGNUM *val[TABLE_SIZE]; 307 BIGNUM *aa;
308 BIGNUM val[TABLE_SIZE];
314 BN_MONT_CTX *mont=NULL; 309 BN_MONT_CTX *mont=NULL;
315 310
311 bn_check_top(a);
312 bn_check_top(p);
313 bn_check_top(m);
314
316 if (!(m->d[0] & 1)) 315 if (!(m->d[0] & 1))
317 { 316 {
318 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); 317 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
319 return(0); 318 return(0);
320 } 319 }
321 d=ctx->bn[ctx->tos++]; 320 d= &(ctx->bn[ctx->tos++]);
321 r= &(ctx->bn[ctx->tos++]);
322 bits=BN_num_bits(p); 322 bits=BN_num_bits(p);
323 if (bits == 0) 323 if (bits == 0)
324 { 324 {
@@ -339,22 +339,23 @@ BN_MONT_CTX *in_mont;
339 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; 339 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
340 } 340 }
341 341
342 val[0]=BN_new(); 342 BN_init(&val[0]);
343 ts=1;
343 if (BN_ucmp(a,m) >= 0) 344 if (BN_ucmp(a,m) >= 0)
344 { 345 {
345 BN_mod(val[0],a,m,ctx); 346 BN_mod(&(val[0]),a,m,ctx);
346 aa=val[0]; 347 aa= &(val[0]);
347 } 348 }
348 else 349 else
349 aa=a; 350 aa=a;
350 if (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err; /* 1 */ 351 if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */
351 if (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err; /* 2 */ 352 if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */
352 353
353 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */ 354 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */
354 window=1; 355 window=1;
355 else if (bits > 250) 356 else if (bits >= 256)
356 window=5; /* max size of window */ 357 window=5; /* max size of window */
357 else if (bits >= 120) 358 else if (bits >= 128)
358 window=4; 359 window=4;
359 else 360 else
360 window=3; 361 window=3;
@@ -362,12 +363,11 @@ BN_MONT_CTX *in_mont;
362 j=1<<(window-1); 363 j=1<<(window-1);
363 for (i=1; i<j; i++) 364 for (i=1; i<j; i++)
364 { 365 {
365 val[i]=BN_new(); 366 BN_init(&(val[i]));
366 if (!BN_mod_mul_montgomery(val[i],val[i-1],d,mont,ctx)) 367 if (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))
367 goto err; 368 goto err;
368 } 369 }
369 for (; i<TABLE_SIZE; i++) 370 ts=i;
370 val[i]=NULL;
371 371
372 start=1; /* This is used to avoid multiplication etc 372 start=1; /* This is used to avoid multiplication etc
373 * when there is only the value '1' in the 373 * when there is only the value '1' in the
@@ -419,7 +419,7 @@ BN_MONT_CTX *in_mont;
419 } 419 }
420 420
421 /* wvalue will be an odd number < 2^window */ 421 /* wvalue will be an odd number < 2^window */
422 if (!BN_mod_mul_montgomery(r,r,val[wvalue>>1],mont,ctx)) 422 if (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))
423 goto err; 423 goto err;
424 424
425 /* move the 'window' down further */ 425 /* move the 'window' down further */
@@ -428,31 +428,27 @@ BN_MONT_CTX *in_mont;
428 start=0; 428 start=0;
429 if (wstart < 0) break; 429 if (wstart < 0) break;
430 } 430 }
431 BN_from_montgomery(r,r,mont,ctx); 431 BN_from_montgomery(rr,r,mont,ctx);
432 ret=1; 432 ret=1;
433err: 433err:
434 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); 434 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
435 ctx->tos--; 435 ctx->tos-=2;
436 for (i=0; i<TABLE_SIZE; i++) 436 for (i=0; i<ts; i++)
437 if (val[i] != NULL) BN_clear_free(val[i]); 437 BN_clear_free(&(val[i]));
438 return(ret); 438 return(ret);
439 } 439 }
440/* #endif */ 440/* #endif */
441 441
442/* The old fallback, simple version :-) */ 442/* The old fallback, simple version :-) */
443int BN_mod_exp_simple(r,a,p,m,ctx) 443int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,
444BIGNUM *r; 444 BN_CTX *ctx)
445BIGNUM *a;
446BIGNUM *p;
447BIGNUM *m;
448BN_CTX *ctx;
449 { 445 {
450 int i,j,bits,ret=0,wstart,wend,window,wvalue; 446 int i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;
451 int start=1; 447 int start=1;
452 BIGNUM *d; 448 BIGNUM *d;
453 BIGNUM *val[16]; 449 BIGNUM val[TABLE_SIZE];
454 450
455 d=ctx->bn[ctx->tos++]; 451 d= &(ctx->bn[ctx->tos++]);
456 bits=BN_num_bits(p); 452 bits=BN_num_bits(p);
457 453
458 if (bits == 0) 454 if (bits == 0)
@@ -461,9 +457,10 @@ BN_CTX *ctx;
461 return(1); 457 return(1);
462 } 458 }
463 459
464 val[0]=BN_new(); 460 BN_init(&(val[0]));
465 if (!BN_mod(val[0],a,m,ctx)) goto err; /* 1 */ 461 ts=1;
466 if (!BN_mod_mul(d,val[0],val[0],m,ctx)) 462 if (!BN_mod(&(val[0]),a,m,ctx)) goto err; /* 1 */
463 if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))
467 goto err; /* 2 */ 464 goto err; /* 2 */
468 465
469 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */ 466 if (bits <= 17) /* This is probably 3 or 0x10001, so just do singles */
@@ -478,12 +475,11 @@ BN_CTX *ctx;
478 j=1<<(window-1); 475 j=1<<(window-1);
479 for (i=1; i<j; i++) 476 for (i=1; i<j; i++)
480 { 477 {
481 val[i]=BN_new(); 478 BN_init(&(val[i]));
482 if (!BN_mod_mul(val[i],val[i-1],d,m,ctx)) 479 if (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))
483 goto err; 480 goto err;
484 } 481 }
485 for (; i<16; i++) 482 ts=i;
486 val[i]=NULL;
487 483
488 start=1; /* This is used to avoid multiplication etc 484 start=1; /* This is used to avoid multiplication etc
489 * when there is only the value '1' in the 485 * when there is only the value '1' in the
@@ -534,7 +530,7 @@ BN_CTX *ctx;
534 } 530 }
535 531
536 /* wvalue will be an odd number < 2^window */ 532 /* wvalue will be an odd number < 2^window */
537 if (!BN_mod_mul(r,r,val[wvalue>>1],m,ctx)) 533 if (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx))
538 goto err; 534 goto err;
539 535
540 /* move the 'window' down further */ 536 /* move the 'window' down further */
@@ -546,8 +542,8 @@ BN_CTX *ctx;
546 ret=1; 542 ret=1;
547err: 543err:
548 ctx->tos--; 544 ctx->tos--;
549 for (i=0; i<16; i++) 545 for (i=0; i<ts; i++)
550 if (val[i] != NULL) BN_clear_free(val[i]); 546 BN_clear_free(&(val[i]));
551 return(ret); 547 return(ret);
552 } 548 }
553 549
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c
new file mode 100644
index 0000000000..1132d53365
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_exp2.c
@@ -0,0 +1,195 @@
1#include <stdio.h>
2#include "cryptlib.h"
3#include "bn_lcl.h"
4
5/* I've done some timing with different table sizes.
6 * The main hassle is that even with bits set at 3, this requires
7 * 63 BIGNUMs to store the pre-calculated values.
8 * 512 1024
9 * bits=1 75.4% 79.4%
10 * bits=2 61.2% 62.4%
11 * bits=3 61.3% 59.3%
12 * The lack of speed improvment is also a function of the pre-calculation
13 * which could be removed.
14 */
15#define EXP2_TABLE_BITS 2 /* 1 2 3 4 5 */
16#define EXP2_TABLE_SIZE 4 /* 2 4 8 16 32 */
17
18int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,
19 BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
20 {
21 int i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue;
22 int start=1,ts=0,x,y;
23 BIGNUM *d,*aa1,*aa2,*r;
24 BIGNUM val[EXP2_TABLE_SIZE][EXP2_TABLE_SIZE];
25 BN_MONT_CTX *mont=NULL;
26
27 bn_check_top(a1);
28 bn_check_top(p1);
29 bn_check_top(a2);
30 bn_check_top(p2);
31 bn_check_top(m);
32
33 if (!(m->d[0] & 1))
34 {
35 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
36 return(0);
37 }
38 d= &(ctx->bn[ctx->tos++]);
39 r= &(ctx->bn[ctx->tos++]);
40 bits1=BN_num_bits(p1);
41 bits2=BN_num_bits(p2);
42 if ((bits1 == 0) && (bits2 == 0))
43 {
44 BN_one(r);
45 return(1);
46 }
47 bits=(bits1 > bits2)?bits1:bits2;
48
49 /* If this is not done, things will break in the montgomery
50 * part */
51
52 if (in_mont != NULL)
53 mont=in_mont;
54 else
55 {
56 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
57 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
58 }
59
60 BN_init(&(val[0][0]));
61 BN_init(&(val[1][1]));
62 BN_init(&(val[0][1]));
63 BN_init(&(val[1][0]));
64 ts=1;
65 if (BN_ucmp(a1,m) >= 0)
66 {
67 BN_mod(&(val[1][0]),a1,m,ctx);
68 aa1= &(val[1][0]);
69 }
70 else
71 aa1=a1;
72 if (BN_ucmp(a2,m) >= 0)
73 {
74 BN_mod(&(val[0][1]),a2,m,ctx);
75 aa2= &(val[0][1]);
76 }
77 else
78 aa2=a2;
79 if (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err;
80 if (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err;
81 if (!BN_mod_mul_montgomery(&(val[1][1]),
82 &(val[1][0]),&(val[0][1]),mont,ctx))
83 goto err;
84
85#if 0
86 if (bits <= 20) /* This is probably 3 or 0x10001, so just do singles */
87 window=1;
88 else if (bits > 250)
89 window=5; /* max size of window */
90 else if (bits >= 120)
91 window=4;
92 else
93 window=3;
94#else
95 window=EXP2_TABLE_BITS;
96#endif
97
98 k=1<<window;
99 for (x=0; x<k; x++)
100 {
101 if (x >= 2)
102 {
103 BN_init(&(val[x][0]));
104 BN_init(&(val[x][1]));
105 if (!BN_mod_mul_montgomery(&(val[x][0]),
106 &(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err;
107 if (!BN_mod_mul_montgomery(&(val[x][1]),
108 &(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err;
109 }
110 for (y=2; y<k; y++)
111 {
112 BN_init(&(val[x][y]));
113 if (!BN_mod_mul_montgomery(&(val[x][y]),
114 &(val[x][y-1]),&(val[0][1]),mont,ctx))
115 goto err;
116 }
117 }
118 ts=k;
119
120 start=1; /* This is used to avoid multiplication etc
121 * when there is only the value '1' in the
122 * buffer. */
123 xvalue=0; /* The 'x value' of the window */
124 yvalue=0; /* The 'y value' of the window */
125 wstart=bits-1; /* The top bit of the window */
126 wend=0; /* The bottom bit of the window */
127
128 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;
129 for (;;)
130 {
131 xvalue=BN_is_bit_set(p1,wstart);
132 yvalue=BN_is_bit_set(p2,wstart);
133 if (!(xvalue || yvalue))
134 {
135 if (!start)
136 {
137 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
138 goto err;
139 }
140 wstart--;
141 if (wstart < 0) break;
142 continue;
143 }
144 /* We now have wstart on a 'set' bit, we now need to work out
145 * how bit a window to do. To do this we need to scan
146 * forward until the last set bit before the end of the
147 * window */
148 j=wstart;
149 /* xvalue=BN_is_bit_set(p1,wstart); already set */
150 /* yvalue=BN_is_bit_set(p1,wstart); already set */
151 wend=0;
152 for (i=1; i<window; i++)
153 {
154 if (wstart-i < 0) break;
155 xvalue+=xvalue;
156 xvalue|=BN_is_bit_set(p1,wstart-i);
157 yvalue+=yvalue;
158 yvalue|=BN_is_bit_set(p2,wstart-i);
159 }
160
161 /* i is the size of the current window */
162 /* add the 'bytes above' */
163 if (!start)
164 for (j=0; j<i; j++)
165 {
166 if (!BN_mod_mul_montgomery(r,r,r,mont,ctx))
167 goto err;
168 }
169
170 /* wvalue will be an odd number < 2^window */
171 if (xvalue || yvalue)
172 {
173 if (!BN_mod_mul_montgomery(r,r,&(val[xvalue][yvalue]),
174 mont,ctx)) goto err;
175 }
176
177 /* move the 'window' down further */
178 wstart-=i;
179 start=0;
180 if (wstart < 0) break;
181 }
182 BN_from_montgomery(rr,r,mont,ctx);
183 ret=1;
184err:
185 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
186 ctx->tos-=2;
187 for (i=0; i<ts; i++)
188 {
189 for (j=0; j<ts; j++)
190 {
191 BN_clear_free(&(val[i][j]));
192 }
193 }
194 return(ret);
195 }
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c
index 071bba3b4b..64a76f4498 100644
--- a/src/lib/libcrypto/bn/bn_gcd.c
+++ b/src/lib/libcrypto/bn/bn_gcd.c
@@ -60,21 +60,17 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63#ifndef NOPROTO
64static BIGNUM *euclid(BIGNUM *a, BIGNUM *b); 63static BIGNUM *euclid(BIGNUM *a, BIGNUM *b);
65#else 64int BN_gcd(BIGNUM *r, BIGNUM *in_a, BIGNUM *in_b, BN_CTX *ctx)
66static BIGNUM *euclid();
67#endif
68
69int BN_gcd(r,in_a,in_b,ctx)
70BIGNUM *r,*in_a,*in_b;
71BN_CTX *ctx;
72 { 65 {
73 BIGNUM *a,*b,*t; 66 BIGNUM *a,*b,*t;
74 int ret=0; 67 int ret=0;
75 68
76 a=ctx->bn[ctx->tos]; 69 bn_check_top(in_a);
77 b=ctx->bn[ctx->tos+1]; 70 bn_check_top(in_b);
71
72 a= &(ctx->bn[ctx->tos]);
73 b= &(ctx->bn[ctx->tos+1]);
78 74
79 if (BN_copy(a,in_a) == NULL) goto err; 75 if (BN_copy(a,in_a) == NULL) goto err;
80 if (BN_copy(b,in_b) == NULL) goto err; 76 if (BN_copy(b,in_b) == NULL) goto err;
@@ -89,12 +85,14 @@ err:
89 return(ret); 85 return(ret);
90 } 86 }
91 87
92static BIGNUM *euclid(a,b) 88static BIGNUM *euclid(BIGNUM *a, BIGNUM *b)
93BIGNUM *a,*b;
94 { 89 {
95 BIGNUM *t; 90 BIGNUM *t;
96 int shifts=0; 91 int shifts=0;
97 92
93 bn_check_top(a);
94 bn_check_top(b);
95
98 for (;;) 96 for (;;)
99 { 97 {
100 if (BN_is_zero(b)) 98 if (BN_is_zero(b))
@@ -142,23 +140,26 @@ err:
142 } 140 }
143 141
144/* solves ax == 1 (mod n) */ 142/* solves ax == 1 (mod n) */
145BIGNUM *BN_mod_inverse(a, n, ctx) 143BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
146BIGNUM *a;
147BIGNUM *n;
148BN_CTX *ctx;
149 { 144 {
150 BIGNUM *A,*B,*X,*Y,*M,*D,*R; 145 BIGNUM *A,*B,*X,*Y,*M,*D,*R;
151 BIGNUM *ret=NULL,*T; 146 BIGNUM *T,*ret=NULL;
152 int sign; 147 int sign;
153 148
154 A=ctx->bn[ctx->tos]; 149 bn_check_top(a);
155 B=ctx->bn[ctx->tos+1]; 150 bn_check_top(n);
156 X=ctx->bn[ctx->tos+2]; 151
157 D=ctx->bn[ctx->tos+3]; 152 A= &(ctx->bn[ctx->tos]);
158 M=ctx->bn[ctx->tos+4]; 153 B= &(ctx->bn[ctx->tos+1]);
159 Y=ctx->bn[ctx->tos+5]; 154 X= &(ctx->bn[ctx->tos+2]);
155 D= &(ctx->bn[ctx->tos+3]);
156 M= &(ctx->bn[ctx->tos+4]);
157 Y= &(ctx->bn[ctx->tos+5]);
160 ctx->tos+=6; 158 ctx->tos+=6;
161 R=BN_new(); 159 if (in == NULL)
160 R=BN_new();
161 else
162 R=in;
162 if (R == NULL) goto err; 163 if (R == NULL) goto err;
163 164
164 BN_zero(X); 165 BN_zero(X);
@@ -175,7 +176,7 @@ BN_CTX *ctx;
175 B=M; 176 B=M;
176 /* T has a struct, M does not */ 177 /* T has a struct, M does not */
177 178
178 if (!BN_mul(T,D,X)) goto err; 179 if (!BN_mul(T,D,X,ctx)) goto err;
179 if (!BN_add(T,T,Y)) goto err; 180 if (!BN_add(T,T,Y)) goto err;
180 M=Y; 181 M=Y;
181 Y=X; 182 Y=X;
@@ -196,7 +197,7 @@ BN_CTX *ctx;
196 } 197 }
197 ret=R; 198 ret=R;
198err: 199err:
199 if ((ret == NULL) && (R != NULL)) BN_free(R); 200 if ((ret == NULL) && (in == NULL)) BN_free(R);
200 ctx->tos-=6; 201 ctx->tos-=6;
201 return(ret); 202 return(ret);
202 } 203 }
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 @@
59#ifndef HEADER_BN_LCL_H 59#ifndef HEADER_BN_LCL_H
60#define HEADER_BN_LCL_H 60#define HEADER_BN_LCL_H
61 61
62#include "bn.h" 62#include <openssl/bn.h>
63 63
64#ifdef __cplusplus 64#ifdef __cplusplus
65extern "C" { 65extern "C" {
66#endif 66#endif
67 67
68/* Pentium pro 16,16,16,32,64 */
69/* Alpha 16,16,16,16.64 */
70#define BN_MULL_SIZE_NORMAL (16) /* 32 */
71#define BN_MUL_RECURSIVE_SIZE_NORMAL (16) /* 32 less than */
72#define BN_SQR_RECURSIVE_SIZE_NORMAL (16) /* 32 */
73#define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32) /* 32 */
74#define BN_MONT_CTX_SET_SIZE_WORD (64) /* 32 */
75
76#if 0
77#ifndef BN_MUL_COMBA
78/* #define bn_mul_comba8(r,a,b) bn_mul_normal(r,a,8,b,8) */
79/* #define bn_mul_comba4(r,a,b) bn_mul_normal(r,a,4,b,4) */
80#endif
81
82#ifndef BN_SQR_COMBA
83/* This is probably faster than using the C code - I need to check */
84#define bn_sqr_comba8(r,a) bn_mul_normal(r,a,8,a,8)
85#define bn_sqr_comba4(r,a) bn_mul_normal(r,a,4,a,4)
86#endif
87#endif
88
68/************************************************************* 89/*************************************************************
69 * Using the long long type 90 * Using the long long type
70 */ 91 */
71#define Lw(t) (((BN_ULONG)(t))&BN_MASK2) 92#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
72#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) 93#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
73 94
74#define bn_fix_top(a) \ 95/* These are used for internal error checking and are not normally used */
75 { \ 96#ifdef BN_DEBUG
76 BN_ULONG *fix_top_l; \ 97#define bn_check_top(a) \
77 for (fix_top_l= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ 98 { if (((a)->top < 0) || ((a)->top > (a)->max)) \
78 if (*(fix_top_l--)) break; \ 99 { char *nullp=NULL; *nullp='z'; } }
100#define bn_check_num(a) if ((a) < 0) { char *nullp=NULL; *nullp='z'; }
101#else
102#define bn_check_top(a)
103#define bn_check_num(a)
104#endif
105
106/* This macro is to add extra stuff for development checking */
107#ifdef BN_DEBUG
108#define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA))
109#else
110#define bn_set_max(r)
111#endif
112
113/* These macros are used to 'take' a section of a bignum for read only use */
114#define bn_set_low(r,a,n) \
115 { \
116 (r)->top=((a)->top > (n))?(n):(a)->top; \
117 (r)->d=(a)->d; \
118 (r)->neg=(a)->neg; \
119 (r)->flags|=BN_FLG_STATIC_DATA; \
120 bn_set_max(r); \
121 }
122
123#define bn_set_high(r,a,n) \
124 { \
125 if ((a)->top > (n)) \
126 { \
127 (r)->top=(a)->top-n; \
128 (r)->d= &((a)->d[n]); \
129 } \
130 else \
131 (r)->top=0; \
132 (r)->neg=(a)->neg; \
133 (r)->flags|=BN_FLG_STATIC_DATA; \
134 bn_set_max(r); \
79 } 135 }
80 136
81/* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */ 137/* #define bn_expand(n,b) ((((b)/BN_BITS2) <= (n)->max)?(n):bn_expand2((n),(b))) */
@@ -175,22 +231,35 @@ extern "C" {
175 231
176#endif 232#endif
177 233
178#ifndef NOPROTO 234OPENSSL_EXTERN int bn_limit_bits;
235OPENSSL_EXTERN int bn_limit_num; /* (1<<bn_limit_bits) */
236/* Recursive 'low' limit */
237OPENSSL_EXTERN int bn_limit_bits_low;
238OPENSSL_EXTERN int bn_limit_num_low; /* (1<<bn_limit_bits_low) */
239/* Do modified 'high' part calculation' */
240OPENSSL_EXTERN int bn_limit_bits_high;
241OPENSSL_EXTERN int bn_limit_num_high; /* (1<<bn_limit_bits_high) */
242OPENSSL_EXTERN int bn_limit_bits_mont;
243OPENSSL_EXTERN int bn_limit_num_mont; /* (1<<bn_limit_bits_mont) */
179 244
180BIGNUM *bn_expand2(BIGNUM *b, int bits); 245BIGNUM *bn_expand2(BIGNUM *b, int bits);
181 246
182#ifdef X86_ASM 247void bn_mul_normal(BN_ULONG *r,BN_ULONG *a,int na,BN_ULONG *b,int nb);
183void bn_add_words(BN_ULONG *r,BN_ULONG *a,int num); 248void bn_mul_comba8(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
184#endif 249void bn_mul_comba4(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b);
185 250void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp);
186#else 251void bn_sqr_comba8(BN_ULONG *r,BN_ULONG *a);
187 252void bn_sqr_comba4(BN_ULONG *r,BN_ULONG *a);
188BIGNUM *bn_expand2(); 253int bn_cmp_words(BN_ULONG *a,BN_ULONG *b,int n);
189#ifdef X86_ASM 254void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,BN_ULONG *t);
190BN_ULONG bn_add_words(); 255void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,
191#endif 256 int tn, int n,BN_ULONG *t);
192 257void bn_sqr_recursive(BN_ULONG *r,BN_ULONG *a, int n2, BN_ULONG *t);
193#endif 258void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n);
259void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,
260 BN_ULONG *t);
261void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2,
262 BN_ULONG *t);
194 263
195#ifdef __cplusplus 264#ifdef __cplusplus
196} 265}
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index bfe7628ad4..5d62d88e8b 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -60,9 +60,68 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63char *BN_version="Big Number part of SSLeay 0.9.0b 29-Jun-1998"; 63const char *BN_version="Big Number" OPENSSL_VERSION_PTEXT;
64
65/* For a 32 bit machine
66 * 2 - 4 == 128
67 * 3 - 8 == 256
68 * 4 - 16 == 512
69 * 5 - 32 == 1024
70 * 6 - 64 == 2048
71 * 7 - 128 == 4096
72 * 8 - 256 == 8192
73 */
74OPENSSL_GLOBAL int bn_limit_bits=0;
75OPENSSL_GLOBAL int bn_limit_num=8; /* (1<<bn_limit_bits) */
76OPENSSL_GLOBAL int bn_limit_bits_low=0;
77OPENSSL_GLOBAL int bn_limit_num_low=8; /* (1<<bn_limit_bits_low) */
78OPENSSL_GLOBAL int bn_limit_bits_high=0;
79OPENSSL_GLOBAL int bn_limit_num_high=8; /* (1<<bn_limit_bits_high) */
80OPENSSL_GLOBAL int bn_limit_bits_mont=0;
81OPENSSL_GLOBAL int bn_limit_num_mont=8; /* (1<<bn_limit_bits_mont) */
82
83void BN_set_params(int mult, int high, int low, int mont)
84 {
85 if (mult >= 0)
86 {
87 if (mult > (sizeof(int)*8)-1)
88 mult=sizeof(int)*8-1;
89 bn_limit_bits=mult;
90 bn_limit_num=1<<mult;
91 }
92 if (high >= 0)
93 {
94 if (high > (sizeof(int)*8)-1)
95 high=sizeof(int)*8-1;
96 bn_limit_bits_high=high;
97 bn_limit_num_high=1<<high;
98 }
99 if (low >= 0)
100 {
101 if (low > (sizeof(int)*8)-1)
102 low=sizeof(int)*8-1;
103 bn_limit_bits_low=low;
104 bn_limit_num_low=1<<low;
105 }
106 if (mont >= 0)
107 {
108 if (mont > (sizeof(int)*8)-1)
109 mont=sizeof(int)*8-1;
110 bn_limit_bits_mont=mont;
111 bn_limit_num_mont=1<<mont;
112 }
113 }
64 114
65BIGNUM *BN_value_one() 115int BN_get_params(int which)
116 {
117 if (which == 0) return(bn_limit_bits);
118 else if (which == 1) return(bn_limit_bits_high);
119 else if (which == 2) return(bn_limit_bits_low);
120 else if (which == 3) return(bn_limit_bits_mont);
121 else return(0);
122 }
123
124BIGNUM *BN_value_one(void)
66 { 125 {
67 static BN_ULONG data_one=1L; 126 static BN_ULONG data_one=1L;
68 static BIGNUM const_one={&data_one,1,1,0}; 127 static BIGNUM const_one={&data_one,1,1,0};
@@ -70,7 +129,7 @@ BIGNUM *BN_value_one()
70 return(&const_one); 129 return(&const_one);
71 } 130 }
72 131
73char *BN_options() 132char *BN_options(void)
74 { 133 {
75 static int init=0; 134 static int init=0;
76 static char data[16]; 135 static char data[16];
@@ -89,10 +148,9 @@ char *BN_options()
89 return(data); 148 return(data);
90 } 149 }
91 150
92int BN_num_bits_word(l) 151int BN_num_bits_word(BN_ULONG l)
93BN_ULONG l;
94 { 152 {
95 static char bits[256]={ 153 static const char bits[256]={
96 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4, 154 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
97 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 155 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
98 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 156 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
@@ -111,24 +169,24 @@ BN_ULONG l;
111 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 169 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
112 }; 170 };
113 171
114#ifdef SIXTY_FOUR_BIT_LONG 172#if defined(SIXTY_FOUR_BIT_LONG)
115 if (l & 0xffffffff00000000L) 173 if (l & 0xffffffff00000000L)
116 { 174 {
117 if (l & 0xffff000000000000L) 175 if (l & 0xffff000000000000L)
118 { 176 {
119 if (l & 0xff00000000000000L) 177 if (l & 0xff00000000000000L)
120 { 178 {
121 return(bits[l>>56]+56); 179 return(bits[(int)(l>>56)]+56);
122 } 180 }
123 else return(bits[l>>48]+48); 181 else return(bits[(int)(l>>48)]+48);
124 } 182 }
125 else 183 else
126 { 184 {
127 if (l & 0x0000ff0000000000L) 185 if (l & 0x0000ff0000000000L)
128 { 186 {
129 return(bits[l>>40]+40); 187 return(bits[(int)(l>>40)]+40);
130 } 188 }
131 else return(bits[l>>32]+32); 189 else return(bits[(int)(l>>32)]+32);
132 } 190 }
133 } 191 }
134 else 192 else
@@ -140,17 +198,17 @@ BN_ULONG l;
140 { 198 {
141 if (l & 0xff00000000000000LL) 199 if (l & 0xff00000000000000LL)
142 { 200 {
143 return(bits[l>>56]+56); 201 return(bits[(int)(l>>56)]+56);
144 } 202 }
145 else return(bits[l>>48]+48); 203 else return(bits[(int)(l>>48)]+48);
146 } 204 }
147 else 205 else
148 { 206 {
149 if (l & 0x0000ff0000000000LL) 207 if (l & 0x0000ff0000000000LL)
150 { 208 {
151 return(bits[l>>40]+40); 209 return(bits[(int)(l>>40)]+40);
152 } 210 }
153 else return(bits[l>>32]+32); 211 else return(bits[(int)(l>>32)]+32);
154 } 212 }
155 } 213 }
156 else 214 else
@@ -161,28 +219,29 @@ BN_ULONG l;
161 if (l & 0xffff0000L) 219 if (l & 0xffff0000L)
162 { 220 {
163 if (l & 0xff000000L) 221 if (l & 0xff000000L)
164 return(bits[l>>24L]+24); 222 return(bits[(int)(l>>24L)]+24);
165 else return(bits[l>>16L]+16); 223 else return(bits[(int)(l>>16L)]+16);
166 } 224 }
167 else 225 else
168#endif 226#endif
169 { 227 {
170#if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) 228#if defined(SIXTEEN_BIT) || defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
171 if (l & 0xff00L) 229 if (l & 0xff00L)
172 return(bits[l>>8]+8); 230 return(bits[(int)(l>>8)]+8);
173 else 231 else
174#endif 232#endif
175 return(bits[l ] ); 233 return(bits[(int)(l )] );
176 } 234 }
177 } 235 }
178 } 236 }
179 237
180int BN_num_bits(a) 238int BN_num_bits(const BIGNUM *a)
181BIGNUM *a;
182 { 239 {
183 BN_ULONG l; 240 BN_ULONG l;
184 int i; 241 int i;
185 242
243 bn_check_top(a);
244
186 if (a->top == 0) return(0); 245 if (a->top == 0) return(0);
187 l=a->d[a->top-1]; 246 l=a->d[a->top-1];
188 i=(a->top-1)*BN_BITS2; 247 i=(a->top-1)*BN_BITS2;
@@ -196,126 +255,256 @@ BIGNUM *a;
196 return(i+BN_num_bits_word(l)); 255 return(i+BN_num_bits_word(l));
197 } 256 }
198 257
199void BN_clear_free(a) 258void BN_clear_free(BIGNUM *a)
200BIGNUM *a;
201 { 259 {
260 int i;
261
202 if (a == NULL) return; 262 if (a == NULL) return;
203 if (a->d != NULL) 263 if (a->d != NULL)
204 { 264 {
205 memset(a->d,0,a->max*sizeof(a->d[0])); 265 memset(a->d,0,a->max*sizeof(a->d[0]));
206 Free(a->d); 266 if (!(BN_get_flags(a,BN_FLG_STATIC_DATA)))
267 Free(a->d);
207 } 268 }
269 i=BN_get_flags(a,BN_FLG_MALLOCED);
208 memset(a,0,sizeof(BIGNUM)); 270 memset(a,0,sizeof(BIGNUM));
209 Free(a); 271 if (i)
272 Free(a);
210 } 273 }
211 274
212void BN_free(a) 275void BN_free(BIGNUM *a)
213BIGNUM *a;
214 { 276 {
215 if (a == NULL) return; 277 if (a == NULL) return;
216 if (a->d != NULL) Free(a->d); 278 if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA)))
217 Free(a); 279 Free(a->d);
280 a->flags|=BN_FLG_FREE; /* REMOVE? */
281 if (a->flags & BN_FLG_MALLOCED)
282 Free(a);
283 }
284
285void BN_init(BIGNUM *a)
286 {
287 memset(a,0,sizeof(BIGNUM));
218 } 288 }
219 289
220BIGNUM *BN_new() 290BIGNUM *BN_new(void)
221 { 291 {
222 BIGNUM *ret; 292 BIGNUM *ret;
223 BN_ULONG *p;
224 293
225 ret=(BIGNUM *)Malloc(sizeof(BIGNUM)); 294 if ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL)
226 if (ret == NULL) goto err; 295 {
296 BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
297 return(NULL);
298 }
299 ret->flags=BN_FLG_MALLOCED;
227 ret->top=0; 300 ret->top=0;
228 ret->neg=0; 301 ret->neg=0;
229 ret->max=(BN_DEFAULT_BITS/BN_BITS2); 302 ret->max=0;
230 p=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(ret->max+1)); 303 ret->d=NULL;
231 if (p == NULL) goto err;
232 ret->d=p;
233
234 memset(p,0,(ret->max+1)*sizeof(p[0]));
235 return(ret); 304 return(ret);
236err:
237 BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
238 return(NULL);
239 } 305 }
240 306
241BN_CTX *BN_CTX_new() 307
308BN_CTX *BN_CTX_new(void)
242 { 309 {
243 BN_CTX *ret; 310 BN_CTX *ret;
244 BIGNUM *n;
245 int i,j;
246 311
247 ret=(BN_CTX *)Malloc(sizeof(BN_CTX)); 312 ret=(BN_CTX *)Malloc(sizeof(BN_CTX));
248 if (ret == NULL) goto err2; 313 if (ret == NULL)
249
250 for (i=0; i<BN_CTX_NUM; i++)
251 { 314 {
252 n=BN_new(); 315 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
253 if (n == NULL) goto err; 316 return(NULL);
254 ret->bn[i]=n;
255 } 317 }
256 318
257 /* There is actually an extra one, this is for debugging my 319 BN_CTX_init(ret);
258 * stuff */ 320 ret->flags=BN_FLG_MALLOCED;
259 ret->bn[BN_CTX_NUM]=NULL;
260
261 ret->tos=0;
262 return(ret); 321 return(ret);
263err:
264 for (j=0; j<i; j++)
265 BN_free(ret->bn[j]);
266 Free(ret);
267err2:
268 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
269 return(NULL);
270 } 322 }
271 323
272void BN_CTX_free(c) 324void BN_CTX_init(BN_CTX *ctx)
273BN_CTX *c; 325 {
326 memset(ctx,0,sizeof(BN_CTX));
327 ctx->tos=0;
328 ctx->flags=0;
329 }
330
331void BN_CTX_free(BN_CTX *c)
274 { 332 {
275 int i; 333 int i;
276 334
335 if(c == NULL)
336 return;
337
277 for (i=0; i<BN_CTX_NUM; i++) 338 for (i=0; i<BN_CTX_NUM; i++)
278 BN_clear_free(c->bn[i]); 339 BN_clear_free(&(c->bn[i]));
279 Free(c); 340 if (c->flags & BN_FLG_MALLOCED)
341 Free(c);
280 } 342 }
281 343
282BIGNUM *bn_expand2(b, words) 344BIGNUM *bn_expand2(BIGNUM *b, int words)
283BIGNUM *b;
284int words;
285 { 345 {
286 BN_ULONG *p; 346 BN_ULONG *A,*a;
347 const BN_ULONG *B;
348 int i;
349
350 bn_check_top(b);
287 351
288 if (words > b->max) 352 if (words > b->max)
289 { 353 {
290 p=(BN_ULONG *)Realloc(b->d,sizeof(BN_ULONG)*(words+1)); 354 bn_check_top(b);
291 if (p == NULL) 355 if (BN_get_flags(b,BN_FLG_STATIC_DATA))
356 {
357 BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
358 return(NULL);
359 }
360 a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
361 if (A == NULL)
292 { 362 {
293 BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); 363 BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
294 return(NULL); 364 return(NULL);
295 } 365 }
296 b->d=p; 366#if 1
297 memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG)); 367 B=b->d;
368 /* Check if the previous number needs to be copied */
369 if (B != NULL)
370 {
371#if 0
372 /* This lot is an unrolled loop to copy b->top
373 * BN_ULONGs from B to A
374 */
375/*
376 * I have nothing against unrolling but it's usually done for
377 * several reasons, namely:
378 * - minimize percentage of decision making code, i.e. branches;
379 * - avoid cache trashing;
380 * - make it possible to schedule loads earlier;
381 * Now let's examine the code below. The cornerstone of C is
382 * "programmer is always right" and that's what we love it for:-)
383 * For this very reason C compilers have to be paranoid when it
384 * comes to data aliasing and assume the worst. Yeah, but what
385 * does it mean in real life? This means that loop body below will
386 * be compiled to sequence of loads immediately followed by stores
387 * as compiler assumes the worst, something in A==B+1 style. As a
388 * result CPU pipeline is going to starve for incoming data. Secondly
389 * if A and B happen to share same cache line such code is going to
390 * cause severe cache trashing. Both factors have severe impact on
391 * performance of modern CPUs and this is the reason why this
392 * particulare piece of code is #ifdefed away and replaced by more
393 * "friendly" version found in #else section below. This comment
394 * also applies to BN_copy function.
395 *
396 * <appro@fy.chalmers.se>
397 */
398 for (i=b->top&(~7); i>0; i-=8)
399 {
400 A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
401 A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
402 A+=8;
403 B+=8;
404 }
405 switch (b->top&7)
406 {
407 case 7:
408 A[6]=B[6];
409 case 6:
410 A[5]=B[5];
411 case 5:
412 A[4]=B[4];
413 case 4:
414 A[3]=B[3];
415 case 3:
416 A[2]=B[2];
417 case 2:
418 A[1]=B[1];
419 case 1:
420 A[0]=B[0];
421 case 0:
422 /* I need the 'case 0' entry for utrix cc.
423 * If the optimiser is turned on, it does the
424 * switch table by doing
425 * a=top&7
426 * a--;
427 * goto jump_table[a];
428 * If top is 0, this makes us jump to 0xffffffc
429 * which is rather bad :-(.
430 * eric 23-Apr-1998
431 */
432 ;
433 }
434#else
435 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
436 {
437 /*
438 * The fact that the loop is unrolled
439 * 4-wise is a tribute to Intel. It's
440 * the one that doesn't have enough
441 * registers to accomodate more data.
442 * I'd unroll it 8-wise otherwise:-)
443 *
444 * <appro@fy.chalmers.se>
445 */
446 BN_ULONG a0,a1,a2,a3;
447 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
448 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
449 }
450 switch (b->top&3)
451 {
452 case 3: A[2]=B[2];
453 case 2: A[1]=B[1];
454 case 1: A[0]=B[0];
455 case 0: ; /* ultrix cc workaround, see above */
456 }
457#endif
458 Free(b->d);
459 }
460
461 b->d=a;
298 b->max=words; 462 b->max=words;
463
464 /* Now need to zero any data between b->top and b->max */
465
466 A= &(b->d[b->top]);
467 for (i=(b->max - b->top)>>3; i>0; i--,A+=8)
468 {
469 A[0]=0; A[1]=0; A[2]=0; A[3]=0;
470 A[4]=0; A[5]=0; A[6]=0; A[7]=0;
471 }
472 for (i=(b->max - b->top)&7; i>0; i--,A++)
473 A[0]=0;
474#else
475 memset(A,0,sizeof(BN_ULONG)*(words+1));
476 memcpy(A,b->d,sizeof(b->d[0])*b->top);
477 b->d=a;
478 b->max=words;
479#endif
480
481/* memset(&(p[b->max]),0,((words+1)-b->max)*sizeof(BN_ULONG)); */
482/* { int i; for (i=b->max; i<words+1; i++) p[i]=i;} */
483
299 } 484 }
300 return(b); 485 return(b);
301 } 486 }
302 487
303BIGNUM *BN_dup(a) 488BIGNUM *BN_dup(const BIGNUM *a)
304BIGNUM *a;
305 { 489 {
306 BIGNUM *r; 490 BIGNUM *r;
307 491
492 if (a == NULL) return NULL;
493
494 bn_check_top(a);
495
308 r=BN_new(); 496 r=BN_new();
309 if (r == NULL) return(NULL); 497 if (r == NULL) return(NULL);
310 return((BIGNUM *)BN_copy(r,a)); 498 return((BIGNUM *)BN_copy(r,a));
311 } 499 }
312 500
313BIGNUM *BN_copy(a, b) 501BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
314BIGNUM *a;
315BIGNUM *b;
316 { 502 {
317 int i; 503 int i;
318 BN_ULONG *A,*B; 504 BN_ULONG *A;
505 const BN_ULONG *B;
506
507 bn_check_top(b);
319 508
320 if (a == b) return(a); 509 if (a == b) return(a);
321 if (bn_wexpand(a,b->top) == NULL) return(NULL); 510 if (bn_wexpand(a,b->top) == NULL) return(NULL);
@@ -323,35 +512,18 @@ BIGNUM *b;
323#if 1 512#if 1
324 A=a->d; 513 A=a->d;
325 B=b->d; 514 B=b->d;
326 for (i=b->top&(~7); i>0; i-=8) 515 for (i=b->top>>2; i>0; i--,A+=4,B+=4)
327 { 516 {
328 A[0]=B[0]; 517 BN_ULONG a0,a1,a2,a3;
329 A[1]=B[1]; 518 a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
330 A[2]=B[2]; 519 A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
331 A[3]=B[3];
332 A[4]=B[4];
333 A[5]=B[5];
334 A[6]=B[6];
335 A[7]=B[7];
336 A+=8;
337 B+=8;
338 } 520 }
339 switch (b->top&7) 521 switch (b->top&3)
340 { 522 {
341 case 7: 523 case 3: A[2]=B[2];
342 A[6]=B[6]; 524 case 2: A[1]=B[1];
343 case 6: 525 case 1: A[0]=B[0];
344 A[5]=B[5]; 526 case 0: ; /* ultrix cc workaround, see comments in bn_expand2 */
345 case 5:
346 A[4]=B[4];
347 case 4:
348 A[3]=B[3];
349 case 3:
350 A[2]=B[2];
351 case 2:
352 A[1]=B[1];
353 case 1:
354 A[0]=B[0];
355 } 527 }
356#else 528#else
357 memcpy(a->d,b->d,sizeof(b->d[0])*b->top); 529 memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
@@ -359,52 +531,47 @@ BIGNUM *b;
359 531
360/* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/ 532/* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/
361 a->top=b->top; 533 a->top=b->top;
362 if (a->top == 0) 534 if ((a->top == 0) && (a->d != NULL))
363 a->d[0]=0; 535 a->d[0]=0;
364 a->neg=b->neg; 536 a->neg=b->neg;
365 return(a); 537 return(a);
366 } 538 }
367 539
368void BN_clear(a) 540void BN_clear(BIGNUM *a)
369BIGNUM *a;
370 { 541 {
371 memset(a->d,0,a->max*sizeof(a->d[0])); 542 if (a->d != NULL)
543 memset(a->d,0,a->max*sizeof(a->d[0]));
372 a->top=0; 544 a->top=0;
373 a->neg=0; 545 a->neg=0;
374 } 546 }
375 547
376unsigned long BN_get_word(a) 548BN_ULONG BN_get_word(BIGNUM *a)
377BIGNUM *a;
378 { 549 {
379 int i,n; 550 int i,n;
380 unsigned long ret=0; 551 BN_ULONG ret=0;
381 552
382 n=BN_num_bytes(a); 553 n=BN_num_bytes(a);
383 if (n > sizeof(unsigned long)) 554 if (n > sizeof(BN_ULONG))
384#ifdef SIXTY_FOUR_BIT_LONG
385 return(BN_MASK2); 555 return(BN_MASK2);
386#else
387 return(0xFFFFFFFFL);
388#endif
389 for (i=a->top-1; i>=0; i--) 556 for (i=a->top-1; i>=0; i--)
390 { 557 {
391#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ 558#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
392 ret<<=BN_BITS4; /* stops the compiler complaining */ 559 ret<<=BN_BITS4; /* stops the compiler complaining */
393 ret<<=BN_BITS4; 560 ret<<=BN_BITS4;
561#else
562 ret=0;
394#endif 563#endif
395 ret|=a->d[i]; 564 ret|=a->d[i];
396 } 565 }
397 return(ret); 566 return(ret);
398 } 567 }
399 568
400int BN_set_word(a,w) 569int BN_set_word(BIGNUM *a, BN_ULONG w)
401BIGNUM *a;
402unsigned long w;
403 { 570 {
404 int i,n; 571 int i,n;
405 if (bn_expand(a,sizeof(unsigned long)*8) == NULL) return(0); 572 if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);
406 573
407 n=sizeof(unsigned long)/BN_BYTES; 574 n=sizeof(BN_ULONG)/BN_BYTES;
408 a->neg=0; 575 a->neg=0;
409 a->top=0; 576 a->top=0;
410 a->d[0]=(BN_ULONG)w&BN_MASK2; 577 a->d[0]=(BN_ULONG)w&BN_MASK2;
@@ -417,6 +584,8 @@ unsigned long w;
417#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */ 584#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
418 w>>=BN_BITS4; 585 w>>=BN_BITS4;
419 w>>=BN_BITS4; 586 w>>=BN_BITS4;
587#else
588 w=0;
420#endif 589#endif
421 a->d[i]=(BN_ULONG)w&BN_MASK2; 590 a->d[i]=(BN_ULONG)w&BN_MASK2;
422 if (a->d[i] != 0) a->top=i+1; 591 if (a->d[i] != 0) a->top=i+1;
@@ -425,10 +594,7 @@ unsigned long w;
425 } 594 }
426 595
427/* ignore negative */ 596/* ignore negative */
428BIGNUM *BN_bin2bn(s, len, ret) 597BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
429unsigned char *s;
430int len;
431BIGNUM *ret;
432 { 598 {
433 unsigned int i,m; 599 unsigned int i,m;
434 unsigned int n; 600 unsigned int n;
@@ -465,9 +631,7 @@ BIGNUM *ret;
465 } 631 }
466 632
467/* ignore negative */ 633/* ignore negative */
468int BN_bn2bin(a, to) 634int BN_bn2bin(const BIGNUM *a, unsigned char *to)
469BIGNUM *a;
470unsigned char *to;
471 { 635 {
472 int n,i; 636 int n,i;
473 BN_ULONG l; 637 BN_ULONG l;
@@ -481,13 +645,14 @@ unsigned char *to;
481 return(n); 645 return(n);
482 } 646 }
483 647
484int BN_ucmp(a, b) 648int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
485BIGNUM *a;
486BIGNUM *b;
487 { 649 {
488 int i; 650 int i;
489 BN_ULONG t1,t2,*ap,*bp; 651 BN_ULONG t1,t2,*ap,*bp;
490 652
653 bn_check_top(a);
654 bn_check_top(b);
655
491 i=a->top-b->top; 656 i=a->top-b->top;
492 if (i != 0) return(i); 657 if (i != 0) return(i);
493 ap=a->d; 658 ap=a->d;
@@ -502,9 +667,7 @@ BIGNUM *b;
502 return(0); 667 return(0);
503 } 668 }
504 669
505int BN_cmp(a, b) 670int BN_cmp(const BIGNUM *a, const BIGNUM *b)
506BIGNUM *a;
507BIGNUM *b;
508 { 671 {
509 int i; 672 int i;
510 int gt,lt; 673 int gt,lt;
@@ -519,6 +682,10 @@ BIGNUM *b;
519 else 682 else
520 return(0); 683 return(0);
521 } 684 }
685
686 bn_check_top(a);
687 bn_check_top(b);
688
522 if (a->neg != b->neg) 689 if (a->neg != b->neg)
523 { 690 {
524 if (a->neg) 691 if (a->neg)
@@ -541,27 +708,25 @@ BIGNUM *b;
541 return(0); 708 return(0);
542 } 709 }
543 710
544int BN_set_bit(a, n) 711int BN_set_bit(BIGNUM *a, int n)
545BIGNUM *a;
546int n;
547 { 712 {
548 int i,j; 713 int i,j,k;
549 714
550 i=n/BN_BITS2; 715 i=n/BN_BITS2;
551 j=n%BN_BITS2; 716 j=n%BN_BITS2;
552 if (a->top <= i) 717 if (a->top <= i)
553 { 718 {
554 if (bn_expand(a,n) == NULL) return(0); 719 if (bn_wexpand(a,i+1) == NULL) return(0);
720 for(k=a->top; k<i+1; k++)
721 a->d[k]=0;
555 a->top=i+1; 722 a->top=i+1;
556 } 723 }
557 724
558 a->d[i]|=(1L<<j); 725 a->d[i]|=(((BN_ULONG)1)<<j);
559 return(1); 726 return(1);
560 } 727 }
561 728
562int BN_clear_bit(a, n) 729int BN_clear_bit(BIGNUM *a, int n)
563BIGNUM *a;
564int n;
565 { 730 {
566 int i,j; 731 int i,j;
567 732
@@ -569,13 +734,12 @@ int n;
569 j=n%BN_BITS2; 734 j=n%BN_BITS2;
570 if (a->top <= i) return(0); 735 if (a->top <= i) return(0);
571 736
572 a->d[i]&=(~(1L<<j)); 737 a->d[i]&=(~(((BN_ULONG)1)<<j));
738 bn_fix_top(a);
573 return(1); 739 return(1);
574 } 740 }
575 741
576int BN_is_bit_set(a, n) 742int BN_is_bit_set(const BIGNUM *a, int n)
577BIGNUM *a;
578int n;
579 { 743 {
580 int i,j; 744 int i,j;
581 745
@@ -586,9 +750,7 @@ int n;
586 return((a->d[i]&(((BN_ULONG)1)<<j))?1:0); 750 return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
587 } 751 }
588 752
589int BN_mask_bits(a,n) 753int BN_mask_bits(BIGNUM *a, int n)
590BIGNUM *a;
591int n;
592 { 754 {
593 int b,w; 755 int b,w;
594 756
@@ -601,11 +763,25 @@ int n;
601 { 763 {
602 a->top=w+1; 764 a->top=w+1;
603 a->d[w]&= ~(BN_MASK2<<b); 765 a->d[w]&= ~(BN_MASK2<<b);
604 while ((w >= 0) && (a->d[w] == 0))
605 {
606 a->top--;
607 w--;
608 }
609 } 766 }
767 bn_fix_top(a);
610 return(1); 768 return(1);
611 } 769 }
770
771int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n)
772 {
773 int i;
774 BN_ULONG aa,bb;
775
776 aa=a[n-1];
777 bb=b[n-1];
778 if (aa != bb) return((aa > bb)?1:-1);
779 for (i=n-2; i>=0; i--)
780 {
781 aa=a[i];
782 bb=b[i];
783 if (aa != bb) return((aa > bb)?1:-1);
784 }
785 return(0);
786 }
787
diff --git a/src/lib/libcrypto/bn/bn_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 @@
1/* crypto/bn/bn_m.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62#include "stack.h"
63
64int limit=16;
65
66typedef struct bn_pool_st
67 {
68 int used;
69 int tos;
70 STACK *sk;
71 } BN_POOL;
72
73BIGNUM *BN_POOL_push(bp)
74BN_POOL *bp;
75 {
76 BIGNUM *ret;
77
78 if (bp->used >= bp->tos)
79 {
80 ret=BN_new();
81 sk_push(bp->sk,(char *)ret);
82 bp->tos++;
83 bp->used++;
84 }
85 else
86 {
87 ret=(BIGNUM *)sk_value(bp->sk,bp->used);
88 bp->used++;
89 }
90 return(ret);
91 }
92
93void BN_POOL_pop(bp,num)
94BN_POOL *bp;
95int num;
96 {
97 bp->used-=num;
98 }
99
100int BN_m(r,a,b)
101BIGNUM *r,*a,*b;
102 {
103 static BN_POOL bp;
104 static init=1;
105
106 if (init)
107 {
108 bp.used=0;
109 bp.tos=0;
110 bp.sk=sk_new_null();
111 init=0;
112 }
113 return(BN_mm(r,a,b,&bp));
114 }
115
116/* r must be different to a and b */
117int BN_mm(m, A, B, bp)
118BIGNUM *m,*A,*B;
119BN_POOL *bp;
120 {
121 int i,num;
122 int an,bn;
123 BIGNUM *a,*b,*c,*d,*ac,*bd;
124
125 an=A->top;
126 bn=B->top;
127 if ((an <= limit) || (bn <= limit))
128 {
129 return(BN_mul(m,A,B));
130 }
131
132 a=BN_POOL_push(bp);
133 b=BN_POOL_push(bp);
134 c=BN_POOL_push(bp);
135 d=BN_POOL_push(bp);
136 ac=BN_POOL_push(bp);
137 bd=BN_POOL_push(bp);
138
139 num=(an <= bn)?an:bn;
140 num=1<<(BN_num_bits_word(num-1)-1);
141
142 /* Are going to now chop things into 'num' word chunks. */
143 num*=BN_BITS2;
144
145 BN_copy(a,A);
146 BN_mask_bits(a,num);
147 BN_rshift(b,A,num);
148
149 BN_copy(c,B);
150 BN_mask_bits(c,num);
151 BN_rshift(d,B,num);
152
153 BN_sub(ac ,b,a);
154 BN_sub(bd,c,d);
155 BN_mm(m,ac,bd,bp);
156 BN_mm(ac,a,c,bp);
157 BN_mm(bd,b,d,bp);
158
159 BN_add(m,m,ac);
160 BN_add(m,m,bd);
161 BN_lshift(m,m,num);
162 BN_lshift(bd,bd,num*2);
163
164 BN_add(m,m,ac);
165 BN_add(m,m,bd);
166 BN_POOL_pop(bp,6);
167 return(1);
168 }
169
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/*
60 * Details about Montgomery multiplication algorithms can be found at:
61 * http://www.ece.orst.edu/ISL/Publications.html
62 * http://www.ece.orst.edu/ISL/Koc/papers/j37acmon.pdf
63 */
64
59#include <stdio.h> 65#include <stdio.h>
60#include "cryptlib.h" 66#include "cryptlib.h"
61#include "bn_lcl.h" 67#include "bn_lcl.h"
62 68
63int BN_mod_mul_montgomery(r,a,b,mont,ctx) 69#define MONT_WORD
64BIGNUM *r,*a,*b; 70
65BN_MONT_CTX *mont; 71int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,
66BN_CTX *ctx; 72 BN_MONT_CTX *mont, BN_CTX *ctx)
67 { 73 {
68 BIGNUM *tmp; 74 BIGNUM *tmp,*tmp2;
75
76 tmp= &(ctx->bn[ctx->tos]);
77 tmp2= &(ctx->bn[ctx->tos]);
78 ctx->tos+=2;
69 79
70 tmp=ctx->bn[ctx->tos++]; 80 bn_check_top(tmp);
81 bn_check_top(tmp2);
71 82
72 if (a == b) 83 if (a == b)
73 { 84 {
85#if 0
86 bn_wexpand(tmp,a->top*2);
87 bn_wexpand(tmp2,a->top*4);
88 bn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);
89 tmp->top=a->top*2;
90 if (tmp->d[tmp->top-1] == 0)
91 tmp->top--;
92#else
74 if (!BN_sqr(tmp,a,ctx)) goto err; 93 if (!BN_sqr(tmp,a,ctx)) goto err;
94#endif
75 } 95 }
76 else 96 else
77 { 97 {
78 if (!BN_mul(tmp,a,b)) goto err; 98 if (!BN_mul(tmp,a,b,ctx)) goto err;
79 } 99 }
80 /* reduce from aRR to aR */ 100 /* reduce from aRR to aR */
81 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err; 101 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
82 ctx->tos--; 102 ctx->tos-=2;
83 return(1); 103 return(1);
84err: 104err:
85 return(0); 105 return(0);
86 } 106 }
87 107
88#define MONT_WORD 108int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,
89 109 BN_CTX *ctx)
90#ifdef MONT_WORD
91int BN_from_montgomery(ret,a,mont,ctx)
92BIGNUM *ret;
93BIGNUM *a;
94BN_MONT_CTX *mont;
95BN_CTX *ctx;
96 { 110 {
97 BIGNUM *n,*t1,*r; 111#ifdef BN_RECURSION_MONT
98 BN_ULONG *ap,*np,*rp,n0,v; 112 if (mont->use_word)
99 int al,nl,max,i,x,ri; 113#endif
100 int retn=0; 114 {
115 BIGNUM *n,*r;
116 BN_ULONG *ap,*np,*rp,n0,v,*nrp;
117 int al,nl,max,i,x,ri;
118 int retn=0;
101 119
102 t1=ctx->bn[ctx->tos]; 120 r= &(ctx->bn[ctx->tos]);
103 r=ctx->bn[ctx->tos+1];
104 121
105 if (!BN_copy(r,a)) goto err; 122 if (!BN_copy(r,a)) goto err1;
106 n=mont->N; 123 n= &(mont->N);
107 124
108 ap=a->d; 125 ap=a->d;
109 /* mont->ri is the size of mont->N in bits/words */ 126 /* mont->ri is the size of mont->N in bits/words */
110 al=ri=mont->ri/BN_BITS2; 127 al=ri=mont->ri/BN_BITS2;
111 128
112 nl=n->top; 129 nl=n->top;
113 if ((al == 0) || (nl == 0)) { r->top=0; return(1); } 130 if ((al == 0) || (nl == 0)) { r->top=0; return(1); }
114 131
115 max=(nl+al+1); /* allow for overflow (no?) XXX */ 132 max=(nl+al+1); /* allow for overflow (no?) XXX */
116 if (bn_wexpand(r,max) == NULL) goto err; 133 if (bn_wexpand(r,max) == NULL) goto err1;
117 if (bn_wexpand(ret,max) == NULL) goto err; 134 if (bn_wexpand(ret,max) == NULL) goto err1;
118 135
119 r->neg=a->neg^n->neg; 136 r->neg=a->neg^n->neg;
120 np=n->d; 137 np=n->d;
121 rp=r->d; 138 rp=r->d;
139 nrp= &(r->d[nl]);
122 140
123 /* clear the top words of T */ 141 /* clear the top words of T */
124#if 1 142#if 1
125 for (i=r->top; i<max; i++) /* memset? XXX */ 143 for (i=r->top; i<max; i++) /* memset? XXX */
126 r->d[i]=0; 144 r->d[i]=0;
127#else 145#else
128 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); 146 memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));
129#endif 147#endif
130 148
131 r->top=max; 149 r->top=max;
132 n0=mont->n0; 150 n0=mont->n0;
133
134 for (i=0; i<nl; i++)
135 {
136#if 0
137 int x1,x2;
138 151
139 if (i+4 > nl) 152#ifdef BN_COUNT
153printf("word BN_from_montgomery %d * %d\n",nl,nl);
154#endif
155 for (i=0; i<nl; i++)
140 { 156 {
141 x2=nl; 157 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
142 x1=0; 158 nrp++;
159 rp++;
160 if (((nrp[-1]+=v)&BN_MASK2) >= v)
161 continue;
162 else
163 {
164 if (((++nrp[0])&BN_MASK2) != 0) continue;
165 if (((++nrp[1])&BN_MASK2) != 0) continue;
166 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
167 }
143 } 168 }
169 bn_fix_top(r);
170
171 /* mont->ri will be a multiple of the word size */
172#if 0
173 BN_rshift(ret,r,mont->ri);
174#else
175 x=ri;
176 rp=ret->d;
177 ap= &(r->d[x]);
178 if (r->top < x)
179 al=0;
144 else 180 else
181 al=r->top-x;
182 ret->top=al;
183 al-=4;
184 for (i=0; i<al; i+=4)
145 { 185 {
146 x2=i+4; 186 BN_ULONG t1,t2,t3,t4;
147 x1=nl-x2; 187
188 t1=ap[i+0];
189 t2=ap[i+1];
190 t3=ap[i+2];
191 t4=ap[i+3];
192 rp[i+0]=t1;
193 rp[i+1]=t2;
194 rp[i+2]=t3;
195 rp[i+3]=t4;
148 } 196 }
149 v=bn_mul_add_words(&(rp[x1]),&(np[x1]),x2,(rp[x1]*n0)&BN_MASK2); 197 al+=4;
150#else 198 for (; i<al; i++)
151 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2); 199 rp[i]=ap[i];
152#endif 200#endif
153 201
154 if (((rp[nl]+=v)&BN_MASK2) < v) 202 if (BN_ucmp(ret, &(mont->N)) >= 0)
155 { 203 {
156 for (x=(nl+1); (((++rp[x])&BN_MASK2) == 0); x++) 204 BN_usub(ret,ret,&(mont->N)); /* XXX */
157 ;
158 } 205 }
159 rp++; 206 retn=1;
207err1:
208 return(retn);
160 } 209 }
161 while (r->d[r->top-1] == 0) 210#ifdef BN_RECURSION_MONT
162 r->top--; 211 else /* bignum version */
163
164 /* mont->ri will be a multiple of the word size */
165#if 0
166 BN_rshift(ret,r,mont->ri);
167#else
168 ap=r->d;
169 rp=ret->d;
170 x=ri;
171 al=r->top-x;
172 for (i=0; i<al; i++)
173 { 212 {
174 rp[i]=ap[i+x]; 213 BIGNUM *t1,*t2,*t3;
175 } 214 int j,i;
176 ret->top=al; 215
216#ifdef BN_COUNT
217printf("number BN_from_montgomery\n");
177#endif 218#endif
178 219
179 if (BN_ucmp(ret,mont->N) >= 0) 220 t1= &(ctx->bn[ctx->tos]);
180 { 221 t2= &(ctx->bn[ctx->tos+1]);
181 bn_qsub(ret,ret,mont->N); /* XXX */ 222 t3= &(ctx->bn[ctx->tos+2]);
182 }
183 retn=1;
184err:
185 return(retn);
186 }
187#else
188int BN_from_montgomery(r,a,mont,ctx)
189BIGNUM *r;
190BIGNUM *a;
191BN_MONT_CTX *mont;
192BN_CTX *ctx;
193 {
194 BIGNUM *t1,*t2;
195 223
196 t1=ctx->bn[ctx->tos]; 224 i=mont->Ni.top;
197 t2=ctx->bn[ctx->tos+1]; 225 bn_wexpand(ret,i); /* perhaps only i*2 */
226 bn_wexpand(t1,i*4); /* perhaps only i*2 */
227 bn_wexpand(t2,i*2); /* perhaps only i */
198 228
199 if (!BN_copy(t1,a)) goto err; 229 bn_mul_low_recursive(t2->d,a->d,mont->Ni.d,i,t1->d);
200 /* can cheat */
201 BN_mask_bits(t1,mont->ri);
202 230
203 if (!BN_mul(t2,t1,mont->Ni)) goto err; 231 BN_zero(t3);
204 BN_mask_bits(t2,mont->ri); 232 BN_set_bit(t3,mont->N.top*BN_BITS2);
233 bn_sub_words(t3->d,t3->d,a->d,i);
234 bn_mul_high(ret->d,t2->d,mont->N.d,t3->d,i,t1->d);
205 235
206 if (!BN_mul(t1,t2,mont->N)) goto err; 236 /* hmm... if a is between i and 2*i, things are bad */
207 if (!BN_add(t2,a,t1)) goto err; 237 if (a->top > i)
208 BN_rshift(r,t2,mont->ri); 238 {
239 j=(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i));
240 if (j) /* overflow */
241 bn_sub_words(ret->d,ret->d,mont->N.d,i);
242 }
243 ret->top=i;
244 bn_fix_top(ret);
245 if (a->d[0])
246 BN_add_word(ret,1); /* Always? */
247 else /* Very very rare */
248 {
249 for (i=1; i<mont->N.top-1; i++)
250 {
251 if (a->d[i])
252 {
253 BN_add_word(ret,1); /* Always? */
254 break;
255 }
256 }
257 }
209 258
210 if (BN_ucmp(r,mont->N) >= 0) 259 if (BN_ucmp(ret,&(mont->N)) >= 0)
211 bn_qsub(r,r,mont->N); 260 BN_usub(ret,ret,&(mont->N));
212 261
213 return(1); 262 return(1);
214err: 263 }
215 return(0);
216 }
217#endif 264#endif
265 }
218 266
219BN_MONT_CTX *BN_MONT_CTX_new() 267BN_MONT_CTX *BN_MONT_CTX_new(void)
220 { 268 {
221 BN_MONT_CTX *ret; 269 BN_MONT_CTX *ret;
222 270
223 if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL) 271 if ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)
224 return(NULL); 272 return(NULL);
225 ret->ri=0; 273
226 ret->RR=BN_new(); 274 BN_MONT_CTX_init(ret);
227 ret->N=BN_new(); 275 ret->flags=BN_FLG_MALLOCED;
228 ret->Ni=NULL;
229 if ((ret->RR == NULL) || (ret->N == NULL))
230 {
231 BN_MONT_CTX_free(ret);
232 return(NULL);
233 }
234 return(ret); 276 return(ret);
235 } 277 }
236 278
237void BN_MONT_CTX_free(mont) 279void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
238BN_MONT_CTX *mont; 280 {
281 ctx->use_word=0;
282 ctx->ri=0;
283 BN_init(&(ctx->RR));
284 BN_init(&(ctx->N));
285 BN_init(&(ctx->Ni));
286 ctx->flags=0;
287 }
288
289void BN_MONT_CTX_free(BN_MONT_CTX *mont)
239 { 290 {
240 if (mont->RR != NULL) BN_free(mont->RR); 291 if(mont == NULL)
241 if (mont->N != NULL) BN_free(mont->N); 292 return;
242 if (mont->Ni != NULL) BN_free(mont->Ni); 293
243 Free(mont); 294 BN_free(&(mont->RR));
295 BN_free(&(mont->N));
296 BN_free(&(mont->Ni));
297 if (mont->flags & BN_FLG_MALLOCED)
298 Free(mont);
244 } 299 }
245 300
246int BN_MONT_CTX_set(mont,mod,ctx) 301int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
247BN_MONT_CTX *mont;
248BIGNUM *mod;
249BN_CTX *ctx;
250 { 302 {
251 BIGNUM *Ri=NULL,*R=NULL; 303 BIGNUM Ri,*R;
252 304
253 if (mont->RR == NULL) mont->RR=BN_new(); 305 BN_init(&Ri);
254 if (mont->N == NULL) mont->N=BN_new(); 306 R= &(mont->RR); /* grab RR as a temp */
255 307 BN_copy(&(mont->N),mod); /* Set N */
256 R=mont->RR; /* grab RR as a temp */ 308
257 BN_copy(mont->N,mod); /* Set N */ 309#ifdef BN_RECURSION_MONT
258 310 if (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)
259#ifdef MONT_WORD 311#endif
260{ 312 {
261 BIGNUM tmod; 313 BIGNUM tmod;
262 BN_ULONG buf[2]; 314 BN_ULONG buf[2];
263 /* int z; */ 315
264 316 mont->use_word=1;
265 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; 317
266 BN_lshift(R,BN_value_one(),BN_BITS2); /* R */ 318 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
267 /* I was bad, this modification of a passed variable was 319 BN_zero(R);
268 * breaking the multithreaded stuff :-( 320 BN_set_bit(R,BN_BITS2);
269 * z=mod->top; 321 /* I was bad, this modification of a passed variable was
270 * mod->top=1; */ 322 * breaking the multithreaded stuff :-(
271 323 * z=mod->top;
272 buf[0]=mod->d[0]; 324 * mod->top=1; */
273 buf[1]=0; 325
274 tmod.d=buf; 326 buf[0]=mod->d[0];
275 tmod.top=1; 327 buf[1]=0;
276 tmod.max=mod->max; 328 tmod.d=buf;
277 tmod.neg=mod->neg; 329 tmod.top=1;
278 330 tmod.max=mod->max;
279 if ((Ri=BN_mod_inverse(R,&tmod,ctx)) == NULL) goto err; /* Ri */ 331 tmod.neg=mod->neg;
280 BN_lshift(Ri,Ri,BN_BITS2); /* R*Ri */ 332
281 bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */ 333 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)
282 BN_div(Ri,NULL,Ri,&tmod,ctx); 334 goto err;
283 mont->n0=Ri->d[0]; 335 BN_lshift(&Ri,&Ri,BN_BITS2); /* R*Ri */
284 BN_free(Ri); 336 if (!BN_is_zero(&Ri))
285 /* mod->top=z; */ 337 {
286} 338#if 1
339 BN_sub_word(&Ri,1);
287#else 340#else
288 mont->ri=BN_num_bits(mod); 341 BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */
289 BN_lshift(R,BN_value_one(),mont->ri); /* R */ 342#endif
290 if ((Ri=BN_mod_inverse(R,mod,ctx)) == NULL) goto err; /* Ri */ 343 }
291 BN_lshift(Ri,Ri,mont->ri); /* R*Ri */ 344 else
292 bn_qsub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */ 345 {
293 BN_div(Ri,NULL,Ri,mod,ctx); 346 /* This is not common..., 1 in BN_MASK2,
294 if (mont->Ni != NULL) BN_free(mont->Ni); 347 * It happens when buf[0] was == 1. So for 8 bit,
295 mont->Ni=Ri; /* Ni=(R*Ri-1)/N */ 348 * this is 1/256, 16bit, 1 in 2^16 etc.
349 */
350 BN_set_word(&Ri,BN_MASK2);
351 }
352 BN_div(&Ri,NULL,&Ri,&tmod,ctx);
353 mont->n0=Ri.d[0];
354 BN_free(&Ri);
355 /* mod->top=z; */
356 }
357#ifdef BN_RECURSION_MONT
358 else
359 {
360 mont->use_word=0;
361 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
362#if 1
363 BN_zero(R);
364 BN_set_bit(R,mont->ri);
365#else
366 BN_lshift(R,BN_value_one(),mont->ri); /* R */
367#endif
368 if ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)
369 goto err;
370 BN_lshift(&Ri,&Ri,mont->ri); /* R*Ri */
371#if 1
372 BN_sub_word(&Ri,1);
373#else
374 BN_usub(&Ri,&Ri,BN_value_one()); /* R*Ri - 1 */
375#endif
376 BN_div(&(mont->Ni),NULL,&Ri,mod,ctx);
377 BN_free(&Ri);
378 }
296#endif 379#endif
297 380
298 /* setup RR for conversions */ 381 /* setup RR for conversions */
382#if 1
383 BN_zero(&(mont->RR));
384 BN_set_bit(&(mont->RR),mont->ri*2);
385#else
299 BN_lshift(mont->RR,BN_value_one(),mont->ri*2); 386 BN_lshift(mont->RR,BN_value_one(),mont->ri*2);
300 BN_mod(mont->RR,mont->RR,mont->N,ctx); 387#endif
388 BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);
301 389
302 return(1); 390 return(1);
303err: 391err:
304 return(0); 392 return(0);
305 } 393 }
306 394
395BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
396 {
397 if (to == from) return(to);
398
399 BN_copy(&(to->RR),&(from->RR));
400 BN_copy(&(to->N),&(from->N));
401 BN_copy(&(to->Ni),&(from->Ni));
402 to->use_word=from->use_word;
403 to->ri=from->ri;
404 to->n0=from->n0;
405 return(to);
406 }
407
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c
index 53945c1057..80e1dca6b7 100644
--- a/src/lib/libcrypto/bn/bn_mpi.c
+++ b/src/lib/libcrypto/bn/bn_mpi.c
@@ -60,9 +60,7 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63int BN_bn2mpi(a,d) 63int BN_bn2mpi(const BIGNUM *a, unsigned char *d)
64BIGNUM *a;
65unsigned char *d;
66 { 64 {
67 int bits; 65 int bits;
68 int num=0; 66 int num=0;
@@ -90,10 +88,7 @@ unsigned char *d;
90 return(num+4+ext); 88 return(num+4+ext);
91 } 89 }
92 90
93BIGNUM *BN_mpi2bn(d,n,a) 91BIGNUM *BN_mpi2bn(unsigned char *d, int n, BIGNUM *a)
94unsigned char *d;
95int n;
96BIGNUM *a;
97 { 92 {
98 long len; 93 long len;
99 int neg=0; 94 int neg=0;
@@ -103,7 +98,7 @@ BIGNUM *a;
103 BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH); 98 BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH);
104 return(NULL); 99 return(NULL);
105 } 100 }
106 len=(d[0]<<24)|(d[1]<<16)|(d[2]<<8)|d[3]; 101 len=((long)d[0]<<24)|((long)d[1]<<16)|((int)d[2]<<8)|(int)d[3];
107 if ((len+4) != n) 102 if ((len+4) != n)
108 { 103 {
109 BNerr(BN_F_BN_MPI2BN,BN_R_ENCODING_ERROR); 104 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 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63/* r must be different to a and b */ 63#ifdef BN_RECURSION
64/* int BN_mmul(r, a, b) */ 64/* r is 2*n2 words in size,
65int BN_mul(r, a, b) 65 * a and b are both n2 words in size.
66BIGNUM *r; 66 * n2 must be a power of 2.
67BIGNUM *a; 67 * We multiply and return the result.
68BIGNUM *b; 68 * t must be 2*n2 words in size
69 * We calulate
70 * a[0]*b[0]
71 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
72 * a[1]*b[1]
73 */
74void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
75 BN_ULONG *t)
69 { 76 {
70 int i; 77 int n=n2/2,c1,c2;
71 int max,al,bl; 78 unsigned int neg,zero;
72 BN_ULONG *ap,*bp,*rp; 79 BN_ULONG ln,lo,*p;
73 80
74 al=a->top; 81#ifdef BN_COUNT
75 bl=b->top; 82printf(" bn_mul_recursive %d * %d\n",n2,n2);
76 if ((al == 0) || (bl == 0)) 83#endif
84#ifdef BN_MUL_COMBA
85/* if (n2 == 4)
77 { 86 {
78 r->top=0; 87 bn_mul_comba4(r,a,b);
79 return(1); 88 return;
89 }
90 else */ if (n2 == 8)
91 {
92 bn_mul_comba8(r,a,b);
93 return;
94 }
95#endif
96 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)
97 {
98 /* This should not happen */
99 bn_mul_normal(r,a,n2,b,n2);
100 return;
101 }
102 /* r=(a[0]-a[1])*(b[1]-b[0]) */
103 c1=bn_cmp_words(a,&(a[n]),n);
104 c2=bn_cmp_words(&(b[n]),b,n);
105 zero=neg=0;
106 switch (c1*3+c2)
107 {
108 case -4:
109 bn_sub_words(t, &(a[n]),a, n); /* - */
110 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
111 break;
112 case -3:
113 zero=1;
114 break;
115 case -2:
116 bn_sub_words(t, &(a[n]),a, n); /* - */
117 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
118 neg=1;
119 break;
120 case -1:
121 case 0:
122 case 1:
123 zero=1;
124 break;
125 case 2:
126 bn_sub_words(t, a, &(a[n]),n); /* + */
127 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
128 neg=1;
129 break;
130 case 3:
131 zero=1;
132 break;
133 case 4:
134 bn_sub_words(t, a, &(a[n]),n);
135 bn_sub_words(&(t[n]),&(b[n]),b, n);
136 break;
80 } 137 }
81 138
82 max=(al+bl); 139#ifdef BN_MUL_COMBA
83 if (bn_wexpand(r,max) == NULL) return(0); 140 if (n == 4)
84 r->top=max; 141 {
85 r->neg=a->neg^b->neg; 142 if (!zero)
86 ap=a->d; 143 bn_mul_comba4(&(t[n2]),t,&(t[n]));
87 bp=b->d; 144 else
88 rp=r->d; 145 memset(&(t[n2]),0,8*sizeof(BN_ULONG));
146
147 bn_mul_comba4(r,a,b);
148 bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));
149 }
150 else if (n == 8)
151 {
152 if (!zero)
153 bn_mul_comba8(&(t[n2]),t,&(t[n]));
154 else
155 memset(&(t[n2]),0,16*sizeof(BN_ULONG));
156
157 bn_mul_comba8(r,a,b);
158 bn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));
159 }
160 else
161#endif
162 {
163 p= &(t[n2*2]);
164 if (!zero)
165 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
166 else
167 memset(&(t[n2]),0,n2*sizeof(BN_ULONG));
168 bn_mul_recursive(r,a,b,n,p);
169 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);
170 }
89 171
90 rp[al]=bn_mul_words(rp,ap,al,*(bp++)); 172 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
91 rp++; 173 * r[10] holds (a[0]*b[0])
92 for (i=1; i<bl; i++) 174 * r[32] holds (b[1]*b[1])
175 */
176
177 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
178
179 if (neg) /* if t[32] is negative */
93 { 180 {
94 rp[al]=bn_mul_add_words(rp,ap,al,*(bp++)); 181 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
95 rp++; 182 }
183 else
184 {
185 /* Might have a carry */
186 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));
96 } 187 }
97 if (r->d[max-1] == 0) r->top--;
98 return(1);
99 }
100 188
101#if 0 189 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
102#include "stack.h" 190 * r[10] holds (a[0]*b[0])
191 * r[32] holds (b[1]*b[1])
192 * c1 holds the carry bits
193 */
194 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
195 if (c1)
196 {
197 p= &(r[n+n2]);
198 lo= *p;
199 ln=(lo+c1)&BN_MASK2;
200 *p=ln;
103 201
104int limit=16; 202 /* The overflow will stop before we over write
203 * words we should not overwrite */
204 if (ln < (BN_ULONG)c1)
205 {
206 do {
207 p++;
208 lo= *p;
209 ln=(lo+1)&BN_MASK2;
210 *p=ln;
211 } while (ln == 0);
212 }
213 }
214 }
105 215
106typedef struct bn_pool_st 216/* n+tn is the word length
217 * t needs to be n*4 is size, as does r */
218void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
219 int n, BN_ULONG *t)
107 { 220 {
108 int used; 221 int i,j,n2=n*2;
109 int tos; 222 unsigned int c1;
110 STACK *sk; 223 BN_ULONG ln,lo,*p;
111 } BN_POOL;
112 224
113BIGNUM *BN_POOL_push(bp) 225#ifdef BN_COUNT
114BN_POOL *bp; 226printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
115 { 227#endif
116 BIGNUM *ret; 228 if (n < 8)
229 {
230 i=tn+n;
231 bn_mul_normal(r,a,i,b,i);
232 return;
233 }
234
235 /* r=(a[0]-a[1])*(b[1]-b[0]) */
236 bn_sub_words(t, a, &(a[n]),n); /* + */
237 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
117 238
118 if (bp->used >= bp->tos) 239/* if (n == 4)
240 {
241 bn_mul_comba4(&(t[n2]),t,&(t[n]));
242 bn_mul_comba4(r,a,b);
243 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
244 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
245 }
246 else */ if (n == 8)
119 { 247 {
120 ret=BN_new(); 248 bn_mul_comba8(&(t[n2]),t,&(t[n]));
121 sk_push(bp->sk,(char *)ret); 249 bn_mul_comba8(r,a,b);
122 bp->tos++; 250 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
123 bp->used++; 251 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
124 } 252 }
125 else 253 else
126 { 254 {
127 ret=(BIGNUM *)sk_value(bp->sk,bp->used); 255 p= &(t[n2*2]);
128 bp->used++; 256 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
257 bn_mul_recursive(r,a,b,n,p);
258 i=n/2;
259 /* If there is only a bottom half to the number,
260 * just do it */
261 j=tn-i;
262 if (j == 0)
263 {
264 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);
265 memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));
266 }
267 else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */
268 {
269 bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),
270 j,i,p);
271 memset(&(r[n2+tn*2]),0,
272 sizeof(BN_ULONG)*(n2-tn*2));
273 }
274 else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */
275 {
276 memset(&(r[n2]),0,sizeof(BN_ULONG)*n2);
277 if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)
278 {
279 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
280 }
281 else
282 {
283 for (;;)
284 {
285 i/=2;
286 if (i < tn)
287 {
288 bn_mul_part_recursive(&(r[n2]),
289 &(a[n]),&(b[n]),
290 tn-i,i,p);
291 break;
292 }
293 else if (i == tn)
294 {
295 bn_mul_recursive(&(r[n2]),
296 &(a[n]),&(b[n]),
297 i,p);
298 break;
299 }
300 }
301 }
302 }
303 }
304
305 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
306 * r[10] holds (a[0]*b[0])
307 * r[32] holds (b[1]*b[1])
308 */
309
310 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
311 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
312
313 /* t[32] holds (a[0]-a[1])*(b[1]-b[0])+(a[0]*b[0])+(a[1]*b[1])
314 * r[10] holds (a[0]*b[0])
315 * r[32] holds (b[1]*b[1])
316 * c1 holds the carry bits
317 */
318 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
319 if (c1)
320 {
321 p= &(r[n+n2]);
322 lo= *p;
323 ln=(lo+c1)&BN_MASK2;
324 *p=ln;
325
326 /* The overflow will stop before we over write
327 * words we should not overwrite */
328 if (ln < c1)
329 {
330 do {
331 p++;
332 lo= *p;
333 ln=(lo+1)&BN_MASK2;
334 *p=ln;
335 } while (ln == 0);
336 }
129 } 337 }
130 return(ret);
131 } 338 }
132 339
133void BN_POOL_pop(bp,num) 340/* a and b must be the same size, which is n2.
134BN_POOL *bp; 341 * r needs to be n2 words and t needs to be n2*2
135int num; 342 */
343void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
344 BN_ULONG *t)
136 { 345 {
137 bp->used-=num; 346 int n=n2/2;
347
348#ifdef BN_COUNT
349printf(" bn_mul_low_recursive %d * %d\n",n2,n2);
350#endif
351
352 bn_mul_recursive(r,a,b,n,&(t[0]));
353 if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL)
354 {
355 bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2]));
356 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
357 bn_mul_low_recursive(&(t[0]),&(a[n]),&(b[0]),n,&(t[n2]));
358 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
359 }
360 else
361 {
362 bn_mul_low_normal(&(t[0]),&(a[0]),&(b[n]),n);
363 bn_mul_low_normal(&(t[n]),&(a[n]),&(b[0]),n);
364 bn_add_words(&(r[n]),&(r[n]),&(t[0]),n);
365 bn_add_words(&(r[n]),&(r[n]),&(t[n]),n);
366 }
138 } 367 }
139 368
140int BN_mul(r,a,b) 369/* a and b must be the same size, which is n2.
141BIGNUM *r,*a,*b; 370 * r needs to be n2 words and t needs to be n2*2
371 * l is the low words of the output.
372 * t needs to be n2*3
373 */
374void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
375 BN_ULONG *t)
142 { 376 {
143 static BN_POOL bp; 377 int i,n;
144 static init=1; 378 int c1,c2;
379 int neg,oneg,zero;
380 BN_ULONG ll,lc,*lp,*mp;
381
382#ifdef BN_COUNT
383printf(" bn_mul_high %d * %d\n",n2,n2);
384#endif
385 n=n2/2;
386
387 /* Calculate (al-ah)*(bh-bl) */
388 neg=zero=0;
389 c1=bn_cmp_words(&(a[0]),&(a[n]),n);
390 c2=bn_cmp_words(&(b[n]),&(b[0]),n);
391 switch (c1*3+c2)
392 {
393 case -4:
394 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
395 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
396 break;
397 case -3:
398 zero=1;
399 break;
400 case -2:
401 bn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);
402 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
403 neg=1;
404 break;
405 case -1:
406 case 0:
407 case 1:
408 zero=1;
409 break;
410 case 2:
411 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
412 bn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);
413 neg=1;
414 break;
415 case 3:
416 zero=1;
417 break;
418 case 4:
419 bn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);
420 bn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);
421 break;
422 }
423
424 oneg=neg;
425 /* t[10] = (a[0]-a[1])*(b[1]-b[0]) */
426 /* r[10] = (a[1]*b[1]) */
427#ifdef BN_MUL_COMBA
428 if (n == 8)
429 {
430 bn_mul_comba8(&(t[0]),&(r[0]),&(r[n]));
431 bn_mul_comba8(r,&(a[n]),&(b[n]));
432 }
433 else
434#endif
435 {
436 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2]));
437 bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2]));
438 }
439
440 /* s0 == low(al*bl)
441 * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl)
442 * We know s0 and s1 so the only unknown is high(al*bl)
443 * high(al*bl) == s1 - low(ah*bh+s0+(al-ah)*(bh-bl))
444 * high(al*bl) == s1 - (r[0]+l[0]+t[0])
445 */
446 if (l != NULL)
447 {
448 lp= &(t[n2+n]);
449 c1=(int)(bn_add_words(lp,&(r[0]),&(l[0]),n));
450 }
451 else
452 {
453 c1=0;
454 lp= &(r[0]);
455 }
456
457 if (neg)
458 neg=(int)(bn_sub_words(&(t[n2]),lp,&(t[0]),n));
459 else
460 {
461 bn_add_words(&(t[n2]),lp,&(t[0]),n);
462 neg=0;
463 }
464
465 if (l != NULL)
466 {
467 bn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n);
468 }
469 else
470 {
471 lp= &(t[n2+n]);
472 mp= &(t[n2]);
473 for (i=0; i<n; i++)
474 lp[i]=((~mp[i])+1)&BN_MASK2;
475 }
476
477 /* s[0] = low(al*bl)
478 * t[3] = high(al*bl)
479 * t[10] = (a[0]-a[1])*(b[1]-b[0]) neg is the sign
480 * r[10] = (a[1]*b[1])
481 */
482 /* R[10] = al*bl
483 * R[21] = al*bl + ah*bh + (a[0]-a[1])*(b[1]-b[0])
484 * R[32] = ah*bh
485 */
486 /* R[1]=t[3]+l[0]+r[0](+-)t[0] (have carry/borrow)
487 * R[2]=r[0]+t[3]+r[1](+-)t[1] (have carry/borrow)
488 * R[3]=r[1]+(carry/borrow)
489 */
490 if (l != NULL)
491 {
492 lp= &(t[n2]);
493 c1= (int)(bn_add_words(lp,&(t[n2+n]),&(l[0]),n));
494 }
495 else
496 {
497 lp= &(t[n2+n]);
498 c1=0;
499 }
500 c1+=(int)(bn_add_words(&(t[n2]),lp, &(r[0]),n));
501 if (oneg)
502 c1-=(int)(bn_sub_words(&(t[n2]),&(t[n2]),&(t[0]),n));
503 else
504 c1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),&(t[0]),n));
145 505
146 if (init) 506 c2 =(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n2+n]),n));
507 c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(r[n]),n));
508 if (oneg)
509 c2-=(int)(bn_sub_words(&(r[0]),&(r[0]),&(t[n]),n));
510 else
511 c2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n]),n));
512
513 if (c1 != 0) /* Add starting at r[0], could be +ve or -ve */
147 { 514 {
148 bp.used=0; 515 i=0;
149 bp.tos=0; 516 if (c1 > 0)
150 bp.sk=sk_new_null(); 517 {
151 init=0; 518 lc=c1;
519 do {
520 ll=(r[i]+lc)&BN_MASK2;
521 r[i++]=ll;
522 lc=(lc > ll);
523 } while (lc);
524 }
525 else
526 {
527 lc= -c1;
528 do {
529 ll=r[i];
530 r[i++]=(ll-lc)&BN_MASK2;
531 lc=(lc > ll);
532 } while (lc);
533 }
534 }
535 if (c2 != 0) /* Add starting at r[1] */
536 {
537 i=n;
538 if (c2 > 0)
539 {
540 lc=c2;
541 do {
542 ll=(r[i]+lc)&BN_MASK2;
543 r[i++]=ll;
544 lc=(lc > ll);
545 } while (lc);
546 }
547 else
548 {
549 lc= -c2;
550 do {
551 ll=r[i];
552 r[i++]=(ll-lc)&BN_MASK2;
553 lc=(lc > ll);
554 } while (lc);
555 }
152 } 556 }
153 return(BN_mm(r,a,b,&bp));
154 } 557 }
558#endif
155 559
156/* r must be different to a and b */ 560int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
157int BN_mm(m, A, B, bp)
158BIGNUM *m,*A,*B;
159BN_POOL *bp;
160 { 561 {
161 int i,num; 562 int top,al,bl;
162 int an,bn; 563 BIGNUM *rr;
163 BIGNUM *a,*b,*c,*d,*ac,*bd; 564#ifdef BN_RECURSION
565 BIGNUM *t;
566 int i,j,k;
567#endif
568
569#ifdef BN_COUNT
570printf("BN_mul %d * %d\n",a->top,b->top);
571#endif
572
573 bn_check_top(a);
574 bn_check_top(b);
575 bn_check_top(r);
576
577 al=a->top;
578 bl=b->top;
579 r->neg=a->neg^b->neg;
580
581 if ((al == 0) || (bl == 0))
582 {
583 BN_zero(r);
584 return(1);
585 }
586 top=al+bl;
164 587
165 an=A->top; 588 if ((r == a) || (r == b))
166 bn=B->top; 589 rr= &(ctx->bn[ctx->tos+1]);
167 if ((an <= limit) || (bn <= limit)) 590 else
591 rr=r;
592
593#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
594 if (al == bl)
168 { 595 {
169 return(BN_mmul(m,A,B)); 596# ifdef BN_MUL_COMBA
597/* if (al == 4)
598 {
599 if (bn_wexpand(rr,8) == NULL) return(0);
600 rr->top=8;
601 bn_mul_comba4(rr->d,a->d,b->d);
602 goto end;
603 }
604 else */ if (al == 8)
605 {
606 if (bn_wexpand(rr,16) == NULL) return(0);
607 rr->top=16;
608 bn_mul_comba8(rr->d,a->d,b->d);
609 goto end;
610 }
611 else
612# endif
613#ifdef BN_RECURSION
614 if (al < BN_MULL_SIZE_NORMAL)
615#endif
616 {
617 if (bn_wexpand(rr,top) == NULL) return(0);
618 rr->top=top;
619 bn_mul_normal(rr->d,a->d,al,b->d,bl);
620 goto end;
621 }
622# ifdef BN_RECURSION
623 goto symetric;
624# endif
170 } 625 }
626#endif
627#ifdef BN_RECURSION
628 else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))
629 {
630 if (bn_wexpand(rr,top) == NULL) return(0);
631 rr->top=top;
632 bn_mul_normal(rr->d,a->d,al,b->d,bl);
633 goto end;
634 }
635 else
636 {
637 i=(al-bl);
638 if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))
639 {
640 bn_wexpand(b,al);
641 b->d[bl]=0;
642 bl++;
643 goto symetric;
644 }
645 else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))
646 {
647 bn_wexpand(a,bl);
648 a->d[al]=0;
649 al++;
650 goto symetric;
651 }
652 }
653#endif
171 654
172 a=BN_POOL_push(bp); 655 /* asymetric and >= 4 */
173 b=BN_POOL_push(bp); 656 if (bn_wexpand(rr,top) == NULL) return(0);
174 c=BN_POOL_push(bp); 657 rr->top=top;
175 d=BN_POOL_push(bp); 658 bn_mul_normal(rr->d,a->d,al,b->d,bl);
176 ac=BN_POOL_push(bp);
177 bd=BN_POOL_push(bp);
178 659
179 num=(an <= bn)?an:bn; 660#ifdef BN_RECURSION
180 num=1<<(BN_num_bits_word(num-1)-1); 661 if (0)
662 {
663symetric:
664 /* symetric and > 4 */
665 /* 16 or larger */
666 j=BN_num_bits_word((BN_ULONG)al);
667 j=1<<(j-1);
668 k=j+j;
669 t= &(ctx->bn[ctx->tos]);
670 if (al == j) /* exact multiple */
671 {
672 bn_wexpand(t,k*2);
673 bn_wexpand(rr,k*2);
674 bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
675 }
676 else
677 {
678 bn_wexpand(a,k);
679 bn_wexpand(b,k);
680 bn_wexpand(t,k*4);
681 bn_wexpand(rr,k*4);
682 for (i=a->top; i<k; i++)
683 a->d[i]=0;
684 for (i=b->top; i<k; i++)
685 b->d[i]=0;
686 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
687 }
688 rr->top=top;
689 }
690#endif
691#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
692end:
693#endif
694 bn_fix_top(rr);
695 if (r != rr) BN_copy(r,rr);
696 return(1);
697 }
181 698
182 /* Are going to now chop things into 'num' word chunks. */ 699void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
183 num*=BN_BITS2; 700 {
701 BN_ULONG *rr;
184 702
185 BN_copy(a,A); 703#ifdef BN_COUNT
186 BN_mask_bits(a,num); 704printf(" bn_mul_normal %d * %d\n",na,nb);
187 BN_rshift(b,A,num); 705#endif
188 706
189 BN_copy(c,B); 707 if (na < nb)
190 BN_mask_bits(c,num); 708 {
191 BN_rshift(d,B,num); 709 int itmp;
710 BN_ULONG *ltmp;
192 711
193 BN_sub(ac ,b,a); 712 itmp=na; na=nb; nb=itmp;
194 BN_sub(bd,c,d); 713 ltmp=a; a=b; b=ltmp;
195 BN_mm(m,ac,bd,bp);
196 BN_mm(ac,a,c,bp);
197 BN_mm(bd,b,d,bp);
198 714
199 BN_add(m,m,ac); 715 }
200 BN_add(m,m,bd); 716 rr= &(r[na]);
201 BN_lshift(m,m,num); 717 rr[0]=bn_mul_words(r,a,na,b[0]);
202 BN_lshift(bd,bd,num*2);
203 718
204 BN_add(m,m,ac); 719 for (;;)
205 BN_add(m,m,bd); 720 {
206 BN_POOL_pop(bp,6); 721 if (--nb <= 0) return;
207 return(1); 722 rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);
723 if (--nb <= 0) return;
724 rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);
725 if (--nb <= 0) return;
726 rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);
727 if (--nb <= 0) return;
728 rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);
729 rr+=4;
730 r+=4;
731 b+=4;
732 }
208 } 733 }
734
735void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
736 {
737#ifdef BN_COUNT
738printf(" bn_mul_low_normal %d * %d\n",n,n);
209#endif 739#endif
740 bn_mul_words(r,a,n,b[0]);
741
742 for (;;)
743 {
744 if (--n <= 0) return;
745 bn_mul_add_words(&(r[1]),a,n,b[1]);
746 if (--n <= 0) return;
747 bn_mul_add_words(&(r[2]),a,n,b[2]);
748 if (--n <= 0) return;
749 bn_mul_add_words(&(r[3]),a,n,b[3]);
750 if (--n <= 0) return;
751 bn_mul_add_words(&(r[4]),a,n,b[4]);
752 r+=4;
753 b+=4;
754 }
755 }
756
diff --git a/src/lib/libcrypto/bn/bn_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 @@
1/* crypto/bn/bn_mulw.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "bn_lcl.h"
62
63#ifdef BN_LLONG
64
65BN_ULONG bn_mul_add_words(rp,ap,num,w)
66BN_ULONG *rp,*ap;
67int num;
68BN_ULONG w;
69 {
70 BN_ULONG c1=0;
71
72 for (;;)
73 {
74 mul_add(rp[0],ap[0],w,c1);
75 if (--num == 0) break;
76 mul_add(rp[1],ap[1],w,c1);
77 if (--num == 0) break;
78 mul_add(rp[2],ap[2],w,c1);
79 if (--num == 0) break;
80 mul_add(rp[3],ap[3],w,c1);
81 if (--num == 0) break;
82 ap+=4;
83 rp+=4;
84 }
85
86 return(c1);
87 }
88
89BN_ULONG bn_mul_words(rp,ap,num,w)
90BN_ULONG *rp,*ap;
91int num;
92BN_ULONG w;
93 {
94 BN_ULONG c1=0;
95
96 for (;;)
97 {
98 mul(rp[0],ap[0],w,c1);
99 if (--num == 0) break;
100 mul(rp[1],ap[1],w,c1);
101 if (--num == 0) break;
102 mul(rp[2],ap[2],w,c1);
103 if (--num == 0) break;
104 mul(rp[3],ap[3],w,c1);
105 if (--num == 0) break;
106 ap+=4;
107 rp+=4;
108 }
109 return(c1);
110 }
111
112void bn_sqr_words(r,a,n)
113BN_ULONG *r,*a;
114int n;
115 {
116 for (;;)
117 {
118 BN_ULLONG t;
119
120 t=(BN_ULLONG)(a[0])*(a[0]);
121 r[0]=Lw(t); r[1]=Hw(t);
122 if (--n == 0) break;
123
124 t=(BN_ULLONG)(a[1])*(a[1]);
125 r[2]=Lw(t); r[3]=Hw(t);
126 if (--n == 0) break;
127
128 t=(BN_ULLONG)(a[2])*(a[2]);
129 r[4]=Lw(t); r[5]=Hw(t);
130 if (--n == 0) break;
131
132 t=(BN_ULLONG)(a[3])*(a[3]);
133 r[6]=Lw(t); r[7]=Hw(t);
134 if (--n == 0) break;
135
136 a+=4;
137 r+=8;
138 }
139 }
140
141BN_ULONG bn_add_words(r,a,b,n)
142BN_ULONG *r,*a,*b;
143int n;
144 {
145 BN_ULLONG ll;
146
147 ll=0;
148 for (;;)
149 {
150 ll+= (BN_ULLONG)a[0]+b[0];
151 r[0]=(BN_ULONG)ll&BN_MASK2;
152 ll>>=BN_BITS2;
153 if (--n <= 0) break;
154
155 ll+= (BN_ULLONG)a[1]+b[1];
156 r[1]=(BN_ULONG)ll&BN_MASK2;
157 ll>>=BN_BITS2;
158 if (--n <= 0) break;
159
160 ll+= (BN_ULLONG)a[2]+b[2];
161 r[2]=(BN_ULONG)ll&BN_MASK2;
162 ll>>=BN_BITS2;
163 if (--n <= 0) break;
164
165 ll+= (BN_ULLONG)a[3]+b[3];
166 r[3]=(BN_ULONG)ll&BN_MASK2;
167 ll>>=BN_BITS2;
168 if (--n <= 0) break;
169
170 a+=4;
171 b+=4;
172 r+=4;
173 }
174 return(ll&BN_MASK2);
175 }
176
177#else
178
179BN_ULONG bn_mul_add_words(rp,ap,num,w)
180BN_ULONG *rp,*ap;
181int num;
182BN_ULONG w;
183 {
184 BN_ULONG c=0;
185 BN_ULONG bl,bh;
186
187 bl=LBITS(w);
188 bh=HBITS(w);
189
190 for (;;)
191 {
192 mul_add(rp[0],ap[0],bl,bh,c);
193 if (--num == 0) break;
194 mul_add(rp[1],ap[1],bl,bh,c);
195 if (--num == 0) break;
196 mul_add(rp[2],ap[2],bl,bh,c);
197 if (--num == 0) break;
198 mul_add(rp[3],ap[3],bl,bh,c);
199 if (--num == 0) break;
200 ap+=4;
201 rp+=4;
202 }
203 return(c);
204 }
205
206BN_ULONG bn_mul_words(rp,ap,num,w)
207BN_ULONG *rp,*ap;
208int num;
209BN_ULONG w;
210 {
211 BN_ULONG carry=0;
212 BN_ULONG bl,bh;
213
214 bl=LBITS(w);
215 bh=HBITS(w);
216
217 for (;;)
218 {
219 mul(rp[0],ap[0],bl,bh,carry);
220 if (--num == 0) break;
221 mul(rp[1],ap[1],bl,bh,carry);
222 if (--num == 0) break;
223 mul(rp[2],ap[2],bl,bh,carry);
224 if (--num == 0) break;
225 mul(rp[3],ap[3],bl,bh,carry);
226 if (--num == 0) break;
227 ap+=4;
228 rp+=4;
229 }
230 return(carry);
231 }
232
233void bn_sqr_words(r,a,n)
234BN_ULONG *r,*a;
235int n;
236 {
237 for (;;)
238 {
239 sqr64(r[0],r[1],a[0]);
240 if (--n == 0) break;
241
242 sqr64(r[2],r[3],a[1]);
243 if (--n == 0) break;
244
245 sqr64(r[4],r[5],a[2]);
246 if (--n == 0) break;
247
248 sqr64(r[6],r[7],a[3]);
249 if (--n == 0) break;
250
251 a+=4;
252 r+=8;
253 }
254 }
255
256BN_ULONG bn_add_words(r,a,b,n)
257BN_ULONG *r,*a,*b;
258int n;
259 {
260 BN_ULONG t1,t2;
261 int carry,i;
262
263 carry=0;
264 for (i=0; i<n; i++)
265 {
266 t1= *(a++);
267 t2= *(b++);
268 if (carry)
269 {
270 carry=(t2 >= ((~t1)&BN_MASK2));
271 t2=(t1+t2+1)&BN_MASK2;
272 }
273 else
274 {
275 t2=(t1+t2)&BN_MASK2;
276 carry=(t2<t1);
277 }
278 *(r++)=t2;
279 }
280 return(carry);
281 }
282
283#endif
284
285#if defined(BN_LLONG) && defined(BN_DIV2W)
286
287BN_ULONG bn_div64(h,l,d)
288BN_ULONG h,l,d;
289 {
290 return((BN_ULONG)(((((BN_ULLONG)h)<<BN_BITS2)|l)/(BN_ULLONG)d));
291 }
292
293#else
294
295/* Divide h-l by d and return the result. */
296/* I need to test this some more :-( */
297BN_ULONG bn_div64(h,l,d)
298BN_ULONG h,l,d;
299 {
300 BN_ULONG dh,dl,q,ret=0,th,tl,t;
301 int i,count=2;
302
303 if (d == 0) return(BN_MASK2);
304
305 i=BN_num_bits_word(d);
306 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i))
307 {
308#if !defined(NO_STDIO) && !defined(WIN16)
309 fprintf(stderr,"Division would overflow (%d)\n",i);
310#endif
311 abort();
312 }
313 i=BN_BITS2-i;
314 if (h >= d) h-=d;
315
316 if (i)
317 {
318 d<<=i;
319 h=(h<<i)|(l>>(BN_BITS2-i));
320 l<<=i;
321 }
322 dh=(d&BN_MASK2h)>>BN_BITS4;
323 dl=(d&BN_MASK2l);
324 for (;;)
325 {
326 if ((h>>BN_BITS4) == dh)
327 q=BN_MASK2l;
328 else
329 q=h/dh;
330
331 for (;;)
332 {
333 t=(h-q*dh);
334 if ((t&BN_MASK2h) ||
335 ((dl*q) <= (
336 (t<<BN_BITS4)+
337 ((l&BN_MASK2h)>>BN_BITS4))))
338 break;
339 q--;
340 }
341 th=q*dh;
342 tl=q*dl;
343 t=(tl>>BN_BITS4);
344 tl=(tl<<BN_BITS4)&BN_MASK2h;
345 th+=t;
346
347 if (l < tl) th++;
348 l-=tl;
349 if (h < th)
350 {
351 h+=d;
352 q--;
353 }
354 h-=th;
355
356 if (--count == 0) break;
357
358 ret=q<<BN_BITS4;
359 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
360 l=(l&BN_MASK2l)<<BN_BITS4;
361 }
362 ret|=q;
363 return(ret);
364 }
365#endif
366
diff --git a/src/lib/libcrypto/bn/bn_opts.c b/src/lib/libcrypto/bn/bn_opts.c
new file mode 100644
index 0000000000..381be529b2
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn_opts.c
@@ -0,0 +1,324 @@
1/* crypto/bn/expspeed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* most of this code has been pilfered from my libdes speed.c program */
60
61#include <stdio.h>
62#include <stdlib.h>
63#include <signal.h>
64#include <string.h>
65#include <openssl/crypto.h>
66#include <openssl/tmdiff.h>
67#include <openssl/bn.h>
68#include <openssl/err.h>
69
70#define DEFAULT_SIZE 512
71#define DEFAULT_TIME 3
72
73int verbose=1;
74
75typedef struct parms_st
76 {
77 char *name;
78 void (*func)();
79 BIGNUM r;
80 BIGNUM a;
81 BIGNUM b;
82 BIGNUM c;
83 BIGNUM low;
84 BN_CTX *ctx;
85 BN_MONT_CTX *mont;
86 int w;
87 } PARMS;
88
89void do_mul_exp(int num,PARMS *p);
90void do_mul(int num,PARMS *p);
91void do_sqr(int num,PARMS *p);
92void do_mul_low(int num,PARMS *p);
93void do_mul_high(int num,PARMS *p);
94void do_from_montgomery(int num,PARMS *p);
95int time_it(int sec, PARMS *p);
96void do_it(int sec, PARMS *p);
97
98#define P_EXP 1
99#define P_MUL 2
100#define P_SQR 3
101#define P_MULL 4
102#define P_MULH 5
103#define P_MRED 6
104
105int main(int argc, char **argv)
106 {
107 PARMS p;
108 BN_MONT_CTX *mont;
109 int size=0,num;
110 char *name;
111 int type=P_EXP;
112
113 mont=BN_MONT_CTX_new();
114 p.mont=NULL;
115 p.ctx=BN_CTX_new();
116 BN_init(&p.r);
117 BN_init(&p.a);
118 BN_init(&p.b);
119 BN_init(&p.c);
120 BN_init(&p.low);
121 p.w=0;
122
123 for (;;)
124 {
125 if (argc > 1)
126 {
127 if (argv[1][0] == '-')
128 {
129 switch(argv[1][1])
130 {
131 case 'e': type=P_EXP; break;
132 case 'm': type=P_MUL; break;
133 case 's': type=P_SQR; break;
134 case 'l': type=P_MULL; break;
135 case 'h': type=P_MULH; break;
136 case 'r': type=P_MRED; break;
137 default:
138 fprintf(stderr,"options: -[emslhr]\n");
139 exit(1);
140 }
141 }
142 else
143 {
144 size=atoi(argv[1]);
145 }
146 argc--;
147 argv++;
148 }
149 else
150 break;
151 }
152 if (size == 0)
153 size=DEFAULT_SIZE;
154
155 printf("bit size:%5d\n",size);
156
157 BN_rand(&p.a,size,1,0);
158 BN_rand(&p.b,size,1,0);
159 BN_rand(&p.c,size,1,1);
160 BN_mod(&p.a,&p.a,&p.c,p.ctx);
161 BN_mod(&p.b,&p.b,&p.c,p.ctx);
162 p.w=(p.a.top+1)/2;
163
164 BN_mul(&p.low,&p.a,&p.b,p.ctx);
165 p.low.top=p.a.top;
166
167 switch(type)
168 {
169 case P_EXP:
170 p.name="r=a^b%c";
171 p.func=do_mul_exp;
172 p.mont=mont;
173 break;
174 case P_MUL:
175 p.name="r=a*b";
176 p.func=do_mul;
177 break;
178 case P_SQR:
179 p.name="r=a*a";
180 p.func=do_sqr;
181 break;
182 case P_MULL:
183 p.name="r=low(a*b)";
184 p.func=do_mul_low;
185 break;
186 case P_MULH:
187 p.name="r=high(a*b)";
188 p.func=do_mul_high;
189 break;
190 case P_MRED:
191 p.name="r=montgomery_reduction(a)";
192 p.func=do_from_montgomery;
193 p.mont=mont;
194 break;
195 default:
196 fprintf(stderr,"options: -[emslhr]\n");
197 exit(1);
198 }
199
200 num=time_it(DEFAULT_TIME,&p);
201 do_it(num,&p);
202 }
203
204void do_it(int num, PARMS *p)
205 {
206 char *start,*end;
207 int i,j,number;
208 double d;
209
210 start=ms_time_new();
211 end=ms_time_new();
212
213 number=BN_num_bits_word((BN_ULONG)BN_num_bits(&(p->c)))-
214 BN_num_bits_word(BN_BITS2)+2;
215 for (i=number-1; i >=0; i--)
216 {
217 if (i == 1) continue;
218 BN_set_params(i,i,i,1);
219 if (p->mont != NULL)
220 BN_MONT_CTX_set(p->mont,&(p->c),p->ctx);
221
222 printf("Timing %5d (%2d bit) %2d %2d %2d %2d :",
223 (1<<i)*BN_BITS2,i,
224 BN_get_params(0),
225 BN_get_params(1),
226 BN_get_params(2),
227 BN_get_params(3));
228 fflush(stdout);
229
230 ms_time_get(start);
231 p->func(num,p);
232 ms_time_get(end);
233 d=ms_time_diff(start,end);
234 printf("%6.6f sec, or %d in %.4f seconds\n",
235 (double)d/num,num,d);
236 }
237 }
238
239int time_it(int sec, PARMS *p)
240 {
241 char *start,*end;
242 int i,j;
243 double d;
244
245 if (p->mont != NULL)
246 BN_MONT_CTX_set(p->mont,&(p->c),p->ctx);
247
248 start=ms_time_new();
249 end=ms_time_new();
250
251 i=1;
252 for (;;)
253 {
254 if (verbose)
255 printf("timing %s for %d interations\n",p->name,i);
256
257 ms_time_get(start);
258 p->func(i,p);
259 ms_time_get(end);
260 d=ms_time_diff(start,end);
261
262 if (d < 0.01) i*=100;
263 else if (d < 0.1 ) i*=10;
264 else if (d > (double)sec) break;
265 else
266 {
267 i=(int)(1.0*i*sec/d);
268 break;
269 }
270 }
271 if (verbose)
272 printf("using %d interations\n",i);
273 return(i);
274 }
275
276void do_mul_exp(int num, PARMS *p)
277 {
278 int i;
279
280 for (i=0; i<num; i++)
281 BN_mod_exp_mont(&(p->r),&(p->a),&(p->b),&(p->c),
282 p->ctx,p->mont);
283 }
284
285void do_mul(int num, PARMS *p)
286 {
287 int i;
288
289 for (i=0; i<num; i++)
290 BN_mul(&(p->r),&(p->a),&(p->b),p->ctx);
291 }
292
293void do_sqr(int num, PARMS *p)
294 {
295 int i;
296
297 for (i=0; i<num; i++)
298 BN_sqr(&(p->r),&(p->a),p->ctx);
299 }
300
301void do_mul_low(int num, PARMS *p)
302 {
303 int i;
304
305 for (i=0; i<num; i++)
306 BN_mul_low(&(p->r),&(p->a),&(p->b),p->w,p->ctx);
307 }
308
309void do_mul_high(int num, PARMS *p)
310 {
311 int i;
312
313 for (i=0; i<num; i++)
314 BN_mul_low(&(p->r),&(p->a),&(p->b),&(p->low),p->w,p->ctx);
315 }
316
317void do_from_montgomery(int num, PARMS *p)
318 {
319 int i;
320
321 for (i=0; i<num; i++)
322 BN_from_montgomery(&(p->r),&(p->a),p->mont,p->ctx);
323 }
324
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
index 0c85f70b59..6fa0f9be1e 100644
--- a/src/lib/libcrypto/bn/bn_prime.c
+++ b/src/lib/libcrypto/bn/bn_prime.c
@@ -60,7 +60,7 @@
60#include <time.h> 60#include <time.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bn_lcl.h" 62#include "bn_lcl.h"
63#include "rand.h" 63#include <openssl/rand.h>
64 64
65/* The quick seive algorithm approach to weeding out primes is 65/* The quick seive algorithm approach to weeding out primes is
66 * Philip Zimmermann's, as implemented in PGP. I have had a read of 66 * Philip Zimmermann's, as implemented in PGP. I have had a read of
@@ -68,7 +68,6 @@
68 */ 68 */
69#include "bn_prime.h" 69#include "bn_prime.h"
70 70
71#ifndef NOPROTO
72static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx,BN_CTX *ctx2, 71static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx,BN_CTX *ctx2,
73 BN_MONT_CTX *mont); 72 BN_MONT_CTX *mont);
74static int probable_prime(BIGNUM *rnd, int bits); 73static int probable_prime(BIGNUM *rnd, int bits);
@@ -76,32 +75,23 @@ static int probable_prime_dh(BIGNUM *rnd, int bits,
76 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); 75 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
77static int probable_prime_dh_strong(BIGNUM *rnd, int bits, 76static int probable_prime_dh_strong(BIGNUM *rnd, int bits,
78 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx); 77 BIGNUM *add, BIGNUM *rem, BN_CTX *ctx);
79#else 78BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int strong, BIGNUM *add,
80static int witness(); 79 BIGNUM *rem, void (*callback)(int,int,void *), void *cb_arg)
81static int probable_prime();
82static int probable_prime_dh();
83static int probable_prime_dh_strong();
84#endif
85
86BIGNUM *BN_generate_prime(bits,strong,add,rem,callback,cb_arg)
87int bits;
88int strong;
89BIGNUM *add;
90BIGNUM *rem;
91void (*callback)(P_I_I_P);
92char *cb_arg;
93 { 80 {
94 BIGNUM *rnd=NULL; 81 BIGNUM *rnd=NULL;
95 BIGNUM *ret=NULL; 82 BIGNUM t;
96 BIGNUM *t=NULL;
97 int i,j,c1=0; 83 int i,j,c1=0;
98 BN_CTX *ctx; 84 BN_CTX *ctx;
99 85
100 ctx=BN_CTX_new(); 86 ctx=BN_CTX_new();
101 if (ctx == NULL) goto err; 87 if (ctx == NULL) goto err;
102 if ((rnd=BN_new()) == NULL) goto err; 88 if (ret == NULL)
103 if (strong) 89 {
104 if ((t=BN_new()) == NULL) goto err; 90 if ((rnd=BN_new()) == NULL) goto err;
91 }
92 else
93 rnd=ret;
94 BN_init(&t);
105loop: 95loop:
106 /* make a random number and set the top and bottom bits */ 96 /* make a random number and set the top and bottom bits */
107 if (add == NULL) 97 if (add == NULL)
@@ -136,7 +126,7 @@ loop:
136 * check that (p-1)/2 is prime. 126 * check that (p-1)/2 is prime.
137 * Since a prime is odd, We just 127 * Since a prime is odd, We just
138 * need to divide by 2 */ 128 * need to divide by 2 */
139 if (!BN_rshift1(t,rnd)) goto err; 129 if (!BN_rshift1(&t,rnd)) goto err;
140 130
141 for (i=0; i<BN_prime_checks; i++) 131 for (i=0; i<BN_prime_checks; i++)
142 { 132 {
@@ -144,7 +134,7 @@ loop:
144 if (j == -1) goto err; 134 if (j == -1) goto err;
145 if (j == 0) goto loop; 135 if (j == 0) goto loop;
146 136
147 j=BN_is_prime(t,1,callback,ctx,cb_arg); 137 j=BN_is_prime(&t,1,callback,ctx,cb_arg);
148 if (j == -1) goto err; 138 if (j == -1) goto err;
149 if (j == 0) goto loop; 139 if (j == 0) goto loop;
150 140
@@ -156,17 +146,13 @@ loop:
156 ret=rnd; 146 ret=rnd;
157err: 147err:
158 if ((ret == NULL) && (rnd != NULL)) BN_free(rnd); 148 if ((ret == NULL) && (rnd != NULL)) BN_free(rnd);
159 if (t != NULL) BN_free(t); 149 BN_free(&t);
160 if (ctx != NULL) BN_CTX_free(ctx); 150 if (ctx != NULL) BN_CTX_free(ctx);
161 return(ret); 151 return(ret);
162 } 152 }
163 153
164int BN_is_prime(a,checks,callback,ctx_passed,cb_arg) 154int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,void *),
165BIGNUM *a; 155 BN_CTX *ctx_passed, void *cb_arg)
166int checks;
167void (*callback)(P_I_I_P);
168BN_CTX *ctx_passed;
169char *cb_arg;
170 { 156 {
171 int i,j,c2=0,ret= -1; 157 int i,j,c2=0,ret= -1;
172 BIGNUM *check; 158 BIGNUM *check;
@@ -183,7 +169,7 @@ char *cb_arg;
183 if ((ctx2=BN_CTX_new()) == NULL) goto err; 169 if ((ctx2=BN_CTX_new()) == NULL) goto err;
184 if ((mont=BN_MONT_CTX_new()) == NULL) goto err; 170 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
185 171
186 check=ctx->bn[ctx->tos++]; 172 check= &(ctx->bn[ctx->tos++]);
187 173
188 /* Setup the montgomery structure */ 174 /* Setup the montgomery structure */
189 if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err; 175 if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;
@@ -214,24 +200,21 @@ err:
214 200
215#define RECP_MUL_MOD 201#define RECP_MUL_MOD
216 202
217static int witness(a,n,ctx,ctx2,mont) 203static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2,
218BIGNUM *a; 204 BN_MONT_CTX *mont)
219BIGNUM *n;
220BN_CTX *ctx,*ctx2;
221BN_MONT_CTX *mont;
222 { 205 {
223 int k,i,ret= -1,good; 206 int k,i,ret= -1,good;
224 BIGNUM *d,*dd,*tmp,*d1,*d2,*n1; 207 BIGNUM *d,*dd,*tmp,*d1,*d2,*n1;
225 BIGNUM *mont_one,*mont_n1,*mont_a; 208 BIGNUM *mont_one,*mont_n1,*mont_a;
226 209
227 d1=ctx->bn[ctx->tos]; 210 d1= &(ctx->bn[ctx->tos]);
228 d2=ctx->bn[ctx->tos+1]; 211 d2= &(ctx->bn[ctx->tos+1]);
229 n1=ctx->bn[ctx->tos+2]; 212 n1= &(ctx->bn[ctx->tos+2]);
230 ctx->tos+=3; 213 ctx->tos+=3;
231 214
232 mont_one=ctx2->bn[ctx2->tos]; 215 mont_one= &(ctx2->bn[ctx2->tos]);
233 mont_n1=ctx2->bn[ctx2->tos+1]; 216 mont_n1= &(ctx2->bn[ctx2->tos+1]);
234 mont_a=ctx2->bn[ctx2->tos+2]; 217 mont_a= &(ctx2->bn[ctx2->tos+2]);
235 ctx2->tos+=3; 218 ctx2->tos+=3;
236 219
237 d=d1; 220 d=d1;
@@ -254,7 +237,7 @@ BN_MONT_CTX *mont;
254 good=0; 237 good=0;
255 238
256 BN_mod_mul_montgomery(dd,d,d,mont,ctx2); 239 BN_mod_mul_montgomery(dd,d,d,mont,ctx2);
257 240
258 if (good && (BN_cmp(dd,mont_one) == 0)) 241 if (good && (BN_cmp(dd,mont_one) == 0))
259 { 242 {
260 ret=1; 243 ret=1;
@@ -281,14 +264,13 @@ err:
281 return(ret); 264 return(ret);
282 } 265 }
283 266
284static int probable_prime(rnd, bits) 267static int probable_prime(BIGNUM *rnd, int bits)
285BIGNUM *rnd;
286int bits;
287 { 268 {
288 int i; 269 int i;
289 MS_STATIC BN_ULONG mods[NUMPRIMES]; 270 MS_STATIC BN_ULONG mods[NUMPRIMES];
290 BN_ULONG delta; 271 BN_ULONG delta,d;
291 272
273again:
292 if (!BN_rand(rnd,bits,1,1)) return(0); 274 if (!BN_rand(rnd,bits,1,1)) return(0);
293 /* we now have a random number 'rand' to test. */ 275 /* we now have a random number 'rand' to test. */
294 for (i=1; i<NUMPRIMES; i++) 276 for (i=1; i<NUMPRIMES; i++)
@@ -300,9 +282,12 @@ int bits;
300 * that gcd(rnd-1,primes) == 1 (except for 2) */ 282 * that gcd(rnd-1,primes) == 1 (except for 2) */
301 if (((mods[i]+delta)%primes[i]) <= 1) 283 if (((mods[i]+delta)%primes[i]) <= 1)
302 { 284 {
285 d=delta;
303 delta+=2; 286 delta+=2;
304 /* perhaps need to check for overflow of 287 /* perhaps need to check for overflow of
305 * delta (but delta can be upto 2^32) */ 288 * delta (but delta can be upto 2^32)
289 * 21-May-98 eay - added overflow check */
290 if (delta < d) goto again;
306 goto loop; 291 goto loop;
307 } 292 }
308 } 293 }
@@ -310,17 +295,13 @@ int bits;
310 return(1); 295 return(1);
311 } 296 }
312 297
313static int probable_prime_dh(rnd, bits, add, rem,ctx) 298static int probable_prime_dh(BIGNUM *rnd, int bits, BIGNUM *add, BIGNUM *rem,
314BIGNUM *rnd; 299 BN_CTX *ctx)
315int bits;
316BIGNUM *add;
317BIGNUM *rem;
318BN_CTX *ctx;
319 { 300 {
320 int i,ret=0; 301 int i,ret=0;
321 BIGNUM *t1; 302 BIGNUM *t1;
322 303
323 t1=ctx->bn[ctx->tos++]; 304 t1= &(ctx->bn[ctx->tos++]);
324 305
325 if (!BN_rand(rnd,bits,0,1)) goto err; 306 if (!BN_rand(rnd,bits,0,1)) goto err;
326 307
@@ -338,7 +319,7 @@ BN_CTX *ctx;
338 loop: for (i=1; i<NUMPRIMES; i++) 319 loop: for (i=1; i<NUMPRIMES; i++)
339 { 320 {
340 /* check that rnd is a prime */ 321 /* check that rnd is a prime */
341 if (BN_mod_word(rnd,(BN_LONG)primes[i]) <= 1) 322 if (BN_mod_word(rnd,(BN_ULONG)primes[i]) <= 1)
342 { 323 {
343 if (!BN_add(rnd,rnd,add)) goto err; 324 if (!BN_add(rnd,rnd,add)) goto err;
344 goto loop; 325 goto loop;
@@ -350,20 +331,16 @@ err:
350 return(ret); 331 return(ret);
351 } 332 }
352 333
353static int probable_prime_dh_strong(p, bits, padd, rem,ctx) 334static int probable_prime_dh_strong(BIGNUM *p, int bits, BIGNUM *padd,
354BIGNUM *p; 335 BIGNUM *rem, BN_CTX *ctx)
355int bits;
356BIGNUM *padd;
357BIGNUM *rem;
358BN_CTX *ctx;
359 { 336 {
360 int i,ret=0; 337 int i,ret=0;
361 BIGNUM *t1,*qadd=NULL,*q=NULL; 338 BIGNUM *t1,*qadd=NULL,*q=NULL;
362 339
363 bits--; 340 bits--;
364 t1=ctx->bn[ctx->tos++]; 341 t1= &(ctx->bn[ctx->tos++]);
365 q=ctx->bn[ctx->tos++]; 342 q= &(ctx->bn[ctx->tos++]);
366 qadd=ctx->bn[ctx->tos++]; 343 qadd= &(ctx->bn[ctx->tos++]);
367 344
368 if (!BN_rshift1(qadd,padd)) goto err; 345 if (!BN_rshift1(qadd,padd)) goto err;
369 346
@@ -389,8 +366,8 @@ BN_CTX *ctx;
389 /* check that p and q are prime */ 366 /* check that p and q are prime */
390 /* check that for p and q 367 /* check that for p and q
391 * gcd(p-1,primes) == 1 (except for 2) */ 368 * gcd(p-1,primes) == 1 (except for 2) */
392 if ( (BN_mod_word(p,(BN_LONG)primes[i]) == 0) || 369 if ( (BN_mod_word(p,(BN_ULONG)primes[i]) == 0) ||
393 (BN_mod_word(q,(BN_LONG)primes[i]) == 0)) 370 (BN_mod_word(q,(BN_ULONG)primes[i]) == 0))
394 { 371 {
395 if (!BN_add(p,p,padd)) goto err; 372 if (!BN_add(p,p,padd)) goto err;
396 if (!BN_add(q,q,qadd)) goto err; 373 if (!BN_add(q,q,qadd)) goto err;
@@ -404,20 +381,17 @@ err:
404 } 381 }
405 382
406#if 0 383#if 0
407static int witness(a, n,ctx) 384static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx)
408BIGNUM *a;
409BIGNUM *n;
410BN_CTX *ctx;
411 { 385 {
412 int k,i,nb,ret= -1; 386 int k,i,nb,ret= -1;
413 BIGNUM *d,*dd,*tmp; 387 BIGNUM *d,*dd,*tmp;
414 BIGNUM *d1,*d2,*x,*n1,*inv; 388 BIGNUM *d1,*d2,*x,*n1,*inv;
415 389
416 d1=ctx->bn[ctx->tos]; 390 d1= &(ctx->bn[ctx->tos]);
417 d2=ctx->bn[ctx->tos+1]; 391 d2= &(ctx->bn[ctx->tos+1]);
418 x=ctx->bn[ctx->tos+2]; 392 x= &(ctx->bn[ctx->tos+2]);
419 n1=ctx->bn[ctx->tos+3]; 393 n1= &(ctx->bn[ctx->tos+3]);
420 inv=ctx->bn[ctx->tos+4]; 394 inv=&(ctx->bn[ctx->tos+4]);
421 ctx->tos+=5; 395 ctx->tos+=5;
422 396
423 d=d1; 397 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# bn_prime.pl 2# bn_prime.pl
3 3
4$num=2048; 4$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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <ctype.h> 60#include <ctype.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "buffer.h" 62#include <openssl/buffer.h>
63#include "bn_lcl.h" 63#include "bn_lcl.h"
64 64
65static char *Hex="0123456789ABCDEF"; 65static const char *Hex="0123456789ABCDEF";
66 66
67/* Must 'Free' the returned data */ 67/* Must 'Free' the returned data */
68char *BN_bn2hex(a) 68char *BN_bn2hex(const BIGNUM *a)
69BIGNUM *a;
70 { 69 {
71 int i,j,v,z=0; 70 int i,j,v,z=0;
72 char *buf; 71 char *buf;
@@ -101,8 +100,7 @@ err:
101 } 100 }
102 101
103/* Must 'Free' the returned data */ 102/* Must 'Free' the returned data */
104char *BN_bn2dec(a) 103char *BN_bn2dec(const BIGNUM *a)
105BIGNUM *a;
106 { 104 {
107 int i=0,num; 105 int i=0,num;
108 char *buf=NULL; 106 char *buf=NULL;
@@ -156,9 +154,7 @@ err:
156 return(buf); 154 return(buf);
157 } 155 }
158 156
159int BN_hex2bn(bn,a) 157int BN_hex2bn(BIGNUM **bn, const char *a)
160BIGNUM **bn;
161char *a;
162 { 158 {
163 BIGNUM *ret=NULL; 159 BIGNUM *ret=NULL;
164 BN_ULONG l=0; 160 BN_ULONG l=0;
@@ -169,7 +165,7 @@ char *a;
169 165
170 if (*a == '-') { neg=1; a++; } 166 if (*a == '-') { neg=1; a++; }
171 167
172 for (i=0; isxdigit(a[i]); i++) 168 for (i=0; isxdigit((unsigned char) a[i]); i++)
173 ; 169 ;
174 170
175 num=i+neg; 171 num=i+neg;
@@ -224,9 +220,7 @@ err:
224 return(0); 220 return(0);
225 } 221 }
226 222
227int BN_dec2bn(bn,a) 223int BN_dec2bn(BIGNUM **bn, const char *a)
228BIGNUM **bn;
229char *a;
230 { 224 {
231 BIGNUM *ret=NULL; 225 BIGNUM *ret=NULL;
232 BN_ULONG l=0; 226 BN_ULONG l=0;
@@ -236,7 +230,7 @@ char *a;
236 if ((a == NULL) || (*a == '\0')) return(0); 230 if ((a == NULL) || (*a == '\0')) return(0);
237 if (*a == '-') { neg=1; a++; } 231 if (*a == '-') { neg=1; a++; }
238 232
239 for (i=0; isdigit(a[i]); i++) 233 for (i=0; isdigit((unsigned char) a[i]); i++)
240 ; 234 ;
241 235
242 num=i+neg; 236 num=i+neg;
@@ -286,9 +280,7 @@ err:
286#ifndef NO_BIO 280#ifndef NO_BIO
287 281
288#ifndef NO_FP_API 282#ifndef NO_FP_API
289int BN_print_fp(fp, a) 283int BN_print_fp(FILE *fp, BIGNUM *a)
290FILE *fp;
291BIGNUM *a;
292 { 284 {
293 BIO *b; 285 BIO *b;
294 int ret; 286 int ret;
@@ -302,9 +294,7 @@ BIGNUM *a;
302 } 294 }
303#endif 295#endif
304 296
305int BN_print(bp, a) 297int BN_print(BIO *bp, const BIGNUM *a)
306BIO *bp;
307BIGNUM *a;
308 { 298 {
309 int i,j,v,z=0; 299 int i,j,v,z=0;
310 int ret=0; 300 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 @@
60#include <time.h> 60#include <time.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bn_lcl.h" 62#include "bn_lcl.h"
63#include "rand.h" 63#include <openssl/rand.h>
64 64
65int BN_rand(rnd, bits, top, bottom) 65int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)
66BIGNUM *rnd;
67int bits;
68int top;
69int bottom;
70 { 66 {
71 unsigned char *buf=NULL; 67 unsigned char *buf=NULL;
72 int ret=0,bit,bytes,mask; 68 int ret=0,bit,bytes,mask;
@@ -85,7 +81,7 @@ int bottom;
85 81
86 /* make a random number and set the top and bottom bits */ 82 /* make a random number and set the top and bottom bits */
87 time(&tim); 83 time(&tim);
88 RAND_seed((unsigned char *)&tim,sizeof(tim)); 84 RAND_seed(&tim,sizeof(tim));
89 85
90 RAND_bytes(buf,(int)bytes); 86 RAND_bytes(buf,(int)bytes);
91 if (top) 87 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 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63int BN_mod_mul_reciprocal(r, x, y, m, i, nb, ctx) 63void BN_RECP_CTX_init(BN_RECP_CTX *recp)
64BIGNUM *r;
65BIGNUM *x;
66BIGNUM *y;
67BIGNUM *m;
68BIGNUM *i;
69int nb;
70BN_CTX *ctx;
71 { 64 {
72 int ret=0,j; 65 BN_init(&(recp->N));
73 BIGNUM *a,*b,*c,*d; 66 BN_init(&(recp->Nr));
67 recp->num_bits=0;
68 recp->flags=0;
69 }
70
71BN_RECP_CTX *BN_RECP_CTX_new(void)
72 {
73 BN_RECP_CTX *ret;
74
75 if ((ret=(BN_RECP_CTX *)Malloc(sizeof(BN_RECP_CTX))) == NULL)
76 return(NULL);
77
78 BN_RECP_CTX_init(ret);
79 ret->flags=BN_FLG_MALLOCED;
80 return(ret);
81 }
82
83void BN_RECP_CTX_free(BN_RECP_CTX *recp)
84 {
85 if(recp == NULL)
86 return;
74 87
75 a=ctx->bn[ctx->tos++]; 88 BN_free(&(recp->N));
76 b=ctx->bn[ctx->tos++]; 89 BN_free(&(recp->Nr));
77 c=ctx->bn[ctx->tos++]; 90 if (recp->flags & BN_FLG_MALLOCED)
78 d=ctx->bn[ctx->tos++]; 91 Free(recp);
92 }
79 93
80 if (x == y) 94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
81 { if (!BN_sqr(a,x,ctx)) goto err; } 95 {
96 BN_copy(&(recp->N),d);
97 BN_zero(&(recp->Nr));
98 recp->num_bits=BN_num_bits(d);
99 recp->shift=0;
100 return(1);
101 }
102
103int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,
104 BN_CTX *ctx)
105 {
106 int ret=0;
107 BIGNUM *a;
108
109 a= &(ctx->bn[ctx->tos++]);
110 if (y != NULL)
111 {
112 if (x == y)
113 { if (!BN_sqr(a,x,ctx)) goto err; }
114 else
115 { if (!BN_mul(a,x,y,ctx)) goto err; }
116 }
82 else 117 else
83 { if (!BN_mul(a,x,y)) goto err; } 118 a=x; /* Just do the mod */
84 if (!BN_rshift(d,a,nb)) goto err; 119
85 if (!BN_mul(b,d,i)) goto err; 120 BN_div_recp(NULL,r,a,recp,ctx);
86 if (!BN_rshift(c,b,nb)) goto err; 121 ret=1;
87 if (!BN_mul(b,m,c)) goto err; 122err:
88 if (!BN_sub(r,a,b)) goto err; 123 ctx->tos--;
124 return(ret);
125 }
126
127int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,
128 BN_CTX *ctx)
129 {
130 int i,j,tos,ret=0,ex;
131 BIGNUM *a,*b,*d,*r;
132
133 tos=ctx->tos;
134 a= &(ctx->bn[ctx->tos++]);
135 b= &(ctx->bn[ctx->tos++]);
136 if (dv != NULL)
137 d=dv;
138 else
139 d= &(ctx->bn[ctx->tos++]);
140 if (rem != NULL)
141 r=rem;
142 else
143 r= &(ctx->bn[ctx->tos++]);
144
145 if (BN_ucmp(m,&(recp->N)) < 0)
146 {
147 BN_zero(d);
148 BN_copy(r,m);
149 ctx->tos=tos;
150 return(1);
151 }
152
153 /* We want the remainder
154 * Given input of ABCDEF / ab
155 * we need multiply ABCDEF by 3 digests of the reciprocal of ab
156 *
157 */
158 i=BN_num_bits(m);
159
160 j=recp->num_bits*2;
161 if (j > i)
162 {
163 i=j;
164 ex=0;
165 }
166 else
167 {
168 ex=(i-j)/2;
169 }
170
171 j=i/2;
172
173 if (i != recp->shift)
174 recp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),
175 i,ctx);
176
177 if (!BN_rshift(a,m,j-ex)) goto err;
178 if (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;
179 if (!BN_rshift(d,b,j+ex)) goto err;
180 d->neg=0;
181 if (!BN_mul(b,&(recp->N),d,ctx)) goto err;
182 if (!BN_usub(r,m,b)) goto err;
183 r->neg=0;
184
89 j=0; 185 j=0;
90 while (BN_cmp(r,m) >= 0) 186#if 1
187 while (BN_ucmp(r,&(recp->N)) >= 0)
91 { 188 {
92 if (j++ > 2) 189 if (j++ > 2)
93 { 190 {
94 BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL); 191 BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);
95 goto err; 192 goto err;
96 } 193 }
97 if (!BN_sub(r,r,m)) goto err; 194 if (!BN_usub(r,r,&(recp->N))) goto err;
195 if (!BN_add_word(d,1)) goto err;
98 } 196 }
197#endif
99 198
199 r->neg=BN_is_zero(r)?0:m->neg;
200 d->neg=m->neg^recp->N.neg;
100 ret=1; 201 ret=1;
101err: 202err:
102 ctx->tos-=4; 203 ctx->tos=tos;
103 return(ret); 204 return(ret);
104 } 205 }
105 206
106int BN_reciprocal(r, m,ctx) 207/* len is the expected size of the result
107BIGNUM *r; 208 * We actually calculate with an extra word of precision, so
108BIGNUM *m; 209 * we can do faster division if the remainder is not required.
109BN_CTX *ctx; 210 */
211int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx)
110 { 212 {
111 int nm,ret= -1; 213 int ret= -1;
112 BIGNUM *t; 214 BIGNUM t;
113 215
114 t=ctx->bn[ctx->tos++]; 216 BN_init(&t);
115 217
116 nm=BN_num_bits(m); 218 BN_zero(&t);
117 if (!BN_lshift(t,BN_value_one(),nm*2)) goto err; 219 if (!BN_set_bit(&t,len)) goto err;
118 220
119 if (!BN_div(r,NULL,t,m,ctx)) goto err; 221 if (!BN_div(r,NULL,&t,m,ctx)) goto err;
120 ret=nm; 222 ret=len;
121err: 223err:
122 ctx->tos--; 224 BN_free(&t);
123 return(ret); 225 return(ret);
124 } 226 }
125 227
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 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63int BN_lshift1(r, a) 63int BN_lshift1(BIGNUM *r, BIGNUM *a)
64BIGNUM *r;
65BIGNUM *a;
66 { 64 {
67 register BN_ULONG *ap,*rp,t,c; 65 register BN_ULONG *ap,*rp,t,c;
68 int i; 66 int i;
@@ -94,9 +92,7 @@ BIGNUM *a;
94 return(1); 92 return(1);
95 } 93 }
96 94
97int BN_rshift1(r, a) 95int BN_rshift1(BIGNUM *r, BIGNUM *a)
98BIGNUM *r;
99BIGNUM *a;
100 { 96 {
101 BN_ULONG *ap,*rp,t,c; 97 BN_ULONG *ap,*rp,t,c;
102 int i; 98 int i;
@@ -125,10 +121,7 @@ BIGNUM *a;
125 return(1); 121 return(1);
126 } 122 }
127 123
128int BN_lshift(r, a, n) 124int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
129BIGNUM *r;
130BIGNUM *a;
131int n;
132 { 125 {
133 int i,nw,lb,rb; 126 int i,nw,lb,rb;
134 BN_ULONG *t,*f; 127 BN_ULONG *t,*f;
@@ -160,10 +153,7 @@ int n;
160 return(1); 153 return(1);
161 } 154 }
162 155
163int BN_rshift(r, a, n) 156int BN_rshift(BIGNUM *r, BIGNUM *a, int n)
164BIGNUM *r;
165BIGNUM *a;
166int n;
167 { 157 {
168 int i,j,nw,lb,rb; 158 int i,j,nw,lb,rb;
169 BN_ULONG *t,*f; 159 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 @@
62 62
63/* r must not be a */ 63/* r must not be a */
64/* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */ 64/* I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96 */
65int BN_sqr(r, a, ctx) 65int BN_sqr(BIGNUM *r, BIGNUM *a, BN_CTX *ctx)
66BIGNUM *r;
67BIGNUM *a;
68BN_CTX *ctx;
69 { 66 {
70 int i,j,max,al; 67 int max,al;
71 BIGNUM *tmp; 68 BIGNUM *tmp,*rr;
72 BN_ULONG *ap,*rp;
73 69
74 tmp=ctx->bn[ctx->tos]; 70#ifdef BN_COUNT
71printf("BN_sqr %d * %d\n",a->top,a->top);
72#endif
73 bn_check_top(a);
74 tmp= &(ctx->bn[ctx->tos]);
75 rr=(a != r)?r: (&ctx->bn[ctx->tos+1]);
75 76
76 al=a->top; 77 al=a->top;
77 if (al == 0) 78 if (al <= 0)
78 { 79 {
79 r->top=0; 80 r->top=0;
80 return(1); 81 return(1);
81 } 82 }
82 83
83 max=(al*2); 84 max=(al+al);
84 if (bn_wexpand(r,1+max) == NULL) return(0); 85 if (bn_wexpand(rr,max+1) == NULL) return(0);
85 if (bn_wexpand(tmp,1+max) == NULL) return(0);
86 86
87 r->neg=0; 87 r->neg=0;
88 if (al == 4)
89 {
90#ifndef BN_SQR_COMBA
91 BN_ULONG t[8];
92 bn_sqr_normal(rr->d,a->d,4,t);
93#else
94 bn_sqr_comba4(rr->d,a->d);
95#endif
96 }
97 else if (al == 8)
98 {
99#ifndef BN_SQR_COMBA
100 BN_ULONG t[16];
101 bn_sqr_normal(rr->d,a->d,8,t);
102#else
103 bn_sqr_comba8(rr->d,a->d);
104#endif
105 }
106 else
107 {
108#if defined(BN_RECURSION)
109 if (al < BN_SQR_RECURSIVE_SIZE_NORMAL)
110 {
111 BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];
112 bn_sqr_normal(rr->d,a->d,al,t);
113 }
114 else
115 {
116 int j,k;
117
118 j=BN_num_bits_word((BN_ULONG)al);
119 j=1<<(j-1);
120 k=j+j;
121 if (al == j)
122 {
123 if (bn_wexpand(a,k*2) == NULL) return(0);
124 if (bn_wexpand(tmp,k*2) == NULL) return(0);
125 bn_sqr_recursive(rr->d,a->d,al,tmp->d);
126 }
127 else
128 {
129 if (bn_wexpand(tmp,max) == NULL) return(0);
130 bn_sqr_normal(rr->d,a->d,al,tmp->d);
131 }
132 }
133#else
134 if (bn_wexpand(tmp,max) == NULL) return(0);
135 bn_sqr_normal(rr->d,a->d,al,tmp->d);
136#endif
137 }
138
139 rr->top=max;
140 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
141 if (rr != r) BN_copy(r,rr);
142 return(1);
143 }
144
145/* tmp must have 2*n words */
146void bn_sqr_normal(BN_ULONG *r, BN_ULONG *a, int n, BN_ULONG *tmp)
147 {
148 int i,j,max;
149 BN_ULONG *ap,*rp;
88 150
89 ap=a->d; 151 max=n*2;
90 rp=r->d; 152 ap=a;
153 rp=r;
91 rp[0]=rp[max-1]=0; 154 rp[0]=rp[max-1]=0;
92 rp++; 155 rp++;
93 j=al; 156 j=n;
94 157
95 if (--j > 0) 158 if (--j > 0)
96 { 159 {
@@ -99,7 +162,7 @@ BN_CTX *ctx;
99 rp+=2; 162 rp+=2;
100 } 163 }
101 164
102 for (i=2; i<al; i++) 165 for (i=n-2; i>0; i--)
103 { 166 {
104 j--; 167 j--;
105 ap++; 168 ap++;
@@ -107,16 +170,112 @@ BN_CTX *ctx;
107 rp+=2; 170 rp+=2;
108 } 171 }
109 172
110 bn_add_words(r->d,r->d,r->d,max); 173 bn_add_words(r,r,r,max);
111 174
112 /* There will not be a carry */ 175 /* There will not be a carry */
113 176
114 bn_sqr_words(tmp->d,a->d,al); 177 bn_sqr_words(tmp,a,n);
115 178
116 bn_add_words(r->d,r->d,tmp->d,max); 179 bn_add_words(r,r,tmp,max);
117
118 r->top=max;
119 if (r->d[max-1] == 0) r->top--;
120 return(1);
121 } 180 }
122 181
182#ifdef BN_RECURSION
183/* r is 2*n words in size,
184 * a and b are both n words in size.
185 * n must be a power of 2.
186 * We multiply and return the result.
187 * t must be 2*n words in size
188 * We calulate
189 * a[0]*b[0]
190 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
191 * a[1]*b[1]
192 */
193void bn_sqr_recursive(BN_ULONG *r, BN_ULONG *a, int n2, BN_ULONG *t)
194 {
195 int n=n2/2;
196 int zero,c1;
197 BN_ULONG ln,lo,*p;
198
199#ifdef BN_COUNT
200printf(" bn_sqr_recursive %d * %d\n",n2,n2);
201#endif
202 if (n2 == 4)
203 {
204#ifndef BN_SQR_COMBA
205 bn_sqr_normal(r,a,4,t);
206#else
207 bn_sqr_comba4(r,a);
208#endif
209 return;
210 }
211 else if (n2 == 8)
212 {
213#ifndef BN_SQR_COMBA
214 bn_sqr_normal(r,a,8,t);
215#else
216 bn_sqr_comba8(r,a);
217#endif
218 return;
219 }
220 if (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL)
221 {
222 bn_sqr_normal(r,a,n2,t);
223 return;
224 }
225 /* r=(a[0]-a[1])*(a[1]-a[0]) */
226 c1=bn_cmp_words(a,&(a[n]),n);
227 zero=0;
228 if (c1 > 0)
229 bn_sub_words(t,a,&(a[n]),n);
230 else if (c1 < 0)
231 bn_sub_words(t,&(a[n]),a,n);
232 else
233 zero=1;
234
235 /* The result will always be negative unless it is zero */
236 p= &(t[n2*2]);
237
238 if (!zero)
239 bn_sqr_recursive(&(t[n2]),t,n,p);
240 else
241 memset(&(t[n2]),0,n*sizeof(BN_ULONG));
242 bn_sqr_recursive(r,a,n,p);
243 bn_sqr_recursive(&(r[n2]),&(a[n]),n,p);
244
245 /* t[32] holds (a[0]-a[1])*(a[1]-a[0]), it is negative or zero
246 * r[10] holds (a[0]*b[0])
247 * r[32] holds (b[1]*b[1])
248 */
249
250 c1=(int)(bn_add_words(t,r,&(r[n2]),n2));
251
252 /* t[32] is negative */
253 c1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));
254
255 /* t[32] holds (a[0]-a[1])*(a[1]-a[0])+(a[0]*a[0])+(a[1]*a[1])
256 * r[10] holds (a[0]*a[0])
257 * r[32] holds (a[1]*a[1])
258 * c1 holds the carry bits
259 */
260 c1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));
261 if (c1)
262 {
263 p= &(r[n+n2]);
264 lo= *p;
265 ln=(lo+c1)&BN_MASK2;
266 *p=ln;
267
268 /* The overflow will stop before we over write
269 * words we should not overwrite */
270 if (ln < (BN_ULONG)c1)
271 {
272 do {
273 p++;
274 lo= *p;
275 ln=(lo+1)&BN_MASK2;
276 *p=ln;
277 } while (ln == 0);
278 }
279 }
280 }
281#endif
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
index 4b3d0f011d..c0cfbc6797 100644
--- a/src/lib/libcrypto/bn/bn_word.c
+++ b/src/lib/libcrypto/bn/bn_word.c
@@ -60,9 +60,7 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn_lcl.h" 61#include "bn_lcl.h"
62 62
63BN_ULONG BN_mod_word(a, w) 63BN_ULONG BN_mod_word(BIGNUM *a, BN_ULONG w)
64BIGNUM *a;
65unsigned long w;
66 { 64 {
67#ifndef BN_LLONG 65#ifndef BN_LLONG
68 BN_ULONG ret=0; 66 BN_ULONG ret=0;
@@ -75,8 +73,8 @@ unsigned long w;
75 for (i=a->top-1; i>=0; i--) 73 for (i=a->top-1; i>=0; i--)
76 { 74 {
77#ifndef BN_LLONG 75#ifndef BN_LLONG
78 ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%(unsigned long)w; 76 ret=((ret<<BN_BITS4)|((a->d[i]>>BN_BITS4)&BN_MASK2l))%w;
79 ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%(unsigned long)w; 77 ret=((ret<<BN_BITS4)|(a->d[i]&BN_MASK2l))%w;
80#else 78#else
81 ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])% 79 ret=(BN_ULLONG)(((ret<<(BN_ULLONG)BN_BITS2)|a->d[i])%
82 (BN_ULLONG)w); 80 (BN_ULLONG)w);
@@ -85,9 +83,7 @@ unsigned long w;
85 return((BN_ULONG)ret); 83 return((BN_ULONG)ret);
86 } 84 }
87 85
88BN_ULONG BN_div_word(a, w) 86BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
89BIGNUM *a;
90unsigned long w;
91 { 87 {
92 BN_ULONG ret; 88 BN_ULONG ret;
93 int i; 89 int i;
@@ -100,18 +96,16 @@ unsigned long w;
100 BN_ULONG l,d; 96 BN_ULONG l,d;
101 97
102 l=a->d[i]; 98 l=a->d[i];
103 d=bn_div64(ret,l,w); 99 d=bn_div_words(ret,l,w);
104 ret=(l-((d*w)&BN_MASK2))&BN_MASK2; 100 ret=(l-((d*w)&BN_MASK2))&BN_MASK2;
105 a->d[i]=d; 101 a->d[i]=d;
106 } 102 }
107 if (a->d[a->top-1] == 0) 103 if ((a->top > 0) && (a->d[a->top-1] == 0))
108 a->top--; 104 a->top--;
109 return(ret); 105 return(ret);
110 } 106 }
111 107
112int BN_add_word(a, w) 108int BN_add_word(BIGNUM *a, BN_ULONG w)
113BIGNUM *a;
114unsigned long w;
115 { 109 {
116 BN_ULONG l; 110 BN_ULONG l;
117 int i; 111 int i;
@@ -142,9 +136,7 @@ unsigned long w;
142 return(1); 136 return(1);
143 } 137 }
144 138
145int BN_sub_word(a, w) 139int BN_sub_word(BIGNUM *a, BN_ULONG w)
146BIGNUM *a;
147unsigned long w;
148 { 140 {
149 int i; 141 int i;
150 142
@@ -183,9 +175,7 @@ unsigned long w;
183 return(1); 175 return(1);
184 } 176 }
185 177
186int BN_mul_word(a,w) 178int BN_mul_word(BIGNUM *a, BN_ULONG w)
187BIGNUM *a;
188unsigned long w;
189 { 179 {
190 BN_ULONG ll; 180 BN_ULONG ll;
191 181
@@ -199,6 +189,6 @@ unsigned long w;
199 a->d[a->top++]=ll; 189 a->d[a->top++]=ll;
200 } 190 }
201 } 191 }
202 return(0); 192 return(1);
203 } 193 }
204 194
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 @@
66#include <stdlib.h> 66#include <stdlib.h>
67#include <signal.h> 67#include <signal.h>
68#include <string.h> 68#include <string.h>
69#include "crypto.h" 69#include <openssl/crypto.h>
70#include "err.h" 70#include <openssl/err.h>
71 71
72#ifndef MSDOS 72#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
73#define TIMES 73#define TIMES
74#endif 74#endif
75 75
76#ifndef VMS
77#ifndef _IRIX 76#ifndef _IRIX
78#include <time.h> 77#include <time.h>
79#endif 78#endif
@@ -81,36 +80,33 @@
81#include <sys/types.h> 80#include <sys/types.h>
82#include <sys/times.h> 81#include <sys/times.h>
83#endif 82#endif
84#else /* VMS */ 83
85#include <types.h> 84/* Depending on the VMS version, the tms structure is perhaps defined.
86struct tms { 85 The __TMS macro will show if it was. If it wasn't defined, we should
87 time_t tms_utime; 86 undefine TIMES, since that tells the rest of the program how things
88 time_t tms_stime; 87 should be handled. -- Richard Levitte */
89 time_t tms_uchild; /* I dunno... */ 88#if defined(VMS) && defined(__DECC) && !defined(__TMS)
90 time_t tms_uchildsys; /* so these names are a guess :-) */ 89#undef TIMES
91 }
92#endif 90#endif
91
93#ifndef TIMES 92#ifndef TIMES
94#include <sys/timeb.h> 93#include <sys/timeb.h>
95#endif 94#endif
96 95
97#ifdef sun 96#if defined(sun) || defined(__ultrix)
97#define _POSIX_SOURCE
98#include <limits.h> 98#include <limits.h>
99#include <sys/param.h> 99#include <sys/param.h>
100#endif 100#endif
101 101
102#include "bn.h" 102#include <openssl/bn.h>
103#include "x509.h" 103#include <openssl/x509.h>
104 104
105/* The following if from times(3) man page. It may need to be changed */ 105/* The following if from times(3) man page. It may need to be changed */
106#ifndef HZ 106#ifndef HZ
107# ifndef CLK_TCK 107# ifndef CLK_TCK
108# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ 108# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
109# ifndef VMS 109# define HZ 100.0
110# define HZ 100.0
111# else /* VMS */
112# define HZ 100.0
113# endif
114# else /* _BSD_CLK_TCK_ */ 110# else /* _BSD_CLK_TCK_ */
115# define HZ ((double)_BSD_CLK_TCK_) 111# define HZ ((double)_BSD_CLK_TCK_)
116# endif 112# endif
@@ -123,17 +119,11 @@ struct tms {
123#define BUFSIZE ((long)1024*8) 119#define BUFSIZE ((long)1024*8)
124int run=0; 120int run=0;
125 121
126#ifndef NOPROTO
127static double Time_F(int s); 122static double Time_F(int s);
128#else
129static double Time_F();
130#endif
131
132#define START 0 123#define START 0
133#define STOP 1 124#define STOP 1
134 125
135static double Time_F(s) 126static double Time_F(int s)
136int s;
137 { 127 {
138 double ret; 128 double ret;
139#ifdef TIMES 129#ifdef TIMES
@@ -175,27 +165,20 @@ static int sizes[NUM_SIZES]={128,256,512,1024,2048};
175 165
176void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx); 166void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx);
177 167
178int main(argc,argv) 168int main(int argc, char **argv)
179int argc;
180char **argv;
181 { 169 {
182 BN_CTX *ctx; 170 BN_CTX *ctx;
183 BIGNUM *a,*b,*c,*r; 171 BIGNUM a,b,c;
184 172
185 ctx=BN_CTX_new(); 173 ctx=BN_CTX_new();
186 a=BN_new(); 174 BN_init(&a);
187 b=BN_new(); 175 BN_init(&b);
188 c=BN_new(); 176 BN_init(&c);
189 r=BN_new();
190 177
191 do_mul(a,b,c,ctx); 178 do_mul(&a,&b,&c,ctx);
192 } 179 }
193 180
194void do_mul(r,a,b,ctx) 181void do_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
195BIGNUM *r;
196BIGNUM *a;
197BIGNUM *b;
198BN_CTX *ctx;
199 { 182 {
200 int i,j,k; 183 int i,j,k;
201 double tm; 184 double tm;
@@ -211,7 +194,7 @@ BN_CTX *ctx;
211 BN_rand(b,sizes[j],1,0); 194 BN_rand(b,sizes[j],1,0);
212 Time_F(START); 195 Time_F(START);
213 for (k=0; k<num; k++) 196 for (k=0; k<num; k++)
214 BN_mul(r,b,a); 197 BN_mul(r,b,a,ctx);
215 tm=Time_F(STOP); 198 tm=Time_F(STOP);
216 printf("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num); 199 printf("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num);
217 } 200 }
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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include "e_os.h" 62
63#include "bio.h" 63#include "openssl/e_os.h"
64#include "bn.h" 64
65#include "rand.h" 65#include <openssl/bio.h>
66#include "x509.h" 66#include <openssl/bn.h>
67#include "err.h" 67#include <openssl/rand.h>
68#include <openssl/x509.h>
69#include <openssl/err.h>
68 70
69#ifdef WINDOWS 71#ifdef WINDOWS
70#include "../bio/bss_file.c" 72#include "../bio/bss_file.c"
71#endif 73#endif
72 74
73#ifndef NOPROTO 75int test_add(BIO *bp);
74int test_add (BIO *bp); 76int test_sub(BIO *bp);
75int test_sub (BIO *bp); 77int test_lshift1(BIO *bp);
76int test_lshift1 (BIO *bp); 78int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_);
77int test_lshift (BIO *bp); 79int test_rshift1(BIO *bp);
78int test_rshift1 (BIO *bp); 80int test_rshift(BIO *bp,BN_CTX *ctx);
79int test_rshift (BIO *bp); 81int test_div(BIO *bp,BN_CTX *ctx);
80int test_div (BIO *bp,BN_CTX *ctx); 82int test_div_recp(BIO *bp,BN_CTX *ctx);
81int test_mul (BIO *bp); 83int test_mul(BIO *bp);
82int test_sqr (BIO *bp,BN_CTX *ctx); 84int test_sqr(BIO *bp,BN_CTX *ctx);
83int test_mont (BIO *bp,BN_CTX *ctx); 85int test_mont(BIO *bp,BN_CTX *ctx);
84int test_mod (BIO *bp,BN_CTX *ctx); 86int test_mod(BIO *bp,BN_CTX *ctx);
85int test_mod_mul (BIO *bp,BN_CTX *ctx); 87int test_mod_mul(BIO *bp,BN_CTX *ctx);
86int test_mod_exp (BIO *bp,BN_CTX *ctx); 88int test_mod_exp(BIO *bp,BN_CTX *ctx);
89int test_exp(BIO *bp,BN_CTX *ctx);
87int rand_neg(void); 90int rand_neg(void);
88#else
89int test_add ();
90int test_sub ();
91int test_lshift1 ();
92int test_lshift ();
93int test_rshift1 ();
94int test_rshift ();
95int test_div ();
96int test_mul ();
97int test_sqr ();
98int test_mont ();
99int test_mod ();
100int test_mod_mul ();
101int test_mod_exp ();
102int rand_neg();
103#endif
104
105static int results=0; 91static int results=0;
106 92
107#ifdef NO_STDIO 93#ifdef NO_STDIO
@@ -109,16 +95,15 @@ static int results=0;
109#include "bss_file.c" 95#include "bss_file.c"
110#endif 96#endif
111 97
112int main(argc,argv) 98static unsigned char lst1[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9"
113int argc; 99"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0";
114char *argv[]; 100
101int main(int argc, char *argv[])
115 { 102 {
116 BN_CTX *ctx; 103 BN_CTX *ctx;
117 BIO *out; 104 BIO *out;
118 char *outfile=NULL; 105 char *outfile=NULL;
119 106
120 srand((unsigned int)time(NULL));
121
122 argc--; 107 argc--;
123 argv++; 108 argv++;
124 while (argc >= 1) 109 while (argc >= 1)
@@ -168,8 +153,13 @@ char *argv[];
168 if (!test_lshift1(out)) goto err; 153 if (!test_lshift1(out)) goto err;
169 fflush(stdout); 154 fflush(stdout);
170 155
156 fprintf(stderr,"test BN_lshift (fixed)\n");
157 if (!test_lshift(out,ctx,BN_bin2bn(lst1,sizeof(lst1)-1,NULL)))
158 goto err;
159 fflush(stdout);
160
171 fprintf(stderr,"test BN_lshift\n"); 161 fprintf(stderr,"test BN_lshift\n");
172 if (!test_lshift(out)) goto err; 162 if (!test_lshift(out,ctx,NULL)) goto err;
173 fflush(stdout); 163 fflush(stdout);
174 164
175 fprintf(stderr,"test BN_rshift1\n"); 165 fprintf(stderr,"test BN_rshift1\n");
@@ -177,7 +167,7 @@ char *argv[];
177 fflush(stdout); 167 fflush(stdout);
178 168
179 fprintf(stderr,"test BN_rshift\n"); 169 fprintf(stderr,"test BN_rshift\n");
180 if (!test_rshift(out)) goto err; 170 if (!test_rshift(out,ctx)) goto err;
181 fflush(stdout); 171 fflush(stdout);
182 172
183 fprintf(stderr,"test BN_sqr\n"); 173 fprintf(stderr,"test BN_sqr\n");
@@ -192,6 +182,10 @@ char *argv[];
192 if (!test_div(out,ctx)) goto err; 182 if (!test_div(out,ctx)) goto err;
193 fflush(stdout); 183 fflush(stdout);
194 184
185 fprintf(stderr,"test BN_div_recp\n");
186 if (!test_div_recp(out,ctx)) goto err;
187 fflush(stdout);
188
195 fprintf(stderr,"test BN_mod\n"); 189 fprintf(stderr,"test BN_mod\n");
196 if (!test_mod(out,ctx)) goto err; 190 if (!test_mod(out,ctx)) goto err;
197 fflush(stdout); 191 fflush(stdout);
@@ -209,298 +203,423 @@ char *argv[];
209 if (!test_mod_exp(out,ctx)) goto err; 203 if (!test_mod_exp(out,ctx)) goto err;
210 fflush(stdout); 204 fflush(stdout);
211 205
206 fprintf(stderr,"test BN_exp\n");
207 if (!test_exp(out,ctx)) goto err;
208 fflush(stdout);
209
212/**/ 210/**/
213 exit(0); 211 exit(0);
214err: 212err:
213 BIO_puts(out,"1\n"); /* make sure bc fails if we are piping to it */
215 ERR_load_crypto_strings(); 214 ERR_load_crypto_strings();
216 ERR_print_errors(out); 215 ERR_print_errors(out);
217 exit(1); 216 exit(1);
218 return(1); 217 return(1);
219 } 218 }
220 219
221int test_add(bp) 220int test_add(BIO *bp)
222BIO *bp;
223 { 221 {
224 BIGNUM *a,*b,*c; 222 BIGNUM a,b,c;
225 int i; 223 int i;
226 int j; 224 int j;
227 225
228 a=BN_new(); 226 BN_init(&a);
229 b=BN_new(); 227 BN_init(&b);
230 c=BN_new(); 228 BN_init(&c);
231 229
232 BN_rand(a,512,0,0); 230 BN_rand(&a,512,0,0);
233 for (i=0; i<100; i++) 231 for (i=0; i<100; i++)
234 { 232 {
235 BN_rand(b,450+i,0,0); 233 BN_rand(&b,450+i,0,0);
236 a->neg=rand_neg(); 234 a.neg=rand_neg();
237 b->neg=rand_neg(); 235 b.neg=rand_neg();
238 if (bp == NULL) 236 if (bp == NULL)
239 for (j=0; j<10000; j++) 237 for (j=0; j<10000; j++)
240 BN_add(c,a,b); 238 BN_add(&c,&a,&b);
241 BN_add(c,a,b); 239 BN_add(&c,&a,&b);
242 if (bp != NULL) 240 if (bp != NULL)
243 { 241 {
244 if (!results) 242 if (!results)
245 { 243 {
246 BN_print(bp,a); 244 BN_print(bp,&a);
247 BIO_puts(bp," + "); 245 BIO_puts(bp," + ");
248 BN_print(bp,b); 246 BN_print(bp,&b);
249 BIO_puts(bp," - "); 247 BIO_puts(bp," - ");
250 } 248 }
251 BN_print(bp,c); 249 BN_print(bp,&c);
252 BIO_puts(bp,"\n"); 250 BIO_puts(bp,"\n");
253 } 251 }
252 a.neg=!a.neg;
253 b.neg=!b.neg;
254 BN_add(&c,&c,&b);
255 BN_add(&c,&c,&a);
256 if(!BN_is_zero(&c))
257 {
258 BIO_puts(bp,"Add test failed!\n");
259 return 0;
260 }
254 } 261 }
255 BN_free(a); 262 BN_free(&a);
256 BN_free(b); 263 BN_free(&b);
257 BN_free(c); 264 BN_free(&c);
258 return(1); 265 return(1);
259 } 266 }
260 267
261int test_sub(bp) 268int test_sub(BIO *bp)
262BIO *bp;
263 { 269 {
264 BIGNUM *a,*b,*c; 270 BIGNUM a,b,c;
265 int i; 271 int i;
266 int j; 272 int j;
267 273
268 a=BN_new(); 274 BN_init(&a);
269 b=BN_new(); 275 BN_init(&b);
270 c=BN_new(); 276 BN_init(&c);
271 277
272 BN_rand(a,512,0,0); 278 BN_rand(&a,512,0,0);
273 for (i=0; i<100; i++) 279 for (i=0; i<100; i++)
274 { 280 {
275 BN_rand(b,400+i,0,0); 281 BN_rand(&b,400+i,0,0);
276 a->neg=rand_neg(); 282 a.neg=rand_neg();
277 b->neg=rand_neg(); 283 b.neg=rand_neg();
278 if (bp == NULL) 284 if (bp == NULL)
279 for (j=0; j<10000; j++) 285 for (j=0; j<10000; j++)
280 BN_sub(c,a,b); 286 BN_sub(&c,&a,&b);
281 BN_sub(c,a,b); 287 BN_sub(&c,&a,&b);
282 if (bp != NULL) 288 if (bp != NULL)
283 { 289 {
284 if (!results) 290 if (!results)
285 { 291 {
286 BN_print(bp,a); 292 BN_print(bp,&a);
287 BIO_puts(bp," - "); 293 BIO_puts(bp," - ");
288 BN_print(bp,b); 294 BN_print(bp,&b);
289 BIO_puts(bp," - "); 295 BIO_puts(bp," - ");
290 } 296 }
291 BN_print(bp,c); 297 BN_print(bp,&c);
292 BIO_puts(bp,"\n"); 298 BIO_puts(bp,"\n");
293 } 299 }
300 BN_add(&c,&c,&b);
301 BN_sub(&c,&c,&a);
302 if(!BN_is_zero(&c))
303 {
304 BIO_puts(bp,"Subtract test failed!\n");
305 return 0;
306 }
294 } 307 }
295 BN_free(a); 308 BN_free(&a);
296 BN_free(b); 309 BN_free(&b);
297 BN_free(c); 310 BN_free(&c);
298 return(1); 311 return(1);
299 } 312 }
300 313
301int test_div(bp,ctx) 314int test_div(BIO *bp, BN_CTX *ctx)
302BIO *bp;
303BN_CTX *ctx;
304 { 315 {
305 BIGNUM *a,*b,*c,*d; 316 BIGNUM a,b,c,d,e;
306 int i; 317 int i;
307 int j; 318 int j;
308 319
309 a=BN_new(); 320 BN_init(&a);
310 b=BN_new(); 321 BN_init(&b);
311 c=BN_new(); 322 BN_init(&c);
312 d=BN_new(); 323 BN_init(&d);
324 BN_init(&e);
313 325
314 BN_rand(a,400,0,0); 326 BN_rand(&a,400,0,0);
315 for (i=0; i<100; i++) 327 for (i=0; i<100; i++)
316 { 328 {
317 BN_rand(b,50+i,0,0); 329 BN_rand(&b,50+i,0,0);
318 a->neg=rand_neg(); 330 a.neg=rand_neg();
319 b->neg=rand_neg(); 331 b.neg=rand_neg();
320 if (bp == NULL) 332 if (bp == NULL)
321 for (j=0; j<100; j++) 333 for (j=0; j<100; j++)
322 BN_div(d,c,a,b,ctx); 334 BN_div(&d,&c,&a,&b,ctx);
323 BN_div(d,c,a,b,ctx); 335 BN_div(&d,&c,&a,&b,ctx);
324 if (bp != NULL) 336 if (bp != NULL)
325 { 337 {
326 if (!results) 338 if (!results)
327 { 339 {
328 BN_print(bp,a); 340 BN_print(bp,&a);
329 BIO_puts(bp," / "); 341 BIO_puts(bp," / ");
330 BN_print(bp,b); 342 BN_print(bp,&b);
331 BIO_puts(bp," - "); 343 BIO_puts(bp," - ");
332 } 344 }
333 BN_print(bp,d); 345 BN_print(bp,&d);
334 BIO_puts(bp,"\n"); 346 BIO_puts(bp,"\n");
335 347
336 if (!results) 348 if (!results)
337 { 349 {
338 BN_print(bp,a); 350 BN_print(bp,&a);
339 BIO_puts(bp," % "); 351 BIO_puts(bp," % ");
340 BN_print(bp,b); 352 BN_print(bp,&b);
341 BIO_puts(bp," - "); 353 BIO_puts(bp," - ");
342 } 354 }
343 BN_print(bp,c); 355 BN_print(bp,&c);
344 BIO_puts(bp,"\n"); 356 BIO_puts(bp,"\n");
345 } 357 }
358 BN_mul(&e,&d,&b,ctx);
359 BN_add(&d,&e,&c);
360 BN_sub(&d,&d,&a);
361 if(!BN_is_zero(&d))
362 {
363 BIO_puts(bp,"Division test failed!\n");
364 return 0;
365 }
346 } 366 }
347 BN_free(a); 367 BN_free(&a);
348 BN_free(b); 368 BN_free(&b);
349 BN_free(c); 369 BN_free(&c);
350 BN_free(d); 370 BN_free(&d);
371 BN_free(&e);
351 return(1); 372 return(1);
352 } 373 }
353 374
354int test_mul(bp) 375int test_div_recp(BIO *bp, BN_CTX *ctx)
355BIO *bp;
356 { 376 {
357 BIGNUM *a,*b,*c; 377 BIGNUM a,b,c,d,e;
378 BN_RECP_CTX recp;
358 int i; 379 int i;
359 int j; 380 int j;
360 381
361 a=BN_new(); 382 BN_RECP_CTX_init(&recp);
362 b=BN_new(); 383 BN_init(&a);
363 c=BN_new(); 384 BN_init(&b);
385 BN_init(&c);
386 BN_init(&d);
387 BN_init(&e);
364 388
365 BN_rand(a,200,0,0); 389 BN_rand(&a,400,0,0);
366 for (i=0; i<100; i++) 390 for (i=0; i<100; i++)
367 { 391 {
368 BN_rand(b,250+i,0,0); 392 BN_rand(&b,50+i,0,0);
369 a->neg=rand_neg(); 393 a.neg=rand_neg();
370 b->neg=rand_neg(); 394 b.neg=rand_neg();
395 BN_RECP_CTX_set(&recp,&b,ctx);
371 if (bp == NULL) 396 if (bp == NULL)
372 for (j=0; j<100; j++) 397 for (j=0; j<100; j++)
373 BN_mul(c,a,b); 398 BN_div_recp(&d,&c,&a,&recp,ctx);
374 BN_mul(c,a,b); 399 BN_div_recp(&d,&c,&a,&recp,ctx);
375 if (bp != NULL) 400 if (bp != NULL)
376 { 401 {
377 if (!results) 402 if (!results)
378 { 403 {
379 BN_print(bp,a); 404 BN_print(bp,&a);
405 BIO_puts(bp," / ");
406 BN_print(bp,&b);
407 BIO_puts(bp," - ");
408 }
409 BN_print(bp,&d);
410 BIO_puts(bp,"\n");
411
412 if (!results)
413 {
414 BN_print(bp,&a);
415 BIO_puts(bp," % ");
416 BN_print(bp,&b);
417 BIO_puts(bp," - ");
418 }
419 BN_print(bp,&c);
420 BIO_puts(bp,"\n");
421 }
422 BN_mul(&e,&d,&b,ctx);
423 BN_add(&d,&e,&c);
424 BN_sub(&d,&d,&a);
425 if(!BN_is_zero(&d))
426 {
427 BIO_puts(bp,"Reciprocal division test failed!\n");
428 return 0;
429 }
430 }
431 BN_free(&a);
432 BN_free(&b);
433 BN_free(&c);
434 BN_free(&d);
435 BN_free(&e);
436 BN_RECP_CTX_free(&recp);
437 return(1);
438 }
439
440int test_mul(BIO *bp)
441 {
442 BIGNUM a,b,c,d,e;
443 int i;
444 int j;
445 BN_CTX ctx;
446
447 BN_CTX_init(&ctx);
448 BN_init(&a);
449 BN_init(&b);
450 BN_init(&c);
451 BN_init(&d);
452 BN_init(&e);
453
454 BN_rand(&a,200,0,0);
455 for (i=0; i<100; i++)
456 {
457 BN_rand(&b,250+i,0,0);
458 BN_rand(&b,200,0,0);
459 a.neg=rand_neg();
460 b.neg=rand_neg();
461 if (bp == NULL)
462 for (j=0; j<100; j++)
463 BN_mul(&c,&a,&b,&ctx);
464 BN_mul(&c,&a,&b,&ctx);
465 if (bp != NULL)
466 {
467 if (!results)
468 {
469 BN_print(bp,&a);
380 BIO_puts(bp," * "); 470 BIO_puts(bp," * ");
381 BN_print(bp,b); 471 BN_print(bp,&b);
382 BIO_puts(bp," - "); 472 BIO_puts(bp," - ");
383 } 473 }
384 BN_print(bp,c); 474 BN_print(bp,&c);
385 BIO_puts(bp,"\n"); 475 BIO_puts(bp,"\n");
386 } 476 }
477 BN_div(&d,&e,&c,&a,&ctx);
478 BN_sub(&d,&d,&b);
479 if(!BN_is_zero(&d) || !BN_is_zero(&e))
480 {
481 BIO_puts(bp,"Multiplication test failed!\n");
482 return 0;
483 }
387 } 484 }
388 BN_free(a); 485 BN_free(&a);
389 BN_free(b); 486 BN_free(&b);
390 BN_free(c); 487 BN_free(&c);
488 BN_free(&d);
489 BN_free(&e);
490 BN_CTX_free(&ctx);
391 return(1); 491 return(1);
392 } 492 }
393 493
394int test_sqr(bp,ctx) 494int test_sqr(BIO *bp, BN_CTX *ctx)
395BIO *bp;
396BN_CTX *ctx;
397 { 495 {
398 BIGNUM *a,*c; 496 BIGNUM a,c,d,e;
399 int i; 497 int i;
400 int j; 498 int j;
401 499
402 a=BN_new(); 500 BN_init(&a);
403 c=BN_new(); 501 BN_init(&c);
502 BN_init(&d);
503 BN_init(&e);
404 504
405 for (i=0; i<40; i++) 505 for (i=0; i<40; i++)
406 { 506 {
407 BN_rand(a,40+i*10,0,0); 507 BN_rand(&a,40+i*10,0,0);
408 a->neg=rand_neg(); 508 a.neg=rand_neg();
409 if (bp == NULL) 509 if (bp == NULL)
410 for (j=0; j<100; j++) 510 for (j=0; j<100; j++)
411 BN_sqr(c,a,ctx); 511 BN_sqr(&c,&a,ctx);
412 BN_sqr(c,a,ctx); 512 BN_sqr(&c,&a,ctx);
413 if (bp != NULL) 513 if (bp != NULL)
414 { 514 {
415 if (!results) 515 if (!results)
416 { 516 {
417 BN_print(bp,a); 517 BN_print(bp,&a);
418 BIO_puts(bp," * "); 518 BIO_puts(bp," * ");
419 BN_print(bp,a); 519 BN_print(bp,&a);
420 BIO_puts(bp," - "); 520 BIO_puts(bp," - ");
421 } 521 }
422 BN_print(bp,c); 522 BN_print(bp,&c);
423 BIO_puts(bp,"\n"); 523 BIO_puts(bp,"\n");
424 } 524 }
525 BN_div(&d,&e,&c,&a,ctx);
526 BN_sub(&d,&d,&a);
527 if(!BN_is_zero(&d) || !BN_is_zero(&e))
528 {
529 BIO_puts(bp,"Square test failed!\n");
530 return 0;
531 }
425 } 532 }
426 BN_free(a); 533 BN_free(&a);
427 BN_free(c); 534 BN_free(&c);
535 BN_free(&d);
536 BN_free(&e);
428 return(1); 537 return(1);
429 } 538 }
430 539
431int test_mont(bp,ctx) 540int test_mont(BIO *bp, BN_CTX *ctx)
432BIO *bp;
433BN_CTX *ctx;
434 { 541 {
435 BIGNUM *a,*b,*c,*A,*B; 542 BIGNUM a,b,c,d,A,B;
436 BIGNUM *n; 543 BIGNUM n;
437 int i; 544 int i;
438 int j; 545 int j;
439 BN_MONT_CTX *mont; 546 BN_MONT_CTX *mont;
440 547
441 a=BN_new(); 548 BN_init(&a);
442 b=BN_new(); 549 BN_init(&b);
443 c=BN_new(); 550 BN_init(&c);
444 A=BN_new(); 551 BN_init(&d);
445 B=BN_new(); 552 BN_init(&A);
446 n=BN_new(); 553 BN_init(&B);
554 BN_init(&n);
447 555
448 mont=BN_MONT_CTX_new(); 556 mont=BN_MONT_CTX_new();
449 557
450 BN_rand(a,100,0,0); /**/ 558 BN_rand(&a,100,0,0); /**/
451 BN_rand(b,100,0,0); /**/ 559 BN_rand(&b,100,0,0); /**/
452 for (i=0; i<10; i++) 560 for (i=0; i<10; i++)
453 { 561 {
454 BN_rand(n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/ 562 BN_rand(&n,(100%BN_BITS2+1)*BN_BITS2*i*BN_BITS2,0,1); /**/
455 BN_MONT_CTX_set(mont,n,ctx); 563 BN_MONT_CTX_set(mont,&n,ctx);
456 564
457 BN_to_montgomery(A,a,mont,ctx); 565 BN_to_montgomery(&A,&a,mont,ctx);
458 BN_to_montgomery(B,b,mont,ctx); 566 BN_to_montgomery(&B,&b,mont,ctx);
459 567
460 if (bp == NULL) 568 if (bp == NULL)
461 for (j=0; j<100; j++) 569 for (j=0; j<100; j++)
462 BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/ 570 BN_mod_mul_montgomery(&c,&A,&B,mont,ctx);/**/
463 BN_mod_mul_montgomery(c,A,B,mont,ctx);/**/ 571 BN_mod_mul_montgomery(&c,&A,&B,mont,ctx);/**/
464 BN_from_montgomery(A,c,mont,ctx);/**/ 572 BN_from_montgomery(&A,&c,mont,ctx);/**/
465 if (bp != NULL) 573 if (bp != NULL)
466 { 574 {
467 if (!results) 575 if (!results)
468 { 576 {
469#ifdef undef 577#ifdef undef
470fprintf(stderr,"%d * %d %% %d\n", 578fprintf(stderr,"%d * %d %% %d\n",
471BN_num_bits(a), 579BN_num_bits(&a),
472BN_num_bits(b), 580BN_num_bits(&b),
473BN_num_bits(mont->N)); 581BN_num_bits(mont->N));
474#endif 582#endif
475 BN_print(bp,a); 583 BN_print(bp,&a);
476 BIO_puts(bp," * "); 584 BIO_puts(bp," * ");
477 BN_print(bp,b); 585 BN_print(bp,&b);
478 BIO_puts(bp," % "); 586 BIO_puts(bp," % ");
479 BN_print(bp,mont->N); 587 BN_print(bp,&(mont->N));
480 BIO_puts(bp," - "); 588 BIO_puts(bp," - ");
481 } 589 }
482 BN_print(bp,A); 590 BN_print(bp,&A);
483 BIO_puts(bp,"\n"); 591 BIO_puts(bp,"\n");
484 } 592 }
593 BN_mod_mul(&d,&a,&b,&n,ctx);
594 BN_sub(&d,&d,&A);
595 if(!BN_is_zero(&d))
596 {
597 BIO_puts(bp,"Montgomery multiplication test failed!\n");
598 return 0;
599 }
485 } 600 }
486 BN_MONT_CTX_free(mont); 601 BN_MONT_CTX_free(mont);
487 BN_free(a); 602 BN_free(&a);
488 BN_free(b); 603 BN_free(&b);
489 BN_free(c); 604 BN_free(&c);
605 BN_free(&d);
606 BN_free(&A);
607 BN_free(&B);
608 BN_free(&n);
490 return(1); 609 return(1);
491 } 610 }
492 611
493int test_mod(bp,ctx) 612int test_mod(BIO *bp, BN_CTX *ctx)
494BIO *bp;
495BN_CTX *ctx;
496 { 613 {
497 BIGNUM *a,*b,*c; 614 BIGNUM *a,*b,*c,*d,*e;
498 int i; 615 int i;
499 int j; 616 int j;
500 617
501 a=BN_new(); 618 a=BN_new();
502 b=BN_new(); 619 b=BN_new();
503 c=BN_new(); 620 c=BN_new();
621 d=BN_new();
622 e=BN_new();
504 623
505 BN_rand(a,1024,0,0); /**/ 624 BN_rand(a,1024,0,0); /**/
506 for (i=0; i<20; i++) 625 for (i=0; i<20; i++)
@@ -524,16 +643,23 @@ BN_CTX *ctx;
524 BN_print(bp,c); 643 BN_print(bp,c);
525 BIO_puts(bp,"\n"); 644 BIO_puts(bp,"\n");
526 } 645 }
646 BN_div(d,e,a,b,ctx);
647 BN_sub(e,e,c);
648 if(!BN_is_zero(e))
649 {
650 BIO_puts(bp,"Modulo test failed!\n");
651 return 0;
652 }
527 } 653 }
528 BN_free(a); 654 BN_free(a);
529 BN_free(b); 655 BN_free(b);
530 BN_free(c); 656 BN_free(c);
657 BN_free(d);
658 BN_free(e);
531 return(1); 659 return(1);
532 } 660 }
533 661
534int test_mod_mul(bp,ctx) 662int test_mod_mul(BIO *bp, BN_CTX *ctx)
535BIO *bp;
536BN_CTX *ctx;
537 { 663 {
538 BIGNUM *a,*b,*c,*d,*e; 664 BIGNUM *a,*b,*c,*d,*e;
539 int i; 665 int i;
@@ -578,6 +704,14 @@ BN_CTX *ctx;
578 BN_print(bp,e); 704 BN_print(bp,e);
579 BIO_puts(bp,"\n"); 705 BIO_puts(bp,"\n");
580 } 706 }
707 BN_mul(d,a,b,ctx);
708 BN_sub(d,d,e);
709 BN_div(a,b,d,c,ctx);
710 if(!BN_is_zero(b))
711 {
712 BIO_puts(bp,"Modulo multiply test failed!\n");
713 return 0;
714 }
581 } 715 }
582 BN_free(a); 716 BN_free(a);
583 BN_free(b); 717 BN_free(b);
@@ -587,9 +721,7 @@ BN_CTX *ctx;
587 return(1); 721 return(1);
588 } 722 }
589 723
590int test_mod_exp(bp,ctx) 724int test_mod_exp(BIO *bp, BN_CTX *ctx)
591BIO *bp;
592BN_CTX *ctx;
593 { 725 {
594 BIGNUM *a,*b,*c,*d,*e; 726 BIGNUM *a,*b,*c,*d,*e;
595 int i; 727 int i;
@@ -623,6 +755,14 @@ BN_CTX *ctx;
623 BN_print(bp,d); 755 BN_print(bp,d);
624 BIO_puts(bp,"\n"); 756 BIO_puts(bp,"\n");
625 } 757 }
758 BN_exp(e,a,b,ctx);
759 BN_sub(e,e,d);
760 BN_div(a,b,e,c,ctx);
761 if(!BN_is_zero(b))
762 {
763 BIO_puts(bp,"Modulo exponentiation test failed!\n");
764 return 0;
765 }
626 } 766 }
627 BN_free(a); 767 BN_free(a);
628 BN_free(b); 768 BN_free(b);
@@ -632,19 +772,74 @@ BN_CTX *ctx;
632 return(1); 772 return(1);
633 } 773 }
634 774
635int test_lshift(bp) 775int test_exp(BIO *bp, BN_CTX *ctx)
636BIO *bp;
637 { 776 {
638 BIGNUM *a,*b,*c; 777 BIGNUM *a,*b,*d,*e,*one;
639 int i; 778 int i;
640 779
641 a=BN_new(); 780 a=BN_new();
642 b=BN_new(); 781 b=BN_new();
782 d=BN_new();
783 e=BN_new();
784 one=BN_new();
785 BN_one(one);
786
787 for (i=0; i<6; i++)
788 {
789 BN_rand(a,20+i*5,0,0); /**/
790 BN_rand(b,2+i,0,0); /**/
791
792 if (!BN_exp(d,a,b,ctx))
793 return(00);
794
795 if (bp != NULL)
796 {
797 if (!results)
798 {
799 BN_print(bp,a);
800 BIO_puts(bp," ^ ");
801 BN_print(bp,b);
802 BIO_puts(bp," - ");
803 }
804 BN_print(bp,d);
805 BIO_puts(bp,"\n");
806 }
807 BN_one(e);
808 for( ; !BN_is_zero(b) ; BN_sub(b,b,one))
809 BN_mul(e,e,a,ctx);
810 BN_sub(e,e,d);
811 if(!BN_is_zero(e))
812 {
813 BIO_puts(bp,"Exponentiation test failed!\n");
814 return 0;
815 }
816 }
817 BN_free(a);
818 BN_free(b);
819 BN_free(d);
820 BN_free(e);
821 BN_free(one);
822 return(1);
823 }
824
825int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_)
826 {
827 BIGNUM *a,*b,*c,*d;
828 int i;
829
830 b=BN_new();
643 c=BN_new(); 831 c=BN_new();
832 d=BN_new();
644 BN_one(c); 833 BN_one(c);
645 834
646 BN_rand(a,200,0,0); /**/ 835 if(a_)
647 a->neg=rand_neg(); 836 a=a_;
837 else
838 {
839 a=BN_new();
840 BN_rand(a,200,0,0); /**/
841 a->neg=rand_neg();
842 }
648 for (i=0; i<70; i++) 843 for (i=0; i<70; i++)
649 { 844 {
650 BN_lshift(b,a,i+1); 845 BN_lshift(b,a,i+1);
@@ -661,21 +856,38 @@ BIO *bp;
661 BN_print(bp,b); 856 BN_print(bp,b);
662 BIO_puts(bp,"\n"); 857 BIO_puts(bp,"\n");
663 } 858 }
859 BN_mul(d,a,c,ctx);
860 BN_sub(d,d,b);
861 if(!BN_is_zero(d))
862 {
863 BIO_puts(bp,"Left shift test failed!\n");
864 BIO_puts(bp,"a=");
865 BN_print(bp,a);
866 BIO_puts(bp,"\nb=");
867 BN_print(bp,b);
868 BIO_puts(bp,"\nc=");
869 BN_print(bp,c);
870 BIO_puts(bp,"\nd=");
871 BN_print(bp,d);
872 BIO_puts(bp,"\n");
873 return 0;
874 }
664 } 875 }
665 BN_free(a); 876 BN_free(a);
666 BN_free(b); 877 BN_free(b);
667 BN_free(c); 878 BN_free(c);
879 BN_free(d);
668 return(1); 880 return(1);
669 } 881 }
670 882
671int test_lshift1(bp) 883int test_lshift1(BIO *bp)
672BIO *bp;
673 { 884 {
674 BIGNUM *a,*b; 885 BIGNUM *a,*b,*c;
675 int i; 886 int i;
676 887
677 a=BN_new(); 888 a=BN_new();
678 b=BN_new(); 889 b=BN_new();
890 c=BN_new();
679 891
680 BN_rand(a,200,0,0); /**/ 892 BN_rand(a,200,0,0); /**/
681 a->neg=rand_neg(); 893 a->neg=rand_neg();
@@ -693,22 +905,32 @@ BIO *bp;
693 BN_print(bp,b); 905 BN_print(bp,b);
694 BIO_puts(bp,"\n"); 906 BIO_puts(bp,"\n");
695 } 907 }
908 BN_add(c,a,a);
909 BN_sub(a,b,c);
910 if(!BN_is_zero(a))
911 {
912 BIO_puts(bp,"Left shift one test failed!\n");
913 return 0;
914 }
915
696 BN_copy(a,b); 916 BN_copy(a,b);
697 } 917 }
698 BN_free(a); 918 BN_free(a);
699 BN_free(b); 919 BN_free(b);
920 BN_free(c);
700 return(1); 921 return(1);
701 } 922 }
702 923
703int test_rshift(bp) 924int test_rshift(BIO *bp,BN_CTX *ctx)
704BIO *bp;
705 { 925 {
706 BIGNUM *a,*b,*c; 926 BIGNUM *a,*b,*c,*d,*e;
707 int i; 927 int i;
708 928
709 a=BN_new(); 929 a=BN_new();
710 b=BN_new(); 930 b=BN_new();
711 c=BN_new(); 931 c=BN_new();
932 d=BN_new();
933 e=BN_new();
712 BN_one(c); 934 BN_one(c);
713 935
714 BN_rand(a,200,0,0); /**/ 936 BN_rand(a,200,0,0); /**/
@@ -729,21 +951,30 @@ BIO *bp;
729 BN_print(bp,b); 951 BN_print(bp,b);
730 BIO_puts(bp,"\n"); 952 BIO_puts(bp,"\n");
731 } 953 }
954 BN_div(d,e,a,c,ctx);
955 BN_sub(d,d,b);
956 if(!BN_is_zero(d))
957 {
958 BIO_puts(bp,"Right shift test failed!\n");
959 return 0;
960 }
732 } 961 }
733 BN_free(a); 962 BN_free(a);
734 BN_free(b); 963 BN_free(b);
735 BN_free(c); 964 BN_free(c);
965 BN_free(d);
966 BN_free(e);
736 return(1); 967 return(1);
737 } 968 }
738 969
739int test_rshift1(bp) 970int test_rshift1(BIO *bp)
740BIO *bp;
741 { 971 {
742 BIGNUM *a,*b; 972 BIGNUM *a,*b,*c;
743 int i; 973 int i;
744 974
745 a=BN_new(); 975 a=BN_new();
746 b=BN_new(); 976 b=BN_new();
977 c=BN_new();
747 978
748 BN_rand(a,200,0,0); /**/ 979 BN_rand(a,200,0,0); /**/
749 a->neg=rand_neg(); 980 a->neg=rand_neg();
@@ -761,14 +992,22 @@ BIO *bp;
761 BN_print(bp,b); 992 BN_print(bp,b);
762 BIO_puts(bp,"\n"); 993 BIO_puts(bp,"\n");
763 } 994 }
995 BN_sub(c,a,b);
996 BN_sub(c,c,b);
997 if(!BN_is_zero(c) && !BN_is_one(c))
998 {
999 BIO_puts(bp,"Right shift one test failed!\n");
1000 return 0;
1001 }
764 BN_copy(a,b); 1002 BN_copy(a,b);
765 } 1003 }
766 BN_free(a); 1004 BN_free(a);
767 BN_free(b); 1005 BN_free(b);
1006 BN_free(c);
768 return(1); 1007 return(1);
769 } 1008 }
770 1009
771int rand_neg() 1010int rand_neg(void)
772 { 1011 {
773 static unsigned int neg=0; 1012 static unsigned int neg=0;
774 static int sign[8]={0,0,0,1,1,0,1,1}; 1013 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 @@
1#!/usr/local/bin/perl
2
3$num=8;
4$num2=8/2;
5
6print <<"EOF";
7/* crypto/bn/bn_comba.c */
8#include <stdio.h>
9#include "bn_lcl.h"
10/* Auto generated from crypto/bn/comba.pl
11 */
12
13#undef bn_mul_comba8
14#undef bn_mul_comba4
15#undef bn_sqr_comba8
16#undef bn_sqr_comba4
17
18#ifdef BN_LLONG
19#define mul_add_c(a,b,c0,c1,c2) \\
20 t=(BN_ULLONG)a*b; \\
21 t1=(BN_ULONG)Lw(t); \\
22 t2=(BN_ULONG)Hw(t); \\
23 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
24 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
25
26#define mul_add_c2(a,b,c0,c1,c2) \\
27 t=(BN_ULLONG)a*b; \\
28 tt=(t+t)&BN_MASK; \\
29 if (tt < t) c2++; \\
30 t1=(BN_ULONG)Lw(tt); \\
31 t2=(BN_ULONG)Hw(tt); \\
32 c0=(c0+t1)&BN_MASK2; \\
33 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \\
34 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
35
36#define sqr_add_c(a,i,c0,c1,c2) \\
37 t=(BN_ULLONG)a[i]*a[i]; \\
38 t1=(BN_ULONG)Lw(t); \\
39 t2=(BN_ULONG)Hw(t); \\
40 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
41 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
42
43#define sqr_add_c2(a,i,j,c0,c1,c2) \\
44 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
45#else
46#define mul_add_c(a,b,c0,c1,c2) \\
47 t1=LBITS(a); t2=HBITS(a); \\
48 bl=LBITS(b); bh=HBITS(b); \\
49 mul64(t1,t2,bl,bh); \\
50 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
51 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
52
53#define mul_add_c2(a,b,c0,c1,c2) \\
54 t1=LBITS(a); t2=HBITS(a); \\
55 bl=LBITS(b); bh=HBITS(b); \\
56 mul64(t1,t2,bl,bh); \\
57 if (t2 & BN_TBIT) c2++; \\
58 t2=(t2+t2)&BN_MASK2; \\
59 if (t1 & BN_TBIT) t2++; \\
60 t1=(t1+t1)&BN_MASK2; \\
61 c0=(c0+t1)&BN_MASK2; \\
62 if ((c0 < t1) && (((++t2)&BN_MASK2) == 0)) c2++; \\
63 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
64
65#define sqr_add_c(a,i,c0,c1,c2) \\
66 sqr64(t1,t2,(a)[i]); \\
67 c0=(c0+t1)&BN_MASK2; if ((c0) < t1) t2++; \\
68 c1=(c1+t2)&BN_MASK2; if ((c1) < t2) c2++;
69
70#define sqr_add_c2(a,i,j,c0,c1,c2) \\
71 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
72#endif
73
74void bn_mul_comba${num}(r,a,b)
75BN_ULONG *r,*a,*b;
76 {
77#ifdef BN_LLONG
78 BN_ULLONG t;
79#else
80 BN_ULONG bl,bh;
81#endif
82 BN_ULONG t1,t2;
83 BN_ULONG c1,c2,c3;
84
85EOF
86$ret=&combas_mul("r","a","b",$num,"c1","c2","c3");
87printf <<"EOF";
88 }
89
90void bn_mul_comba${num2}(r,a,b)
91BN_ULONG *r,*a,*b;
92 {
93#ifdef BN_LLONG
94 BN_ULLONG t;
95#else
96 BN_ULONG bl,bh;
97#endif
98 BN_ULONG t1,t2;
99 BN_ULONG c1,c2,c3;
100
101EOF
102$ret=&combas_mul("r","a","b",$num2,"c1","c2","c3");
103printf <<"EOF";
104 }
105
106void bn_sqr_comba${num}(r,a)
107BN_ULONG *r,*a;
108 {
109#ifdef BN_LLONG
110 BN_ULLONG t,tt;
111#else
112 BN_ULONG bl,bh;
113#endif
114 BN_ULONG t1,t2;
115 BN_ULONG c1,c2,c3;
116
117EOF
118$ret=&combas_sqr("r","a",$num,"c1","c2","c3");
119printf <<"EOF";
120 }
121
122void bn_sqr_comba${num2}(r,a)
123BN_ULONG *r,*a;
124 {
125#ifdef BN_LLONG
126 BN_ULLONG t,tt;
127#else
128 BN_ULONG bl,bh;
129#endif
130 BN_ULONG t1,t2;
131 BN_ULONG c1,c2,c3;
132
133EOF
134$ret=&combas_sqr("r","a",$num2,"c1","c2","c3");
135printf <<"EOF";
136 }
137EOF
138
139sub bn_str
140 {
141 local($var,$val)=@_;
142 print "\t$var=$val;\n";
143 }
144
145sub bn_ary
146 {
147 local($var,$idx)=@_;
148 return("${var}[$idx]");
149 }
150
151sub bn_clr
152 {
153 local($var)=@_;
154
155 print "\t$var=0;\n";
156 }
157
158sub bn_mad
159 {
160 local($a,$b,$c0,$c1,$c2,$num)=@_;
161
162 if ($num == 2)
163 { printf("\tmul_add_c2($a,$b,$c0,$c1,$c2);\n"); }
164 else
165 { printf("\tmul_add_c($a,$b,$c0,$c1,$c2);\n"); }
166 }
167
168sub bn_sad
169 {
170 local($a,$i,$j,$c0,$c1,$c2,$num)=@_;
171
172 if ($num == 2)
173 { printf("\tsqr_add_c2($a,$i,$j,$c0,$c1,$c2);\n"); }
174 else
175 { printf("\tsqr_add_c($a,$i,$c0,$c1,$c2);\n"); }
176 }
177
178sub combas_mul
179 {
180 local($r,$a,$b,$num,$c0,$c1,$c2)=@_;
181 local($i,$as,$ae,$bs,$be,$ai,$bi);
182 local($tot,$end);
183
184 $as=0;
185 $ae=0;
186 $bs=0;
187 $be=0;
188 $tot=$num+$num-1;
189 &bn_clr($c0);
190 &bn_clr($c1);
191 for ($i=0; $i<$tot; $i++)
192 {
193 $ai=$as;
194 $bi=$bs;
195 $end=$be+1;
196 @numa=@numb=();
197
198#print "($as $ae) ($bs $be) $bs -> $end [$i $num]\n";
199 for ($j=$bs; $j<$end; $j++)
200 {
201 push(@numa,$ai);
202 push(@numb,$bi);
203 $ai--;
204 $bi++;
205 }
206
207 if ($i & 1)
208 {
209 @numa=reverse(@numa);
210 @numb=reverse(@numb);
211 }
212
213 &bn_clr($c2);
214 for ($j=0; $j<=$#numa; $j++)
215 {
216 &bn_mad(&bn_ary($a,$numa[$j]),
217 &bn_ary($b,$numb[$j]),$c0,$c1,$c2,1);
218 }
219 &bn_str(&bn_ary($r,$i),$c0);
220 ($c0,$c1,$c2)=($c1,$c2,$c0);
221
222 $as++ if ($i < ($num-1));
223 $ae++ if ($i >= ($num-1));
224
225 $bs++ if ($i >= ($num-1));
226 $be++ if ($i < ($num-1));
227 }
228 &bn_str(&bn_ary($r,$i),$c0);
229 }
230
231sub combas_sqr
232 {
233 local($r,$a,$num,$c0,$c1,$c2)=@_;
234 local($i,$as,$ae,$bs,$be,$ai,$bi);
235 local($b,$tot,$end,$half);
236
237 $b=$a;
238 $as=0;
239 $ae=0;
240 $bs=0;
241 $be=0;
242 $tot=$num+$num-1;
243 &bn_clr($c0);
244 &bn_clr($c1);
245 for ($i=0; $i<$tot; $i++)
246 {
247 $ai=$as;
248 $bi=$bs;
249 $end=$be+1;
250 @numa=@numb=();
251
252#print "($as $ae) ($bs $be) $bs -> $end [$i $num]\n";
253 for ($j=$bs; $j<$end; $j++)
254 {
255 push(@numa,$ai);
256 push(@numb,$bi);
257 $ai--;
258 $bi++;
259 last if ($ai < $bi);
260 }
261 if (!($i & 1))
262 {
263 @numa=reverse(@numa);
264 @numb=reverse(@numb);
265 }
266
267 &bn_clr($c2);
268 for ($j=0; $j <= $#numa; $j++)
269 {
270 if ($numa[$j] == $numb[$j])
271 {&bn_sad($a,$numa[$j],$numb[$j],$c0,$c1,$c2,1);}
272 else
273 {&bn_sad($a,$numa[$j],$numb[$j],$c0,$c1,$c2,2);}
274 }
275 &bn_str(&bn_ary($r,$i),$c0);
276 ($c0,$c1,$c2)=($c1,$c2,$c0);
277
278 $as++ if ($i < ($num-1));
279 $ae++ if ($i >= ($num-1));
280
281 $bs++ if ($i >= ($num-1));
282 $be++ if ($i < ($num-1));
283 }
284 &bn_str(&bn_ary($r,$i),$c0);
285 }
diff --git a/src/lib/libcrypto/bn/d.c b/src/lib/libcrypto/bn/d.c
new file mode 100644
index 0000000000..ced2291b25
--- /dev/null
+++ b/src/lib/libcrypto/bn/d.c
@@ -0,0 +1,72 @@
1#include <stdio.h>
2#include <openssl/bio.h>
3#include "bn_lcl.h"
4
5#define SIZE_A (100*4+4)
6#define SIZE_B (13*4)
7
8main(argc,argv)
9int argc;
10char *argv[];
11 {
12 BN_CTX ctx;
13 BN_RECP_CTX recp;
14 BIGNUM a,b,dd,d,r,rr,t,l;
15 int i;
16
17 MemCheck_start();
18 MemCheck_on();
19 BN_CTX_init(&ctx);
20 BN_RECP_CTX_init(&recp);
21
22 BN_init(&r);
23 BN_init(&rr);
24 BN_init(&d);
25 BN_init(&dd);
26 BN_init(&a);
27 BN_init(&b);
28
29 {
30 BN_rand(&a,SIZE_A,0,0);
31 BN_rand(&b,SIZE_B,0,0);
32
33 a.neg=1;
34 BN_RECP_CTX_set(&recp,&b,&ctx);
35
36 BN_print_fp(stdout,&a); printf(" a\n");
37 BN_print_fp(stdout,&b); printf(" b\n");
38
39 BN_print_fp(stdout,&recp.N); printf(" N\n");
40 BN_print_fp(stdout,&recp.Nr); printf(" Nr num_bits=%d\n",recp.num_bits);
41
42 BN_div_recp(&r,&d,&a,&recp,&ctx);
43
44for (i=0; i<300; i++)
45 BN_div(&rr,&dd,&a,&b,&ctx);
46
47 BN_print_fp(stdout,&r); printf(" div recp\n");
48 BN_print_fp(stdout,&rr); printf(" div\n");
49 BN_print_fp(stdout,&d); printf(" rem recp\n");
50 BN_print_fp(stdout,&dd); printf(" rem\n");
51 }
52 BN_CTX_free(&ctx);
53 BN_RECP_CTX_free(&recp);
54
55 BN_free(&r);
56 BN_free(&rr);
57 BN_free(&d);
58 BN_free(&dd);
59 BN_free(&a);
60 BN_free(&b);
61
62 {
63 BIO *out;
64
65 if ((out=BIO_new(BIO_s_file())) != NULL)
66 BIO_set_fp(out,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
67
68 CRYPTO_mem_leaks(out);
69 BIO_free(out);
70 }
71
72 }
diff --git a/src/lib/libcrypto/bn/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 @@
1#include <stdio.h>
2#include <openssl/tmdiff.h>
3#include "bn_lcl.h"
4
5#define SIZE 256
6#define NUM (8*8*8)
7#define MOD (8*8*8*8*8)
8
9main(argc,argv)
10int argc;
11char *argv[];
12 {
13 BN_CTX ctx;
14 BIGNUM a,b,c,r,rr,t,l;
15 int j,i,size=SIZE,num=NUM,mod=MOD;
16 char *start,*end;
17 BN_MONT_CTX mont;
18 double d,md;
19
20 BN_MONT_CTX_init(&mont);
21 BN_CTX_init(&ctx);
22 BN_init(&a);
23 BN_init(&b);
24 BN_init(&c);
25 BN_init(&r);
26
27 start=ms_time_new();
28 end=ms_time_new();
29 while (size <= 1024*8)
30 {
31 BN_rand(&a,size,0,0);
32 BN_rand(&b,size,1,0);
33 BN_rand(&c,size,0,1);
34
35 BN_mod(&a,&a,&c,&ctx);
36
37 ms_time_get(start);
38 for (i=0; i<10; i++)
39 BN_MONT_CTX_set(&mont,&c,&ctx);
40 ms_time_get(end);
41 md=ms_time_diff(start,end);
42
43 ms_time_get(start);
44 for (i=0; i<num; i++)
45 {
46 /* bn_mull(&r,&a,&b,&ctx); */
47 /* BN_sqr(&r,&a,&ctx); */
48 BN_mod_exp_mont(&r,&a,&b,&c,&ctx,&mont);
49 }
50 ms_time_get(end);
51 d=ms_time_diff(start,end)/* *50/33 */;
52 printf("%5d bit:%6.2f %6d %6.4f %4d m_set(%5.4f)\n",size,
53 d,num,d/num,(int)((d/num)*mod),md/10.0);
54 num/=8;
55 mod/=8;
56 if (num <= 0) num=1;
57 size*=2;
58 }
59
60 }
diff --git a/src/lib/libcrypto/bn/expspeed.c b/src/lib/libcrypto/bn/expspeed.c
index 344f883d35..3656d5bb4c 100644
--- a/src/lib/libcrypto/bn/expspeed.c
+++ b/src/lib/libcrypto/bn/expspeed.c
@@ -66,14 +66,13 @@
66#include <stdlib.h> 66#include <stdlib.h>
67#include <signal.h> 67#include <signal.h>
68#include <string.h> 68#include <string.h>
69#include "crypto.h" 69#include <openssl/crypto.h>
70#include "err.h" 70#include <openssl/err.h>
71 71
72#ifndef MSDOS 72#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
73#define TIMES 73#define TIMES
74#endif 74#endif
75 75
76#ifndef VMS
77#ifndef _IRIX 76#ifndef _IRIX
78#include <time.h> 77#include <time.h>
79#endif 78#endif
@@ -81,36 +80,33 @@
81#include <sys/types.h> 80#include <sys/types.h>
82#include <sys/times.h> 81#include <sys/times.h>
83#endif 82#endif
84#else /* VMS */ 83
85#include <types.h> 84/* Depending on the VMS version, the tms structure is perhaps defined.
86struct tms { 85 The __TMS macro will show if it was. If it wasn't defined, we should
87 time_t tms_utime; 86 undefine TIMES, since that tells the rest of the program how things
88 time_t tms_stime; 87 should be handled. -- Richard Levitte */
89 time_t tms_uchild; /* I dunno... */ 88#if defined(VMS) && defined(__DECC) && !defined(__TMS)
90 time_t tms_uchildsys; /* so these names are a guess :-) */ 89#undef TIMES
91 }
92#endif 90#endif
91
93#ifndef TIMES 92#ifndef TIMES
94#include <sys/timeb.h> 93#include <sys/timeb.h>
95#endif 94#endif
96 95
97#ifdef sun 96#if defined(sun) || defined(__ultrix)
97#define _POSIX_SOURCE
98#include <limits.h> 98#include <limits.h>
99#include <sys/param.h> 99#include <sys/param.h>
100#endif 100#endif
101 101
102#include "bn.h" 102#include <openssl/bn.h>
103#include "x509.h" 103#include <openssl/x509.h>
104 104
105/* The following if from times(3) man page. It may need to be changed */ 105/* The following if from times(3) man page. It may need to be changed */
106#ifndef HZ 106#ifndef HZ
107# ifndef CLK_TCK 107# ifndef CLK_TCK
108# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ 108# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
109# ifndef VMS 109# define HZ 100.0
110# define HZ 100.0
111# else /* VMS */
112# define HZ 100.0
113# endif
114# else /* _BSD_CLK_TCK_ */ 110# else /* _BSD_CLK_TCK_ */
115# define HZ ((double)_BSD_CLK_TCK_) 111# define HZ ((double)_BSD_CLK_TCK_)
116# endif 112# endif
@@ -123,17 +119,11 @@ struct tms {
123#define BUFSIZE ((long)1024*8) 119#define BUFSIZE ((long)1024*8)
124int run=0; 120int run=0;
125 121
126#ifndef NOPROTO
127static double Time_F(int s); 122static double Time_F(int s);
128#else
129static double Time_F();
130#endif
131
132#define START 0 123#define START 0
133#define STOP 1 124#define STOP 1
134 125
135static double Time_F(s) 126static double Time_F(int s)
136int s;
137 { 127 {
138 double ret; 128 double ret;
139#ifdef TIMES 129#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};
176 166
177void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx); 167void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx);
178 168
179int main(argc,argv) 169int main(int argc, char **argv)
180int argc;
181char **argv;
182 { 170 {
183 BN_CTX *ctx; 171 BN_CTX *ctx;
184 BIGNUM *a,*b,*c,*r; 172 BIGNUM *a,*b,*c,*r;
@@ -192,12 +180,7 @@ char **argv;
192 do_mul_exp(r,a,b,c,ctx); 180 do_mul_exp(r,a,b,c,ctx);
193 } 181 }
194 182
195void do_mul_exp(r,a,b,c,ctx) 183void do_mul_exp(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx)
196BIGNUM *r;
197BIGNUM *a;
198BIGNUM *b;
199BIGNUM *c;
200BN_CTX *ctx;
201 { 184 {
202 int i,k; 185 int i,k;
203 double tm; 186 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include "bio.h" 62#include <openssl/bio.h>
63#include "bn.h" 63#include <openssl/bn.h>
64#include "rand.h" 64#include <openssl/rand.h>
65#include "err.h" 65#include <openssl/err.h>
66#ifdef WINDOWS 66#ifdef WINDOWS
67#include "../bio/bss_file.c" 67#include "../bio/bss_file.c"
68#endif 68#endif
69 69
70#define NUM_BITS (BN_BITS*2) 70#define NUM_BITS (BN_BITS*2)
71 71
72int main(argc,argv) 72int main(int argc, char *argv[])
73int argc;
74char *argv[];
75 { 73 {
76 BN_CTX *ctx; 74 BN_CTX *ctx;
77 BIO *out=NULL; 75 BIO *out=NULL;
78 int i,ret; 76 int i,ret;
79 unsigned char c; 77 unsigned char c;
80 BIGNUM *r_mont,*r_recp,*a,*b,*m; 78 BIGNUM *r_mont,*r_recp,*r_simple,*a,*b,*m;
79
80 ERR_load_BN_strings();
81 81
82 ctx=BN_CTX_new(); 82 ctx=BN_CTX_new();
83 if (ctx == NULL) exit(1); 83 if (ctx == NULL) exit(1);
84 r_mont=BN_new(); 84 r_mont=BN_new();
85 r_recp=BN_new(); 85 r_recp=BN_new();
86 r_simple=BN_new();
86 a=BN_new(); 87 a=BN_new();
87 b=BN_new(); 88 b=BN_new();
88 m=BN_new(); 89 m=BN_new();
@@ -114,29 +115,52 @@ char *argv[];
114 115
115 ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL); 116 ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL);
116 if (ret <= 0) 117 if (ret <= 0)
117 { printf("BN_mod_exp_mont() problems\n"); exit(1); } 118 {
119 printf("BN_mod_exp_mont() problems\n");
120 ERR_print_errors(out);
121 exit(1);
122 }
118 123
119 ret=BN_mod_exp_recp(r_recp,a,b,m,ctx); 124 ret=BN_mod_exp_recp(r_recp,a,b,m,ctx);
120 if (ret <= 0) 125 if (ret <= 0)
121 { printf("BN_mod_exp_recp() problems\n"); exit(1); }
122
123 if (BN_cmp(r_mont,r_recp) != 0)
124 { 126 {
125 printf("\nmont and recp results differ\n"); 127 printf("BN_mod_exp_recp() problems\n");
128 ERR_print_errors(out);
129 exit(1);
130 }
131
132 ret=BN_mod_exp_simple(r_simple,a,b,m,ctx);
133 if (ret <= 0)
134 {
135 printf("BN_mod_exp_simple() problems\n");
136 ERR_print_errors(out);
137 exit(1);
138 }
139
140 if (BN_cmp(r_simple, r_mont) == 0
141 && BN_cmp(r_simple,r_recp) == 0)
142 {
143 printf(".");
144 fflush(stdout);
145 }
146 else
147 {
148 if (BN_cmp(r_simple,r_mont) != 0)
149 printf("\nsimple and mont results differ\n");
150 if (BN_cmp(r_simple,r_recp) != 0)
151 printf("\nsimple and recp results differ\n");
152
126 printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a); 153 printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a);
127 printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b); 154 printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b);
128 printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m); 155 printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m);
156 printf("\nsimple ="); BN_print(out,r_simple);
129 printf("\nrecp ="); BN_print(out,r_recp); 157 printf("\nrecp ="); BN_print(out,r_recp);
130 printf("\nmont ="); BN_print(out,r_mont); 158 printf("\nmont ="); BN_print(out,r_mont);
131 printf("\n"); 159 printf("\n");
132 exit(1); 160 exit(1);
133 } 161 }
134 else
135 {
136 printf(".");
137 fflush(stdout);
138 }
139 } 162 }
163 CRYPTO_mem_leaks(out);
140 printf(" done\n"); 164 printf(" done\n");
141 exit(0); 165 exit(0);
142err: 166err:
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 @@
1void BN_RECP_CTX_init(BN_RECP_CTX *recp);
2BN_RECP_CTX *BN_RECP_CTX_new();
3void BN_RECP_CTX_free(BN_RECP_CTX *recp);
4int BN_RECP_CTX_set(BN_RECP_CTX *recp,BIGNUM *div,BN_CTX *ctx);
5
6int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,
7 BN_RECP_CTX *recp,BN_CTX *ctx);
8
9int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BIGNUM *d,
10 BN_RECP_CTX *recp, BN_CTX *ctx);
11int BN_mod_recp(BIGNUM *rem, BIGNUM *m, BIGNUM *d,
12 BN_RECP_CTX *recp, BN_CTX *ctx);
13int BN_mod_mul_recp(BIGNUM *ret,BIGNUM *a,BIGNUM *b,BIGNUM *m
14
15int BN_mod_exp_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *p,
16 BN_MONT_CTX *m_ctx,BN_CTX *ctx);
17int BN_mod_exp2_montgomery(BIGNUM *r, BIGNUM *a1, BIGNUM *p1,BIGNUM *a2,
18 BIGNUM *p2,BN_MONT_CTX *m_ctx,BN_CTX *ctx);
19
20
21bn_div64 -> bn_div_words
22
23
diff --git a/src/lib/libcrypto/bn/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 @@
1#include <stdio.h>
2#include "cryptlib.h"
3#include "bn_lcl.h"
4
5#define SIZE 32
6
7#define BN_MONT_CTX_set bn_mcs
8#define BN_from_montgomery bn_fm
9#define BN_mod_mul_montgomery bn_mmm
10#undef BN_to_montgomery
11#define BN_to_montgomery(r,a,mont,ctx) bn_mmm(\
12 r,a,(mont)->RR,(mont),ctx)
13
14main()
15 {
16 BIGNUM prime,a,b,r,A,B,R;
17 BN_MONT_CTX *mont;
18 BN_CTX *ctx;
19 int i;
20
21 ctx=BN_CTX_new();
22 BN_init(&prime);
23 BN_init(&a); BN_init(&b); BN_init(&r);
24 BN_init(&A); BN_init(&B); BN_init(&R);
25
26 BN_generate_prime(&prime,SIZE,0,NULL,NULL,NULL,NULL);
27 BN_rand(&A,SIZE,1,0);
28 BN_rand(&B,SIZE,1,0);
29 BN_mod(&A,&A,&prime,ctx);
30 BN_mod(&B,&B,&prime,ctx);
31
32 i=A.top;
33 BN_mul(&R,&A,&B,ctx);
34 BN_mask_bits(&R,i*BN_BITS2);
35
36
37 BN_print_fp(stdout,&A); printf(" <- a\n");
38 BN_print_fp(stdout,&B); printf(" <- b\n");
39 BN_mul_high(&r,&A,&B,&R,i);
40 BN_print_fp(stdout,&r); printf(" <- high(BA*DC)\n");
41
42 BN_mask_bits(&A,i*32);
43 BN_mask_bits(&B,i*32);
44
45 BN_mul(&R,&A,&B);
46 BN_rshift(&R,&R,i*32);
47 BN_print_fp(stdout,&R); printf(" <- norm BA*DC\n");
48 BN_sub(&R,&R,&r);
49 BN_print_fp(stdout,&R); printf(" <- diff\n");
50 }
51
52#if 0
53int bn_mul_high(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *low, int words)
54 {
55 int i;
56 BIGNUM t1,t2,t3,h,ah,al,bh,bl,m,s0,s1;
57
58 BN_init(&al); BN_init(&ah);
59 BN_init(&bl); BN_init(&bh);
60 BN_init(&t1); BN_init(&t2); BN_init(&t3);
61 BN_init(&s0); BN_init(&s1);
62 BN_init(&h); BN_init(&m);
63
64 i=a->top;
65 if (i >= words)
66 {
67 al.top=words;
68 ah.top=a->top-words;
69 ah.d= &(a->d[ah.top]);
70 }
71 else
72 al.top=i;
73 al.d=a->d;
74
75 i=b->top;
76 if (i >= words)
77 {
78 bl.top=words;
79 bh.top=i-words;
80 bh.d= &(b->d[bh.top]);
81 }
82 else
83 bl.top=i;
84 bl.d=b->d;
85
86 i=low->top;
87 if (i >= words)
88 {
89 s0.top=words;
90 s1.top=i-words;
91 s1.d= &(low->d[s1.top]);
92 }
93 else
94 s0.top=i;
95 s0.d=low->d;
96
97al.max=al.top; ah.max=ah.top;
98bl.max=bl.top; bh.max=bh.top;
99s0.max=bl.top; s1.max=bh.top;
100
101 /* Calculate (al-ah)*(bh-bl) */
102 BN_sub(&t1,&al,&ah);
103 BN_sub(&t2,&bh,&bl);
104 BN_mul(&m,&t1,&t2);
105
106 /* Calculate ah*bh */
107 BN_mul(&h,&ah,&bh);
108
109 /* s0 == low(al*bl)
110 * s1 == low(ah*bh)+low((al-ah)*(bh-bl))+low(al*bl)+high(al*bl)
111 * We know s0 and s1 so the only unknown is high(al*bl)
112 * high(al*bl) == s1 - low(ah*bh+(al-ah)*(bh-bl)+s0)
113 */
114 BN_add(&m,&m,&h);
115 BN_add(&t2,&m,&s0);
116 /* Quick and dirty mask off of high words */
117 t3.d=t2.d;
118 t3.top=(t2.top > words)?words:t2.top;
119 t3.neg=t2.neg;
120t3.max=t3.top;
121/* BN_print_fp(stdout,&s1); printf(" s1\n"); */
122/* BN_print_fp(stdout,&t2); printf(" middle value\n"); */
123/* BN_print_fp(stdout,&t3); printf(" low middle value\n"); */
124 BN_sub(&t1,&s1,&t3);
125
126 if (t1.neg)
127 {
128/*printf("neg fixup\n"); BN_print_fp(stdout,&t1); printf(" before\n"); */
129 BN_lshift(&t2,BN_value_one(),words*32);
130 BN_add(&t1,&t2,&t1);
131 BN_mask_bits(&t1,words*32);
132/* BN_print_fp(stdout,&t1); printf(" after\n"); */
133 }
134 /* al*bl == high(al*bl)<<words+s0 */
135 BN_lshift(&t1,&t1,words*32);
136 BN_add(&t1,&t1,&s0);
137
138 /* We now have
139 * al*bl - t1
140 * (al-ah)*(bh-bl)+ah*bh - m
141 * ah*bh - h
142 */
143 BN_copy(r,&t1);
144 BN_mask_bits(r,words*32*2);
145
146 /*BN_lshift(&m,&m,words*/
147
148 BN_free(&t1); BN_free(&t2);
149 BN_free(&m); BN_free(&h);
150 }
151
152int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,
153 BN_CTX *ctx)
154 {
155 BIGNUM *tmp;
156
157 tmp= &(ctx->bn[ctx->tos++]);
158
159 if (a == b)
160 {
161 if (!BN_sqr(tmp,a,ctx)) goto err;
162 }
163 else
164 {
165 if (!BN_mul(tmp,a,b)) goto err;
166 }
167 /* reduce from aRR to aR */
168 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
169 ctx->tos--;
170 return(1);
171err:
172 return(0);
173 }
174
175int BN_from_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont, BN_CTX *ctx)
176 {
177 BIGNUM z1;
178 BIGNUM *t1,*t2;
179 BN_ULONG *ap,*bp,*rp;
180 int j,i,bl,al;
181
182 BN_init(&z1);
183 t1= &(ctx->bn[ctx->tos]);
184 t2= &(ctx->bn[ctx->tos+1]);
185
186 if (!BN_copy(t1,a)) goto err;
187 /* can cheat */
188 BN_mask_bits(t1,mont->ri);
189 if (!BN_mul(t2,t1,mont->Ni)) goto err;
190 BN_mask_bits(t2,mont->ri);
191
192 if (!BN_mul(t1,t2,mont->N)) goto err;
193 if (!BN_add(t2,t1,a)) goto err;
194
195 /* At this point, t2 has the bottom ri bits set to zero.
196 * This means that the bottom ri bits == the 1^ri minus the bottom
197 * ri bits of a.
198 * This means that only the bits above 'ri' in a need to be added,
199 * and XXXXXXXXXXXXXXXXXXXXXXXX
200 */
201BN_print_fp(stdout,t2); printf("\n");
202 BN_rshift(r,t2,mont->ri);
203
204 if (BN_ucmp(r,mont->N) >= 0)
205 BN_usub(r,r,mont->N);
206
207 return(1);
208err:
209 return(0);
210 }
211
212int BN_MONT_CTX_set(BN_MONT_CTX *mont, BIGNUM *mod, BN_CTX *ctx)
213 {
214 BIGNUM *Ri=NULL,*R=NULL;
215
216 if (mont->RR == NULL) mont->RR=BN_new();
217 if (mont->N == NULL) mont->N=BN_new();
218
219 R=mont->RR; /* grab RR as a temp */
220 BN_copy(mont->N,mod); /* Set N */
221
222 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
223 BN_lshift(R,BN_value_one(),mont->ri); /* R */
224 if ((Ri=BN_mod_inverse(NULL,R,mod,ctx)) == NULL) goto err;/* Ri */
225 BN_lshift(Ri,Ri,mont->ri); /* R*Ri */
226 BN_usub(Ri,Ri,BN_value_one()); /* R*Ri - 1 */
227 BN_div(Ri,NULL,Ri,mod,ctx);
228 if (mont->Ni != NULL) BN_free(mont->Ni);
229 mont->Ni=Ri; /* Ni=(R*Ri-1)/N */
230
231 /* setup RR for conversions */
232 BN_lshift(mont->RR,BN_value_one(),mont->ri*2);
233 BN_mod(mont->RR,mont->RR,mont->N,ctx);
234
235 return(1);
236err:
237 return(0);
238 }
239
240
241#endif
diff --git a/src/lib/libcrypto/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 @@
1Cache RECP_CTX values
2make the result argument independant of the inputs.
3split 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 @@
1/* vms-helper.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57#include "cryptlib.h"
58#include "bn_lcl.h"
59
60bn_div_words_abort(int i)
61{
62#if !defined(NO_STDIO) && !defined(WIN16)
63 fprintf(stderr,"Division would overflow (%d)\n",i);
64#endif
65 abort();
66}
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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=buffer
19ERRC=buf_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= 21TEST=
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= buffer.c $(ERRC).c 25LIBSRC= buffer.c buf_err.c
26LIBOBJ= buffer.o $(ERRC).o 26LIBOBJ= buffer.o buf_err.o
27 27
28SRC= $(LIBSRC) 28SRC= $(LIBSRC)
29 29
@@ -39,24 +39,23 @@ all: lib
39 39
40lib: $(LIBOBJ) 40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
42 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
43 @touch lib 43 @touch lib
44 44
45files: 45files:
46 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
47 47
48links: 48links:
49 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
50 $(TOP)/util/point.sh Makefile.ssl Makefile; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
51 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
52 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
53 $(TOP)/util/mklink.sh ../../apps $(APPS)
54 53
55install: 54install:
56 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
57 do \ 56 do \
58 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done; 59 done;
61 60
62tags: 61tags:
@@ -68,17 +67,20 @@ lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
69 68
70depend: 69depend:
71 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
72 71
73dclean: 72dclean:
74 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
76 75
77clean: 76clean:
78 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80errors:
81 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
82 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
83 78
84# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81buf_err.o: ../../include/openssl/buffer.h ../../include/openssl/err.h
82buffer.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
83buffer.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
84buffer.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85buffer.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
86buffer.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 @@
1/* lib/buf/buf_err.c */ 1/* crypto/buffer/buf_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
57 */ 58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "buffer.h" 62#include <openssl/buffer.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -66,21 +68,26 @@ static ERR_STRING_DATA BUF_str_functs[]=
66{ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"}, 68{ERR_PACK(0,BUF_F_BUF_MEM_GROW,0), "BUF_MEM_grow"},
67{ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"}, 69{ERR_PACK(0,BUF_F_BUF_MEM_NEW,0), "BUF_MEM_new"},
68{ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"}, 70{ERR_PACK(0,BUF_F_BUF_STRDUP,0), "BUF_strdup"},
69{ERR_PACK(0,BUF_F_PXYCLNT_READ,0), "PXYCLNT_READ"}, 71{0,NULL}
70{0,NULL}, 72 };
73
74static ERR_STRING_DATA BUF_str_reasons[]=
75 {
76{0,NULL}
71 }; 77 };
72 78
73#endif 79#endif
74 80
75void ERR_load_BUF_strings() 81void ERR_load_BUF_strings(void)
76 { 82 {
77 static int init=1; 83 static int init=1;
78 84
79 if (init); 85 if (init)
80 {; 86 {
81 init=0; 87 init=0;
82#ifndef NO_ERR 88#ifndef NO_ERR
83 ERR_load_strings(ERR_LIB_BUF,BUF_str_functs); 89 ERR_load_strings(ERR_LIB_BUF,BUF_str_functs);
90 ERR_load_strings(ERR_LIB_BUF,BUF_str_reasons);
84#endif 91#endif
85 92
86 } 93 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62 62
63BUF_MEM *BUF_MEM_new() 63BUF_MEM *BUF_MEM_new(void)
64 { 64 {
65 BUF_MEM *ret; 65 BUF_MEM *ret;
66 66
67 ret=(BUF_MEM *)Malloc(sizeof(BUF_MEM)); 67 ret=Malloc(sizeof(BUF_MEM));
68 if (ret == NULL) 68 if (ret == NULL)
69 { 69 {
70 BUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE); 70 BUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE);
@@ -76,9 +76,11 @@ BUF_MEM *BUF_MEM_new()
76 return(ret); 76 return(ret);
77 } 77 }
78 78
79void BUF_MEM_free(a) 79void BUF_MEM_free(BUF_MEM *a)
80BUF_MEM *a;
81 { 80 {
81 if(a == NULL)
82 return;
83
82 if (a->data != NULL) 84 if (a->data != NULL)
83 { 85 {
84 memset(a->data,0,(unsigned int)a->max); 86 memset(a->data,0,(unsigned int)a->max);
@@ -87,9 +89,7 @@ BUF_MEM *a;
87 Free(a); 89 Free(a);
88 } 90 }
89 91
90int BUF_MEM_grow(str, len) 92int BUF_MEM_grow(BUF_MEM *str, int len)
91BUF_MEM *str;
92int len;
93 { 93 {
94 char *ret; 94 char *ret;
95 unsigned int n; 95 unsigned int n;
@@ -101,15 +101,15 @@ int len;
101 } 101 }
102 if (str->max >= len) 102 if (str->max >= len)
103 { 103 {
104 memset(&(str->data[str->length]),0,len-str->length); 104 memset(&str->data[str->length],0,len-str->length);
105 str->length=len; 105 str->length=len;
106 return(len); 106 return(len);
107 } 107 }
108 n=(len+3)/3*4; 108 n=(len+3)/3*4;
109 if (str->data == NULL) 109 if (str->data == NULL)
110 ret=(char *)Malloc(n); 110 ret=Malloc(n);
111 else 111 else
112 ret=(char *)Realloc(str->data,n); 112 ret=Realloc(str->data,n);
113 if (ret == NULL) 113 if (ret == NULL)
114 { 114 {
115 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); 115 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
@@ -124,8 +124,7 @@ int len;
124 return(len); 124 return(len);
125 } 125 }
126 126
127char *BUF_strdup(str) 127char *BUF_strdup(const char *str)
128char *str;
129 { 128 {
130 char *ret; 129 char *ret;
131 int n; 130 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 @@
1/* Error codes for the BUF functions. */
2
3/* Function codes. */
4#define BUF_F_BUF_MEM_GROW 100
5#define BUF_F_BUF_MEM_NEW 101
6#define BUF_F_BUF_STRDUP 102
7#define BUF_F_PXYCLNT_READ 103
8
9/* 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
70 int max; /* size of buffer */ 70 int max; /* size of buffer */
71 } BUF_MEM; 71 } BUF_MEM;
72 72
73#ifndef NOPROTO
74BUF_MEM *BUF_MEM_new(void); 73BUF_MEM *BUF_MEM_new(void);
75void BUF_MEM_free(BUF_MEM *a); 74void BUF_MEM_free(BUF_MEM *a);
76int BUF_MEM_grow(BUF_MEM *str, int len); 75int BUF_MEM_grow(BUF_MEM *str, int len);
77char * BUF_strdup(char *str); 76char * BUF_strdup(const char *str);
78 77
79void ERR_load_BUF_strings(void ); 78void ERR_load_BUF_strings(void );
80 79
81#else
82
83BUF_MEM *BUF_MEM_new();
84void BUF_MEM_free();
85int BUF_MEM_grow();
86char * BUF_strdup();
87
88void ERR_load_BUF_strings();
89
90#endif
91
92/* BEGIN ERROR CODES */ 80/* BEGIN ERROR CODES */
81/* The following lines are auto generated by the script mkerr.pl. Any changes
82 * made after this point may be overwritten when the script is next run.
83 */
84
93/* Error codes for the BUF functions. */ 85/* Error codes for the BUF functions. */
94 86
95/* Function codes. */ 87/* Function codes. */
96#define BUF_F_BUF_MEM_GROW 100 88#define BUF_F_BUF_MEM_GROW 100
97#define BUF_F_BUF_MEM_NEW 101 89#define BUF_F_BUF_MEM_NEW 101
98#define BUF_F_BUF_STRDUP 102 90#define BUF_F_BUF_STRDUP 102
99#define BUF_F_PXYCLNT_READ 103
100 91
101/* Reason codes. */ 92/* Reason codes. */
102 93
103#ifdef __cplusplus 94#ifdef __cplusplus
104} 95}
105#endif 96#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
8CPP= $(CC) -E 8CPP= $(CC) -E
9INCLUDES= 9INCLUDES=
10CFLAG=-g 10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
11INSTALLTOP=/usr/local/ssl 13INSTALLTOP=/usr/local/ssl
12MAKE= make -f Makefile.ssl 14MAKE= make -f Makefile.ssl
13MAKEDEPEND= makedepend -f Makefile.ssl 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
14MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
15AR= ar r 17AR= ar r
16 18
@@ -45,7 +47,7 @@ all: lib
45 47
46lib: $(LIBOBJ) 48lib: $(LIBOBJ)
47 $(AR) $(LIB) $(LIBOBJ) 49 $(AR) $(LIB) $(LIBOBJ)
48 sh $(TOP)/util/ranlib.sh $(LIB) 50 $(RANLIB) $(LIB)
49 @touch lib 51 @touch lib
50 52
51# elf 53# elf
@@ -64,26 +66,25 @@ asm/cx86-out.o: asm/cx86unix.cpp
64 66
65# bsdi 67# bsdi
66asm/cx86bsdi.o: asm/cx86unix.cpp 68asm/cx86bsdi.o: asm/cx86unix.cpp
67 $(CPP) -DBSDI asm/cx86unix.cpp | as -o asm/cx86bsdi.o 69 $(CPP) -DBSDI asm/cx86unix.cpp | sed 's/ :/:/' | as -o asm/cx86bsdi.o
68 70
69asm/cx86unix.cpp: 71asm/cx86unix.cpp: asm/cast-586.pl
70 (cd asm; perl cast-586.pl cpp >cx86unix.cpp) 72 (cd asm; $(PERL) cast-586.pl cpp $(PROCESSOR) >cx86unix.cpp)
71 73
72files: 74files:
73 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 75 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
74 76
75links: 77links:
76 /bin/rm -f Makefile 78 @$(TOP)/util/point.sh Makefile.ssl Makefile
77 $(TOP)/util/point.sh Makefile.ssl Makefile ; 79 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
78 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 80 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
79 $(TOP)/util/mklink.sh ../../test $(TEST) 81 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
80 $(TOP)/util/mklink.sh ../../apps $(APPS)
81 82
82install: 83install:
83 @for i in $(EXHEADER) ; \ 84 @for i in $(EXHEADER) ; \
84 do \ 85 do \
85 (cp $$i $(INSTALLTOP)/include/$$i; \ 86 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
86 chmod 644 $(INSTALLTOP)/include/$$i ); \ 87 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
87 done; 88 done;
88 89
89tags: 90tags:
@@ -95,15 +96,29 @@ lint:
95 lint -DLINT $(INCLUDES) $(SRC)>fluff 96 lint -DLINT $(INCLUDES) $(SRC)>fluff
96 97
97depend: 98depend:
98 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 99 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
99 100
100dclean: 101dclean:
101 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 102 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
102 mv -f Makefile.new $(MAKEFILE) 103 mv -f Makefile.new $(MAKEFILE)
103 104
104clean: 105clean:
105 /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 106 rm -f asm/cx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
106
107errors:
108 107
109# DO NOT DELETE THIS LINE -- make depend depends on it. 108# DO NOT DELETE THIS LINE -- make depend depends on it.
109
110c_cfb64.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h
111c_cfb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
112c_cfb64.o: cast_lcl.h
113c_ecb.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h
114c_ecb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
115c_ecb.o: ../../include/openssl/opensslv.h cast_lcl.h
116c_enc.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h
117c_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
118c_enc.o: cast_lcl.h
119c_ofb64.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h
120c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
121c_ofb64.o: cast_lcl.h
122c_skey.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h
123c_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
124c_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
24MAKEDEPEND= makedepend 24MAKEDEPEND= makedepend
25MAKEFILE= Makefile.uni 25MAKEFILE= Makefile.uni
26AR= ar r 26AR= ar r
27RANLIB= ranlib
27 28
28CAST_ENC=c_enc.o 29CAST_ENC=c_enc.o
29# or use 30# or use
@@ -55,7 +56,7 @@ all: $(LIB) $(TEST) $(APPS)
55 56
56$(LIB): $(LIBOBJ) 57$(LIB): $(LIBOBJ)
57 $(AR) $(LIB) $(LIBOBJ) 58 $(AR) $(LIB) $(LIBOBJ)
58 sh $(TOP)/ranlib.sh $(LIB) 59 $(RANLIB) $(LIB)
59# elf 60# elf
60asm/cx86-elf.o: asm/cx86unix.cpp 61asm/cx86-elf.o: asm/cx86unix.cpp
61 $(CPP) -DELF asm/cx86unix.cpp | as -o asm/cx86-elf.o 62 $(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
25 ; Load the 2 words 25 ; Load the 2 words
26 mov edi, DWORD PTR [ebx] 26 mov edi, DWORD PTR [ebx]
27 mov esi, DWORD PTR 4[ebx] 27 mov esi, DWORD PTR 4[ebx]
28 ; Get short key flag
29 mov eax, DWORD PTR 128[ebp]
30 push eax
28 xor eax, eax 31 xor eax, eax
29 ; round 0 32 ; round 0
30 mov edx, DWORD PTR [ebp] 33 mov edx, DWORD PTR [ebp]
@@ -278,6 +281,10 @@ _CAST_encrypt PROC NEAR
278 mov ebx, DWORD PTR _CAST_S_table3[edx*4] 281 mov ebx, DWORD PTR _CAST_S_table3[edx*4]
279 sub ecx, ebx 282 sub ecx, ebx
280 xor esi, ecx 283 xor esi, ecx
284 ; test short key flag
285 pop edx
286 or edx, edx
287 jnz $L000cast_enc_done
281 ; round 12 288 ; round 12
282 mov edx, DWORD PTR 96[ebp] 289 mov edx, DWORD PTR 96[ebp]
283 mov ecx, DWORD PTR 100[ebp] 290 mov ecx, DWORD PTR 100[ebp]
@@ -361,9 +368,10 @@ _CAST_encrypt PROC NEAR
361 sub ecx, ebx 368 sub ecx, ebx
362 mov ebx, DWORD PTR _CAST_S_table3[edx*4] 369 mov ebx, DWORD PTR _CAST_S_table3[edx*4]
363 add ecx, ebx 370 add ecx, ebx
364 mov eax, DWORD PTR 20[esp]
365 xor esi, ecx 371 xor esi, ecx
372$L000cast_enc_done:
366 nop 373 nop
374 mov eax, DWORD PTR 20[esp]
367 mov DWORD PTR 4[eax],edi 375 mov DWORD PTR 4[eax],edi
368 mov DWORD PTR [eax],esi 376 mov DWORD PTR [eax],esi
369 pop edi 377 pop edi
@@ -391,6 +399,10 @@ _CAST_decrypt PROC NEAR
391 ; Load the 2 words 399 ; Load the 2 words
392 mov edi, DWORD PTR [ebx] 400 mov edi, DWORD PTR [ebx]
393 mov esi, DWORD PTR 4[ebx] 401 mov esi, DWORD PTR 4[ebx]
402 ; Get short key flag
403 mov eax, DWORD PTR 128[ebp]
404 or eax, eax
405 jnz $L001cast_dec_skip
394 xor eax, eax 406 xor eax, eax
395 ; round 15 407 ; round 15
396 mov edx, DWORD PTR 120[ebp] 408 mov edx, DWORD PTR 120[ebp]
@@ -476,6 +488,7 @@ _CAST_decrypt PROC NEAR
476 mov ebx, DWORD PTR _CAST_S_table3[edx*4] 488 mov ebx, DWORD PTR _CAST_S_table3[edx*4]
477 add ecx, ebx 489 add ecx, ebx
478 xor esi, ecx 490 xor esi, ecx
491$L001cast_dec_skip:
479 ; round 11 492 ; round 11
480 mov edx, DWORD PTR 88[ebp] 493 mov edx, DWORD PTR 88[ebp]
481 mov ecx, DWORD PTR 92[ebp] 494 mov ecx, DWORD PTR 92[ebp]
@@ -727,9 +740,9 @@ _CAST_decrypt PROC NEAR
727 sub ecx, ebx 740 sub ecx, ebx
728 mov ebx, DWORD PTR _CAST_S_table3[edx*4] 741 mov ebx, DWORD PTR _CAST_S_table3[edx*4]
729 add ecx, ebx 742 add ecx, ebx
730 mov eax, DWORD PTR 20[esp]
731 xor esi, ecx 743 xor esi, ecx
732 nop 744 nop
745 mov eax, DWORD PTR 20[esp]
733 mov DWORD PTR 4[eax],edi 746 mov DWORD PTR 4[eax],edi
734 mov DWORD PTR [eax],esi 747 mov DWORD PTR [eax],esi
735 pop edi 748 pop edi
@@ -767,12 +780,12 @@ _CAST_cbc_encrypt PROC NEAR
767 push eax 780 push eax
768 push ebx 781 push ebx
769 cmp ecx, 0 782 cmp ecx, 0
770 jz $L000decrypt 783 jz $L002decrypt
771 and ebp, 4294967288 784 and ebp, 4294967288
772 mov eax, DWORD PTR 8[esp] 785 mov eax, DWORD PTR 8[esp]
773 mov ebx, DWORD PTR 12[esp] 786 mov ebx, DWORD PTR 12[esp]
774 jz $L001encrypt_finish 787 jz $L003encrypt_finish
775L002encrypt_loop: 788L004encrypt_loop:
776 mov ecx, DWORD PTR [esi] 789 mov ecx, DWORD PTR [esi]
777 mov edx, DWORD PTR 4[esi] 790 mov edx, DWORD PTR 4[esi]
778 xor eax, ecx 791 xor eax, ecx
@@ -791,35 +804,35 @@ L002encrypt_loop:
791 add esi, 8 804 add esi, 8
792 add edi, 8 805 add edi, 8
793 sub ebp, 8 806 sub ebp, 8
794 jnz L002encrypt_loop 807 jnz L004encrypt_loop
795$L001encrypt_finish: 808$L003encrypt_finish:
796 mov ebp, DWORD PTR 52[esp] 809 mov ebp, DWORD PTR 52[esp]
797 and ebp, 7 810 and ebp, 7
798 jz $L003finish 811 jz $L005finish
799 xor ecx, ecx 812 xor ecx, ecx
800 xor edx, edx 813 xor edx, edx
801 mov ebp, DWORD PTR $L004cbc_enc_jmp_table[ebp*4] 814 mov ebp, DWORD PTR $L006cbc_enc_jmp_table[ebp*4]
802 jmp ebp 815 jmp ebp
803L005ej7: 816L007ej7:
804 xor edx, edx 817 xor edx, edx
805 mov dh, BYTE PTR 6[esi] 818 mov dh, BYTE PTR 6[esi]
806 shl edx, 8 819 shl edx, 8
807L006ej6: 820L008ej6:
808 mov dh, BYTE PTR 5[esi] 821 mov dh, BYTE PTR 5[esi]
809L007ej5: 822L009ej5:
810 mov dl, BYTE PTR 4[esi] 823 mov dl, BYTE PTR 4[esi]
811L008ej4: 824L010ej4:
812 mov ecx, DWORD PTR [esi] 825 mov ecx, DWORD PTR [esi]
813 jmp $L009ejend 826 jmp $L011ejend
814L010ej3: 827L012ej3:
815 mov ch, BYTE PTR 2[esi] 828 mov ch, BYTE PTR 2[esi]
816 xor ecx, ecx 829 xor ecx, ecx
817 shl ecx, 8 830 shl ecx, 8
818L011ej2: 831L013ej2:
819 mov ch, BYTE PTR 1[esi] 832 mov ch, BYTE PTR 1[esi]
820L012ej1: 833L014ej1:
821 mov cl, BYTE PTR [esi] 834 mov cl, BYTE PTR [esi]
822$L009ejend: 835$L011ejend:
823 xor eax, ecx 836 xor eax, ecx
824 xor ebx, edx 837 xor ebx, edx
825 bswap eax 838 bswap eax
@@ -833,13 +846,13 @@ $L009ejend:
833 bswap ebx 846 bswap ebx
834 mov DWORD PTR [edi],eax 847 mov DWORD PTR [edi],eax
835 mov DWORD PTR 4[edi],ebx 848 mov DWORD PTR 4[edi],ebx
836 jmp $L003finish 849 jmp $L005finish
837$L000decrypt: 850$L002decrypt:
838 and ebp, 4294967288 851 and ebp, 4294967288
839 mov eax, DWORD PTR 16[esp] 852 mov eax, DWORD PTR 16[esp]
840 mov ebx, DWORD PTR 20[esp] 853 mov ebx, DWORD PTR 20[esp]
841 jz $L013decrypt_finish 854 jz $L015decrypt_finish
842L014decrypt_loop: 855L016decrypt_loop:
843 mov eax, DWORD PTR [esi] 856 mov eax, DWORD PTR [esi]
844 mov ebx, DWORD PTR 4[esi] 857 mov ebx, DWORD PTR 4[esi]
845 bswap eax 858 bswap eax
@@ -864,11 +877,11 @@ L014decrypt_loop:
864 add esi, 8 877 add esi, 8
865 add edi, 8 878 add edi, 8
866 sub ebp, 8 879 sub ebp, 8
867 jnz L014decrypt_loop 880 jnz L016decrypt_loop
868$L013decrypt_finish: 881$L015decrypt_finish:
869 mov ebp, DWORD PTR 52[esp] 882 mov ebp, DWORD PTR 52[esp]
870 and ebp, 7 883 and ebp, 7
871 jz $L003finish 884 jz $L005finish
872 mov eax, DWORD PTR [esi] 885 mov eax, DWORD PTR [esi]
873 mov ebx, DWORD PTR 4[esi] 886 mov ebx, DWORD PTR 4[esi]
874 bswap eax 887 bswap eax
@@ -886,28 +899,28 @@ $L013decrypt_finish:
886 xor edx, ebx 899 xor edx, ebx
887 mov eax, DWORD PTR [esi] 900 mov eax, DWORD PTR [esi]
888 mov ebx, DWORD PTR 4[esi] 901 mov ebx, DWORD PTR 4[esi]
889L015dj7: 902L017dj7:
890 ror edx, 16 903 ror edx, 16
891 mov BYTE PTR 6[edi],dl 904 mov BYTE PTR 6[edi],dl
892 shr edx, 16 905 shr edx, 16
893L016dj6: 906L018dj6:
894 mov BYTE PTR 5[edi],dh 907 mov BYTE PTR 5[edi],dh
895L017dj5: 908L019dj5:
896 mov BYTE PTR 4[edi],dl 909 mov BYTE PTR 4[edi],dl
897L018dj4: 910L020dj4:
898 mov DWORD PTR [edi],ecx 911 mov DWORD PTR [edi],ecx
899 jmp $L019djend 912 jmp $L021djend
900L020dj3: 913L022dj3:
901 ror ecx, 16 914 ror ecx, 16
902 mov BYTE PTR 2[edi],cl 915 mov BYTE PTR 2[edi],cl
903 shl ecx, 16 916 shl ecx, 16
904L021dj2: 917L023dj2:
905 mov BYTE PTR 1[esi],ch 918 mov BYTE PTR 1[esi],ch
906L022dj1: 919L024dj1:
907 mov BYTE PTR [esi], cl 920 mov BYTE PTR [esi], cl
908$L019djend: 921$L021djend:
909 jmp $L003finish 922 jmp $L005finish
910$L003finish: 923$L005finish:
911 mov ecx, DWORD PTR 60[esp] 924 mov ecx, DWORD PTR 60[esp]
912 add esp, 24 925 add esp, 24
913 mov DWORD PTR [ecx],eax 926 mov DWORD PTR [ecx],eax
@@ -917,24 +930,24 @@ $L003finish:
917 pop ebx 930 pop ebx
918 pop ebp 931 pop ebp
919 ret 932 ret
920$L004cbc_enc_jmp_table: 933$L006cbc_enc_jmp_table:
921 DD 0 934 DD 0
922 DD L012ej1 935 DD L014ej1
923 DD L011ej2 936 DD L013ej2
924 DD L010ej3 937 DD L012ej3
925 DD L008ej4 938 DD L010ej4
926 DD L007ej5 939 DD L009ej5
927 DD L006ej6 940 DD L008ej6
928 DD L005ej7 941 DD L007ej7
929L023cbc_dec_jmp_table: 942L025cbc_dec_jmp_table:
930 DD 0 943 DD 0
931 DD L022dj1 944 DD L024dj1
932 DD L021dj2 945 DD L023dj2
933 DD L020dj3 946 DD L022dj3
934 DD L018dj4 947 DD L020dj4
935 DD L017dj5 948 DD L019dj5
936 DD L016dj6 949 DD L018dj6
937 DD L015dj7 950 DD L017dj7
938_CAST_cbc_encrypt ENDP 951_CAST_cbc_encrypt ENDP
939_TEXT ENDS 952_TEXT ENDS
940END 953END
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# define for pentium pro friendly version 3# define for pentium pro friendly version
4$ppro=1; 4$ppro=1;
@@ -7,7 +7,7 @@ push(@INC,"perlasm","../../perlasm");
7require "x86asm.pl"; 7require "x86asm.pl";
8require "cbc.pl"; 8require "cbc.pl";
9 9
10&asm_init($ARGV[0],"cast-586.pl"); 10&asm_init($ARGV[0],"cast-586.pl",$ARGV[$#ARGV] eq "386");
11 11
12$CAST_ROUNDS=16; 12$CAST_ROUNDS=16;
13$L="edi"; 13$L="edi";
@@ -32,136 +32,145 @@ $S4="CAST_S_table3";
32 32
33&asm_finish(); 33&asm_finish();
34 34
35sub CAST_encrypt 35sub CAST_encrypt {
36 { 36 local($name,$enc)=@_;
37 local($name,$enc)=@_;
38 37
39 local($win_ex)=<<"EOF"; 38 local($win_ex)=<<"EOF";
40EXTERN _CAST_S_table0:DWORD 39EXTERN _CAST_S_table0:DWORD
41EXTERN _CAST_S_table1:DWORD 40EXTERN _CAST_S_table1:DWORD
42EXTERN _CAST_S_table2:DWORD 41EXTERN _CAST_S_table2:DWORD
43EXTERN _CAST_S_table3:DWORD 42EXTERN _CAST_S_table3:DWORD
44EOF 43EOF
45 &main'external_label( 44 &main::external_label(
46 "CAST_S_table0", 45 "CAST_S_table0",
47 "CAST_S_table1", 46 "CAST_S_table1",
48 "CAST_S_table2", 47 "CAST_S_table2",
49 "CAST_S_table3", 48 "CAST_S_table3",
50 ); 49 );
51 50
52 &function_begin_B($name,$win_ex); 51 &function_begin_B($name,$win_ex);
53 52
54 &comment(""); 53 &comment("");
55 54
56 &push("ebp"); 55 &push("ebp");
57 &push("ebx"); 56 &push("ebx");
58 &mov($tmp2,&wparam(0)); 57 &mov($tmp2,&wparam(0));
59 &mov($K,&wparam(1)); 58 &mov($K,&wparam(1));
60 &push("esi"); 59 &push("esi");
61 &push("edi"); 60 &push("edi");
62 61
63 &comment("Load the 2 words"); 62 &comment("Load the 2 words");
64 &mov($L,&DWP(0,$tmp2,"",0)); 63 &mov($L,&DWP(0,$tmp2,"",0));
65 &mov($R,&DWP(4,$tmp2,"",0)); 64 &mov($R,&DWP(4,$tmp2,"",0));
66 65
67 &xor( $tmp3, $tmp3); 66 &comment('Get short key flag');
68 67 &mov($tmp3,&DWP(128,$K,"",0));
69 # encrypting part 68 if($enc) {
70 69 &push($tmp3);
71 if ($enc) 70 } else {
72 { 71 &or($tmp3,$tmp3);
73 &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 72 &jnz(&label('cast_dec_skip'));
74 &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 73 }
75 &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 74
76 &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 75 &xor($tmp3, $tmp3);
77 &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 76
78 &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 77 # encrypting part
79 &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 78
80 &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 79 if ($enc) {
81 &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 80 &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
82 &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 81 &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
83 &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 82 &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
84 &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 83 &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
85 &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 84 &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
86 &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 85 &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
87 &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 86 &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
88 &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); 87 &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
89 } 88 &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
90 else 89 &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
91 { 90 &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
92 &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 91 &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
93 &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 92 &comment('test short key flag');
94 &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 93 &pop($tmp4);
95 &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 94 &or($tmp4,$tmp4);
96 &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 95 &jnz(&label('cast_enc_done'));
97 &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 96 &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
98 &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 97 &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
99 &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 98 &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
100 &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 99 &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
101 &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 100 } else {
102 &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 101 &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
103 &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 102 &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
104 &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); 103 &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
105 &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); 104 &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
106 &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); 105 &set_label('cast_dec_skip');
107 &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); 106 &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
108 } 107 &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
109 108 &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
110 &nop(); 109 &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
111 &mov(&DWP(4,$tmp3,"",0),$L); 110 &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
112 &mov(&DWP(0,$tmp3,"",0),$R); 111 &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
113 &function_end($name); 112 &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
114 } 113 &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
115 114 &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
116sub E_CAST 115 &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4);
117 { 116 &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4);
118 local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4,$lst)=@_; 117 &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4);
119 # Ri needs to have 16 pre added. 118 }
120 119
121 &comment("round $i"); 120 &set_label('cast_enc_done') if $enc;
122 &mov( $tmp4, &DWP($i*8,$K,"",1)); 121# Why the nop? - Ben 17/1/99
123 122 &nop();
124 &mov( $tmp1, &DWP($i*8+4,$K,"",1));# must be word 123 &mov($tmp3,&wparam(0));
125 &$OP1( $tmp4, $R); 124 &mov(&DWP(4,$tmp3,"",0),$L);
126 125 &mov(&DWP(0,$tmp3,"",0),$R);
127 &rotl( $tmp4, &LB($tmp1)); 126 &function_end($name);
128 127}
129 if ($ppro) 128
130 { 129sub E_CAST {
131 &mov( $tmp2, $tmp4); # B 130 local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4)=@_;
132 &xor( $tmp1, $tmp1); 131 # Ri needs to have 16 pre added.
133 132
134 &movb( &LB($tmp1), &HB($tmp4)); # A 133 &comment("round $i");
135 &and( $tmp2, 0xff); 134 &mov( $tmp4, &DWP($i*8,$K,"",1));
136 135
137 &shr( $tmp4, 16); # 136 &mov( $tmp1, &DWP($i*8+4,$K,"",1));
138 &xor( $tmp3, $tmp3); 137 &$OP1( $tmp4, $R);
139 } 138
140 else 139 &rotl( $tmp4, &LB($tmp1));
141 { 140
142 &mov( $tmp2, $tmp4); # B 141 if ($ppro) {
143 &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD 142 &mov( $tmp2, $tmp4); # B
144 143 &xor( $tmp1, $tmp1);
145 &shr( $tmp4, 16); # 144
146 &and( $tmp2, 0xff); 145 &movb( &LB($tmp1), &HB($tmp4)); # A
147 } 146 &and( $tmp2, 0xff);
148 147
149 &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD 148 &shr( $tmp4, 16); #
150 &and( $tmp4, 0xff); # D 149 &xor( $tmp3, $tmp3);
151 150 } else {
152 &mov( $tmp1, &DWP($S1,"",$tmp1,4)); 151 &mov( $tmp2, $tmp4); # B
153 &mov( $tmp2, &DWP($S2,"",$tmp2,4)); 152 &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD
154 153
155 &$OP2( $tmp1, $tmp2); 154 &shr( $tmp4, 16); #
156 &mov( $tmp2, &DWP($S3,"",$tmp3,4)); 155 &and( $tmp2, 0xff);
157 156 }
158 &$OP3( $tmp1, $tmp2); 157
159 &mov( $tmp2, &DWP($S4,"",$tmp4,4)); 158 &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD
160 159 &and( $tmp4, 0xff); # D
161 &$OP1( $tmp1, $tmp2); 160
162 &mov($tmp3,&wparam(0)) if $lst; 161 &mov( $tmp1, &DWP($S1,"",$tmp1,4));
163 # XXX 162 &mov( $tmp2, &DWP($S2,"",$tmp2,4));
164 163
165 &xor( $L, $tmp1); 164 &$OP2( $tmp1, $tmp2);
166 # XXX 165 &mov( $tmp2, &DWP($S3,"",$tmp3,4));
167 } 166
167 &$OP3( $tmp1, $tmp2);
168 &mov( $tmp2, &DWP($S4,"",$tmp4,4));
169
170 &$OP1( $tmp1, $tmp2);
171 # XXX
172
173 &xor( $L, $tmp1);
174 # XXX
175}
176
diff --git a/src/lib/libcrypto/cast/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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define CAST_S_table0 _CAST_S_table0
13#define CAST_S_table1 _CAST_S_table1
14#define CAST_S_table2 _CAST_S_table2
15#define CAST_S_table3 _CAST_S_table3
16#define CAST_encrypt _CAST_encrypt
17#define CAST_S_table0 _CAST_S_table0
18#define CAST_S_table1 _CAST_S_table1
19#define CAST_S_table2 _CAST_S_table2
20#define CAST_S_table3 _CAST_S_table3
21#define CAST_decrypt _CAST_decrypt
22#define CAST_cbc_encrypt _CAST_cbc_encrypt
23
24#endif
25
26#ifdef OUT
27#define OK 1
28#define ALIGN 4
29#endif
30
31#ifdef BSDI
32#define OK 1
33#define ALIGN 4
34#undef SIZE
35#undef TYPE
36#define SIZE(a,b)
37#define TYPE(a,b)
38#endif
39
40#if defined(ELF) || defined(SOL)
41#define OK 1
42#define ALIGN 16
43#endif
44
45#ifndef OK
46You need to define one of
47ELF - elf systems - linux-elf, NetBSD and DG-UX
48OUT - a.out systems - linux-a.out and FreeBSD
49SOL - solaris systems, which are elf with strange comment lines
50BSDI - a.out with a very primative version of as.
51#endif
52
53/* Let the Assembler begin :-) */
54 /* Don't even think of reading this code */
55 /* It was automatically generated by cast-586.pl */
56 /* Which is a perl program used to generate the x86 assember for */
57 /* any of elf, a.out, BSDI,Win32, or Solaris */
58 /* eric <eay@cryptsoft.com> */
59
60 .file "cast-586.s"
61 .version "01.01"
62gcc2_compiled.:
63.text
64 .align ALIGN
65.globl CAST_encrypt
66 TYPE(CAST_encrypt,@function)
67CAST_encrypt:
68
69 pushl %ebp
70 pushl %ebx
71 movl 12(%esp), %ebx
72 movl 16(%esp), %ebp
73 pushl %esi
74 pushl %edi
75 /* Load the 2 words */
76 movl (%ebx), %edi
77 movl 4(%ebx), %esi
78 xorl %eax, %eax
79 /* round 0 */
80 movl (%ebp), %edx
81 movl 4(%ebp), %ecx
82 addl %esi, %edx
83 roll %cl, %edx
84 movl %edx, %ebx
85 xorl %ecx, %ecx
86 movb %dh, %cl
87 andl $255, %ebx
88 shrl $16, %edx
89 xorl %eax, %eax
90 movb %dh, %al
91 andl $255, %edx
92 movl CAST_S_table0(,%ecx,4),%ecx
93 movl CAST_S_table1(,%ebx,4),%ebx
94 xorl %ebx, %ecx
95 movl CAST_S_table2(,%eax,4),%ebx
96 subl %ebx, %ecx
97 movl CAST_S_table3(,%edx,4),%ebx
98 addl %ebx, %ecx
99 xorl %ecx, %edi
100 /* round 1 */
101 movl 8(%ebp), %edx
102 movl 12(%ebp), %ecx
103 xorl %edi, %edx
104 roll %cl, %edx
105 movl %edx, %ebx
106 xorl %ecx, %ecx
107 movb %dh, %cl
108 andl $255, %ebx
109 shrl $16, %edx
110 xorl %eax, %eax
111 movb %dh, %al
112 andl $255, %edx
113 movl CAST_S_table0(,%ecx,4),%ecx
114 movl CAST_S_table1(,%ebx,4),%ebx
115 subl %ebx, %ecx
116 movl CAST_S_table2(,%eax,4),%ebx
117 addl %ebx, %ecx
118 movl CAST_S_table3(,%edx,4),%ebx
119 xorl %ebx, %ecx
120 xorl %ecx, %esi
121 /* round 2 */
122 movl 16(%ebp), %edx
123 movl 20(%ebp), %ecx
124 subl %esi, %edx
125 roll %cl, %edx
126 movl %edx, %ebx
127 xorl %ecx, %ecx
128 movb %dh, %cl
129 andl $255, %ebx
130 shrl $16, %edx
131 xorl %eax, %eax
132 movb %dh, %al
133 andl $255, %edx
134 movl CAST_S_table0(,%ecx,4),%ecx
135 movl CAST_S_table1(,%ebx,4),%ebx
136 addl %ebx, %ecx
137 movl CAST_S_table2(,%eax,4),%ebx
138 xorl %ebx, %ecx
139 movl CAST_S_table3(,%edx,4),%ebx
140 subl %ebx, %ecx
141 xorl %ecx, %edi
142 /* round 3 */
143 movl 24(%ebp), %edx
144 movl 28(%ebp), %ecx
145 addl %edi, %edx
146 roll %cl, %edx
147 movl %edx, %ebx
148 xorl %ecx, %ecx
149 movb %dh, %cl
150 andl $255, %ebx
151 shrl $16, %edx
152 xorl %eax, %eax
153 movb %dh, %al
154 andl $255, %edx
155 movl CAST_S_table0(,%ecx,4),%ecx
156 movl CAST_S_table1(,%ebx,4),%ebx
157 xorl %ebx, %ecx
158 movl CAST_S_table2(,%eax,4),%ebx
159 subl %ebx, %ecx
160 movl CAST_S_table3(,%edx,4),%ebx
161 addl %ebx, %ecx
162 xorl %ecx, %esi
163 /* round 4 */
164 movl 32(%ebp), %edx
165 movl 36(%ebp), %ecx
166 xorl %esi, %edx
167 roll %cl, %edx
168 movl %edx, %ebx
169 xorl %ecx, %ecx
170 movb %dh, %cl
171 andl $255, %ebx
172 shrl $16, %edx
173 xorl %eax, %eax
174 movb %dh, %al
175 andl $255, %edx
176 movl CAST_S_table0(,%ecx,4),%ecx
177 movl CAST_S_table1(,%ebx,4),%ebx
178 subl %ebx, %ecx
179 movl CAST_S_table2(,%eax,4),%ebx
180 addl %ebx, %ecx
181 movl CAST_S_table3(,%edx,4),%ebx
182 xorl %ebx, %ecx
183 xorl %ecx, %edi
184 /* round 5 */
185 movl 40(%ebp), %edx
186 movl 44(%ebp), %ecx
187 subl %edi, %edx
188 roll %cl, %edx
189 movl %edx, %ebx
190 xorl %ecx, %ecx
191 movb %dh, %cl
192 andl $255, %ebx
193 shrl $16, %edx
194 xorl %eax, %eax
195 movb %dh, %al
196 andl $255, %edx
197 movl CAST_S_table0(,%ecx,4),%ecx
198 movl CAST_S_table1(,%ebx,4),%ebx
199 addl %ebx, %ecx
200 movl CAST_S_table2(,%eax,4),%ebx
201 xorl %ebx, %ecx
202 movl CAST_S_table3(,%edx,4),%ebx
203 subl %ebx, %ecx
204 xorl %ecx, %esi
205 /* round 6 */
206 movl 48(%ebp), %edx
207 movl 52(%ebp), %ecx
208 addl %esi, %edx
209 roll %cl, %edx
210 movl %edx, %ebx
211 xorl %ecx, %ecx
212 movb %dh, %cl
213 andl $255, %ebx
214 shrl $16, %edx
215 xorl %eax, %eax
216 movb %dh, %al
217 andl $255, %edx
218 movl CAST_S_table0(,%ecx,4),%ecx
219 movl CAST_S_table1(,%ebx,4),%ebx
220 xorl %ebx, %ecx
221 movl CAST_S_table2(,%eax,4),%ebx
222 subl %ebx, %ecx
223 movl CAST_S_table3(,%edx,4),%ebx
224 addl %ebx, %ecx
225 xorl %ecx, %edi
226 /* round 7 */
227 movl 56(%ebp), %edx
228 movl 60(%ebp), %ecx
229 xorl %edi, %edx
230 roll %cl, %edx
231 movl %edx, %ebx
232 xorl %ecx, %ecx
233 movb %dh, %cl
234 andl $255, %ebx
235 shrl $16, %edx
236 xorl %eax, %eax
237 movb %dh, %al
238 andl $255, %edx
239 movl CAST_S_table0(,%ecx,4),%ecx
240 movl CAST_S_table1(,%ebx,4),%ebx
241 subl %ebx, %ecx
242 movl CAST_S_table2(,%eax,4),%ebx
243 addl %ebx, %ecx
244 movl CAST_S_table3(,%edx,4),%ebx
245 xorl %ebx, %ecx
246 xorl %ecx, %esi
247 /* round 8 */
248 movl 64(%ebp), %edx
249 movl 68(%ebp), %ecx
250 subl %esi, %edx
251 roll %cl, %edx
252 movl %edx, %ebx
253 xorl %ecx, %ecx
254 movb %dh, %cl
255 andl $255, %ebx
256 shrl $16, %edx
257 xorl %eax, %eax
258 movb %dh, %al
259 andl $255, %edx
260 movl CAST_S_table0(,%ecx,4),%ecx
261 movl CAST_S_table1(,%ebx,4),%ebx
262 addl %ebx, %ecx
263 movl CAST_S_table2(,%eax,4),%ebx
264 xorl %ebx, %ecx
265 movl CAST_S_table3(,%edx,4),%ebx
266 subl %ebx, %ecx
267 xorl %ecx, %edi
268 /* round 9 */
269 movl 72(%ebp), %edx
270 movl 76(%ebp), %ecx
271 addl %edi, %edx
272 roll %cl, %edx
273 movl %edx, %ebx
274 xorl %ecx, %ecx
275 movb %dh, %cl
276 andl $255, %ebx
277 shrl $16, %edx
278 xorl %eax, %eax
279 movb %dh, %al
280 andl $255, %edx
281 movl CAST_S_table0(,%ecx,4),%ecx
282 movl CAST_S_table1(,%ebx,4),%ebx
283 xorl %ebx, %ecx
284 movl CAST_S_table2(,%eax,4),%ebx
285 subl %ebx, %ecx
286 movl CAST_S_table3(,%edx,4),%ebx
287 addl %ebx, %ecx
288 xorl %ecx, %esi
289 /* round 10 */
290 movl 80(%ebp), %edx
291 movl 84(%ebp), %ecx
292 xorl %esi, %edx
293 roll %cl, %edx
294 movl %edx, %ebx
295 xorl %ecx, %ecx
296 movb %dh, %cl
297 andl $255, %ebx
298 shrl $16, %edx
299 xorl %eax, %eax
300 movb %dh, %al
301 andl $255, %edx
302 movl CAST_S_table0(,%ecx,4),%ecx
303 movl CAST_S_table1(,%ebx,4),%ebx
304 subl %ebx, %ecx
305 movl CAST_S_table2(,%eax,4),%ebx
306 addl %ebx, %ecx
307 movl CAST_S_table3(,%edx,4),%ebx
308 xorl %ebx, %ecx
309 xorl %ecx, %edi
310 /* round 11 */
311 movl 88(%ebp), %edx
312 movl 92(%ebp), %ecx
313 subl %edi, %edx
314 roll %cl, %edx
315 movl %edx, %ebx
316 xorl %ecx, %ecx
317 movb %dh, %cl
318 andl $255, %ebx
319 shrl $16, %edx
320 xorl %eax, %eax
321 movb %dh, %al
322 andl $255, %edx
323 movl CAST_S_table0(,%ecx,4),%ecx
324 movl CAST_S_table1(,%ebx,4),%ebx
325 addl %ebx, %ecx
326 movl CAST_S_table2(,%eax,4),%ebx
327 xorl %ebx, %ecx
328 movl CAST_S_table3(,%edx,4),%ebx
329 subl %ebx, %ecx
330 xorl %ecx, %esi
331 /* round 12 */
332 movl 96(%ebp), %edx
333 movl 100(%ebp), %ecx
334 addl %esi, %edx
335 roll %cl, %edx
336 movl %edx, %ebx
337 xorl %ecx, %ecx
338 movb %dh, %cl
339 andl $255, %ebx
340 shrl $16, %edx
341 xorl %eax, %eax
342 movb %dh, %al
343 andl $255, %edx
344 movl CAST_S_table0(,%ecx,4),%ecx
345 movl CAST_S_table1(,%ebx,4),%ebx
346 xorl %ebx, %ecx
347 movl CAST_S_table2(,%eax,4),%ebx
348 subl %ebx, %ecx
349 movl CAST_S_table3(,%edx,4),%ebx
350 addl %ebx, %ecx
351 xorl %ecx, %edi
352 /* round 13 */
353 movl 104(%ebp), %edx
354 movl 108(%ebp), %ecx
355 xorl %edi, %edx
356 roll %cl, %edx
357 movl %edx, %ebx
358 xorl %ecx, %ecx
359 movb %dh, %cl
360 andl $255, %ebx
361 shrl $16, %edx
362 xorl %eax, %eax
363 movb %dh, %al
364 andl $255, %edx
365 movl CAST_S_table0(,%ecx,4),%ecx
366 movl CAST_S_table1(,%ebx,4),%ebx
367 subl %ebx, %ecx
368 movl CAST_S_table2(,%eax,4),%ebx
369 addl %ebx, %ecx
370 movl CAST_S_table3(,%edx,4),%ebx
371 xorl %ebx, %ecx
372 xorl %ecx, %esi
373 /* round 14 */
374 movl 112(%ebp), %edx
375 movl 116(%ebp), %ecx
376 subl %esi, %edx
377 roll %cl, %edx
378 movl %edx, %ebx
379 xorl %ecx, %ecx
380 movb %dh, %cl
381 andl $255, %ebx
382 shrl $16, %edx
383 xorl %eax, %eax
384 movb %dh, %al
385 andl $255, %edx
386 movl CAST_S_table0(,%ecx,4),%ecx
387 movl CAST_S_table1(,%ebx,4),%ebx
388 addl %ebx, %ecx
389 movl CAST_S_table2(,%eax,4),%ebx
390 xorl %ebx, %ecx
391 movl CAST_S_table3(,%edx,4),%ebx
392 subl %ebx, %ecx
393 xorl %ecx, %edi
394 /* round 15 */
395 movl 120(%ebp), %edx
396 movl 124(%ebp), %ecx
397 addl %edi, %edx
398 roll %cl, %edx
399 movl %edx, %ebx
400 xorl %ecx, %ecx
401 movb %dh, %cl
402 andl $255, %ebx
403 shrl $16, %edx
404 xorl %eax, %eax
405 movb %dh, %al
406 andl $255, %edx
407 movl CAST_S_table0(,%ecx,4),%ecx
408 movl CAST_S_table1(,%ebx,4),%ebx
409 xorl %ebx, %ecx
410 movl CAST_S_table2(,%eax,4),%ebx
411 subl %ebx, %ecx
412 movl CAST_S_table3(,%edx,4),%ebx
413 addl %ebx, %ecx
414 movl 20(%esp), %eax
415 xorl %ecx, %esi
416 nop
417 movl %edi, 4(%eax)
418 movl %esi, (%eax)
419 popl %edi
420 popl %esi
421 popl %ebx
422 popl %ebp
423 ret
424.CAST_encrypt_end:
425 SIZE(CAST_encrypt,.CAST_encrypt_end-CAST_encrypt)
426.ident "CAST_encrypt"
427.text
428 .align ALIGN
429.globl CAST_decrypt
430 TYPE(CAST_decrypt,@function)
431CAST_decrypt:
432
433 pushl %ebp
434 pushl %ebx
435 movl 12(%esp), %ebx
436 movl 16(%esp), %ebp
437 pushl %esi
438 pushl %edi
439 /* Load the 2 words */
440 movl (%ebx), %edi
441 movl 4(%ebx), %esi
442 xorl %eax, %eax
443 /* round 15 */
444 movl 120(%ebp), %edx
445 movl 124(%ebp), %ecx
446 addl %esi, %edx
447 roll %cl, %edx
448 movl %edx, %ebx
449 xorl %ecx, %ecx
450 movb %dh, %cl
451 andl $255, %ebx
452 shrl $16, %edx
453 xorl %eax, %eax
454 movb %dh, %al
455 andl $255, %edx
456 movl CAST_S_table0(,%ecx,4),%ecx
457 movl CAST_S_table1(,%ebx,4),%ebx
458 xorl %ebx, %ecx
459 movl CAST_S_table2(,%eax,4),%ebx
460 subl %ebx, %ecx
461 movl CAST_S_table3(,%edx,4),%ebx
462 addl %ebx, %ecx
463 xorl %ecx, %edi
464 /* round 14 */
465 movl 112(%ebp), %edx
466 movl 116(%ebp), %ecx
467 subl %edi, %edx
468 roll %cl, %edx
469 movl %edx, %ebx
470 xorl %ecx, %ecx
471 movb %dh, %cl
472 andl $255, %ebx
473 shrl $16, %edx
474 xorl %eax, %eax
475 movb %dh, %al
476 andl $255, %edx
477 movl CAST_S_table0(,%ecx,4),%ecx
478 movl CAST_S_table1(,%ebx,4),%ebx
479 addl %ebx, %ecx
480 movl CAST_S_table2(,%eax,4),%ebx
481 xorl %ebx, %ecx
482 movl CAST_S_table3(,%edx,4),%ebx
483 subl %ebx, %ecx
484 xorl %ecx, %esi
485 /* round 13 */
486 movl 104(%ebp), %edx
487 movl 108(%ebp), %ecx
488 xorl %esi, %edx
489 roll %cl, %edx
490 movl %edx, %ebx
491 xorl %ecx, %ecx
492 movb %dh, %cl
493 andl $255, %ebx
494 shrl $16, %edx
495 xorl %eax, %eax
496 movb %dh, %al
497 andl $255, %edx
498 movl CAST_S_table0(,%ecx,4),%ecx
499 movl CAST_S_table1(,%ebx,4),%ebx
500 subl %ebx, %ecx
501 movl CAST_S_table2(,%eax,4),%ebx
502 addl %ebx, %ecx
503 movl CAST_S_table3(,%edx,4),%ebx
504 xorl %ebx, %ecx
505 xorl %ecx, %edi
506 /* round 12 */
507 movl 96(%ebp), %edx
508 movl 100(%ebp), %ecx
509 addl %edi, %edx
510 roll %cl, %edx
511 movl %edx, %ebx
512 xorl %ecx, %ecx
513 movb %dh, %cl
514 andl $255, %ebx
515 shrl $16, %edx
516 xorl %eax, %eax
517 movb %dh, %al
518 andl $255, %edx
519 movl CAST_S_table0(,%ecx,4),%ecx
520 movl CAST_S_table1(,%ebx,4),%ebx
521 xorl %ebx, %ecx
522 movl CAST_S_table2(,%eax,4),%ebx
523 subl %ebx, %ecx
524 movl CAST_S_table3(,%edx,4),%ebx
525 addl %ebx, %ecx
526 xorl %ecx, %esi
527 /* round 11 */
528 movl 88(%ebp), %edx
529 movl 92(%ebp), %ecx
530 subl %esi, %edx
531 roll %cl, %edx
532 movl %edx, %ebx
533 xorl %ecx, %ecx
534 movb %dh, %cl
535 andl $255, %ebx
536 shrl $16, %edx
537 xorl %eax, %eax
538 movb %dh, %al
539 andl $255, %edx
540 movl CAST_S_table0(,%ecx,4),%ecx
541 movl CAST_S_table1(,%ebx,4),%ebx
542 addl %ebx, %ecx
543 movl CAST_S_table2(,%eax,4),%ebx
544 xorl %ebx, %ecx
545 movl CAST_S_table3(,%edx,4),%ebx
546 subl %ebx, %ecx
547 xorl %ecx, %edi
548 /* round 10 */
549 movl 80(%ebp), %edx
550 movl 84(%ebp), %ecx
551 xorl %edi, %edx
552 roll %cl, %edx
553 movl %edx, %ebx
554 xorl %ecx, %ecx
555 movb %dh, %cl
556 andl $255, %ebx
557 shrl $16, %edx
558 xorl %eax, %eax
559 movb %dh, %al
560 andl $255, %edx
561 movl CAST_S_table0(,%ecx,4),%ecx
562 movl CAST_S_table1(,%ebx,4),%ebx
563 subl %ebx, %ecx
564 movl CAST_S_table2(,%eax,4),%ebx
565 addl %ebx, %ecx
566 movl CAST_S_table3(,%edx,4),%ebx
567 xorl %ebx, %ecx
568 xorl %ecx, %esi
569 /* round 9 */
570 movl 72(%ebp), %edx
571 movl 76(%ebp), %ecx
572 addl %esi, %edx
573 roll %cl, %edx
574 movl %edx, %ebx
575 xorl %ecx, %ecx
576 movb %dh, %cl
577 andl $255, %ebx
578 shrl $16, %edx
579 xorl %eax, %eax
580 movb %dh, %al
581 andl $255, %edx
582 movl CAST_S_table0(,%ecx,4),%ecx
583 movl CAST_S_table1(,%ebx,4),%ebx
584 xorl %ebx, %ecx
585 movl CAST_S_table2(,%eax,4),%ebx
586 subl %ebx, %ecx
587 movl CAST_S_table3(,%edx,4),%ebx
588 addl %ebx, %ecx
589 xorl %ecx, %edi
590 /* round 8 */
591 movl 64(%ebp), %edx
592 movl 68(%ebp), %ecx
593 subl %edi, %edx
594 roll %cl, %edx
595 movl %edx, %ebx
596 xorl %ecx, %ecx
597 movb %dh, %cl
598 andl $255, %ebx
599 shrl $16, %edx
600 xorl %eax, %eax
601 movb %dh, %al
602 andl $255, %edx
603 movl CAST_S_table0(,%ecx,4),%ecx
604 movl CAST_S_table1(,%ebx,4),%ebx
605 addl %ebx, %ecx
606 movl CAST_S_table2(,%eax,4),%ebx
607 xorl %ebx, %ecx
608 movl CAST_S_table3(,%edx,4),%ebx
609 subl %ebx, %ecx
610 xorl %ecx, %esi
611 /* round 7 */
612 movl 56(%ebp), %edx
613 movl 60(%ebp), %ecx
614 xorl %esi, %edx
615 roll %cl, %edx
616 movl %edx, %ebx
617 xorl %ecx, %ecx
618 movb %dh, %cl
619 andl $255, %ebx
620 shrl $16, %edx
621 xorl %eax, %eax
622 movb %dh, %al
623 andl $255, %edx
624 movl CAST_S_table0(,%ecx,4),%ecx
625 movl CAST_S_table1(,%ebx,4),%ebx
626 subl %ebx, %ecx
627 movl CAST_S_table2(,%eax,4),%ebx
628 addl %ebx, %ecx
629 movl CAST_S_table3(,%edx,4),%ebx
630 xorl %ebx, %ecx
631 xorl %ecx, %edi
632 /* round 6 */
633 movl 48(%ebp), %edx
634 movl 52(%ebp), %ecx
635 addl %edi, %edx
636 roll %cl, %edx
637 movl %edx, %ebx
638 xorl %ecx, %ecx
639 movb %dh, %cl
640 andl $255, %ebx
641 shrl $16, %edx
642 xorl %eax, %eax
643 movb %dh, %al
644 andl $255, %edx
645 movl CAST_S_table0(,%ecx,4),%ecx
646 movl CAST_S_table1(,%ebx,4),%ebx
647 xorl %ebx, %ecx
648 movl CAST_S_table2(,%eax,4),%ebx
649 subl %ebx, %ecx
650 movl CAST_S_table3(,%edx,4),%ebx
651 addl %ebx, %ecx
652 xorl %ecx, %esi
653 /* round 5 */
654 movl 40(%ebp), %edx
655 movl 44(%ebp), %ecx
656 subl %esi, %edx
657 roll %cl, %edx
658 movl %edx, %ebx
659 xorl %ecx, %ecx
660 movb %dh, %cl
661 andl $255, %ebx
662 shrl $16, %edx
663 xorl %eax, %eax
664 movb %dh, %al
665 andl $255, %edx
666 movl CAST_S_table0(,%ecx,4),%ecx
667 movl CAST_S_table1(,%ebx,4),%ebx
668 addl %ebx, %ecx
669 movl CAST_S_table2(,%eax,4),%ebx
670 xorl %ebx, %ecx
671 movl CAST_S_table3(,%edx,4),%ebx
672 subl %ebx, %ecx
673 xorl %ecx, %edi
674 /* round 4 */
675 movl 32(%ebp), %edx
676 movl 36(%ebp), %ecx
677 xorl %edi, %edx
678 roll %cl, %edx
679 movl %edx, %ebx
680 xorl %ecx, %ecx
681 movb %dh, %cl
682 andl $255, %ebx
683 shrl $16, %edx
684 xorl %eax, %eax
685 movb %dh, %al
686 andl $255, %edx
687 movl CAST_S_table0(,%ecx,4),%ecx
688 movl CAST_S_table1(,%ebx,4),%ebx
689 subl %ebx, %ecx
690 movl CAST_S_table2(,%eax,4),%ebx
691 addl %ebx, %ecx
692 movl CAST_S_table3(,%edx,4),%ebx
693 xorl %ebx, %ecx
694 xorl %ecx, %esi
695 /* round 3 */
696 movl 24(%ebp), %edx
697 movl 28(%ebp), %ecx
698 addl %esi, %edx
699 roll %cl, %edx
700 movl %edx, %ebx
701 xorl %ecx, %ecx
702 movb %dh, %cl
703 andl $255, %ebx
704 shrl $16, %edx
705 xorl %eax, %eax
706 movb %dh, %al
707 andl $255, %edx
708 movl CAST_S_table0(,%ecx,4),%ecx
709 movl CAST_S_table1(,%ebx,4),%ebx
710 xorl %ebx, %ecx
711 movl CAST_S_table2(,%eax,4),%ebx
712 subl %ebx, %ecx
713 movl CAST_S_table3(,%edx,4),%ebx
714 addl %ebx, %ecx
715 xorl %ecx, %edi
716 /* round 2 */
717 movl 16(%ebp), %edx
718 movl 20(%ebp), %ecx
719 subl %edi, %edx
720 roll %cl, %edx
721 movl %edx, %ebx
722 xorl %ecx, %ecx
723 movb %dh, %cl
724 andl $255, %ebx
725 shrl $16, %edx
726 xorl %eax, %eax
727 movb %dh, %al
728 andl $255, %edx
729 movl CAST_S_table0(,%ecx,4),%ecx
730 movl CAST_S_table1(,%ebx,4),%ebx
731 addl %ebx, %ecx
732 movl CAST_S_table2(,%eax,4),%ebx
733 xorl %ebx, %ecx
734 movl CAST_S_table3(,%edx,4),%ebx
735 subl %ebx, %ecx
736 xorl %ecx, %esi
737 /* round 1 */
738 movl 8(%ebp), %edx
739 movl 12(%ebp), %ecx
740 xorl %esi, %edx
741 roll %cl, %edx
742 movl %edx, %ebx
743 xorl %ecx, %ecx
744 movb %dh, %cl
745 andl $255, %ebx
746 shrl $16, %edx
747 xorl %eax, %eax
748 movb %dh, %al
749 andl $255, %edx
750 movl CAST_S_table0(,%ecx,4),%ecx
751 movl CAST_S_table1(,%ebx,4),%ebx
752 subl %ebx, %ecx
753 movl CAST_S_table2(,%eax,4),%ebx
754 addl %ebx, %ecx
755 movl CAST_S_table3(,%edx,4),%ebx
756 xorl %ebx, %ecx
757 xorl %ecx, %edi
758 /* round 0 */
759 movl (%ebp), %edx
760 movl 4(%ebp), %ecx
761 addl %edi, %edx
762 roll %cl, %edx
763 movl %edx, %ebx
764 xorl %ecx, %ecx
765 movb %dh, %cl
766 andl $255, %ebx
767 shrl $16, %edx
768 xorl %eax, %eax
769 movb %dh, %al
770 andl $255, %edx
771 movl CAST_S_table0(,%ecx,4),%ecx
772 movl CAST_S_table1(,%ebx,4),%ebx
773 xorl %ebx, %ecx
774 movl CAST_S_table2(,%eax,4),%ebx
775 subl %ebx, %ecx
776 movl CAST_S_table3(,%edx,4),%ebx
777 addl %ebx, %ecx
778 movl 20(%esp), %eax
779 xorl %ecx, %esi
780 nop
781 movl %edi, 4(%eax)
782 movl %esi, (%eax)
783 popl %edi
784 popl %esi
785 popl %ebx
786 popl %ebp
787 ret
788.CAST_decrypt_end:
789 SIZE(CAST_decrypt,.CAST_decrypt_end-CAST_decrypt)
790.ident "CAST_decrypt"
791.text
792 .align ALIGN
793.globl CAST_cbc_encrypt
794 TYPE(CAST_cbc_encrypt,@function)
795CAST_cbc_encrypt:
796
797 pushl %ebp
798 pushl %ebx
799 pushl %esi
800 pushl %edi
801 movl 28(%esp), %ebp
802 /* getting iv ptr from parameter 4 */
803 movl 36(%esp), %ebx
804 movl (%ebx), %esi
805 movl 4(%ebx), %edi
806 pushl %edi
807 pushl %esi
808 pushl %edi
809 pushl %esi
810 movl %esp, %ebx
811 movl 36(%esp), %esi
812 movl 40(%esp), %edi
813 /* getting encrypt flag from parameter 5 */
814 movl 56(%esp), %ecx
815 /* get and push parameter 3 */
816 movl 48(%esp), %eax
817 pushl %eax
818 pushl %ebx
819 cmpl $0, %ecx
820 jz .L000decrypt
821 andl $4294967288, %ebp
822 movl 8(%esp), %eax
823 movl 12(%esp), %ebx
824 jz .L001encrypt_finish
825.L002encrypt_loop:
826 movl (%esi), %ecx
827 movl 4(%esi), %edx
828 xorl %ecx, %eax
829 xorl %edx, %ebx
830.byte 15
831.byte 200 /* bswapl %eax */
832.byte 15
833.byte 203 /* bswapl %ebx */
834 movl %eax, 8(%esp)
835 movl %ebx, 12(%esp)
836 call CAST_encrypt
837 movl 8(%esp), %eax
838 movl 12(%esp), %ebx
839.byte 15
840.byte 200 /* bswapl %eax */
841.byte 15
842.byte 203 /* bswapl %ebx */
843 movl %eax, (%edi)
844 movl %ebx, 4(%edi)
845 addl $8, %esi
846 addl $8, %edi
847 subl $8, %ebp
848 jnz .L002encrypt_loop
849.L001encrypt_finish:
850 movl 52(%esp), %ebp
851 andl $7, %ebp
852 jz .L003finish
853 xorl %ecx, %ecx
854 xorl %edx, %edx
855 movl .L004cbc_enc_jmp_table(,%ebp,4),%ebp
856 jmp *%ebp
857.L005ej7:
858 xorl %edx, %edx
859 movb 6(%esi), %dh
860 sall $8, %edx
861.L006ej6:
862 movb 5(%esi), %dh
863.L007ej5:
864 movb 4(%esi), %dl
865.L008ej4:
866 movl (%esi), %ecx
867 jmp .L009ejend
868.L010ej3:
869 movb 2(%esi), %ch
870 xorl %ecx, %ecx
871 sall $8, %ecx
872.L011ej2:
873 movb 1(%esi), %ch
874.L012ej1:
875 movb (%esi), %cl
876.L009ejend:
877 xorl %ecx, %eax
878 xorl %edx, %ebx
879.byte 15
880.byte 200 /* bswapl %eax */
881.byte 15
882.byte 203 /* bswapl %ebx */
883 movl %eax, 8(%esp)
884 movl %ebx, 12(%esp)
885 call CAST_encrypt
886 movl 8(%esp), %eax
887 movl 12(%esp), %ebx
888.byte 15
889.byte 200 /* bswapl %eax */
890.byte 15
891.byte 203 /* bswapl %ebx */
892 movl %eax, (%edi)
893 movl %ebx, 4(%edi)
894 jmp .L003finish
895.align ALIGN
896.L000decrypt:
897 andl $4294967288, %ebp
898 movl 16(%esp), %eax
899 movl 20(%esp), %ebx
900 jz .L013decrypt_finish
901.L014decrypt_loop:
902 movl (%esi), %eax
903 movl 4(%esi), %ebx
904.byte 15
905.byte 200 /* bswapl %eax */
906.byte 15
907.byte 203 /* bswapl %ebx */
908 movl %eax, 8(%esp)
909 movl %ebx, 12(%esp)
910 call CAST_decrypt
911 movl 8(%esp), %eax
912 movl 12(%esp), %ebx
913.byte 15
914.byte 200 /* bswapl %eax */
915.byte 15
916.byte 203 /* bswapl %ebx */
917 movl 16(%esp), %ecx
918 movl 20(%esp), %edx
919 xorl %eax, %ecx
920 xorl %ebx, %edx
921 movl (%esi), %eax
922 movl 4(%esi), %ebx
923 movl %ecx, (%edi)
924 movl %edx, 4(%edi)
925 movl %eax, 16(%esp)
926 movl %ebx, 20(%esp)
927 addl $8, %esi
928 addl $8, %edi
929 subl $8, %ebp
930 jnz .L014decrypt_loop
931.L013decrypt_finish:
932 movl 52(%esp), %ebp
933 andl $7, %ebp
934 jz .L003finish
935 movl (%esi), %eax
936 movl 4(%esi), %ebx
937.byte 15
938.byte 200 /* bswapl %eax */
939.byte 15
940.byte 203 /* bswapl %ebx */
941 movl %eax, 8(%esp)
942 movl %ebx, 12(%esp)
943 call CAST_decrypt
944 movl 8(%esp), %eax
945 movl 12(%esp), %ebx
946.byte 15
947.byte 200 /* bswapl %eax */
948.byte 15
949.byte 203 /* bswapl %ebx */
950 movl 16(%esp), %ecx
951 movl 20(%esp), %edx
952 xorl %eax, %ecx
953 xorl %ebx, %edx
954 movl (%esi), %eax
955 movl 4(%esi), %ebx
956.L015dj7:
957 rorl $16, %edx
958 movb %dl, 6(%edi)
959 shrl $16, %edx
960.L016dj6:
961 movb %dh, 5(%edi)
962.L017dj5:
963 movb %dl, 4(%edi)
964.L018dj4:
965 movl %ecx, (%edi)
966 jmp .L019djend
967.L020dj3:
968 rorl $16, %ecx
969 movb %cl, 2(%edi)
970 sall $16, %ecx
971.L021dj2:
972 movb %ch, 1(%esi)
973.L022dj1:
974 movb %cl, (%esi)
975.L019djend:
976 jmp .L003finish
977.align ALIGN
978.L003finish:
979 movl 60(%esp), %ecx
980 addl $24, %esp
981 movl %eax, (%ecx)
982 movl %ebx, 4(%ecx)
983 popl %edi
984 popl %esi
985 popl %ebx
986 popl %ebp
987 ret
988.align ALIGN
989.L004cbc_enc_jmp_table:
990 .long 0
991 .long .L012ej1
992 .long .L011ej2
993 .long .L010ej3
994 .long .L008ej4
995 .long .L007ej5
996 .long .L006ej6
997 .long .L005ej7
998.align ALIGN
999.L023cbc_dec_jmp_table:
1000 .long 0
1001 .long .L022dj1
1002 .long .L021dj2
1003 .long .L020dj3
1004 .long .L018dj4
1005 .long .L017dj5
1006 .long .L016dj6
1007 .long .L015dj7
1008.CAST_cbc_encrypt_end:
1009 SIZE(CAST_cbc_encrypt,.CAST_cbc_encrypt_end-CAST_cbc_encrypt)
1010.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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61 61
62/* The input and output encrypted as though 64bit cfb mode is being 62/* The input and output encrypted as though 64bit cfb mode is being
@@ -64,14 +64,9 @@
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66 66
67void CAST_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) 67void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
68unsigned char *in; 68 long length, CAST_KEY *schedule, unsigned char *ivec,
69unsigned char *out; 69 int *num, int enc)
70long length;
71CAST_KEY *schedule;
72unsigned char *ivec;
73int *num;
74int encrypt;
75 { 70 {
76 register CAST_LONG v0,v1,t; 71 register CAST_LONG v0,v1,t;
77 register int n= *num; 72 register int n= *num;
@@ -79,8 +74,8 @@ int encrypt;
79 CAST_LONG ti[2]; 74 CAST_LONG ti[2];
80 unsigned char *iv,c,cc; 75 unsigned char *iv,c,cc;
81 76
82 iv=(unsigned char *)ivec; 77 iv=ivec;
83 if (encrypt) 78 if (enc)
84 { 79 {
85 while (l--) 80 while (l--)
86 { 81 {
@@ -89,10 +84,10 @@ int encrypt;
89 n2l(iv,v0); ti[0]=v0; 84 n2l(iv,v0); ti[0]=v0;
90 n2l(iv,v1); ti[1]=v1; 85 n2l(iv,v1); ti[1]=v1;
91 CAST_encrypt((CAST_LONG *)ti,schedule); 86 CAST_encrypt((CAST_LONG *)ti,schedule);
92 iv=(unsigned char *)ivec; 87 iv=ivec;
93 t=ti[0]; l2n(t,iv); 88 t=ti[0]; l2n(t,iv);
94 t=ti[1]; l2n(t,iv); 89 t=ti[1]; l2n(t,iv);
95 iv=(unsigned char *)ivec; 90 iv=ivec;
96 } 91 }
97 c= *(in++)^iv[n]; 92 c= *(in++)^iv[n];
98 *(out++)=c; 93 *(out++)=c;
@@ -109,10 +104,10 @@ int encrypt;
109 n2l(iv,v0); ti[0]=v0; 104 n2l(iv,v0); ti[0]=v0;
110 n2l(iv,v1); ti[1]=v1; 105 n2l(iv,v1); ti[1]=v1;
111 CAST_encrypt((CAST_LONG *)ti,schedule); 106 CAST_encrypt((CAST_LONG *)ti,schedule);
112 iv=(unsigned char *)ivec; 107 iv=ivec;
113 t=ti[0]; l2n(t,iv); 108 t=ti[0]; l2n(t,iv);
114 t=ti[1]; l2n(t,iv); 109 t=ti[1]; l2n(t,iv);
115 iv=(unsigned char *)ivec; 110 iv=ivec;
116 } 111 }
117 cc= *(in++); 112 cc= *(in++);
118 c=iv[n]; 113 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61#include <openssl/opensslv.h>
61 62
62char *CAST_version="CAST part of SSLeay 0.9.0b 29-Jun-1998"; 63char *CAST_version="CAST" OPENSSL_VERSION_PTEXT;
63 64
64void CAST_ecb_encrypt(in, out, ks, encrypt) 65void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
65unsigned char *in; 66 CAST_KEY *ks, int enc)
66unsigned char *out;
67CAST_KEY *ks;
68int encrypt;
69 { 67 {
70 CAST_LONG l,d[2]; 68 CAST_LONG l,d[2];
71 69
72 n2l(in,l); d[0]=l; 70 n2l(in,l); d[0]=l;
73 n2l(in,l); d[1]=l; 71 n2l(in,l); d[1]=l;
74 if (encrypt) 72 if (enc)
75 CAST_encrypt(d,ks); 73 CAST_encrypt(d,ks);
76 else 74 else
77 CAST_decrypt(d,ks); 75 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61 61
62void CAST_encrypt(data,key) 62void CAST_encrypt(CAST_LONG *data, CAST_KEY *key)
63CAST_LONG *data;
64CAST_KEY *key;
65 { 63 {
66 register CAST_LONG l,r,*k,t; 64 register CAST_LONG l,r,*k,t;
67 65
@@ -81,18 +79,19 @@ CAST_KEY *key;
81 E_CAST( 9,k,r,l,+,^,-); 79 E_CAST( 9,k,r,l,+,^,-);
82 E_CAST(10,k,l,r,^,-,+); 80 E_CAST(10,k,l,r,^,-,+);
83 E_CAST(11,k,r,l,-,+,^); 81 E_CAST(11,k,r,l,-,+,^);
84 E_CAST(12,k,l,r,+,^,-); 82 if(!key->short_key)
85 E_CAST(13,k,r,l,^,-,+); 83 {
86 E_CAST(14,k,l,r,-,+,^); 84 E_CAST(12,k,l,r,+,^,-);
87 E_CAST(15,k,r,l,+,^,-); 85 E_CAST(13,k,r,l,^,-,+);
86 E_CAST(14,k,l,r,-,+,^);
87 E_CAST(15,k,r,l,+,^,-);
88 }
88 89
89 data[1]=l&0xffffffffL; 90 data[1]=l&0xffffffffL;
90 data[0]=r&0xffffffffL; 91 data[0]=r&0xffffffffL;
91 } 92 }
92 93
93void CAST_decrypt(data,key) 94void CAST_decrypt(CAST_LONG *data, CAST_KEY *key)
94CAST_LONG *data;
95CAST_KEY *key;
96 { 95 {
97 register CAST_LONG l,r,*k,t; 96 register CAST_LONG l,r,*k,t;
98 97
@@ -100,10 +99,13 @@ CAST_KEY *key;
100 l=data[0]; 99 l=data[0];
101 r=data[1]; 100 r=data[1];
102 101
103 E_CAST(15,k,l,r,+,^,-); 102 if(!key->short_key)
104 E_CAST(14,k,r,l,-,+,^); 103 {
105 E_CAST(13,k,l,r,^,-,+); 104 E_CAST(15,k,l,r,+,^,-);
106 E_CAST(12,k,r,l,+,^,-); 105 E_CAST(14,k,r,l,-,+,^);
106 E_CAST(13,k,l,r,^,-,+);
107 E_CAST(12,k,r,l,+,^,-);
108 }
107 E_CAST(11,k,l,r,-,+,^); 109 E_CAST(11,k,l,r,-,+,^);
108 E_CAST(10,k,r,l,^,-,+); 110 E_CAST(10,k,r,l,^,-,+);
109 E_CAST( 9,k,l,r,+,^,-); 111 E_CAST( 9,k,l,r,+,^,-);
@@ -121,20 +123,15 @@ CAST_KEY *key;
121 data[0]=r&0xffffffffL; 123 data[0]=r&0xffffffffL;
122 } 124 }
123 125
124void CAST_cbc_encrypt(in, out, length, ks, iv, encrypt) 126void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
125unsigned char *in; 127 CAST_KEY *ks, unsigned char *iv, int enc)
126unsigned char *out;
127long length;
128CAST_KEY *ks;
129unsigned char *iv;
130int encrypt;
131 { 128 {
132 register CAST_LONG tin0,tin1; 129 register CAST_LONG tin0,tin1;
133 register CAST_LONG tout0,tout1,xor0,xor1; 130 register CAST_LONG tout0,tout1,xor0,xor1;
134 register long l=length; 131 register long l=length;
135 CAST_LONG tin[2]; 132 CAST_LONG tin[2];
136 133
137 if (encrypt) 134 if (enc)
138 { 135 {
139 n2l(iv,tout0); 136 n2l(iv,tout0);
140 n2l(iv,tout1); 137 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61 61
62/* The input and output encrypted as though 64bit ofb mode is being 62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the 63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66void CAST_ofb64_encrypt(in, out, length, schedule, ivec, num) 66void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
67unsigned char *in; 67 long length, CAST_KEY *schedule, unsigned char *ivec,
68unsigned char *out; 68 int *num)
69long length;
70CAST_KEY *schedule;
71unsigned char *ivec;
72int *num;
73 { 69 {
74 register CAST_LONG v0,v1,t; 70 register CAST_LONG v0,v1,t;
75 register int n= *num; 71 register int n= *num;
@@ -80,7 +76,7 @@ int *num;
80 unsigned char *iv; 76 unsigned char *iv;
81 int save=0; 77 int save=0;
82 78
83 iv=(unsigned char *)ivec; 79 iv=ivec;
84 n2l(iv,v0); 80 n2l(iv,v0);
85 n2l(iv,v1); 81 n2l(iv,v1);
86 ti[0]=v0; 82 ti[0]=v0;
@@ -105,7 +101,7 @@ int *num;
105 { 101 {
106 v0=ti[0]; 102 v0=ti[0];
107 v1=ti[1]; 103 v1=ti[1];
108 iv=(unsigned char *)ivec; 104 iv=ivec;
109 l2n(v0,iv); 105 l2n(v0,iv);
110 l2n(v1,iv); 106 l2n(v1,iv);
111 } 107 }
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "cast.h" 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61#include "cast_s.h" 61#include "cast_s.h"
62 62
@@ -72,10 +72,7 @@
72#define S6 CAST_S_table6 72#define S6 CAST_S_table6
73#define S7 CAST_S_table7 73#define S7 CAST_S_table7
74 74
75void CAST_set_key(key,len,data) 75void CAST_set_key(CAST_KEY *key, int len, unsigned char *data)
76CAST_KEY *key;
77int len;
78unsigned char *data;
79 { 76 {
80 CAST_LONG x[16]; 77 CAST_LONG x[16];
81 CAST_LONG z[16]; 78 CAST_LONG z[16];
@@ -88,6 +85,10 @@ unsigned char *data;
88 if (len > 16) len=16; 85 if (len > 16) len=16;
89 for (i=0; i<len; i++) 86 for (i=0; i<len; i++)
90 x[i]=data[i]; 87 x[i]=data[i];
88 if(len <= 10)
89 key->short_key=1;
90 else
91 key->short_key=0;
91 92
92 K= &k[0]; 93 K= &k[0];
93 X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL; 94 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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifdef NO_CAST
67#error CAST is disabled.
68#endif
69
66#define CAST_ENCRYPT 1 70#define CAST_ENCRYPT 1
67#define CAST_DECRYPT 0 71#define CAST_DECRYPT 0
68 72
@@ -74,33 +78,23 @@ extern "C" {
74typedef struct cast_key_st 78typedef struct cast_key_st
75 { 79 {
76 CAST_LONG data[32]; 80 CAST_LONG data[32];
81 int short_key; /* Use reduced rounds for short key */
77 } CAST_KEY; 82 } CAST_KEY;
78 83
79#ifndef NOPROTO
80 84
81void CAST_set_key(CAST_KEY *key, int len, unsigned char *data); 85void CAST_set_key(CAST_KEY *key, int len, unsigned char *data);
82void CAST_ecb_encrypt(unsigned char *in,unsigned char *out,CAST_KEY *key, 86void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key,
83 int enc); 87 int enc);
84void CAST_encrypt(CAST_LONG *data,CAST_KEY *key); 88void CAST_encrypt(CAST_LONG *data,CAST_KEY *key);
85void CAST_decrypt(CAST_LONG *data,CAST_KEY *key); 89void CAST_decrypt(CAST_LONG *data,CAST_KEY *key);
86void CAST_cbc_encrypt(unsigned char *in, unsigned char *out, long length, 90void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
87 CAST_KEY *ks, unsigned char *iv, int enc); 91 CAST_KEY *ks, unsigned char *iv, int enc);
88void CAST_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, 92void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out,
89 CAST_KEY *schedule, unsigned char *ivec, int *num, int enc); 93 long length, CAST_KEY *schedule, unsigned char *ivec,
90void CAST_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, 94 int *num, int enc);
91 CAST_KEY *schedule, unsigned char *ivec, int *num); 95void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out,
92 96 long length, CAST_KEY *schedule, unsigned char *ivec,
93#else 97 int *num);
94
95void CAST_set_key();
96void CAST_ecb_encrypt();
97void CAST_encrypt();
98void CAST_decrypt();
99void CAST_cbc_encrypt();
100void CAST_cfb64_encrypt();
101void CAST_ofb64_encrypt();
102
103#endif
104 98
105#ifdef __cplusplus 99#ifdef __cplusplus
106} 100}
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 @@
60#include <stdlib.h> 60#include <stdlib.h>
61#endif 61#endif
62 62
63
64#include "openssl/e_os.h" /* OPENSSL_EXTERN */
65
63#undef c2l 66#undef c2l
64#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ 67#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
65 l|=((unsigned long)(*((c)++)))<< 8L, \ 68 l|=((unsigned long)(*((c)++)))<< 8L, \
@@ -213,12 +216,11 @@
213 } 216 }
214#endif 217#endif
215 218
216extern CAST_LONG CAST_S_table0[256]; 219OPENSSL_EXTERN CAST_LONG CAST_S_table0[256];
217extern CAST_LONG CAST_S_table1[256]; 220OPENSSL_EXTERN CAST_LONG CAST_S_table1[256];
218extern CAST_LONG CAST_S_table2[256]; 221OPENSSL_EXTERN CAST_LONG CAST_S_table2[256];
219extern CAST_LONG CAST_S_table3[256]; 222OPENSSL_EXTERN CAST_LONG CAST_S_table3[256];
220extern CAST_LONG CAST_S_table4[256]; 223OPENSSL_EXTERN CAST_LONG CAST_S_table4[256];
221extern CAST_LONG CAST_S_table5[256]; 224OPENSSL_EXTERN CAST_LONG CAST_S_table5[256];
222extern CAST_LONG CAST_S_table6[256]; 225OPENSSL_EXTERN CAST_LONG CAST_S_table6[256];
223extern CAST_LONG CAST_S_table7[256]; 226OPENSSL_EXTERN CAST_LONG CAST_S_table7[256];
224
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 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58CAST_LONG CAST_S_table0[256]={ 58OPENSSL_GLOBAL CAST_LONG CAST_S_table0[256]={
59 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a, 59 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a,
60 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949, 60 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949,
61 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675, 61 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675,
@@ -121,7 +121,7 @@ CAST_LONG CAST_S_table0[256]={
121 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d, 121 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d,
122 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf, 122 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf,
123 }; 123 };
124CAST_LONG CAST_S_table1[256]={ 124OPENSSL_GLOBAL CAST_LONG CAST_S_table1[256]={
125 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380, 125 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380,
126 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651, 126 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651,
127 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba, 127 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba,
@@ -187,7 +187,7 @@ CAST_LONG CAST_S_table1[256]={
187 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef, 187 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef,
188 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1, 188 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1,
189 }; 189 };
190CAST_LONG CAST_S_table2[256]={ 190OPENSSL_GLOBAL CAST_LONG CAST_S_table2[256]={
191 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907, 191 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907,
192 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90, 192 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90,
193 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae, 193 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae,
@@ -253,7 +253,7 @@ CAST_LONG CAST_S_table2[256]={
253 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5, 253 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5,
254 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783, 254 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783,
255 }; 255 };
256CAST_LONG CAST_S_table3[256]={ 256OPENSSL_GLOBAL CAST_LONG CAST_S_table3[256]={
257 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298, 257 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298,
258 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1, 258 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1,
259 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120, 259 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120,
@@ -319,7 +319,7 @@ CAST_LONG CAST_S_table3[256]={
319 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e, 319 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e,
320 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2, 320 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2,
321 }; 321 };
322CAST_LONG CAST_S_table4[256]={ 322OPENSSL_GLOBAL CAST_LONG CAST_S_table4[256]={
323 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911, 323 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911,
324 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f, 324 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f,
325 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00, 325 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00,
@@ -385,7 +385,7 @@ CAST_LONG CAST_S_table4[256]={
385 0xe822fe15,0x88570983,0x750e6249,0xda627e55, 385 0xe822fe15,0x88570983,0x750e6249,0xda627e55,
386 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4, 386 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4,
387 }; 387 };
388CAST_LONG CAST_S_table5[256]={ 388OPENSSL_GLOBAL CAST_LONG CAST_S_table5[256]={
389 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c, 389 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c,
390 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac, 390 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac,
391 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9, 391 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9,
@@ -451,7 +451,7 @@ CAST_LONG CAST_S_table5[256]={
451 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454, 451 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454,
452 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f, 452 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f,
453 }; 453 };
454CAST_LONG CAST_S_table6[256]={ 454OPENSSL_GLOBAL CAST_LONG CAST_S_table6[256]={
455 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693, 455 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693,
456 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f, 456 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f,
457 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82, 457 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82,
@@ -517,7 +517,7 @@ CAST_LONG CAST_S_table6[256]={
517 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada, 517 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada,
518 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3, 518 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3,
519 }; 519 };
520CAST_LONG CAST_S_table7[256]={ 520OPENSSL_GLOBAL CAST_LONG CAST_S_table7[256]={
521 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095, 521 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095,
522 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5, 522 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5,
523 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174, 523 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174,
diff --git a/src/lib/libcrypto/cast/cast_spd.c b/src/lib/libcrypto/cast/cast_spd.c
index ab75e65386..c0726906c2 100644
--- a/src/lib/libcrypto/cast/cast_spd.c
+++ b/src/lib/libcrypto/cast/cast_spd.c
@@ -59,19 +59,17 @@
59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ 59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ 60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61 61
62#ifndef MSDOS 62#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
63#define TIMES 63#define TIMES
64#endif 64#endif
65 65
66#include <stdio.h> 66#include <stdio.h>
67#ifndef MSDOS 67
68#include <unistd.h> 68#include <openssl/e_os2.h>
69#else 69#include OPENSSL_UNISTD_IO
70#include <io.h> 70OPENSSL_DECLARE_EXIT
71extern int exit(); 71
72#endif
73#include <signal.h> 72#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX 73#ifndef _IRIX
76#include <time.h> 74#include <time.h>
77#endif 75#endif
@@ -79,34 +77,31 @@ extern int exit();
79#include <sys/types.h> 77#include <sys/types.h>
80#include <sys/times.h> 78#include <sys/times.h>
81#endif 79#endif
82#else /* VMS */ 80
83#include <types.h> 81/* Depending on the VMS version, the tms structure is perhaps defined.
84struct tms { 82 The __TMS macro will show if it was. If it wasn't defined, we should
85 time_t tms_utime; 83 undefine TIMES, since that tells the rest of the program how things
86 time_t tms_stime; 84 should be handled. -- Richard Levitte */
87 time_t tms_uchild; /* I dunno... */ 85#if defined(VMS) && defined(__DECC) && !defined(__TMS)
88 time_t tms_uchildsys; /* so these names are a guess :-) */ 86#undef TIMES
89 }
90#endif 87#endif
88
91#ifndef TIMES 89#ifndef TIMES
92#include <sys/timeb.h> 90#include <sys/timeb.h>
93#endif 91#endif
94 92
95#ifdef sun 93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
96#include <limits.h> 95#include <limits.h>
97#include <sys/param.h> 96#include <sys/param.h>
98#endif 97#endif
99 98
100#include "cast.h" 99#include <openssl/cast.h>
101 100
102/* The following if from times(3) man page. It may need to be changed */ 101/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ 102#ifndef HZ
104#ifndef CLK_TCK 103#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0 104#define HZ 100.0
109#endif
110#else /* CLK_TCK */ 105#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK) 106#define HZ ((double)CLK_TCK)
112#endif 107#endif
@@ -115,12 +110,7 @@ struct tms {
115#define BUFSIZE ((long)1024) 110#define BUFSIZE ((long)1024)
116long run=0; 111long run=0;
117 112
118#ifndef NOPROTO
119double Time_F(int s); 113double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM 114#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX) 115#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void 116#define SIGRETTYPE void
@@ -128,14 +118,8 @@ double Time_F();
128#define SIGRETTYPE int 118#define SIGRETTYPE int
129#endif 119#endif
130 120
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig); 121SIGRETTYPE sig_done(int sig);
133#else 122SIGRETTYPE sig_done(int sig)
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 { 123 {
140 signal(SIGALRM,sig_done); 124 signal(SIGALRM,sig_done);
141 run=0; 125 run=0;
@@ -148,8 +132,7 @@ int sig;
148#define START 0 132#define START 0
149#define STOP 1 133#define STOP 1
150 134
151double Time_F(s) 135double Time_F(int s)
152int s;
153 { 136 {
154 double ret; 137 double ret;
155#ifdef TIMES 138#ifdef TIMES
@@ -185,9 +168,7 @@ int s;
185#endif 168#endif
186 } 169 }
187 170
188int main(argc,argv) 171int main(int argc, char **argv)
189int argc;
190char **argv;
191 { 172 {
192 long count; 173 long count;
193 static unsigned char buf[BUFSIZE]; 174 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 @@
59/* define PART1, PART2, PART3 or PART4 to build only with a few of the options. 59/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */ 60 * This is for machines with 64k code segment size restrictions. */
61 61
62#ifndef MSDOS 62#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
63#define TIMES 63#define TIMES
64#endif 64#endif
65 65
66#include <stdio.h> 66#include <stdio.h>
67#ifndef MSDOS 67
68#include <unistd.h> 68#include <openssl/e_os2.h>
69#else 69#include OPENSSL_UNISTD_IO
70#include <io.h> 70OPENSSL_DECLARE_EXIT
71extern void exit(); 71
72#endif
73#include <signal.h> 72#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX 73#ifndef _IRIX
76#include <time.h> 74#include <time.h>
77#endif 75#endif
@@ -79,25 +77,26 @@ extern void exit();
79#include <sys/types.h> 77#include <sys/types.h>
80#include <sys/times.h> 78#include <sys/times.h>
81#endif 79#endif
82#else /* VMS */ 80
83#include <types.h> 81/* Depending on the VMS version, the tms structure is perhaps defined.
84struct tms { 82 The __TMS macro will show if it was. If it wasn't defined, we should
85 time_t tms_utime; 83 undefine TIMES, since that tells the rest of the program how things
86 time_t tms_stime; 84 should be handled. -- Richard Levitte */
87 time_t tms_uchild; /* I dunno... */ 85#if defined(VMS) && defined(__DECC) && !defined(__TMS)
88 time_t tms_uchildsys; /* so these names are a guess :-) */ 86#undef TIMES
89 }
90#endif 87#endif
88
91#ifndef TIMES 89#ifndef TIMES
92#include <sys/timeb.h> 90#include <sys/timeb.h>
93#endif 91#endif
94 92
95#ifdef sun 93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
96#include <limits.h> 95#include <limits.h>
97#include <sys/param.h> 96#include <sys/param.h>
98#endif 97#endif
99 98
100#include "cast.h" 99#include <openssl/cast.h>
101 100
102#define CAST_DEFAULT_OPTIONS 101#define CAST_DEFAULT_OPTIONS
103 102
@@ -136,11 +135,7 @@ struct tms {
136#ifndef HZ 135#ifndef HZ
137# ifndef CLK_TCK 136# ifndef CLK_TCK
138# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ 137# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
139# ifndef VMS 138# define HZ 100.0
140# define HZ 100.0
141# else /* VMS */
142# define HZ 100.0
143# endif
144# else /* _BSD_CLK_TCK_ */ 139# else /* _BSD_CLK_TCK_ */
145# define HZ ((double)_BSD_CLK_TCK_) 140# define HZ ((double)_BSD_CLK_TCK_)
146# endif 141# endif
@@ -152,12 +147,7 @@ struct tms {
152#define BUFSIZE ((long)1024) 147#define BUFSIZE ((long)1024)
153long run=0; 148long run=0;
154 149
155#ifndef NOPROTO
156double Time_F(int s); 150double Time_F(int s);
157#else
158double Time_F();
159#endif
160
161#ifdef SIGALRM 151#ifdef SIGALRM
162#if defined(__STDC__) || defined(sgi) 152#if defined(__STDC__) || defined(sgi)
163#define SIGRETTYPE void 153#define SIGRETTYPE void
@@ -165,14 +155,8 @@ double Time_F();
165#define SIGRETTYPE int 155#define SIGRETTYPE int
166#endif 156#endif
167 157
168#ifndef NOPROTO
169SIGRETTYPE sig_done(int sig); 158SIGRETTYPE sig_done(int sig);
170#else 159SIGRETTYPE sig_done(int sig)
171SIGRETTYPE sig_done();
172#endif
173
174SIGRETTYPE sig_done(sig)
175int sig;
176 { 160 {
177 signal(SIGALRM,sig_done); 161 signal(SIGALRM,sig_done);
178 run=0; 162 run=0;
@@ -185,8 +169,7 @@ int sig;
185#define START 0 169#define START 0
186#define STOP 1 170#define STOP 1
187 171
188double Time_F(s) 172double Time_F(int s)
189int s;
190 { 173 {
191 double ret; 174 double ret;
192#ifdef TIMES 175#ifdef TIMES
@@ -247,9 +230,7 @@ int s;
247 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ 230 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
248 tm[index]*8,1.0e6/tm[index]); 231 tm[index]*8,1.0e6/tm[index]);
249 232
250int main(argc,argv) 233int main(int argc, char **argv)
251int argc;
252char **argv;
253 { 234 {
254 long count; 235 long count;
255 static unsigned char buf[BUFSIZE]; 236 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)
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <stdlib.h> 34#include <stdlib.h>
35#include "cast.h" 35#include <openssl/cast.h>
36 36
37void main(int argc,char *argv[]) 37void main(int argc,char *argv[])
38 { 38 {
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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include "cast.h"
63 62
64/* #define FULL_TEST */ 63#ifdef NO_CAST
64int main(int argc, char *argv[])
65{
66 printf("No CAST support\n");
67 return(0);
68}
69#else
70#include <openssl/cast.h>
71
72#define FULL_TEST
65 73
66unsigned char k[16]={ 74unsigned char k[16]={
67 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, 75 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
@@ -70,7 +78,7 @@ unsigned char k[16]={
70 78
71unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; 79unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
72 80
73int k_len[3]={16,10}; 81int k_len[3]={16,10,5};
74unsigned char c[3][8]={ 82unsigned char c[3][8]={
75 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, 83 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
76 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, 84 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
@@ -120,104 +128,103 @@ static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
120 }; 128 };
121#endif 129#endif
122 130
123int main(argc,argv) 131int main(int argc, char *argv[])
124int argc; 132 {
125char *argv[];
126 {
127#ifdef FULL_TEST 133#ifdef FULL_TEST
128 long l; 134 long l;
129 CAST_KEY key_b; 135 CAST_KEY key_b;
130#endif 136#endif
131 int i,z,err=0; 137 int i,z,err=0;
132 CAST_KEY key; 138 CAST_KEY key;
133 139
134 for (z=0; z<1; z++) 140 for (z=0; z<3; z++)
135 { 141 {
136 CAST_set_key(&key,k_len[z],k); 142 CAST_set_key(&key,k_len[z],k);
137 143
138 CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT); 144 CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT);
139 if (memcmp(out,&(c[z][0]),8) != 0) 145 if (memcmp(out,&(c[z][0]),8) != 0)
140 { 146 {
141 printf("ecb cast error encrypting\n"); 147 printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8);
142 printf("got :"); 148 printf("got :");
143 for (i=0; i<8; i++) 149 for (i=0; i<8; i++)
144 printf("%02X ",out[i]); 150 printf("%02X ",out[i]);
145 printf("\n"); 151 printf("\n");
146 printf("expected:"); 152 printf("expected:");
147 for (i=0; i<8; i++) 153 for (i=0; i<8; i++)
148 printf("%02X ",c[z][i]); 154 printf("%02X ",c[z][i]);
149 err=20; 155 err=20;
150 printf("\n"); 156 printf("\n");
151 } 157 }
152 158
153 CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT); 159 CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT);
154 if (memcmp(out,in,8) != 0) 160 if (memcmp(out,in,8) != 0)
155 { 161 {
156 printf("ecb cast error decrypting\n"); 162 printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8);
157 printf("got :"); 163 printf("got :");
158 for (i=0; i<8; i++) 164 for (i=0; i<8; i++)
159 printf("%02X ",out[i]); 165 printf("%02X ",out[i]);
160 printf("\n"); 166 printf("\n");
161 printf("expected:"); 167 printf("expected:");
162 for (i=0; i<8; i++) 168 for (i=0; i<8; i++)
163 printf("%02X ",in[i]); 169 printf("%02X ",in[i]);
164 printf("\n"); 170 printf("\n");
165 err=3; 171 err=3;
166 } 172 }
167 } 173 }
168 if (err == 0) printf("ecb cast5 ok\n"); 174 if (err == 0)
175 printf("ecb cast5 ok\n");
169 176
170#ifdef FULL_TEST 177#ifdef FULL_TEST
171 { 178 {
172 unsigned char out_a[16],out_b[16]; 179 unsigned char out_a[16],out_b[16];
173 static char *hex="0123456789ABCDEF"; 180 static char *hex="0123456789ABCDEF";
174 181
175 printf("This test will take some time...."); 182 printf("This test will take some time....");
176 fflush(stdout); 183 fflush(stdout);
177 memcpy(out_a,in_a,sizeof(in_a)); 184 memcpy(out_a,in_a,sizeof(in_a));
178 memcpy(out_b,in_b,sizeof(in_b)); 185 memcpy(out_b,in_b,sizeof(in_b));
179 i=1; 186 i=1;
180 187
181 for (l=0; l<1000000L; l++) 188 for (l=0; l<1000000L; l++)
182 { 189 {
183 CAST_set_key(&key_b,16,out_b); 190 CAST_set_key(&key_b,16,out_b);
184 CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); 191 CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT);
185 CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); 192 CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT);
186 CAST_set_key(&key,16,out_a); 193 CAST_set_key(&key,16,out_a);
187 CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); 194 CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT);
188 CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); 195 CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT);
189 if ((l & 0xffff) == 0xffff) 196 if ((l & 0xffff) == 0xffff)
190 { 197 {
191 printf("%c",hex[i&0x0f]); 198 printf("%c",hex[i&0x0f]);
192 fflush(stdout); 199 fflush(stdout);
193 i++; 200 i++;
194 } 201 }
195 } 202 }
196 203
197 if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || 204 if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) ||
198 (memcmp(out_b,c_b,sizeof(c_b)) != 0)) 205 (memcmp(out_b,c_b,sizeof(c_b)) != 0))
199 { 206 {
200 printf("\n"); 207 printf("\n");
201 printf("Error\n"); 208 printf("Error\n");
202 209
203 printf("A out ="); 210 printf("A out =");
204 for (i=0; i<16; i++) printf("%02X ",out_a[i]); 211 for (i=0; i<16; i++) printf("%02X ",out_a[i]);
205 printf("\nactual="); 212 printf("\nactual=");
206 for (i=0; i<16; i++) printf("%02X ",c_a[i]); 213 for (i=0; i<16; i++) printf("%02X ",c_a[i]);
207 printf("\n"); 214 printf("\n");
208 215
209 printf("B out ="); 216 printf("B out =");
210 for (i=0; i<16; i++) printf("%02X ",out_b[i]); 217 for (i=0; i<16; i++) printf("%02X ",out_b[i]);
211 printf("\nactual="); 218 printf("\nactual=");
212 for (i=0; i<16; i++) printf("%02X ",c_b[i]); 219 for (i=0; i<16; i++) printf("%02X ",c_b[i]);
213 printf("\n"); 220 printf("\n");
214 } 221 }
215 else 222 else
216 printf(" ok\n"); 223 printf(" ok\n");
217 } 224 }
218#endif 225#endif
219 226
220 exit(err); 227 exit(err);
221 return(err); 228 return(err);
222 } 229 }
223 230#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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=conf
19ERRC=conf_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= 21TEST=
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= conf.c $(ERRC).c 25LIBSRC= conf.c conf_err.c
26 26
27LIBOBJ= conf.o $(ERRC).o 27LIBOBJ= conf.o conf_err.o
28 28
29SRC= $(LIBSRC) 29SRC= $(LIBSRC)
30 30
@@ -40,24 +40,23 @@ all: lib
40 40
41lib: $(LIBOBJ) 41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ) 42 $(AR) $(LIB) $(LIBOBJ)
43 sh $(TOP)/util/ranlib.sh $(LIB) 43 $(RANLIB) $(LIB)
44 @touch lib 44 @touch lib
45 45
46files: 46files:
47 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48 48
49links: 49links:
50 /bin/rm -f Makefile 50 @$(TOP)/util/point.sh Makefile.ssl Makefile
51 $(TOP)/util/point.sh Makefile.ssl Makefile ; 51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 $(TOP)/util/mklink.sh ../../test $(TEST) 53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54 $(TOP)/util/mklink.sh ../../apps $(APPS)
55 54
56install: 55install:
57 @for i in $(EXHEADER) ; \ 56 @for i in $(EXHEADER) ; \
58 do \ 57 do \
59 (cp $$i $(INSTALLTOP)/include/$$i; \ 58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
60 chmod 644 $(INSTALLTOP)/include/$$i ); \ 59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
61 done; 60 done;
62 61
63tags: 62tags:
@@ -69,17 +68,25 @@ lint:
69 lint -DLINT $(INCLUDES) $(SRC)>fluff 68 lint -DLINT $(INCLUDES) $(SRC)>fluff
70 69
71depend: 70depend:
72 $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) 71 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC)
73 72
74dclean: 73dclean:
75 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
76 mv -f Makefile.new $(MAKEFILE) 75 mv -f Makefile.new $(MAKEFILE)
77 76
78clean: 77clean:
79 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
80
81errors:
82 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
83 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
84 79
85# DO NOT DELETE THIS LINE -- make depend depends on it. 80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82conf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
83conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
84conf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
85conf.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
86conf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
87conf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
88conf.o: ../cryptlib.h conf_lcl.h
89conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
90conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/err.h
91conf_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslv.h
92conf_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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "conf.h" 60#include <openssl/conf.h>
61 61
62void print_conf(CONF_VALUE *cv); 62void print_conf(CONF_VALUE *cv);
63 63
@@ -66,7 +66,7 @@ main()
66 LHASH *conf; 66 LHASH *conf;
67 long l; 67 long l;
68 68
69 conf=CONF_load(NULL,"../../apps/ssleay.cnf",&l); 69 conf=CONF_load(NULL,"../../apps/openssl.cnf",&l);
70 if (conf == NULL) 70 if (conf == NULL)
71 { 71 {
72 fprintf(stderr,"error loading config, line %ld\n",l); 72 fprintf(stderr,"error loading config, line %ld\n",l);
@@ -77,8 +77,7 @@ main()
77 } 77 }
78 78
79 79
80void print_conf(cv) 80void print_conf(CONF_VALUE *cv)
81CONF_VALUE *cv;
82 { 81 {
83 int i; 82 int i;
84 CONF_VALUE *v; 83 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "stack.h" 62#include <openssl/stack.h>
63#include "lhash.h" 63#include <openssl/lhash.h>
64#include "conf.h" 64#include <openssl/conf.h>
65#include "buffer.h" 65#include <openssl/buffer.h>
66#include "err.h" 66#include <openssl/err.h>
67 67
68#include "conf_lcl.h" 68#include "conf_lcl.h"
69 69
70#ifndef NOPROTO
71static void value_free_hash(CONF_VALUE *a, LHASH *conf); 70static void value_free_hash(CONF_VALUE *a, LHASH *conf);
72static void value_free_stack(CONF_VALUE *a,LHASH *conf); 71static void value_free_stack(CONF_VALUE *a,LHASH *conf);
73static unsigned long hash(CONF_VALUE *v); 72static unsigned long hash(CONF_VALUE *v);
74static int cmp(CONF_VALUE *a,CONF_VALUE *b); 73static int cmp_conf(CONF_VALUE *a,CONF_VALUE *b);
75static char *eat_ws(char *p); 74static char *eat_ws(char *p);
76static char *eat_alpha_numeric(char *p); 75static char *eat_alpha_numeric(char *p);
77static void clear_comments(char *p); 76static void clear_comments(char *p);
@@ -79,71 +78,84 @@ static int str_copy(LHASH *conf,char *section,char **to, char *from);
79static char *scan_quote(char *p); 78static char *scan_quote(char *p);
80static CONF_VALUE *new_section(LHASH *conf,char *section); 79static CONF_VALUE *new_section(LHASH *conf,char *section);
81static CONF_VALUE *get_section(LHASH *conf,char *section); 80static CONF_VALUE *get_section(LHASH *conf,char *section);
81#define scan_esc(p) ((((p)[1] == '\0')?(p++):(p+=2)),p)
82
83const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
84
85
86LHASH *CONF_load(LHASH *h, const char *file, long *line)
87 {
88 LHASH *ltmp;
89 FILE *in=NULL;
90
91#ifdef VMS
92 in=fopen(file,"r");
82#else 93#else
83static void value_free_hash(); 94 in=fopen(file,"rb");
84static void value_free_stack();
85static unsigned long hash();
86static int cmp();
87static char *eat_ws();
88static char *eat_alpha_numeric();
89static void clear_comments();
90static int str_copy();
91static char *scan_quote();
92static CONF_VALUE *new_section();
93static CONF_VALUE *get_section();
94#endif 95#endif
96 if (in == NULL)
97 {
98 SYSerr(SYS_F_FOPEN,get_last_sys_error());
99 ERR_set_error_data(BUF_strdup(file),
100 ERR_TXT_MALLOCED|ERR_TXT_STRING);
101 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
102 return NULL;
103 }
95 104
96#define scan_esc(p) ((*(++p) == '\0')?(p):(++p)) 105 ltmp = CONF_load_fp(h, in, line);
106 fclose(in);
97 107
98char *CONF_version="CONF part of SSLeay 0.9.0b 29-Jun-1998"; 108 return ltmp;
109}
110
111LHASH *CONF_load_fp(LHASH *h, FILE *in, long *line)
112{
113 BIO *btmp;
114 LHASH *ltmp;
115 if(!(btmp = BIO_new_fp(in, BIO_NOCLOSE))) {
116 CONFerr(CONF_F_CONF_LOAD_FP,ERR_R_BUF_LIB);
117 return NULL;
118 }
119 ltmp = CONF_load_bio(h, btmp, line);
120 BIO_free(btmp);
121 return ltmp;
122}
99 123
100LHASH *CONF_load(h,file,line) 124LHASH *CONF_load_bio(LHASH *h, BIO *in, long *line)
101LHASH *h;
102char *file;
103long *line;
104 { 125 {
105 LHASH *ret=NULL; 126 LHASH *ret=NULL;
106 FILE *in=NULL;
107#define BUFSIZE 512 127#define BUFSIZE 512
128 char btmp[16];
108 int bufnum=0,i,ii; 129 int bufnum=0,i,ii;
109 BUF_MEM *buff=NULL; 130 BUF_MEM *buff=NULL;
110 char *s,*p,*end; 131 char *s,*p,*end;
111 int again,n,eline=0; 132 int again,n;
133 long eline=0;
112 CONF_VALUE *v=NULL,*vv,*tv; 134 CONF_VALUE *v=NULL,*vv,*tv;
113 CONF_VALUE *sv=NULL; 135 CONF_VALUE *sv=NULL;
114 char *section=NULL,*buf; 136 char *section=NULL,*buf;
115 STACK *section_sk=NULL,*ts; 137 STACK_OF(CONF_VALUE) *section_sk=NULL,*ts;
116 char *start,*psection,*pname; 138 char *start,*psection,*pname;
117 139
118 if ((buff=BUF_MEM_new()) == NULL) 140 if ((buff=BUF_MEM_new()) == NULL)
119 { 141 {
120 CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB); 142 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
121 goto err;
122 }
123
124 in=fopen(file,"rb");
125 if (in == NULL)
126 {
127 SYSerr(SYS_F_FOPEN,get_last_sys_error());
128 ERR_set_error_data(BUF_strdup(file),
129 ERR_TXT_MALLOCED|ERR_TXT_STRING);
130 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
131 goto err; 143 goto err;
132 } 144 }
133 145
134 section=(char *)Malloc(10); 146 section=(char *)Malloc(10);
135 if (section == NULL) 147 if (section == NULL)
136 { 148 {
137 CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); 149 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
138 goto err; 150 goto err;
139 } 151 }
140 strcpy(section,"default"); 152 strcpy(section,"default");
141 153
142 if (h == NULL) 154 if (h == NULL)
143 { 155 {
144 if ((ret=lh_new(hash,cmp)) == NULL) 156 if ((ret=lh_new(hash,cmp_conf)) == NULL)
145 { 157 {
146 CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); 158 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
147 goto err; 159 goto err;
148 } 160 }
149 } 161 }
@@ -153,10 +165,11 @@ long *line;
153 sv=new_section(ret,section); 165 sv=new_section(ret,section);
154 if (sv == NULL) 166 if (sv == NULL)
155 { 167 {
156 CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION); 168 CONFerr(CONF_F_CONF_LOAD_BIO,
169 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
157 goto err; 170 goto err;
158 } 171 }
159 section_sk=(STACK *)sv->value; 172 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
160 173
161 bufnum=0; 174 bufnum=0;
162 for (;;) 175 for (;;)
@@ -164,12 +177,12 @@ long *line;
164 again=0; 177 again=0;
165 if (!BUF_MEM_grow(buff,bufnum+BUFSIZE)) 178 if (!BUF_MEM_grow(buff,bufnum+BUFSIZE))
166 { 179 {
167 CONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB); 180 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
168 goto err; 181 goto err;
169 } 182 }
170 p= &(buff->data[bufnum]); 183 p= &(buff->data[bufnum]);
171 *p='\0'; 184 *p='\0';
172 fgets(p,BUFSIZE-1,in); 185 BIO_gets(in, p, BUFSIZE-1);
173 p[BUFSIZE-1]='\0'; 186 p[BUFSIZE-1]='\0';
174 ii=i=strlen(p); 187 ii=i=strlen(p);
175 if (i == 0) break; 188 if (i == 0) break;
@@ -219,13 +232,23 @@ long *line;
219 if (IS_EOF(*s)) continue; /* blank line */ 232 if (IS_EOF(*s)) continue; /* blank line */
220 if (*s == '[') 233 if (*s == '[')
221 { 234 {
235 char *ss;
236
222 s++; 237 s++;
223 start=eat_ws(s); 238 start=eat_ws(s);
224 end=eat_alpha_numeric(start); 239 ss=start;
240again:
241 end=eat_alpha_numeric(ss);
225 p=eat_ws(end); 242 p=eat_ws(end);
226 if (*p != ']') 243 if (*p != ']')
227 { 244 {
228 CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_CLOSE_SQUARE_BRACKET); 245 if (*p != '\0')
246 {
247 ss=p;
248 goto again;
249 }
250 CONFerr(CONF_F_CONF_LOAD_BIO,
251 CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
229 goto err; 252 goto err;
230 } 253 }
231 *end='\0'; 254 *end='\0';
@@ -234,10 +257,11 @@ long *line;
234 sv=new_section(ret,section); 257 sv=new_section(ret,section);
235 if (sv == NULL) 258 if (sv == NULL)
236 { 259 {
237 CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION); 260 CONFerr(CONF_F_CONF_LOAD_BIO,
261 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
238 goto err; 262 goto err;
239 } 263 }
240 section_sk=(STACK *)sv->value; 264 section_sk=(STACK_OF(CONF_VALUE) *)sv->value;
241 continue; 265 continue;
242 } 266 }
243 else 267 else
@@ -256,7 +280,8 @@ long *line;
256 p=eat_ws(end); 280 p=eat_ws(end);
257 if (*p != '=') 281 if (*p != '=')
258 { 282 {
259 CONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_EQUAL_SIGN); 283 CONFerr(CONF_F_CONF_LOAD_BIO,
284 CONF_R_MISSING_EQUAL_SIGN);
260 goto err; 285 goto err;
261 } 286 }
262 *end='\0'; 287 *end='\0';
@@ -270,9 +295,10 @@ long *line;
270 p++; 295 p++;
271 *p='\0'; 296 *p='\0';
272 297
273 if ((v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))) == NULL) 298 if (!(v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))))
274 { 299 {
275 CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); 300 CONFerr(CONF_F_CONF_LOAD_BIO,
301 ERR_R_MALLOC_FAILURE);
276 goto err; 302 goto err;
277 } 303 }
278 if (psection == NULL) psection=section; 304 if (psection == NULL) psection=section;
@@ -280,7 +306,8 @@ long *line;
280 v->value=NULL; 306 v->value=NULL;
281 if (v->name == NULL) 307 if (v->name == NULL)
282 { 308 {
283 CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); 309 CONFerr(CONF_F_CONF_LOAD_BIO,
310 ERR_R_MALLOC_FAILURE);
284 goto err; 311 goto err;
285 } 312 }
286 strcpy(v->name,pname); 313 strcpy(v->name,pname);
@@ -293,10 +320,11 @@ long *line;
293 tv=new_section(ret,psection); 320 tv=new_section(ret,psection);
294 if (tv == NULL) 321 if (tv == NULL)
295 { 322 {
296 CONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION); 323 CONFerr(CONF_F_CONF_LOAD_BIO,
324 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
297 goto err; 325 goto err;
298 } 326 }
299 ts=(STACK *)tv->value; 327 ts=(STACK_OF(CONF_VALUE) *)tv->value;
300 } 328 }
301 else 329 else
302 { 330 {
@@ -304,15 +332,16 @@ long *line;
304 ts=section_sk; 332 ts=section_sk;
305 } 333 }
306 v->section=tv->section; 334 v->section=tv->section;
307 if (!sk_push(ts,(char *)v)) 335 if (!sk_CONF_VALUE_push(ts,v))
308 { 336 {
309 CONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE); 337 CONFerr(CONF_F_CONF_LOAD_BIO,
338 ERR_R_MALLOC_FAILURE);
310 goto err; 339 goto err;
311 } 340 }
312 vv=(CONF_VALUE *)lh_insert(ret,(char *)v); 341 vv=(CONF_VALUE *)lh_insert(ret,(char *)v);
313 if (vv != NULL) 342 if (vv != NULL)
314 { 343 {
315 sk_delete_ptr(ts,(char *)vv); 344 sk_CONF_VALUE_delete_ptr(ts,vv);
316 Free(vv->name); 345 Free(vv->name);
317 Free(vv->value); 346 Free(vv->value);
318 Free(vv); 347 Free(vv);
@@ -322,13 +351,13 @@ long *line;
322 } 351 }
323 if (buff != NULL) BUF_MEM_free(buff); 352 if (buff != NULL) BUF_MEM_free(buff);
324 if (section != NULL) Free(section); 353 if (section != NULL) Free(section);
325 if (in != NULL) fclose(in);
326 return(ret); 354 return(ret);
327err: 355err:
328 if (buff != NULL) BUF_MEM_free(buff); 356 if (buff != NULL) BUF_MEM_free(buff);
329 if (section != NULL) Free(section); 357 if (section != NULL) Free(section);
330 if (line != NULL) *line=eline; 358 if (line != NULL) *line=eline;
331 if (in != NULL) fclose(in); 359 sprintf(btmp,"%ld",eline);
360 ERR_add_error_data(2,"line ",btmp);
332 if ((h != ret) && (ret != NULL)) CONF_free(ret); 361 if ((h != ret) && (ret != NULL)) CONF_free(ret);
333 if (v != NULL) 362 if (v != NULL)
334 { 363 {
@@ -338,11 +367,8 @@ err:
338 } 367 }
339 return(NULL); 368 return(NULL);
340 } 369 }
341 370
342char *CONF_get_string(conf,section,name) 371char *CONF_get_string(LHASH *conf, char *section, char *name)
343LHASH *conf;
344char *section;
345char *name;
346 { 372 {
347 CONF_VALUE *v,vv; 373 CONF_VALUE *v,vv;
348 char *p; 374 char *p;
@@ -374,9 +400,7 @@ char *name;
374 return(Getenv(name)); 400 return(Getenv(name));
375 } 401 }
376 402
377static CONF_VALUE *get_section(conf,section) 403static CONF_VALUE *get_section(LHASH *conf, char *section)
378LHASH *conf;
379char *section;
380 { 404 {
381 CONF_VALUE *v,vv; 405 CONF_VALUE *v,vv;
382 406
@@ -387,23 +411,18 @@ char *section;
387 return(v); 411 return(v);
388 } 412 }
389 413
390STACK *CONF_get_section(conf,section) 414STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf, char *section)
391LHASH *conf;
392char *section;
393 { 415 {
394 CONF_VALUE *v; 416 CONF_VALUE *v;
395 417
396 v=get_section(conf,section); 418 v=get_section(conf,section);
397 if (v != NULL) 419 if (v != NULL)
398 return((STACK *)v->value); 420 return((STACK_OF(CONF_VALUE) *)v->value);
399 else 421 else
400 return(NULL); 422 return(NULL);
401 } 423 }
402 424
403long CONF_get_number(conf,section,name) 425long CONF_get_number(LHASH *conf, char *section, char *name)
404LHASH *conf;
405char *section;
406char *name;
407 { 426 {
408 char *str; 427 char *str;
409 long ret=0; 428 long ret=0;
@@ -420,8 +439,7 @@ char *name;
420 } 439 }
421 } 440 }
422 441
423void CONF_free(conf) 442void CONF_free(LHASH *conf)
424LHASH *conf;
425 { 443 {
426 if (conf == NULL) return; 444 if (conf == NULL) return;
427 445
@@ -436,9 +454,7 @@ LHASH *conf;
436 lh_free(conf); 454 lh_free(conf);
437 } 455 }
438 456
439static void value_free_hash(a,conf) 457static void value_free_hash(CONF_VALUE *a, LHASH *conf)
440CONF_VALUE *a;
441LHASH *conf;
442 { 458 {
443 if (a->name != NULL) 459 if (a->name != NULL)
444 { 460 {
@@ -446,9 +462,7 @@ LHASH *conf;
446 } 462 }
447 } 463 }
448 464
449static void value_free_stack(a,conf) 465static void value_free_stack(CONF_VALUE *a, LHASH *conf)
450CONF_VALUE *a;
451LHASH *conf;
452 { 466 {
453 CONF_VALUE *vv; 467 CONF_VALUE *vv;
454 STACK *sk; 468 STACK *sk;
@@ -469,8 +483,7 @@ LHASH *conf;
469 Free(a); 483 Free(a);
470 } 484 }
471 485
472static void clear_comments(p) 486static void clear_comments(char *p)
473char *p;
474 { 487 {
475 char *to; 488 char *to;
476 489
@@ -499,10 +512,7 @@ char *p;
499 } 512 }
500 } 513 }
501 514
502static int str_copy(conf,section,pto,from) 515static int str_copy(LHASH *conf, char *section, char **pto, char *from)
503LHASH *conf;
504char *section;
505char **pto,*from;
506 { 516 {
507 int q,r,rr=0,to=0,len=0; 517 int q,r,rr=0,to=0,len=0;
508 char *s,*e,*rp,*p,*rrp,*np,*cp,v; 518 char *s,*e,*rp,*p,*rrp,*np,*cp,v;
@@ -616,16 +626,14 @@ err:
616 return(0); 626 return(0);
617 } 627 }
618 628
619static char *eat_ws(p) 629static char *eat_ws(char *p)
620char *p;
621 { 630 {
622 while (IS_WS(*p) && (!IS_EOF(*p))) 631 while (IS_WS(*p) && (!IS_EOF(*p)))
623 p++; 632 p++;
624 return(p); 633 return(p);
625 } 634 }
626 635
627static char *eat_alpha_numeric(p) 636static char *eat_alpha_numeric(char *p)
628char *p;
629 { 637 {
630 for (;;) 638 for (;;)
631 { 639 {
@@ -640,14 +648,12 @@ char *p;
640 } 648 }
641 } 649 }
642 650
643static unsigned long hash(v) 651static unsigned long hash(CONF_VALUE *v)
644CONF_VALUE *v;
645 { 652 {
646 return((lh_strhash(v->section)<<2)^lh_strhash(v->name)); 653 return((lh_strhash(v->section)<<2)^lh_strhash(v->name));
647 } 654 }
648 655
649static int cmp(a,b) 656static int cmp_conf(CONF_VALUE *a, CONF_VALUE *b)
650CONF_VALUE *a,*b;
651 { 657 {
652 int i; 658 int i;
653 659
@@ -668,8 +674,7 @@ CONF_VALUE *a,*b;
668 return((a->name == NULL)?-1:1); 674 return((a->name == NULL)?-1:1);
669 } 675 }
670 676
671static char *scan_quote(p) 677static char *scan_quote(char *p)
672char *p;
673 { 678 {
674 int q= *p; 679 int q= *p;
675 680
@@ -687,9 +692,7 @@ char *p;
687 return(p); 692 return(p);
688 } 693 }
689 694
690static CONF_VALUE *new_section(conf,section) 695static CONF_VALUE *new_section(LHASH *conf, char *section)
691LHASH *conf;
692char *section;
693 { 696 {
694 STACK *sk=NULL; 697 STACK *sk=NULL;
695 int ok=0,i; 698 int ok=0,i;
@@ -725,3 +728,5 @@ err:
725 } 728 }
726 return(v); 729 return(v);
727 } 730 }
731
732IMPLEMENT_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 @@
1/* Error codes for the CONF functions. */
2
3/* Function codes. */
4#define CONF_F_CONF_LOAD 100
5#define CONF_F_STR_COPY 101
6
7/* Reason codes. */
8#define CONF_R_MISSING_CLOSE_SQUARE_BRACKET 100
9#define CONF_R_MISSING_EQUAL_SIGN 101
10#define CONF_R_NO_CLOSE_BRACE 102
11#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
12#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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "stack.h" 66#include <openssl/bio.h>
67#include "lhash.h" 67#include <openssl/lhash.h>
68#include <openssl/stack.h>
69#include <openssl/safestack.h>
68 70
69typedef struct 71typedef struct
70 { 72 {
@@ -73,31 +75,29 @@ typedef struct
73 char *value; 75 char *value;
74 } CONF_VALUE; 76 } CONF_VALUE;
75 77
76#ifndef NOPROTO 78DECLARE_STACK_OF(CONF_VALUE)
77 79
78LHASH *CONF_load(LHASH *conf,char *file,long *eline); 80LHASH *CONF_load(LHASH *conf,const char *file,long *eline);
79STACK *CONF_get_section(LHASH *conf,char *section); 81LHASH *CONF_load_fp(LHASH *conf, FILE *fp,long *eline);
82LHASH *CONF_load_bio(LHASH *conf, BIO *bp,long *eline);
83STACK_OF(CONF_VALUE) *CONF_get_section(LHASH *conf,char *section);
80char *CONF_get_string(LHASH *conf,char *group,char *name); 84char *CONF_get_string(LHASH *conf,char *group,char *name);
81long CONF_get_number(LHASH *conf,char *group,char *name); 85long CONF_get_number(LHASH *conf,char *group,char *name);
82void CONF_free(LHASH *conf); 86void CONF_free(LHASH *conf);
83void ERR_load_CONF_strings(void ); 87void ERR_load_CONF_strings(void );
84 88
85#else
86
87LHASH *CONF_load();
88STACK *CONF_get_section();
89char *CONF_get_string();
90long CONF_get_number();
91void CONF_free();
92void ERR_load_CONF_strings();
93
94#endif
95 89
96/* BEGIN ERROR CODES */ 90/* BEGIN ERROR CODES */
91/* The following lines are auto generated by the script mkerr.pl. Any changes
92 * made after this point may be overwritten when the script is next run.
93 */
94
97/* Error codes for the CONF functions. */ 95/* Error codes for the CONF functions. */
98 96
99/* Function codes. */ 97/* Function codes. */
100#define CONF_F_CONF_LOAD 100 98#define CONF_F_CONF_LOAD 100
99#define CONF_F_CONF_LOAD_BIO 102
100#define CONF_F_CONF_LOAD_FP 103
101#define CONF_F_STR_COPY 101 101#define CONF_F_STR_COPY 101
102 102
103/* Reason codes. */ 103/* Reason codes. */
@@ -106,7 +106,7 @@ void ERR_load_CONF_strings();
106#define CONF_R_NO_CLOSE_BRACE 102 106#define CONF_R_NO_CLOSE_BRACE 102
107#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103 107#define CONF_R_UNABLE_TO_CREATE_NEW_SECTION 103
108#define CONF_R_VARIABLE_HAS_NO_VALUE 104 108#define CONF_R_VARIABLE_HAS_NO_VALUE 104
109 109
110#ifdef __cplusplus 110#ifdef __cplusplus
111} 111}
112#endif 112#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 @@
1/* lib/conf/conf_err.c */ 1/* crypto/conf/conf_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "conf.h" 62#include <openssl/conf.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
64static ERR_STRING_DATA CONF_str_functs[]= 66static ERR_STRING_DATA CONF_str_functs[]=
65 { 67 {
66{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"}, 68{ERR_PACK(0,CONF_F_CONF_LOAD,0), "CONF_load"},
69{ERR_PACK(0,CONF_F_CONF_LOAD_BIO,0), "CONF_load_bio"},
70{ERR_PACK(0,CONF_F_CONF_LOAD_FP,0), "CONF_load_fp"},
67{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"}, 71{ERR_PACK(0,CONF_F_STR_COPY,0), "STR_COPY"},
68{0,NULL}, 72{0,NULL}
69 }; 73 };
70 74
71static ERR_STRING_DATA CONF_str_reasons[]= 75static ERR_STRING_DATA CONF_str_reasons[]=
@@ -75,17 +79,17 @@ static ERR_STRING_DATA CONF_str_reasons[]=
75{CONF_R_NO_CLOSE_BRACE ,"no close brace"}, 79{CONF_R_NO_CLOSE_BRACE ,"no close brace"},
76{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"}, 80{CONF_R_UNABLE_TO_CREATE_NEW_SECTION ,"unable to create new section"},
77{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"}, 81{CONF_R_VARIABLE_HAS_NO_VALUE ,"variable has no value"},
78{0,NULL}, 82{0,NULL}
79 }; 83 };
80 84
81#endif 85#endif
82 86
83void ERR_load_CONF_strings() 87void ERR_load_CONF_strings(void)
84 { 88 {
85 static int init=1; 89 static int init=1;
86 90
87 if (init); 91 if (init)
88 {; 92 {
89 init=0; 93 init=0;
90#ifndef NO_ERR 94#ifndef NO_ERR
91 ERR_load_strings(ERR_LIB_CONF,CONF_str_functs); 95 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 @@
71#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \ 71#define CONF_ALPHA_NUMERIC_PUNCT (CONF_ALPHA|CONF_NUMBER|CONF_UNDER| \
72 CONF_PUNCTUATION) 72 CONF_PUNCTUATION)
73 73
74#ifndef CHARSET_EBCDIC
74#define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[(a)&0x7f])) 75#define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[(a)&0x7f]))
75#define IS_EOF(a) ((a) == '\0') 76#define IS_EOF(a) ((a) == '\0')
76#define IS_ESC(a) ((a) == '\\') 77#define IS_ESC(a) ((a) == '\\')
@@ -81,6 +82,19 @@
81 (CONF_type[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT) 82 (CONF_type[(a)&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
82#define IS_QUOTE(a) (CONF_type[(a)&0x7f]&CONF_QUOTE) 83#define IS_QUOTE(a) (CONF_type[(a)&0x7f]&CONF_QUOTE)
83 84
85#else /*CHARSET_EBCDIC*/
86
87#define IS_COMMENT(a) (CONF_COMMENT&(CONF_type[os_toascii[a]&0x7f]))
88#define IS_EOF(a) (os_toascii[a] == '\0')
89#define IS_ESC(a) (os_toascii[a] == '\\')
90#define IS_NUMER(a) (CONF_type[os_toascii[a]&0x7f]&CONF_NUMBER)
91#define IS_WS(a) (CONF_type[os_toascii[a]&0x7f]&CONF_WS)
92#define IS_ALPHA_NUMERIC(a) (CONF_type[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC)
93#define IS_ALPHA_NUMERIC_PUNCT(a) \
94 (CONF_type[os_toascii[a]&0x7f]&CONF_ALPHA_NUMERIC_PUNCT)
95#define IS_QUOTE(a) (CONF_type[os_toascii[a]&0x7f]&CONF_QUOTE)
96#endif /*CHARSET_EBCDIC*/
97
84static unsigned short CONF_type[128]={ 98static unsigned short CONF_type[128]={
85 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000, 99 0x008,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
86 0x000,0x010,0x010,0x000,0x000,0x010,0x000,0x000, 100 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3$NUMBER=0x01; 3$NUMBER=0x01;
4$UPPER=0x02; 4$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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "conf.h" 61#include <openssl/conf.h>
62#include <openssl/err.h>
62 63
63main() 64main()
64 { 65 {
@@ -66,7 +67,7 @@ main()
66 long eline; 67 long eline;
67 char *s,*s2; 68 char *s,*s2;
68 69
69 conf=CONF_load(NULL,"ssleay.conf",&eline); 70 conf=CONF_load(NULL,"openssl.conf",&eline);
70 if (conf == NULL) 71 if (conf == NULL)
71 { 72 {
72 ERR_load_crypto_strings(); 73 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 @@
1/* lib/crypto/crypto_err.c */ 1/* crypto/cpt_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
57 */ 58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "crypto.h" 62#include <openssl/crypto.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -66,20 +68,26 @@ static ERR_STRING_DATA CRYPTO_str_functs[]=
66{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,0), "CRYPTO_get_ex_new_index"}, 68{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,0), "CRYPTO_get_ex_new_index"},
67{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_LOCKID,0), "CRYPTO_get_new_lockid"}, 69{ERR_PACK(0,CRYPTO_F_CRYPTO_GET_NEW_LOCKID,0), "CRYPTO_get_new_lockid"},
68{ERR_PACK(0,CRYPTO_F_CRYPTO_SET_EX_DATA,0), "CRYPTO_set_ex_data"}, 70{ERR_PACK(0,CRYPTO_F_CRYPTO_SET_EX_DATA,0), "CRYPTO_set_ex_data"},
69{0,NULL}, 71{0,NULL}
72 };
73
74static ERR_STRING_DATA CRYPTO_str_reasons[]=
75 {
76{0,NULL}
70 }; 77 };
71 78
72#endif 79#endif
73 80
74void ERR_load_CRYPTO_strings() 81void ERR_load_CRYPTO_strings(void)
75 { 82 {
76 static int init=1; 83 static int init=1;
77 84
78 if (init); 85 if (init)
79 {; 86 {
80 init=0; 87 init=0;
81#ifndef NO_ERR 88#ifndef NO_ERR
82 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_functs); 89 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_functs);
90 ERR_load_strings(ERR_LIB_CRYPTO,CRYPTO_str_reasons);
83#endif 91#endif
84 92
85 } 93 }
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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "crypto.h" 62#include <openssl/crypto.h>
63#include "date.h"
64 63
65#if defined(WIN32) || defined(WIN16) 64#if defined(WIN32) || defined(WIN16)
66static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */ 65static double SSLeay_MSVC5_hack=0.0; /* and for VC1.5 */
67#endif 66#endif
68 67
69/* real #defines in crypto.h, keep these upto date */ 68/* real #defines in crypto.h, keep these upto date */
70static char* lock_names[CRYPTO_NUM_LOCKS] = 69static const char* lock_names[CRYPTO_NUM_LOCKS] =
71 { 70 {
72 "<<ERROR>>", 71 "<<ERROR>>",
73 "err", 72 "err",
@@ -84,30 +83,28 @@ static char* lock_names[CRYPTO_NUM_LOCKS] =
84 "ssl_ctx", 83 "ssl_ctx",
85 "ssl_cert", 84 "ssl_cert",
86 "ssl_session", 85 "ssl_session",
86 "ssl_sess_cert",
87 "ssl", 87 "ssl",
88 "rand", 88 "rand",
89 "debug_malloc", 89 "debug_malloc",
90 "BIO", 90 "BIO",
91 "bio_gethostbyname", 91 "gethostbyname",
92 "getservbyname",
93 "readdir",
92 "RSA_blinding", 94 "RSA_blinding",
95#if CRYPTO_NUM_LOCKS != 24
96# error "Inconsistency between crypto.h and cryptlib.c"
97#endif
93 }; 98 };
94 99
95static STACK *app_locks=NULL; 100static STACK *app_locks=NULL;
96 101
97#ifndef NOPROTO
98static void (MS_FAR *locking_callback)(int mode,int type, 102static void (MS_FAR *locking_callback)(int mode,int type,
99 char *file,int line)=NULL; 103 const char *file,int line)=NULL;
100static int (MS_FAR *add_lock_callback)(int *pointer,int amount, 104static int (MS_FAR *add_lock_callback)(int *pointer,int amount,
101 int type,char *file,int line)=NULL; 105 int type,const char *file,int line)=NULL;
102static unsigned long (MS_FAR *id_callback)(void)=NULL; 106static unsigned long (MS_FAR *id_callback)(void)=NULL;
103#else 107int CRYPTO_get_new_lockid(char *name)
104static void (MS_FAR *locking_callback)()=NULL;
105static int (MS_FAR *add_lock_callback)()=NULL;
106static unsigned long (MS_FAR *id_callback)()=NULL;
107#endif
108
109int CRYPTO_get_new_lockid(name)
110char *name;
111 { 108 {
112 char *str; 109 char *str;
113 int i; 110 int i;
@@ -120,10 +117,11 @@ char *name;
120 SSLeay_MSVC5_hack=(double)name[0]*(double)name[1]; 117 SSLeay_MSVC5_hack=(double)name[0]*(double)name[1];
121#endif 118#endif
122 119
123 if (app_locks == NULL) 120 if ((app_locks == NULL) && ((app_locks=sk_new_null()) == NULL))
124 if ((app_locks=sk_new_null()) == NULL) 121 {
125 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE); 122 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID,ERR_R_MALLOC_FAILURE);
126 return(0); 123 return(0);
124 }
127 if ((str=BUF_strdup(name)) == NULL) 125 if ((str=BUF_strdup(name)) == NULL)
128 return(0); 126 return(0);
129 i=sk_push(app_locks,str); 127 i=sk_push(app_locks,str);
@@ -134,40 +132,46 @@ char *name;
134 return(i); 132 return(i);
135 } 133 }
136 134
137void (*CRYPTO_get_locking_callback(P_V))(P_I_I_P_I) 135int CRYPTO_num_locks(void)
136 {
137 return CRYPTO_NUM_LOCKS;
138 }
139
140void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
141 int line)
138 { 142 {
139 return(locking_callback); 143 return(locking_callback);
140 } 144 }
141 145
142int (*CRYPTO_get_add_lock_callback(P_V))(P_IP_I_I_P_I) 146int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
147 const char *file,int line)
143 { 148 {
144 return(add_lock_callback); 149 return(add_lock_callback);
145 } 150 }
146 151
147void CRYPTO_set_locking_callback(func) 152void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
148void (*func)(P_I_I_P_I); 153 const char *file,int line))
149 { 154 {
150 locking_callback=func; 155 locking_callback=func;
151 } 156 }
152 157
153void CRYPTO_set_add_lock_callback(func) 158void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
154int (*func)(P_IP_I_I_P_I); 159 const char *file,int line))
155 { 160 {
156 add_lock_callback=func; 161 add_lock_callback=func;
157 } 162 }
158 163
159unsigned long (*CRYPTO_get_id_callback(P_V))(P_V) 164unsigned long (*CRYPTO_get_id_callback(void))(void)
160 { 165 {
161 return(id_callback); 166 return(id_callback);
162 } 167 }
163 168
164void CRYPTO_set_id_callback(func) 169void CRYPTO_set_id_callback(unsigned long (*func)(void))
165unsigned long (*func)(P_V);
166 { 170 {
167 id_callback=func; 171 id_callback=func;
168 } 172 }
169 173
170unsigned long CRYPTO_thread_id() 174unsigned long CRYPTO_thread_id(void)
171 { 175 {
172 unsigned long ret=0; 176 unsigned long ret=0;
173 177
@@ -188,11 +192,7 @@ unsigned long CRYPTO_thread_id()
188 return(ret); 192 return(ret);
189 } 193 }
190 194
191void CRYPTO_lock(mode,type,file,line) 195void CRYPTO_lock(int mode, int type, const char *file, int line)
192int mode;
193int type;
194char *file;
195int line;
196 { 196 {
197#ifdef LOCK_DEBUG 197#ifdef LOCK_DEBUG
198 { 198 {
@@ -221,12 +221,8 @@ int line;
221 locking_callback(mode,type,file,line); 221 locking_callback(mode,type,file,line);
222 } 222 }
223 223
224int CRYPTO_add_lock(pointer,amount,type,file,line) 224int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,
225int *pointer; 225 int line)
226int amount;
227int type;
228char *file;
229int line;
230 { 226 {
231 int ret; 227 int ret;
232 228
@@ -264,8 +260,7 @@ int line;
264 return(ret); 260 return(ret);
265 } 261 }
266 262
267char *CRYPTO_get_lock_name(type) 263const char *CRYPTO_get_lock_name(int type)
268int type;
269 { 264 {
270 if (type < 0) 265 if (type < 0)
271 return("ERROR"); 266 return("ERROR");
@@ -283,10 +278,8 @@ int type;
283/* All we really need to do is remove the 'error' state when a thread 278/* All we really need to do is remove the 'error' state when a thread
284 * detaches */ 279 * detaches */
285 280
286BOOL WINAPI DLLEntryPoint(hinstDLL,fdwReason,lpvReserved) 281BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason,
287HINSTANCE hinstDLL; 282 LPVOID lpvReserved)
288DWORD fdwReason;
289LPVOID lpvReserved;
290 { 283 {
291 switch(fdwReason) 284 switch(fdwReason)
292 { 285 {
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 @@
66extern "C" { 66extern "C" {
67#endif 67#endif
68 68
69/* #ifdef FLAT_INC */ 69#include "openssl/e_os.h"
70 70
71#include "e_os.h" 71#include <openssl/crypto.h>
72#include "crypto.h" 72#include <openssl/buffer.h>
73#include "buffer.h" 73#include <openssl/bio.h>
74#include "bio.h" 74#include <openssl/err.h>
75#include "err.h" 75#include <openssl/opensslconf.h>
76 76
77/* 77#ifndef VMS
78#define X509_CERT_AREA OPENSSLDIR
79#define X509_CERT_DIR OPENSSLDIR "/certs"
80#define X509_CERT_FILE OPENSSLDIR "/cert.pem"
81#define X509_PRIVATE_DIR OPENSSLDIR "/private"
78#else 82#else
79 83#define X509_CERT_AREA "SSLROOT:[000000]"
80#include "../e_os.h" 84#define X509_CERT_DIR "SSLCERTS:"
81#include "crypto.h" 85#define X509_CERT_FILE "SSLCERTS:cert.pem"
82#include "buffer/buffer.h" 86#define X509_PRIVATE_DIR "SSLPRIVATE:"
83#include "bio/bio.h"
84#include "err/err.h"
85#endif 87#endif
86*/
87
88#define X509_CERT_AREA "/etc/ssl"
89#define X509_CERT_DIR "/etc/ssl/certs"
90#define X509_CERT_FILE "/etc/ssl/cert.pem"
91#define X509_PRIVATE_DIR "/etc/ssl/private"
92 88
93#define X509_CERT_DIR_EVP "SSL_CERT_DIR" 89#define X509_CERT_DIR_EVP "SSL_CERT_DIR"
94#define X509_CERT_FILE_EVP "SSL_CERT_FILE" 90#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 @@
1$!
2$! CRYPTO-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates the "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB"
11$! library for OpenSSL. The "xxx" denotes the machine architecture of AXP
12$! or VAX.
13$!
14$! It was re-written so it would try to determine what "C" compiler to use
15$! or you can specify which "C" compiler to use.
16$!
17$! Specify RSAREF as P1 to compile with the RSAREF library instead of
18$! the regular one. If you specify NORSAREF it will compile with the
19$! regular RSAREF routines. (Note: If you are in the United States
20$! you MUST compile with RSAREF unless you have a license from RSA).
21$!
22$! Note: The RSAREF libraries are NOT INCLUDED and you have to
23$! download it from "ftp://ftp.rsa.com/rsaref". You have to
24$! get the ".tar-Z" file as the ".zip" file dosen't have the
25$! directory structure stored. You have to extract the file
26$! into the [.RSAREF] directory under the root directory as that
27$! is where the scripts will look for the files.
28$!
29$! Specify DEBUG or NODEBUG as P2 to compile with or without debugger
30$! information.
31$!
32$! Specify which compiler at P3 to try to compile under.
33$!
34$! VAXC For VAX C.
35$! DECC For DEC C.
36$! GNUC For GNU C.
37$!
38$! If you don't speficy a compiler, it will try to determine which
39$! "C" compiler to use.
40$!
41$! P4, if defined, sets a TCP/IP library to use, through one of the following
42$! keywords:
43$!
44$! UCX for UCX
45$! SOCKETSHR for SOCKETSHR+NETLIB
46$!
47$! P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
48$!
49$! P6, if defined, sets a choice of crypto methods to compile.
50$! WARNING: this should only be done to recompile some part of an already
51$! fully compiled library.
52$!
53$!
54$! Define A TCP/IP Library That We Will Need To Link To.
55$! (That Is, If We Need To Link To One.)
56$!
57$ TCPIP_LIB = ""
58$!
59$! Check Which Architecture We Are Using.
60$!
61$ IF (F$GETSYI("CPU").GE.128)
62$ THEN
63$!
64$! The Architecture Is AXP
65$!
66$ ARCH := AXP
67$!
68$! Else...
69$!
70$ ELSE
71$!
72$! The Architecture Is VAX.
73$!
74$ ARCH := VAX
75$!
76$! End The Architecture Check.
77$!
78$ ENDIF
79$!
80$! Define The Different Encryption Types.
81$!
82$ ENCRYPT_TYPES = ",MD2,MD5,SHA,MDC2,HMAC,RIPEMD,"+ -
83 "DES,RC2,RC4,RC5,IDEA,BF,CAST,"+ -
84 "BN,RSA,DSA,DH,"+ -
85 "BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ -
86 "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
87 "CONF,TXT_DB,PKCS7,PKCS12,COMP"
88$!
89$! Check To Make Sure We Have Valid Command Line Parameters.
90$!
91$ GOSUB CHECK_OPTIONS
92$!
93$! Initialise logical names and such
94$!
95$ GOSUB INITIALISE
96$!
97$! Tell The User What Kind of Machine We Run On.
98$!
99$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
100$!
101$! Define The OBJ Directory.
102$!
103$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.CRYPTO]
104$!
105$! Check To See If The Architecture Specific OBJ Directory Exists.
106$!
107$ IF (F$PARSE(OBJ_DIR).EQS."")
108$ THEN
109$!
110$! It Dosen't Exist, So Create It.
111$!
112$ CREATE/DIR 'OBJ_DIR'
113$!
114$! End The Architecture Specific OBJ Directory Check.
115$!
116$ ENDIF
117$!
118$! Define The EXE Directory.
119$!
120$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]
121$!
122$! Check To See If The Architecture Specific Directory Exists.
123$!
124$ IF (F$PARSE(EXE_DIR).EQS."")
125$ THEN
126$!
127$! It Dosen't Exist, So Create It.
128$!
129$ CREATE/DIRECTORY 'EXE_DIR'
130$!
131$! End The Architecture Specific Directory Check.
132$!
133$ ENDIF
134$!
135$! Define The Library Name.
136$!
137$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB
138$!
139$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library...
140$!
141$ IF (F$SEARCH(LIB_NAME).EQS."")
142$ THEN
143$!
144$! Guess Not, Create The Library.
145$!
146$ LIBRARY/CREATE/OBJECT 'LIB_NAME'
147$!
148$! End The Library Check.
149$!
150$ ENDIF
151$!
152$! Define The Different Encryption "library" Strings.
153$!
154$ LIB_ = "cryptlib,mem,cversion,ex_data,tmdiff,cpt_err"
155$ LIB_MD2 = "md2_dgst,md2_one"
156$ LIB_MD5 = "md5_dgst,md5_one"
157$ LIB_SHA = "sha_dgst,sha1dgst,sha_one,sha1_one"
158$ LIB_MDC2 = "mdc2dgst,mdc2_one"
159$ LIB_HMAC = "hmac"
160$ LIB_RIPEMD = "rmd_dgst,rmd_one"
161$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
162 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
163 "enc_read,enc_writ,ofb64enc,"+ -
164 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
165 "des_enc,fcrypt_b,read2pwd,"+ -
166 "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp,ede_cbcm_enc"
167$ LIB_RC2 = "rc2_ecb,rc2_skey,rc2_cbc,rc2cfb64,rc2ofb64"
168$ LIB_RC4 = "rc4_skey,rc4_enc"
169$ LIB_RC5 = "rc5_skey,rc5_ecb,rc5_enc,rc5cfb64,rc5ofb64"
170$ LIB_IDEA = "i_cbc,i_cfb64,i_ofb64,i_ecb,i_skey"
171$ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64"
172$ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64"
173$ LIB_BN_ASM = "[.asm]vms.mar,vms-helper"
174$ IF F$TRNLNM("OPENSSL_NO_ASM") .NES. "" THEN LIB_BN_ASM = "bn_asm"
175$ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_mul,"+ -
176 "bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ -
177 "bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+",bn_recp,bn_mont,"+ -
178 "bn_mpi,bn_exp2"
179$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ -
180 "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk"
181$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err"
182$ LIB_DH = "dh_gen,dh_key,dh_lib,dh_check,dh_err"
183$ LIB_BUFFER = "buffer,buf_err"
184$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
185 "bss_mem,bss_null,bss_fd,"+ -
186 "bss_file,bss_sock,bss_conn,"+ -
187 "bf_null,bf_buff,b_print,b_dump,"+ -
188 "b_sock,bss_acpt,bf_nbio,bss_rtcp,bss_bio" ! + ",bss_log" for syslog
189$ LIB_STACK = "stack"
190$ LIB_LHASH = "lhash,lh_stats"
191$ LIB_RAND = "md_rand,randfile,rand_lib"
192$ LIB_ERR = "err,err_all,err_prn"
193$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err"
194$ LIB_EVP = "encode,digest,evp_enc,evp_key,"+ -
195 "e_ecb_d,e_cbc_d,e_cfb_d,e_ofb_d,"+ -
196 "e_ecb_i,e_cbc_i,e_cfb_i,e_ofb_i,"+ -
197 "e_ecb_3d,e_cbc_3d,e_rc4,names,"+ -
198 "e_cfb_3d,e_ofb_3d,e_xcbc_d,"+ -
199 "e_ecb_r2,e_cbc_r2,e_cfb_r2,e_ofb_r2,"+ -
200 "e_ecb_bf,e_cbc_bf,e_cfb_bf,e_ofb_bf"
201$ LIB_EVP_2 = "e_ecb_c,e_cbc_c,e_cfb_c,e_ofb_c,"+ -
202 "e_ecb_r5,e_cbc_r5,e_cfb_r5,e_ofb_r5,"+ -
203 "m_null,m_md2,m_md5,m_sha,m_sha1,m_dss,m_dss1,m_mdc2,"+ -
204 "m_ripemd,"+ -
205 "p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ -
206 "bio_md,bio_b64,bio_enc,evp_err,e_null,"+ -
207 "c_all,evp_lib,bio_ok,evp_pkey,evp_pbe,p5_crpt,p5_crpt2"
208$ LIB_ASN1 = "a_object,a_bitstr,a_utctm,a_gentm,a_time,a_int,a_octet,"+ -
209 "a_print,a_type,a_set,a_dup,a_d2i_fp,a_i2d_fp,a_bmp,"+ -
210 "a_enum,a_vis,a_utf8,a_sign,a_digest,a_verify,"+ -
211 "x_algor,x_val,x_pubkey,x_sig,x_req,x_attrib,"+ -
212 "x_name,x_cinf,x_x509,x_crl,x_info,x_spki,nsseq,"+ -
213 "d2i_r_pr,i2d_r_pr,d2i_r_pu,i2d_r_pu,"+ -
214 "d2i_s_pr,i2d_s_pr,d2i_s_pu,i2d_s_pu,"+ -
215 "d2i_pu,d2i_pr,i2d_pu,i2d_pr"
216$ LIB_ASN1_2 = "t_req,t_x509,t_crl,t_pkey,"+ -
217 "p7_i_s,p7_signi,p7_signd,p7_recip,p7_enc_c,p7_evp,"+ -
218 "p7_dgst,p7_s_e,p7_enc,p7_lib,"+ -
219 "f_int,f_string,i2d_dhp,i2d_dsap,d2i_dhp,d2i_dsap,n_pkey,"+ -
220 "f_enum,a_hdr,x_pkey,a_bool,x_exten,"+ -
221 "asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,"+ -
222 "evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey"
223$ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err"
224$ LIB_X509 = "x509_def,x509_d2,x509_r2x,x509_cmp,"+ -
225 "x509_obj,x509_req,x509_vfy,"+ -
226 "x509_set,x509rset,x509_err,"+ -
227 "x509name,x509_v3,x509_ext,"+ -
228 "x509type,x509_lu,x_all,x509_txt,"+ -
229 "by_file,by_dir"
230$ LIB_X509V3 = "v3_bcons,v3_bitst,v3_conf,v3_extku,v3_ia5,v3_lib,"+ -
231 "v3_prn,v3_utl,v3err,v3_genn,v3_alt,v3_skey,v3_akey,v3_pku,"+ -
232 "v3_int,v3_enum,v3_sxnet,v3_cpols,v3_crld"
233$ LIB_CONF = "conf,conf_err"
234$ LIB_TXT_DB = "txt_db"
235$ LIB_PKCS7 = "pk7_lib,pkcs7err,pk7_doit"
236$ LIB_PKCS12 = "p12_add,p12_attr,p12_bags,p12_crpt,p12_crt,p12_decr,"+ -
237 "p12_init,p12_key,p12_kiss,p12_lib,p12_mac,p12_mutl,"+ -
238 "p12_sbag,p12_utl,pk12err"
239$ LIB_COMP = "comp_lib,"+ -
240 "c_rle,c_zlib"
241$!
242$! Setup exceptional compilations
243$!
244$ COMPILEWITH_CC3 = ",bss_rtcp,"
245$ COMPILEWITH_CC4 = ",a_utctm,"
246$ COMPILEWITH_CC5 = ",md2_dgst,md5_dgst,mdc2dgst,sha_dgst,sha1dgst," + -
247 "rmd_dgst,bf_enc,"
248$!
249$! Check To See If We Are Going To Use RSAREF.
250$!
251$ IF (RSAREF.EQS."TRUE" .AND. ENCRYPT_TYPES - "RSA".NES.ENCRYPT_TYPES)
252$ THEN
253$!
254$! Check To See If The File [-.RSAREF]RSAREF.C Is Actually There.
255$!
256$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]RSAREF.C").EQS."")
257$ THEN
258$!
259$! Tell The User That The File Dosen't Exist.
260$!
261$ WRITE SYS$OUTPUT ""
262$ WRITE SYS$OUTPUT "The File [-.RSAREF]RSAREF.C Dosen't Exist."
263$ WRITE SYS$OUTPUT ""
264$!
265$! Exit The Build.
266$!
267$ GOTO EXIT
268$!
269$! End The [-.RSAREF]RSAREF.C Check.
270$!
271$ ENDIF
272$!
273$! Tell The User We Are Compiling The [-.RSAREF]RSAREF File.
274$!
275$ WRITE SYS$OUTPUT "Compiling The [-.RSAREF]RSAREF File."
276$!
277$! Compile [-.RSAREF]RSAREF.C
278$!
279$ CC/OBJECT='OBJ_DIR'RSAREF.OBJ SYS$DISK:[-.RSAREF]RSAREF.C
280$!
281$! Add It To The Library.
282$!
283$ LIBRARY/REPLACE 'LIB_NAME' 'OBJ_DIR'RSAREF.OBJ
284$!
285$! Delete The Object File.
286$!
287$ DELETE 'OBJ_DIR'RSAREF.OBJ;*
288$!
289$! Check To See If The File [-.RSAREF]RSAR_ERR.C Is Actually There.
290$!
291$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]RSAR_ERR.C").EQS."")
292$ THEN
293$!
294$! Tell The User That The File Dosen't Exist.
295$!
296$ WRITE SYS$OUTPUT ""
297$ WRITE SYS$OUTPUT "The File [-.RSAREF]RSAR_ERR.C Dosen't Exist."
298$ WRITE SYS$OUTPUT ""
299$!
300$! Exit The Build.
301$!
302$ GOTO EXIT
303$!
304$! End The [-.RSAREF]RSAR_ERR.C File Check.
305$!
306$ ENDIF
307$!
308$! Tell The User We Are Compiling The [-.RSAREF]RSAR_ERR File.
309$!
310$ WRITE SYS$OUTPUT "Compiling The [-.RSAREF]RSAR_ERR File."
311$!
312$! Compile [-.RSAREF]RSAR_ERR.C
313$!
314$ CC/OBJECT='OBJ_DIR'RSAR_ERR.OBJ SYS$DISK:[-.RSAREF]RSAR_ERR.C
315$!
316$! Add It To The Library.
317$!
318$ LIBRARY/REPLACE 'LIB_NAME' 'OBJ_DIR'RSAR_ERR.OBJ
319$!
320$! Delete The Object File.
321$!
322$ DELETE 'OBJ_DIR'RSAR_ERR.OBJ;*
323$!
324$! End The RSAREF Check.
325$!
326$ ENDIF
327$!
328$! Figure Out What Other Modules We Are To Build.
329$!
330$ BUILD_SET:
331$!
332$! Define A Module Counter.
333$!
334$ MODULE_COUNTER = 0
335$!
336$! Top Of The Loop.
337$!
338$ MODULE_NEXT:
339$!
340$! Extract The Module Name From The Encryption List.
341$!
342$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES)
343$!
344$! Check To See If We Are At The End Of The Module List.
345$!
346$ IF (MODULE_NAME.EQS.",")
347$ THEN
348$!
349$! We Are At The End Of The Module List, Go To MODULE_DONE.
350$!
351$ GOTO MODULE_DONE
352$!
353$! End The Module List Check.
354$!
355$ ENDIF
356$!
357$! Increment The Moudle Counter.
358$!
359$ MODULE_COUNTER = MODULE_COUNTER + 1
360$!
361$! Tell The User What Module We Are Building.
362$!
363$ IF (MODULE_NAME.NES."")
364$ THEN
365$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME," Files."
366$ ENDIF
367$!
368$! Define A File Counter And Set It To "0".
369$!
370$ FILE_COUNTER = 0
371$!
372$! Create The Library Module Name.
373$!
374$ LIB_MODULE = "LIB_" + MODULE_NAME
375$ IF (MODULE_NAME.EQS."ASN1_2")
376$ THEN
377$ MODULE_NAME = "ASN1"
378$ ENDIF
379$ IF (MODULE_NAME.EQS."EVP_2")
380$ THEN
381$ MODULE_NAME = "EVP"
382$ ENDIF
383$!
384$! Check if the library module name actually is defined
385$!
386$ IF F$TYPE('LIB_MODULE') .EQS. ""
387$ THEN
388$ WRITE SYS$ERROR ""
389$ WRITE SYS$ERROR "The module ",MODULE_NAME," does not exist. Continuing..."
390$ WRITE SYS$ERROR ""
391$ GOTO MODULE_NEXT
392$ ENDIF
393$!
394$! Top Of The File Loop.
395$!
396$ NEXT_FILE:
397$!
398$! O.K, Extract The File Name From The File List.
399$!
400$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE')
401$!
402$! Check To See If We Are At The End Of The File List.
403$!
404$ IF (FILE_NAME.EQS.",")
405$ THEN
406$!
407$! We Are At The End Of The File List, Goto FILE_DONE.
408$!
409$ GOTO FILE_DONE
410$!
411$! End The File List Check.
412$!
413$ ENDIF
414$!
415$! Increment The Counter.
416$!
417$ FILE_COUNTER = FILE_COUNTER + 1
418$!
419$! Create The Source File Name.
420$!
421$ TMP_FILE_NAME = F$ELEMENT(1,"]",FILE_NAME)
422$ IF TMP_FILE_NAME .EQS. "]" THEN TMP_FILE_NAME = FILE_NAME
423$ IF F$ELEMENT(0,".",TMP_FILE_NAME) .EQS. TMP_FILE_NAME THEN -
424 FILE_NAME = FILE_NAME + ".c"
425$ IF (MODULE_NAME.NES."")
426$ THEN
427$ SOURCE_FILE = "SYS$DISK:[." + MODULE_NAME+ "]" + FILE_NAME
428$ ELSE
429$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME
430$ ENDIF
431$ SOURCE_FILE = SOURCE_FILE - "]["
432$!
433$! Create The Object File Name.
434$!
435$ OBJECT_FILE = OBJ_DIR + F$PARSE(FILE_NAME,,,"NAME","SYNTAX_ONLY") + ".OBJ"
436$ ON WARNING THEN GOTO NEXT_FILE
437$!
438$! Check To See If The File We Want To Compile Is Actually There.
439$!
440$ IF (F$SEARCH(SOURCE_FILE).EQS."")
441$ THEN
442$!
443$! Tell The User That The File Dosen't Exist.
444$!
445$ WRITE SYS$OUTPUT ""
446$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
447$ WRITE SYS$OUTPUT ""
448$!
449$! Exit The Build.
450$!
451$ GOTO EXIT
452$!
453$! End The File Exist Check.
454$!
455$ ENDIF
456$!
457$! Tell The User We Are Compiling The File.
458$!
459$ IF (MODULE_NAME.EQS."")
460$ THEN
461 WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File."
462$ ENDIF
463$ IF (MODULE_NAME.NES."")
464$ THEN
465$ WRITE SYS$OUTPUT " ",FILE_NAME,""
466$ ENDIF
467$!
468$! Compile The File.
469$!
470$ ON ERROR THEN GOTO NEXT_FILE
471$ FILE_NAME0 = F$ELEMENT(0,".",FILE_NAME)
472$ IF FILE_NAME - ".mar" .NES. FILE_NAME
473$ THEN
474$ MACRO/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
475$ ELSE
476$ IF COMPILEWITH_CC3 - FILE_NAME0 .NES. COMPILEWITH_CC3
477$ THEN
478$ CC3/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
479$ ELSE
480$ IF COMPILEWITH_CC4 - FILE_NAME0 .NES. COMPILEWITH_CC4
481$ THEN
482$ CC4/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
483$ ELSE
484$ IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5
485$ THEN
486$ CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
487$ ELSE
488$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
489$ ENDIF
490$ ENDIF
491$ ENDIF
492$ ENDIF
493$!
494$! Add It To The Library.
495$!
496$ LIBRARY/REPLACE 'LIB_NAME' 'OBJECT_FILE'
497$!
498$! Time To Clean Up The Object File.
499$!
500$ DELETE 'OBJECT_FILE';*
501$!
502$! Go Back And Do It Again.
503$!
504$ GOTO NEXT_FILE
505$!
506$! All Done With This Library Part.
507$!
508$ FILE_DONE:
509$!
510$! Go Back And Get The Next Module.
511$!
512$ GOTO MODULE_NEXT
513$!
514$! All Done With This Module.
515$!
516$ MODULE_DONE:
517$!
518$! Tell The User That We Are All Done.
519$!
520$ WRITE SYS$OUTPUT "All Done..."
521$ EXIT:
522$ GOSUB CLEANUP
523$ EXIT
524$!
525$! Check For The Link Option FIle.
526$!
527$ CHECK_OPT_FILE:
528$!
529$! Check To See If We Need To Make A VAX C Option File.
530$!
531$ IF (COMPILER.EQS."VAXC")
532$ THEN
533$!
534$! Check To See If We Already Have A VAX C Linker Option File.
535$!
536$ IF (F$SEARCH(OPT_FILE).EQS."")
537$ THEN
538$!
539$! We Need A VAX C Linker Option File.
540$!
541$ CREATE 'OPT_FILE'
542$DECK
543!
544! Default System Options File To Link Agianst
545! The Sharable VAX C Runtime Library.
546!
547SYS$SHARE:VAXCRTL.EXE/SHARE
548$EOD
549$!
550$! End The Option File Check.
551$!
552$ ENDIF
553$!
554$! End The VAXC Check.
555$!
556$ ENDIF
557$!
558$! Check To See If We Need A GNU C Option File.
559$!
560$ IF (COMPILER.EQS."GNUC")
561$ THEN
562$!
563$! Check To See If We Already Have A GNU C Linker Option File.
564$!
565$ IF (F$SEARCH(OPT_FILE).EQS."")
566$ THEN
567$!
568$! We Need A GNU C Linker Option File.
569$!
570$ CREATE 'OPT_FILE'
571$DECK
572!
573! Default System Options File To Link Agianst
574! The Sharable C Runtime Library.
575!
576GNU_CC:[000000]GCCLIB/LIBRARY
577SYS$SHARE:VAXCRTL/SHARE
578$EOD
579$!
580$! End The Option File Check.
581$!
582$ ENDIF
583$!
584$! End The GNU C Check.
585$!
586$ ENDIF
587$!
588$! Check To See If We Need A DEC C Option File.
589$!
590$ IF (COMPILER.EQS."DECC")
591$ THEN
592$!
593$! Check To See If We Already Have A DEC C Linker Option File.
594$!
595$ IF (F$SEARCH(OPT_FILE).EQS."")
596$ THEN
597$!
598$! Figure Out If We Need An AXP Or A VAX Linker Option File.
599$!
600$ IF ARCH .EQS. "VAX"
601$ THEN
602$!
603$! We Need A DEC C Linker Option File For VAX.
604$!
605$ CREATE 'OPT_FILE'
606$DECK
607!
608! Default System Options File To Link Agianst
609! The Sharable DEC C Runtime Library.
610!
611SYS$SHARE:DECC$SHR.EXE/SHARE
612$EOD
613$!
614$! Else...
615$!
616$ ELSE
617$!
618$! Create The AXP Linker Option File.
619$!
620$ CREATE 'OPT_FILE'
621$DECK
622!
623! Default System Options File For AXP To Link Agianst
624! The Sharable C Runtime Library.
625!
626SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
627SYS$SHARE:CMA$OPEN_RTL/SHARE
628$EOD
629$!
630$! End The VAX/AXP DEC C Option File Check.
631$!
632$ ENDIF
633$!
634$! End The Option File Search.
635$!
636$ ENDIF
637$!
638$! End The DEC C Check.
639$!
640$ ENDIF
641$!
642$! Tell The User What Linker Option File We Are Using.
643$!
644$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
645$!
646$! Time To RETURN.
647$!
648$ RETURN
649$!
650$! Check The User's Options.
651$!
652$ CHECK_OPTIONS:
653$!
654$! Check To See If P1 Is Blank.
655$!
656$ IF (P1.EQS."NORSAREF")
657$ THEN
658$!
659$! P1 Is NORSAREF, So Compile With The Regular RSA Libraries.
660$!
661$ RSAREF = "FALSE"
662$ ELSE
663$!
664$! Check To See If We Are To Use The RSAREF Library.
665$!
666$ IF (P1.EQS."RSAREF")
667$ THEN
668$!
669$! Check To Make Sure We Have The RSAREF Source Code Directory.
670$!
671$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]SOURCE.DIR").EQS."")
672$ THEN
673$!
674$! We Don't Have The RSAREF Souce Code Directory, So Tell The
675$! User This.
676$!
677$ WRITE SYS$OUTPUT ""
678$ WRITE SYS$OUTPUT "It appears that you don't have the RSAREF Souce Code."
679$ WRITE SYS$OUTPUT "You need to go to 'ftp://ftp.rsa.com/rsaref'. You have to"
680$ WRITE SYS$OUTPUT "get the '.tar-Z' file as the '.zip' file dosen't have the"
681$ WRITE SYS$OUTPUT "directory structure stored. You have to extract the file"
682$ WRITE SYS$OUTPUT "into the [.RSAREF] directory under the root directory"
683$ WRITE SYS$OUTPUT "as that is where the scripts will look for the files."
684$ WRITE SYS$OUTPUT ""
685$!
686$! Time To Exit.
687$!
688$ EXIT
689$!
690$! Else, Compile Using The RSAREF Library.
691$!
692$ ELSE
693$ RSAREF = "TRUE"
694$ ENDIF
695$ ELSE
696$!
697$! They Entered An Invalid Option..
698$!
699$ WRITE SYS$OUTPUT ""
700$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
701$ WRITE SYS$OUTPUT ""
702$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library."
703$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library."
704$ WRITE SYS$OUTPUT ""
705$!
706$! Time To EXIT.
707$!
708$ EXIT
709$!
710$! End The Valid Arguement Check.
711$!
712$ ENDIF
713$!
714$! End The P1 Check.
715$!
716$ ENDIF
717$!
718$! Check To See If P2 Is Blank.
719$!
720$ IF (P2.EQS."NODEBUG")
721$ THEN
722$!
723$! P2 Is NODEBUG, So Compile Without The Debugger Information.
724$!
725$ DEBUGGER = "NODEBUG"
726$ TRACEBACK = "NOTRACEBACK"
727$ GCC_OPTIMIZE = "OPTIMIZE"
728$ CC_OPTIMIZE = "OPTIMIZE"
729$ MACRO_OPTIMIZE = "OPTIMIZE"
730$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
731$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
732$ ELSE
733$!
734$! Check To See If We Are To Compile With Debugger Information.
735$!
736$ IF (P2.EQS."DEBUG")
737$ THEN
738$!
739$! Compile With Debugger Information.
740$!
741$ DEBUGGER = "DEBUG"
742$ TRACEBACK = "TRACEBACK"
743$ GCC_OPTIMIZE = "NOOPTIMIZE"
744$ CC_OPTIMIZE = "NOOPTIMIZE"
745$ MACRO_OPTIMIZE = "NOOPTIMIZE"
746$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
747$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
748$ ELSE
749$!
750$! They Entered An Invalid Option..
751$!
752$ WRITE SYS$OUTPUT ""
753$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
754$ WRITE SYS$OUTPUT ""
755$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
756$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
757$ WRITE SYS$OUTPUT ""
758$!
759$! Time To EXIT.
760$!
761$ EXIT
762$!
763$! End The Valid Arguement Check.
764$!
765$ ENDIF
766$!
767$! End The P2 Check.
768$!
769$ ENDIF
770$!
771$! Special Threads For OpenVMS v7.1 Or Later
772$!
773$! Written By: Richard Levitte
774$! richard@levitte.org
775$!
776$!
777$! Check To See If We Have A Option For P5.
778$!
779$ IF (P5.EQS."")
780$ THEN
781$!
782$! Get The Version Of VMS We Are Using.
783$!
784$ ISSEVEN :=
785$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
786$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
787$!
788$! Check To See If The VMS Version Is v7.1 Or Later.
789$!
790$ IF (TMP.GE.71)
791$ THEN
792$!
793$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
794$!
795$ ISSEVEN := ,PTHREAD_USE_D4
796$!
797$! End The VMS Version Check.
798$!
799$ ENDIF
800$!
801$! End The P5 Check.
802$!
803$ ENDIF
804$!
805$! Check To See If P3 Is Blank.
806$!
807$ IF (P3.EQS."")
808$ THEN
809$!
810$! O.K., The User Didn't Specify A Compiler, Let's Try To
811$! Find Out Which One To Use.
812$!
813$! Check To See If We Have GNU C.
814$!
815$ IF (F$TRNLNM("GNU_CC").NES."")
816$ THEN
817$!
818$! Looks Like GNUC, Set To Use GNUC.
819$!
820$ P3 = "GNUC"
821$!
822$! Else...
823$!
824$ ELSE
825$!
826$! Check To See If We Have VAXC Or DECC.
827$!
828$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
829$ THEN
830$!
831$! Looks Like DECC, Set To Use DECC.
832$!
833$ P3 = "DECC"
834$!
835$! Else...
836$!
837$ ELSE
838$!
839$! Looks Like VAXC, Set To Use VAXC.
840$!
841$ P3 = "VAXC"
842$!
843$! End The VAXC Compiler Check.
844$!
845$ ENDIF
846$!
847$! End The DECC & VAXC Compiler Check.
848$!
849$ ENDIF
850$!
851$! End The Compiler Check.
852$!
853$ ENDIF
854$!
855$! Check To See If We Have A Option For P4.
856$!
857$ IF (P4.EQS."")
858$ THEN
859$!
860$! Find out what socket library we have available
861$!
862$ IF F$PARSE("SOCKETSHR:") .NES. ""
863$ THEN
864$!
865$! We have SOCKETSHR, and it is my opinion that it's the best to use.
866$!
867$ P4 = "SOCKETSHR"
868$!
869$! Tell the user
870$!
871$ WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
872$!
873$! Else, let's look for something else
874$!
875$ ELSE
876$!
877$! Like UCX (the reason to do this before Multinet is that the UCX
878$! emulation is easier to use...)
879$!
880$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
881 .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
882 .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
883$ THEN
884$!
885$! Last resort: a UCX or UCX-compatible library
886$!
887$ P4 = "UCX"
888$!
889$! Tell the user
890$!
891$ WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
892$!
893$! That was all...
894$!
895$ ENDIF
896$ ENDIF
897$ ENDIF
898$!
899$! Set Up Initial CC Definitions, Possibly With User Ones
900$!
901$ CCDEFS = "VMS=1,TCPIP_TYPE_''P4'"
902$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
903$ CCEXTRAFLAGS = ""
904$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
905$ CCDISABLEWARNINGS = ""
906$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
907 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
908$!
909$! Check To See If The User Entered A Valid Paramter.
910$!
911$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
912$ THEN
913$!
914$! Check To See If The User Wanted DECC.
915$!
916$ IF (P3.EQS."DECC")
917$ THEN
918$!
919$! Looks Like DECC, Set To Use DECC.
920$!
921$ COMPILER = "DECC"
922$!
923$! Tell The User We Are Using DECC.
924$!
925$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
926$!
927$! Use DECC...
928$!
929$ CC = "CC"
930$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
931 THEN CC = "CC/DECC"
932$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
933 "/NOLIST/PREFIX=ALL/INCLUDE=SYS$DISK:[]" + CCEXTRAFLAGS
934$!
935$! Define The Linker Options File Name.
936$!
937$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
938$!
939$! End DECC Check.
940$!
941$ ENDIF
942$!
943$! Check To See If We Are To Use VAXC.
944$!
945$ IF (P3.EQS."VAXC")
946$ THEN
947$!
948$! Looks Like VAXC, Set To Use VAXC.
949$!
950$ COMPILER = "VAXC"
951$!
952$! Tell The User We Are Using VAX C.
953$!
954$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
955$!
956$! Compile Using VAXC.
957$!
958$ CC = "CC"
959$ IF ARCH.EQS."AXP"
960$ THEN
961$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
962$ EXIT
963$ ENDIF
964$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
965$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST/INCLUDE=SYS$DISK:[]" + -
966 CCEXTRAFLAGS
967$ CCDEFS = """VAXC""," + CCDEFS
968$!
969$! Define <sys> As SYS$COMMON:[SYSLIB]
970$!
971$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
972$!
973$! Define The Linker Options File Name.
974$!
975$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
976$!
977$! End VAXC Check
978$!
979$ ENDIF
980$!
981$! Check To See If We Are To Use GNU C.
982$!
983$ IF (P3.EQS."GNUC")
984$ THEN
985$!
986$! Looks Like GNUC, Set To Use GNUC.
987$!
988$ COMPILER = "GNUC"
989$!
990$! Tell The User We Are Using GNUC.
991$!
992$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
993$!
994$! Use GNU C...
995$!
996$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
997 "/INCLUDE=SYS$DISK:[]" + CCEXTRAFLAGS
998$!
999$! Define The Linker Options File Name.
1000$!
1001$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
1002$!
1003$! End The GNU C Check.
1004$!
1005$ ENDIF
1006$!
1007$! Set up default defines
1008$!
1009$ CCDEFS = """FLAT_INC=1""," + CCDEFS
1010$!
1011$! Check To See If We Are To Compile With RSAREF Routines.
1012$!
1013$ IF (RSAREF.EQS."TRUE")
1014$ THEN
1015$!
1016$! Compile With RSAREF.
1017$!
1018$ CCDEFS = CCDEFS + ",""RSAref=1"""
1019$!
1020$! Tell The User This.
1021$!
1022$ WRITE SYS$OUTPUT "Compiling With RSAREF Routines."
1023$!
1024$! Else, We Don't Care. Compile Without The RSAREF Library.
1025$!
1026$ ELSE
1027$!
1028$! Tell The User We Are Compile Without The RSAREF Routines.
1029$!
1030$ WRITE SYS$OUTPUT "Compiling Without The RSAREF Routines.
1031$!
1032$! End The RSAREF Check.
1033$!
1034$ ENDIF
1035$!
1036$! Finish up the definition of CC.
1037$!
1038$ IF COMPILER .EQS. "DECC"
1039$ THEN
1040$ IF CCDISABLEWARNINGS .EQS. ""
1041$ THEN
1042$ CC4DISABLEWARNINGS = "DOLLARID"
1043$ ELSE
1044$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
1045$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
1046$ ENDIF
1047$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
1048$ ELSE
1049$ CCDISABLEWARNINGS = ""
1050$ CC4DISABLEWARNINGS = ""
1051$ ENDIF
1052$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
1053$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
1054$ IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P2 .NES. "DEBUG"
1055$ THEN
1056$ CC5 = CC + "/OPTIMIZE=NODISJOINT"
1057$ ELSE
1058$ CC5 = CC + "/NOOPTIMIZE"
1059$ ENDIF
1060$ CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
1061$!
1062$! Show user the result
1063$!
1064$ WRITE SYS$OUTPUT "Main C Compiling Command: ",CC
1065$!
1066$! Else The User Entered An Invalid Arguement.
1067$!
1068$ ELSE
1069$!
1070$! Tell The User We Don't Know What They Want.
1071$!
1072$ WRITE SYS$OUTPUT ""
1073$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
1074$ WRITE SYS$OUTPUT ""
1075$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
1076$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
1077$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
1078$ WRITE SYS$OUTPUT ""
1079$!
1080$! Time To EXIT.
1081$!
1082$ EXIT
1083$!
1084$! End The Valid Arguement Check.
1085$!
1086$ ENDIF
1087$!
1088$! Build a MACRO command for the architecture at hand
1089$!
1090$ IF ARCH .EQS. "VAX" THEN MACRO = "MACRO/''DEBUGGER'"
1091$ IF ARCH .EQS. "AXP" THEN MACRO = "MACRO/MIGRATION/''DEBUGGER'/''MACRO_OPTIMIZE'"
1092$!
1093$! Show user the result
1094$!
1095$ WRITE SYS$OUTPUT "Main MACRO Compiling Command: ",MACRO
1096$!
1097$! Time to check the contents, and to make sure we get the correct library.
1098$!
1099$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX"
1100$ THEN
1101$!
1102$! Check to see if SOCKETSHR was chosen
1103$!
1104$ IF P4.EQS."SOCKETSHR"
1105$ THEN
1106$!
1107$! Set the library to use SOCKETSHR
1108$!
1109$ TCPIP_LIB = "[-.VMS]SOCKETSHR_SHR.OPT/OPT"
1110$!
1111$! Done with SOCKETSHR
1112$!
1113$ ENDIF
1114$!
1115$! Check to see if MULTINET was chosen
1116$!
1117$ IF P4.EQS."MULTINET"
1118$ THEN
1119$!
1120$! Set the library to use UCX emulation.
1121$!
1122$ P4 = "UCX"
1123$!
1124$! Done with MULTINET
1125$!
1126$ ENDIF
1127$!
1128$! Check to see if UCX was chosen
1129$!
1130$ IF P4.EQS."UCX"
1131$ THEN
1132$!
1133$! Set the library to use UCX.
1134$!
1135$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC.OPT/OPT"
1136$ IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
1137$ THEN
1138$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
1139$ ELSE
1140$ IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
1141 TCPIP_LIB = "[-.VMS]UCX_SHR_VAXC.OPT/OPT"
1142$ ENDIF
1143$!
1144$! Done with UCX
1145$!
1146$ ENDIF
1147$!
1148$! Print info
1149$!
1150$ WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
1151$!
1152$! Else The User Entered An Invalid Arguement.
1153$!
1154$ ELSE
1155$!
1156$! Tell The User We Don't Know What They Want.
1157$!
1158$ WRITE SYS$OUTPUT ""
1159$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:"
1160$ WRITE SYS$OUTPUT ""
1161$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library."
1162$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library."
1163$ WRITE SYS$OUTPUT ""
1164$!
1165$! Time To EXIT.
1166$!
1167$ EXIT
1168$!
1169$! Done with TCP/IP libraries
1170$!
1171$ ENDIF
1172$!
1173$! Check if the user wanted to compile just a subset of all the encryption
1174$! methods.
1175$!
1176$ IF P6 .NES. ""
1177$ THEN
1178$ ENCRYPT_TYPES = P6
1179$ ENDIF
1180$!
1181$! Time To RETURN...
1182$!
1183$ RETURN
1184$!
1185$ INITIALISE:
1186$!
1187$! Save old value of the logical name OPENSSL
1188$!
1189$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
1190$!
1191$! Save directory information
1192$!
1193$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
1194$ __TOP = __HERE - "CRYPTO]"
1195$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
1196$!
1197$! Set up the logical name OPENSSL to point at the include directory
1198$!
1199$ DEFINE OPENSSL/NOLOG '__INCLUDE'
1200$!
1201$! Done
1202$!
1203$ RETURN
1204$!
1205$ CLEANUP:
1206$!
1207$! Restore the logical name OPENSSL if it had a value
1208$!
1209$ IF __SAVE_OPENSSL .EQS. ""
1210$ THEN
1211$ DEASSIGN OPENSSL
1212$ ELSE
1213$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
1214$ ENDIF
1215$!
1216$! Done
1217$!
1218$ 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 @@
1/* crypto/crypto.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* If you are happy to use the assmbler version of bn/bn_mulw.c, define
60 * BN_ASM */
61#ifndef BN_ASM
62#undef BN_ASM
63#define X86_ASM
64#endif
65
66#ifndef DES_ASM
67#undef DES_ASM
68#endif
69
70#ifndef BF_ASM
71#undef BF_ASM
72#endif
73
74/* The following defines are only to break the compiles into chunks.
75 * If you wish to not compile some sections, use the 'NO_XXX' macros
76 */
77#ifndef CRYPTO_SUBSET
78/* Define all subset symbols. */
79#define CRYPTO_LIB_SUBSET
80#define CRYPTO_ASN1_SUBSET
81#define CRYPTO_BN_SUBSET
82#define CRYPTO_BUFFER_SUBSET
83#define CRYPTO_BIO_SUBSET
84#define CRYPTO_CONF_SUBSET
85#define CRYPTO_DES_SUBSET
86#define CRYPTO_DH_SUBSET
87#define CRYPTO_DSA_SUBSET
88#define CRYPTO_ERROR_SUBSET
89#define CRYPTO_EVP_SUBSET
90#define CRYPTO_IDEA_SUBSET
91#define CRYPTO_LHASH_SUBSET
92#define CRYPTO_MD_SUBSET
93#define CRYPTO_MDC2_SUBSET
94#define CRYPTO_METH_SUBSET
95#define CRYPTO_OBJECTS_SUBSET
96#define CRYPTO_PEM_SUBSET
97#define CRYPTO_RAND_SUBSET
98#define CRYPTO_RC_SUBSET
99#define CRYPTO_BLOWFISH_SUBSET
100#define CRYPTO_CAST_SUBSET
101#define CRYPTO_RSA_SUBSET
102#define CRYPTO_SHA_SUBSET
103#define CRYPTO_HMAC_SUBSET
104#define CRYPTO_SHA1_SUBSET
105#define CRYPTO_STACK_SUBSET
106#define CRYPTO_TXT_DB_SUBSET
107#define CRYPTO_X509_SUBSET
108#define CRYPTO_PKCS7_SUBSET
109#endif
110
111#include <stdio.h>
112#include <stdlib.h>
113#include <string.h>
114
115#define USE_SOCKETS
116#include "../e_os.h"
117
118#include "buffer.h"
119#include "bio.h"
120#include "stack.h"
121#include "lhash.h"
122
123#include "err.h"
124
125#include "bn.h"
126#include "evp.h"
127
128#include "rand.h"
129#include "conf.h"
130#include "txt_db.h"
131
132#include "x509.h"
133#include "pkcs7.h"
134#include "pem.h"
135#include "asn1.h"
136#include "objects.h"
137
138#ifdef CRYPTO_LIB_SUBSET
139#include "cryptlib.c"
140#include "mem.c"
141#include "cversion.c"
142#endif
143
144#ifdef CRYPTO_ASN1_SUBSET
145#include "asn1/a_meth.c"
146#include "asn1/a_bitstr.c"
147#include "asn1/a_d2i_fp.c"
148#include "asn1/a_dup.c"
149#include "asn1/a_hdr.c"
150#include "asn1/a_i2d_fp.c"
151#include "asn1/a_int.c"
152#include "asn1/a_bool.c"
153#include "asn1/a_bytes.c"
154#include "asn1/a_object.c"
155#include "asn1/a_octet.c"
156#include "asn1/a_print.c"
157#include "asn1/a_set.c"
158#include "asn1/a_sign.c"
159#include "asn1/a_type.c"
160#include "asn1/a_utctm.c"
161#include "asn1/a_verify.c"
162#include "asn1/a_digest.c"
163#include "asn1/asn1_err.c"
164#include "asn1/asn1_lib.c"
165#include "asn1/asn1_par.c"
166#ifndef NO_DH
167#include "asn1/d2i_dhp.c"
168#include "asn1/i2d_dhp.c"
169#endif
170#ifndef NO_DSA
171#include "asn1/d2i_dsap.c"
172#include "asn1/i2d_dsap.c"
173#include "asn1/d2i_s_pr.c"
174#include "asn1/i2d_s_pr.c"
175#include "asn1/d2i_s_pu.c"
176#include "asn1/i2d_s_pu.c"
177#endif
178#ifndef NO_RSA
179#include "asn1/d2i_r_pr.c"
180#include "asn1/i2d_r_pr.c"
181#include "asn1/d2i_r_pu.c"
182#include "asn1/i2d_r_pu.c"
183#include "asn1/n_pkey.c"
184#endif
185#include "asn1/d2i_pr.c"
186#include "asn1/d2i_pu.c"
187#include "asn1/i2d_pr.c"
188#include "asn1/i2d_pu.c"
189#include "asn1/f_int.c"
190#include "asn1/f_string.c"
191#include "asn1/p7_dgst.c"
192#include "asn1/p7_enc.c"
193#include "asn1/p7_enc_c.c"
194#include "asn1/p7_evp.c"
195#include "asn1/p7_i_s.c"
196#include "asn1/p7_lib.c"
197#include "asn1/p7_recip.c"
198#include "asn1/p7_s_e.c"
199#include "asn1/p7_signd.c"
200#include "asn1/p7_signi.c"
201#include "asn1/t_pkey.c"
202#include "asn1/t_req.c"
203#include "asn1/t_x509.c"
204#include "asn1/x_algor.c"
205#include "asn1/x_attrib.c"
206#include "asn1/x_exten.c"
207#include "asn1/x_cinf.c"
208#include "asn1/x_crl.c"
209#include "asn1/x_info.c"
210#include "asn1/x_name.c"
211#include "asn1/x_pkey.c"
212#include "asn1/x_pubkey.c"
213#include "asn1/x_req.c"
214#include "asn1/x_sig.c"
215#include "asn1/x_spki.c"
216#include "asn1/x_val.c"
217#include "asn1/x_x509.c"
218#endif
219
220#ifdef CRYPTO_BN_SUBSET
221#include "bn/bn_add.c"
222#include "bn/bn_div.c"
223#include "bn/bn_exp.c"
224#include "bn/bn_mont.c"
225#include "bn/bn_recp.c"
226#include "bn/bn_gcd.c"
227#include "bn/bn_lib.c"
228#include "bn/bn_mod.c"
229#include "bn/bn_mul.c"
230#ifndef BN_ASM
231#include "bn/bn_mulw.c"
232#endif
233#include "bn/bn_prime.c"
234#include "bn/bn_rand.c"
235#include "bn/bn_shift.c"
236#include "bn/bn_sqr.c"
237#include "bn/bn_sub.c"
238#include "bn/bn_word.c"
239#include "bn/bn_print.c"
240#include "bn/bn_err.c"
241#include "bn/bn_blind.c"
242#endif
243
244#ifdef CRYPTO_BIO_SUBSET
245#include "bio/bf_buff.c"
246#include "bio/bf_null.c"
247#include "bio/bf_nbio.c"
248#include "bio/bio_cb.c"
249#include "bio/bio_lib.c"
250#include "bio/bss_fd.c"
251#include "bio/bss_file.c"
252#include "bio/bss_mem.c"
253#include "bio/bss_null.c"
254#ifdef VMS
255#include "bio/bss_rtcp.c"
256#endif
257#include "bio/bss_sock.c"
258#include "bio/bss_conn.c"
259#include "bio/bss_acpt.c"
260#include "bio/b_sock.c"
261#include "bio/b_print.c"
262#include "bio/b_dump.c"
263#include "bio/bio_err.c"
264#endif
265
266#ifdef CRYPTO_BUFFER_SUBSET
267#include "buffer/buf_err.c"
268#include "buffer/buffer.c"
269#endif
270
271#ifdef CRYPTO_CONF_SUBSET
272#include "conf/conf.c"
273#include "conf/conf_err.c"
274#endif
275
276#ifdef CRYPTO_DES_SUBSET
277#include "des/read_pwd.c"
278#ifndef NO_DES
279#ifndef DES_ASM
280#include "des/fcrypt_b.c"
281#include "des/des_enc.c"
282#endif
283#include "des/cbc_cksm.c"
284#include "des/xcbc_enc.c"
285#include "des/cbc_enc.c"
286#include "des/cfb64ede.c"
287#include "des/cfb64enc.c"
288#include "des/cfb_enc.c"
289#include "des/ecb3_enc.c"
290#include "des/ecb_enc.c"
291#include "des/enc_read.c"
292#include "des/enc_writ.c"
293#include "des/fcrypt.c"
294#include "des/ofb64ede.c"
295#include "des/ofb64enc.c"
296#include "des/ofb_enc.c"
297#include "des/pcbc_enc.c"
298#include "des/qud_cksm.c"
299#include "des/rand_key.c"
300#include "des/read2pwd.c"
301#include "des/rpc_enc.c"
302#include "des/set_key.c"
303#include "des/str2key.c"
304#include "des/supp.c"
305#endif
306#endif
307
308#ifdef CRYPTO_DH_SUBSET
309#ifndef NO_DH
310#include "dh/dh_check.c"
311#include "dh/dh_err.c"
312#include "dh/dh_gen.c"
313#include "dh/dh_key.c"
314#include "dh/dh_lib.c"
315#endif
316#endif
317
318#ifdef CRYPTO_DSA_SUBSET
319#ifndef NO_DSA
320#include "dsa/dsa_gen.c"
321#include "dsa/dsa_key.c"
322#include "dsa/dsa_lib.c"
323#include "dsa/dsa_sign.c"
324#include "dsa/dsa_vrf.c"
325#include "dsa/dsa_err.c"
326#endif
327#endif
328
329#ifdef CRYPTO_ERROR_SUBSET
330#include "err/err.c"
331#include "err/err_all.c"
332#include "err/err_prn.c"
333#endif
334
335#ifdef CRYPTO_EVP_SUBSET
336#include "evp/bio_md.c"
337#include "evp/bio_b64.c"
338#include "evp/bio_enc.c"
339#include "evp/c_all.c"
340#include "evp/digest.c"
341#ifndef NO_DES
342#include "evp/e_cbc_3d.c"
343#include "evp/e_cfb_3d.c"
344#include "evp/e_ecb_3d.c"
345#include "evp/e_ofb_3d.c"
346#include "evp/e_cbc_d.c"
347#include "evp/e_cfb_d.c"
348#include "evp/e_xcbc_d.c"
349#include "evp/e_ecb_d.c"
350#include "evp/e_ofb_d.c"
351#endif
352#ifndef NO_IDEA
353#include "evp/e_cbc_i.c"
354#include "evp/e_cfb_i.c"
355#include "evp/e_ecb_i.c"
356#include "evp/e_ofb_i.c"
357#endif
358#ifndef NO_RC2
359#include "evp/e_cbc_r2.c"
360#include "evp/e_cfb_r2.c"
361#include "evp/e_ecb_r2.c"
362#include "evp/e_ofb_r2.c"
363#endif
364#ifndef NO_BLOWFISH
365#include "evp/e_cbc_bf.c"
366#include "evp/e_cfb_bf.c"
367#include "evp/e_ecb_bf.c"
368#include "evp/e_ofb_bf.c"
369#endif
370#ifndef NO_CAST
371#include "evp/e_cbc_c.c"
372#include "evp/e_cfb_c.c"
373#include "evp/e_ecb_c.c"
374#include "evp/e_ofb_c.c"
375#endif
376#ifndef NO_RC4
377#include "evp/e_rc4.c"
378#endif
379#include "rc5/rc5_enc.c"
380#include "rc5/rc5cfb64.c"
381#include "rc5/rc5_ecb.c"
382#include "rc5/rc5_skey.c"
383#include "rc5/rc5ofb64.c"
384#include "ripemd/rmd160.c"
385#include "ripemd/rmd_dgst.c"
386#include "ripemd/rmd_one.c"
387#include "evp/evp_lib.c"
388
389#include "evp/names.c"
390#include "evp/e_null.c"
391#include "evp/encode.c"
392#include "evp/evp_enc.c"
393#include "evp/evp_err.c"
394#include "evp/evp_key.c"
395#include "evp/m_null.c"
396#include "evp/p_lib.c"
397#ifndef NO_RSA
398#include "evp/p_open.c"
399#include "evp/p_seal.c"
400#endif
401#include "evp/p_sign.c"
402#include "evp/p_verify.c"
403#endif
404
405#ifdef CRYPTO_IDEA_SUBSET
406#ifndef NO_IDEA
407#include "idea/i_cbc.c"
408#include "idea/i_cfb64.c"
409#include "idea/i_ecb.c"
410#include "idea/i_ofb64.c"
411#include "idea/i_skey.c"
412#endif
413#endif
414
415#ifdef CRYPTO_BLOWFISH_SUBSET
416#ifndef NO_BLOWFISH
417#include "bf/bf_cfb64.c"
418#include "bf/bf_ecb.c"
419#ifndef BF_ASM
420#include "bf/bf_enc.c"
421#endif
422#include "bf/bf_ofb64.c"
423#include "bf/bf_skey.c"
424#endif
425#endif
426
427#ifdef CRYPTO_CAST_SUBSET
428#ifndef NO_CAST
429#include "cast/c_cfb64.c"
430#include "cast/c_ecb.c"
431#ifndef CAST_ASM
432#include "cast/c_enc.c"
433#endif
434#include "cast/c_ofb64.c"
435#include "cast/c_skey.c"
436#endif
437#endif
438
439#ifdef CRYPTO_LHASH_SUBSET
440#include "lhash/lh_stats.c"
441#include "lhash/lhash.c"
442#endif
443
444#ifdef CRYPTO_MD_SUBSET
445#ifndef NO_MD2
446#include "md2/md2_dgst.c"
447#include "md2/md2_one.c"
448#include "evp/m_md2.c"
449#endif
450#ifndef NO_MD5
451#include "md5/md5_dgst.c"
452#include "md5/md5_one.c"
453#include "evp/m_md5.c"
454#endif
455#endif
456
457#ifdef CRYPTO_MDC2_SUBSET
458#ifndef NO_MDC2
459#include "mdc2/mdc2dgst.c"
460#include "mdc2/mdc2_one.c"
461#include "evp/m_mdc2.c"
462#endif
463#endif
464
465#ifdef CRYPTO_OBJECTS_SUBSET
466#include "objects/obj_dat.c"
467#include "objects/obj_err.c"
468#include "objects/obj_lib.c"
469#endif
470
471#ifdef CRYPTO_PEM_SUBSET
472#include "pem/pem_err.c"
473#include "pem/pem_info.c"
474#include "pem/pem_lib.c"
475#include "pem/pem_all.c"
476#ifndef NO_RSA
477#include "pem/pem_seal.c"
478#include "pem/pem_sign.c"
479#endif
480#endif
481
482#ifdef CRYPTO_RAND_SUBSET
483#include "rand/md_rand.c"
484#include "rand/randfile.c"
485#endif
486
487#ifdef CRYPTO_RC_SUBSET
488#ifndef NO_RC2
489#include "rc2/rc2_cbc.c"
490#include "rc2/rc2_ecb.c"
491#include "rc2/rc2_skey.c"
492#include "rc2/rc2cfb64.c"
493#include "rc2/rc2ofb64.c"
494#endif
495#ifndef NO_RC4
496#include "rc4/rc4_skey.c"
497#ifndef RC4_ASM
498#include "rc4/rc4_enc.c"
499#endif
500#endif
501#endif
502
503#ifdef CRYPTO_HMAC_SUBSET
504#include "hmac/hmac.c"
505#endif
506
507#ifdef CRYPTO_RSA_SUBSET
508#ifndef NO_RSA
509#include "rsa/rsa_eay.c"
510#include "rsa/rsa_err.c"
511#include "rsa/rsa_gen.c"
512#include "rsa/rsa_lib.c"
513#include "rsa/rsa_sign.c"
514#include "rsa/rsa_saos.c"
515#endif
516#endif
517
518#ifdef CRYPTO_SHA1_SUBSET
519#ifndef NO_SHA1
520#include "sha/sha1_one.c"
521#include "sha/sha1dgst.c"
522#include "evp/m_dss1.c"
523#include "evp/m_sha1.c"
524#endif
525#endif
526
527#ifdef CRYPTO_SHA_SUBSET
528#ifndef NO_SHA
529#include "evp/m_dss.c"
530#include "sha/sha_dgst.c"
531#include "sha/sha_one.c"
532#include "evp/m_sha.c"
533#endif
534#endif
535
536#ifdef CRYPTO_STACK_SUBSET
537#include "stack/stack.c"
538#endif
539
540#ifdef CRYPTO_TXT_DB_SUBSET
541#include "txt_db/txt_db.c"
542#endif
543
544#ifdef CRYPTO_X509_SUBSET
545#include "x509/x509_cmp.c"
546#include "x509/x509_d2.c"
547#include "x509/x509_def.c"
548#include "x509/x509_err.c"
549#include "x509/x509_ext.c"
550#include "x509/x509_lu.c"
551#include "x509/x509_obj.c"
552#include "x509/x509_r2x.c"
553#include "x509/x509_req.c"
554#include "x509/x509_set.c"
555#include "x509/x509_v3.c"
556#include "x509/x509_vfy.c"
557#include "x509/x509name.c"
558#include "x509/x509pack.c"
559#include "x509/x509rset.c"
560#include "x509/x509type.c"
561#include "x509/x_all.c"
562#include "x509/x509_txt.c"
563#include "x509/by_dir.c"
564#include "x509/by_file.c"
565#include "x509/v3_net.c"
566#include "x509/v3_x509.c"
567#endif
568
569
570#ifdef CRYPTO_PKCS7_SUBSET /* I have an explicit removal of 7 lines */
571#include "pkcs7/pk7_lib.c"
572#include "pkcs7/pkcs7err.c"
573#include "pkcs7/pk7_doit.c"
574#endif /* CRYPTO_PKCS7_SUBSET */
575
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 @@
1/* Error codes for the CRYPTO functions. */
2
3/* Function codes. */
4#define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100
5#define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101
6#define CRYPTO_F_CRYPTO_SET_EX_DATA 102
7
8/* 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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "stack.h" 66#ifndef NO_FP_API
67#include <stdio.h>
68#endif
67 69
70#include <openssl/stack.h>
71#include <openssl/opensslv.h>
72
73#ifdef CHARSET_EBCDIC
74#include <openssl/ebcdic.h>
75#endif
76
77/* Backward compatibility to SSLeay */
68/* This is more to be used to check the correct DLL is being used 78/* This is more to be used to check the correct DLL is being used
69 * in the MS world. */ 79 * in the MS world. */
70#define SSLEAY_VERSION_NUMBER 0x0902 /* Version 0.5.1c would be 0513 */ 80#define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
71
72#define SSLEAY_VERSION 0 81#define SSLEAY_VERSION 0
73/* #define SSLEAY_OPTIONS 1 no longer supported */ 82/* #define SSLEAY_OPTIONS 1 no longer supported */
74#define SSLEAY_CFLAGS 2 83#define SSLEAY_CFLAGS 2
75#define SSLEAY_BUILT_ON 3 84#define SSLEAY_BUILT_ON 3
85#define SSLEAY_PLATFORM 4
76 86
77/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock 87/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
78 * names in cryptlib.c 88 * names in cryptlib.c
@@ -92,19 +102,23 @@ extern "C" {
92#define CRYPTO_LOCK_SSL_CTX 12 102#define CRYPTO_LOCK_SSL_CTX 12
93#define CRYPTO_LOCK_SSL_CERT 13 103#define CRYPTO_LOCK_SSL_CERT 13
94#define CRYPTO_LOCK_SSL_SESSION 14 104#define CRYPTO_LOCK_SSL_SESSION 14
95#define CRYPTO_LOCK_SSL 15 105#define CRYPTO_LOCK_SSL_SESS_CERT 15
96#define CRYPTO_LOCK_RAND 16 106#define CRYPTO_LOCK_SSL 16
97#define CRYPTO_LOCK_MALLOC 17 107#define CRYPTO_LOCK_RAND 17
98#define CRYPTO_LOCK_BIO 18 108#define CRYPTO_LOCK_MALLOC 18
99#define CRYPTO_LOCK_BIO_GETHOSTBYNAME 19 109#define CRYPTO_LOCK_BIO 19
100#define CRYPTO_LOCK_RSA_BLINDING 20 110#define CRYPTO_LOCK_GETHOSTBYNAME 20
101#define CRYPTO_NUM_LOCKS 21 111#define CRYPTO_LOCK_GETSERVBYNAME 21
112#define CRYPTO_LOCK_READDIR 22
113#define CRYPTO_LOCK_RSA_BLINDING 23
114#define CRYPTO_NUM_LOCKS 24
102 115
103#define CRYPTO_LOCK 1 116#define CRYPTO_LOCK 1
104#define CRYPTO_UNLOCK 2 117#define CRYPTO_UNLOCK 2
105#define CRYPTO_READ 4 118#define CRYPTO_READ 4
106#define CRYPTO_WRITE 8 119#define CRYPTO_WRITE 8
107 120
121#ifndef NO_LOCKING
108#ifndef CRYPTO_w_lock 122#ifndef CRYPTO_w_lock
109#define CRYPTO_w_lock(type) \ 123#define CRYPTO_w_lock(type) \
110 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__) 124 CRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,__FILE__,__LINE__)
@@ -116,14 +130,22 @@ extern "C" {
116 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__) 130 CRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_READ,type,__FILE__,__LINE__)
117#define CRYPTO_add(addr,amount,type) \ 131#define CRYPTO_add(addr,amount,type) \
118 CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__) 132 CRYPTO_add_lock(addr,amount,type,__FILE__,__LINE__)
119 133#endif
134#else
135#define CRYPTO_w_lock(a)
136#define CRYPTO_w_unlock(a)
137#define CRYPTO_r_lock(a)
138#define CRYPTO_r_unlock(a)
139#define CRYPTO_add(a,b,c) ((*(a))+=(b))
120#endif 140#endif
121 141
122/* The following can be used to detect memory leaks in the SSLeay library. 142/* The following can be used to detect memory leaks in the SSLeay library.
123 * It used, it turns on malloc checking */ 143 * It used, it turns on malloc checking */
124 144
125#define CRYPTO_MEM_CHECK_OFF 0x0 145#define CRYPTO_MEM_CHECK_OFF 0x0 /* an enume */
126#define CRYPTO_MEM_CHECK_ON 0x1 146#define CRYPTO_MEM_CHECK_ON 0x1 /* a bit */
147#define CRYPTO_MEM_CHECK_ENABLE 0x2 /* a bit */
148#define CRYPTO_MEM_CHECK_DISABLE 0x3 /* an enume */
127 149
128/* 150/*
129typedef struct crypto_mem_st 151typedef struct crypto_mem_st
@@ -178,37 +200,65 @@ typedef struct crypto_ex_data_func_st
178 (char *(*)())realloc,\ 200 (char *(*)())realloc,\
179 (void (*)())free) 201 (void (*)())free)
180 202
203#ifdef CRYPTO_MDEBUG_ALL
204# ifndef CRYPTO_MDEBUG_TIME
205# define CRYPTO_MDEBUG_TIME
206# endif
207# ifndef CRYPTO_MDEBUG_THREAD
208# define CRYPTO_MDEBUG_THREAD
209# endif
210#endif
211
212#if defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
213# ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
214# define CRYPTO_MDEBUG
215# endif
216#endif
217
181#ifdef CRYPTO_MDEBUG 218#ifdef CRYPTO_MDEBUG
219#define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
220#define MemCheck_stop() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
221#define MemCheck_on() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
222#define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
182#define Malloc(num) CRYPTO_dbg_malloc((int)num,__FILE__,__LINE__) 223#define Malloc(num) CRYPTO_dbg_malloc((int)num,__FILE__,__LINE__)
183#define Realloc(addr,num) \ 224#define Realloc(addr,num) \
184 CRYPTO_dbg_realloc((char *)addr,(int)num,__FILE__,__LINE__) 225 CRYPTO_dbg_realloc((char *)addr,(int)num,__FILE__,__LINE__)
185#define Remalloc(addr,num) \ 226#define Remalloc(addr,num) \
186 CRYPTO_dbg_remalloc((char **)addr,(int)num,__FILE__,__LINE__) 227 CRYPTO_dbg_remalloc((char **)addr,(int)num,__FILE__,__LINE__)
187#define FreeFunc CRYPTO_dbg_free 228#define FreeFunc CRYPTO_dbg_free
188#define Free(addr) CRYPTO_dbg_free((char *)(addr)) 229#define Free(addr) CRYPTO_dbg_free(addr)
230#define Malloc_locked(num) CRYPTO_malloc_locked((int)num)
231#define Free_locked(addr) CRYPTO_free_locked(addr)
189#else 232#else
233#define MemCheck_start()
234#define MemCheck_stop()
235#define MemCheck_on()
236#define MemCheck_off()
190#define Remalloc CRYPTO_remalloc 237#define Remalloc CRYPTO_remalloc
191#if defined(WIN32) || defined(MFUNC) 238#if defined(WIN32) || defined(MFUNC)
192#define Malloc CRYPTO_malloc 239#define Malloc CRYPTO_malloc
193#define Realloc(a,n) CRYPTO_realloc((char *)(a),(n)) 240#define Realloc(a,n) CRYPTO_realloc(a,(n))
194#define FreeFunc CRYPTO_free 241#define FreeFunc CRYPTO_free
195#define Free(addr) CRYPTO_free((char *)(addr)) 242#define Free(addr) CRYPTO_free(addr)
243#define Malloc_locked CRYPTO_malloc_locked
244#define Free_locked(addr) CRYPTO_free_locked(addr)
196#else 245#else
197#define Malloc malloc 246#define Malloc malloc
198#define Realloc realloc 247#define Realloc realloc
199#define FreeFunc free 248#define FreeFunc free
200#define Free(addr) free((char *)(addr)) 249#define Free(addr) free(addr)
250#define Malloc_locked malloc
251#define Free_locked(addr) free(addr)
201#endif /* WIN32 || MFUNC */ 252#endif /* WIN32 || MFUNC */
202#endif /* MDEBUG */ 253#endif /* MDEBUG */
203 254
204/* Case insensiteve linking causes problems.... */ 255/* Case insensiteve linking causes problems.... */
205#ifdef WIN16 256#if defined(WIN16) || defined(VMS)
206#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings 257#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
207#endif 258#endif
208 259
209#ifndef NOPROTO
210 260
211char *SSLeay_version(int type); 261const char *SSLeay_version(int type);
212unsigned long SSLeay(void); 262unsigned long SSLeay(void);
213 263
214int CRYPTO_get_ex_new_index(int idx,STACK **sk,long argl,char *argp, 264int 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);
221 271
222int CRYPTO_mem_ctrl(int mode); 272int CRYPTO_mem_ctrl(int mode);
223int CRYPTO_get_new_lockid(char *name); 273int CRYPTO_get_new_lockid(char *name);
224void CRYPTO_lock(int mode, int type,char *file,int line); 274
225void CRYPTO_set_locking_callback(void (*func)(int mode,int type,char *file, 275int CRYPTO_num_locks(void); /* return CRYPTO_NUM_LOCKS (shared libs!) */
226 int line)); 276void CRYPTO_lock(int mode, int type,const char *file,int line);
227void (*CRYPTO_get_locking_callback(void))(int mode,int type,char *file, 277void CRYPTO_set_locking_callback(void (*func)(int mode,int type,
278 const char *file,int line));
279void (*CRYPTO_get_locking_callback(void))(int mode,int type,const char *file,
228 int line); 280 int line);
229void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount, 281void CRYPTO_set_add_lock_callback(int (*func)(int *num,int mount,int type,
230 int type,char *file, int line)); 282 const char *file, int line));
231int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount, 283int (*CRYPTO_get_add_lock_callback(void))(int *num,int mount,int type,
232 int type,char *file,int line); 284 const char *file,int line);
233void CRYPTO_set_id_callback(unsigned long (*func)(void)); 285void CRYPTO_set_id_callback(unsigned long (*func)(void));
234unsigned long (*CRYPTO_get_id_callback(void))(void); 286unsigned long (*CRYPTO_get_id_callback(void))(void);
235unsigned long CRYPTO_thread_id(void); 287unsigned long CRYPTO_thread_id(void);
236char *CRYPTO_get_lock_name(int type); 288const char *CRYPTO_get_lock_name(int type);
237int CRYPTO_add_lock(int *pointer,int amount,int type, char *file,int line); 289int CRYPTO_add_lock(int *pointer,int amount,int type, const char *file,
290 int line);
238 291
239void CRYPTO_set_mem_functions(char *(*m)(),char *(*r)(), void (*free_func)()); 292void CRYPTO_set_mem_functions(char *(*m)(),char *(*r)(), void (*free_func)());
240void CRYPTO_get_mem_functions(char *(**m)(),char *(**r)(), void (**f)()); 293void CRYPTO_get_mem_functions(char *(**m)(),char *(**r)(), void (**f)());
241 294void CRYPTO_set_locked_mem_functions(char *(*m)(), void (*free_func)());
242char *CRYPTO_malloc(int num); 295void CRYPTO_get_locked_mem_functions(char *(**m)(), void (**f)());
243char *CRYPTO_realloc(char *addr,int num); 296
244void CRYPTO_free(char *); 297void *CRYPTO_malloc_locked(int num);
245char *CRYPTO_remalloc(char *addr,int num); 298void CRYPTO_free_locked(void *);
246 299void *CRYPTO_malloc(int num);
247char *CRYPTO_dbg_malloc(int num,char *file,int line); 300void CRYPTO_free(void *);
248char *CRYPTO_dbg_realloc(char *addr,int num,char *file,int line); 301void *CRYPTO_realloc(void *addr,int num);
249void CRYPTO_dbg_free(char *); 302void *CRYPTO_remalloc(void *addr,int num);
250char *CRYPTO_dbg_remalloc(char *addr,int num,char *file,int line); 303
304void *CRYPTO_dbg_malloc(int num,const char *file,int line);
305void *CRYPTO_dbg_realloc(void *addr,int num,const char *file,int line);
306void CRYPTO_dbg_free(void *);
307void *CRYPTO_dbg_remalloc(void *addr,int num,const char *file,int line);
251#ifndef NO_FP_API 308#ifndef NO_FP_API
252void CRYPTO_mem_leaks_fp(FILE *); 309void CRYPTO_mem_leaks_fp(FILE *);
253#endif 310#endif
@@ -257,52 +314,11 @@ void CRYPTO_mem_leaks_cb(void (*cb)());
257 314
258void ERR_load_CRYPTO_strings(void ); 315void ERR_load_CRYPTO_strings(void );
259 316
260#else
261
262int CRYPTO_get_ex_new_index();
263int CRYPTO_set_ex_data();
264char *CRYPTO_get_ex_data();
265int CRYPTO_dup_ex_data();
266void CRYPTO_free_ex_data();
267void CRYPTO_new_ex_data();
268
269int CRYPTO_mem_ctrl();
270char *SSLeay_version();
271unsigned long SSLeay();
272
273int CRYPTO_get_new_lockid();
274void CRYPTO_lock();
275void CRYPTO_set_locking_callback();
276void (*CRYPTO_get_locking_callback())();
277void CRYPTO_set_add_lock_callback();
278int (*CRYPTO_get_add_lock_callback())();
279void CRYPTO_set_id_callback();
280unsigned long (*CRYPTO_get_id_callback())();
281unsigned long CRYPTO_thread_id();
282char *CRYPTO_get_lock_name();
283int CRYPTO_add_lock();
284
285void CRYPTO_set_mem_functions();
286void CRYPTO_get_mem_functions();
287char *CRYPTO_malloc();
288char *CRYPTO_realloc();
289void CRYPTO_free();
290char *CRYPTO_remalloc();
291char *CRYPTO_dbg_remalloc();
292char *CRYPTO_dbg_malloc();
293char *CRYPTO_dbg_realloc();
294void CRYPTO_dbg_free();
295#ifndef NO_FP_API
296void CRYPTO_mem_leaks_fp();
297#endif
298void CRYPTO_mem_leaks();
299void CRYPTO_mem_leaks_cb();
300
301void ERR_load_CRYPTO_strings();
302
303#endif
304
305/* BEGIN ERROR CODES */ 317/* BEGIN ERROR CODES */
318/* The following lines are auto generated by the script mkerr.pl. Any changes
319 * made after this point may be overwritten when the script is next run.
320 */
321
306/* Error codes for the CRYPTO functions. */ 322/* Error codes for the CRYPTO functions. */
307 323
308/* Function codes. */ 324/* Function codes. */
@@ -311,7 +327,7 @@ void ERR_load_CRYPTO_strings();
311#define CRYPTO_F_CRYPTO_SET_EX_DATA 102 327#define CRYPTO_F_CRYPTO_SET_EX_DATA 102
312 328
313/* Reason codes. */ 329/* Reason codes. */
314 330
315#ifdef __cplusplus 331#ifdef __cplusplus
316} 332}
317#endif 333#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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "crypto.h" 62#include <openssl/crypto.h>
63#include "date.h"
64 63
65char *SSLeay_version(t) 64#ifndef NO_WINDOWS_BRAINDEATH
66int t; 65#include "buildinf.h"
66#endif
67
68const char *SSLeay_version(int t)
67 { 69 {
68 if (t == SSLEAY_VERSION) 70 if (t == SSLEAY_VERSION)
69 return("SSLeay 0.9.0b 29-Jun-1998"); 71 return OPENSSL_VERSION_TEXT;
70 if (t == SSLEAY_BUILT_ON) 72 if (t == SSLEAY_BUILT_ON)
71 { 73 {
72#ifdef DATE 74#ifdef DATE
73 static char buf[sizeof(DATE)+10]; 75 static char buf[sizeof(DATE)+11];
74 76
75 sprintf(buf,"built on %s",DATE); 77 sprintf(buf,"built on: %s",DATE);
76 return(buf); 78 return(buf);
77#else 79#else
78 return("build date not available"); 80 return("built on: date not available");
79#endif 81#endif
80 } 82 }
81 if (t == SSLEAY_CFLAGS) 83 if (t == SSLEAY_CFLAGS)
82 { 84 {
83#ifdef CFLAGS 85#ifdef CFLAGS
84 static char buf[sizeof(CFLAGS)+10]; 86 static char buf[sizeof(CFLAGS)+11];
87
88 sprintf(buf,"compiler: %s",CFLAGS);
89 return(buf);
90#else
91 return("compiler: information not available");
92#endif
93 }
94 if (t == SSLEAY_PLATFORM)
95 {
96#ifdef PLATFORM
97 static char buf[sizeof(PLATFORM)+11];
85 98
86 sprintf(buf,"C flags:%s",CFLAGS); 99 sprintf(buf,"platform: %s", PLATFORM);
87 return(buf); 100 return(buf);
88#else 101#else
89 return("C flags not available"); 102 return("platform: information not available");
90#endif 103#endif
91 } 104 }
92 return("not available"); 105 return("not available");
93 } 106 }
94 107
95unsigned long SSLeay() 108unsigned long SSLeay(void)
96 { 109 {
97 return(SSLEAY_VERSION_NUMBER); 110 return(SSLEAY_VERSION_NUMBER);
98 } 111 }
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 @@
1#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
6TOP= ../.. 6TOP= ../..
7CC= cc 7CC= cc
8CPP= $(CC) -E 8CPP= $(CC) -E
9INCLUDES= 9INCLUDES=-I../../include
10CFLAG=-g 10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
11INSTALLTOP=/usr/local/ssl 13INSTALLTOP=/usr/local/ssl
12MAKE= make -f Makefile.ssl 14MAKE= make -f Makefile.ssl
13MAKEDEPEND= makedepend -f Makefile.ssl 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
14MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
15AR= ar r 17AR= ar r
16DES_ENC= des_enc.o fcrypt_b.o 18DES_ENC= des_enc.o fcrypt_b.o
@@ -19,7 +21,7 @@ DES_ENC= des_enc.o fcrypt_b.o
19 21
20CFLAGS= $(INCLUDES) $(CFLAG) 22CFLAGS= $(INCLUDES) $(CFLAG)
21 23
22GENERAL=Makefile des.org des_locl.org 24GENERAL=Makefile
23TEST=destest.c 25TEST=destest.c
24APPS= 26APPS=
25 27
@@ -30,14 +32,15 @@ LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \
30 qud_cksm.c rand_key.c read_pwd.c rpc_enc.c set_key.c \ 32 qud_cksm.c rand_key.c read_pwd.c rpc_enc.c set_key.c \
31 des_enc.c fcrypt_b.c read2pwd.c \ 33 des_enc.c fcrypt_b.c read2pwd.c \
32 fcrypt.c xcbc_enc.c \ 34 fcrypt.c xcbc_enc.c \
33 str2key.c cfb64ede.c ofb64ede.c supp.c 35 str2key.c cfb64ede.c ofb64ede.c supp.c ede_cbcm_enc.c
34 36
35LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \ 37LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \
36 ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \ 38 ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \
37 enc_read.o enc_writ.o ofb64enc.o \ 39 enc_read.o enc_writ.o ofb64enc.o \
38 ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \ 40 ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \
39 ${DES_ENC} read2pwd.o \ 41 ${DES_ENC} read2pwd.o \
40 fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o 42 fcrypt.o xcbc_enc.o read_pwd.o rpc_enc.o cbc_cksm.o supp.o \
43 ede_cbcm_enc.o
41 44
42SRC= $(LIBSRC) 45SRC= $(LIBSRC)
43 46
@@ -53,9 +56,12 @@ all: lib
53 56
54lib: $(LIBOBJ) 57lib: $(LIBOBJ)
55 $(AR) $(LIB) $(LIBOBJ) 58 $(AR) $(LIB) $(LIBOBJ)
56 sh $(TOP)/util/ranlib.sh $(LIB) 59 $(RANLIB) $(LIB)
57 @touch lib 60 @touch lib
58 61
62des: des.o cbc3_enc.o lib
63 $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB)
64
59# elf 65# elf
60asm/dx86-elf.o: asm/dx86unix.cpp 66asm/dx86-elf.o: asm/dx86unix.cpp
61 $(CPP) -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o 67 $(CPP) -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o
@@ -83,38 +89,34 @@ asm/yx86-out.o: asm/yx86unix.cpp
83 89
84# bsdi 90# bsdi
85asm/dx86bsdi.o: asm/dx86unix.cpp 91asm/dx86bsdi.o: asm/dx86unix.cpp
86 $(CPP) -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o 92 $(CPP) -DBSDI asm/dx86unix.cpp | sed 's/ :/:/' | as -o asm/dx86bsdi.o
87 93
88asm/yx86bsdi.o: asm/yx86unix.cpp 94asm/yx86bsdi.o: asm/yx86unix.cpp
89 $(CPP) -DBSDI asm/yx86unix.cpp | as -o asm/yx86bsdi.o 95 $(CPP) -DBSDI asm/yx86unix.cpp | sed 's/ :/:/' | as -o asm/yx86bsdi.o
90 96
91asm/dx86unix.cpp: 97asm/dx86unix.cpp: asm/des-586.pl
92 (cd asm; perl des-586.pl cpp >dx86unix.cpp) 98 (cd asm; $(PERL) des-586.pl cpp >dx86unix.cpp)
93 99
94asm/yx86unix.cpp: 100asm/yx86unix.cpp: asm/crypt586.pl
95 (cd asm; perl crypt586.pl cpp >yx86unix.cpp) 101 (cd asm; $(PERL) crypt586.pl cpp >yx86unix.cpp)
96 102
97files: 103files:
98 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 104 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
99 105
100links: 106links:
101 /bin/rm -f Makefile 107 @$(TOP)/util/point.sh Makefile.ssl Makefile
102 $(TOP)/util/point.sh Makefile.ssl Makefile 108 @$(TOP)/util/point.sh ../../perlasm asm/perlasm
103 /bin/rm -f des.doc 109 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
104 /bin/rm -fr asm/perlasm 110 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
105 $(TOP)/util/point.sh ../../perlasm asm/perlasm 111 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
106 $(TOP)/util/point.sh ../../doc/des.doc des.doc
107 $(TOP)/util/mklink.sh ../../include $(EXHEADER)
108 $(TOP)/util/mklink.sh ../../test $(TEST)
109 $(TOP)/util/mklink.sh ../../apps $(APPS)
110 112
111install: installs 113install: installs
112 114
113installs: 115installs:
114 @for i in $(EXHEADER) ; \ 116 @for i in $(EXHEADER) ; \
115 do \ 117 do \
116 (cp $$i $(INSTALLTOP)/include/$$i; \ 118 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
117 chmod 644 $(INSTALLTOP)/include/$$i ); \ 119 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
118 done; 120 done;
119 121
120tags: 122tags:
@@ -126,15 +128,81 @@ lint:
126 lint -DLINT $(INCLUDES) $(SRC)>fluff 128 lint -DLINT $(INCLUDES) $(SRC)>fluff
127 129
128depend: 130depend:
129 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 131 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
130 132
131dclean: 133dclean:
132 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 134 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
133 mv -f Makefile.new $(MAKEFILE) 135 mv -f Makefile.new $(MAKEFILE)
134 136
135clean: 137clean:
136 /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 138 rm -f asm/dx86unix.cpp asm/yx86unix.cpp *.o asm/*.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff
137
138errors:
139 139
140# DO NOT DELETE THIS LINE -- make depend depends on it. 140# DO NOT DELETE THIS LINE -- make depend depends on it.
141
142cbc_cksm.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
143cbc_cksm.o: ../../include/openssl/opensslconf.h des_locl.h
144cbc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
145cbc_enc.o: ../../include/openssl/opensslconf.h des_locl.h ncbc_enc.c
146cfb64ede.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
147cfb64ede.o: ../../include/openssl/opensslconf.h des_locl.h
148cfb64enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
149cfb64enc.o: ../../include/openssl/opensslconf.h des_locl.h
150cfb_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
151cfb_enc.o: ../../include/openssl/opensslconf.h des_locl.h
152des_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
153des_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_locl.h ncbc_enc.c
154ecb3_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
155ecb3_enc.o: ../../include/openssl/opensslconf.h des_locl.h
156ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
157ecb_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
158ecb_enc.o: des_locl.h spr.h
159ede_cbcm_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
160ede_cbcm_enc.o: ../../include/openssl/opensslconf.h des_locl.h
161enc_read.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
162enc_read.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
163enc_read.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
164enc_read.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
165enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
166enc_read.o: ../cryptlib.h des_locl.h
167enc_writ.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
168enc_writ.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
169enc_writ.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
170enc_writ.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
171enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
172enc_writ.o: ../../include/openssl/stack.h ../cryptlib.h des_locl.h
173fcrypt.o: ../../include/openssl/des.h ../../include/openssl/des.h
174fcrypt.o: ../../include/openssl/e_os2.h ../../include/openssl/e_os2.h
175fcrypt.o: ../../include/openssl/opensslconf.h
176fcrypt.o: ../../include/openssl/opensslconf.h des_locl.h des_locl.h
177fcrypt_b.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
178fcrypt_b.o: ../../include/openssl/opensslconf.h des_locl.h
179ofb64ede.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
180ofb64ede.o: ../../include/openssl/opensslconf.h des_locl.h
181ofb64enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
182ofb64enc.o: ../../include/openssl/opensslconf.h des_locl.h
183ofb_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
184ofb_enc.o: ../../include/openssl/opensslconf.h des_locl.h
185pcbc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
186pcbc_enc.o: ../../include/openssl/opensslconf.h des_locl.h
187qud_cksm.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
188qud_cksm.o: ../../include/openssl/opensslconf.h des_locl.h
189rand_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
190rand_key.o: ../../include/openssl/opensslconf.h des_locl.h
191read2pwd.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
192read2pwd.o: ../../include/openssl/opensslconf.h des_locl.h
193read_pwd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
194read_pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
195read_pwd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
196read_pwd.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
197read_pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
198read_pwd.o: ../cryptlib.h des_locl.h
199rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
200rpc_enc.o: ../../include/openssl/opensslconf.h des_locl.h des_ver.h rpc_des.h
201set_key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
202set_key.o: ../../include/openssl/opensslconf.h des_locl.h podd.h sk.h
203str2key.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
204str2key.o: ../../include/openssl/opensslconf.h des_locl.h
205supp.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
206supp.o: ../../include/openssl/opensslconf.h des_locl.h
207xcbc_enc.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
208xcbc_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
51CFLAGS=$(OPTS) $(CFLAG) 51CFLAGS=$(OPTS) $(CFLAG)
52CPP=$(CC) -E 52CPP=$(CC) -E
53AS=as 53AS=as
54RANLIB=ranlib
54 55
55# Assember version of des_encrypt*(). 56# Assember version of des_encrypt*().
56DES_ENC=des_enc.o fcrypt_b.o # normal C version 57DES_ENC=des_enc.o fcrypt_b.o # normal C version
@@ -169,9 +170,7 @@ test: all
169$(DLIB): $(OBJ) 170$(DLIB): $(OBJ)
170 /bin/rm -f $(DLIB) 171 /bin/rm -f $(DLIB)
171 ar cr $(DLIB) $(OBJ) 172 ar cr $(DLIB) $(OBJ)
172 -if test -s /bin/ranlib; then /bin/ranlib $(DLIB); \ 173 $(RANLIB) $(DLIB)
173 else if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(DLIB); \
174 else exit 0; fi; fi
175 174
176des_opts: des_opts.o $(DLIB) 175des_opts: des_opts.o $(DLIB)
177 $(CC) $(CFLAGS) -o des_opts des_opts.o $(DLIB) 176 $(CC) $(CFLAGS) -o des_opts des_opts.o $(DLIB)
@@ -231,25 +230,14 @@ install: des
231 if test $(INSTALLTOP); then \ 230 if test $(INSTALLTOP); then \
232 echo SSL style install; \ 231 echo SSL style install; \
233 cp $(DLIB) $(INSTALLTOP)/lib; \ 232 cp $(DLIB) $(INSTALLTOP)/lib; \
234 if test -s /bin/ranlib; then \ 233 $(RANLIB) $(DLIB); \
235 /bin/ranlib $(INSTALLTOP)/lib/$(DLIB); \
236 else \
237 if test -s /usr/bin/ranlib; then \
238 /usr/bin/ranlib $(INSTALLTOP)/lib/$(DLIB); \
239 fi; fi; \
240 chmod 644 $(INSTALLTOP)/lib/$(DLIB); \ 234 chmod 644 $(INSTALLTOP)/lib/$(DLIB); \
241 cp des.h $(INSTALLTOP)/include; \ 235 cp des.h $(INSTALLTOP)/include; \
242 chmod 644 $(INSTALLTOP)/include/des.h; \ 236 chmod 644 $(INSTALLTOP)/include/des.h; \
243 else \ 237 else \
244 echo Standalone install; \ 238 echo Standalone install; \
245 cp $(DLIB) $(LIBDIR)/$(DLIB); \ 239 cp $(DLIB) $(LIBDIR)/$(DLIB); \
246 if test -s /bin/ranlib; then \ 240 $(RANLIB) $(DLIB); \
247 /bin/ranlib $(LIBDIR)/$(DLIB); \
248 else \
249 if test -s /usr/bin/ranlib; then \
250 /usr/bin/ranlib $(LIBDIR)/$(DLIB); \
251 fi; \
252 fi; \
253 chmod 644 $(LIBDIR)/$(DLIB); \ 241 chmod 644 $(LIBDIR)/$(DLIB); \
254 cp des $(BINDIR)/des; \ 242 cp des $(BINDIR)/des; \
255 chmod 711 $(BINDIR)/des; \ 243 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 @@
1 Fixed the weak key values which were wrong :-(
1 Defining SIGACTION causes sigaction() to be used instead of signal(). 2 Defining SIGACTION causes sigaction() to be used instead of signal().
2 SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it 3 SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it
3 can cause problems. This should hopefully not affect normal 4 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# The inner loop instruction sequence and the IP/FP modifications are from 3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> 4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
@@ -32,7 +32,7 @@ sub fcrypt_body
32 &xor( $R, $R); 32 &xor( $R, $R);
33 &mov($ks,&wparam(1)); 33 &mov($ks,&wparam(1));
34 34
35 &push(25); # add a variable 35 &push(&DWC(25)); # add a variable
36 36
37 &set_label("start"); 37 &set_label("start");
38 for ($i=0; $i<16; $i+=2) 38 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# The inner loop instruction sequence and the IP/FP modifications are from 3# The inner loop instruction sequence and the IP/FP modifications are from
4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> 4# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
@@ -187,6 +187,8 @@ sub R_PERM_OP
187 &mov( $tt, $a ); 187 &mov( $tt, $a );
188 &xor( $a, $b ); 188 &xor( $a, $b );
189 &and( $a, $mask ); 189 &and( $a, $mask );
190 # This can never succeed, and besides it is difficult to see what the
191 # idea was - Ben 13 Feb 99
190 if (!$last eq $b) 192 if (!$last eq $b)
191 { 193 {
192 &xor( $b, $a ); 194 &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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3$prog="des686.pl"; 3$prog="des686.pl";
4 4
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3$L="edi"; 3$L="edi";
4$R="esi"; 4$R="esi";
@@ -44,15 +44,15 @@ sub des_encrypt3
44 &mov("edi",&wparam(2)); 44 &mov("edi",&wparam(2));
45 &mov("eax",&wparam(3)); 45 &mov("eax",&wparam(3));
46 } 46 }
47 &mov(&swtmp(2), (($enc)?"1":"0")); 47 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
48 &mov(&swtmp(1), "eax"); 48 &mov(&swtmp(1), "eax");
49 &mov(&swtmp(0), "ebx"); 49 &mov(&swtmp(0), "ebx");
50 &call("des_encrypt2"); 50 &call("des_encrypt2");
51 &mov(&swtmp(2), (($enc)?"0":"1")); 51 &mov(&swtmp(2), (DWC(($enc)?"0":"1")));
52 &mov(&swtmp(1), "edi"); 52 &mov(&swtmp(1), "edi");
53 &mov(&swtmp(0), "ebx"); 53 &mov(&swtmp(0), "ebx");
54 &call("des_encrypt2"); 54 &call("des_encrypt2");
55 &mov(&swtmp(2), (($enc)?"1":"0")); 55 &mov(&swtmp(2), (DWC(($enc)?"1":"0")));
56 &mov(&swtmp(1), "esi"); 56 &mov(&swtmp(1), "esi");
57 &mov(&swtmp(0), "ebx"); 57 &mov(&swtmp(0), "ebx");
58 &call("des_encrypt2"); 58 &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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define des_SPtrans _des_SPtrans
13#define des_encrypt _des_encrypt
14#define des_encrypt2 _des_encrypt2
15#define des_encrypt3 _des_encrypt3
16#define des_decrypt3 _des_decrypt3
17#define des_ncbc_encrypt _des_ncbc_encrypt
18#define des_ede3_cbc_encrypt _des_ede3_cbc_encrypt
19
20#endif
21
22#ifdef OUT
23#define OK 1
24#define ALIGN 4
25#endif
26
27#ifdef BSDI
28#define OK 1
29#define ALIGN 4
30#undef SIZE
31#undef TYPE
32#define SIZE(a,b)
33#define TYPE(a,b)
34#endif
35
36#if defined(ELF) || defined(SOL)
37#define OK 1
38#define ALIGN 16
39#endif
40
41#ifndef OK
42You need to define one of
43ELF - elf systems - linux-elf, NetBSD and DG-UX
44OUT - a.out systems - linux-a.out and FreeBSD
45SOL - solaris systems, which are elf with strange comment lines
46BSDI - a.out with a very primative version of as.
47#endif
48
49/* Let the Assembler begin :-) */
50 /* Don't even think of reading this code */
51 /* It was automatically generated by des-586.pl */
52 /* Which is a perl program used to generate the x86 assember for */
53 /* any of elf, a.out, BSDI,Win32, or Solaris */
54 /* eric <eay@cryptsoft.com> */
55
56 .file "des-586.s"
57 .version "01.01"
58gcc2_compiled.:
59.text
60 .align ALIGN
61.globl des_encrypt
62 TYPE(des_encrypt,@function)
63des_encrypt:
64 pushl %esi
65 pushl %edi
66
67 /* Load the 2 words */
68 movl 12(%esp), %esi
69 xorl %ecx, %ecx
70 pushl %ebx
71 pushl %ebp
72 movl (%esi), %eax
73 movl 28(%esp), %ebx
74 movl 4(%esi), %edi
75
76 /* IP */
77 roll $4, %eax
78 movl %eax, %esi
79 xorl %edi, %eax
80 andl $0xf0f0f0f0, %eax
81 xorl %eax, %esi
82 xorl %eax, %edi
83
84 roll $20, %edi
85 movl %edi, %eax
86 xorl %esi, %edi
87 andl $0xfff0000f, %edi
88 xorl %edi, %eax
89 xorl %edi, %esi
90
91 roll $14, %eax
92 movl %eax, %edi
93 xorl %esi, %eax
94 andl $0x33333333, %eax
95 xorl %eax, %edi
96 xorl %eax, %esi
97
98 roll $22, %esi
99 movl %esi, %eax
100 xorl %edi, %esi
101 andl $0x03fc03fc, %esi
102 xorl %esi, %eax
103 xorl %esi, %edi
104
105 roll $9, %eax
106 movl %eax, %esi
107 xorl %edi, %eax
108 andl $0xaaaaaaaa, %eax
109 xorl %eax, %esi
110 xorl %eax, %edi
111
112.byte 209
113.byte 199 /* roll $1 %edi */
114 movl 24(%esp), %ebp
115 cmpl $0, %ebx
116 je .L000start_decrypt
117
118 /* Round 0 */
119 movl (%ebp), %eax
120 xorl %ebx, %ebx
121 movl 4(%ebp), %edx
122 xorl %esi, %eax
123 xorl %esi, %edx
124 andl $0xfcfcfcfc, %eax
125 andl $0xcfcfcfcf, %edx
126 movb %al, %bl
127 movb %ah, %cl
128 rorl $4, %edx
129 movl des_SPtrans(%ebx),%ebp
130 movb %dl, %bl
131 xorl %ebp, %edi
132 movl 0x200+des_SPtrans(%ecx),%ebp
133 xorl %ebp, %edi
134 movb %dh, %cl
135 shrl $16, %eax
136 movl 0x100+des_SPtrans(%ebx),%ebp
137 xorl %ebp, %edi
138 movb %ah, %bl
139 shrl $16, %edx
140 movl 0x300+des_SPtrans(%ecx),%ebp
141 xorl %ebp, %edi
142 movl 24(%esp), %ebp
143 movb %dh, %cl
144 andl $0xff, %eax
145 andl $0xff, %edx
146 movl 0x600+des_SPtrans(%ebx),%ebx
147 xorl %ebx, %edi
148 movl 0x700+des_SPtrans(%ecx),%ebx
149 xorl %ebx, %edi
150 movl 0x400+des_SPtrans(%eax),%ebx
151 xorl %ebx, %edi
152 movl 0x500+des_SPtrans(%edx),%ebx
153 xorl %ebx, %edi
154
155 /* Round 1 */
156 movl 8(%ebp), %eax
157 xorl %ebx, %ebx
158 movl 12(%ebp), %edx
159 xorl %edi, %eax
160 xorl %edi, %edx
161 andl $0xfcfcfcfc, %eax
162 andl $0xcfcfcfcf, %edx
163 movb %al, %bl
164 movb %ah, %cl
165 rorl $4, %edx
166 movl des_SPtrans(%ebx),%ebp
167 movb %dl, %bl
168 xorl %ebp, %esi
169 movl 0x200+des_SPtrans(%ecx),%ebp
170 xorl %ebp, %esi
171 movb %dh, %cl
172 shrl $16, %eax
173 movl 0x100+des_SPtrans(%ebx),%ebp
174 xorl %ebp, %esi
175 movb %ah, %bl
176 shrl $16, %edx
177 movl 0x300+des_SPtrans(%ecx),%ebp
178 xorl %ebp, %esi
179 movl 24(%esp), %ebp
180 movb %dh, %cl
181 andl $0xff, %eax
182 andl $0xff, %edx
183 movl 0x600+des_SPtrans(%ebx),%ebx
184 xorl %ebx, %esi
185 movl 0x700+des_SPtrans(%ecx),%ebx
186 xorl %ebx, %esi
187 movl 0x400+des_SPtrans(%eax),%ebx
188 xorl %ebx, %esi
189 movl 0x500+des_SPtrans(%edx),%ebx
190 xorl %ebx, %esi
191
192 /* Round 2 */
193 movl 16(%ebp), %eax
194 xorl %ebx, %ebx
195 movl 20(%ebp), %edx
196 xorl %esi, %eax
197 xorl %esi, %edx
198 andl $0xfcfcfcfc, %eax
199 andl $0xcfcfcfcf, %edx
200 movb %al, %bl
201 movb %ah, %cl
202 rorl $4, %edx
203 movl des_SPtrans(%ebx),%ebp
204 movb %dl, %bl
205 xorl %ebp, %edi
206 movl 0x200+des_SPtrans(%ecx),%ebp
207 xorl %ebp, %edi
208 movb %dh, %cl
209 shrl $16, %eax
210 movl 0x100+des_SPtrans(%ebx),%ebp
211 xorl %ebp, %edi
212 movb %ah, %bl
213 shrl $16, %edx
214 movl 0x300+des_SPtrans(%ecx),%ebp
215 xorl %ebp, %edi
216 movl 24(%esp), %ebp
217 movb %dh, %cl
218 andl $0xff, %eax
219 andl $0xff, %edx
220 movl 0x600+des_SPtrans(%ebx),%ebx
221 xorl %ebx, %edi
222 movl 0x700+des_SPtrans(%ecx),%ebx
223 xorl %ebx, %edi
224 movl 0x400+des_SPtrans(%eax),%ebx
225 xorl %ebx, %edi
226 movl 0x500+des_SPtrans(%edx),%ebx
227 xorl %ebx, %edi
228
229 /* Round 3 */
230 movl 24(%ebp), %eax
231 xorl %ebx, %ebx
232 movl 28(%ebp), %edx
233 xorl %edi, %eax
234 xorl %edi, %edx
235 andl $0xfcfcfcfc, %eax
236 andl $0xcfcfcfcf, %edx
237 movb %al, %bl
238 movb %ah, %cl
239 rorl $4, %edx
240 movl des_SPtrans(%ebx),%ebp
241 movb %dl, %bl
242 xorl %ebp, %esi
243 movl 0x200+des_SPtrans(%ecx),%ebp
244 xorl %ebp, %esi
245 movb %dh, %cl
246 shrl $16, %eax
247 movl 0x100+des_SPtrans(%ebx),%ebp
248 xorl %ebp, %esi
249 movb %ah, %bl
250 shrl $16, %edx
251 movl 0x300+des_SPtrans(%ecx),%ebp
252 xorl %ebp, %esi
253 movl 24(%esp), %ebp
254 movb %dh, %cl
255 andl $0xff, %eax
256 andl $0xff, %edx
257 movl 0x600+des_SPtrans(%ebx),%ebx
258 xorl %ebx, %esi
259 movl 0x700+des_SPtrans(%ecx),%ebx
260 xorl %ebx, %esi
261 movl 0x400+des_SPtrans(%eax),%ebx
262 xorl %ebx, %esi
263 movl 0x500+des_SPtrans(%edx),%ebx
264 xorl %ebx, %esi
265
266 /* Round 4 */
267 movl 32(%ebp), %eax
268 xorl %ebx, %ebx
269 movl 36(%ebp), %edx
270 xorl %esi, %eax
271 xorl %esi, %edx
272 andl $0xfcfcfcfc, %eax
273 andl $0xcfcfcfcf, %edx
274 movb %al, %bl
275 movb %ah, %cl
276 rorl $4, %edx
277 movl des_SPtrans(%ebx),%ebp
278 movb %dl, %bl
279 xorl %ebp, %edi
280 movl 0x200+des_SPtrans(%ecx),%ebp
281 xorl %ebp, %edi
282 movb %dh, %cl
283 shrl $16, %eax
284 movl 0x100+des_SPtrans(%ebx),%ebp
285 xorl %ebp, %edi
286 movb %ah, %bl
287 shrl $16, %edx
288 movl 0x300+des_SPtrans(%ecx),%ebp
289 xorl %ebp, %edi
290 movl 24(%esp), %ebp
291 movb %dh, %cl
292 andl $0xff, %eax
293 andl $0xff, %edx
294 movl 0x600+des_SPtrans(%ebx),%ebx
295 xorl %ebx, %edi
296 movl 0x700+des_SPtrans(%ecx),%ebx
297 xorl %ebx, %edi
298 movl 0x400+des_SPtrans(%eax),%ebx
299 xorl %ebx, %edi
300 movl 0x500+des_SPtrans(%edx),%ebx
301 xorl %ebx, %edi
302
303 /* Round 5 */
304 movl 40(%ebp), %eax
305 xorl %ebx, %ebx
306 movl 44(%ebp), %edx
307 xorl %edi, %eax
308 xorl %edi, %edx
309 andl $0xfcfcfcfc, %eax
310 andl $0xcfcfcfcf, %edx
311 movb %al, %bl
312 movb %ah, %cl
313 rorl $4, %edx
314 movl des_SPtrans(%ebx),%ebp
315 movb %dl, %bl
316 xorl %ebp, %esi
317 movl 0x200+des_SPtrans(%ecx),%ebp
318 xorl %ebp, %esi
319 movb %dh, %cl
320 shrl $16, %eax
321 movl 0x100+des_SPtrans(%ebx),%ebp
322 xorl %ebp, %esi
323 movb %ah, %bl
324 shrl $16, %edx
325 movl 0x300+des_SPtrans(%ecx),%ebp
326 xorl %ebp, %esi
327 movl 24(%esp), %ebp
328 movb %dh, %cl
329 andl $0xff, %eax
330 andl $0xff, %edx
331 movl 0x600+des_SPtrans(%ebx),%ebx
332 xorl %ebx, %esi
333 movl 0x700+des_SPtrans(%ecx),%ebx
334 xorl %ebx, %esi
335 movl 0x400+des_SPtrans(%eax),%ebx
336 xorl %ebx, %esi
337 movl 0x500+des_SPtrans(%edx),%ebx
338 xorl %ebx, %esi
339
340 /* Round 6 */
341 movl 48(%ebp), %eax
342 xorl %ebx, %ebx
343 movl 52(%ebp), %edx
344 xorl %esi, %eax
345 xorl %esi, %edx
346 andl $0xfcfcfcfc, %eax
347 andl $0xcfcfcfcf, %edx
348 movb %al, %bl
349 movb %ah, %cl
350 rorl $4, %edx
351 movl des_SPtrans(%ebx),%ebp
352 movb %dl, %bl
353 xorl %ebp, %edi
354 movl 0x200+des_SPtrans(%ecx),%ebp
355 xorl %ebp, %edi
356 movb %dh, %cl
357 shrl $16, %eax
358 movl 0x100+des_SPtrans(%ebx),%ebp
359 xorl %ebp, %edi
360 movb %ah, %bl
361 shrl $16, %edx
362 movl 0x300+des_SPtrans(%ecx),%ebp
363 xorl %ebp, %edi
364 movl 24(%esp), %ebp
365 movb %dh, %cl
366 andl $0xff, %eax
367 andl $0xff, %edx
368 movl 0x600+des_SPtrans(%ebx),%ebx
369 xorl %ebx, %edi
370 movl 0x700+des_SPtrans(%ecx),%ebx
371 xorl %ebx, %edi
372 movl 0x400+des_SPtrans(%eax),%ebx
373 xorl %ebx, %edi
374 movl 0x500+des_SPtrans(%edx),%ebx
375 xorl %ebx, %edi
376
377 /* Round 7 */
378 movl 56(%ebp), %eax
379 xorl %ebx, %ebx
380 movl 60(%ebp), %edx
381 xorl %edi, %eax
382 xorl %edi, %edx
383 andl $0xfcfcfcfc, %eax
384 andl $0xcfcfcfcf, %edx
385 movb %al, %bl
386 movb %ah, %cl
387 rorl $4, %edx
388 movl des_SPtrans(%ebx),%ebp
389 movb %dl, %bl
390 xorl %ebp, %esi
391 movl 0x200+des_SPtrans(%ecx),%ebp
392 xorl %ebp, %esi
393 movb %dh, %cl
394 shrl $16, %eax
395 movl 0x100+des_SPtrans(%ebx),%ebp
396 xorl %ebp, %esi
397 movb %ah, %bl
398 shrl $16, %edx
399 movl 0x300+des_SPtrans(%ecx),%ebp
400 xorl %ebp, %esi
401 movl 24(%esp), %ebp
402 movb %dh, %cl
403 andl $0xff, %eax
404 andl $0xff, %edx
405 movl 0x600+des_SPtrans(%ebx),%ebx
406 xorl %ebx, %esi
407 movl 0x700+des_SPtrans(%ecx),%ebx
408 xorl %ebx, %esi
409 movl 0x400+des_SPtrans(%eax),%ebx
410 xorl %ebx, %esi
411 movl 0x500+des_SPtrans(%edx),%ebx
412 xorl %ebx, %esi
413
414 /* Round 8 */
415 movl 64(%ebp), %eax
416 xorl %ebx, %ebx
417 movl 68(%ebp), %edx
418 xorl %esi, %eax
419 xorl %esi, %edx
420 andl $0xfcfcfcfc, %eax
421 andl $0xcfcfcfcf, %edx
422 movb %al, %bl
423 movb %ah, %cl
424 rorl $4, %edx
425 movl des_SPtrans(%ebx),%ebp
426 movb %dl, %bl
427 xorl %ebp, %edi
428 movl 0x200+des_SPtrans(%ecx),%ebp
429 xorl %ebp, %edi
430 movb %dh, %cl
431 shrl $16, %eax
432 movl 0x100+des_SPtrans(%ebx),%ebp
433 xorl %ebp, %edi
434 movb %ah, %bl
435 shrl $16, %edx
436 movl 0x300+des_SPtrans(%ecx),%ebp
437 xorl %ebp, %edi
438 movl 24(%esp), %ebp
439 movb %dh, %cl
440 andl $0xff, %eax
441 andl $0xff, %edx
442 movl 0x600+des_SPtrans(%ebx),%ebx
443 xorl %ebx, %edi
444 movl 0x700+des_SPtrans(%ecx),%ebx
445 xorl %ebx, %edi
446 movl 0x400+des_SPtrans(%eax),%ebx
447 xorl %ebx, %edi
448 movl 0x500+des_SPtrans(%edx),%ebx
449 xorl %ebx, %edi
450
451 /* Round 9 */
452 movl 72(%ebp), %eax
453 xorl %ebx, %ebx
454 movl 76(%ebp), %edx
455 xorl %edi, %eax
456 xorl %edi, %edx
457 andl $0xfcfcfcfc, %eax
458 andl $0xcfcfcfcf, %edx
459 movb %al, %bl
460 movb %ah, %cl
461 rorl $4, %edx
462 movl des_SPtrans(%ebx),%ebp
463 movb %dl, %bl
464 xorl %ebp, %esi
465 movl 0x200+des_SPtrans(%ecx),%ebp
466 xorl %ebp, %esi
467 movb %dh, %cl
468 shrl $16, %eax
469 movl 0x100+des_SPtrans(%ebx),%ebp
470 xorl %ebp, %esi
471 movb %ah, %bl
472 shrl $16, %edx
473 movl 0x300+des_SPtrans(%ecx),%ebp
474 xorl %ebp, %esi
475 movl 24(%esp), %ebp
476 movb %dh, %cl
477 andl $0xff, %eax
478 andl $0xff, %edx
479 movl 0x600+des_SPtrans(%ebx),%ebx
480 xorl %ebx, %esi
481 movl 0x700+des_SPtrans(%ecx),%ebx
482 xorl %ebx, %esi
483 movl 0x400+des_SPtrans(%eax),%ebx
484 xorl %ebx, %esi
485 movl 0x500+des_SPtrans(%edx),%ebx
486 xorl %ebx, %esi
487
488 /* Round 10 */
489 movl 80(%ebp), %eax
490 xorl %ebx, %ebx
491 movl 84(%ebp), %edx
492 xorl %esi, %eax
493 xorl %esi, %edx
494 andl $0xfcfcfcfc, %eax
495 andl $0xcfcfcfcf, %edx
496 movb %al, %bl
497 movb %ah, %cl
498 rorl $4, %edx
499 movl des_SPtrans(%ebx),%ebp
500 movb %dl, %bl
501 xorl %ebp, %edi
502 movl 0x200+des_SPtrans(%ecx),%ebp
503 xorl %ebp, %edi
504 movb %dh, %cl
505 shrl $16, %eax
506 movl 0x100+des_SPtrans(%ebx),%ebp
507 xorl %ebp, %edi
508 movb %ah, %bl
509 shrl $16, %edx
510 movl 0x300+des_SPtrans(%ecx),%ebp
511 xorl %ebp, %edi
512 movl 24(%esp), %ebp
513 movb %dh, %cl
514 andl $0xff, %eax
515 andl $0xff, %edx
516 movl 0x600+des_SPtrans(%ebx),%ebx
517 xorl %ebx, %edi
518 movl 0x700+des_SPtrans(%ecx),%ebx
519 xorl %ebx, %edi
520 movl 0x400+des_SPtrans(%eax),%ebx
521 xorl %ebx, %edi
522 movl 0x500+des_SPtrans(%edx),%ebx
523 xorl %ebx, %edi
524
525 /* Round 11 */
526 movl 88(%ebp), %eax
527 xorl %ebx, %ebx
528 movl 92(%ebp), %edx
529 xorl %edi, %eax
530 xorl %edi, %edx
531 andl $0xfcfcfcfc, %eax
532 andl $0xcfcfcfcf, %edx
533 movb %al, %bl
534 movb %ah, %cl
535 rorl $4, %edx
536 movl des_SPtrans(%ebx),%ebp
537 movb %dl, %bl
538 xorl %ebp, %esi
539 movl 0x200+des_SPtrans(%ecx),%ebp
540 xorl %ebp, %esi
541 movb %dh, %cl
542 shrl $16, %eax
543 movl 0x100+des_SPtrans(%ebx),%ebp
544 xorl %ebp, %esi
545 movb %ah, %bl
546 shrl $16, %edx
547 movl 0x300+des_SPtrans(%ecx),%ebp
548 xorl %ebp, %esi
549 movl 24(%esp), %ebp
550 movb %dh, %cl
551 andl $0xff, %eax
552 andl $0xff, %edx
553 movl 0x600+des_SPtrans(%ebx),%ebx
554 xorl %ebx, %esi
555 movl 0x700+des_SPtrans(%ecx),%ebx
556 xorl %ebx, %esi
557 movl 0x400+des_SPtrans(%eax),%ebx
558 xorl %ebx, %esi
559 movl 0x500+des_SPtrans(%edx),%ebx
560 xorl %ebx, %esi
561
562 /* Round 12 */
563 movl 96(%ebp), %eax
564 xorl %ebx, %ebx
565 movl 100(%ebp), %edx
566 xorl %esi, %eax
567 xorl %esi, %edx
568 andl $0xfcfcfcfc, %eax
569 andl $0xcfcfcfcf, %edx
570 movb %al, %bl
571 movb %ah, %cl
572 rorl $4, %edx
573 movl des_SPtrans(%ebx),%ebp
574 movb %dl, %bl
575 xorl %ebp, %edi
576 movl 0x200+des_SPtrans(%ecx),%ebp
577 xorl %ebp, %edi
578 movb %dh, %cl
579 shrl $16, %eax
580 movl 0x100+des_SPtrans(%ebx),%ebp
581 xorl %ebp, %edi
582 movb %ah, %bl
583 shrl $16, %edx
584 movl 0x300+des_SPtrans(%ecx),%ebp
585 xorl %ebp, %edi
586 movl 24(%esp), %ebp
587 movb %dh, %cl
588 andl $0xff, %eax
589 andl $0xff, %edx
590 movl 0x600+des_SPtrans(%ebx),%ebx
591 xorl %ebx, %edi
592 movl 0x700+des_SPtrans(%ecx),%ebx
593 xorl %ebx, %edi
594 movl 0x400+des_SPtrans(%eax),%ebx
595 xorl %ebx, %edi
596 movl 0x500+des_SPtrans(%edx),%ebx
597 xorl %ebx, %edi
598
599 /* Round 13 */
600 movl 104(%ebp), %eax
601 xorl %ebx, %ebx
602 movl 108(%ebp), %edx
603 xorl %edi, %eax
604 xorl %edi, %edx
605 andl $0xfcfcfcfc, %eax
606 andl $0xcfcfcfcf, %edx
607 movb %al, %bl
608 movb %ah, %cl
609 rorl $4, %edx
610 movl des_SPtrans(%ebx),%ebp
611 movb %dl, %bl
612 xorl %ebp, %esi
613 movl 0x200+des_SPtrans(%ecx),%ebp
614 xorl %ebp, %esi
615 movb %dh, %cl
616 shrl $16, %eax
617 movl 0x100+des_SPtrans(%ebx),%ebp
618 xorl %ebp, %esi
619 movb %ah, %bl
620 shrl $16, %edx
621 movl 0x300+des_SPtrans(%ecx),%ebp
622 xorl %ebp, %esi
623 movl 24(%esp), %ebp
624 movb %dh, %cl
625 andl $0xff, %eax
626 andl $0xff, %edx
627 movl 0x600+des_SPtrans(%ebx),%ebx
628 xorl %ebx, %esi
629 movl 0x700+des_SPtrans(%ecx),%ebx
630 xorl %ebx, %esi
631 movl 0x400+des_SPtrans(%eax),%ebx
632 xorl %ebx, %esi
633 movl 0x500+des_SPtrans(%edx),%ebx
634 xorl %ebx, %esi
635
636 /* Round 14 */
637 movl 112(%ebp), %eax
638 xorl %ebx, %ebx
639 movl 116(%ebp), %edx
640 xorl %esi, %eax
641 xorl %esi, %edx
642 andl $0xfcfcfcfc, %eax
643 andl $0xcfcfcfcf, %edx
644 movb %al, %bl
645 movb %ah, %cl
646 rorl $4, %edx
647 movl des_SPtrans(%ebx),%ebp
648 movb %dl, %bl
649 xorl %ebp, %edi
650 movl 0x200+des_SPtrans(%ecx),%ebp
651 xorl %ebp, %edi
652 movb %dh, %cl
653 shrl $16, %eax
654 movl 0x100+des_SPtrans(%ebx),%ebp
655 xorl %ebp, %edi
656 movb %ah, %bl
657 shrl $16, %edx
658 movl 0x300+des_SPtrans(%ecx),%ebp
659 xorl %ebp, %edi
660 movl 24(%esp), %ebp
661 movb %dh, %cl
662 andl $0xff, %eax
663 andl $0xff, %edx
664 movl 0x600+des_SPtrans(%ebx),%ebx
665 xorl %ebx, %edi
666 movl 0x700+des_SPtrans(%ecx),%ebx
667 xorl %ebx, %edi
668 movl 0x400+des_SPtrans(%eax),%ebx
669 xorl %ebx, %edi
670 movl 0x500+des_SPtrans(%edx),%ebx
671 xorl %ebx, %edi
672
673 /* Round 15 */
674 movl 120(%ebp), %eax
675 xorl %ebx, %ebx
676 movl 124(%ebp), %edx
677 xorl %edi, %eax
678 xorl %edi, %edx
679 andl $0xfcfcfcfc, %eax
680 andl $0xcfcfcfcf, %edx
681 movb %al, %bl
682 movb %ah, %cl
683 rorl $4, %edx
684 movl des_SPtrans(%ebx),%ebp
685 movb %dl, %bl
686 xorl %ebp, %esi
687 movl 0x200+des_SPtrans(%ecx),%ebp
688 xorl %ebp, %esi
689 movb %dh, %cl
690 shrl $16, %eax
691 movl 0x100+des_SPtrans(%ebx),%ebp
692 xorl %ebp, %esi
693 movb %ah, %bl
694 shrl $16, %edx
695 movl 0x300+des_SPtrans(%ecx),%ebp
696 xorl %ebp, %esi
697 movl 24(%esp), %ebp
698 movb %dh, %cl
699 andl $0xff, %eax
700 andl $0xff, %edx
701 movl 0x600+des_SPtrans(%ebx),%ebx
702 xorl %ebx, %esi
703 movl 0x700+des_SPtrans(%ecx),%ebx
704 xorl %ebx, %esi
705 movl 0x400+des_SPtrans(%eax),%ebx
706 xorl %ebx, %esi
707 movl 0x500+des_SPtrans(%edx),%ebx
708 xorl %ebx, %esi
709 jmp .L001end
710.L000start_decrypt:
711
712 /* Round 15 */
713 movl 120(%ebp), %eax
714 xorl %ebx, %ebx
715 movl 124(%ebp), %edx
716 xorl %esi, %eax
717 xorl %esi, %edx
718 andl $0xfcfcfcfc, %eax
719 andl $0xcfcfcfcf, %edx
720 movb %al, %bl
721 movb %ah, %cl
722 rorl $4, %edx
723 movl des_SPtrans(%ebx),%ebp
724 movb %dl, %bl
725 xorl %ebp, %edi
726 movl 0x200+des_SPtrans(%ecx),%ebp
727 xorl %ebp, %edi
728 movb %dh, %cl
729 shrl $16, %eax
730 movl 0x100+des_SPtrans(%ebx),%ebp
731 xorl %ebp, %edi
732 movb %ah, %bl
733 shrl $16, %edx
734 movl 0x300+des_SPtrans(%ecx),%ebp
735 xorl %ebp, %edi
736 movl 24(%esp), %ebp
737 movb %dh, %cl
738 andl $0xff, %eax
739 andl $0xff, %edx
740 movl 0x600+des_SPtrans(%ebx),%ebx
741 xorl %ebx, %edi
742 movl 0x700+des_SPtrans(%ecx),%ebx
743 xorl %ebx, %edi
744 movl 0x400+des_SPtrans(%eax),%ebx
745 xorl %ebx, %edi
746 movl 0x500+des_SPtrans(%edx),%ebx
747 xorl %ebx, %edi
748
749 /* Round 14 */
750 movl 112(%ebp), %eax
751 xorl %ebx, %ebx
752 movl 116(%ebp), %edx
753 xorl %edi, %eax
754 xorl %edi, %edx
755 andl $0xfcfcfcfc, %eax
756 andl $0xcfcfcfcf, %edx
757 movb %al, %bl
758 movb %ah, %cl
759 rorl $4, %edx
760 movl des_SPtrans(%ebx),%ebp
761 movb %dl, %bl
762 xorl %ebp, %esi
763 movl 0x200+des_SPtrans(%ecx),%ebp
764 xorl %ebp, %esi
765 movb %dh, %cl
766 shrl $16, %eax
767 movl 0x100+des_SPtrans(%ebx),%ebp
768 xorl %ebp, %esi
769 movb %ah, %bl
770 shrl $16, %edx
771 movl 0x300+des_SPtrans(%ecx),%ebp
772 xorl %ebp, %esi
773 movl 24(%esp), %ebp
774 movb %dh, %cl
775 andl $0xff, %eax
776 andl $0xff, %edx
777 movl 0x600+des_SPtrans(%ebx),%ebx
778 xorl %ebx, %esi
779 movl 0x700+des_SPtrans(%ecx),%ebx
780 xorl %ebx, %esi
781 movl 0x400+des_SPtrans(%eax),%ebx
782 xorl %ebx, %esi
783 movl 0x500+des_SPtrans(%edx),%ebx
784 xorl %ebx, %esi
785
786 /* Round 13 */
787 movl 104(%ebp), %eax
788 xorl %ebx, %ebx
789 movl 108(%ebp), %edx
790 xorl %esi, %eax
791 xorl %esi, %edx
792 andl $0xfcfcfcfc, %eax
793 andl $0xcfcfcfcf, %edx
794 movb %al, %bl
795 movb %ah, %cl
796 rorl $4, %edx
797 movl des_SPtrans(%ebx),%ebp
798 movb %dl, %bl
799 xorl %ebp, %edi
800 movl 0x200+des_SPtrans(%ecx),%ebp
801 xorl %ebp, %edi
802 movb %dh, %cl
803 shrl $16, %eax
804 movl 0x100+des_SPtrans(%ebx),%ebp
805 xorl %ebp, %edi
806 movb %ah, %bl
807 shrl $16, %edx
808 movl 0x300+des_SPtrans(%ecx),%ebp
809 xorl %ebp, %edi
810 movl 24(%esp), %ebp
811 movb %dh, %cl
812 andl $0xff, %eax
813 andl $0xff, %edx
814 movl 0x600+des_SPtrans(%ebx),%ebx
815 xorl %ebx, %edi
816 movl 0x700+des_SPtrans(%ecx),%ebx
817 xorl %ebx, %edi
818 movl 0x400+des_SPtrans(%eax),%ebx
819 xorl %ebx, %edi
820 movl 0x500+des_SPtrans(%edx),%ebx
821 xorl %ebx, %edi
822
823 /* Round 12 */
824 movl 96(%ebp), %eax
825 xorl %ebx, %ebx
826 movl 100(%ebp), %edx
827 xorl %edi, %eax
828 xorl %edi, %edx
829 andl $0xfcfcfcfc, %eax
830 andl $0xcfcfcfcf, %edx
831 movb %al, %bl
832 movb %ah, %cl
833 rorl $4, %edx
834 movl des_SPtrans(%ebx),%ebp
835 movb %dl, %bl
836 xorl %ebp, %esi
837 movl 0x200+des_SPtrans(%ecx),%ebp
838 xorl %ebp, %esi
839 movb %dh, %cl
840 shrl $16, %eax
841 movl 0x100+des_SPtrans(%ebx),%ebp
842 xorl %ebp, %esi
843 movb %ah, %bl
844 shrl $16, %edx
845 movl 0x300+des_SPtrans(%ecx),%ebp
846 xorl %ebp, %esi
847 movl 24(%esp), %ebp
848 movb %dh, %cl
849 andl $0xff, %eax
850 andl $0xff, %edx
851 movl 0x600+des_SPtrans(%ebx),%ebx
852 xorl %ebx, %esi
853 movl 0x700+des_SPtrans(%ecx),%ebx
854 xorl %ebx, %esi
855 movl 0x400+des_SPtrans(%eax),%ebx
856 xorl %ebx, %esi
857 movl 0x500+des_SPtrans(%edx),%ebx
858 xorl %ebx, %esi
859
860 /* Round 11 */
861 movl 88(%ebp), %eax
862 xorl %ebx, %ebx
863 movl 92(%ebp), %edx
864 xorl %esi, %eax
865 xorl %esi, %edx
866 andl $0xfcfcfcfc, %eax
867 andl $0xcfcfcfcf, %edx
868 movb %al, %bl
869 movb %ah, %cl
870 rorl $4, %edx
871 movl des_SPtrans(%ebx),%ebp
872 movb %dl, %bl
873 xorl %ebp, %edi
874 movl 0x200+des_SPtrans(%ecx),%ebp
875 xorl %ebp, %edi
876 movb %dh, %cl
877 shrl $16, %eax
878 movl 0x100+des_SPtrans(%ebx),%ebp
879 xorl %ebp, %edi
880 movb %ah, %bl
881 shrl $16, %edx
882 movl 0x300+des_SPtrans(%ecx),%ebp
883 xorl %ebp, %edi
884 movl 24(%esp), %ebp
885 movb %dh, %cl
886 andl $0xff, %eax
887 andl $0xff, %edx
888 movl 0x600+des_SPtrans(%ebx),%ebx
889 xorl %ebx, %edi
890 movl 0x700+des_SPtrans(%ecx),%ebx
891 xorl %ebx, %edi
892 movl 0x400+des_SPtrans(%eax),%ebx
893 xorl %ebx, %edi
894 movl 0x500+des_SPtrans(%edx),%ebx
895 xorl %ebx, %edi
896
897 /* Round 10 */
898 movl 80(%ebp), %eax
899 xorl %ebx, %ebx
900 movl 84(%ebp), %edx
901 xorl %edi, %eax
902 xorl %edi, %edx
903 andl $0xfcfcfcfc, %eax
904 andl $0xcfcfcfcf, %edx
905 movb %al, %bl
906 movb %ah, %cl
907 rorl $4, %edx
908 movl des_SPtrans(%ebx),%ebp
909 movb %dl, %bl
910 xorl %ebp, %esi
911 movl 0x200+des_SPtrans(%ecx),%ebp
912 xorl %ebp, %esi
913 movb %dh, %cl
914 shrl $16, %eax
915 movl 0x100+des_SPtrans(%ebx),%ebp
916 xorl %ebp, %esi
917 movb %ah, %bl
918 shrl $16, %edx
919 movl 0x300+des_SPtrans(%ecx),%ebp
920 xorl %ebp, %esi
921 movl 24(%esp), %ebp
922 movb %dh, %cl
923 andl $0xff, %eax
924 andl $0xff, %edx
925 movl 0x600+des_SPtrans(%ebx),%ebx
926 xorl %ebx, %esi
927 movl 0x700+des_SPtrans(%ecx),%ebx
928 xorl %ebx, %esi
929 movl 0x400+des_SPtrans(%eax),%ebx
930 xorl %ebx, %esi
931 movl 0x500+des_SPtrans(%edx),%ebx
932 xorl %ebx, %esi
933
934 /* Round 9 */
935 movl 72(%ebp), %eax
936 xorl %ebx, %ebx
937 movl 76(%ebp), %edx
938 xorl %esi, %eax
939 xorl %esi, %edx
940 andl $0xfcfcfcfc, %eax
941 andl $0xcfcfcfcf, %edx
942 movb %al, %bl
943 movb %ah, %cl
944 rorl $4, %edx
945 movl des_SPtrans(%ebx),%ebp
946 movb %dl, %bl
947 xorl %ebp, %edi
948 movl 0x200+des_SPtrans(%ecx),%ebp
949 xorl %ebp, %edi
950 movb %dh, %cl
951 shrl $16, %eax
952 movl 0x100+des_SPtrans(%ebx),%ebp
953 xorl %ebp, %edi
954 movb %ah, %bl
955 shrl $16, %edx
956 movl 0x300+des_SPtrans(%ecx),%ebp
957 xorl %ebp, %edi
958 movl 24(%esp), %ebp
959 movb %dh, %cl
960 andl $0xff, %eax
961 andl $0xff, %edx
962 movl 0x600+des_SPtrans(%ebx),%ebx
963 xorl %ebx, %edi
964 movl 0x700+des_SPtrans(%ecx),%ebx
965 xorl %ebx, %edi
966 movl 0x400+des_SPtrans(%eax),%ebx
967 xorl %ebx, %edi
968 movl 0x500+des_SPtrans(%edx),%ebx
969 xorl %ebx, %edi
970
971 /* Round 8 */
972 movl 64(%ebp), %eax
973 xorl %ebx, %ebx
974 movl 68(%ebp), %edx
975 xorl %edi, %eax
976 xorl %edi, %edx
977 andl $0xfcfcfcfc, %eax
978 andl $0xcfcfcfcf, %edx
979 movb %al, %bl
980 movb %ah, %cl
981 rorl $4, %edx
982 movl des_SPtrans(%ebx),%ebp
983 movb %dl, %bl
984 xorl %ebp, %esi
985 movl 0x200+des_SPtrans(%ecx),%ebp
986 xorl %ebp, %esi
987 movb %dh, %cl
988 shrl $16, %eax
989 movl 0x100+des_SPtrans(%ebx),%ebp
990 xorl %ebp, %esi
991 movb %ah, %bl
992 shrl $16, %edx
993 movl 0x300+des_SPtrans(%ecx),%ebp
994 xorl %ebp, %esi
995 movl 24(%esp), %ebp
996 movb %dh, %cl
997 andl $0xff, %eax
998 andl $0xff, %edx
999 movl 0x600+des_SPtrans(%ebx),%ebx
1000 xorl %ebx, %esi
1001 movl 0x700+des_SPtrans(%ecx),%ebx
1002 xorl %ebx, %esi
1003 movl 0x400+des_SPtrans(%eax),%ebx
1004 xorl %ebx, %esi
1005 movl 0x500+des_SPtrans(%edx),%ebx
1006 xorl %ebx, %esi
1007
1008 /* Round 7 */
1009 movl 56(%ebp), %eax
1010 xorl %ebx, %ebx
1011 movl 60(%ebp), %edx
1012 xorl %esi, %eax
1013 xorl %esi, %edx
1014 andl $0xfcfcfcfc, %eax
1015 andl $0xcfcfcfcf, %edx
1016 movb %al, %bl
1017 movb %ah, %cl
1018 rorl $4, %edx
1019 movl des_SPtrans(%ebx),%ebp
1020 movb %dl, %bl
1021 xorl %ebp, %edi
1022 movl 0x200+des_SPtrans(%ecx),%ebp
1023 xorl %ebp, %edi
1024 movb %dh, %cl
1025 shrl $16, %eax
1026 movl 0x100+des_SPtrans(%ebx),%ebp
1027 xorl %ebp, %edi
1028 movb %ah, %bl
1029 shrl $16, %edx
1030 movl 0x300+des_SPtrans(%ecx),%ebp
1031 xorl %ebp, %edi
1032 movl 24(%esp), %ebp
1033 movb %dh, %cl
1034 andl $0xff, %eax
1035 andl $0xff, %edx
1036 movl 0x600+des_SPtrans(%ebx),%ebx
1037 xorl %ebx, %edi
1038 movl 0x700+des_SPtrans(%ecx),%ebx
1039 xorl %ebx, %edi
1040 movl 0x400+des_SPtrans(%eax),%ebx
1041 xorl %ebx, %edi
1042 movl 0x500+des_SPtrans(%edx),%ebx
1043 xorl %ebx, %edi
1044
1045 /* Round 6 */
1046 movl 48(%ebp), %eax
1047 xorl %ebx, %ebx
1048 movl 52(%ebp), %edx
1049 xorl %edi, %eax
1050 xorl %edi, %edx
1051 andl $0xfcfcfcfc, %eax
1052 andl $0xcfcfcfcf, %edx
1053 movb %al, %bl
1054 movb %ah, %cl
1055 rorl $4, %edx
1056 movl des_SPtrans(%ebx),%ebp
1057 movb %dl, %bl
1058 xorl %ebp, %esi
1059 movl 0x200+des_SPtrans(%ecx),%ebp
1060 xorl %ebp, %esi
1061 movb %dh, %cl
1062 shrl $16, %eax
1063 movl 0x100+des_SPtrans(%ebx),%ebp
1064 xorl %ebp, %esi
1065 movb %ah, %bl
1066 shrl $16, %edx
1067 movl 0x300+des_SPtrans(%ecx),%ebp
1068 xorl %ebp, %esi
1069 movl 24(%esp), %ebp
1070 movb %dh, %cl
1071 andl $0xff, %eax
1072 andl $0xff, %edx
1073 movl 0x600+des_SPtrans(%ebx),%ebx
1074 xorl %ebx, %esi
1075 movl 0x700+des_SPtrans(%ecx),%ebx
1076 xorl %ebx, %esi
1077 movl 0x400+des_SPtrans(%eax),%ebx
1078 xorl %ebx, %esi
1079 movl 0x500+des_SPtrans(%edx),%ebx
1080 xorl %ebx, %esi
1081
1082 /* Round 5 */
1083 movl 40(%ebp), %eax
1084 xorl %ebx, %ebx
1085 movl 44(%ebp), %edx
1086 xorl %esi, %eax
1087 xorl %esi, %edx
1088 andl $0xfcfcfcfc, %eax
1089 andl $0xcfcfcfcf, %edx
1090 movb %al, %bl
1091 movb %ah, %cl
1092 rorl $4, %edx
1093 movl des_SPtrans(%ebx),%ebp
1094 movb %dl, %bl
1095 xorl %ebp, %edi
1096 movl 0x200+des_SPtrans(%ecx),%ebp
1097 xorl %ebp, %edi
1098 movb %dh, %cl
1099 shrl $16, %eax
1100 movl 0x100+des_SPtrans(%ebx),%ebp
1101 xorl %ebp, %edi
1102 movb %ah, %bl
1103 shrl $16, %edx
1104 movl 0x300+des_SPtrans(%ecx),%ebp
1105 xorl %ebp, %edi
1106 movl 24(%esp), %ebp
1107 movb %dh, %cl
1108 andl $0xff, %eax
1109 andl $0xff, %edx
1110 movl 0x600+des_SPtrans(%ebx),%ebx
1111 xorl %ebx, %edi
1112 movl 0x700+des_SPtrans(%ecx),%ebx
1113 xorl %ebx, %edi
1114 movl 0x400+des_SPtrans(%eax),%ebx
1115 xorl %ebx, %edi
1116 movl 0x500+des_SPtrans(%edx),%ebx
1117 xorl %ebx, %edi
1118
1119 /* Round 4 */
1120 movl 32(%ebp), %eax
1121 xorl %ebx, %ebx
1122 movl 36(%ebp), %edx
1123 xorl %edi, %eax
1124 xorl %edi, %edx
1125 andl $0xfcfcfcfc, %eax
1126 andl $0xcfcfcfcf, %edx
1127 movb %al, %bl
1128 movb %ah, %cl
1129 rorl $4, %edx
1130 movl des_SPtrans(%ebx),%ebp
1131 movb %dl, %bl
1132 xorl %ebp, %esi
1133 movl 0x200+des_SPtrans(%ecx),%ebp
1134 xorl %ebp, %esi
1135 movb %dh, %cl
1136 shrl $16, %eax
1137 movl 0x100+des_SPtrans(%ebx),%ebp
1138 xorl %ebp, %esi
1139 movb %ah, %bl
1140 shrl $16, %edx
1141 movl 0x300+des_SPtrans(%ecx),%ebp
1142 xorl %ebp, %esi
1143 movl 24(%esp), %ebp
1144 movb %dh, %cl
1145 andl $0xff, %eax
1146 andl $0xff, %edx
1147 movl 0x600+des_SPtrans(%ebx),%ebx
1148 xorl %ebx, %esi
1149 movl 0x700+des_SPtrans(%ecx),%ebx
1150 xorl %ebx, %esi
1151 movl 0x400+des_SPtrans(%eax),%ebx
1152 xorl %ebx, %esi
1153 movl 0x500+des_SPtrans(%edx),%ebx
1154 xorl %ebx, %esi
1155
1156 /* Round 3 */
1157 movl 24(%ebp), %eax
1158 xorl %ebx, %ebx
1159 movl 28(%ebp), %edx
1160 xorl %esi, %eax
1161 xorl %esi, %edx
1162 andl $0xfcfcfcfc, %eax
1163 andl $0xcfcfcfcf, %edx
1164 movb %al, %bl
1165 movb %ah, %cl
1166 rorl $4, %edx
1167 movl des_SPtrans(%ebx),%ebp
1168 movb %dl, %bl
1169 xorl %ebp, %edi
1170 movl 0x200+des_SPtrans(%ecx),%ebp
1171 xorl %ebp, %edi
1172 movb %dh, %cl
1173 shrl $16, %eax
1174 movl 0x100+des_SPtrans(%ebx),%ebp
1175 xorl %ebp, %edi
1176 movb %ah, %bl
1177 shrl $16, %edx
1178 movl 0x300+des_SPtrans(%ecx),%ebp
1179 xorl %ebp, %edi
1180 movl 24(%esp), %ebp
1181 movb %dh, %cl
1182 andl $0xff, %eax
1183 andl $0xff, %edx
1184 movl 0x600+des_SPtrans(%ebx),%ebx
1185 xorl %ebx, %edi
1186 movl 0x700+des_SPtrans(%ecx),%ebx
1187 xorl %ebx, %edi
1188 movl 0x400+des_SPtrans(%eax),%ebx
1189 xorl %ebx, %edi
1190 movl 0x500+des_SPtrans(%edx),%ebx
1191 xorl %ebx, %edi
1192
1193 /* Round 2 */
1194 movl 16(%ebp), %eax
1195 xorl %ebx, %ebx
1196 movl 20(%ebp), %edx
1197 xorl %edi, %eax
1198 xorl %edi, %edx
1199 andl $0xfcfcfcfc, %eax
1200 andl $0xcfcfcfcf, %edx
1201 movb %al, %bl
1202 movb %ah, %cl
1203 rorl $4, %edx
1204 movl des_SPtrans(%ebx),%ebp
1205 movb %dl, %bl
1206 xorl %ebp, %esi
1207 movl 0x200+des_SPtrans(%ecx),%ebp
1208 xorl %ebp, %esi
1209 movb %dh, %cl
1210 shrl $16, %eax
1211 movl 0x100+des_SPtrans(%ebx),%ebp
1212 xorl %ebp, %esi
1213 movb %ah, %bl
1214 shrl $16, %edx
1215 movl 0x300+des_SPtrans(%ecx),%ebp
1216 xorl %ebp, %esi
1217 movl 24(%esp), %ebp
1218 movb %dh, %cl
1219 andl $0xff, %eax
1220 andl $0xff, %edx
1221 movl 0x600+des_SPtrans(%ebx),%ebx
1222 xorl %ebx, %esi
1223 movl 0x700+des_SPtrans(%ecx),%ebx
1224 xorl %ebx, %esi
1225 movl 0x400+des_SPtrans(%eax),%ebx
1226 xorl %ebx, %esi
1227 movl 0x500+des_SPtrans(%edx),%ebx
1228 xorl %ebx, %esi
1229
1230 /* Round 1 */
1231 movl 8(%ebp), %eax
1232 xorl %ebx, %ebx
1233 movl 12(%ebp), %edx
1234 xorl %esi, %eax
1235 xorl %esi, %edx
1236 andl $0xfcfcfcfc, %eax
1237 andl $0xcfcfcfcf, %edx
1238 movb %al, %bl
1239 movb %ah, %cl
1240 rorl $4, %edx
1241 movl des_SPtrans(%ebx),%ebp
1242 movb %dl, %bl
1243 xorl %ebp, %edi
1244 movl 0x200+des_SPtrans(%ecx),%ebp
1245 xorl %ebp, %edi
1246 movb %dh, %cl
1247 shrl $16, %eax
1248 movl 0x100+des_SPtrans(%ebx),%ebp
1249 xorl %ebp, %edi
1250 movb %ah, %bl
1251 shrl $16, %edx
1252 movl 0x300+des_SPtrans(%ecx),%ebp
1253 xorl %ebp, %edi
1254 movl 24(%esp), %ebp
1255 movb %dh, %cl
1256 andl $0xff, %eax
1257 andl $0xff, %edx
1258 movl 0x600+des_SPtrans(%ebx),%ebx
1259 xorl %ebx, %edi
1260 movl 0x700+des_SPtrans(%ecx),%ebx
1261 xorl %ebx, %edi
1262 movl 0x400+des_SPtrans(%eax),%ebx
1263 xorl %ebx, %edi
1264 movl 0x500+des_SPtrans(%edx),%ebx
1265 xorl %ebx, %edi
1266
1267 /* Round 0 */
1268 movl (%ebp), %eax
1269 xorl %ebx, %ebx
1270 movl 4(%ebp), %edx
1271 xorl %edi, %eax
1272 xorl %edi, %edx
1273 andl $0xfcfcfcfc, %eax
1274 andl $0xcfcfcfcf, %edx
1275 movb %al, %bl
1276 movb %ah, %cl
1277 rorl $4, %edx
1278 movl des_SPtrans(%ebx),%ebp
1279 movb %dl, %bl
1280 xorl %ebp, %esi
1281 movl 0x200+des_SPtrans(%ecx),%ebp
1282 xorl %ebp, %esi
1283 movb %dh, %cl
1284 shrl $16, %eax
1285 movl 0x100+des_SPtrans(%ebx),%ebp
1286 xorl %ebp, %esi
1287 movb %ah, %bl
1288 shrl $16, %edx
1289 movl 0x300+des_SPtrans(%ecx),%ebp
1290 xorl %ebp, %esi
1291 movl 24(%esp), %ebp
1292 movb %dh, %cl
1293 andl $0xff, %eax
1294 andl $0xff, %edx
1295 movl 0x600+des_SPtrans(%ebx),%ebx
1296 xorl %ebx, %esi
1297 movl 0x700+des_SPtrans(%ecx),%ebx
1298 xorl %ebx, %esi
1299 movl 0x400+des_SPtrans(%eax),%ebx
1300 xorl %ebx, %esi
1301 movl 0x500+des_SPtrans(%edx),%ebx
1302 xorl %ebx, %esi
1303.L001end:
1304
1305 /* FP */
1306 movl 20(%esp), %edx
1307.byte 209
1308.byte 206 /* rorl $1 %esi */
1309 movl %edi, %eax
1310 xorl %esi, %edi
1311 andl $0xaaaaaaaa, %edi
1312 xorl %edi, %eax
1313 xorl %edi, %esi
1314
1315 roll $23, %eax
1316 movl %eax, %edi
1317 xorl %esi, %eax
1318 andl $0x03fc03fc, %eax
1319 xorl %eax, %edi
1320 xorl %eax, %esi
1321
1322 roll $10, %edi
1323 movl %edi, %eax
1324 xorl %esi, %edi
1325 andl $0x33333333, %edi
1326 xorl %edi, %eax
1327 xorl %edi, %esi
1328
1329 roll $18, %esi
1330 movl %esi, %edi
1331 xorl %eax, %esi
1332 andl $0xfff0000f, %esi
1333 xorl %esi, %edi
1334 xorl %esi, %eax
1335
1336 roll $12, %edi
1337 movl %edi, %esi
1338 xorl %eax, %edi
1339 andl $0xf0f0f0f0, %edi
1340 xorl %edi, %esi
1341 xorl %edi, %eax
1342
1343 rorl $4, %eax
1344 movl %eax, (%edx)
1345 movl %esi, 4(%edx)
1346 popl %ebp
1347 popl %ebx
1348 popl %edi
1349 popl %esi
1350 ret
1351.des_encrypt_end:
1352 SIZE(des_encrypt,.des_encrypt_end-des_encrypt)
1353.ident "desasm.pl"
1354.text
1355 .align ALIGN
1356.globl des_encrypt2
1357 TYPE(des_encrypt2,@function)
1358des_encrypt2:
1359 pushl %esi
1360 pushl %edi
1361
1362 /* Load the 2 words */
1363 movl 12(%esp), %eax
1364 xorl %ecx, %ecx
1365 pushl %ebx
1366 pushl %ebp
1367 movl (%eax), %esi
1368 movl 28(%esp), %ebx
1369 roll $3, %esi
1370 movl 4(%eax), %edi
1371 roll $3, %edi
1372 movl 24(%esp), %ebp
1373 cmpl $0, %ebx
1374 je .L002start_decrypt
1375
1376 /* Round 0 */
1377 movl (%ebp), %eax
1378 xorl %ebx, %ebx
1379 movl 4(%ebp), %edx
1380 xorl %esi, %eax
1381 xorl %esi, %edx
1382 andl $0xfcfcfcfc, %eax
1383 andl $0xcfcfcfcf, %edx
1384 movb %al, %bl
1385 movb %ah, %cl
1386 rorl $4, %edx
1387 movl des_SPtrans(%ebx),%ebp
1388 movb %dl, %bl
1389 xorl %ebp, %edi
1390 movl 0x200+des_SPtrans(%ecx),%ebp
1391 xorl %ebp, %edi
1392 movb %dh, %cl
1393 shrl $16, %eax
1394 movl 0x100+des_SPtrans(%ebx),%ebp
1395 xorl %ebp, %edi
1396 movb %ah, %bl
1397 shrl $16, %edx
1398 movl 0x300+des_SPtrans(%ecx),%ebp
1399 xorl %ebp, %edi
1400 movl 24(%esp), %ebp
1401 movb %dh, %cl
1402 andl $0xff, %eax
1403 andl $0xff, %edx
1404 movl 0x600+des_SPtrans(%ebx),%ebx
1405 xorl %ebx, %edi
1406 movl 0x700+des_SPtrans(%ecx),%ebx
1407 xorl %ebx, %edi
1408 movl 0x400+des_SPtrans(%eax),%ebx
1409 xorl %ebx, %edi
1410 movl 0x500+des_SPtrans(%edx),%ebx
1411 xorl %ebx, %edi
1412
1413 /* Round 1 */
1414 movl 8(%ebp), %eax
1415 xorl %ebx, %ebx
1416 movl 12(%ebp), %edx
1417 xorl %edi, %eax
1418 xorl %edi, %edx
1419 andl $0xfcfcfcfc, %eax
1420 andl $0xcfcfcfcf, %edx
1421 movb %al, %bl
1422 movb %ah, %cl
1423 rorl $4, %edx
1424 movl des_SPtrans(%ebx),%ebp
1425 movb %dl, %bl
1426 xorl %ebp, %esi
1427 movl 0x200+des_SPtrans(%ecx),%ebp
1428 xorl %ebp, %esi
1429 movb %dh, %cl
1430 shrl $16, %eax
1431 movl 0x100+des_SPtrans(%ebx),%ebp
1432 xorl %ebp, %esi
1433 movb %ah, %bl
1434 shrl $16, %edx
1435 movl 0x300+des_SPtrans(%ecx),%ebp
1436 xorl %ebp, %esi
1437 movl 24(%esp), %ebp
1438 movb %dh, %cl
1439 andl $0xff, %eax
1440 andl $0xff, %edx
1441 movl 0x600+des_SPtrans(%ebx),%ebx
1442 xorl %ebx, %esi
1443 movl 0x700+des_SPtrans(%ecx),%ebx
1444 xorl %ebx, %esi
1445 movl 0x400+des_SPtrans(%eax),%ebx
1446 xorl %ebx, %esi
1447 movl 0x500+des_SPtrans(%edx),%ebx
1448 xorl %ebx, %esi
1449
1450 /* Round 2 */
1451 movl 16(%ebp), %eax
1452 xorl %ebx, %ebx
1453 movl 20(%ebp), %edx
1454 xorl %esi, %eax
1455 xorl %esi, %edx
1456 andl $0xfcfcfcfc, %eax
1457 andl $0xcfcfcfcf, %edx
1458 movb %al, %bl
1459 movb %ah, %cl
1460 rorl $4, %edx
1461 movl des_SPtrans(%ebx),%ebp
1462 movb %dl, %bl
1463 xorl %ebp, %edi
1464 movl 0x200+des_SPtrans(%ecx),%ebp
1465 xorl %ebp, %edi
1466 movb %dh, %cl
1467 shrl $16, %eax
1468 movl 0x100+des_SPtrans(%ebx),%ebp
1469 xorl %ebp, %edi
1470 movb %ah, %bl
1471 shrl $16, %edx
1472 movl 0x300+des_SPtrans(%ecx),%ebp
1473 xorl %ebp, %edi
1474 movl 24(%esp), %ebp
1475 movb %dh, %cl
1476 andl $0xff, %eax
1477 andl $0xff, %edx
1478 movl 0x600+des_SPtrans(%ebx),%ebx
1479 xorl %ebx, %edi
1480 movl 0x700+des_SPtrans(%ecx),%ebx
1481 xorl %ebx, %edi
1482 movl 0x400+des_SPtrans(%eax),%ebx
1483 xorl %ebx, %edi
1484 movl 0x500+des_SPtrans(%edx),%ebx
1485 xorl %ebx, %edi
1486
1487 /* Round 3 */
1488 movl 24(%ebp), %eax
1489 xorl %ebx, %ebx
1490 movl 28(%ebp), %edx
1491 xorl %edi, %eax
1492 xorl %edi, %edx
1493 andl $0xfcfcfcfc, %eax
1494 andl $0xcfcfcfcf, %edx
1495 movb %al, %bl
1496 movb %ah, %cl
1497 rorl $4, %edx
1498 movl des_SPtrans(%ebx),%ebp
1499 movb %dl, %bl
1500 xorl %ebp, %esi
1501 movl 0x200+des_SPtrans(%ecx),%ebp
1502 xorl %ebp, %esi
1503 movb %dh, %cl
1504 shrl $16, %eax
1505 movl 0x100+des_SPtrans(%ebx),%ebp
1506 xorl %ebp, %esi
1507 movb %ah, %bl
1508 shrl $16, %edx
1509 movl 0x300+des_SPtrans(%ecx),%ebp
1510 xorl %ebp, %esi
1511 movl 24(%esp), %ebp
1512 movb %dh, %cl
1513 andl $0xff, %eax
1514 andl $0xff, %edx
1515 movl 0x600+des_SPtrans(%ebx),%ebx
1516 xorl %ebx, %esi
1517 movl 0x700+des_SPtrans(%ecx),%ebx
1518 xorl %ebx, %esi
1519 movl 0x400+des_SPtrans(%eax),%ebx
1520 xorl %ebx, %esi
1521 movl 0x500+des_SPtrans(%edx),%ebx
1522 xorl %ebx, %esi
1523
1524 /* Round 4 */
1525 movl 32(%ebp), %eax
1526 xorl %ebx, %ebx
1527 movl 36(%ebp), %edx
1528 xorl %esi, %eax
1529 xorl %esi, %edx
1530 andl $0xfcfcfcfc, %eax
1531 andl $0xcfcfcfcf, %edx
1532 movb %al, %bl
1533 movb %ah, %cl
1534 rorl $4, %edx
1535 movl des_SPtrans(%ebx),%ebp
1536 movb %dl, %bl
1537 xorl %ebp, %edi
1538 movl 0x200+des_SPtrans(%ecx),%ebp
1539 xorl %ebp, %edi
1540 movb %dh, %cl
1541 shrl $16, %eax
1542 movl 0x100+des_SPtrans(%ebx),%ebp
1543 xorl %ebp, %edi
1544 movb %ah, %bl
1545 shrl $16, %edx
1546 movl 0x300+des_SPtrans(%ecx),%ebp
1547 xorl %ebp, %edi
1548 movl 24(%esp), %ebp
1549 movb %dh, %cl
1550 andl $0xff, %eax
1551 andl $0xff, %edx
1552 movl 0x600+des_SPtrans(%ebx),%ebx
1553 xorl %ebx, %edi
1554 movl 0x700+des_SPtrans(%ecx),%ebx
1555 xorl %ebx, %edi
1556 movl 0x400+des_SPtrans(%eax),%ebx
1557 xorl %ebx, %edi
1558 movl 0x500+des_SPtrans(%edx),%ebx
1559 xorl %ebx, %edi
1560
1561 /* Round 5 */
1562 movl 40(%ebp), %eax
1563 xorl %ebx, %ebx
1564 movl 44(%ebp), %edx
1565 xorl %edi, %eax
1566 xorl %edi, %edx
1567 andl $0xfcfcfcfc, %eax
1568 andl $0xcfcfcfcf, %edx
1569 movb %al, %bl
1570 movb %ah, %cl
1571 rorl $4, %edx
1572 movl des_SPtrans(%ebx),%ebp
1573 movb %dl, %bl
1574 xorl %ebp, %esi
1575 movl 0x200+des_SPtrans(%ecx),%ebp
1576 xorl %ebp, %esi
1577 movb %dh, %cl
1578 shrl $16, %eax
1579 movl 0x100+des_SPtrans(%ebx),%ebp
1580 xorl %ebp, %esi
1581 movb %ah, %bl
1582 shrl $16, %edx
1583 movl 0x300+des_SPtrans(%ecx),%ebp
1584 xorl %ebp, %esi
1585 movl 24(%esp), %ebp
1586 movb %dh, %cl
1587 andl $0xff, %eax
1588 andl $0xff, %edx
1589 movl 0x600+des_SPtrans(%ebx),%ebx
1590 xorl %ebx, %esi
1591 movl 0x700+des_SPtrans(%ecx),%ebx
1592 xorl %ebx, %esi
1593 movl 0x400+des_SPtrans(%eax),%ebx
1594 xorl %ebx, %esi
1595 movl 0x500+des_SPtrans(%edx),%ebx
1596 xorl %ebx, %esi
1597
1598 /* Round 6 */
1599 movl 48(%ebp), %eax
1600 xorl %ebx, %ebx
1601 movl 52(%ebp), %edx
1602 xorl %esi, %eax
1603 xorl %esi, %edx
1604 andl $0xfcfcfcfc, %eax
1605 andl $0xcfcfcfcf, %edx
1606 movb %al, %bl
1607 movb %ah, %cl
1608 rorl $4, %edx
1609 movl des_SPtrans(%ebx),%ebp
1610 movb %dl, %bl
1611 xorl %ebp, %edi
1612 movl 0x200+des_SPtrans(%ecx),%ebp
1613 xorl %ebp, %edi
1614 movb %dh, %cl
1615 shrl $16, %eax
1616 movl 0x100+des_SPtrans(%ebx),%ebp
1617 xorl %ebp, %edi
1618 movb %ah, %bl
1619 shrl $16, %edx
1620 movl 0x300+des_SPtrans(%ecx),%ebp
1621 xorl %ebp, %edi
1622 movl 24(%esp), %ebp
1623 movb %dh, %cl
1624 andl $0xff, %eax
1625 andl $0xff, %edx
1626 movl 0x600+des_SPtrans(%ebx),%ebx
1627 xorl %ebx, %edi
1628 movl 0x700+des_SPtrans(%ecx),%ebx
1629 xorl %ebx, %edi
1630 movl 0x400+des_SPtrans(%eax),%ebx
1631 xorl %ebx, %edi
1632 movl 0x500+des_SPtrans(%edx),%ebx
1633 xorl %ebx, %edi
1634
1635 /* Round 7 */
1636 movl 56(%ebp), %eax
1637 xorl %ebx, %ebx
1638 movl 60(%ebp), %edx
1639 xorl %edi, %eax
1640 xorl %edi, %edx
1641 andl $0xfcfcfcfc, %eax
1642 andl $0xcfcfcfcf, %edx
1643 movb %al, %bl
1644 movb %ah, %cl
1645 rorl $4, %edx
1646 movl des_SPtrans(%ebx),%ebp
1647 movb %dl, %bl
1648 xorl %ebp, %esi
1649 movl 0x200+des_SPtrans(%ecx),%ebp
1650 xorl %ebp, %esi
1651 movb %dh, %cl
1652 shrl $16, %eax
1653 movl 0x100+des_SPtrans(%ebx),%ebp
1654 xorl %ebp, %esi
1655 movb %ah, %bl
1656 shrl $16, %edx
1657 movl 0x300+des_SPtrans(%ecx),%ebp
1658 xorl %ebp, %esi
1659 movl 24(%esp), %ebp
1660 movb %dh, %cl
1661 andl $0xff, %eax
1662 andl $0xff, %edx
1663 movl 0x600+des_SPtrans(%ebx),%ebx
1664 xorl %ebx, %esi
1665 movl 0x700+des_SPtrans(%ecx),%ebx
1666 xorl %ebx, %esi
1667 movl 0x400+des_SPtrans(%eax),%ebx
1668 xorl %ebx, %esi
1669 movl 0x500+des_SPtrans(%edx),%ebx
1670 xorl %ebx, %esi
1671
1672 /* Round 8 */
1673 movl 64(%ebp), %eax
1674 xorl %ebx, %ebx
1675 movl 68(%ebp), %edx
1676 xorl %esi, %eax
1677 xorl %esi, %edx
1678 andl $0xfcfcfcfc, %eax
1679 andl $0xcfcfcfcf, %edx
1680 movb %al, %bl
1681 movb %ah, %cl
1682 rorl $4, %edx
1683 movl des_SPtrans(%ebx),%ebp
1684 movb %dl, %bl
1685 xorl %ebp, %edi
1686 movl 0x200+des_SPtrans(%ecx),%ebp
1687 xorl %ebp, %edi
1688 movb %dh, %cl
1689 shrl $16, %eax
1690 movl 0x100+des_SPtrans(%ebx),%ebp
1691 xorl %ebp, %edi
1692 movb %ah, %bl
1693 shrl $16, %edx
1694 movl 0x300+des_SPtrans(%ecx),%ebp
1695 xorl %ebp, %edi
1696 movl 24(%esp), %ebp
1697 movb %dh, %cl
1698 andl $0xff, %eax
1699 andl $0xff, %edx
1700 movl 0x600+des_SPtrans(%ebx),%ebx
1701 xorl %ebx, %edi
1702 movl 0x700+des_SPtrans(%ecx),%ebx
1703 xorl %ebx, %edi
1704 movl 0x400+des_SPtrans(%eax),%ebx
1705 xorl %ebx, %edi
1706 movl 0x500+des_SPtrans(%edx),%ebx
1707 xorl %ebx, %edi
1708
1709 /* Round 9 */
1710 movl 72(%ebp), %eax
1711 xorl %ebx, %ebx
1712 movl 76(%ebp), %edx
1713 xorl %edi, %eax
1714 xorl %edi, %edx
1715 andl $0xfcfcfcfc, %eax
1716 andl $0xcfcfcfcf, %edx
1717 movb %al, %bl
1718 movb %ah, %cl
1719 rorl $4, %edx
1720 movl des_SPtrans(%ebx),%ebp
1721 movb %dl, %bl
1722 xorl %ebp, %esi
1723 movl 0x200+des_SPtrans(%ecx),%ebp
1724 xorl %ebp, %esi
1725 movb %dh, %cl
1726 shrl $16, %eax
1727 movl 0x100+des_SPtrans(%ebx),%ebp
1728 xorl %ebp, %esi
1729 movb %ah, %bl
1730 shrl $16, %edx
1731 movl 0x300+des_SPtrans(%ecx),%ebp
1732 xorl %ebp, %esi
1733 movl 24(%esp), %ebp
1734 movb %dh, %cl
1735 andl $0xff, %eax
1736 andl $0xff, %edx
1737 movl 0x600+des_SPtrans(%ebx),%ebx
1738 xorl %ebx, %esi
1739 movl 0x700+des_SPtrans(%ecx),%ebx
1740 xorl %ebx, %esi
1741 movl 0x400+des_SPtrans(%eax),%ebx
1742 xorl %ebx, %esi
1743 movl 0x500+des_SPtrans(%edx),%ebx
1744 xorl %ebx, %esi
1745
1746 /* Round 10 */
1747 movl 80(%ebp), %eax
1748 xorl %ebx, %ebx
1749 movl 84(%ebp), %edx
1750 xorl %esi, %eax
1751 xorl %esi, %edx
1752 andl $0xfcfcfcfc, %eax
1753 andl $0xcfcfcfcf, %edx
1754 movb %al, %bl
1755 movb %ah, %cl
1756 rorl $4, %edx
1757 movl des_SPtrans(%ebx),%ebp
1758 movb %dl, %bl
1759 xorl %ebp, %edi
1760 movl 0x200+des_SPtrans(%ecx),%ebp
1761 xorl %ebp, %edi
1762 movb %dh, %cl
1763 shrl $16, %eax
1764 movl 0x100+des_SPtrans(%ebx),%ebp
1765 xorl %ebp, %edi
1766 movb %ah, %bl
1767 shrl $16, %edx
1768 movl 0x300+des_SPtrans(%ecx),%ebp
1769 xorl %ebp, %edi
1770 movl 24(%esp), %ebp
1771 movb %dh, %cl
1772 andl $0xff, %eax
1773 andl $0xff, %edx
1774 movl 0x600+des_SPtrans(%ebx),%ebx
1775 xorl %ebx, %edi
1776 movl 0x700+des_SPtrans(%ecx),%ebx
1777 xorl %ebx, %edi
1778 movl 0x400+des_SPtrans(%eax),%ebx
1779 xorl %ebx, %edi
1780 movl 0x500+des_SPtrans(%edx),%ebx
1781 xorl %ebx, %edi
1782
1783 /* Round 11 */
1784 movl 88(%ebp), %eax
1785 xorl %ebx, %ebx
1786 movl 92(%ebp), %edx
1787 xorl %edi, %eax
1788 xorl %edi, %edx
1789 andl $0xfcfcfcfc, %eax
1790 andl $0xcfcfcfcf, %edx
1791 movb %al, %bl
1792 movb %ah, %cl
1793 rorl $4, %edx
1794 movl des_SPtrans(%ebx),%ebp
1795 movb %dl, %bl
1796 xorl %ebp, %esi
1797 movl 0x200+des_SPtrans(%ecx),%ebp
1798 xorl %ebp, %esi
1799 movb %dh, %cl
1800 shrl $16, %eax
1801 movl 0x100+des_SPtrans(%ebx),%ebp
1802 xorl %ebp, %esi
1803 movb %ah, %bl
1804 shrl $16, %edx
1805 movl 0x300+des_SPtrans(%ecx),%ebp
1806 xorl %ebp, %esi
1807 movl 24(%esp), %ebp
1808 movb %dh, %cl
1809 andl $0xff, %eax
1810 andl $0xff, %edx
1811 movl 0x600+des_SPtrans(%ebx),%ebx
1812 xorl %ebx, %esi
1813 movl 0x700+des_SPtrans(%ecx),%ebx
1814 xorl %ebx, %esi
1815 movl 0x400+des_SPtrans(%eax),%ebx
1816 xorl %ebx, %esi
1817 movl 0x500+des_SPtrans(%edx),%ebx
1818 xorl %ebx, %esi
1819
1820 /* Round 12 */
1821 movl 96(%ebp), %eax
1822 xorl %ebx, %ebx
1823 movl 100(%ebp), %edx
1824 xorl %esi, %eax
1825 xorl %esi, %edx
1826 andl $0xfcfcfcfc, %eax
1827 andl $0xcfcfcfcf, %edx
1828 movb %al, %bl
1829 movb %ah, %cl
1830 rorl $4, %edx
1831 movl des_SPtrans(%ebx),%ebp
1832 movb %dl, %bl
1833 xorl %ebp, %edi
1834 movl 0x200+des_SPtrans(%ecx),%ebp
1835 xorl %ebp, %edi
1836 movb %dh, %cl
1837 shrl $16, %eax
1838 movl 0x100+des_SPtrans(%ebx),%ebp
1839 xorl %ebp, %edi
1840 movb %ah, %bl
1841 shrl $16, %edx
1842 movl 0x300+des_SPtrans(%ecx),%ebp
1843 xorl %ebp, %edi
1844 movl 24(%esp), %ebp
1845 movb %dh, %cl
1846 andl $0xff, %eax
1847 andl $0xff, %edx
1848 movl 0x600+des_SPtrans(%ebx),%ebx
1849 xorl %ebx, %edi
1850 movl 0x700+des_SPtrans(%ecx),%ebx
1851 xorl %ebx, %edi
1852 movl 0x400+des_SPtrans(%eax),%ebx
1853 xorl %ebx, %edi
1854 movl 0x500+des_SPtrans(%edx),%ebx
1855 xorl %ebx, %edi
1856
1857 /* Round 13 */
1858 movl 104(%ebp), %eax
1859 xorl %ebx, %ebx
1860 movl 108(%ebp), %edx
1861 xorl %edi, %eax
1862 xorl %edi, %edx
1863 andl $0xfcfcfcfc, %eax
1864 andl $0xcfcfcfcf, %edx
1865 movb %al, %bl
1866 movb %ah, %cl
1867 rorl $4, %edx
1868 movl des_SPtrans(%ebx),%ebp
1869 movb %dl, %bl
1870 xorl %ebp, %esi
1871 movl 0x200+des_SPtrans(%ecx),%ebp
1872 xorl %ebp, %esi
1873 movb %dh, %cl
1874 shrl $16, %eax
1875 movl 0x100+des_SPtrans(%ebx),%ebp
1876 xorl %ebp, %esi
1877 movb %ah, %bl
1878 shrl $16, %edx
1879 movl 0x300+des_SPtrans(%ecx),%ebp
1880 xorl %ebp, %esi
1881 movl 24(%esp), %ebp
1882 movb %dh, %cl
1883 andl $0xff, %eax
1884 andl $0xff, %edx
1885 movl 0x600+des_SPtrans(%ebx),%ebx
1886 xorl %ebx, %esi
1887 movl 0x700+des_SPtrans(%ecx),%ebx
1888 xorl %ebx, %esi
1889 movl 0x400+des_SPtrans(%eax),%ebx
1890 xorl %ebx, %esi
1891 movl 0x500+des_SPtrans(%edx),%ebx
1892 xorl %ebx, %esi
1893
1894 /* Round 14 */
1895 movl 112(%ebp), %eax
1896 xorl %ebx, %ebx
1897 movl 116(%ebp), %edx
1898 xorl %esi, %eax
1899 xorl %esi, %edx
1900 andl $0xfcfcfcfc, %eax
1901 andl $0xcfcfcfcf, %edx
1902 movb %al, %bl
1903 movb %ah, %cl
1904 rorl $4, %edx
1905 movl des_SPtrans(%ebx),%ebp
1906 movb %dl, %bl
1907 xorl %ebp, %edi
1908 movl 0x200+des_SPtrans(%ecx),%ebp
1909 xorl %ebp, %edi
1910 movb %dh, %cl
1911 shrl $16, %eax
1912 movl 0x100+des_SPtrans(%ebx),%ebp
1913 xorl %ebp, %edi
1914 movb %ah, %bl
1915 shrl $16, %edx
1916 movl 0x300+des_SPtrans(%ecx),%ebp
1917 xorl %ebp, %edi
1918 movl 24(%esp), %ebp
1919 movb %dh, %cl
1920 andl $0xff, %eax
1921 andl $0xff, %edx
1922 movl 0x600+des_SPtrans(%ebx),%ebx
1923 xorl %ebx, %edi
1924 movl 0x700+des_SPtrans(%ecx),%ebx
1925 xorl %ebx, %edi
1926 movl 0x400+des_SPtrans(%eax),%ebx
1927 xorl %ebx, %edi
1928 movl 0x500+des_SPtrans(%edx),%ebx
1929 xorl %ebx, %edi
1930
1931 /* Round 15 */
1932 movl 120(%ebp), %eax
1933 xorl %ebx, %ebx
1934 movl 124(%ebp), %edx
1935 xorl %edi, %eax
1936 xorl %edi, %edx
1937 andl $0xfcfcfcfc, %eax
1938 andl $0xcfcfcfcf, %edx
1939 movb %al, %bl
1940 movb %ah, %cl
1941 rorl $4, %edx
1942 movl des_SPtrans(%ebx),%ebp
1943 movb %dl, %bl
1944 xorl %ebp, %esi
1945 movl 0x200+des_SPtrans(%ecx),%ebp
1946 xorl %ebp, %esi
1947 movb %dh, %cl
1948 shrl $16, %eax
1949 movl 0x100+des_SPtrans(%ebx),%ebp
1950 xorl %ebp, %esi
1951 movb %ah, %bl
1952 shrl $16, %edx
1953 movl 0x300+des_SPtrans(%ecx),%ebp
1954 xorl %ebp, %esi
1955 movl 24(%esp), %ebp
1956 movb %dh, %cl
1957 andl $0xff, %eax
1958 andl $0xff, %edx
1959 movl 0x600+des_SPtrans(%ebx),%ebx
1960 xorl %ebx, %esi
1961 movl 0x700+des_SPtrans(%ecx),%ebx
1962 xorl %ebx, %esi
1963 movl 0x400+des_SPtrans(%eax),%ebx
1964 xorl %ebx, %esi
1965 movl 0x500+des_SPtrans(%edx),%ebx
1966 xorl %ebx, %esi
1967 jmp .L003end
1968.L002start_decrypt:
1969
1970 /* Round 15 */
1971 movl 120(%ebp), %eax
1972 xorl %ebx, %ebx
1973 movl 124(%ebp), %edx
1974 xorl %esi, %eax
1975 xorl %esi, %edx
1976 andl $0xfcfcfcfc, %eax
1977 andl $0xcfcfcfcf, %edx
1978 movb %al, %bl
1979 movb %ah, %cl
1980 rorl $4, %edx
1981 movl des_SPtrans(%ebx),%ebp
1982 movb %dl, %bl
1983 xorl %ebp, %edi
1984 movl 0x200+des_SPtrans(%ecx),%ebp
1985 xorl %ebp, %edi
1986 movb %dh, %cl
1987 shrl $16, %eax
1988 movl 0x100+des_SPtrans(%ebx),%ebp
1989 xorl %ebp, %edi
1990 movb %ah, %bl
1991 shrl $16, %edx
1992 movl 0x300+des_SPtrans(%ecx),%ebp
1993 xorl %ebp, %edi
1994 movl 24(%esp), %ebp
1995 movb %dh, %cl
1996 andl $0xff, %eax
1997 andl $0xff, %edx
1998 movl 0x600+des_SPtrans(%ebx),%ebx
1999 xorl %ebx, %edi
2000 movl 0x700+des_SPtrans(%ecx),%ebx
2001 xorl %ebx, %edi
2002 movl 0x400+des_SPtrans(%eax),%ebx
2003 xorl %ebx, %edi
2004 movl 0x500+des_SPtrans(%edx),%ebx
2005 xorl %ebx, %edi
2006
2007 /* Round 14 */
2008 movl 112(%ebp), %eax
2009 xorl %ebx, %ebx
2010 movl 116(%ebp), %edx
2011 xorl %edi, %eax
2012 xorl %edi, %edx
2013 andl $0xfcfcfcfc, %eax
2014 andl $0xcfcfcfcf, %edx
2015 movb %al, %bl
2016 movb %ah, %cl
2017 rorl $4, %edx
2018 movl des_SPtrans(%ebx),%ebp
2019 movb %dl, %bl
2020 xorl %ebp, %esi
2021 movl 0x200+des_SPtrans(%ecx),%ebp
2022 xorl %ebp, %esi
2023 movb %dh, %cl
2024 shrl $16, %eax
2025 movl 0x100+des_SPtrans(%ebx),%ebp
2026 xorl %ebp, %esi
2027 movb %ah, %bl
2028 shrl $16, %edx
2029 movl 0x300+des_SPtrans(%ecx),%ebp
2030 xorl %ebp, %esi
2031 movl 24(%esp), %ebp
2032 movb %dh, %cl
2033 andl $0xff, %eax
2034 andl $0xff, %edx
2035 movl 0x600+des_SPtrans(%ebx),%ebx
2036 xorl %ebx, %esi
2037 movl 0x700+des_SPtrans(%ecx),%ebx
2038 xorl %ebx, %esi
2039 movl 0x400+des_SPtrans(%eax),%ebx
2040 xorl %ebx, %esi
2041 movl 0x500+des_SPtrans(%edx),%ebx
2042 xorl %ebx, %esi
2043
2044 /* Round 13 */
2045 movl 104(%ebp), %eax
2046 xorl %ebx, %ebx
2047 movl 108(%ebp), %edx
2048 xorl %esi, %eax
2049 xorl %esi, %edx
2050 andl $0xfcfcfcfc, %eax
2051 andl $0xcfcfcfcf, %edx
2052 movb %al, %bl
2053 movb %ah, %cl
2054 rorl $4, %edx
2055 movl des_SPtrans(%ebx),%ebp
2056 movb %dl, %bl
2057 xorl %ebp, %edi
2058 movl 0x200+des_SPtrans(%ecx),%ebp
2059 xorl %ebp, %edi
2060 movb %dh, %cl
2061 shrl $16, %eax
2062 movl 0x100+des_SPtrans(%ebx),%ebp
2063 xorl %ebp, %edi
2064 movb %ah, %bl
2065 shrl $16, %edx
2066 movl 0x300+des_SPtrans(%ecx),%ebp
2067 xorl %ebp, %edi
2068 movl 24(%esp), %ebp
2069 movb %dh, %cl
2070 andl $0xff, %eax
2071 andl $0xff, %edx
2072 movl 0x600+des_SPtrans(%ebx),%ebx
2073 xorl %ebx, %edi
2074 movl 0x700+des_SPtrans(%ecx),%ebx
2075 xorl %ebx, %edi
2076 movl 0x400+des_SPtrans(%eax),%ebx
2077 xorl %ebx, %edi
2078 movl 0x500+des_SPtrans(%edx),%ebx
2079 xorl %ebx, %edi
2080
2081 /* Round 12 */
2082 movl 96(%ebp), %eax
2083 xorl %ebx, %ebx
2084 movl 100(%ebp), %edx
2085 xorl %edi, %eax
2086 xorl %edi, %edx
2087 andl $0xfcfcfcfc, %eax
2088 andl $0xcfcfcfcf, %edx
2089 movb %al, %bl
2090 movb %ah, %cl
2091 rorl $4, %edx
2092 movl des_SPtrans(%ebx),%ebp
2093 movb %dl, %bl
2094 xorl %ebp, %esi
2095 movl 0x200+des_SPtrans(%ecx),%ebp
2096 xorl %ebp, %esi
2097 movb %dh, %cl
2098 shrl $16, %eax
2099 movl 0x100+des_SPtrans(%ebx),%ebp
2100 xorl %ebp, %esi
2101 movb %ah, %bl
2102 shrl $16, %edx
2103 movl 0x300+des_SPtrans(%ecx),%ebp
2104 xorl %ebp, %esi
2105 movl 24(%esp), %ebp
2106 movb %dh, %cl
2107 andl $0xff, %eax
2108 andl $0xff, %edx
2109 movl 0x600+des_SPtrans(%ebx),%ebx
2110 xorl %ebx, %esi
2111 movl 0x700+des_SPtrans(%ecx),%ebx
2112 xorl %ebx, %esi
2113 movl 0x400+des_SPtrans(%eax),%ebx
2114 xorl %ebx, %esi
2115 movl 0x500+des_SPtrans(%edx),%ebx
2116 xorl %ebx, %esi
2117
2118 /* Round 11 */
2119 movl 88(%ebp), %eax
2120 xorl %ebx, %ebx
2121 movl 92(%ebp), %edx
2122 xorl %esi, %eax
2123 xorl %esi, %edx
2124 andl $0xfcfcfcfc, %eax
2125 andl $0xcfcfcfcf, %edx
2126 movb %al, %bl
2127 movb %ah, %cl
2128 rorl $4, %edx
2129 movl des_SPtrans(%ebx),%ebp
2130 movb %dl, %bl
2131 xorl %ebp, %edi
2132 movl 0x200+des_SPtrans(%ecx),%ebp
2133 xorl %ebp, %edi
2134 movb %dh, %cl
2135 shrl $16, %eax
2136 movl 0x100+des_SPtrans(%ebx),%ebp
2137 xorl %ebp, %edi
2138 movb %ah, %bl
2139 shrl $16, %edx
2140 movl 0x300+des_SPtrans(%ecx),%ebp
2141 xorl %ebp, %edi
2142 movl 24(%esp), %ebp
2143 movb %dh, %cl
2144 andl $0xff, %eax
2145 andl $0xff, %edx
2146 movl 0x600+des_SPtrans(%ebx),%ebx
2147 xorl %ebx, %edi
2148 movl 0x700+des_SPtrans(%ecx),%ebx
2149 xorl %ebx, %edi
2150 movl 0x400+des_SPtrans(%eax),%ebx
2151 xorl %ebx, %edi
2152 movl 0x500+des_SPtrans(%edx),%ebx
2153 xorl %ebx, %edi
2154
2155 /* Round 10 */
2156 movl 80(%ebp), %eax
2157 xorl %ebx, %ebx
2158 movl 84(%ebp), %edx
2159 xorl %edi, %eax
2160 xorl %edi, %edx
2161 andl $0xfcfcfcfc, %eax
2162 andl $0xcfcfcfcf, %edx
2163 movb %al, %bl
2164 movb %ah, %cl
2165 rorl $4, %edx
2166 movl des_SPtrans(%ebx),%ebp
2167 movb %dl, %bl
2168 xorl %ebp, %esi
2169 movl 0x200+des_SPtrans(%ecx),%ebp
2170 xorl %ebp, %esi
2171 movb %dh, %cl
2172 shrl $16, %eax
2173 movl 0x100+des_SPtrans(%ebx),%ebp
2174 xorl %ebp, %esi
2175 movb %ah, %bl
2176 shrl $16, %edx
2177 movl 0x300+des_SPtrans(%ecx),%ebp
2178 xorl %ebp, %esi
2179 movl 24(%esp), %ebp
2180 movb %dh, %cl
2181 andl $0xff, %eax
2182 andl $0xff, %edx
2183 movl 0x600+des_SPtrans(%ebx),%ebx
2184 xorl %ebx, %esi
2185 movl 0x700+des_SPtrans(%ecx),%ebx
2186 xorl %ebx, %esi
2187 movl 0x400+des_SPtrans(%eax),%ebx
2188 xorl %ebx, %esi
2189 movl 0x500+des_SPtrans(%edx),%ebx
2190 xorl %ebx, %esi
2191
2192 /* Round 9 */
2193 movl 72(%ebp), %eax
2194 xorl %ebx, %ebx
2195 movl 76(%ebp), %edx
2196 xorl %esi, %eax
2197 xorl %esi, %edx
2198 andl $0xfcfcfcfc, %eax
2199 andl $0xcfcfcfcf, %edx
2200 movb %al, %bl
2201 movb %ah, %cl
2202 rorl $4, %edx
2203 movl des_SPtrans(%ebx),%ebp
2204 movb %dl, %bl
2205 xorl %ebp, %edi
2206 movl 0x200+des_SPtrans(%ecx),%ebp
2207 xorl %ebp, %edi
2208 movb %dh, %cl
2209 shrl $16, %eax
2210 movl 0x100+des_SPtrans(%ebx),%ebp
2211 xorl %ebp, %edi
2212 movb %ah, %bl
2213 shrl $16, %edx
2214 movl 0x300+des_SPtrans(%ecx),%ebp
2215 xorl %ebp, %edi
2216 movl 24(%esp), %ebp
2217 movb %dh, %cl
2218 andl $0xff, %eax
2219 andl $0xff, %edx
2220 movl 0x600+des_SPtrans(%ebx),%ebx
2221 xorl %ebx, %edi
2222 movl 0x700+des_SPtrans(%ecx),%ebx
2223 xorl %ebx, %edi
2224 movl 0x400+des_SPtrans(%eax),%ebx
2225 xorl %ebx, %edi
2226 movl 0x500+des_SPtrans(%edx),%ebx
2227 xorl %ebx, %edi
2228
2229 /* Round 8 */
2230 movl 64(%ebp), %eax
2231 xorl %ebx, %ebx
2232 movl 68(%ebp), %edx
2233 xorl %edi, %eax
2234 xorl %edi, %edx
2235 andl $0xfcfcfcfc, %eax
2236 andl $0xcfcfcfcf, %edx
2237 movb %al, %bl
2238 movb %ah, %cl
2239 rorl $4, %edx
2240 movl des_SPtrans(%ebx),%ebp
2241 movb %dl, %bl
2242 xorl %ebp, %esi
2243 movl 0x200+des_SPtrans(%ecx),%ebp
2244 xorl %ebp, %esi
2245 movb %dh, %cl
2246 shrl $16, %eax
2247 movl 0x100+des_SPtrans(%ebx),%ebp
2248 xorl %ebp, %esi
2249 movb %ah, %bl
2250 shrl $16, %edx
2251 movl 0x300+des_SPtrans(%ecx),%ebp
2252 xorl %ebp, %esi
2253 movl 24(%esp), %ebp
2254 movb %dh, %cl
2255 andl $0xff, %eax
2256 andl $0xff, %edx
2257 movl 0x600+des_SPtrans(%ebx),%ebx
2258 xorl %ebx, %esi
2259 movl 0x700+des_SPtrans(%ecx),%ebx
2260 xorl %ebx, %esi
2261 movl 0x400+des_SPtrans(%eax),%ebx
2262 xorl %ebx, %esi
2263 movl 0x500+des_SPtrans(%edx),%ebx
2264 xorl %ebx, %esi
2265
2266 /* Round 7 */
2267 movl 56(%ebp), %eax
2268 xorl %ebx, %ebx
2269 movl 60(%ebp), %edx
2270 xorl %esi, %eax
2271 xorl %esi, %edx
2272 andl $0xfcfcfcfc, %eax
2273 andl $0xcfcfcfcf, %edx
2274 movb %al, %bl
2275 movb %ah, %cl
2276 rorl $4, %edx
2277 movl des_SPtrans(%ebx),%ebp
2278 movb %dl, %bl
2279 xorl %ebp, %edi
2280 movl 0x200+des_SPtrans(%ecx),%ebp
2281 xorl %ebp, %edi
2282 movb %dh, %cl
2283 shrl $16, %eax
2284 movl 0x100+des_SPtrans(%ebx),%ebp
2285 xorl %ebp, %edi
2286 movb %ah, %bl
2287 shrl $16, %edx
2288 movl 0x300+des_SPtrans(%ecx),%ebp
2289 xorl %ebp, %edi
2290 movl 24(%esp), %ebp
2291 movb %dh, %cl
2292 andl $0xff, %eax
2293 andl $0xff, %edx
2294 movl 0x600+des_SPtrans(%ebx),%ebx
2295 xorl %ebx, %edi
2296 movl 0x700+des_SPtrans(%ecx),%ebx
2297 xorl %ebx, %edi
2298 movl 0x400+des_SPtrans(%eax),%ebx
2299 xorl %ebx, %edi
2300 movl 0x500+des_SPtrans(%edx),%ebx
2301 xorl %ebx, %edi
2302
2303 /* Round 6 */
2304 movl 48(%ebp), %eax
2305 xorl %ebx, %ebx
2306 movl 52(%ebp), %edx
2307 xorl %edi, %eax
2308 xorl %edi, %edx
2309 andl $0xfcfcfcfc, %eax
2310 andl $0xcfcfcfcf, %edx
2311 movb %al, %bl
2312 movb %ah, %cl
2313 rorl $4, %edx
2314 movl des_SPtrans(%ebx),%ebp
2315 movb %dl, %bl
2316 xorl %ebp, %esi
2317 movl 0x200+des_SPtrans(%ecx),%ebp
2318 xorl %ebp, %esi
2319 movb %dh, %cl
2320 shrl $16, %eax
2321 movl 0x100+des_SPtrans(%ebx),%ebp
2322 xorl %ebp, %esi
2323 movb %ah, %bl
2324 shrl $16, %edx
2325 movl 0x300+des_SPtrans(%ecx),%ebp
2326 xorl %ebp, %esi
2327 movl 24(%esp), %ebp
2328 movb %dh, %cl
2329 andl $0xff, %eax
2330 andl $0xff, %edx
2331 movl 0x600+des_SPtrans(%ebx),%ebx
2332 xorl %ebx, %esi
2333 movl 0x700+des_SPtrans(%ecx),%ebx
2334 xorl %ebx, %esi
2335 movl 0x400+des_SPtrans(%eax),%ebx
2336 xorl %ebx, %esi
2337 movl 0x500+des_SPtrans(%edx),%ebx
2338 xorl %ebx, %esi
2339
2340 /* Round 5 */
2341 movl 40(%ebp), %eax
2342 xorl %ebx, %ebx
2343 movl 44(%ebp), %edx
2344 xorl %esi, %eax
2345 xorl %esi, %edx
2346 andl $0xfcfcfcfc, %eax
2347 andl $0xcfcfcfcf, %edx
2348 movb %al, %bl
2349 movb %ah, %cl
2350 rorl $4, %edx
2351 movl des_SPtrans(%ebx),%ebp
2352 movb %dl, %bl
2353 xorl %ebp, %edi
2354 movl 0x200+des_SPtrans(%ecx),%ebp
2355 xorl %ebp, %edi
2356 movb %dh, %cl
2357 shrl $16, %eax
2358 movl 0x100+des_SPtrans(%ebx),%ebp
2359 xorl %ebp, %edi
2360 movb %ah, %bl
2361 shrl $16, %edx
2362 movl 0x300+des_SPtrans(%ecx),%ebp
2363 xorl %ebp, %edi
2364 movl 24(%esp), %ebp
2365 movb %dh, %cl
2366 andl $0xff, %eax
2367 andl $0xff, %edx
2368 movl 0x600+des_SPtrans(%ebx),%ebx
2369 xorl %ebx, %edi
2370 movl 0x700+des_SPtrans(%ecx),%ebx
2371 xorl %ebx, %edi
2372 movl 0x400+des_SPtrans(%eax),%ebx
2373 xorl %ebx, %edi
2374 movl 0x500+des_SPtrans(%edx),%ebx
2375 xorl %ebx, %edi
2376
2377 /* Round 4 */
2378 movl 32(%ebp), %eax
2379 xorl %ebx, %ebx
2380 movl 36(%ebp), %edx
2381 xorl %edi, %eax
2382 xorl %edi, %edx
2383 andl $0xfcfcfcfc, %eax
2384 andl $0xcfcfcfcf, %edx
2385 movb %al, %bl
2386 movb %ah, %cl
2387 rorl $4, %edx
2388 movl des_SPtrans(%ebx),%ebp
2389 movb %dl, %bl
2390 xorl %ebp, %esi
2391 movl 0x200+des_SPtrans(%ecx),%ebp
2392 xorl %ebp, %esi
2393 movb %dh, %cl
2394 shrl $16, %eax
2395 movl 0x100+des_SPtrans(%ebx),%ebp
2396 xorl %ebp, %esi
2397 movb %ah, %bl
2398 shrl $16, %edx
2399 movl 0x300+des_SPtrans(%ecx),%ebp
2400 xorl %ebp, %esi
2401 movl 24(%esp), %ebp
2402 movb %dh, %cl
2403 andl $0xff, %eax
2404 andl $0xff, %edx
2405 movl 0x600+des_SPtrans(%ebx),%ebx
2406 xorl %ebx, %esi
2407 movl 0x700+des_SPtrans(%ecx),%ebx
2408 xorl %ebx, %esi
2409 movl 0x400+des_SPtrans(%eax),%ebx
2410 xorl %ebx, %esi
2411 movl 0x500+des_SPtrans(%edx),%ebx
2412 xorl %ebx, %esi
2413
2414 /* Round 3 */
2415 movl 24(%ebp), %eax
2416 xorl %ebx, %ebx
2417 movl 28(%ebp), %edx
2418 xorl %esi, %eax
2419 xorl %esi, %edx
2420 andl $0xfcfcfcfc, %eax
2421 andl $0xcfcfcfcf, %edx
2422 movb %al, %bl
2423 movb %ah, %cl
2424 rorl $4, %edx
2425 movl des_SPtrans(%ebx),%ebp
2426 movb %dl, %bl
2427 xorl %ebp, %edi
2428 movl 0x200+des_SPtrans(%ecx),%ebp
2429 xorl %ebp, %edi
2430 movb %dh, %cl
2431 shrl $16, %eax
2432 movl 0x100+des_SPtrans(%ebx),%ebp
2433 xorl %ebp, %edi
2434 movb %ah, %bl
2435 shrl $16, %edx
2436 movl 0x300+des_SPtrans(%ecx),%ebp
2437 xorl %ebp, %edi
2438 movl 24(%esp), %ebp
2439 movb %dh, %cl
2440 andl $0xff, %eax
2441 andl $0xff, %edx
2442 movl 0x600+des_SPtrans(%ebx),%ebx
2443 xorl %ebx, %edi
2444 movl 0x700+des_SPtrans(%ecx),%ebx
2445 xorl %ebx, %edi
2446 movl 0x400+des_SPtrans(%eax),%ebx
2447 xorl %ebx, %edi
2448 movl 0x500+des_SPtrans(%edx),%ebx
2449 xorl %ebx, %edi
2450
2451 /* Round 2 */
2452 movl 16(%ebp), %eax
2453 xorl %ebx, %ebx
2454 movl 20(%ebp), %edx
2455 xorl %edi, %eax
2456 xorl %edi, %edx
2457 andl $0xfcfcfcfc, %eax
2458 andl $0xcfcfcfcf, %edx
2459 movb %al, %bl
2460 movb %ah, %cl
2461 rorl $4, %edx
2462 movl des_SPtrans(%ebx),%ebp
2463 movb %dl, %bl
2464 xorl %ebp, %esi
2465 movl 0x200+des_SPtrans(%ecx),%ebp
2466 xorl %ebp, %esi
2467 movb %dh, %cl
2468 shrl $16, %eax
2469 movl 0x100+des_SPtrans(%ebx),%ebp
2470 xorl %ebp, %esi
2471 movb %ah, %bl
2472 shrl $16, %edx
2473 movl 0x300+des_SPtrans(%ecx),%ebp
2474 xorl %ebp, %esi
2475 movl 24(%esp), %ebp
2476 movb %dh, %cl
2477 andl $0xff, %eax
2478 andl $0xff, %edx
2479 movl 0x600+des_SPtrans(%ebx),%ebx
2480 xorl %ebx, %esi
2481 movl 0x700+des_SPtrans(%ecx),%ebx
2482 xorl %ebx, %esi
2483 movl 0x400+des_SPtrans(%eax),%ebx
2484 xorl %ebx, %esi
2485 movl 0x500+des_SPtrans(%edx),%ebx
2486 xorl %ebx, %esi
2487
2488 /* Round 1 */
2489 movl 8(%ebp), %eax
2490 xorl %ebx, %ebx
2491 movl 12(%ebp), %edx
2492 xorl %esi, %eax
2493 xorl %esi, %edx
2494 andl $0xfcfcfcfc, %eax
2495 andl $0xcfcfcfcf, %edx
2496 movb %al, %bl
2497 movb %ah, %cl
2498 rorl $4, %edx
2499 movl des_SPtrans(%ebx),%ebp
2500 movb %dl, %bl
2501 xorl %ebp, %edi
2502 movl 0x200+des_SPtrans(%ecx),%ebp
2503 xorl %ebp, %edi
2504 movb %dh, %cl
2505 shrl $16, %eax
2506 movl 0x100+des_SPtrans(%ebx),%ebp
2507 xorl %ebp, %edi
2508 movb %ah, %bl
2509 shrl $16, %edx
2510 movl 0x300+des_SPtrans(%ecx),%ebp
2511 xorl %ebp, %edi
2512 movl 24(%esp), %ebp
2513 movb %dh, %cl
2514 andl $0xff, %eax
2515 andl $0xff, %edx
2516 movl 0x600+des_SPtrans(%ebx),%ebx
2517 xorl %ebx, %edi
2518 movl 0x700+des_SPtrans(%ecx),%ebx
2519 xorl %ebx, %edi
2520 movl 0x400+des_SPtrans(%eax),%ebx
2521 xorl %ebx, %edi
2522 movl 0x500+des_SPtrans(%edx),%ebx
2523 xorl %ebx, %edi
2524
2525 /* Round 0 */
2526 movl (%ebp), %eax
2527 xorl %ebx, %ebx
2528 movl 4(%ebp), %edx
2529 xorl %edi, %eax
2530 xorl %edi, %edx
2531 andl $0xfcfcfcfc, %eax
2532 andl $0xcfcfcfcf, %edx
2533 movb %al, %bl
2534 movb %ah, %cl
2535 rorl $4, %edx
2536 movl des_SPtrans(%ebx),%ebp
2537 movb %dl, %bl
2538 xorl %ebp, %esi
2539 movl 0x200+des_SPtrans(%ecx),%ebp
2540 xorl %ebp, %esi
2541 movb %dh, %cl
2542 shrl $16, %eax
2543 movl 0x100+des_SPtrans(%ebx),%ebp
2544 xorl %ebp, %esi
2545 movb %ah, %bl
2546 shrl $16, %edx
2547 movl 0x300+des_SPtrans(%ecx),%ebp
2548 xorl %ebp, %esi
2549 movl 24(%esp), %ebp
2550 movb %dh, %cl
2551 andl $0xff, %eax
2552 andl $0xff, %edx
2553 movl 0x600+des_SPtrans(%ebx),%ebx
2554 xorl %ebx, %esi
2555 movl 0x700+des_SPtrans(%ecx),%ebx
2556 xorl %ebx, %esi
2557 movl 0x400+des_SPtrans(%eax),%ebx
2558 xorl %ebx, %esi
2559 movl 0x500+des_SPtrans(%edx),%ebx
2560 xorl %ebx, %esi
2561.L003end:
2562
2563 /* Fixup */
2564 rorl $3, %edi
2565 movl 20(%esp), %eax
2566 rorl $3, %esi
2567 movl %edi, (%eax)
2568 movl %esi, 4(%eax)
2569 popl %ebp
2570 popl %ebx
2571 popl %edi
2572 popl %esi
2573 ret
2574.des_encrypt2_end:
2575 SIZE(des_encrypt2,.des_encrypt2_end-des_encrypt2)
2576.ident "desasm.pl"
2577.text
2578 .align ALIGN
2579.globl des_encrypt3
2580 TYPE(des_encrypt3,@function)
2581des_encrypt3:
2582 pushl %ebx
2583 movl 8(%esp), %ebx
2584 pushl %ebp
2585 pushl %esi
2586 pushl %edi
2587
2588 /* Load the data words */
2589 movl (%ebx), %edi
2590 movl 4(%ebx), %esi
2591 subl $12, %esp
2592
2593 /* IP */
2594 roll $4, %edi
2595 movl %edi, %edx
2596 xorl %esi, %edi
2597 andl $0xf0f0f0f0, %edi
2598 xorl %edi, %edx
2599 xorl %edi, %esi
2600
2601 roll $20, %esi
2602 movl %esi, %edi
2603 xorl %edx, %esi
2604 andl $0xfff0000f, %esi
2605 xorl %esi, %edi
2606 xorl %esi, %edx
2607
2608 roll $14, %edi
2609 movl %edi, %esi
2610 xorl %edx, %edi
2611 andl $0x33333333, %edi
2612 xorl %edi, %esi
2613 xorl %edi, %edx
2614
2615 roll $22, %edx
2616 movl %edx, %edi
2617 xorl %esi, %edx
2618 andl $0x03fc03fc, %edx
2619 xorl %edx, %edi
2620 xorl %edx, %esi
2621
2622 roll $9, %edi
2623 movl %edi, %edx
2624 xorl %esi, %edi
2625 andl $0xaaaaaaaa, %edi
2626 xorl %edi, %edx
2627 xorl %edi, %esi
2628
2629 rorl $3, %edx
2630 rorl $2, %esi
2631 movl %esi, 4(%ebx)
2632 movl 36(%esp), %eax
2633 movl %edx, (%ebx)
2634 movl 40(%esp), %edi
2635 movl 44(%esp), %esi
2636 movl $1, 8(%esp)
2637 movl %eax, 4(%esp)
2638 movl %ebx, (%esp)
2639 call des_encrypt2
2640 movl $0, 8(%esp)
2641 movl %edi, 4(%esp)
2642 movl %ebx, (%esp)
2643 call des_encrypt2
2644 movl $1, 8(%esp)
2645 movl %esi, 4(%esp)
2646 movl %ebx, (%esp)
2647 call des_encrypt2
2648 addl $12, %esp
2649 movl (%ebx), %edi
2650 movl 4(%ebx), %esi
2651
2652 /* FP */
2653 roll $2, %esi
2654 roll $3, %edi
2655 movl %edi, %eax
2656 xorl %esi, %edi
2657 andl $0xaaaaaaaa, %edi
2658 xorl %edi, %eax
2659 xorl %edi, %esi
2660
2661 roll $23, %eax
2662 movl %eax, %edi
2663 xorl %esi, %eax
2664 andl $0x03fc03fc, %eax
2665 xorl %eax, %edi
2666 xorl %eax, %esi
2667
2668 roll $10, %edi
2669 movl %edi, %eax
2670 xorl %esi, %edi
2671 andl $0x33333333, %edi
2672 xorl %edi, %eax
2673 xorl %edi, %esi
2674
2675 roll $18, %esi
2676 movl %esi, %edi
2677 xorl %eax, %esi
2678 andl $0xfff0000f, %esi
2679 xorl %esi, %edi
2680 xorl %esi, %eax
2681
2682 roll $12, %edi
2683 movl %edi, %esi
2684 xorl %eax, %edi
2685 andl $0xf0f0f0f0, %edi
2686 xorl %edi, %esi
2687 xorl %edi, %eax
2688
2689 rorl $4, %eax
2690 movl %eax, (%ebx)
2691 movl %esi, 4(%ebx)
2692 popl %edi
2693 popl %esi
2694 popl %ebp
2695 popl %ebx
2696 ret
2697.des_encrypt3_end:
2698 SIZE(des_encrypt3,.des_encrypt3_end-des_encrypt3)
2699.ident "desasm.pl"
2700.text
2701 .align ALIGN
2702.globl des_decrypt3
2703 TYPE(des_decrypt3,@function)
2704des_decrypt3:
2705 pushl %ebx
2706 movl 8(%esp), %ebx
2707 pushl %ebp
2708 pushl %esi
2709 pushl %edi
2710
2711 /* Load the data words */
2712 movl (%ebx), %edi
2713 movl 4(%ebx), %esi
2714 subl $12, %esp
2715
2716 /* IP */
2717 roll $4, %edi
2718 movl %edi, %edx
2719 xorl %esi, %edi
2720 andl $0xf0f0f0f0, %edi
2721 xorl %edi, %edx
2722 xorl %edi, %esi
2723
2724 roll $20, %esi
2725 movl %esi, %edi
2726 xorl %edx, %esi
2727 andl $0xfff0000f, %esi
2728 xorl %esi, %edi
2729 xorl %esi, %edx
2730
2731 roll $14, %edi
2732 movl %edi, %esi
2733 xorl %edx, %edi
2734 andl $0x33333333, %edi
2735 xorl %edi, %esi
2736 xorl %edi, %edx
2737
2738 roll $22, %edx
2739 movl %edx, %edi
2740 xorl %esi, %edx
2741 andl $0x03fc03fc, %edx
2742 xorl %edx, %edi
2743 xorl %edx, %esi
2744
2745 roll $9, %edi
2746 movl %edi, %edx
2747 xorl %esi, %edi
2748 andl $0xaaaaaaaa, %edi
2749 xorl %edi, %edx
2750 xorl %edi, %esi
2751
2752 rorl $3, %edx
2753 rorl $2, %esi
2754 movl %esi, 4(%ebx)
2755 movl 36(%esp), %esi
2756 movl %edx, (%ebx)
2757 movl 40(%esp), %edi
2758 movl 44(%esp), %eax
2759 movl $0, 8(%esp)
2760 movl %eax, 4(%esp)
2761 movl %ebx, (%esp)
2762 call des_encrypt2
2763 movl $1, 8(%esp)
2764 movl %edi, 4(%esp)
2765 movl %ebx, (%esp)
2766 call des_encrypt2
2767 movl $0, 8(%esp)
2768 movl %esi, 4(%esp)
2769 movl %ebx, (%esp)
2770 call des_encrypt2
2771 addl $12, %esp
2772 movl (%ebx), %edi
2773 movl 4(%ebx), %esi
2774
2775 /* FP */
2776 roll $2, %esi
2777 roll $3, %edi
2778 movl %edi, %eax
2779 xorl %esi, %edi
2780 andl $0xaaaaaaaa, %edi
2781 xorl %edi, %eax
2782 xorl %edi, %esi
2783
2784 roll $23, %eax
2785 movl %eax, %edi
2786 xorl %esi, %eax
2787 andl $0x03fc03fc, %eax
2788 xorl %eax, %edi
2789 xorl %eax, %esi
2790
2791 roll $10, %edi
2792 movl %edi, %eax
2793 xorl %esi, %edi
2794 andl $0x33333333, %edi
2795 xorl %edi, %eax
2796 xorl %edi, %esi
2797
2798 roll $18, %esi
2799 movl %esi, %edi
2800 xorl %eax, %esi
2801 andl $0xfff0000f, %esi
2802 xorl %esi, %edi
2803 xorl %esi, %eax
2804
2805 roll $12, %edi
2806 movl %edi, %esi
2807 xorl %eax, %edi
2808 andl $0xf0f0f0f0, %edi
2809 xorl %edi, %esi
2810 xorl %edi, %eax
2811
2812 rorl $4, %eax
2813 movl %eax, (%ebx)
2814 movl %esi, 4(%ebx)
2815 popl %edi
2816 popl %esi
2817 popl %ebp
2818 popl %ebx
2819 ret
2820.des_decrypt3_end:
2821 SIZE(des_decrypt3,.des_decrypt3_end-des_decrypt3)
2822.ident "desasm.pl"
2823.text
2824 .align ALIGN
2825.globl des_ncbc_encrypt
2826 TYPE(des_ncbc_encrypt,@function)
2827des_ncbc_encrypt:
2828
2829 pushl %ebp
2830 pushl %ebx
2831 pushl %esi
2832 pushl %edi
2833 movl 28(%esp), %ebp
2834 /* getting iv ptr from parameter 4 */
2835 movl 36(%esp), %ebx
2836 movl (%ebx), %esi
2837 movl 4(%ebx), %edi
2838 pushl %edi
2839 pushl %esi
2840 pushl %edi
2841 pushl %esi
2842 movl %esp, %ebx
2843 movl 36(%esp), %esi
2844 movl 40(%esp), %edi
2845 /* getting encrypt flag from parameter 5 */
2846 movl 56(%esp), %ecx
2847 /* get and push parameter 5 */
2848 pushl %ecx
2849 /* get and push parameter 3 */
2850 movl 52(%esp), %eax
2851 pushl %eax
2852 pushl %ebx
2853 cmpl $0, %ecx
2854 jz .L004decrypt
2855 andl $4294967288, %ebp
2856 movl 12(%esp), %eax
2857 movl 16(%esp), %ebx
2858 jz .L005encrypt_finish
2859.L006encrypt_loop:
2860 movl (%esi), %ecx
2861 movl 4(%esi), %edx
2862 xorl %ecx, %eax
2863 xorl %edx, %ebx
2864 movl %eax, 12(%esp)
2865 movl %ebx, 16(%esp)
2866 call des_encrypt
2867 movl 12(%esp), %eax
2868 movl 16(%esp), %ebx
2869 movl %eax, (%edi)
2870 movl %ebx, 4(%edi)
2871 addl $8, %esi
2872 addl $8, %edi
2873 subl $8, %ebp
2874 jnz .L006encrypt_loop
2875.L005encrypt_finish:
2876 movl 56(%esp), %ebp
2877 andl $7, %ebp
2878 jz .L007finish
2879 xorl %ecx, %ecx
2880 xorl %edx, %edx
2881 movl .L008cbc_enc_jmp_table(,%ebp,4),%ebp
2882 jmp *%ebp
2883.L009ej7:
2884 movb 6(%esi), %dh
2885 sall $8, %edx
2886.L010ej6:
2887 movb 5(%esi), %dh
2888.L011ej5:
2889 movb 4(%esi), %dl
2890.L012ej4:
2891 movl (%esi), %ecx
2892 jmp .L013ejend
2893.L014ej3:
2894 movb 2(%esi), %ch
2895 sall $8, %ecx
2896.L015ej2:
2897 movb 1(%esi), %ch
2898.L016ej1:
2899 movb (%esi), %cl
2900.L013ejend:
2901 xorl %ecx, %eax
2902 xorl %edx, %ebx
2903 movl %eax, 12(%esp)
2904 movl %ebx, 16(%esp)
2905 call des_encrypt
2906 movl 12(%esp), %eax
2907 movl 16(%esp), %ebx
2908 movl %eax, (%edi)
2909 movl %ebx, 4(%edi)
2910 jmp .L007finish
2911.align ALIGN
2912.L004decrypt:
2913 andl $4294967288, %ebp
2914 movl 20(%esp), %eax
2915 movl 24(%esp), %ebx
2916 jz .L017decrypt_finish
2917.L018decrypt_loop:
2918 movl (%esi), %eax
2919 movl 4(%esi), %ebx
2920 movl %eax, 12(%esp)
2921 movl %ebx, 16(%esp)
2922 call des_encrypt
2923 movl 12(%esp), %eax
2924 movl 16(%esp), %ebx
2925 movl 20(%esp), %ecx
2926 movl 24(%esp), %edx
2927 xorl %eax, %ecx
2928 xorl %ebx, %edx
2929 movl (%esi), %eax
2930 movl 4(%esi), %ebx
2931 movl %ecx, (%edi)
2932 movl %edx, 4(%edi)
2933 movl %eax, 20(%esp)
2934 movl %ebx, 24(%esp)
2935 addl $8, %esi
2936 addl $8, %edi
2937 subl $8, %ebp
2938 jnz .L018decrypt_loop
2939.L017decrypt_finish:
2940 movl 56(%esp), %ebp
2941 andl $7, %ebp
2942 jz .L007finish
2943 movl (%esi), %eax
2944 movl 4(%esi), %ebx
2945 movl %eax, 12(%esp)
2946 movl %ebx, 16(%esp)
2947 call des_encrypt
2948 movl 12(%esp), %eax
2949 movl 16(%esp), %ebx
2950 movl 20(%esp), %ecx
2951 movl 24(%esp), %edx
2952 xorl %eax, %ecx
2953 xorl %ebx, %edx
2954 movl (%esi), %eax
2955 movl 4(%esi), %ebx
2956.L019dj7:
2957 rorl $16, %edx
2958 movb %dl, 6(%edi)
2959 shrl $16, %edx
2960.L020dj6:
2961 movb %dh, 5(%edi)
2962.L021dj5:
2963 movb %dl, 4(%edi)
2964.L022dj4:
2965 movl %ecx, (%edi)
2966 jmp .L023djend
2967.L024dj3:
2968 rorl $16, %ecx
2969 movb %cl, 2(%edi)
2970 sall $16, %ecx
2971.L025dj2:
2972 movb %ch, 1(%esi)
2973.L026dj1:
2974 movb %cl, (%esi)
2975.L023djend:
2976 jmp .L007finish
2977.align ALIGN
2978.L007finish:
2979 movl 64(%esp), %ecx
2980 addl $28, %esp
2981 movl %eax, (%ecx)
2982 movl %ebx, 4(%ecx)
2983 popl %edi
2984 popl %esi
2985 popl %ebx
2986 popl %ebp
2987 ret
2988.align ALIGN
2989.L008cbc_enc_jmp_table:
2990 .long 0
2991 .long .L016ej1
2992 .long .L015ej2
2993 .long .L014ej3
2994 .long .L012ej4
2995 .long .L011ej5
2996 .long .L010ej6
2997 .long .L009ej7
2998.align ALIGN
2999.L027cbc_dec_jmp_table:
3000 .long 0
3001 .long .L026dj1
3002 .long .L025dj2
3003 .long .L024dj3
3004 .long .L022dj4
3005 .long .L021dj5
3006 .long .L020dj6
3007 .long .L019dj7
3008.des_ncbc_encrypt_end:
3009 SIZE(des_ncbc_encrypt,.des_ncbc_encrypt_end-des_ncbc_encrypt)
3010.ident "desasm.pl"
3011.text
3012 .align ALIGN
3013.globl des_ede3_cbc_encrypt
3014 TYPE(des_ede3_cbc_encrypt,@function)
3015des_ede3_cbc_encrypt:
3016
3017 pushl %ebp
3018 pushl %ebx
3019 pushl %esi
3020 pushl %edi
3021 movl 28(%esp), %ebp
3022 /* getting iv ptr from parameter 6 */
3023 movl 44(%esp), %ebx
3024 movl (%ebx), %esi
3025 movl 4(%ebx), %edi
3026 pushl %edi
3027 pushl %esi
3028 pushl %edi
3029 pushl %esi
3030 movl %esp, %ebx
3031 movl 36(%esp), %esi
3032 movl 40(%esp), %edi
3033 /* getting encrypt flag from parameter 7 */
3034 movl 64(%esp), %ecx
3035 /* get and push parameter 5 */
3036 movl 56(%esp), %eax
3037 pushl %eax
3038 /* get and push parameter 4 */
3039 movl 56(%esp), %eax
3040 pushl %eax
3041 /* get and push parameter 3 */
3042 movl 56(%esp), %eax
3043 pushl %eax
3044 pushl %ebx
3045 cmpl $0, %ecx
3046 jz .L028decrypt
3047 andl $4294967288, %ebp
3048 movl 16(%esp), %eax
3049 movl 20(%esp), %ebx
3050 jz .L029encrypt_finish
3051.L030encrypt_loop:
3052 movl (%esi), %ecx
3053 movl 4(%esi), %edx
3054 xorl %ecx, %eax
3055 xorl %edx, %ebx
3056 movl %eax, 16(%esp)
3057 movl %ebx, 20(%esp)
3058 call des_encrypt3
3059 movl 16(%esp), %eax
3060 movl 20(%esp), %ebx
3061 movl %eax, (%edi)
3062 movl %ebx, 4(%edi)
3063 addl $8, %esi
3064 addl $8, %edi
3065 subl $8, %ebp
3066 jnz .L030encrypt_loop
3067.L029encrypt_finish:
3068 movl 60(%esp), %ebp
3069 andl $7, %ebp
3070 jz .L031finish
3071 xorl %ecx, %ecx
3072 xorl %edx, %edx
3073 movl .L032cbc_enc_jmp_table(,%ebp,4),%ebp
3074 jmp *%ebp
3075.L033ej7:
3076 movb 6(%esi), %dh
3077 sall $8, %edx
3078.L034ej6:
3079 movb 5(%esi), %dh
3080.L035ej5:
3081 movb 4(%esi), %dl
3082.L036ej4:
3083 movl (%esi), %ecx
3084 jmp .L037ejend
3085.L038ej3:
3086 movb 2(%esi), %ch
3087 sall $8, %ecx
3088.L039ej2:
3089 movb 1(%esi), %ch
3090.L040ej1:
3091 movb (%esi), %cl
3092.L037ejend:
3093 xorl %ecx, %eax
3094 xorl %edx, %ebx
3095 movl %eax, 16(%esp)
3096 movl %ebx, 20(%esp)
3097 call des_encrypt3
3098 movl 16(%esp), %eax
3099 movl 20(%esp), %ebx
3100 movl %eax, (%edi)
3101 movl %ebx, 4(%edi)
3102 jmp .L031finish
3103.align ALIGN
3104.L028decrypt:
3105 andl $4294967288, %ebp
3106 movl 24(%esp), %eax
3107 movl 28(%esp), %ebx
3108 jz .L041decrypt_finish
3109.L042decrypt_loop:
3110 movl (%esi), %eax
3111 movl 4(%esi), %ebx
3112 movl %eax, 16(%esp)
3113 movl %ebx, 20(%esp)
3114 call des_decrypt3
3115 movl 16(%esp), %eax
3116 movl 20(%esp), %ebx
3117 movl 24(%esp), %ecx
3118 movl 28(%esp), %edx
3119 xorl %eax, %ecx
3120 xorl %ebx, %edx
3121 movl (%esi), %eax
3122 movl 4(%esi), %ebx
3123 movl %ecx, (%edi)
3124 movl %edx, 4(%edi)
3125 movl %eax, 24(%esp)
3126 movl %ebx, 28(%esp)
3127 addl $8, %esi
3128 addl $8, %edi
3129 subl $8, %ebp
3130 jnz .L042decrypt_loop
3131.L041decrypt_finish:
3132 movl 60(%esp), %ebp
3133 andl $7, %ebp
3134 jz .L031finish
3135 movl (%esi), %eax
3136 movl 4(%esi), %ebx
3137 movl %eax, 16(%esp)
3138 movl %ebx, 20(%esp)
3139 call des_decrypt3
3140 movl 16(%esp), %eax
3141 movl 20(%esp), %ebx
3142 movl 24(%esp), %ecx
3143 movl 28(%esp), %edx
3144 xorl %eax, %ecx
3145 xorl %ebx, %edx
3146 movl (%esi), %eax
3147 movl 4(%esi), %ebx
3148.L043dj7:
3149 rorl $16, %edx
3150 movb %dl, 6(%edi)
3151 shrl $16, %edx
3152.L044dj6:
3153 movb %dh, 5(%edi)
3154.L045dj5:
3155 movb %dl, 4(%edi)
3156.L046dj4:
3157 movl %ecx, (%edi)
3158 jmp .L047djend
3159.L048dj3:
3160 rorl $16, %ecx
3161 movb %cl, 2(%edi)
3162 sall $16, %ecx
3163.L049dj2:
3164 movb %ch, 1(%esi)
3165.L050dj1:
3166 movb %cl, (%esi)
3167.L047djend:
3168 jmp .L031finish
3169.align ALIGN
3170.L031finish:
3171 movl 76(%esp), %ecx
3172 addl $32, %esp
3173 movl %eax, (%ecx)
3174 movl %ebx, 4(%ecx)
3175 popl %edi
3176 popl %esi
3177 popl %ebx
3178 popl %ebp
3179 ret
3180.align ALIGN
3181.L032cbc_enc_jmp_table:
3182 .long 0
3183 .long .L040ej1
3184 .long .L039ej2
3185 .long .L038ej3
3186 .long .L036ej4
3187 .long .L035ej5
3188 .long .L034ej6
3189 .long .L033ej7
3190.align ALIGN
3191.L051cbc_dec_jmp_table:
3192 .long 0
3193 .long .L050dj1
3194 .long .L049dj2
3195 .long .L048dj3
3196 .long .L046dj4
3197 .long .L045dj5
3198 .long .L044dj6
3199 .long .L043dj7
3200.des_ede3_cbc_encrypt_end:
3201 SIZE(des_ede3_cbc_encrypt,.des_ede3_cbc_encrypt_end-des_ede3_cbc_encrypt)
3202.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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define des_SPtrans _des_SPtrans
13#define fcrypt_body _fcrypt_body
14
15#endif
16
17#ifdef OUT
18#define OK 1
19#define ALIGN 4
20#endif
21
22#ifdef BSDI
23#define OK 1
24#define ALIGN 4
25#undef SIZE
26#undef TYPE
27#define SIZE(a,b)
28#define TYPE(a,b)
29#endif
30
31#if defined(ELF) || defined(SOL)
32#define OK 1
33#define ALIGN 16
34#endif
35
36#ifndef OK
37You need to define one of
38ELF - elf systems - linux-elf, NetBSD and DG-UX
39OUT - a.out systems - linux-a.out and FreeBSD
40SOL - solaris systems, which are elf with strange comment lines
41BSDI - a.out with a very primative version of as.
42#endif
43
44/* Let the Assembler begin :-) */
45 /* Don't even think of reading this code */
46 /* It was automatically generated by crypt586.pl */
47 /* Which is a perl program used to generate the x86 assember for */
48 /* any of elf, a.out, BSDI,Win32, or Solaris */
49 /* eric <eay@cryptsoft.com> */
50
51 .file "crypt586.s"
52 .version "01.01"
53gcc2_compiled.:
54.text
55 .align ALIGN
56.globl fcrypt_body
57 TYPE(fcrypt_body,@function)
58fcrypt_body:
59 pushl %ebp
60 pushl %ebx
61 pushl %esi
62 pushl %edi
63
64
65 /* Load the 2 words */
66 xorl %edi, %edi
67 xorl %esi, %esi
68 movl 24(%esp), %ebp
69 pushl $25
70.L000start:
71
72 /* Round 0 */
73 movl 32(%esp), %eax
74 movl %esi, %edx
75 shrl $16, %edx
76 movl 36(%esp), %ecx
77 xorl %esi, %edx
78 andl %edx, %eax
79 andl %ecx, %edx
80 movl %eax, %ebx
81 sall $16, %ebx
82 movl %edx, %ecx
83 sall $16, %ecx
84 xorl %ebx, %eax
85 xorl %ecx, %edx
86 movl (%ebp), %ebx
87 xorl %ebx, %eax
88 movl 4(%ebp), %ecx
89 xorl %esi, %eax
90 xorl %esi, %edx
91 xorl %ecx, %edx
92 andl $0xfcfcfcfc, %eax
93 xorl %ebx, %ebx
94 andl $0xcfcfcfcf, %edx
95 xorl %ecx, %ecx
96 movb %al, %bl
97 movb %ah, %cl
98 rorl $4, %edx
99 movl des_SPtrans(%ebx),%ebp
100 movb %dl, %bl
101 xorl %ebp, %edi
102 movl 0x200+des_SPtrans(%ecx),%ebp
103 xorl %ebp, %edi
104 movb %dh, %cl
105 shrl $16, %eax
106 movl 0x100+des_SPtrans(%ebx),%ebp
107 xorl %ebp, %edi
108 movb %ah, %bl
109 shrl $16, %edx
110 movl 0x300+des_SPtrans(%ecx),%ebp
111 xorl %ebp, %edi
112 movl 28(%esp), %ebp
113 movb %dh, %cl
114 andl $0xff, %eax
115 andl $0xff, %edx
116 movl 0x600+des_SPtrans(%ebx),%ebx
117 xorl %ebx, %edi
118 movl 0x700+des_SPtrans(%ecx),%ebx
119 xorl %ebx, %edi
120 movl 0x400+des_SPtrans(%eax),%ebx
121 xorl %ebx, %edi
122 movl 0x500+des_SPtrans(%edx),%ebx
123 xorl %ebx, %edi
124
125 /* Round 1 */
126 movl 32(%esp), %eax
127 movl %edi, %edx
128 shrl $16, %edx
129 movl 36(%esp), %ecx
130 xorl %edi, %edx
131 andl %edx, %eax
132 andl %ecx, %edx
133 movl %eax, %ebx
134 sall $16, %ebx
135 movl %edx, %ecx
136 sall $16, %ecx
137 xorl %ebx, %eax
138 xorl %ecx, %edx
139 movl 8(%ebp), %ebx
140 xorl %ebx, %eax
141 movl 12(%ebp), %ecx
142 xorl %edi, %eax
143 xorl %edi, %edx
144 xorl %ecx, %edx
145 andl $0xfcfcfcfc, %eax
146 xorl %ebx, %ebx
147 andl $0xcfcfcfcf, %edx
148 xorl %ecx, %ecx
149 movb %al, %bl
150 movb %ah, %cl
151 rorl $4, %edx
152 movl des_SPtrans(%ebx),%ebp
153 movb %dl, %bl
154 xorl %ebp, %esi
155 movl 0x200+des_SPtrans(%ecx),%ebp
156 xorl %ebp, %esi
157 movb %dh, %cl
158 shrl $16, %eax
159 movl 0x100+des_SPtrans(%ebx),%ebp
160 xorl %ebp, %esi
161 movb %ah, %bl
162 shrl $16, %edx
163 movl 0x300+des_SPtrans(%ecx),%ebp
164 xorl %ebp, %esi
165 movl 28(%esp), %ebp
166 movb %dh, %cl
167 andl $0xff, %eax
168 andl $0xff, %edx
169 movl 0x600+des_SPtrans(%ebx),%ebx
170 xorl %ebx, %esi
171 movl 0x700+des_SPtrans(%ecx),%ebx
172 xorl %ebx, %esi
173 movl 0x400+des_SPtrans(%eax),%ebx
174 xorl %ebx, %esi
175 movl 0x500+des_SPtrans(%edx),%ebx
176 xorl %ebx, %esi
177
178 /* Round 2 */
179 movl 32(%esp), %eax
180 movl %esi, %edx
181 shrl $16, %edx
182 movl 36(%esp), %ecx
183 xorl %esi, %edx
184 andl %edx, %eax
185 andl %ecx, %edx
186 movl %eax, %ebx
187 sall $16, %ebx
188 movl %edx, %ecx
189 sall $16, %ecx
190 xorl %ebx, %eax
191 xorl %ecx, %edx
192 movl 16(%ebp), %ebx
193 xorl %ebx, %eax
194 movl 20(%ebp), %ecx
195 xorl %esi, %eax
196 xorl %esi, %edx
197 xorl %ecx, %edx
198 andl $0xfcfcfcfc, %eax
199 xorl %ebx, %ebx
200 andl $0xcfcfcfcf, %edx
201 xorl %ecx, %ecx
202 movb %al, %bl
203 movb %ah, %cl
204 rorl $4, %edx
205 movl des_SPtrans(%ebx),%ebp
206 movb %dl, %bl
207 xorl %ebp, %edi
208 movl 0x200+des_SPtrans(%ecx),%ebp
209 xorl %ebp, %edi
210 movb %dh, %cl
211 shrl $16, %eax
212 movl 0x100+des_SPtrans(%ebx),%ebp
213 xorl %ebp, %edi
214 movb %ah, %bl
215 shrl $16, %edx
216 movl 0x300+des_SPtrans(%ecx),%ebp
217 xorl %ebp, %edi
218 movl 28(%esp), %ebp
219 movb %dh, %cl
220 andl $0xff, %eax
221 andl $0xff, %edx
222 movl 0x600+des_SPtrans(%ebx),%ebx
223 xorl %ebx, %edi
224 movl 0x700+des_SPtrans(%ecx),%ebx
225 xorl %ebx, %edi
226 movl 0x400+des_SPtrans(%eax),%ebx
227 xorl %ebx, %edi
228 movl 0x500+des_SPtrans(%edx),%ebx
229 xorl %ebx, %edi
230
231 /* Round 3 */
232 movl 32(%esp), %eax
233 movl %edi, %edx
234 shrl $16, %edx
235 movl 36(%esp), %ecx
236 xorl %edi, %edx
237 andl %edx, %eax
238 andl %ecx, %edx
239 movl %eax, %ebx
240 sall $16, %ebx
241 movl %edx, %ecx
242 sall $16, %ecx
243 xorl %ebx, %eax
244 xorl %ecx, %edx
245 movl 24(%ebp), %ebx
246 xorl %ebx, %eax
247 movl 28(%ebp), %ecx
248 xorl %edi, %eax
249 xorl %edi, %edx
250 xorl %ecx, %edx
251 andl $0xfcfcfcfc, %eax
252 xorl %ebx, %ebx
253 andl $0xcfcfcfcf, %edx
254 xorl %ecx, %ecx
255 movb %al, %bl
256 movb %ah, %cl
257 rorl $4, %edx
258 movl des_SPtrans(%ebx),%ebp
259 movb %dl, %bl
260 xorl %ebp, %esi
261 movl 0x200+des_SPtrans(%ecx),%ebp
262 xorl %ebp, %esi
263 movb %dh, %cl
264 shrl $16, %eax
265 movl 0x100+des_SPtrans(%ebx),%ebp
266 xorl %ebp, %esi
267 movb %ah, %bl
268 shrl $16, %edx
269 movl 0x300+des_SPtrans(%ecx),%ebp
270 xorl %ebp, %esi
271 movl 28(%esp), %ebp
272 movb %dh, %cl
273 andl $0xff, %eax
274 andl $0xff, %edx
275 movl 0x600+des_SPtrans(%ebx),%ebx
276 xorl %ebx, %esi
277 movl 0x700+des_SPtrans(%ecx),%ebx
278 xorl %ebx, %esi
279 movl 0x400+des_SPtrans(%eax),%ebx
280 xorl %ebx, %esi
281 movl 0x500+des_SPtrans(%edx),%ebx
282 xorl %ebx, %esi
283
284 /* Round 4 */
285 movl 32(%esp), %eax
286 movl %esi, %edx
287 shrl $16, %edx
288 movl 36(%esp), %ecx
289 xorl %esi, %edx
290 andl %edx, %eax
291 andl %ecx, %edx
292 movl %eax, %ebx
293 sall $16, %ebx
294 movl %edx, %ecx
295 sall $16, %ecx
296 xorl %ebx, %eax
297 xorl %ecx, %edx
298 movl 32(%ebp), %ebx
299 xorl %ebx, %eax
300 movl 36(%ebp), %ecx
301 xorl %esi, %eax
302 xorl %esi, %edx
303 xorl %ecx, %edx
304 andl $0xfcfcfcfc, %eax
305 xorl %ebx, %ebx
306 andl $0xcfcfcfcf, %edx
307 xorl %ecx, %ecx
308 movb %al, %bl
309 movb %ah, %cl
310 rorl $4, %edx
311 movl des_SPtrans(%ebx),%ebp
312 movb %dl, %bl
313 xorl %ebp, %edi
314 movl 0x200+des_SPtrans(%ecx),%ebp
315 xorl %ebp, %edi
316 movb %dh, %cl
317 shrl $16, %eax
318 movl 0x100+des_SPtrans(%ebx),%ebp
319 xorl %ebp, %edi
320 movb %ah, %bl
321 shrl $16, %edx
322 movl 0x300+des_SPtrans(%ecx),%ebp
323 xorl %ebp, %edi
324 movl 28(%esp), %ebp
325 movb %dh, %cl
326 andl $0xff, %eax
327 andl $0xff, %edx
328 movl 0x600+des_SPtrans(%ebx),%ebx
329 xorl %ebx, %edi
330 movl 0x700+des_SPtrans(%ecx),%ebx
331 xorl %ebx, %edi
332 movl 0x400+des_SPtrans(%eax),%ebx
333 xorl %ebx, %edi
334 movl 0x500+des_SPtrans(%edx),%ebx
335 xorl %ebx, %edi
336
337 /* Round 5 */
338 movl 32(%esp), %eax
339 movl %edi, %edx
340 shrl $16, %edx
341 movl 36(%esp), %ecx
342 xorl %edi, %edx
343 andl %edx, %eax
344 andl %ecx, %edx
345 movl %eax, %ebx
346 sall $16, %ebx
347 movl %edx, %ecx
348 sall $16, %ecx
349 xorl %ebx, %eax
350 xorl %ecx, %edx
351 movl 40(%ebp), %ebx
352 xorl %ebx, %eax
353 movl 44(%ebp), %ecx
354 xorl %edi, %eax
355 xorl %edi, %edx
356 xorl %ecx, %edx
357 andl $0xfcfcfcfc, %eax
358 xorl %ebx, %ebx
359 andl $0xcfcfcfcf, %edx
360 xorl %ecx, %ecx
361 movb %al, %bl
362 movb %ah, %cl
363 rorl $4, %edx
364 movl des_SPtrans(%ebx),%ebp
365 movb %dl, %bl
366 xorl %ebp, %esi
367 movl 0x200+des_SPtrans(%ecx),%ebp
368 xorl %ebp, %esi
369 movb %dh, %cl
370 shrl $16, %eax
371 movl 0x100+des_SPtrans(%ebx),%ebp
372 xorl %ebp, %esi
373 movb %ah, %bl
374 shrl $16, %edx
375 movl 0x300+des_SPtrans(%ecx),%ebp
376 xorl %ebp, %esi
377 movl 28(%esp), %ebp
378 movb %dh, %cl
379 andl $0xff, %eax
380 andl $0xff, %edx
381 movl 0x600+des_SPtrans(%ebx),%ebx
382 xorl %ebx, %esi
383 movl 0x700+des_SPtrans(%ecx),%ebx
384 xorl %ebx, %esi
385 movl 0x400+des_SPtrans(%eax),%ebx
386 xorl %ebx, %esi
387 movl 0x500+des_SPtrans(%edx),%ebx
388 xorl %ebx, %esi
389
390 /* Round 6 */
391 movl 32(%esp), %eax
392 movl %esi, %edx
393 shrl $16, %edx
394 movl 36(%esp), %ecx
395 xorl %esi, %edx
396 andl %edx, %eax
397 andl %ecx, %edx
398 movl %eax, %ebx
399 sall $16, %ebx
400 movl %edx, %ecx
401 sall $16, %ecx
402 xorl %ebx, %eax
403 xorl %ecx, %edx
404 movl 48(%ebp), %ebx
405 xorl %ebx, %eax
406 movl 52(%ebp), %ecx
407 xorl %esi, %eax
408 xorl %esi, %edx
409 xorl %ecx, %edx
410 andl $0xfcfcfcfc, %eax
411 xorl %ebx, %ebx
412 andl $0xcfcfcfcf, %edx
413 xorl %ecx, %ecx
414 movb %al, %bl
415 movb %ah, %cl
416 rorl $4, %edx
417 movl des_SPtrans(%ebx),%ebp
418 movb %dl, %bl
419 xorl %ebp, %edi
420 movl 0x200+des_SPtrans(%ecx),%ebp
421 xorl %ebp, %edi
422 movb %dh, %cl
423 shrl $16, %eax
424 movl 0x100+des_SPtrans(%ebx),%ebp
425 xorl %ebp, %edi
426 movb %ah, %bl
427 shrl $16, %edx
428 movl 0x300+des_SPtrans(%ecx),%ebp
429 xorl %ebp, %edi
430 movl 28(%esp), %ebp
431 movb %dh, %cl
432 andl $0xff, %eax
433 andl $0xff, %edx
434 movl 0x600+des_SPtrans(%ebx),%ebx
435 xorl %ebx, %edi
436 movl 0x700+des_SPtrans(%ecx),%ebx
437 xorl %ebx, %edi
438 movl 0x400+des_SPtrans(%eax),%ebx
439 xorl %ebx, %edi
440 movl 0x500+des_SPtrans(%edx),%ebx
441 xorl %ebx, %edi
442
443 /* Round 7 */
444 movl 32(%esp), %eax
445 movl %edi, %edx
446 shrl $16, %edx
447 movl 36(%esp), %ecx
448 xorl %edi, %edx
449 andl %edx, %eax
450 andl %ecx, %edx
451 movl %eax, %ebx
452 sall $16, %ebx
453 movl %edx, %ecx
454 sall $16, %ecx
455 xorl %ebx, %eax
456 xorl %ecx, %edx
457 movl 56(%ebp), %ebx
458 xorl %ebx, %eax
459 movl 60(%ebp), %ecx
460 xorl %edi, %eax
461 xorl %edi, %edx
462 xorl %ecx, %edx
463 andl $0xfcfcfcfc, %eax
464 xorl %ebx, %ebx
465 andl $0xcfcfcfcf, %edx
466 xorl %ecx, %ecx
467 movb %al, %bl
468 movb %ah, %cl
469 rorl $4, %edx
470 movl des_SPtrans(%ebx),%ebp
471 movb %dl, %bl
472 xorl %ebp, %esi
473 movl 0x200+des_SPtrans(%ecx),%ebp
474 xorl %ebp, %esi
475 movb %dh, %cl
476 shrl $16, %eax
477 movl 0x100+des_SPtrans(%ebx),%ebp
478 xorl %ebp, %esi
479 movb %ah, %bl
480 shrl $16, %edx
481 movl 0x300+des_SPtrans(%ecx),%ebp
482 xorl %ebp, %esi
483 movl 28(%esp), %ebp
484 movb %dh, %cl
485 andl $0xff, %eax
486 andl $0xff, %edx
487 movl 0x600+des_SPtrans(%ebx),%ebx
488 xorl %ebx, %esi
489 movl 0x700+des_SPtrans(%ecx),%ebx
490 xorl %ebx, %esi
491 movl 0x400+des_SPtrans(%eax),%ebx
492 xorl %ebx, %esi
493 movl 0x500+des_SPtrans(%edx),%ebx
494 xorl %ebx, %esi
495
496 /* Round 8 */
497 movl 32(%esp), %eax
498 movl %esi, %edx
499 shrl $16, %edx
500 movl 36(%esp), %ecx
501 xorl %esi, %edx
502 andl %edx, %eax
503 andl %ecx, %edx
504 movl %eax, %ebx
505 sall $16, %ebx
506 movl %edx, %ecx
507 sall $16, %ecx
508 xorl %ebx, %eax
509 xorl %ecx, %edx
510 movl 64(%ebp), %ebx
511 xorl %ebx, %eax
512 movl 68(%ebp), %ecx
513 xorl %esi, %eax
514 xorl %esi, %edx
515 xorl %ecx, %edx
516 andl $0xfcfcfcfc, %eax
517 xorl %ebx, %ebx
518 andl $0xcfcfcfcf, %edx
519 xorl %ecx, %ecx
520 movb %al, %bl
521 movb %ah, %cl
522 rorl $4, %edx
523 movl des_SPtrans(%ebx),%ebp
524 movb %dl, %bl
525 xorl %ebp, %edi
526 movl 0x200+des_SPtrans(%ecx),%ebp
527 xorl %ebp, %edi
528 movb %dh, %cl
529 shrl $16, %eax
530 movl 0x100+des_SPtrans(%ebx),%ebp
531 xorl %ebp, %edi
532 movb %ah, %bl
533 shrl $16, %edx
534 movl 0x300+des_SPtrans(%ecx),%ebp
535 xorl %ebp, %edi
536 movl 28(%esp), %ebp
537 movb %dh, %cl
538 andl $0xff, %eax
539 andl $0xff, %edx
540 movl 0x600+des_SPtrans(%ebx),%ebx
541 xorl %ebx, %edi
542 movl 0x700+des_SPtrans(%ecx),%ebx
543 xorl %ebx, %edi
544 movl 0x400+des_SPtrans(%eax),%ebx
545 xorl %ebx, %edi
546 movl 0x500+des_SPtrans(%edx),%ebx
547 xorl %ebx, %edi
548
549 /* Round 9 */
550 movl 32(%esp), %eax
551 movl %edi, %edx
552 shrl $16, %edx
553 movl 36(%esp), %ecx
554 xorl %edi, %edx
555 andl %edx, %eax
556 andl %ecx, %edx
557 movl %eax, %ebx
558 sall $16, %ebx
559 movl %edx, %ecx
560 sall $16, %ecx
561 xorl %ebx, %eax
562 xorl %ecx, %edx
563 movl 72(%ebp), %ebx
564 xorl %ebx, %eax
565 movl 76(%ebp), %ecx
566 xorl %edi, %eax
567 xorl %edi, %edx
568 xorl %ecx, %edx
569 andl $0xfcfcfcfc, %eax
570 xorl %ebx, %ebx
571 andl $0xcfcfcfcf, %edx
572 xorl %ecx, %ecx
573 movb %al, %bl
574 movb %ah, %cl
575 rorl $4, %edx
576 movl des_SPtrans(%ebx),%ebp
577 movb %dl, %bl
578 xorl %ebp, %esi
579 movl 0x200+des_SPtrans(%ecx),%ebp
580 xorl %ebp, %esi
581 movb %dh, %cl
582 shrl $16, %eax
583 movl 0x100+des_SPtrans(%ebx),%ebp
584 xorl %ebp, %esi
585 movb %ah, %bl
586 shrl $16, %edx
587 movl 0x300+des_SPtrans(%ecx),%ebp
588 xorl %ebp, %esi
589 movl 28(%esp), %ebp
590 movb %dh, %cl
591 andl $0xff, %eax
592 andl $0xff, %edx
593 movl 0x600+des_SPtrans(%ebx),%ebx
594 xorl %ebx, %esi
595 movl 0x700+des_SPtrans(%ecx),%ebx
596 xorl %ebx, %esi
597 movl 0x400+des_SPtrans(%eax),%ebx
598 xorl %ebx, %esi
599 movl 0x500+des_SPtrans(%edx),%ebx
600 xorl %ebx, %esi
601
602 /* Round 10 */
603 movl 32(%esp), %eax
604 movl %esi, %edx
605 shrl $16, %edx
606 movl 36(%esp), %ecx
607 xorl %esi, %edx
608 andl %edx, %eax
609 andl %ecx, %edx
610 movl %eax, %ebx
611 sall $16, %ebx
612 movl %edx, %ecx
613 sall $16, %ecx
614 xorl %ebx, %eax
615 xorl %ecx, %edx
616 movl 80(%ebp), %ebx
617 xorl %ebx, %eax
618 movl 84(%ebp), %ecx
619 xorl %esi, %eax
620 xorl %esi, %edx
621 xorl %ecx, %edx
622 andl $0xfcfcfcfc, %eax
623 xorl %ebx, %ebx
624 andl $0xcfcfcfcf, %edx
625 xorl %ecx, %ecx
626 movb %al, %bl
627 movb %ah, %cl
628 rorl $4, %edx
629 movl des_SPtrans(%ebx),%ebp
630 movb %dl, %bl
631 xorl %ebp, %edi
632 movl 0x200+des_SPtrans(%ecx),%ebp
633 xorl %ebp, %edi
634 movb %dh, %cl
635 shrl $16, %eax
636 movl 0x100+des_SPtrans(%ebx),%ebp
637 xorl %ebp, %edi
638 movb %ah, %bl
639 shrl $16, %edx
640 movl 0x300+des_SPtrans(%ecx),%ebp
641 xorl %ebp, %edi
642 movl 28(%esp), %ebp
643 movb %dh, %cl
644 andl $0xff, %eax
645 andl $0xff, %edx
646 movl 0x600+des_SPtrans(%ebx),%ebx
647 xorl %ebx, %edi
648 movl 0x700+des_SPtrans(%ecx),%ebx
649 xorl %ebx, %edi
650 movl 0x400+des_SPtrans(%eax),%ebx
651 xorl %ebx, %edi
652 movl 0x500+des_SPtrans(%edx),%ebx
653 xorl %ebx, %edi
654
655 /* Round 11 */
656 movl 32(%esp), %eax
657 movl %edi, %edx
658 shrl $16, %edx
659 movl 36(%esp), %ecx
660 xorl %edi, %edx
661 andl %edx, %eax
662 andl %ecx, %edx
663 movl %eax, %ebx
664 sall $16, %ebx
665 movl %edx, %ecx
666 sall $16, %ecx
667 xorl %ebx, %eax
668 xorl %ecx, %edx
669 movl 88(%ebp), %ebx
670 xorl %ebx, %eax
671 movl 92(%ebp), %ecx
672 xorl %edi, %eax
673 xorl %edi, %edx
674 xorl %ecx, %edx
675 andl $0xfcfcfcfc, %eax
676 xorl %ebx, %ebx
677 andl $0xcfcfcfcf, %edx
678 xorl %ecx, %ecx
679 movb %al, %bl
680 movb %ah, %cl
681 rorl $4, %edx
682 movl des_SPtrans(%ebx),%ebp
683 movb %dl, %bl
684 xorl %ebp, %esi
685 movl 0x200+des_SPtrans(%ecx),%ebp
686 xorl %ebp, %esi
687 movb %dh, %cl
688 shrl $16, %eax
689 movl 0x100+des_SPtrans(%ebx),%ebp
690 xorl %ebp, %esi
691 movb %ah, %bl
692 shrl $16, %edx
693 movl 0x300+des_SPtrans(%ecx),%ebp
694 xorl %ebp, %esi
695 movl 28(%esp), %ebp
696 movb %dh, %cl
697 andl $0xff, %eax
698 andl $0xff, %edx
699 movl 0x600+des_SPtrans(%ebx),%ebx
700 xorl %ebx, %esi
701 movl 0x700+des_SPtrans(%ecx),%ebx
702 xorl %ebx, %esi
703 movl 0x400+des_SPtrans(%eax),%ebx
704 xorl %ebx, %esi
705 movl 0x500+des_SPtrans(%edx),%ebx
706 xorl %ebx, %esi
707
708 /* Round 12 */
709 movl 32(%esp), %eax
710 movl %esi, %edx
711 shrl $16, %edx
712 movl 36(%esp), %ecx
713 xorl %esi, %edx
714 andl %edx, %eax
715 andl %ecx, %edx
716 movl %eax, %ebx
717 sall $16, %ebx
718 movl %edx, %ecx
719 sall $16, %ecx
720 xorl %ebx, %eax
721 xorl %ecx, %edx
722 movl 96(%ebp), %ebx
723 xorl %ebx, %eax
724 movl 100(%ebp), %ecx
725 xorl %esi, %eax
726 xorl %esi, %edx
727 xorl %ecx, %edx
728 andl $0xfcfcfcfc, %eax
729 xorl %ebx, %ebx
730 andl $0xcfcfcfcf, %edx
731 xorl %ecx, %ecx
732 movb %al, %bl
733 movb %ah, %cl
734 rorl $4, %edx
735 movl des_SPtrans(%ebx),%ebp
736 movb %dl, %bl
737 xorl %ebp, %edi
738 movl 0x200+des_SPtrans(%ecx),%ebp
739 xorl %ebp, %edi
740 movb %dh, %cl
741 shrl $16, %eax
742 movl 0x100+des_SPtrans(%ebx),%ebp
743 xorl %ebp, %edi
744 movb %ah, %bl
745 shrl $16, %edx
746 movl 0x300+des_SPtrans(%ecx),%ebp
747 xorl %ebp, %edi
748 movl 28(%esp), %ebp
749 movb %dh, %cl
750 andl $0xff, %eax
751 andl $0xff, %edx
752 movl 0x600+des_SPtrans(%ebx),%ebx
753 xorl %ebx, %edi
754 movl 0x700+des_SPtrans(%ecx),%ebx
755 xorl %ebx, %edi
756 movl 0x400+des_SPtrans(%eax),%ebx
757 xorl %ebx, %edi
758 movl 0x500+des_SPtrans(%edx),%ebx
759 xorl %ebx, %edi
760
761 /* Round 13 */
762 movl 32(%esp), %eax
763 movl %edi, %edx
764 shrl $16, %edx
765 movl 36(%esp), %ecx
766 xorl %edi, %edx
767 andl %edx, %eax
768 andl %ecx, %edx
769 movl %eax, %ebx
770 sall $16, %ebx
771 movl %edx, %ecx
772 sall $16, %ecx
773 xorl %ebx, %eax
774 xorl %ecx, %edx
775 movl 104(%ebp), %ebx
776 xorl %ebx, %eax
777 movl 108(%ebp), %ecx
778 xorl %edi, %eax
779 xorl %edi, %edx
780 xorl %ecx, %edx
781 andl $0xfcfcfcfc, %eax
782 xorl %ebx, %ebx
783 andl $0xcfcfcfcf, %edx
784 xorl %ecx, %ecx
785 movb %al, %bl
786 movb %ah, %cl
787 rorl $4, %edx
788 movl des_SPtrans(%ebx),%ebp
789 movb %dl, %bl
790 xorl %ebp, %esi
791 movl 0x200+des_SPtrans(%ecx),%ebp
792 xorl %ebp, %esi
793 movb %dh, %cl
794 shrl $16, %eax
795 movl 0x100+des_SPtrans(%ebx),%ebp
796 xorl %ebp, %esi
797 movb %ah, %bl
798 shrl $16, %edx
799 movl 0x300+des_SPtrans(%ecx),%ebp
800 xorl %ebp, %esi
801 movl 28(%esp), %ebp
802 movb %dh, %cl
803 andl $0xff, %eax
804 andl $0xff, %edx
805 movl 0x600+des_SPtrans(%ebx),%ebx
806 xorl %ebx, %esi
807 movl 0x700+des_SPtrans(%ecx),%ebx
808 xorl %ebx, %esi
809 movl 0x400+des_SPtrans(%eax),%ebx
810 xorl %ebx, %esi
811 movl 0x500+des_SPtrans(%edx),%ebx
812 xorl %ebx, %esi
813
814 /* Round 14 */
815 movl 32(%esp), %eax
816 movl %esi, %edx
817 shrl $16, %edx
818 movl 36(%esp), %ecx
819 xorl %esi, %edx
820 andl %edx, %eax
821 andl %ecx, %edx
822 movl %eax, %ebx
823 sall $16, %ebx
824 movl %edx, %ecx
825 sall $16, %ecx
826 xorl %ebx, %eax
827 xorl %ecx, %edx
828 movl 112(%ebp), %ebx
829 xorl %ebx, %eax
830 movl 116(%ebp), %ecx
831 xorl %esi, %eax
832 xorl %esi, %edx
833 xorl %ecx, %edx
834 andl $0xfcfcfcfc, %eax
835 xorl %ebx, %ebx
836 andl $0xcfcfcfcf, %edx
837 xorl %ecx, %ecx
838 movb %al, %bl
839 movb %ah, %cl
840 rorl $4, %edx
841 movl des_SPtrans(%ebx),%ebp
842 movb %dl, %bl
843 xorl %ebp, %edi
844 movl 0x200+des_SPtrans(%ecx),%ebp
845 xorl %ebp, %edi
846 movb %dh, %cl
847 shrl $16, %eax
848 movl 0x100+des_SPtrans(%ebx),%ebp
849 xorl %ebp, %edi
850 movb %ah, %bl
851 shrl $16, %edx
852 movl 0x300+des_SPtrans(%ecx),%ebp
853 xorl %ebp, %edi
854 movl 28(%esp), %ebp
855 movb %dh, %cl
856 andl $0xff, %eax
857 andl $0xff, %edx
858 movl 0x600+des_SPtrans(%ebx),%ebx
859 xorl %ebx, %edi
860 movl 0x700+des_SPtrans(%ecx),%ebx
861 xorl %ebx, %edi
862 movl 0x400+des_SPtrans(%eax),%ebx
863 xorl %ebx, %edi
864 movl 0x500+des_SPtrans(%edx),%ebx
865 xorl %ebx, %edi
866
867 /* Round 15 */
868 movl 32(%esp), %eax
869 movl %edi, %edx
870 shrl $16, %edx
871 movl 36(%esp), %ecx
872 xorl %edi, %edx
873 andl %edx, %eax
874 andl %ecx, %edx
875 movl %eax, %ebx
876 sall $16, %ebx
877 movl %edx, %ecx
878 sall $16, %ecx
879 xorl %ebx, %eax
880 xorl %ecx, %edx
881 movl 120(%ebp), %ebx
882 xorl %ebx, %eax
883 movl 124(%ebp), %ecx
884 xorl %edi, %eax
885 xorl %edi, %edx
886 xorl %ecx, %edx
887 andl $0xfcfcfcfc, %eax
888 xorl %ebx, %ebx
889 andl $0xcfcfcfcf, %edx
890 xorl %ecx, %ecx
891 movb %al, %bl
892 movb %ah, %cl
893 rorl $4, %edx
894 movl des_SPtrans(%ebx),%ebp
895 movb %dl, %bl
896 xorl %ebp, %esi
897 movl 0x200+des_SPtrans(%ecx),%ebp
898 xorl %ebp, %esi
899 movb %dh, %cl
900 shrl $16, %eax
901 movl 0x100+des_SPtrans(%ebx),%ebp
902 xorl %ebp, %esi
903 movb %ah, %bl
904 shrl $16, %edx
905 movl 0x300+des_SPtrans(%ecx),%ebp
906 xorl %ebp, %esi
907 movl 28(%esp), %ebp
908 movb %dh, %cl
909 andl $0xff, %eax
910 andl $0xff, %edx
911 movl 0x600+des_SPtrans(%ebx),%ebx
912 xorl %ebx, %esi
913 movl 0x700+des_SPtrans(%ecx),%ebx
914 xorl %ebx, %esi
915 movl 0x400+des_SPtrans(%eax),%ebx
916 xorl %ebx, %esi
917 movl 0x500+des_SPtrans(%edx),%ebx
918 xorl %ebx, %esi
919 movl (%esp), %ebx
920 movl %edi, %eax
921 decl %ebx
922 movl %esi, %edi
923 movl %eax, %esi
924 movl %ebx, (%esp)
925 jnz .L000start
926
927 /* FP */
928 movl 24(%esp), %edx
929.byte 209
930.byte 207 /* rorl $1 %edi */
931 movl %esi, %eax
932 xorl %edi, %esi
933 andl $0xaaaaaaaa, %esi
934 xorl %esi, %eax
935 xorl %esi, %edi
936
937 roll $23, %eax
938 movl %eax, %esi
939 xorl %edi, %eax
940 andl $0x03fc03fc, %eax
941 xorl %eax, %esi
942 xorl %eax, %edi
943
944 roll $10, %esi
945 movl %esi, %eax
946 xorl %edi, %esi
947 andl $0x33333333, %esi
948 xorl %esi, %eax
949 xorl %esi, %edi
950
951 roll $18, %edi
952 movl %edi, %esi
953 xorl %eax, %edi
954 andl $0xfff0000f, %edi
955 xorl %edi, %esi
956 xorl %edi, %eax
957
958 roll $12, %esi
959 movl %esi, %edi
960 xorl %eax, %esi
961 andl $0xf0f0f0f0, %esi
962 xorl %esi, %edi
963 xorl %esi, %eax
964
965 rorl $4, %eax
966 movl %eax, (%edx)
967 movl %edi, 4(%edx)
968 popl %ecx
969 popl %edi
970 popl %esi
971 popl %ebx
972 popl %ebp
973 ret
974.fcrypt_body_end:
975 SIZE(fcrypt_body,.fcrypt_body_end-fcrypt_body)
976.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 @@
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61/* HAS BUGS? DON'T USE - this is only present for use in des.c */ 61/* HAS BUGS? DON'T USE - this is only present for use in des.c */
62void des_3cbc_encrypt(input, output, length, ks1, ks2, iv1, iv2, enc) 62void des_3cbc_encrypt(des_cblock *input, des_cblock *output, long length,
63des_cblock (*input); 63 des_key_schedule ks1, des_key_schedule ks2, des_cblock *iv1,
64des_cblock (*output); 64 des_cblock *iv2, int enc)
65long length;
66des_key_schedule ks1;
67des_key_schedule ks2;
68des_cblock (*iv1);
69des_cblock (*iv2);
70int enc;
71 { 65 {
72 int off=((int)length-1)/8; 66 int off=((int)length-1)/8;
73 long l8=((length+7)/8)*8; 67 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 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61DES_LONG des_cbc_cksum(input, output, length, schedule, ivec) 61DES_LONG des_cbc_cksum(const unsigned char *in, des_cblock *output,
62des_cblock (*input); 62 long length,
63des_cblock (*output); 63 des_key_schedule schedule, const_des_cblock *ivec)
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67 { 64 {
68 register DES_LONG tout0,tout1,tin0,tin1; 65 register DES_LONG tout0,tout1,tin0,tin1;
69 register long l=length; 66 register long l=length;
70 DES_LONG tin[2]; 67 DES_LONG tin[2];
71 unsigned char *in,*out,*iv; 68 unsigned char *out = &(*output)[0];
72 69 const unsigned char *iv = &(*ivec)[0];
73 in=(unsigned char *)input;
74 out=(unsigned char *)output;
75 iv=(unsigned char *)ivec;
76 70
77 c2l(iv,tout0); 71 c2l(iv,tout0);
78 c2l(iv,tout1); 72 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "des_locl.h" 59#define CBC_ENC_C__DONT_UPDATE_IV
60
61void des_cbc_encrypt(input, output, length, schedule, ivec, enc)
62des_cblock (*input);
63des_cblock (*output);
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67int enc;
68 {
69 register DES_LONG tin0,tin1;
70 register DES_LONG tout0,tout1,xor0,xor1;
71 register unsigned char *in,*out;
72 register long l=length;
73 DES_LONG tin[2];
74 unsigned char *iv;
75
76 in=(unsigned char *)input;
77 out=(unsigned char *)output;
78 iv=(unsigned char *)ivec;
79
80 if (enc)
81 {
82 c2l(iv,tout0);
83 c2l(iv,tout1);
84 for (l-=8; l>=0; l-=8)
85 {
86 c2l(in,tin0);
87 c2l(in,tin1);
88 tin0^=tout0; tin[0]=tin0;
89 tin1^=tout1; tin[1]=tin1;
90 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
91 tout0=tin[0]; l2c(tout0,out);
92 tout1=tin[1]; l2c(tout1,out);
93 }
94 if (l != -8)
95 {
96 c2ln(in,tin0,tin1,l+8);
97 tin0^=tout0; tin[0]=tin0;
98 tin1^=tout1; tin[1]=tin1;
99 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
100 tout0=tin[0]; l2c(tout0,out);
101 tout1=tin[1]; l2c(tout1,out);
102 }
103 }
104 else
105 {
106 c2l(iv,xor0);
107 c2l(iv,xor1);
108 for (l-=8; l>=0; l-=8)
109 {
110 c2l(in,tin0); tin[0]=tin0;
111 c2l(in,tin1); tin[1]=tin1;
112 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
113 tout0=tin[0]^xor0;
114 tout1=tin[1]^xor1;
115 l2c(tout0,out);
116 l2c(tout1,out);
117 xor0=tin0;
118 xor1=tin1;
119 }
120 if (l != -8)
121 {
122 c2l(in,tin0); tin[0]=tin0;
123 c2l(in,tin1); tin[1]=tin1;
124 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
125 tout0=tin[0]^xor0;
126 tout1=tin[1]^xor1;
127 l2cn(tout0,tout1,out,l+8);
128 /* xor0=tin0;
129 xor1=tin1; */
130 }
131 }
132 tin0=tin1=tout0=tout1=xor0=xor1=0;
133 tin[0]=tin[1]=0;
134 }
135 60
61#include "ncbc_enc.c" /* des_cbc_encrypt */
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c
index 80b8a9eaaa..5362a551bf 100644
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ b/src/lib/libcrypto/des/cfb64ede.c
@@ -63,14 +63,9 @@
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65 65
66void des_ede3_cfb64_encrypt(in, out, length, ks1,ks2,ks3, ivec, num, enc) 66void des_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
67unsigned char *in; 67 long length, des_key_schedule ks1, des_key_schedule ks2,
68unsigned char *out; 68 des_key_schedule ks3, des_cblock *ivec, int *num, int enc)
69long length;
70des_key_schedule ks1,ks2,ks3;
71des_cblock (*ivec);
72int *num;
73int enc;
74 { 69 {
75 register DES_LONG v0,v1; 70 register DES_LONG v0,v1;
76 register long l=length; 71 register long l=length;
@@ -78,7 +73,7 @@ int enc;
78 DES_LONG ti[2]; 73 DES_LONG ti[2];
79 unsigned char *iv,c,cc; 74 unsigned char *iv,c,cc;
80 75
81 iv=(unsigned char *)ivec; 76 iv=&(*ivec)[0];
82 if (enc) 77 if (enc)
83 { 78 {
84 while (l--) 79 while (l--)
@@ -90,14 +85,14 @@ int enc;
90 85
91 ti[0]=v0; 86 ti[0]=v0;
92 ti[1]=v1; 87 ti[1]=v1;
93 des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); 88 des_encrypt3(ti,ks1,ks2,ks3);
94 v0=ti[0]; 89 v0=ti[0];
95 v1=ti[1]; 90 v1=ti[1];
96 91
97 iv=(unsigned char *)ivec; 92 iv = &(*ivec)[0];
98 l2c(v0,iv); 93 l2c(v0,iv);
99 l2c(v1,iv); 94 l2c(v1,iv);
100 iv=(unsigned char *)ivec; 95 iv = &(*ivec)[0];
101 } 96 }
102 c= *(in++)^iv[n]; 97 c= *(in++)^iv[n];
103 *(out++)=c; 98 *(out++)=c;
@@ -116,14 +111,14 @@ int enc;
116 111
117 ti[0]=v0; 112 ti[0]=v0;
118 ti[1]=v1; 113 ti[1]=v1;
119 des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); 114 des_encrypt3(ti,ks1,ks2,ks3);
120 v0=ti[0]; 115 v0=ti[0];
121 v1=ti[1]; 116 v1=ti[1];
122 117
123 iv=(unsigned char *)ivec; 118 iv = &(*ivec)[0];
124 l2c(v0,iv); 119 l2c(v0,iv);
125 l2c(v1,iv); 120 l2c(v1,iv);
126 iv=(unsigned char *)ivec; 121 iv = &(*ivec)[0];
127 } 122 }
128 cc= *(in++); 123 cc= *(in++);
129 c=iv[n]; 124 c=iv[n];
@@ -137,14 +132,9 @@ int enc;
137 } 132 }
138 133
139#ifdef undef /* MACRO */ 134#ifdef undef /* MACRO */
140void des_ede2_cfb64_encrypt(in, out, length, ks1,ks2, ivec, num, enc) 135void des_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
141unsigned char *in; 136 des_key_schedule ks1, des_key_schedule ks2, des_cblock (*ivec),
142unsigned char *out; 137 int *num, int enc)
143long length;
144des_key_schedule ks1,ks2;
145des_cblock (*ivec);
146int *num;
147int enc;
148 { 138 {
149 des_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc); 139 des_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
150 } 140 }
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 @@
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65 65
66void des_cfb64_encrypt(in, out, length, schedule, ivec, num, enc) 66void des_cfb64_encrypt(const unsigned char *in, unsigned char *out,
67unsigned char *in; 67 long length, des_key_schedule schedule, des_cblock *ivec,
68unsigned char *out; 68 int *num, int enc)
69long length;
70des_key_schedule schedule;
71des_cblock (*ivec);
72int *num;
73int enc;
74 { 69 {
75 register DES_LONG v0,v1; 70 register DES_LONG v0,v1;
76 register long l=length; 71 register long l=length;
@@ -78,7 +73,7 @@ int enc;
78 DES_LONG ti[2]; 73 DES_LONG ti[2];
79 unsigned char *iv,c,cc; 74 unsigned char *iv,c,cc;
80 75
81 iv=(unsigned char *)ivec; 76 iv = &(*ivec)[0];
82 if (enc) 77 if (enc)
83 { 78 {
84 while (l--) 79 while (l--)
@@ -87,12 +82,11 @@ int enc;
87 { 82 {
88 c2l(iv,v0); ti[0]=v0; 83 c2l(iv,v0); ti[0]=v0;
89 c2l(iv,v1); ti[1]=v1; 84 c2l(iv,v1); ti[1]=v1;
90 des_encrypt((DES_LONG *)ti, 85 des_encrypt(ti,schedule,DES_ENCRYPT);
91 schedule,DES_ENCRYPT); 86 iv = &(*ivec)[0];
92 iv=(unsigned char *)ivec;
93 v0=ti[0]; l2c(v0,iv); 87 v0=ti[0]; l2c(v0,iv);
94 v0=ti[1]; l2c(v0,iv); 88 v0=ti[1]; l2c(v0,iv);
95 iv=(unsigned char *)ivec; 89 iv = &(*ivec)[0];
96 } 90 }
97 c= *(in++)^iv[n]; 91 c= *(in++)^iv[n];
98 *(out++)=c; 92 *(out++)=c;
@@ -108,12 +102,11 @@ int enc;
108 { 102 {
109 c2l(iv,v0); ti[0]=v0; 103 c2l(iv,v0); ti[0]=v0;
110 c2l(iv,v1); ti[1]=v1; 104 c2l(iv,v1); ti[1]=v1;
111 des_encrypt((DES_LONG *)ti, 105 des_encrypt(ti,schedule,DES_ENCRYPT);
112 schedule,DES_ENCRYPT); 106 iv = &(*ivec)[0];
113 iv=(unsigned char *)ivec;
114 v0=ti[0]; l2c(v0,iv); 107 v0=ti[0]; l2c(v0,iv);
115 v0=ti[1]; l2c(v0,iv); 108 v0=ti[1]; l2c(v0,iv);
116 iv=(unsigned char *)ivec; 109 iv = &(*ivec)[0];
117 } 110 }
118 cc= *(in++); 111 cc= *(in++);
119 c=iv[n]; 112 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 @@
64 * the second. The second 12 bits will come from the 3rd and half the 4th 64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte. 65 * byte.
66 */ 66 */
67void des_cfb_encrypt(in, out, numbits, length, schedule, ivec, enc) 67void des_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
68unsigned char *in; 68 long length, des_key_schedule schedule, des_cblock *ivec, int enc)
69unsigned char *out;
70int numbits;
71long length;
72des_key_schedule schedule;
73des_cblock (*ivec);
74int enc;
75 { 69 {
76 register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8; 70 register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8;
77 register DES_LONG mask0,mask1; 71 register DES_LONG mask0,mask1;
@@ -96,7 +90,7 @@ int enc;
96 mask1=0x00000000L; 90 mask1=0x00000000L;
97 } 91 }
98 92
99 iv=(unsigned char *)ivec; 93 iv = &(*ivec)[0];
100 c2l(iv,v0); 94 c2l(iv,v0);
101 c2l(iv,v1); 95 c2l(iv,v1);
102 if (enc) 96 if (enc)
@@ -163,7 +157,7 @@ int enc;
163 out+=n; 157 out+=n;
164 } 158 }
165 } 159 }
166 iv=(unsigned char *)ivec; 160 iv = &(*ivec)[0];
167 l2c(v0,iv); 161 l2c(v0,iv);
168 l2c(v1,iv); 162 l2c(v1,iv);
169 v0=v1=d0=d1=ti[0]=ti[1]=0; 163 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 @@
1$!
2$! DES-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates the
11$! "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" library. The "xxx" denotes the machine
12$! architecture of AXP or VAX.
13$!
14$! It was re-written to try to determine which "C" compiler to try to use
15$! or the user can specify a compiler in P3.
16$!
17$! Specify one of the following to build just that part, specify "ALL" to
18$! just build everything.
19$!
20$! ALL To Just Build "Everything".
21$! LIBRARY To Just Build The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library.
22$! DESTEST To Just Build The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program.
23$! SPEED To Just Build The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program.
24$! RPW To Just Build The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program.
25$! DES To Just Build The [.xxx.EXE.CRYPTO.DES]DES.EXE Program.
26$! DES_OPTS To Just Build The [.xxx.EXE.CRYPTO.DES]DES_OPTS.EXE Program.
27$!
28$! Specify either DEBUG or NODEBUG as P2 to compile with or without
29$! debugging information.
30$!
31$! Specify which compiler at P3 to try to compile under.
32$!
33$! VAXC For VAX C.
34$! DECC For DEC C.
35$! GNUC For GNU C.
36$!
37$! If you don't speficy a compiler, it will try to determine which
38$! "C" compiler to try to use.
39$!
40$! P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
41$!
42$!
43$! Make sure we know what architecture we run on.
44$!
45$!
46$! Check Which Architecture We Are Using.
47$!
48$ IF (F$GETSYI("CPU").GE.128)
49$ THEN
50$!
51$! The Architecture Is AXP.
52$!
53$ ARCH := AXP
54$!
55$! Else...
56$!
57$ ELSE
58$!
59$! The Architecture Is VAX.
60$!
61$ ARCH := VAX
62$!
63$! End The Architecture Check.
64$!
65$ ENDIF
66$!
67$! Check To Make Sure We Have Valid Command Line Parameters.
68$!
69$ GOSUB CHECK_OPTIONS
70$!
71$! Tell The User What Kind of Machine We Run On.
72$!
73$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
74$!
75$! Define The OBJ Directory Name.
76$!
77$ OBJ_DIR := SYS$DISK:[--.'ARCH'.OBJ.CRYPTO.DES]
78$!
79$! Check To See If The Architecture Specific OBJ Directory Exists.
80$!
81$ IF (F$PARSE(OBJ_DIR).EQS."")
82$ THEN
83$!
84$! It Dosen't Exist, So Create It.
85$!
86$ CREATE/DIR 'OBJ_DIR'
87$!
88$! End The Architecture Specific OBJ Directory Check.
89$!
90$ ENDIF
91$!
92$! Define The EXE Directory Name.
93$!
94$ EXE_DIR :== SYS$DISK:[--.'ARCH'.EXE.CRYPTO.DES]
95$!
96$! Check To See If The Architecture Specific Directory Exists.
97$!
98$ IF (F$PARSE(EXE_DIR).EQS."")
99$ THEN
100$!
101$! It Dosen't Exist, So Create It.
102$!
103$ CREATE/DIR 'EXE_DIR'
104$!
105$! End The Architecture Specific Directory Check.
106$!
107$ ENDIF
108$!
109$! Define The Library Name.
110$!
111$ LIB_NAME := 'EXE_DIR'LIBDES.OLB
112$!
113$! Check To See What We Are To Do.
114$!
115$ IF (BUILDALL.EQS."TRUE")
116$ THEN
117$!
118$! Since Nothing Special Was Specified, Do Everything.
119$!
120$ GOSUB LIBRARY
121$ GOSUB DESTEST
122$ GOSUB SPEED
123$ GOSUB RPW
124$ GOSUB DES
125$ GOSUB DES_OPTS
126$!
127$! Else...
128$!
129$ ELSE
130$!
131$! Build Just What The User Wants Us To Build.
132$!
133$ GOSUB 'BUILDALL'
134$!
135$! End The BUILDALL Check.
136$!
137$ ENDIF
138$!
139$! Time To EXIT.
140$!
141$ EXIT
142$ LIBRARY:
143$!
144$! Tell The User That We Are Compiling.
145$!
146$ WRITE SYS$OUTPUT "Compiling The ",LIB_NAME," Files."
147$!
148$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" Library...
149$!
150$ IF (F$SEARCH(LIB_NAME).EQS."")
151$ THEN
152$!
153$! Guess Not, Create The Library.
154$!
155$ LIBRARY/CREATE/OBJECT 'LIB_NAME'
156$!
157$! End The Library Exist Check.
158$!
159$ ENDIF
160$!
161$! Define The DES Library Files.
162$!
163$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
164 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
165 "enc_read,enc_writ,ofb64enc,"+ -
166 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
167 "des_enc,fcrypt_b,read2pwd,"+ -
168 "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp"
169$!
170$! Define A File Counter And Set It To "0".
171$!
172$ FILE_COUNTER = 0
173$!
174$! Top Of The File Loop.
175$!
176$ NEXT_FILE:
177$!
178$! O.K, Extract The File Name From The File List.
179$!
180$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",LIB_DES)
181$!
182$! Check To See If We Are At The End Of The File List.
183$!
184$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE
185$!
186$! Increment The Counter.
187$!
188$ FILE_COUNTER = FILE_COUNTER + 1
189$!
190$! Create The Source File Name.
191$!
192$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C"
193$!
194$! Tell The User We Are Compiling The Source File.
195$!
196$ WRITE SYS$OUTPUT " ",FILE_NAME,".C"
197$!
198$! Create The Object File Name.
199$!
200$ OBJECT_FILE = OBJ_DIR + FILE_NAME + "." + ARCH + "OBJ"
201$ ON WARNING THEN GOTO NEXT_FILE
202$!
203$! Check To See If The File We Want To Compile Actually Exists.
204$!
205$ IF (F$SEARCH(SOURCE_FILE).EQS."")
206$ THEN
207$!
208$! Tell The User That The File Dosen't Exist.
209$!
210$ WRITE SYS$OUTPUT ""
211$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
212$ WRITE SYS$OUTPUT ""
213$!
214$! Exit The Build.
215$!
216$ EXIT
217$!
218$! End The File Exists Check.
219$!
220$ ENDIF
221$!
222$! Compile The File.
223$!
224$ ON ERROR THEN GOTO NEXT_FILE
225$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
226$!
227$! Add It To The Library.
228$!
229$ LIBRARY/REPLACE/OBJECT 'LIB_NAME' 'OBJECT_FILE'
230$!
231$! Time To Clean Up The Object File.
232$!
233$ DELETE 'OBJECT_FILE';*
234$!
235$! Go Back And Do It Again.
236$!
237$ GOTO NEXT_FILE
238$!
239$! All Done With This Library Part.
240$!
241$ FILE_DONE:
242$!
243$! Tell The User That We Are All Done.
244$!
245$ WRITE SYS$OUTPUT "Library ",LIB_NAME," Built."
246$!
247$! All Done, Time To Return.
248$!
249$ RETURN
250$!
251$! Compile The DESTEST Program.
252$!
253$ DESTEST:
254$!
255$! Check To See If We Have The Proper Libraries.
256$!
257$ GOSUB LIB_CHECK
258$!
259$! Check To See If We Have A Linker Option File.
260$!
261$ GOSUB CHECK_OPT_FILE
262$!
263$! Check To See If The File We Want To Compile Actually Exists.
264$!
265$ IF (F$SEARCH("SYS$DISK:[]DESTEST.C").EQS."")
266$ THEN
267$!
268$! Tell The User That The File Dosen't Exist.
269$!
270$ WRITE SYS$OUTPUT ""
271$ WRITE SYS$OUTPUT "The File DESTEST.C Dosen't Exist."
272$ WRITE SYS$OUTPUT ""
273$!
274$! Exit The Build.
275$!
276$ EXIT
277$!
278$! End The DESTEST.C File Check.
279$!
280$ ENDIF
281$!
282$! Tell The User What We Are Building.
283$!
284$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DESTEST.EXE"
285$!
286$! Compile The DESTEST Program.
287$!
288$ CC/OBJECT='OBJ_DIR'DESTEST.OBJ SYS$DISK:[]DESTEST.C
289$!
290$! Link The DESTEST Program.
291$!
292$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DESTEST.EXE -
293 'OBJ_DIR'DESTEST.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
294$!
295$! All Done, Time To Return.
296$!
297$ RETURN
298$!
299$! Compile The SPEED Program.
300$!
301$ SPEED:
302$!
303$! Check To See If We Have The Proper Libraries.
304$!
305$ GOSUB LIB_CHECK
306$!
307$! Check To See If We Have A Linker Option File.
308$!
309$ GOSUB CHECK_OPT_FILE
310$!
311$! Check To See If The File We Want To Compile Actually Exists.
312$!
313$ IF (F$SEARCH("SYS$DISK:[]SPEED.C").EQS."")
314$ THEN
315$!
316$! Tell The User That The File Dosen't Exist.
317$!
318$ WRITE SYS$OUTPUT ""
319$ WRITE SYS$OUTPUT "The File SPEED.C Dosen't Exist."
320$ WRITE SYS$OUTPUT ""
321$!
322$! Exit The Build.
323$!
324$ EXIT
325$!
326$! End The SPEED.C File Check.
327$!
328$ ENDIF
329$!
330$! Tell The User What We Are Building.
331$!
332$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"SPEED.EXE"
333$!
334$! Compile The SPEED Program.
335$!
336$ CC/OBJECT='OBJ_DIR'SPEED.OBJ SYS$DISK:[]SPEED.C
337$!
338$! Link The SPEED Program.
339$!
340$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'SPEED.EXE -
341 'OBJ_DIR'SPEED.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
342$!
343$! All Done, Time To Return.
344$!
345$ RETURN
346$!
347$! Compile The RPW Program.
348$!
349$ RPW:
350$!
351$! Check To See If We Have The Proper Libraries.
352$!
353$ GOSUB LIB_CHECK
354$!
355$! Check To See If We Have A Linker Option File.
356$!
357$ GOSUB CHECK_OPT_FILE
358$!
359$! Check To See If The File We Want To Compile Actually Exists.
360$!
361$ IF (F$SEARCH("SYS$DISK:[]RPW.C").EQS."")
362$ THEN
363$!
364$! Tell The User That The File Dosen't Exist.
365$!
366$ WRITE SYS$OUTPUT ""
367$ WRITE SYS$OUTPUT "The File RPW.C Dosen't Exist."
368$ WRITE SYS$OUTPUT ""
369$!
370$! Exit The Build.
371$!
372$ EXIT
373$!
374$! End The RPW.C File Check.
375$!
376$ ENDIF
377$!
378$! Tell The User What We Are Building.
379$!
380$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"RPW.EXE"
381$!
382$! Compile The RPW Program.
383$!
384$ CC/OBJECT='OBJ_DIR'RPW.OBJ SYS$DISK:[]RPW.C
385$!
386$! Link The RPW Program.
387$!
388$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'RPW.EXE -
389 'OBJ_DIR'RPW.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
390$!
391$! All Done, Time To Return.
392$!
393$ RETURN
394$!
395$! Compile The DES Program.
396$!
397$ DES:
398$!
399$! Check To See If We Have The Proper Libraries.
400$!
401$ GOSUB LIB_CHECK
402$!
403$! Check To See If We Have A Linker Option File.
404$!
405$ GOSUB CHECK_OPT_FILE
406$!
407$! Check To See If The File We Want To Compile Actually Exists.
408$!
409$ IF (F$SEARCH("SYS$DISK:[]DES.C").EQS."")
410$ THEN
411$!
412$! Tell The User That The File Dosen't Exist.
413$!
414$ WRITE SYS$OUTPUT ""
415$ WRITE SYS$OUTPUT "The File DES.C Dosen't Exist."
416$ WRITE SYS$OUTPUT ""
417$!
418$! Exit The Build.
419$!
420$ EXIT
421$!
422$! End The DES.C File Check.
423$!
424$ ENDIF
425$!
426$! Tell The User What We Are Building.
427$!
428$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES.EXE"
429$!
430$! Compile The DES Program.
431$!
432$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]DES.C
433$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]CBC3_ENC.C
434$!
435$! Link The DES Program.
436$!
437$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES.EXE -
438 'OBJ_DIR'DES.OBJ,'OBJ_DIR'CBC3_ENC.OBJ,-
439 'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
440$!
441$! All Done, Time To Return.
442$!
443$ RETURN
444$!
445$! Compile The DES_OPTS Program.
446$!
447$ DES_OPTS:
448$!
449$! Check To See If We Have The Proper Libraries.
450$!
451$ GOSUB LIB_CHECK
452$!
453$! Check To See If We Have A Linker Option File.
454$!
455$ GOSUB CHECK_OPT_FILE
456$!
457$! Check To See If The File We Want To Compile Actually Exists.
458$!
459$ IF (F$SEARCH("SYS$DISK:[]DES_OPTS.C").EQS."")
460$ THEN
461$!
462$! Tell The User That The File Dosen't Exist.
463$!
464$ WRITE SYS$OUTPUT ""
465$ WRITE SYS$OUTPUT "The File DES_OPTS.C Dosen't Exist."
466$ WRITE SYS$OUTPUT ""
467$!
468$! Exit The Build.
469$!
470$ EXIT
471$!
472$! End The DES_OPTS.C File Check.
473$!
474$ ENDIF
475$!
476$! Tell The User What We Are Building.
477$!
478$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES_OPTS.EXE"
479$!
480$! Compile The DES_OPTS Program.
481$!
482$ CC/OBJECT='OBJ_DIR'DES_OPTS.OBJ SYS$DISK:[]DES_OPTS.C
483$!
484$! Link The DES_OPTS Program.
485$!
486$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES_OPTS.EXE -
487 'OBJ_DIR'DES_OPTS.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
488$!
489$! All Done, Time To Return.
490$!
491$ RETURN
492$ EXIT
493$!
494$! Check For The Link Option FIle.
495$!
496$ CHECK_OPT_FILE:
497$!
498$! Check To See If We Need To Make A VAX C Option File.
499$!
500$ IF (COMPILER.EQS."VAXC")
501$ THEN
502$!
503$! Check To See If We Already Have A VAX C Linker Option File.
504$!
505$ IF (F$SEARCH(OPT_FILE).EQS."")
506$ THEN
507$!
508$! We Need A VAX C Linker Option File.
509$!
510$ CREATE 'OPT_FILE'
511$DECK
512!
513! Default System Options File To Link Agianst
514! The Sharable VAX C Runtime Library.
515!
516SYS$SHARE:VAXCRTL.EXE/SHARE
517$EOD
518$!
519$! End The Option File Check.
520$!
521$ ENDIF
522$!
523$! End The VAXC Check.
524$!
525$ ENDIF
526$!
527$! Check To See If We Need A GNU C Option File.
528$!
529$ IF (COMPILER.EQS."GNUC")
530$ THEN
531$!
532$! Check To See If We Already Have A GNU C Linker Option File.
533$!
534$ IF (F$SEARCH(OPT_FILE).EQS."")
535$ THEN
536$!
537$! We Need A GNU C Linker Option File.
538$!
539$ CREATE 'OPT_FILE'
540$DECK
541!
542! Default System Options File To Link Agianst
543! The Sharable C Runtime Library.
544!
545GNU_CC:[000000]GCCLIB/LIBRARY
546SYS$SHARE:VAXCRTL/SHARE
547$EOD
548$!
549$! End The Option File Check.
550$!
551$ ENDIF
552$!
553$! End The GNU C Check.
554$!
555$ ENDIF
556$!
557$! Check To See If We Need A DEC C Option File.
558$!
559$ IF (COMPILER.EQS."DECC")
560$ THEN
561$!
562$! Check To See If We Already Have A DEC C Linker Option File.
563$!
564$ IF (F$SEARCH(OPT_FILE).EQS."")
565$ THEN
566$!
567$! Figure Out If We Need An AXP Or A VAX Linker Option File.
568$!
569$ IF (F$GETSYI("CPU").LT.128)
570$ THEN
571$!
572$! We Need A DEC C Linker Option File For VAX.
573$!
574$ CREATE 'OPT_FILE'
575$DECK
576!
577! Default System Options File To Link Agianst
578! The Sharable DEC C Runtime Library.
579!
580SYS$SHARE:DECC$SHR.EXE/SHARE
581$EOD
582$!
583$! Else...
584$!
585$ ELSE
586$!
587$! Create The AXP Linker Option File.
588$!
589$ CREATE 'OPT_FILE'
590$DECK
591!
592! Default System Options File For AXP To Link Agianst
593! The Sharable C Runtime Library.
594!
595SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
596SYS$SHARE:CMA$OPEN_RTL/SHARE
597$EOD
598$!
599$! End The VAX/AXP DEC C Option File Check.
600$!
601$ ENDIF
602$!
603$! End The Option File Search.
604$!
605$ ENDIF
606$!
607$! End The DEC C Check.
608$!
609$ ENDIF
610$!
611$! Tell The User What Linker Option File We Are Using.
612$!
613$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
614$!
615$! Time To RETURN.
616$!
617$ RETURN
618$!
619$! Library Check.
620$!
621$ LIB_CHECK:
622$!
623$! Look For The Library LIBDES.OLB.
624$!
625$ IF (F$SEARCH(LIB_NAME).EQS."")
626$ THEN
627$!
628$! Tell The User We Can't Find The [.xxx.CRYPTO.DES]LIBDES.OLB Library.
629$!
630$ WRITE SYS$OUTPUT ""
631$ WRITE SYS$OUTPUT "Can't Find The Library ",LIB_NAME,"."
632$ WRITE SYS$OUTPUT "We Can't Link Without It."
633$ WRITE SYS$OUTPUT ""
634$!
635$! Since We Can't Link Without It, Exit.
636$!
637$ EXIT
638$ ENDIF
639$!
640$! Time To Return.
641$!
642$ RETURN
643$!
644$! Check The User's Options.
645$!
646$ CHECK_OPTIONS:
647$!
648$! Check To See If We Are To "Just Build Everything".
649$!
650$ IF (P1.EQS."ALL")
651$ THEN
652$!
653$! P1 Is "ALL", So Build Everything.
654$!
655$ BUILDALL = "TRUE"
656$!
657$! Else...
658$!
659$ ELSE
660$!
661$! Else, Check To See If P1 Has A Valid Arguement.
662$!
663$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."DESTEST").OR.(P1.EQS."SPEED") -
664 .OR.(P1.EQS."RPW").OR.(P1.EQS."DES").OR.(P1.EQS."DES_OPTS")
665$ THEN
666$!
667$! A Valid Arguement.
668$!
669$ BUILDALL = P1
670$!
671$! Else...
672$!
673$ ELSE
674$!
675$! Tell The User We Don't Know What They Want.
676$!
677$ WRITE SYS$OUTPUT ""
678$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
679$ WRITE SYS$OUTPUT ""
680$ WRITE SYS$OUTPUT " ALL : Just Build Everything.
681$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library."
682$ WRITE SYS$OUTPUT " DESTEST : To Compile Just The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program."
683$ WRITE SYS$OUTPUT " SPEED : To Compile Just The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program."
684$ WRITE SYS$OUTPUT " RPW : To Compile Just The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program."
685$ WRITE SYS$OUTPUT " DES : To Compile Just The [.xxx.EXE.CRYPTO.DES]DES.EXE Program."
686$ WRITE SYS$OUTPUT " DES_OPTS : To Compile Just The [.xxx.EXE.CRYTPO.DES]DES_OPTS.EXE Program."
687$ WRITE SYS$OUTPUT ""
688$ WRITE SYS$OUTPUT " Where 'xxx' Stands For: "
689$ WRITE SYS$OUTPUT ""
690$ WRITE SYS$OUTPUT " AXP : Alpha Architecture."
691$ WRITE SYS$OUTPUT " VAX : VAX Architecture."
692$ WRITE SYS$OUTPUT ""
693$!
694$! Time To EXIT.
695$!
696$ EXIT
697$!
698$! End The Valid Arguement Check.
699$!
700$ ENDIF
701$!
702$! End The P1 Check.
703$!
704$ ENDIF
705$!
706$! Check To See If We Are To Compile Without Debugger Information.
707$!
708$ IF (P2.EQS."NODEBUG")
709$ THEN
710$!
711$! P2 Is Blank, So Compile Without Debugger Information.
712$!
713$ DEBUGGER = "NODEBUG"
714$ TRACEBACK = "NOTRACEBACK"
715$ GCC_OPTIMIZE = "OPTIMIZE"
716$ CC_OPTIMIZE = "OPTIMIZE"
717$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
718$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
719$!
720$! Else...
721$!
722$ ELSE
723$!
724$! Check To See If We Are To Compile With Debugger Information.
725$!
726$ IF (P2.EQS."DEBUG")
727$ THEN
728$!
729$! Compile With Debugger Information.
730$!
731$ DEBUGGER = "DEBUG"
732$ TRACEBACK = "TRACEBACK"
733$ GCC_OPTIMIZE = "NOOPTIMIZE"
734$ CC_OPTIMIZE = "NOOPTIMIZE"
735$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
736$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
737$!
738$! Else...
739$!
740$ ELSE
741$!
742$! Tell The User Entered An Invalid Option..
743$!
744$ WRITE SYS$OUTPUT ""
745$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
746$ WRITE SYS$OUTPUT ""
747$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
748$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
749$ WRITE SYS$OUTPUT ""
750$!
751$! Time To EXIT.
752$!
753$ EXIT
754$!
755$! End The Valid Arguement Check.
756$!
757$ ENDIF
758$!
759$! End The P2 Check.
760$!
761$ ENDIF
762$!
763$! Special Threads For OpenVMS v7.1 Or Later.
764$!
765$! Written By: Richard Levitte
766$! richard@levitte.org
767$!
768$!
769$! Check To See If We Have A Option For P4.
770$!
771$ IF (P4.EQS."")
772$ THEN
773$!
774$! Get The Version Of VMS We Are Using.
775$!
776$ ISSEVEN := ""
777$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
778$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
779$!
780$! Check To See If The VMS Version Is v7.1 Or Later.
781$!
782$ IF (TMP.GE.71)
783$ THEN
784$!
785$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
786$!
787$ ISSEVEN := ,PTHREAD_USE_D4
788$!
789$! End The VMS Version Check.
790$!
791$ ENDIF
792$!
793$! End The P4 Check.
794$!
795$ ENDIF
796$!
797$! Check To See If P3 Is Blank.
798$!
799$ IF (P3.EQS."")
800$ THEN
801$!
802$! O.K., The User Didn't Specify A Compiler, Let's Try To
803$! Find Out Which One To Use.
804$!
805$! Check To See If We Have GNU C.
806$!
807$ IF (F$TRNLNM("GNU_CC").NES."")
808$ THEN
809$!
810$! Looks Like GNUC, Set To Use GNUC.
811$!
812$ P3 = "GNUC"
813$!
814$! Else...
815$!
816$ ELSE
817$!
818$! Check To See If We Have VAXC Or DECC.
819$!
820$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
821$ THEN
822$!
823$! Looks Like DECC, Set To Use DECC.
824$!
825$ P3 = "DECC"
826$!
827$! Else...
828$!
829$ ELSE
830$!
831$! Looks Like VAXC, Set To Use VAXC.
832$!
833$ P3 = "VAXC"
834$!
835$! End The VAXC Compiler Check.
836$!
837$ ENDIF
838$!
839$! End The DECC & VAXC Compiler Check.
840$!
841$ ENDIF
842$!
843$! End The Compiler Check.
844$!
845$ ENDIF
846$!
847$! Set Up Initial CC Definitions, Possibly With User Ones
848$!
849$ CCDEFS = "VMS=1"
850$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
851$ CCEXTRAFLAGS = ""
852$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
853$ CCDISABLEWARNINGS = ""
854$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
855 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
856$!
857$! Check To See If The User Entered A Valid Paramter.
858$!
859$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
860$ THEN
861$!
862$! Check To See If The User Wanted DECC.
863$!
864$ IF (P3.EQS."DECC")
865$ THEN
866$!
867$! Looks Like DECC, Set To Use DECC.
868$!
869$ COMPILER = "DECC"
870$!
871$! Tell The User We Are Using DECC.
872$!
873$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
874$!
875$! Use DECC...
876$!
877$ CC = "CC"
878$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
879 THEN CC = "CC/DECC"
880$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
881 "/NOLIST/PREFIX=ALL" + CCEXTRAFLAGS
882$!
883$! Define The Linker Options File Name.
884$!
885$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
886$!
887$! End DECC Check.
888$!
889$ ENDIF
890$!
891$! Check To See If We Are To Use VAXC.
892$!
893$ IF (P3.EQS."VAXC")
894$ THEN
895$!
896$! Looks Like VAXC, Set To Use VAXC.
897$!
898$ COMPILER = "VAXC"
899$!
900$! Tell The User We Are Using VAX C.
901$!
902$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
903$!
904$! Compile Using VAXC.
905$!
906$ CC = "CC"
907$ IF ARCH.EQS."AXP"
908$ THEN
909$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
910$ EXIT
911$ ENDIF
912$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
913$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
914$ CCDEFS = """VAXC""," + CCDEFS
915$!
916$! Define <sys> As SYS$COMMON:[SYSLIB]
917$!
918$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
919$!
920$! Define The Linker Options File Name.
921$!
922$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
923$!
924$! End VAXC Check
925$!
926$ ENDIF
927$!
928$! Check To See If We Are To Use GNU C.
929$!
930$ IF (P3.EQS."GNUC")
931$ THEN
932$!
933$! Looks Like GNUC, Set To Use GNUC.
934$!
935$ COMPILER = "GNUC"
936$!
937$! Tell The User We Are Using GNUC.
938$!
939$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
940$!
941$! Use GNU C...
942$!
943$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
944$!
945$! Define The Linker Options File Name.
946$!
947$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
948$!
949$! End The GNU C Check.
950$!
951$ ENDIF
952$!
953$! Set up default defines
954$!
955$ CCDEFS = """FLAT_INC=1""," + CCDEFS
956$!
957$! Finish up the definition of CC.
958$!
959$ IF COMPILER .EQS. "DECC"
960$ THEN
961$ IF CCDISABLEWARNINGS .EQS. ""
962$ THEN
963$ CC4DISABLEWARNINGS = "DOLLARID"
964$ ELSE
965$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
966$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
967$ ENDIF
968$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
969$ ELSE
970$ CCDISABLEWARNINGS = ""
971$ CC4DISABLEWARNINGS = ""
972$ ENDIF
973$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
974$!
975$! Show user the result
976$!
977$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC
978$!
979$! Else The User Entered An Invalid Arguement.
980$!
981$ ELSE
982$!
983$! Tell The User We Don't Know What They Want.
984$!
985$ WRITE SYS$OUTPUT ""
986$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
987$ WRITE SYS$OUTPUT ""
988$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
989$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
990$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
991$ WRITE SYS$OUTPUT ""
992$!
993$! Time To EXIT.
994$!
995$ EXIT
996$!
997$! End The P3 Check.
998$!
999$ ENDIF
1000$!
1001$! Time To RETURN...
1002$!
1003$ 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#ifndef MSDOS 61#ifndef MSDOS
62#ifndef VMS
63#include <openssl/opensslconf.h>
64#include OPENSSL_UNISTD
65#else /* VMS */
66#ifdef __DECC
62#include <unistd.h> 67#include <unistd.h>
68#else /* not __DECC */
69#include <math.h>
70#endif /* __DECC */
71#endif /* VMS */
63#else 72#else
64#include <io.h> 73#include <io.h>
65#define RAND
66#endif 74#endif
67 75
68#include <time.h> 76#include <time.h>
@@ -77,21 +85,13 @@
77#endif 85#endif
78#include <sys/stat.h> 86#include <sys/stat.h>
79#endif 87#endif
80#if defined(NOCONST) 88#include <openssl/des.h>
81#define const 89#include <openssl/rand.h>
82#endif
83#include "des.h"
84 90
85#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS) 91#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
86#include <string.h> 92#include <string.h>
87#endif 93#endif
88 94
89#ifdef RAND
90#define random rand
91#define srandom(s) srand(s)
92#endif
93
94#ifndef NOPROTO
95void usage(void); 95void usage(void);
96void doencryption(void); 96void doencryption(void);
97int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp); 97int 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);
102void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length, 102void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length,
103 des_key_schedule sk1,des_key_schedule sk2, 103 des_key_schedule sk1,des_key_schedule sk2,
104 des_cblock *ivec1,des_cblock *ivec2,int enc); 104 des_cblock *ivec1,des_cblock *ivec2,int enc);
105#else
106void usage();
107void doencryption();
108int uufwrite();
109void uufwriteEnd();
110int uufread();
111int uuencode();
112int uudecode();
113void des_3cbc_encrypt();
114#endif
115
116#ifdef VMS 105#ifdef VMS
117#define EXIT(a) exit(a&0x10000000L) 106#define EXIT(a) exit(a&0x10000000L)
118#else 107#else
@@ -138,9 +127,7 @@ char cksumname[200]="";
138 127
139int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error; 128int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
140 129
141int main(argc, argv) 130int main(int argc, char **argv)
142int argc;
143char **argv;
144 { 131 {
145 int i; 132 int i;
146 struct stat ins,outs; 133 struct stat ins,outs;
@@ -331,7 +318,7 @@ char **argv;
331 EXIT(0); 318 EXIT(0);
332 } 319 }
333 320
334void usage() 321void usage(void)
335 { 322 {
336 char **u; 323 char **u;
337 static const char *Usage[]={ 324 static const char *Usage[]={
@@ -357,7 +344,7 @@ void usage()
357"-3 : encrypt using tripple DES encryption. This uses 2 keys", 344"-3 : encrypt using tripple DES encryption. This uses 2 keys",
358" generated from the input key. If the input key is less", 345" generated from the input key. If the input key is less",
359" than 8 characters long, this is equivelent to normal", 346" than 8 characters long, this is equivelent to normal",
360" encryption. Default is tripple cbc, -b makes it tripple ecb.", 347" encryption. Default is triple cbc, -b makes it triple ecb.",
361NULL 348NULL
362}; 349};
363 for (u=(char **)Usage; *u; u++) 350 for (u=(char **)Usage; *u; u++)
@@ -369,17 +356,15 @@ NULL
369 EXIT(1); 356 EXIT(1);
370 } 357 }
371 358
372void doencryption() 359void doencryption(void)
373 { 360 {
374#ifdef _LIBC 361#ifdef _LIBC
375 extern int srandom();
376 extern int random();
377 extern unsigned long time(); 362 extern unsigned long time();
378#endif 363#endif
379 364
380 register int i; 365 register int i;
381 des_key_schedule ks,ks2; 366 des_key_schedule ks,ks2;
382 unsigned char iv[8],iv2[8]; 367 des_cblock iv,iv2;
383 char *p; 368 char *p;
384 int num=0,j,k,l,rem,ll,len,last,ex=0; 369 int num=0,j,k,l,rem,ll,len,last,ex=0;
385 des_cblock kk,k2; 370 des_cblock kk,k2;
@@ -392,8 +377,8 @@ void doencryption()
392 377
393 if (buf == NULL) 378 if (buf == NULL)
394 { 379 {
395 if ( (( buf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL) || 380 if ( (( buf=Malloc(BUFSIZE+8)) == NULL) ||
396 ((obuf=(unsigned char *)Malloc(BUFSIZE+8)) == NULL)) 381 ((obuf=Malloc(BUFSIZE+8)) == NULL))
397 { 382 {
398 fputs("Not enough memory\n",stderr); 383 fputs("Not enough memory\n",stderr);
399 Exit=10; 384 Exit=10;
@@ -440,19 +425,19 @@ void doencryption()
440 else 425 else
441 k2[i-8]=k; 426 k2[i-8]=k;
442 } 427 }
443 des_set_key((C_Block *)k2,ks2); 428 des_set_key(&k2,ks2);
444 memset(k2,0,sizeof(k2)); 429 memset(k2,0,sizeof(k2));
445 } 430 }
446 else if (longk || flag3) 431 else if (longk || flag3)
447 { 432 {
448 if (flag3) 433 if (flag3)
449 { 434 {
450 des_string_to_2keys(key,(C_Block *)kk,(C_Block *)k2); 435 des_string_to_2keys(key,&kk,&k2);
451 des_set_key((C_Block *)k2,ks2); 436 des_set_key(&k2,ks2);
452 memset(k2,0,sizeof(k2)); 437 memset(k2,0,sizeof(k2));
453 } 438 }
454 else 439 else
455 des_string_to_key(key,(C_Block *)kk); 440 des_string_to_key(key,&kk);
456 } 441 }
457 else 442 else
458 for (i=0; i<KEYSIZ; i++) 443 for (i=0; i<KEYSIZ; i++)
@@ -470,7 +455,7 @@ void doencryption()
470 kk[i]=key[i]|0x80; 455 kk[i]=key[i]|0x80;
471 } 456 }
472 457
473 des_set_key((C_Block *)kk,ks); 458 des_set_key(&kk,ks);
474 memset(key,0,sizeof(key)); 459 memset(key,0,sizeof(key));
475 memset(kk,0,sizeof(kk)); 460 memset(kk,0,sizeof(kk));
476 /* woops - A bug that does not showup under unix :-( */ 461 /* woops - A bug that does not showup under unix :-( */
@@ -498,9 +483,8 @@ void doencryption()
498 len=l-rem; 483 len=l-rem;
499 if (feof(DES_IN)) 484 if (feof(DES_IN))
500 { 485 {
501 srandom((unsigned int)time(NULL));
502 for (i=7-rem; i>0; i--) 486 for (i=7-rem; i>0; i--)
503 buf[l++]=random()&0xff; 487 RAND_bytes(buf + l++, 1);
504 buf[l++]=rem; 488 buf[l++]=rem;
505 ex=1; 489 ex=1;
506 len+=rem; 490 len+=rem;
@@ -510,8 +494,8 @@ void doencryption()
510 494
511 if (cflag) 495 if (cflag)
512 { 496 {
513 des_cbc_cksum((C_Block *)buf,(C_Block *)cksum, 497 des_cbc_cksum(buf,&cksum,
514 (long)len,ks,(C_Block *)cksum); 498 (long)len,ks,&cksum);
515 if (!eflag) 499 if (!eflag)
516 { 500 {
517 if (feof(DES_IN)) break; 501 if (feof(DES_IN)) break;
@@ -539,16 +523,16 @@ void doencryption()
539 (unsigned int)rem); 523 (unsigned int)rem);
540 des_3cbc_encrypt( 524 des_3cbc_encrypt(
541 (des_cblock *)buf,(des_cblock *)obuf, 525 (des_cblock *)buf,(des_cblock *)obuf,
542 (long)l,ks,ks2,(des_cblock *)iv, 526 (long)l,ks,ks2,&iv,
543 (des_cblock *)iv2,do_encrypt); 527 &iv2,do_encrypt);
544 if (rem) memcpy(&(buf[l]),tmpbuf, 528 if (rem) memcpy(&(buf[l]),tmpbuf,
545 (unsigned int)rem); 529 (unsigned int)rem);
546 } 530 }
547 else 531 else
548 { 532 {
549 des_cbc_encrypt( 533 des_cbc_encrypt(
550 (des_cblock *)buf,(des_cblock *)obuf, 534 buf,obuf,
551 (long)l,ks,(des_cblock *)iv,do_encrypt); 535 (long)l,ks,&iv,do_encrypt);
552 if (l >= 8) memcpy(iv,&(obuf[l-8]),8); 536 if (l >= 8) memcpy(iv,&(obuf[l-8]),8);
553 } 537 }
554 if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem); 538 if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem);
@@ -614,14 +598,14 @@ void doencryption()
614 { 598 {
615 des_3cbc_encrypt( 599 des_3cbc_encrypt(
616 (des_cblock *)buf,(des_cblock *)obuf, 600 (des_cblock *)buf,(des_cblock *)obuf,
617 (long)l,ks,ks2,(des_cblock *)iv, 601 (long)l,ks,ks2,&iv,
618 (des_cblock *)iv2,do_encrypt); 602 &iv2,do_encrypt);
619 } 603 }
620 else 604 else
621 { 605 {
622 des_cbc_encrypt( 606 des_cbc_encrypt(
623 (des_cblock *)buf,(des_cblock *)obuf, 607 buf,obuf,
624 (long)l,ks,(des_cblock *)iv,do_encrypt); 608 (long)l,ks,&iv,do_encrypt);
625 if (l >= 8) memcpy(iv,&(buf[l-8]),8); 609 if (l >= 8) memcpy(iv,&(buf[l-8]),8);
626 } 610 }
627 611
@@ -646,9 +630,9 @@ void doencryption()
646 l=l-8+last; 630 l=l-8+last;
647 } 631 }
648 i=0; 632 i=0;
649 if (cflag) des_cbc_cksum((C_Block *)obuf, 633 if (cflag) des_cbc_cksum(obuf,
650 (C_Block *)cksum,(long)l/8*8,ks, 634 (des_cblock *)cksum,(long)l/8*8,ks,
651 (C_Block *)cksum); 635 (des_cblock *)cksum);
652 while (i != l) 636 while (i != l)
653 { 637 {
654 j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT); 638 j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT);
@@ -696,15 +680,8 @@ problems:
696 if (Exit) EXIT(Exit); 680 if (Exit) EXIT(Exit);
697 } 681 }
698 682
699int uufwrite(data, size, num, fp) 683/* We ignore this parameter but it should be > ~50 I believe */
700unsigned char *data; 684int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp)
701int size;
702unsigned int num;
703FILE *fp;
704
705 /* We ignore this parameter but it should be > ~50 I believe */
706
707
708 { 685 {
709 int i,j,left,rem,ret=num; 686 int i,j,left,rem,ret=num;
710 static int start=1; 687 static int start=1;
@@ -757,8 +734,7 @@ FILE *fp;
757 return(ret); 734 return(ret);
758 } 735 }
759 736
760void uufwriteEnd(fp) 737void uufwriteEnd(FILE *fp)
761FILE *fp;
762 { 738 {
763 int j; 739 int j;
764 static const char *end=" \nend\n"; 740 static const char *end=" \nend\n";
@@ -774,11 +750,8 @@ FILE *fp;
774 fwrite(end,1,strlen(end),fp); 750 fwrite(end,1,strlen(end),fp);
775 } 751 }
776 752
777int uufread(out, size, num, fp) 753/* int size: should always be > ~ 60; I actually ignore this parameter :-) */
778unsigned char *out; 754int uufread(unsigned char *out, int size, unsigned int num, FILE *fp)
779int size; /* should always be > ~ 60; I actually ignore this parameter :-) */
780unsigned int num;
781FILE *fp;
782 { 755 {
783 int i,j,tot; 756 int i,j,tot;
784 static int done=0; 757 static int done=0;
@@ -850,10 +823,7 @@ FILE *fp;
850 *((c)++)=(unsigned char)(((l) )&0xff)) 823 *((c)++)=(unsigned char)(((l) )&0xff))
851 824
852 825
853int uuencode(in, num, out) 826int uuencode(unsigned char *in, int num, unsigned char *out)
854unsigned char *in;
855int num;
856unsigned char *out;
857 { 827 {
858 int j,i,n,tot=0; 828 int j,i,n,tot=0;
859 DES_LONG l; 829 DES_LONG l;
@@ -883,10 +853,7 @@ unsigned char *out;
883 return(tot); 853 return(tot);
884 } 854 }
885 855
886int uudecode(in, num, out) 856int uudecode(unsigned char *in, int num, unsigned char *out)
887unsigned char *in;
888int num;
889unsigned char *out;
890 { 857 {
891 int j,i,k; 858 int j,i,k;
892 unsigned int n=0,space=0; 859 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 @@
1/* crypto/des/des.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_DES_H
60#define HEADER_DES_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_DES
67#error DES is disabled.
68#endif
69
70#ifdef _KERBEROS_DES_H
71#error <openssl/des.h> replaces <kerberos/des.h>.
72#endif
73
74#include <stdio.h>
75#include <openssl/opensslconf.h> /* DES_LONG */
76#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
77
78typedef unsigned char des_cblock[8];
79typedef /* const */ unsigned char const_des_cblock[8];
80/* With "const", gcc 2.8.1 on Solaris thinks that des_cblock *
81 * and const_des_cblock * are incompatible pointer types.
82 * I haven't seen that warning on other systems ... I'll look
83 * what the standard says. */
84
85
86typedef struct des_ks_struct
87 {
88 union {
89 des_cblock cblock;
90 /* make sure things are correct size on machines with
91 * 8 byte longs */
92 DES_LONG deslong[2];
93 } ks;
94 int weak_key;
95 } des_key_schedule[16];
96
97#define DES_KEY_SZ (sizeof(des_cblock))
98#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
99
100#define DES_ENCRYPT 1
101#define DES_DECRYPT 0
102
103#define DES_CBC_MODE 0
104#define DES_PCBC_MODE 1
105
106#define des_ecb2_encrypt(i,o,k1,k2,e) \
107 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
108
109#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
110 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
111
112#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
113 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
114
115#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
116 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
117
118OPENSSL_EXTERN int des_check_key; /* defaults to false */
119OPENSSL_EXTERN int des_rw_mode; /* defaults to DES_PCBC_MODE */
120OPENSSL_EXTERN int des_set_weak_key_flag; /* set the weak key flag */
121
122const char *des_options(void);
123void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output,
124 des_key_schedule ks1,des_key_schedule ks2,
125 des_key_schedule ks3, int enc);
126DES_LONG des_cbc_cksum(const unsigned char *input,des_cblock *output,
127 long length,des_key_schedule schedule,
128 const_des_cblock *ivec);
129/* des_cbc_encrypt does not update the IV! Use des_ncbc_encrypt instead. */
130void des_cbc_encrypt(const unsigned char *input,unsigned char *output,
131 long length,des_key_schedule schedule,des_cblock *ivec,
132 int enc);
133void des_ncbc_encrypt(const unsigned char *input,unsigned char *output,
134 long length,des_key_schedule schedule,des_cblock *ivec,
135 int enc);
136void des_xcbc_encrypt(const unsigned char *input,unsigned char *output,
137 long length,des_key_schedule schedule,des_cblock *ivec,
138 const_des_cblock *inw,const_des_cblock *outw,int enc);
139void des_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
140 long length,des_key_schedule schedule,des_cblock *ivec,
141 int enc);
142void des_ecb_encrypt(const_des_cblock *input,des_cblock *output,
143 des_key_schedule ks,int enc);
144void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
145void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
146void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
147 des_key_schedule ks2, des_key_schedule ks3);
148void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
149 des_key_schedule ks2, des_key_schedule ks3);
150void des_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
151 long length,
152 des_key_schedule ks1,des_key_schedule ks2,
153 des_key_schedule ks3,des_cblock *ivec,int enc);
154void des_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
155 long length,
156 des_key_schedule ks1,des_key_schedule ks2,
157 des_key_schedule ks3,
158 des_cblock *ivec1,des_cblock *ivec2,
159 int enc);
160void des_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
161 long length,des_key_schedule ks1,
162 des_key_schedule ks2,des_key_schedule ks3,
163 des_cblock *ivec,int *num,int enc);
164void des_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
165 long length,des_key_schedule ks1,
166 des_key_schedule ks2,des_key_schedule ks3,
167 des_cblock *ivec,int *num);
168
169void des_xwhite_in2out(const_des_cblock *des_key,const_des_cblock *in_white,
170 des_cblock *out_white);
171
172int des_enc_read(int fd,void *buf,int len,des_key_schedule sched,
173 des_cblock *iv);
174int des_enc_write(int fd,const void *buf,int len,des_key_schedule sched,
175 des_cblock *iv);
176char *des_fcrypt(const char *buf,const char *salt, char *ret);
177char *des_crypt(const char *buf,const char *salt);
178#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
179char *crypt(const char *buf,const char *salt);
180#endif
181void des_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
182 long length,des_key_schedule schedule,des_cblock *ivec);
183void des_pcbc_encrypt(const unsigned char *input,unsigned char *output,
184 long length,des_key_schedule schedule,des_cblock *ivec,
185 int enc);
186DES_LONG des_quad_cksum(const unsigned char *input,des_cblock output[],
187 long length,int out_count,des_cblock *seed);
188void des_random_seed(des_cblock *key);
189void des_random_key(des_cblock *ret);
190int des_read_password(des_cblock *key,const char *prompt,int verify);
191int des_read_2passwords(des_cblock *key1,des_cblock *key2,
192 const char *prompt,int verify);
193int des_read_pw_string(char *buf,int length,const char *prompt,int verify);
194void des_set_odd_parity(des_cblock *key);
195int des_is_weak_key(const_des_cblock *key);
196int des_set_key(const_des_cblock *key,des_key_schedule schedule);
197int des_key_sched(const_des_cblock *key,des_key_schedule schedule);
198void des_string_to_key(const char *str,des_cblock *key);
199void des_string_to_2keys(const char *str,des_cblock *key1,des_cblock *key2);
200void des_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
201 des_key_schedule schedule,des_cblock *ivec,int *num,
202 int enc);
203void des_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
204 des_key_schedule schedule,des_cblock *ivec,int *num);
205int des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify);
206
207/* Extra functions from Mark Murray <mark@grondar.za> */
208void des_cblock_print_file(const_des_cblock *cb, FILE *fp);
209
210/* The following definitions provide compatibility with the MIT Kerberos
211 * library. The des_key_schedule structure is not binary compatible. */
212
213#define _KERBEROS_DES_H
214
215#define KRBDES_ENCRYPT DES_ENCRYPT
216#define KRBDES_DECRYPT DES_DECRYPT
217
218#ifdef KERBEROS
219# define ENCRYPT DES_ENCRYPT
220# define DECRYPT DES_DECRYPT
221#endif
222
223#ifndef NCOMPAT
224# define C_Block des_cblock
225# define Key_schedule des_key_schedule
226# define KEY_SZ DES_KEY_SZ
227# define string_to_key des_string_to_key
228# define read_pw_string des_read_pw_string
229# define random_key des_random_key
230# define pcbc_encrypt des_pcbc_encrypt
231# define set_key des_set_key
232# define key_sched des_key_sched
233# define ecb_encrypt des_ecb_encrypt
234# define cbc_encrypt des_cbc_encrypt
235# define ncbc_encrypt des_ncbc_encrypt
236# define xcbc_encrypt des_xcbc_encrypt
237# define cbc_cksum des_cbc_cksum
238# define quad_cksum des_quad_cksum
239#endif
240
241typedef des_key_schedule bit_64;
242#define des_fixup_key_parity des_set_odd_parity
243#define des_check_key_parity check_parity
244
245#ifdef __cplusplus
246}
247#endif
248
249#endif
diff --git a/src/lib/libcrypto/des/des.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 @@
1/* crypto/des/des.org */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify des.org since des.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_DES_H
68#define HEADER_DES_H
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74#include <stdio.h>
75
76/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
77 * %20 speed up (longs are 8 bytes, int's are 4). */
78#ifndef DES_LONG
79#define DES_LONG unsigned long
80#endif
81
82typedef unsigned char des_cblock[8];
83typedef struct des_ks_struct
84 {
85 union {
86 des_cblock _;
87 /* make sure things are correct size on machines with
88 * 8 byte longs */
89 DES_LONG pad[2];
90 } ks;
91#undef _
92#define _ ks._
93 } des_key_schedule[16];
94
95#define DES_KEY_SZ (sizeof(des_cblock))
96#define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
97
98#define DES_ENCRYPT 1
99#define DES_DECRYPT 0
100
101#define DES_CBC_MODE 0
102#define DES_PCBC_MODE 1
103
104#define des_ecb2_encrypt(i,o,k1,k2,e) \
105 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
106
107#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
108 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
109
110#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
111 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
112
113#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
114 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
115
116#define C_Block des_cblock
117#define Key_schedule des_key_schedule
118#ifdef KERBEROS
119#define ENCRYPT DES_ENCRYPT
120#define DECRYPT DES_DECRYPT
121#endif
122#define KEY_SZ DES_KEY_SZ
123#define string_to_key des_string_to_key
124#define read_pw_string des_read_pw_string
125#define random_key des_random_key
126#define pcbc_encrypt des_pcbc_encrypt
127#define set_key des_set_key
128#define key_sched des_key_sched
129#define ecb_encrypt des_ecb_encrypt
130#define cbc_encrypt des_cbc_encrypt
131#define ncbc_encrypt des_ncbc_encrypt
132#define xcbc_encrypt des_xcbc_encrypt
133#define cbc_cksum des_cbc_cksum
134#define quad_cksum des_quad_cksum
135
136/* For compatibility with the MIT lib - eay 20/05/92 */
137typedef des_key_schedule bit_64;
138#define des_fixup_key_parity des_set_odd_parity
139#define des_check_key_parity check_parity
140
141extern int des_check_key; /* defaults to false */
142extern int des_rw_mode; /* defaults to DES_PCBC_MODE */
143
144/* The next line is used to disable full ANSI prototypes, if your
145 * compiler has problems with the prototypes, make sure this line always
146 * evaluates to true :-) */
147#if defined(MSDOS) || defined(__STDC__)
148#undef NOPROTO
149#endif
150#ifndef NOPROTO
151char *des_options(void);
152void des_ecb3_encrypt(des_cblock *input,des_cblock *output,
153 des_key_schedule ks1,des_key_schedule ks2,
154 des_key_schedule ks3, int enc);
155DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output,
156 long length,des_key_schedule schedule,des_cblock *ivec);
157void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,
158 des_key_schedule schedule,des_cblock *ivec,int enc);
159void des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length,
160 des_key_schedule schedule,des_cblock *ivec,int enc);
161void des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length,
162 des_key_schedule schedule,des_cblock *ivec,
163 des_cblock *inw,des_cblock *outw,int enc);
164void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
165 long length,des_key_schedule schedule,des_cblock *ivec,int enc);
166void des_ecb_encrypt(des_cblock *input,des_cblock *output,
167 des_key_schedule ks,int enc);
168void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
169void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
170void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
171 des_key_schedule ks2, des_key_schedule ks3);
172void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
173 des_key_schedule ks2, des_key_schedule ks3);
174void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output,
175 long length, des_key_schedule ks1, des_key_schedule ks2,
176 des_key_schedule ks3, des_cblock *ivec, int enc);
177void des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
178 long length, des_key_schedule ks1, des_key_schedule ks2,
179 des_key_schedule ks3, des_cblock *ivec, int *num, int enc);
180void des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
181 long length, des_key_schedule ks1, des_key_schedule ks2,
182 des_key_schedule ks3, des_cblock *ivec, int *num);
183
184void des_xwhite_in2out(des_cblock (*des_key), des_cblock (*in_white),
185 des_cblock (*out_white));
186
187int des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
188 des_cblock *iv);
189int des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
190 des_cblock *iv);
191char *des_fcrypt(const char *buf,const char *salt, char *ret);
192#ifdef PERL5
193char *des_crypt(const char *buf,const char *salt);
194#else
195/* some stupid compilers complain because I have declared char instead
196 * of const char */
197#ifdef HEADER_DES_LOCL_H
198char *crypt(const char *buf,const char *salt);
199#else
200char *crypt();
201#endif
202#endif
203void des_ofb_encrypt(unsigned char *in,unsigned char *out,
204 int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
205void des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,
206 des_key_schedule schedule,des_cblock *ivec,int enc);
207DES_LONG des_quad_cksum(des_cblock *input,des_cblock *output,
208 long length,int out_count,des_cblock *seed);
209void des_random_seed(des_cblock key);
210void des_random_key(des_cblock ret);
211int des_read_password(des_cblock *key,char *prompt,int verify);
212int des_read_2passwords(des_cblock *key1,des_cblock *key2,
213 char *prompt,int verify);
214int des_read_pw_string(char *buf,int length,char *prompt,int verify);
215void des_set_odd_parity(des_cblock *key);
216int des_is_weak_key(des_cblock *key);
217int des_set_key(des_cblock *key,des_key_schedule schedule);
218int des_key_sched(des_cblock *key,des_key_schedule schedule);
219void des_string_to_key(char *str,des_cblock *key);
220void des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
221void des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
222 des_key_schedule schedule, des_cblock *ivec, int *num, int enc);
223void des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
224 des_key_schedule schedule, des_cblock *ivec, int *num);
225int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify);
226
227/* Extra functions from Mark Murray <mark@grondar.za> */
228void des_cblock_print_file(des_cblock *cb, FILE *fp);
229/* The following functions are not in the normal unix build or the
230 * SSLeay build. When using the SSLeay build, use RAND_seed()
231 * and RAND_bytes() instead. */
232int des_new_random_key(des_cblock *key);
233void des_init_random_number_generator(des_cblock *key);
234void des_set_random_generator_seed(des_cblock *key);
235void des_set_sequence_number(des_cblock new_sequence_number);
236void des_generate_random_block(des_cblock *block);
237
238#else
239
240char *des_options();
241void des_ecb3_encrypt();
242DES_LONG des_cbc_cksum();
243void des_cbc_encrypt();
244void des_ncbc_encrypt();
245void des_xcbc_encrypt();
246void des_cfb_encrypt();
247void des_ede3_cfb64_encrypt();
248void des_ede3_ofb64_encrypt();
249void des_ecb_encrypt();
250void des_encrypt();
251void des_encrypt2();
252void des_encrypt3();
253void des_decrypt3();
254void des_ede3_cbc_encrypt();
255int des_enc_read();
256int des_enc_write();
257char *des_fcrypt();
258#ifdef PERL5
259char *des_crypt();
260#else
261char *crypt();
262#endif
263void des_ofb_encrypt();
264void des_pcbc_encrypt();
265DES_LONG des_quad_cksum();
266void des_random_seed();
267void des_random_key();
268int des_read_password();
269int des_read_2passwords();
270int des_read_pw_string();
271void des_set_odd_parity();
272int des_is_weak_key();
273int des_set_key();
274int des_key_sched();
275void des_string_to_key();
276void des_string_to_2keys();
277void des_cfb64_encrypt();
278void des_ofb64_encrypt();
279int des_read_pw();
280void des_xwhite_in2out();
281
282/* Extra functions from Mark Murray <mark@grondar.za> */
283void des_cblock_print_file();
284/* The following functions are not in the normal unix build or the
285 * SSLeay build. When using the SSLeay build, use RAND_seed()
286 * and RAND_bytes() instead. */
287#ifdef FreeBSD
288int des_new_random_key();
289void des_init_random_number_generator();
290void des_set_random_generator_seed();
291void des_set_sequence_number();
292void des_generate_random_block();
293#endif
294
295#endif
296
297#ifdef __cplusplus
298}
299#endif
300
301#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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# des.pl - eric young 22/11/1991 eay@cryptsoft.com 2# des.pl - eric young 22/11/1991 eay@cryptsoft.com
3# 3#
4# Copyright (C) 1993 Eric Young 4# 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)
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <stdlib.h> 34#include <stdlib.h>
35#include "des.h" 35#include <openssl/des.h>
36 36
37void main(int argc,char *argv[]) 37void main(int argc,char *argv[])
38 { 38 {
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 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_encrypt(data, ks, enc) 61void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)
62DES_LONG *data;
63des_key_schedule ks;
64int enc;
65 { 62 {
66 register DES_LONG l,r,t,u; 63 register DES_LONG l,r,t,u;
67#ifdef DES_PTR 64#ifdef DES_PTR
68 register unsigned char *des_SP=(unsigned char *)des_SPtrans; 65 register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
69#endif 66#endif
70#ifndef DES_UNROLL 67#ifndef DES_UNROLL
71 register int i; 68 register int i;
@@ -87,7 +84,7 @@ int enc;
87 r=ROTATE(r,29)&0xffffffffL; 84 r=ROTATE(r,29)&0xffffffffL;
88 l=ROTATE(l,29)&0xffffffffL; 85 l=ROTATE(l,29)&0xffffffffL;
89 86
90 s=(DES_LONG *)ks; 87 s=ks->ks.deslong;
91 /* I don't know if it is worth the effort of loop unrolling the 88 /* I don't know if it is worth the effort of loop unrolling the
92 * inner loop */ 89 * inner loop */
93 if (enc) 90 if (enc)
@@ -159,14 +156,11 @@ int enc;
159 l=r=t=u=0; 156 l=r=t=u=0;
160 } 157 }
161 158
162void des_encrypt2(data, ks, enc) 159void des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)
163DES_LONG *data;
164des_key_schedule ks;
165int enc;
166 { 160 {
167 register DES_LONG l,r,t,u; 161 register DES_LONG l,r,t,u;
168#ifdef DES_PTR 162#ifdef DES_PTR
169 register unsigned char *des_SP=(unsigned char *)des_SPtrans; 163 register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
170#endif 164#endif
171#ifndef DES_UNROLL 165#ifndef DES_UNROLL
172 register int i; 166 register int i;
@@ -186,7 +180,7 @@ int enc;
186 r=ROTATE(r,29)&0xffffffffL; 180 r=ROTATE(r,29)&0xffffffffL;
187 l=ROTATE(l,29)&0xffffffffL; 181 l=ROTATE(l,29)&0xffffffffL;
188 182
189 s=(DES_LONG *)ks; 183 s=ks->ks.deslong;
190 /* I don't know if it is worth the effort of loop unrolling the 184 /* I don't know if it is worth the effort of loop unrolling the
191 * inner loop */ 185 * inner loop */
192 if (enc) 186 if (enc)
@@ -253,11 +247,8 @@ int enc;
253 l=r=t=u=0; 247 l=r=t=u=0;
254 } 248 }
255 249
256void des_encrypt3(data,ks1,ks2,ks3) 250void des_encrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
257DES_LONG *data; 251 des_key_schedule ks3)
258des_key_schedule ks1;
259des_key_schedule ks2;
260des_key_schedule ks3;
261 { 252 {
262 register DES_LONG l,r; 253 register DES_LONG l,r;
263 254
@@ -276,11 +267,8 @@ des_key_schedule ks3;
276 data[1]=r; 267 data[1]=r;
277 } 268 }
278 269
279void des_decrypt3(data,ks1,ks2,ks3) 270void des_decrypt3(DES_LONG *data, des_key_schedule ks1, des_key_schedule ks2,
280DES_LONG *data; 271 des_key_schedule ks3)
281des_key_schedule ks1;
282des_key_schedule ks2;
283des_key_schedule ks3;
284 { 272 {
285 register DES_LONG l,r; 273 register DES_LONG l,r;
286 274
@@ -301,108 +289,24 @@ des_key_schedule ks3;
301 289
302#ifndef DES_DEFAULT_OPTIONS 290#ifndef DES_DEFAULT_OPTIONS
303 291
304void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) 292#undef CBC_ENC_C__DONT_UPDATE_IV
305des_cblock (*input); 293#include "ncbc_enc.c" /* des_ncbc_encrypt */
306des_cblock (*output);
307long length;
308des_key_schedule schedule;
309des_cblock (*ivec);
310int enc;
311 {
312 register DES_LONG tin0,tin1;
313 register DES_LONG tout0,tout1,xor0,xor1;
314 register unsigned char *in,*out;
315 register long l=length;
316 DES_LONG tin[2];
317 unsigned char *iv;
318
319 in=(unsigned char *)input;
320 out=(unsigned char *)output;
321 iv=(unsigned char *)ivec;
322
323 if (enc)
324 {
325 c2l(iv,tout0);
326 c2l(iv,tout1);
327 for (l-=8; l>=0; l-=8)
328 {
329 c2l(in,tin0);
330 c2l(in,tin1);
331 tin0^=tout0; tin[0]=tin0;
332 tin1^=tout1; tin[1]=tin1;
333 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
334 tout0=tin[0]; l2c(tout0,out);
335 tout1=tin[1]; l2c(tout1,out);
336 }
337 if (l != -8)
338 {
339 c2ln(in,tin0,tin1,l+8);
340 tin0^=tout0; tin[0]=tin0;
341 tin1^=tout1; tin[1]=tin1;
342 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);
343 tout0=tin[0]; l2c(tout0,out);
344 tout1=tin[1]; l2c(tout1,out);
345 }
346 iv=(unsigned char *)ivec;
347 l2c(tout0,iv);
348 l2c(tout1,iv);
349 }
350 else
351 {
352 c2l(iv,xor0);
353 c2l(iv,xor1);
354 for (l-=8; l>=0; l-=8)
355 {
356 c2l(in,tin0); tin[0]=tin0;
357 c2l(in,tin1); tin[1]=tin1;
358 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
359 tout0=tin[0]^xor0;
360 tout1=tin[1]^xor1;
361 l2c(tout0,out);
362 l2c(tout1,out);
363 xor0=tin0;
364 xor1=tin1;
365 }
366 if (l != -8)
367 {
368 c2l(in,tin0); tin[0]=tin0;
369 c2l(in,tin1); tin[1]=tin1;
370 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
371 tout0=tin[0]^xor0;
372 tout1=tin[1]^xor1;
373 l2cn(tout0,tout1,out,l+8);
374 xor0=tin0;
375 xor1=tin1;
376 }
377
378 iv=(unsigned char *)ivec;
379 l2c(xor0,iv);
380 l2c(xor1,iv);
381 }
382 tin0=tin1=tout0=tout1=xor0=xor1=0;
383 tin[0]=tin[1]=0;
384 }
385 294
386void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc) 295void des_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
387des_cblock (*input); 296 long length, des_key_schedule ks1, des_key_schedule ks2,
388des_cblock (*output); 297 des_key_schedule ks3, des_cblock *ivec, int enc)
389long length;
390des_key_schedule ks1;
391des_key_schedule ks2;
392des_key_schedule ks3;
393des_cblock (*ivec);
394int enc;
395 { 298 {
396 register DES_LONG tin0,tin1; 299 register DES_LONG tin0,tin1;
397 register DES_LONG tout0,tout1,xor0,xor1; 300 register DES_LONG tout0,tout1,xor0,xor1;
398 register unsigned char *in,*out; 301 register const unsigned char *in;
302 unsigned char *out;
399 register long l=length; 303 register long l=length;
400 DES_LONG tin[2]; 304 DES_LONG tin[2];
401 unsigned char *iv; 305 unsigned char *iv;
402 306
403 in=(unsigned char *)input; 307 in=input;
404 out=(unsigned char *)output; 308 out=output;
405 iv=(unsigned char *)ivec; 309 iv = &(*ivec)[0];
406 310
407 if (enc) 311 if (enc)
408 { 312 {
@@ -439,7 +343,7 @@ int enc;
439 l2c(tout0,out); 343 l2c(tout0,out);
440 l2c(tout1,out); 344 l2c(tout1,out);
441 } 345 }
442 iv=(unsigned char *)ivec; 346 iv = &(*ivec)[0];
443 l2c(tout0,iv); 347 l2c(tout0,iv);
444 l2c(tout1,iv); 348 l2c(tout1,iv);
445 } 349 }
@@ -491,7 +395,7 @@ int enc;
491 xor1=t1; 395 xor1=t1;
492 } 396 }
493 397
494 iv=(unsigned char *)ivec; 398 iv = &(*ivec)[0];
495 l2c(xor0,iv); 399 l2c(xor0,iv);
496 l2c(xor1,iv); 400 l2c(xor1,iv);
497 } 401 }
diff --git a/src/lib/libcrypto/des/des_locl.org b/src/lib/libcrypto/des/des_locl.h
index e2e503cbed..d6ea17cb68 100644
--- a/src/lib/libcrypto/des/des_locl.org
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -1,4 +1,4 @@
1/* crypto/des/des_locl.org */ 1/* crypto/des/des_locl.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,14 +56,6 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify des_locl.org since des_locl.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_DES_LOCL_H 59#ifndef HEADER_DES_LOCL_H
68#define HEADER_DES_LOCL_H 60#define HEADER_DES_LOCL_H
69 61
@@ -75,123 +67,28 @@
75 67
76#include <stdio.h> 68#include <stdio.h>
77#include <stdlib.h> 69#include <stdlib.h>
78#ifndef MSDOS
79#include <unistd.h>
80#endif
81#include "des.h"
82
83#ifndef DES_DEFAULT_OPTIONS
84/* the following is tweaked from a config script, that is why it is a
85 * protected undef/define */
86#ifndef DES_PTR
87#undef DES_PTR
88#endif
89 70
90/* This helps C compiler generate the correct code for multiple functional 71#include <openssl/opensslconf.h>
91 * units. It reduces register dependancies at the expense of 2 more
92 * registers */
93#ifndef DES_RISC1
94#undef DES_RISC1
95#endif
96
97#ifndef DES_RISC2
98#undef DES_RISC2
99#endif
100
101#if defined(DES_RISC1) && defined(DES_RISC2)
102YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
103#endif
104 72
105/* Unroll the inner loop, this sometimes helps, sometimes hinders. 73#ifndef MSDOS
106 * Very mucy CPU dependant */ 74#if !defined(VMS) || defined(__DECC)
107#ifndef DES_UNROLL 75#include OPENSSL_UNISTD
108#undef DES_UNROLL 76#include <math.h>
109#endif 77#endif
110
111/* These default values were supplied by
112 * Peter Gutman <pgut001@cs.auckland.ac.nz>
113 * They are only used if nothing else has been defined */
114#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
115/* Special defines which change the way the code is built depending on the
116 CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
117 even newer MIPS CPU's, but at the moment one size fits all for
118 optimization options. Older Sparc's work better with only UNROLL, but
119 there's no way to tell at compile time what it is you're running on */
120
121#if defined( sun ) /* Newer Sparc's */
122 #define DES_PTR
123 #define DES_RISC1
124 #define DES_UNROLL
125#elif defined( __ultrix ) /* Older MIPS */
126 #define DES_PTR
127 #define DES_RISC2
128 #define DES_UNROLL
129#elif defined( __osf1__ ) /* Alpha */
130 #define DES_PTR
131 #define DES_RISC2
132#elif defined ( _AIX ) /* RS6000 */
133 /* Unknown */
134#elif defined( __hpux ) /* HP-PA */
135 /* Unknown */
136#elif defined( __aux ) /* 68K */
137 /* Unknown */
138#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */
139 #define DES_UNROLL
140#elif defined( __sgi ) /* Newer MIPS */
141 #define DES_PTR
142 #define DES_RISC2
143 #define DES_UNROLL
144#elif defined( i386 ) /* x86 boxes, should be gcc */
145 #define DES_PTR
146 #define DES_RISC1
147 #define DES_UNROLL
148#endif /* Systems-specific speed defines */
149#endif 78#endif
150 79#include <openssl/des.h>
151#endif /* DES_DEFAULT_OPTIONS */
152 80
153#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */ 81#ifdef MSDOS /* Visual C++ 2.1 (Windows NT/95) */
154#include <stdlib.h> 82#include <stdlib.h>
155#include <errno.h> 83#include <errno.h>
156#include <time.h> 84#include <time.h>
157#include <io.h> 85#include <io.h>
158#ifndef RAND
159#define RAND
160#endif
161#undef NOPROTO
162#endif 86#endif
163 87
164#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS) 88#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
165#include <string.h> 89#include <string.h>
166#endif 90#endif
167 91
168#ifndef RAND
169#define RAND
170#endif
171
172#ifdef linux
173#undef RAND
174#endif
175
176#ifdef MSDOS
177#define getpid() 2
178#define RAND
179#undef NOPROTO
180#endif
181
182#if defined(NOCONST)
183#define const
184#endif
185
186#ifdef __STDC__
187#undef NOPROTO
188#endif
189
190#ifdef RAND
191#define srandom(s) srand(s)
192#define random rand
193#endif
194
195#define ITERATIONS 16 92#define ITERATIONS 16
196#define HALF_ITERATIONS 8 93#define HALF_ITERATIONS 8
197 94
@@ -302,24 +199,24 @@ YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
302 u2&=0xfc; \ 199 u2&=0xfc; \
303 t=ROTATE(t,4); \ 200 t=ROTATE(t,4); \
304 u>>=16L; \ 201 u>>=16L; \
305 LL^= *(DES_LONG *)((unsigned char *)des_SP +u1); \ 202 LL^= *(const DES_LONG *)(des_SP +u1); \
306 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x200+u2); \ 203 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
307 u3=(int)(u>>8L); \ 204 u3=(int)(u>>8L); \
308 u1=(int)u&0xfc; \ 205 u1=(int)u&0xfc; \
309 u3&=0xfc; \ 206 u3&=0xfc; \
310 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x400+u1); \ 207 LL^= *(const DES_LONG *)(des_SP+0x400+u1); \
311 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x600+u3); \ 208 LL^= *(const DES_LONG *)(des_SP+0x600+u3); \
312 u2=(int)t>>8L; \ 209 u2=(int)t>>8L; \
313 u1=(int)t&0xfc; \ 210 u1=(int)t&0xfc; \
314 u2&=0xfc; \ 211 u2&=0xfc; \
315 t>>=16L; \ 212 t>>=16L; \
316 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x100+u1); \ 213 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
317 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x300+u2); \ 214 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
318 u3=(int)t>>8L; \ 215 u3=(int)t>>8L; \
319 u1=(int)t&0xfc; \ 216 u1=(int)t&0xfc; \
320 u3&=0xfc; \ 217 u3&=0xfc; \
321 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x500+u1); \ 218 LL^= *(const DES_LONG *)(des_SP+0x500+u1); \
322 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x700+u3); } 219 LL^= *(const DES_LONG *)(des_SP+0x700+u3); }
323#endif 220#endif
324#ifdef DES_RISC2 221#ifdef DES_RISC2
325#define D_ENCRYPT(LL,R,S) { \ 222#define D_ENCRYPT(LL,R,S) { \
@@ -329,39 +226,39 @@ YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
329 u1=(int)u&0xfc; \ 226 u1=(int)u&0xfc; \
330 u2&=0xfc; \ 227 u2&=0xfc; \
331 t=ROTATE(t,4); \ 228 t=ROTATE(t,4); \
332 LL^= *(DES_LONG *)((unsigned char *)des_SP +u1); \ 229 LL^= *(const DES_LONG *)(des_SP +u1); \
333 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x200+u2); \ 230 LL^= *(const DES_LONG *)(des_SP+0x200+u2); \
334 s1=(int)(u>>16L); \ 231 s1=(int)(u>>16L); \
335 s2=(int)(u>>24L); \ 232 s2=(int)(u>>24L); \
336 s1&=0xfc; \ 233 s1&=0xfc; \
337 s2&=0xfc; \ 234 s2&=0xfc; \
338 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x400+s1); \ 235 LL^= *(const DES_LONG *)(des_SP+0x400+s1); \
339 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x600+s2); \ 236 LL^= *(const DES_LONG *)(des_SP+0x600+s2); \
340 u2=(int)t>>8L; \ 237 u2=(int)t>>8L; \
341 u1=(int)t&0xfc; \ 238 u1=(int)t&0xfc; \
342 u2&=0xfc; \ 239 u2&=0xfc; \
343 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x100+u1); \ 240 LL^= *(const DES_LONG *)(des_SP+0x100+u1); \
344 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x300+u2); \ 241 LL^= *(const DES_LONG *)(des_SP+0x300+u2); \
345 s1=(int)(t>>16L); \ 242 s1=(int)(t>>16L); \
346 s2=(int)(t>>24L); \ 243 s2=(int)(t>>24L); \
347 s1&=0xfc; \ 244 s1&=0xfc; \
348 s2&=0xfc; \ 245 s2&=0xfc; \
349 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x500+s1); \ 246 LL^= *(const DES_LONG *)(des_SP+0x500+s1); \
350 LL^= *(DES_LONG *)((unsigned char *)des_SP+0x700+s2); } 247 LL^= *(const DES_LONG *)(des_SP+0x700+s2); }
351#endif 248#endif
352#else 249#else
353#define D_ENCRYPT(LL,R,S) { \ 250#define D_ENCRYPT(LL,R,S) { \
354 LOAD_DATA_tmp(R,S,u,t,E0,E1); \ 251 LOAD_DATA_tmp(R,S,u,t,E0,E1); \
355 t=ROTATE(t,4); \ 252 t=ROTATE(t,4); \
356 LL^= \ 253 LL^= \
357 *(DES_LONG *)((unsigned char *)des_SP +((u )&0xfc))^ \ 254 *(const DES_LONG *)(des_SP +((u )&0xfc))^ \
358 *(DES_LONG *)((unsigned char *)des_SP+0x200+((u>> 8L)&0xfc))^ \ 255 *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \
359 *(DES_LONG *)((unsigned char *)des_SP+0x400+((u>>16L)&0xfc))^ \ 256 *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \
360 *(DES_LONG *)((unsigned char *)des_SP+0x600+((u>>24L)&0xfc))^ \ 257 *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \
361 *(DES_LONG *)((unsigned char *)des_SP+0x100+((t )&0xfc))^ \ 258 *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \
362 *(DES_LONG *)((unsigned char *)des_SP+0x300+((t>> 8L)&0xfc))^ \ 259 *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \
363 *(DES_LONG *)((unsigned char *)des_SP+0x500+((t>>16L)&0xfc))^ \ 260 *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \
364 *(DES_LONG *)((unsigned char *)des_SP+0x700+((t>>24L)&0xfc)); } 261 *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); }
365#endif 262#endif
366 263
367#else /* original version */ 264#else /* original version */
@@ -504,13 +401,8 @@ YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
504 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ 401 PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \
505 } 402 }
506 403
507extern const DES_LONG des_SPtrans[8][64]; 404OPENSSL_EXTERN const DES_LONG des_SPtrans[8][64];
508 405
509#ifndef NOPROTO
510void fcrypt_body(DES_LONG *out,des_key_schedule ks, 406void fcrypt_body(DES_LONG *out,des_key_schedule ks,
511 DES_LONG Eswap0, DES_LONG Eswap1); 407 DES_LONG Eswap0, DES_LONG Eswap1);
512#else
513void fcrypt_body();
514#endif
515
516#endif 408#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 @@
59/* define PART1, PART2, PART3 or PART4 to build only with a few of the options. 59/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
60 * This is for machines with 64k code segment size restrictions. */ 60 * This is for machines with 64k code segment size restrictions. */
61 61
62#ifndef MSDOS 62#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
63#define TIMES 63#define TIMES
64#endif 64#endif
65 65
66#include <stdio.h> 66#include <stdio.h>
67#ifndef MSDOS 67#ifndef MSDOS
68#include <unistd.h> 68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD
69#else 70#else
70#include <io.h> 71#include <io.h>
71extern void exit(); 72extern void exit();
72#endif 73#endif
73#include <signal.h> 74#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX 75#ifndef _IRIX
76#include <time.h> 76#include <time.h>
77#endif 77#endif
@@ -79,25 +79,27 @@ extern void exit();
79#include <sys/types.h> 79#include <sys/types.h>
80#include <sys/times.h> 80#include <sys/times.h>
81#endif 81#endif
82#else /* VMS */ 82
83#include <types.h> 83/* Depending on the VMS version, the tms structure is perhaps defined.
84struct tms { 84 The __TMS macro will show if it was. If it wasn't defined, we should
85 time_t tms_utime; 85 undefine TIMES, since that tells the rest of the program how things
86 time_t tms_stime; 86 should be handled. -- Richard Levitte */
87 time_t tms_uchild; /* I dunno... */ 87#if defined(VMS) && defined(__DECC) && !defined(__TMS)
88 time_t tms_uchildsys; /* so these names are a guess :-) */ 88#undef TIMES
89 }
90#endif 89#endif
90
91#ifndef TIMES 91#ifndef TIMES
92#include <sys/timeb.h> 92#include <sys/timeb.h>
93#endif 93#endif
94 94
95#ifdef sun 95
96#if defined(sun) || defined(__ultrix)
97#define _POSIX_SOURCE
96#include <limits.h> 98#include <limits.h>
97#include <sys/param.h> 99#include <sys/param.h>
98#endif 100#endif
99 101
100#include "des.h" 102#include <openssl/des.h>
101#include "spr.h" 103#include "spr.h"
102 104
103#define DES_DEFAULT_OPTIONS 105#define DES_DEFAULT_OPTIONS
@@ -317,11 +319,7 @@ struct tms {
317#ifndef HZ 319#ifndef HZ
318# ifndef CLK_TCK 320# ifndef CLK_TCK
319# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ 321# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
320# ifndef VMS 322# define HZ 100.0
321# define HZ 100.0
322# else /* VMS */
323# define HZ 100.0
324# endif
325# else /* _BSD_CLK_TCK_ */ 323# else /* _BSD_CLK_TCK_ */
326# define HZ ((double)_BSD_CLK_TCK_) 324# define HZ ((double)_BSD_CLK_TCK_)
327# endif 325# endif
@@ -333,12 +331,7 @@ struct tms {
333#define BUFSIZE ((long)1024) 331#define BUFSIZE ((long)1024)
334long run=0; 332long run=0;
335 333
336#ifndef NOPROTO
337double Time_F(int s); 334double Time_F(int s);
338#else
339double Time_F();
340#endif
341
342#ifdef SIGALRM 335#ifdef SIGALRM
343#if defined(__STDC__) || defined(sgi) 336#if defined(__STDC__) || defined(sgi)
344#define SIGRETTYPE void 337#define SIGRETTYPE void
@@ -346,14 +339,8 @@ double Time_F();
346#define SIGRETTYPE int 339#define SIGRETTYPE int
347#endif 340#endif
348 341
349#ifndef NOPROTO
350SIGRETTYPE sig_done(int sig); 342SIGRETTYPE sig_done(int sig);
351#else 343SIGRETTYPE sig_done(int sig)
352SIGRETTYPE sig_done();
353#endif
354
355SIGRETTYPE sig_done(sig)
356int sig;
357 { 344 {
358 signal(SIGALRM,sig_done); 345 signal(SIGALRM,sig_done);
359 run=0; 346 run=0;
@@ -366,8 +353,7 @@ int sig;
366#define START 0 353#define START 0
367#define STOP 1 354#define STOP 1
368 355
369double Time_F(s) 356double Time_F(int s)
370int s;
371 { 357 {
372 double ret; 358 double ret;
373#ifdef TIMES 359#ifdef TIMES
@@ -425,9 +411,7 @@ int s;
425 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \ 411 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
426 tm[index]*8,1.0e6/tm[index]); 412 tm[index]*8,1.0e6/tm[index]);
427 413
428int main(argc,argv) 414int main(int argc, char **argv)
429int argc;
430char **argv;
431 { 415 {
432 long count; 416 long count;
433 static unsigned char buf[BUFSIZE]; 417 static unsigned char buf[BUFSIZE];
@@ -454,13 +438,13 @@ char **argv;
454 fprintf(stderr,"program when this computer is idle.\n"); 438 fprintf(stderr,"program when this computer is idle.\n");
455#endif 439#endif
456 440
457 des_set_key((C_Block *)key,sch); 441 des_set_key(&key,sch);
458 des_set_key((C_Block *)key2,sch2); 442 des_set_key(&key2,sch2);
459 des_set_key((C_Block *)key3,sch3); 443 des_set_key(&key3,sch3);
460 444
461#ifndef SIGALRM 445#ifndef SIGALRM
462 fprintf(stderr,"First we calculate the approximate speed ...\n"); 446 fprintf(stderr,"First we calculate the approximate speed ...\n");
463 des_set_key((C_Block *)key,sch); 447 des_set_key(&key,sch);
464 count=10; 448 count=10;
465 do { 449 do {
466 long i; 450 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59extern char *DES_version; /* SSLeay version string */ 59#include <openssl/e_os2.h>
60extern char *libdes_version; /* old libdes version string */ 60OPENSSL_EXTERN char *DES_version; /* SSLeay version string */
61OPENSSL_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)
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <stdlib.h> 34#include <stdlib.h>
35#include "des.h" 35#include <openssl/des.h>
36 36
37void main(int argc,char *argv[]) 37void main(int argc,char *argv[])
38 { 38 {
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 @@
65#include <stdio.h> 65#include <stdio.h>
66#include <stdlib.h> 66#include <stdlib.h>
67#ifndef MSDOS 67#ifndef MSDOS
68#include <unistd.h> 68#if !defined(VMS) || defined(__DECC)
69#include <openssl/opensslconf.h>
70#include OPENSSL_UNISTD
71#endif /* VMS */
69#else 72#else
70#include <io.h> 73#include <io.h>
71#endif 74#endif
72#include <string.h> 75#include <string.h>
73#include "des.h" 76
77#ifdef NO_DES
78int main(int argc, char *argv[])
79{
80 printf("No DES support\n");
81 return(0);
82}
83#else
84#include <openssl/des.h>
85
86#if defined(PERL5) || defined(__FreeBSD__)
87#define crypt(c,s) (des_crypt((c),(s)))
88#endif
74 89
75/* tisk tisk - the test keys don't all have odd parity :-( */ 90/* tisk tisk - the test keys don't all have odd parity :-( */
76/* test data */ 91/* test data */
@@ -225,7 +240,7 @@ static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
225/* Changed the following text constant to binary so it will work on ebcdic 240/* Changed the following text constant to binary so it will work on ebcdic
226 * machines :-) */ 241 * machines :-) */
227/* static char cbc_data[40]="7654321 Now is the time for \0001"; */ 242/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
228static char cbc_data[40]={ 243static unsigned char cbc_data[40]={
229 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20, 244 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
230 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74, 245 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
231 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20, 246 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
@@ -297,24 +312,14 @@ static unsigned char ofb_cipher[24]=
297DES_LONG cbc_cksum_ret=0xB462FEF7L; 312DES_LONG cbc_cksum_ret=0xB462FEF7L;
298unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4}; 313unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
299 314
300#ifndef NOPROTO
301static char *pt(unsigned char *p); 315static char *pt(unsigned char *p);
302static int cfb_test(int bits, unsigned char *cfb_cipher); 316static int cfb_test(int bits, unsigned char *cfb_cipher);
303static int cfb64_test(unsigned char *cfb_cipher); 317static int cfb64_test(unsigned char *cfb_cipher);
304static int ede_cfb64_test(unsigned char *cfb_cipher); 318static int ede_cfb64_test(unsigned char *cfb_cipher);
305#else 319int main(int argc, char *argv[])
306static char *pt();
307static int cfb_test();
308static int cfb64_test();
309static int ede_cfb64_test();
310#endif
311
312int main(argc,argv)
313int argc;
314char *argv[];
315 { 320 {
316 int i,j,err=0; 321 int i,j,err=0;
317 des_cblock in,out,outin,iv3; 322 des_cblock in,out,outin,iv3,iv2;
318 des_key_schedule ks,ks2,ks3; 323 des_key_schedule ks,ks2,ks3;
319 unsigned char cbc_in[40]; 324 unsigned char cbc_in[40];
320 unsigned char cbc_out[40]; 325 unsigned char cbc_out[40];
@@ -324,10 +329,63 @@ char *argv[];
324 int num; 329 int num;
325 char *str; 330 char *str;
326 331
332#ifndef NO_DESCBCM
333 printf("Doing cbcm\n");
334 if ((j=des_key_sched(&cbc_key,ks)) != 0)
335 {
336 printf("Key error %d\n",j);
337 err=1;
338 }
339 if ((j=des_key_sched(&cbc2_key,ks2)) != 0)
340 {
341 printf("Key error %d\n",j);
342 err=1;
343 }
344 if ((j=des_key_sched(&cbc3_key,ks3)) != 0)
345 {
346 printf("Key error %d\n",j);
347 err=1;
348 }
349 memset(cbc_out,0,40);
350 memset(cbc_in,0,40);
351 i=strlen((char *)cbc_data)+1;
352 /* i=((i+7)/8)*8; */
353 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
354 memset(iv2,'\0',sizeof iv2);
355
356 des_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,&iv2,
357 DES_ENCRYPT);
358 des_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,ks,ks2,ks3,
359 &iv3,&iv2,DES_ENCRYPT);
360 /* if (memcmp(cbc_out,cbc3_ok,
361 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
362 {
363 printf("des_ede3_cbc_encrypt encrypt error\n");
364 err=1;
365 }
366 */
367 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
368 memset(iv2,'\0',sizeof iv2);
369 des_ede3_cbcm_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,&iv2,DES_DECRYPT);
370 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
371 {
372 int n;
373
374 printf("des_ede3_cbcm_encrypt decrypt error\n");
375 for(n=0 ; n < i ; ++n)
376 printf(" %02x",cbc_data[n]);
377 printf("\n");
378 for(n=0 ; n < i ; ++n)
379 printf(" %02x",cbc_in[n]);
380 printf("\n");
381 err=1;
382 }
383#endif
384
327 printf("Doing ecb\n"); 385 printf("Doing ecb\n");
328 for (i=0; i<NUM_TESTS; i++) 386 for (i=0; i<NUM_TESTS; i++)
329 { 387 {
330 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) 388 if ((j=des_key_sched(&key_data[i],ks)) != 0)
331 { 389 {
332 printf("Key error %2d:%d\n",i+1,j); 390 printf("Key error %2d:%d\n",i+1,j);
333 err=1; 391 err=1;
@@ -335,8 +393,8 @@ char *argv[];
335 memcpy(in,plain_data[i],8); 393 memcpy(in,plain_data[i],8);
336 memset(out,0,8); 394 memset(out,0,8);
337 memset(outin,0,8); 395 memset(outin,0,8);
338 des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT); 396 des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT);
339 des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT); 397 des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT);
340 398
341 if (memcmp(out,cipher_data[i],8) != 0) 399 if (memcmp(out,cipher_data[i],8) != 0)
342 { 400 {
@@ -357,17 +415,17 @@ char *argv[];
357 printf("Doing ede ecb\n"); 415 printf("Doing ede ecb\n");
358 for (i=0; i<(NUM_TESTS-1); i++) 416 for (i=0; i<(NUM_TESTS-1); i++)
359 { 417 {
360 if ((j=des_key_sched((C_Block *)(key_data[i]),ks)) != 0) 418 if ((j=des_key_sched(&key_data[i],ks)) != 0)
361 { 419 {
362 err=1; 420 err=1;
363 printf("Key error %2d:%d\n",i+1,j); 421 printf("Key error %2d:%d\n",i+1,j);
364 } 422 }
365 if ((j=des_key_sched((C_Block *)(key_data[i+1]),ks2)) != 0) 423 if ((j=des_key_sched(&key_data[i+1],ks2)) != 0)
366 { 424 {
367 printf("Key error %2d:%d\n",i+2,j); 425 printf("Key error %2d:%d\n",i+2,j);
368 err=1; 426 err=1;
369 } 427 }
370 if ((j=des_key_sched((C_Block *)(key_data[i+2]),ks3)) != 0) 428 if ((j=des_key_sched(&key_data[i+2],ks3)) != 0)
371 { 429 {
372 printf("Key error %2d:%d\n",i+3,j); 430 printf("Key error %2d:%d\n",i+3,j);
373 err=1; 431 err=1;
@@ -375,10 +433,8 @@ char *argv[];
375 memcpy(in,plain_data[i],8); 433 memcpy(in,plain_data[i],8);
376 memset(out,0,8); 434 memset(out,0,8);
377 memset(outin,0,8); 435 memset(outin,0,8);
378 des_ecb2_encrypt((C_Block *)in,(C_Block *)out,ks,ks2, 436 des_ecb2_encrypt(&in,&out,ks,ks2,DES_ENCRYPT);
379 DES_ENCRYPT); 437 des_ecb2_encrypt(&out,&outin,ks,ks2,DES_DECRYPT);
380 des_ecb2_encrypt((C_Block *)out,(C_Block *)outin,ks,ks2,
381 DES_DECRYPT);
382 438
383 if (memcmp(out,cipher_ecb2[i],8) != 0) 439 if (memcmp(out,cipher_ecb2[i],8) != 0)
384 { 440 {
@@ -397,7 +453,7 @@ char *argv[];
397#endif 453#endif
398 454
399 printf("Doing cbc\n"); 455 printf("Doing cbc\n");
400 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) 456 if ((j=des_key_sched(&cbc_key,ks)) != 0)
401 { 457 {
402 printf("Key error %d\n",j); 458 printf("Key error %d\n",j);
403 err=1; 459 err=1;
@@ -405,16 +461,14 @@ char *argv[];
405 memset(cbc_out,0,40); 461 memset(cbc_out,0,40);
406 memset(cbc_in,0,40); 462 memset(cbc_in,0,40);
407 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 463 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
408 des_ncbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, 464 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
409 (long)strlen((char *)cbc_data)+1,ks, 465 &iv3,DES_ENCRYPT);
410 (C_Block *)iv3,DES_ENCRYPT);
411 if (memcmp(cbc_out,cbc_ok,32) != 0) 466 if (memcmp(cbc_out,cbc_ok,32) != 0)
412 printf("cbc_encrypt encrypt error\n"); 467 printf("cbc_encrypt encrypt error\n");
413 468
414 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 469 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
415 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, 470 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
416 (long)strlen((char *)cbc_data)+1,ks, 471 &iv3,DES_DECRYPT);
417 (C_Block *)iv3,DES_DECRYPT);
418 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0) 472 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
419 { 473 {
420 printf("cbc_encrypt decrypt error\n"); 474 printf("cbc_encrypt decrypt error\n");
@@ -423,7 +477,7 @@ char *argv[];
423 477
424#ifndef LIBDES_LIT 478#ifndef LIBDES_LIT
425 printf("Doing desx cbc\n"); 479 printf("Doing desx cbc\n");
426 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) 480 if ((j=des_key_sched(&cbc_key,ks)) != 0)
427 { 481 {
428 printf("Key error %d\n",j); 482 printf("Key error %d\n",j);
429 err=1; 483 err=1;
@@ -431,19 +485,15 @@ char *argv[];
431 memset(cbc_out,0,40); 485 memset(cbc_out,0,40);
432 memset(cbc_in,0,40); 486 memset(cbc_in,0,40);
433 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 487 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
434 des_xcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, 488 des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
435 (long)strlen((char *)cbc_data)+1,ks, 489 &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT);
436 (C_Block *)iv3,
437 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_ENCRYPT);
438 if (memcmp(cbc_out,xcbc_ok,32) != 0) 490 if (memcmp(cbc_out,xcbc_ok,32) != 0)
439 { 491 {
440 printf("des_xcbc_encrypt encrypt error\n"); 492 printf("des_xcbc_encrypt encrypt error\n");
441 } 493 }
442 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 494 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
443 des_xcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, 495 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
444 (long)strlen((char *)cbc_data)+1,ks, 496 &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT);
445 (C_Block *)iv3,
446 (C_Block *)cbc2_key, (C_Block *)cbc3_key, DES_DECRYPT);
447 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0) 497 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
448 { 498 {
449 printf("des_xcbc_encrypt decrypt error\n"); 499 printf("des_xcbc_encrypt decrypt error\n");
@@ -452,17 +502,17 @@ char *argv[];
452#endif 502#endif
453 503
454 printf("Doing ede cbc\n"); 504 printf("Doing ede cbc\n");
455 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) 505 if ((j=des_key_sched(&cbc_key,ks)) != 0)
456 { 506 {
457 printf("Key error %d\n",j); 507 printf("Key error %d\n",j);
458 err=1; 508 err=1;
459 } 509 }
460 if ((j=des_key_sched((C_Block *)cbc2_key,ks2)) != 0) 510 if ((j=des_key_sched(&cbc2_key,ks2)) != 0)
461 { 511 {
462 printf("Key error %d\n",j); 512 printf("Key error %d\n",j);
463 err=1; 513 err=1;
464 } 514 }
465 if ((j=des_key_sched((C_Block *)cbc3_key,ks3)) != 0) 515 if ((j=des_key_sched(&cbc3_key,ks3)) != 0)
466 { 516 {
467 printf("Key error %d\n",j); 517 printf("Key error %d\n",j);
468 err=1; 518 err=1;
@@ -473,11 +523,9 @@ char *argv[];
473 /* i=((i+7)/8)*8; */ 523 /* i=((i+7)/8)*8; */
474 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 524 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
475 525
476 des_ede3_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, 526 des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,DES_ENCRYPT);
477 16L,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT); 527 des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3,
478 des_ede3_cbc_encrypt((C_Block *)&(cbc_data[16]), 528 &iv3,DES_ENCRYPT);
479 (C_Block *)&(cbc_out[16]),
480 (long)i-16,ks,ks2,ks3,(C_Block *)iv3,DES_ENCRYPT);
481 if (memcmp(cbc_out,cbc3_ok, 529 if (memcmp(cbc_out,cbc3_ok,
482 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0) 530 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
483 { 531 {
@@ -486,9 +534,8 @@ char *argv[];
486 } 534 }
487 535
488 memcpy(iv3,cbc_iv,sizeof(cbc_iv)); 536 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
489 des_ede3_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, 537 des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT);
490 (long)i,ks,ks2,ks3,(C_Block *)iv3,DES_DECRYPT); 538 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
491 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
492 { 539 {
493 printf("des_ede3_cbc_encrypt decrypt error\n"); 540 printf("des_ede3_cbc_encrypt decrypt error\n");
494 err=1; 541 err=1;
@@ -496,23 +543,23 @@ char *argv[];
496 543
497#ifndef LIBDES_LIT 544#ifndef LIBDES_LIT
498 printf("Doing pcbc\n"); 545 printf("Doing pcbc\n");
499 if ((j=des_key_sched((C_Block *)cbc_key,ks)) != 0) 546 if ((j=des_key_sched(&cbc_key,ks)) != 0)
500 { 547 {
501 printf("Key error %d\n",j); 548 printf("Key error %d\n",j);
502 err=1; 549 err=1;
503 } 550 }
504 memset(cbc_out,0,40); 551 memset(cbc_out,0,40);
505 memset(cbc_in,0,40); 552 memset(cbc_in,0,40);
506 des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out, 553 des_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
507 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_ENCRYPT); 554 &cbc_iv,DES_ENCRYPT);
508 if (memcmp(cbc_out,pcbc_ok,32) != 0) 555 if (memcmp(cbc_out,pcbc_ok,32) != 0)
509 { 556 {
510 printf("pcbc_encrypt encrypt error\n"); 557 printf("pcbc_encrypt encrypt error\n");
511 err=1; 558 err=1;
512 } 559 }
513 des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in, 560 des_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,&cbc_iv,
514 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv,DES_DECRYPT); 561 DES_DECRYPT);
515 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0) 562 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
516 { 563 {
517 printf("pcbc_encrypt decrypt error\n"); 564 printf("pcbc_encrypt decrypt error\n");
518 err=1; 565 err=1;
@@ -536,7 +583,7 @@ char *argv[];
536 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 583 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
537 for (i=0; i<sizeof(plain); i++) 584 for (i=0; i<sizeof(plain); i++)
538 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]), 585 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
539 8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT); 586 8,1,ks,&cfb_tmp,DES_ENCRYPT);
540 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0) 587 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
541 { 588 {
542 printf("cfb_encrypt small encrypt error\n"); 589 printf("cfb_encrypt small encrypt error\n");
@@ -546,7 +593,7 @@ char *argv[];
546 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 593 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
547 for (i=0; i<sizeof(plain); i++) 594 for (i=0; i<sizeof(plain); i++)
548 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]), 595 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
549 8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT); 596 8,1,ks,&cfb_tmp,DES_DECRYPT);
550 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) 597 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
551 { 598 {
552 printf("cfb_encrypt small decrypt error\n"); 599 printf("cfb_encrypt small decrypt error\n");
@@ -559,10 +606,9 @@ char *argv[];
559 printf("done\n"); 606 printf("done\n");
560 607
561 printf("Doing ofb\n"); 608 printf("Doing ofb\n");
562 des_key_sched((C_Block *)ofb_key,ks); 609 des_key_sched(&ofb_key,ks);
563 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 610 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
564 des_ofb_encrypt(plain,ofb_buf1,64,(long)sizeof(plain)/8,ks, 611 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
565 (C_Block *)ofb_tmp);
566 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) 612 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
567 { 613 {
568 printf("ofb_encrypt encrypt error\n"); 614 printf("ofb_encrypt encrypt error\n");
@@ -575,8 +621,7 @@ ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
575 err=1; 621 err=1;
576 } 622 }
577 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 623 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
578 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks, 624 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp);
579 (C_Block *)ofb_tmp);
580 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) 625 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
581 { 626 {
582 printf("ofb_encrypt decrypt error\n"); 627 printf("ofb_encrypt decrypt error\n");
@@ -590,15 +635,15 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
590 } 635 }
591 636
592 printf("Doing ofb64\n"); 637 printf("Doing ofb64\n");
593 des_key_sched((C_Block *)ofb_key,ks); 638 des_key_sched(&ofb_key,ks);
594 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 639 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
595 memset(ofb_buf1,0,sizeof(ofb_buf1)); 640 memset(ofb_buf1,0,sizeof(ofb_buf1));
596 memset(ofb_buf2,0,sizeof(ofb_buf1)); 641 memset(ofb_buf2,0,sizeof(ofb_buf1));
597 num=0; 642 num=0;
598 for (i=0; i<sizeof(plain); i++) 643 for (i=0; i<sizeof(plain); i++)
599 { 644 {
600 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks, 645 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,&ofb_tmp,
601 (C_Block *)ofb_tmp,&num); 646 &num);
602 } 647 }
603 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) 648 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
604 { 649 {
@@ -607,8 +652,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
607 } 652 }
608 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 653 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
609 num=0; 654 num=0;
610 des_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, 655 des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,&ofb_tmp,&num);
611 (C_Block *)ofb_tmp,&num);
612 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) 656 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
613 { 657 {
614 printf("ofb64_encrypt decrypt error\n"); 658 printf("ofb64_encrypt decrypt error\n");
@@ -616,7 +660,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
616 } 660 }
617 661
618 printf("Doing ede_ofb64\n"); 662 printf("Doing ede_ofb64\n");
619 des_key_sched((C_Block *)ofb_key,ks); 663 des_key_sched(&ofb_key,ks);
620 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 664 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
621 memset(ofb_buf1,0,sizeof(ofb_buf1)); 665 memset(ofb_buf1,0,sizeof(ofb_buf1));
622 memset(ofb_buf2,0,sizeof(ofb_buf1)); 666 memset(ofb_buf2,0,sizeof(ofb_buf1));
@@ -624,7 +668,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
624 for (i=0; i<sizeof(plain); i++) 668 for (i=0; i<sizeof(plain); i++)
625 { 669 {
626 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks, 670 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,ks,
627 (C_Block *)ofb_tmp,&num); 671 &ofb_tmp,&num);
628 } 672 }
629 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0) 673 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
630 { 674 {
@@ -633,8 +677,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
633 } 677 }
634 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv)); 678 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
635 num=0; 679 num=0;
636 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,(long)sizeof(ofb_buf1),ks, 680 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,
637 ks,ks,(C_Block *)ofb_tmp,&num); 681 ks,ks,&ofb_tmp,&num);
638 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0) 682 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
639 { 683 {
640 printf("ede_ofb64_encrypt decrypt error\n"); 684 printf("ede_ofb64_encrypt decrypt error\n");
@@ -642,9 +686,8 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
642 } 686 }
643 687
644 printf("Doing cbc_cksum\n"); 688 printf("Doing cbc_cksum\n");
645 des_key_sched((C_Block *)cbc_key,ks); 689 des_key_sched(&cbc_key,ks);
646 cs=des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cret, 690 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
647 (long)strlen(cbc_data),ks,(C_Block *)cbc_iv);
648 if (cs != cbc_cksum_ret) 691 if (cs != cbc_cksum_ret)
649 { 692 {
650 printf("bad return value (%08lX), should be %08lX\n", 693 printf("bad return value (%08lX), should be %08lX\n",
@@ -658,19 +701,26 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
658 } 701 }
659 702
660 printf("Doing quad_cksum\n"); 703 printf("Doing quad_cksum\n");
661 cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret, 704 /* This is obviously done this way especially to puzzle me. Although
662 (long)strlen(cbc_data),2,(C_Block *)cbc_iv); 705 quad_cksum returns up to 4 groups of 8 bytes, this test gets it to
706 produce 2 groups then treats them as 4 groups of 4 bytes.
707 Ben 13 Feb 1999 */
708 cs=quad_cksum(cbc_data,(des_cblock *)qret,strlen((char *)cbc_data),2,
709 &cbc_iv);
710
711 { /* Big-endian fix */
712 static DES_LONG l=1;
713 static unsigned char *c=(unsigned char *)&l;
714 DES_LONG ll;
715
663 j=sizeof(lqret[0])-4; 716 j=sizeof(lqret[0])-4;
664 for (i=0; i<4; i++) 717 for (i=0; i<4; i++)
665 { 718 {
666 lqret[i]=0; 719 lqret[i]=0;
667 memcpy(&(lqret[i]),&(qret[i][0]),4); 720 memcpy(&(lqret[i]),&(qret[i][0]),4);
668 if (j > 0) lqret[i]=lqret[i]>>(j*8); /* For Cray */ 721 if (!c[0] && (j > 0))
722 lqret[i]=lqret[i]>>(j*8); /* For Cray */
669 } 723 }
670 { /* Big-endian fix */
671 static DES_LONG l=1;
672 static unsigned char *c=(unsigned char *)&l;
673 DES_LONG ll;
674 724
675 if (!c[0]) 725 if (!c[0])
676 { 726 {
@@ -691,25 +741,25 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
691 if (lqret[0] != 0x327eba8dL) 741 if (lqret[0] != 0x327eba8dL)
692 { 742 {
693 printf("quad_cksum error, out[0] %08lx is not %08lx\n", 743 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
694 (unsigned long)lqret[0],0x327eba8dL); 744 (unsigned long)lqret[0],0x327eba8dUL);
695 err=1; 745 err=1;
696 } 746 }
697 if (lqret[1] != 0x201a49ccL) 747 if (lqret[1] != 0x201a49ccL)
698 { 748 {
699 printf("quad_cksum error, out[1] %08lx is not %08lx\n", 749 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
700 (unsigned long)lqret[1],0x201a49ccL); 750 (unsigned long)lqret[1],0x201a49ccUL);
701 err=1; 751 err=1;
702 } 752 }
703 if (lqret[2] != 0x70d7a63aL) 753 if (lqret[2] != 0x70d7a63aL)
704 { 754 {
705 printf("quad_cksum error, out[2] %08lx is not %08lx\n", 755 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
706 (unsigned long)lqret[2],0x70d7a63aL); 756 (unsigned long)lqret[2],0x70d7a63aUL);
707 err=1; 757 err=1;
708 } 758 }
709 if (lqret[3] != 0x501c2c26L) 759 if (lqret[3] != 0x501c2c26L)
710 { 760 {
711 printf("quad_cksum error, out[3] %08lx is not %08lx\n", 761 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
712 (unsigned long)lqret[3],0x501c2c26L); 762 (unsigned long)lqret[3],0x501c2c26UL);
713 err=1; 763 err=1;
714 } 764 }
715#endif 765#endif
@@ -718,17 +768,17 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
718 for (i=0; i<4; i++) 768 for (i=0; i<4; i++)
719 { 769 {
720 printf(" %d",i); 770 printf(" %d",i);
721 des_ncbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in, 771 des_ncbc_encrypt(&(cbc_out[i]),cbc_in,
722 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, 772 strlen((char *)cbc_data)+1,ks,
723 DES_ENCRYPT); 773 &cbc_iv,DES_ENCRYPT);
724 } 774 }
725 printf("\noutput word alignment test"); 775 printf("\noutput word alignment test");
726 for (i=0; i<4; i++) 776 for (i=0; i<4; i++)
727 { 777 {
728 printf(" %d",i); 778 printf(" %d",i);
729 des_ncbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]), 779 des_ncbc_encrypt(cbc_out,&(cbc_in[i]),
730 (long)strlen(cbc_data)+1,ks,(C_Block *)cbc_iv, 780 strlen((char *)cbc_data)+1,ks,
731 DES_ENCRYPT); 781 &cbc_iv,DES_ENCRYPT);
732 } 782 }
733 printf("\n"); 783 printf("\n");
734 printf("fast crypt test "); 784 printf("fast crypt test ");
@@ -749,8 +799,7 @@ plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
749 return(0); 799 return(0);
750 } 800 }
751 801
752static char *pt(p) 802static char *pt(unsigned char *p)
753unsigned char *p;
754 { 803 {
755 static char bufs[10][20]; 804 static char bufs[10][20];
756 static int bnum=0; 805 static int bnum=0;
@@ -771,17 +820,15 @@ unsigned char *p;
771 820
772#ifndef LIBDES_LIT 821#ifndef LIBDES_LIT
773 822
774static int cfb_test(bits, cfb_cipher) 823static int cfb_test(int bits, unsigned char *cfb_cipher)
775int bits;
776unsigned char *cfb_cipher;
777 { 824 {
778 des_key_schedule ks; 825 des_key_schedule ks;
779 int i,err=0; 826 int i,err=0;
780 827
781 des_key_sched((C_Block *)cfb_key,ks); 828 des_key_sched(&cfb_key,ks);
782 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 829 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
783 des_cfb_encrypt(plain,cfb_buf1,bits,(long)sizeof(plain),ks, 830 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
784 (C_Block *)cfb_tmp,DES_ENCRYPT); 831 DES_ENCRYPT);
785 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) 832 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
786 { 833 {
787 err=1; 834 err=1;
@@ -790,8 +837,8 @@ unsigned char *cfb_cipher;
790 printf("%s\n",pt(&(cfb_buf1[i]))); 837 printf("%s\n",pt(&(cfb_buf1[i])));
791 } 838 }
792 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 839 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
793 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,(long)sizeof(plain),ks, 840 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp,
794 (C_Block *)cfb_tmp,DES_DECRYPT); 841 DES_DECRYPT);
795 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) 842 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
796 { 843 {
797 err=1; 844 err=1;
@@ -802,20 +849,17 @@ unsigned char *cfb_cipher;
802 return(err); 849 return(err);
803 } 850 }
804 851
805static int cfb64_test(cfb_cipher) 852static int cfb64_test(unsigned char *cfb_cipher)
806unsigned char *cfb_cipher;
807 { 853 {
808 des_key_schedule ks; 854 des_key_schedule ks;
809 int err=0,i,n; 855 int err=0,i,n;
810 856
811 des_key_sched((C_Block *)cfb_key,ks); 857 des_key_sched(&cfb_key,ks);
812 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 858 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
813 n=0; 859 n=0;
814 des_cfb64_encrypt(plain,cfb_buf1,(long)12,ks, 860 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
815 (C_Block *)cfb_tmp,&n,DES_ENCRYPT); 861 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
816 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), 862 &cfb_tmp,&n,DES_ENCRYPT);
817 (long)sizeof(plain)-12,ks,
818 (C_Block *)cfb_tmp,&n,DES_ENCRYPT);
819 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) 863 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
820 { 864 {
821 err=1; 865 err=1;
@@ -825,11 +869,9 @@ unsigned char *cfb_cipher;
825 } 869 }
826 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 870 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
827 n=0; 871 n=0;
828 des_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks, 872 des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT);
829 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
830 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), 873 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
831 (long)sizeof(plain)-17,ks, 874 sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT);
832 (C_Block *)cfb_tmp,&n,DES_DECRYPT);
833 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) 875 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
834 { 876 {
835 err=1; 877 err=1;
@@ -840,20 +882,19 @@ unsigned char *cfb_cipher;
840 return(err); 882 return(err);
841 } 883 }
842 884
843static int ede_cfb64_test(cfb_cipher) 885static int ede_cfb64_test(unsigned char *cfb_cipher)
844unsigned char *cfb_cipher;
845 { 886 {
846 des_key_schedule ks; 887 des_key_schedule ks;
847 int err=0,i,n; 888 int err=0,i,n;
848 889
849 des_key_sched((C_Block *)cfb_key,ks); 890 des_key_sched(&cfb_key,ks);
850 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 891 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
851 n=0; 892 n=0;
852 des_ede3_cfb64_encrypt(plain,cfb_buf1,(long)12,ks,ks,ks, 893 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
853 (C_Block *)cfb_tmp,&n,DES_ENCRYPT); 894 DES_ENCRYPT);
854 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]), 895 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
855 (long)sizeof(plain)-12,ks,ks,ks, 896 sizeof(plain)-12,ks,ks,ks,
856 (C_Block *)cfb_tmp,&n,DES_ENCRYPT); 897 &cfb_tmp,&n,DES_ENCRYPT);
857 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0) 898 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
858 { 899 {
859 err=1; 900 err=1;
@@ -864,10 +905,10 @@ unsigned char *cfb_cipher;
864 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv)); 905 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
865 n=0; 906 n=0;
866 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks, 907 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
867 (C_Block *)cfb_tmp,&n,DES_DECRYPT); 908 &cfb_tmp,&n,DES_DECRYPT);
868 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]), 909 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
869 (long)sizeof(plain)-17,ks,ks,ks, 910 sizeof(plain)-17,ks,ks,ks,
870 (C_Block *)cfb_tmp,&n,DES_DECRYPT); 911 &cfb_tmp,&n,DES_DECRYPT);
871 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0) 912 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
872 { 913 {
873 err=1; 914 err=1;
@@ -879,4 +920,4 @@ unsigned char *cfb_cipher;
879 } 920 }
880 921
881#endif 922#endif
882 923#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 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_ecb3_encrypt(input, output, ks1, ks2, ks3, enc) 61void des_ecb3_encrypt(const_des_cblock *input, des_cblock *output,
62des_cblock (*input); 62 des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3,
63des_cblock (*output); 63 int enc)
64des_key_schedule ks1;
65des_key_schedule ks2;
66des_key_schedule ks3;
67int enc;
68 { 64 {
69 register DES_LONG l0,l1; 65 register DES_LONG l0,l1;
70 register unsigned char *in,*out;
71 DES_LONG ll[2]; 66 DES_LONG ll[2];
67 const unsigned char *in = &(*input)[0];
68 unsigned char *out = &(*output)[0];
72 69
73 in=(unsigned char *)input;
74 out=(unsigned char *)output;
75 c2l(in,l0); 70 c2l(in,l0);
76 c2l(in,l1); 71 c2l(in,l1);
77 ll[0]=l0; 72 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 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60#include "spr.h" 60#include "spr.h"
61#include <openssl/opensslv.h>
61 62
62char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; 63OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT;
63char *DES_version="DES part of SSLeay 0.9.0b 29-Jun-1998"; 64OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT;
64 65
65char *des_options() 66const char *des_options(void)
66 { 67 {
67 static int init=1; 68 static int init=1;
68 static char buf[32]; 69 static char buf[32];
69 70
70 if (init) 71 if (init)
71 { 72 {
72 char *ptr,*unroll,*risc,*size; 73 const char *ptr,*unroll,*risc,*size;
73 74
74 init=0;
75#ifdef DES_PTR 75#ifdef DES_PTR
76 ptr="ptr"; 76 ptr="ptr";
77#else 77#else
@@ -97,23 +97,21 @@ char *des_options()
97 else 97 else
98 size="long"; 98 size="long";
99 sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size); 99 sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size);
100 init=0;
100 } 101 }
101 return(buf); 102 return(buf);
102 } 103 }
103 104
104 105
105void des_ecb_encrypt(input, output, ks, enc) 106void des_ecb_encrypt(const_des_cblock *input, des_cblock *output,
106des_cblock (*input); 107 des_key_schedule ks,
107des_cblock (*output); 108 int enc)
108des_key_schedule ks;
109int enc;
110 { 109 {
111 register DES_LONG l; 110 register DES_LONG l;
112 register unsigned char *in,*out;
113 DES_LONG ll[2]; 111 DES_LONG ll[2];
112 const unsigned char *in = &(*input)[0];
113 unsigned char *out = &(*output)[0];
114 114
115 in=(unsigned char *)input;
116 out=(unsigned char *)output;
117 c2l(in,l); ll[0]=l; 115 c2l(in,l); ll[0]=l;
118 c2l(in,l); ll[1]=l; 116 c2l(in,l); ll[1]=l;
119 des_encrypt(ll,ks,enc); 117 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 @@
1/* ede_cbcm_enc.c */
2/* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL
3 * project 13 Feb 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/*
60
61This is an implementation of Triple DES Cipher Block Chaining with Output
62Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom).
63
64Note that there is a known attack on this by Biham and Knudsen but it takes
65a lot of work:
66
67http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
68
69*/
70
71#ifndef NO_DESCBCM
72#include "des_locl.h"
73
74void des_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out,
75 long length, des_key_schedule ks1, des_key_schedule ks2,
76 des_key_schedule ks3, des_cblock *ivec1, des_cblock *ivec2,
77 int enc)
78 {
79 register DES_LONG tin0,tin1;
80 register DES_LONG tout0,tout1,xor0,xor1,m0,m1;
81 register long l=length;
82 DES_LONG tin[2];
83 unsigned char *iv1,*iv2;
84
85 iv1 = &(*ivec1)[0];
86 iv2 = &(*ivec2)[0];
87
88 if (enc)
89 {
90 c2l(iv1,m0);
91 c2l(iv1,m1);
92 c2l(iv2,tout0);
93 c2l(iv2,tout1);
94 for (l-=8; l>=-7; l-=8)
95 {
96 tin[0]=m0;
97 tin[1]=m1;
98 des_encrypt(tin,ks3,1);
99 m0=tin[0];
100 m1=tin[1];
101
102 if(l < 0)
103 {
104 c2ln(in,tin0,tin1,l+8);
105 }
106 else
107 {
108 c2l(in,tin0);
109 c2l(in,tin1);
110 }
111 tin0^=tout0;
112 tin1^=tout1;
113
114 tin[0]=tin0;
115 tin[1]=tin1;
116 des_encrypt(tin,ks1,1);
117 tin[0]^=m0;
118 tin[1]^=m1;
119 des_encrypt(tin,ks2,0);
120 tin[0]^=m0;
121 tin[1]^=m1;
122 des_encrypt(tin,ks1,1);
123 tout0=tin[0];
124 tout1=tin[1];
125
126 l2c(tout0,out);
127 l2c(tout1,out);
128 }
129 iv1=&(*ivec1)[0];
130 l2c(m0,iv1);
131 l2c(m1,iv1);
132
133 iv2=&(*ivec2)[0];
134 l2c(tout0,iv2);
135 l2c(tout1,iv2);
136 }
137 else
138 {
139 register DES_LONG t0,t1;
140
141 c2l(iv1,m0);
142 c2l(iv1,m1);
143 c2l(iv2,xor0);
144 c2l(iv2,xor1);
145 for (l-=8; l>=-7; l-=8)
146 {
147 tin[0]=m0;
148 tin[1]=m1;
149 des_encrypt(tin,ks3,1);
150 m0=tin[0];
151 m1=tin[1];
152
153 c2l(in,tin0);
154 c2l(in,tin1);
155
156 t0=tin0;
157 t1=tin1;
158
159 tin[0]=tin0;
160 tin[1]=tin1;
161 des_encrypt(tin,ks1,0);
162 tin[0]^=m0;
163 tin[1]^=m1;
164 des_encrypt(tin,ks2,1);
165 tin[0]^=m0;
166 tin[1]^=m1;
167 des_encrypt(tin,ks1,0);
168 tout0=tin[0];
169 tout1=tin[1];
170
171 tout0^=xor0;
172 tout1^=xor1;
173 if(l < 0)
174 {
175 l2cn(tout0,tout1,out,l+8);
176 }
177 else
178 {
179 l2c(tout0,out);
180 l2c(tout1,out);
181 }
182 xor0=t0;
183 xor1=t1;
184 }
185
186 iv1=&(*ivec1)[0];
187 l2c(m0,iv1);
188 l2c(m1,iv1);
189
190 iv2=&(*ivec2)[0];
191 l2c(xor0,iv2);
192 l2c(xor1,iv2);
193 }
194 tin0=tin1=tout0=tout1=xor0=xor1=0;
195 tin[0]=tin[1]=0;
196 }
197#endif
diff --git a/src/lib/libcrypto/des/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 @@
1/* crypto/des/ede_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc)
62des_cblock (*input);
63des_cblock (*output);
64long length;
65des_key_schedule ks1;
66des_key_schedule ks2;
67des_key_schedule ks3;
68des_cblock (*ivec);
69int enc;
70 {
71 register DES_LONG tin0,tin1;
72 register DES_LONG tout0,tout1,xor0,xor1;
73 register unsigned char *in,*out;
74 register long l=length;
75 DES_LONG tin[2];
76 unsigned char *iv;
77
78 in=(unsigned char *)input;
79 out=(unsigned char *)output;
80 iv=(unsigned char *)ivec;
81
82 if (enc)
83 {
84 c2l(iv,tout0);
85 c2l(iv,tout1);
86 for (l-=8; l>=0; l-=8)
87 {
88 c2l(in,tin0);
89 c2l(in,tin1);
90 tin0^=tout0;
91 tin1^=tout1;
92
93 tin[0]=tin0;
94 tin[1]=tin1;
95 des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
96 tout0=tin[0];
97 tout1=tin[1];
98
99 l2c(tout0,out);
100 l2c(tout1,out);
101 }
102 if (l != -8)
103 {
104 c2ln(in,tin0,tin1,l+8);
105 tin0^=tout0;
106 tin1^=tout1;
107
108 tin[0]=tin0;
109 tin[1]=tin1;
110 des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3);
111 tout0=tin[0];
112 tout1=tin[1];
113
114 l2c(tout0,out);
115 l2c(tout1,out);
116 }
117 iv=(unsigned char *)ivec;
118 l2c(tout0,iv);
119 l2c(tout1,iv);
120 }
121 else
122 {
123 register DES_LONG t0,t1;
124
125 c2l(iv,xor0);
126 c2l(iv,xor1);
127 for (l-=8; l>=0; l-=8)
128 {
129 c2l(in,tin0);
130 c2l(in,tin1);
131
132 t0=tin0;
133 t1=tin1;
134
135 tin[0]=tin0;
136 tin[1]=tin1;
137 des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
138 tout0=tin[0];
139 tout1=tin[1];
140
141 tout0^=xor0;
142 tout1^=xor1;
143 l2c(tout0,out);
144 l2c(tout1,out);
145 xor0=t0;
146 xor1=t1;
147 }
148 if (l != -8)
149 {
150 c2l(in,tin0);
151 c2l(in,tin1);
152
153 t0=tin0;
154 t1=tin1;
155
156 tin[0]=tin0;
157 tin[1]=tin1;
158 des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3);
159 tout0=tin[0];
160 tout1=tin[1];
161
162 tout0^=xor0;
163 tout1^=xor1;
164 l2cn(tout0,tout1,out,l+8);
165 xor0=t0;
166 xor1=t1;
167 }
168
169 iv=(unsigned char *)ivec;
170 l2c(xor0,iv);
171 l2c(xor1,iv);
172 }
173 tin0=tin1=tout0=tout1=xor0=xor1=0;
174 tin[0]=tin[1]=0;
175 }
176
177#ifdef undef /* MACRO */
178void des_ede2_cbc_encrypt(input, output, length, ks1, ks2, ivec, enc)
179des_cblock (*input);
180des_cblock (*output);
181long length;
182des_key_schedule ks1;
183des_key_schedule ks2;
184des_cblock (*ivec);
185int enc;
186 {
187 des_ede3_cbc_encrypt(input,output,length,ks1,ks2,ks1,ivec,enc);
188 }
189#endif
190
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h"
61#include "des_locl.h" 62#include "des_locl.h"
62 63
63/* This has some uglies in it but it works - even over sockets. */ 64/* This has some uglies in it but it works - even over sockets. */
64/*extern int errno;*/ 65/*extern int errno;*/
65int des_rw_mode=DES_PCBC_MODE; 66OPENSSL_GLOBAL int des_rw_mode=DES_PCBC_MODE;
66 67
67int des_enc_read(fd, buf, len, sched, iv) 68
68int fd; 69/*
69char *buf; 70 * WARNINGS:
70int len; 71 *
71des_key_schedule sched; 72 * - The data format used by des_enc_write() and des_enc_read()
72des_cblock (*iv); 73 * has a cryptographic weakness: When asked to write more
74 * than MAXWRITE bytes, des_enc_write will split the data
75 * into several chunks that are all encrypted
76 * using the same IV. So don't use these functions unless you
77 * are sure you know what you do (in which case you might
78 * not want to use them anyway).
79 *
80 * - This code cannot handle non-blocking sockets.
81 *
82 * - This function uses an internal state and thus cannot be
83 * used on multiple files.
84 */
85
86
87int des_enc_read(int fd, void *buf, int len, des_key_schedule sched,
88 des_cblock *iv)
73 { 89 {
74 /* data to be unencrypted */ 90 /* data to be unencrypted */
75 int net_num=0; 91 int net_num=0;
@@ -77,27 +93,27 @@ des_cblock (*iv);
77 /* extra unencrypted data 93 /* extra unencrypted data
78 * for when a block of 100 comes in but is des_read one byte at 94 * for when a block of 100 comes in but is des_read one byte at
79 * a time. */ 95 * a time. */
80 static char *unnet=NULL; 96 static unsigned char *unnet=NULL;
81 static int unnet_start=0; 97 static int unnet_start=0;
82 static int unnet_left=0; 98 static int unnet_left=0;
83 static char *tmpbuf=NULL; 99 static unsigned char *tmpbuf=NULL;
84 int i; 100 int i;
85 long num=0,rnum; 101 long num=0,rnum;
86 unsigned char *p; 102 unsigned char *p;
87 103
88 if (tmpbuf == NULL) 104 if (tmpbuf == NULL)
89 { 105 {
90 tmpbuf=(char *)malloc(BSIZE); 106 tmpbuf=Malloc(BSIZE);
91 if (tmpbuf == NULL) return(-1); 107 if (tmpbuf == NULL) return(-1);
92 } 108 }
93 if (net == NULL) 109 if (net == NULL)
94 { 110 {
95 net=(unsigned char *)malloc(BSIZE); 111 net=Malloc(BSIZE);
96 if (net == NULL) return(-1); 112 if (net == NULL) return(-1);
97 } 113 }
98 if (unnet == NULL) 114 if (unnet == NULL)
99 { 115 {
100 unnet=(char *)malloc(BSIZE); 116 unnet=Malloc(BSIZE);
101 if (unnet == NULL) return(-1); 117 if (unnet == NULL) return(-1);
102 } 118 }
103 /* left over data from last decrypt */ 119 /* left over data from last decrypt */
@@ -109,7 +125,7 @@ des_cblock (*iv);
109 * with the number of bytes we have - should always 125 * with the number of bytes we have - should always
110 * check the return value */ 126 * check the return value */
111 memcpy(buf,&(unnet[unnet_start]), 127 memcpy(buf,&(unnet[unnet_start]),
112 (unsigned int)unnet_left); 128 unnet_left);
113 /* eay 26/08/92 I had the next 2 lines 129 /* eay 26/08/92 I had the next 2 lines
114 * reversed :-( */ 130 * reversed :-( */
115 i=unnet_left; 131 i=unnet_left;
@@ -117,7 +133,7 @@ des_cblock (*iv);
117 } 133 }
118 else 134 else
119 { 135 {
120 memcpy(buf,&(unnet[unnet_start]),(unsigned int)len); 136 memcpy(buf,&(unnet[unnet_start]),len);
121 unnet_start+=len; 137 unnet_start+=len;
122 unnet_left-=len; 138 unnet_left-=len;
123 i=len; 139 i=len;
@@ -131,7 +147,7 @@ des_cblock (*iv);
131 /* first - get the length */ 147 /* first - get the length */
132 while (net_num < HDRSIZE) 148 while (net_num < HDRSIZE)
133 { 149 {
134 i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num); 150 i=read(fd,&(net[net_num]),HDRSIZE-net_num);
135#ifdef EINTR 151#ifdef EINTR
136 if ((i == -1) && (errno == EINTR)) continue; 152 if ((i == -1) && (errno == EINTR)) continue;
137#endif 153#endif
@@ -153,7 +169,7 @@ des_cblock (*iv);
153 net_num=0; 169 net_num=0;
154 while (net_num < rnum) 170 while (net_num < rnum)
155 { 171 {
156 i=read(fd,&(net[net_num]),(unsigned int)rnum-net_num); 172 i=read(fd,&(net[net_num]),rnum-net_num);
157#ifdef EINTR 173#ifdef EINTR
158 if ((i == -1) && (errno == EINTR)) continue; 174 if ((i == -1) && (errno == EINTR)) continue;
159#endif 175#endif
@@ -165,14 +181,12 @@ des_cblock (*iv);
165 if (len < num) 181 if (len < num)
166 { 182 {
167 if (des_rw_mode & DES_PCBC_MODE) 183 if (des_rw_mode & DES_PCBC_MODE)
168 des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet, 184 des_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
169 num,sched,iv,DES_DECRYPT);
170 else 185 else
171 des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet, 186 des_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT);
172 num,sched,iv,DES_DECRYPT); 187 memcpy(buf,unnet,len);
173 memcpy(buf,unnet,(unsigned int)len);
174 unnet_start=len; 188 unnet_start=len;
175 unnet_left=(int)num-len; 189 unnet_left=num-len;
176 190
177 /* The following line is done because we return num 191 /* The following line is done because we return num
178 * as the number of bytes read. */ 192 * as the number of bytes read. */
@@ -189,30 +203,26 @@ des_cblock (*iv);
189 { 203 {
190 204
191 if (des_rw_mode & DES_PCBC_MODE) 205 if (des_rw_mode & DES_PCBC_MODE)
192 des_pcbc_encrypt((des_cblock *)net, 206 des_pcbc_encrypt(net,tmpbuf,num,sched,iv,
193 (des_cblock *)tmpbuf, 207 DES_DECRYPT);
194 num,sched,iv,DES_DECRYPT);
195 else 208 else
196 des_cbc_encrypt((des_cblock *)net, 209 des_cbc_encrypt(net,tmpbuf,num,sched,iv,
197 (des_cblock *)tmpbuf, 210 DES_DECRYPT);
198 num,sched,iv,DES_DECRYPT);
199 211
200 /* eay 26/08/92 fix a bug that returned more 212 /* eay 26/08/92 fix a bug that returned more
201 * bytes than you asked for (returned len bytes :-( */ 213 * bytes than you asked for (returned len bytes :-( */
202 memcpy(buf,tmpbuf,(unsigned int)num); 214 memcpy(buf,tmpbuf,num);
203 } 215 }
204 else 216 else
205 { 217 {
206 if (des_rw_mode & DES_PCBC_MODE) 218 if (des_rw_mode & DES_PCBC_MODE)
207 des_pcbc_encrypt((des_cblock *)net, 219 des_pcbc_encrypt(net,buf,num,sched,iv,
208 (des_cblock *)buf,num,sched,iv, 220 DES_DECRYPT);
209 DES_DECRYPT);
210 else 221 else
211 des_cbc_encrypt((des_cblock *)net, 222 des_cbc_encrypt(net,buf,num,sched,iv,
212 (des_cblock *)buf,num,sched,iv, 223 DES_DECRYPT);
213 DES_DECRYPT);
214 } 224 }
215 } 225 }
216 return((int)num); 226 return num;
217 } 227 }
218 228
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 @@
58 58
59#include <errno.h> 59#include <errno.h>
60#include <time.h> 60#include <time.h>
61#include <stdio.h>
62#include "cryptlib.h"
61#include "des_locl.h" 63#include "des_locl.h"
64#include <openssl/rand.h>
62 65
63int des_enc_write(fd, buf, len, sched, iv) 66/*
64int fd; 67 * WARNINGS:
65char *buf; 68 *
66int len; 69 * - The data format used by des_enc_write() and des_enc_read()
67des_key_schedule sched; 70 * has a cryptographic weakness: When asked to write more
68des_cblock (*iv); 71 * than MAXWRITE bytes, des_enc_write will split the data
72 * into several chunks that are all encrypted
73 * using the same IV. So don't use these functions unless you
74 * are sure you know what you do (in which case you might
75 * not want to use them anyway).
76 *
77 * - This code cannot handle non-blocking sockets.
78 */
79
80int des_enc_write(int fd, const void *_buf, int len,
81 des_key_schedule sched, des_cblock *iv)
69 { 82 {
70#ifdef _LIBC 83#ifdef _LIBC
71 extern int srandom();
72 extern unsigned long time(); 84 extern unsigned long time();
73 extern int random();
74 extern int write(); 85 extern int write();
75#endif 86#endif
76 87 const unsigned char *buf=_buf;
77 long rnum; 88 long rnum;
78 int i,j,k,outnum; 89 int i,j,k,outnum;
79 static char *outbuf=NULL; 90 static unsigned char *outbuf=NULL;
80 char shortbuf[8]; 91 unsigned char shortbuf[8];
81 char *p; 92 unsigned char *p;
93 const unsigned char *cp;
82 static int start=1; 94 static int start=1;
83 95
84 if (outbuf == NULL) 96 if (outbuf == NULL)
85 { 97 {
86 outbuf=(char *)malloc(BSIZE+HDRSIZE); 98 outbuf=Malloc(BSIZE+HDRSIZE);
87 if (outbuf == NULL) return(-1); 99 if (outbuf == NULL) return(-1);
88 } 100 }
89 /* If we are sending less than 8 bytes, the same char will look 101 /* If we are sending less than 8 bytes, the same char will look
@@ -91,7 +103,6 @@ des_cblock (*iv);
91 if (start) 103 if (start)
92 { 104 {
93 start=0; 105 start=0;
94 srandom((unsigned int)time(NULL));
95 } 106 }
96 107
97 /* lets recurse if we want to send the data in small chunks */ 108 /* lets recurse if we want to send the data in small chunks */
@@ -117,35 +128,32 @@ des_cblock (*iv);
117 /* pad short strings */ 128 /* pad short strings */
118 if (len < 8) 129 if (len < 8)
119 { 130 {
120 p=shortbuf; 131 cp=shortbuf;
121 memcpy(shortbuf,buf,(unsigned int)len); 132 memcpy(shortbuf,buf,len);
122 for (i=len; i<8; i++) 133 RAND_bytes(shortbuf+len, 8-len);
123 shortbuf[i]=random();
124 rnum=8; 134 rnum=8;
125 } 135 }
126 else 136 else
127 { 137 {
128 p=buf; 138 cp=(unsigned char*)buf;
129 rnum=((len+7)/8*8); /* round up to nearest eight */ 139 rnum=((len+7)/8*8); /* round up to nearest eight */
130 } 140 }
131 141
132 if (des_rw_mode & DES_PCBC_MODE) 142 if (des_rw_mode & DES_PCBC_MODE)
133 des_pcbc_encrypt((des_cblock *)p, 143 des_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
134 (des_cblock *)&(outbuf[HDRSIZE]), 144 DES_ENCRYPT);
135 (long)((len<8)?8:len),sched,iv,DES_ENCRYPT);
136 else 145 else
137 des_cbc_encrypt((des_cblock *)p, 146 des_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv,
138 (des_cblock *)&(outbuf[HDRSIZE]), 147 DES_ENCRYPT);
139 (long)((len<8)?8:len),sched,iv,DES_ENCRYPT);
140 148
141 /* output */ 149 /* output */
142 outnum=(int)rnum+HDRSIZE; 150 outnum=rnum+HDRSIZE;
143 151
144 for (j=0; j<outnum; j+=i) 152 for (j=0; j<outnum; j+=i)
145 { 153 {
146 /* eay 26/08/92 I was not doing writing from where we 154 /* eay 26/08/92 I was not doing writing from where we
147 * got upto. */ 155 * got upto. */
148 i=write(fd,&(outbuf[j]),(unsigned int)(outnum-j)); 156 i=write(fd,&(outbuf[j]),outnum-j);
149 if (i == -1) 157 if (i == -1)
150 { 158 {
151 if (errno == EINTR) 159 if (errno == EINTR)
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c
index 1544634bc1..9cbea97c1f 100644
--- a/src/lib/libcrypto/des/fcrypt_b.c
+++ b/src/lib/libcrypto/des/fcrypt_b.c
@@ -77,15 +77,12 @@
77#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ 77#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
78 (a)=(a)^(t)^(t>>(16-(n))))\ 78 (a)=(a)^(t)^(t>>(16-(n))))\
79 79
80void fcrypt_body(out, ks, Eswap0, Eswap1) 80void fcrypt_body(DES_LONG *out, des_key_schedule ks, DES_LONG Eswap0,
81DES_LONG *out; 81 DES_LONG Eswap1)
82des_key_schedule ks;
83DES_LONG Eswap0;
84DES_LONG Eswap1;
85 { 82 {
86 register DES_LONG l,r,t,u; 83 register DES_LONG l,r,t,u;
87#ifdef DES_PTR 84#ifdef DES_PTR
88 register unsigned char *des_SP=(unsigned char *)des_SPtrans; 85 register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
89#endif 86#endif
90 register DES_LONG *s; 87 register DES_LONG *s;
91 register int j; 88 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 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) 61#ifdef CBC_ENC_C__DONT_UPDATE_IV
62des_cblock (*input); 62void des_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
63des_cblock (*output); 63 des_key_schedule schedule, des_cblock *ivec, int enc)
64long length; 64#else
65des_key_schedule schedule; 65void des_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length,
66des_cblock (*ivec); 66 des_key_schedule schedule, des_cblock *ivec, int enc)
67int enc; 67#endif
68 { 68 {
69 register DES_LONG tin0,tin1; 69 register DES_LONG tin0,tin1;
70 register DES_LONG tout0,tout1,xor0,xor1; 70 register DES_LONG tout0,tout1,xor0,xor1;
71 register unsigned char *in,*out;
72 register long l=length; 71 register long l=length;
73 DES_LONG tin[2]; 72 DES_LONG tin[2];
74 unsigned char *iv; 73 unsigned char *iv;
75 74
76 in=(unsigned char *)input; 75 iv = &(*ivec)[0];
77 out=(unsigned char *)output;
78 iv=(unsigned char *)ivec;
79 76
80 if (enc) 77 if (enc)
81 { 78 {
@@ -100,9 +97,11 @@ int enc;
100 tout0=tin[0]; l2c(tout0,out); 97 tout0=tin[0]; l2c(tout0,out);
101 tout1=tin[1]; l2c(tout1,out); 98 tout1=tin[1]; l2c(tout1,out);
102 } 99 }
103 iv=(unsigned char *)ivec; 100#ifndef CBC_ENC_C__DONT_UPDATE_IV
101 iv = &(*ivec)[0];
104 l2c(tout0,iv); 102 l2c(tout0,iv);
105 l2c(tout1,iv); 103 l2c(tout1,iv);
104#endif
106 } 105 }
107 else 106 else
108 { 107 {
@@ -120,11 +119,25 @@ int enc;
120 xor0=tin0; 119 xor0=tin0;
121 xor1=tin1; 120 xor1=tin1;
122 } 121 }
123 iv=(unsigned char *)ivec; 122 if (l != -8)
123 {
124 c2l(in,tin0); tin[0]=tin0;
125 c2l(in,tin1); tin[1]=tin1;
126 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT);
127 tout0=tin[0]^xor0;
128 tout1=tin[1]^xor1;
129 l2cn(tout0,tout1,out,l+8);
130#ifndef CBC_ENC_C__DONT_UPDATE_IV
131 xor0=tin0;
132 xor1=tin1;
133#endif
134 }
135#ifndef CBC_ENC_C__DONT_UPDATE_IV
136 iv = &(*ivec)[0];
124 l2c(xor0,iv); 137 l2c(xor0,iv);
125 l2c(xor1,iv); 138 l2c(xor1,iv);
139#endif
126 } 140 }
127 tin0=tin1=tout0=tout1=xor0=xor1=0; 141 tin0=tin1=tout0=tout1=xor0=xor1=0;
128 tin[0]=tin[1]=0; 142 tin[0]=tin[1]=0;
129 } 143 }
130
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 @@
62 * used. The extra state information to record how much of the 62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65void des_ede3_ofb64_encrypt(in, out, length, k1,k2,k3, ivec, num) 65void des_ede3_ofb64_encrypt(register const unsigned char *in,
66register unsigned char *in; 66 register unsigned char *out, long length, des_key_schedule k1,
67register unsigned char *out; 67 des_key_schedule k2, des_key_schedule k3, des_cblock *ivec,
68long length; 68 int *num)
69des_key_schedule k1,k2,k3;
70des_cblock (*ivec);
71int *num;
72 { 69 {
73 register DES_LONG v0,v1; 70 register DES_LONG v0,v1;
74 register int n= *num; 71 register int n= *num;
@@ -79,7 +76,7 @@ int *num;
79 unsigned char *iv; 76 unsigned char *iv;
80 int save=0; 77 int save=0;
81 78
82 iv=(unsigned char *)ivec; 79 iv = &(*ivec)[0];
83 c2l(iv,v0); 80 c2l(iv,v0);
84 c2l(iv,v1); 81 c2l(iv,v1);
85 ti[0]=v0; 82 ti[0]=v0;
@@ -93,7 +90,7 @@ int *num;
93 { 90 {
94 /* ti[0]=v0; */ 91 /* ti[0]=v0; */
95 /* ti[1]=v1; */ 92 /* ti[1]=v1; */
96 des_encrypt3((DES_LONG *)ti,k1,k2,k3); 93 des_encrypt3(ti,k1,k2,k3);
97 v0=ti[0]; 94 v0=ti[0];
98 v1=ti[1]; 95 v1=ti[1];
99 96
@@ -109,7 +106,7 @@ int *num;
109 { 106 {
110/* v0=ti[0]; 107/* v0=ti[0];
111 v1=ti[1];*/ 108 v1=ti[1];*/
112 iv=(unsigned char *)ivec; 109 iv = &(*ivec)[0];
113 l2c(v0,iv); 110 l2c(v0,iv);
114 l2c(v1,iv); 111 l2c(v1,iv);
115 } 112 }
@@ -118,13 +115,9 @@ int *num;
118 } 115 }
119 116
120#ifdef undef /* MACRO */ 117#ifdef undef /* MACRO */
121void des_ede2_ofb64_encrypt(in, out, length, k1,k2, ivec, num) 118void des_ede2_ofb64_encrypt(register unsigned char *in,
122register unsigned char *in; 119 register unsigned char *out, long length, des_key_schedule k1,
123register unsigned char *out; 120 des_key_schedule k2, des_cblock (*ivec), int *num)
124long length;
125des_key_schedule k1,k2;
126des_cblock (*ivec);
127int *num;
128 { 121 {
129 des_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num); 122 des_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num);
130 } 123 }
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 @@
62 * used. The extra state information to record how much of the 62 * used. The extra state information to record how much of the
63 * 64bit block we have used is contained in *num; 63 * 64bit block we have used is contained in *num;
64 */ 64 */
65void des_ofb64_encrypt(in, out, length, schedule, ivec, num) 65void des_ofb64_encrypt(register const unsigned char *in,
66register unsigned char *in; 66 register unsigned char *out, long length, des_key_schedule schedule,
67register unsigned char *out; 67 des_cblock *ivec, int *num)
68long length;
69des_key_schedule schedule;
70des_cblock (*ivec);
71int *num;
72 { 68 {
73 register DES_LONG v0,v1,t; 69 register DES_LONG v0,v1,t;
74 register int n= *num; 70 register int n= *num;
75 register long l=length; 71 register long l=length;
76 des_cblock d; 72 des_cblock d;
77 register char *dp; 73 register unsigned char *dp;
78 DES_LONG ti[2]; 74 DES_LONG ti[2];
79 unsigned char *iv; 75 unsigned char *iv;
80 int save=0; 76 int save=0;
81 77
82 iv=(unsigned char *)ivec; 78 iv = &(*ivec)[0];
83 c2l(iv,v0); 79 c2l(iv,v0);
84 c2l(iv,v1); 80 c2l(iv,v1);
85 ti[0]=v0; 81 ti[0]=v0;
86 ti[1]=v1; 82 ti[1]=v1;
87 dp=(char *)d; 83 dp=d;
88 l2c(v0,dp); 84 l2c(v0,dp);
89 l2c(v1,dp); 85 l2c(v1,dp);
90 while (l--) 86 while (l--)
91 { 87 {
92 if (n == 0) 88 if (n == 0)
93 { 89 {
94 des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); 90 des_encrypt(ti,schedule,DES_ENCRYPT);
95 dp=(char *)d; 91 dp=d;
96 t=ti[0]; l2c(t,dp); 92 t=ti[0]; l2c(t,dp);
97 t=ti[1]; l2c(t,dp); 93 t=ti[1]; l2c(t,dp);
98 save++; 94 save++;
@@ -104,7 +100,7 @@ int *num;
104 { 100 {
105 v0=ti[0]; 101 v0=ti[0];
106 v1=ti[1]; 102 v1=ti[1];
107 iv=(unsigned char *)ivec; 103 iv = &(*ivec)[0];
108 l2c(v0,iv); 104 l2c(v0,iv);
109 l2c(v1,iv); 105 l2c(v1,iv);
110 } 106 }
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 @@
64 * the second. The second 12 bits will come from the 3rd and half the 4th 64 * the second. The second 12 bits will come from the 3rd and half the 4th
65 * byte. 65 * byte.
66 */ 66 */
67void des_ofb_encrypt(in, out, numbits, length, schedule, ivec) 67void des_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
68unsigned char *in; 68 long length, des_key_schedule schedule, des_cblock *ivec)
69unsigned char *out;
70int numbits;
71long length;
72des_key_schedule schedule;
73des_cblock (*ivec);
74 { 69 {
75 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8; 70 register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8;
76 register DES_LONG mask0,mask1; 71 register DES_LONG mask0,mask1;
@@ -97,7 +92,7 @@ des_cblock (*ivec);
97 mask1=0x00000000L; 92 mask1=0x00000000L;
98 } 93 }
99 94
100 iv=(unsigned char *)ivec; 95 iv = &(*ivec)[0];
101 c2l(iv,v0); 96 c2l(iv,v0);
102 c2l(iv,v1); 97 c2l(iv,v1);
103 ti[0]=v0; 98 ti[0]=v0;
@@ -131,7 +126,7 @@ des_cblock (*ivec);
131 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL; 126 v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL;
132 } 127 }
133 } 128 }
134 iv=(unsigned char *)ivec; 129 iv = &(*ivec)[0];
135 l2c(v0,iv); 130 l2c(v0,iv);
136 l2c(v1,iv); 131 l2c(v1,iv);
137 v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0; 132 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 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void des_pcbc_encrypt(input, output, length, schedule, ivec, enc) 61void des_pcbc_encrypt(const unsigned char *input, unsigned char *output,
62des_cblock (*input); 62 long length, des_key_schedule schedule, des_cblock *ivec, int enc)
63des_cblock (*output);
64long length;
65des_key_schedule schedule;
66des_cblock (*ivec);
67int enc;
68 { 63 {
69 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1; 64 register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1;
70 DES_LONG tin[2]; 65 DES_LONG tin[2];
71 unsigned char *in,*out,*iv; 66 const unsigned char *in;
67 unsigned char *out,*iv;
72 68
73 in=(unsigned char *)input; 69 in=input;
74 out=(unsigned char *)output; 70 out=output;
75 iv=(unsigned char *)ivec; 71 iv = &(*ivec)[0];
76 72
77 if (enc) 73 if (enc)
78 { 74 {
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 @@
73/* Got the value MIT uses via brute force :-) 2/10/90 eay */ 73/* Got the value MIT uses via brute force :-) 2/10/90 eay */
74#define NOISE ((DES_LONG)83653421L) 74#define NOISE ((DES_LONG)83653421L)
75 75
76DES_LONG des_quad_cksum(input, output, length, out_count, seed) 76DES_LONG des_quad_cksum(const unsigned char *input, des_cblock output[],
77des_cblock (*input); 77 long length, int out_count, des_cblock *seed)
78des_cblock (*output);
79long length;
80int out_count;
81des_cblock (*seed);
82 { 78 {
83 DES_LONG z0,z1,t0,t1; 79 DES_LONG z0,z1,t0,t1;
84 int i; 80 int i;
85 long l; 81 long l;
86 unsigned char *cp; 82 const unsigned char *cp;
87 unsigned char *lp; 83 unsigned char *lp;
88 84
89 if (out_count < 1) out_count=1; 85 if (out_count < 1) out_count=1;
90 lp=(unsigned char *)output; 86 lp = &(output[0])[0];
91 87
92 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]); 88 z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]);
93 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]); 89 z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]);
94 90
95 for (i=0; ((i<4)&&(i<out_count)); i++) 91 for (i=0; ((i<4)&&(i<out_count)); i++)
96 { 92 {
97 cp=(unsigned char *)input; 93 cp=input;
98 l=length; 94 l=length;
99 while (l > 0) 95 while (l > 0)
100 { 96 {
@@ -133,7 +129,7 @@ des_cblock (*seed);
133 } 129 }
134 else 130 else
135 { 131 {
136 lp=output[out_count-i-1]; 132 lp = &(output[out_count-i-1])[0];
137 l2n(z1,lp); 133 l2n(z1,lp);
138 l2n(z0,lp); 134 l2n(z0,lp);
139 } 135 }
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 @@
62static int seed=0; 62static int seed=0;
63static des_cblock init; 63static des_cblock init;
64 64
65void des_random_seed(key) 65void des_random_seed(des_cblock *key)
66des_cblock key;
67 { 66 {
68 memcpy(init,key,sizeof(des_cblock)); 67 memcpy(&init,key,sizeof(des_cblock));
69 seed=1; 68 seed=1;
70 } 69 }
71 70
72void des_random_key(ret) 71void des_random_key(des_cblock *ret)
73unsigned char *ret;
74 { 72 {
75 des_key_schedule ks; 73 des_key_schedule ks;
76 static DES_LONG c=0; 74 static DES_LONG c=0;
@@ -101,15 +99,13 @@ unsigned char *ret;
101 t=(DES_LONG)((pid)|((c++)<<16)); 99 t=(DES_LONG)((pid)|((c++)<<16));
102 l2c(t,p); 100 l2c(t,p);
103 101
104 des_set_odd_parity((des_cblock *)data); 102 des_set_odd_parity(&data);
105 des_set_key((des_cblock *)data,ks); 103 des_set_key(&data,ks);
106 des_cbc_cksum((des_cblock *)key,(des_cblock *)key, 104 des_cbc_cksum(key,&key,sizeof(key),ks,&data);
107 (long)sizeof(key),ks,(des_cblock *)data);
108 105
109 des_set_odd_parity((des_cblock *)key); 106 des_set_odd_parity(&key);
110 des_set_key((des_cblock *)key,ks); 107 des_set_key(&key,ks);
111 des_cbc_cksum((des_cblock *)key,(des_cblock *)data, 108 des_cbc_cksum(key,&data,sizeof(key),ks,&key);
112 (long)sizeof(key),ks,(des_cblock *)key);
113 109
114 memcpy(ret,data,sizeof(key)); 110 memcpy(ret,data,sizeof(key));
115 memset(key,0,sizeof(key)); 111 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 @@
1#!/bin/sh
2
3cwd=`pwd`
4cd /tmp
5
6if [ -s /bin/ranlib ] ; then
7 RL=/bin/ranlib
8else if [ -s /usr/bin/ranlib ] ; then
9 RL=/usr/bin/ranlib
10fi
11fi
12
13if [ "x$RL" != "x" ]
14then
15 case "$1" in
16 /*)
17 $RL "$1"
18 ;;
19 *)
20 $RL "$cwd/$1"
21 ;;
22 esac
23fi
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 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61int des_read_password(key, prompt, verify) 61int des_read_password(des_cblock *key, const char *prompt, int verify)
62des_cblock (*key);
63char *prompt;
64int verify;
65 { 62 {
66 int ok; 63 int ok;
67 char buf[BUFSIZ],buff[BUFSIZ]; 64 char buf[BUFSIZ],buff[BUFSIZ];
@@ -73,11 +70,8 @@ int verify;
73 return(ok); 70 return(ok);
74 } 71 }
75 72
76int des_read_2passwords(key1, key2, prompt, verify) 73int des_read_2passwords(des_cblock *key1, des_cblock *key2, const char *prompt,
77des_cblock (*key1); 74 int verify)
78des_cblock (*key2);
79char *prompt;
80int verify;
81 { 75 {
82 int ok; 76 int ok;
83 char buf[BUFSIZ],buff[BUFSIZ]; 77 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#if !defined(MSDOS) && !defined(VMS) && !defined(WIN32)
60#include <openssl/opensslconf.h>
61#include OPENSSL_UNISTD
62/* If unistd.h defines _POSIX_VERSION, we conclude that we
63 * are on a POSIX system and have sigaction and termios. */
64#if defined(_POSIX_VERSION)
65
66# define SIGACTION
67# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
68# define TERMIOS
69# endif
70
71#endif
72#endif
73
59/* #define SIGACTION */ /* Define this if you have sigaction() */ 74/* #define SIGACTION */ /* Define this if you have sigaction() */
75
60#ifdef WIN16TTY 76#ifdef WIN16TTY
61#undef WIN16 77#undef WIN16
62#undef _WINDOWS 78#undef _WINDOWS
@@ -65,11 +81,26 @@
65 81
66/* 06-Apr-92 Luke Brennan Support for VMS */ 82/* 06-Apr-92 Luke Brennan Support for VMS */
67#include "des_locl.h" 83#include "des_locl.h"
84#include "cryptlib.h"
68#include <signal.h> 85#include <signal.h>
86#include <stdio.h>
69#include <string.h> 87#include <string.h>
70#include <setjmp.h> 88#include <setjmp.h>
71#include <errno.h> 89#include <errno.h>
72 90
91#ifdef VMS /* prototypes for sys$whatever */
92#include <starlet.h>
93#ifdef __DECC
94#pragma message disable DOLLARID
95#endif
96#endif
97
98#ifdef WIN_CONSOLE_BUG
99#include <windows.h>
100#include <wincon.h>
101#endif
102
103
73/* There are 5 types of terminal interface supported, 104/* There are 5 types of terminal interface supported,
74 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY 105 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
75 */ 106 */
@@ -147,7 +178,6 @@ struct IOSB {
147#define NX509_SIG 32 178#define NX509_SIG 32
148#endif 179#endif
149 180
150#ifndef NOPROTO
151static void read_till_nl(FILE *); 181static void read_till_nl(FILE *);
152static void recsig(int); 182static void recsig(int);
153static void pushsig(void); 183static void pushsig(void);
@@ -155,32 +185,15 @@ static void popsig(void);
155#if defined(MSDOS) && !defined(WIN16) 185#if defined(MSDOS) && !defined(WIN16)
156static int noecho_fgets(char *buf, int size, FILE *tty); 186static int noecho_fgets(char *buf, int size, FILE *tty);
157#endif 187#endif
158#else
159static void read_till_nl();
160static void recsig();
161static void pushsig();
162static void popsig();
163#if defined(MSDOS) && !defined(WIN16)
164static int noecho_fgets();
165#endif
166#endif
167
168#ifdef SIGACTION 188#ifdef SIGACTION
169 static struct sigaction savsig[NX509_SIG]; 189 static struct sigaction savsig[NX509_SIG];
170#else 190#else
171# ifndef NOPROTO
172 static void (*savsig[NX509_SIG])(int ); 191 static void (*savsig[NX509_SIG])(int );
173# else
174 static void (*savsig[NX509_SIG])();
175# endif
176#endif 192#endif
177static jmp_buf save; 193static jmp_buf save;
178 194
179int des_read_pw_string(buf, length, prompt, verify) 195int des_read_pw_string(char *buf, int length, const char *prompt,
180char *buf; 196 int verify)
181int length;
182char *prompt;
183int verify;
184 { 197 {
185 char buff[BUFSIZ]; 198 char buff[BUFSIZ];
186 int ret; 199 int ret;
@@ -192,8 +205,7 @@ int verify;
192 205
193#ifndef WIN16 206#ifndef WIN16
194 207
195static void read_till_nl(in) 208static void read_till_nl(FILE *in)
196FILE *in;
197 { 209 {
198#define SIZE 4 210#define SIZE 4
199 char buf[SIZE+1]; 211 char buf[SIZE+1];
@@ -205,12 +217,8 @@ FILE *in;
205 217
206 218
207/* return 0 if ok, 1 (or -1) otherwise */ 219/* return 0 if ok, 1 (or -1) otherwise */
208int des_read_pw(buf, buff, size, prompt, verify) 220int des_read_pw(char *buf, char *buff, int size, const char *prompt,
209char *buf; 221 int verify)
210char *buff;
211int size;
212char *prompt;
213int verify;
214 { 222 {
215#ifdef VMS 223#ifdef VMS
216 struct IOSB iosb; 224 struct IOSB iosb;
@@ -223,14 +231,27 @@ int verify;
223 TTY_STRUCT tty_orig,tty_new; 231 TTY_STRUCT tty_orig,tty_new;
224#endif 232#endif
225#endif 233#endif
226 int number=5; 234 int number;
227 int ok=0; 235 int ok;
228 int ps=0; 236 /* statics are simply to avoid warnings about longjmp clobbering
229 int is_a_tty=1; 237 things */
230 238 static int ps;
231 FILE *tty=NULL; 239 int is_a_tty;
240 static FILE *tty;
232 char *p; 241 char *p;
233 242
243 if (setjmp(save))
244 {
245 ok=0;
246 goto error;
247 }
248
249 number=5;
250 ok=0;
251 ps=0;
252 is_a_tty=1;
253 tty=NULL;
254
234#ifndef MSDOS 255#ifndef MSDOS
235 if ((tty=fopen("/dev/tty","r")) == NULL) 256 if ((tty=fopen("/dev/tty","r")) == NULL)
236 tty=stdin; 257 tty=stdin;
@@ -259,19 +280,14 @@ int verify;
259 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig)); 280 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
260#endif 281#endif
261#ifdef VMS 282#ifdef VMS
262 status = SYS$ASSIGN(&terminal,&channel,0,0); 283 status = sys$assign(&terminal,&channel,0,0);
263 if (status != SS$_NORMAL) 284 if (status != SS$_NORMAL)
264 return(-1); 285 return(-1);
265 status=SYS$QIOW(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0); 286 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
266 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) 287 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
267 return(-1); 288 return(-1);
268#endif 289#endif
269 290
270 if (setjmp(save))
271 {
272 ok=0;
273 goto error;
274 }
275 pushsig(); 291 pushsig();
276 ps=1; 292 ps=1;
277 293
@@ -287,7 +303,7 @@ int verify;
287 tty_new[0] = tty_orig[0]; 303 tty_new[0] = tty_orig[0];
288 tty_new[1] = tty_orig[1] | TT$M_NOECHO; 304 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
289 tty_new[2] = tty_orig[2]; 305 tty_new[2] = tty_orig[2];
290 status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0); 306 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
291 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) 307 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
292 return(-1); 308 return(-1);
293#endif 309#endif
@@ -333,31 +349,26 @@ error:
333 perror("fgets(tty)"); 349 perror("fgets(tty)");
334#endif 350#endif
335 /* What can we do if there is an error? */ 351 /* What can we do if there is an error? */
336#if defined(TTY_set) && !defined(VMS) 352#if defined(TTY_set) && !defined(VMS)
337 if (ps >= 2) TTY_set(fileno(tty),&tty_orig); 353 if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
338#endif 354#endif
339#ifdef VMS 355#ifdef VMS
340 if (ps >= 2) 356 if (ps >= 2)
341 status = SYS$QIOW(0,channel,IO$_SETMODE,&iosb,0,0 357 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0
342 ,tty_orig,12,0,0,0,0); 358 ,tty_orig,12,0,0,0,0);
343#endif 359#endif
344 360
345 if (ps >= 1) popsig(); 361 if (ps >= 1) popsig();
346 if (stdin != tty) fclose(tty); 362 if (stdin != tty) fclose(tty);
347#ifdef VMS 363#ifdef VMS
348 status = SYS$DASSGN(channel); 364 status = sys$dassgn(channel);
349#endif 365#endif
350 return(!ok); 366 return(!ok);
351 } 367 }
352 368
353#else /* WIN16 */ 369#else /* WIN16 */
354 370
355int des_read_pw(buf, buff, size, prompt, verify) 371int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
356char *buf;
357char *buff;
358int size;
359char *prompt;
360int verify;
361 { 372 {
362 memset(buf,0,size); 373 memset(buf,0,size);
363 memset(buff,0,size); 374 memset(buff,0,size);
@@ -366,9 +377,15 @@ int verify;
366 377
367#endif 378#endif
368 379
369static void pushsig() 380static void pushsig(void)
370 { 381 {
371 int i; 382 int i;
383#ifdef SIGACTION
384 struct sigaction sa;
385
386 memset(&sa,0,sizeof sa);
387 sa.sa_handler=recsig;
388#endif
372 389
373 for (i=1; i<NX509_SIG; i++) 390 for (i=1; i<NX509_SIG; i++)
374 { 391 {
@@ -381,7 +398,7 @@ static void pushsig()
381 continue; 398 continue;
382#endif 399#endif
383#ifdef SIGACTION 400#ifdef SIGACTION
384 sigaction(i,NULL,&savsig[i]); 401 sigaction(i,&sa,&savsig[i]);
385#else 402#else
386 savsig[i]=signal(i,recsig); 403 savsig[i]=signal(i,recsig);
387#endif 404#endif
@@ -392,7 +409,7 @@ static void pushsig()
392#endif 409#endif
393 } 410 }
394 411
395static void popsig() 412static void popsig(void)
396 { 413 {
397 int i; 414 int i;
398 415
@@ -414,8 +431,7 @@ static void popsig()
414 } 431 }
415 } 432 }
416 433
417static void recsig(i) 434static void recsig(int i)
418int i;
419 { 435 {
420 longjmp(save,1); 436 longjmp(save,1);
421#ifdef LINT 437#ifdef LINT
@@ -424,10 +440,7 @@ int i;
424 } 440 }
425 441
426#if defined(MSDOS) && !defined(WIN16) 442#if defined(MSDOS) && !defined(WIN16)
427static int noecho_fgets(buf,size,tty) 443static int noecho_fgets(char *buf, int size, FILE *tty)
428char *buf;
429int size;
430FILE *tty;
431 { 444 {
432 int i; 445 int i;
433 char *p; 446 char *p;
@@ -454,6 +467,18 @@ FILE *tty;
454 break; 467 break;
455 } 468 }
456 } 469 }
470#ifdef WIN_CONSOLE_BUG
471/* Win95 has several evil console bugs: one of these is that the
472 * last character read using getch() is passed to the next read: this is
473 * usually a CR so this can be trouble. No STDIO fix seems to work but
474 * flushing the console appears to do the trick.
475 */
476 {
477 HANDLE inh;
478 inh = GetStdHandle(STD_INPUT_HANDLE);
479 FlushConsoleInputBuffer(inh);
480 }
481#endif
457 return(strlen(buf)); 482 return(strlen(buf));
458 } 483 }
459#endif 484#endif
diff --git a/src/lib/libcrypto/des/rpc_enc.c b/src/lib/libcrypto/des/rpc_enc.c
index 7c1da1f538..c96c204147 100644
--- a/src/lib/libcrypto/des/rpc_enc.c
+++ b/src/lib/libcrypto/des/rpc_enc.c
@@ -60,32 +60,23 @@
60#include "des_locl.h" 60#include "des_locl.h"
61#include "des_ver.h" 61#include "des_ver.h"
62 62
63#ifndef NOPROTO
64int _des_crypt(char *buf,int len,struct desparams *desp); 63int _des_crypt(char *buf,int len,struct desparams *desp);
65#else 64int _des_crypt(char *buf, int len, struct desparams *desp)
66int _des_crypt();
67#endif
68
69int _des_crypt(buf, len, desp)
70char *buf;
71int len;
72struct desparams *desp;
73 { 65 {
74 des_key_schedule ks; 66 des_key_schedule ks;
75 int enc; 67 int enc;
76 68
77 des_set_key((des_cblock *)desp->des_key,ks); 69 des_set_key(&desp->des_key,ks);
78 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT; 70 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
79 71
80 if (desp->des_mode == CBC) 72 if (desp->des_mode == CBC)
81 des_ecb_encrypt((des_cblock *)desp->UDES.UDES_buf, 73 des_ecb_encrypt((const_des_cblock *)desp->UDES.UDES_buf,
82 (des_cblock *)desp->UDES.UDES_buf,ks,enc); 74 (des_cblock *)desp->UDES.UDES_buf,ks,
75 enc);
83 else 76 else
84 { 77 {
85 des_ncbc_encrypt((des_cblock *)desp->UDES.UDES_buf, 78 des_ncbc_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,
86 (des_cblock *)desp->UDES.UDES_buf, 79 len,ks,&desp->des_ivec,enc);
87 (long)len,ks,
88 (des_cblock *)desp->des_ivec,enc);
89#ifdef undef 80#ifdef undef
90 /* len will always be %8 if called from common_crypt 81 /* len will always be %8 if called from common_crypt
91 * in secure_rpc. 82 * 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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "des.h" 60#include <openssl/des.h>
61 61
62int main(argc,argv) 62int main(int argc, char *argv[])
63int argc;
64char *argv[];
65 { 63 {
66 des_cblock k,k1; 64 des_cblock k,k1;
67 int i; 65 int i;
68 66
69 printf("read passwd\n"); 67 printf("read passwd\n");
70 if ((i=des_read_password((C_Block *)k,"Enter password:",0)) == 0) 68 if ((i=des_read_password(&k,"Enter password:",0)) == 0)
71 { 69 {
72 printf("password = "); 70 printf("password = ");
73 for (i=0; i<8; i++) 71 for (i=0; i<8; i++)
@@ -77,7 +75,7 @@ char *argv[];
77 printf("error %d\n",i); 75 printf("error %d\n",i);
78 printf("\n"); 76 printf("\n");
79 printf("read 2passwds and verify\n"); 77 printf("read 2passwds and verify\n");
80 if ((i=des_read_2passwords((C_Block *)k,(C_Block *)k1, 78 if ((i=des_read_2passwords(&k,&k1,
81 "Enter verified password:",1)) == 0) 79 "Enter verified password:",1)) == 0)
82 { 80 {
83 printf("password1 = "); 81 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 @@
67#include "podd.h" 67#include "podd.h"
68#include "sk.h" 68#include "sk.h"
69 69
70#ifndef NOPROTO 70static int check_parity(const_des_cblock *key);
71static int check_parity(des_cblock (*key)); 71OPENSSL_GLOBAL int des_check_key=0;
72#else
73static int check_parity();
74#endif
75 72
76int des_check_key=0; 73void des_set_odd_parity(des_cblock *key)
77
78void des_set_odd_parity(key)
79des_cblock (*key);
80 { 74 {
81 int i; 75 int i;
82 76
@@ -84,8 +78,7 @@ des_cblock (*key);
84 (*key)[i]=odd_parity[(*key)[i]]; 78 (*key)[i]=odd_parity[(*key)[i]];
85 } 79 }
86 80
87static int check_parity(key) 81static int check_parity(const_des_cblock *key)
88des_cblock (*key);
89 { 82 {
90 int i; 83 int i;
91 84
@@ -111,8 +104,8 @@ static des_cblock weak_keys[NUM_WEAK_KEY]={
111 /* weak keys */ 104 /* weak keys */
112 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, 105 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
113 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, 106 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
114 {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, 107 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
115 {0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0}, 108 {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1},
116 /* semi-weak keys */ 109 /* semi-weak keys */
117 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE}, 110 {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE},
118 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01}, 111 {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01},
@@ -127,8 +120,7 @@ static des_cblock weak_keys[NUM_WEAK_KEY]={
127 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, 120 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
128 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}}; 121 {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};
129 122
130int des_is_weak_key(key) 123int des_is_weak_key(const_des_cblock *key)
131des_cblock (*key);
132 { 124 {
133 int i; 125 int i;
134 126
@@ -157,13 +149,11 @@ des_cblock (*key);
157 * return -1 if key parity error, 149 * return -1 if key parity error,
158 * return -2 if illegal weak key. 150 * return -2 if illegal weak key.
159 */ 151 */
160int des_set_key(key, schedule) 152int des_set_key(const_des_cblock *key, des_key_schedule schedule)
161des_cblock (*key);
162des_key_schedule schedule;
163 { 153 {
164 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; 154 static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
165 register DES_LONG c,d,t,s,t2; 155 register DES_LONG c,d,t,s,t2;
166 register unsigned char *in; 156 register const unsigned char *in;
167 register DES_LONG *k; 157 register DES_LONG *k;
168 register int i; 158 register int i;
169 159
@@ -176,8 +166,8 @@ des_key_schedule schedule;
176 return(-2); 166 return(-2);
177 } 167 }
178 168
179 k=(DES_LONG *)schedule; 169 k = &schedule->ks.deslong[0];
180 in=(unsigned char *)key; 170 in = &(*key)[0];
181 171
182 c2l(in,c); 172 c2l(in,c);
183 c2l(in,d); 173 c2l(in,d);
@@ -238,9 +228,7 @@ des_key_schedule schedule;
238 return(0); 228 return(0);
239 } 229 }
240 230
241int des_key_sched(key, schedule) 231int des_key_sched(const_des_cblock *key, des_key_schedule schedule)
242des_cblock (*key);
243des_key_schedule schedule;
244 { 232 {
245 return(des_set_key(key,schedule)); 233 return(des_set_key(key,schedule));
246 } 234 }
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3sub lab_shift 3sub lab_shift
4 { 4 {
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 @@
59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ 59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ 60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61 61
62#ifndef MSDOS 62#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
63#define TIMES 63#define TIMES
64#endif 64#endif
65 65
66#include <stdio.h> 66#include <stdio.h>
67#ifndef MSDOS 67
68#include <unistd.h> 68#include <openssl/e_os2.h>
69#else 69#include OPENSSL_UNISTD_IO
70#include <io.h> 70OPENSSL_DECLARE_EXIT
71extern int exit(); 71
72#endif
73#include <signal.h> 72#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX 73#ifndef _IRIX
76#include <time.h> 74#include <time.h>
77#endif 75#endif
@@ -79,35 +77,32 @@ extern int exit();
79#include <sys/types.h> 77#include <sys/types.h>
80#include <sys/times.h> 78#include <sys/times.h>
81#endif 79#endif
82#else /* VMS */ 80
83#include <types.h> 81/* Depending on the VMS version, the tms structure is perhaps defined.
84struct tms { 82 The __TMS macro will show if it was. If it wasn't defined, we should
85 time_t tms_utime; 83 undefine TIMES, since that tells the rest of the program how things
86 time_t tms_stime; 84 should be handled. -- Richard Levitte */
87 time_t tms_uchild; /* I dunno... */ 85#if defined(VMS) && defined(__DECC) && !defined(__TMS)
88 time_t tms_uchildsys; /* so these names are a guess :-) */ 86#undef TIMES
89 }
90#endif 87#endif
88
91#ifndef TIMES 89#ifndef TIMES
92#include <sys/timeb.h> 90#include <sys/timeb.h>
93#endif 91#endif
94 92
95#ifdef sun 93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
96#include <limits.h> 95#include <limits.h>
97#include <sys/param.h> 96#include <sys/param.h>
98#endif 97#endif
99 98
100#include "des.h" 99#include <openssl/des.h>
101 100
102/* The following if from times(3) man page. It may need to be changed */ 101/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ 102#ifndef HZ
104# ifndef CLK_TCK 103# ifndef CLK_TCK
105# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ 104# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
106# ifndef VMS 105# define HZ 100.0
107# define HZ 100.0
108# else /* VMS */
109# define HZ 100.0
110# endif
111# else /* _BSD_CLK_TCK_ */ 106# else /* _BSD_CLK_TCK_ */
112# define HZ ((double)_BSD_CLK_TCK_) 107# define HZ ((double)_BSD_CLK_TCK_)
113# endif 108# endif
@@ -119,12 +114,7 @@ struct tms {
119#define BUFSIZE ((long)1024) 114#define BUFSIZE ((long)1024)
120long run=0; 115long run=0;
121 116
122#ifndef NOPROTO
123double Time_F(int s); 117double Time_F(int s);
124#else
125double Time_F();
126#endif
127
128#ifdef SIGALRM 118#ifdef SIGALRM
129#if defined(__STDC__) || defined(sgi) || defined(_AIX) 119#if defined(__STDC__) || defined(sgi) || defined(_AIX)
130#define SIGRETTYPE void 120#define SIGRETTYPE void
@@ -132,14 +122,8 @@ double Time_F();
132#define SIGRETTYPE int 122#define SIGRETTYPE int
133#endif 123#endif
134 124
135#ifndef NOPROTO
136SIGRETTYPE sig_done(int sig); 125SIGRETTYPE sig_done(int sig);
137#else 126SIGRETTYPE sig_done(int sig)
138SIGRETTYPE sig_done();
139#endif
140
141SIGRETTYPE sig_done(sig)
142int sig;
143 { 127 {
144 signal(SIGALRM,sig_done); 128 signal(SIGALRM,sig_done);
145 run=0; 129 run=0;
@@ -152,8 +136,7 @@ int sig;
152#define START 0 136#define START 0
153#define STOP 1 137#define STOP 1
154 138
155double Time_F(s) 139double Time_F(int s)
156int s;
157 { 140 {
158 double ret; 141 double ret;
159#ifdef TIMES 142#ifdef TIMES
@@ -189,9 +172,7 @@ int s;
189#endif 172#endif
190 } 173 }
191 174
192int main(argc,argv) 175int main(int argc, char **argv)
193int argc;
194char **argv;
195 { 176 {
196 long count; 177 long count;
197 static unsigned char buf[BUFSIZE]; 178 static unsigned char buf[BUFSIZE];
@@ -209,12 +190,12 @@ char **argv;
209 printf("program when this computer is idle.\n"); 190 printf("program when this computer is idle.\n");
210#endif 191#endif
211 192
212 des_set_key((C_Block *)key2,sch2); 193 des_set_key(&key2,sch2);
213 des_set_key((C_Block *)key3,sch3); 194 des_set_key(&key3,sch3);
214 195
215#ifndef SIGALRM 196#ifndef SIGALRM
216 printf("First we calculate the approximate speed ...\n"); 197 printf("First we calculate the approximate speed ...\n");
217 des_set_key((C_Block *)key,sch); 198 des_set_key(&key,sch);
218 count=10; 199 count=10;
219 do { 200 do {
220 long i; 201 long i;
@@ -244,7 +225,7 @@ char **argv;
244 225
245 Time_F(START); 226 Time_F(START);
246 for (count=0,run=1; COND(ca); count++) 227 for (count=0,run=1; COND(ca); count++)
247 des_set_key((C_Block *)key,sch); 228 des_set_key(&key,sch);
248 d=Time_F(STOP); 229 d=Time_F(STOP);
249 printf("%ld set_key's in %.2f seconds\n",count,d); 230 printf("%ld set_key's in %.2f seconds\n",count,d);
250 a=((double)COUNT(ca))/d; 231 a=((double)COUNT(ca))/d;
@@ -276,8 +257,8 @@ char **argv;
276#endif 257#endif
277 Time_F(START); 258 Time_F(START);
278 for (count=0,run=1; COND(cc); count++) 259 for (count=0,run=1; COND(cc); count++)
279 des_ncbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,&(sch[0]), 260 des_ncbc_encrypt(buf,buf,BUFSIZE,&(sch[0]),
280 (C_Block *)&(key[0]),DES_ENCRYPT); 261 &key,DES_ENCRYPT);
281 d=Time_F(STOP); 262 d=Time_F(STOP);
282 printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n", 263 printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n",
283 count,BUFSIZE,d); 264 count,BUFSIZE,d);
@@ -293,11 +274,11 @@ char **argv;
293#endif 274#endif
294 Time_F(START); 275 Time_F(START);
295 for (count=0,run=1; COND(cd); count++) 276 for (count=0,run=1; COND(cd); count++)
296 des_ede3_cbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE, 277 des_ede3_cbc_encrypt(buf,buf,BUFSIZE,
297 &(sch[0]), 278 &(sch[0]),
298 &(sch2[0]), 279 &(sch2[0]),
299 &(sch3[0]), 280 &(sch3[0]),
300 (C_Block *)&(key[0]), 281 &key,
301 DES_ENCRYPT); 282 DES_ENCRYPT);
302 d=Time_F(STOP); 283 d=Time_F(STOP);
303 printf("%ld des_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n", 284 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59const DES_LONG des_SPtrans[8][64]={ 59OPENSSL_GLOBAL const DES_LONG des_SPtrans[8][64]={
60{ 60{
61/* nibble 0 */ 61/* nibble 0 */
620x02080800L, 0x00080000L, 0x02000002L, 0x02080802L, 620x02080800L, 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 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61extern int des_check_key; 61OPENSSL_EXTERN int des_check_key;
62 62
63void des_string_to_key(str, key) 63void des_string_to_key(const char *str, des_cblock *key)
64char *str;
65des_cblock (*key);
66 { 64 {
67 des_key_schedule ks; 65 des_key_schedule ks;
68 int i,length; 66 int i,length;
@@ -89,21 +87,17 @@ des_cblock (*key);
89 } 87 }
90 } 88 }
91#endif 89#endif
92 des_set_odd_parity((des_cblock *)key); 90 des_set_odd_parity(key);
93 i=des_check_key; 91 i=des_check_key;
94 des_check_key=0; 92 des_check_key=0;
95 des_set_key((des_cblock *)key,ks); 93 des_set_key(key,ks);
96 des_check_key=i; 94 des_check_key=i;
97 des_cbc_cksum((des_cblock *)str,(des_cblock *)key,(long)length,ks, 95 des_cbc_cksum((unsigned char*)str,key,length,ks,key);
98 (des_cblock *)key);
99 memset(ks,0,sizeof(ks)); 96 memset(ks,0,sizeof(ks));
100 des_set_odd_parity((des_cblock *)key); 97 des_set_odd_parity(key);
101 } 98 }
102 99
103void des_string_to_2keys(str, key1, key2) 100void des_string_to_2keys(const char *str, des_cblock *key1, des_cblock *key2)
104char *str;
105des_cblock (*key1);
106des_cblock (*key2);
107 { 101 {
108 des_key_schedule ks; 102 des_key_schedule ks;
109 int i,length; 103 int i,length;
@@ -154,16 +148,14 @@ des_cblock (*key2);
154 } 148 }
155 if (length <= 8) memcpy(key2,key1,8); 149 if (length <= 8) memcpy(key2,key1,8);
156#endif 150#endif
157 des_set_odd_parity((des_cblock *)key1); 151 des_set_odd_parity(key1);
158 des_set_odd_parity((des_cblock *)key2); 152 des_set_odd_parity(key2);
159 i=des_check_key; 153 i=des_check_key;
160 des_check_key=0; 154 des_check_key=0;
161 des_set_key((des_cblock *)key1,ks); 155 des_set_key(key1,ks);
162 des_cbc_cksum((des_cblock *)str,(des_cblock *)key1,(long)length,ks, 156 des_cbc_cksum((unsigned char*)str,key1,length,ks,key1);
163 (des_cblock *)key1); 157 des_set_key(key2,ks);
164 des_set_key((des_cblock *)key2,ks); 158 des_cbc_cksum((unsigned char*)str,key2,length,ks,key2);
165 des_cbc_cksum((des_cblock *)str,(des_cblock *)key2,(long)length,ks,
166 (des_cblock *)key2);
167 des_check_key=i; 159 des_check_key=i;
168 memset(ks,0,sizeof(ks)); 160 memset(ks,0,sizeof(ks));
169 des_set_odd_parity(key1); 161 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 @@
87 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 87 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88 * SUCH DAMAGE. 88 * SUCH DAMAGE.
89 * 89 *
90 * $Id: supp.c,v 1.1.1.1 1998/10/05 20:12:45 ryker Exp $ 90 * $Id: supp.c,v 1.2 1999/09/29 04:36:01 beck Exp $
91 */ 91 */
92 92
93#include <stdio.h> 93#include <stdio.h>
94#include "des_locl.h" 94#include "des_locl.h"
95 95
96void des_cblock_print_file(cb, fp) 96void des_cblock_print_file(const_des_cblock *cb, FILE *fp)
97 des_cblock *cb;
98 FILE *fp;
99{ 97{
100 int i; 98 int i;
101 unsigned int *p = (unsigned int *)cb; 99 const unsigned int *p = (const unsigned int *)cb;
102 100
103 fprintf(fp, " 0x { "); 101 fprintf(fp, " 0x { ");
104 for (i = 0; i < 8; i++) { 102 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# des.pl tesing code 3# des.pl tesing code
4 4
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 @@
1$! --- VMS.com ---
2$!
3$ GoSub defines
4$ GoSub linker_options
5$ If (P1 .nes. "")
6$ Then
7$ GoSub 'P1'
8$ Else
9$ GoSub lib
10$ GoSub destest
11$ GoSub rpw
12$ GoSub speed
13$ GoSub des
14$ EndIF
15$!
16$ Exit
17$!
18$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
19$!
20$DEFINES:
21$ OPT_FILE := "VAX_LINKER_OPTIONS.OPT"
22$!
23$ CC_OPTS := "/NODebug/OPTimize/NOWarn"
24$!
25$ LINK_OPTS := "/NODebug/NOTraceback/Contiguous"
26$!
27$ OBJS = "cbc_cksm.obj,cbc_enc.obj,ecb_enc.obj,pcbc_enc.obj," + -
28 "qud_cksm.obj,rand_key.obj,read_pwd.obj,set_key.obj," + -
29 "str2key.obj,enc_read.obj,enc_writ.obj,fcrypt.obj," + -
30 "cfb_enc.obj,ecb3_enc.obj,ofb_enc.obj"
31
32
33$!
34$ LIBDES = "cbc_cksm.c,cbc_enc.c,ecb_enc.c,enc_read.c," + -
35 "enc_writ.c,pcbc_enc.c,qud_cksm.c,rand_key.c," + -
36 "read_pwd.c,set_key.c,str2key.c,fcrypt.c," + -
37 "cfb_enc.c,ecb3_enc.c,ofb_enc.c"
38$ Return
39$!
40$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41$!
42$LINKER_OPTIONS:
43$ If (f$search(OPT_FILE) .eqs. "")
44$ Then
45$ Create 'OPT_FILE'
46$DECK
47! Default system options file to link against the sharable C runtime library
48!
49Sys$Share:VAXcRTL.exe/Share
50$EOD
51$ EndIF
52$ Return
53$!
54$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
55$!
56$LIB:
57$ CC 'CC_OPTS' 'LIBDES'
58$ If (f$search("LIBDES.OLB") .nes. "")
59$ Then Library /Object /Replace libdes 'OBJS'
60$ Else Library /Create /Object libdes 'OBJS'
61$ EndIF
62$ Return
63$!
64$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65$!
66$DESTEST:
67$ CC 'CC_OPTS' destest
68$ Link 'link_opts' /Exec=destest destest.obj,libdes/LIBRARY,'opt_file'/Option
69$ Return
70$!
71$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72$!
73$RPW:
74$ CC 'CC_OPTS' rpw
75$ Link 'link_opts' /Exec=rpw rpw.obj,libdes/LIBRARY,'opt_file'/Option
76$ Return
77$!
78$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
79$!
80$SPEED:
81$ CC 'CC_OPTS' speed
82$ Link 'link_opts' /Exec=speed speed.obj,libdes/LIBRARY,'opt_file'/Option
83$ Return
84$!
85$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
86$!
87$DES:
88$ CC 'CC_OPTS' des
89$ Link 'link_opts' /Exec=des des.obj,libdes/LIBRARY,'opt_file'/Option
90$ 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]={
790xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB, 790xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB,
80 }; 80 };
81 81
82void des_xwhite_in2out(des_key,in_white,out_white) 82void des_xwhite_in2out(const_des_cblock *des_key, const_des_cblock *in_white,
83des_cblock (*des_key); 83 des_cblock *out_white)
84des_cblock (*in_white);
85des_cblock (*out_white);
86 { 84 {
87 unsigned char *key,*in,*out;
88 int out0,out1; 85 int out0,out1;
89 int i; 86 int i;
90 87 const unsigned char *key = &(*des_key)[0];
91 key=(unsigned char *)des_key; 88 const unsigned char *in = &(*in_white)[0];
92 in=(unsigned char *)in_white; 89 unsigned char *out = &(*out_white)[0];
93 out=(unsigned char *)out_white;
94 90
95 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0; 91 out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0;
96 out0=out1=0; 92 out0=out1=0;
@@ -111,34 +107,26 @@ des_cblock (*out_white);
111 } 107 }
112 } 108 }
113 109
114void des_xcbc_encrypt(input, output, length, schedule, ivec, inw,outw,enc) 110void des_xcbc_encrypt(const unsigned char *in, unsigned char *out,
115des_cblock (*input); 111 long length, des_key_schedule schedule, des_cblock *ivec,
116des_cblock (*output); 112 const_des_cblock *inw, const_des_cblock *outw, int enc)
117long length;
118des_key_schedule schedule;
119des_cblock (*ivec);
120des_cblock (*inw);
121des_cblock (*outw);
122int enc;
123 { 113 {
124 register DES_LONG tin0,tin1; 114 register DES_LONG tin0,tin1;
125 register DES_LONG tout0,tout1,xor0,xor1; 115 register DES_LONG tout0,tout1,xor0,xor1;
126 register DES_LONG inW0,inW1,outW0,outW1; 116 register DES_LONG inW0,inW1,outW0,outW1;
127 register unsigned char *in,*out; 117 register const unsigned char *in2;
128 register long l=length; 118 register long l=length;
129 DES_LONG tin[2]; 119 DES_LONG tin[2];
130 unsigned char *iv; 120 unsigned char *iv;
131 121
132 in=(unsigned char *)inw; 122 in2 = &(*inw)[0];
133 c2l(in,inW0); 123 c2l(in2,inW0);
134 c2l(in,inW1); 124 c2l(in2,inW1);
135 in=(unsigned char *)outw; 125 in2 = &(*outw)[0];
136 c2l(in,outW0); 126 c2l(in2,outW0);
137 c2l(in,outW1); 127 c2l(in2,outW1);
138 128
139 in=(unsigned char *)input; 129 iv = &(*ivec)[0];
140 out=(unsigned char *)output;
141 iv=(unsigned char *)ivec;
142 130
143 if (enc) 131 if (enc)
144 { 132 {
@@ -150,7 +138,7 @@ int enc;
150 c2l(in,tin1); 138 c2l(in,tin1);
151 tin0^=tout0^inW0; tin[0]=tin0; 139 tin0^=tout0^inW0; tin[0]=tin0;
152 tin1^=tout1^inW1; tin[1]=tin1; 140 tin1^=tout1^inW1; tin[1]=tin1;
153 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); 141 des_encrypt(tin,schedule,DES_ENCRYPT);
154 tout0=tin[0]^outW0; l2c(tout0,out); 142 tout0=tin[0]^outW0; l2c(tout0,out);
155 tout1=tin[1]^outW1; l2c(tout1,out); 143 tout1=tin[1]^outW1; l2c(tout1,out);
156 } 144 }
@@ -159,11 +147,11 @@ int enc;
159 c2ln(in,tin0,tin1,l+8); 147 c2ln(in,tin0,tin1,l+8);
160 tin0^=tout0^inW0; tin[0]=tin0; 148 tin0^=tout0^inW0; tin[0]=tin0;
161 tin1^=tout1^inW1; tin[1]=tin1; 149 tin1^=tout1^inW1; tin[1]=tin1;
162 des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); 150 des_encrypt(tin,schedule,DES_ENCRYPT);
163 tout0=tin[0]^outW0; l2c(tout0,out); 151 tout0=tin[0]^outW0; l2c(tout0,out);
164 tout1=tin[1]^outW1; l2c(tout1,out); 152 tout1=tin[1]^outW1; l2c(tout1,out);
165 } 153 }
166 iv=(unsigned char *)ivec; 154 iv = &(*ivec)[0];
167 l2c(tout0,iv); 155 l2c(tout0,iv);
168 l2c(tout1,iv); 156 l2c(tout1,iv);
169 } 157 }
@@ -175,7 +163,7 @@ int enc;
175 { 163 {
176 c2l(in,tin0); tin[0]=tin0^outW0; 164 c2l(in,tin0); tin[0]=tin0^outW0;
177 c2l(in,tin1); tin[1]=tin1^outW1; 165 c2l(in,tin1); tin[1]=tin1^outW1;
178 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); 166 des_encrypt(tin,schedule,DES_DECRYPT);
179 tout0=tin[0]^xor0^inW0; 167 tout0=tin[0]^xor0^inW0;
180 tout1=tin[1]^xor1^inW1; 168 tout1=tin[1]^xor1^inW1;
181 l2c(tout0,out); 169 l2c(tout0,out);
@@ -187,7 +175,7 @@ int enc;
187 { 175 {
188 c2l(in,tin0); tin[0]=tin0^outW0; 176 c2l(in,tin0); tin[0]=tin0^outW0;
189 c2l(in,tin1); tin[1]=tin1^outW1; 177 c2l(in,tin1); tin[1]=tin1^outW1;
190 des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); 178 des_encrypt(tin,schedule,DES_DECRYPT);
191 tout0=tin[0]^xor0^inW0; 179 tout0=tin[0]^xor0^inW0;
192 tout1=tin[1]^xor1^inW1; 180 tout1=tin[1]^xor1^inW1;
193 l2cn(tout0,tout1,out,l+8); 181 l2cn(tout0,tout1,out,l+8);
@@ -195,7 +183,7 @@ int enc;
195 xor1=tin1; 183 xor1=tin1;
196 } 184 }
197 185
198 iv=(unsigned char *)ivec; 186 iv = &(*ivec)[0];
199 l2c(xor0,iv); 187 l2c(xor0,iv);
200 l2c(xor1,iv); 188 l2c(xor1,iv);
201 } 189 }
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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=dh
19ERRC=dh_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= dhtest.c 21TEST= dhtest.c
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c $(ERRC).c 25LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c
26LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o $(ERRC).o 26LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o
27 27
28SRC= $(LIBSRC) 28SRC= $(LIBSRC)
29 29
@@ -39,24 +39,23 @@ all: lib
39 39
40lib: $(LIBOBJ) 40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
42 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
43 @touch lib 43 @touch lib
44 44
45files: 45files:
46 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
47 47
48links: 48links:
49 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
50 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
51 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
52 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
53 $(TOP)/util/mklink.sh ../../apps $(APPS)
54 53
55install: 54install:
56 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
57 do \ 56 do \
58 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done; 59 done;
61 60
62tags: 61tags:
@@ -68,17 +67,42 @@ lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
69 68
70depend: 69depend:
71 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
72 71
73dclean: 72dclean:
74 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
76 75
77clean: 76clean:
78 /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80errors:
81 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
82 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
83 78
84# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81dh_check.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
82dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
83dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
84dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85dh_check.o: ../../include/openssl/opensslconf.h
86dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
87dh_check.o: ../cryptlib.h
88dh_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h
89dh_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
90dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
91dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
92dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
93dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
94dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95dh_gen.o: ../../include/openssl/stack.h ../cryptlib.h
96dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
97dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
98dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
99dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
100dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
101dh_key.o: ../../include/openssl/rand.h ../../include/openssl/stack.h
102dh_key.o: ../cryptlib.h
103dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
104dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
105dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
106dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
107dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
108dh_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 @@
1/* Error codes for the DH functions. */
2
3/* Function codes. */
4#define DH_F_DHPARAMS_PRINT 100
5#define DH_F_DHPARAMS_PRINT_FP 101
6#define DH_F_DH_COMPUTE_KEY 102
7#define DH_F_DH_GENERATE_KEY 103
8#define DH_F_DH_GENERATE_PARAMETERS 104
9#define DH_F_DH_NEW 105
10
11/* Reason codes. */
12#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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifndef HEADER_BN_H 66#ifdef NO_DH
67#define BIGNUM char 67#error DH is disabled.
68#endif 68#endif
69 69
70#include <openssl/bn.h>
71
72#define DH_FLAG_CACHE_MONT_P 0x01
73
70typedef struct dh_st 74typedef struct dh_st
71 { 75 {
72 /* This first argument is used to pick up errors when 76 /* This first argument is used to pick up errors when
@@ -78,6 +82,9 @@ typedef struct dh_st
78 int length; /* optional */ 82 int length; /* optional */
79 BIGNUM *pub_key; /* y */ 83 BIGNUM *pub_key; /* y */
80 BIGNUM *priv_key; /* x */ 84 BIGNUM *priv_key; /* x */
85
86 int flags;
87 char *method_mont_p;
81 } DH; 88 } DH;
82 89
83#define DH_GENERATOR_2 2 90#define DH_GENERATOR_2 2
@@ -98,15 +105,19 @@ typedef struct dh_st
98 (unsigned char *)(x)) 105 (unsigned char *)(x))
99#define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \ 106#define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \
100 (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x)) 107 (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x))
108#ifdef __cplusplus
109#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \
110 (unsigned char *)(x))
111#else
101#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \ 112#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \
102 (unsigned char *)(x)) 113 (unsigned char *)(x))
114#endif
103 115
104#ifndef NOPROTO
105DH * DH_new(void); 116DH * DH_new(void);
106void DH_free(DH *dh); 117void DH_free(DH *dh);
107int DH_size(DH *dh); 118int DH_size(DH *dh);
108DH * DH_generate_parameters(int prime_len,int generator, 119DH * DH_generate_parameters(int prime_len,int generator,
109 void (*callback)(int,int,char *),char *cb_arg); 120 void (*callback)(int,int,void *),void *cb_arg);
110int DH_check(DH *dh,int *codes); 121int DH_check(DH *dh,int *codes);
111int DH_generate_key(DH *dh); 122int DH_generate_key(DH *dh);
112int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh); 123int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh);
@@ -122,26 +133,11 @@ int DHparams_print(char *bp, DH *x);
122#endif 133#endif
123void ERR_load_DH_strings(void ); 134void ERR_load_DH_strings(void );
124 135
125#else
126
127DH * DH_new();
128void DH_free();
129int DH_size();
130DH * DH_generate_parameters();
131int DH_check();
132int DH_generate_key();
133int DH_compute_key();
134DH * d2i_DHparams();
135int i2d_DHparams();
136#ifndef NO_FP_API
137int DHparams_print_fp();
138#endif
139int DHparams_print();
140void ERR_load_DH_strings();
141
142#endif
143
144/* BEGIN ERROR CODES */ 136/* BEGIN ERROR CODES */
137/* The following lines are auto generated by the script mkerr.pl. Any changes
138 * made after this point may be overwritten when the script is next run.
139 */
140
145/* Error codes for the DH functions. */ 141/* Error codes for the DH functions. */
146 142
147/* Function codes. */ 143/* Function codes. */
@@ -154,7 +150,7 @@ void ERR_load_DH_strings();
154 150
155/* Reason codes. */ 151/* Reason codes. */
156#define DH_R_NO_PRIVATE_VALUE 100 152#define DH_R_NO_PRIVATE_VALUE 100
157 153
158#ifdef __cplusplus 154#ifdef __cplusplus
159} 155}
160#endif 156#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "dh.h" 62#include <openssl/dh.h>
63 63
64/* Check that p is a strong prime and 64/* Check that p is a strong prime and
65 * if g is 2, 3 or 5, check that is is a suitable generator 65 * if g is 2, 3 or 5, check that is is a suitable generator
@@ -70,9 +70,7 @@
70 * should hold. 70 * should hold.
71 */ 71 */
72 72
73int DH_check(dh,ret) 73int DH_check(DH *dh, int *ret)
74DH *dh;
75int *ret;
76 { 74 {
77 int ok=0; 75 int ok=0;
78 BN_CTX *ctx=NULL; 76 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 @@
1/* lib/dh/dh_err.c */ 1/* crypto/dh/dh_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "dh.h" 62#include <openssl/dh.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -69,23 +71,23 @@ static ERR_STRING_DATA DH_str_functs[]=
69{ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"}, 71{ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"},
70{ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"}, 72{ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"},
71{ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"}, 73{ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"},
72{0,NULL}, 74{0,NULL}
73 }; 75 };
74 76
75static ERR_STRING_DATA DH_str_reasons[]= 77static ERR_STRING_DATA DH_str_reasons[]=
76 { 78 {
77{DH_R_NO_PRIVATE_VALUE ,"no private value"}, 79{DH_R_NO_PRIVATE_VALUE ,"no private value"},
78{0,NULL}, 80{0,NULL}
79 }; 81 };
80 82
81#endif 83#endif
82 84
83void ERR_load_DH_strings() 85void ERR_load_DH_strings(void)
84 { 86 {
85 static int init=1; 87 static int init=1;
86 88
87 if (init); 89 if (init)
88 {; 90 {
89 init=0; 91 init=0;
90#ifndef NO_ERR 92#ifndef NO_ERR
91 ERR_load_strings(ERR_LIB_DH,DH_str_functs); 93 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "dh.h" 62#include <openssl/dh.h>
63 63
64/* We generate DH parameters as follows 64/* We generate DH parameters as follows
65 * find a prime q which is prime_len/2 bits long. 65 * find a prime q which is prime_len/2 bits long.
@@ -83,11 +83,8 @@
83 * this generator function can take a very very long time to run. 83 * this generator function can take a very very long time to run.
84 */ 84 */
85 85
86DH *DH_generate_parameters(prime_len,generator,callback,cb_arg) 86DH *DH_generate_parameters(int prime_len, int generator,
87int prime_len; 87 void (*callback)(int,int,void *), void *cb_arg)
88int generator;
89void (*callback)(P_I_I_P);
90char *cb_arg;
91 { 88 {
92 BIGNUM *p=NULL,*t1,*t2; 89 BIGNUM *p=NULL,*t1,*t2;
93 DH *ret=NULL; 90 DH *ret=NULL;
@@ -95,10 +92,11 @@ char *cb_arg;
95 BN_CTX *ctx=NULL; 92 BN_CTX *ctx=NULL;
96 93
97 ret=DH_new(); 94 ret=DH_new();
95 if (ret == NULL) goto err;
98 ctx=BN_CTX_new(); 96 ctx=BN_CTX_new();
99 if (ctx == NULL) goto err; 97 if (ctx == NULL) goto err;
100 t1=ctx->bn[0]; 98 t1= &(ctx->bn[0]);
101 t2=ctx->bn[1]; 99 t2= &(ctx->bn[1]);
102 ctx->tos=2; 100 ctx->tos=2;
103 101
104 if (generator == DH_GENERATOR_2) 102 if (generator == DH_GENERATOR_2)
@@ -126,7 +124,7 @@ char *cb_arg;
126 else 124 else
127 g=generator; 125 g=generator;
128 126
129 p=BN_generate_prime(prime_len,1,t1,t2,callback,cb_arg); 127 p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg);
130 if (p == NULL) goto err; 128 if (p == NULL) goto err;
131 if (callback != NULL) callback(3,0,cb_arg); 129 if (callback != NULL) callback(3,0,cb_arg);
132 ret->p=p; 130 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "rand.h" 62#include <openssl/rand.h>
63#include "dh.h" 63#include <openssl/dh.h>
64 64
65int DH_generate_key(dh) 65int DH_generate_key(DH *dh)
66DH *dh;
67 { 66 {
68 int ok=0; 67 int ok=0;
69 unsigned int i; 68 unsigned int i;
70 BN_CTX *ctx=NULL; 69 BN_CTX ctx;
70 BN_MONT_CTX *mont;
71 BIGNUM *pub_key=NULL,*priv_key=NULL; 71 BIGNUM *pub_key=NULL,*priv_key=NULL;
72 72
73 ctx=BN_CTX_new(); 73 BN_CTX_init(&ctx);
74 if (ctx == NULL) goto err;
75 74
76 if (dh->priv_key == NULL) 75 if (dh->priv_key == NULL)
77 { 76 {
@@ -96,7 +95,15 @@ DH *dh;
96 else 95 else
97 pub_key=dh->pub_key; 96 pub_key=dh->pub_key;
98 97
99 if (!BN_mod_exp(pub_key,dh->g,priv_key,dh->p,ctx)) goto err; 98 if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
99 {
100 if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
101 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
102 dh->p,&ctx)) goto err;
103 }
104 mont=(BN_MONT_CTX *)dh->method_mont_p;
105
106 if (!BN_mod_exp_mont(pub_key,dh->g,priv_key,dh->p,&ctx,mont)) goto err;
100 107
101 dh->pub_key=pub_key; 108 dh->pub_key=pub_key;
102 dh->priv_key=priv_key; 109 dh->priv_key=priv_key;
@@ -107,29 +114,34 @@ err:
107 114
108 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key); 115 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
109 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key); 116 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
110 if (ctx != NULL) BN_CTX_free(ctx); 117 BN_CTX_free(&ctx);
111 return(ok); 118 return(ok);
112 } 119 }
113 120
114int DH_compute_key(key,pub_key,dh) 121int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
115unsigned char *key;
116BIGNUM *pub_key;
117DH *dh;
118 { 122 {
119 BN_CTX *ctx; 123 BN_CTX ctx;
124 BN_MONT_CTX *mont;
120 BIGNUM *tmp; 125 BIGNUM *tmp;
121 int ret= -1; 126 int ret= -1;
122 127
123 ctx=BN_CTX_new(); 128 BN_CTX_init(&ctx);
124 if (ctx == NULL) goto err; 129 tmp= &(ctx.bn[ctx.tos++]);
125 tmp=ctx->bn[ctx->tos++];
126 130
127 if (dh->priv_key == NULL) 131 if (dh->priv_key == NULL)
128 { 132 {
129 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE); 133 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
130 goto err; 134 goto err;
131 } 135 }
132 if (!BN_mod_exp(tmp,pub_key,dh->priv_key,dh->p,ctx)) 136 if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))
137 {
138 if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
139 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,
140 dh->p,&ctx)) goto err;
141 }
142
143 mont=(BN_MONT_CTX *)dh->method_mont_p;
144 if (!BN_mod_exp_mont(tmp,pub_key,dh->priv_key,dh->p,&ctx,mont))
133 { 145 {
134 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB); 146 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
135 goto err; 147 goto err;
@@ -137,6 +149,6 @@ DH *dh;
137 149
138 ret=BN_bn2bin(tmp,key); 150 ret=BN_bn2bin(tmp,key);
139err: 151err:
140 if (ctx != NULL) BN_CTX_free(ctx); 152 BN_CTX_free(&ctx);
141 return(ret); 153 return(ret);
142 } 154 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "dh.h" 62#include <openssl/dh.h>
63 63
64char *DH_version="Diffie-Hellman part of SSLeay 0.9.0b 29-Jun-1998"; 64const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
65 65
66DH *DH_new() 66DH *DH_new(void)
67 { 67 {
68 DH *ret; 68 DH *ret;
69 69
@@ -80,21 +80,24 @@ DH *DH_new()
80 ret->length=0; 80 ret->length=0;
81 ret->pub_key=NULL; 81 ret->pub_key=NULL;
82 ret->priv_key=NULL; 82 ret->priv_key=NULL;
83 ret->flags=DH_FLAG_CACHE_MONT_P;
84 ret->method_mont_p=NULL;
83 return(ret); 85 return(ret);
84 } 86 }
85 87
86void DH_free(r) 88void DH_free(DH *r)
87DH *r;
88 { 89 {
90 if(r == NULL) return;
89 if (r->p != NULL) BN_clear_free(r->p); 91 if (r->p != NULL) BN_clear_free(r->p);
90 if (r->g != NULL) BN_clear_free(r->g); 92 if (r->g != NULL) BN_clear_free(r->g);
91 if (r->pub_key != NULL) BN_clear_free(r->pub_key); 93 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
92 if (r->priv_key != NULL) BN_clear_free(r->priv_key); 94 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
95 if (r->method_mont_p != NULL)
96 BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p);
93 Free(r); 97 Free(r);
94 } 98 }
95 99
96int DH_size(dh) 100int DH_size(DH *dh)
97DH *dh;
98 { 101 {
99 return(BN_num_bytes(dh->p)); 102 return(BN_num_bytes(dh->p));
100 } 103 }
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 @@
62#ifdef WINDOWS 62#ifdef WINDOWS
63#include "../bio/bss_file.c" 63#include "../bio/bss_file.c"
64#endif 64#endif
65#include "crypto.h" 65#include <openssl/crypto.h>
66#include "bio.h" 66#include <openssl/bio.h>
67#include "bn.h" 67#include <openssl/bn.h>
68#include "dh.h" 68
69#ifdef NO_DH
70int main(int argc, char *argv[])
71{
72 printf("No DH support\n");
73 return(0);
74}
75#else
76#include <openssl/dh.h>
69 77
70#ifdef WIN16 78#ifdef WIN16
71#define MS_CALLBACK _far _loadds 79#define MS_CALLBACK _far _loadds
@@ -73,12 +81,7 @@
73#define MS_CALLBACK 81#define MS_CALLBACK
74#endif 82#endif
75 83
76#ifndef NOPROTO 84static void MS_CALLBACK cb(int p, int n, void *arg);
77static void MS_CALLBACK cb(int p, int n, char *arg);
78#else
79static void MS_CALLBACK cb();
80#endif
81
82#ifdef NO_STDIO 85#ifdef NO_STDIO
83#define APPS_WIN16 86#define APPS_WIN16
84#include "bss_file.c" 87#include "bss_file.c"
@@ -86,9 +89,7 @@ static void MS_CALLBACK cb();
86 89
87BIO *out=NULL; 90BIO *out=NULL;
88 91
89int main(argc,argv) 92int main(int argc, char *argv[])
90int argc;
91char *argv[];
92 { 93 {
93 DH *a,*b; 94 DH *a,*b;
94 char buf[12]; 95 char buf[12];
@@ -103,7 +104,7 @@ char *argv[];
103 if (out == NULL) exit(1); 104 if (out == NULL) exit(1);
104 BIO_set_fp(out,stdout,BIO_NOCLOSE); 105 BIO_set_fp(out,stdout,BIO_NOCLOSE);
105 106
106 a=DH_generate_parameters(64,DH_GENERATOR_5,cb,(char *)out); 107 a=DH_generate_parameters(64,DH_GENERATOR_5,cb,out);
107 if (a == NULL) goto err; 108 if (a == NULL) goto err;
108 109
109 BIO_puts(out,"\np ="); 110 BIO_puts(out,"\np =");
@@ -170,10 +171,7 @@ err:
170 return(ret); 171 return(ret);
171 } 172 }
172 173
173static void MS_CALLBACK cb(p, n,arg) 174static void MS_CALLBACK cb(int p, int n, void *arg)
174int p;
175int n;
176char *arg;
177 { 175 {
178 char c='*'; 176 char c='*';
179 177
@@ -182,7 +180,9 @@ char *arg;
182 if (p == 2) c='*'; 180 if (p == 2) c='*';
183 if (p == 3) c='\n'; 181 if (p == 3) c='\n';
184 BIO_write((BIO *)arg,&c,1); 182 BIO_write((BIO *)arg,&c,1);
183 (void)BIO_flush((BIO *)arg);
185#ifdef LINT 184#ifdef LINT
186 p=n; 185 p=n;
187#endif 186#endif
188 } 187 }
188#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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "bn.h" 60#include <openssl/bn.h>
61#include "asn1.h" 61#include <openssl/asn1.h>
62#include "dh.h" 62#include <openssl/dh.h>
63#include "pem.h" 63#include <openssl/pem.h>
64 64
65unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD, 65unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD,
66 0x28,0x28,0xE1,0x3F,0x1D,0x68,0xB6,0xD3, 66 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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "bn.h" 60#include <openssl/bn.h>
61#include "asn1.h" 61#include <openssl/asn1.h>
62#include "dh.h" 62#include <openssl/dh.h>
63#include "pem.h" 63#include <openssl/pem.h>
64 64
65unsigned char data[]={ 65unsigned char data[]={
660xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E, 660xD4,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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "bn.h" 60#include <openssl/bn.h>
61#include "asn1.h" 61#include <openssl/asn1.h>
62#include "dh.h" 62#include <openssl/dh.h>
63#include "pem.h" 63#include <openssl/pem.h>
64 64
65unsigned char data[]={ 65unsigned char data[]={
660xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89, 660xDA,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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=dsa
19ERRC=dsa_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST=dsatest.c 21TEST=dsatest.c
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_vrf.c dsa_sign.c $(ERRC).c 25LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c dsa_err.c
26LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_vrf.o dsa_sign.o $(ERRC).o 26LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o dsa_err.o
27 27
28SRC= $(LIBSRC) 28SRC= $(LIBSRC)
29 29
@@ -39,24 +39,23 @@ all: lib
39 39
40lib: $(LIBOBJ) 40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
42 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
43 @touch lib 43 @touch lib
44 44
45files: 45files:
46 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
47 47
48links: 48links:
49 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
50 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
51 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
52 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
53 $(TOP)/util/mklink.sh ../../apps $(APPS)
54 53
55install: 54install:
56 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
57 do \ 56 do \
58 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done; 59 done;
61 60
62tags: 61tags:
@@ -68,17 +67,67 @@ lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
69 68
70depend: 69depend:
71 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
72 71
73dclean: 72dclean:
74 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
76 75
77clean: 76clean:
78 /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80errors:
81 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
82 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
83 78
84# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81dsa_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
82dsa_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
83dsa_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
84dsa_asn1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
85dsa_asn1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
86dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
87dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
88dsa_asn1.o: ../../include/openssl/stack.h ../cryptlib.h
89dsa_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h
90dsa_err.o: ../../include/openssl/dsa.h ../../include/openssl/err.h
91dsa_err.o: ../../include/openssl/opensslconf.h
92dsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
93dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
94dsa_gen.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
95dsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
96dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
97dsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
98dsa_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
99dsa_gen.o: ../cryptlib.h
100dsa_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
101dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
102dsa_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
103dsa_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
104dsa_key.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
105dsa_key.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
106dsa_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
107dsa_key.o: ../cryptlib.h
108dsa_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
109dsa_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
110dsa_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
111dsa_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
112dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
113dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
114dsa_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
115dsa_lib.o: ../cryptlib.h
116dsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
117dsa_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
118dsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
119dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
120dsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
121dsa_sign.o: ../../include/openssl/opensslconf.h
122dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
123dsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
124dsa_sign.o: ../cryptlib.h
125dsa_vrf.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
126dsa_vrf.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
127dsa_vrf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
128dsa_vrf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
129dsa_vrf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
130dsa_vrf.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
131dsa_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
132dsa_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
133dsa_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 @@
1/* Error codes for the DSA functions. */
2
3/* Function codes. */
4#define DSA_F_DSAPARAMS_PRINT 100
5#define DSA_F_DSAPARAMS_PRINT_FP 101
6#define DSA_F_DSA_IS_PRIME 102
7#define DSA_F_DSA_NEW 103
8#define DSA_F_DSA_PRINT 104
9#define DSA_F_DSA_PRINT_FP 105
10#define DSA_F_DSA_SIGN 106
11#define DSA_F_DSA_SIGN_SETUP 107
12#define DSA_F_DSA_VERIFY 108
13
14/* Reason codes. */
15#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 @@
69extern "C" { 69extern "C" {
70#endif 70#endif
71 71
72#include "bn.h" 72#ifdef NO_DSA
73#error DSA is disabled.
74#endif
75
76#include <openssl/bn.h>
77#ifndef NO_DH
78# include <openssl/dh.h>
79#endif
80
81#define DSA_FLAG_CACHE_MONT_P 0x01
73 82
74typedef struct dsa_st 83typedef struct dsa_st
75 { 84 {
@@ -88,9 +97,19 @@ typedef struct dsa_st
88 BIGNUM *kinv; /* Signing pre-calc */ 97 BIGNUM *kinv; /* Signing pre-calc */
89 BIGNUM *r; /* Signing pre-calc */ 98 BIGNUM *r; /* Signing pre-calc */
90 99
100 int flags;
101 /* Normally used to cache montgomery values */
102 char *method_mont_p;
103
91 int references; 104 int references;
92 } DSA; 105 } DSA;
93 106
107typedef struct DSA_SIG_st
108 {
109 BIGNUM *r;
110 BIGNUM *s;
111 } DSA_SIG;
112
94#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \ 113#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
95 (char *(*)())d2i_DSAparams,(char *)(x)) 114 (char *(*)())d2i_DSAparams,(char *)(x))
96#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ 115#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
@@ -102,15 +121,23 @@ typedef struct dsa_st
102#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \ 121#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \
103 (unsigned char *)(x)) 122 (unsigned char *)(x))
104 123
105#ifndef NOPROTO 124
125DSA_SIG * DSA_SIG_new(void);
126void DSA_SIG_free(DSA_SIG *a);
127int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp);
128DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length);
129
130DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
131int DSA_do_verify(const unsigned char *dgst,int dgst_len,
132 DSA_SIG *sig,DSA *dsa);
106 133
107DSA * DSA_new(void); 134DSA * DSA_new(void);
108int DSA_size(DSA *); 135int DSA_size(DSA *);
109 /* next 4 return -1 on error */ 136 /* next 4 return -1 on error */
110int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); 137int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
111int DSA_sign(int type,unsigned char *dgst,int dlen, 138int DSA_sign(int type,const unsigned char *dgst,int dlen,
112 unsigned char *sig, unsigned int *siglen, DSA *dsa); 139 unsigned char *sig, unsigned int *siglen, DSA *dsa);
113int DSA_verify(int type,unsigned char *dgst,int dgst_len, 140int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
114 unsigned char *sigbuf, int siglen, DSA *dsa); 141 unsigned char *sigbuf, int siglen, DSA *dsa);
115void DSA_free (DSA *r); 142void DSA_free (DSA *r);
116 143
@@ -138,55 +165,38 @@ int DSA_print_fp(FILE *bp, DSA *x, int off);
138 165
139int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg); 166int DSA_is_prime(BIGNUM *q,void (*callback)(),char *cb_arg);
140 167
141#else 168#ifndef NO_DH
142 169/* Convert DSA structure (key or just parameters) into DH structure
143DSA * DSA_new(); 170 * (be careful to avoid small subgroup attacks when using this!) */
144int DSA_size(); 171DH *DSA_dup_DH(DSA *r);
145int DSA_sign_setup();
146int DSA_sign();
147int DSA_verify();
148void DSA_free ();
149
150void ERR_load_DSA_strings();
151
152DSA * d2i_DSAPublicKey();
153DSA * d2i_DSAPrivateKey();
154DSA * d2i_DSAparams();
155DSA * DSA_generate_parameters();
156int DSA_generate_key();
157int i2d_DSAPublicKey();
158int i2d_DSAPrivateKey();
159int i2d_DSAparams();
160
161int DSA_is_prime();
162
163int DSAparams_print();
164int DSA_print();
165
166#ifndef NO_FP_API
167int DSAparams_print_fp();
168int DSA_print_fp();
169#endif
170
171#endif 172#endif
172 173
173/* BEGIN ERROR CODES */ 174/* BEGIN ERROR CODES */
175/* The following lines are auto generated by the script mkerr.pl. Any changes
176 * made after this point may be overwritten when the script is next run.
177 */
178
174/* Error codes for the DSA functions. */ 179/* Error codes for the DSA functions. */
175 180
176/* Function codes. */ 181/* Function codes. */
182#define DSA_F_D2I_DSA_SIG 110
177#define DSA_F_DSAPARAMS_PRINT 100 183#define DSA_F_DSAPARAMS_PRINT 100
178#define DSA_F_DSAPARAMS_PRINT_FP 101 184#define DSA_F_DSAPARAMS_PRINT_FP 101
185#define DSA_F_DSA_DO_SIGN 112
186#define DSA_F_DSA_DO_VERIFY 113
179#define DSA_F_DSA_IS_PRIME 102 187#define DSA_F_DSA_IS_PRIME 102
180#define DSA_F_DSA_NEW 103 188#define DSA_F_DSA_NEW 103
181#define DSA_F_DSA_PRINT 104 189#define DSA_F_DSA_PRINT 104
182#define DSA_F_DSA_PRINT_FP 105 190#define DSA_F_DSA_PRINT_FP 105
183#define DSA_F_DSA_SIGN 106 191#define DSA_F_DSA_SIGN 106
184#define DSA_F_DSA_SIGN_SETUP 107 192#define DSA_F_DSA_SIGN_SETUP 107
193#define DSA_F_DSA_SIG_NEW 109
185#define DSA_F_DSA_VERIFY 108 194#define DSA_F_DSA_VERIFY 108
195#define DSA_F_I2D_DSA_SIG 111
186 196
187/* Reason codes. */ 197/* Reason codes. */
188#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 198#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
189 199
190#ifdef __cplusplus 200#ifdef __cplusplus
191} 201}
192#endif 202#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 @@
1/* crypto/dsa/dsa_asn1.c */
2
3#include <stdio.h>
4#include "cryptlib.h"
5#include <openssl/dsa.h>
6#include <openssl/asn1.h>
7#include <openssl/asn1_mac.h>
8
9DSA_SIG *DSA_SIG_new(void)
10{
11 DSA_SIG *ret;
12
13 ret = Malloc(sizeof(DSA_SIG));
14 if (ret == NULL)
15 {
16 DSAerr(DSA_F_DSA_SIG_NEW,ERR_R_MALLOC_FAILURE);
17 return(NULL);
18 }
19 ret->r = NULL;
20 ret->s = NULL;
21 return(ret);
22}
23
24void DSA_SIG_free(DSA_SIG *r)
25{
26 if (r == NULL) return;
27 if (r->r) BN_clear_free(r->r);
28 if (r->s) BN_clear_free(r->s);
29 Free(r);
30}
31
32int i2d_DSA_SIG(DSA_SIG *v, unsigned char **pp)
33{
34 int t=0,len;
35 ASN1_INTEGER rbs,sbs;
36 unsigned char *p;
37
38 rbs.data=Malloc(BN_num_bits(v->r)/8+1);
39 if (rbs.data == NULL)
40 {
41 DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE);
42 return(0);
43 }
44 rbs.type=V_ASN1_INTEGER;
45 rbs.length=BN_bn2bin(v->r,rbs.data);
46 sbs.data=Malloc(BN_num_bits(v->s)/8+1);
47 if (sbs.data == NULL)
48 {
49 Free(rbs.data);
50 DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE);
51 return(0);
52 }
53 sbs.type=V_ASN1_INTEGER;
54 sbs.length=BN_bn2bin(v->s,sbs.data);
55
56 len=i2d_ASN1_INTEGER(&rbs,NULL);
57 len+=i2d_ASN1_INTEGER(&sbs,NULL);
58
59 if (pp)
60 {
61 p=*pp;
62 ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
63 i2d_ASN1_INTEGER(&rbs,&p);
64 i2d_ASN1_INTEGER(&sbs,&p);
65 }
66 t=ASN1_object_size(1,len,V_ASN1_SEQUENCE);
67 Free(rbs.data);
68 Free(sbs.data);
69 return(t);
70}
71
72DSA_SIG *d2i_DSA_SIG(DSA_SIG **a, unsigned char **pp, long length)
73{
74 int i=ERR_R_NESTED_ASN1_ERROR;
75 ASN1_INTEGER *bs=NULL;
76 M_ASN1_D2I_vars(a,DSA_SIG *,DSA_SIG_new);
77
78 M_ASN1_D2I_Init();
79 M_ASN1_D2I_start_sequence();
80 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
81 if ((ret->r=BN_bin2bn(bs->data,bs->length,ret->r)) == NULL)
82 goto err_bn;
83 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
84 if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL)
85 goto err_bn;
86 ASN1_BIT_STRING_free(bs);
87 M_ASN1_D2I_Finish_2(a);
88
89err_bn:
90 i=ERR_R_BN_LIB;
91err:
92 DSAerr(DSA_F_D2I_DSA_SIG,i);
93 if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret);
94 if (bs != NULL) ASN1_BIT_STRING_free(bs);
95 return(NULL);
96}
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
index 318e9f31aa..33a8270afd 100644
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ b/src/lib/libcrypto/dsa/dsa_err.c
@@ -1,94 +1,101 @@
1/* lib/dsa/dsa_err.c */ 1/* crypto/dsa/dsa_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "dsa.h" 62#include <openssl/dsa.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
64static ERR_STRING_DATA DSA_str_functs[]= 66static ERR_STRING_DATA DSA_str_functs[]=
65 { 67 {
68{ERR_PACK(0,DSA_F_D2I_DSA_SIG,0), "d2i_DSA_SIG"},
66{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"}, 69{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"},
67{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"}, 70{ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"},
71{ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"},
72{ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"},
68{ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"}, 73{ERR_PACK(0,DSA_F_DSA_IS_PRIME,0), "DSA_is_prime"},
69{ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"}, 74{ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"},
70{ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"}, 75{ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"},
71{ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"}, 76{ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"},
72{ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"}, 77{ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"},
73{ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"}, 78{ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"},
79{ERR_PACK(0,DSA_F_DSA_SIG_NEW,0), "DSA_SIG_new"},
74{ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"}, 80{ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"},
75{0,NULL}, 81{ERR_PACK(0,DSA_F_I2D_DSA_SIG,0), "i2d_DSA_SIG"},
82{0,NULL}
76 }; 83 };
77 84
78static ERR_STRING_DATA DSA_str_reasons[]= 85static ERR_STRING_DATA DSA_str_reasons[]=
79 { 86 {
80{DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, 87{DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
81{0,NULL}, 88{0,NULL}
82 }; 89 };
83 90
84#endif 91#endif
85 92
86void ERR_load_DSA_strings() 93void ERR_load_DSA_strings(void)
87 { 94 {
88 static int init=1; 95 static int init=1;
89 96
90 if (init); 97 if (init)
91 {; 98 {
92 init=0; 99 init=0;
93#ifndef NO_ERR 100#ifndef NO_ERR
94 ERR_load_strings(ERR_LIB_DSA,DSA_str_functs); 101 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 @@
64#define HASH SHA1 64#define HASH SHA1
65#endif 65#endif
66 66
67#ifndef NO_SHA
67#include <stdio.h> 68#include <stdio.h>
68#include <time.h> 69#include <time.h>
69#include "cryptlib.h" 70#include "cryptlib.h"
70#include "sha.h" 71#include <openssl/sha.h>
71#include "bn.h" 72#include <openssl/bn.h>
72#include "dsa.h" 73#include <openssl/dsa.h>
73#include "rand.h" 74#include <openssl/rand.h>
74 75
75DSA *DSA_generate_parameters(bits,seed_in,seed_len,counter_ret,h_ret,callback, 76DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
76 cb_arg) 77 int *counter_ret, unsigned long *h_ret, void (*callback)(),
77int bits; 78 char *cb_arg)
78unsigned char *seed_in;
79int seed_len;
80int *counter_ret;
81unsigned long *h_ret;
82void (*callback)();
83char *cb_arg;
84 { 79 {
85 int ok=0; 80 int ok=0;
86 unsigned char seed[SHA_DIGEST_LENGTH]; 81 unsigned char seed[SHA_DIGEST_LENGTH];
@@ -88,6 +83,7 @@ char *cb_arg;
88 unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH]; 83 unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
89 BIGNUM *r0,*W,*X,*c,*test; 84 BIGNUM *r0,*W,*X,*c,*test;
90 BIGNUM *g=NULL,*q=NULL,*p=NULL; 85 BIGNUM *g=NULL,*q=NULL,*p=NULL;
86 BN_MONT_CTX *mont=NULL;
91 int k,n=0,i,b,m=0; 87 int k,n=0,i,b,m=0;
92 int counter=0; 88 int counter=0;
93 BN_CTX *ctx=NULL,*ctx2=NULL; 89 BN_CTX *ctx=NULL,*ctx2=NULL;
@@ -100,20 +96,20 @@ char *cb_arg;
100 if ((seed_in != NULL) && (seed_len == 20)) 96 if ((seed_in != NULL) && (seed_len == 20))
101 memcpy(seed,seed_in,seed_len); 97 memcpy(seed,seed_in,seed_len);
102 98
103 ctx=BN_CTX_new(); 99 if ((ctx=BN_CTX_new()) == NULL) goto err;
104 if (ctx == NULL) goto err; 100 if ((ctx2=BN_CTX_new()) == NULL) goto err;
105 ctx2=BN_CTX_new(); 101 if ((ret=DSA_new()) == NULL) goto err;
106 if (ctx2 == NULL) goto err; 102
107 ret=DSA_new(); 103 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
108 if (ret == NULL) goto err; 104
109 r0=ctx2->bn[0]; 105 r0= &(ctx2->bn[0]);
110 g=ctx2->bn[1]; 106 g= &(ctx2->bn[1]);
111 W=ctx2->bn[2]; 107 W= &(ctx2->bn[2]);
112 q=ctx2->bn[3]; 108 q= &(ctx2->bn[3]);
113 X=ctx2->bn[4]; 109 X= &(ctx2->bn[4]);
114 c=ctx2->bn[5]; 110 c= &(ctx2->bn[5]);
115 p=ctx2->bn[6]; 111 p= &(ctx2->bn[6]);
116 test=ctx2->bn[7]; 112 test= &(ctx2->bn[7]);
117 113
118 BN_lshift(test,BN_value_one(),bits-1); 114 BN_lshift(test,BN_value_one(),bits-1);
119 115
@@ -216,14 +212,16 @@ end:
216 212
217 /* We now need to gernerate g */ 213 /* We now need to gernerate g */
218 /* Set r0=(p-1)/q */ 214 /* Set r0=(p-1)/q */
219 BN_sub(test,p,BN_value_one()); 215 BN_sub(test,p,BN_value_one());
220 BN_div(r0,NULL,test,q,ctx); 216 BN_div(r0,NULL,test,q,ctx);
221 217
222 BN_set_word(test,h); 218 BN_set_word(test,h);
219 BN_MONT_CTX_set(mont,p,ctx);
220
223 for (;;) 221 for (;;)
224 { 222 {
225 /* g=test^r0%p */ 223 /* g=test^r0%p */
226 BN_mod_exp(g,test,r0,p,ctx); 224 BN_mod_exp_mont(g,test,r0,p,ctx,mont);
227 if (!BN_is_one(g)) break; 225 if (!BN_is_one(g)) break;
228 BN_add(test,test,BN_value_one()); 226 BN_add(test,test,BN_value_one());
229 h++; 227 h++;
@@ -246,32 +244,32 @@ err:
246 if (counter_ret != NULL) *counter_ret=counter; 244 if (counter_ret != NULL) *counter_ret=counter;
247 if (h_ret != NULL) *h_ret=h; 245 if (h_ret != NULL) *h_ret=h;
248 } 246 }
249 BN_CTX_free(ctx); 247 if (ctx != NULL) BN_CTX_free(ctx);
250 BN_CTX_free(ctx2); 248 if (ctx != NULL) BN_CTX_free(ctx2);
249 if (mont != NULL) BN_MONT_CTX_free(mont);
251 return(ok?ret:NULL); 250 return(ok?ret:NULL);
252 } 251 }
253 252
254int DSA_is_prime(w, callback,cb_arg) 253int DSA_is_prime(BIGNUM *w, void (*callback)(), char *cb_arg)
255BIGNUM *w;
256void (*callback)();
257char *cb_arg;
258 { 254 {
259 int ok= -1,j,i,n; 255 int ok= -1,j,i,n;
260 BN_CTX *ctx=NULL,*ctx2=NULL; 256 BN_CTX *ctx=NULL,*ctx2=NULL;
261 BIGNUM *w_1,*b,*m,*z; 257 BIGNUM *w_1,*b,*m,*z,*tmp,*mont_1;
262 int a; 258 int a;
259 BN_MONT_CTX *mont=NULL;
263 260
264 if (!BN_is_bit_set(w,0)) return(0); 261 if (!BN_is_bit_set(w,0)) return(0);
265 262
266 ctx=BN_CTX_new(); 263 if ((ctx=BN_CTX_new()) == NULL) goto err;
267 if (ctx == NULL) goto err; 264 if ((ctx2=BN_CTX_new()) == NULL) goto err;
268 ctx2=BN_CTX_new(); 265 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
269 if (ctx2 == NULL) goto err;
270 266
271 m= ctx2->bn[2]; 267 m= &(ctx2->bn[2]);
272 b= ctx2->bn[3]; 268 b= &(ctx2->bn[3]);
273 z= ctx2->bn[4]; 269 z= &(ctx2->bn[4]);
274 w_1=ctx2->bn[5]; 270 w_1= &(ctx2->bn[5]);
271 tmp= &(ctx2->bn[6]);
272 mont_1= &(ctx2->bn[7]);
275 273
276 /* step 1 */ 274 /* step 1 */
277 n=50; 275 n=50;
@@ -282,24 +280,30 @@ char *cb_arg;
282 ; 280 ;
283 if (!BN_rshift(m,w_1,a)) goto err; 281 if (!BN_rshift(m,w_1,a)) goto err;
284 282
283 BN_MONT_CTX_set(mont,w,ctx);
284 BN_to_montgomery(mont_1,BN_value_one(),mont,ctx);
285 BN_to_montgomery(w_1,w_1,mont,ctx);
285 for (i=1; i < n; i++) 286 for (i=1; i < n; i++)
286 { 287 {
287 /* step 3 */ 288 /* step 3 */
288 BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0); 289 BN_rand(b,BN_num_bits(w)-2/*-1*/,0,0);
289 BN_set_word(b,0x10001L); 290 /* BN_set_word(b,0x10001L); */
290 291
291 /* step 4 */ 292 /* step 4 */
292 j=0; 293 j=0;
293 if (!BN_mod_exp(z,b,m,w,ctx)) goto err; 294 if (!BN_mod_exp_mont(z,b,m,w,ctx,mont)) goto err;
295
296 if (!BN_to_montgomery(z,z,mont,ctx)) goto err;
294 297
295 /* step 5 */ 298 /* step 5 */
296 for (;;) 299 for (;;)
297 { 300 {
298 if (((j == 0) && BN_is_one(z)) || (BN_cmp(z,w_1) == 0)) 301 if (((j == 0) && (BN_cmp(z,mont_1) == 0)) ||
302 (BN_cmp(z,w_1) == 0))
299 break; 303 break;
300 304
301 /* step 6 */ 305 /* step 6 */
302 if ((j > 0) && BN_is_one(z)) 306 if ((j > 0) && (BN_cmp(z,mont_1) == 0))
303 { 307 {
304 ok=0; 308 ok=0;
305 goto err; 309 goto err;
@@ -312,7 +316,7 @@ char *cb_arg;
312 goto err; 316 goto err;
313 } 317 }
314 318
315 if (!BN_mod_mul(z,z,z,w,ctx)) goto err; 319 if (!BN_mod_mul_montgomery(z,z,z,mont,ctx)) goto err;
316 if (callback != NULL) callback(1,j,cb_arg); 320 if (callback != NULL) callback(1,j,cb_arg);
317 } 321 }
318 } 322 }
@@ -322,7 +326,8 @@ err:
322 if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB); 326 if (ok == -1) DSAerr(DSA_F_DSA_IS_PRIME,ERR_R_BN_LIB);
323 BN_CTX_free(ctx); 327 BN_CTX_free(ctx);
324 BN_CTX_free(ctx2); 328 BN_CTX_free(ctx2);
329 BN_MONT_CTX_free(mont);
325 330
326 return(ok); 331 return(ok);
327 } 332 }
328 333#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_SHA
59#include <stdio.h> 60#include <stdio.h>
60#include <time.h> 61#include <time.h>
61#include "cryptlib.h" 62#include "cryptlib.h"
62#include "sha.h" 63#include <openssl/sha.h>
63#include "bn.h" 64#include <openssl/bn.h>
64#include "dsa.h" 65#include <openssl/dsa.h>
65#include "rand.h" 66#include <openssl/rand.h>
66 67
67int DSA_generate_key(dsa) 68int DSA_generate_key(DSA *dsa)
68DSA *dsa;
69 { 69 {
70 int ok=0; 70 int ok=0;
71 unsigned int i; 71 unsigned int i;
@@ -109,4 +109,4 @@ err:
109 if (ctx != NULL) BN_CTX_free(ctx); 109 if (ctx != NULL) BN_CTX_free(ctx);
110 return(ok); 110 return(ok);
111 } 111 }
112 112#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ 59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "bn.h" 63#include <openssl/bn.h>
64#include "dsa.h" 64#include <openssl/dsa.h>
65#include "asn1.h" 65#include <openssl/asn1.h>
66 66
67char *DSA_version="\0DSA part of SSLeay 0.9.0b 29-Jun-1998"; 67const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT;
68 68
69DSA *DSA_new() 69DSA *DSA_new(void)
70 { 70 {
71 DSA *ret; 71 DSA *ret;
72 72
@@ -82,19 +82,20 @@ DSA *DSA_new()
82 ret->p=NULL; 82 ret->p=NULL;
83 ret->q=NULL; 83 ret->q=NULL;
84 ret->g=NULL; 84 ret->g=NULL;
85 ret->flags=DSA_FLAG_CACHE_MONT_P;
85 86
86 ret->pub_key=NULL; 87 ret->pub_key=NULL;
87 ret->priv_key=NULL; 88 ret->priv_key=NULL;
88 89
89 ret->kinv=NULL; 90 ret->kinv=NULL;
90 ret->r=NULL; 91 ret->r=NULL;
92 ret->method_mont_p=NULL;
91 93
92 ret->references=1; 94 ret->references=1;
93 return(ret); 95 return(ret);
94 } 96 }
95 97
96void DSA_free(r) 98void DSA_free(DSA *r)
97DSA *r;
98 { 99 {
99 int i; 100 int i;
100 101
@@ -120,11 +121,12 @@ DSA *r;
120 if (r->priv_key != NULL) BN_clear_free(r->priv_key); 121 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
121 if (r->kinv != NULL) BN_clear_free(r->kinv); 122 if (r->kinv != NULL) BN_clear_free(r->kinv);
122 if (r->r != NULL) BN_clear_free(r->r); 123 if (r->r != NULL) BN_clear_free(r->r);
124 if (r->method_mont_p != NULL)
125 BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p);
123 Free(r); 126 Free(r);
124 } 127 }
125 128
126int DSA_size(r) 129int DSA_size(DSA *r)
127DSA *r;
128 { 130 {
129 int ret,i; 131 int ret,i;
130 ASN1_INTEGER bs; 132 ASN1_INTEGER bs;
@@ -143,3 +145,40 @@ DSA *r;
143 return(ret); 145 return(ret);
144 } 146 }
145 147
148#ifndef NO_DH
149DH *DSA_dup_DH(DSA *r)
150 {
151 /* DSA has p, q, g, optional pub_key, optional priv_key.
152 * DH has p, optional length, g, optional pub_key, optional priv_key.
153 */
154
155 DH *ret = NULL;
156
157 if (r == NULL)
158 goto err;
159 ret = DH_new();
160 if (ret == NULL)
161 goto err;
162 if (r->p != NULL)
163 if ((ret->p = BN_dup(r->p)) == NULL)
164 goto err;
165 if (r->q != NULL)
166 ret->length = BN_num_bits(r->q);
167 if (r->g != NULL)
168 if ((ret->g = BN_dup(r->g)) == NULL)
169 goto err;
170 if (r->pub_key != NULL)
171 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
172 goto err;
173 if (r->priv_key != NULL)
174 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
175 goto err;
176
177 return ret;
178
179 err:
180 if (ret != NULL)
181 DH_free(ret);
182 return NULL;
183 }
184#endif
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
index 6ca1c318f2..774c161964 100644
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ b/src/lib/libcrypto/dsa/dsa_sign.c
@@ -56,35 +56,28 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ 59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "bn.h" 63#include <openssl/bn.h>
64#include "dsa.h" 64#include <openssl/dsa.h>
65#include "rand.h" 65#include <openssl/rand.h>
66#include "asn1.h" 66#include <openssl/asn1.h>
67 67
68/* data has already been hashed (probably with SHA or SHA-1). */ 68DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
69/* DSAerr(DSA_F_DSA_SIGN,DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); */
70
71int DSA_sign(type,dgst,dlen,sig,siglen,dsa)
72int type;
73unsigned char *dgst;
74int dlen;
75unsigned char *sig; /* out */
76unsigned int *siglen; /* out */
77DSA *dsa;
78 { 69 {
79 BIGNUM *kinv=NULL,*r=NULL; 70 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
80 BIGNUM *m=NULL; 71 BIGNUM m;
81 BIGNUM *xr=NULL,*s=NULL; 72 BIGNUM xr;
82 BN_CTX *ctx=NULL; 73 BN_CTX *ctx=NULL;
83 unsigned char *p; 74 int i,reason=ERR_R_BN_LIB;
84 int i,len=0,ret=0,reason=ERR_R_BN_LIB; 75 DSA_SIG *ret=NULL;
85 ASN1_INTEGER rbs,sbs; 76
86 MS_STATIC unsigned char rbuf[50]; /* assuming r is 20 bytes +extra */ 77 BN_init(&m);
87 MS_STATIC unsigned char sbuf[50]; /* assuming s is 20 bytes +extra */ 78 BN_init(&xr);
79 s=BN_new();
80 if (s == NULL) goto err;
88 81
89 i=BN_num_bytes(dsa->q); /* should be 20 */ 82 i=BN_num_bytes(dsa->q); /* should be 20 */
90 if ((dlen > i) || (dlen > 50)) 83 if ((dlen > i) || (dlen > 50))
@@ -108,59 +101,58 @@ DSA *dsa;
108 dsa->r=NULL; 101 dsa->r=NULL;
109 } 102 }
110 103
111 m=BN_new(); 104 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
112 xr=BN_new();
113 s=BN_new();
114 if (m == NULL || xr == NULL || s == NULL) goto err;
115
116 if (BN_bin2bn(dgst,dlen,m) == NULL) goto err;
117 105
118 /* Compute s = inv(k) (m + xr) mod q */ 106 /* Compute s = inv(k) (m + xr) mod q */
119 if (!BN_mul(xr, dsa->priv_key, r)) goto err; /* s = xr */ 107 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
120 if (!BN_add(s, xr, m)) goto err; /* s = m + xr */ 108 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
109 if (BN_cmp(s,dsa->q) > 0)
110 BN_sub(s,s,dsa->q);
121 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err; 111 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
122 112
123 /* 113 ret=DSA_SIG_new();
124 * Now create a ASN.1 sequence of the integers R and S. 114 if (ret == NULL) goto err;
125 */ 115 ret->r = r;
126 rbs.data=rbuf; 116 ret->s = s;
127 sbs.data=sbuf; 117
128 rbs.type = V_ASN1_INTEGER;
129 sbs.type = V_ASN1_INTEGER;
130 rbs.length=BN_bn2bin(r,rbs.data);
131 sbs.length=BN_bn2bin(s,sbs.data);
132
133 len =i2d_ASN1_INTEGER(&rbs,NULL);
134 len+=i2d_ASN1_INTEGER(&sbs,NULL);
135
136 p=sig;
137 ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
138 i2d_ASN1_INTEGER(&rbs,&p);
139 i2d_ASN1_INTEGER(&sbs,&p);
140 *siglen=(p-sig);
141 ret=1;
142err: 118err:
143 if (!ret) DSAerr(DSA_F_DSA_SIGN,reason); 119 if (!ret)
144 120 {
145#if 1 /* do the right thing :-) */ 121 DSAerr(DSA_F_DSA_DO_SIGN,reason);
146 if (kinv != NULL) BN_clear_free(kinv); 122 BN_free(r);
147 if (r != NULL) BN_clear_free(r); 123 BN_free(s);
148#endif 124 }
149 if (ctx != NULL) BN_CTX_free(ctx); 125 if (ctx != NULL) BN_CTX_free(ctx);
150 if (m != NULL) BN_clear_free(m); 126 BN_clear_free(&m);
151 if (xr != NULL) BN_clear_free(xr); 127 BN_clear_free(&xr);
152 if (s != NULL) BN_clear_free(s); 128 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
129 BN_clear_free(kinv);
153 return(ret); 130 return(ret);
154 } 131 }
155 132
156int DSA_sign_setup(dsa,ctx_in,kinvp,rp) 133/* data has already been hashed (probably with SHA or SHA-1). */
157DSA *dsa; 134
158BN_CTX *ctx_in; 135/* unsigned char *sig: out */
159BIGNUM **kinvp; 136/* unsigned int *siglen: out */
160BIGNUM **rp; 137int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
138 unsigned int *siglen, DSA *dsa)
139 {
140 DSA_SIG *s;
141 s=DSA_do_sign(dgst,dlen,dsa);
142 if (s == NULL)
143 {
144 *siglen=0;
145 return(0);
146 }
147 *siglen=i2d_DSA_SIG(s,&sig);
148 DSA_SIG_free(s);
149 return(1);
150 }
151
152int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
161 { 153 {
162 BN_CTX *ctx; 154 BN_CTX *ctx;
163 BIGNUM *k=NULL,*kinv=NULL,*r=NULL; 155 BIGNUM k,*kinv=NULL,*r=NULL;
164 int ret=0; 156 int ret=0;
165 157
166 if (ctx_in == NULL) 158 if (ctx_in == NULL)
@@ -170,29 +162,33 @@ BIGNUM **rp;
170 else 162 else
171 ctx=ctx_in; 163 ctx=ctx_in;
172 164
173 r=BN_new(); 165 BN_init(&k);
174 k=BN_new(); 166 if ((r=BN_new()) == NULL) goto err;
175 if ((r == NULL) || (k == NULL))
176 goto err;
177 kinv=NULL; 167 kinv=NULL;
178 168
179 if (r == NULL) goto err;
180
181 /* Get random k */ 169 /* Get random k */
182 for (;;) 170 for (;;)
183 { 171 {
184 if (!BN_rand(k, BN_num_bits(dsa->q), 1, 0)) goto err; 172 if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err;
185 if (BN_cmp(k,dsa->q) >= 0) 173 if (BN_cmp(&k,dsa->q) >= 0)
186 BN_sub(k,k,dsa->q); 174 BN_sub(&k,&k,dsa->q);
187 if (!BN_is_zero(k)) break; 175 if (!BN_is_zero(&k)) break;
176 }
177
178 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
179 {
180 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
181 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
182 dsa->p,ctx)) goto err;
188 } 183 }
189 184
190 /* Compute r = (g^k mod p) mod q */ 185 /* Compute r = (g^k mod p) mod q */
191 if (!BN_mod_exp(r,dsa->g,k,dsa->p,ctx)) goto err; 186 if (!BN_mod_exp_mont(r,dsa->g,&k,dsa->p,ctx,
187 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
192 if (!BN_mod(r,r,dsa->q,ctx)) goto err; 188 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
193 189
194 /* Compute part of 's = inv(k) (m + xr) mod q' */ 190 /* Compute part of 's = inv(k) (m + xr) mod q' */
195 if ((kinv=BN_mod_inverse(k,dsa->q,ctx)) == NULL) goto err; 191 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
196 192
197 if (*kinvp != NULL) BN_clear_free(*kinvp); 193 if (*kinvp != NULL) BN_clear_free(*kinvp);
198 *kinvp=kinv; 194 *kinvp=kinv;
@@ -208,8 +204,8 @@ err:
208 if (r != NULL) BN_clear_free(r); 204 if (r != NULL) BN_clear_free(r);
209 } 205 }
210 if (ctx_in == NULL) BN_CTX_free(ctx); 206 if (ctx_in == NULL) BN_CTX_free(ctx);
211 if (k != NULL) BN_clear_free(k);
212 if (kinv != NULL) BN_clear_free(kinv); 207 if (kinv != NULL) BN_clear_free(kinv);
208 BN_clear_free(&k);
213 return(ret); 209 return(ret);
214 } 210 }
215 211
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* Origional version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ 59/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "bn.h" 63#include <openssl/bn.h>
64#include "dsa.h" 64#include <openssl/dsa.h>
65#include "rand.h" 65#include <openssl/rand.h>
66#include "asn1.h" 66#include <openssl/asn1.h>
67#include "asn1_mac.h" 67#include <openssl/asn1_mac.h>
68 68
69/* data has already been hashed (probably with SHA or SHA-1). */ 69int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
70/* returns 70 DSA *dsa)
71 * 1: correct signature
72 * 0: incorrect signature
73 * -1: error
74 */
75int DSA_verify(type,dgst,dgst_len,sigbuf,siglen, dsa)
76int type;
77unsigned char *dgst;
78int dgst_len;
79unsigned char *sigbuf;
80int siglen;
81DSA *dsa;
82 { 71 {
83 /* The next 3 are used by the M_ASN1 macros */
84 long length=siglen;
85 ASN1_CTX c;
86 unsigned char **pp= &sigbuf;
87 BN_CTX *ctx; 72 BN_CTX *ctx;
88 BIGNUM *r=NULL; 73 BIGNUM u1,u2,t1;
89 BIGNUM *t1=NULL,*t2=NULL; 74 BN_MONT_CTX *mont=NULL;
90 BIGNUM *u1=NULL,*u2=NULL;
91 ASN1_INTEGER *bs=NULL;
92 int ret = -1; 75 int ret = -1;
93 76
94 ctx=BN_CTX_new(); 77 if ((ctx=BN_CTX_new()) == NULL) goto err;
95 if (ctx == NULL) goto err; 78 BN_init(&u1);
96 79 BN_init(&u2);
97 t1=BN_new(); 80 BN_init(&t1);
98 t2=BN_new();
99 if (t1 == NULL || t2 == NULL) goto err;
100
101 M_ASN1_D2I_Init();
102 M_ASN1_D2I_start_sequence();
103 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
104 if ((r=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn;
105 M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
106 if ((u1=BN_bin2bn(bs->data,bs->length,NULL)) == NULL) goto err_bn;
107 if (!asn1_Finish(&c)) goto err;
108 81
109 /* Calculate W = inv(S) mod Q 82 /* Calculate W = inv(S) mod Q
110 * save W in u2 */ 83 * save W in u2 */
111 if ((u2=BN_mod_inverse(u1,dsa->q,ctx)) == NULL) goto err_bn; 84 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
112 85
113 /* save M in u1 */ 86 /* save M in u1 */
114 if (BN_bin2bn(dgst,dgst_len,u1) == NULL) goto err_bn; 87 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
115 88
116 /* u1 = M * w mod q */ 89 /* u1 = M * w mod q */
117 if (!BN_mod_mul(u1,u1,u2,dsa->q,ctx)) goto err_bn; 90 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
118 91
119 /* u2 = r * w mod q */ 92 /* u2 = r * w mod q */
120 if (!BN_mod_mul(u2,r,u2,dsa->q,ctx)) goto err_bn; 93 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
94
95 if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))
96 {
97 if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)
98 if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,
99 dsa->p,ctx)) goto err;
100 }
101 mont=(BN_MONT_CTX *)dsa->method_mont_p;
102
103#if 0
104 {
105 BIGNUM t2;
121 106
107 BN_init(&t2);
122 /* v = ( g^u1 * y^u2 mod p ) mod q */ 108 /* v = ( g^u1 * y^u2 mod p ) mod q */
123 /* let t1 = g ^ u1 mod p */ 109 /* let t1 = g ^ u1 mod p */
124 if (!BN_mod_exp(t1,dsa->g,u1,dsa->p,ctx)) goto err_bn; 110 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
125 /* let t2 = y ^ u2 mod p */ 111 /* let t2 = y ^ u2 mod p */
126 if (!BN_mod_exp(t2,dsa->pub_key,u2,dsa->p,ctx)) goto err_bn; 112 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
127 /* let u1 = t1 * t2 mod p */ 113 /* let u1 = t1 * t2 mod p */
128 if (!BN_mod_mul(u1,t1,t2,dsa->p,ctx)) goto err_bn; 114 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
115 BN_free(&t2);
116 }
129 /* let u1 = u1 mod q */ 117 /* let u1 = u1 mod q */
130 if (!BN_mod(u1,u1,dsa->q,ctx)) goto err_bn; 118 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
119#else
120 {
121 if (!BN_mod_exp2_mont(&t1,dsa->g,&u1,dsa->pub_key,&u2,dsa->p,ctx,mont))
122 goto err;
123 /* BN_copy(&u1,&t1); */
124 /* let u1 = u1 mod q */
125 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
126 }
127#endif
131 /* V is now in u1. If the signature is correct, it will be 128 /* V is now in u1. If the signature is correct, it will be
132 * equal to R. */ 129 * equal to R. */
133 ret=(BN_ucmp(u1, r) == 0); 130 ret=(BN_ucmp(&u1, sig->r) == 0);
134 if (0) 131
135 { 132 err:
136err: /* ASN1 error */ 133 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
137 DSAerr(DSA_F_DSA_VERIFY,c.error);
138 }
139 if (0)
140 {
141err_bn: /* BN error */
142 DSAerr(DSA_F_DSA_VERIFY,ERR_R_BN_LIB);
143 }
144 if (ctx != NULL) BN_CTX_free(ctx); 134 if (ctx != NULL) BN_CTX_free(ctx);
145 if (r != NULL) BN_free(r); 135 BN_free(&u1);
146 if (t1 != NULL) BN_free(t1); 136 BN_free(&u2);
147 if (t2 != NULL) BN_free(t2); 137 BN_free(&t1);
148 if (u1 != NULL) BN_free(u1); 138 return(ret);
149 if (u2 != NULL) BN_free(u2); 139 }
150 if (bs != NULL) ASN1_BIT_STRING_free(bs); 140
141/* data has already been hashed (probably with SHA or SHA-1). */
142/* returns
143 * 1: correct signature
144 * 0: incorrect signature
145 * -1: error
146 */
147int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
148 unsigned char *sigbuf, int siglen, DSA *dsa)
149 {
150 DSA_SIG *s;
151 int ret=-1;
152
153 s = DSA_SIG_new();
154 if (s == NULL) return(ret);
155 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
156 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
157err:
158 DSA_SIG_free(s);
151 return(ret); 159 return(ret);
152 } 160 }
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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "dsa.h" 60#include <openssl/dsa.h>
61 61
62#define TEST 62#define TEST
63#define GENUINE_DSA 63#define GENUINE_DSA
@@ -77,8 +77,7 @@ unsigned char seed[20]={
77 0xe0,0x42,0x7d,LAST_VALUE}; 77 0xe0,0x42,0x7d,LAST_VALUE};
78#endif 78#endif
79 79
80int cb(p,n) 80int cb(int p, int n)
81int p,n;
82 { 81 {
83 char c='*'; 82 char c='*';
84 83
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 @@
61#include <string.h> 61#include <string.h>
62#include <sys/types.h> 62#include <sys/types.h>
63#include <sys/stat.h> 63#include <sys/stat.h>
64#include "crypto.h" 64#include <openssl/crypto.h>
65#include "rand.h" 65#include <openssl/rand.h>
66#include "bio.h" 66#include <openssl/bio.h>
67#include "err.h" 67#include <openssl/err.h>
68#include "dsa.h"
69#ifdef WINDOWS 68#ifdef WINDOWS
70#include "../bio/bss_file.c" 69#include "../bio/bss_file.c"
71#endif 70#endif
72 71
72#ifdef NO_DSA
73int main(int argc, char *argv[])
74{
75 printf("No DSA support\n");
76 return(0);
77}
78#else
79#include <openssl/dsa.h>
80
73#ifdef WIN16 81#ifdef WIN16
74#define MS_CALLBACK _far _loadds 82#define MS_CALLBACK _far _loadds
75#else 83#else
76#define MS_CALLBACK 84#define MS_CALLBACK
77#endif 85#endif
78 86
79#ifndef NOPROTO
80static void MS_CALLBACK dsa_cb(int p, int n, char *arg); 87static void MS_CALLBACK dsa_cb(int p, int n, char *arg);
81#else
82static void MS_CALLBACK dsa_cb();
83#endif
84
85static unsigned char seed[20]={ 88static unsigned char seed[20]={
86 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40, 89 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40,
87 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3, 90 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3,
@@ -115,20 +118,24 @@ static unsigned char out_g[]={
115 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02, 118 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02,
116 }; 119 };
117 120
121static const unsigned char str1[]="12345678901234567890";
122
118static BIO *bio_err=NULL; 123static BIO *bio_err=NULL;
119 124
120int main(argc, argv) 125int main(int argc, char **argv)
121int argc;
122char **argv;
123 { 126 {
124 DSA *dsa=NULL; 127 DSA *dsa=NULL;
125 int counter,ret=0,i,j; 128 int counter,ret=0,i,j;
126 unsigned char buf[256]; 129 unsigned char buf[256];
127 unsigned long h; 130 unsigned long h;
131 unsigned char sig[256];
132 unsigned int siglen;
128 133
129 if (bio_err == NULL) 134 if (bio_err == NULL)
130 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 135 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
131 136
137 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
138
132 BIO_printf(bio_err,"test generation of DSA parameters\n"); 139 BIO_printf(bio_err,"test generation of DSA parameters\n");
133 BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n"); 140 BIO_printf(bio_err,"expect '.*' followed by 5 lines of '.'s and '+'s\n");
134 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb, 141 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,
@@ -178,21 +185,21 @@ char **argv;
178 BIO_printf(bio_err,"g value is wrong\n"); 185 BIO_printf(bio_err,"g value is wrong\n");
179 goto end; 186 goto end;
180 } 187 }
181 188 DSA_generate_key(dsa);
182 ret=1; 189 DSA_sign(0, str1, 20, sig, &siglen, dsa);
190 if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
191 ret=1;
183end: 192end:
184 if (!ret) 193 if (!ret)
185 ERR_print_errors(bio_err); 194 ERR_print_errors(bio_err);
186 if (bio_err != NULL) BIO_free(bio_err);
187 if (dsa != NULL) DSA_free(dsa); 195 if (dsa != NULL) DSA_free(dsa);
196 CRYPTO_mem_leaks(bio_err);
197 if (bio_err != NULL) BIO_free(bio_err);
188 exit(!ret); 198 exit(!ret);
189 return(0); 199 return(0);
190 } 200 }
191 201
192static void MS_CALLBACK dsa_cb(p, n, arg) 202static void MS_CALLBACK dsa_cb(int p, int n, char *arg)
193int p;
194int n;
195char *arg;
196 { 203 {
197 char c='*'; 204 char c='*';
198 static int ok=0,num=0; 205 static int ok=0,num=0;
@@ -202,7 +209,7 @@ char *arg;
202 if (p == 2) { c='*'; ok++; } 209 if (p == 2) { c='*'; ok++; }
203 if (p == 3) c='\n'; 210 if (p == 3) c='\n';
204 BIO_write((BIO *)arg,&c,1); 211 BIO_write((BIO *)arg,&c,1);
205 BIO_flush((BIO *)arg); 212 (void)BIO_flush((BIO *)arg);
206 213
207 if (!ok && (p == 0) && (num > 1)) 214 if (!ok && (p == 0) && (num > 1))
208 { 215 {
@@ -210,5 +217,4 @@ char *arg;
210 exit(1); 217 exit(1);
211 } 218 }
212 } 219 }
213 220#endif
214
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 @@
1#ifndef HEADER_EBCDIC_H
2#define HEADER_EBCDIC_H
3
4#include <sys/types.h>
5
6/* Avoid name clashes with other applications */
7#define os_toascii _eay2000_os_toascii
8#define os_toebcdic _eay2000_os_toebcdic
9#define ebcdic2ascii _eay2000_ebcdic2ascii
10#define ascii2ebcdic _eay2000_ascii2ebcdic
11
12extern const unsigned char os_toascii[256];
13extern const unsigned char os_toebcdic[256];
14void ebcdic2ascii(unsigned char *dest, const unsigned char *srce, size_t count);
15void ascii2ebcdic(unsigned char *dest, const unsigned char *srce, size_t count);
16
17#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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,44 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81err.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
85err.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
86err.o: ../cryptlib.h
87err_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
88err_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
89err_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
90err_all.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
91err_all.o: ../../include/openssl/des.h ../../include/openssl/dh.h
92err_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
93err_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
94err_all.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
95err_all.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
96err_all.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
97err_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
98err_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
99err_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
100err_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
101err_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
102err_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
103err_all.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
104err_all.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
105err_prn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
106err_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
107err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
108err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
109err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
110err_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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "lhash.h" 60#include <stdarg.h>
61#include "crypto.h" 61#include <openssl/lhash.h>
62#include <openssl/crypto.h>
62#include "cryptlib.h" 63#include "cryptlib.h"
63#include "buffer.h" 64#include <openssl/buffer.h>
64#include "err.h" 65#include <openssl/err.h>
65#include "crypto.h" 66#include <openssl/crypto.h>
66 67
67 68
68static LHASH *error_hash=NULL; 69static LHASH *error_hash=NULL;
69static LHASH *thread_hash=NULL; 70static LHASH *thread_hash=NULL;
70 71
71#ifndef NOPROTO
72static unsigned long err_hash(ERR_STRING_DATA *a); 72static unsigned long err_hash(ERR_STRING_DATA *a);
73static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); 73static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b);
74static unsigned long pid_hash(ERR_STATE *pid); 74static unsigned long pid_hash(ERR_STATE *pid);
75static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); 75static int pid_cmp(ERR_STATE *a,ERR_STATE *pid);
76static unsigned long get_error_values(int inc,char **file,int *line, 76static unsigned long get_error_values(int inc,const char **file,int *line,
77 char **data,int *flags); 77 const char **data,int *flags);
78static void ERR_STATE_free(ERR_STATE *s); 78static void ERR_STATE_free(ERR_STATE *s);
79#else
80static unsigned long err_hash();
81static int err_cmp();
82static unsigned long pid_hash();
83static int pid_cmp();
84static void ERR_STATE_free();
85ERR_STATE *s;
86#endif
87
88#ifndef NO_ERR 79#ifndef NO_ERR
89static ERR_STRING_DATA ERR_str_libraries[]= 80static ERR_STRING_DATA ERR_str_libraries[]=
90 { 81 {
@@ -107,6 +98,8 @@ static ERR_STRING_DATA ERR_str_libraries[]=
107{ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"}, 98{ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"},
108{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"}, 99{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
109{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"}, 100{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
101{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
102{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
110{0,NULL}, 103{0,NULL},
111 }; 104 };
112 105
@@ -123,6 +116,7 @@ static ERR_STRING_DATA ERR_str_functs[]=
123#ifdef WINDOWS 116#ifdef WINDOWS
124 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"}, 117 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
125#endif 118#endif
119 {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
126 {0,NULL}, 120 {0,NULL},
127 }; 121 };
128 122
@@ -146,8 +140,17 @@ static ERR_STRING_DATA ERR_str_reasons[]=
146{ERR_R_PROXY_LIB ,"PROXY lib"}, 140{ERR_R_PROXY_LIB ,"PROXY lib"},
147{ERR_R_BIO_LIB ,"BIO lib"}, 141{ERR_R_BIO_LIB ,"BIO lib"},
148{ERR_R_PKCS7_LIB ,"PKCS7 lib"}, 142{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
143{ERR_R_PKCS12_LIB ,"PKCS12 lib"},
149{ERR_R_MALLOC_FAILURE ,"Malloc failure"}, 144{ERR_R_MALLOC_FAILURE ,"Malloc failure"},
150{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a fuction you should not call"}, 145{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
146{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
147{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"},
148{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"},
149{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"},
150{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
151{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
152{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
153
151{0,NULL}, 154{0,NULL},
152 }; 155 };
153#endif 156#endif
@@ -161,11 +164,13 @@ static ERR_STRING_DATA ERR_str_reasons[]=
161 } \ 164 } \
162 (p)->err_data_flags[i]=0; 165 (p)->err_data_flags[i]=0;
163 166
164static void ERR_STATE_free(s) 167static void ERR_STATE_free(ERR_STATE *s)
165ERR_STATE *s;
166 { 168 {
167 int i; 169 int i;
168 170
171 if(s == NULL)
172 return;
173
169 for (i=0; i<ERR_NUM_ERRORS; i++) 174 for (i=0; i<ERR_NUM_ERRORS; i++)
170 { 175 {
171 err_clear_data(s,i); 176 err_clear_data(s,i);
@@ -173,7 +178,7 @@ ERR_STATE *s;
173 Free(s); 178 Free(s);
174 } 179 }
175 180
176void ERR_load_ERR_strings() 181void ERR_load_ERR_strings(void)
177 { 182 {
178 static int init=1; 183 static int init=1;
179 184
@@ -196,9 +201,7 @@ void ERR_load_ERR_strings()
196 } 201 }
197 } 202 }
198 203
199void ERR_load_strings(lib,str) 204void ERR_load_strings(int lib, ERR_STRING_DATA *str)
200int lib;
201ERR_STRING_DATA *str;
202 { 205 {
203 if (error_hash == NULL) 206 if (error_hash == NULL)
204 { 207 {
@@ -224,7 +227,7 @@ ERR_STRING_DATA *str;
224 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH); 227 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
225 } 228 }
226 229
227void ERR_free_strings() 230void ERR_free_strings(void)
228 { 231 {
229 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 232 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
230 233
@@ -239,13 +242,30 @@ void ERR_free_strings()
239 242
240/********************************************************/ 243/********************************************************/
241 244
242void ERR_put_error(lib,func,reason,file,line) 245void ERR_put_error(int lib, int func, int reason, const char *file,
243int lib,func,reason; 246 int line)
244char *file;
245int line;
246 { 247 {
247 ERR_STATE *es; 248 ERR_STATE *es;
248 249
250#ifdef _OSD_POSIX
251 /* In the BS2000-OSD POSIX subsystem, the compiler generates
252 * path names in the form "*POSIX(/etc/passwd)".
253 * This dirty hack strips them to something sensible.
254 * @@@ We shouldn't modify a const string, though.
255 */
256 if (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
257 char *end;
258
259 /* Skip the "*POSIX(" prefix */
260 file += sizeof("*POSIX(")-1;
261 end = &file[strlen(file)-1];
262 if (*end == ')')
263 *end = '\0';
264 /* Optional: use the basename of the path only. */
265 if ((end = strrchr(file, '/')) != NULL)
266 file = &end[1];
267 }
268#endif
249 es=ERR_get_state(); 269 es=ERR_get_state();
250 270
251 es->top=(es->top+1)%ERR_NUM_ERRORS; 271 es->top=(es->top+1)%ERR_NUM_ERRORS;
@@ -257,7 +277,7 @@ int line;
257 err_clear_data(es,es->top); 277 err_clear_data(es,es->top);
258 } 278 }
259 279
260void ERR_clear_error() 280void ERR_clear_error(void)
261 { 281 {
262 ERR_STATE *es; 282 ERR_STATE *es;
263 283
@@ -277,42 +297,32 @@ void ERR_clear_error()
277 } 297 }
278 298
279 299
280unsigned long ERR_get_error() 300unsigned long ERR_get_error(void)
281 { return(get_error_values(1,NULL,NULL,NULL,NULL)); } 301 { return(get_error_values(1,NULL,NULL,NULL,NULL)); }
282 302
283unsigned long ERR_get_error_line(file,line) 303unsigned long ERR_get_error_line(const char **file,
284char **file; 304 int *line)
285int *line;
286 { return(get_error_values(1,file,line,NULL,NULL)); } 305 { return(get_error_values(1,file,line,NULL,NULL)); }
287 306
288unsigned long ERR_get_error_line_data(file,line,data,flags) 307unsigned long ERR_get_error_line_data(const char **file, int *line,
289char **file; 308 const char **data, int *flags)
290int *line; 309 { return(get_error_values(1,file,line,
291char **data; 310 data,flags)); }
292int *flags;
293 { return(get_error_values(1,file,line,data,flags)); }
294 311
295unsigned long ERR_peek_error() 312unsigned long ERR_peek_error(void)
296 { return(get_error_values(0,NULL,NULL,NULL,NULL)); } 313 { return(get_error_values(0,NULL,NULL,NULL,NULL)); }
297 314
298unsigned long ERR_peek_error_line(file,line) 315unsigned long ERR_peek_error_line(const char **file,
299char **file; 316 int *line)
300int *line;
301 { return(get_error_values(0,file,line,NULL,NULL)); } 317 { return(get_error_values(0,file,line,NULL,NULL)); }
302 318
303unsigned long ERR_peek_error_line_data(file,line,data,flags) 319unsigned long ERR_peek_error_line_data(const char **file, int *line,
304char **file; 320 const char **data, int *flags)
305int *line; 321 { return(get_error_values(0,file,line,
306char **data; 322 data,flags)); }
307int *flags; 323
308 { return(get_error_values(0,file,line,data,flags)); } 324static unsigned long get_error_values(int inc, const char **file, int *line,
309 325 const char **data, int *flags)
310static unsigned long get_error_values(inc,file,line,data,flags)
311int inc;
312char **file;
313int *line;
314char **data;
315int *flags;
316 { 326 {
317 int i=0; 327 int i=0;
318 ERR_STATE *es; 328 ERR_STATE *es;
@@ -361,12 +371,10 @@ int *flags;
361 } 371 }
362 372
363/* BAD for multi-threaded, uses a local buffer if ret == NULL */ 373/* BAD for multi-threaded, uses a local buffer if ret == NULL */
364char *ERR_error_string(e,ret) 374char *ERR_error_string(unsigned long e, char *ret)
365unsigned long e;
366char *ret;
367 { 375 {
368 static char buf[256]; 376 static char buf[256];
369 char *ls,*fs,*rs; 377 const char *ls,*fs,*rs;
370 unsigned long l,f,r; 378 unsigned long l,f,r;
371 int i; 379 int i;
372 380
@@ -397,18 +405,17 @@ char *ret;
397 return(ret); 405 return(ret);
398 } 406 }
399 407
400LHASH *ERR_get_string_table() 408LHASH *ERR_get_string_table(void)
401 { 409 {
402 return(error_hash); 410 return(error_hash);
403 } 411 }
404 412
405LHASH *ERR_get_err_state_table() 413LHASH *ERR_get_err_state_table(void)
406 { 414 {
407 return(thread_hash); 415 return(thread_hash);
408 } 416 }
409 417
410char *ERR_lib_error_string(e) 418const char *ERR_lib_error_string(unsigned long e)
411unsigned long e;
412 { 419 {
413 ERR_STRING_DATA d,*p=NULL; 420 ERR_STRING_DATA d,*p=NULL;
414 unsigned long l; 421 unsigned long l;
@@ -428,8 +435,7 @@ unsigned long e;
428 return((p == NULL)?NULL:p->string); 435 return((p == NULL)?NULL:p->string);
429 } 436 }
430 437
431char *ERR_func_error_string(e) 438const char *ERR_func_error_string(unsigned long e)
432unsigned long e;
433 { 439 {
434 ERR_STRING_DATA d,*p=NULL; 440 ERR_STRING_DATA d,*p=NULL;
435 unsigned long l,f; 441 unsigned long l,f;
@@ -450,8 +456,7 @@ unsigned long e;
450 return((p == NULL)?NULL:p->string); 456 return((p == NULL)?NULL:p->string);
451 } 457 }
452 458
453char *ERR_reason_error_string(e) 459const char *ERR_reason_error_string(unsigned long e)
454unsigned long e;
455 { 460 {
456 ERR_STRING_DATA d,*p=NULL; 461 ERR_STRING_DATA d,*p=NULL;
457 unsigned long l,r; 462 unsigned long l,r;
@@ -478,8 +483,7 @@ unsigned long e;
478 return((p == NULL)?NULL:p->string); 483 return((p == NULL)?NULL:p->string);
479 } 484 }
480 485
481static unsigned long err_hash(a) 486static unsigned long err_hash(ERR_STRING_DATA *a)
482ERR_STRING_DATA *a;
483 { 487 {
484 unsigned long ret,l; 488 unsigned long ret,l;
485 489
@@ -488,26 +492,22 @@ ERR_STRING_DATA *a;
488 return(ret^ret%19*13); 492 return(ret^ret%19*13);
489 } 493 }
490 494
491static int err_cmp(a,b) 495static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b)
492ERR_STRING_DATA *a,*b;
493 { 496 {
494 return((int)(a->error-b->error)); 497 return((int)(a->error-b->error));
495 } 498 }
496 499
497static unsigned long pid_hash(a) 500static unsigned long pid_hash(ERR_STATE *a)
498ERR_STATE *a;
499 { 501 {
500 return(a->pid*13); 502 return(a->pid*13);
501 } 503 }
502 504
503static int pid_cmp(a,b) 505static int pid_cmp(ERR_STATE *a, ERR_STATE *b)
504ERR_STATE *a,*b;
505 { 506 {
506 return((int)((long)a->pid - (long)b->pid)); 507 return((int)((long)a->pid - (long)b->pid));
507 } 508 }
508 509
509void ERR_remove_state(pid) 510void ERR_remove_state(unsigned long pid)
510unsigned long pid;
511 { 511 {
512 ERR_STATE *p,tmp; 512 ERR_STATE *p,tmp;
513 513
@@ -523,7 +523,7 @@ unsigned long pid;
523 if (p != NULL) ERR_STATE_free(p); 523 if (p != NULL) ERR_STATE_free(p);
524 } 524 }
525 525
526ERR_STATE *ERR_get_state() 526ERR_STATE *ERR_get_state(void)
527 { 527 {
528 static ERR_STATE fallback; 528 static ERR_STATE fallback;
529 ERR_STATE *ret=NULL,tmp,*tmpp; 529 ERR_STATE *ret=NULL,tmp,*tmpp;
@@ -539,7 +539,9 @@ ERR_STATE *ERR_get_state()
539 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 539 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
540 if (thread_hash == NULL) 540 if (thread_hash == NULL)
541 { 541 {
542 MemCheck_off();
542 thread_hash=lh_new(pid_hash,pid_cmp); 543 thread_hash=lh_new(pid_hash,pid_cmp);
544 MemCheck_on();
543 CRYPTO_w_unlock(CRYPTO_LOCK_ERR); 545 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
544 if (thread_hash == NULL) return(&fallback); 546 if (thread_hash == NULL) return(&fallback);
545 } 547 }
@@ -577,16 +579,14 @@ ERR_STATE *ERR_get_state()
577 return(ret); 579 return(ret);
578 } 580 }
579 581
580int ERR_get_next_error_library() 582int ERR_get_next_error_library(void)
581 { 583 {
582 static int value=ERR_LIB_USER; 584 static int value=ERR_LIB_USER;
583 585
584 return(value++); 586 return(value++);
585 } 587 }
586 588
587void ERR_set_error_data(data,flags) 589void ERR_set_error_data(char *data, int flags)
588char *data;
589int flags;
590 { 590 {
591 ERR_STATE *es; 591 ERR_STATE *es;
592 int i; 592 int i;
@@ -601,10 +601,9 @@ int flags;
601 es->err_data_flags[es->top]=flags; 601 es->err_data_flags[es->top]=flags;
602 } 602 }
603 603
604void ERR_add_error_data( VAR_PLIST(int , num)) 604void ERR_add_error_data(int num, ...)
605VAR_ALIST 605 {
606 { 606 va_list args;
607 VAR_BDEFN(args, int, num);
608 int i,n,s; 607 int i,n,s;
609 char *str,*p,*a; 608 char *str,*p,*a;
610 609
@@ -613,12 +612,14 @@ VAR_ALIST
613 if (str == NULL) return; 612 if (str == NULL) return;
614 str[0]='\0'; 613 str[0]='\0';
615 614
616 VAR_INIT(args,int,num); 615 va_start(args, num);
617 n=0; 616 n=0;
618 for (i=0; i<num; i++) 617 for (i=0; i<num; i++)
619 { 618 {
620 VAR_ARG(args,char *,a); 619 a=va_arg(args, char*);
621 if (a != NULL) { 620 /* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
621 if (a != NULL)
622 {
622 n+=strlen(a); 623 n+=strlen(a);
623 if (n > s) 624 if (n > s)
624 { 625 {
@@ -637,6 +638,6 @@ VAR_ALIST
637 } 638 }
638 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); 639 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
639 640
640 VAR_END( args ); 641 va_end(args);
641 } 642 }
642 643
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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifndef NO_FP_API
67#include <stdio.h>
68#endif
69
66/* The following is a bit of a trick to help the object files only contain 70/* The following is a bit of a trick to help the object files only contain
67 * the 'name of the file' string once. Since 'err.h' is protected by the 71 * the 'name of the file' string once. Since 'err.h' is protected by the
68 * HEADER_ERR_H stuff, this should be included only once per file. */ 72 * HEADER_ERR_H stuff, this should be included only once per file. */
@@ -87,7 +91,7 @@ typedef struct err_state_st
87 unsigned long err_buffer[ERR_NUM_ERRORS]; 91 unsigned long err_buffer[ERR_NUM_ERRORS];
88 char *err_data[ERR_NUM_ERRORS]; 92 char *err_data[ERR_NUM_ERRORS];
89 int err_data_flags[ERR_NUM_ERRORS]; 93 int err_data_flags[ERR_NUM_ERRORS];
90 char *err_file[ERR_NUM_ERRORS]; 94 const char *err_file[ERR_NUM_ERRORS];
91 int err_line[ERR_NUM_ERRORS]; 95 int err_line[ERR_NUM_ERRORS];
92 int top,bottom; 96 int top,bottom;
93 } ERR_STATE; 97 } ERR_STATE;
@@ -116,6 +120,8 @@ typedef struct err_state_st
116#define ERR_LIB_PROXY 31 120#define ERR_LIB_PROXY 31
117#define ERR_LIB_BIO 32 121#define ERR_LIB_BIO 32
118#define ERR_LIB_PKCS7 33 122#define ERR_LIB_PKCS7 33
123#define ERR_LIB_X509V3 34
124#define ERR_LIB_PKCS12 35
119 125
120#define ERR_LIB_USER 128 126#define ERR_LIB_USER 128
121 127
@@ -141,6 +147,8 @@ typedef struct err_state_st
141#define RSAREFerr(f,r) ERR_PUT_error(ERR_LIB_RSAREF,(f),(r),ERR_file_name,__LINE__) 147#define RSAREFerr(f,r) ERR_PUT_error(ERR_LIB_RSAREF,(f),(r),ERR_file_name,__LINE__)
142#define PROXYerr(f,r) ERR_PUT_error(ERR_LIB_PROXY,(f),(r),ERR_file_name,__LINE__) 148#define PROXYerr(f,r) ERR_PUT_error(ERR_LIB_PROXY,(f),(r),ERR_file_name,__LINE__)
143#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__) 149#define PKCS7err(f,r) ERR_PUT_error(ERR_LIB_PKCS7,(f),(r),ERR_file_name,__LINE__)
150#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__)
151#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__)
144 152
145/* Borland C seems too stupid to be able to shift and do longs in 153/* Borland C seems too stupid to be able to shift and do longs in
146 * the pre-processor :-( */ 154 * the pre-processor :-( */
@@ -162,6 +170,7 @@ typedef struct err_state_st
162#define SYS_F_LISTEN 7 170#define SYS_F_LISTEN 7
163#define SYS_F_ACCEPT 8 171#define SYS_F_ACCEPT 8
164#define SYS_F_WSASTARTUP 9 /* Winsock stuff */ 172#define SYS_F_WSASTARTUP 9 /* Winsock stuff */
173#define SYS_F_OPENDIR 10
165 174
166#define ERR_R_FATAL 32 175#define ERR_R_FATAL 32
167/* reasons */ 176/* reasons */
@@ -187,41 +196,47 @@ typedef struct err_state_st
187#define ERR_R_PROXY_LIB ERR_LIB_PROXY 196#define ERR_R_PROXY_LIB ERR_LIB_PROXY
188#define ERR_R_BIO_LIB ERR_LIB_BIO 197#define ERR_R_BIO_LIB ERR_LIB_BIO
189#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 198#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7
199#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12
190 200
191/* fatal error */ 201/* fatal error */
192#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) 202#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
193#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) 203#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
194#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) 204#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
205#define ERR_R_NESTED_ASN1_ERROR (4)
206#define ERR_R_BAD_ASN1_OBJECT_HEADER (5)
207#define ERR_R_BAD_GET_ASN1_OBJECT_CALL (6)
208#define ERR_R_EXPECTING_AN_ASN1_SEQUENCE (7)
209#define ERR_R_ASN1_LENGTH_MISMATCH (8)
210#define ERR_R_MISSING_ASN1_EOS (9)
195 211
196typedef struct ERR_string_data_st 212typedef struct ERR_string_data_st
197 { 213 {
198 unsigned long error; 214 unsigned long error;
199 char *string; 215 const char *string;
200 } ERR_STRING_DATA; 216 } ERR_STRING_DATA;
201 217
202#ifndef NOPROTO 218void ERR_put_error(int lib, int func,int reason,const char *file,int line);
203void ERR_put_error(int lib, int func,int reason,char *file,int line);
204void ERR_set_error_data(char *data,int flags); 219void ERR_set_error_data(char *data,int flags);
205 220
206unsigned long ERR_get_error(void ); 221unsigned long ERR_get_error(void );
207unsigned long ERR_get_error_line(char **file,int *line); 222unsigned long ERR_get_error_line(const char **file,int *line);
208unsigned long ERR_get_error_line_data(char **file,int *line, 223unsigned long ERR_get_error_line_data(const char **file,int *line,
209 char **data, int *flags); 224 const char **data, int *flags);
210unsigned long ERR_peek_error(void ); 225unsigned long ERR_peek_error(void );
211unsigned long ERR_peek_error_line(char **file,int *line); 226unsigned long ERR_peek_error_line(const char **file,int *line);
212unsigned long ERR_peek_error_line_data(char **file,int *line, 227unsigned long ERR_peek_error_line_data(const char **file,int *line,
213 char **data,int *flags); 228 const char **data,int *flags);
214void ERR_clear_error(void ); 229void ERR_clear_error(void );
215char *ERR_error_string(unsigned long e,char *buf); 230char *ERR_error_string(unsigned long e,char *buf);
216char *ERR_lib_error_string(unsigned long e); 231const char *ERR_lib_error_string(unsigned long e);
217char *ERR_func_error_string(unsigned long e); 232const char *ERR_func_error_string(unsigned long e);
218char *ERR_reason_error_string(unsigned long e); 233const char *ERR_reason_error_string(unsigned long e);
219#ifndef NO_FP_API 234#ifndef NO_FP_API
220void ERR_print_errors_fp(FILE *fp); 235void ERR_print_errors_fp(FILE *fp);
221#endif 236#endif
222#ifdef HEADER_BIO_H 237#ifdef HEADER_BIO_H
223void ERR_print_errors(BIO *bp); 238void ERR_print_errors(BIO *bp);
224void ERR_add_error_data( VAR_PLIST( int, num ) ); 239void ERR_add_error_data(int num, ...);
225#endif 240#endif
226void ERR_load_strings(int lib,ERR_STRING_DATA str[]); 241void ERR_load_strings(int lib,ERR_STRING_DATA str[]);
227void ERR_load_ERR_strings(void ); 242void ERR_load_ERR_strings(void );
@@ -241,45 +256,6 @@ char *ERR_get_err_state_table(void );
241 256
242int ERR_get_next_error_library(void ); 257int ERR_get_next_error_library(void );
243 258
244#else
245
246void ERR_put_error();
247void ERR_set_error_data();
248
249unsigned long ERR_get_error();
250unsigned long ERR_get_error_line();
251unsigned long ERR_peek_error();
252unsigned long ERR_peek_error_line();
253void ERR_clear_error();
254char *ERR_error_string();
255char *ERR_lib_error_string();
256char *ERR_func_error_string();
257char *ERR_reason_error_string();
258#ifndef NO_FP_API
259void ERR_print_errors_fp();
260#endif
261void ERR_print_errors();
262void ERR_add_error_data();
263void ERR_load_strings();
264void ERR_load_ERR_strings();
265void ERR_load_crypto_strings();
266void ERR_free_strings();
267
268void ERR_remove_state();
269ERR_STATE *ERR_get_state();
270
271#ifdef HEADER_LHASH_H
272LHASH *ERR_get_string_table();
273LHASH *ERR_get_err_state_table();
274#else
275char *ERR_get_string_table();
276char *ERR_get_err_state_table();
277#endif
278
279int ERR_get_next_error_library();
280
281#endif
282
283#ifdef __cplusplus 259#ifdef __cplusplus
284} 260}
285#endif 261#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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "asn1.h" 60#include <openssl/asn1.h>
61#include "bn.h" 61#include <openssl/bn.h>
62#include "buffer.h" 62#include <openssl/buffer.h>
63#include "bio.h" 63#include <openssl/bio.h>
64#ifndef NO_RSA 64#ifndef NO_RSA
65#include "rsa.h" 65#include <openssl/rsa.h>
66#endif 66#endif
67#ifdef RSAref 67#ifdef RSAref
68#include "rsaref.h" 68#include <openssl/rsaref.h>
69#endif 69#endif
70#ifndef NO_DH 70#ifndef NO_DH
71#include "dh.h" 71#include <openssl/dh.h>
72#endif 72#endif
73#ifndef NO_DSA 73#ifndef NO_DSA
74#include "dsa.h" 74#include <openssl/dsa.h>
75#endif 75#endif
76#include "evp.h" 76#include <openssl/evp.h>
77#include "objects.h" 77#include <openssl/objects.h>
78#include "pem.h" 78#include <openssl/pem2.h>
79#include "x509.h" 79#include <openssl/x509.h>
80#include "conf.h" 80#include <openssl/x509v3.h>
81#include "err.h" 81#include <openssl/conf.h>
82#include <openssl/pkcs12.h>
83#include <openssl/err.h>
82 84
83void ERR_load_crypto_strings() 85void ERR_load_crypto_strings(void)
84 { 86 {
85 static int done=0; 87 static int done=0;
86 88
@@ -110,7 +112,9 @@ void ERR_load_crypto_strings()
110 ERR_load_OBJ_strings(); 112 ERR_load_OBJ_strings();
111 ERR_load_PEM_strings(); 113 ERR_load_PEM_strings();
112 ERR_load_X509_strings(); 114 ERR_load_X509_strings();
115 ERR_load_X509V3_strings();
113 ERR_load_CRYPTO_strings(); 116 ERR_load_CRYPTO_strings();
114 ERR_load_PKCS7_strings(); 117 ERR_load_PKCS7_strings();
118 ERR_load_PKCS12_strings();
115#endif 119#endif
116 } 120 }
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 @@
1#!/usr/bin/perl
2
3while (@ARGV)
4 {
5 $in=shift(@ARGV);
6 if ($in =~ /^-conf$/)
7 {
8 $in=shift(@ARGV);
9 open(IN,"<$in") || die "unable to open '$in'\n";
10 while (<IN>)
11 {
12 s/#.*$//;
13 s/\s+$//;
14 next if (/^$/);
15 if (/^L\s+(\S+)\s+(\S+)$/)
16 { $errfile{$1}=$2; }
17 elsif (/^F\s+(\S+)$/)
18 { $function{$1}=1; }
19 elsif (/^R\s+(\S+)\s+(\S+)$/)
20 { $r_value{$1}=$2; }
21 else { die "bad input line: $in:$.\n"; }
22 }
23 close(IN);
24 next;
25 }
26
27 open(IN,"<$in") || die "unable to open '$in'\n";
28 $last="";
29 while (<IN>)
30 {
31 if (/err\(([A-Z0-9]+_F_[0-9A-Z_]+)\s*,\s*([0-9A-Z]+_R_[0-9A-Z_]+)\s*\)/)
32 {
33 if ($1 != $last)
34 {
35 if ($function{$1} == 0)
36 {
37 printf STDERR "$. $1 is bad\n";
38 }
39 }
40 $function{$1}++;
41 $last=$1;
42 $reason{$2}++;
43 }
44 }
45 close(IN);
46 }
47
48foreach (keys %function,keys %reason)
49 {
50 /^([A-Z0-9]+)_/;
51 $prefix{$1}++;
52 }
53
54@F=sort keys %function;
55@R=sort keys %reason;
56foreach $j (sort keys %prefix)
57 {
58 next if $errfile{$j} eq "NONE";
59 printf STDERR "doing %-6s - ",$j;
60 if (defined($errfile{$j}))
61 {
62 open(OUT,">$errfile{$j}") ||
63 die "unable to open '$errfile{$j}':$!\n";
64 $close_file=1;
65 }
66 else
67 {
68 *OUT=*STDOUT;
69 $close=0;
70 }
71 @f=grep(/^${j}_/,@F);
72 @r=grep(/^${j}_/,@R);
73 $num=100;
74 print OUT "/* Error codes for the $j functions. */\n\n";
75 print OUT "/* Function codes. */\n";
76 $f_count=0;
77 foreach $i (@f)
78 {
79 $z=6-int(length($i)/8);
80 printf OUT "#define $i%s $num\n","\t" x $z;
81 $num++;
82 $f_count++;
83 }
84 $num=100;
85 print OUT "\n/* Reason codes. */\n";
86 $r_count=0;
87 foreach $i (@r)
88 {
89 $z=6-int(length($i)/8);
90 if (defined($r_value{$i}))
91 {
92 printf OUT "#define $i%s $r_value{$i}\n","\t" x $z;
93 }
94 else
95 {
96 printf OUT "#define $i%s $num\n","\t" x $z;
97 $num++;
98 }
99 $r_count++;
100 }
101 close(OUT) if $close_file;
102
103 printf STDERR "%3d functions, %3d reasons\n",$f_count,$r_count;
104 }
105
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 @@
1#!/usr/bin/perl
2
3if ($ARGV[0] eq "-s") { $static=1; shift @ARGV; }
4
5($#ARGV == 1) || die "usage: $0 [-s] <header file> <output C file>\n";
6open(IN,"<$ARGV[0]") || die "unable to open $ARGV[0]:$!\n";
7open(STDOUT,">$ARGV[1]") || die "unable to open $ARGV[1]:$!\n";
8
9$Func=0;
10$Reas=0;
11$fuction{'FOPEN'}='fopen';
12while (<IN>)
13 {
14 if (/(\S+)\s*\(\);/)
15 {
16 $t=$1;
17 $t =~ s/\*//;
18 ($upper=$t) =~ tr/a-z/A-Z/;
19 $fuction{$upper}=$t;
20 }
21 next unless (/^#define\s+(\S+)\s/);
22
23 $o=$1;
24 if ($o =~ /^([^_]+)_F_(.*)/)
25 {
26 $type=$1;
27 $Func++;
28 $n=$2;
29 $n=$fuction{$n} if (defined($fuction{$n}));
30 $out{$1."_str_functs"}.=
31 sprintf("{ERR_PACK(0,%s,0),\t\"$n\"},\n",$o);
32 }
33 elsif ($o =~ /^([^_]+)_R_(.*)/)
34 {
35 $type=$1;
36 $Reas++;
37 $r=$2;
38 $r =~ tr/A-Z_/a-z /;
39 $pkg{$type."_str_reasons"}=$type;
40 $out{$type."_str_reasons"}.=sprintf("{%-40s,\"$r\"},\n",$o);
41 }
42 elsif ($ARGV[0] =~ /rsaref/ && $o =~ /^RE_(.*)/)
43 {
44 $type="RSAREF";
45 $Reas++;
46 $r=$1;
47 $r =~ tr/A-Z_/a-z /;
48 $pkg{$type."_str_reasons"}=$type;
49 $out{$type."_str_reasons"}.=sprintf("{%-40s,\"$r\"},\n",$o);
50 }
51 }
52close(IN);
53
54&header($type,$ARGV[0]);
55
56foreach (sort keys %out)
57 {
58 print "static ERR_STRING_DATA ${_}[]=\n\t{\n";
59 print $out{$_};
60 print "{0,NULL},\n";
61 print "\t};\n\n";
62 }
63print "#endif\n";
64
65if ($static)
66 { $lib="ERR_LIB_$type"; }
67else
68 { $lib="${type}_lib_error_code"; }
69
70$str="";
71$str.="#ifndef NO_ERR\n";
72$str.="\t\tERR_load_strings($lib,${type}_str_functs);\n" if $Func;
73$str.="\t\tERR_load_strings($lib,${type}_str_reasons);\n" if $Reas;
74$str.="#endif\n";
75
76if (!$static)
77 {
78print <<"EOF";
79
80static int ${type}_lib_error_code=0;
81
82void ERR_load_${type}_strings()
83 {
84 static int init=1;
85
86 if (${type}_lib_error_code == 0)
87 ${type}_lib_error_code=ERR_get_next_error_library();
88
89 if (init);
90 {;
91 init=0;
92$str
93 }
94 }
95
96void ERR_${type}_error(function,reason,file,line)
97int function;
98int reason;
99char *file;
100int line;
101 {
102 if (${type}_lib_error_code == 0)
103 ${type}_lib_error_code=ERR_get_next_error_library();
104 ERR_PUT_error(${type}_lib_error_code,function,reason,file,line);
105 }
106EOF
107 }
108else # $static
109 {
110 print <<"EOF";
111
112void ERR_load_${type}_strings()
113 {
114 static int init=1;
115
116 if (init);
117 {;
118 init=0;
119$str
120 }
121 }
122EOF
123 }
124
125sub header
126 {
127 ($type,$header)=@_;
128
129 ($lc=$type) =~ tr/A-Z/a-z/;
130 $header =~ s/^.*\///;
131
132 print "/* lib/$lc/${lc}\_err.c */\n";
133 print <<'EOF';
134/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
135 * All rights reserved.
136 *
137 * This package is an SSL implementation written
138 * by Eric Young (eay@cryptsoft.com).
139 * The implementation was written so as to conform with Netscapes SSL.
140 *
141 * This library is free for commercial and non-commercial use as long as
142 * the following conditions are aheared to. The following conditions
143 * apply to all code found in this distribution, be it the RC4, RSA,
144 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
145 * included with this distribution is covered by the same copyright terms
146 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
147 *
148 * Copyright remains Eric Young's, and as such any Copyright notices in
149 * the code are not to be removed.
150 * If this package is used in a product, Eric Young should be given attribution
151 * as the author of the parts of the library used.
152 * This can be in the form of a textual message at program startup or
153 * in documentation (online or textual) provided with the package.
154 *
155 * Redistribution and use in source and binary forms, with or without
156 * modification, are permitted provided that the following conditions
157 * are met:
158 * 1. Redistributions of source code must retain the copyright
159 * notice, this list of conditions and the following disclaimer.
160 * 2. Redistributions in binary form must reproduce the above copyright
161 * notice, this list of conditions and the following disclaimer in the
162 * documentation and/or other materials provided with the distribution.
163 * 3. All advertising materials mentioning features or use of this software
164 * must display the following acknowledgement:
165 * "This product includes cryptographic software written by
166 * Eric Young (eay@cryptsoft.com)"
167 * The word 'cryptographic' can be left out if the rouines from the library
168 * being used are not cryptographic related :-).
169 * 4. If you include any Windows specific code (or a derivative thereof) from
170 * the apps directory (application code) you must include an acknowledgement:
171 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
172 *
173 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
174 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
175 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
176 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
177 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
178 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
179 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
180 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
181 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
182 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
183 * SUCH DAMAGE.
184 *
185 * The licence and distribution terms for any publically available version or
186 * derivative of this code cannot be changed. i.e. this code cannot simply be
187 * copied and put under another distribution licence
188 * [including the GNU Public Licence.]
189 */
190EOF
191
192 print "#include <stdio.h>\n";
193 print "#include \"err.h\"\n";
194 print "#include \"$header\"\n";
195 print "\n/* BEGIN ERROR CODES */\n";
196 print "#ifndef NO_ERR\n";
197 }
198
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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "lhash.h" 60#include <openssl/lhash.h>
61#include "crypto.h" 61#include <openssl/crypto.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "buffer.h" 63#include <openssl/buffer.h>
64#include "err.h" 64#include <openssl/err.h>
65#include "crypto.h" 65#include <openssl/crypto.h>
66 66
67#ifndef NO_FP_API 67#ifndef NO_FP_API
68void ERR_print_errors_fp(fp) 68void ERR_print_errors_fp(FILE *fp)
69FILE *fp;
70 { 69 {
71 unsigned long l; 70 unsigned long l;
72 char buf[200]; 71 char buf[200];
73 char *file,*data; 72 const char *file,*data;
74 int line,flags; 73 int line,flags;
75 unsigned long es; 74 unsigned long es;
76 75
@@ -83,13 +82,12 @@ FILE *fp;
83 } 82 }
84#endif 83#endif
85 84
86void ERR_print_errors(bp) 85void ERR_print_errors(BIO *bp)
87BIO *bp;
88 { 86 {
89 unsigned long l; 87 unsigned long l;
90 char buf[256]; 88 char buf[256];
91 char buf2[256]; 89 char buf2[256];
92 char *file,*data; 90 const char *file,*data;
93 int line,flags; 91 int line,flags;
94 unsigned long es; 92 unsigned long es;
95 93
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 @@
1/* Error codes for the ERR functions. */
2
3/* Function codes. */
4
5/* Reason codes. */
6#define ERR_R_BN_LIB 100
7#define ERR_R_DER_LIB 101
8#define ERR_R_MALLOC_FAILURE 102
9#define ERR_R_PEM_LIB 103
10#define ERR_R_RSA_LIB 104
11#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED 105
12#define ERR_R_SYS_LIB 106
13#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 @@
1L ERR NONE NONE
2L CRYPTO crypto/crypto.h crypto/cpt_err.c
3L BN crypto/bn/bn.h crypto/bn/bn_err.c
4L RSA crypto/rsa/rsa.h crypto/rsa/rsa_err.c
5L DSA crypto/dsa/dsa.h crypto/dsa/dsa_err.c
6L DH crypto/dh/dh.h crypto/dh/dh_err.c
7L EVP crypto/evp/evp.h crypto/evp/evp_err.c
8L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c
9L BIO crypto/bio/bio.h crypto/bio/bio_err.c
10L OBJ crypto/objects/objects.h crypto/objects/obj_err.c
11L PEM crypto/pem/pem.h crypto/pem/pem_err.c
12L X509 crypto/x509/x509.h crypto/x509/x509_err.c
13L NONE crypto/x509/x509_vfy.h NONE
14L X509V3 crypto/x509v3/x509v3.h crypto/x509v3/v3err.c
15#L METH crypto/meth/meth.h crypto/meth/meth_err.c
16L ASN1 crypto/asn1/asn1.h crypto/asn1/asn1_err.c
17L CONF crypto/conf/conf.h crypto/conf/conf_err.c
18#L PROXY crypto/proxy/proxy.h crypto/proxy/proxy_err.c
19L PKCS7 crypto/pkcs7/pkcs7.h crypto/pkcs7/pkcs7err.c
20L PKCS12 crypto/pkcs12/pkcs12.h crypto/pkcs12/pk12err.c
21L RSAREF rsaref/rsaref.h rsaref/rsar_err.c
22L SSL ssl/ssl.h ssl/ssl_err.c
23L COMP crypto/comp/comp.h crypto/comp/comp_err.c
24
25
26F RSAREF_F_RSA_BN2BIN
27F RSAREF_F_RSA_PRIVATE_DECRYPT
28F RSAREF_F_RSA_PRIVATE_ENCRYPT
29F RSAREF_F_RSA_PUBLIC_DECRYPT
30F RSAREF_F_RSA_PUBLIC_ENCRYPT
31#F SSL_F_CLIENT_CERTIFICATE
32
33R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
34R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
35R SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
36R SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
37R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
38R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
39R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
40R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
41R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
42R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
43R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
44R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
45R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
46R SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
47R SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
48R SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
49R SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
50R SSL_R_TLSV1_ALERT_EXPORT_RESTRICION 1060
51R SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
52R SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
53R SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
54R SSL_R_TLSV1_ALERT_USER_CANCLED 1090
55R SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
56
57R RSAREF_R_CONTENT_ENCODING 0x0400
58R RSAREF_R_DATA 0x0401
59R RSAREF_R_DIGEST_ALGORITHM 0x0402
60R RSAREF_R_ENCODING 0x0403
61R RSAREF_R_KEY 0x0404
62R RSAREF_R_KEY_ENCODING 0x0405
63R RSAREF_R_LEN 0x0406
64R RSAREF_R_MODULUS_LEN 0x0407
65R RSAREF_R_NEED_RANDOM 0x0408
66R RSAREF_R_PRIVATE_KEY 0x0409
67R RSAREF_R_PUBLIC_KEY 0x040a
68R RSAREF_R_SIGNATURE 0x040b
69R RSAREF_R_SIGNATURE_ENCODING 0x040c
70R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d
71
diff --git a/src/lib/libcrypto/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 @@
1L ERR NONE
2L CRYPTO crypto.err
3L BN bn/bn.err
4L RSA rsa/rsa.err
5L DSA dsa/dsa.err
6L DH dh/dh.err
7L EVP evp/evp.err
8L BUF buffer/buffer.err
9L BIO bio/bio.err
10L OBJ objects/objects.err
11L PEM pem/pem.err
12L X509 x509/x509.err
13L METH meth/meth.err
14L ASN1 asn1/asn1.err
15L CONF conf/conf.err
16L PROXY proxy/proxy.err
17L PKCS7 pkcs7/pkcs7.err
18L RSAREF ../rsaref/rsaref.err
19L SSL ../ssl/ssl.err
20L SSL2 ../ssl/ssl2.err
21L SSL3 ../ssl/ssl3.err
22L SSL23 ../ssl/ssl23.err
23
24F RSAREF_F_RSA_BN2BIN
25F RSAREF_F_RSA_PRIVATE_DECRYPT
26F RSAREF_F_RSA_PRIVATE_ENCRYPT
27F RSAREF_F_RSA_PUBLIC_DECRYPT
28F RSAREF_F_RSA_PUBLIC_ENCRYPT
29#F SSL_F_CLIENT_CERTIFICATE
30
31R SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
32R SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
33R SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
34R SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
35R SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
36R SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
37R SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
38R SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
39R SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
40R SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
41R SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
42
43R RSAREF_R_CONTENT_ENCODING 0x0400
44R RSAREF_R_DATA 0x0401
45R RSAREF_R_DIGEST_ALGORITHM 0x0402
46R RSAREF_R_ENCODING 0x0403
47R RSAREF_R_KEY 0x0404
48R RSAREF_R_KEY_ENCODING 0x0405
49R RSAREF_R_LEN 0x0406
50R RSAREF_R_MODULUS_LEN 0x0407
51R RSAREF_R_NEED_RANDOM 0x0408
52R RSAREF_R_PRIVATE_KEY 0x0409
53R RSAREF_R_PUBLIC_KEY 0x040a
54R RSAREF_R_SIGNATURE 0x040b
55R RSAREF_R_SIGNATURE_ENCODING 0x040c
56R RSAREF_R_ENCRYPTION_ALGORITHM 0x040d
57
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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=evp
19ERRC=evp_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= 21TEST=
22APPS= 22APPS=
@@ -34,8 +34,8 @@ LIBSRC= encode.c digest.c evp_enc.c evp_key.c \
34 m_null.c m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c m_dss1.c m_mdc2.c \ 34 m_null.c m_md2.c m_md5.c m_sha.c m_sha1.c m_dss.c m_dss1.c m_mdc2.c \
35 m_ripemd.c \ 35 m_ripemd.c \
36 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \ 36 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
37 bio_md.c bio_b64.c bio_enc.c $(ERRC).c e_null.c \ 37 bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
38 c_all.c evp_lib.c 38 c_all.c evp_lib.c bio_ok.c evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c
39 39
40LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \ 40LIBOBJ= encode.o digest.o evp_enc.o evp_key.o \
41 e_ecb_d.o e_cbc_d.o e_cfb_d.o e_ofb_d.o \ 41 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 \
49 m_null.o m_md2.o m_md5.o m_sha.o m_sha1.o m_dss.o m_dss1.o m_mdc2.o \ 49 m_null.o m_md2.o m_md5.o m_sha.o m_sha1.o m_dss.o m_dss1.o m_mdc2.o \
50 m_ripemd.o \ 50 m_ripemd.o \
51 p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \ 51 p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \
52 bio_md.o bio_b64.o bio_enc.o $(ERRC).o e_null.o \ 52 bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \
53 c_all.o evp_lib.o 53 c_all.o evp_lib.o bio_ok.o evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o
54 54
55SRC= $(LIBSRC) 55SRC= $(LIBSRC)
56 56
@@ -66,24 +66,23 @@ all: lib
66 66
67lib: $(LIBOBJ) 67lib: $(LIBOBJ)
68 $(AR) $(LIB) $(LIBOBJ) 68 $(AR) $(LIB) $(LIBOBJ)
69 sh $(TOP)/util/ranlib.sh $(LIB) 69 $(RANLIB) $(LIB)
70 @touch lib 70 @touch lib
71 71
72files: 72files:
73 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 73 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
74 74
75links: 75links:
76 /bin/rm -f Makefile 76 @$(TOP)/util/point.sh Makefile.ssl Makefile
77 $(TOP)/util/point.sh Makefile.ssl Makefile ; 77 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
78 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 78 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
79 $(TOP)/util/mklink.sh ../../test $(TEST) 79 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
80 $(TOP)/util/mklink.sh ../../apps $(APPS)
81 80
82install: 81install:
83 @for i in $(EXHEADER) ; \ 82 @for i in $(EXHEADER) ; \
84 do \ 83 do \
85 (cp $$i $(INSTALLTOP)/include/$$i; \ 84 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
86 chmod 644 $(INSTALLTOP)/include/$$i ); \ 85 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
87 done; 86 done;
88 87
89tags: 88tags:
@@ -95,17 +94,1006 @@ lint:
95 lint -DLINT $(INCLUDES) $(SRC)>fluff 94 lint -DLINT $(INCLUDES) $(SRC)>fluff
96 95
97depend: 96depend:
98 $(MAKEDEPEND) $(INCLUDES) $(LIBSRC) 97 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC)
99 98
100dclean: 99dclean:
101 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 100 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
102 mv -f Makefile.new $(MAKEFILE) 101 mv -f Makefile.new $(MAKEFILE)
103 102
104clean: 103clean:
105 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 104 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
106
107errors:
108 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
109 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
110 105
111# DO NOT DELETE THIS LINE -- make depend depends on it. 106# DO NOT DELETE THIS LINE -- make depend depends on it.
107
108bio_b64.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
109bio_b64.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
110bio_b64.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
111bio_b64.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
112bio_b64.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
113bio_b64.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
114bio_b64.o: ../../include/openssl/err.h ../../include/openssl/evp.h
115bio_b64.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
116bio_b64.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
117bio_b64.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
118bio_b64.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
119bio_b64.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
120bio_b64.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
121bio_b64.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
122bio_b64.o: ../../include/openssl/stack.h ../cryptlib.h
123bio_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
124bio_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
125bio_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
126bio_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
127bio_enc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
128bio_enc.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
129bio_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
130bio_enc.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
131bio_enc.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
132bio_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
133bio_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
134bio_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
135bio_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
136bio_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
137bio_enc.o: ../../include/openssl/stack.h ../cryptlib.h
138bio_md.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
139bio_md.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
140bio_md.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
141bio_md.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
142bio_md.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
143bio_md.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
144bio_md.o: ../../include/openssl/err.h ../../include/openssl/evp.h
145bio_md.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
146bio_md.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
147bio_md.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
148bio_md.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
149bio_md.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
150bio_md.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
151bio_md.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
152bio_md.o: ../../include/openssl/stack.h ../cryptlib.h
153bio_ok.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
154bio_ok.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
155bio_ok.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
156bio_ok.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
157bio_ok.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
158bio_ok.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
159bio_ok.o: ../../include/openssl/err.h ../../include/openssl/evp.h
160bio_ok.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
161bio_ok.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
162bio_ok.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
163bio_ok.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
164bio_ok.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
165bio_ok.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
166bio_ok.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
167bio_ok.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
168bio_ok.o: ../cryptlib.h
169c_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
170c_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
171c_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
172c_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
173c_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
174c_all.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
175c_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
176c_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
177c_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
178c_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
179c_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs12.h
180c_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
181c_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
182c_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
183c_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
184c_all.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
185c_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
186digest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
187digest.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
188digest.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
189digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
190digest.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
191digest.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
192digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
193digest.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
194digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
195digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
196digest.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
197digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
198digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
199digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
200digest.o: ../../include/openssl/stack.h ../cryptlib.h
201e_cbc_3d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
202e_cbc_3d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
203e_cbc_3d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
204e_cbc_3d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
205e_cbc_3d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
206e_cbc_3d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
207e_cbc_3d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
208e_cbc_3d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
209e_cbc_3d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
210e_cbc_3d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
211e_cbc_3d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
212e_cbc_3d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
213e_cbc_3d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
214e_cbc_3d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
215e_cbc_3d.o: ../../include/openssl/stack.h ../cryptlib.h
216e_cbc_bf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
217e_cbc_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
218e_cbc_bf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
219e_cbc_bf.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
220e_cbc_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
221e_cbc_bf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
222e_cbc_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
223e_cbc_bf.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
224e_cbc_bf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
225e_cbc_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
226e_cbc_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
227e_cbc_bf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
228e_cbc_bf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
229e_cbc_bf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
230e_cbc_bf.o: ../../include/openssl/stack.h ../cryptlib.h
231e_cbc_c.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
232e_cbc_c.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
233e_cbc_c.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
234e_cbc_c.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
235e_cbc_c.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
236e_cbc_c.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
237e_cbc_c.o: ../../include/openssl/err.h ../../include/openssl/evp.h
238e_cbc_c.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
239e_cbc_c.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
240e_cbc_c.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
241e_cbc_c.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
242e_cbc_c.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
243e_cbc_c.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
244e_cbc_c.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
245e_cbc_c.o: ../../include/openssl/stack.h ../cryptlib.h
246e_cbc_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
247e_cbc_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
248e_cbc_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
249e_cbc_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
250e_cbc_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
251e_cbc_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
252e_cbc_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
253e_cbc_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
254e_cbc_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
255e_cbc_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
256e_cbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
257e_cbc_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
258e_cbc_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
259e_cbc_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
260e_cbc_d.o: ../../include/openssl/stack.h ../cryptlib.h
261e_cbc_i.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
262e_cbc_i.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
263e_cbc_i.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
264e_cbc_i.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
265e_cbc_i.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
266e_cbc_i.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
267e_cbc_i.o: ../../include/openssl/err.h ../../include/openssl/evp.h
268e_cbc_i.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
269e_cbc_i.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
270e_cbc_i.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
271e_cbc_i.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
272e_cbc_i.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
273e_cbc_i.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
274e_cbc_i.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
275e_cbc_i.o: ../../include/openssl/stack.h ../cryptlib.h
276e_cbc_r2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
277e_cbc_r2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
278e_cbc_r2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
279e_cbc_r2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
280e_cbc_r2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
281e_cbc_r2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
282e_cbc_r2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
283e_cbc_r2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
284e_cbc_r2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
285e_cbc_r2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
286e_cbc_r2.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
287e_cbc_r2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
288e_cbc_r2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
289e_cbc_r2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
290e_cbc_r2.o: ../../include/openssl/stack.h ../cryptlib.h
291e_cbc_r5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
292e_cbc_r5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
293e_cbc_r5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
294e_cbc_r5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
295e_cbc_r5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
296e_cbc_r5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
297e_cbc_r5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
298e_cbc_r5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
299e_cbc_r5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
300e_cbc_r5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
301e_cbc_r5.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
302e_cbc_r5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
303e_cbc_r5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
304e_cbc_r5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
305e_cbc_r5.o: ../../include/openssl/stack.h ../cryptlib.h
306e_cfb_3d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
307e_cfb_3d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
308e_cfb_3d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
309e_cfb_3d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
310e_cfb_3d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
311e_cfb_3d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
312e_cfb_3d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
313e_cfb_3d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
314e_cfb_3d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
315e_cfb_3d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
316e_cfb_3d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
317e_cfb_3d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
318e_cfb_3d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
319e_cfb_3d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
320e_cfb_3d.o: ../../include/openssl/stack.h ../cryptlib.h
321e_cfb_bf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
322e_cfb_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
323e_cfb_bf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
324e_cfb_bf.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
325e_cfb_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
326e_cfb_bf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
327e_cfb_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
328e_cfb_bf.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
329e_cfb_bf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
330e_cfb_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
331e_cfb_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
332e_cfb_bf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
333e_cfb_bf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
334e_cfb_bf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
335e_cfb_bf.o: ../../include/openssl/stack.h ../cryptlib.h
336e_cfb_c.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
337e_cfb_c.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
338e_cfb_c.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
339e_cfb_c.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
340e_cfb_c.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
341e_cfb_c.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
342e_cfb_c.o: ../../include/openssl/err.h ../../include/openssl/evp.h
343e_cfb_c.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
344e_cfb_c.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
345e_cfb_c.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
346e_cfb_c.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
347e_cfb_c.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
348e_cfb_c.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
349e_cfb_c.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
350e_cfb_c.o: ../../include/openssl/stack.h ../cryptlib.h
351e_cfb_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
352e_cfb_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
353e_cfb_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
354e_cfb_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
355e_cfb_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
356e_cfb_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
357e_cfb_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
358e_cfb_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
359e_cfb_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
360e_cfb_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
361e_cfb_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
362e_cfb_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
363e_cfb_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
364e_cfb_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
365e_cfb_d.o: ../../include/openssl/stack.h ../cryptlib.h
366e_cfb_i.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
367e_cfb_i.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
368e_cfb_i.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
369e_cfb_i.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
370e_cfb_i.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
371e_cfb_i.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
372e_cfb_i.o: ../../include/openssl/err.h ../../include/openssl/evp.h
373e_cfb_i.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
374e_cfb_i.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
375e_cfb_i.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
376e_cfb_i.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
377e_cfb_i.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
378e_cfb_i.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
379e_cfb_i.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
380e_cfb_i.o: ../../include/openssl/stack.h ../cryptlib.h
381e_cfb_r2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
382e_cfb_r2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
383e_cfb_r2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
384e_cfb_r2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
385e_cfb_r2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
386e_cfb_r2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
387e_cfb_r2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
388e_cfb_r2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
389e_cfb_r2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
390e_cfb_r2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
391e_cfb_r2.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
392e_cfb_r2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
393e_cfb_r2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
394e_cfb_r2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
395e_cfb_r2.o: ../../include/openssl/stack.h ../cryptlib.h
396e_cfb_r5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
397e_cfb_r5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
398e_cfb_r5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
399e_cfb_r5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
400e_cfb_r5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
401e_cfb_r5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
402e_cfb_r5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
403e_cfb_r5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
404e_cfb_r5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
405e_cfb_r5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
406e_cfb_r5.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
407e_cfb_r5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
408e_cfb_r5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
409e_cfb_r5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
410e_cfb_r5.o: ../../include/openssl/stack.h ../cryptlib.h
411e_ecb_3d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
412e_ecb_3d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
413e_ecb_3d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
414e_ecb_3d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
415e_ecb_3d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
416e_ecb_3d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
417e_ecb_3d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
418e_ecb_3d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
419e_ecb_3d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
420e_ecb_3d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
421e_ecb_3d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
422e_ecb_3d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
423e_ecb_3d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
424e_ecb_3d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
425e_ecb_3d.o: ../../include/openssl/stack.h ../cryptlib.h
426e_ecb_bf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
427e_ecb_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
428e_ecb_bf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
429e_ecb_bf.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
430e_ecb_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
431e_ecb_bf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
432e_ecb_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
433e_ecb_bf.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
434e_ecb_bf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
435e_ecb_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
436e_ecb_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
437e_ecb_bf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
438e_ecb_bf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
439e_ecb_bf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
440e_ecb_bf.o: ../../include/openssl/stack.h ../cryptlib.h
441e_ecb_c.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
442e_ecb_c.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
443e_ecb_c.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
444e_ecb_c.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
445e_ecb_c.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
446e_ecb_c.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
447e_ecb_c.o: ../../include/openssl/err.h ../../include/openssl/evp.h
448e_ecb_c.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
449e_ecb_c.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
450e_ecb_c.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
451e_ecb_c.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
452e_ecb_c.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
453e_ecb_c.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
454e_ecb_c.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
455e_ecb_c.o: ../../include/openssl/stack.h ../cryptlib.h
456e_ecb_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
457e_ecb_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
458e_ecb_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
459e_ecb_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
460e_ecb_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
461e_ecb_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
462e_ecb_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
463e_ecb_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
464e_ecb_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
465e_ecb_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
466e_ecb_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
467e_ecb_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
468e_ecb_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
469e_ecb_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
470e_ecb_d.o: ../../include/openssl/stack.h ../cryptlib.h
471e_ecb_i.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
472e_ecb_i.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
473e_ecb_i.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
474e_ecb_i.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
475e_ecb_i.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
476e_ecb_i.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
477e_ecb_i.o: ../../include/openssl/err.h ../../include/openssl/evp.h
478e_ecb_i.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
479e_ecb_i.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
480e_ecb_i.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
481e_ecb_i.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
482e_ecb_i.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
483e_ecb_i.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
484e_ecb_i.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
485e_ecb_i.o: ../../include/openssl/stack.h ../cryptlib.h
486e_ecb_r2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
487e_ecb_r2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
488e_ecb_r2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
489e_ecb_r2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
490e_ecb_r2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
491e_ecb_r2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
492e_ecb_r2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
493e_ecb_r2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
494e_ecb_r2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
495e_ecb_r2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
496e_ecb_r2.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
497e_ecb_r2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
498e_ecb_r2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
499e_ecb_r2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
500e_ecb_r2.o: ../../include/openssl/stack.h ../cryptlib.h
501e_ecb_r5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
502e_ecb_r5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
503e_ecb_r5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
504e_ecb_r5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
505e_ecb_r5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
506e_ecb_r5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
507e_ecb_r5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
508e_ecb_r5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
509e_ecb_r5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
510e_ecb_r5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
511e_ecb_r5.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
512e_ecb_r5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
513e_ecb_r5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
514e_ecb_r5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
515e_ecb_r5.o: ../../include/openssl/stack.h ../cryptlib.h
516e_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
517e_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
518e_null.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
519e_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
520e_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
521e_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
522e_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
523e_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
524e_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
525e_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
526e_null.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
527e_null.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
528e_null.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
529e_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
530e_null.o: ../../include/openssl/stack.h ../cryptlib.h
531e_ofb_3d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
532e_ofb_3d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
533e_ofb_3d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
534e_ofb_3d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
535e_ofb_3d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
536e_ofb_3d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
537e_ofb_3d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
538e_ofb_3d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
539e_ofb_3d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
540e_ofb_3d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
541e_ofb_3d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
542e_ofb_3d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
543e_ofb_3d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
544e_ofb_3d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
545e_ofb_3d.o: ../../include/openssl/stack.h ../cryptlib.h
546e_ofb_bf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
547e_ofb_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
548e_ofb_bf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
549e_ofb_bf.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
550e_ofb_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
551e_ofb_bf.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
552e_ofb_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
553e_ofb_bf.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
554e_ofb_bf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
555e_ofb_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
556e_ofb_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
557e_ofb_bf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
558e_ofb_bf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
559e_ofb_bf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
560e_ofb_bf.o: ../../include/openssl/stack.h ../cryptlib.h
561e_ofb_c.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
562e_ofb_c.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
563e_ofb_c.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
564e_ofb_c.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
565e_ofb_c.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
566e_ofb_c.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
567e_ofb_c.o: ../../include/openssl/err.h ../../include/openssl/evp.h
568e_ofb_c.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
569e_ofb_c.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
570e_ofb_c.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
571e_ofb_c.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
572e_ofb_c.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
573e_ofb_c.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
574e_ofb_c.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
575e_ofb_c.o: ../../include/openssl/stack.h ../cryptlib.h
576e_ofb_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
577e_ofb_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
578e_ofb_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
579e_ofb_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
580e_ofb_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
581e_ofb_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
582e_ofb_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
583e_ofb_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
584e_ofb_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
585e_ofb_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
586e_ofb_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
587e_ofb_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
588e_ofb_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
589e_ofb_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
590e_ofb_d.o: ../../include/openssl/stack.h ../cryptlib.h
591e_ofb_i.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
592e_ofb_i.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
593e_ofb_i.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
594e_ofb_i.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
595e_ofb_i.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
596e_ofb_i.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
597e_ofb_i.o: ../../include/openssl/err.h ../../include/openssl/evp.h
598e_ofb_i.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
599e_ofb_i.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
600e_ofb_i.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
601e_ofb_i.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
602e_ofb_i.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
603e_ofb_i.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
604e_ofb_i.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
605e_ofb_i.o: ../../include/openssl/stack.h ../cryptlib.h
606e_ofb_r2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
607e_ofb_r2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
608e_ofb_r2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
609e_ofb_r2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
610e_ofb_r2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
611e_ofb_r2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
612e_ofb_r2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
613e_ofb_r2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
614e_ofb_r2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
615e_ofb_r2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
616e_ofb_r2.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
617e_ofb_r2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
618e_ofb_r2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
619e_ofb_r2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
620e_ofb_r2.o: ../../include/openssl/stack.h ../cryptlib.h
621e_ofb_r5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
622e_ofb_r5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
623e_ofb_r5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
624e_ofb_r5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
625e_ofb_r5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
626e_ofb_r5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
627e_ofb_r5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
628e_ofb_r5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
629e_ofb_r5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
630e_ofb_r5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
631e_ofb_r5.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
632e_ofb_r5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
633e_ofb_r5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
634e_ofb_r5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
635e_ofb_r5.o: ../../include/openssl/stack.h ../cryptlib.h
636e_rc4.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
637e_rc4.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
638e_rc4.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
639e_rc4.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
640e_rc4.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
641e_rc4.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
642e_rc4.o: ../../include/openssl/err.h ../../include/openssl/evp.h
643e_rc4.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
644e_rc4.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
645e_rc4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
646e_rc4.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
647e_rc4.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
648e_rc4.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
649e_rc4.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
650e_rc4.o: ../../include/openssl/stack.h ../cryptlib.h
651e_xcbc_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
652e_xcbc_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
653e_xcbc_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
654e_xcbc_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
655e_xcbc_d.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
656e_xcbc_d.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
657e_xcbc_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
658e_xcbc_d.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
659e_xcbc_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
660e_xcbc_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
661e_xcbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
662e_xcbc_d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
663e_xcbc_d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
664e_xcbc_d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
665e_xcbc_d.o: ../../include/openssl/stack.h ../cryptlib.h
666encode.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
667encode.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
668encode.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
669encode.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
670encode.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
671encode.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
672encode.o: ../../include/openssl/err.h ../../include/openssl/evp.h
673encode.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
674encode.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
675encode.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
676encode.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
677encode.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
678encode.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
679encode.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
680encode.o: ../../include/openssl/stack.h ../cryptlib.h
681evp_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
682evp_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
683evp_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
684evp_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
685evp_enc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
686evp_enc.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
687evp_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
688evp_enc.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
689evp_enc.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
690evp_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
691evp_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
692evp_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
693evp_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
694evp_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
695evp_enc.o: ../../include/openssl/stack.h ../cryptlib.h
696evp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
697evp_err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
698evp_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
699evp_err.o: ../../include/openssl/des.h ../../include/openssl/dh.h
700evp_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
701evp_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
702evp_err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
703evp_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
704evp_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
705evp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
706evp_err.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
707evp_err.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
708evp_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
709evp_err.o: ../../include/openssl/stack.h
710evp_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
711evp_key.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
712evp_key.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
713evp_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
714evp_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
715evp_key.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
716evp_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h
717evp_key.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
718evp_key.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
719evp_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
720evp_key.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
721evp_key.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
722evp_key.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
723evp_key.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
724evp_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
725evp_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
726evp_key.o: ../cryptlib.h
727evp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
728evp_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
729evp_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
730evp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
731evp_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
732evp_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
733evp_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
734evp_lib.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
735evp_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
736evp_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
737evp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
738evp_lib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
739evp_lib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
740evp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
741evp_lib.o: ../../include/openssl/stack.h ../cryptlib.h
742evp_pbe.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
743evp_pbe.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
744evp_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
745evp_pbe.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
746evp_pbe.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
747evp_pbe.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
748evp_pbe.o: ../../include/openssl/err.h ../../include/openssl/evp.h
749evp_pbe.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
750evp_pbe.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
751evp_pbe.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
752evp_pbe.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
753evp_pbe.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
754evp_pbe.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
755evp_pbe.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
756evp_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
757evp_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
758evp_pbe.o: ../cryptlib.h
759evp_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
760evp_pkey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
761evp_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
762evp_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
763evp_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
764evp_pkey.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
765evp_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
766evp_pkey.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
767evp_pkey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
768evp_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
769evp_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
770evp_pkey.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
771evp_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
772evp_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
773evp_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
774evp_pkey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
775evp_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
776m_dss.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
777m_dss.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
778m_dss.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
779m_dss.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
780m_dss.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
781m_dss.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
782m_dss.o: ../../include/openssl/err.h ../../include/openssl/evp.h
783m_dss.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
784m_dss.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
785m_dss.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
786m_dss.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
787m_dss.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
788m_dss.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
789m_dss.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
790m_dss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
791m_dss.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
792m_dss.o: ../cryptlib.h
793m_dss1.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
794m_dss1.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
795m_dss1.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
796m_dss1.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
797m_dss1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
798m_dss1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
799m_dss1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
800m_dss1.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
801m_dss1.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
802m_dss1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
803m_dss1.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
804m_dss1.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
805m_dss1.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
806m_dss1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
807m_dss1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
808m_dss1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
809m_dss1.o: ../cryptlib.h
810m_md2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
811m_md2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
812m_md2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
813m_md2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
814m_md2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
815m_md2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
816m_md2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
817m_md2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
818m_md2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
819m_md2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
820m_md2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
821m_md2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
822m_md2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
823m_md2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
824m_md2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
825m_md2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
826m_md2.o: ../cryptlib.h
827m_md5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
828m_md5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
829m_md5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
830m_md5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
831m_md5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
832m_md5.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
833m_md5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
834m_md5.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
835m_md5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
836m_md5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
837m_md5.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
838m_md5.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
839m_md5.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
840m_md5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
841m_md5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
842m_md5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
843m_md5.o: ../cryptlib.h
844m_mdc2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
845m_mdc2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
846m_mdc2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
847m_mdc2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
848m_mdc2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
849m_mdc2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
850m_mdc2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
851m_mdc2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
852m_mdc2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
853m_mdc2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
854m_mdc2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
855m_mdc2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
856m_mdc2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
857m_mdc2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
858m_mdc2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
859m_mdc2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
860m_mdc2.o: ../cryptlib.h
861m_null.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
862m_null.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
863m_null.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
864m_null.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
865m_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
866m_null.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
867m_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
868m_null.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
869m_null.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
870m_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
871m_null.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
872m_null.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
873m_null.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
874m_null.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
875m_null.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
876m_null.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
877m_null.o: ../cryptlib.h
878m_ripemd.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
879m_ripemd.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
880m_ripemd.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
881m_ripemd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
882m_ripemd.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
883m_ripemd.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
884m_ripemd.o: ../../include/openssl/err.h ../../include/openssl/evp.h
885m_ripemd.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
886m_ripemd.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
887m_ripemd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
888m_ripemd.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
889m_ripemd.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
890m_ripemd.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
891m_ripemd.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
892m_ripemd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
893m_ripemd.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
894m_ripemd.o: ../cryptlib.h
895m_sha.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
896m_sha.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
897m_sha.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
898m_sha.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
899m_sha.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
900m_sha.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
901m_sha.o: ../../include/openssl/err.h ../../include/openssl/evp.h
902m_sha.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
903m_sha.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
904m_sha.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
905m_sha.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
906m_sha.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
907m_sha.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
908m_sha.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
909m_sha.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
910m_sha.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
911m_sha.o: ../cryptlib.h
912m_sha1.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
913m_sha1.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
914m_sha1.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
915m_sha1.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
916m_sha1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
917m_sha1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
918m_sha1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
919m_sha1.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
920m_sha1.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
921m_sha1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
922m_sha1.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
923m_sha1.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
924m_sha1.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
925m_sha1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
926m_sha1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
927m_sha1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
928m_sha1.o: ../cryptlib.h
929names.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
930names.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
931names.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
932names.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
933names.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
934names.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
935names.o: ../../include/openssl/err.h ../../include/openssl/evp.h
936names.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
937names.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
938names.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
939names.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
940names.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
941names.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
942names.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
943names.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
944names.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
945names.o: ../cryptlib.h
946p5_crpt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
947p5_crpt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
948p5_crpt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
949p5_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
950p5_crpt.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
951p5_crpt.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
952p5_crpt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
953p5_crpt.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
954p5_crpt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
955p5_crpt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
956p5_crpt.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
957p5_crpt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
958p5_crpt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
959p5_crpt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
960p5_crpt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
961p5_crpt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
962p5_crpt.o: ../cryptlib.h
963p5_crpt2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
964p5_crpt2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
965p5_crpt2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
966p5_crpt2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
967p5_crpt2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
968p5_crpt2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
969p5_crpt2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
970p5_crpt2.o: ../../include/openssl/hmac.h ../../include/openssl/idea.h
971p5_crpt2.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
972p5_crpt2.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
973p5_crpt2.o: ../../include/openssl/opensslconf.h
974p5_crpt2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
975p5_crpt2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
976p5_crpt2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
977p5_crpt2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
978p5_crpt2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
979p5_crpt2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
980p5_crpt2.o: ../cryptlib.h
981p_dec.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
982p_dec.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
983p_dec.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
984p_dec.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
985p_dec.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
986p_dec.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
987p_dec.o: ../../include/openssl/err.h ../../include/openssl/evp.h
988p_dec.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
989p_dec.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
990p_dec.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
991p_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
992p_dec.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
993p_dec.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
994p_dec.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
995p_dec.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
996p_dec.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
997p_dec.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
998p_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
999p_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1000p_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1001p_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1002p_enc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1003p_enc.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
1004p_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1005p_enc.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
1006p_enc.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1007p_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1008p_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
1009p_enc.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
1010p_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1011p_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1012p_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1013p_enc.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1014p_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
1015p_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
1016p_lib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1017p_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1018p_lib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1019p_lib.o: ../../include/openssl/des.h ../../include/openssl/dh.h
1020p_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
1021p_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1022p_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1023p_lib.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
1024p_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
1025p_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1026p_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1027p_lib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1028p_lib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1029p_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1030p_lib.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1031p_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
1032p_open.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
1033p_open.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1034p_open.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1035p_open.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1036p_open.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1037p_open.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
1038p_open.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1039p_open.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
1040p_open.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1041p_open.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1042p_open.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
1043p_open.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1044p_open.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1045p_open.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1046p_open.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1047p_open.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1048p_open.o: ../cryptlib.h
1049p_seal.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
1050p_seal.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1051p_seal.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1052p_seal.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1053p_seal.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1054p_seal.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
1055p_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1056p_seal.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
1057p_seal.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1058p_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1059p_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
1060p_seal.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
1061p_seal.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1062p_seal.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1063p_seal.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1064p_seal.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
1065p_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
1066p_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
1067p_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1068p_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1069p_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1070p_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1071p_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
1072p_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1073p_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
1074p_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1075p_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1076p_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
1077p_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1078p_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1079p_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1080p_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1081p_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1082p_sign.o: ../cryptlib.h
1083p_verify.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
1084p_verify.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1085p_verify.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1086p_verify.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1087p_verify.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1088p_verify.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
1089p_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1090p_verify.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
1091p_verify.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1092p_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1093p_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
1094p_verify.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1095p_verify.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1096p_verify.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1097p_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1098p_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1099p_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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "buffer.h" 62#include <openssl/buffer.h>
63#include "evp.h" 63#include <openssl/evp.h>
64 64
65#ifndef NOPROTO
66static int b64_write(BIO *h,char *buf,int num); 65static int b64_write(BIO *h,char *buf,int num);
67static int b64_read(BIO *h,char *buf,int size); 66static int b64_read(BIO *h,char *buf,int size);
68/*static int b64_puts(BIO *h,char *str); */ 67/*static int b64_puts(BIO *h,char *str); */
@@ -70,16 +69,6 @@ static int b64_read(BIO *h,char *buf,int size);
70static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long b64_ctrl(BIO *h,int cmd,long arg1,char *arg2);
71static int b64_new(BIO *h); 70static int b64_new(BIO *h);
72static int b64_free(BIO *data); 71static int b64_free(BIO *data);
73#else
74static int b64_write();
75static int b64_read();
76/*static int b64_puts(); */
77/*static int b64_gets(); */
78static long b64_ctrl();
79static int b64_new();
80static int b64_free();
81#endif
82
83#define B64_BLOCK_SIZE 1024 72#define B64_BLOCK_SIZE 1024
84#define B64_BLOCK_SIZE2 768 73#define B64_BLOCK_SIZE2 768
85#define B64_NONE 0 74#define B64_NONE 0
@@ -113,13 +102,12 @@ static BIO_METHOD methods_b64=
113 b64_free, 102 b64_free,
114 }; 103 };
115 104
116BIO_METHOD *BIO_f_base64() 105BIO_METHOD *BIO_f_base64(void)
117 { 106 {
118 return(&methods_b64); 107 return(&methods_b64);
119 } 108 }
120 109
121static int b64_new(bi) 110static int b64_new(BIO *bi)
122BIO *bi;
123 { 111 {
124 BIO_B64_CTX *ctx; 112 BIO_B64_CTX *ctx;
125 113
@@ -140,8 +128,7 @@ BIO *bi;
140 return(1); 128 return(1);
141 } 129 }
142 130
143static int b64_free(a) 131static int b64_free(BIO *a)
144BIO *a;
145 { 132 {
146 if (a == NULL) return(0); 133 if (a == NULL) return(0);
147 Free(a->ptr); 134 Free(a->ptr);
@@ -151,10 +138,7 @@ BIO *a;
151 return(1); 138 return(1);
152 } 139 }
153 140
154static int b64_read(b,out,outl) 141static int b64_read(BIO *b, char *out, int outl)
155BIO *b;
156char *out;
157int outl;
158 { 142 {
159 int ret=0,i,ii,j,k,x,n,num,ret_code=0; 143 int ret=0,i,ii,j,k,x,n,num,ret_code=0;
160 BIO_B64_CTX *ctx; 144 BIO_B64_CTX *ctx;
@@ -354,10 +338,7 @@ int outl;
354 return((ret == 0)?ret_code:ret); 338 return((ret == 0)?ret_code:ret);
355 } 339 }
356 340
357static int b64_write(b,in,inl) 341static int b64_write(BIO *b, char *in, int inl)
358BIO *b;
359char *in;
360int inl;
361 { 342 {
362 int ret=inl,n,i; 343 int ret=inl,n,i;
363 BIO_B64_CTX *ctx; 344 BIO_B64_CTX *ctx;
@@ -451,11 +432,7 @@ int inl;
451 return(ret); 432 return(ret);
452 } 433 }
453 434
454static long b64_ctrl(b,cmd,num,ptr) 435static long b64_ctrl(BIO *b, int cmd, long num, char *ptr)
455BIO *b;
456int cmd;
457long num;
458char *ptr;
459 { 436 {
460 BIO_B64_CTX *ctx; 437 BIO_B64_CTX *ctx;
461 long ret=1; 438 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "buffer.h" 62#include <openssl/buffer.h>
63#include "evp.h" 63#include <openssl/evp.h>
64 64
65#ifndef NOPROTO
66static int enc_write(BIO *h,char *buf,int num); 65static int enc_write(BIO *h,char *buf,int num);
67static int enc_read(BIO *h,char *buf,int size); 66static int enc_read(BIO *h,char *buf,int size);
68/*static int enc_puts(BIO *h,char *str); */ 67/*static int enc_puts(BIO *h,char *str); */
@@ -70,16 +69,6 @@ static int enc_read(BIO *h,char *buf,int size);
70static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2); 69static long enc_ctrl(BIO *h,int cmd,long arg1,char *arg2);
71static int enc_new(BIO *h); 70static int enc_new(BIO *h);
72static int enc_free(BIO *data); 71static int enc_free(BIO *data);
73#else
74static int enc_write();
75static int enc_read();
76/*static int enc_puts(); */
77/*static int enc_gets(); */
78static long enc_ctrl();
79static int enc_new();
80static int enc_free();
81#endif
82
83#define ENC_BLOCK_SIZE (1024*4) 72#define ENC_BLOCK_SIZE (1024*4)
84 73
85typedef struct enc_struct 74typedef struct enc_struct
@@ -105,13 +94,12 @@ static BIO_METHOD methods_enc=
105 enc_free, 94 enc_free,
106 }; 95 };
107 96
108BIO_METHOD *BIO_f_cipher() 97BIO_METHOD *BIO_f_cipher(void)
109 { 98 {
110 return(&methods_enc); 99 return(&methods_enc);
111 } 100 }
112 101
113static int enc_new(bi) 102static int enc_new(BIO *bi)
114BIO *bi;
115 { 103 {
116 BIO_ENC_CTX *ctx; 104 BIO_ENC_CTX *ctx;
117 105
@@ -131,8 +119,7 @@ BIO *bi;
131 return(1); 119 return(1);
132 } 120 }
133 121
134static int enc_free(a) 122static int enc_free(BIO *a)
135BIO *a;
136 { 123 {
137 BIO_ENC_CTX *b; 124 BIO_ENC_CTX *b;
138 125
@@ -147,10 +134,7 @@ BIO *a;
147 return(1); 134 return(1);
148 } 135 }
149 136
150static int enc_read(b,out,outl) 137static int enc_read(BIO *b, char *out, int outl)
151BIO *b;
152char *out;
153int outl;
154 { 138 {
155 int ret=0,i; 139 int ret=0,i;
156 BIO_ENC_CTX *ctx; 140 BIO_ENC_CTX *ctx;
@@ -230,10 +214,7 @@ int outl;
230 return((ret == 0)?ctx->cont:ret); 214 return((ret == 0)?ctx->cont:ret);
231 } 215 }
232 216
233static int enc_write(b,in,inl) 217static int enc_write(BIO *b, char *in, int inl)
234BIO *b;
235char *in;
236int inl;
237 { 218 {
238 int ret=0,n,i; 219 int ret=0,n,i;
239 BIO_ENC_CTX *ctx; 220 BIO_ENC_CTX *ctx;
@@ -288,16 +269,13 @@ int inl;
288 return(ret); 269 return(ret);
289 } 270 }
290 271
291static long enc_ctrl(b,cmd,num,ptr) 272static long enc_ctrl(BIO *b, int cmd, long num, char *ptr)
292BIO *b;
293int cmd;
294long num;
295char *ptr;
296 { 273 {
297 BIO *dbio; 274 BIO *dbio;
298 BIO_ENC_CTX *ctx,*dctx; 275 BIO_ENC_CTX *ctx,*dctx;
299 long ret=1; 276 long ret=1;
300 int i; 277 int i;
278 EVP_CIPHER_CTX **c_ctx;
301 279
302 ctx=(BIO_ENC_CTX *)b->ptr; 280 ctx=(BIO_ENC_CTX *)b->ptr;
303 281
@@ -364,7 +342,11 @@ again:
364 ret=BIO_ctrl(b->next_bio,cmd,num,ptr); 342 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
365 BIO_copy_next_retry(b); 343 BIO_copy_next_retry(b);
366 break; 344 break;
367 345 case BIO_C_GET_CIPHER_CTX:
346 c_ctx=(EVP_CIPHER_CTX **)ptr;
347 (*c_ctx)= &(ctx->cipher);
348 b->init=1;
349 break;
368 case BIO_CTRL_DUP: 350 case BIO_CTRL_DUP:
369 dbio=(BIO *)ptr; 351 dbio=(BIO *)ptr;
370 dctx=(BIO_ENC_CTX *)dbio->ptr; 352 dctx=(BIO_ENC_CTX *)dbio->ptr;
@@ -398,19 +380,15 @@ EVP_CIPHER_ctx *c;
398 } 380 }
399*/ 381*/
400 382
401void BIO_set_cipher(b,c,k,i,e) 383void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
402BIO *b; 384 unsigned char *i, int e)
403EVP_CIPHER *c;
404unsigned char *k;
405unsigned char *i;
406int e;
407 { 385 {
408 BIO_ENC_CTX *ctx; 386 BIO_ENC_CTX *ctx;
409 387
410 if (b == NULL) return; 388 if (b == NULL) return;
411 389
412 if ((b->callback != NULL) && 390 if ((b->callback != NULL) &&
413 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0)) 391 (b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,0L) <= 0))
414 return; 392 return;
415 393
416 b->init=1; 394 b->init=1;
@@ -418,6 +396,6 @@ int e;
418 EVP_CipherInit(&(ctx->cipher),c,k,i,e); 396 EVP_CipherInit(&(ctx->cipher),c,k,i,e);
419 397
420 if (b->callback != NULL) 398 if (b->callback != NULL)
421 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L); 399 b->callback(b,BIO_CB_CTRL,(const char *)c,BIO_CTRL_SET,e,1L);
422 } 400 }
423 401
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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <errno.h> 60#include <errno.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "buffer.h" 62#include <openssl/buffer.h>
63#include "evp.h" 63#include <openssl/evp.h>
64 64
65/* BIO_put and BIO_get both add to the digest, 65/* BIO_put and BIO_get both add to the digest,
66 * BIO_gets returns the digest */ 66 * BIO_gets returns the digest */
67 67
68#ifndef NOPROTO
69static int md_write(BIO *h,char *buf,int num); 68static int md_write(BIO *h,char *buf,int num);
70static int md_read(BIO *h,char *buf,int size); 69static int md_read(BIO *h,char *buf,int size);
71/*static int md_puts(BIO *h,char *str); */ 70/*static int md_puts(BIO *h,char *str); */
@@ -73,16 +72,6 @@ static int md_gets(BIO *h,char *str,int size);
73static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2); 72static long md_ctrl(BIO *h,int cmd,long arg1,char *arg2);
74static int md_new(BIO *h); 73static int md_new(BIO *h);
75static int md_free(BIO *data); 74static int md_free(BIO *data);
76#else
77static int md_write();
78static int md_read();
79/*static int md_puts(); */
80static int md_gets();
81static long md_ctrl();
82static int md_new();
83static int md_free();
84#endif
85
86static BIO_METHOD methods_md= 75static BIO_METHOD methods_md=
87 { 76 {
88 BIO_TYPE_MD,"message digest", 77 BIO_TYPE_MD,"message digest",
@@ -95,13 +84,12 @@ static BIO_METHOD methods_md=
95 md_free, 84 md_free,
96 }; 85 };
97 86
98BIO_METHOD *BIO_f_md() 87BIO_METHOD *BIO_f_md(void)
99 { 88 {
100 return(&methods_md); 89 return(&methods_md);
101 } 90 }
102 91
103static int md_new(bi) 92static int md_new(BIO *bi)
104BIO *bi;
105 { 93 {
106 EVP_MD_CTX *ctx; 94 EVP_MD_CTX *ctx;
107 95
@@ -114,8 +102,7 @@ BIO *bi;
114 return(1); 102 return(1);
115 } 103 }
116 104
117static int md_free(a) 105static int md_free(BIO *a)
118BIO *a;
119 { 106 {
120 if (a == NULL) return(0); 107 if (a == NULL) return(0);
121 Free(a->ptr); 108 Free(a->ptr);
@@ -125,10 +112,7 @@ BIO *a;
125 return(1); 112 return(1);
126 } 113 }
127 114
128static int md_read(b,out,outl) 115static int md_read(BIO *b, char *out, int outl)
129BIO *b;
130char *out;
131int outl;
132 { 116 {
133 int ret=0; 117 int ret=0;
134 EVP_MD_CTX *ctx; 118 EVP_MD_CTX *ctx;
@@ -152,10 +136,7 @@ int outl;
152 return(ret); 136 return(ret);
153 } 137 }
154 138
155static int md_write(b,in,inl) 139static int md_write(BIO *b, char *in, int inl)
156BIO *b;
157char *in;
158int inl;
159 { 140 {
160 int ret=0; 141 int ret=0;
161 EVP_MD_CTX *ctx; 142 EVP_MD_CTX *ctx;
@@ -178,14 +159,10 @@ int inl;
178 return(ret); 159 return(ret);
179 } 160 }
180 161
181static long md_ctrl(b,cmd,num,ptr) 162static long md_ctrl(BIO *b, int cmd, long num, char *ptr)
182BIO *b;
183int cmd;
184long num;
185char *ptr;
186 { 163 {
187 EVP_MD_CTX *ctx,*dctx,**pctx; 164 EVP_MD_CTX *ctx,*dctx,**pctx;
188 EVP_MD **ppmd; 165 const EVP_MD **ppmd;
189 EVP_MD *md; 166 EVP_MD *md;
190 long ret=1; 167 long ret=1;
191 BIO *dbio; 168 BIO *dbio;
@@ -204,7 +181,7 @@ char *ptr;
204 case BIO_C_GET_MD: 181 case BIO_C_GET_MD:
205 if (b->init) 182 if (b->init)
206 { 183 {
207 ppmd=(EVP_MD **)ptr; 184 ppmd=(const EVP_MD **)ptr;
208 *ppmd=ctx->digest; 185 *ppmd=ctx->digest;
209 } 186 }
210 else 187 else
@@ -243,10 +220,7 @@ char *ptr;
243 return(ret); 220 return(ret);
244 } 221 }
245 222
246static int md_gets(bp,buf,size) 223static int md_gets(BIO *bp, char *buf, int size)
247BIO *bp;
248char *buf;
249int size;
250 { 224 {
251 EVP_MD_CTX *ctx; 225 EVP_MD_CTX *ctx;
252 unsigned int ret; 226 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 @@
1/* crypto/evp/bio_ok.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 From: Arne Ansper <arne@cyber.ee>
61
62 Why BIO_f_reliable?
63
64 I wrote function which took BIO* as argument, read data from it
65 and processed it. Then I wanted to store the input file in
66 encrypted form. OK I pushed BIO_f_cipher to the BIO stack
67 and everything was OK. BUT if user types wrong password
68 BIO_f_cipher outputs only garbage and my function crashes. Yes
69 I can and I should fix my function, but BIO_f_cipher is
70 easy way to add encryption support to many exisiting applications
71 and it's hard to debug and fix them all.
72
73 So I wanted another BIO which would catch the incorrect passwords and
74 file damages which cause garbage on BIO_f_cipher's output.
75
76 The easy way is to push the BIO_f_md and save the checksum at
77 the end of the file. However there are several problems with this
78 approach:
79
80 1) you must somehow separate checksum from actual data.
81 2) you need lot's of memory when reading the file, because you
82 must read to the end of the file and verify the checksum before
83 leting the application to read the data.
84
85 BIO_f_reliable tries to solve both problems, so that you can
86 read and write arbitraly long streams using only fixed amount
87 of memory.
88
89 BIO_f_reliable splits data stream into blocks. Each block is prefixed
90 with it's length and suffixed with it's digest. So you need only
91 several Kbytes of memory to buffer single block before verifying
92 it's digest.
93
94 BIO_f_reliable goes futher and adds several important capabilities:
95
96 1) the digest of the block is computed over the whole stream
97 -- so nobody can rearrange the blocks or remove or replace them.
98
99 2) to detect invalid passwords right at the start BIO_f_reliable
100 adds special prefix to the stream. In order to avoid known plain-text
101 attacks this prefix is generated as follows:
102
103 *) digest is initialized with random seed instead of
104 standardized one.
105 *) same seed is written to ouput
106 *) well-known text is then hashed and the output
107 of the digest is also written to output.
108
109 reader can now read the seed from stream, hash the same string
110 and then compare the digest output.
111
112 Bad things: BIO_f_reliable knows what's going on in EVP_Digest. I
113 initialy wrote and tested this code on x86 machine and wrote the
114 digests out in machine-dependent order :( There are people using
115 this code and I cannot change this easily without making existing
116 data files unreadable.
117
118*/
119
120#include <stdio.h>
121#include <errno.h>
122#include "cryptlib.h"
123#include <openssl/buffer.h>
124#include <openssl/bio.h>
125#include <openssl/evp.h>
126#include <openssl/rand.h>
127
128static int ok_write(BIO *h,char *buf,int num);
129static int ok_read(BIO *h,char *buf,int size);
130static long ok_ctrl(BIO *h,int cmd,long arg1,char *arg2);
131static int ok_new(BIO *h);
132static int ok_free(BIO *data);
133static void sig_out(BIO* b);
134static void sig_in(BIO* b);
135static void block_out(BIO* b);
136static void block_in(BIO* b);
137#define OK_BLOCK_SIZE (1024*4)
138#define OK_BLOCK_BLOCK 4
139#define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE)
140#define WELLKNOWN "The quick brown fox jumped over the lazy dog's back."
141
142#ifndef L_ENDIAN
143#define swapem(x) \
144 ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
145 (((unsigned long int)(x) & 0x0000ff00U) << 8) | \
146 (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
147 (((unsigned long int)(x) & 0xff000000U) >> 24)))
148#else
149#define swapem(x) (x)
150#endif
151
152typedef struct ok_struct
153 {
154 int buf_len;
155 int buf_off;
156 int buf_len_save;
157 int buf_off_save;
158 int cont; /* <= 0 when finished */
159 int finished;
160 EVP_MD_CTX md;
161 int blockout; /* output block is ready */
162 int sigio; /* must process signature */
163 char buf[IOBS];
164 } BIO_OK_CTX;
165
166static BIO_METHOD methods_ok=
167 {
168 BIO_TYPE_CIPHER,"reliable",
169 ok_write,
170 ok_read,
171 NULL, /* ok_puts, */
172 NULL, /* ok_gets, */
173 ok_ctrl,
174 ok_new,
175 ok_free,
176 };
177
178BIO_METHOD *BIO_f_reliable(void)
179 {
180 return(&methods_ok);
181 }
182
183static int ok_new(BIO *bi)
184 {
185 BIO_OK_CTX *ctx;
186
187 ctx=(BIO_OK_CTX *)Malloc(sizeof(BIO_OK_CTX));
188 if (ctx == NULL) return(0);
189
190 ctx->buf_len=0;
191 ctx->buf_off=0;
192 ctx->buf_len_save=0;
193 ctx->buf_off_save=0;
194 ctx->cont=1;
195 ctx->finished=0;
196 ctx->blockout= 0;
197 ctx->sigio=1;
198
199 bi->init=0;
200 bi->ptr=(char *)ctx;
201 bi->flags=0;
202 return(1);
203 }
204
205static int ok_free(BIO *a)
206 {
207 if (a == NULL) return(0);
208 memset(a->ptr,0,sizeof(BIO_OK_CTX));
209 Free(a->ptr);
210 a->ptr=NULL;
211 a->init=0;
212 a->flags=0;
213 return(1);
214 }
215
216static int ok_read(BIO *b, char *out, int outl)
217 {
218 int ret=0,i,n;
219 BIO_OK_CTX *ctx;
220
221 if (out == NULL) return(0);
222 ctx=(BIO_OK_CTX *)b->ptr;
223
224 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
225
226 while(outl > 0)
227 {
228
229 /* copy clean bytes to output buffer */
230 if (ctx->blockout)
231 {
232 i=ctx->buf_len-ctx->buf_off;
233 if (i > outl) i=outl;
234 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
235 ret+=i;
236 out+=i;
237 outl-=i;
238 ctx->buf_off+=i;
239
240 /* all clean bytes are out */
241 if (ctx->buf_len == ctx->buf_off)
242 {
243 ctx->buf_off=0;
244
245 /* copy start of the next block into proper place */
246 if(ctx->buf_len_save- ctx->buf_off_save > 0)
247 {
248 ctx->buf_len= ctx->buf_len_save- ctx->buf_off_save;
249 memmove(ctx->buf, &(ctx->buf[ctx->buf_off_save]),
250 ctx->buf_len);
251 }
252 else
253 {
254 ctx->buf_len=0;
255 }
256 ctx->blockout= 0;
257 }
258 }
259
260 /* output buffer full -- cancel */
261 if (outl == 0) break;
262
263 /* no clean bytes in buffer -- fill it */
264 n=IOBS- ctx->buf_len;
265 i=BIO_read(b->next_bio,&(ctx->buf[ctx->buf_len]),n);
266
267 if (i <= 0) break; /* nothing new */
268
269 ctx->buf_len+= i;
270
271 /* no signature yet -- check if we got one */
272 if (ctx->sigio == 1) sig_in(b);
273
274 /* signature ok -- check if we got block */
275 if (ctx->sigio == 0) block_in(b);
276
277 /* invalid block -- cancel */
278 if (ctx->cont <= 0) break;
279
280 }
281
282 BIO_clear_retry_flags(b);
283 BIO_copy_next_retry(b);
284 return(ret);
285 }
286
287static int ok_write(BIO *b, char *in, int inl)
288 {
289 int ret=0,n,i;
290 BIO_OK_CTX *ctx;
291
292 ctx=(BIO_OK_CTX *)b->ptr;
293 ret=inl;
294
295 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
296
297 if(ctx->sigio) sig_out(b);
298
299 do{
300 BIO_clear_retry_flags(b);
301 n=ctx->buf_len-ctx->buf_off;
302 while (ctx->blockout && n > 0)
303 {
304 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
305 if (i <= 0)
306 {
307 BIO_copy_next_retry(b);
308 if(!BIO_should_retry(b))
309 ctx->cont= 0;
310 return(i);
311 }
312 ctx->buf_off+=i;
313 n-=i;
314 }
315
316 /* at this point all pending data has been written */
317 ctx->blockout= 0;
318 if (ctx->buf_len == ctx->buf_off)
319 {
320 ctx->buf_len=OK_BLOCK_BLOCK;
321 ctx->buf_off=0;
322 }
323
324 if ((in == NULL) || (inl <= 0)) return(0);
325
326 n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ?
327 OK_BLOCK_SIZE+ OK_BLOCK_BLOCK- ctx->buf_len : inl;
328
329 memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n);
330 ctx->buf_len+= n;
331 inl-=n;
332 in+=n;
333
334 if(ctx->buf_len >= OK_BLOCK_SIZE+ OK_BLOCK_BLOCK)
335 {
336 block_out(b);
337 }
338 }while(inl > 0);
339
340 BIO_clear_retry_flags(b);
341 BIO_copy_next_retry(b);
342 return(ret);
343 }
344
345static long ok_ctrl(BIO *b, int cmd, long num, char *ptr)
346 {
347 BIO_OK_CTX *ctx;
348 EVP_MD *md;
349 const EVP_MD **ppmd;
350 long ret=1;
351 int i;
352
353 ctx=(BIO_OK_CTX *)b->ptr;
354
355 switch (cmd)
356 {
357 case BIO_CTRL_RESET:
358 ctx->buf_len=0;
359 ctx->buf_off=0;
360 ctx->buf_len_save=0;
361 ctx->buf_off_save=0;
362 ctx->cont=1;
363 ctx->finished=0;
364 ctx->blockout= 0;
365 ctx->sigio=1;
366 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
367 break;
368 case BIO_CTRL_EOF: /* More to read */
369 if (ctx->cont <= 0)
370 ret=1;
371 else
372 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
373 break;
374 case BIO_CTRL_PENDING: /* More to read in buffer */
375 case BIO_CTRL_WPENDING: /* More to read in buffer */
376 ret=ctx->blockout ? ctx->buf_len-ctx->buf_off : 0;
377 if (ret <= 0)
378 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
379 break;
380 case BIO_CTRL_FLUSH:
381 /* do a final write */
382 if(ctx->blockout == 0)
383 block_out(b);
384
385 while (ctx->blockout)
386 {
387 i=ok_write(b,NULL,0);
388 if (i < 0)
389 {
390 ret=i;
391 break;
392 }
393 }
394
395 ctx->finished=1;
396 ctx->buf_off=ctx->buf_len=0;
397 ctx->cont=(int)ret;
398
399 /* Finally flush the underlying BIO */
400 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
401 break;
402 case BIO_C_DO_STATE_MACHINE:
403 BIO_clear_retry_flags(b);
404 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
405 BIO_copy_next_retry(b);
406 break;
407 case BIO_CTRL_INFO:
408 ret=(long)ctx->cont;
409 break;
410 case BIO_C_SET_MD:
411 md=(EVP_MD *)ptr;
412 EVP_DigestInit(&(ctx->md),md);
413 b->init=1;
414 break;
415 case BIO_C_GET_MD:
416 if (b->init)
417 {
418 ppmd=(const EVP_MD **)ptr;
419 *ppmd=ctx->md.digest;
420 }
421 else
422 ret=0;
423 break;
424 default:
425 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
426 break;
427 }
428 return(ret);
429 }
430
431static void longswap(void *_ptr, int len)
432{
433#ifndef L_ENDIAN
434 int i;
435 char *ptr=_ptr;
436
437 for(i= 0;i < len;i+= 4){
438 *((unsigned long *)&(ptr[i]))= swapem(*((unsigned long *)&(ptr[i])));
439 }
440#endif
441}
442
443static void sig_out(BIO* b)
444 {
445 BIO_OK_CTX *ctx;
446 EVP_MD_CTX *md;
447
448 ctx=(BIO_OK_CTX *)b->ptr;
449 md= &(ctx->md);
450
451 if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return;
452
453 EVP_DigestInit(md, md->digest);
454 RAND_bytes(&(md->md.base[0]), md->digest->md_size);
455 memcpy(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]), md->digest->md_size);
456 longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
457 ctx->buf_len+= md->digest->md_size;
458
459 EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN));
460 md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]));
461 ctx->buf_len+= md->digest->md_size;
462 ctx->blockout= 1;
463 ctx->sigio= 0;
464 }
465
466static void sig_in(BIO* b)
467 {
468 BIO_OK_CTX *ctx;
469 EVP_MD_CTX *md;
470 unsigned char tmp[EVP_MAX_MD_SIZE];
471 int ret= 0;
472
473 ctx=(BIO_OK_CTX *)b->ptr;
474 md= &(ctx->md);
475
476 if(ctx->buf_len- ctx->buf_off < 2* md->digest->md_size) return;
477
478 EVP_DigestInit(md, md->digest);
479 memcpy(&(md->md.base[0]), &(ctx->buf[ctx->buf_off]), md->digest->md_size);
480 longswap(&(md->md.base[0]), md->digest->md_size);
481 ctx->buf_off+= md->digest->md_size;
482
483 EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN));
484 md->digest->final(tmp, &(md->md.base[0]));
485 ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
486 ctx->buf_off+= md->digest->md_size;
487 if(ret == 1)
488 {
489 ctx->sigio= 0;
490 if(ctx->buf_len != ctx->buf_off)
491 {
492 memmove(ctx->buf, &(ctx->buf[ctx->buf_off]), ctx->buf_len- ctx->buf_off);
493 }
494 ctx->buf_len-= ctx->buf_off;
495 ctx->buf_off= 0;
496 }
497 else
498 {
499 ctx->cont= 0;
500 }
501 }
502
503static void block_out(BIO* b)
504 {
505 BIO_OK_CTX *ctx;
506 EVP_MD_CTX *md;
507 unsigned long tl;
508
509 ctx=(BIO_OK_CTX *)b->ptr;
510 md= &(ctx->md);
511
512 tl= ctx->buf_len- OK_BLOCK_BLOCK;
513 tl= swapem(tl);
514 memcpy(ctx->buf, &tl, OK_BLOCK_BLOCK);
515 tl= swapem(tl);
516 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
517 md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]));
518 ctx->buf_len+= md->digest->md_size;
519 ctx->blockout= 1;
520 }
521
522static void block_in(BIO* b)
523 {
524 BIO_OK_CTX *ctx;
525 EVP_MD_CTX *md;
526 long tl= 0;
527 unsigned char tmp[EVP_MAX_MD_SIZE];
528
529 ctx=(BIO_OK_CTX *)b->ptr;
530 md= &(ctx->md);
531
532 memcpy(&tl, ctx->buf, OK_BLOCK_BLOCK);
533 tl= swapem(tl);
534 if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return;
535
536 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
537 md->digest->final(tmp, &(md->md.base[0]));
538 if(memcmp(&(ctx->buf[tl+ OK_BLOCK_BLOCK]), tmp, md->digest->md_size) == 0)
539 {
540 /* there might be parts from next block lurking around ! */
541 ctx->buf_off_save= tl+ OK_BLOCK_BLOCK+ md->digest->md_size;
542 ctx->buf_len_save= ctx->buf_len;
543 ctx->buf_off= OK_BLOCK_BLOCK;
544 ctx->buf_len= tl+ OK_BLOCK_BLOCK;
545 ctx->blockout= 1;
546 }
547 else
548 {
549 ctx->cont= 0;
550 }
551 }
552
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
63 64
64void SSLeay_add_all_algorithms() 65void SSLeay_add_all_algorithms(void)
65 { 66 {
66 SSLeay_add_all_ciphers(); 67 SSLeay_add_all_ciphers();
67 SSLeay_add_all_digests(); 68 SSLeay_add_all_digests();
68 } 69 }
69 70
70void SSLeay_add_all_ciphers() 71void SSLeay_add_all_ciphers(void)
71 { 72 {
72#ifndef NO_DES 73#ifndef NO_DES
73 EVP_add_cipher(EVP_des_cfb()); 74 EVP_add_cipher(EVP_des_cfb());
@@ -79,16 +80,16 @@ void SSLeay_add_all_ciphers()
79 EVP_add_cipher(EVP_des_ede3_ofb()); 80 EVP_add_cipher(EVP_des_ede3_ofb());
80 81
81 EVP_add_cipher(EVP_desx_cbc()); 82 EVP_add_cipher(EVP_desx_cbc());
82 EVP_add_alias(SN_desx_cbc,"DESX"); 83 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
83 EVP_add_alias(SN_desx_cbc,"desx"); 84 EVP_add_cipher_alias(SN_desx_cbc,"desx");
84 85
85 EVP_add_cipher(EVP_des_cbc()); 86 EVP_add_cipher(EVP_des_cbc());
86 EVP_add_alias(SN_des_cbc,"DES"); 87 EVP_add_cipher_alias(SN_des_cbc,"DES");
87 EVP_add_alias(SN_des_cbc,"des"); 88 EVP_add_cipher_alias(SN_des_cbc,"des");
88 EVP_add_cipher(EVP_des_ede_cbc()); 89 EVP_add_cipher(EVP_des_ede_cbc());
89 EVP_add_cipher(EVP_des_ede3_cbc()); 90 EVP_add_cipher(EVP_des_ede3_cbc());
90 EVP_add_alias(SN_des_ede3_cbc,"DES3"); 91 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
91 EVP_add_alias(SN_des_ede3_cbc,"des3"); 92 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
92 93
93 EVP_add_cipher(EVP_des_ecb()); 94 EVP_add_cipher(EVP_des_ecb());
94 EVP_add_cipher(EVP_des_ede()); 95 EVP_add_cipher(EVP_des_ede());
@@ -105,8 +106,8 @@ void SSLeay_add_all_ciphers()
105 EVP_add_cipher(EVP_idea_cfb()); 106 EVP_add_cipher(EVP_idea_cfb());
106 EVP_add_cipher(EVP_idea_ofb()); 107 EVP_add_cipher(EVP_idea_ofb());
107 EVP_add_cipher(EVP_idea_cbc()); 108 EVP_add_cipher(EVP_idea_cbc());
108 EVP_add_alias(SN_idea_cbc,"IDEA"); 109 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
109 EVP_add_alias(SN_idea_cbc,"idea"); 110 EVP_add_cipher_alias(SN_idea_cbc,"idea");
110#endif 111#endif
111 112
112#ifndef NO_RC2 113#ifndef NO_RC2
@@ -115,18 +116,19 @@ void SSLeay_add_all_ciphers()
115 EVP_add_cipher(EVP_rc2_ofb()); 116 EVP_add_cipher(EVP_rc2_ofb());
116 EVP_add_cipher(EVP_rc2_cbc()); 117 EVP_add_cipher(EVP_rc2_cbc());
117 EVP_add_cipher(EVP_rc2_40_cbc()); 118 EVP_add_cipher(EVP_rc2_40_cbc());
118 EVP_add_alias(SN_rc2_cbc,"RC2"); 119 EVP_add_cipher(EVP_rc2_64_cbc());
119 EVP_add_alias(SN_rc2_cbc,"rc2"); 120 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
121 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
120#endif 122#endif
121 123
122#ifndef NO_BLOWFISH 124#ifndef NO_BF
123 EVP_add_cipher(EVP_bf_ecb()); 125 EVP_add_cipher(EVP_bf_ecb());
124 EVP_add_cipher(EVP_bf_cfb()); 126 EVP_add_cipher(EVP_bf_cfb());
125 EVP_add_cipher(EVP_bf_ofb()); 127 EVP_add_cipher(EVP_bf_ofb());
126 EVP_add_cipher(EVP_bf_cbc()); 128 EVP_add_cipher(EVP_bf_cbc());
127 EVP_add_alias(SN_bf_cbc,"BF"); 129 EVP_add_cipher_alias(SN_bf_cbc,"BF");
128 EVP_add_alias(SN_bf_cbc,"bf"); 130 EVP_add_cipher_alias(SN_bf_cbc,"bf");
129 EVP_add_alias(SN_bf_cbc,"blowfish"); 131 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
130#endif 132#endif
131 133
132#ifndef NO_CAST 134#ifndef NO_CAST
@@ -134,10 +136,10 @@ void SSLeay_add_all_ciphers()
134 EVP_add_cipher(EVP_cast5_cfb()); 136 EVP_add_cipher(EVP_cast5_cfb());
135 EVP_add_cipher(EVP_cast5_ofb()); 137 EVP_add_cipher(EVP_cast5_ofb());
136 EVP_add_cipher(EVP_cast5_cbc()); 138 EVP_add_cipher(EVP_cast5_cbc());
137 EVP_add_alias(SN_cast5_cbc,"CAST"); 139 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
138 EVP_add_alias(SN_cast5_cbc,"cast"); 140 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
139 EVP_add_alias(SN_cast5_cbc,"CAST-cbc"); 141 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
140 EVP_add_alias(SN_cast5_cbc,"cast-cbc"); 142 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
141#endif 143#endif
142 144
143#ifndef NO_RC5 145#ifndef NO_RC5
@@ -145,23 +147,21 @@ void SSLeay_add_all_ciphers()
145 EVP_add_cipher(EVP_rc5_32_12_16_cfb()); 147 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
146 EVP_add_cipher(EVP_rc5_32_12_16_ofb()); 148 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
147 EVP_add_cipher(EVP_rc5_32_12_16_cbc()); 149 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
148 EVP_add_alias(SN_rc5_cbc,"rc5"); 150 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
149 EVP_add_alias(SN_rc5_cbc,"RC5"); 151 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
150 EVP_add_alias(SN_rc5_cbc,"rc5-cbc");
151 EVP_add_alias(SN_rc5_cbc,"RC5-cbc");
152#endif 152#endif
153 } 153 }
154 154
155 155
156void SSLeay_add_all_digests() 156void SSLeay_add_all_digests(void)
157 { 157 {
158#ifndef NO_MD2 158#ifndef NO_MD2
159 EVP_add_digest(EVP_md2()); 159 EVP_add_digest(EVP_md2());
160#endif 160#endif
161#ifndef NO_MD5 161#ifndef NO_MD5
162 EVP_add_digest(EVP_md5()); 162 EVP_add_digest(EVP_md5());
163 EVP_add_alias(SN_md5,"ssl2-md5"); 163 EVP_add_digest_alias(SN_md5,"ssl2-md5");
164 EVP_add_alias(SN_md5,"ssl3-md5"); 164 EVP_add_digest_alias(SN_md5,"ssl3-md5");
165#endif 165#endif
166#ifndef NO_SHA 166#ifndef NO_SHA
167 EVP_add_digest(EVP_sha()); 167 EVP_add_digest(EVP_sha());
@@ -169,22 +169,25 @@ void SSLeay_add_all_digests()
169 EVP_add_digest(EVP_dss()); 169 EVP_add_digest(EVP_dss());
170#endif 170#endif
171#endif 171#endif
172#ifndef NO_SHA1 172#ifndef NO_SHA
173 EVP_add_digest(EVP_sha1()); 173 EVP_add_digest(EVP_sha1());
174 EVP_add_alias(SN_sha1,"ssl3-sha1"); 174 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
175 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
175#ifndef NO_DSA 176#ifndef NO_DSA
176 EVP_add_digest(EVP_dss1()); 177 EVP_add_digest(EVP_dss1());
177 EVP_add_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2); 178 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
178 EVP_add_alias(SN_dsaWithSHA1,"DSS1"); 179 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
179 EVP_add_alias(SN_dsaWithSHA1,"dss1"); 180 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
180#endif 181#endif
181#endif 182#endif
182#if !defined(NO_MDC2) && !defined(NO_DES) 183#if !defined(NO_MDC2) && !defined(NO_DES)
183 EVP_add_digest(EVP_mdc2()); 184 EVP_add_digest(EVP_mdc2());
184#endif 185#endif
185#ifndef NO_RIPEMD160 186#ifndef NO_RIPEMD
186 EVP_add_digest(EVP_ripemd160()); 187 EVP_add_digest(EVP_ripemd160());
187 EVP_add_alias(SN_ripemd160,"ripemd"); 188 EVP_add_digest_alias(SN_ripemd160,"ripemd");
188 EVP_add_alias(SN_ripemd160,"rmd160"); 189 EVP_add_digest_alias(SN_ripemd160,"rmd160");
189#endif 190#endif
191 PKCS12_PBE_add();
192 PKCS5_PBE_add();
190 } 193 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "objects.h" 61#include <openssl/objects.h>
62#include "evp.h" 62#include <openssl/evp.h>
63 63
64void EVP_DigestInit(ctx,type) 64void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
65EVP_MD_CTX *ctx;
66EVP_MD *type;
67 { 65 {
68 ctx->digest=type; 66 ctx->digest=type;
69 type->init(&(ctx->md)); 67 type->init(&(ctx->md));
70 } 68 }
71 69
72void EVP_DigestUpdate(ctx,data,count) 70void EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
73EVP_MD_CTX *ctx; 71 unsigned int count)
74unsigned char *data;
75unsigned int count;
76 { 72 {
77 ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count); 73 ctx->digest->update(&(ctx->md.base[0]),data,(unsigned long)count);
78 } 74 }
79 75
80void EVP_DigestFinal(ctx,md,size) 76void EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
81EVP_MD_CTX *ctx;
82unsigned char *md;
83unsigned int *size;
84 { 77 {
85 ctx->digest->final(md,&(ctx->md.base[0])); 78 ctx->digest->final(md,&(ctx->md.base[0]));
86 if (size != NULL) 79 if (size != NULL)
87 *size=ctx->digest->md_size; 80 *size=ctx->digest->md_size;
88 memset(&(ctx->md),0,sizeof(ctx->md)); 81 memset(&(ctx->md),0,sizeof(ctx->md));
89 } 82 }
83
84int EVP_MD_CTX_copy(EVP_MD_CTX *out, EVP_MD_CTX *in)
85{
86 if ((in == NULL) || (in->digest == NULL)) {
87 EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
88 return 0;
89 }
90 memcpy((char *)out,(char *)in,in->digest->ctx_size);
91 return 1;
92}
diff --git a/src/lib/libcrypto/evp/e_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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 67static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 68 unsigned char *iv,int enc);
69static void des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 69static void des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 70 unsigned char *in, unsigned int inl);
71#else
72static void des_cbc_ede_init_key();
73static void des_cbc_ede3_init_key();
74static void des_cbc_ede_cipher();
75#endif
76
77static EVP_CIPHER d_cbc_ede_cipher2= 71static EVP_CIPHER d_cbc_ede_cipher2=
78 { 72 {
79 NID_des_ede_cbc, 73 NID_des_ede_cbc,
@@ -83,8 +77,8 @@ static EVP_CIPHER d_cbc_ede_cipher2=
83 NULL, 77 NULL,
84 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 78 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
85 sizeof((((EVP_CIPHER_CTX *)NULL)->c.des_ede)), 79 sizeof((((EVP_CIPHER_CTX *)NULL)->c.des_ede)),
86 EVP_CIPHER_get_asn1_iv,
87 EVP_CIPHER_set_asn1_iv, 80 EVP_CIPHER_set_asn1_iv,
81 EVP_CIPHER_get_asn1_iv,
88 }; 82 };
89 83
90static EVP_CIPHER d_cbc_ede_cipher3= 84static EVP_CIPHER d_cbc_ede_cipher3=
@@ -100,64 +94,58 @@ static EVP_CIPHER d_cbc_ede_cipher3=
100 EVP_CIPHER_get_asn1_iv, 94 EVP_CIPHER_get_asn1_iv,
101 }; 95 };
102 96
103EVP_CIPHER *EVP_des_ede_cbc() 97EVP_CIPHER *EVP_des_ede_cbc(void)
104 { 98 {
105 return(&d_cbc_ede_cipher2); 99 return(&d_cbc_ede_cipher2);
106 } 100 }
107 101
108EVP_CIPHER *EVP_des_ede3_cbc() 102EVP_CIPHER *EVP_des_ede3_cbc(void)
109 { 103 {
110 return(&d_cbc_ede_cipher3); 104 return(&d_cbc_ede_cipher3);
111 } 105 }
112 106
113static void des_cbc_ede_init_key(ctx,key,iv,enc) 107static void des_cbc_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
114EVP_CIPHER_CTX *ctx; 108 unsigned char *iv, int enc)
115unsigned char *key;
116unsigned char *iv;
117int enc;
118 { 109 {
110 des_cblock *deskey = (des_cblock *)key;
111
119 if (iv != NULL) 112 if (iv != NULL)
120 memcpy(&(ctx->oiv[0]),iv,8); 113 memcpy(&(ctx->oiv[0]),iv,8);
121 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 114 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
122 115
123 if (key != NULL) 116 if (deskey != NULL)
124 { 117 {
125 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 118 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
126 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 119 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
127 memcpy( (char *)ctx->c.des_ede.ks3, 120 memcpy( (char *)ctx->c.des_ede.ks3,
128 (char *)ctx->c.des_ede.ks1, 121 (char *)ctx->c.des_ede.ks1,
129 sizeof(ctx->c.des_ede.ks1)); 122 sizeof(ctx->c.des_ede.ks1));
130 } 123 }
131 } 124 }
132 125
133static void des_cbc_ede3_init_key(ctx,key,iv,enc) 126static void des_cbc_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
134EVP_CIPHER_CTX *ctx; 127 unsigned char *iv, int enc)
135unsigned char *key;
136unsigned char *iv;
137int enc;
138 { 128 {
129 des_cblock *deskey = (des_cblock *)key;
130
139 if (iv != NULL) 131 if (iv != NULL)
140 memcpy(&(ctx->oiv[0]),iv,8); 132 memcpy(&(ctx->oiv[0]),iv,8);
141 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 133 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
142 134
143 if (key != NULL) 135 if (deskey != NULL)
144 { 136 {
145 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 137 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
146 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 138 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
147 des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); 139 des_set_key(&deskey[2],ctx->c.des_ede.ks3);
148 } 140 }
149 } 141 }
150 142
151static void des_cbc_ede_cipher(ctx,out,in,inl) 143static void des_cbc_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
152EVP_CIPHER_CTX *ctx; 144 unsigned char *in, unsigned int inl)
153unsigned char *out;
154unsigned char *in;
155unsigned int inl;
156 { 145 {
157 des_ede3_cbc_encrypt( 146 des_ede3_cbc_encrypt(in,out,inl, ctx->c.des_ede.ks1,
158 (des_cblock *)in,(des_cblock *)out,
159 (long)inl, ctx->c.des_ede.ks1,
160 ctx->c.des_ede.ks2,ctx->c.des_ede.ks3, 147 ctx->c.des_ede.ks2,ctx->c.des_ede.ks3,
161 (des_cblock *)&(ctx->iv[0]), 148 (des_cblock *) &(ctx->iv[0]),
162 ctx->encrypt); 149 ctx->encrypt);
163 } 150 }
151#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_BLOWFISH 59#ifndef NO_BF
60
61#include <stdio.h> 60#include <stdio.h>
62#include "cryptlib.h" 61#include "cryptlib.h"
63#include "evp.h" 62#include <openssl/evp.h>
64#include "objects.h" 63#include <openssl/objects.h>
65 64
66#ifndef NOPROTO
67static void bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
69static void bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
71#else
72static void bf_cbc_init_key();
73static void bf_cbc_cipher();
74#endif
75
76static EVP_CIPHER bfish_cbc_cipher= 69static EVP_CIPHER bfish_cbc_cipher=
77 { 70 {
78 NID_bf_cbc, 71 NID_bf_cbc,
@@ -82,20 +75,17 @@ static EVP_CIPHER bfish_cbc_cipher=
82 NULL, 75 NULL,
83 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 76 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
84 sizeof((((EVP_CIPHER_CTX *)NULL)->c.bf_ks)), 77 sizeof((((EVP_CIPHER_CTX *)NULL)->c.bf_ks)),
85 EVP_CIPHER_get_asn1_iv,
86 EVP_CIPHER_set_asn1_iv, 78 EVP_CIPHER_set_asn1_iv,
79 EVP_CIPHER_get_asn1_iv,
87 }; 80 };
88 81
89EVP_CIPHER *EVP_bf_cbc() 82EVP_CIPHER *EVP_bf_cbc(void)
90 { 83 {
91 return(&bfish_cbc_cipher); 84 return(&bfish_cbc_cipher);
92 } 85 }
93 86
94static void bf_cbc_init_key(ctx,key,iv,enc) 87static void bf_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 89 {
100 if (iv != NULL) 90 if (iv != NULL)
101 memcpy(&(ctx->oiv[0]),iv,8); 91 memcpy(&(ctx->oiv[0]),iv,8);
@@ -104,11 +94,8 @@ int enc;
104 BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); 94 BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key);
105 } 95 }
106 96
107static void bf_cbc_cipher(ctx,out,in,inl) 97static void bf_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
108EVP_CIPHER_CTX *ctx; 98 unsigned char *in, unsigned int inl)
109unsigned char *out;
110unsigned char *in;
111unsigned int inl;
112 { 99 {
113 BF_cbc_encrypt( 100 BF_cbc_encrypt(
114 in,out,(long)inl, 101 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void cast_cbc_init_key();
73static void cast_cbc_cipher();
74#endif
75
76static EVP_CIPHER cast5_cbc_cipher= 70static EVP_CIPHER cast5_cbc_cipher=
77 { 71 {
78 NID_cast5_cbc, 72 NID_cast5_cbc,
@@ -82,20 +76,17 @@ static EVP_CIPHER cast5_cbc_cipher=
82 NULL, 76 NULL,
83 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 77 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
84 sizeof((((EVP_CIPHER_CTX *)NULL)->c.cast_ks)), 78 sizeof((((EVP_CIPHER_CTX *)NULL)->c.cast_ks)),
85 EVP_CIPHER_get_asn1_iv,
86 EVP_CIPHER_set_asn1_iv, 79 EVP_CIPHER_set_asn1_iv,
80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_cast5_cbc() 83EVP_CIPHER *EVP_cast5_cbc(void)
90 { 84 {
91 return(&cast5_cbc_cipher); 85 return(&cast5_cbc_cipher);
92 } 86 }
93 87
94static void cast_cbc_init_key(ctx,key,iv,enc) 88static void cast_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 if (iv != NULL) 91 if (iv != NULL)
101 memcpy(&(ctx->oiv[0]),iv,8); 92 memcpy(&(ctx->oiv[0]),iv,8);
@@ -104,11 +95,8 @@ int enc;
104 CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key); 95 CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key);
105 } 96 }
106 97
107static void cast_cbc_cipher(ctx,out,in,inl) 98static void cast_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
108EVP_CIPHER_CTX *ctx; 99 unsigned char *in, unsigned int inl)
109unsigned char *out;
110unsigned char *in;
111unsigned int inl;
112 { 100 {
113 CAST_cbc_encrypt( 101 CAST_cbc_encrypt(
114 in,out,(long)inl, 102 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
69#else
70static void des_cbc_init_key();
71static void des_cbc_cipher();
72#endif
73
74static EVP_CIPHER d_cbc_cipher= 69static EVP_CIPHER d_cbc_cipher=
75 { 70 {
76 NID_des_cbc, 71 NID_des_cbc,
@@ -80,37 +75,32 @@ static EVP_CIPHER d_cbc_cipher=
80 NULL, 75 NULL,
81 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 76 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
82 sizeof((((EVP_CIPHER_CTX *)NULL)->c.des_ks)), 77 sizeof((((EVP_CIPHER_CTX *)NULL)->c.des_ks)),
83 EVP_CIPHER_get_asn1_iv,
84 EVP_CIPHER_set_asn1_iv, 78 EVP_CIPHER_set_asn1_iv,
79 EVP_CIPHER_get_asn1_iv,
85 }; 80 };
86 81
87EVP_CIPHER *EVP_des_cbc() 82EVP_CIPHER *EVP_des_cbc(void)
88 { 83 {
89 return(&d_cbc_cipher); 84 return(&d_cbc_cipher);
90 } 85 }
91 86
92static void des_cbc_init_key(ctx,key,iv,enc) 87static void des_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
93EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
94unsigned char *key;
95unsigned char *iv;
96int enc;
97 { 89 {
90 des_cblock *deskey = (des_cblock *)key;
91
98 if (iv != NULL) 92 if (iv != NULL)
99 memcpy(&(ctx->oiv[0]),iv,8); 93 memcpy(&(ctx->oiv[0]),iv,8);
100 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 94 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
101 if (key != NULL) 95 if (deskey != NULL)
102 des_set_key((des_cblock *)key,ctx->c.des_ks); 96 des_set_key(deskey,ctx->c.des_ks);
103 } 97 }
104 98
105static void des_cbc_cipher(ctx,out,in,inl) 99static void des_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
106EVP_CIPHER_CTX *ctx; 100 unsigned char *in, unsigned int inl)
107unsigned char *out;
108unsigned char *in;
109unsigned int inl;
110 { 101 {
111 des_ncbc_encrypt( 102 des_ncbc_encrypt(in,out,inl,ctx->c.des_ks,
112 (des_cblock *)in,(des_cblock *)out,
113 (long)inl, ctx->c.des_ks,
114 (des_cblock *)&(ctx->iv[0]), 103 (des_cblock *)&(ctx->iv[0]),
115 ctx->encrypt); 104 ctx->encrypt);
116 } 105 }
106#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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void idea_cbc_init_key();
73static void idea_cbc_cipher();
74#endif
75
76static EVP_CIPHER i_cbc_cipher= 70static EVP_CIPHER i_cbc_cipher=
77 { 71 {
78 NID_idea_cbc, 72 NID_idea_cbc,
@@ -82,20 +76,17 @@ static EVP_CIPHER i_cbc_cipher=
82 NULL, 76 NULL,
83 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 77 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
84 sizeof((((EVP_CIPHER_CTX *)NULL)->c.idea_ks)), 78 sizeof((((EVP_CIPHER_CTX *)NULL)->c.idea_ks)),
85 EVP_CIPHER_get_asn1_iv,
86 EVP_CIPHER_set_asn1_iv, 79 EVP_CIPHER_set_asn1_iv,
80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_idea_cbc() 83EVP_CIPHER *EVP_idea_cbc(void)
90 { 84 {
91 return(&i_cbc_cipher); 85 return(&i_cbc_cipher);
92 } 86 }
93 87
94static void idea_cbc_init_key(ctx,key,iv,enc) 88static void idea_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 if (iv != NULL) 91 if (iv != NULL)
101 memcpy(&(ctx->oiv[0]),iv,8); 92 memcpy(&(ctx->oiv[0]),iv,8);
@@ -116,11 +107,8 @@ int enc;
116 } 107 }
117 } 108 }
118 109
119static void idea_cbc_cipher(ctx,out,in,inl) 110static void idea_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
120EVP_CIPHER_CTX *ctx; 111 unsigned char *in, unsigned int inl)
121unsigned char *out;
122unsigned char *in;
123unsigned int inl;
124 { 112 {
125 idea_cbc_encrypt( 113 idea_cbc_encrypt(
126 in,out,(long)inl, 114 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else 70static int rc2_meth_to_magic(const EVP_CIPHER *e);
72static void rc2_cbc_init_key(); 71static EVP_CIPHER *rc2_magic_to_meth(int i);
73static void rc2_cbc_cipher(); 72static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
74#endif 73static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
74
75#define RC2_40_MAGIC 0xa0
76#define RC2_64_MAGIC 0x78
77#define RC2_128_MAGIC 0x3a
75 78
76static EVP_CIPHER r2_cbc_cipher= 79static EVP_CIPHER r2_cbc_cipher=
77 { 80 {
@@ -82,8 +85,21 @@ static EVP_CIPHER r2_cbc_cipher=
82 NULL, 85 NULL,
83 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 86 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
84 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)), 87 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)),
85 EVP_CIPHER_get_asn1_iv, 88 rc2_set_asn1_type_and_iv,
86 EVP_CIPHER_set_asn1_iv, 89 rc2_get_asn1_type_and_iv,
90 };
91
92static EVP_CIPHER r2_64_cbc_cipher=
93 {
94 NID_rc2_64_cbc,
95 8,8 /* 64 bit */,8,
96 rc2_cbc_init_key,
97 rc2_cbc_cipher,
98 NULL,
99 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
100 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)),
101 rc2_set_asn1_type_and_iv,
102 rc2_get_asn1_type_and_iv,
87 }; 103 };
88 104
89static EVP_CIPHER r2_40_cbc_cipher= 105static EVP_CIPHER r2_40_cbc_cipher=
@@ -95,23 +111,27 @@ static EVP_CIPHER r2_40_cbc_cipher=
95 NULL, 111 NULL,
96 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+ 112 sizeof(EVP_CIPHER_CTX)-sizeof((((EVP_CIPHER_CTX *)NULL)->c))+
97 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)), 113 sizeof((((EVP_CIPHER_CTX *)NULL)->c.rc2_ks)),
114 rc2_set_asn1_type_and_iv,
115 rc2_get_asn1_type_and_iv,
98 }; 116 };
99 117
100EVP_CIPHER *EVP_rc2_cbc() 118EVP_CIPHER *EVP_rc2_cbc(void)
101 { 119 {
102 return(&r2_cbc_cipher); 120 return(&r2_cbc_cipher);
103 } 121 }
104 122
105EVP_CIPHER *EVP_rc2_40_cbc() 123EVP_CIPHER *EVP_rc2_64_cbc(void)
124 {
125 return(&r2_64_cbc_cipher);
126 }
127
128EVP_CIPHER *EVP_rc2_40_cbc(void)
106 { 129 {
107 return(&r2_40_cbc_cipher); 130 return(&r2_40_cbc_cipher);
108 } 131 }
109 132
110static void rc2_cbc_init_key(ctx,key,iv,enc) 133static void rc2_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
111EVP_CIPHER_CTX *ctx; 134 unsigned char *iv, int enc)
112unsigned char *key;
113unsigned char *iv;
114int enc;
115 { 135 {
116 if (iv != NULL) 136 if (iv != NULL)
117 memcpy(&(ctx->oiv[0]),iv,8); 137 memcpy(&(ctx->oiv[0]),iv,8);
@@ -121,11 +141,8 @@ int enc;
121 key,EVP_CIPHER_CTX_key_length(ctx)*8); 141 key,EVP_CIPHER_CTX_key_length(ctx)*8);
122 } 142 }
123 143
124static void rc2_cbc_cipher(ctx,out,in,inl) 144static void rc2_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
125EVP_CIPHER_CTX *ctx; 145 unsigned char *in, unsigned int inl)
126unsigned char *out;
127unsigned char *in;
128unsigned int inl;
129 { 146 {
130 RC2_cbc_encrypt( 147 RC2_cbc_encrypt(
131 in,out,(long)inl, 148 in,out,(long)inl,
@@ -133,4 +150,67 @@ unsigned int inl;
133 ctx->encrypt); 150 ctx->encrypt);
134 } 151 }
135 152
153static int rc2_meth_to_magic(const EVP_CIPHER *e)
154 {
155 int i;
156
157 i=EVP_CIPHER_key_length(e);
158 if (i == 16) return(RC2_128_MAGIC);
159 else if (i == 8) return(RC2_64_MAGIC);
160 else if (i == 5) return(RC2_40_MAGIC);
161 else return(0);
162 }
163
164static EVP_CIPHER *rc2_magic_to_meth(int i)
165 {
166 if (i == RC2_128_MAGIC) return(EVP_rc2_cbc());
167 else if (i == RC2_64_MAGIC) return(EVP_rc2_64_cbc());
168 else if (i == RC2_40_MAGIC) return(EVP_rc2_40_cbc());
169 else
170 {
171 EVPerr(EVP_F_RC2_MAGIC_TO_METH,EVP_R_UNSUPPORTED_KEY_SIZE);
172 return(NULL);
173 }
174 }
175
176static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
177 {
178 long num=0;
179 int i=0,l;
180 EVP_CIPHER *e;
181
182 if (type != NULL)
183 {
184 l=EVP_CIPHER_CTX_iv_length(c);
185 i=ASN1_TYPE_get_int_octetstring(type,&num,c->oiv,l);
186 if (i != l)
187 return(-1);
188 else if (i > 0)
189 memcpy(c->iv,c->oiv,l);
190 e=rc2_magic_to_meth((int)num);
191 if (e == NULL)
192 return(-1);
193 if (e != EVP_CIPHER_CTX_cipher(c))
194 {
195 EVP_CIPHER_CTX_cipher(c)=e;
196 rc2_cbc_init_key(c,NULL,NULL,1);
197 }
198 }
199 return(i);
200 }
201
202static int rc2_set_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
203 {
204 long num;
205 int i=0,j;
206
207 if (type != NULL)
208 {
209 num=rc2_meth_to_magic(EVP_CIPHER_CTX_cipher(c));
210 j=EVP_CIPHER_CTX_iv_length(c);
211 i=ASN1_TYPE_set_int_octetstring(type,num,c->oiv,j);
212 }
213 return(i);
214 }
215
136#endif 216#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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void r_32_12_16_cbc_init_key();
73static void r_32_12_16_cbc_cipher();
74#endif
75
76static EVP_CIPHER rc5_32_12_16_cbc_cipher= 70static EVP_CIPHER rc5_32_12_16_cbc_cipher=
77 { 71 {
78 NID_rc5_cbc, 72 NID_rc5_cbc,
@@ -86,16 +80,13 @@ static EVP_CIPHER rc5_32_12_16_cbc_cipher=
86 NULL, 80 NULL,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_rc5_32_12_16_cbc() 83EVP_CIPHER *EVP_rc5_32_12_16_cbc(void)
90 { 84 {
91 return(&rc5_32_12_16_cbc_cipher); 85 return(&rc5_32_12_16_cbc_cipher);
92 } 86 }
93 87
94static void r_32_12_16_cbc_init_key(ctx,key,iv,enc) 88static void r_32_12_16_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 if (iv != NULL) 91 if (iv != NULL)
101 memcpy(&(ctx->oiv[0]),iv,8); 92 memcpy(&(ctx->oiv[0]),iv,8);
@@ -105,11 +96,8 @@ int enc;
105 key,RC5_12_ROUNDS); 96 key,RC5_12_ROUNDS);
106 } 97 }
107 98
108static void r_32_12_16_cbc_cipher(ctx,out,in,inl) 99static void r_32_12_16_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
109EVP_CIPHER_CTX *ctx; 100 unsigned char *in, unsigned int inl)
110unsigned char *out;
111unsigned char *in;
112unsigned int inl;
113 { 101 {
114 RC5_32_cbc_encrypt( 102 RC5_32_cbc_encrypt(
115 in,out,(long)inl, 103 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 67static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 68 unsigned char *iv,int enc);
69static void des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 69static void des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 70 unsigned char *in, unsigned int inl);
71#else
72static void des_ede_cfb_init_key();
73static void des_ede3_cfb_init_key();
74static void des_ede_cfb_cipher();
75#endif
76
77static EVP_CIPHER d_ede_cfb_cipher2= 71static EVP_CIPHER d_ede_cfb_cipher2=
78 { 72 {
79 NID_des_ede_cfb64, 73 NID_des_ede_cfb64,
@@ -100,67 +94,62 @@ static EVP_CIPHER d_ede3_cfb_cipher3=
100 EVP_CIPHER_get_asn1_iv, 94 EVP_CIPHER_get_asn1_iv,
101 }; 95 };
102 96
103EVP_CIPHER *EVP_des_ede_cfb() 97EVP_CIPHER *EVP_des_ede_cfb(void)
104 { 98 {
105 return(&d_ede_cfb_cipher2); 99 return(&d_ede_cfb_cipher2);
106 } 100 }
107 101
108EVP_CIPHER *EVP_des_ede3_cfb() 102EVP_CIPHER *EVP_des_ede3_cfb(void)
109 { 103 {
110 return(&d_ede3_cfb_cipher3); 104 return(&d_ede3_cfb_cipher3);
111 } 105 }
112 106
113static void des_ede_cfb_init_key(ctx,key,iv,enc) 107static void des_ede_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
114EVP_CIPHER_CTX *ctx; 108 unsigned char *iv, int enc)
115unsigned char *key;
116unsigned char *iv;
117int enc;
118 { 109 {
110 des_cblock *deskey = (des_cblock *)key;
111
119 ctx->num=0; 112 ctx->num=0;
120 113
121 if (iv != NULL) 114 if (iv != NULL)
122 memcpy(&(ctx->oiv[0]),iv,8); 115 memcpy(&(ctx->oiv[0]),iv,8);
123 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 116 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
124 if (key != NULL) 117 if (deskey != NULL)
125 { 118 {
126 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 119 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
127 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 120 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
128 memcpy( (char *)ctx->c.des_ede.ks3, 121 memcpy( (char *)ctx->c.des_ede.ks3,
129 (char *)ctx->c.des_ede.ks1, 122 (char *)ctx->c.des_ede.ks1,
130 sizeof(ctx->c.des_ede.ks1)); 123 sizeof(ctx->c.des_ede.ks1));
131 } 124 }
132 } 125 }
133 126
134static void des_ede3_cfb_init_key(ctx,key,iv,enc) 127static void des_ede3_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
135EVP_CIPHER_CTX *ctx; 128 unsigned char *iv, int enc)
136unsigned char *key;
137unsigned char *iv;
138int enc;
139 { 129 {
130 des_cblock *deskey = (des_cblock *)key;
131
140 ctx->num=0; 132 ctx->num=0;
141 133
142 if (iv != NULL) 134 if (iv != NULL)
143 memcpy(&(ctx->oiv[0]),iv,8); 135 memcpy(&(ctx->oiv[0]),iv,8);
144 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 136 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
145 if (key != NULL) 137 if (deskey != NULL)
146 { 138 {
147 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 139 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
148 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 140 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
149 des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); 141 des_set_key(&deskey[2],ctx->c.des_ede.ks3);
150 } 142 }
151 } 143 }
152 144
153static void des_ede_cfb_cipher(ctx,out,in,inl) 145static void des_ede_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
154EVP_CIPHER_CTX *ctx; 146 unsigned char *in, unsigned int inl)
155unsigned char *out;
156unsigned char *in;
157unsigned int inl;
158 { 147 {
159 des_ede3_cfb64_encrypt( 148 des_ede3_cfb64_encrypt(in,out,(long)inl,
160 in,out,(long)inl, 149 ctx->c.des_ede.ks1,
161 ctx->c.des_ede.ks1, 150 ctx->c.des_ede.ks2,
162 ctx->c.des_ede.ks2, 151 ctx->c.des_ede.ks3,
163 ctx->c.des_ede.ks3, 152 (des_cblock*)&(ctx->iv[0]),
164 (des_cblock *)&(ctx->iv[0]), 153 &ctx->num,ctx->encrypt);
165 &ctx->num,ctx->encrypt);
166 } 154 }
155#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_BLOWFISH 59#ifndef NO_BF
60
61#include <stdio.h> 60#include <stdio.h>
62#include "cryptlib.h" 61#include "cryptlib.h"
63#include "evp.h" 62#include <openssl/evp.h>
64#include "objects.h" 63#include <openssl/objects.h>
65 64
66#ifndef NOPROTO
67static void bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
69static void bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
71#else
72static void bf_cfb_init_key();
73static void bf_cfb_cipher();
74#endif
75
76static EVP_CIPHER bfish_cfb_cipher= 69static EVP_CIPHER bfish_cfb_cipher=
77 { 70 {
78 NID_bf_cfb64, 71 NID_bf_cfb64,
@@ -86,16 +79,13 @@ static EVP_CIPHER bfish_cfb_cipher=
86 EVP_CIPHER_get_asn1_iv, 79 EVP_CIPHER_get_asn1_iv,
87 }; 80 };
88 81
89EVP_CIPHER *EVP_bf_cfb() 82EVP_CIPHER *EVP_bf_cfb(void)
90 { 83 {
91 return(&bfish_cfb_cipher); 84 return(&bfish_cfb_cipher);
92 } 85 }
93 86
94static void bf_cfb_init_key(ctx,key,iv,enc) 87static void bf_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 89 {
100 ctx->num=0; 90 ctx->num=0;
101 91
@@ -106,11 +96,8 @@ int enc;
106 BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); 96 BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key);
107 } 97 }
108 98
109static void bf_cfb_cipher(ctx,out,in,inl) 99static void bf_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
110EVP_CIPHER_CTX *ctx; 100 unsigned char *in, unsigned int inl)
111unsigned char *out;
112unsigned char *in;
113unsigned int inl;
114 { 101 {
115 BF_cfb64_encrypt( 102 BF_cfb64_encrypt(
116 in,out, 103 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void cast_cfb_init_key();
73static void cast_cfb_cipher();
74#endif
75
76static EVP_CIPHER cast5_cfb_cipher= 70static EVP_CIPHER cast5_cfb_cipher=
77 { 71 {
78 NID_cast5_cfb64, 72 NID_cast5_cfb64,
@@ -86,16 +80,13 @@ static EVP_CIPHER cast5_cfb_cipher=
86 EVP_CIPHER_get_asn1_iv, 80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_cast5_cfb() 83EVP_CIPHER *EVP_cast5_cfb(void)
90 { 84 {
91 return(&cast5_cfb_cipher); 85 return(&cast5_cfb_cipher);
92 } 86 }
93 87
94static void cast_cfb_init_key(ctx,key,iv,enc) 88static void cast_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 ctx->num=0; 91 ctx->num=0;
101 92
@@ -106,11 +97,8 @@ int enc;
106 CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key); 97 CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key);
107 } 98 }
108 99
109static void cast_cfb_cipher(ctx,out,in,inl) 100static void cast_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
110EVP_CIPHER_CTX *ctx; 101 unsigned char *in, unsigned int inl)
111unsigned char *out;
112unsigned char *in;
113unsigned int inl;
114 { 102 {
115 CAST_cfb64_encrypt( 103 CAST_cfb64_encrypt(
116 in,out, 104 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63 63
64#ifndef NOPROTO 64#ifndef NO_DES
65static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
69#else
70static void des_cfb_init_key();
71static void des_cfb_cipher();
72#endif
73
74static EVP_CIPHER d_cfb_cipher= 69static EVP_CIPHER d_cfb_cipher=
75 { 70 {
76 NID_des_cfb64, 71 NID_des_cfb64,
@@ -84,31 +79,27 @@ static EVP_CIPHER d_cfb_cipher=
84 EVP_CIPHER_get_asn1_iv, 79 EVP_CIPHER_get_asn1_iv,
85 }; 80 };
86 81
87EVP_CIPHER *EVP_des_cfb() 82EVP_CIPHER *EVP_des_cfb(void)
88 { 83 {
89 return(&d_cfb_cipher); 84 return(&d_cfb_cipher);
90 } 85 }
91 86
92static void des_cfb_init_key(ctx,key,iv,enc) 87static void des_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
93EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
94unsigned char *key;
95unsigned char *iv;
96int enc;
97 { 89 {
90 des_cblock *deskey = (des_cblock *)key;
91
98 ctx->num=0; 92 ctx->num=0;
99 93
100 if (iv != NULL) 94 if (iv != NULL)
101 memcpy(&(ctx->oiv[0]),iv,8); 95 memcpy(&(ctx->oiv[0]),iv,8);
102 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 96 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
103 if (key != NULL) 97 if (deskey != NULL)
104 des_set_key((des_cblock *)key,ctx->c.des_ks); 98 des_set_key(deskey,ctx->c.des_ks);
105 } 99 }
106 100
107static void des_cfb_cipher(ctx,out,in,inl) 101static void des_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
108EVP_CIPHER_CTX *ctx; 102 unsigned char *in, unsigned int inl)
109unsigned char *out;
110unsigned char *in;
111unsigned int inl;
112 { 103 {
113 des_cfb64_encrypt( 104 des_cfb64_encrypt(
114 in,out, 105 in,out,
@@ -116,3 +107,4 @@ unsigned int inl;
116 (des_cblock *)&(ctx->iv[0]), 107 (des_cblock *)&(ctx->iv[0]),
117 &ctx->num,ctx->encrypt); 108 &ctx->num,ctx->encrypt);
118 } 109 }
110#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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void idea_cfb_init_key();
73static void idea_cfb_cipher();
74#endif
75
76static EVP_CIPHER i_cfb_cipher= 70static EVP_CIPHER i_cfb_cipher=
77 { 71 {
78 NID_idea_cfb64, 72 NID_idea_cfb64,
@@ -86,16 +80,13 @@ static EVP_CIPHER i_cfb_cipher=
86 EVP_CIPHER_get_asn1_iv, 80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_idea_cfb() 83EVP_CIPHER *EVP_idea_cfb(void)
90 { 84 {
91 return(&i_cfb_cipher); 85 return(&i_cfb_cipher);
92 } 86 }
93 87
94static void idea_cfb_init_key(ctx,key,iv,enc) 88static void idea_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 ctx->num=0; 91 ctx->num=0;
101 92
@@ -106,11 +97,8 @@ int enc;
106 idea_set_encrypt_key(key,&(ctx->c.idea_ks)); 97 idea_set_encrypt_key(key,&(ctx->c.idea_ks));
107 } 98 }
108 99
109static void idea_cfb_cipher(ctx,out,in,inl) 100static void idea_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
110EVP_CIPHER_CTX *ctx; 101 unsigned char *in, unsigned int inl)
111unsigned char *out;
112unsigned char *in;
113unsigned int inl;
114 { 102 {
115 idea_cfb64_encrypt( 103 idea_cfb64_encrypt(
116 in,out,(long)inl, 104 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void rc2_cfb_init_key();
73static void rc2_cfb_cipher();
74#endif
75
76static EVP_CIPHER r2_cfb_cipher= 70static EVP_CIPHER r2_cfb_cipher=
77 { 71 {
78 NID_rc2_cfb64, 72 NID_rc2_cfb64,
@@ -86,16 +80,13 @@ static EVP_CIPHER r2_cfb_cipher=
86 EVP_CIPHER_get_asn1_iv, 80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_rc2_cfb() 83EVP_CIPHER *EVP_rc2_cfb(void)
90 { 84 {
91 return(&r2_cfb_cipher); 85 return(&r2_cfb_cipher);
92 } 86 }
93 87
94static void rc2_cfb_init_key(ctx,key,iv,enc) 88static void rc2_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 ctx->num=0; 91 ctx->num=0;
101 92
@@ -103,15 +94,12 @@ int enc;
103 memcpy(&(ctx->oiv[0]),iv,8); 94 memcpy(&(ctx->oiv[0]),iv,8);
104 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 95 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
105 if (key != NULL) 96 if (key != NULL)
106 RC2_set_key(&(ctx->c.rc2_ks),EVP_RC2_KEY_SIZE,key, 97 RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
107 EVP_RC2_KEY_SIZE*8); 98 key,EVP_CIPHER_CTX_key_length(ctx)*8);
108 } 99 }
109 100
110static void rc2_cfb_cipher(ctx,out,in,inl) 101static void rc2_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
111EVP_CIPHER_CTX *ctx; 102 unsigned char *in, unsigned int inl)
112unsigned char *out;
113unsigned char *in;
114unsigned int inl;
115 { 103 {
116 RC2_cfb64_encrypt( 104 RC2_cfb64_encrypt(
117 in,out, 105 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void rc5_32_12_16_cfb_init_key();
73static void rc5_32_12_16_cfb_cipher();
74#endif
75
76static EVP_CIPHER rc5_cfb_cipher= 70static EVP_CIPHER rc5_cfb_cipher=
77 { 71 {
78 NID_rc5_cfb64, 72 NID_rc5_cfb64,
@@ -86,16 +80,13 @@ static EVP_CIPHER rc5_cfb_cipher=
86 EVP_CIPHER_get_asn1_iv, 80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_rc5_32_12_16_cfb() 83EVP_CIPHER *EVP_rc5_32_12_16_cfb(void)
90 { 84 {
91 return(&rc5_cfb_cipher); 85 return(&rc5_cfb_cipher);
92 } 86 }
93 87
94static void rc5_32_12_16_cfb_init_key(ctx,key,iv,enc) 88static void rc5_32_12_16_cfb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 ctx->num=0; 91 ctx->num=0;
101 92
@@ -107,11 +98,8 @@ int enc;
107 RC5_12_ROUNDS); 98 RC5_12_ROUNDS);
108 } 99 }
109 100
110static void rc5_32_12_16_cfb_cipher(ctx,out,in,inl) 101static void rc5_32_12_16_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
111EVP_CIPHER_CTX *ctx; 102 unsigned char *in, unsigned int inl)
112unsigned char *out;
113unsigned char *in;
114unsigned int inl;
115 { 103 {
116 RC5_32_cfb64_encrypt( 104 RC5_32_cfb64_encrypt(
117 in,out, 105 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/x509.h>
64 64
65static EVP_PKEY_METHOD dss_method= 65static EVP_PKEY_METHOD dss_method=
66 { 66 {
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 67static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 68 unsigned char *iv,int enc);
69static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 69static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 70 unsigned char *in, unsigned int inl);
71#else
72static void des_ede_init_key();
73static void des_ede3_init_key();
74static void des_ede_cipher();
75#endif
76
77static EVP_CIPHER d_ede_cipher2= 71static EVP_CIPHER d_ede_cipher2=
78 { 72 {
79 NID_des_ede, 73 NID_des_ede,
@@ -99,63 +93,66 @@ static EVP_CIPHER d_ede3_cipher3=
99 NULL, 93 NULL,
100 }; 94 };
101 95
102EVP_CIPHER *EVP_des_ede() 96EVP_CIPHER *EVP_des_ede(void)
103 { 97 {
104 return(&d_ede_cipher2); 98 return(&d_ede_cipher2);
105 } 99 }
106 100
107EVP_CIPHER *EVP_des_ede3() 101EVP_CIPHER *EVP_des_ede3(void)
108 { 102 {
109 return(&d_ede3_cipher3); 103 return(&d_ede3_cipher3);
110 } 104 }
111 105
112static void des_ede_init_key(ctx,key,iv,enc) 106static void des_ede_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
113EVP_CIPHER_CTX *ctx; 107 unsigned char *iv, int enc)
114unsigned char *key;
115unsigned char *iv;
116int enc;
117 { 108 {
118 if (key != NULL) 109 des_cblock *deskey = (des_cblock *)key;
110
111 if (deskey != NULL)
119 { 112 {
120 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 113 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
121 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 114 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
122 memcpy( (char *)ctx->c.des_ede.ks3, 115 memcpy( (char *)ctx->c.des_ede.ks3,
123 (char *)ctx->c.des_ede.ks1, 116 (char *)ctx->c.des_ede.ks1,
124 sizeof(ctx->c.des_ede.ks1)); 117 sizeof(ctx->c.des_ede.ks1));
125 } 118 }
126 } 119 }
127 120
128static void des_ede3_init_key(ctx,key,iv,enc) 121static void des_ede3_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
129EVP_CIPHER_CTX *ctx; 122 unsigned char *iv, int enc)
130unsigned char *key;
131unsigned char *iv;
132int enc;
133 { 123 {
134 if (key != NULL) 124 des_cblock *deskey = (des_cblock *)key;
125
126 if (deskey != NULL)
135 { 127 {
136 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 128 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
137 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 129 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
138 des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); 130 des_set_key(&deskey[2],ctx->c.des_ede.ks3);
139 } 131 }
140 } 132 }
141 133
142static void des_ede_cipher(ctx,out,in,inl) 134static void des_ede_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
143EVP_CIPHER_CTX *ctx; 135 unsigned char *in, unsigned int inl)
144unsigned char *out;
145unsigned char *in;
146unsigned int inl;
147 { 136 {
148 unsigned int i; 137 unsigned int i;
138 des_cblock *output /* = (des_cblock *)out */;
139 des_cblock *input /* = (des_cblock *)in */;
149 140
150 if (inl < 8) return; 141 if (inl < 8) return;
151 inl-=8; 142 inl-=8;
152 for (i=0; i<=inl; i+=8) 143 for (i=0; i<=inl; i+=8)
153 { 144 {
154 des_ecb3_encrypt( 145 output = (des_cblock *)(out + i);
155 (des_cblock *)&(in[i]),(des_cblock *)&(out[i]), 146 input = (des_cblock *)(in + i);
147
148 des_ecb3_encrypt(input,output,
156 ctx->c.des_ede.ks1, 149 ctx->c.des_ede.ks1,
157 ctx->c.des_ede.ks2, 150 ctx->c.des_ede.ks2,
158 ctx->c.des_ede.ks3, 151 ctx->c.des_ede.ks3,
159 ctx->encrypt); 152 ctx->encrypt);
153
154 /* output++; */
155 /* input++; */
160 } 156 }
161 } 157 }
158#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_BLOWFISH 59#ifndef NO_BF
60
61#include <stdio.h> 60#include <stdio.h>
62#include "cryptlib.h" 61#include "cryptlib.h"
63#include "evp.h" 62#include <openssl/evp.h>
64#include "objects.h" 63#include <openssl/objects.h>
65 64
66#ifndef NOPROTO
67static void bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
69static void bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
71#else
72static void bf_ecb_init_key();
73static void bf_ecb_cipher();
74#endif
75
76static EVP_CIPHER bfish_ecb_cipher= 69static EVP_CIPHER bfish_ecb_cipher=
77 { 70 {
78 NID_bf_ecb, 71 NID_bf_ecb,
@@ -86,26 +79,20 @@ static EVP_CIPHER bfish_ecb_cipher=
86 NULL, 79 NULL,
87 }; 80 };
88 81
89EVP_CIPHER *EVP_bf_ecb() 82EVP_CIPHER *EVP_bf_ecb(void)
90 { 83 {
91 return(&bfish_ecb_cipher); 84 return(&bfish_ecb_cipher);
92 } 85 }
93 86
94static void bf_ecb_init_key(ctx,key,iv,enc) 87static void bf_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 89 {
100 if (key != NULL) 90 if (key != NULL)
101 BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); 91 BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key);
102 } 92 }
103 93
104static void bf_ecb_cipher(ctx,out,in,inl) 94static void bf_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
105EVP_CIPHER_CTX *ctx; 95 unsigned char *in, unsigned int inl)
106unsigned char *out;
107unsigned char *in;
108unsigned int inl;
109 { 96 {
110 unsigned int i; 97 unsigned int i;
111 98
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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void cast_ecb_init_key();
73static void cast_ecb_cipher();
74#endif
75
76static EVP_CIPHER cast5_ecb_cipher= 70static EVP_CIPHER cast5_ecb_cipher=
77 { 71 {
78 NID_cast5_ecb, 72 NID_cast5_ecb,
@@ -86,26 +80,20 @@ static EVP_CIPHER cast5_ecb_cipher=
86 NULL, 80 NULL,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_cast5_ecb() 83EVP_CIPHER *EVP_cast5_ecb(void)
90 { 84 {
91 return(&cast5_ecb_cipher); 85 return(&cast5_ecb_cipher);
92 } 86 }
93 87
94static void cast_ecb_init_key(ctx,key,iv,enc) 88static void cast_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 if (key != NULL) 91 if (key != NULL)
101 CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key); 92 CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key);
102 } 93 }
103 94
104static void cast_ecb_cipher(ctx,out,in,inl) 95static void cast_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
105EVP_CIPHER_CTX *ctx; 96 unsigned char *in, unsigned int inl)
106unsigned char *out;
107unsigned char *in;
108unsigned int inl;
109 { 97 {
110 unsigned int i; 98 unsigned int i;
111 99
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
69#else
70static void des_ecb_init_key();
71static void des_ecb_cipher();
72#endif
73
74static EVP_CIPHER d_ecb_cipher= 69static EVP_CIPHER d_ecb_cipher=
75 { 70 {
76 NID_des_ecb, 71 NID_des_ecb,
@@ -84,35 +79,40 @@ static EVP_CIPHER d_ecb_cipher=
84 NULL, 79 NULL,
85 }; 80 };
86 81
87EVP_CIPHER *EVP_des_ecb() 82EVP_CIPHER *EVP_des_ecb(void)
88 { 83 {
89 return(&d_ecb_cipher); 84 return(&d_ecb_cipher);
90 } 85 }
91 86
92static void des_ecb_init_key(ctx,key,iv,enc) 87static void des_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
93EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
94unsigned char *key;
95unsigned char *iv;
96int enc;
97 { 89 {
98 if (key != NULL) 90 des_cblock *deskey = (des_cblock *)key;
99 des_set_key((des_cblock *)key,ctx->c.des_ks); 91
92 if (deskey != NULL)
93 des_set_key(deskey,ctx->c.des_ks);
100 } 94 }
101 95
102static void des_ecb_cipher(ctx,out,in,inl) 96static void des_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
103EVP_CIPHER_CTX *ctx; 97 unsigned char *in, unsigned int inl)
104unsigned char *out;
105unsigned char *in;
106unsigned int inl;
107 { 98 {
108 unsigned int i; 99 unsigned int i;
100 des_cblock *output /* = (des_cblock *)out */;
101 des_cblock *input /* = (des_cblock *)in */;
109 102
110 if (inl < 8) return; 103 if (inl < 8) return;
111 inl-=8; 104 inl-=8;
112 for (i=0; i<=inl; i+=8) 105 for (i=0; i<=inl; i+=8)
113 { 106 {
114 des_ecb_encrypt( 107 /* Either this ... */
115 (des_cblock *)&(in[i]),(des_cblock *)&(out[i]), 108 output = (des_cblock *)(out + i);
116 ctx->c.des_ks,ctx->encrypt); 109 input = (des_cblock *)(in + i);
110
111 des_ecb_encrypt(input,output,ctx->c.des_ks,ctx->encrypt);
112
113 /* ... or this. */
114 /* output++; */
115 /* input++; */
117 } 116 }
118 } 117 }
118#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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void idea_ecb_init_key();
73static void idea_ecb_cipher();
74#endif
75
76static EVP_CIPHER i_ecb_cipher= 70static EVP_CIPHER i_ecb_cipher=
77 { 71 {
78 NID_idea_ecb, 72 NID_idea_ecb,
@@ -86,16 +80,13 @@ static EVP_CIPHER i_ecb_cipher=
86 NULL, 80 NULL,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_idea_ecb() 83EVP_CIPHER *EVP_idea_ecb(void)
90 { 84 {
91 return(&i_ecb_cipher); 85 return(&i_ecb_cipher);
92 } 86 }
93 87
94static void idea_ecb_init_key(ctx,key,iv,enc) 88static void idea_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 if (key != NULL) 91 if (key != NULL)
101 { 92 {
@@ -113,11 +104,8 @@ int enc;
113 } 104 }
114 } 105 }
115 106
116static void idea_ecb_cipher(ctx,out,in,inl) 107static void idea_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
117EVP_CIPHER_CTX *ctx; 108 unsigned char *in, unsigned int inl)
118unsigned char *out;
119unsigned char *in;
120unsigned int inl;
121 { 109 {
122 unsigned int i; 110 unsigned int i;
123 111
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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void rc2_ecb_init_key();
73static void rc2_ecb_cipher();
74#endif
75
76static EVP_CIPHER r2_ecb_cipher= 70static EVP_CIPHER r2_ecb_cipher=
77 { 71 {
78 NID_rc2_ecb, 72 NID_rc2_ecb,
@@ -86,27 +80,21 @@ static EVP_CIPHER r2_ecb_cipher=
86 NULL, 80 NULL,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_rc2_ecb() 83EVP_CIPHER *EVP_rc2_ecb(void)
90 { 84 {
91 return(&r2_ecb_cipher); 85 return(&r2_ecb_cipher);
92 } 86 }
93 87
94static void rc2_ecb_init_key(ctx,key,iv,enc) 88static void rc2_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 if (key != NULL) 91 if (key != NULL)
101 RC2_set_key(&(ctx->c.rc2_ks),EVP_RC2_KEY_SIZE,key, 92 RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
102 EVP_RC2_KEY_SIZE*8); 93 key,EVP_CIPHER_CTX_key_length(ctx)*8);
103 } 94 }
104 95
105static void rc2_ecb_cipher(ctx,out,in,inl) 96static void rc2_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
106EVP_CIPHER_CTX *ctx; 97 unsigned char *in, unsigned int inl)
107unsigned char *out;
108unsigned char *in;
109unsigned int inl;
110 { 98 {
111 unsigned int i; 99 unsigned int i;
112 100
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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void rc5_32_12_16_ecb_init_key();
73static void rc5_32_12_16_ecb_cipher();
74#endif
75
76static EVP_CIPHER rc5_ecb_cipher= 70static EVP_CIPHER rc5_ecb_cipher=
77 { 71 {
78 NID_rc5_ecb, 72 NID_rc5_ecb,
@@ -86,27 +80,21 @@ static EVP_CIPHER rc5_ecb_cipher=
86 NULL, 80 NULL,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_rc5_32_12_16_ecb() 83EVP_CIPHER *EVP_rc5_32_12_16_ecb(void)
90 { 84 {
91 return(&rc5_ecb_cipher); 85 return(&rc5_ecb_cipher);
92 } 86 }
93 87
94static void rc5_32_12_16_ecb_init_key(ctx,key,iv,enc) 88static void rc5_32_12_16_ecb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 if (key != NULL) 91 if (key != NULL)
101 RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key, 92 RC5_32_set_key(&(ctx->c.rc5_ks),EVP_RC5_32_12_16_KEY_SIZE,key,
102 RC5_12_ROUNDS); 93 RC5_12_ROUNDS);
103 } 94 }
104 95
105static void rc5_32_12_16_ecb_cipher(ctx,out,in,inl) 96static void rc5_32_12_16_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
106EVP_CIPHER_CTX *ctx; 97 unsigned char *in, unsigned int inl)
107unsigned char *out;
108unsigned char *in;
109unsigned int inl;
110 { 98 {
111 unsigned int i; 99 unsigned int i;
112 100
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63 63
64#ifndef NOPROTO
65static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 64static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 65 unsigned char *iv,int enc);
67static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 66static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl); 67 unsigned char *in, unsigned int inl);
69#else
70static void null_init_key();
71static void null_cipher();
72#endif
73
74static EVP_CIPHER n_cipher= 68static EVP_CIPHER n_cipher=
75 { 69 {
76 NID_undef, 70 NID_undef,
@@ -83,25 +77,19 @@ static EVP_CIPHER n_cipher=
83 NULL, 77 NULL,
84 }; 78 };
85 79
86EVP_CIPHER *EVP_enc_null() 80EVP_CIPHER *EVP_enc_null(void)
87 { 81 {
88 return(&n_cipher); 82 return(&n_cipher);
89 } 83 }
90 84
91static void null_init_key(ctx,key,iv,enc) 85static void null_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
92EVP_CIPHER_CTX *ctx; 86 unsigned char *iv, int enc)
93unsigned char *key;
94unsigned char *iv;
95int enc;
96 { 87 {
97 memset(&(ctx->c),0,sizeof(ctx->c)); 88 memset(&(ctx->c),0,sizeof(ctx->c));
98 } 89 }
99 90
100static void null_cipher(ctx,out,in,inl) 91static void null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
101EVP_CIPHER_CTX *ctx; 92 unsigned char *in, unsigned int inl)
102unsigned char *out;
103unsigned char *in;
104unsigned int inl;
105 { 93 {
106 if (in != out) 94 if (in != out)
107 memcpy((char *)out,(char *)in,(int)inl); 95 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 67static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 68 unsigned char *iv,int enc);
69static void des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 69static void des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 70 unsigned char *in, unsigned int inl);
71#else
72static void des_ede_ofb_init_key();
73static void des_ede3_ofb_init_key();
74static void des_ede_ofb_cipher();
75#endif
76
77static EVP_CIPHER d_ede_ofb_cipher2= 71static EVP_CIPHER d_ede_ofb_cipher2=
78 { 72 {
79 NID_des_ede_ofb64, 73 NID_des_ede_ofb64,
@@ -100,66 +94,59 @@ static EVP_CIPHER d_ede3_ofb_cipher3=
100 EVP_CIPHER_get_asn1_iv, 94 EVP_CIPHER_get_asn1_iv,
101 }; 95 };
102 96
103EVP_CIPHER *EVP_des_ede_ofb() 97EVP_CIPHER *EVP_des_ede_ofb(void)
104 { 98 {
105 return(&d_ede_ofb_cipher2); 99 return(&d_ede_ofb_cipher2);
106 } 100 }
107 101
108EVP_CIPHER *EVP_des_ede3_ofb() 102EVP_CIPHER *EVP_des_ede3_ofb(void)
109 { 103 {
110 return(&d_ede3_ofb_cipher3); 104 return(&d_ede3_ofb_cipher3);
111 } 105 }
112 106
113static void des_ede_ofb_init_key(ctx,key,iv,enc) 107static void des_ede_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
114EVP_CIPHER_CTX *ctx; 108 unsigned char *iv, int enc)
115unsigned char *key;
116unsigned char *iv;
117int enc;
118 { 109 {
110 des_cblock *deskey = (des_cblock *)key;
111
119 ctx->num=0; 112 ctx->num=0;
120 113
121 if (iv != NULL) 114 if (iv != NULL)
122 memcpy(&(ctx->oiv[0]),iv,8); 115 memcpy(&(ctx->oiv[0]),iv,8);
123 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 116 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
124 if (key != NULL) 117 if (deskey != NULL)
125 { 118 {
126 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 119 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
127 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 120 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
128 memcpy( (char *)ctx->c.des_ede.ks3, 121 memcpy( (char *)ctx->c.des_ede.ks3,
129 (char *)ctx->c.des_ede.ks1, 122 (char *)ctx->c.des_ede.ks1,
130 sizeof(ctx->c.des_ede.ks1)); 123 sizeof(ctx->c.des_ede.ks1));
131 } 124 }
132 } 125 }
133 126
134static void des_ede3_ofb_init_key(ctx,key,iv,enc) 127static void des_ede3_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
135EVP_CIPHER_CTX *ctx; 128 unsigned char *iv, int enc)
136unsigned char *key;
137unsigned char *iv;
138int enc;
139 { 129 {
130 des_cblock *deskey = (des_cblock *)key;
131
140 ctx->num=0; 132 ctx->num=0;
141 133
142 if (iv != NULL) 134 if (iv != NULL)
143 memcpy(&(ctx->oiv[0]),iv,8); 135 memcpy(&(ctx->oiv[0]),iv,8);
144 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 136 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
145 if (key != NULL) 137 if (deskey != NULL)
146 { 138 {
147 des_set_key((des_cblock *)key,ctx->c.des_ede.ks1); 139 des_set_key(&deskey[0],ctx->c.des_ede.ks1);
148 des_set_key((des_cblock *)&(key[8]),ctx->c.des_ede.ks2); 140 des_set_key(&deskey[1],ctx->c.des_ede.ks2);
149 des_set_key((des_cblock *)&(key[16]),ctx->c.des_ede.ks3); 141 des_set_key(&deskey[2],ctx->c.des_ede.ks3);
150 } 142 }
151 } 143 }
152 144
153static void des_ede_ofb_cipher(ctx,out,in,inl) 145static void des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
154EVP_CIPHER_CTX *ctx; 146 unsigned char *in, unsigned int inl)
155unsigned char *out;
156unsigned char *in;
157unsigned int inl;
158 { 147 {
159 des_ede3_ofb64_encrypt( 148 des_ede3_ofb64_encrypt(in,out,inl,ctx->c.des_ede.ks1,
160 in,out, 149 ctx->c.des_ede.ks2, ctx->c.des_ede.ks3,
161 (long)inl, 150 (des_cblock *)&(ctx->iv[0]),&ctx->num);
162 ctx->c.des_ede.ks1, ctx->c.des_ede.ks2, ctx->c.des_ede.ks3,
163 (des_cblock *)&(ctx->iv[0]),
164 &ctx->num);
165 } 151 }
152#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_BLOWFISH 59#ifndef NO_BF
60
61#include <stdio.h> 60#include <stdio.h>
62#include "cryptlib.h" 61#include "cryptlib.h"
63#include "evp.h" 62#include <openssl/evp.h>
64#include "objects.h" 63#include <openssl/objects.h>
65 64
66#ifndef NOPROTO
67static void bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
69static void bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
71#else
72static void bf_ofb_init_key();
73static void bf_ofb_cipher();
74#endif
75
76static EVP_CIPHER bfish_ofb_cipher= 69static EVP_CIPHER bfish_ofb_cipher=
77 { 70 {
78 NID_bf_ofb64, 71 NID_bf_ofb64,
@@ -86,16 +79,13 @@ static EVP_CIPHER bfish_ofb_cipher=
86 EVP_CIPHER_get_asn1_iv, 79 EVP_CIPHER_get_asn1_iv,
87 }; 80 };
88 81
89EVP_CIPHER *EVP_bf_ofb() 82EVP_CIPHER *EVP_bf_ofb(void)
90 { 83 {
91 return(&bfish_ofb_cipher); 84 return(&bfish_ofb_cipher);
92 } 85 }
93 86
94static void bf_ofb_init_key(ctx,key,iv,enc) 87static void bf_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 89 {
100 ctx->num=0; 90 ctx->num=0;
101 91
@@ -106,11 +96,8 @@ int enc;
106 BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key); 96 BF_set_key(&(ctx->c.bf_ks),EVP_BLOWFISH_KEY_SIZE,key);
107 } 97 }
108 98
109static void bf_ofb_cipher(ctx,out,in,inl) 99static void bf_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
110EVP_CIPHER_CTX *ctx; 100 unsigned char *in, unsigned int inl)
111unsigned char *out;
112unsigned char *in;
113unsigned int inl;
114 { 101 {
115 BF_ofb64_encrypt( 102 BF_ofb64_encrypt(
116 in,out, 103 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void cast_ofb_init_key();
73static void cast_ofb_cipher();
74#endif
75
76static EVP_CIPHER cast5_ofb_cipher= 70static EVP_CIPHER cast5_ofb_cipher=
77 { 71 {
78 NID_cast5_ofb64, 72 NID_cast5_ofb64,
@@ -86,16 +80,13 @@ static EVP_CIPHER cast5_ofb_cipher=
86 EVP_CIPHER_get_asn1_iv, 80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_cast5_ofb() 83EVP_CIPHER *EVP_cast5_ofb(void)
90 { 84 {
91 return(&cast5_ofb_cipher); 85 return(&cast5_ofb_cipher);
92 } 86 }
93 87
94static void cast_ofb_init_key(ctx,key,iv,enc) 88static void cast_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 ctx->num=0; 91 ctx->num=0;
101 92
@@ -106,11 +97,8 @@ int enc;
106 CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key); 97 CAST_set_key(&(ctx->c.cast_ks),EVP_CAST5_KEY_SIZE,key);
107 } 98 }
108 99
109static void cast_ofb_cipher(ctx,out,in,inl) 100static void cast_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
110EVP_CIPHER_CTX *ctx; 101 unsigned char *in, unsigned int inl)
111unsigned char *out;
112unsigned char *in;
113unsigned int inl;
114 { 102 {
115 CAST_ofb64_encrypt( 103 CAST_ofb64_encrypt(
116 in,out, 104 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
69#else
70static void des_ofb_init_key();
71static void des_ofb_cipher();
72#endif
73
74static EVP_CIPHER d_ofb_cipher= 69static EVP_CIPHER d_ofb_cipher=
75 { 70 {
76 NID_des_ofb64, 71 NID_des_ofb64,
@@ -84,35 +79,29 @@ static EVP_CIPHER d_ofb_cipher=
84 EVP_CIPHER_get_asn1_iv, 79 EVP_CIPHER_get_asn1_iv,
85 }; 80 };
86 81
87EVP_CIPHER *EVP_des_ofb() 82EVP_CIPHER *EVP_des_ofb(void)
88 { 83 {
89 return(&d_ofb_cipher); 84 return(&d_ofb_cipher);
90 } 85 }
91 86
92static void des_ofb_init_key(ctx,key,iv,enc) 87static void des_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
93EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
94unsigned char *key;
95unsigned char *iv;
96int enc;
97 { 89 {
90 des_cblock *deskey = (des_cblock *)key;
91
98 ctx->num=0; 92 ctx->num=0;
99 93
100 if (iv != NULL) 94 if (iv != NULL)
101 memcpy(&(ctx->oiv[0]),iv,8); 95 memcpy(&(ctx->oiv[0]),iv,8);
102 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 96 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
103 if (key != NULL) 97 if (deskey != NULL)
104 des_set_key((des_cblock *)key,ctx->c.des_ks); 98 des_set_key(deskey,ctx->c.des_ks);
105 } 99 }
106 100
107static void des_ofb_cipher(ctx,out,in,inl) 101static void des_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
108EVP_CIPHER_CTX *ctx; 102 unsigned char *in, unsigned int inl)
109unsigned char *out;
110unsigned char *in;
111unsigned int inl;
112 { 103 {
113 des_ofb64_encrypt( 104 des_ofb64_encrypt(in,out,inl,ctx->c.des_ks,
114 in,out, 105 (des_cblock *)&(ctx->iv[0]),&ctx->num);
115 (long)inl, ctx->c.des_ks,
116 (des_cblock *)&(ctx->iv[0]),
117 &ctx->num);
118 } 106 }
107#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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void idea_ofb_init_key();
73static void idea_ofb_cipher();
74#endif
75
76static EVP_CIPHER i_ofb_cipher= 70static EVP_CIPHER i_ofb_cipher=
77 { 71 {
78 NID_idea_ofb64, 72 NID_idea_ofb64,
@@ -86,16 +80,13 @@ static EVP_CIPHER i_ofb_cipher=
86 EVP_CIPHER_get_asn1_iv, 80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_idea_ofb() 83EVP_CIPHER *EVP_idea_ofb(void)
90 { 84 {
91 return(&i_ofb_cipher); 85 return(&i_ofb_cipher);
92 } 86 }
93 87
94static void idea_ofb_init_key(ctx,key,iv,enc) 88static void idea_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 ctx->num=0; 91 ctx->num=0;
101 92
@@ -106,11 +97,8 @@ int enc;
106 idea_set_encrypt_key(key,&(ctx->c.idea_ks)); 97 idea_set_encrypt_key(key,&(ctx->c.idea_ks));
107 } 98 }
108 99
109static void idea_ofb_cipher(ctx,out,in,inl) 100static void idea_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
110EVP_CIPHER_CTX *ctx; 101 unsigned char *in, unsigned int inl)
111unsigned char *out;
112unsigned char *in;
113unsigned int inl;
114 { 102 {
115 idea_ofb64_encrypt( 103 idea_ofb64_encrypt(
116 in,out,(long)inl, 104 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void rc2_ofb_init_key();
73static void rc2_ofb_cipher();
74#endif
75
76static EVP_CIPHER r2_ofb_cipher= 70static EVP_CIPHER r2_ofb_cipher=
77 { 71 {
78 NID_rc2_ofb64, 72 NID_rc2_ofb64,
@@ -86,16 +80,13 @@ static EVP_CIPHER r2_ofb_cipher=
86 EVP_CIPHER_get_asn1_iv, 80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_rc2_ofb() 83EVP_CIPHER *EVP_rc2_ofb(void)
90 { 84 {
91 return(&r2_ofb_cipher); 85 return(&r2_ofb_cipher);
92 } 86 }
93 87
94static void rc2_ofb_init_key(ctx,key,iv,enc) 88static void rc2_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 ctx->num=0; 91 ctx->num=0;
101 92
@@ -103,15 +94,12 @@ int enc;
103 memcpy(&(ctx->oiv[0]),iv,8); 94 memcpy(&(ctx->oiv[0]),iv,8);
104 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 95 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
105 if (key != NULL) 96 if (key != NULL)
106 RC2_set_key(&(ctx->c.rc2_ks),EVP_RC2_KEY_SIZE,key, 97 RC2_set_key(&(ctx->c.rc2_ks),EVP_CIPHER_CTX_key_length(ctx),
107 EVP_RC2_KEY_SIZE*8); 98 key,EVP_CIPHER_CTX_key_length(ctx)*8);
108 } 99 }
109 100
110static void rc2_ofb_cipher(ctx,out,in,inl) 101static void rc2_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
111EVP_CIPHER_CTX *ctx; 102 unsigned char *in, unsigned int inl)
112unsigned char *out;
113unsigned char *in;
114unsigned int inl;
115 { 103 {
116 RC2_ofb64_encrypt( 104 RC2_ofb64_encrypt(
117 in,out, 105 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void rc5_32_12_16_ofb_init_key();
73static void rc5_32_12_16_ofb_cipher();
74#endif
75
76static EVP_CIPHER rc5_ofb_cipher= 70static EVP_CIPHER rc5_ofb_cipher=
77 { 71 {
78 NID_rc5_ofb64, 72 NID_rc5_ofb64,
@@ -86,16 +80,13 @@ static EVP_CIPHER rc5_ofb_cipher=
86 EVP_CIPHER_get_asn1_iv, 80 EVP_CIPHER_get_asn1_iv,
87 }; 81 };
88 82
89EVP_CIPHER *EVP_rc5_32_12_16_ofb() 83EVP_CIPHER *EVP_rc5_32_12_16_ofb(void)
90 { 84 {
91 return(&rc5_ofb_cipher); 85 return(&rc5_ofb_cipher);
92 } 86 }
93 87
94static void rc5_32_12_16_ofb_init_key(ctx,key,iv,enc) 88static void rc5_32_12_16_ofb_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
95EVP_CIPHER_CTX *ctx; 89 unsigned char *iv, int enc)
96unsigned char *key;
97unsigned char *iv;
98int enc;
99 { 90 {
100 ctx->num=0; 91 ctx->num=0;
101 92
@@ -107,11 +98,8 @@ int enc;
107 RC5_12_ROUNDS); 98 RC5_12_ROUNDS);
108 } 99 }
109 100
110static void rc5_32_12_16_ofb_cipher(ctx,out,in,inl) 101static void rc5_32_12_16_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
111EVP_CIPHER_CTX *ctx; 102 unsigned char *in, unsigned int inl)
112unsigned char *out;
113unsigned char *in;
114unsigned int inl;
115 { 103 {
116 RC5_32_ofb64_encrypt( 104 RC5_32_ofb64_encrypt(
117 in,out, 105 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 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "evp.h" 63#include <openssl/evp.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66#ifndef NOPROTO
67static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 66static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
68 unsigned char *iv,int enc); 67 unsigned char *iv,int enc);
69static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 68static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
70 unsigned char *in, unsigned int inl); 69 unsigned char *in, unsigned int inl);
71#else
72static void rc4_init_key();
73static void rc4_cipher();
74#endif
75
76static EVP_CIPHER r4_cipher= 70static EVP_CIPHER r4_cipher=
77 { 71 {
78 NID_rc4, 72 NID_rc4,
@@ -94,21 +88,18 @@ static EVP_CIPHER r4_40_cipher=
94 rc4_cipher, 88 rc4_cipher,
95 }; 89 };
96 90
97EVP_CIPHER *EVP_rc4() 91EVP_CIPHER *EVP_rc4(void)
98 { 92 {
99 return(&r4_cipher); 93 return(&r4_cipher);
100 } 94 }
101 95
102EVP_CIPHER *EVP_rc4_40() 96EVP_CIPHER *EVP_rc4_40(void)
103 { 97 {
104 return(&r4_40_cipher); 98 return(&r4_40_cipher);
105 } 99 }
106 100
107static void rc4_init_key(ctx,key,iv,enc) 101static void rc4_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
108EVP_CIPHER_CTX *ctx; 102 unsigned char *iv, int enc)
109unsigned char *key;
110unsigned char *iv;
111int enc;
112 { 103 {
113 if (key != NULL) 104 if (key != NULL)
114 memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx)); 105 memcpy(&(ctx->c.rc4.key[0]),key,EVP_CIPHER_CTX_key_length(ctx));
@@ -116,11 +107,8 @@ int enc;
116 ctx->c.rc4.key); 107 ctx->c.rc4.key);
117 } 108 }
118 109
119static void rc4_cipher(ctx,out,in,inl) 110static void rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
120EVP_CIPHER_CTX *ctx; 111 unsigned char *in, unsigned int inl)
121unsigned char *out;
122unsigned char *in;
123unsigned int inl;
124 { 112 {
125 RC4(&(ctx->c.rc4.ks),inl,in,out); 113 RC4(&(ctx->c.rc4.ks),inl,in,out);
126 } 114 }
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63 64
64#ifndef NOPROTO
65static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key, 65static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
66 unsigned char *iv,int enc); 66 unsigned char *iv,int enc);
67static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, 67static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
68 unsigned char *in, unsigned int inl); 68 unsigned char *in, unsigned int inl);
69#else
70static void desx_cbc_init_key();
71static void desx_cbc_cipher();
72#endif
73
74static EVP_CIPHER d_xcbc_cipher= 69static EVP_CIPHER d_xcbc_cipher=
75 { 70 {
76 NID_desx_cbc, 71 NID_desx_cbc,
@@ -84,39 +79,34 @@ static EVP_CIPHER d_xcbc_cipher=
84 EVP_CIPHER_get_asn1_iv, 79 EVP_CIPHER_get_asn1_iv,
85 }; 80 };
86 81
87EVP_CIPHER *EVP_desx_cbc() 82EVP_CIPHER *EVP_desx_cbc(void)
88 { 83 {
89 return(&d_xcbc_cipher); 84 return(&d_xcbc_cipher);
90 } 85 }
91 86
92static void desx_cbc_init_key(ctx,key,iv,enc) 87static void desx_cbc_init_key(EVP_CIPHER_CTX *ctx, unsigned char *key,
93EVP_CIPHER_CTX *ctx; 88 unsigned char *iv, int enc)
94unsigned char *key;
95unsigned char *iv;
96int enc;
97 { 89 {
90 des_cblock *deskey = (des_cblock *)key;
91
98 if (iv != NULL) 92 if (iv != NULL)
99 memcpy(&(ctx->oiv[0]),iv,8); 93 memcpy(&(ctx->oiv[0]),iv,8);
100 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8); 94 memcpy(&(ctx->iv[0]),&(ctx->oiv[0]),8);
101 if (key != NULL) 95 if (deskey != NULL)
102 { 96 {
103 des_set_key((des_cblock *)key,ctx->c.desx_cbc.ks); 97 des_set_key(deskey,ctx->c.desx_cbc.ks);
104 memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8); 98 memcpy(&(ctx->c.desx_cbc.inw[0]),&(key[8]),8);
105 memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8); 99 memcpy(&(ctx->c.desx_cbc.outw[0]),&(key[16]),8);
106 } 100 }
107 } 101 }
108 102
109static void desx_cbc_cipher(ctx,out,in,inl) 103static void desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
110EVP_CIPHER_CTX *ctx; 104 unsigned char *in, unsigned int inl)
111unsigned char *out;
112unsigned char *in;
113unsigned int inl;
114 { 105 {
115 des_xcbc_encrypt( 106 des_xcbc_encrypt(in,out,inl,ctx->c.desx_cbc.ks,
116 (des_cblock *)in,(des_cblock *)out,
117 (long)inl, ctx->c.desx_cbc.ks,
118 (des_cblock *)&(ctx->iv[0]), 107 (des_cblock *)&(ctx->iv[0]),
119 (des_cblock *)&(ctx->c.desx_cbc.inw[0]), 108 &ctx->c.desx_cbc.inw,
120 (des_cblock *)&(ctx->c.desx_cbc.outw[0]), 109 &ctx->c.desx_cbc.outw,
121 ctx->encrypt); 110 ctx->encrypt);
122 } 111 }
112#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62 62
63#ifndef CHARSET_EBCDIC
63#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f]) 64#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
64#define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f]) 65#define conv_ascii2bin(a) (data_ascii2bin[(a)&0x7f])
66#else
67/* We assume that PEM encoded files are EBCDIC files
68 * (i.e., printable text files). Convert them here while decoding.
69 * When encoding, output is EBCDIC (text) format again.
70 * (No need for conversion in the conv_bin2ascii macro, as the
71 * underlying textstring data_bin2ascii[] is already EBCDIC)
72 */
73#define conv_bin2ascii(a) (data_bin2ascii[(a)&0x3f])
74#define conv_ascii2bin(a) (data_ascii2bin[os_toascii[a]&0x7f])
75#endif
65 76
66/* 64 char lines 77/* 64 char lines
67 * pad input with 0 78 * pad input with 0
@@ -110,20 +121,15 @@ static unsigned char data_ascii2bin[128]={
110 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF, 121 0x31,0x32,0x33,0xFF,0xFF,0xFF,0xFF,0xFF,
111 }; 122 };
112 123
113void EVP_EncodeInit(ctx) 124void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
114EVP_ENCODE_CTX *ctx;
115 { 125 {
116 ctx->length=48; 126 ctx->length=48;
117 ctx->num=0; 127 ctx->num=0;
118 ctx->line_num=0; 128 ctx->line_num=0;
119 } 129 }
120 130
121void EVP_EncodeUpdate(ctx,out,outl,in,inl) 131void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
122EVP_ENCODE_CTX *ctx; 132 unsigned char *in, int inl)
123unsigned char *out;
124int *outl;
125unsigned char *in;
126int inl;
127 { 133 {
128 int i,j; 134 int i,j;
129 unsigned int total=0; 135 unsigned int total=0;
@@ -165,10 +171,7 @@ int inl;
165 *outl=total; 171 *outl=total;
166 } 172 }
167 173
168void EVP_EncodeFinal(ctx,out,outl) 174void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
169EVP_ENCODE_CTX *ctx;
170unsigned char *out;
171int *outl;
172 { 175 {
173 unsigned int ret=0; 176 unsigned int ret=0;
174 177
@@ -182,9 +185,7 @@ int *outl;
182 *outl=ret; 185 *outl=ret;
183 } 186 }
184 187
185int EVP_EncodeBlock(t,f,dlen) 188int EVP_EncodeBlock(unsigned char *t, unsigned char *f, int dlen)
186unsigned char *t,*f;
187int dlen;
188 { 189 {
189 int i,ret=0; 190 int i,ret=0;
190 unsigned long l; 191 unsigned long l;
@@ -218,8 +219,7 @@ int dlen;
218 return(ret); 219 return(ret);
219 } 220 }
220 221
221void EVP_DecodeInit(ctx) 222void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
222EVP_ENCODE_CTX *ctx;
223 { 223 {
224 ctx->length=30; 224 ctx->length=30;
225 ctx->num=0; 225 ctx->num=0;
@@ -231,12 +231,8 @@ EVP_ENCODE_CTX *ctx;
231 * 0 for last line 231 * 0 for last line
232 * 1 for full line 232 * 1 for full line
233 */ 233 */
234int EVP_DecodeUpdate(ctx,out,outl,in,inl) 234int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
235EVP_ENCODE_CTX *ctx; 235 unsigned char *in, int inl)
236unsigned char *out;
237int *outl;
238unsigned char *in;
239int inl;
240 { 236 {
241 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; 237 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
242 unsigned char *d; 238 unsigned char *d;
@@ -341,9 +337,7 @@ end:
341 return(rv); 337 return(rv);
342 } 338 }
343 339
344int EVP_DecodeBlock(t,f,n) 340int EVP_DecodeBlock(unsigned char *t, unsigned char *f, int n)
345unsigned char *t,*f;
346int n;
347 { 341 {
348 int i,ret=0,a,b,c,d; 342 int i,ret=0,a,b,c,d;
349 unsigned long l; 343 unsigned long l;
@@ -383,10 +377,7 @@ int n;
383 return(ret); 377 return(ret);
384 } 378 }
385 379
386int EVP_DecodeFinal(ctx,out,outl) 380int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
387EVP_ENCODE_CTX *ctx;
388unsigned char *out;
389int *outl;
390 { 381 {
391 int i; 382 int i;
392 383
@@ -404,9 +395,7 @@ int *outl;
404 } 395 }
405 396
406#ifdef undef 397#ifdef undef
407int EVP_DecodeValid(buf,len) 398int EVP_DecodeValid(unsigned char *buf, int len)
408unsigned char *buf;
409int len;
410 { 399 {
411 int i,num=0,bad=0; 400 int i,num=0,bad=0;
412 401
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 @@
1/* Error codes for the EVP functions. */
2
3/* Function codes. */
4#define EVP_F_D2I_PKEY 100
5#define EVP_F_EVP_DECRYPTFINAL 101
6#define EVP_F_EVP_OPENINIT 102
7#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
8#define EVP_F_EVP_PKEY_DECRYPT 104
9#define EVP_F_EVP_PKEY_ENCRYPT 105
10#define EVP_F_EVP_PKEY_NEW 106
11#define EVP_F_EVP_SIGNFINAL 107
12#define EVP_F_EVP_VERIFYFINAL 108
13
14/* Reason codes. */
15#define EVP_R_BAD_DECRYPT 100
16#define EVP_R_DIFFERENT_KEY_TYPES 101
17#define EVP_R_IV_TOO_LARGE 102
18#define EVP_R_MISSING_PARMATERS 103
19#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
20#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
21#define EVP_R_PUBLIC_KEY_NOT_RSA 106
22#define EVP_R_UNSUPPORTED_CIPHER 107
23#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108
24#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" {
64#endif 64#endif
65 65
66#ifndef NO_MD2 66#ifndef NO_MD2
67#include "md2.h" 67#include <openssl/md2.h>
68#endif 68#endif
69#ifndef NO_MD5 69#ifndef NO_MD5
70#include "md5.h" 70#include <openssl/md5.h>
71#endif 71#endif
72#if !defined(NO_SHA) || !defined(NO_SHA1) 72#ifndef NO_SHA
73#include "sha.h" 73#include <openssl/sha.h>
74#endif 74#endif
75#ifndef NO_RIPEMD 75#ifndef NO_RIPEMD
76#include "ripemd.h" 76#include <openssl/ripemd.h>
77#endif 77#endif
78#ifndef NO_DES 78#ifndef NO_DES
79#include "des.h" 79#include <openssl/des.h>
80#endif 80#endif
81#ifndef NO_RC4 81#ifndef NO_RC4
82#include "rc4.h" 82#include <openssl/rc4.h>
83#endif 83#endif
84#ifndef NO_RC2 84#ifndef NO_RC2
85#include "rc2.h" 85#include <openssl/rc2.h>
86#endif 86#endif
87#ifndef NO_RC5 87#ifndef NO_RC5
88#include "rc5.h" 88#include <openssl/rc5.h>
89#endif 89#endif
90#ifndef NO_BLOWFISH 90#ifndef NO_BF
91#include "blowfish.h" 91#include <openssl/blowfish.h>
92#endif 92#endif
93#ifndef NO_CAST 93#ifndef NO_CAST
94#include "cast.h" 94#include <openssl/cast.h>
95#endif 95#endif
96#ifndef NO_IDEA 96#ifndef NO_IDEA
97#include "idea.h" 97#include <openssl/idea.h>
98#endif 98#endif
99#ifndef NO_MDC2 99#ifndef NO_MDC2
100#include "mdc2.h" 100#include <openssl/mdc2.h>
101#endif 101#endif
102 102
103#define EVP_RC2_KEY_SIZE 16 103#define EVP_RC2_KEY_SIZE 16
@@ -109,25 +109,23 @@ extern "C" {
109#define EVP_MAX_KEY_LENGTH 24 109#define EVP_MAX_KEY_LENGTH 24
110#define EVP_MAX_IV_LENGTH 8 110#define EVP_MAX_IV_LENGTH 8
111 111
112#define PKCS5_SALT_LEN 8
113/* Default PKCS#5 iteration count */
114#define PKCS5_DEFAULT_ITER 2048
115
112#ifndef NO_RSA 116#ifndef NO_RSA
113#include "rsa.h" 117#include <openssl/rsa.h>
114#else
115#define RSA long
116#endif 118#endif
117 119
118#ifndef NO_DSA 120#ifndef NO_DSA
119#include "dsa.h" 121#include <openssl/dsa.h>
120#else
121#define DSA long
122#endif 122#endif
123 123
124#ifndef NO_DH 124#ifndef NO_DH
125#include "dh.h" 125#include <openssl/dh.h>
126#else
127#define DH long
128#endif 126#endif
129 127
130#include "objects.h" 128#include <openssl/objects.h>
131 129
132#define EVP_PK_RSA 0x0001 130#define EVP_PK_RSA 0x0001
133#define EVP_PK_DSA 0x0002 131#define EVP_PK_DSA 0x0002
@@ -159,16 +157,18 @@ typedef struct evp_pkey_st
159 int references; 157 int references;
160 union { 158 union {
161 char *ptr; 159 char *ptr;
160#ifndef NO_RSA
162 struct rsa_st *rsa; /* RSA */ 161 struct rsa_st *rsa; /* RSA */
162#endif
163#ifndef NO_DSA
163 struct dsa_st *dsa; /* DSA */ 164 struct dsa_st *dsa; /* DSA */
165#endif
166#ifndef NO_DH
164 struct dh_st *dh; /* DH */ 167 struct dh_st *dh; /* DH */
168#endif
165 } pkey; 169 } pkey;
166 int save_parameters; 170 int save_parameters;
167#ifdef HEADER_STACK_H 171 STACK /*X509_ATTRIBUTE*/ *attributes; /* [ 0 ] */
168 STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */
169#else
170 char /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */
171#endif
172 } EVP_PKEY; 172 } EVP_PKEY;
173 173
174#define EVP_PKEY_MO_SIGN 0x0001 174#define EVP_PKEY_MO_SIGN 0x0001
@@ -183,7 +183,7 @@ typedef struct evp_pkey_st
183 * This is required because for various smart-card perform the digest and 183 * This is required because for various smart-card perform the digest and
184 * signing/verification on-board. To handle this case, the specific 184 * signing/verification on-board. To handle this case, the specific
185 * EVP_MD and EVP_PKEY_METHODs need to be closely associated. 185 * EVP_MD and EVP_PKEY_METHODs need to be closely associated.
186 * When a PKEY is created, it will have a EVP_PKEY_METHOD ossociated with it. 186 * When a PKEY is created, it will have a EVP_PKEY_METHOD associated with it.
187 * This can either be software or a token to provide the required low level 187 * This can either be software or a token to provide the required low level
188 * routines. 188 * routines.
189 */ 189 */
@@ -194,28 +194,28 @@ typedef struct evp_pkey_md_st
194 EVP_PKEY_METHOD *pkey; 194 EVP_PKEY_METHOD *pkey;
195 } EVP_PKEY_MD; 195 } EVP_PKEY_MD;
196 196
197#define EVP_rsa_md2() 197#define EVP_rsa_md2() \
198 EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\ 198 EVP_PKEY_MD_add(NID_md2WithRSAEncryption,\
199 EVP_rsa_pkcs1(),EVP_md2()) 199 EVP_rsa_pkcs1(),EVP_md2())
200#define EVP_rsa_md5() 200#define EVP_rsa_md5() \
201 EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\ 201 EVP_PKEY_MD_add(NID_md5WithRSAEncryption,\
202 EVP_rsa_pkcs1(),EVP_md5()) 202 EVP_rsa_pkcs1(),EVP_md5())
203#define EVP_rsa_sha0() 203#define EVP_rsa_sha0() \
204 EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\ 204 EVP_PKEY_MD_add(NID_shaWithRSAEncryption,\
205 EVP_rsa_pkcs1(),EVP_sha()) 205 EVP_rsa_pkcs1(),EVP_sha())
206#define EVP_rsa_sha1() 206#define EVP_rsa_sha1() \
207 EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\ 207 EVP_PKEY_MD_add(NID_sha1WithRSAEncryption,\
208 EVP_rsa_pkcs1(),EVP_sha1()) 208 EVP_rsa_pkcs1(),EVP_sha1())
209#define EVP_rsa_ripemd160() 209#define EVP_rsa_ripemd160() \
210 EVP_PKEY_MD_add(NID_ripemd160WithRSA,\ 210 EVP_PKEY_MD_add(NID_ripemd160WithRSA,\
211 EVP_rsa_pkcs1(),EVP_ripemd160()) 211 EVP_rsa_pkcs1(),EVP_ripemd160())
212#define EVP_rsa_mdc2() 212#define EVP_rsa_mdc2() \
213 EVP_PKEY_MD_add(NID_mdc2WithRSA,\ 213 EVP_PKEY_MD_add(NID_mdc2WithRSA,\
214 EVP_rsa_octet_string(),EVP_mdc2()) 214 EVP_rsa_octet_string(),EVP_mdc2())
215#define EVP_dsa_sha() 215#define EVP_dsa_sha() \
216 EVP_PKEY_MD_add(NID_dsaWithSHA,\ 216 EVP_PKEY_MD_add(NID_dsaWithSHA,\
217 EVP_dsa(),EVP_mdc2()) 217 EVP_dsa(),EVP_mdc2())
218#define EVP_dsa_sha1() 218#define EVP_dsa_sha1() \
219 EVP_PKEY_MD_add(NID_dsaWithSHA1,\ 219 EVP_PKEY_MD_add(NID_dsaWithSHA1,\
220 EVP_dsa(),EVP_sha1()) 220 EVP_dsa(),EVP_sha1())
221 221
@@ -261,6 +261,8 @@ typedef struct env_md_st
261 int ctx_size; /* how big does the ctx need to be */ 261 int ctx_size; /* how big does the ctx need to be */
262 } EVP_MD; 262 } EVP_MD;
263 263
264
265
264#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} 266#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
265 267
266#ifndef NO_DSA 268#ifndef NO_DSA
@@ -287,7 +289,7 @@ typedef struct env_md_st
287 289
288typedef struct env_md_ctx_st 290typedef struct env_md_ctx_st
289 { 291 {
290 EVP_MD *digest; 292 const EVP_MD *digest;
291 union { 293 union {
292 unsigned char base[4]; 294 unsigned char base[4];
293#ifndef NO_MD2 295#ifndef NO_MD2
@@ -296,10 +298,10 @@ typedef struct env_md_ctx_st
296#ifndef NO_MD5 298#ifndef NO_MD5
297 MD5_CTX md5; 299 MD5_CTX md5;
298#endif 300#endif
299#ifndef NO_MD5 301#ifndef NO_RIPEMD
300 RIPEMD160_CTX ripemd160; 302 RIPEMD160_CTX ripemd160;
301#endif 303#endif
302#if !defined(NO_SHA) || !defined(NO_SHA1) 304#ifndef NO_SHA
303 SHA_CTX sha; 305 SHA_CTX sha;
304#endif 306#endif
305#ifndef NO_MDC2 307#ifndef NO_MDC2
@@ -326,13 +328,13 @@ typedef struct evp_cipher_st
326 328
327typedef struct evp_cipher_info_st 329typedef struct evp_cipher_info_st
328 { 330 {
329 EVP_CIPHER *cipher; 331 const EVP_CIPHER *cipher;
330 unsigned char iv[EVP_MAX_IV_LENGTH]; 332 unsigned char iv[EVP_MAX_IV_LENGTH];
331 } EVP_CIPHER_INFO; 333 } EVP_CIPHER_INFO;
332 334
333typedef struct evp_cipher_ctx_st 335typedef struct evp_cipher_ctx_st
334 { 336 {
335 EVP_CIPHER *cipher; 337 const EVP_CIPHER *cipher;
336 int encrypt; /* encrypt or decrypt */ 338 int encrypt; /* encrypt or decrypt */
337 int buf_len; /* number we have left */ 339 int buf_len; /* number we have left */
338 340
@@ -355,8 +357,8 @@ typedef struct evp_cipher_ctx_st
355 struct 357 struct
356 { 358 {
357 des_key_schedule ks;/* key schedule */ 359 des_key_schedule ks;/* key schedule */
358 C_Block inw; 360 des_cblock inw;
359 C_Block outw; 361 des_cblock outw;
360 } desx_cbc; 362 } desx_cbc;
361 struct 363 struct
362 { 364 {
@@ -374,7 +376,7 @@ typedef struct evp_cipher_ctx_st
374#ifndef NO_RC5 376#ifndef NO_RC5
375 RC5_32_KEY rc5_ks;/* key schedule */ 377 RC5_32_KEY rc5_ks;/* key schedule */
376#endif 378#endif
377#ifndef NO_BLOWFISH 379#ifndef NO_BF
378 BF_KEY bf_ks;/* key schedule */ 380 BF_KEY bf_ks;/* key schedule */
379#endif 381#endif
380#ifndef NO_CAST 382#ifndef NO_CAST
@@ -396,6 +398,11 @@ typedef struct evp_Encode_Ctx_st
396 int expect_nl; 398 int expect_nl;
397 } EVP_ENCODE_CTX; 399 } EVP_ENCODE_CTX;
398 400
401/* Password based encryption function */
402typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
403 ASN1_TYPE *param, EVP_CIPHER *cipher,
404 EVP_MD *md, int en_de);
405
399#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ 406#define EVP_PKEY_assign_RSA(pkey,rsa) EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
400 (char *)(rsa)) 407 (char *)(rsa))
401#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\ 408#define EVP_PKEY_assign_DSA(pkey,dsa) EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\
@@ -430,6 +437,7 @@ typedef struct evp_Encode_Ctx_st
430#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len) 437#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
431#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) 438#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
432#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d)) 439#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
440#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
433 441
434#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) 442#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
435#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) 443#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
@@ -441,43 +449,56 @@ typedef struct evp_Encode_Ctx_st
441#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e) 449#define EVP_OpenUpdate(a,b,c,d,e) EVP_DecryptUpdate(a,b,c,d,e)
442#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e) 450#define EVP_SealUpdate(a,b,c,d,e) EVP_EncryptUpdate(a,b,c,d,e)
443 451
444#define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md) 452#ifdef CONST_STRICT
453void BIO_set_md(BIO *,const EVP_MD *md);
454#else
455# define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,0,(char *)md)
456#endif
445#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp) 457#define BIO_get_md(b,mdp) BIO_ctrl(b,BIO_C_GET_MD,0,(char *)mdp)
446#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp) 458#define BIO_get_md_ctx(b,mdcp) BIO_ctrl(b,BIO_C_GET_MD_CTX,0,(char *)mdcp)
447#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) 459#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
460#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
448 461
449#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l)) 462#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
450 463
451#ifndef NOPROTO 464#define EVP_add_cipher_alias(n,alias) \
465 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
466#define EVP_add_digest_alias(n,alias) \
467 OBJ_NAME_add((alias),OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,(n))
468#define EVP_delete_cipher_alias(alias) \
469 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS);
470#define EVP_delete_digest_alias(alias) \
471 OBJ_NAME_remove(alias,OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS);
452 472
453void EVP_DigestInit(EVP_MD_CTX *ctx, EVP_MD *type); 473
454void EVP_DigestUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt); 474int EVP_MD_CTX_copy(EVP_MD_CTX *out,EVP_MD_CTX *in);
475void EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
476void EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
477 unsigned int cnt);
455void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); 478void EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
456 479
457int EVP_read_pw_string(char *buf,int length,char *prompt,int verify); 480int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
458void EVP_set_pw_prompt(char *prompt); 481void EVP_set_pw_prompt(char *prompt);
459char * EVP_get_pw_prompt(void); 482char * EVP_get_pw_prompt(void);
460 483
461int EVP_BytesToKey(EVP_CIPHER *type,EVP_MD *md,unsigned char *salt, 484int EVP_BytesToKey(const EVP_CIPHER *type,EVP_MD *md,unsigned char *salt,
462 unsigned char *data, int datal, int count, 485 unsigned char *data, int datal, int count,
463 unsigned char *key,unsigned char *iv); 486 unsigned char *key,unsigned char *iv);
464 487
465EVP_CIPHER *EVP_get_cipherbyname(char *name); 488void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
466
467void EVP_EncryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type,
468 unsigned char *key, unsigned char *iv); 489 unsigned char *key, unsigned char *iv);
469void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, 490void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
470 int *outl, unsigned char *in, int inl); 491 int *outl, unsigned char *in, int inl);
471void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); 492void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
472 493
473void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, 494void EVP_DecryptInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
474 unsigned char *key, unsigned char *iv); 495 unsigned char *key, unsigned char *iv);
475void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, 496void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
476 int *outl, unsigned char *in, int inl); 497 int *outl, unsigned char *in, int inl);
477int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); 498int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
478 499
479void EVP_CipherInit(EVP_CIPHER_CTX *ctx,EVP_CIPHER *type, unsigned char *key, 500void EVP_CipherInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,
480 unsigned char *iv,int enc); 501 unsigned char *key,unsigned char *iv,int enc);
481void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, 502void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
482 int *outl, unsigned char *in, int inl); 503 int *outl, unsigned char *in, int inl);
483int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl); 504int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
@@ -519,7 +540,8 @@ void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
519BIO_METHOD *BIO_f_md(void); 540BIO_METHOD *BIO_f_md(void);
520BIO_METHOD *BIO_f_base64(void); 541BIO_METHOD *BIO_f_base64(void);
521BIO_METHOD *BIO_f_cipher(void); 542BIO_METHOD *BIO_f_cipher(void);
522void BIO_set_cipher(BIO *b,EVP_CIPHER *c,unsigned char *k, 543BIO_METHOD *BIO_f_reliable(void);
544void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k,
523 unsigned char *i, int enc); 545 unsigned char *i, int enc);
524#endif 546#endif
525 547
@@ -556,6 +578,7 @@ EVP_CIPHER *EVP_idea_cbc(void);
556EVP_CIPHER *EVP_rc2_ecb(void); 578EVP_CIPHER *EVP_rc2_ecb(void);
557EVP_CIPHER *EVP_rc2_cbc(void); 579EVP_CIPHER *EVP_rc2_cbc(void);
558EVP_CIPHER *EVP_rc2_40_cbc(void); 580EVP_CIPHER *EVP_rc2_40_cbc(void);
581EVP_CIPHER *EVP_rc2_64_cbc(void);
559EVP_CIPHER *EVP_rc2_cfb(void); 582EVP_CIPHER *EVP_rc2_cfb(void);
560EVP_CIPHER *EVP_rc2_ofb(void); 583EVP_CIPHER *EVP_rc2_ofb(void);
561EVP_CIPHER *EVP_bf_ecb(void); 584EVP_CIPHER *EVP_bf_ecb(void);
@@ -577,11 +600,9 @@ void SSLeay_add_all_digests(void);
577 600
578int EVP_add_cipher(EVP_CIPHER *cipher); 601int EVP_add_cipher(EVP_CIPHER *cipher);
579int EVP_add_digest(EVP_MD *digest); 602int EVP_add_digest(EVP_MD *digest);
580int EVP_add_alias(char *name,char *alias);
581int EVP_delete_alias(char *name);
582 603
583EVP_CIPHER *EVP_get_cipherbyname(char *name); 604const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
584EVP_MD *EVP_get_digestbyname(char *name); 605const EVP_MD *EVP_get_digestbyname(const char *name);
585void EVP_cleanup(void); 606void EVP_cleanup(void);
586 607
587int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key, 608int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
@@ -607,6 +628,8 @@ int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
607int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode); 628int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
608int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b); 629int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
609 630
631int EVP_CIPHER_type(const EVP_CIPHER *ctx);
632
610/* calls methods */ 633/* calls methods */
611int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type); 634int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
612int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type); 635int 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);
615int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); 638int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
616int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type); 639int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c,ASN1_TYPE *type);
617 640
618#else 641/* PKCS5 password based encryption */
619 642int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
620void EVP_DigestInit(); 643 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
621void EVP_DigestUpdate(); 644 int en_de);
622void EVP_DigestFinal(); 645int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
623 646 unsigned char *salt, int saltlen, int iter,
624int EVP_read_pw_string(); 647 int keylen, unsigned char *out);
625void EVP_set_pw_prompt(); 648int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
626char * EVP_get_pw_prompt(); 649 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
627 650 int en_de);
628int EVP_BytesToKey(); 651
629 652void PKCS5_PBE_add(void);
630EVP_CIPHER *EVP_get_cipherbyname(); 653
631 654int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
632void EVP_EncryptInit(); 655 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de);
633void EVP_EncryptUpdate(); 656int EVP_PBE_alg_add(int nid, EVP_CIPHER *cipher, EVP_MD *md,
634void EVP_EncryptFinal(); 657 EVP_PBE_KEYGEN *keygen);
635 658void EVP_PBE_cleanup(void);
636void EVP_DecryptInit();
637void EVP_DecryptUpdate();
638int EVP_DecryptFinal();
639
640void EVP_CipherInit();
641void EVP_CipherUpdate();
642int EVP_CipherFinal();
643
644int EVP_SignFinal();
645
646int EVP_VerifyFinal();
647
648int EVP_OpenInit();
649int EVP_OpenFinal();
650
651int EVP_SealInit();
652void EVP_SealFinal();
653
654void EVP_EncodeInit();
655void EVP_EncodeUpdate();
656void EVP_EncodeFinal();
657int EVP_EncodeBlock();
658
659void EVP_DecodeInit();
660int EVP_DecodeUpdate();
661int EVP_DecodeFinal();
662int EVP_DecodeBlock();
663
664void ERR_load_EVP_strings();
665
666void EVP_CIPHER_CTX_init();
667void EVP_CIPHER_CTX_cleanup();
668
669#ifdef HEADER_BIO_H
670BIO_METHOD *BIO_f_md();
671BIO_METHOD *BIO_f_base64();
672BIO_METHOD *BIO_f_cipher();
673void BIO_set_cipher();
674#endif
675
676EVP_MD *EVP_md_null();
677EVP_MD *EVP_md2();
678EVP_MD *EVP_md5();
679EVP_MD *EVP_sha();
680EVP_MD *EVP_sha1();
681EVP_MD *EVP_dss();
682EVP_MD *EVP_dss1();
683EVP_MD *EVP_mdc2();
684
685EVP_CIPHER *EVP_enc_null();
686EVP_CIPHER *EVP_des_ecb();
687EVP_CIPHER *EVP_des_ede();
688EVP_CIPHER *EVP_des_ede3();
689EVP_CIPHER *EVP_des_cfb();
690EVP_CIPHER *EVP_des_ede_cfb();
691EVP_CIPHER *EVP_des_ede3_cfb();
692EVP_CIPHER *EVP_des_ofb();
693EVP_CIPHER *EVP_des_ede_ofb();
694EVP_CIPHER *EVP_des_ede3_ofb();
695EVP_CIPHER *EVP_des_cbc();
696EVP_CIPHER *EVP_des_ede_cbc();
697EVP_CIPHER *EVP_des_ede3_cbc();
698EVP_CIPHER *EVP_desx_cbc();
699EVP_CIPHER *EVP_rc4();
700EVP_CIPHER *EVP_rc4_40();
701EVP_CIPHER *EVP_idea_ecb();
702EVP_CIPHER *EVP_idea_cfb();
703EVP_CIPHER *EVP_idea_ofb();
704EVP_CIPHER *EVP_idea_cbc();
705EVP_CIPHER *EVP_rc2_ecb();
706EVP_CIPHER *EVP_rc2_cbc();
707EVP_CIPHER *EVP_rc2_40_cbc();
708EVP_CIPHER *EVP_rc2_cfb();
709EVP_CIPHER *EVP_rc2_ofb();
710EVP_CIPHER *EVP_bf_ecb();
711EVP_CIPHER *EVP_bf_cbc();
712EVP_CIPHER *EVP_bf_cfb();
713EVP_CIPHER *EVP_bf_ofb();
714EVP_CIPHER *EVP_cast5_ecb();
715EVP_CIPHER *EVP_cast5_cbc();
716EVP_CIPHER *EVP_cast5_cfb();
717EVP_CIPHER *EVP_cast5_ofb();
718EVP_CIPHER *EVP_rc5_32_12_16_cbc();
719EVP_CIPHER *EVP_rc5_32_12_16_ecb();
720EVP_CIPHER *EVP_rc5_32_12_16_cfb();
721EVP_CIPHER *EVP_rc5_32_12_16_ofb();
722
723void SSLeay_add_all_algorithms();
724void SSLeay_add_all_ciphers();
725void SSLeay_add_all_digests();
726
727int EVP_add_cipher();
728int EVP_add_digest();
729int EVP_add_alias();
730int EVP_delete_alias();
731
732EVP_CIPHER *EVP_get_cipherbyname();
733EVP_MD *EVP_get_digestbyname();
734void EVP_cleanup();
735
736int EVP_PKEY_decrypt();
737int EVP_PKEY_encrypt();
738int EVP_PKEY_type();
739int EVP_PKEY_bits();
740int EVP_PKEY_size();
741int EVP_PKEY_assign();
742EVP_PKEY * EVP_PKEY_new();
743void EVP_PKEY_free();
744EVP_PKEY * d2i_PublicKey();
745int i2d_PublicKey();
746
747EVP_PKEY * d2i_PrivateKey();
748int i2d_PrivateKey();
749
750int EVP_PKEY_copy_parameters();
751int EVP_PKEY_missing_parameters();
752int EVP_PKEY_save_parameters();
753int EVP_PKEY_cmp_parameters();
754
755int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
756int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type);
757
758int EVP_CIPHER_set_asn1_iv();
759int EVP_CIPHER_get_asn1_iv();
760
761#endif
762 659
763/* BEGIN ERROR CODES */ 660/* BEGIN ERROR CODES */
661/* The following lines are auto generated by the script mkerr.pl. Any changes
662 * made after this point may be overwritten when the script is next run.
663 */
664
764/* Error codes for the EVP functions. */ 665/* Error codes for the EVP functions. */
765 666
766/* Function codes. */ 667/* Function codes. */
767#define EVP_F_D2I_PKEY 100 668#define EVP_F_D2I_PKEY 100
768#define EVP_F_EVP_DECRYPTFINAL 101 669#define EVP_F_EVP_DECRYPTFINAL 101
670#define EVP_F_EVP_MD_CTX_COPY 110
769#define EVP_F_EVP_OPENINIT 102 671#define EVP_F_EVP_OPENINIT 102
672#define EVP_F_EVP_PBE_ALG_ADD 115
673#define EVP_F_EVP_PBE_CIPHERINIT 116
674#define EVP_F_EVP_PKCS82PKEY 111
675#define EVP_F_EVP_PKCS8_SET_BROKEN 112
676#define EVP_F_EVP_PKEY2PKCS8 113
770#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 677#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
771#define EVP_F_EVP_PKEY_DECRYPT 104 678#define EVP_F_EVP_PKEY_DECRYPT 104
772#define EVP_F_EVP_PKEY_ENCRYPT 105 679#define EVP_F_EVP_PKEY_ENCRYPT 105
773#define EVP_F_EVP_PKEY_NEW 106 680#define EVP_F_EVP_PKEY_NEW 106
774#define EVP_F_EVP_SIGNFINAL 107 681#define EVP_F_EVP_SIGNFINAL 107
775#define EVP_F_EVP_VERIFYFINAL 108 682#define EVP_F_EVP_VERIFYFINAL 108
683#define EVP_F_PKCS5_PBE_KEYIVGEN 117
684#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
685#define EVP_F_RC2_MAGIC_TO_METH 109
776 686
777/* Reason codes. */ 687/* Reason codes. */
778#define EVP_R_BAD_DECRYPT 100 688#define EVP_R_BAD_DECRYPT 100
689#define EVP_R_BN_DECODE_ERROR 112
690#define EVP_R_BN_PUBKEY_ERROR 113
691#define EVP_R_CIPHER_PARAMETER_ERROR 122
692#define EVP_R_DECODE_ERROR 114
779#define EVP_R_DIFFERENT_KEY_TYPES 101 693#define EVP_R_DIFFERENT_KEY_TYPES 101
694#define EVP_R_ENCODE_ERROR 115
695#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
696#define EVP_R_INPUT_NOT_INITIALIZED 111
780#define EVP_R_IV_TOO_LARGE 102 697#define EVP_R_IV_TOO_LARGE 102
698#define EVP_R_KEYGEN_FAILURE 120
781#define EVP_R_MISSING_PARMATERS 103 699#define EVP_R_MISSING_PARMATERS 103
700#define EVP_R_NO_DSA_PARAMETERS 116
782#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104 701#define EVP_R_NO_SIGN_FUNCTION_CONFIGURED 104
783#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105 702#define EVP_R_NO_VERIFY_FUNCTION_CONFIGURED 105
703#define EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE 117
784#define EVP_R_PUBLIC_KEY_NOT_RSA 106 704#define EVP_R_PUBLIC_KEY_NOT_RSA 106
705#define EVP_R_UNKNOWN_PBE_ALGORITHM 121
785#define EVP_R_UNSUPPORTED_CIPHER 107 706#define EVP_R_UNSUPPORTED_CIPHER 107
786#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 108 707#define EVP_R_UNSUPPORTED_KEYLENGTH 123
787#define EVP_R_WRONG_PUBLIC_KEY_TYPE 109 708#define EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION 124
788 709#define EVP_R_UNSUPPORTED_KEY_SIZE 108
710#define EVP_R_UNSUPPORTED_PRF 125
711#define EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM 118
712#define EVP_R_UNSUPPORTED_SALT_TYPE 126
713#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
714#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
715
789#ifdef __cplusplus 716#ifdef __cplusplus
790} 717}
791#endif 718#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62 62
63char *EVP_version="EVP part of SSLeay 0.9.0b 29-Jun-1998"; 63const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
64 64
65void EVP_CIPHER_CTX_init(ctx) 65void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
66EVP_CIPHER_CTX *ctx;
67 { 66 {
68 memset(ctx,0,sizeof(EVP_CIPHER_CTX)); 67 memset(ctx,0,sizeof(EVP_CIPHER_CTX));
69 /* ctx->cipher=NULL; */ 68 /* ctx->cipher=NULL; */
70 } 69 }
71 70
72void EVP_CipherInit(ctx,data,key,iv,enc) 71void EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *data,
73EVP_CIPHER_CTX *ctx; 72 unsigned char *key, unsigned char *iv, int enc)
74EVP_CIPHER *data;
75unsigned char *key;
76unsigned char *iv;
77int enc;
78 { 73 {
79 if (enc) 74 if (enc)
80 EVP_EncryptInit(ctx,data,key,iv); 75 EVP_EncryptInit(ctx,data,key,iv);
@@ -82,22 +77,15 @@ int enc;
82 EVP_DecryptInit(ctx,data,key,iv); 77 EVP_DecryptInit(ctx,data,key,iv);
83 } 78 }
84 79
85void EVP_CipherUpdate(ctx,out,outl,in,inl) 80void EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
86EVP_CIPHER_CTX *ctx; 81 unsigned char *in, int inl)
87unsigned char *out;
88int *outl;
89unsigned char *in;
90int inl;
91 { 82 {
92 if (ctx->encrypt) 83 if (ctx->encrypt)
93 EVP_EncryptUpdate(ctx,out,outl,in,inl); 84 EVP_EncryptUpdate(ctx,out,outl,in,inl);
94 else EVP_DecryptUpdate(ctx,out,outl,in,inl); 85 else EVP_DecryptUpdate(ctx,out,outl,in,inl);
95 } 86 }
96 87
97int EVP_CipherFinal(ctx,out,outl) 88int EVP_CipherFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
98EVP_CIPHER_CTX *ctx;
99unsigned char *out;
100int *outl;
101 { 89 {
102 if (ctx->encrypt) 90 if (ctx->encrypt)
103 { 91 {
@@ -107,11 +95,8 @@ int *outl;
107 else return(EVP_DecryptFinal(ctx,out,outl)); 95 else return(EVP_DecryptFinal(ctx,out,outl));
108 } 96 }
109 97
110void EVP_EncryptInit(ctx,cipher,key,iv) 98void EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
111EVP_CIPHER_CTX *ctx; 99 unsigned char *key, unsigned char *iv)
112EVP_CIPHER *cipher;
113unsigned char *key;
114unsigned char *iv;
115 { 100 {
116 if (cipher != NULL) 101 if (cipher != NULL)
117 ctx->cipher=cipher; 102 ctx->cipher=cipher;
@@ -120,11 +105,8 @@ unsigned char *iv;
120 ctx->buf_len=0; 105 ctx->buf_len=0;
121 } 106 }
122 107
123void EVP_DecryptInit(ctx,cipher,key,iv) 108void EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
124EVP_CIPHER_CTX *ctx; 109 unsigned char *key, unsigned char *iv)
125EVP_CIPHER *cipher;
126unsigned char *key;
127unsigned char *iv;
128 { 110 {
129 if (cipher != NULL) 111 if (cipher != NULL)
130 ctx->cipher=cipher; 112 ctx->cipher=cipher;
@@ -134,12 +116,8 @@ unsigned char *iv;
134 } 116 }
135 117
136 118
137void EVP_EncryptUpdate(ctx,out,outl,in,inl) 119void EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
138EVP_CIPHER_CTX *ctx; 120 unsigned char *in, int inl)
139unsigned char *out;
140int *outl;
141unsigned char *in;
142int inl;
143 { 121 {
144 int i,j,bl; 122 int i,j,bl;
145 123
@@ -179,10 +157,7 @@ int inl;
179 ctx->buf_len=i; 157 ctx->buf_len=i;
180 } 158 }
181 159
182void EVP_EncryptFinal(ctx,out,outl) 160void EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
183EVP_CIPHER_CTX *ctx;
184unsigned char *out;
185int *outl;
186 { 161 {
187 int i,n,b,bl; 162 int i,n,b,bl;
188 163
@@ -200,12 +175,8 @@ int *outl;
200 *outl=b; 175 *outl=b;
201 } 176 }
202 177
203void EVP_DecryptUpdate(ctx,out,outl,in,inl) 178void EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
204EVP_CIPHER_CTX *ctx; 179 unsigned char *in, int inl)
205unsigned char *out;
206int *outl;
207unsigned char *in;
208int inl;
209 { 180 {
210 int b,bl,n; 181 int b,bl,n;
211 int keep_last=0; 182 int keep_last=0;
@@ -249,10 +220,7 @@ int inl;
249 } 220 }
250 } 221 }
251 222
252int EVP_DecryptFinal(ctx,out,outl) 223int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
253EVP_CIPHER_CTX *ctx;
254unsigned char *out;
255int *outl;
256 { 224 {
257 int i,b; 225 int i,b;
258 int n; 226 int n;
@@ -293,8 +261,7 @@ int *outl;
293 return(1); 261 return(1);
294 } 262 }
295 263
296void EVP_CIPHER_CTX_cleanup(c) 264void EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
297EVP_CIPHER_CTX *c;
298 { 265 {
299 if ((c->cipher != NULL) && (c->cipher->cleanup != NULL)) 266 if ((c->cipher != NULL) && (c->cipher->cleanup != NULL))
300 c->cipher->cleanup(c); 267 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 @@
1/* lib/evp/evp_err.c */ 1/* crypto/evp/evp_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "evp.h" 62#include <openssl/evp.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -65,39 +67,65 @@ static ERR_STRING_DATA EVP_str_functs[]=
65 { 67 {
66{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"}, 68{ERR_PACK(0,EVP_F_D2I_PKEY,0), "D2I_PKEY"},
67{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"}, 69{ERR_PACK(0,EVP_F_EVP_DECRYPTFINAL,0), "EVP_DecryptFinal"},
70{ERR_PACK(0,EVP_F_EVP_MD_CTX_COPY,0), "EVP_MD_CTX_copy"},
68{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"}, 71{ERR_PACK(0,EVP_F_EVP_OPENINIT,0), "EVP_OpenInit"},
72{ERR_PACK(0,EVP_F_EVP_PBE_ALG_ADD,0), "EVP_PBE_alg_add"},
73{ERR_PACK(0,EVP_F_EVP_PBE_CIPHERINIT,0), "EVP_PBE_CipherInit"},
74{ERR_PACK(0,EVP_F_EVP_PKCS82PKEY,0), "EVP_PKCS82PKEY"},
75{ERR_PACK(0,EVP_F_EVP_PKCS8_SET_BROKEN,0), "EVP_PKCS8_SET_BROKEN"},
76{ERR_PACK(0,EVP_F_EVP_PKEY2PKCS8,0), "EVP_PKEY2PKCS8"},
69{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"}, 77{ERR_PACK(0,EVP_F_EVP_PKEY_COPY_PARAMETERS,0), "EVP_PKEY_copy_parameters"},
70{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"}, 78{ERR_PACK(0,EVP_F_EVP_PKEY_DECRYPT,0), "EVP_PKEY_decrypt"},
71{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"}, 79{ERR_PACK(0,EVP_F_EVP_PKEY_ENCRYPT,0), "EVP_PKEY_encrypt"},
72{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"}, 80{ERR_PACK(0,EVP_F_EVP_PKEY_NEW,0), "EVP_PKEY_new"},
73{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"}, 81{ERR_PACK(0,EVP_F_EVP_SIGNFINAL,0), "EVP_SignFinal"},
74{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"}, 82{ERR_PACK(0,EVP_F_EVP_VERIFYFINAL,0), "EVP_VerifyFinal"},
75{0,NULL}, 83{ERR_PACK(0,EVP_F_PKCS5_PBE_KEYIVGEN,0), "PKCS5_PBE_keyivgen"},
84{ERR_PACK(0,EVP_F_PKCS5_V2_PBE_KEYIVGEN,0), "PKCS5_v2_PBE_keyivgen"},
85{ERR_PACK(0,EVP_F_RC2_MAGIC_TO_METH,0), "RC2_MAGIC_TO_METH"},
86{0,NULL}
76 }; 87 };
77 88
78static ERR_STRING_DATA EVP_str_reasons[]= 89static ERR_STRING_DATA EVP_str_reasons[]=
79 { 90 {
80{EVP_R_BAD_DECRYPT ,"bad decrypt"}, 91{EVP_R_BAD_DECRYPT ,"bad decrypt"},
92{EVP_R_BN_DECODE_ERROR ,"bn decode error"},
93{EVP_R_BN_PUBKEY_ERROR ,"bn pubkey error"},
94{EVP_R_CIPHER_PARAMETER_ERROR ,"cipher parameter error"},
95{EVP_R_DECODE_ERROR ,"decode error"},
81{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"}, 96{EVP_R_DIFFERENT_KEY_TYPES ,"different key types"},
97{EVP_R_ENCODE_ERROR ,"encode error"},
98{EVP_R_EVP_PBE_CIPHERINIT_ERROR ,"evp pbe cipherinit error"},
99{EVP_R_INPUT_NOT_INITIALIZED ,"input not initialized"},
82{EVP_R_IV_TOO_LARGE ,"iv too large"}, 100{EVP_R_IV_TOO_LARGE ,"iv too large"},
101{EVP_R_KEYGEN_FAILURE ,"keygen failure"},
83{EVP_R_MISSING_PARMATERS ,"missing parmaters"}, 102{EVP_R_MISSING_PARMATERS ,"missing parmaters"},
103{EVP_R_NO_DSA_PARAMETERS ,"no dsa parameters"},
84{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"}, 104{EVP_R_NO_SIGN_FUNCTION_CONFIGURED ,"no sign function configured"},
85{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"}, 105{EVP_R_NO_VERIFY_FUNCTION_CONFIGURED ,"no verify function configured"},
106{EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE ,"pkcs8 unknown broken type"},
86{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"}, 107{EVP_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
108{EVP_R_UNKNOWN_PBE_ALGORITHM ,"unknown pbe algorithm"},
87{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, 109{EVP_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
110{EVP_R_UNSUPPORTED_KEYLENGTH ,"unsupported keylength"},
111{EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION,"unsupported key derivation function"},
112{EVP_R_UNSUPPORTED_KEY_SIZE ,"unsupported key size"},
113{EVP_R_UNSUPPORTED_PRF ,"unsupported prf"},
114{EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM ,"unsupported private key algorithm"},
115{EVP_R_UNSUPPORTED_SALT_TYPE ,"unsupported salt type"},
88{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"}, 116{EVP_R_WRONG_FINAL_BLOCK_LENGTH ,"wrong final block length"},
89{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"}, 117{EVP_R_WRONG_PUBLIC_KEY_TYPE ,"wrong public key type"},
90{0,NULL}, 118{0,NULL}
91 }; 119 };
92 120
93#endif 121#endif
94 122
95void ERR_load_EVP_strings() 123void ERR_load_EVP_strings(void)
96 { 124 {
97 static int init=1; 125 static int init=1;
98 126
99 if (init); 127 if (init)
100 {; 128 {
101 init=0; 129 init=0;
102#ifndef NO_ERR 130#ifndef NO_ERR
103 ERR_load_strings(ERR_LIB_EVP,EVP_str_functs); 131 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "x509.h" 61#include <openssl/x509.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "evp.h" 63#include <openssl/evp.h>
64 64
65/* should be init to zeros. */ 65/* should be init to zeros. */
66static char prompt_string[80]; 66static char prompt_string[80];
67 67
68void EVP_set_pw_prompt(prompt) 68void EVP_set_pw_prompt(char *prompt)
69char *prompt;
70 { 69 {
71 if (prompt == NULL) 70 if (prompt == NULL)
72 prompt_string[0]='\0'; 71 prompt_string[0]='\0';
@@ -74,7 +73,7 @@ char *prompt;
74 strncpy(prompt_string,prompt,79); 73 strncpy(prompt_string,prompt,79);
75 } 74 }
76 75
77char *EVP_get_pw_prompt() 76char *EVP_get_pw_prompt(void)
78 { 77 {
79 if (prompt_string[0] == '\0') 78 if (prompt_string[0] == '\0')
80 return(NULL); 79 return(NULL);
@@ -83,29 +82,19 @@ char *EVP_get_pw_prompt()
83 } 82 }
84 83
85#ifdef NO_DES 84#ifdef NO_DES
86int des_read_pw_string(char *buf,int len,char *prompt,int verify); 85int des_read_pw_string(char *buf,int len,const char *prompt,int verify);
87#endif 86#endif
88 87
89int EVP_read_pw_string(buf,len,prompt,verify) 88int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify)
90char *buf;
91int len;
92char *prompt;
93int verify;
94 { 89 {
95 if ((prompt == NULL) && (prompt_string[0] != '\0')) 90 if ((prompt == NULL) && (prompt_string[0] != '\0'))
96 prompt=prompt_string; 91 prompt=prompt_string;
97 return(des_read_pw_string(buf,len,prompt,verify)); 92 return(des_read_pw_string(buf,len,prompt,verify));
98 } 93 }
99 94
100int EVP_BytesToKey(type,md,salt,data,datal,count,key,iv) 95int EVP_BytesToKey(const EVP_CIPHER *type, EVP_MD *md, unsigned char *salt,
101EVP_CIPHER *type; 96 unsigned char *data, int datal, int count, unsigned char *key,
102EVP_MD *md; 97 unsigned char *iv)
103unsigned char *salt;
104unsigned char *data;
105int datal;
106int count;
107unsigned char *key;
108unsigned char *iv;
109 { 98 {
110 EVP_MD_CTX c; 99 EVP_MD_CTX c;
111 unsigned char md_buf[EVP_MAX_MD_SIZE]; 100 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63 63
64int EVP_CIPHER_param_to_asn1(c,type) 64int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
65EVP_CIPHER_CTX *c;
66ASN1_TYPE *type;
67 { 65 {
68 int ret; 66 int ret;
69 67
@@ -74,9 +72,7 @@ ASN1_TYPE *type;
74 return(ret); 72 return(ret);
75 } 73 }
76 74
77int EVP_CIPHER_asn1_to_param(c,type) 75int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
78EVP_CIPHER_CTX *c;
79ASN1_TYPE *type;
80 { 76 {
81 int ret; 77 int ret;
82 78
@@ -87,9 +83,7 @@ ASN1_TYPE *type;
87 return(ret); 83 return(ret);
88 } 84 }
89 85
90int EVP_CIPHER_get_asn1_iv(c,type) 86int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
91EVP_CIPHER_CTX *c;
92ASN1_TYPE *type;
93 { 87 {
94 int i=0,l; 88 int i=0,l;
95 89
@@ -97,14 +91,15 @@ ASN1_TYPE *type;
97 { 91 {
98 l=EVP_CIPHER_CTX_iv_length(c); 92 l=EVP_CIPHER_CTX_iv_length(c);
99 i=ASN1_TYPE_get_octetstring(type,c->oiv,l); 93 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
100 memcpy(c->iv,c->oiv,l); 94 if (i != l)
95 return(-1);
96 else if (i > 0)
97 memcpy(c->iv,c->oiv,l);
101 } 98 }
102 return(i); 99 return(i);
103 } 100 }
104 101
105int EVP_CIPHER_set_asn1_iv(c,type) 102int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
106EVP_CIPHER_CTX *c;
107ASN1_TYPE *type;
108 { 103 {
109 int i=0,j; 104 int i=0,j;
110 105
@@ -115,3 +110,29 @@ ASN1_TYPE *type;
115 } 110 }
116 return(i); 111 return(i);
117 } 112 }
113
114/* Convert the various cipher NIDs and dummies to a proper OID NID */
115int EVP_CIPHER_type(const EVP_CIPHER *ctx)
116{
117 int nid;
118 nid = EVP_CIPHER_nid(ctx);
119
120 switch(nid) {
121
122 case NID_rc2_cbc:
123 case NID_rc2_64_cbc:
124 case NID_rc2_40_cbc:
125
126 return NID_rc2_cbc;
127
128 case NID_rc4:
129 case NID_rc4_40:
130
131 return NID_rc4;
132
133 default:
134
135 return nid;
136 }
137}
138
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
new file mode 100644
index 0000000000..353c3ad667
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_pbe.c
@@ -0,0 +1,134 @@
1/* evp_pbe.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/evp.h>
61#include <openssl/x509.h>
62#include "cryptlib.h"
63
64/* Password based encryption (PBE) functions */
65
66static STACK *pbe_algs;
67
68/* Setup a cipher context from a PBE algorithm */
69
70typedef struct {
71int pbe_nid;
72EVP_CIPHER *cipher;
73EVP_MD *md;
74EVP_PBE_KEYGEN *keygen;
75} EVP_PBE_CTL;
76
77int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
78 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
79{
80
81 EVP_PBE_CTL *pbetmp, pbelu;
82 int i;
83 pbelu.pbe_nid = OBJ_obj2nid(pbe_obj);
84 if (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu);
85 else i = -1;
86
87 if (i == -1) {
88 char obj_tmp[80];
89 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM);
90 if (!pbe_obj) strcpy (obj_tmp, "NULL");
91 else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj);
92 ERR_add_error_data(2, "TYPE=", obj_tmp);
93 return 0;
94 }
95 if (passlen == -1) passlen = strlen(pass);
96 pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
97 i = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,
98 pbetmp->md, en_de);
99 if (!i) {
100 EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);
101 return 0;
102 }
103 return 1;
104}
105
106static int pbe_cmp (EVP_PBE_CTL **pbe1, EVP_PBE_CTL **pbe2)
107{
108 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
109}
110
111/* Add a PBE algorithm */
112
113int EVP_PBE_alg_add (int nid, EVP_CIPHER *cipher, EVP_MD *md,
114 EVP_PBE_KEYGEN *keygen)
115{
116 EVP_PBE_CTL *pbe_tmp;
117 if (!pbe_algs) pbe_algs = sk_new (pbe_cmp);
118 if (!(pbe_tmp = (EVP_PBE_CTL*) Malloc (sizeof(EVP_PBE_CTL)))) {
119 EVPerr(EVP_F_EVP_PBE_ALG_ADD,ERR_R_MALLOC_FAILURE);
120 return 0;
121 }
122 pbe_tmp->pbe_nid = nid;
123 pbe_tmp->cipher = cipher;
124 pbe_tmp->md = md;
125 pbe_tmp->keygen = keygen;
126 sk_push (pbe_algs, (char *)pbe_tmp);
127 return 1;
128}
129
130void EVP_PBE_cleanup(void)
131{
132 sk_pop_free(pbe_algs, FreeFunc);
133 pbe_algs = NULL;
134}
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
new file mode 100644
index 0000000000..421e452db1
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -0,0 +1,298 @@
1/* evp_pkey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include "cryptlib.h"
62#include <openssl/x509.h>
63#include <openssl/rand.h>
64
65/* Extract a private key from a PKCS8 structure */
66
67EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
68{
69 EVP_PKEY *pkey;
70#ifndef NO_RSA
71 RSA *rsa;
72#endif
73#ifndef NO_DSA
74 DSA *dsa;
75 ASN1_INTEGER *dsapriv;
76 STACK *ndsa;
77 BN_CTX *ctx;
78 int plen;
79#endif
80 X509_ALGOR *a;
81 unsigned char *p;
82 int pkeylen;
83 char obj_tmp[80];
84
85 switch (p8->broken) {
86 case PKCS8_OK:
87 p = p8->pkey->value.octet_string->data;
88 pkeylen = p8->pkey->value.octet_string->length;
89 break;
90
91 case PKCS8_NO_OCTET:
92 p = p8->pkey->value.sequence->data;
93 pkeylen = p8->pkey->value.sequence->length;
94 break;
95
96 default:
97 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
98 return NULL;
99 break;
100 }
101 if (!(pkey = EVP_PKEY_new())) {
102 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
103 return NULL;
104 }
105 a = p8->pkeyalg;
106 switch (OBJ_obj2nid(a->algorithm))
107 {
108#ifndef NO_RSA
109 case NID_rsaEncryption:
110 if (!(rsa = d2i_RSAPrivateKey (NULL, &p, pkeylen))) {
111 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
112 return NULL;
113 }
114 EVP_PKEY_assign_RSA (pkey, rsa);
115 break;
116#endif
117#ifndef NO_DSA
118 case NID_dsa:
119 /* PKCS#8 DSA is weird: you just get a private key integer
120 * and parameters in the AlgorithmIdentifier the pubkey must
121 * be recalculated.
122 */
123
124 /* Check for broken Netscape Database DSA PKCS#8, UGH! */
125 if(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {
126 if(!(ndsa = ASN1_seq_unpack(p, pkeylen,
127 (char *(*)())d2i_ASN1_INTEGER,
128 ASN1_STRING_free))) {
129 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
130 return NULL;
131 }
132 if(sk_num(ndsa) != 2 ) {
133 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
134 sk_pop_free(ndsa, ASN1_STRING_free);
135 return NULL;
136 }
137 dsapriv = (ASN1_INTEGER *) sk_pop(ndsa);
138 sk_pop_free(ndsa, ASN1_STRING_free);
139 } else if (!(dsapriv=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {
140 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
141 return NULL;
142 }
143 /* Retrieve parameters */
144 if (a->parameter->type != V_ASN1_SEQUENCE) {
145 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_NO_DSA_PARAMETERS);
146 return NULL;
147 }
148 p = a->parameter->value.sequence->data;
149 plen = a->parameter->value.sequence->length;
150 if (!(dsa = d2i_DSAparams (NULL, &p, plen))) {
151 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
152 return NULL;
153 }
154 /* We have parameters now set private key */
155 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(dsapriv, NULL))) {
156 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);
157 DSA_free (dsa);
158 return NULL;
159 }
160 /* Calculate public key (ouch!) */
161 if (!(dsa->pub_key = BN_new())) {
162 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
163 DSA_free (dsa);
164 return NULL;
165 }
166 if (!(ctx = BN_CTX_new())) {
167 EVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);
168 DSA_free (dsa);
169 return NULL;
170 }
171
172 if (!BN_mod_exp(dsa->pub_key, dsa->g,
173 dsa->priv_key, dsa->p, ctx)) {
174
175 EVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);
176 BN_CTX_free (ctx);
177 DSA_free (dsa);
178 return NULL;
179 }
180
181 EVP_PKEY_assign_DSA (pkey, dsa);
182 BN_CTX_free (ctx);
183 break;
184#endif
185 default:
186 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
187 if (!a->algorithm) strcpy (obj_tmp, "NULL");
188 else i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);
189 ERR_add_error_data(2, "TYPE=", obj_tmp);
190 EVP_PKEY_free (pkey);
191 return NULL;
192 }
193 return pkey;
194}
195
196/* Turn a private key into a PKCS8 structure */
197
198PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)
199{
200 PKCS8_PRIV_KEY_INFO *p8;
201#ifndef NO_DSA
202 ASN1_INTEGER *dpkey;
203 unsigned char *p, *q;
204 int len;
205#endif
206 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
207 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
208 return NULL;
209 }
210 ASN1_INTEGER_set (p8->version, 0);
211 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
212 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
213 PKCS8_PRIV_KEY_INFO_free (p8);
214 return NULL;
215 }
216 switch (EVP_PKEY_type(pkey->type)) {
217#ifndef NO_RSA
218 case EVP_PKEY_RSA:
219
220 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
221 p8->pkeyalg->parameter->type = V_ASN1_NULL;
222 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
223 &p8->pkey->value.octet_string)) {
224 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
225 PKCS8_PRIV_KEY_INFO_free (p8);
226 return NULL;
227 }
228 break;
229#endif
230#ifndef NO_DSA
231 case EVP_PKEY_DSA:
232 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
233
234 /* get paramaters and place in AlgorithmIdentifier */
235 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
236 if (!(p = Malloc(len))) {
237 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
238 PKCS8_PRIV_KEY_INFO_free (p8);
239 return NULL;
240 }
241 q = p;
242 i2d_DSAparams (pkey->pkey.dsa, &q);
243 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
244 p8->pkeyalg->parameter->value.sequence = ASN1_STRING_new();
245 ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, len);
246 Free(p);
247 /* Get private key into an integer and pack */
248 if (!(dpkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
249 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
250 PKCS8_PRIV_KEY_INFO_free (p8);
251 return NULL;
252 }
253
254 if (!ASN1_pack_string((char *)dpkey, i2d_ASN1_INTEGER,
255 &p8->pkey->value.octet_string)) {
256 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
257 ASN1_INTEGER_free (dpkey);
258 PKCS8_PRIV_KEY_INFO_free (p8);
259 return NULL;
260 }
261 ASN1_INTEGER_free (dpkey);
262 break;
263#endif
264 default:
265 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
266 PKCS8_PRIV_KEY_INFO_free (p8);
267 return NULL;
268 }
269 p8->pkey->type = V_ASN1_OCTET_STRING;
270 RAND_seed (p8->pkey->value.octet_string->data,
271 p8->pkey->value.octet_string->length);
272 return p8;
273}
274
275PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
276{
277 switch (broken) {
278
279 case PKCS8_OK:
280 p8->broken = PKCS8_OK;
281 return p8;
282 break;
283
284 case PKCS8_NO_OCTET:
285 p8->broken = PKCS8_NO_OCTET;
286 p8->pkey->type = V_ASN1_SEQUENCE;
287 return p8;
288 break;
289
290 default:
291 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
292 return NULL;
293 break;
294
295 }
296}
297
298
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c
index 3549b1699c..8ea826868e 100644
--- a/src/lib/libcrypto/evp/m_dss.c
+++ b/src/lib/libcrypto/evp/m_dss.c
@@ -58,10 +58,11 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/x509.h>
64 64
65#ifndef NO_SHA
65static EVP_MD dsa_md= 66static EVP_MD dsa_md=
66 { 67 {
67 NID_dsaWithSHA, 68 NID_dsaWithSHA,
@@ -75,8 +76,8 @@ static EVP_MD dsa_md=
75 sizeof(EVP_MD *)+sizeof(SHA_CTX), 76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 }; 77 };
77 78
78EVP_MD *EVP_dss() 79EVP_MD *EVP_dss(void)
79 { 80 {
80 return(&dsa_md); 81 return(&dsa_md);
81 } 82 }
82 83#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_SHA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63#include "x509.h" 64#include <openssl/x509.h>
64 65
65static EVP_MD dss1_md= 66static EVP_MD dss1_md=
66 { 67 {
@@ -75,7 +76,8 @@ static EVP_MD dss1_md=
75 sizeof(EVP_MD *)+sizeof(SHA_CTX), 76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 }; 77 };
77 78
78EVP_MD *EVP_dss1() 79EVP_MD *EVP_dss1(void)
79 { 80 {
80 return(&dss1_md); 81 return(&dss1_md);
81 } 82 }
83#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_MD2
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63#include "x509.h" 64#include <openssl/x509.h>
64 65
65static EVP_MD md2_md= 66static EVP_MD md2_md=
66 { 67 {
@@ -75,8 +76,8 @@ static EVP_MD md2_md=
75 sizeof(EVP_MD *)+sizeof(MD2_CTX), 76 sizeof(EVP_MD *)+sizeof(MD2_CTX),
76 }; 77 };
77 78
78EVP_MD *EVP_md2() 79EVP_MD *EVP_md2(void)
79 { 80 {
80 return(&md2_md); 81 return(&md2_md);
81 } 82 }
82 83#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_MD5
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63#include "x509.h" 64#include <openssl/x509.h>
64 65
65static EVP_MD md5_md= 66static EVP_MD md5_md=
66 { 67 {
@@ -75,7 +76,8 @@ static EVP_MD md5_md=
75 sizeof(EVP_MD *)+sizeof(MD5_CTX), 76 sizeof(EVP_MD *)+sizeof(MD5_CTX),
76 }; 77 };
77 78
78EVP_MD *EVP_md5() 79EVP_MD *EVP_md5(void)
79 { 80 {
80 return(&md5_md); 81 return(&md5_md);
81 } 82 }
83#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_MDC2
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63#include "x509.h" 64#include <openssl/x509.h>
64 65
65static EVP_MD mdc2_md= 66static EVP_MD mdc2_md=
66 { 67 {
@@ -75,7 +76,8 @@ static EVP_MD mdc2_md=
75 sizeof(EVP_MD *)+sizeof(MDC2_CTX), 76 sizeof(EVP_MD *)+sizeof(MDC2_CTX),
76 }; 77 };
77 78
78EVP_MD *EVP_mdc2() 79EVP_MD *EVP_mdc2(void)
79 { 80 {
80 return(&mdc2_md); 81 return(&mdc2_md);
81 } 82 }
83#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/x509.h>
64 64
65static void function() 65static void function(void)
66 { 66 {
67 } 67 }
68 68
@@ -80,7 +80,7 @@ static EVP_MD null_md=
80 sizeof(EVP_MD *), 80 sizeof(EVP_MD *),
81 }; 81 };
82 82
83EVP_MD *EVP_md_null() 83EVP_MD *EVP_md_null(void)
84 { 84 {
85 return(&null_md); 85 return(&null_md);
86 } 86 }
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RIPEMD
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/ripemd.h>
62#include "objects.h" 63#include <openssl/evp.h>
63#include "x509.h" 64#include <openssl/objects.h>
65#include <openssl/x509.h>
64 66
65static EVP_MD ripemd160_md= 67static EVP_MD ripemd160_md=
66 { 68 {
@@ -75,7 +77,8 @@ static EVP_MD ripemd160_md=
75 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX), 77 sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
76 }; 78 };
77 79
78EVP_MD *EVP_ripemd160() 80EVP_MD *EVP_ripemd160(void)
79 { 81 {
80 return(&ripemd160_md); 82 return(&ripemd160_md);
81 } 83 }
84#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_SHA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63#include "x509.h" 64#include <openssl/x509.h>
64 65
65static EVP_MD sha_md= 66static EVP_MD sha_md=
66 { 67 {
@@ -75,8 +76,8 @@ static EVP_MD sha_md=
75 sizeof(EVP_MD *)+sizeof(SHA_CTX), 76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 }; 77 };
77 78
78EVP_MD *EVP_sha() 79EVP_MD *EVP_sha(void)
79 { 80 {
80 return(&sha_md); 81 return(&sha_md);
81 } 82 }
82 83#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_SHA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63#include "x509.h" 64#include <openssl/x509.h>
64 65
65static EVP_MD sha1_md= 66static EVP_MD sha1_md=
66 { 67 {
@@ -75,7 +76,8 @@ static EVP_MD sha1_md=
75 sizeof(EVP_MD *)+sizeof(SHA_CTX), 76 sizeof(EVP_MD *)+sizeof(SHA_CTX),
76 }; 77 };
77 78
78EVP_MD *EVP_sha1() 79EVP_MD *EVP_sha1(void)
79 { 80 {
80 return(&sha1_md); 81 return(&sha1_md);
81 } 82 }
83#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include <openssl/x509.h>
63 64
64typedef struct aliases_st { 65int EVP_add_cipher(EVP_CIPHER *c)
65 char *alias;
66 /* This must be the last field becaue I will allocate things
67 * so they go off the end of it */
68 char name[4];
69 } ALIASES;
70
71static STACK /* ALIASES */ *aliases=NULL;
72static STACK /* EVP_CIPHERS */ *ciphers=NULL;
73static STACK /* EVP_MD */ *digests=NULL;
74
75static int cipher_nid_cmp(a,b)
76EVP_CIPHER **a,**b;
77 { return((*a)->nid - (*b)->nid); }
78
79static int digest_type_cmp(a,b)
80EVP_MD **a,**b;
81 { return((*a)->pkey_type - (*b)->pkey_type); }
82
83int EVP_add_cipher(c)
84EVP_CIPHER *c;
85 {
86 int i;
87
88 if (ciphers == NULL)
89 {
90 ciphers=sk_new(cipher_nid_cmp);
91 if (ciphers == NULL) return(0);
92 }
93 if ((i=sk_find(ciphers,(char *)c)) >= 0)
94 {
95 if (sk_value(ciphers,i) == (char *)c)
96 return(1);
97 sk_delete(ciphers,i);
98 }
99 return(sk_push(ciphers,(char *)c));
100 }
101
102int EVP_add_digest(md)
103EVP_MD *md;
104 { 66 {
105 int i; 67 int r;
106 char *n;
107 68
108 if (digests == NULL) 69 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
109 { 70 if (r == 0) return(0);
110 digests=sk_new(digest_type_cmp); 71 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
111 if (digests == NULL) return(0); 72 return(r);
112 }
113 if ((i=sk_find(digests,(char *)md)) >= 0)
114 {
115 if (sk_value(digests,i) == (char *)md)
116 return(1);
117 sk_delete(digests,i);
118 }
119 if (md->type != md->pkey_type)
120 {
121 n=OBJ_nid2sn(md->pkey_type);
122 EVP_add_alias(n,OBJ_nid2sn(md->type));
123 EVP_add_alias(n,OBJ_nid2ln(md->type));
124 }
125 sk_push(digests,(char *)md);
126 return(1);
127 }
128
129static int alias_cmp(a,b)
130ALIASES **a,**b;
131 {
132 return(strcmp((*a)->alias,(*b)->alias));
133 } 73 }
134 74
135int EVP_add_alias(name,aname) 75int EVP_add_digest(EVP_MD *md)
136char *name;
137char *aname;
138 { 76 {
139 int l1,l2,i; 77 int r;
140 ALIASES *a; 78 const char *name;
141 char *p;
142 79
143 if ((name == NULL) || (aname == NULL)) return(0); 80 name=OBJ_nid2sn(md->type);
144 l1=strlen(name)+1; 81 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md);
145 l2=strlen(aname)+1; 82 if (r == 0) return(0);
146 i=sizeof(ALIASES)+l1+l2; 83 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md);
147 if ((a=(ALIASES *)Malloc(i)) == NULL) 84 if (r == 0) return(0);
148 return(0);
149 strcpy(a->name,name);
150 p= &(a->name[l1]);
151 strcpy(p,aname);
152 a->alias=p;
153 85
154 if (aliases == NULL) 86 if (md->type != md->pkey_type)
155 {
156 aliases=sk_new(alias_cmp);
157 if (aliases == NULL) goto err;
158 }
159
160 if ((i=sk_find(aliases,(char *)a)) >= 0)
161 { 87 {
162 Free(sk_delete(aliases,i)); 88 r=OBJ_NAME_add(OBJ_nid2sn(md->pkey_type),
89 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
90 if (r == 0) return(0);
91 r=OBJ_NAME_add(OBJ_nid2ln(md->pkey_type),
92 OBJ_NAME_TYPE_MD_METH|OBJ_NAME_ALIAS,name);
163 } 93 }
164 if (!sk_push(aliases,(char *)a)) goto err; 94 return(r);
165 return(1);
166err:
167 return(0);
168 } 95 }
169 96
170int EVP_delete_alias(name) 97const EVP_CIPHER *EVP_get_cipherbyname(const char *name)
171char *name;
172 { 98 {
173 ALIASES a; 99 const EVP_CIPHER *cp;
174 int i;
175 100
176 if (aliases != NULL) 101 cp=(const EVP_CIPHER *)OBJ_NAME_get(name,OBJ_NAME_TYPE_CIPHER_METH);
177 { 102 return(cp);
178 a.alias=name;
179 if ((i=sk_find(aliases,(char *)&a)) >= 0)
180 {
181 Free(sk_delete(aliases,i));
182 return(1);
183 }
184 }
185 return(0);
186 } 103 }
187 104
188EVP_CIPHER *EVP_get_cipherbyname(name) 105const EVP_MD *EVP_get_digestbyname(const char *name)
189char *name;
190 { 106 {
191 int nid,num=6,i; 107 const EVP_MD *cp;
192 EVP_CIPHER c,*cp;
193 ALIASES a,*ap;
194
195 if (ciphers == NULL) return(NULL);
196 for (;;)
197 {
198 if (num-- <= 0) return(NULL);
199 if (aliases != NULL)
200 {
201 a.alias=name;
202 i=sk_find(aliases,(char *)&a);
203 if (i >= 0)
204 {
205 ap=(ALIASES *)sk_value(aliases,i);
206 name=ap->name;
207 continue;
208 }
209 }
210 108
211 nid=OBJ_txt2nid(name); 109 cp=(const EVP_MD *)OBJ_NAME_get(name,OBJ_NAME_TYPE_MD_METH);
212 if (nid == NID_undef) return(NULL); 110 return(cp);
213 c.nid=nid;
214 i=sk_find(ciphers,(char *)&c);
215 if (i >= 0)
216 {
217 cp=(EVP_CIPHER *)sk_value(ciphers,i);
218 return(cp);
219 }
220 else
221 return(NULL);
222 }
223 } 111 }
224 112
225EVP_MD *EVP_get_digestbyname(name) 113void EVP_cleanup(void)
226char *name;
227 { 114 {
228 int nid,num=6,i; 115 OBJ_NAME_cleanup(OBJ_NAME_TYPE_CIPHER_METH);
229 EVP_MD c,*cp; 116 OBJ_NAME_cleanup(OBJ_NAME_TYPE_MD_METH);
230 ALIASES a,*ap; 117 EVP_PBE_cleanup();
231
232 if (digests == NULL) return(NULL);
233
234 for (;;)
235 {
236 if (num-- <= 0) return(NULL);
237
238 if (aliases != NULL)
239 {
240 a.alias=name;
241 i=sk_find(aliases,(char *)&a);
242 if (i >= 0)
243 {
244 ap=(ALIASES *)sk_value(aliases,i);
245 name=ap->name;
246 continue;
247 }
248 }
249
250 nid=OBJ_txt2nid(name);
251 if (nid == NID_undef) return(NULL);
252 c.pkey_type=nid;
253 i=sk_find(digests,(char *)&c);
254 if (i >= 0)
255 {
256 cp=(EVP_MD *)sk_value(digests,i);
257 return(cp);
258 }
259 else
260 return(NULL);
261 }
262 }
263
264void EVP_cleanup()
265 {
266 int i;
267
268 if (aliases != NULL)
269 {
270 for (i=0; i<sk_num(aliases); i++)
271 Free(sk_value(aliases,i));
272 sk_free(aliases);
273 aliases=NULL;
274 }
275 if (ciphers != NULL)
276 {
277 sk_free(ciphers);
278 ciphers=NULL;
279 }
280 if (digests != NULL)
281 {
282 sk_free(digests);
283 digests=NULL;
284 }
285 } 118 }
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
new file mode 100644
index 0000000000..e3dae52d4d
--- /dev/null
+++ b/src/lib/libcrypto/evp/p5_crpt.c
@@ -0,0 +1,146 @@
1/* p5_crpt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include "cryptlib.h"
64
65/* PKCS#5 v1.5 compatible PBE functions: see PKCS#5 v2.0 for more info.
66 */
67
68void PKCS5_PBE_add(void)
69{
70#ifndef NO_DES
71# ifndef NO_MD5
72EVP_PBE_alg_add(NID_pbeWithMD5AndDES_CBC, EVP_des_cbc(), EVP_md5(),
73 PKCS5_PBE_keyivgen);
74# endif
75# ifndef NO_MD2
76EVP_PBE_alg_add(NID_pbeWithMD2AndDES_CBC, EVP_des_cbc(), EVP_md2(),
77 PKCS5_PBE_keyivgen);
78# endif
79# ifndef NO_SHA
80EVP_PBE_alg_add(NID_pbeWithSHA1AndDES_CBC, EVP_des_cbc(), EVP_sha1(),
81 PKCS5_PBE_keyivgen);
82# endif
83#endif
84#ifndef NO_RC2
85# ifndef NO_MD5
86EVP_PBE_alg_add(NID_pbeWithMD5AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md5(),
87 PKCS5_PBE_keyivgen);
88# endif
89# ifndef NO_MD2
90EVP_PBE_alg_add(NID_pbeWithMD2AndRC2_CBC, EVP_rc2_64_cbc(), EVP_md2(),
91 PKCS5_PBE_keyivgen);
92# endif
93# ifndef NO_SHA
94EVP_PBE_alg_add(NID_pbeWithSHA1AndRC2_CBC, EVP_rc2_64_cbc(), EVP_sha1(),
95 PKCS5_PBE_keyivgen);
96# endif
97#endif
98#ifndef NO_HMAC
99EVP_PBE_alg_add(NID_pbes2, NULL, NULL, PKCS5_v2_PBE_keyivgen);
100#endif
101}
102
103int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
104 ASN1_TYPE *param, EVP_CIPHER *cipher, EVP_MD *md,
105 int en_de)
106{
107 EVP_MD_CTX ctx;
108 unsigned char md_tmp[EVP_MAX_MD_SIZE];
109 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
110 int i;
111 PBEPARAM *pbe;
112 int saltlen, iter;
113 unsigned char *salt, *pbuf;
114
115 /* Extract useful info from parameter */
116 pbuf = param->value.sequence->data;
117 if (!param || (param->type != V_ASN1_SEQUENCE) ||
118 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
120 return 0;
121 }
122
123 if (!pbe->iter) iter = 1;
124 else iter = ASN1_INTEGER_get (pbe->iter);
125 salt = pbe->salt->data;
126 saltlen = pbe->salt->length;
127
128 EVP_DigestInit (&ctx, md);
129 EVP_DigestUpdate (&ctx, pass, passlen);
130 EVP_DigestUpdate (&ctx, salt, saltlen);
131 PBEPARAM_free(pbe);
132 EVP_DigestFinal (&ctx, md_tmp, NULL);
133 for (i = 1; i < iter; i++) {
134 EVP_DigestInit(&ctx, md);
135 EVP_DigestUpdate(&ctx, md_tmp, EVP_MD_size(md));
136 EVP_DigestFinal (&ctx, md_tmp, NULL);
137 }
138 memcpy (key, md_tmp, EVP_CIPHER_key_length(cipher));
139 memcpy (iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
140 EVP_CIPHER_iv_length(cipher));
141 EVP_CipherInit(cctx, cipher, key, iv, en_de);
142 memset(md_tmp, 0, EVP_MAX_MD_SIZE);
143 memset(key, 0, EVP_MAX_KEY_LENGTH);
144 memset(iv, 0, EVP_MAX_IV_LENGTH);
145 return 1;
146}
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
new file mode 100644
index 0000000000..27a2c518be
--- /dev/null
+++ b/src/lib/libcrypto/evp/p5_crpt2.c
@@ -0,0 +1,247 @@
1/* p5_crpt2.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58#if !defined(NO_HMAC) && !defined(NO_SHA)
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include <openssl/hmac.h>
64#include "cryptlib.h"
65
66/* set this to print out info about the keygen algorithm */
67/* #define DEBUG_PKCS5V2 */
68
69#ifdef DEBUG_PKCS5V2
70 static void h__dump (const unsigned char *p, int len);
71#endif
72
73/* This is an implementation of PKCS#5 v2.0 password based encryption key
74 * derivation function PBKDF2 using the only currently defined function HMAC
75 * with SHA1. Verified against test vectors posted by Peter Gutmann
76 * <pgut001@cs.auckland.ac.nz> to the PKCS-TNG <pkcs-tng@rsa.com> mailing list.
77 */
78
79int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
80 unsigned char *salt, int saltlen, int iter,
81 int keylen, unsigned char *out)
82{
83 unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4];
84 int cplen, j, k, tkeylen;
85 unsigned long i = 1;
86 HMAC_CTX hctx;
87 p = out;
88 tkeylen = keylen;
89 if(passlen == -1) passlen = strlen(pass);
90 while(tkeylen) {
91 if(tkeylen > SHA_DIGEST_LENGTH) cplen = SHA_DIGEST_LENGTH;
92 else cplen = tkeylen;
93 /* We are unlikely to ever use more than 256 blocks (5120 bits!)
94 * but just in case...
95 */
96 itmp[0] = (unsigned char)((i >> 24) & 0xff);
97 itmp[1] = (unsigned char)((i >> 16) & 0xff);
98 itmp[2] = (unsigned char)((i >> 8) & 0xff);
99 itmp[3] = (unsigned char)(i & 0xff);
100 HMAC_Init(&hctx, pass, passlen, EVP_sha1());
101 HMAC_Update(&hctx, salt, saltlen);
102 HMAC_Update(&hctx, itmp, 4);
103 HMAC_Final(&hctx, digtmp, NULL);
104 memcpy(p, digtmp, cplen);
105 for(j = 1; j < iter; j++) {
106 HMAC(EVP_sha1(), pass, passlen,
107 digtmp, SHA_DIGEST_LENGTH, digtmp, NULL);
108 for(k = 0; k < cplen; k++) p[k] ^= digtmp[k];
109 }
110 tkeylen-= cplen;
111 i++;
112 p+= cplen;
113 }
114 HMAC_cleanup(&hctx);
115#ifdef DEBUG_PKCS5V2
116 fprintf(stderr, "Password:\n");
117 h__dump (pass, passlen);
118 fprintf(stderr, "Salt:\n");
119 h__dump (salt, saltlen);
120 fprintf(stderr, "Iteration count %d\n", iter);
121 fprintf(stderr, "Key:\n");
122 h__dump (out, keylen);
123#endif
124 return 1;
125}
126
127#ifdef DO_TEST
128main()
129{
130 unsigned char out[4];
131 unsigned char salt[] = {0x12, 0x34, 0x56, 0x78};
132 PKCS5_PBKDF2_HMAC_SHA1("password", -1, salt, 4, 5, 4, out);
133 fprintf(stderr, "Out %02X %02X %02X %02X\n",
134 out[0], out[1], out[2], out[3]);
135}
136
137#endif
138
139/* Now the key derivation function itself. This is a bit evil because
140 * it has to check the ASN1 parameters are valid: and there are quite a
141 * few of them...
142 */
143
144int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
145 ASN1_TYPE *param, EVP_CIPHER *c, EVP_MD *md,
146 int en_de)
147{
148 unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH];
149 int saltlen, keylen, iter, plen;
150 PBE2PARAM *pbe2 = NULL;
151 const EVP_CIPHER *cipher;
152 PBKDF2PARAM *kdf = NULL;
153
154 pbuf = param->value.sequence->data;
155 plen = param->value.sequence->length;
156 if(!param || (param->type != V_ASN1_SEQUENCE) ||
157 !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
158 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
159 return 0;
160 }
161
162 /* See if we recognise the key derivation function */
163
164 if(OBJ_obj2nid(pbe2->keyfunc->algorithm) != NID_id_pbkdf2) {
165 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
166 EVP_R_UNSUPPORTED_KEY_DERIVATION_FUNCTION);
167 goto err;
168 }
169
170 /* lets see if we recognise the encryption algorithm.
171 */
172
173 cipher = EVP_get_cipherbyname(
174 OBJ_nid2sn(OBJ_obj2nid(pbe2->encryption->algorithm)));
175
176 if(!cipher) {
177 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
178 EVP_R_UNSUPPORTED_CIPHER);
179 goto err;
180 }
181
182 /* Fixup cipher based on AlgorithmIdentifier */
183 EVP_CipherInit(ctx, cipher, NULL, NULL, en_de);
184 if(EVP_CIPHER_asn1_to_param(ctx, pbe2->encryption->parameter) < 0) {
185 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
186 EVP_R_CIPHER_PARAMETER_ERROR);
187 goto err;
188 }
189 keylen = EVP_CIPHER_CTX_key_length(ctx);
190
191 /* Now decode key derivation function */
192
193 pbuf = pbe2->keyfunc->parameter->value.sequence->data;
194 plen = pbe2->keyfunc->parameter->value.sequence->length;
195 if(!pbe2->keyfunc->parameter ||
196 (pbe2->keyfunc->parameter->type != V_ASN1_SEQUENCE) ||
197 !(kdf = d2i_PBKDF2PARAM(NULL, &pbuf, plen)) ) {
198 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
199 goto err;
200 }
201
202 PBE2PARAM_free(pbe2);
203 pbe2 = NULL;
204
205 /* Now check the parameters of the kdf */
206
207 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){
208 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
209 EVP_R_UNSUPPORTED_KEYLENGTH);
210 goto err;
211 }
212
213 if(kdf->prf && (OBJ_obj2nid(kdf->prf->algorithm) != NID_hmacWithSHA1)) {
214 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);
215 goto err;
216 }
217
218 if(kdf->salt->type != V_ASN1_OCTET_STRING) {
219 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
220 EVP_R_UNSUPPORTED_SALT_TYPE);
221 goto err;
222 }
223
224 /* it seems that its all OK */
225 salt = kdf->salt->value.octet_string->data;
226 saltlen = kdf->salt->value.octet_string->length;
227 iter = ASN1_INTEGER_get(kdf->iter);
228 PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key);
229 EVP_CipherInit(ctx, NULL, key, NULL, en_de);
230 memset(key, 0, keylen);
231 PBKDF2PARAM_free(kdf);
232 return 1;
233
234 err:
235 PBE2PARAM_free(pbe2);
236 PBKDF2PARAM_free(kdf);
237 return 0;
238}
239
240#ifdef DEBUG_PKCS5V2
241static void h__dump (const unsigned char *p, int len)
242{
243 for (; len --; p++) fprintf(stderr, "%02X ", *p);
244 fprintf(stderr, "\n");
245}
246#endif
247#endif
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c
index e845ce70c7..57b5daa453 100644
--- a/src/lib/libcrypto/evp/p_dec.c
+++ b/src/lib/libcrypto/evp/p_dec.c
@@ -58,27 +58,30 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "rand.h" 61#include <openssl/rand.h>
62#include "rsa.h" 62#ifndef NO_RSA
63#include "evp.h" 63#include <openssl/rsa.h>
64#include "objects.h" 64#endif
65#include "x509.h" 65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
66 68
67int EVP_PKEY_decrypt(key,ek,ekl,priv) 69int EVP_PKEY_decrypt(unsigned char *key, unsigned char *ek, int ekl,
68unsigned char *key; 70 EVP_PKEY *priv)
69unsigned char *ek;
70int ekl;
71EVP_PKEY *priv;
72 { 71 {
73 int ret= -1; 72 int ret= -1;
74 73
74#ifndef NO_RSA
75 if (priv->type != EVP_PKEY_RSA) 75 if (priv->type != EVP_PKEY_RSA)
76 { 76 {
77#endif
77 EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); 78 EVPerr(EVP_F_EVP_PKEY_DECRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef NO_RSA
78 goto err; 80 goto err;
79 } 81 }
80 82
81 ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING); 83 ret=RSA_private_decrypt(ekl,ek,key,priv->pkey.rsa,RSA_PKCS1_PADDING);
82err: 84err:
85#endif
83 return(ret); 86 return(ret);
84 } 87 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "rand.h" 61#include <openssl/rand.h>
62#include "rsa.h" 62#ifndef NO_RSA
63#include "evp.h" 63#include <openssl/rsa.h>
64#include "objects.h" 64#endif
65#include "x509.h" 65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
66 68
67int EVP_PKEY_encrypt(ek,key,key_len,pubk) 69int EVP_PKEY_encrypt(unsigned char *ek, unsigned char *key, int key_len,
68unsigned char *ek; 70 EVP_PKEY *pubk)
69unsigned char *key;
70int key_len;
71EVP_PKEY *pubk;
72 { 71 {
73 int ret=0; 72 int ret=0;
74 73
74#ifndef NO_RSA
75 if (pubk->type != EVP_PKEY_RSA) 75 if (pubk->type != EVP_PKEY_RSA)
76 { 76 {
77#endif
77 EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA); 78 EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
79#ifndef NO_RSA
78 goto err; 80 goto err;
79 } 81 }
80 ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING); 82 ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING);
81err: 83err:
84#endif
82 return(ret); 85 return(ret);
83 } 86 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "objects.h" 61#include <openssl/objects.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "asn1_mac.h" 63#include <openssl/asn1_mac.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66/* EVPerr(EVP_F_D2I_PKEY,EVP_R_UNSUPPORTED_CIPHER); */
67/* EVPerr(EVP_F_D2I_PKEY,EVP_R_IV_TOO_LARGE); */
68
69#ifndef NOPROTO
70static void EVP_PKEY_free_it(EVP_PKEY *x); 66static void EVP_PKEY_free_it(EVP_PKEY *x);
71#else 67int EVP_PKEY_bits(EVP_PKEY *pkey)
72static void EVP_PKEY_free_it();
73#endif
74
75int EVP_PKEY_bits(pkey)
76EVP_PKEY *pkey;
77 { 68 {
78#ifndef NO_RSA 69#ifndef NO_RSA
79 if (pkey->type == EVP_PKEY_RSA) 70 if (pkey->type == EVP_PKEY_RSA)
@@ -87,9 +78,10 @@ EVP_PKEY *pkey;
87 return(0); 78 return(0);
88 } 79 }
89 80
90int EVP_PKEY_size(pkey) 81int EVP_PKEY_size(EVP_PKEY *pkey)
91EVP_PKEY *pkey;
92 { 82 {
83 if (pkey == NULL)
84 return(0);
93#ifndef NO_RSA 85#ifndef NO_RSA
94 if (pkey->type == EVP_PKEY_RSA) 86 if (pkey->type == EVP_PKEY_RSA)
95 return(RSA_size(pkey->pkey.rsa)); 87 return(RSA_size(pkey->pkey.rsa));
@@ -102,9 +94,7 @@ EVP_PKEY *pkey;
102 return(0); 94 return(0);
103 } 95 }
104 96
105int EVP_PKEY_save_parameters(pkey,mode) 97int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
106EVP_PKEY *pkey;
107int mode;
108 { 98 {
109#ifndef NO_DSA 99#ifndef NO_DSA
110 if (pkey->type == EVP_PKEY_DSA) 100 if (pkey->type == EVP_PKEY_DSA)
@@ -119,8 +109,7 @@ int mode;
119 return(0); 109 return(0);
120 } 110 }
121 111
122int EVP_PKEY_copy_parameters(to,from) 112int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
123EVP_PKEY *to,*from;
124 { 113 {
125 if (to->type != from->type) 114 if (to->type != from->type)
126 { 115 {
@@ -156,8 +145,7 @@ err:
156 return(0); 145 return(0);
157 } 146 }
158 147
159int EVP_PKEY_missing_parameters(pkey) 148int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
160EVP_PKEY *pkey;
161 { 149 {
162#ifndef NO_DSA 150#ifndef NO_DSA
163 if (pkey->type == EVP_PKEY_DSA) 151 if (pkey->type == EVP_PKEY_DSA)
@@ -172,8 +160,7 @@ EVP_PKEY *pkey;
172 return(0); 160 return(0);
173 } 161 }
174 162
175int EVP_PKEY_cmp_parameters(a,b) 163int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
176EVP_PKEY *a,*b;
177 { 164 {
178#ifndef NO_DSA 165#ifndef NO_DSA
179 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) 166 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
@@ -189,7 +176,7 @@ EVP_PKEY *a,*b;
189 return(-1); 176 return(-1);
190 } 177 }
191 178
192EVP_PKEY *EVP_PKEY_new() 179EVP_PKEY *EVP_PKEY_new(void)
193 { 180 {
194 EVP_PKEY *ret; 181 EVP_PKEY *ret;
195 182
@@ -207,10 +194,7 @@ EVP_PKEY *EVP_PKEY_new()
207 return(ret); 194 return(ret);
208 } 195 }
209 196
210int EVP_PKEY_assign(pkey,type,key) 197int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
211EVP_PKEY *pkey;
212int type;
213char *key;
214 { 198 {
215 if (pkey == NULL) return(0); 199 if (pkey == NULL) return(0);
216 if (pkey->pkey.ptr != NULL) 200 if (pkey->pkey.ptr != NULL)
@@ -221,8 +205,7 @@ char *key;
221 return(1); 205 return(1);
222 } 206 }
223 207
224int EVP_PKEY_type(type) 208int EVP_PKEY_type(int type)
225int type;
226 { 209 {
227 switch (type) 210 switch (type)
228 { 211 {
@@ -242,8 +225,7 @@ int type;
242 } 225 }
243 } 226 }
244 227
245void EVP_PKEY_free(x) 228void EVP_PKEY_free(EVP_PKEY *x)
246EVP_PKEY *x;
247 { 229 {
248 int i; 230 int i;
249 231
@@ -265,8 +247,7 @@ EVP_PKEY *x;
265 Free((char *)x); 247 Free((char *)x);
266 } 248 }
267 249
268static void EVP_PKEY_free_it(x) 250static void EVP_PKEY_free_it(EVP_PKEY *x)
269EVP_PKEY *x;
270 { 251 {
271 switch (x->type) 252 switch (x->type)
272 { 253 {
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "objects.h" 63#include <openssl/objects.h>
63#include "x509.h" 64#include <openssl/x509.h>
64 65
65int EVP_OpenInit(ctx,type,ek,ekl,iv,priv) 66int EVP_OpenInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char *ek,
66EVP_CIPHER_CTX *ctx; 67 int ekl, unsigned char *iv, EVP_PKEY *priv)
67EVP_CIPHER *type;
68unsigned char *ek;
69int ekl;
70unsigned char *iv;
71EVP_PKEY *priv;
72 { 68 {
73 unsigned char *key=NULL; 69 unsigned char *key=NULL;
74 int i,size=0,ret=0; 70 int i,size=0,ret=0;
@@ -106,10 +102,7 @@ err:
106 return(ret); 102 return(ret);
107 } 103 }
108 104
109int EVP_OpenFinal(ctx,out,outl) 105int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
110EVP_CIPHER_CTX *ctx;
111unsigned char *out;
112int *outl;
113 { 106 {
114 int i; 107 int i;
115 108
@@ -117,3 +110,4 @@ int *outl;
117 EVP_DecryptInit(ctx,NULL,NULL,NULL); 110 EVP_DecryptInit(ctx,NULL,NULL,NULL);
118 return(i); 111 return(i);
119 } 112 }
113#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "rand.h" 61#include <openssl/rand.h>
62#include "rsa.h" 62#ifndef NO_RSA
63#include "evp.h" 63#include <openssl/rsa.h>
64#include "objects.h" 64#endif
65#include "x509.h" 65#include <openssl/evp.h>
66#include <openssl/objects.h>
67#include <openssl/x509.h>
66 68
67int EVP_SealInit(ctx,type,ek,ekl,iv,pubk,npubk) 69int EVP_SealInit(EVP_CIPHER_CTX *ctx, EVP_CIPHER *type, unsigned char **ek,
68EVP_CIPHER_CTX *ctx; 70 int *ekl, unsigned char *iv, EVP_PKEY **pubk, int npubk)
69EVP_CIPHER *type;
70unsigned char **ek;
71int *ekl;
72unsigned char *iv;
73EVP_PKEY **pubk;
74int npubk;
75 { 71 {
76 unsigned char key[EVP_MAX_KEY_LENGTH]; 72 unsigned char key[EVP_MAX_KEY_LENGTH];
77 int i; 73 int i;
@@ -105,10 +101,7 @@ int inl;
105 } 101 }
106*/ 102*/
107 103
108void EVP_SealFinal(ctx,out,outl) 104void EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
109EVP_CIPHER_CTX *ctx;
110unsigned char *out;
111int *outl;
112 { 105 {
113 EVP_EncryptFinal(ctx,out,outl); 106 EVP_EncryptFinal(ctx,out,outl);
114 EVP_EncryptInit(ctx,NULL,NULL,NULL); 107 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/x509.h>
64 64
65#ifdef undef 65#ifdef undef
66void EVP_SignInit(ctx,type) 66void EVP_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
67EVP_MD_CTX *ctx;
68EVP_MD *type;
69 { 67 {
70 EVP_DigestInit(ctx,type); 68 EVP_DigestInit(ctx,type);
71 } 69 }
72 70
73void EVP_SignUpdate(ctx,data,count) 71void EVP_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
74EVP_MD_CTX *ctx; 72 unsigned int count)
75unsigned char *data;
76unsigned int count;
77 { 73 {
78 EVP_DigestUpdate(ctx,data,count); 74 EVP_DigestUpdate(ctx,data,count);
79 } 75 }
80#endif 76#endif
81 77
82int EVP_SignFinal(ctx,sigret,siglen,pkey) 78int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
83EVP_MD_CTX *ctx; 79 EVP_PKEY *pkey)
84unsigned char *sigret;
85unsigned int *siglen;
86EVP_PKEY *pkey;
87 { 80 {
88 unsigned char m[EVP_MAX_MD_SIZE]; 81 unsigned char m[EVP_MAX_MD_SIZE];
89 unsigned int m_len; 82 unsigned int m_len;
@@ -91,7 +84,7 @@ EVP_PKEY *pkey;
91 MS_STATIC EVP_MD_CTX tmp_ctx; 84 MS_STATIC EVP_MD_CTX tmp_ctx;
92 85
93 *siglen=0; 86 *siglen=0;
94 memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); 87 EVP_MD_CTX_copy(&tmp_ctx,ctx);
95 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); 88 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len);
96 for (i=0; i<4; i++) 89 for (i=0; i<4; i++)
97 { 90 {
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/x509.h>
64 64
65int EVP_VerifyFinal(ctx,sigbuf,siglen,pkey) 65int EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf,
66EVP_MD_CTX *ctx; 66 unsigned int siglen, EVP_PKEY *pkey)
67unsigned char *sigbuf;
68unsigned int siglen;
69EVP_PKEY *pkey;
70 { 67 {
71 unsigned char m[EVP_MAX_MD_SIZE]; 68 unsigned char m[EVP_MAX_MD_SIZE];
72 unsigned int m_len; 69 unsigned int m_len;
@@ -88,7 +85,7 @@ EVP_PKEY *pkey;
88 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE); 85 EVPerr(EVP_F_EVP_VERIFYFINAL,EVP_R_WRONG_PUBLIC_KEY_TYPE);
89 return(-1); 86 return(-1);
90 } 87 }
91 memcpy(&tmp_ctx,ctx,sizeof(EVP_MD_CTX)); 88 EVP_MD_CTX_copy(&tmp_ctx,ctx);
92 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len); 89 EVP_DigestFinal(&tmp_ctx,&(m[0]),&m_len);
93 if (ctx->digest->verify == NULL) 90 if (ctx->digest->verify == NULL)
94 { 91 {
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "bio.h" 62#include <openssl/bio.h>
63#include "lhash.h" 63#include <openssl/lhash.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65 65
66int CRYPTO_get_ex_new_index(idx,skp,argl,argp,new_func,dup_func,free_func) 66int CRYPTO_get_ex_new_index(int idx, STACK **skp, long argl, char *argp,
67int idx; 67 int (*new_func)(), int (*dup_func)(), void (*free_func)())
68STACK **skp;
69long argl;
70char *argp;
71int (*new_func)();
72int (*dup_func)();
73void (*free_func)();
74 { 68 {
69 int ret= -1;
75 CRYPTO_EX_DATA_FUNCS *a; 70 CRYPTO_EX_DATA_FUNCS *a;
76 71
72 MemCheck_off();
77 if (*skp == NULL) 73 if (*skp == NULL)
78 *skp=sk_new_null(); 74 *skp=sk_new_null();
79 if (*skp == NULL) 75 if (*skp == NULL)
80 { 76 {
81 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); 77 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
82 return(-1); 78 goto err;
83 } 79 }
84 a=(CRYPTO_EX_DATA_FUNCS *)Malloc(sizeof(CRYPTO_EX_DATA_FUNCS)); 80 a=(CRYPTO_EX_DATA_FUNCS *)Malloc(sizeof(CRYPTO_EX_DATA_FUNCS));
85 if (a == NULL) 81 if (a == NULL)
86 { 82 {
87 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); 83 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
88 return(-1); 84 goto err;
89 } 85 }
90 a->argl=argl; 86 a->argl=argl;
91 a->argp=argp; 87 a->argp=argp;
@@ -98,17 +94,17 @@ void (*free_func)();
98 { 94 {
99 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE); 95 CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX,ERR_R_MALLOC_FAILURE);
100 Free(a); 96 Free(a);
101 return(-1); 97 goto err;
102 } 98 }
103 } 99 }
104 sk_value(*skp,idx)=(char *)a; 100 sk_set(*skp,idx, (char *)a);
101 ret=idx;
102err:
103 MemCheck_on();
105 return(idx); 104 return(idx);
106 } 105 }
107 106
108int CRYPTO_set_ex_data(ad,idx,val) 107int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, char *val)
109CRYPTO_EX_DATA *ad;
110int idx;
111char *val;
112 { 108 {
113 int i; 109 int i;
114 110
@@ -131,13 +127,11 @@ char *val;
131 } 127 }
132 i++; 128 i++;
133 } 129 }
134 sk_value(ad->sk,idx)=val; 130 sk_set(ad->sk,idx,val);
135 return(1); 131 return(1);
136 } 132 }
137 133
138char *CRYPTO_get_ex_data(ad,idx) 134char *CRYPTO_get_ex_data(CRYPTO_EX_DATA *ad, int idx)
139CRYPTO_EX_DATA *ad;
140int idx;
141 { 135 {
142 if (ad->sk == NULL) 136 if (ad->sk == NULL)
143 return(0); 137 return(0);
@@ -147,13 +141,12 @@ int idx;
147 return(sk_value(ad->sk,idx)); 141 return(sk_value(ad->sk,idx));
148 } 142 }
149 143
150/* The callback is called with the 'object', which is the origional data object 144/* The callback is called with the 'object', which is the original data object
151 * being duplicated, a pointer to the 145 * being duplicated, a pointer to the
152 * 'new' object to be inserted, the index, and the argi/argp 146 * 'new' object to be inserted, the index, and the argi/argp
153 */ 147 */
154int CRYPTO_dup_ex_data(meth,to,from) 148int CRYPTO_dup_ex_data(STACK *meth, CRYPTO_EX_DATA *to,
155STACK *meth; 149 CRYPTO_EX_DATA *from)
156CRYPTO_EX_DATA *to,*from;
157 { 150 {
158 int i,j,m,r; 151 int i,j,m,r;
159 CRYPTO_EX_DATA_FUNCS *mm; 152 CRYPTO_EX_DATA_FUNCS *mm;
@@ -179,10 +172,7 @@ CRYPTO_EX_DATA *to,*from;
179 } 172 }
180 173
181/* Call each free callback */ 174/* Call each free callback */
182void CRYPTO_free_ex_data(meth,obj,ad) 175void CRYPTO_free_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad)
183STACK *meth;
184char *obj;
185CRYPTO_EX_DATA *ad;
186 { 176 {
187 CRYPTO_EX_DATA_FUNCS *m; 177 CRYPTO_EX_DATA_FUNCS *m;
188 char *ptr; 178 char *ptr;
@@ -208,10 +198,7 @@ CRYPTO_EX_DATA *ad;
208 } 198 }
209 } 199 }
210 200
211void CRYPTO_new_ex_data(meth,obj,ad) 201void CRYPTO_new_ex_data(STACK *meth, char *obj, CRYPTO_EX_DATA *ad)
212STACK *meth;
213char *obj;
214CRYPTO_EX_DATA *ad;
215 { 202 {
216 CRYPTO_EX_DATA_FUNCS *m; 203 CRYPTO_EX_DATA_FUNCS *m;
217 char *ptr; 204 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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,28 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81hmac.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
82hmac.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
83hmac.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
84hmac.o: ../../include/openssl/des.h ../../include/openssl/dh.h
85hmac.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
86hmac.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
87hmac.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
88hmac.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
89hmac.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
90hmac.o: ../../include/openssl/opensslv.h ../../include/openssl/rc2.h
91hmac.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
92hmac.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
93hmac.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
94hmac.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 @@
58#include <stdio.h> 58#include <stdio.h>
59#include <stdlib.h> 59#include <stdlib.h>
60#include <string.h> 60#include <string.h>
61#include "hmac.h" 61#include <openssl/hmac.h>
62 62
63void HMAC_Init(ctx,key,len,md) 63void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
64HMAC_CTX *ctx; 64 const EVP_MD *md)
65unsigned char *key;
66int len;
67EVP_MD *md;
68 { 65 {
69 int i,j,reset=0; 66 int i,j,reset=0;
70 unsigned char pad[HMAC_MAX_MD_CBLOCK]; 67 unsigned char pad[HMAC_MAX_MD_CBLOCK];
@@ -112,18 +109,12 @@ EVP_MD *md;
112 memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx)); 109 memcpy(&ctx->md_ctx,&ctx->i_ctx,sizeof(ctx->i_ctx));
113 } 110 }
114 111
115void HMAC_Update(ctx,data,len) 112void HMAC_Update(HMAC_CTX *ctx, unsigned char *data, int len)
116HMAC_CTX *ctx;
117unsigned char *data;
118int len;
119 { 113 {
120 EVP_DigestUpdate(&(ctx->md_ctx),data,len); 114 EVP_DigestUpdate(&(ctx->md_ctx),data,len);
121 } 115 }
122 116
123void HMAC_Final(ctx,md,len) 117void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
124HMAC_CTX *ctx;
125unsigned char *md;
126unsigned int *len;
127 { 118 {
128 int j; 119 int j;
129 unsigned int i; 120 unsigned int i;
@@ -137,20 +128,14 @@ unsigned int *len;
137 EVP_DigestFinal(&(ctx->md_ctx),md,len); 128 EVP_DigestFinal(&(ctx->md_ctx),md,len);
138 } 129 }
139 130
140void HMAC_cleanup(ctx) 131void HMAC_cleanup(HMAC_CTX *ctx)
141HMAC_CTX *ctx;
142 { 132 {
143 memset(ctx,0,sizeof(HMAC_CTX)); 133 memset(ctx,0,sizeof(HMAC_CTX));
144 } 134 }
145 135
146unsigned char *HMAC(evp_md,key,key_len,d,n,md,md_len) 136unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
147EVP_MD *evp_md; 137 unsigned char *d, int n, unsigned char *md,
148unsigned char *key; 138 unsigned int *md_len)
149int key_len;
150unsigned char *d;
151int n;
152unsigned char *md;
153unsigned int *md_len;
154 { 139 {
155 HMAC_CTX c; 140 HMAC_CTX c;
156 static unsigned char m[EVP_MAX_MD_SIZE]; 141 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 @@
62extern "C" { 62extern "C" {
63#endif 63#endif
64 64
65#include "evp.h" 65#ifdef NO_HMAC
66#error HMAC is disabled.
67#endif
68
69#include <openssl/evp.h>
66 70
67#define HMAC_MAX_MD_CBLOCK 64 71#define HMAC_MAX_MD_CBLOCK 64
68 72
69typedef struct hmac_ctx_st 73typedef struct hmac_ctx_st
70 { 74 {
71 EVP_MD *md; 75 const EVP_MD *md;
72 EVP_MD_CTX md_ctx; 76 EVP_MD_CTX md_ctx;
73 EVP_MD_CTX i_ctx; 77 EVP_MD_CTX i_ctx;
74 EVP_MD_CTX o_ctx; 78 EVP_MD_CTX o_ctx;
@@ -78,26 +82,16 @@ typedef struct hmac_ctx_st
78 82
79#define HMAC_size(e) (EVP_MD_size((e)->md)) 83#define HMAC_size(e) (EVP_MD_size((e)->md))
80 84
81#ifndef NOPROTO
82 85
83void HMAC_Init(HMAC_CTX *ctx, unsigned char *key, int len, 86void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
84 EVP_MD *md); 87 const EVP_MD *md);
85void HMAC_Update(HMAC_CTX *ctx,unsigned char *key, int len); 88void HMAC_Update(HMAC_CTX *ctx,unsigned char *key, int len);
86void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 89void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
87void HMAC_cleanup(HMAC_CTX *ctx); 90void HMAC_cleanup(HMAC_CTX *ctx);
88unsigned char *HMAC(EVP_MD *evp_md, unsigned char *key, int key_len, 91unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
89 unsigned char *d, int n, unsigned char *md, unsigned int *md_len); 92 unsigned char *d, int n, unsigned char *md,
90 93 unsigned int *md_len);
91 94
92#else
93
94void HMAC_Init();
95void HMAC_Update();
96void HMAC_Final();
97void HMAC_cleanup();
98unsigned char *HMAC();
99
100#endif
101 95
102#ifdef __cplusplus 96#ifdef __cplusplus
103} 97}
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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include "hmac.h" 62
63#ifdef NO_HMAC
64int main(int argc, char *argv[])
65{
66 printf("No HMAC support\n");
67 return(0);
68}
69#else
70#include <openssl/hmac.h>
71
72#ifdef CHARSET_EBCDIC
73#include <openssl/ebcdic.h>
74#endif
63 75
64struct test_st 76struct test_st
65 { 77 {
@@ -102,19 +114,19 @@ struct test_st
102 }; 114 };
103 115
104 116
105#ifndef NOPROTO
106static char *pt(unsigned char *md); 117static char *pt(unsigned char *md);
107#else 118int main(int argc, char *argv[])
108static char *pt();
109#endif
110
111int main(argc,argv)
112int argc;
113char *argv[];
114 { 119 {
115 int i,err=0; 120 int i,err=0;
116 char *p; 121 char *p;
117 122
123#ifdef CHARSET_EBCDIC
124 ebcdic2ascii(test[0].data, test[0].data, test[0].data_len);
125 ebcdic2ascii(test[1].data, test[1].data, test[1].data_len);
126 ebcdic2ascii(test[2].key, test[2].key, test[2].key_len);
127 ebcdic2ascii(test[2].data, test[2].data, test[2].data_len);
128#endif
129
118 for (i=0; i<4; i++) 130 for (i=0; i<4; i++)
119 { 131 {
120 p=pt(HMAC(EVP_md5(), 132 p=pt(HMAC(EVP_md5(),
@@ -135,8 +147,7 @@ char *argv[];
135 return(0); 147 return(0);
136 } 148 }
137 149
138static char *pt(md) 150static char *pt(unsigned char *md)
139unsigned char *md;
140 { 151 {
141 int i; 152 int i;
142 static char buf[80]; 153 static char buf[80];
@@ -145,3 +156,4 @@ unsigned char *md;
145 sprintf(&(buf[i*2]),"%02x",md[i]); 156 sprintf(&(buf[i*2]),"%02x",md[i]);
146 return(buf); 157 return(buf);
147 } 158 }
159#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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,24 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81i_cbc.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
82i_cbc.o: idea_lcl.h
83i_cfb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
84i_cfb64.o: idea_lcl.h
85i_ecb.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
86i_ecb.o: ../../include/openssl/opensslv.h idea_lcl.h
87i_ofb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
88i_ofb64.o: idea_lcl.h
89i_skey.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
90i_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 @@
1/* crypto/idea/idea.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_IDEA_H
60#define HEADER_IDEA_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_IDEA
67#error IDEA is disabled.
68#endif
69
70#define IDEA_ENCRYPT 1
71#define IDEA_DECRYPT 0
72
73#include <openssl/opensslconf.h> /* IDEA_INT */
74#define IDEA_BLOCK 8
75#define IDEA_KEY_LENGTH 16
76
77typedef struct idea_key_st
78 {
79 IDEA_INT data[9][6];
80 } IDEA_KEY_SCHEDULE;
81
82const char *idea_options(void);
83void idea_ecb_encrypt(unsigned char *in, unsigned char *out,
84 IDEA_KEY_SCHEDULE *ks);
85void idea_set_encrypt_key(unsigned char *key, IDEA_KEY_SCHEDULE *ks);
86void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
87void idea_cbc_encrypt(unsigned char *in, unsigned char *out,
88 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc);
89void idea_cfb64_encrypt(unsigned char *in, unsigned char *out,
90 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,
91 int *num,int enc);
92void idea_ofb64_encrypt(unsigned char *in, unsigned char *out,
93 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv, int *num);
94void idea_encrypt(unsigned long *in, IDEA_KEY_SCHEDULE *ks);
95#ifdef __cplusplus
96}
97#endif
98
99#endif
diff --git a/src/lib/libcrypto/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 @@
1$! INSTALL.COM -- Installs the files in a given directory tree
2$!
3$! Author: Richard Levitte <richard@levitte.org>
4$! Time of creation: 22-MAY-1998 10:13
5$!
6$! P1 root of the directory tree
7$!
8$ IF P1 .EQS. ""
9$ THEN
10$ WRITE SYS$OUTPUT "First argument missing."
11$ WRITE SYS$OUTPUT "Should be the directory where you want things installed."
12$ EXIT
13$ ENDIF
14$
15$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
16$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
17$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
18 - "[000000." - "][" - "[" - "]"
19$ ROOT = ROOT_DEV + "[" + ROOT_DIR
20$
21$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
22$ DEFINE/NOLOG WRK_SSLVLIB WRK_SSLROOT:[VAX_LIB]
23$ DEFINE/NOLOG WRK_SSLALIB WRK_SSLROOT:[ALPHA_LIB]
24$ DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
25$
26$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
27 CREATE/DIR/LOG WRK_SSLROOT:[000000]
28$ IF F$PARSE("WRK_SSLVLIB:") .EQS. "" THEN -
29 CREATE/DIR/LOG WRK_SSLVLIB:
30$ IF F$PARSE("WRK_SSLALIB:") .EQS. "" THEN -
31 CREATE/DIR/LOG WRK_SSLALIB:
32$ IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
33 CREATE/DIR/LOG WRK_SSLINCLUDE:
34$
35$ SDIRS := ,MD2,MD5,SHA,MDC2,HMAC,RIPEMD,-
36 DES,RC2,RC4,RC5,IDEA,BF,CAST,-
37 BN,RSA,DSA,DH,-
38 BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,-
39 EVP,ASN1,PEM,X509,X509V3,-
40 CONF,TXT_DB,PKCS7,PKCS12,COMP
41$ EXHEADER_ := crypto.h,tmdiff.h,opensslv.h,opensslconf.h,ebcdic.h
42$ EXHEADER_MD2 := md2.h
43$ EXHEADER_MD5 := md5.h
44$ EXHEADER_SHA := sha.h
45$ EXHEADER_MDC2 := mdc2.h
46$ EXHEADER_HMAC := hmac.h
47$ EXHEADER_RIPEMD := ripemd.h
48$ EXHEADER_DES := des.h
49$ EXHEADER_RC2 := rc2.h
50$ EXHEADER_RC4 := rc4.h
51$ EXHEADER_RC5 := rc5.h
52$ EXHEADER_IDEA := idea.h
53$ EXHEADER_BF := blowfish.h
54$ EXHEADER_CAST := cast.h
55$ EXHEADER_BN := bn.h
56$ EXHEADER_RSA := rsa.h
57$ EXHEADER_DSA := dsa.h
58$ EXHEADER_DH := dh.h
59$ EXHEADER_BUFFER := buffer.h
60$ EXHEADER_BIO := bio.h
61$ EXHEADER_STACK := stack.h,safestack.h
62$ EXHEADER_LHASH := lhash.h
63$ EXHEADER_RAND := rand.h
64$ EXHEADER_ERR := err.h
65$ EXHEADER_OBJECTS := objects.h
66$ EXHEADER_EVP := evp.h
67$ EXHEADER_ASN1 := asn1.h,asn1_mac.h
68$ EXHEADER_PEM := pem.h,pem2.h
69$ EXHEADER_X509 := x509.h,x509_vfy.h
70$ EXHEADER_X509V3 := x509v3.h
71$ EXHEADER_CONF := conf.h
72$ EXHEADER_TXT_DB := txt_db.h
73$ EXHEADER_PKCS7 := pkcs7.h
74$ EXHEADER_PKCS12 := pkcs12.h
75$ EXHEADER_COMP := comp.h
76$ LIBS := LIBCRYPTO
77$
78$ VEXE_DIR := [-.VAX.EXE.CRYPTO]
79$ AEXE_DIR := [-.AXP.EXE.CRYPTO]
80$
81$ I = 0
82$ LOOP_SDIRS:
83$ D = F$EDIT(F$ELEMENT(I, ",", SDIRS),"TRIM")
84$ I = I + 1
85$ IF D .EQS. "," THEN GOTO LOOP_SDIRS_END
86$ tmp = EXHEADER_'D'
87$ IF D .EQS. ""
88$ THEN
89$ COPY 'tmp' WRK_SSLINCLUDE: /LOG
90$ ELSE
91$ COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG
92$ ENDIF
93$ GOTO LOOP_SDIRS
94$ LOOP_SDIRS_END:
95$
96$ I = 0
97$ LOOP_LIB:
98$ E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM")
99$ I = I + 1
100$ IF E .EQS. "," THEN GOTO LOOP_LIB_END
101$ SET NOON
102$ IF F$SEARCH(VEXE_DIR+E+".OLB") .NES. ""
103$ THEN
104$ COPY 'VEXE_DIR''E'.OLB WRK_SSLVLIB:'E'.OLB/log
105$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.OLB
106$ ENDIF
107$ ! Preparing for the time when we have shareable images
108$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. ""
109$ THEN
110$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVLIB:'E'.EXE/log
111$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.EXE
112$ ENDIF
113$ IF F$SEARCH(AEXE_DIR+E+".OLB") .NES. ""
114$ THEN
115$ COPY 'AEXE_DIR''E'.OLB WRK_SSLALIB:'E'.OLB/log
116$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.OLB
117$ ENDIF
118$ ! Preparing for the time when we have shareable images
119$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. ""
120$ THEN
121$ COPY 'AEXE_DIR''E'.EXE WRK_SSLALIB:'E'.EXE/log
122$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.EXE
123$ ENDIF
124$ SET ON
125$ GOTO LOOP_LIB
126$ LOOP_LIB_END:
127$
128$ 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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,22 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81lh_stats.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82lh_stats.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
85lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
86lh_stats.o: ../cryptlib.h
87lhash.o: ../../include/openssl/crypto.h ../../include/openssl/lhash.h
88lhash.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 @@
63 * and things should work as expected */ 63 * and things should work as expected */
64#include "cryptlib.h" 64#include "cryptlib.h"
65 65
66#include "lhash.h" 66#include <openssl/lhash.h>
67 67
68#ifndef HEADER_BIO_H 68#ifndef HEADER_BIO_H
69 69
70void lh_stats(lh, out) 70void lh_stats(LHASH *lh, FILE *out)
71LHASH *lh;
72FILE *out;
73 { 71 {
74 fprintf(out,"num_items = %lu\n",lh->num_items); 72 fprintf(out,"num_items = %lu\n",lh->num_items);
75 fprintf(out,"num_nodes = %u\n",lh->num_nodes); 73 fprintf(out,"num_nodes = %u\n",lh->num_nodes);
@@ -95,9 +93,7 @@ FILE *out;
95#endif 93#endif
96 } 94 }
97 95
98void lh_node_stats(lh, out) 96void lh_node_stats(LHASH *lh, FILE *out)
99LHASH *lh;
100FILE *out;
101 { 97 {
102 LHASH_NODE *n; 98 LHASH_NODE *n;
103 unsigned int i,num; 99 unsigned int i,num;
@@ -110,9 +106,7 @@ FILE *out;
110 } 106 }
111 } 107 }
112 108
113void lh_node_usage_stats(lh, out) 109void lh_node_usage_stats(LHASH *lh, FILE *out)
114LHASH *lh;
115FILE *out;
116 { 110 {
117 LHASH_NODE *n; 111 LHASH_NODE *n;
118 unsigned long num; 112 unsigned long num;
@@ -142,9 +136,7 @@ FILE *out;
142#else 136#else
143 137
144#ifndef NO_FP_API 138#ifndef NO_FP_API
145void lh_stats(lh,fp) 139void lh_stats(LHASH *lh, FILE *fp)
146LHASH *lh;
147FILE *fp;
148 { 140 {
149 BIO *bp; 141 BIO *bp;
150 142
@@ -156,9 +148,7 @@ FILE *fp;
156end:; 148end:;
157 } 149 }
158 150
159void lh_node_stats(lh,fp) 151void lh_node_stats(LHASH *lh, FILE *fp)
160LHASH *lh;
161FILE *fp;
162 { 152 {
163 BIO *bp; 153 BIO *bp;
164 154
@@ -170,9 +160,7 @@ FILE *fp;
170end:; 160end:;
171 } 161 }
172 162
173void lh_node_usage_stats(lh,fp) 163void lh_node_usage_stats(LHASH *lh, FILE *fp)
174LHASH *lh;
175FILE *fp;
176 { 164 {
177 BIO *bp; 165 BIO *bp;
178 166
@@ -186,9 +174,7 @@ end:;
186 174
187#endif 175#endif
188 176
189void lh_stats_bio(lh, out) 177void lh_stats_bio(LHASH *lh, BIO *out)
190LHASH *lh;
191BIO *out;
192 { 178 {
193 char buf[128]; 179 char buf[128];
194 180
@@ -236,9 +222,7 @@ BIO *out;
236#endif 222#endif
237 } 223 }
238 224
239void lh_node_stats_bio(lh, out) 225void lh_node_stats_bio(LHASH *lh, BIO *out)
240LHASH *lh;
241BIO *out;
242 { 226 {
243 LHASH_NODE *n; 227 LHASH_NODE *n;
244 unsigned int i,num; 228 unsigned int i,num;
@@ -253,9 +237,7 @@ BIO *out;
253 } 237 }
254 } 238 }
255 239
256void lh_node_usage_stats_bio(lh, out) 240void lh_node_usage_stats_bio(LHASH *lh, BIO *out)
257LHASH *lh;
258BIO *out;
259 { 241 {
260 LHASH_NODE *n; 242 LHASH_NODE *n;
261 unsigned long num; 243 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include "lhash.h" 62#include <openssl/lhash.h>
63 63
64main() 64main()
65 { 65 {
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59char *lh_version="lhash part of SSLeay 0.9.0b 29-Jun-1998";
60
61/* Code for dynamic hash table routines 59/* Code for dynamic hash table routines
62 * Author - Eric Young v 2.0 60 * Author - Eric Young v 2.0
63 * 61 *
62 * 2.2 eay - added #include "crypto.h" so the memory leak checking code is
63 * present. eay 18-Jun-98
64 *
65 * 2.1 eay - Added an 'error in last operation' flag. eay 6-May-98
66 *
64 * 2.0 eay - Fixed a bug that occured when using lh_delete 67 * 2.0 eay - Fixed a bug that occured when using lh_delete
65 * from inside lh_doall(). As entries were deleted, 68 * from inside lh_doall(). As entries were deleted,
66 * the 'table' was 'contract()ed', making some entries 69 * 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";
94#include <stdio.h> 97#include <stdio.h>
95#include <string.h> 98#include <string.h>
96#include <stdlib.h> 99#include <stdlib.h>
97#include "lhash.h" 100#include <openssl/crypto.h>
101#include <openssl/lhash.h>
102
103const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
98 104
99#undef MIN_NODES 105#undef MIN_NODES
100#define MIN_NODES 16 106#define MIN_NODES 16
101#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */ 107#define UP_LOAD (2*LH_LOAD_MULT) /* load times 256 (default 2) */
102#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */ 108#define DOWN_LOAD (LH_LOAD_MULT) /* load times 256 (default 1) */
103 109
104#ifndef NOPROTO
105 110
106#define P_CP char * 111#define P_CP char *
107#define P_CPP char *,char * 112#define P_CPP char *,char *
@@ -109,26 +114,14 @@ static void expand(LHASH *lh);
109static void contract(LHASH *lh); 114static void contract(LHASH *lh);
110static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash); 115static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash);
111 116
112#else 117LHASH *lh_new(unsigned long (*h)(), int (*c)())
113
114#define P_CP
115#define P_CPP
116static void expand();
117static void contract();
118static LHASH_NODE **getrn();
119
120#endif
121
122LHASH *lh_new(h, c)
123unsigned long (*h)();
124int (*c)();
125 { 118 {
126 LHASH *ret; 119 LHASH *ret;
127 int i; 120 int i;
128 121
129 if ((ret=(LHASH *)malloc(sizeof(LHASH))) == NULL) 122 if ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)
130 goto err0; 123 goto err0;
131 if ((ret->b=(LHASH_NODE **)malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL) 124 if ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
132 goto err1; 125 goto err1;
133 for (i=0; i<MIN_NODES; i++) 126 for (i=0; i<MIN_NODES; i++)
134 ret->b[i]=NULL; 127 ret->b[i]=NULL;
@@ -156,41 +149,43 @@ int (*c)();
156 ret->num_retrieve_miss=0; 149 ret->num_retrieve_miss=0;
157 ret->num_hash_comps=0; 150 ret->num_hash_comps=0;
158 151
152 ret->error=0;
159 return(ret); 153 return(ret);
160err1: 154err1:
161 free((char *)ret); 155 Free((char *)ret);
162err0: 156err0:
163 return(NULL); 157 return(NULL);
164 } 158 }
165 159
166void lh_free(lh) 160void lh_free(LHASH *lh)
167LHASH *lh;
168 { 161 {
169 unsigned int i; 162 unsigned int i;
170 LHASH_NODE *n,*nn; 163 LHASH_NODE *n,*nn;
171 164
165 if(lh == NULL)
166 return;
167
172 for (i=0; i<lh->num_nodes; i++) 168 for (i=0; i<lh->num_nodes; i++)
173 { 169 {
174 n=lh->b[i]; 170 n=lh->b[i];
175 while (n != NULL) 171 while (n != NULL)
176 { 172 {
177 nn=n->next; 173 nn=n->next;
178 free(n); 174 Free(n);
179 n=nn; 175 n=nn;
180 } 176 }
181 } 177 }
182 free((char *)lh->b); 178 Free((char *)lh->b);
183 free((char *)lh); 179 Free((char *)lh);
184 } 180 }
185 181
186char *lh_insert(lh, data) 182char *lh_insert(LHASH *lh, char *data)
187LHASH *lh;
188char *data;
189 { 183 {
190 unsigned long hash; 184 unsigned long hash;
191 LHASH_NODE *nn,**rn; 185 LHASH_NODE *nn,**rn;
192 char *ret; 186 char *ret;
193 187
188 lh->error=0;
194 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) 189 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
195 expand(lh); 190 expand(lh);
196 191
@@ -198,8 +193,11 @@ char *data;
198 193
199 if (*rn == NULL) 194 if (*rn == NULL)
200 { 195 {
201 if ((nn=(LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL) 196 if ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)
197 {
198 lh->error++;
202 return(NULL); 199 return(NULL);
200 }
203 nn->data=data; 201 nn->data=data;
204 nn->next=NULL; 202 nn->next=NULL;
205#ifndef NO_HASH_COMP 203#ifndef NO_HASH_COMP
@@ -219,14 +217,13 @@ char *data;
219 return(ret); 217 return(ret);
220 } 218 }
221 219
222char *lh_delete(lh, data) 220char *lh_delete(LHASH *lh, char *data)
223LHASH *lh;
224char *data;
225 { 221 {
226 unsigned long hash; 222 unsigned long hash;
227 LHASH_NODE *nn,**rn; 223 LHASH_NODE *nn,**rn;
228 char *ret; 224 char *ret;
229 225
226 lh->error=0;
230 rn=getrn(lh,data,&hash); 227 rn=getrn(lh,data,&hash);
231 228
232 if (*rn == NULL) 229 if (*rn == NULL)
@@ -239,7 +236,7 @@ char *data;
239 nn= *rn; 236 nn= *rn;
240 *rn=nn->next; 237 *rn=nn->next;
241 ret=nn->data; 238 ret=nn->data;
242 free((char *)nn); 239 Free((char *)nn);
243 lh->num_delete++; 240 lh->num_delete++;
244 } 241 }
245 242
@@ -251,14 +248,13 @@ char *data;
251 return(ret); 248 return(ret);
252 } 249 }
253 250
254char *lh_retrieve(lh, data) 251char *lh_retrieve(LHASH *lh, char *data)
255LHASH *lh;
256char *data;
257 { 252 {
258 unsigned long hash; 253 unsigned long hash;
259 LHASH_NODE **rn; 254 LHASH_NODE **rn;
260 char *ret; 255 char *ret;
261 256
257 lh->error=0;
262 rn=getrn(lh,data,&hash); 258 rn=getrn(lh,data,&hash);
263 259
264 if (*rn == NULL) 260 if (*rn == NULL)
@@ -274,17 +270,12 @@ char *data;
274 return(ret); 270 return(ret);
275 } 271 }
276 272
277void lh_doall(lh, func) 273void lh_doall(LHASH *lh, void (*func)())
278LHASH *lh;
279void (*func)();
280 { 274 {
281 lh_doall_arg(lh,func,NULL); 275 lh_doall_arg(lh,func,NULL);
282 } 276 }
283 277
284void lh_doall_arg(lh, func, arg) 278void lh_doall_arg(LHASH *lh, void (*func)(), char *arg)
285LHASH *lh;
286void (*func)();
287char *arg;
288 { 279 {
289 int i; 280 int i;
290 LHASH_NODE *a,*n; 281 LHASH_NODE *a,*n;
@@ -305,8 +296,7 @@ char *arg;
305 } 296 }
306 } 297 }
307 298
308static void expand(lh) 299static void expand(LHASH *lh)
309LHASH *lh;
310 { 300 {
311 LHASH_NODE **n,**n1,**n2,*np; 301 LHASH_NODE **n,**n1,**n2,*np;
312 unsigned int p,i,j; 302 unsigned int p,i,j;
@@ -342,11 +332,12 @@ LHASH *lh;
342 if ((lh->p) >= lh->pmax) 332 if ((lh->p) >= lh->pmax)
343 { 333 {
344 j=(int)lh->num_alloc_nodes*2; 334 j=(int)lh->num_alloc_nodes*2;
345 n=(LHASH_NODE **)realloc((char *)lh->b, 335 n=(LHASH_NODE **)Realloc((char *)lh->b,
346 (unsigned int)sizeof(LHASH_NODE *)*j); 336 (unsigned int)sizeof(LHASH_NODE *)*j);
347 if (n == NULL) 337 if (n == NULL)
348 { 338 {
349/* fputs("realloc error in lhash",stderr); */ 339/* fputs("realloc error in lhash",stderr); */
340 lh->error++;
350 lh->p=0; 341 lh->p=0;
351 return; 342 return;
352 } 343 }
@@ -361,8 +352,7 @@ LHASH *lh;
361 } 352 }
362 } 353 }
363 354
364static void contract(lh) 355static void contract(LHASH *lh)
365LHASH *lh;
366 { 356 {
367 LHASH_NODE **n,*n1,*np; 357 LHASH_NODE **n,*n1,*np;
368 358
@@ -370,11 +360,12 @@ LHASH *lh;
370 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */ 360 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
371 if (lh->p == 0) 361 if (lh->p == 0)
372 { 362 {
373 n=(LHASH_NODE **)realloc((char *)lh->b, 363 n=(LHASH_NODE **)Realloc((char *)lh->b,
374 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); 364 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
375 if (n == NULL) 365 if (n == NULL)
376 { 366 {
377/* fputs("realloc error in lhash",stderr); */ 367/* fputs("realloc error in lhash",stderr); */
368 lh->error++;
378 return; 369 return;
379 } 370 }
380 lh->num_contract_reallocs++; 371 lh->num_contract_reallocs++;
@@ -400,10 +391,7 @@ LHASH *lh;
400 } 391 }
401 } 392 }
402 393
403static LHASH_NODE **getrn(lh, data, rhash) 394static LHASH_NODE **getrn(LHASH *lh, char *data, unsigned long *rhash)
404LHASH *lh;
405char *data;
406unsigned long *rhash;
407 { 395 {
408 LHASH_NODE **ret,*n1; 396 LHASH_NODE **ret,*n1;
409 unsigned long hash,nn; 397 unsigned long hash,nn;
@@ -457,8 +445,7 @@ char *str;
457 * no collisions on /usr/dict/words and it distributes on %2^n quite 445 * no collisions on /usr/dict/words and it distributes on %2^n quite
458 * well, not as good as MD5, but still good. 446 * well, not as good as MD5, but still good.
459 */ 447 */
460unsigned long lh_strhash(c) 448unsigned long lh_strhash(const char *c)
461char *c;
462 { 449 {
463 unsigned long ret=0; 450 unsigned long ret=0;
464 long n; 451 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 @@
67extern "C" { 67extern "C" {
68#endif 68#endif
69 69
70#ifndef NO_FP_API
71#include <stdio.h>
72#endif
73
70typedef struct lhash_node_st 74typedef struct lhash_node_st
71 { 75 {
72 char *data; 76 char *data;
@@ -102,11 +106,16 @@ typedef struct lhash_st
102 unsigned long num_retrieve; 106 unsigned long num_retrieve;
103 unsigned long num_retrieve_miss; 107 unsigned long num_retrieve_miss;
104 unsigned long num_hash_comps; 108 unsigned long num_hash_comps;
109
110 int error;
105 } LHASH; 111 } LHASH;
106 112
107#define LH_LOAD_MULT 256 113#define LH_LOAD_MULT 256
108 114
109#ifndef NOPROTO 115/* Indicates a malloc() error in the last call, this is only bad
116 * in lh_insert(). */
117#define lh_error(lh) ((lh)->error)
118
110LHASH *lh_new(unsigned long (*h)(), int (*c)()); 119LHASH *lh_new(unsigned long (*h)(), int (*c)());
111void lh_free(LHASH *lh); 120void lh_free(LHASH *lh);
112char *lh_insert(LHASH *lh, char *data); 121char *lh_insert(LHASH *lh, char *data);
@@ -114,7 +123,7 @@ char *lh_delete(LHASH *lh, char *data);
114char *lh_retrieve(LHASH *lh, char *data); 123char *lh_retrieve(LHASH *lh, char *data);
115void lh_doall(LHASH *lh, void (*func)(/* char *b */)); 124void lh_doall(LHASH *lh, void (*func)(/* char *b */));
116void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg); 125void lh_doall_arg(LHASH *lh, void (*func)(/*char *a,char *b*/),char *arg);
117unsigned long lh_strhash(char *c); 126unsigned long lh_strhash(const char *c);
118 127
119#ifndef NO_FP_API 128#ifndef NO_FP_API
120void lh_stats(LHASH *lh, FILE *out); 129void lh_stats(LHASH *lh, FILE *out);
@@ -127,26 +136,6 @@ void lh_stats_bio(LHASH *lh, BIO *out);
127void lh_node_stats_bio(LHASH *lh, BIO *out); 136void lh_node_stats_bio(LHASH *lh, BIO *out);
128void lh_node_usage_stats_bio(LHASH *lh, BIO *out); 137void lh_node_usage_stats_bio(LHASH *lh, BIO *out);
129#endif 138#endif
130#else
131LHASH *lh_new();
132void lh_free();
133char *lh_insert();
134char *lh_delete();
135char *lh_retrieve();
136void lh_doall();
137void lh_doall_arg();
138unsigned long lh_strhash();
139
140#ifndef NO_FP_API
141void lh_stats();
142void lh_node_stats();
143void lh_node_usage_stats();
144#endif
145void lh_stats_bio();
146void lh_node_stats_bio();
147void lh_node_usage_stats_bio();
148#endif
149
150#ifdef __cplusplus 139#ifdef __cplusplus
151} 140}
152#endif 141#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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3#node 10 -> 4 3#node 10 -> 4
4 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 @@
1$!
2$! Compile crypto.c as several subset modules and insert in crypto-xxx.olb.
3$! If P1 is specifed, it specifies alternate list of subsets to compile.
4$!
5$ libname = "CRYPTO-AXP.OLB"
6$ subset_list = "LIB,ASN1,BN,BUFFER,CONF,DES,DH,DSA,ERROR,EVP,IDEA,LHASH,MD," + -
7 "METH,OBJECTS,PEM,RAND,RC,RSA,SHA,STACK,TXT_DB,X509"
8$ if p1 .nes. "" then subset_list = p1
9$!
10$ if f$getsyi("CPU") .lt. 128 then libname = "CRYPTO-VAX.OLB"
11$ if f$search(libname) .eqs. "" then library/create/object/log 'libname'
12$!
13$ cc = "cc/include=[-.include]/prefix=all" + P2
14$!
15$ i = 0
16$ next_subset:
17$ subset = f$element(i,",",subset_list)
18$ if subset .eqs. "," then goto done
19$ i = i + 1
20$ create crypto_'subset'.subset
21#include "crypto.c"
22$ ofile = "sys$disk:[]crypto_" + subset + ".obj"
23$ on warning then goto next_subset
24$ write sys$output "Compiling ", ofile
25$ cc /object='ofile' crypto_'subset'.subset -
26 /define=(CRYPTO_SUBSET,CRYPTO_'subset'_SUBSET)
27$ library/replace/log 'libname'/module=CRYPTO_'subset' 'ofile'
28$ goto next_subset
29$!
30$ done:
31$ 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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -20,7 +22,7 @@ TEST=md2test.c
20APPS= 22APPS=
21 23
22LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
23LIBSRC=md2_dgst.c md5_one.c 25LIBSRC=md2_dgst.c md2_one.c
24LIBOBJ=md2_dgst.o md2_one.o 26LIBOBJ=md2_dgst.o md2_one.o
25 27
26SRC= $(LIBSRC) 28SRC= $(LIBSRC)
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,22 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81md2_dgst.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h
82md2_dgst.o: ../../include/openssl/opensslv.h
83md2_one.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
84md2_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
85md2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
86md2_one.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h
87md2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
88md2_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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "md2.h" 61#include <openssl/md2.h>
62 62
63#define BUFSIZE 1024*16 63#define BUFSIZE 1024*16
64 64
65#ifndef NOPROTO
66void do_fp(FILE *f); 65void do_fp(FILE *f);
67void pt(unsigned char *md); 66void pt(unsigned char *md);
68int read(int, void *, unsigned int); 67int read(int, void *, unsigned int);
69void exit(int); 68void exit(int);
70#else 69int main(int argc, char *argv[])
71void do_fp();
72void pt();
73int read();
74void exit();
75#endif
76
77int main(argc, argv)
78int argc;
79char *argv[];
80 { 70 {
81 int i,err=0; 71 int i,err=0;
82 FILE *IN; 72 FILE *IN;
@@ -105,8 +95,7 @@ char *argv[];
105 return(err); 95 return(err);
106 } 96 }
107 97
108void do_fp(f) 98void do_fp(FILE *f)
109FILE *f;
110 { 99 {
111 MD2_CTX c; 100 MD2_CTX c;
112 unsigned char md[MD2_DIGEST_LENGTH]; 101 unsigned char md[MD2_DIGEST_LENGTH];
@@ -125,8 +114,7 @@ FILE *f;
125 pt(md); 114 pt(md);
126 } 115 }
127 116
128void pt(md) 117void pt(unsigned char *md)
129unsigned char *md;
130 { 118 {
131 int i; 119 int i;
132 120
diff --git a/src/lib/libcrypto/md2/md2.org b/src/lib/libcrypto/md2/md2.h
index 9f39933790..0d3592506c 100644
--- a/src/lib/libcrypto/md2/md2.org
+++ b/src/lib/libcrypto/md2/md2.h
@@ -1,4 +1,4 @@
1/* crypto/md/md2.org */ 1/* crypto/md/md2.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,15 +56,6 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify md2.org since md2.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67
68#ifndef HEADER_MD2_H 59#ifndef HEADER_MD2_H
69#define HEADER_MD2_H 60#define HEADER_MD2_H
70 61
@@ -72,10 +63,13 @@
72extern "C" { 63extern "C" {
73#endif 64#endif
74 65
66#ifdef NO_MD2
67#error MD2 is disabled.
68#endif
69
75#define MD2_DIGEST_LENGTH 16 70#define MD2_DIGEST_LENGTH 16
76#define MD2_BLOCK 16 71#define MD2_BLOCK 16
77 72#include <openssl/opensslconf.h> /* MD2_INT */
78#define MD2_INT unsigned int
79 73
80typedef struct MD2state_st 74typedef struct MD2state_st
81 { 75 {
@@ -85,20 +79,11 @@ typedef struct MD2state_st
85 MD2_INT state[MD2_BLOCK]; 79 MD2_INT state[MD2_BLOCK];
86 } MD2_CTX; 80 } MD2_CTX;
87 81
88#ifndef NOPROTO 82const char *MD2_options(void);
89char *MD2_options(void);
90void MD2_Init(MD2_CTX *c); 83void MD2_Init(MD2_CTX *c);
91void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len); 84void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len);
92void MD2_Final(unsigned char *md, MD2_CTX *c); 85void MD2_Final(unsigned char *md, MD2_CTX *c);
93unsigned char *MD2(unsigned char *d, unsigned long n,unsigned char *md); 86unsigned char *MD2(unsigned char *d, unsigned long n,unsigned char *md);
94#else
95char *MD2_options();
96void MD2_Init();
97void MD2_Update();
98void MD2_Final();
99unsigned char *MD2();
100#endif
101
102#ifdef __cplusplus 87#ifdef __cplusplus
103} 88}
104#endif 89#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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include "md2.h" 62#include <openssl/md2.h>
63#include <openssl/opensslv.h>
63 64
64char *MD2_version="MD2 part of SSLeay 0.9.0b 29-Jun-1998"; 65const char *MD2_version="MD2" OPENSSL_VERSION_PTEXT;
65 66
66/* Implemented from RFC1319 The MD2 Message-Digest Algorithm 67/* Implemented from RFC1319 The MD2 Message-Digest Algorithm
67 */ 68 */
68 69
69#define UCHAR unsigned char 70#define UCHAR unsigned char
70 71
71#ifndef NOPROTO
72static void md2_block(MD2_CTX *c, unsigned char *d); 72static void md2_block(MD2_CTX *c, unsigned char *d);
73#else
74static void md2_block();
75#endif
76
77/* The magic S table - I have converted it to hex since it is 73/* The magic S table - I have converted it to hex since it is
78 * basicaly just a random byte string. */ 74 * basicaly just a random byte string. */
79static MD2_INT S[256]={ 75static MD2_INT S[256]={
@@ -111,7 +107,7 @@ static MD2_INT S[256]={
111 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14, 107 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14,
112 }; 108 };
113 109
114char *MD2_options() 110const char *MD2_options(void)
115 { 111 {
116 if (sizeof(MD2_INT) == 1) 112 if (sizeof(MD2_INT) == 1)
117 return("md2(char)"); 113 return("md2(char)");
@@ -119,8 +115,7 @@ char *MD2_options()
119 return("md2(int)"); 115 return("md2(int)");
120 } 116 }
121 117
122void MD2_Init(c) 118void MD2_Init(MD2_CTX *c)
123MD2_CTX *c;
124 { 119 {
125 c->num=0; 120 c->num=0;
126 memset(c->state,0,MD2_BLOCK*sizeof(MD2_INT)); 121 memset(c->state,0,MD2_BLOCK*sizeof(MD2_INT));
@@ -128,10 +123,7 @@ MD2_CTX *c;
128 memset(c->data,0,MD2_BLOCK); 123 memset(c->data,0,MD2_BLOCK);
129 } 124 }
130 125
131void MD2_Update(c, data, len) 126void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len)
132MD2_CTX *c;
133register unsigned char *data;
134unsigned long len;
135 { 127 {
136 register UCHAR *p; 128 register UCHAR *p;
137 129
@@ -169,9 +161,7 @@ unsigned long len;
169 c->num=(int)len; 161 c->num=(int)len;
170 } 162 }
171 163
172static void md2_block(c, d) 164static void md2_block(MD2_CTX *c, unsigned char *d)
173MD2_CTX *c;
174unsigned char *d;
175 { 165 {
176 register MD2_INT t,*sp1,*sp2; 166 register MD2_INT t,*sp1,*sp2;
177 register int i,j; 167 register int i,j;
@@ -207,9 +197,7 @@ unsigned char *d;
207 memset(state,0,48*sizeof(MD2_INT)); 197 memset(state,0,48*sizeof(MD2_INT));
208 } 198 }
209 199
210void MD2_Final(md, c) 200void MD2_Final(unsigned char *md, MD2_CTX *c)
211unsigned char *md;
212MD2_CTX *c;
213 { 201 {
214 int i,v; 202 int i,v;
215 register UCHAR *cp; 203 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "md2.h" 61#include <openssl/md2.h>
62 62
63/* This is a separate file so that #defines in cryptlib.h can 63/* This is a separate file so that #defines in cryptlib.h can
64 * map my MD functions to different names */ 64 * map my MD functions to different names */
65 65
66unsigned char *MD2(d, n, md) 66unsigned char *MD2(unsigned char *d, unsigned long n, unsigned char *md)
67unsigned char *d;
68unsigned long n;
69unsigned char *md;
70 { 67 {
71 MD2_CTX c; 68 MD2_CTX c;
72 static unsigned char m[MD2_DIGEST_LENGTH]; 69 static unsigned char m[MD2_DIGEST_LENGTH];
73 70
74 if (md == NULL) md=m; 71 if (md == NULL) md=m;
75 MD2_Init(&c); 72 MD2_Init(&c);
73#ifndef CHARSET_EBCDIC
76 MD2_Update(&c,d,n); 74 MD2_Update(&c,d,n);
75#else
76 {
77 char temp[1024];
78 unsigned long chunk;
79
80 while (n > 0)
81 {
82 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
83 ebcdic2ascii(temp, d, chunk);
84 MD2_Update(&c,temp,chunk);
85 n -= chunk;
86 d += chunk;
87 }
88 }
89#endif
77 MD2_Final(md,&c); 90 MD2_Final(md,&c);
78 memset(&c,0,sizeof(c)); /* Security consideration */ 91 memset(&c,0,sizeof(c)); /* Security consideration */
79 return(md); 92 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include "md2.h" 62
63#ifdef NO_MD2
64int main(int argc, char *argv[])
65{
66 printf("No MD2 support\n");
67 return(0);
68}
69#else
70#include <openssl/md2.h>
71
72#ifdef CHARSET_EBCDIC
73#include <openssl/ebcdic.h>
74#endif
63 75
64char *test[]={ 76char *test[]={
65 "", 77 "",
@@ -82,15 +94,8 @@ char *ret[]={
82 "d5976f79d83d3a0dc9806c3c66f3efd8", 94 "d5976f79d83d3a0dc9806c3c66f3efd8",
83 }; 95 };
84 96
85#ifndef NOPROTO
86static char *pt(unsigned char *md); 97static char *pt(unsigned char *md);
87#else 98int main(int argc, char *argv[])
88static char *pt();
89#endif
90
91int main(argc,argv)
92int argc;
93char *argv[];
94 { 99 {
95 int i,err=0; 100 int i,err=0;
96 char **P,**R; 101 char **P,**R;
@@ -118,8 +123,7 @@ char *argv[];
118 return(0); 123 return(0);
119 } 124 }
120 125
121static char *pt(md) 126static char *pt(unsigned char *md)
122unsigned char *md;
123 { 127 {
124 int i; 128 int i;
125 static char buf[80]; 129 static char buf[80];
@@ -128,3 +132,4 @@ unsigned char *md;
128 sprintf(&(buf[i*2]),"%02x",md[i]); 132 sprintf(&(buf[i*2]),"%02x",md[i]);
129 return(buf); 133 return(buf);
130 } 134 }
135#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 @@
1/* crypto/md32_common.h */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/*
57 * This is a generic 32 bit "collector" for message digest algorithms.
58 * Whenever needed it collects input character stream into chunks of
59 * 32 bit values and invokes a block function that performs actual hash
60 * calculations.
61 *
62 * Porting guide.
63 *
64 * Obligatory macros:
65 *
66 * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN
67 * this macro defines byte order of input stream.
68 * HASH_CBLOCK
69 * size of a unit chunk HASH_BLOCK operates on.
70 * HASH_LONG
71 * has to be at lest 32 bit wide, if it's wider, then
72 * HASH_LONG_LOG2 *has to* be defined along
73 * HASH_CTX
74 * context structure that at least contains following
75 * members:
76 * typedef struct {
77 * ...
78 * HASH_LONG Nl,Nh;
79 * HASH_LONG data[HASH_LBLOCK];
80 * int num;
81 * ...
82 * } HASH_CTX;
83 * HASH_UPDATE
84 * name of "Update" function, implemented here.
85 * HASH_TRANSFORM
86 * name of "Transform" function, implemented here.
87 * HASH_FINAL
88 * name of "Final" function, implemented here.
89 * HASH_BLOCK_HOST_ORDER
90 * name of "block" function treating *aligned* input message
91 * in host byte order, implemented externally.
92 * HASH_BLOCK_DATA_ORDER
93 * name of "block" function treating *unaligned* input message
94 * in original (data) byte order, implemented externally (it
95 * actually is optional if data and host are of the same
96 * "endianess").
97 *
98 * Optional macros:
99 *
100 * B_ENDIAN or L_ENDIAN
101 * defines host byte-order.
102 * HASH_LONG_LOG2
103 * defaults to 2 if not states otherwise.
104 * HASH_LBLOCK
105 * assumed to be HASH_CBLOCK/4 if not stated otherwise.
106 * HASH_BLOCK_DATA_ORDER_ALIGNED
107 * alternative "block" function capable of treating
108 * aligned input message in original (data) order,
109 * implemented externally.
110 *
111 * MD5 example:
112 *
113 * #define DATA_ORDER_IS_LITTLE_ENDIAN
114 *
115 * #define HASH_LONG MD5_LONG
116 * #define HASH_LONG_LOG2 MD5_LONG_LOG2
117 * #define HASH_CTX MD5_CTX
118 * #define HASH_CBLOCK MD5_CBLOCK
119 * #define HASH_LBLOCK MD5_LBLOCK
120 * #define HASH_UPDATE MD5_Update
121 * #define HASH_TRANSFORM MD5_Transform
122 * #define HASH_FINAL MD5_Final
123 * #define HASH_BLOCK_HOST_ORDER md5_block_host_order
124 * #define HASH_BLOCK_DATA_ORDER md5_block_data_order
125 *
126 * <appro@fy.chalmers.se>
127 */
128
129#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
130#error "DATA_ORDER must be defined!"
131#endif
132
133#ifndef HASH_CBLOCK
134#error "HASH_CBLOCK must be defined!"
135#endif
136#ifndef HASH_LONG
137#error "HASH_LONG must be defined!"
138#endif
139#ifndef HASH_CTX
140#error "HASH_CTX must be defined!"
141#endif
142
143#ifndef HASH_UPDATE
144#error "HASH_UPDATE must be defined!"
145#endif
146#ifndef HASH_TRANSFORM
147#error "HASH_TRANSFORM must be defined!"
148#endif
149#ifndef HASH_FINAL
150#error "HASH_FINAL must be defined!"
151#endif
152
153#ifndef HASH_BLOCK_HOST_ORDER
154#error "HASH_BLOCK_HOST_ORDER must be defined!"
155#endif
156
157#if 0
158/*
159 * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
160 * isn't defined.
161 */
162#ifndef HASH_BLOCK_DATA_ORDER
163#error "HASH_BLOCK_DATA_ORDER must be defined!"
164#endif
165#endif
166
167#ifndef HASH_LBLOCK
168#define HASH_LBLOCK (HASH_CBLOCK/4)
169#endif
170
171#ifndef HASH_LONG_LOG2
172#define HASH_LONG_LOG2 2
173#endif
174
175/*
176 * Engage compiler specific rotate intrinsic function if available.
177 */
178#undef ROTATE
179#ifndef PEDANTIC
180# if defined(_MSC_VER)
181# define ROTATE(a,n) _lrotl(a,n)
182# elif defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM)
183 /*
184 * Some GNU C inline assembler templates. Note that these are
185 * rotates by *constant* number of bits! But that's exactly
186 * what we need here...
187 *
188 * <appro@fy.chalmers.se>
189 */
190# if defined(__i386)
191# define ROTATE(a,n) ({ register unsigned int ret; \
192 asm volatile ( \
193 "roll %1,%0" \
194 : "=r"(ret) \
195 : "I"(n), "0"(a) \
196 : "cc"); \
197 ret; \
198 })
199# elif defined(__powerpc)
200# define ROTATE(a,n) ({ register unsigned int ret; \
201 asm volatile ( \
202 "rlwinm %0,%1,%2,0,31" \
203 : "=r"(ret) \
204 : "r"(a), "I"(n)); \
205 ret; \
206 })
207# endif
208# endif
209
210/*
211 * Engage compiler specific "fetch in reverse byte order"
212 * intrinsic function if available.
213 */
214# if defined(__GNUC__) && __GNUC__>=2 && !defined(NO_ASM)
215 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
216# if defined(__i386) && !defined(I386_ONLY)
217# define BE_FETCH32(a) ({ register unsigned int l=(a);\
218 asm volatile ( \
219 "bswapl %0" \
220 : "=r"(l) : "0"(l)); \
221 l; \
222 })
223# elif defined(__powerpc)
224# define LE_FETCH32(a) ({ register unsigned int l; \
225 asm volatile ( \
226 "lwbrx %0,0,%1" \
227 : "=r"(l) \
228 : "r"(a)); \
229 l; \
230 })
231
232# elif defined(__sparc) && defined(ULTRASPARC)
233# define LE_FETCH32(a) ({ register unsigned int l; \
234 asm volatile ( \
235 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
236 : "=r"(l) \
237 : "r"(a)); \
238 l; \
239 })
240# endif
241# endif
242#endif /* PEDANTIC */
243
244#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */
245/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
246#ifdef ROTATE
247/* 5 instructions with rotate instruction, else 9 */
248#define REVERSE_FETCH32(a,l) ( \
249 l=*(const HASH_LONG *)(a), \
250 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
251 )
252#else
253/* 6 instructions with rotate instruction, else 8 */
254#define REVERSE_FETCH32(a,l) ( \
255 l=*(const HASH_LONG *)(a), \
256 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
257 ROTATE(l,16) \
258 )
259/*
260 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
261 * It's rewritten as above for two reasons:
262 * - RISCs aren't good at long constants and have to explicitely
263 * compose 'em with several (well, usually 2) instructions in a
264 * register before performing the actual operation and (as you
265 * already realized:-) having same constant should inspire the
266 * compiler to permanently allocate the only register for it;
267 * - most modern CPUs have two ALUs, but usually only one has
268 * circuitry for shifts:-( this minor tweak inspires compiler
269 * to schedule shift instructions in a better way...
270 *
271 * <appro@fy.chalmers.se>
272 */
273#endif
274#endif
275
276#ifndef ROTATE
277#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
278#endif
279
280/*
281 * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
282 * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
283 * and host are of the same "endianess". It's possible to mask
284 * this with blank #define HASH_BLOCK_DATA_ORDER though...
285 *
286 * <appro@fy.chalmers.se>
287 */
288#if defined(B_ENDIAN)
289# if defined(DATA_ORDER_IS_BIG_ENDIAN)
290# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
291# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
292# endif
293# elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
294# ifndef HOST_FETCH32
295# ifdef LE_FETCH32
296# define HOST_FETCH32(p,l) LE_FETCH32(p)
297# elif defined(REVERSE_FETCH32)
298# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
299# endif
300# endif
301# endif
302#elif defined(L_ENDIAN)
303# if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
304# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
305# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
306# endif
307# elif defined(DATA_ORDER_IS_BIG_ENDIAN)
308# ifndef HOST_FETCH32
309# ifdef BE_FETCH32
310# define HOST_FETCH32(p,l) BE_FETCH32(p)
311# elif defined(REVERSE_FETCH32)
312# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
313# endif
314# endif
315# endif
316#endif
317
318#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
319#ifndef HASH_BLOCK_DATA_ORDER
320#error "HASH_BLOCK_DATA_ORDER must be defined!"
321#endif
322#endif
323
324#if defined(DATA_ORDER_IS_BIG_ENDIAN)
325
326#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
327 l|=(((unsigned long)(*((c)++)))<<16), \
328 l|=(((unsigned long)(*((c)++)))<< 8), \
329 l|=(((unsigned long)(*((c)++))) ), \
330 l)
331#define HOST_p_c2l(c,l,n) { \
332 switch (n) { \
333 case 0: l =((unsigned long)(*((c)++)))<<24; \
334 case 1: l|=((unsigned long)(*((c)++)))<<16; \
335 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
336 case 3: l|=((unsigned long)(*((c)++))); \
337 } }
338#define HOST_p_c2l_p(c,l,sc,len) { \
339 switch (sc) { \
340 case 0: l =((unsigned long)(*((c)++)))<<24; \
341 if (--len == 0) break; \
342 case 1: l|=((unsigned long)(*((c)++)))<<16; \
343 if (--len == 0) break; \
344 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
345 } }
346/* NOTE the pointer is not incremented at the end of this */
347#define HOST_c2l_p(c,l,n) { \
348 l=0; (c)+=n; \
349 switch (n) { \
350 case 3: l =((unsigned long)(*(--(c))))<< 8; \
351 case 2: l|=((unsigned long)(*(--(c))))<<16; \
352 case 1: l|=((unsigned long)(*(--(c))))<<24; \
353 } }
354#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
355 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
356 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
357 *((c)++)=(unsigned char)(((l) )&0xff), \
358 l)
359
360#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
361
362#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
363 l|=(((unsigned long)(*((c)++)))<< 8), \
364 l|=(((unsigned long)(*((c)++)))<<16), \
365 l|=(((unsigned long)(*((c)++)))<<24), \
366 l)
367#define HOST_p_c2l(c,l,n) { \
368 switch (n) { \
369 case 0: l =((unsigned long)(*((c)++))); \
370 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
371 case 2: l|=((unsigned long)(*((c)++)))<<16; \
372 case 3: l|=((unsigned long)(*((c)++)))<<24; \
373 } }
374#define HOST_p_c2l_p(c,l,sc,len) { \
375 switch (sc) { \
376 case 0: l =((unsigned long)(*((c)++))); \
377 if (--len == 0) break; \
378 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
379 if (--len == 0) break; \
380 case 2: l|=((unsigned long)(*((c)++)))<<16; \
381 } }
382/* NOTE the pointer is not incremented at the end of this */
383#define HOST_c2l_p(c,l,n) { \
384 l=0; (c)+=n; \
385 switch (n) { \
386 case 3: l =((unsigned long)(*(--(c))))<<16; \
387 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
388 case 1: l|=((unsigned long)(*(--(c)))); \
389 } }
390#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
391 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
392 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
393 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
394 l)
395
396#endif
397
398/*
399 * Time for some action:-)
400 */
401
402void HASH_UPDATE (HASH_CTX *c, const unsigned char *data, unsigned long len)
403 {
404 register HASH_LONG * p;
405 register unsigned long l;
406 int sw,sc,ew,ec;
407
408 if (len==0) return;
409
410 l=(c->Nl+(len<<3))&0xffffffffL;
411 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
412 * Wei Dai <weidai@eskimo.com> for pointing it out. */
413 if (l < c->Nl) /* overflow */
414 c->Nh++;
415 c->Nh+=(len>>29);
416 c->Nl=l;
417
418 if (c->num != 0)
419 {
420 p=c->data;
421 sw=c->num>>2;
422 sc=c->num&0x03;
423
424 if ((c->num+len) >= HASH_CBLOCK)
425 {
426 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
427 for (; sw<HASH_LBLOCK; sw++)
428 {
429 HOST_c2l(data,l); p[sw]=l;
430 }
431 HASH_BLOCK_HOST_ORDER (c,p,1);
432 len-=(HASH_CBLOCK-c->num);
433 c->num=0;
434 /* drop through and do the rest */
435 }
436 else
437 {
438 c->num+=len;
439 if ((sc+len) < 4) /* ugly, add char's to a word */
440 {
441 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
442 }
443 else
444 {
445 ew=(c->num>>2);
446 ec=(c->num&0x03);
447 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
448 for (; sw < ew; sw++)
449 {
450 HOST_c2l(data,l); p[sw]=l;
451 }
452 if (ec)
453 {
454 HOST_c2l_p(data,l,ec); p[sw]=l;
455 }
456 }
457 return;
458 }
459 }
460
461 sw=len/HASH_CBLOCK;
462 if (sw > 0)
463 {
464#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
465 /*
466 * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
467 * only if sizeof(HASH_LONG)==4.
468 */
469 if ((((unsigned long)data)%4) == 0)
470 {
471 /* data is properly aligned so that we can cast it: */
472 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
473 sw*=HASH_CBLOCK;
474 data+=sw;
475 len-=sw;
476 }
477 else
478#if !defined(HASH_BLOCK_DATA_ORDER)
479 while (sw--)
480 {
481 memcpy (p=c->data,data,HASH_CBLOCK);
482 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
483 data+=HASH_CBLOCK;
484 len-=HASH_CBLOCK;
485 }
486#endif
487#endif
488#if defined(HASH_BLOCK_DATA_ORDER)
489 {
490 HASH_BLOCK_DATA_ORDER(c,data,sw);
491 sw*=HASH_CBLOCK;
492 data+=sw;
493 len-=sw;
494 }
495#endif
496 }
497
498 if (len!=0)
499 {
500 p = c->data;
501 c->num = len;
502 ew=len>>2; /* words to copy */
503 ec=len&0x03;
504 for (; ew; ew--,p++)
505 {
506 HOST_c2l(data,l); *p=l;
507 }
508 HOST_c2l_p(data,l,ec);
509 *p=l;
510 }
511 }
512
513
514void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
515 {
516#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
517 if ((((unsigned long)data)%4) == 0)
518 /* data is properly aligned so that we can cast it: */
519 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
520 else
521#if !defined(HASH_BLOCK_DATA_ORDER)
522 {
523 memcpy (c->data,data,HASH_CBLOCK);
524 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
525 }
526#endif
527#endif
528#if defined(HASH_BLOCK_DATA_ORDER)
529 HASH_BLOCK_DATA_ORDER (c,data,1);
530#endif
531 }
532
533
534void HASH_FINAL (unsigned char *md, HASH_CTX *c)
535 {
536 register HASH_LONG *p;
537 register unsigned long l;
538 register int i,j;
539 static const unsigned char end[4]={0x80,0x00,0x00,0x00};
540 const unsigned char *cp=end;
541
542 /* c->num should definitly have room for at least one more byte. */
543 p=c->data;
544 i=c->num>>2;
545 j=c->num&0x03;
546
547#if 0
548 /* purify often complains about the following line as an
549 * Uninitialized Memory Read. While this can be true, the
550 * following p_c2l macro will reset l when that case is true.
551 * This is because j&0x03 contains the number of 'valid' bytes
552 * already in p[i]. If and only if j&0x03 == 0, the UMR will
553 * occur but this is also the only time p_c2l will do
554 * l= *(cp++) instead of l|= *(cp++)
555 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
556 * 'potential bug' */
557#ifdef PURIFY
558 if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
559#endif
560 l=p[i];
561#else
562 l = (j==0) ? 0 : p[i];
563#endif
564 HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
565
566 if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
567 {
568 if (i<HASH_LBLOCK) p[i]=0;
569 HASH_BLOCK_HOST_ORDER (c,p,1);
570 i=0;
571 }
572 for (; i<(HASH_LBLOCK-2); i++)
573 p[i]=0;
574
575#if defined(DATA_ORDER_IS_BIG_ENDIAN)
576 p[HASH_LBLOCK-2]=c->Nh;
577 p[HASH_LBLOCK-1]=c->Nl;
578#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
579 p[HASH_LBLOCK-2]=c->Nl;
580 p[HASH_LBLOCK-1]=c->Nh;
581#endif
582 HASH_BLOCK_HOST_ORDER (c,p,1);
583
584 l=c->A; HOST_l2c(l,md);
585 l=c->B; HOST_l2c(l,md);
586 l=c->C; HOST_l2c(l,md);
587 l=c->D; HOST_l2c(l,md);
588
589 c->num=0;
590 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
591 * but I'm not worried :-)
592 memset((void *)c,0,sizeof(HASH_CTX));
593 */
594 }
diff --git a/src/lib/libcrypto/md5/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
8CPP= $(CC) -E 8CPP= $(CC) -E
9INCLUDES= 9INCLUDES=
10CFLAG=-g 10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
11INSTALLTOP=/usr/local/ssl 13INSTALLTOP=/usr/local/ssl
12MAKE= make -f Makefile.ssl 14MAKE= make -f Makefile.ssl
13MAKEDEPEND= makedepend -f Makefile.ssl 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
14MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
15AR= ar r 17AR= ar r
16 18
17MD5_ASM_OBJ= 19MD5_ASM_OBJ=
18 20
19CFLAGS= $(INCLUDES) $(CFLAG) 21CFLAGS= $(INCLUDES) $(CFLAG)
22ASFLAGS=$(CFLAGS)
20 23
21GENERAL=Makefile 24GENERAL=Makefile
22TEST=md5test.c 25TEST=md5test.c
@@ -40,7 +43,7 @@ all: lib
40 43
41lib: $(LIBOBJ) 44lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ) 45 $(AR) $(LIB) $(LIBOBJ)
43 sh $(TOP)/util/ranlib.sh $(LIB) 46 $(RANLIB) $(LIB)
44 @touch lib 47 @touch lib
45 48
46# elf 49# elf
@@ -59,26 +62,43 @@ asm/mx86-out.o: asm/mx86unix.cpp
59 62
60# bsdi 63# bsdi
61asm/mx86bsdi.o: asm/mx86unix.cpp 64asm/mx86bsdi.o: asm/mx86unix.cpp
62 $(CPP) -DBSDI asm/mx86unix.cpp | as -o asm/mx86bsdi.o 65 $(CPP) -DBSDI asm/mx86unix.cpp | sed 's/ :/:/' | as -o asm/mx86bsdi.o
63 66
64asm/mx86unix.cpp: 67asm/mx86unix.cpp: asm/md5-586.pl
65 (cd asm; perl md5-586.pl cpp >mx86unix.cpp) 68 (cd asm; $(PERL) md5-586.pl cpp >mx86unix.cpp)
69
70asm/md5-sparcv8plus.o: asm/md5-sparcv9.S
71 $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -c \
72 -o asm/md5-sparcv8plus.o asm/md5-sparcv9.S
73
74# Old GNU assembler doesn't understand V9 instructions, so we
75# hire /usr/ccs/bin/as to do the job. Note that option is called
76# *-gcc27, but even gcc 2>=8 users may experience similar problem
77# if they didn't bother to upgrade GNU assembler. Such users should
78# not choose this option, but be adviced to *remove* GNU assembler
79# or upgrade it.
80sm/md5-sparcv8plus-gcc27.o: asm/md5-sparcv9.S
81 $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -E asm/md5-sparcv9.S | \
82 /usr/ccs/bin/as -xarch=v8plus - -o asm/md5-sparcv8plus-gcc27.o
83
84asm/md5-sparcv9.o: asm/md5-sparcv9.S
85 $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -c \
86 -o asm/md5-sparcv9.o asm/md5-sparcv9.S
66 87
67files: 88files:
68 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 89 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
69 90
70links: 91links:
71 /bin/rm -f Makefile 92 @$(TOP)/util/point.sh Makefile.ssl Makefile
72 $(TOP)/util/point.sh Makefile.ssl Makefile ; 93 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
73 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 94 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
74 $(TOP)/util/mklink.sh ../../test $(TEST) 95 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
75 $(TOP)/util/mklink.sh ../../apps $(APPS)
76 96
77install: 97install:
78 @for i in $(EXHEADER) ; \ 98 @for i in $(EXHEADER) ; \
79 do \ 99 do \
80 (cp $$i $(INSTALLTOP)/include/$$i; \ 100 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
81 chmod 644 $(INSTALLTOP)/include/$$i ); \ 101 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
82 done; 102 done;
83 103
84tags: 104tags:
@@ -90,15 +110,17 @@ lint:
90 lint -DLINT $(INCLUDES) $(SRC)>fluff 110 lint -DLINT $(INCLUDES) $(SRC)>fluff
91 111
92depend: 112depend:
93 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 113 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
94 114
95dclean: 115dclean:
96 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 116 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
97 mv -f Makefile.new $(MAKEFILE) 117 mv -f Makefile.new $(MAKEFILE)
98 118
99clean: 119clean:
100 /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 120 rm -f asm/mx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
101
102errors:
103 121
104# DO NOT DELETE THIS LINE -- make depend depends on it. 122# DO NOT DELETE THIS LINE -- make depend depends on it.
123
124md5_dgst.o: ../../include/openssl/md5.h ../../include/openssl/opensslconf.h
125md5_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md5_locl.h
126md5_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
19MAKEDEPEND= makedepend 19MAKEDEPEND= makedepend
20MAKEFILE= Makefile.uni 20MAKEFILE= Makefile.uni
21AR= ar r 21AR= ar r
22RANLIB= ranlib
22 23
23MD5_ASM_OBJ= 24MD5_ASM_OBJ=
24 25
@@ -43,7 +44,7 @@ all: $(LIB) $(TEST) $(APPS)
43 44
44$(LIB): $(LIBOBJ) 45$(LIB): $(LIBOBJ)
45 $(AR) $(LIB) $(LIBOBJ) 46 $(AR) $(LIB) $(LIBOBJ)
46 sh $(TOP)/ranlib.sh $(LIB) 47 $(RANLIB) $(LIB)
47 48
48# elf 49# elf
49asm/mx86-elf.o: asm/mx86unix.cpp 50asm/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 @@
8 .386 8 .386
9.model FLAT 9.model FLAT
10_TEXT SEGMENT 10_TEXT SEGMENT
11PUBLIC _md5_block_x86 11PUBLIC _md5_block_asm_host_order
12 12
13_md5_block_x86 PROC NEAR 13_md5_block_asm_host_order PROC NEAR
14 push esi 14 push esi
15 push edi 15 push edi
16 mov edi, DWORD PTR 12[esp] 16 mov edi, DWORD PTR 12[esp]
17 mov esi, DWORD PTR 16[esp] 17 mov esi, DWORD PTR 16[esp]
18 mov ecx, DWORD PTR 20[esp] 18 mov ecx, DWORD PTR 20[esp]
19 push ebp 19 push ebp
20 shl ecx, 6
20 push ebx 21 push ebx
21 add ecx, esi 22 add ecx, esi
22 sub ecx, 64 23 sub ecx, 64
@@ -34,161 +35,161 @@ L000start:
34 xor edi, edx 35 xor edi, edx
35 and edi, ebx 36 and edi, ebx
36 lea eax, DWORD PTR 3614090360[ebp*1+eax] 37 lea eax, DWORD PTR 3614090360[ebp*1+eax]
37 mov ebp, DWORD PTR 4[esi]
38 xor edi, edx 38 xor edi, edx
39 add eax, edi 39 add eax, edi
40 mov edi, ebx 40 mov edi, ebx
41 rol eax, 7 41 rol eax, 7
42 mov ebp, DWORD PTR 4[esi]
42 add eax, ebx 43 add eax, ebx
43 ; R0 1 44 ; R0 1
44 xor edi, ecx 45 xor edi, ecx
45 and edi, eax 46 and edi, eax
46 lea edx, DWORD PTR 3905402710[ebp*1+edx] 47 lea edx, DWORD PTR 3905402710[ebp*1+edx]
47 mov ebp, DWORD PTR 8[esi]
48 xor edi, ecx 48 xor edi, ecx
49 add edx, edi 49 add edx, edi
50 mov edi, eax 50 mov edi, eax
51 rol edx, 12 51 rol edx, 12
52 mov ebp, DWORD PTR 8[esi]
52 add edx, eax 53 add edx, eax
53 ; R0 2 54 ; R0 2
54 xor edi, ebx 55 xor edi, ebx
55 and edi, edx 56 and edi, edx
56 lea ecx, DWORD PTR 606105819[ebp*1+ecx] 57 lea ecx, DWORD PTR 606105819[ebp*1+ecx]
57 mov ebp, DWORD PTR 12[esi]
58 xor edi, ebx 58 xor edi, ebx
59 add ecx, edi 59 add ecx, edi
60 mov edi, edx 60 mov edi, edx
61 rol ecx, 17 61 rol ecx, 17
62 mov ebp, DWORD PTR 12[esi]
62 add ecx, edx 63 add ecx, edx
63 ; R0 3 64 ; R0 3
64 xor edi, eax 65 xor edi, eax
65 and edi, ecx 66 and edi, ecx
66 lea ebx, DWORD PTR 3250441966[ebp*1+ebx] 67 lea ebx, DWORD PTR 3250441966[ebp*1+ebx]
67 mov ebp, DWORD PTR 16[esi]
68 xor edi, eax 68 xor edi, eax
69 add ebx, edi 69 add ebx, edi
70 mov edi, ecx 70 mov edi, ecx
71 rol ebx, 22 71 rol ebx, 22
72 mov ebp, DWORD PTR 16[esi]
72 add ebx, ecx 73 add ebx, ecx
73 ; R0 4 74 ; R0 4
74 xor edi, edx 75 xor edi, edx
75 and edi, ebx 76 and edi, ebx
76 lea eax, DWORD PTR 4118548399[ebp*1+eax] 77 lea eax, DWORD PTR 4118548399[ebp*1+eax]
77 mov ebp, DWORD PTR 20[esi]
78 xor edi, edx 78 xor edi, edx
79 add eax, edi 79 add eax, edi
80 mov edi, ebx 80 mov edi, ebx
81 rol eax, 7 81 rol eax, 7
82 mov ebp, DWORD PTR 20[esi]
82 add eax, ebx 83 add eax, ebx
83 ; R0 5 84 ; R0 5
84 xor edi, ecx 85 xor edi, ecx
85 and edi, eax 86 and edi, eax
86 lea edx, DWORD PTR 1200080426[ebp*1+edx] 87 lea edx, DWORD PTR 1200080426[ebp*1+edx]
87 mov ebp, DWORD PTR 24[esi]
88 xor edi, ecx 88 xor edi, ecx
89 add edx, edi 89 add edx, edi
90 mov edi, eax 90 mov edi, eax
91 rol edx, 12 91 rol edx, 12
92 mov ebp, DWORD PTR 24[esi]
92 add edx, eax 93 add edx, eax
93 ; R0 6 94 ; R0 6
94 xor edi, ebx 95 xor edi, ebx
95 and edi, edx 96 and edi, edx
96 lea ecx, DWORD PTR 2821735955[ebp*1+ecx] 97 lea ecx, DWORD PTR 2821735955[ebp*1+ecx]
97 mov ebp, DWORD PTR 28[esi]
98 xor edi, ebx 98 xor edi, ebx
99 add ecx, edi 99 add ecx, edi
100 mov edi, edx 100 mov edi, edx
101 rol ecx, 17 101 rol ecx, 17
102 mov ebp, DWORD PTR 28[esi]
102 add ecx, edx 103 add ecx, edx
103 ; R0 7 104 ; R0 7
104 xor edi, eax 105 xor edi, eax
105 and edi, ecx 106 and edi, ecx
106 lea ebx, DWORD PTR 4249261313[ebp*1+ebx] 107 lea ebx, DWORD PTR 4249261313[ebp*1+ebx]
107 mov ebp, DWORD PTR 32[esi]
108 xor edi, eax 108 xor edi, eax
109 add ebx, edi 109 add ebx, edi
110 mov edi, ecx 110 mov edi, ecx
111 rol ebx, 22 111 rol ebx, 22
112 mov ebp, DWORD PTR 32[esi]
112 add ebx, ecx 113 add ebx, ecx
113 ; R0 8 114 ; R0 8
114 xor edi, edx 115 xor edi, edx
115 and edi, ebx 116 and edi, ebx
116 lea eax, DWORD PTR 1770035416[ebp*1+eax] 117 lea eax, DWORD PTR 1770035416[ebp*1+eax]
117 mov ebp, DWORD PTR 36[esi]
118 xor edi, edx 118 xor edi, edx
119 add eax, edi 119 add eax, edi
120 mov edi, ebx 120 mov edi, ebx
121 rol eax, 7 121 rol eax, 7
122 mov ebp, DWORD PTR 36[esi]
122 add eax, ebx 123 add eax, ebx
123 ; R0 9 124 ; R0 9
124 xor edi, ecx 125 xor edi, ecx
125 and edi, eax 126 and edi, eax
126 lea edx, DWORD PTR 2336552879[ebp*1+edx] 127 lea edx, DWORD PTR 2336552879[ebp*1+edx]
127 mov ebp, DWORD PTR 40[esi]
128 xor edi, ecx 128 xor edi, ecx
129 add edx, edi 129 add edx, edi
130 mov edi, eax 130 mov edi, eax
131 rol edx, 12 131 rol edx, 12
132 mov ebp, DWORD PTR 40[esi]
132 add edx, eax 133 add edx, eax
133 ; R0 10 134 ; R0 10
134 xor edi, ebx 135 xor edi, ebx
135 and edi, edx 136 and edi, edx
136 lea ecx, DWORD PTR 4294925233[ebp*1+ecx] 137 lea ecx, DWORD PTR 4294925233[ebp*1+ecx]
137 mov ebp, DWORD PTR 44[esi]
138 xor edi, ebx 138 xor edi, ebx
139 add ecx, edi 139 add ecx, edi
140 mov edi, edx 140 mov edi, edx
141 rol ecx, 17 141 rol ecx, 17
142 mov ebp, DWORD PTR 44[esi]
142 add ecx, edx 143 add ecx, edx
143 ; R0 11 144 ; R0 11
144 xor edi, eax 145 xor edi, eax
145 and edi, ecx 146 and edi, ecx
146 lea ebx, DWORD PTR 2304563134[ebp*1+ebx] 147 lea ebx, DWORD PTR 2304563134[ebp*1+ebx]
147 mov ebp, DWORD PTR 48[esi]
148 xor edi, eax 148 xor edi, eax
149 add ebx, edi 149 add ebx, edi
150 mov edi, ecx 150 mov edi, ecx
151 rol ebx, 22 151 rol ebx, 22
152 mov ebp, DWORD PTR 48[esi]
152 add ebx, ecx 153 add ebx, ecx
153 ; R0 12 154 ; R0 12
154 xor edi, edx 155 xor edi, edx
155 and edi, ebx 156 and edi, ebx
156 lea eax, DWORD PTR 1804603682[ebp*1+eax] 157 lea eax, DWORD PTR 1804603682[ebp*1+eax]
157 mov ebp, DWORD PTR 52[esi]
158 xor edi, edx 158 xor edi, edx
159 add eax, edi 159 add eax, edi
160 mov edi, ebx 160 mov edi, ebx
161 rol eax, 7 161 rol eax, 7
162 mov ebp, DWORD PTR 52[esi]
162 add eax, ebx 163 add eax, ebx
163 ; R0 13 164 ; R0 13
164 xor edi, ecx 165 xor edi, ecx
165 and edi, eax 166 and edi, eax
166 lea edx, DWORD PTR 4254626195[ebp*1+edx] 167 lea edx, DWORD PTR 4254626195[ebp*1+edx]
167 mov ebp, DWORD PTR 56[esi]
168 xor edi, ecx 168 xor edi, ecx
169 add edx, edi 169 add edx, edi
170 mov edi, eax 170 mov edi, eax
171 rol edx, 12 171 rol edx, 12
172 mov ebp, DWORD PTR 56[esi]
172 add edx, eax 173 add edx, eax
173 ; R0 14 174 ; R0 14
174 xor edi, ebx 175 xor edi, ebx
175 and edi, edx 176 and edi, edx
176 lea ecx, DWORD PTR 2792965006[ebp*1+ecx] 177 lea ecx, DWORD PTR 2792965006[ebp*1+ecx]
177 mov ebp, DWORD PTR 60[esi]
178 xor edi, ebx 178 xor edi, ebx
179 add ecx, edi 179 add ecx, edi
180 mov edi, edx 180 mov edi, edx
181 rol ecx, 17 181 rol ecx, 17
182 mov ebp, DWORD PTR 60[esi]
182 add ecx, edx 183 add ecx, edx
183 ; R0 15 184 ; R0 15
184 xor edi, eax 185 xor edi, eax
185 and edi, ecx 186 and edi, ecx
186 lea ebx, DWORD PTR 1236535329[ebp*1+ebx] 187 lea ebx, DWORD PTR 1236535329[ebp*1+ebx]
187 mov ebp, DWORD PTR 4[esi]
188 xor edi, eax 188 xor edi, eax
189 add ebx, edi 189 add ebx, edi
190 mov edi, ecx 190 mov edi, ecx
191 rol ebx, 22 191 rol ebx, 22
192 mov ebp, DWORD PTR 4[esi]
192 add ebx, ecx 193 add ebx, ecx
193 ; 194 ;
194 ; R1 section 195 ; R1 section
@@ -359,8 +360,8 @@ L000start:
359 xor edi, ebx 360 xor edi, ebx
360 lea eax, DWORD PTR 4294588738[ebp*1+eax] 361 lea eax, DWORD PTR 4294588738[ebp*1+eax]
361 add eax, edi 362 add eax, edi
362 mov ebp, DWORD PTR 32[esi]
363 rol eax, 4 363 rol eax, 4
364 mov ebp, DWORD PTR 32[esi]
364 mov edi, ebx 365 mov edi, ebx
365 ; R2 33 366 ; R2 33
366 lea edx, DWORD PTR 2272392833[ebp*1+edx] 367 lea edx, DWORD PTR 2272392833[ebp*1+edx]
@@ -377,8 +378,8 @@ L000start:
377 xor edi, edx 378 xor edi, edx
378 lea ecx, DWORD PTR 1839030562[ebp*1+ecx] 379 lea ecx, DWORD PTR 1839030562[ebp*1+ecx]
379 add ecx, edi 380 add ecx, edi
380 mov ebp, DWORD PTR 56[esi]
381 rol ecx, 16 381 rol ecx, 16
382 mov ebp, DWORD PTR 56[esi]
382 mov edi, edx 383 mov edi, edx
383 ; R2 35 384 ; R2 35
384 lea ebx, DWORD PTR 4259657740[ebp*1+ebx] 385 lea ebx, DWORD PTR 4259657740[ebp*1+ebx]
@@ -395,8 +396,8 @@ L000start:
395 xor edi, ebx 396 xor edi, ebx
396 lea eax, DWORD PTR 2763975236[ebp*1+eax] 397 lea eax, DWORD PTR 2763975236[ebp*1+eax]
397 add eax, edi 398 add eax, edi
398 mov ebp, DWORD PTR 16[esi]
399 rol eax, 4 399 rol eax, 4
400 mov ebp, DWORD PTR 16[esi]
400 mov edi, ebx 401 mov edi, ebx
401 ; R2 37 402 ; R2 37
402 lea edx, DWORD PTR 1272893353[ebp*1+edx] 403 lea edx, DWORD PTR 1272893353[ebp*1+edx]
@@ -413,8 +414,8 @@ L000start:
413 xor edi, edx 414 xor edi, edx
414 lea ecx, DWORD PTR 4139469664[ebp*1+ecx] 415 lea ecx, DWORD PTR 4139469664[ebp*1+ecx]
415 add ecx, edi 416 add ecx, edi
416 mov ebp, DWORD PTR 40[esi]
417 rol ecx, 16 417 rol ecx, 16
418 mov ebp, DWORD PTR 40[esi]
418 mov edi, edx 419 mov edi, edx
419 ; R2 39 420 ; R2 39
420 lea ebx, DWORD PTR 3200236656[ebp*1+ebx] 421 lea ebx, DWORD PTR 3200236656[ebp*1+ebx]
@@ -431,8 +432,8 @@ L000start:
431 xor edi, ebx 432 xor edi, ebx
432 lea eax, DWORD PTR 681279174[ebp*1+eax] 433 lea eax, DWORD PTR 681279174[ebp*1+eax]
433 add eax, edi 434 add eax, edi
434 mov ebp, DWORD PTR [esi]
435 rol eax, 4 435 rol eax, 4
436 mov ebp, DWORD PTR [esi]
436 mov edi, ebx 437 mov edi, ebx
437 ; R2 41 438 ; R2 41
438 lea edx, DWORD PTR 3936430074[ebp*1+edx] 439 lea edx, DWORD PTR 3936430074[ebp*1+edx]
@@ -449,8 +450,8 @@ L000start:
449 xor edi, edx 450 xor edi, edx
450 lea ecx, DWORD PTR 3572445317[ebp*1+ecx] 451 lea ecx, DWORD PTR 3572445317[ebp*1+ecx]
451 add ecx, edi 452 add ecx, edi
452 mov ebp, DWORD PTR 24[esi]
453 rol ecx, 16 453 rol ecx, 16
454 mov ebp, DWORD PTR 24[esi]
454 mov edi, edx 455 mov edi, edx
455 ; R2 43 456 ; R2 43
456 lea ebx, DWORD PTR 76029189[ebp*1+ebx] 457 lea ebx, DWORD PTR 76029189[ebp*1+ebx]
@@ -467,8 +468,8 @@ L000start:
467 xor edi, ebx 468 xor edi, ebx
468 lea eax, DWORD PTR 3654602809[ebp*1+eax] 469 lea eax, DWORD PTR 3654602809[ebp*1+eax]
469 add eax, edi 470 add eax, edi
470 mov ebp, DWORD PTR 48[esi]
471 rol eax, 4 471 rol eax, 4
472 mov ebp, DWORD PTR 48[esi]
472 mov edi, ebx 473 mov edi, ebx
473 ; R2 45 474 ; R2 45
474 lea edx, DWORD PTR 3873151461[ebp*1+edx] 475 lea edx, DWORD PTR 3873151461[ebp*1+edx]
@@ -485,8 +486,8 @@ L000start:
485 xor edi, edx 486 xor edi, edx
486 lea ecx, DWORD PTR 530742520[ebp*1+ecx] 487 lea ecx, DWORD PTR 530742520[ebp*1+ecx]
487 add ecx, edi 488 add ecx, edi
488 mov ebp, DWORD PTR 8[esi]
489 rol ecx, 16 489 rol ecx, 16
490 mov ebp, DWORD PTR 8[esi]
490 mov edi, edx 491 mov edi, edx
491 ; R2 47 492 ; R2 47
492 lea ebx, DWORD PTR 3299628645[ebp*1+ebx] 493 lea ebx, DWORD PTR 3299628645[ebp*1+ebx]
@@ -681,6 +682,6 @@ L000start:
681 pop edi 682 pop edi
682 pop esi 683 pop esi
683 ret 684 ret
684_md5_block_x86 ENDP 685_md5_block_asm_host_order ENDP
685_TEXT ENDS 686_TEXT ENDS
686END 687END
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# Normal is the 3# Normal is the
4# md5_block_x86(MD5_CTX *c, ULONG *X); 4# md5_block_x86(MD5_CTX *c, ULONG *X);
@@ -29,7 +29,7 @@ $X="esi";
29 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3 29 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3
30 ); 30 );
31 31
32&md5_block("md5_block_x86"); 32&md5_block("md5_block_asm_host_order");
33&asm_finish(); 33&asm_finish();
34 34
35sub Np 35sub Np
@@ -44,7 +44,7 @@ sub R0
44 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; 44 local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
45 45
46 &mov($tmp1,$C) if $pos < 0; 46 &mov($tmp1,$C) if $pos < 0;
47 &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one 47 &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one
48 48
49 # body proper 49 # body proper
50 50
@@ -54,7 +54,6 @@ sub R0
54 &and($tmp1,$b); # F function - part 3 54 &and($tmp1,$b); # F function - part 3
55 &lea($a,&DWP($t,$a,$tmp2,1)); 55 &lea($a,&DWP($t,$a,$tmp2,1));
56 56
57 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
58 &xor($tmp1,$d); # F function - part 4 57 &xor($tmp1,$d); # F function - part 4
59 58
60 &add($a,$tmp1); 59 &add($a,$tmp1);
@@ -62,8 +61,10 @@ sub R0
62 &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1 61 &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1
63 62
64 &rotl($a,$s); 63 &rotl($a,$s);
65 &add($a,$b);
66 64
65 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
66
67 &add($a,$b);
67 } 68 }
68 69
69sub R1 70sub R1
@@ -100,16 +101,16 @@ if (($n & 1) == 0)
100 # make sure to do 'D' first, not 'B', else we clash with 101 # make sure to do 'D' first, not 'B', else we clash with
101 # the last add from the previous round. 102 # the last add from the previous round.
102 103
103 &xor($tmp1,$d); # H function - part 2 104 &xor($tmp1,$d); # H function - part 2
104 105
105 &xor($tmp1,$b); # H function - part 3 106 &xor($tmp1,$b); # H function - part 3
106 &lea($a,&DWP($t,$a,$tmp2,1)); 107 &lea($a,&DWP($t,$a,$tmp2,1));
107 108
108 &add($a,$tmp1); 109 &add($a,$tmp1);
109 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0));
110 110
111 &rotl($a,$s); 111 &rotl($a,$s);
112 112
113 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0));
113 &mov($tmp1,&Np($c)); 114 &mov($tmp1,&Np($c));
114 } 115 }
115else 116else
@@ -118,17 +119,17 @@ else
118 # make sure to do 'D' first, not 'B', else we clash with 119 # make sure to do 'D' first, not 'B', else we clash with
119 # the last add from the previous round. 120 # the last add from the previous round.
120 121
121 &lea($a,&DWP($t,$a,$tmp2,1)); 122 &lea($a,&DWP($t,$a,$tmp2,1));
122 123
123 &add($b,$c); # MOVED FORWARD 124 &add($b,$c); # MOVED FORWARD
124 &xor($tmp1,$d); # H function - part 2 125 &xor($tmp1,$d); # H function - part 2
125 126
126 &xor($tmp1,$b); # H function - part 3 127 &xor($tmp1,$b); # H function - part 3
127 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); 128 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);
128 129
129 &add($a,$tmp1); 130 &add($a,$tmp1);
130 &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1 131 &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1
131 &mov($tmp1,-1) if $pos == 1; # I function - part 1 132 &mov($tmp1,-1) if $pos == 1; # I function - part 1
132 133
133 &rotl($a,$s); 134 &rotl($a,$s);
134 135
@@ -146,21 +147,21 @@ sub R3
146 &xor($tmp1,$d) if $pos < 0; # I function - part 2 147 &xor($tmp1,$d) if $pos < 0; # I function - part 2
147 148
148 &or($tmp1,$b); # I function - part 3 149 &or($tmp1,$b); # I function - part 3
149 &lea($a,&DWP($t,$a,$tmp2,1)); 150 &lea($a,&DWP($t,$a,$tmp2,1));
150 151
151 &xor($tmp1,$c); # I function - part 4 152 &xor($tmp1,$c); # I function - part 4
152 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value 153 &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value
153 &mov($tmp2,&wparam(0)) if $pos == 2; 154 &mov($tmp2,&wparam(0)) if $pos == 2;
154 155
155 &add($a,$tmp1); 156 &add($a,$tmp1);
156 &mov($tmp1,-1) if $pos < 1; # H function - part 1 157 &mov($tmp1,-1) if $pos < 1; # H function - part 1
157 &add($K,64) if $pos >=1 && !$normal; 158 &add($K,64) if $pos >=1 && !$normal;
158 159
159 &rotl($a,$s); 160 &rotl($a,$s);
160 161
161 &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time 162 &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time
162 &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0; 163 &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0;
163 &add($a,$b); 164 &add($a,$b);
164 } 165 }
165 166
166 167
@@ -182,6 +183,7 @@ sub md5_block
182 &mov($X, &wparam(1)); # esi 183 &mov($X, &wparam(1)); # esi
183 &mov($C, &wparam(2)); 184 &mov($C, &wparam(2));
184 &push("ebp"); 185 &push("ebp");
186 &shl($C, 6);
185 &push("ebx"); 187 &push("ebx");
186 &add($C, $X); # offset we end at 188 &add($C, $X); # offset we end at
187 &sub($C, 64); 189 &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 @@
1.ident "md5-sparcv9.S, Version 1.0"
2.ident "SPARC V9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3.file "md5-sparcv9.S"
4
5/*
6 * ====================================================================
7 * Copyright (c) 1999 Andy Polyakov <appro@fy.chalmers.se>.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted as long as above copyright notices are retained. Warranty
11 * of any kind is (of course:-) disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contribution to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is an
18 * assembler implementation of MD5 block hash function. I've hand-coded
19 * this for the sole reason to reach UltraSPARC-specific "load in
20 * little-endian byte order" instruction. This gives up to 15%
21 * performance improvement for cases when input message is aligned at
22 * 32 bits boundary. The module was tested under both 32 *and* 64 bit
23 * kernels. For updates see http://fy.chalmers.se/~appro/hpe/.
24 *
25 * To compile with SC4.x/SC5.x:
26 *
27 * cc -xarch=v[9|8plus] -DULTRASPARC -DMD5_BLOCK_DATA_ORDER \
28 * -c md5-sparcv9.S
29 *
30 * and with gcc:
31 *
32 * gcc -mcpu=ultrasparc -DULTRASPARC -DMD5_BLOCK_DATA_ORDER \
33 * -c md5-sparcv9.S
34 *
35 * or if above fails (it does if you have gas):
36 *
37 * gcc -E -DULTRASPARC -DMD5_BLOCK_DATA_ORDER md5_block.sparc.S | \
38 * as -xarch=v8plus /dev/fd/0 -o md5-sparcv9.o
39 */
40
41#define A %o0
42#define B %o1
43#define C %o2
44#define D %o3
45#define T1 %o4
46#define T2 %o5
47
48#define R0 %l0
49#define R1 %l1
50#define R2 %l2
51#define R3 %l3
52#define R4 %l4
53#define R5 %l5
54#define R6 %l6
55#define R7 %l7
56#define R8 %i3
57#define R9 %i4
58#define R10 %i5
59#define R11 %g1
60#define R12 %g2
61#define R13 %g3
62#define RX %g4
63
64#define Aptr %i0+0
65#define Bptr %i0+4
66#define Cptr %i0+8
67#define Dptr %i0+12
68
69#define Aval R5 /* those not used at the end of the last round */
70#define Bval R6
71#define Cval R7
72#define Dval R8
73
74#if defined(MD5_BLOCK_DATA_ORDER)
75# if defined(ULTRASPARC)
76# define LOAD lda
77# define X(i) [%i1+i*4]%asi
78# define md5_block md5_block_asm_data_order_aligned
79# define ASI_PRIMARY_LITTLE 0x88
80# else
81# error "MD5_BLOCK_DATA_ORDER is supported only on UltraSPARC!"
82# endif
83#else
84# define LOAD ld
85# define X(i) [%i1+i*4]
86# define md5_block md5_block_asm_host_order
87#endif
88
89.section ".text",#alloc,#execinstr
90
91#if defined(__SUNPRO_C) && defined(__sparcv9)
92 /* They've said -xarch=v9 at command line */
93 .register %g2,#scratch
94 .register %g3,#scratch
95# define FRAME -192
96#elif defined(__GNUC__) && defined(__arch64__)
97 /* They've said -m64 at command line */
98 .register %g2,#scratch
99 .register %g3,#scratch
100# define FRAME -192
101#else
102# define FRAME -96
103#endif
104
105.align 32
106
107.global md5_block
108md5_block:
109 save %sp,FRAME,%sp
110
111 ld [Dptr],D
112 ld [Cptr],C
113 ld [Bptr],B
114 ld [Aptr],A
115#ifdef ASI_PRIMARY_LITTLE
116 rd %asi,%o7 ! How dare I? Well, I just do:-)
117 wr %g0,ASI_PRIMARY_LITTLE,%asi
118#endif
119 LOAD X(0),R0
120
121.Lmd5_block_loop:
122
123!!!!!!!!Round 0
124
125 xor C,D,T1
126 sethi %hi(0xd76aa478),T2
127 and T1,B,T1
128 or T2,%lo(0xd76aa478),T2 !=
129 xor T1,D,T1
130 add T1,R0,T1
131 LOAD X(1),R1
132 add T1,T2,T1 !=
133 add A,T1,A
134 sll A,7,T2
135 srl A,32-7,A
136 or A,T2,A !=
137 xor B,C,T1
138 add A,B,A
139
140 sethi %hi(0xe8c7b756),T2
141 and T1,A,T1 !=
142 or T2,%lo(0xe8c7b756),T2
143 xor T1,C,T1
144 LOAD X(2),R2
145 add T1,R1,T1 !=
146 add T1,T2,T1
147 add D,T1,D
148 sll D,12,T2
149 srl D,32-12,D !=
150 or D,T2,D
151 xor A,B,T1
152 add D,A,D
153
154 sethi %hi(0x242070db),T2 !=
155 and T1,D,T1
156 or T2,%lo(0x242070db),T2
157 xor T1,B,T1
158 add T1,R2,T1 !=
159 LOAD X(3),R3
160 add T1,T2,T1
161 add C,T1,C
162 sll C,17,T2 !=
163 srl C,32-17,C
164 or C,T2,C
165 xor D,A,T1
166 add C,D,C !=
167
168 sethi %hi(0xc1bdceee),T2
169 and T1,C,T1
170 or T2,%lo(0xc1bdceee),T2
171 xor T1,A,T1 !=
172 add T1,R3,T1
173 LOAD X(4),R4
174 add T1,T2,T1
175 add B,T1,B !=
176 sll B,22,T2
177 srl B,32-22,B
178 or B,T2,B
179 xor C,D,T1 !=
180 add B,C,B
181
182 sethi %hi(0xf57c0faf),T2
183 and T1,B,T1
184 or T2,%lo(0xf57c0faf),T2 !=
185 xor T1,D,T1
186 add T1,R4,T1
187 LOAD X(5),R5
188 add T1,T2,T1 !=
189 add A,T1,A
190 sll A,7,T2
191 srl A,32-7,A
192 or A,T2,A !=
193 xor B,C,T1
194 add A,B,A
195
196 sethi %hi(0x4787c62a),T2
197 and T1,A,T1 !=
198 or T2,%lo(0x4787c62a),T2
199 xor T1,C,T1
200 LOAD X(6),R6
201 add T1,R5,T1 !=
202 add T1,T2,T1
203 add D,T1,D
204 sll D,12,T2
205 srl D,32-12,D !=
206 or D,T2,D
207 xor A,B,T1
208 add D,A,D
209
210 sethi %hi(0xa8304613),T2 !=
211 and T1,D,T1
212 or T2,%lo(0xa8304613),T2
213 xor T1,B,T1
214 add T1,R6,T1 !=
215 LOAD X(7),R7
216 add T1,T2,T1
217 add C,T1,C
218 sll C,17,T2 !=
219 srl C,32-17,C
220 or C,T2,C
221 xor D,A,T1
222 add C,D,C !=
223
224 sethi %hi(0xfd469501),T2
225 and T1,C,T1
226 or T2,%lo(0xfd469501),T2
227 xor T1,A,T1 !=
228 add T1,R7,T1
229 LOAD X(8),R8
230 add T1,T2,T1
231 add B,T1,B !=
232 sll B,22,T2
233 srl B,32-22,B
234 or B,T2,B
235 xor C,D,T1 !=
236 add B,C,B
237
238 sethi %hi(0x698098d8),T2
239 and T1,B,T1
240 or T2,%lo(0x698098d8),T2 !=
241 xor T1,D,T1
242 add T1,R8,T1
243 LOAD X(9),R9
244 add T1,T2,T1 !=
245 add A,T1,A
246 sll A,7,T2
247 srl A,32-7,A
248 or A,T2,A !=
249 xor B,C,T1
250 add A,B,A
251
252 sethi %hi(0x8b44f7af),T2
253 and T1,A,T1 !=
254 or T2,%lo(0x8b44f7af),T2
255 xor T1,C,T1
256 LOAD X(10),R10
257 add T1,R9,T1 !=
258 add T1,T2,T1
259 add D,T1,D
260 sll D,12,T2
261 srl D,32-12,D !=
262 or D,T2,D
263 xor A,B,T1
264 add D,A,D
265
266 sethi %hi(0xffff5bb1),T2 !=
267 and T1,D,T1
268 or T2,%lo(0xffff5bb1),T2
269 xor T1,B,T1
270 add T1,R10,T1 !=
271 LOAD X(11),R11
272 add T1,T2,T1
273 add C,T1,C
274 sll C,17,T2 !=
275 srl C,32-17,C
276 or C,T2,C
277 xor D,A,T1
278 add C,D,C !=
279
280 sethi %hi(0x895cd7be),T2
281 and T1,C,T1
282 or T2,%lo(0x895cd7be),T2
283 xor T1,A,T1 !=
284 add T1,R11,T1
285 LOAD X(12),R12
286 add T1,T2,T1
287 add B,T1,B !=
288 sll B,22,T2
289 srl B,32-22,B
290 or B,T2,B
291 xor C,D,T1 !=
292 add B,C,B
293
294 sethi %hi(0x6b901122),T2
295 and T1,B,T1
296 or T2,%lo(0x6b901122),T2 !=
297 xor T1,D,T1
298 add T1,R12,T1
299 LOAD X(13),R13
300 add T1,T2,T1 !=
301 add A,T1,A
302 sll A,7,T2
303 srl A,32-7,A
304 or A,T2,A !=
305 xor B,C,T1
306 add A,B,A
307
308 sethi %hi(0xfd987193),T2
309 and T1,A,T1 !=
310 or T2,%lo(0xfd987193),T2
311 xor T1,C,T1
312 LOAD X(14),RX
313 add T1,R13,T1 !=
314 add T1,T2,T1
315 add D,T1,D
316 sll D,12,T2
317 srl D,32-12,D !=
318 or D,T2,D
319 xor A,B,T1
320 add D,A,D
321
322 sethi %hi(0xa679438e),T2 !=
323 and T1,D,T1
324 or T2,%lo(0xa679438e),T2
325 xor T1,B,T1
326 add T1,RX,T1 !=
327 LOAD X(15),RX
328 add T1,T2,T1
329 add C,T1,C
330 sll C,17,T2 !=
331 srl C,32-17,C
332 or C,T2,C
333 xor D,A,T1
334 add C,D,C !=
335
336 sethi %hi(0x49b40821),T2
337 and T1,C,T1
338 or T2,%lo(0x49b40821),T2
339 xor T1,A,T1 !=
340 add T1,RX,T1
341 !pre-LOADed X(1),R1
342 add T1,T2,T1
343 add B,T1,B
344 sll B,22,T2 !=
345 srl B,32-22,B
346 or B,T2,B
347 add B,C,B
348
349!!!!!!!!Round 1
350
351 xor B,C,T1 !=
352 sethi %hi(0xf61e2562),T2
353 and T1,D,T1
354 or T2,%lo(0xf61e2562),T2
355 xor T1,C,T1 !=
356 add T1,R1,T1
357 !pre-LOADed X(6),R6
358 add T1,T2,T1
359 add A,T1,A
360 sll A,5,T2 !=
361 srl A,32-5,A
362 or A,T2,A
363 add A,B,A
364
365 xor A,B,T1 !=
366 sethi %hi(0xc040b340),T2
367 and T1,C,T1
368 or T2,%lo(0xc040b340),T2
369 xor T1,B,T1 !=
370 add T1,R6,T1
371 !pre-LOADed X(11),R11
372 add T1,T2,T1
373 add D,T1,D
374 sll D,9,T2 !=
375 srl D,32-9,D
376 or D,T2,D
377 add D,A,D
378
379 xor D,A,T1 !=
380 sethi %hi(0x265e5a51),T2
381 and T1,B,T1
382 or T2,%lo(0x265e5a51),T2
383 xor T1,A,T1 !=
384 add T1,R11,T1
385 !pre-LOADed X(0),R0
386 add T1,T2,T1
387 add C,T1,C
388 sll C,14,T2 !=
389 srl C,32-14,C
390 or C,T2,C
391 add C,D,C
392
393 xor C,D,T1 !=
394 sethi %hi(0xe9b6c7aa),T2
395 and T1,A,T1
396 or T2,%lo(0xe9b6c7aa),T2
397 xor T1,D,T1 !=
398 add T1,R0,T1
399 !pre-LOADed X(5),R5
400 add T1,T2,T1
401 add B,T1,B
402 sll B,20,T2 !=
403 srl B,32-20,B
404 or B,T2,B
405 add B,C,B
406
407 xor B,C,T1 !=
408 sethi %hi(0xd62f105d),T2
409 and T1,D,T1
410 or T2,%lo(0xd62f105d),T2
411 xor T1,C,T1 !=
412 add T1,R5,T1
413 !pre-LOADed X(10),R10
414 add T1,T2,T1
415 add A,T1,A
416 sll A,5,T2 !=
417 srl A,32-5,A
418 or A,T2,A
419 add A,B,A
420
421 xor A,B,T1 !=
422 sethi %hi(0x02441453),T2
423 and T1,C,T1
424 or T2,%lo(0x02441453),T2
425 xor T1,B,T1 !=
426 add T1,R10,T1
427 LOAD X(15),RX
428 add T1,T2,T1
429 add D,T1,D !=
430 sll D,9,T2
431 srl D,32-9,D
432 or D,T2,D
433 add D,A,D !=
434
435 xor D,A,T1
436 sethi %hi(0xd8a1e681),T2
437 and T1,B,T1
438 or T2,%lo(0xd8a1e681),T2 !=
439 xor T1,A,T1
440 add T1,RX,T1
441 !pre-LOADed X(4),R4
442 add T1,T2,T1
443 add C,T1,C !=
444 sll C,14,T2
445 srl C,32-14,C
446 or C,T2,C
447 add C,D,C !=
448
449 xor C,D,T1
450 sethi %hi(0xe7d3fbc8),T2
451 and T1,A,T1
452 or T2,%lo(0xe7d3fbc8),T2 !=
453 xor T1,D,T1
454 add T1,R4,T1
455 !pre-LOADed X(9),R9
456 add T1,T2,T1
457 add B,T1,B !=
458 sll B,20,T2
459 srl B,32-20,B
460 or B,T2,B
461 add B,C,B !=
462
463 xor B,C,T1
464 sethi %hi(0x21e1cde6),T2
465 and T1,D,T1
466 or T2,%lo(0x21e1cde6),T2 !=
467 xor T1,C,T1
468 add T1,R9,T1
469 LOAD X(14),RX
470 add T1,T2,T1 !=
471 add A,T1,A
472 sll A,5,T2
473 srl A,32-5,A
474 or A,T2,A !=
475 add A,B,A
476
477 xor A,B,T1
478 sethi %hi(0xc33707d6),T2
479 and T1,C,T1 !=
480 or T2,%lo(0xc33707d6),T2
481 xor T1,B,T1
482 add T1,RX,T1
483 !pre-LOADed X(3),R3
484 add T1,T2,T1 !=
485 add D,T1,D
486 sll D,9,T2
487 srl D,32-9,D
488 or D,T2,D !=
489 add D,A,D
490
491 xor D,A,T1
492 sethi %hi(0xf4d50d87),T2
493 and T1,B,T1 !=
494 or T2,%lo(0xf4d50d87),T2
495 xor T1,A,T1
496 add T1,R3,T1
497 !pre-LOADed X(8),R8
498 add T1,T2,T1 !=
499 add C,T1,C
500 sll C,14,T2
501 srl C,32-14,C
502 or C,T2,C !=
503 add C,D,C
504
505 xor C,D,T1
506 sethi %hi(0x455a14ed),T2
507 and T1,A,T1 !=
508 or T2,%lo(0x455a14ed),T2
509 xor T1,D,T1
510 add T1,R8,T1
511 !pre-LOADed X(13),R13
512 add T1,T2,T1 !=
513 add B,T1,B
514 sll B,20,T2
515 srl B,32-20,B
516 or B,T2,B !=
517 add B,C,B
518
519 xor B,C,T1
520 sethi %hi(0xa9e3e905),T2
521 and T1,D,T1 !=
522 or T2,%lo(0xa9e3e905),T2
523 xor T1,C,T1
524 add T1,R13,T1
525 !pre-LOADed X(2),R2
526 add T1,T2,T1 !=
527 add A,T1,A
528 sll A,5,T2
529 srl A,32-5,A
530 or A,T2,A !=
531 add A,B,A
532
533 xor A,B,T1
534 sethi %hi(0xfcefa3f8),T2
535 and T1,C,T1 !=
536 or T2,%lo(0xfcefa3f8),T2
537 xor T1,B,T1
538 add T1,R2,T1
539 !pre-LOADed X(7),R7
540 add T1,T2,T1 !=
541 add D,T1,D
542 sll D,9,T2
543 srl D,32-9,D
544 or D,T2,D !=
545 add D,A,D
546
547 xor D,A,T1
548 sethi %hi(0x676f02d9),T2
549 and T1,B,T1 !=
550 or T2,%lo(0x676f02d9),T2
551 xor T1,A,T1
552 add T1,R7,T1
553 !pre-LOADed X(12),R12
554 add T1,T2,T1 !=
555 add C,T1,C
556 sll C,14,T2
557 srl C,32-14,C
558 or C,T2,C !=
559 add C,D,C
560
561 xor C,D,T1
562 sethi %hi(0x8d2a4c8a),T2
563 and T1,A,T1 !=
564 or T2,%lo(0x8d2a4c8a),T2
565 xor T1,D,T1
566 add T1,R12,T1
567 !pre-LOADed X(5),R5
568 add T1,T2,T1 !=
569 add B,T1,B
570 sll B,20,T2
571 srl B,32-20,B
572 or B,T2,B !=
573 add B,C,B
574
575!!!!!!!!Round 2
576
577 xor B,C,T1
578 sethi %hi(0xfffa3942),T2
579 xor T1,D,T1 !=
580 or T2,%lo(0xfffa3942),T2
581 add T1,R5,T1
582 !pre-LOADed X(8),R8
583 add T1,T2,T1
584 add A,T1,A !=
585 sll A,4,T2
586 srl A,32-4,A
587 or A,T2,A
588 add A,B,A !=
589
590 xor A,B,T1
591 sethi %hi(0x8771f681),T2
592 xor T1,C,T1
593 or T2,%lo(0x8771f681),T2 !=
594 add T1,R8,T1
595 !pre-LOADed X(11),R11
596 add T1,T2,T1
597 add D,T1,D
598 sll D,11,T2 !=
599 srl D,32-11,D
600 or D,T2,D
601 add D,A,D
602
603 xor D,A,T1 !=
604 sethi %hi(0x6d9d6122),T2
605 xor T1,B,T1
606 or T2,%lo(0x6d9d6122),T2
607 add T1,R11,T1 !=
608 LOAD X(14),RX
609 add T1,T2,T1
610 add C,T1,C
611 sll C,16,T2 !=
612 srl C,32-16,C
613 or C,T2,C
614 add C,D,C
615
616 xor C,D,T1 !=
617 sethi %hi(0xfde5380c),T2
618 xor T1,A,T1
619 or T2,%lo(0xfde5380c),T2
620 add T1,RX,T1 !=
621 !pre-LOADed X(1),R1
622 add T1,T2,T1
623 add B,T1,B
624 sll B,23,T2
625 srl B,32-23,B !=
626 or B,T2,B
627 add B,C,B
628
629 xor B,C,T1
630 sethi %hi(0xa4beea44),T2 !=
631 xor T1,D,T1
632 or T2,%lo(0xa4beea44),T2
633 add T1,R1,T1
634 !pre-LOADed X(4),R4
635 add T1,T2,T1 !=
636 add A,T1,A
637 sll A,4,T2
638 srl A,32-4,A
639 or A,T2,A !=
640 add A,B,A
641
642 xor A,B,T1
643 sethi %hi(0x4bdecfa9),T2
644 xor T1,C,T1 !=
645 or T2,%lo(0x4bdecfa9),T2
646 add T1,R4,T1
647 !pre-LOADed X(7),R7
648 add T1,T2,T1
649 add D,T1,D !=
650 sll D,11,T2
651 srl D,32-11,D
652 or D,T2,D
653 add D,A,D !=
654
655 xor D,A,T1
656 sethi %hi(0xf6bb4b60),T2
657 xor T1,B,T1
658 or T2,%lo(0xf6bb4b60),T2 !=
659 add T1,R7,T1
660 !pre-LOADed X(10),R10
661 add T1,T2,T1
662 add C,T1,C
663 sll C,16,T2 !=
664 srl C,32-16,C
665 or C,T2,C
666 add C,D,C
667
668 xor C,D,T1 !=
669 sethi %hi(0xbebfbc70),T2
670 xor T1,A,T1
671 or T2,%lo(0xbebfbc70),T2
672 add T1,R10,T1 !=
673 !pre-LOADed X(13),R13
674 add T1,T2,T1
675 add B,T1,B
676 sll B,23,T2
677 srl B,32-23,B !=
678 or B,T2,B
679 add B,C,B
680
681 xor B,C,T1
682 sethi %hi(0x289b7ec6),T2 !=
683 xor T1,D,T1
684 or T2,%lo(0x289b7ec6),T2
685 add T1,R13,T1
686 !pre-LOADed X(0),R0
687 add T1,T2,T1 !=
688 add A,T1,A
689 sll A,4,T2
690 srl A,32-4,A
691 or A,T2,A !=
692 add A,B,A
693
694 xor A,B,T1
695 sethi %hi(0xeaa127fa),T2
696 xor T1,C,T1 !=
697 or T2,%lo(0xeaa127fa),T2
698 add T1,R0,T1
699 !pre-LOADed X(3),R3
700 add T1,T2,T1
701 add D,T1,D !=
702 sll D,11,T2
703 srl D,32-11,D
704 or D,T2,D
705 add D,A,D !=
706
707 xor D,A,T1
708 sethi %hi(0xd4ef3085),T2
709 xor T1,B,T1
710 or T2,%lo(0xd4ef3085),T2 !=
711 add T1,R3,T1
712 !pre-LOADed X(6),R6
713 add T1,T2,T1
714 add C,T1,C
715 sll C,16,T2 !=
716 srl C,32-16,C
717 or C,T2,C
718 add C,D,C
719
720 xor C,D,T1 !=
721 sethi %hi(0x04881d05),T2
722 xor T1,A,T1
723 or T2,%lo(0x04881d05),T2
724 add T1,R6,T1 !=
725 !pre-LOADed X(9),R9
726 add T1,T2,T1
727 add B,T1,B
728 sll B,23,T2
729 srl B,32-23,B !=
730 or B,T2,B
731 add B,C,B
732
733 xor B,C,T1
734 sethi %hi(0xd9d4d039),T2 !=
735 xor T1,D,T1
736 or T2,%lo(0xd9d4d039),T2
737 add T1,R9,T1
738 !pre-LOADed X(12),R12
739 add T1,T2,T1 !=
740 add A,T1,A
741 sll A,4,T2
742 srl A,32-4,A
743 or A,T2,A !=
744 add A,B,A
745
746 xor A,B,T1
747 sethi %hi(0xe6db99e5),T2
748 xor T1,C,T1 !=
749 or T2,%lo(0xe6db99e5),T2
750 add T1,R12,T1
751 LOAD X(15),RX
752 add T1,T2,T1 !=
753 add D,T1,D
754 sll D,11,T2
755 srl D,32-11,D
756 or D,T2,D !=
757 add D,A,D
758
759 xor D,A,T1
760 sethi %hi(0x1fa27cf8),T2
761 xor T1,B,T1 !=
762 or T2,%lo(0x1fa27cf8),T2
763 add T1,RX,T1
764 !pre-LOADed X(2),R2
765 add T1,T2,T1
766 add C,T1,C !=
767 sll C,16,T2
768 srl C,32-16,C
769 or C,T2,C
770 add C,D,C !=
771
772 xor C,D,T1
773 sethi %hi(0xc4ac5665),T2
774 xor T1,A,T1
775 or T2,%lo(0xc4ac5665),T2 !=
776 add T1,R2,T1
777 !pre-LOADed X(0),R0
778 add T1,T2,T1
779 add B,T1,B
780 sll B,23,T2 !=
781 srl B,32-23,B
782 or B,T2,B
783 add B,C,B
784
785!!!!!!!!Round 3
786
787 orn B,D,T1 !=
788 sethi %hi(0xf4292244),T2
789 xor T1,C,T1
790 or T2,%lo(0xf4292244),T2
791 add T1,R0,T1 !=
792 !pre-LOADed X(7),R7
793 add T1,T2,T1
794 add A,T1,A
795 sll A,6,T2
796 srl A,32-6,A !=
797 or A,T2,A
798 add A,B,A
799
800 orn A,C,T1
801 sethi %hi(0x432aff97),T2 !=
802 xor T1,B,T1
803 or T2,%lo(0x432aff97),T2
804 LOAD X(14),RX
805 add T1,R7,T1 !=
806 add T1,T2,T1
807 add D,T1,D
808 sll D,10,T2
809 srl D,32-10,D !=
810 or D,T2,D
811 add D,A,D
812
813 orn D,B,T1
814 sethi %hi(0xab9423a7),T2 !=
815 xor T1,A,T1
816 or T2,%lo(0xab9423a7),T2
817 add T1,RX,T1
818 !pre-LOADed X(5),R5
819 add T1,T2,T1 !=
820 add C,T1,C
821 sll C,15,T2
822 srl C,32-15,C
823 or C,T2,C !=
824 add C,D,C
825
826 orn C,A,T1
827 sethi %hi(0xfc93a039),T2
828 xor T1,D,T1 !=
829 or T2,%lo(0xfc93a039),T2
830 add T1,R5,T1
831 !pre-LOADed X(12),R12
832 add T1,T2,T1
833 add B,T1,B !=
834 sll B,21,T2
835 srl B,32-21,B
836 or B,T2,B
837 add B,C,B !=
838
839 orn B,D,T1
840 sethi %hi(0x655b59c3),T2
841 xor T1,C,T1
842 or T2,%lo(0x655b59c3),T2 !=
843 add T1,R12,T1
844 !pre-LOADed X(3),R3
845 add T1,T2,T1
846 add A,T1,A
847 sll A,6,T2 !=
848 srl A,32-6,A
849 or A,T2,A
850 add A,B,A
851
852 orn A,C,T1 !=
853 sethi %hi(0x8f0ccc92),T2
854 xor T1,B,T1
855 or T2,%lo(0x8f0ccc92),T2
856 add T1,R3,T1 !=
857 !pre-LOADed X(10),R10
858 add T1,T2,T1
859 add D,T1,D
860 sll D,10,T2
861 srl D,32-10,D !=
862 or D,T2,D
863 add D,A,D
864
865 orn D,B,T1
866 sethi %hi(0xffeff47d),T2 !=
867 xor T1,A,T1
868 or T2,%lo(0xffeff47d),T2
869 add T1,R10,T1
870 !pre-LOADed X(1),R1
871 add T1,T2,T1 !=
872 add C,T1,C
873 sll C,15,T2
874 srl C,32-15,C
875 or C,T2,C !=
876 add C,D,C
877
878 orn C,A,T1
879 sethi %hi(0x85845dd1),T2
880 xor T1,D,T1 !=
881 or T2,%lo(0x85845dd1),T2
882 add T1,R1,T1
883 !pre-LOADed X(8),R8
884 add T1,T2,T1
885 add B,T1,B !=
886 sll B,21,T2
887 srl B,32-21,B
888 or B,T2,B
889 add B,C,B !=
890
891 orn B,D,T1
892 sethi %hi(0x6fa87e4f),T2
893 xor T1,C,T1
894 or T2,%lo(0x6fa87e4f),T2 !=
895 add T1,R8,T1
896 LOAD X(15),RX
897 add T1,T2,T1
898 add A,T1,A !=
899 sll A,6,T2
900 srl A,32-6,A
901 or A,T2,A
902 add A,B,A !=
903
904 orn A,C,T1
905 sethi %hi(0xfe2ce6e0),T2
906 xor T1,B,T1
907 or T2,%lo(0xfe2ce6e0),T2 !=
908 add T1,RX,T1
909 !pre-LOADed X(6),R6
910 add T1,T2,T1
911 add D,T1,D
912 sll D,10,T2 !=
913 srl D,32-10,D
914 or D,T2,D
915 add D,A,D
916
917 orn D,B,T1 !=
918 sethi %hi(0xa3014314),T2
919 xor T1,A,T1
920 or T2,%lo(0xa3014314),T2
921 add T1,R6,T1 !=
922 !pre-LOADed X(13),R13
923 add T1,T2,T1
924 add C,T1,C
925 sll C,15,T2
926 srl C,32-15,C !=
927 or C,T2,C
928 add C,D,C
929
930 orn C,A,T1
931 sethi %hi(0x4e0811a1),T2 !=
932 xor T1,D,T1
933 or T2,%lo(0x4e0811a1),T2
934 !pre-LOADed X(4),R4
935 ld [Aptr],Aval
936 add T1,R13,T1 !=
937 add T1,T2,T1
938 add B,T1,B
939 sll B,21,T2
940 srl B,32-21,B !=
941 or B,T2,B
942 add B,C,B
943
944 orn B,D,T1
945 sethi %hi(0xf7537e82),T2 !=
946 xor T1,C,T1
947 or T2,%lo(0xf7537e82),T2
948 !pre-LOADed X(11),R11
949 ld [Dptr],Dval
950 add T1,R4,T1 !=
951 add T1,T2,T1
952 add A,T1,A
953 sll A,6,T2
954 srl A,32-6,A !=
955 or A,T2,A
956 add A,B,A
957
958 orn A,C,T1
959 sethi %hi(0xbd3af235),T2 !=
960 xor T1,B,T1
961 or T2,%lo(0xbd3af235),T2
962 !pre-LOADed X(2),R2
963 ld [Cptr],Cval
964 add T1,R11,T1 !=
965 add T1,T2,T1
966 add D,T1,D
967 sll D,10,T2
968 srl D,32-10,D !=
969 or D,T2,D
970 add D,A,D
971
972 orn D,B,T1
973 sethi %hi(0x2ad7d2bb),T2 !=
974 xor T1,A,T1
975 or T2,%lo(0x2ad7d2bb),T2
976 !pre-LOADed X(9),R9
977 ld [Bptr],Bval
978 add T1,R2,T1 !=
979 add Aval,A,Aval
980 add T1,T2,T1
981 st Aval,[Aptr]
982 add C,T1,C !=
983 sll C,15,T2
984 add Dval,D,Dval
985 srl C,32-15,C
986 or C,T2,C !=
987 st Dval,[Dptr]
988 add C,D,C
989
990 orn C,A,T1
991 sethi %hi(0xeb86d391),T2 !=
992 xor T1,D,T1
993 or T2,%lo(0xeb86d391),T2
994 add T1,R9,T1
995 !pre-LOADed X(0),R0
996 mov Aval,A !=
997 add T1,T2,T1
998 mov Dval,D
999 add B,T1,B
1000 sll B,21,T2 !=
1001 add Cval,C,Cval
1002 srl B,32-21,B
1003 st Cval,[Cptr]
1004 or B,T2,B !=
1005 add B,C,B
1006
1007 deccc %i2
1008 mov Cval,C
1009 add B,Bval,B !=
1010 inc 64,%i1
1011 nop
1012 st B,[Bptr]
1013 nop !=
1014
1015#ifdef ULTRASPARC
1016 bg,a,pt %icc,.Lmd5_block_loop
1017#else
1018 bg,a .Lmd5_block_loop
1019#endif
1020 LOAD X(0),R0
1021
1022#ifdef ASI_PRIMARY_LITTLE
1023 wr %g0,%o7,%asi
1024#endif
1025 ret
1026 restore %g0,0,%o0
1027
1028.type md5_block,#function
1029.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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define md5_block_x86 _md5_block_x86
13
14#endif
15
16#ifdef OUT
17#define OK 1
18#define ALIGN 4
19#endif
20
21#ifdef BSDI
22#define OK 1
23#define ALIGN 4
24#undef SIZE
25#undef TYPE
26#define SIZE(a,b)
27#define TYPE(a,b)
28#endif
29
30#if defined(ELF) || defined(SOL)
31#define OK 1
32#define ALIGN 16
33#endif
34
35#ifndef OK
36You need to define one of
37ELF - elf systems - linux-elf, NetBSD and DG-UX
38OUT - a.out systems - linux-a.out and FreeBSD
39SOL - solaris systems, which are elf with strange comment lines
40BSDI - a.out with a very primative version of as.
41#endif
42
43/* Let the Assembler begin :-) */
44 /* Don't even think of reading this code */
45 /* It was automatically generated by md5-586.pl */
46 /* Which is a perl program used to generate the x86 assember for */
47 /* any of elf, a.out, BSDI,Win32, or Solaris */
48 /* eric <eay@cryptsoft.com> */
49
50 .file "md5-586.s"
51 .version "01.01"
52gcc2_compiled.:
53.text
54 .align ALIGN
55.globl md5_block_x86
56 TYPE(md5_block_x86,@function)
57md5_block_x86:
58 pushl %esi
59 pushl %edi
60 movl 12(%esp), %edi
61 movl 16(%esp), %esi
62 movl 20(%esp), %ecx
63 pushl %ebp
64 pushl %ebx
65 addl %esi, %ecx
66 subl $64, %ecx
67 movl (%edi), %eax
68 pushl %ecx
69 movl 4(%edi), %ebx
70 movl 8(%edi), %ecx
71 movl 12(%edi), %edx
72.L000start:
73
74 /* R0 section */
75 movl %ecx, %edi
76 movl (%esi), %ebp
77 /* R0 0 */
78 xorl %edx, %edi
79 andl %ebx, %edi
80 leal 3614090360(%eax,%ebp,1),%eax
81 movl 4(%esi), %ebp
82 xorl %edx, %edi
83 addl %edi, %eax
84 movl %ebx, %edi
85 roll $7, %eax
86 addl %ebx, %eax
87 /* R0 1 */
88 xorl %ecx, %edi
89 andl %eax, %edi
90 leal 3905402710(%edx,%ebp,1),%edx
91 movl 8(%esi), %ebp
92 xorl %ecx, %edi
93 addl %edi, %edx
94 movl %eax, %edi
95 roll $12, %edx
96 addl %eax, %edx
97 /* R0 2 */
98 xorl %ebx, %edi
99 andl %edx, %edi
100 leal 606105819(%ecx,%ebp,1),%ecx
101 movl 12(%esi), %ebp
102 xorl %ebx, %edi
103 addl %edi, %ecx
104 movl %edx, %edi
105 roll $17, %ecx
106 addl %edx, %ecx
107 /* R0 3 */
108 xorl %eax, %edi
109 andl %ecx, %edi
110 leal 3250441966(%ebx,%ebp,1),%ebx
111 movl 16(%esi), %ebp
112 xorl %eax, %edi
113 addl %edi, %ebx
114 movl %ecx, %edi
115 roll $22, %ebx
116 addl %ecx, %ebx
117 /* R0 4 */
118 xorl %edx, %edi
119 andl %ebx, %edi
120 leal 4118548399(%eax,%ebp,1),%eax
121 movl 20(%esi), %ebp
122 xorl %edx, %edi
123 addl %edi, %eax
124 movl %ebx, %edi
125 roll $7, %eax
126 addl %ebx, %eax
127 /* R0 5 */
128 xorl %ecx, %edi
129 andl %eax, %edi
130 leal 1200080426(%edx,%ebp,1),%edx
131 movl 24(%esi), %ebp
132 xorl %ecx, %edi
133 addl %edi, %edx
134 movl %eax, %edi
135 roll $12, %edx
136 addl %eax, %edx
137 /* R0 6 */
138 xorl %ebx, %edi
139 andl %edx, %edi
140 leal 2821735955(%ecx,%ebp,1),%ecx
141 movl 28(%esi), %ebp
142 xorl %ebx, %edi
143 addl %edi, %ecx
144 movl %edx, %edi
145 roll $17, %ecx
146 addl %edx, %ecx
147 /* R0 7 */
148 xorl %eax, %edi
149 andl %ecx, %edi
150 leal 4249261313(%ebx,%ebp,1),%ebx
151 movl 32(%esi), %ebp
152 xorl %eax, %edi
153 addl %edi, %ebx
154 movl %ecx, %edi
155 roll $22, %ebx
156 addl %ecx, %ebx
157 /* R0 8 */
158 xorl %edx, %edi
159 andl %ebx, %edi
160 leal 1770035416(%eax,%ebp,1),%eax
161 movl 36(%esi), %ebp
162 xorl %edx, %edi
163 addl %edi, %eax
164 movl %ebx, %edi
165 roll $7, %eax
166 addl %ebx, %eax
167 /* R0 9 */
168 xorl %ecx, %edi
169 andl %eax, %edi
170 leal 2336552879(%edx,%ebp,1),%edx
171 movl 40(%esi), %ebp
172 xorl %ecx, %edi
173 addl %edi, %edx
174 movl %eax, %edi
175 roll $12, %edx
176 addl %eax, %edx
177 /* R0 10 */
178 xorl %ebx, %edi
179 andl %edx, %edi
180 leal 4294925233(%ecx,%ebp,1),%ecx
181 movl 44(%esi), %ebp
182 xorl %ebx, %edi
183 addl %edi, %ecx
184 movl %edx, %edi
185 roll $17, %ecx
186 addl %edx, %ecx
187 /* R0 11 */
188 xorl %eax, %edi
189 andl %ecx, %edi
190 leal 2304563134(%ebx,%ebp,1),%ebx
191 movl 48(%esi), %ebp
192 xorl %eax, %edi
193 addl %edi, %ebx
194 movl %ecx, %edi
195 roll $22, %ebx
196 addl %ecx, %ebx
197 /* R0 12 */
198 xorl %edx, %edi
199 andl %ebx, %edi
200 leal 1804603682(%eax,%ebp,1),%eax
201 movl 52(%esi), %ebp
202 xorl %edx, %edi
203 addl %edi, %eax
204 movl %ebx, %edi
205 roll $7, %eax
206 addl %ebx, %eax
207 /* R0 13 */
208 xorl %ecx, %edi
209 andl %eax, %edi
210 leal 4254626195(%edx,%ebp,1),%edx
211 movl 56(%esi), %ebp
212 xorl %ecx, %edi
213 addl %edi, %edx
214 movl %eax, %edi
215 roll $12, %edx
216 addl %eax, %edx
217 /* R0 14 */
218 xorl %ebx, %edi
219 andl %edx, %edi
220 leal 2792965006(%ecx,%ebp,1),%ecx
221 movl 60(%esi), %ebp
222 xorl %ebx, %edi
223 addl %edi, %ecx
224 movl %edx, %edi
225 roll $17, %ecx
226 addl %edx, %ecx
227 /* R0 15 */
228 xorl %eax, %edi
229 andl %ecx, %edi
230 leal 1236535329(%ebx,%ebp,1),%ebx
231 movl 4(%esi), %ebp
232 xorl %eax, %edi
233 addl %edi, %ebx
234 movl %ecx, %edi
235 roll $22, %ebx
236 addl %ecx, %ebx
237
238 /* R1 section */
239 /* R1 16 */
240 leal 4129170786(%eax,%ebp,1),%eax
241 xorl %ebx, %edi
242 andl %edx, %edi
243 movl 24(%esi), %ebp
244 xorl %ecx, %edi
245 addl %edi, %eax
246 movl %ebx, %edi
247 roll $5, %eax
248 addl %ebx, %eax
249 /* R1 17 */
250 leal 3225465664(%edx,%ebp,1),%edx
251 xorl %eax, %edi
252 andl %ecx, %edi
253 movl 44(%esi), %ebp
254 xorl %ebx, %edi
255 addl %edi, %edx
256 movl %eax, %edi
257 roll $9, %edx
258 addl %eax, %edx
259 /* R1 18 */
260 leal 643717713(%ecx,%ebp,1),%ecx
261 xorl %edx, %edi
262 andl %ebx, %edi
263 movl (%esi), %ebp
264 xorl %eax, %edi
265 addl %edi, %ecx
266 movl %edx, %edi
267 roll $14, %ecx
268 addl %edx, %ecx
269 /* R1 19 */
270 leal 3921069994(%ebx,%ebp,1),%ebx
271 xorl %ecx, %edi
272 andl %eax, %edi
273 movl 20(%esi), %ebp
274 xorl %edx, %edi
275 addl %edi, %ebx
276 movl %ecx, %edi
277 roll $20, %ebx
278 addl %ecx, %ebx
279 /* R1 20 */
280 leal 3593408605(%eax,%ebp,1),%eax
281 xorl %ebx, %edi
282 andl %edx, %edi
283 movl 40(%esi), %ebp
284 xorl %ecx, %edi
285 addl %edi, %eax
286 movl %ebx, %edi
287 roll $5, %eax
288 addl %ebx, %eax
289 /* R1 21 */
290 leal 38016083(%edx,%ebp,1),%edx
291 xorl %eax, %edi
292 andl %ecx, %edi
293 movl 60(%esi), %ebp
294 xorl %ebx, %edi
295 addl %edi, %edx
296 movl %eax, %edi
297 roll $9, %edx
298 addl %eax, %edx
299 /* R1 22 */
300 leal 3634488961(%ecx,%ebp,1),%ecx
301 xorl %edx, %edi
302 andl %ebx, %edi
303 movl 16(%esi), %ebp
304 xorl %eax, %edi
305 addl %edi, %ecx
306 movl %edx, %edi
307 roll $14, %ecx
308 addl %edx, %ecx
309 /* R1 23 */
310 leal 3889429448(%ebx,%ebp,1),%ebx
311 xorl %ecx, %edi
312 andl %eax, %edi
313 movl 36(%esi), %ebp
314 xorl %edx, %edi
315 addl %edi, %ebx
316 movl %ecx, %edi
317 roll $20, %ebx
318 addl %ecx, %ebx
319 /* R1 24 */
320 leal 568446438(%eax,%ebp,1),%eax
321 xorl %ebx, %edi
322 andl %edx, %edi
323 movl 56(%esi), %ebp
324 xorl %ecx, %edi
325 addl %edi, %eax
326 movl %ebx, %edi
327 roll $5, %eax
328 addl %ebx, %eax
329 /* R1 25 */
330 leal 3275163606(%edx,%ebp,1),%edx
331 xorl %eax, %edi
332 andl %ecx, %edi
333 movl 12(%esi), %ebp
334 xorl %ebx, %edi
335 addl %edi, %edx
336 movl %eax, %edi
337 roll $9, %edx
338 addl %eax, %edx
339 /* R1 26 */
340 leal 4107603335(%ecx,%ebp,1),%ecx
341 xorl %edx, %edi
342 andl %ebx, %edi
343 movl 32(%esi), %ebp
344 xorl %eax, %edi
345 addl %edi, %ecx
346 movl %edx, %edi
347 roll $14, %ecx
348 addl %edx, %ecx
349 /* R1 27 */
350 leal 1163531501(%ebx,%ebp,1),%ebx
351 xorl %ecx, %edi
352 andl %eax, %edi
353 movl 52(%esi), %ebp
354 xorl %edx, %edi
355 addl %edi, %ebx
356 movl %ecx, %edi
357 roll $20, %ebx
358 addl %ecx, %ebx
359 /* R1 28 */
360 leal 2850285829(%eax,%ebp,1),%eax
361 xorl %ebx, %edi
362 andl %edx, %edi
363 movl 8(%esi), %ebp
364 xorl %ecx, %edi
365 addl %edi, %eax
366 movl %ebx, %edi
367 roll $5, %eax
368 addl %ebx, %eax
369 /* R1 29 */
370 leal 4243563512(%edx,%ebp,1),%edx
371 xorl %eax, %edi
372 andl %ecx, %edi
373 movl 28(%esi), %ebp
374 xorl %ebx, %edi
375 addl %edi, %edx
376 movl %eax, %edi
377 roll $9, %edx
378 addl %eax, %edx
379 /* R1 30 */
380 leal 1735328473(%ecx,%ebp,1),%ecx
381 xorl %edx, %edi
382 andl %ebx, %edi
383 movl 48(%esi), %ebp
384 xorl %eax, %edi
385 addl %edi, %ecx
386 movl %edx, %edi
387 roll $14, %ecx
388 addl %edx, %ecx
389 /* R1 31 */
390 leal 2368359562(%ebx,%ebp,1),%ebx
391 xorl %ecx, %edi
392 andl %eax, %edi
393 movl 20(%esi), %ebp
394 xorl %edx, %edi
395 addl %edi, %ebx
396 movl %ecx, %edi
397 roll $20, %ebx
398 addl %ecx, %ebx
399
400 /* R2 section */
401 /* R2 32 */
402 xorl %edx, %edi
403 xorl %ebx, %edi
404 leal 4294588738(%eax,%ebp,1),%eax
405 addl %edi, %eax
406 movl 32(%esi), %ebp
407 roll $4, %eax
408 movl %ebx, %edi
409 /* R2 33 */
410 leal 2272392833(%edx,%ebp,1),%edx
411 addl %ebx, %eax
412 xorl %ecx, %edi
413 xorl %eax, %edi
414 movl 44(%esi), %ebp
415 addl %edi, %edx
416 movl %eax, %edi
417 roll $11, %edx
418 addl %eax, %edx
419 /* R2 34 */
420 xorl %ebx, %edi
421 xorl %edx, %edi
422 leal 1839030562(%ecx,%ebp,1),%ecx
423 addl %edi, %ecx
424 movl 56(%esi), %ebp
425 roll $16, %ecx
426 movl %edx, %edi
427 /* R2 35 */
428 leal 4259657740(%ebx,%ebp,1),%ebx
429 addl %edx, %ecx
430 xorl %eax, %edi
431 xorl %ecx, %edi
432 movl 4(%esi), %ebp
433 addl %edi, %ebx
434 movl %ecx, %edi
435 roll $23, %ebx
436 addl %ecx, %ebx
437 /* R2 36 */
438 xorl %edx, %edi
439 xorl %ebx, %edi
440 leal 2763975236(%eax,%ebp,1),%eax
441 addl %edi, %eax
442 movl 16(%esi), %ebp
443 roll $4, %eax
444 movl %ebx, %edi
445 /* R2 37 */
446 leal 1272893353(%edx,%ebp,1),%edx
447 addl %ebx, %eax
448 xorl %ecx, %edi
449 xorl %eax, %edi
450 movl 28(%esi), %ebp
451 addl %edi, %edx
452 movl %eax, %edi
453 roll $11, %edx
454 addl %eax, %edx
455 /* R2 38 */
456 xorl %ebx, %edi
457 xorl %edx, %edi
458 leal 4139469664(%ecx,%ebp,1),%ecx
459 addl %edi, %ecx
460 movl 40(%esi), %ebp
461 roll $16, %ecx
462 movl %edx, %edi
463 /* R2 39 */
464 leal 3200236656(%ebx,%ebp,1),%ebx
465 addl %edx, %ecx
466 xorl %eax, %edi
467 xorl %ecx, %edi
468 movl 52(%esi), %ebp
469 addl %edi, %ebx
470 movl %ecx, %edi
471 roll $23, %ebx
472 addl %ecx, %ebx
473 /* R2 40 */
474 xorl %edx, %edi
475 xorl %ebx, %edi
476 leal 681279174(%eax,%ebp,1),%eax
477 addl %edi, %eax
478 movl (%esi), %ebp
479 roll $4, %eax
480 movl %ebx, %edi
481 /* R2 41 */
482 leal 3936430074(%edx,%ebp,1),%edx
483 addl %ebx, %eax
484 xorl %ecx, %edi
485 xorl %eax, %edi
486 movl 12(%esi), %ebp
487 addl %edi, %edx
488 movl %eax, %edi
489 roll $11, %edx
490 addl %eax, %edx
491 /* R2 42 */
492 xorl %ebx, %edi
493 xorl %edx, %edi
494 leal 3572445317(%ecx,%ebp,1),%ecx
495 addl %edi, %ecx
496 movl 24(%esi), %ebp
497 roll $16, %ecx
498 movl %edx, %edi
499 /* R2 43 */
500 leal 76029189(%ebx,%ebp,1),%ebx
501 addl %edx, %ecx
502 xorl %eax, %edi
503 xorl %ecx, %edi
504 movl 36(%esi), %ebp
505 addl %edi, %ebx
506 movl %ecx, %edi
507 roll $23, %ebx
508 addl %ecx, %ebx
509 /* R2 44 */
510 xorl %edx, %edi
511 xorl %ebx, %edi
512 leal 3654602809(%eax,%ebp,1),%eax
513 addl %edi, %eax
514 movl 48(%esi), %ebp
515 roll $4, %eax
516 movl %ebx, %edi
517 /* R2 45 */
518 leal 3873151461(%edx,%ebp,1),%edx
519 addl %ebx, %eax
520 xorl %ecx, %edi
521 xorl %eax, %edi
522 movl 60(%esi), %ebp
523 addl %edi, %edx
524 movl %eax, %edi
525 roll $11, %edx
526 addl %eax, %edx
527 /* R2 46 */
528 xorl %ebx, %edi
529 xorl %edx, %edi
530 leal 530742520(%ecx,%ebp,1),%ecx
531 addl %edi, %ecx
532 movl 8(%esi), %ebp
533 roll $16, %ecx
534 movl %edx, %edi
535 /* R2 47 */
536 leal 3299628645(%ebx,%ebp,1),%ebx
537 addl %edx, %ecx
538 xorl %eax, %edi
539 xorl %ecx, %edi
540 movl (%esi), %ebp
541 addl %edi, %ebx
542 movl $-1, %edi
543 roll $23, %ebx
544 addl %ecx, %ebx
545
546 /* R3 section */
547 /* R3 48 */
548 xorl %edx, %edi
549 orl %ebx, %edi
550 leal 4096336452(%eax,%ebp,1),%eax
551 xorl %ecx, %edi
552 movl 28(%esi), %ebp
553 addl %edi, %eax
554 movl $-1, %edi
555 roll $6, %eax
556 xorl %ecx, %edi
557 addl %ebx, %eax
558 /* R3 49 */
559 orl %eax, %edi
560 leal 1126891415(%edx,%ebp,1),%edx
561 xorl %ebx, %edi
562 movl 56(%esi), %ebp
563 addl %edi, %edx
564 movl $-1, %edi
565 roll $10, %edx
566 xorl %ebx, %edi
567 addl %eax, %edx
568 /* R3 50 */
569 orl %edx, %edi
570 leal 2878612391(%ecx,%ebp,1),%ecx
571 xorl %eax, %edi
572 movl 20(%esi), %ebp
573 addl %edi, %ecx
574 movl $-1, %edi
575 roll $15, %ecx
576 xorl %eax, %edi
577 addl %edx, %ecx
578 /* R3 51 */
579 orl %ecx, %edi
580 leal 4237533241(%ebx,%ebp,1),%ebx
581 xorl %edx, %edi
582 movl 48(%esi), %ebp
583 addl %edi, %ebx
584 movl $-1, %edi
585 roll $21, %ebx
586 xorl %edx, %edi
587 addl %ecx, %ebx
588 /* R3 52 */
589 orl %ebx, %edi
590 leal 1700485571(%eax,%ebp,1),%eax
591 xorl %ecx, %edi
592 movl 12(%esi), %ebp
593 addl %edi, %eax
594 movl $-1, %edi
595 roll $6, %eax
596 xorl %ecx, %edi
597 addl %ebx, %eax
598 /* R3 53 */
599 orl %eax, %edi
600 leal 2399980690(%edx,%ebp,1),%edx
601 xorl %ebx, %edi
602 movl 40(%esi), %ebp
603 addl %edi, %edx
604 movl $-1, %edi
605 roll $10, %edx
606 xorl %ebx, %edi
607 addl %eax, %edx
608 /* R3 54 */
609 orl %edx, %edi
610 leal 4293915773(%ecx,%ebp,1),%ecx
611 xorl %eax, %edi
612 movl 4(%esi), %ebp
613 addl %edi, %ecx
614 movl $-1, %edi
615 roll $15, %ecx
616 xorl %eax, %edi
617 addl %edx, %ecx
618 /* R3 55 */
619 orl %ecx, %edi
620 leal 2240044497(%ebx,%ebp,1),%ebx
621 xorl %edx, %edi
622 movl 32(%esi), %ebp
623 addl %edi, %ebx
624 movl $-1, %edi
625 roll $21, %ebx
626 xorl %edx, %edi
627 addl %ecx, %ebx
628 /* R3 56 */
629 orl %ebx, %edi
630 leal 1873313359(%eax,%ebp,1),%eax
631 xorl %ecx, %edi
632 movl 60(%esi), %ebp
633 addl %edi, %eax
634 movl $-1, %edi
635 roll $6, %eax
636 xorl %ecx, %edi
637 addl %ebx, %eax
638 /* R3 57 */
639 orl %eax, %edi
640 leal 4264355552(%edx,%ebp,1),%edx
641 xorl %ebx, %edi
642 movl 24(%esi), %ebp
643 addl %edi, %edx
644 movl $-1, %edi
645 roll $10, %edx
646 xorl %ebx, %edi
647 addl %eax, %edx
648 /* R3 58 */
649 orl %edx, %edi
650 leal 2734768916(%ecx,%ebp,1),%ecx
651 xorl %eax, %edi
652 movl 52(%esi), %ebp
653 addl %edi, %ecx
654 movl $-1, %edi
655 roll $15, %ecx
656 xorl %eax, %edi
657 addl %edx, %ecx
658 /* R3 59 */
659 orl %ecx, %edi
660 leal 1309151649(%ebx,%ebp,1),%ebx
661 xorl %edx, %edi
662 movl 16(%esi), %ebp
663 addl %edi, %ebx
664 movl $-1, %edi
665 roll $21, %ebx
666 xorl %edx, %edi
667 addl %ecx, %ebx
668 /* R3 60 */
669 orl %ebx, %edi
670 leal 4149444226(%eax,%ebp,1),%eax
671 xorl %ecx, %edi
672 movl 44(%esi), %ebp
673 addl %edi, %eax
674 movl $-1, %edi
675 roll $6, %eax
676 xorl %ecx, %edi
677 addl %ebx, %eax
678 /* R3 61 */
679 orl %eax, %edi
680 leal 3174756917(%edx,%ebp,1),%edx
681 xorl %ebx, %edi
682 movl 8(%esi), %ebp
683 addl %edi, %edx
684 movl $-1, %edi
685 roll $10, %edx
686 xorl %ebx, %edi
687 addl %eax, %edx
688 /* R3 62 */
689 orl %edx, %edi
690 leal 718787259(%ecx,%ebp,1),%ecx
691 xorl %eax, %edi
692 movl 36(%esi), %ebp
693 addl %edi, %ecx
694 movl $-1, %edi
695 roll $15, %ecx
696 xorl %eax, %edi
697 addl %edx, %ecx
698 /* R3 63 */
699 orl %ecx, %edi
700 leal 3951481745(%ebx,%ebp,1),%ebx
701 xorl %edx, %edi
702 movl 24(%esp), %ebp
703 addl %edi, %ebx
704 addl $64, %esi
705 roll $21, %ebx
706 movl (%ebp), %edi
707 addl %ecx, %ebx
708 addl %edi, %eax
709 movl 4(%ebp), %edi
710 addl %edi, %ebx
711 movl 8(%ebp), %edi
712 addl %edi, %ecx
713 movl 12(%ebp), %edi
714 addl %edi, %edx
715 movl %eax, (%ebp)
716 movl %ebx, 4(%ebp)
717 movl (%esp), %edi
718 movl %ecx, 8(%ebp)
719 movl %edx, 12(%ebp)
720 cmpl %esi, %edi
721 jge .L000start
722 popl %eax
723 popl %ebx
724 popl %ebp
725 popl %edi
726 popl %esi
727 ret
728.md5_block_x86_end:
729 SIZE(md5_block_x86,.md5_block_x86_end-md5_block_x86)
730.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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "md5.h" 61#include <openssl/md5.h>
62 62
63#define BUFSIZE 1024*16 63#define BUFSIZE 1024*16
64 64
65#ifndef NOPROTO
66void do_fp(FILE *f); 65void do_fp(FILE *f);
67void pt(unsigned char *md); 66void pt(unsigned char *md);
67#ifndef _OSD_POSIX
68int read(int, void *, unsigned int); 68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif 69#endif
74 70
75int main(argc, argv) 71int main(int argc, char **argv)
76int argc;
77char **argv;
78 { 72 {
79 int i,err=0; 73 int i,err=0;
80 FILE *IN; 74 FILE *IN;
@@ -102,8 +96,7 @@ char **argv;
102 exit(err); 96 exit(err);
103 } 97 }
104 98
105void do_fp(f) 99void do_fp(FILE *f)
106FILE *f;
107 { 100 {
108 MD5_CTX c; 101 MD5_CTX c;
109 unsigned char md[MD5_DIGEST_LENGTH]; 102 unsigned char md[MD5_DIGEST_LENGTH];
@@ -123,8 +116,7 @@ FILE *f;
123 pt(md); 116 pt(md);
124 } 117 }
125 118
126void pt(md) 119void pt(unsigned char *md)
127unsigned char *md;
128 { 120 {
129 int i; 121 int i;
130 122
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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifdef NO_MD5
67#error MD5 is disabled.
68#endif
69
70/*
71 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72 * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then !
73 * ! MD5_LONG_LOG2 has to be defined along. !
74 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 */
76
77#if defined(WIN16) || defined(__LP32__)
78#define MD5_LONG unsigned long
79#elif defined(_CRAY) || defined(__ILP64__)
80#define MD5_LONG unsigned long
81#define MD5_LONG_LOG2 3
82/*
83 * _CRAY note. I could declare short, but I have no idea what impact
84 * does it have on performance on none-T3E machines. I could declare
85 * int, but at least on C90 sizeof(int) can be chosen at compile time.
86 * So I've chosen long...
87 * <appro@fy.chalmers.se>
88 */
89#else
90#define MD5_LONG unsigned int
91#endif
92
66#define MD5_CBLOCK 64 93#define MD5_CBLOCK 64
67#define MD5_LBLOCK 16 94#define MD5_LBLOCK (MD5_CBLOCK/4)
68#define MD5_BLOCK 16
69#define MD5_LAST_BLOCK 56
70#define MD5_LENGTH_BLOCK 8
71#define MD5_DIGEST_LENGTH 16 95#define MD5_DIGEST_LENGTH 16
72 96
73typedef struct MD5state_st 97typedef struct MD5state_st
74 { 98 {
75 unsigned long A,B,C,D; 99 MD5_LONG A,B,C,D;
76 unsigned long Nl,Nh; 100 MD5_LONG Nl,Nh;
77 unsigned long data[MD5_LBLOCK]; 101 MD5_LONG data[MD5_LBLOCK];
78 int num; 102 int num;
79 } MD5_CTX; 103 } MD5_CTX;
80 104
81#ifndef NOPROTO
82void MD5_Init(MD5_CTX *c); 105void MD5_Init(MD5_CTX *c);
83void MD5_Update(MD5_CTX *c, unsigned char *data, unsigned long len); 106void MD5_Update(MD5_CTX *c, const unsigned char *data, unsigned long len);
84void MD5_Final(unsigned char *md, MD5_CTX *c); 107void MD5_Final(unsigned char *md, MD5_CTX *c);
85unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md); 108unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md);
86void MD5_Transform(MD5_CTX *c, unsigned char *b); 109void MD5_Transform(MD5_CTX *c, const unsigned char *b);
87#else
88void MD5_Init();
89void MD5_Update();
90void MD5_Final();
91unsigned char *MD5();
92void MD5_Transform();
93#endif
94
95#ifdef __cplusplus 110#ifdef __cplusplus
96} 111}
97#endif 112#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "md5_locl.h" 60#include "md5_locl.h"
61#include <openssl/opensslv.h>
61 62
62char *MD5_version="MD5 part of SSLeay 0.9.0b 29-Jun-1998"; 63char *MD5_version="MD5" OPENSSL_VERSION_PTEXT;
63 64
64/* Implemented from RFC1321 The MD5 Message-Digest Algorithm 65/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
65 */ 66 */
@@ -69,24 +70,7 @@ char *MD5_version="MD5 part of SSLeay 0.9.0b 29-Jun-1998";
69#define INIT_DATA_C (unsigned long)0x98badcfeL 70#define INIT_DATA_C (unsigned long)0x98badcfeL
70#define INIT_DATA_D (unsigned long)0x10325476L 71#define INIT_DATA_D (unsigned long)0x10325476L
71 72
72#ifndef NOPROTO 73void MD5_Init(MD5_CTX *c)
73# ifdef MD5_ASM
74 void md5_block_x86(MD5_CTX *c, unsigned long *p,int num);
75# define md5_block md5_block_x86
76# else
77 static void md5_block(MD5_CTX *c, unsigned long *p,int num);
78# endif
79#else
80# ifdef MD5_ASM
81 void md5_block_x86();
82# define md5_block md5_block_x86
83# else
84 static void md5_block();
85# endif
86#endif
87
88void MD5_Init(c)
89MD5_CTX *c;
90 { 74 {
91 c->A=INIT_DATA_A; 75 c->A=INIT_DATA_A;
92 c->B=INIT_DATA_B; 76 c->B=INIT_DATA_B;
@@ -97,190 +81,32 @@ MD5_CTX *c;
97 c->num=0; 81 c->num=0;
98 } 82 }
99 83
100void MD5_Update(c, data, len) 84#ifndef md5_block_host_order
101MD5_CTX *c; 85void md5_block_host_order (MD5_CTX *c, const void *data, int num)
102register unsigned char *data;
103unsigned long len;
104 {
105 register ULONG *p;
106 int sw,sc;
107 ULONG l;
108
109 if (len == 0) return;
110
111 l=(c->Nl+(len<<3))&0xffffffffL;
112 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
113 * Wei Dai <weidai@eskimo.com> for pointing it out. */
114 if (l < c->Nl) /* overflow */
115 c->Nh++;
116 c->Nh+=(len>>29);
117 c->Nl=l;
118
119 if (c->num != 0)
120 {
121 p=c->data;
122 sw=c->num>>2;
123 sc=c->num&0x03;
124
125 if ((c->num+len) >= MD5_CBLOCK)
126 {
127 l= p[sw];
128 p_c2l(data,l,sc);
129 p[sw++]=l;
130 for (; sw<MD5_LBLOCK; sw++)
131 {
132 c2l(data,l);
133 p[sw]=l;
134 }
135 len-=(MD5_CBLOCK-c->num);
136
137 md5_block(c,p,64);
138 c->num=0;
139 /* drop through and do the rest */
140 }
141 else
142 {
143 int ew,ec;
144
145 c->num+=(int)len;
146 if ((sc+len) < 4) /* ugly, add char's to a word */
147 {
148 l= p[sw];
149 p_c2l_p(data,l,sc,len);
150 p[sw]=l;
151 }
152 else
153 {
154 ew=(c->num>>2);
155 ec=(c->num&0x03);
156 l= p[sw];
157 p_c2l(data,l,sc);
158 p[sw++]=l;
159 for (; sw < ew; sw++)
160 { c2l(data,l); p[sw]=l; }
161 if (ec)
162 {
163 c2l_p(data,l,ec);
164 p[sw]=l;
165 }
166 }
167 return;
168 }
169 }
170 /* we now can process the input data in blocks of MD5_CBLOCK
171 * chars and save the leftovers to c->data. */
172#ifdef L_ENDIAN
173 if ((((unsigned long)data)%sizeof(ULONG)) == 0)
174 {
175 sw=(int)len/MD5_CBLOCK;
176 if (sw > 0)
177 {
178 sw*=MD5_CBLOCK;
179 md5_block(c,(ULONG *)data,sw);
180 data+=sw;
181 len-=sw;
182 }
183 }
184#endif
185 p=c->data;
186 while (len >= MD5_CBLOCK)
187 {
188#if defined(L_ENDIAN) || defined(B_ENDIAN)
189 if (p != (unsigned long *)data)
190 memcpy(p,data,MD5_CBLOCK);
191 data+=MD5_CBLOCK;
192#ifdef B_ENDIAN
193 for (sw=(MD5_LBLOCK/4); sw; sw--)
194 {
195 Endian_Reverse32(p[0]);
196 Endian_Reverse32(p[1]);
197 Endian_Reverse32(p[2]);
198 Endian_Reverse32(p[3]);
199 p+=4;
200 }
201#endif
202#else
203 for (sw=(MD5_LBLOCK/4); sw; sw--)
204 {
205 c2l(data,l); *(p++)=l;
206 c2l(data,l); *(p++)=l;
207 c2l(data,l); *(p++)=l;
208 c2l(data,l); *(p++)=l;
209 }
210#endif
211 p=c->data;
212 md5_block(c,p,64);
213 len-=MD5_CBLOCK;
214 }
215 sc=(int)len;
216 c->num=sc;
217 if (sc)
218 {
219 sw=sc>>2; /* words to copy */
220#ifdef L_ENDIAN
221 p[sw]=0;
222 memcpy(p,data,sc);
223#else
224 sc&=0x03;
225 for ( ; sw; sw--)
226 { c2l(data,l); *(p++)=l; }
227 c2l_p(data,l,sc);
228 *p=l;
229#endif
230 }
231 }
232
233void MD5_Transform(c,b)
234MD5_CTX *c;
235unsigned char *b;
236 { 86 {
237 ULONG p[16]; 87 const MD5_LONG *X=data;
238#if !defined(L_ENDIAN) 88 register unsigned long A,B,C,D;
239 ULONG *q; 89 /*
240 int i; 90 * In case you wonder why A-D are declared as long and not
241#endif 91 * as MD5_LONG. Doing so results in slight performance
242 92 * boost on LP64 architectures. The catch is we don't
243#if defined(B_ENDIAN) || defined(L_ENDIAN) 93 * really care if 32 MSBs of a 64-bit register get polluted
244 memcpy(p,b,64); 94 * with eventual overflows as we *save* only 32 LSBs in
245#ifdef B_ENDIAN 95 * *either* case. Now declaring 'em long excuses the compiler
246 q=p; 96 * from keeping 32 MSBs zeroed resulting in 13% performance
247 for (i=(MD5_LBLOCK/4); i; i--) 97 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
248 { 98 * Well, to be honest it should say that this *prevents*
249 Endian_Reverse32(q[0]); 99 * performance degradation.
250 Endian_Reverse32(q[1]); 100 *
251 Endian_Reverse32(q[2]); 101 * <appro@fy.chalmers.se>
252 Endian_Reverse32(q[3]); 102 */
253 q+=4;
254 }
255#endif
256#else
257 q=p;
258 for (i=(MD5_LBLOCK/4); i; i--)
259 {
260 ULONG l;
261 c2l(b,l); *(q++)=l;
262 c2l(b,l); *(q++)=l;
263 c2l(b,l); *(q++)=l;
264 c2l(b,l); *(q++)=l;
265 }
266#endif
267 md5_block(c,p,64);
268 }
269
270#ifndef MD5_ASM
271
272static void md5_block(c, X, num)
273MD5_CTX *c;
274register ULONG *X;
275int num;
276 {
277 register ULONG A,B,C,D;
278 103
279 A=c->A; 104 A=c->A;
280 B=c->B; 105 B=c->B;
281 C=c->C; 106 C=c->C;
282 D=c->D; 107 D=c->D;
283 for (;;) 108
109 for (;num--;X+=HASH_LBLOCK)
284 { 110 {
285 /* Round 0 */ 111 /* Round 0 */
286 R0(A,B,C,D,X[ 0], 7,0xd76aa478L); 112 R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
@@ -351,80 +177,131 @@ int num;
351 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL); 177 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
352 R3(B,C,D,A,X[ 9],21,0xeb86d391L); 178 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
353 179
354 A+=c->A&0xffffffffL; 180 A = c->A += A;
355 B+=c->B&0xffffffffL; 181 B = c->B += B;
356 c->A=A; 182 C = c->C += C;
357 c->B=B; 183 D = c->D += D;
358 C+=c->C&0xffffffffL;
359 D+=c->D&0xffffffffL;
360 c->C=C;
361 c->D=D;
362 X+=16;
363 num-=64;
364 if (num <= 0) break;
365 } 184 }
366 } 185 }
367#endif 186#endif
368 187
369void MD5_Final(md, c) 188#ifndef md5_block_data_order
370unsigned char *md; 189void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
371MD5_CTX *c;
372 { 190 {
373 register int i,j; 191 const unsigned char *data=data_;
374 register ULONG l; 192 register unsigned long A,B,C,D,l;
375 register ULONG *p; 193 /*
376 static unsigned char end[4]={0x80,0x00,0x00,0x00}; 194 * In case you wonder why A-D are declared as long and not
377 unsigned char *cp=end; 195 * as MD5_LONG. Doing so results in slight performance
196 * boost on LP64 architectures. The catch is we don't
197 * really care if 32 MSBs of a 64-bit register get polluted
198 * with eventual overflows as we *save* only 32 LSBs in
199 * *either* case. Now declaring 'em long excuses the compiler
200 * from keeping 32 MSBs zeroed resulting in 13% performance
201 * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
202 * Well, to be honest it should say that this *prevents*
203 * performance degradation.
204 *
205 * <appro@fy.chalmers.se>
206 */
207 MD5_LONG X[MD5_LBLOCK];
208 /*
209 * In case you wonder why don't I use c->data for this.
210 * RISCs usually have a handful of registers and if X is
211 * declared as automatic array good optimizing compiler
212 * shall accomodate at least part of it in register bank
213 * instead of memory.
214 *
215 * <appro@fy.chalmers.se>
216 */
378 217
379 /* c->num should definitly have room for at least one more byte. */ 218 A=c->A;
380 p=c->data; 219 B=c->B;
381 j=c->num; 220 C=c->C;
382 i=j>>2; 221 D=c->D;
383 222
384 /* purify often complains about the following line as an 223 for (;num--;)
385 * Uninitialized Memory Read. While this can be true, the
386 * following p_c2l macro will reset l when that case is true.
387 * This is because j&0x03 contains the number of 'valid' bytes
388 * already in p[i]. If and only if j&0x03 == 0, the UMR will
389 * occur but this is also the only time p_c2l will do
390 * l= *(cp++) instead of l|= *(cp++)
391 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
392 * 'potential bug' */
393#ifdef PURIFY
394 if ((j&0x03) == 0) p[i]=0;
395#endif
396 l=p[i];
397 p_c2l(cp,l,j&0x03);
398 p[i]=l;
399 i++;
400 /* i is the next 'undefined word' */
401 if (c->num >= MD5_LAST_BLOCK)
402 { 224 {
403 for (; i<MD5_LBLOCK; i++) 225 HOST_c2l(data,l); X[ 0]=l; HOST_c2l(data,l); X[ 1]=l;
404 p[i]=0; 226 /* Round 0 */
405 md5_block(c,p,64); 227 R0(A,B,C,D,X[ 0], 7,0xd76aa478L); HOST_c2l(data,l); X[ 2]=l;
406 i=0; 228 R0(D,A,B,C,X[ 1],12,0xe8c7b756L); HOST_c2l(data,l); X[ 3]=l;
407 } 229 R0(C,D,A,B,X[ 2],17,0x242070dbL); HOST_c2l(data,l); X[ 4]=l;
408 for (; i<(MD5_LBLOCK-2); i++) 230 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL); HOST_c2l(data,l); X[ 5]=l;
409 p[i]=0; 231 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL); HOST_c2l(data,l); X[ 6]=l;
410 p[MD5_LBLOCK-2]=c->Nl; 232 R0(D,A,B,C,X[ 5],12,0x4787c62aL); HOST_c2l(data,l); X[ 7]=l;
411 p[MD5_LBLOCK-1]=c->Nh; 233 R0(C,D,A,B,X[ 6],17,0xa8304613L); HOST_c2l(data,l); X[ 8]=l;
412 md5_block(c,p,64); 234 R0(B,C,D,A,X[ 7],22,0xfd469501L); HOST_c2l(data,l); X[ 9]=l;
413 cp=md; 235 R0(A,B,C,D,X[ 8], 7,0x698098d8L); HOST_c2l(data,l); X[10]=l;
414 l=c->A; l2c(l,cp); 236 R0(D,A,B,C,X[ 9],12,0x8b44f7afL); HOST_c2l(data,l); X[11]=l;
415 l=c->B; l2c(l,cp); 237 R0(C,D,A,B,X[10],17,0xffff5bb1L); HOST_c2l(data,l); X[12]=l;
416 l=c->C; l2c(l,cp); 238 R0(B,C,D,A,X[11],22,0x895cd7beL); HOST_c2l(data,l); X[13]=l;
417 l=c->D; l2c(l,cp); 239 R0(A,B,C,D,X[12], 7,0x6b901122L); HOST_c2l(data,l); X[14]=l;
240 R0(D,A,B,C,X[13],12,0xfd987193L); HOST_c2l(data,l); X[15]=l;
241 R0(C,D,A,B,X[14],17,0xa679438eL);
242 R0(B,C,D,A,X[15],22,0x49b40821L);
243 /* Round 1 */
244 R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
245 R1(D,A,B,C,X[ 6], 9,0xc040b340L);
246 R1(C,D,A,B,X[11],14,0x265e5a51L);
247 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
248 R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
249 R1(D,A,B,C,X[10], 9,0x02441453L);
250 R1(C,D,A,B,X[15],14,0xd8a1e681L);
251 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
252 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
253 R1(D,A,B,C,X[14], 9,0xc33707d6L);
254 R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
255 R1(B,C,D,A,X[ 8],20,0x455a14edL);
256 R1(A,B,C,D,X[13], 5,0xa9e3e905L);
257 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
258 R1(C,D,A,B,X[ 7],14,0x676f02d9L);
259 R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
260 /* Round 2 */
261 R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
262 R2(D,A,B,C,X[ 8],11,0x8771f681L);
263 R2(C,D,A,B,X[11],16,0x6d9d6122L);
264 R2(B,C,D,A,X[14],23,0xfde5380cL);
265 R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
266 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
267 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
268 R2(B,C,D,A,X[10],23,0xbebfbc70L);
269 R2(A,B,C,D,X[13], 4,0x289b7ec6L);
270 R2(D,A,B,C,X[ 0],11,0xeaa127faL);
271 R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
272 R2(B,C,D,A,X[ 6],23,0x04881d05L);
273 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
274 R2(D,A,B,C,X[12],11,0xe6db99e5L);
275 R2(C,D,A,B,X[15],16,0x1fa27cf8L);
276 R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
277 /* Round 3 */
278 R3(A,B,C,D,X[ 0], 6,0xf4292244L);
279 R3(D,A,B,C,X[ 7],10,0x432aff97L);
280 R3(C,D,A,B,X[14],15,0xab9423a7L);
281 R3(B,C,D,A,X[ 5],21,0xfc93a039L);
282 R3(A,B,C,D,X[12], 6,0x655b59c3L);
283 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
284 R3(C,D,A,B,X[10],15,0xffeff47dL);
285 R3(B,C,D,A,X[ 1],21,0x85845dd1L);
286 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
287 R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
288 R3(C,D,A,B,X[ 6],15,0xa3014314L);
289 R3(B,C,D,A,X[13],21,0x4e0811a1L);
290 R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
291 R3(D,A,B,C,X[11],10,0xbd3af235L);
292 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
293 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
418 294
419 /* clear stuff, md5_block may be leaving some stuff on the stack 295 A = c->A += A;
420 * but I'm not worried :-) */ 296 B = c->B += B;
421 c->num=0; 297 C = c->C += C;
422/* memset((char *)&c,0,sizeof(c));*/ 298 D = c->D += D;
299 }
423 } 300 }
301#endif
424 302
425#ifdef undef 303#ifdef undef
426int printit(l) 304int printit(unsigned long *l)
427unsigned long *l;
428 { 305 {
429 int i,ii; 306 int i,ii;
430 307
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* On sparc, this actually slows things down :-( */
60#if defined(sun)
61#undef B_ENDIAN
62#endif
63
64#include <stdlib.h> 59#include <stdlib.h>
65#include <string.h> 60#include <string.h>
66#include "md5.h" 61#include <openssl/opensslconf.h>
67 62#include <openssl/md5.h>
68#define ULONG unsigned long
69#define UCHAR unsigned char
70#define UINT unsigned int
71 63
72#if defined(NOCONST) 64#ifndef MD5_LONG_LOG2
73#define const 65#define MD5_LONG_LOG2 2 /* default to 32 bits */
74#endif 66#endif
75 67
76#undef c2l 68#ifdef MD5_ASM
77#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \ 69# if defined(__i386) || defined(_M_IX86)
78 l|=(((unsigned long)(*((c)++)))<< 8), \ 70# define md5_block_host_order md5_block_asm_host_order
79 l|=(((unsigned long)(*((c)++)))<<16), \ 71# elif defined(__sparc) && defined(ULTRASPARC)
80 l|=(((unsigned long)(*((c)++)))<<24)) 72 void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num);
81 73# define HASH_BLOCK_DATA_ORDER_ALIGNED md5_block_asm_data_order_aligned
82#undef p_c2l 74# endif
83#define p_c2l(c,l,n) { \ 75#endif
84 switch (n) { \
85 case 0: l =((unsigned long)(*((c)++))); \
86 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
87 case 2: l|=((unsigned long)(*((c)++)))<<16; \
88 case 3: l|=((unsigned long)(*((c)++)))<<24; \
89 } \
90 }
91
92/* NOTE the pointer is not incremented at the end of this */
93#undef c2l_p
94#define c2l_p(c,l,n) { \
95 l=0; \
96 (c)+=n; \
97 switch (n) { \
98 case 3: l =((unsigned long)(*(--(c))))<<16; \
99 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
100 case 1: l|=((unsigned long)(*(--(c)))) ; \
101 } \
102 }
103 76
104#undef p_c2l_p 77void md5_block_host_order (MD5_CTX *c, const void *p,int num);
105#define p_c2l_p(c,l,sc,len) { \ 78void md5_block_data_order (MD5_CTX *c, const void *p,int num);
106 switch (sc) \
107 { \
108 case 0: l =((unsigned long)(*((c)++))); \
109 if (--len == 0) break; \
110 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
111 if (--len == 0) break; \
112 case 2: l|=((unsigned long)(*((c)++)))<<16; \
113 } \
114 }
115 79
116#undef l2c 80#if defined(__i386) || defined(_M_IX86)
117#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ 81/*
118 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ 82 * *_block_host_order is expected to handle aligned data while
119 *((c)++)=(unsigned char)(((l)>>16)&0xff), \ 83 * *_block_data_order - unaligned. As algorithm and host (x86)
120 *((c)++)=(unsigned char)(((l)>>24)&0xff)) 84 * are in this case of the same "endianess" these two are
85 * otherwise indistinguishable. But normally you don't want to
86 * call the same function because unaligned access in places
87 * where alignment is expected is usually a "Bad Thing". Indeed,
88 * on RISCs you get punished with BUS ERROR signal or *severe*
89 * performance degradation. Intel CPUs are in turn perfectly
90 * capable of loading unaligned data without such drastic side
91 * effect. Yes, they say it's slower than aligned load, but no
92 * exception is generated and therefore performance degradation
93 * is *incomparable* with RISCs. What we should weight here is
94 * costs of unaligned access against costs of aligning data.
95 * According to my measurements allowing unaligned access results
96 * in ~9% performance improvement on Pentium II operating at
97 * 266MHz. I won't be surprised if the difference will be higher
98 * on faster systems:-)
99 *
100 * <appro@fy.chalmers.se>
101 */
102#define md5_block_data_order md5_block_host_order
103#endif
121 104
122/* NOTE - c is not incremented as per l2c */ 105#define DATA_ORDER_IS_LITTLE_ENDIAN
123#undef l2cn 106
124#define l2cn(l1,l2,c,n) { \ 107#define HASH_LONG MD5_LONG
125 c+=n; \ 108#define HASH_LONG_LOG2 MD5_LONG_LOG2
126 switch (n) { \ 109#define HASH_CTX MD5_CTX
127 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ 110#define HASH_CBLOCK MD5_CBLOCK
128 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ 111#define HASH_LBLOCK MD5_LBLOCK
129 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ 112#define HASH_UPDATE MD5_Update
130 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ 113#define HASH_TRANSFORM MD5_Transform
131 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ 114#define HASH_FINAL MD5_Final
132 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ 115#define HASH_BLOCK_HOST_ORDER md5_block_host_order
133 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ 116#if !defined(L_ENDIAN) || defined(md5_block_data_order)
134 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ 117#define HASH_BLOCK_DATA_ORDER md5_block_data_order
135 } \ 118/*
136 } 119 * Little-endians (Intel and Alpha) feel better without this.
120 * It looks like memcpy does better job than generic
121 * md5_block_data_order on copying-n-aligning input data.
122 * But franlky speaking I didn't expect such result on Alpha.
123 * On the other hand I've got this with egcs-1.0.2 and if
124 * program is compiled with another (better?) compiler it
125 * might turn out other way around.
126 *
127 * <appro@fy.chalmers.se>
128 */
129#endif
137 130
138/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ 131#ifndef FLAT_INC
139#if defined(WIN32) 132#include "../md32_common.h"
140/* 5 instructions with rotate instruction, else 9 */
141#define Endian_Reverse32(a) \
142 { \
143 unsigned long l=(a); \
144 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
145 }
146#else 133#else
147/* 6 instructions with rotate instruction, else 8 */ 134#include "md32_common.h"
148#define Endian_Reverse32(a) \
149 { \
150 unsigned long l=(a); \
151 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
152 (a)=ROTATE(l,16L); \
153 }
154#endif 135#endif
136
155/* 137/*
156#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) 138#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
157#define G(x,y,z) (((x) & (z)) | ((y) & (~(z)))) 139#define G(x,y,z) (((x) & (z)) | ((y) & (~(z))))
@@ -166,14 +148,6 @@
166#define H(b,c,d) ((b) ^ (c) ^ (d)) 148#define H(b,c,d) ((b) ^ (c) ^ (d))
167#define I(b,c,d) (((~(d)) | (b)) ^ (c)) 149#define I(b,c,d) (((~(d)) | (b)) ^ (c))
168 150
169#undef ROTATE
170#if defined(WIN32)
171#define ROTATE(a,n) _lrotl(a,n)
172#else
173#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
174#endif
175
176
177#define R0(a,b,c,d,k,s,t) { \ 151#define R0(a,b,c,d,k,s,t) { \
178 a+=((k)+(t)+F((b),(c),(d))); \ 152 a+=((k)+(t)+F((b),(c),(d))); \
179 a=ROTATE(a,s); \ 153 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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "md5_locl.h" 60#include <string.h>
61#include <openssl/md5.h>
61 62
62unsigned char *MD5(d, n, md) 63#ifdef CHARSET_EBCDIC
63unsigned char *d; 64#include <openssl/ebcdic.h>
64unsigned long n; 65#endif
65unsigned char *md; 66
67unsigned char *MD5(unsigned char *d, unsigned long n, unsigned char *md)
66 { 68 {
67 MD5_CTX c; 69 MD5_CTX c;
68 static unsigned char m[MD5_DIGEST_LENGTH]; 70 static unsigned char m[MD5_DIGEST_LENGTH];
69 71
70 if (md == NULL) md=m; 72 if (md == NULL) md=m;
71 MD5_Init(&c); 73 MD5_Init(&c);
74#ifndef CHARSET_EBCDIC
72 MD5_Update(&c,d,n); 75 MD5_Update(&c,d,n);
76#else
77 {
78 char temp[1024];
79 unsigned long chunk;
80
81 while (n > 0)
82 {
83 chunk = (n > sizeof(temp)) ? sizeof(temp) : n;
84 ebcdic2ascii(temp, d, chunk);
85 MD5_Update(&c,temp,chunk);
86 n -= chunk;
87 d += chunk;
88 }
89 }
90#endif
73 MD5_Final(md,&c); 91 MD5_Final(md,&c);
74 memset(&c,0,sizeof(c)); /* security consideration */ 92 memset(&c,0,sizeof(c)); /* security consideration */
75 return(md); 93 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)
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <stdlib.h> 34#include <stdlib.h>
35#include "md5.h" 35#include <openssl/md5.h>
36 36
37extern "C" { 37extern "C" {
38void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num); 38void 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include "md5.h" 62
63#ifdef NO_MD5
64int main(int argc, char *argv[])
65{
66 printf("No MD5 support\n");
67 return(0);
68}
69#else
70#include <openssl/md5.h>
63 71
64char *test[]={ 72char *test[]={
65 "", 73 "",
@@ -82,15 +90,8 @@ char *ret[]={
82 "57edf4a22be3c955ac49da2e2107b67a", 90 "57edf4a22be3c955ac49da2e2107b67a",
83 }; 91 };
84 92
85#ifndef NOPROTO
86static char *pt(unsigned char *md); 93static char *pt(unsigned char *md);
87#else 94int main(int argc, char *argv[])
88static char *pt();
89#endif
90
91int main(argc,argv)
92int argc;
93char *argv[];
94 { 95 {
95 int i,err=0; 96 int i,err=0;
96 unsigned char **P,**R; 97 unsigned char **P,**R;
@@ -118,8 +119,7 @@ char *argv[];
118 return(0); 119 return(0);
119 } 120 }
120 121
121static char *pt(md) 122static char *pt(unsigned char *md)
122unsigned char *md;
123 { 123 {
124 int i; 124 int i;
125 static char buf[80]; 125 static char buf[80];
@@ -128,3 +128,4 @@ unsigned char *md;
128 sprintf(&(buf[i*2]),"%02x",md[i]); 128 sprintf(&(buf[i*2]),"%02x",md[i]);
129 return(buf); 129 return(buf);
130 } 130 }
131#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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,23 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81mdc2_one.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82mdc2_one.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
83mdc2_one.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
84mdc2_one.o: ../../include/openssl/err.h ../../include/openssl/mdc2.h
85mdc2_one.o: ../../include/openssl/opensslconf.h
86mdc2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
87mdc2_one.o: ../cryptlib.h
88mdc2dgst.o: ../../include/openssl/des.h ../../include/openssl/e_os2.h
89mdc2dgst.o: ../../include/openssl/mdc2.h ../../include/openssl/opensslconf.h
diff --git a/src/lib/libcrypto/mdc2/mdc2.h b/src/lib/libcrypto/mdc2/mdc2.h
index 0b104be184..ec8e159fc9 100644
--- a/src/lib/libcrypto/mdc2/mdc2.h
+++ b/src/lib/libcrypto/mdc2/mdc2.h
@@ -63,7 +63,11 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "des.h" 66#include <openssl/des.h>
67
68#ifdef NO_MDC2
69#error MDC2 is disabled.
70#endif
67 71
68#define MDC2_BLOCK 8 72#define MDC2_BLOCK 8
69#define MDC2_DIGEST_LENGTH 16 73#define MDC2_DIGEST_LENGTH 16
@@ -76,22 +80,12 @@ typedef struct mdc2_ctx_st
76 int pad_type; /* either 1 or 2, default 1 */ 80 int pad_type; /* either 1 or 2, default 1 */
77 } MDC2_CTX; 81 } MDC2_CTX;
78 82
79#ifndef NOPROTO
80 83
81void MDC2_Init(MDC2_CTX *c); 84void MDC2_Init(MDC2_CTX *c);
82void MDC2_Update(MDC2_CTX *c, unsigned char *data, unsigned long len); 85void MDC2_Update(MDC2_CTX *c, unsigned char *data, unsigned long len);
83void MDC2_Final(unsigned char *md, MDC2_CTX *c); 86void MDC2_Final(unsigned char *md, MDC2_CTX *c);
84unsigned char *MDC2(unsigned char *d, unsigned long n, unsigned char *md); 87unsigned char *MDC2(unsigned char *d, unsigned long n, unsigned char *md);
85 88
86#else
87
88void MDC2_Init();
89void MDC2_Update();
90void MDC2_Final();
91unsigned char *MDC2();
92
93#endif
94
95#ifdef __cplusplus 89#ifdef __cplusplus
96} 90}
97#endif 91#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "buffer.h" 61#include <openssl/crypto.h>
62#include "bio.h" 62#ifdef CRYPTO_MDEBUG_TIME
63#include "lhash.h" 63# include <time.h>
64#endif
65#include <openssl/buffer.h>
66#include <openssl/bio.h>
67#include <openssl/lhash.h>
64#include "cryptlib.h" 68#include "cryptlib.h"
65 69
70/* #ifdef CRYPTO_MDEBUG */
71/* static int mh_mode=CRYPTO_MEM_CHECK_ON; */
72/* #else */
66static int mh_mode=CRYPTO_MEM_CHECK_OFF; 73static int mh_mode=CRYPTO_MEM_CHECK_OFF;
74/* #endif */
75/* State CRYPTO_MEM_CHECK_ON exists only temporarily when the library
76 * thinks that certain allocations should not be checked (e.g. the data
77 * structures used for memory checking). It is not suitable as an initial
78 * state: the library will unexpectedly enable memory checking when it
79 * executes one of those sections that want to disable checking
80 * temporarily.
81 *
82 * State CRYPTO_MEM_CHECK_ENABLE without ..._ON makes no sense whatsoever.
83 */
84
67static unsigned long order=0; 85static unsigned long order=0;
68 86
69static LHASH *mh=NULL; 87static LHASH *mh=NULL;
@@ -72,25 +90,41 @@ typedef struct mem_st
72 { 90 {
73 char *addr; 91 char *addr;
74 int num; 92 int num;
75 char *file; 93 const char *file;
76 int line; 94 int line;
95#ifdef CRYPTO_MDEBUG_THREAD
96 unsigned long thread;
97#endif
77 unsigned long order; 98 unsigned long order;
99#ifdef CRYPTO_MDEBUG_TIME
100 time_t time;
101#endif
78 } MEM; 102 } MEM;
79 103
80int CRYPTO_mem_ctrl(mode) 104int CRYPTO_mem_ctrl(int mode)
81int mode;
82 { 105 {
83 int ret=mh_mode; 106 int ret=mh_mode;
84 107
85 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); 108 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
86 switch (mode) 109 switch (mode)
87 { 110 {
88 case CRYPTO_MEM_CHECK_ON: 111 /* for applications: */
89 mh_mode|=CRYPTO_MEM_CHECK_ON; 112 case CRYPTO_MEM_CHECK_ON: /* aka MemCheck_start() */
113 mh_mode = CRYPTO_MEM_CHECK_ON|CRYPTO_MEM_CHECK_ENABLE;
114 break;
115 case CRYPTO_MEM_CHECK_OFF: /* aka MemCheck_stop() */
116 mh_mode = 0;
90 break; 117 break;
91 case CRYPTO_MEM_CHECK_OFF: 118
92 mh_mode&= ~CRYPTO_MEM_CHECK_ON; 119 /* switch off temporarily (for library-internal use): */
120 case CRYPTO_MEM_CHECK_DISABLE: /* aka MemCheck_off() */
121 mh_mode&= ~CRYPTO_MEM_CHECK_ENABLE;
93 break; 122 break;
123 case CRYPTO_MEM_CHECK_ENABLE: /* aka MemCheck_on() */
124 if (mh_mode&CRYPTO_MEM_CHECK_ON)
125 mh_mode|=CRYPTO_MEM_CHECK_ENABLE;
126 break;
127
94 default: 128 default:
95 break; 129 break;
96 } 130 }
@@ -98,14 +132,12 @@ int mode;
98 return(ret); 132 return(ret);
99 } 133 }
100 134
101static int mem_cmp(a,b) 135static int mem_cmp(MEM *a, MEM *b)
102MEM *a,*b;
103 { 136 {
104 return(a->addr - b->addr); 137 return(a->addr - b->addr);
105 } 138 }
106 139
107static unsigned long mem_hash(a) 140static unsigned long mem_hash(MEM *a)
108MEM *a;
109 { 141 {
110 unsigned long ret; 142 unsigned long ret;
111 143
@@ -115,54 +147,69 @@ MEM *a;
115 return(ret); 147 return(ret);
116 } 148 }
117 149
150static char *(*malloc_locked_func)()=(char *(*)())malloc;
151static void (*free_locked_func)()=(void (*)())free;
118static char *(*malloc_func)()= (char *(*)())malloc; 152static char *(*malloc_func)()= (char *(*)())malloc;
119static char *(*realloc_func)()= (char *(*)())realloc; 153static char *(*realloc_func)()= (char *(*)())realloc;
120static void (*free_func)()= (void (*)())free; 154static void (*free_func)()= (void (*)())free;
121 155
122void CRYPTO_set_mem_functions(m,r,f) 156void CRYPTO_set_mem_functions(char *(*m)(), char *(*r)(), void (*f)())
123char *(*m)();
124char *(*r)();
125void (*f)();
126 { 157 {
127 if ((m == NULL) || (r == NULL) || (f == NULL)) return; 158 if ((m == NULL) || (r == NULL) || (f == NULL)) return;
128 malloc_func=m; 159 malloc_func=m;
129 realloc_func=r; 160 realloc_func=r;
130 free_func=f; 161 free_func=f;
162 malloc_locked_func=m;
163 free_locked_func=f;
131 } 164 }
132 165
133void CRYPTO_get_mem_functions(m,r,f) 166void CRYPTO_set_locked_mem_functions(char *(*m)(), void (*f)())
134char *(**m)(); 167 {
135char *(**r)(); 168 if ((m == NULL) || (f == NULL)) return;
136void (**f)(); 169 malloc_locked_func=m;
170 free_locked_func=f;
171 }
172
173void CRYPTO_get_mem_functions(char *(**m)(), char *(**r)(), void (**f)())
137 { 174 {
138 if (m != NULL) *m=malloc_func; 175 if (m != NULL) *m=malloc_func;
139 if (r != NULL) *r=realloc_func; 176 if (r != NULL) *r=realloc_func;
140 if (f != NULL) *f=free_func; 177 if (f != NULL) *f=free_func;
141 } 178 }
142 179
143char *CRYPTO_malloc(num) 180void CRYPTO_get_locked_mem_functions(char *(**m)(), void (**f)())
144int num; 181 {
182 if (m != NULL) *m=malloc_locked_func;
183 if (f != NULL) *f=free_locked_func;
184 }
185
186void *CRYPTO_malloc_locked(int num)
187 {
188 return(malloc_locked_func(num));
189 }
190
191void CRYPTO_free_locked(void *str)
192 {
193 free_locked_func(str);
194 }
195
196void *CRYPTO_malloc(int num)
145 { 197 {
146 return(malloc_func(num)); 198 return(malloc_func(num));
147 } 199 }
148 200
149char *CRYPTO_realloc(str,num) 201void *CRYPTO_realloc(void *str, int num)
150char *str;
151int num;
152 { 202 {
153 return(realloc_func(str,num)); 203 return(realloc_func(str,num));
154 } 204 }
155 205
156void CRYPTO_free(str) 206void CRYPTO_free(void *str)
157char *str;
158 { 207 {
159 free_func(str); 208 free_func(str);
160 } 209 }
161 210
162char *CRYPTO_dbg_malloc(num,file,line) 211static unsigned long break_order_num=0;
163int num; 212void *CRYPTO_dbg_malloc(int num, const char *file, int line)
164char *file;
165int line;
166 { 213 {
167 char *ret; 214 char *ret;
168 MEM *m,*mm; 215 MEM *m,*mm;
@@ -170,11 +217,13 @@ int line;
170 if ((ret=malloc_func(num)) == NULL) 217 if ((ret=malloc_func(num)) == NULL)
171 return(NULL); 218 return(NULL);
172 219
173 if (mh_mode & CRYPTO_MEM_CHECK_ON) 220 if (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
174 { 221 {
175 if ((m=(MEM *)malloc(sizeof(MEM))) == NULL) 222 MemCheck_off();
223 if ((m=(MEM *)Malloc(sizeof(MEM))) == NULL)
176 { 224 {
177 free(ret); 225 Free(ret);
226 MemCheck_on();
178 return(NULL); 227 return(NULL);
179 } 228 }
180 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); 229 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
@@ -182,9 +231,10 @@ int line;
182 { 231 {
183 if ((mh=lh_new(mem_hash,mem_cmp)) == NULL) 232 if ((mh=lh_new(mem_hash,mem_cmp)) == NULL)
184 { 233 {
185 free(ret); 234 Free(ret);
186 free(m); 235 Free(m);
187 return(NULL); 236 ret=NULL;
237 goto err;
188 } 238 }
189 } 239 }
190 240
@@ -192,39 +242,49 @@ int line;
192 m->file=file; 242 m->file=file;
193 m->line=line; 243 m->line=line;
194 m->num=num; 244 m->num=num;
245#ifdef CRYPTO_MDEBUG_THREAD
246 m->thread=CRYPTO_thread_id();
247#endif
248 if (order == break_order_num)
249 {
250 /* BREAK HERE */
251 m->order=order;
252 }
195 m->order=order++; 253 m->order=order++;
254#ifdef CRYPTO_MDEBUG_TIME
255 m->time=time(NULL);
256#endif
196 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL) 257 if ((mm=(MEM *)lh_insert(mh,(char *)m)) != NULL)
197 { 258 {
198 /* Not good, but don't sweat it */ 259 /* Not good, but don't sweat it */
199 free(mm); 260 Free(mm);
200 } 261 }
262err:
201 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); 263 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
264 MemCheck_on();
202 } 265 }
203 return(ret); 266 return(ret);
204 } 267 }
205 268
206void CRYPTO_dbg_free(addr) 269void CRYPTO_dbg_free(void *addr)
207char *addr;
208 { 270 {
209 MEM m,*mp; 271 MEM m,*mp;
210 272
211 if ((mh_mode & CRYPTO_MEM_CHECK_ON) && (mh != NULL)) 273 if ((mh_mode & CRYPTO_MEM_CHECK_ENABLE) && (mh != NULL))
212 { 274 {
275 MemCheck_off();
213 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); 276 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
214 m.addr=addr; 277 m.addr=addr;
215 mp=(MEM *)lh_delete(mh,(char *)&m); 278 mp=(MEM *)lh_delete(mh,(char *)&m);
216 if (mp != NULL) 279 if (mp != NULL)
217 free(mp); 280 Free(mp);
218 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); 281 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
282 MemCheck_on();
219 } 283 }
220 free_func(addr); 284 free_func(addr);
221 } 285 }
222 286
223char *CRYPTO_dbg_realloc(addr,num,file,line) 287void *CRYPTO_dbg_realloc(void *addr, int num, const char *file, int line)
224char *addr;
225int num;
226char *file;
227int line;
228 { 288 {
229 char *ret; 289 char *ret;
230 MEM m,*mp; 290 MEM m,*mp;
@@ -232,8 +292,9 @@ int line;
232 ret=realloc_func(addr,num); 292 ret=realloc_func(addr,num);
233 if (ret == addr) return(ret); 293 if (ret == addr) return(ret);
234 294
235 if (mh_mode & CRYPTO_MEM_CHECK_ON) 295 if (mh_mode & CRYPTO_MEM_CHECK_ENABLE)
236 { 296 {
297 MemCheck_off();
237 if (ret == NULL) return(NULL); 298 if (ret == NULL) return(NULL);
238 m.addr=addr; 299 m.addr=addr;
239 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); 300 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
@@ -244,24 +305,19 @@ int line;
244 lh_insert(mh,(char *)mp); 305 lh_insert(mh,(char *)mp);
245 } 306 }
246 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); 307 CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);
308 MemCheck_on();
247 } 309 }
248 return(ret); 310 return(ret);
249 } 311 }
250 312
251char *CRYPTO_remalloc(a,n) 313void *CRYPTO_remalloc(void *a, int n)
252char *a;
253int n;
254 { 314 {
255 if (a != NULL) Free(a); 315 if (a != NULL) Free(a);
256 a=(char *)Malloc(n); 316 a=(char *)Malloc(n);
257 return(a); 317 return(a);
258 } 318 }
259 319
260char *CRYPTO_dbg_remalloc(a,n,file,line) 320void *CRYPTO_dbg_remalloc(void *a, int n, const char *file, int line)
261char *a;
262int n;
263char *file;
264int line;
265 { 321 {
266 if (a != NULL) CRYPTO_dbg_free(a); 322 if (a != NULL) CRYPTO_dbg_free(a);
267 a=(char *)CRYPTO_dbg_malloc(n,file,line); 323 a=(char *)CRYPTO_dbg_malloc(n,file,line);
@@ -276,21 +332,44 @@ typedef struct mem_leak_st
276 long bytes; 332 long bytes;
277 } MEM_LEAK; 333 } MEM_LEAK;
278 334
279static void print_leak(m,l) 335static void print_leak(MEM *m, MEM_LEAK *l)
280MEM *m;
281MEM_LEAK *l;
282 { 336 {
283 char buf[128]; 337 char buf[128];
338#ifdef CRYPTO_MDEBUG_TIME
339 struct tm *lcl;
340#endif
341
342 if(m->addr == (char *)l->bio)
343 return;
344
345#ifdef CRYPTO_MDEBUG_TIME
346 lcl = localtime(&m->time);
347#endif
348
349 sprintf(buf,
350#ifdef CRYPTO_MDEBUG_TIME
351 "[%02d:%02d:%02d] "
352#endif
353 "%5lu file=%s, line=%d, "
354#ifdef CRYPTO_MDEBUG_THREAD
355 "thread=%lu, "
356#endif
357 "number=%d, address=%08lX\n",
358#ifdef CRYPTO_MDEBUG_TIME
359 lcl->tm_hour,lcl->tm_min,lcl->tm_sec,
360#endif
361 m->order,m->file,m->line,
362#ifdef CRYPTO_MDEBUG_THREAD
363 m->thread,
364#endif
365 m->num,(unsigned long)m->addr);
284 366
285 sprintf(buf,"%5ld file=%s, line=%d, number=%d, address=%08lX\n",
286 m->order,m->file,m->line,m->num,(long)m->addr);
287 BIO_puts(l->bio,buf); 367 BIO_puts(l->bio,buf);
288 l->chunks++; 368 l->chunks++;
289 l->bytes+=m->num; 369 l->bytes+=m->num;
290 } 370 }
291 371
292void CRYPTO_mem_leaks(b) 372void CRYPTO_mem_leaks(BIO *b)
293BIO *b;
294 { 373 {
295 MEM_LEAK ml; 374 MEM_LEAK ml;
296 char buf[80]; 375 char buf[80];
@@ -308,25 +387,23 @@ BIO *b;
308 ml.bytes,ml.chunks); 387 ml.bytes,ml.chunks);
309 BIO_puts(b,buf); 388 BIO_puts(b,buf);
310 } 389 }
311 /* 390
391#if 0
312 lh_stats_bio(mh,b); 392 lh_stats_bio(mh,b);
313 lh_node_stats_bio(mh,b); 393 lh_node_stats_bio(mh,b);
314 lh_node_usage_stats_bio(mh,b); 394 lh_node_usage_stats_bio(mh,b);
315 */ 395#endif
316 } 396 }
317 397
318static void (*mem_cb)()=NULL; 398static void (*mem_cb)()=NULL;
319 399
320static void cb_leak(m,cb) 400static void cb_leak(MEM *m, char *cb)
321MEM *m;
322char *cb;
323 { 401 {
324 void (*mem_callback)()=(void (*)())cb; 402 void (*mem_callback)()=(void (*)())cb;
325 mem_callback(m->order,m->file,m->line,m->num,m->addr); 403 mem_callback(m->order,m->file,m->line,m->num,m->addr);
326 } 404 }
327 405
328void CRYPTO_mem_leaks_cb(cb) 406void CRYPTO_mem_leaks_cb(void (*cb)())
329void (*cb)();
330 { 407 {
331 if (mh == NULL) return; 408 if (mh == NULL) return;
332 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); 409 CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);
@@ -337,8 +414,7 @@ void (*cb)();
337 } 414 }
338 415
339#ifndef NO_FP_API 416#ifndef NO_FP_API
340void CRYPTO_mem_leaks_fp(fp) 417void CRYPTO_mem_leaks_fp(FILE *fp)
341FILE *fp;
342 { 418 {
343 BIO *b; 419 BIO *b;
344 420
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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=objects
19ERRC=obj_err
20GENERAL=Makefile README 20GENERAL=Makefile README
21TEST= 21TEST=
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= obj_dat.c obj_lib.c $(ERRC).c 25LIBSRC= o_names.c obj_dat.c obj_lib.c obj_err.c
26LIBOBJ= obj_dat.o obj_lib.o $(ERRC).o 26LIBOBJ= o_names.o obj_dat.o obj_lib.o obj_err.o
27 27
28SRC= $(LIBSRC) 28SRC= $(LIBSRC)
29 29
@@ -38,28 +38,27 @@ top:
38all: obj_dat.h lib 38all: obj_dat.h lib
39 39
40obj_dat.h: objects.h obj_dat.pl 40obj_dat.h: objects.h obj_dat.pl
41 perl ./obj_dat.pl < objects.h > obj_dat.h 41 $(PERL) ./obj_dat.pl < objects.h > obj_dat.h
42 42
43lib: $(LIBOBJ) 43lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ) 44 $(AR) $(LIB) $(LIBOBJ)
45 sh $(TOP)/util/ranlib.sh $(LIB) 45 $(RANLIB) $(LIB)
46 @touch lib 46 @touch lib
47 47
48files: 48files:
49 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 49 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
50 50
51links: 51links:
52 /bin/rm -f Makefile 52 @$(TOP)/util/point.sh Makefile.ssl Makefile
53 $(TOP)/util/point.sh Makefile.ssl Makefile ; 53 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
54 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 54 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
55 $(TOP)/util/mklink.sh ../../test $(TEST) 55 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
56 $(TOP)/util/mklink.sh ../../apps $(APPS)
57 56
58install: 57install:
59 @for i in $(EXHEADER) ; \ 58 @for i in $(EXHEADER) ; \
60 do \ 59 do \
61 (cp $$i $(INSTALLTOP)/include/$$i; \ 60 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
62 chmod 644 $(INSTALLTOP)/include/$$i ); \ 61 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
63 done; 62 done;
64 63
65tags: 64tags:
@@ -71,17 +70,40 @@ lint:
71 lint -DLINT $(INCLUDES) $(SRC)>fluff 70 lint -DLINT $(INCLUDES) $(SRC)>fluff
72 71
73depend: 72depend:
74 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 73 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
75 74
76dclean: 75dclean:
77 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 76 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
78 mv -f Makefile.new $(MAKEFILE) 77 mv -f Makefile.new $(MAKEFILE)
79 78
80clean: 79clean:
81 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 80 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
82
83errors:
84 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
85 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
86 81
87# DO NOT DELETE THIS LINE -- make depend depends on it. 82# DO NOT DELETE THIS LINE -- make depend depends on it.
83
84o_names.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
85o_names.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
86o_names.o: ../../include/openssl/lhash.h ../../include/openssl/objects.h
87o_names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
88o_names.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
89obj_dat.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
90obj_dat.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
91obj_dat.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
92obj_dat.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
93obj_dat.o: ../../include/openssl/lhash.h ../../include/openssl/objects.h
94obj_dat.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95obj_dat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
96obj_dat.o: ../cryptlib.h obj_dat.h
97obj_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
98obj_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
99obj_err.o: ../../include/openssl/err.h ../../include/openssl/objects.h
100obj_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
101obj_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
102obj_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
103obj_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
104obj_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
105obj_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
106obj_lib.o: ../../include/openssl/lhash.h ../../include/openssl/objects.h
107obj_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
108obj_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
109obj_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 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#include <openssl/lhash.h>
6#include <openssl/objects.h>
7
8/* I use the ex_data stuff to manage the identifiers for the obj_name_types
9 * that applications may define. I only really use the free function field.
10 */
11static LHASH *names_lh=NULL;
12static int names_type_num=OBJ_NAME_TYPE_NUM;
13static STACK *names_cmp=NULL;
14static STACK *names_hash=NULL;
15static STACK *names_free=NULL;
16
17static unsigned long obj_name_hash(OBJ_NAME *a);
18static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b);
19
20int OBJ_NAME_init(void)
21 {
22 if (names_lh != NULL) return(1);
23 MemCheck_off();
24 names_lh=lh_new(obj_name_hash,obj_name_cmp);
25 MemCheck_on();
26 return(names_lh != NULL);
27 }
28
29int OBJ_NAME_new_index(unsigned long (*hash_func)(), int (*cmp_func)(),
30 void (*free_func)())
31 {
32 int ret;
33 int i;
34
35 if (names_free == NULL)
36 {
37 MemCheck_off();
38 names_hash=sk_new_null();
39 names_cmp=sk_new_null();
40 names_free=sk_new_null();
41 MemCheck_on();
42 }
43 if ((names_free == NULL) || (names_hash == NULL) || (names_cmp == NULL))
44 {
45 /* ERROR */
46 return(0);
47 }
48 ret=names_type_num;
49 names_type_num++;
50 for (i=sk_num(names_free); i<names_type_num; i++)
51 {
52 MemCheck_off();
53 sk_push(names_hash,(char *)strcmp);
54 sk_push(names_cmp,(char *)lh_strhash);
55 sk_push(names_free,NULL);
56 MemCheck_on();
57 }
58 if (hash_func != NULL)
59 sk_set(names_hash,ret,(char *)hash_func);
60 if (cmp_func != NULL)
61 sk_set(names_cmp,ret,(char *)cmp_func);
62 if (free_func != NULL)
63 sk_set(names_free,ret,(char *)free_func);
64 return(ret);
65 }
66
67static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b)
68 {
69 int ret;
70 int (*cmp)();
71
72 ret=a->type-b->type;
73 if (ret == 0)
74 {
75 if ((names_cmp != NULL) && (sk_num(names_cmp) > a->type))
76 {
77 cmp=(int (*)())sk_value(names_cmp,a->type);
78 ret=cmp(a->name,b->name);
79 }
80 else
81 ret=strcmp(a->name,b->name);
82 }
83 return(ret);
84 }
85
86static unsigned long obj_name_hash(OBJ_NAME *a)
87 {
88 unsigned long ret;
89 unsigned long (*hash)();
90
91 if ((names_hash != NULL) && (sk_num(names_hash) > a->type))
92 {
93 hash=(unsigned long (*)())sk_value(names_hash,a->type);
94 ret=hash(a->name);
95 }
96 else
97 {
98 ret=lh_strhash(a->name);
99 }
100 ret^=a->type;
101 return(ret);
102 }
103
104const char *OBJ_NAME_get(const char *name, int type)
105 {
106 OBJ_NAME on,*ret;
107 int num=0,alias;
108
109 if (name == NULL) return(NULL);
110 if ((names_lh == NULL) && !OBJ_NAME_init()) return(NULL);
111
112 alias=type&OBJ_NAME_ALIAS;
113 type&= ~OBJ_NAME_ALIAS;
114
115 on.name=name;
116 on.type=type;
117
118 for (;;)
119 {
120 ret=(OBJ_NAME *)lh_retrieve(names_lh,(char *)&on);
121 if (ret == NULL) return(NULL);
122 if ((ret->alias) && !alias)
123 {
124 if (++num > 10) return(NULL);
125 on.name=ret->data;
126 }
127 else
128 {
129 return(ret->data);
130 }
131 }
132 }
133
134int OBJ_NAME_add(const char *name, int type, const char *data)
135 {
136 void (*f)();
137 OBJ_NAME *onp,*ret;
138 int alias;
139
140 if ((names_lh == NULL) && !OBJ_NAME_init()) return(0);
141
142 alias=type&OBJ_NAME_ALIAS;
143 type&= ~OBJ_NAME_ALIAS;
144
145 onp=(OBJ_NAME *)Malloc(sizeof(OBJ_NAME));
146 if (onp == NULL)
147 {
148 /* ERROR */
149 return(0);
150 }
151
152 onp->name=name;
153 onp->alias=alias;
154 onp->type=type;
155 onp->data=data;
156
157 ret=(OBJ_NAME *)lh_insert(names_lh,(char *)onp);
158 if (ret != NULL)
159 {
160 /* free things */
161 if ((names_free != NULL) && (sk_num(names_free) > ret->type))
162 {
163 f=(void (*)())sk_value(names_free,ret->type);
164 f(ret->name,ret->type,ret->data);
165 }
166 Free((char *)ret);
167 }
168 else
169 {
170 if (lh_error(names_lh))
171 {
172 /* ERROR */
173 return(0);
174 }
175 }
176 return(1);
177 }
178
179int OBJ_NAME_remove(const char *name, int type)
180 {
181 OBJ_NAME on,*ret;
182 void (*f)();
183
184 if (names_lh == NULL) return(0);
185
186 type&= ~OBJ_NAME_ALIAS;
187 on.name=name;
188 on.type=type;
189 ret=(OBJ_NAME *)lh_delete(names_lh,(char *)&on);
190 if (ret != NULL)
191 {
192 /* free things */
193 if ((names_free != NULL) && (sk_num(names_free) > type))
194 {
195 f=(void (*)())sk_value(names_free,type);
196 f(ret->name,ret->type,ret->data);
197 }
198 Free((char *)ret);
199 return(1);
200 }
201 else
202 return(0);
203 }
204
205static int free_type;
206
207static void names_lh_free(OBJ_NAME *onp, int type)
208{
209 if(onp == NULL)
210 return;
211
212 if ((free_type < 0) || (free_type == onp->type))
213 {
214 OBJ_NAME_remove(onp->name,onp->type);
215 }
216 }
217
218void OBJ_NAME_cleanup(int type)
219 {
220 unsigned long down_load;
221
222 if (names_lh == NULL) return;
223
224 free_type=type;
225 down_load=names_lh->down_load;
226 names_lh->down_load=0;
227
228 lh_doall(names_lh,names_lh_free);
229 if (type < 0)
230 {
231 lh_free(names_lh);
232 sk_free(names_hash);
233 sk_free(names_cmp);
234 sk_free(names_free);
235 names_lh=NULL;
236 names_hash=NULL;
237 names_cmp=NULL;
238 names_free=NULL;
239 }
240 else
241 names_lh->down_load=down_load;
242 }
243
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index 34866ebbd2..d47b874399 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -59,23 +59,29 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <ctype.h> 60#include <ctype.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "lhash.h" 62#include <openssl/lhash.h>
63#include "asn1.h" 63#include <openssl/asn1.h>
64#include "objects.h" 64#include <openssl/objects.h>
65 65
66/* obj_dat.h is generated from objects.h by obj_dat.pl */ 66/* obj_dat.h is generated from objects.h by obj_dat.pl */
67#ifndef NO_OBJECT
67#include "obj_dat.h" 68#include "obj_dat.h"
69#else
70/* You will have to load all the objects needed manually in the application */
71#define NUM_NID 0
72#define NUM_SN 0
73#define NUM_LN 0
74#define NUM_OBJ 0
75static unsigned char lvalues[1];
76static ASN1_OBJECT nid_objs[1];
77static ASN1_OBJECT *sn_objs[1];
78static ASN1_OBJECT *ln_objs[1];
79static ASN1_OBJECT *obj_objs[1];
80#endif
68 81
69#ifndef NOPROTO
70static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); 82static int sn_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
71static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); 83static int ln_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
72static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b); 84static int obj_cmp(ASN1_OBJECT **a, ASN1_OBJECT **b);
73#else
74static int sn_cmp();
75static int ln_cmp();
76static int obj_cmp();
77#endif
78
79#define ADDED_DATA 0 85#define ADDED_DATA 0
80#define ADDED_SNAME 1 86#define ADDED_SNAME 1
81#define ADDED_LNAME 2 87#define ADDED_LNAME 2
@@ -90,18 +96,13 @@ typedef struct added_obj_st
90static int new_nid=NUM_NID; 96static int new_nid=NUM_NID;
91static LHASH *added=NULL; 97static LHASH *added=NULL;
92 98
93static int sn_cmp(ap,bp) 99static int sn_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
94ASN1_OBJECT **ap;
95ASN1_OBJECT **bp;
96 { return(strcmp((*ap)->sn,(*bp)->sn)); } 100 { return(strcmp((*ap)->sn,(*bp)->sn)); }
97 101
98static int ln_cmp(ap,bp) 102static int ln_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
99ASN1_OBJECT **ap;
100ASN1_OBJECT **bp;
101 { return(strcmp((*ap)->ln,(*bp)->ln)); } 103 { return(strcmp((*ap)->ln,(*bp)->ln)); }
102 104
103static unsigned long add_hash(ca) 105static unsigned long add_hash(ADDED_OBJ *ca)
104ADDED_OBJ *ca;
105 { 106 {
106 ASN1_OBJECT *a; 107 ASN1_OBJECT *a;
107 int i; 108 int i;
@@ -134,8 +135,7 @@ ADDED_OBJ *ca;
134 return(ret); 135 return(ret);
135 } 136 }
136 137
137static int add_cmp(ca,cb) 138static int add_cmp(ADDED_OBJ *ca, ADDED_OBJ *cb)
138ADDED_OBJ *ca,*cb;
139 { 139 {
140 ASN1_OBJECT *a,*b; 140 ASN1_OBJECT *a,*b;
141 int i; 141 int i;
@@ -163,36 +163,35 @@ ADDED_OBJ *ca,*cb;
163 default: 163 default:
164 abort(); 164 abort();
165 } 165 }
166 return(1); /* should not get here */
166 } 167 }
167 168
168static int init_added() 169static int init_added(void)
169 { 170 {
170 if (added != NULL) return(1); 171 if (added != NULL) return(1);
171 added=lh_new(add_hash,add_cmp); 172 added=lh_new(add_hash,add_cmp);
172 return(added != NULL); 173 return(added != NULL);
173 } 174 }
174 175
175static void cleanup1(a) 176static void cleanup1(ADDED_OBJ *a)
176ADDED_OBJ *a;
177 { 177 {
178 a->obj->nid=0; 178 a->obj->nid=0;
179 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC| 179 a->obj->flags|=ASN1_OBJECT_FLAG_DYNAMIC|
180 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS; 180 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
181 ASN1_OBJECT_FLAG_DYNAMIC_DATA;
181 } 182 }
182 183
183static void cleanup2(a) 184static void cleanup2(ADDED_OBJ *a)
184ADDED_OBJ *a;
185 { a->obj->nid++; } 185 { a->obj->nid++; }
186 186
187static void cleanup3(a) 187static void cleanup3(ADDED_OBJ *a)
188ADDED_OBJ *a;
189 { 188 {
190 if (--a->obj->nid == 0) 189 if (--a->obj->nid == 0)
191 ASN1_OBJECT_free(a->obj); 190 ASN1_OBJECT_free(a->obj);
192 Free(a); 191 Free(a);
193 } 192 }
194 193
195void OBJ_cleanup() 194void OBJ_cleanup(void)
196 { 195 {
197 if (added == NULL) return; 196 if (added == NULL) return;
198 added->down_load=0; 197 added->down_load=0;
@@ -203,8 +202,7 @@ void OBJ_cleanup()
203 added=NULL; 202 added=NULL;
204 } 203 }
205 204
206int OBJ_new_nid(num) 205int OBJ_new_nid(int num)
207int num;
208 { 206 {
209 int i; 207 int i;
210 208
@@ -213,8 +211,7 @@ int num;
213 return(i); 211 return(i);
214 } 212 }
215 213
216int OBJ_add_object(obj) 214int OBJ_add_object(ASN1_OBJECT *obj)
217ASN1_OBJECT *obj;
218 { 215 {
219 ASN1_OBJECT *o; 216 ASN1_OBJECT *o;
220 ADDED_OBJ *ao[4],*aop; 217 ADDED_OBJ *ao[4],*aop;
@@ -247,7 +244,9 @@ ASN1_OBJECT *obj;
247 Free(aop); 244 Free(aop);
248 } 245 }
249 } 246 }
250 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS); 247 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
248 ASN1_OBJECT_FLAG_DYNAMIC_DATA);
249
251 return(o->nid); 250 return(o->nid);
252err: 251err:
253 for (i=ADDED_DATA; i<=ADDED_NID; i++) 252 for (i=ADDED_DATA; i<=ADDED_NID; i++)
@@ -256,8 +255,7 @@ err:
256 return(NID_undef); 255 return(NID_undef);
257 } 256 }
258 257
259ASN1_OBJECT *OBJ_nid2obj(n) 258ASN1_OBJECT *OBJ_nid2obj(int n)
260int n;
261 { 259 {
262 ADDED_OBJ ad,*adp; 260 ADDED_OBJ ad,*adp;
263 ASN1_OBJECT ob; 261 ASN1_OBJECT ob;
@@ -289,8 +287,7 @@ int n;
289 } 287 }
290 } 288 }
291 289
292char *OBJ_nid2sn(n) 290const char *OBJ_nid2sn(int n)
293int n;
294 { 291 {
295 ADDED_OBJ ad,*adp; 292 ADDED_OBJ ad,*adp;
296 ASN1_OBJECT ob; 293 ASN1_OBJECT ob;
@@ -322,8 +319,7 @@ int n;
322 } 319 }
323 } 320 }
324 321
325char *OBJ_nid2ln(n) 322const char *OBJ_nid2ln(int n)
326int n;
327 { 323 {
328 ADDED_OBJ ad,*adp; 324 ADDED_OBJ ad,*adp;
329 ASN1_OBJECT ob; 325 ASN1_OBJECT ob;
@@ -355,8 +351,7 @@ int n;
355 } 351 }
356 } 352 }
357 353
358int OBJ_obj2nid(a) 354int OBJ_obj2nid(ASN1_OBJECT *a)
359ASN1_OBJECT *a;
360 { 355 {
361 ASN1_OBJECT **op; 356 ASN1_OBJECT **op;
362 ADDED_OBJ ad,*adp; 357 ADDED_OBJ ad,*adp;
@@ -380,45 +375,126 @@ ASN1_OBJECT *a;
380 return((*op)->nid); 375 return((*op)->nid);
381 } 376 }
382 377
383int OBJ_txt2nid(s) 378/* Convert an object name into an ASN1_OBJECT
384char *s; 379 * if "noname" is not set then search for short and long names first.
380 * This will convert the "dotted" form into an object: unlike OBJ_txt2nid
381 * it can be used with any objects, not just registered ones.
382 */
383
384ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
385 { 385 {
386 int ret; 386 int nid = NID_undef;
387 ASN1_OBJECT *op=NULL;
388 unsigned char *buf,*p;
389 int i, j;
387 390
388 ret=OBJ_sn2nid(s); 391 if(!no_name) {
389 if (ret == NID_undef) 392 if( ((nid = OBJ_sn2nid(s)) != NID_undef) ||
390 { 393 ((nid = OBJ_ln2nid(s)) != NID_undef) )
391 ret=OBJ_ln2nid(s); 394 return OBJ_nid2obj(nid);
392 if (ret == NID_undef) 395 }
393 {
394 ASN1_OBJECT *op=NULL;
395 unsigned char *buf,*p;
396 int i;
397 396
398 i=a2d_ASN1_OBJECT(NULL,0,s,-1); 397 /* Work out size of content octets */
399 if (i <= 0) 398 i=a2d_ASN1_OBJECT(NULL,0,s,-1);
400 { 399 if (i <= 0) {
401 /* clear the error */ 400 /* Clear the error */
402 ERR_get_error(); 401 ERR_get_error();
403 return(0); 402 return NULL;
404 } 403 }
404 /* Work out total size */
405 j = ASN1_object_size(0,i,V_ASN1_OBJECT);
406
407 if((buf=(unsigned char *)Malloc(j)) == NULL) return NULL;
408
409 p = buf;
410 /* Write out tag+length */
411 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
412 /* Write out contents */
413 a2d_ASN1_OBJECT(p,i,s,-1);
414
415 p=buf;
416 op=d2i_ASN1_OBJECT(NULL,&p,i);
417 Free(buf);
418 return op;
419 }
420
421int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name)
422{
423 int i,idx=0,n=0,len,nid;
424 unsigned long l;
425 unsigned char *p;
426 const char *s;
427 char tbuf[32];
428
429 if (buf_len <= 0) return(0);
430
431 if ((a == NULL) || (a->data == NULL)) {
432 buf[0]='\0';
433 return(0);
434 }
405 435
406 if ((buf=(unsigned char *)Malloc(i)) == NULL) 436 nid=OBJ_obj2nid(a);
407 return(NID_undef); 437 if ((nid == NID_undef) || no_name) {
408 a2d_ASN1_OBJECT(buf,i,s,-1); 438 len=a->length;
409 p=buf; 439 p=a->data;
410 op=d2i_ASN1_OBJECT(NULL,&p,i); 440
411 if (op == NULL) return(NID_undef); 441 idx=0;
412 ret=OBJ_obj2nid(op); 442 l=0;
413 ASN1_OBJECT_free(op); 443 while (idx < a->length) {
414 Free(buf); 444 l|=(p[idx]&0x7f);
445 if (!(p[idx] & 0x80)) break;
446 l<<=7L;
447 idx++;
448 }
449 idx++;
450 i=(int)(l/40);
451 if (i > 2) i=2;
452 l-=(long)(i*40);
453
454 sprintf(tbuf,"%d.%lu",i,l);
455 i=strlen(tbuf);
456 strncpy(buf,tbuf,buf_len);
457 buf_len-=i;
458 buf+=i;
459 n+=i;
460
461 l=0;
462 for (; idx<len; idx++) {
463 l|=p[idx]&0x7f;
464 if (!(p[idx] & 0x80)) {
465 sprintf(tbuf,".%lu",l);
466 i=strlen(tbuf);
467 if (buf_len > 0)
468 strncpy(buf,tbuf,buf_len);
469 buf_len-=i;
470 buf+=i;
471 n+=i;
472 l=0;
415 } 473 }
474 l<<=7L;
416 } 475 }
417 return(ret); 476 } else {
477 s=OBJ_nid2ln(nid);
478 if (s == NULL)
479 s=OBJ_nid2sn(nid);
480 strncpy(buf,s,buf_len);
481 n=strlen(s);
418 } 482 }
483 buf[buf_len-1]='\0';
484 return(n);
485}
419 486
420int OBJ_ln2nid(s) 487int OBJ_txt2nid(char *s)
421char *s; 488{
489 ASN1_OBJECT *obj;
490 int nid;
491 obj = OBJ_txt2obj(s, 0);
492 nid = OBJ_obj2nid(obj);
493 ASN1_OBJECT_free(obj);
494 return nid;
495}
496
497int OBJ_ln2nid(const char *s)
422 { 498 {
423 ASN1_OBJECT o,*oo= &o,**op; 499 ASN1_OBJECT o,*oo= &o,**op;
424 ADDED_OBJ ad,*adp; 500 ADDED_OBJ ad,*adp;
@@ -437,8 +513,7 @@ char *s;
437 return((*op)->nid); 513 return((*op)->nid);
438 } 514 }
439 515
440int OBJ_sn2nid(s) 516int OBJ_sn2nid(const char *s)
441char *s;
442 { 517 {
443 ASN1_OBJECT o,*oo= &o,**op; 518 ASN1_OBJECT o,*oo= &o,**op;
444 ADDED_OBJ ad,*adp; 519 ADDED_OBJ ad,*adp;
@@ -457,9 +532,7 @@ char *s;
457 return((*op)->nid); 532 return((*op)->nid);
458 } 533 }
459 534
460static int obj_cmp(ap, bp) 535static int obj_cmp(ASN1_OBJECT **ap, ASN1_OBJECT **bp)
461ASN1_OBJECT **ap;
462ASN1_OBJECT **bp;
463 { 536 {
464 int j; 537 int j;
465 ASN1_OBJECT *a= *ap; 538 ASN1_OBJECT *a= *ap;
@@ -470,12 +543,7 @@ ASN1_OBJECT **bp;
470 return(memcmp(a->data,b->data,a->length)); 543 return(memcmp(a->data,b->data,a->length));
471 } 544 }
472 545
473char *OBJ_bsearch(key,base,num,size,cmp) 546char *OBJ_bsearch(char *key, char *base, int num, int size, int (*cmp)())
474char *key;
475char *base;
476int num;
477int size;
478int (*cmp)();
479 { 547 {
480 int l,h,i,c; 548 int l,h,i,c;
481 char *p; 549 char *p;
@@ -495,14 +563,24 @@ int (*cmp)();
495 else 563 else
496 return(p); 564 return(p);
497 } 565 }
566#ifdef CHARSET_EBCDIC
567/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and
568 * I don't have perl (yet), we revert to a *LINEAR* search
569 * when the object wasn't found in the binary search.
570 */
571 for (i=0; i<num; ++i) {
572 p= &(base[i*size]);
573 if ((*cmp)(key,p) == 0)
574 return p;
575 }
576#endif
498 return(NULL); 577 return(NULL);
499 } 578 }
500 579
501int OBJ_create_objects(in) 580int OBJ_create_objects(BIO *in)
502BIO *in;
503 { 581 {
504 MS_STATIC char buf[512]; 582 MS_STATIC char buf[512];
505 int i,num= -1; 583 int i,num=0;
506 char *o,*s,*l=NULL; 584 char *o,*s,*l=NULL;
507 585
508 for (;;) 586 for (;;)
@@ -511,26 +589,26 @@ BIO *in;
511 i=BIO_gets(in,buf,512); 589 i=BIO_gets(in,buf,512);
512 if (i <= 0) return(num); 590 if (i <= 0) return(num);
513 buf[i-1]='\0'; 591 buf[i-1]='\0';
514 if (!isalnum(buf[0])) return(num); 592 if (!isalnum((unsigned char)buf[0])) return(num);
515 o=s=buf; 593 o=s=buf;
516 while (isdigit(*s) || (*s == '.')) 594 while (isdigit((unsigned char)*s) || (*s == '.'))
517 s++; 595 s++;
518 if (*s != '\0') 596 if (*s != '\0')
519 { 597 {
520 *(s++)='\0'; 598 *(s++)='\0';
521 while (isspace(*s)) 599 while (isspace((unsigned char)*s))
522 s++; 600 s++;
523 if (*s == '\0') 601 if (*s == '\0')
524 s=NULL; 602 s=NULL;
525 else 603 else
526 { 604 {
527 l=s; 605 l=s;
528 while ((*l != '\0') && !isspace(*l)) 606 while ((*l != '\0') && !isspace((unsigned char)*l))
529 l++; 607 l++;
530 if (*l != '\0') 608 if (*l != '\0')
531 { 609 {
532 *(l++)='\0'; 610 *(l++)='\0';
533 while (isspace(*l)) 611 while (isspace((unsigned char)*l))
534 l++; 612 l++;
535 if (*l == '\0') l=NULL; 613 if (*l == '\0') l=NULL;
536 } 614 }
@@ -544,13 +622,10 @@ BIO *in;
544 if (!OBJ_create(o,s,l)) return(num); 622 if (!OBJ_create(o,s,l)) return(num);
545 num++; 623 num++;
546 } 624 }
547 return(num); 625 /* return(num); */
548 } 626 }
549 627
550int OBJ_create(oid,sn,ln) 628int OBJ_create(char *oid, char *sn, char *ln)
551char *oid;
552char *sn;
553char *ln;
554 { 629 {
555 int ok=0; 630 int ok=0;
556 ASN1_OBJECT *op=NULL; 631 ASN1_OBJECT *op=NULL;
diff --git a/src/lib/libcrypto/objects/obj_dat.h b/src/lib/libcrypto/objects/obj_dat.h
deleted file mode 100644
index 48143ae3c7..0000000000
--- a/src/lib/libcrypto/objects/obj_dat.h
+++ /dev/null
@@ -1,656 +0,0 @@
1/* lib/obj/obj_dat.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* THIS FILE IS GENERATED FROM Objects.h by obj_dat.pl via the
60 * following command:
61 * perl obj_dat.pl < objects.h > obj_dat.h
62 */
63
64#define NUM_NID 124
65#define NUM_SN 95
66#define NUM_LN 122
67#define NUM_OBJ 95
68
69static unsigned char lvalues[600]={
700x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */
710x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */
720x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */
730x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x05, /* [ 21] OBJ_md5 */
740x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x04, /* [ 29] OBJ_rc4 */
750x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x01,/* [ 37] OBJ_rsaEncryption */
760x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x02,/* [ 46] OBJ_md2WithRSAEncryption */
770x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x04,/* [ 55] OBJ_md5WithRSAEncryption */
780x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x01,/* [ 64] OBJ_pbeWithMD2AndDES_CBC */
790x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x03,/* [ 73] OBJ_pbeWithMD5AndDES_CBC */
800x55, /* [ 82] OBJ_X500 */
810x55,0x04, /* [ 83] OBJ_X509 */
820x55,0x04,0x03, /* [ 85] OBJ_commonName */
830x55,0x04,0x06, /* [ 88] OBJ_countryName */
840x55,0x04,0x07, /* [ 91] OBJ_localityName */
850x55,0x04,0x08, /* [ 94] OBJ_stateOrProvinceName */
860x55,0x04,0x0A, /* [ 97] OBJ_organizationName */
870x55,0x04,0x0B, /* [100] OBJ_organizationalUnitName */
880x55,0x08,0x01,0x01, /* [103] OBJ_rsa */
890x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07, /* [107] OBJ_pkcs7 */
900x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x01,/* [115] OBJ_pkcs7_data */
910x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x02,/* [124] OBJ_pkcs7_signed */
920x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x03,/* [133] OBJ_pkcs7_enveloped */
930x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x04,/* [142] OBJ_pkcs7_signedAndEnveloped */
940x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x05,/* [151] OBJ_pkcs7_digest */
950x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x07,0x06,/* [160] OBJ_pkcs7_encrypted */
960x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03, /* [169] OBJ_pkcs3 */
970x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x03,0x01,/* [177] OBJ_dhKeyAgreement */
980x2B,0x0E,0x03,0x02,0x06, /* [186] OBJ_des_ecb */
990x2B,0x0E,0x03,0x02,0x09, /* [191] OBJ_des_cfb64 */
1000x2B,0x0E,0x03,0x02,0x07, /* [196] OBJ_des_cbc */
1010x2B,0x0E,0x03,0x02,0x11, /* [201] OBJ_des_ede */
1020x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x02, /* [206] OBJ_rc2_cbc */
1030x2B,0x0E,0x03,0x02,0x12, /* [214] OBJ_sha */
1040x2B,0x0E,0x03,0x02,0x0F, /* [219] OBJ_shaWithRSAEncryption */
1050x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x07, /* [224] OBJ_des_ede3_cbc */
1060x2B,0x0E,0x03,0x02,0x08, /* [232] OBJ_des_ofb64 */
1070x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09, /* [237] OBJ_pkcs9 */
1080x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x01,/* [245] OBJ_pkcs9_emailAddress */
1090x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x02,/* [254] OBJ_pkcs9_unstructuredName */
1100x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x03,/* [263] OBJ_pkcs9_contentType */
1110x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x04,/* [272] OBJ_pkcs9_messageDigest */
1120x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x05,/* [281] OBJ_pkcs9_signingTime */
1130x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x06,/* [290] OBJ_pkcs9_countersignature */
1140x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x07,/* [299] OBJ_pkcs9_challengePassword */
1150x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x08,/* [308] OBJ_pkcs9_unstructuredAddress */
1160x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x09,0x09,/* [317] OBJ_pkcs9_extCertAttributes */
1170x60,0x86,0x48,0x01,0x86,0xF8,0x42, /* [326] OBJ_netscape */
1180x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01, /* [333] OBJ_netscape_cert_extension */
1190x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02, /* [341] OBJ_netscape_data_type */
1200x2B,0x0E,0x03,0x02,0x1A, /* [349] OBJ_sha1 */
1210x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x01,0x05,/* [354] OBJ_sha1WithRSAEncryption */
1220x2B,0x0E,0x03,0x02,0x0D, /* [363] OBJ_dsaWithSHA */
1230x2B,0x0E,0x03,0x02,0x0C, /* [368] OBJ_dsa_2 */
1240x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0B,/* [373] OBJ_pbeWithSHA1AndRC2_CBC */
1250x2A,0x86,0x48,0x86,0xF7,0x0D,0x01,0x05,0x0C,/* [382] OBJ_pbeWithSHA1AndRC4 */
1260x2B,0x0E,0x03,0x02,0x1B, /* [391] OBJ_dsaWithSHA1_2 */
1270x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x01,/* [396] OBJ_netscape_cert_type */
1280x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x02,/* [405] OBJ_netscape_base_url */
1290x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x03,/* [414] OBJ_netscape_revocation_url */
1300x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x04,/* [423] OBJ_netscape_ca_revocation_url */
1310x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x07,/* [432] OBJ_netscape_renewal_url */
1320x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x08,/* [441] OBJ_netscape_ca_policy_url */
1330x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0C,/* [450] OBJ_netscape_ssl_server_name */
1340x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x01,0x0D,/* [459] OBJ_netscape_comment */
1350x60,0x86,0x48,0x01,0x86,0xF8,0x42,0x02,0x05,/* [468] OBJ_netscape_cert_sequence */
1360x55,0x1D, /* [477] OBJ_ld_ce */
1370x55,0x1D,0x0E, /* [479] OBJ_subject_key_identifier */
1380x55,0x1D,0x0F, /* [482] OBJ_key_usage */
1390x55,0x1D,0x10, /* [485] OBJ_private_key_usage_period */
1400x55,0x1D,0x11, /* [488] OBJ_subject_alt_name */
1410x55,0x1D,0x12, /* [491] OBJ_issuer_alt_name */
1420x55,0x1D,0x13, /* [494] OBJ_basic_constraints */
1430x55,0x1D,0x14, /* [497] OBJ_crl_number */
1440x55,0x1D,0x20, /* [500] OBJ_certificate_policies */
1450x55,0x1D,0x23, /* [503] OBJ_authority_key_identifier */
1460x55,0x08,0x03,0x65, /* [506] OBJ_mdc2 */
1470x55,0x08,0x03,0x64, /* [510] OBJ_mdc2WithRSA */
1480x55,0x04,0x2A, /* [514] OBJ_givenName */
1490x55,0x04,0x04, /* [517] OBJ_surname */
1500x55,0x04,0x2B, /* [520] OBJ_initials */
1510x55,0x04,0x2D, /* [523] OBJ_uniqueIdentifier */
1520x55,0x1D,0x1F, /* [526] OBJ_crl_distribution_points */
1530x2B,0x0E,0x03,0x02,0x03, /* [529] OBJ_md5WithRSA */
1540x55,0x04,0x05, /* [534] OBJ_serialNumber */
1550x55,0x04,0x0C, /* [537] OBJ_title */
1560x55,0x04,0x0D, /* [540] OBJ_description */
1570x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0A,/* [543] OBJ_cast5_cbc */
1580x2A,0x86,0x48,0x86,0xF6,0x7D,0x07,0x42,0x0C,/* [552] OBJ_pbeWithMD5AndCast5_CBC */
1590x2A,0x86,0x48,0xCE,0x38,0x04,0x03, /* [561] OBJ_dsaWithSHA1 */
1600x2B,0x0E,0x03,0x02,0x1D, /* [568] OBJ_sha1WithRSA */
1610x2A,0x86,0x48,0xCE,0x38,0x04,0x01, /* [573] OBJ_dsa */
1620x2B,0x24,0x03,0x02,0x01, /* [580] OBJ_ripemd160 */
1630x2B,0x24,0x03,0x03,0x01,0x02, /* [585] OBJ_ripemd160WithRSA */
1640x2A,0x86,0x48,0x86,0xF7,0x0D,0x03,0x08, /* [591] OBJ_rc5_cbc */
165};
166
167static ASN1_OBJECT nid_objs[NUM_NID]={
168{"UNDEF","undefined",NID_undef,0,NULL},
169{"rsadsi","rsadsi",NID_rsadsi,6,&(lvalues[0]),0},
170{"pkcs","pkcs",NID_pkcs,7,&(lvalues[6]),0},
171{"MD2","md2",NID_md2,8,&(lvalues[13]),0},
172{"MD5","md5",NID_md5,8,&(lvalues[21]),0},
173{"RC4","rc4",NID_rc4,8,&(lvalues[29]),0},
174{"rsaEncryption","rsaEncryption",NID_rsaEncryption,9,&(lvalues[37]),0},
175{"RSA-MD2","md2WithRSAEncryption",NID_md2WithRSAEncryption,9,
176 &(lvalues[46]),0},
177{"RSA-MD5","md5WithRSAEncryption",NID_md5WithRSAEncryption,9,
178 &(lvalues[55]),0},
179{"pbeWithMD2AndDES-CBC","pbeWithMD2AndDES-CBC",
180 NID_pbeWithMD2AndDES_CBC,9,&(lvalues[64]),0},
181{"pbeWithMD5AndDES-CBC","pbeWithMD5AndDES-CBC",
182 NID_pbeWithMD5AndDES_CBC,9,&(lvalues[73]),0},
183{"X500","X500",NID_X500,1,&(lvalues[82]),0},
184{"X509","X509",NID_X509,2,&(lvalues[83]),0},
185{"CN","commonName",NID_commonName,3,&(lvalues[85]),0},
186{"C","countryName",NID_countryName,3,&(lvalues[88]),0},
187{"L","localityName",NID_localityName,3,&(lvalues[91]),0},
188{"ST","stateOrProvinceName",NID_stateOrProvinceName,3,&(lvalues[94]),0},
189{"O","organizationName",NID_organizationName,3,&(lvalues[97]),0},
190{"OU","organizationalUnitName",NID_organizationalUnitName,3,
191 &(lvalues[100]),0},
192{"RSA","rsa",NID_rsa,4,&(lvalues[103]),0},
193{"pkcs7","pkcs7",NID_pkcs7,8,&(lvalues[107]),0},
194{"pkcs7-data","pkcs7-data",NID_pkcs7_data,9,&(lvalues[115]),0},
195{"pkcs7-signedData","pkcs7-signedData",NID_pkcs7_signed,9,
196 &(lvalues[124]),0},
197{"pkcs7-envelopedData","pkcs7-envelopedData",NID_pkcs7_enveloped,9,
198 &(lvalues[133]),0},
199{"pkcs7-signedAndEnvelopedData","pkcs7-signedAndEnvelopedData",
200 NID_pkcs7_signedAndEnveloped,9,&(lvalues[142]),0},
201{"pkcs7-digestData","pkcs7-digestData",NID_pkcs7_digest,9,
202 &(lvalues[151]),0},
203{"pkcs7-encryptedData","pkcs7-encryptedData",NID_pkcs7_encrypted,9,
204 &(lvalues[160]),0},
205{"pkcs3","pkcs3",NID_pkcs3,8,&(lvalues[169]),0},
206{"dhKeyAgreement","dhKeyAgreement",NID_dhKeyAgreement,9,
207 &(lvalues[177]),0},
208{"DES-ECB","des-ecb",NID_des_ecb,5,&(lvalues[186]),0},
209{"DES-CFB","des-cfb",NID_des_cfb64,5,&(lvalues[191]),0},
210{"DES-CBC","des-cbc",NID_des_cbc,5,&(lvalues[196]),0},
211{"DES-EDE","des-ede",NID_des_ede,5,&(lvalues[201]),0},
212{"DES-EDE3","des-ede3",NID_des_ede3,0,NULL},
213{"IDEA-CBC","idea-cbc",NID_idea_cbc,0,NULL},
214{"IDEA-CFB","idea-cfb",NID_idea_cfb64,0,NULL},
215{"IDEA-ECB","idea-ecb",NID_idea_ecb,0,NULL},
216{"RC2-CBC","rc2-cbc",NID_rc2_cbc,8,&(lvalues[206]),0},
217{"RC2-ECB","rc2-ecb",NID_rc2_ecb,0,NULL},
218{"RC2-CFB","rc2-cfb",NID_rc2_cfb64,0,NULL},
219{"RC2-OFB","rc2-ofb",NID_rc2_ofb64,0,NULL},
220{"SHA","sha",NID_sha,5,&(lvalues[214]),0},
221{"RSA-SHA","shaWithRSAEncryption",NID_shaWithRSAEncryption,5,
222 &(lvalues[219]),0},
223{"DES-EDE-CBC","des-ede-cbc",NID_des_ede_cbc,0,NULL},
224{"DES-EDE3-CBC","des-ede3-cbc",NID_des_ede3_cbc,8,&(lvalues[224]),0},
225{"DES-OFB","des-ofb",NID_des_ofb64,5,&(lvalues[232]),0},
226{"IDEA-OFB","idea-ofb",NID_idea_ofb64,0,NULL},
227{"pkcs9","pkcs9",NID_pkcs9,8,&(lvalues[237]),0},
228{"Email","emailAddress",NID_pkcs9_emailAddress,9,&(lvalues[245]),0},
229{"unstructuredName","unstructuredName",NID_pkcs9_unstructuredName,9,
230 &(lvalues[254]),0},
231{"contentType","contentType",NID_pkcs9_contentType,9,&(lvalues[263]),0},
232{"messageDigest","messageDigest",NID_pkcs9_messageDigest,9,
233 &(lvalues[272]),0},
234{"signingTime","signingTime",NID_pkcs9_signingTime,9,&(lvalues[281]),0},
235{"countersignature","countersignature",NID_pkcs9_countersignature,9,
236 &(lvalues[290]),0},
237{"challengePassword","challengePassword",NID_pkcs9_challengePassword,
238 9,&(lvalues[299]),0},
239{"unstructuredAddress","unstructuredAddress",
240 NID_pkcs9_unstructuredAddress,9,&(lvalues[308]),0},
241{"extendedCertificateAttributes","extendedCertificateAttributes",
242 NID_pkcs9_extCertAttributes,9,&(lvalues[317]),0},
243{"Netscape","Netscape Communications Corp.",NID_netscape,7,
244 &(lvalues[326]),0},
245{"nsCertExt","Netscape Certificate Extension",
246 NID_netscape_cert_extension,8,&(lvalues[333]),0},
247{"nsDataType","Netscape Data Type",NID_netscape_data_type,8,
248 &(lvalues[341]),0},
249{"DES-EDE-CFB","des-ede-cfb",NID_des_ede_cfb64,0,NULL},
250{"DES-EDE3-CFB","des-ede3-cfb",NID_des_ede3_cfb64,0,NULL},
251{"DES-EDE-OFB","des-ede-ofb",NID_des_ede_ofb64,0,NULL},
252{"DES-EDE3-OFB","des-ede3-ofb",NID_des_ede3_ofb64,0,NULL},
253{"SHA1","sha1",NID_sha1,5,&(lvalues[349]),0},
254{"RSA-SHA1","sha1WithRSAEncryption",NID_sha1WithRSAEncryption,9,
255 &(lvalues[354]),0},
256{"DSA-SHA","dsaWithSHA",NID_dsaWithSHA,5,&(lvalues[363]),0},
257{"DSA-old","dsaEncryption-old",NID_dsa_2,5,&(lvalues[368]),0},
258{"pbeWithSHA1AndRC2-CBC","pbeWithSHA1AndRC2-CBC",
259 NID_pbeWithSHA1AndRC2_CBC,9,&(lvalues[373]),0},
260{"pbeWithSHA1AndRC4","pbeWithSHA1AndRC4",NID_pbeWithSHA1AndRC4,9,
261 &(lvalues[382]),0},
262{"DSA-SHA1-old","dsaWithSHA1",NID_dsaWithSHA1_2,5,&(lvalues[391]),0},
263{"nsCertType","Netscape Cert Type",NID_netscape_cert_type,9,
264 &(lvalues[396]),0},
265{"nsBaseUrl","Netscape Base Url",NID_netscape_base_url,9,
266 &(lvalues[405]),0},
267{"nsRevocationUrl","Netscape Revocation Url",
268 NID_netscape_revocation_url,9,&(lvalues[414]),0},
269{"nsCaRevocationUrl","Netscape CA Revocation Url",
270 NID_netscape_ca_revocation_url,9,&(lvalues[423]),0},
271{"nsRenewalUrl","Netscape Renewal Url",NID_netscape_renewal_url,9,
272 &(lvalues[432]),0},
273{"nsCaPolicyUrl","Netscape CA Policy Url",NID_netscape_ca_policy_url,
274 9,&(lvalues[441]),0},
275{"nsSslServerName","Netscape SSL Server Name",
276 NID_netscape_ssl_server_name,9,&(lvalues[450]),0},
277{"nsComment","Netscape Comment",NID_netscape_comment,9,&(lvalues[459]),0},
278{"nsCertSequence","Netscape Certificate Sequence",
279 NID_netscape_cert_sequence,9,&(lvalues[468]),0},
280{"DESX-CBC","desx-cbc",NID_desx_cbc,0,NULL},
281{"ld-ce","ld-ce",NID_ld_ce,2,&(lvalues[477]),0},
282{"subjectKeyIdentifier","X509v3 Subject Key Identifier",
283 NID_subject_key_identifier,3,&(lvalues[479]),0},
284{"keyUsage","X509v3 Key Usage",NID_key_usage,3,&(lvalues[482]),0},
285{"privateKeyUsagePeriod","X509v3 Private Key Usage Period",
286 NID_private_key_usage_period,3,&(lvalues[485]),0},
287{"subjectAltName","X509v3 Subject Alternative Name",
288 NID_subject_alt_name,3,&(lvalues[488]),0},
289{"issuerAltName","X509v3 Issuer Alternative Name",NID_issuer_alt_name,
290 3,&(lvalues[491]),0},
291{"basicConstraints","X509v3 Basic Constraints",NID_basic_constraints,
292 3,&(lvalues[494]),0},
293{"crlNumber","X509v3 CRL Number",NID_crl_number,3,&(lvalues[497]),0},
294{"certificatePolicies","X509v3 Certificate Policies",
295 NID_certificate_policies,3,&(lvalues[500]),0},
296{"authorityKeyIdentifier","X509v3 Authority Key Identifier",
297 NID_authority_key_identifier,3,&(lvalues[503]),0},
298{"BF-CBC","bf-cbc",NID_bf_cbc,0,NULL},
299{"BF-ECB","bf-ecb",NID_bf_ecb,0,NULL},
300{"BF-CFB","bf-cfb",NID_bf_cfb64,0,NULL},
301{"BF-OFB","bf-ofb",NID_bf_ofb64,0,NULL},
302{"MDC2","mdc2",NID_mdc2,4,&(lvalues[506]),0},
303{"RSA-MDC2","mdc2withRSA",NID_mdc2WithRSA,4,&(lvalues[510]),0},
304{"RC4-40","rc4-40",NID_rc4_40,0,NULL},
305{"RC2-40-CBC","rc2-40-cbc",NID_rc2_40_cbc,0,NULL},
306{"G","givenName",NID_givenName,3,&(lvalues[514]),0},
307{"S","surname",NID_surname,3,&(lvalues[517]),0},
308{"I","initials",NID_initials,3,&(lvalues[520]),0},
309{"UID","uniqueIdentifier",NID_uniqueIdentifier,3,&(lvalues[523]),0},
310{"crlDistributionPoints","X509v3 CRL Distribution Points",
311 NID_crl_distribution_points,3,&(lvalues[526]),0},
312{"RSA-NP-MD5","md5WithRSA",NID_md5WithRSA,5,&(lvalues[529]),0},
313{"SN","serialNumber",NID_serialNumber,3,&(lvalues[534]),0},
314{"T","title",NID_title,3,&(lvalues[537]),0},
315{"D","description",NID_description,3,&(lvalues[540]),0},
316{"CAST5-CBC","cast5-cbc",NID_cast5_cbc,9,&(lvalues[543]),0},
317{"CAST5-ECB","cast5-ecb",NID_cast5_ecb,0,NULL},
318{"CAST5-CFB","cast5-cfb",NID_cast5_cfb64,0,NULL},
319{"CAST5-OFB","cast5-ofb",NID_cast5_ofb64,0,NULL},
320{"pbeWithMD5AndCast5CBC","pbeWithMD5AndCast5CBC",
321 NID_pbeWithMD5AndCast5_CBC,9,&(lvalues[552]),0},
322{"DSA-SHA1","dsaWithSHA1",NID_dsaWithSHA1,7,&(lvalues[561]),0},
323{"MD5-SHA1","md5-sha1",NID_md5_sha1,0,NULL},
324{"RSA-SHA1-2","sha1WithRSA",NID_sha1WithRSA,5,&(lvalues[568]),0},
325{"DSA","dsaEncryption",NID_dsa,7,&(lvalues[573]),0},
326{"RIPEMD160","ripemd160",NID_ripemd160,5,&(lvalues[580]),0},
327{NULL,NULL,NID_undef,0,NULL},
328{"RSA-RIPEMD160","ripemd160WithRSA",NID_ripemd160WithRSA,6,
329 &(lvalues[585]),0},
330{"RC5-CBC","rc5-cbc",NID_rc5_cbc,8,&(lvalues[591]),0},
331{"RC5-ECB","rc5-ecb",NID_rc5_ecb,0,NULL},
332{"RC5-CFB","rc5-cfb",NID_rc5_cfb64,0,NULL},
333{"RC5-OFB","rc5-ofb",NID_rc5_ofb64,0,NULL},
334};
335
336static ASN1_OBJECT *sn_objs[NUM_SN]={
337&(nid_objs[91]),/* "BF-CBC" */
338&(nid_objs[93]),/* "BF-CFB" */
339&(nid_objs[92]),/* "BF-ECB" */
340&(nid_objs[94]),/* "BF-OFB" */
341&(nid_objs[14]),/* "C" */
342&(nid_objs[108]),/* "CAST5-CBC" */
343&(nid_objs[110]),/* "CAST5-CFB" */
344&(nid_objs[109]),/* "CAST5-ECB" */
345&(nid_objs[111]),/* "CAST5-OFB" */
346&(nid_objs[13]),/* "CN" */
347&(nid_objs[107]),/* "D" */
348&(nid_objs[31]),/* "DES-CBC" */
349&(nid_objs[30]),/* "DES-CFB" */
350&(nid_objs[29]),/* "DES-ECB" */
351&(nid_objs[32]),/* "DES-EDE" */
352&(nid_objs[43]),/* "DES-EDE-CBC" */
353&(nid_objs[60]),/* "DES-EDE-CFB" */
354&(nid_objs[62]),/* "DES-EDE-OFB" */
355&(nid_objs[33]),/* "DES-EDE3" */
356&(nid_objs[44]),/* "DES-EDE3-CBC" */
357&(nid_objs[61]),/* "DES-EDE3-CFB" */
358&(nid_objs[63]),/* "DES-EDE3-OFB" */
359&(nid_objs[45]),/* "DES-OFB" */
360&(nid_objs[80]),/* "DESX-CBC" */
361&(nid_objs[116]),/* "DSA" */
362&(nid_objs[66]),/* "DSA-SHA" */
363&(nid_objs[113]),/* "DSA-SHA1" */
364&(nid_objs[70]),/* "DSA-SHA1-old" */
365&(nid_objs[67]),/* "DSA-old" */
366&(nid_objs[48]),/* "Email" */
367&(nid_objs[99]),/* "G" */
368&(nid_objs[101]),/* "I" */
369&(nid_objs[34]),/* "IDEA-CBC" */
370&(nid_objs[35]),/* "IDEA-CFB" */
371&(nid_objs[36]),/* "IDEA-ECB" */
372&(nid_objs[46]),/* "IDEA-OFB" */
373&(nid_objs[15]),/* "L" */
374&(nid_objs[ 3]),/* "MD2" */
375&(nid_objs[ 4]),/* "MD5" */
376&(nid_objs[114]),/* "MD5-SHA1" */
377&(nid_objs[95]),/* "MDC2" */
378&(nid_objs[57]),/* "Netscape" */
379&(nid_objs[17]),/* "O" */
380&(nid_objs[18]),/* "OU" */
381&(nid_objs[98]),/* "RC2-40-CBC" */
382&(nid_objs[37]),/* "RC2-CBC" */
383&(nid_objs[39]),/* "RC2-CFB" */
384&(nid_objs[38]),/* "RC2-ECB" */
385&(nid_objs[40]),/* "RC2-OFB" */
386&(nid_objs[ 5]),/* "RC4" */
387&(nid_objs[97]),/* "RC4-40" */
388&(nid_objs[120]),/* "RC5-CBC" */
389&(nid_objs[122]),/* "RC5-CFB" */
390&(nid_objs[121]),/* "RC5-ECB" */
391&(nid_objs[123]),/* "RC5-OFB" */
392&(nid_objs[117]),/* "RIPEMD160" */
393&(nid_objs[19]),/* "RSA" */
394&(nid_objs[ 7]),/* "RSA-MD2" */
395&(nid_objs[ 8]),/* "RSA-MD5" */
396&(nid_objs[96]),/* "RSA-MDC2" */
397&(nid_objs[104]),/* "RSA-NP-MD5" */
398&(nid_objs[119]),/* "RSA-RIPEMD160" */
399&(nid_objs[42]),/* "RSA-SHA" */
400&(nid_objs[65]),/* "RSA-SHA1" */
401&(nid_objs[115]),/* "RSA-SHA1-2" */
402&(nid_objs[100]),/* "S" */
403&(nid_objs[41]),/* "SHA" */
404&(nid_objs[64]),/* "SHA1" */
405&(nid_objs[105]),/* "SN" */
406&(nid_objs[16]),/* "ST" */
407&(nid_objs[106]),/* "T" */
408&(nid_objs[102]),/* "UID" */
409&(nid_objs[ 0]),/* "UNDEF" */
410&(nid_objs[90]),/* "authorityKeyIdentifier" */
411&(nid_objs[87]),/* "basicConstraints" */
412&(nid_objs[89]),/* "certificatePolicies" */
413&(nid_objs[103]),/* "crlDistributionPoints" */
414&(nid_objs[88]),/* "crlNumber" */
415&(nid_objs[86]),/* "issuerAltName" */
416&(nid_objs[83]),/* "keyUsage" */
417&(nid_objs[81]),/* "ld-ce" */
418&(nid_objs[72]),/* "nsBaseUrl" */
419&(nid_objs[76]),/* "nsCaPolicyUrl" */
420&(nid_objs[74]),/* "nsCaRevocationUrl" */
421&(nid_objs[58]),/* "nsCertExt" */
422&(nid_objs[79]),/* "nsCertSequence" */
423&(nid_objs[71]),/* "nsCertType" */
424&(nid_objs[78]),/* "nsComment" */
425&(nid_objs[59]),/* "nsDataType" */
426&(nid_objs[75]),/* "nsRenewalUrl" */
427&(nid_objs[73]),/* "nsRevocationUrl" */
428&(nid_objs[77]),/* "nsSslServerName" */
429&(nid_objs[84]),/* "privateKeyUsagePeriod" */
430&(nid_objs[85]),/* "subjectAltName" */
431&(nid_objs[82]),/* "subjectKeyIdentifier" */
432};
433
434static ASN1_OBJECT *ln_objs[NUM_LN]={
435&(nid_objs[72]),/* "Netscape Base Url" */
436&(nid_objs[76]),/* "Netscape CA Policy Url" */
437&(nid_objs[74]),/* "Netscape CA Revocation Url" */
438&(nid_objs[71]),/* "Netscape Cert Type" */
439&(nid_objs[58]),/* "Netscape Certificate Extension" */
440&(nid_objs[79]),/* "Netscape Certificate Sequence" */
441&(nid_objs[78]),/* "Netscape Comment" */
442&(nid_objs[57]),/* "Netscape Communications Corp." */
443&(nid_objs[59]),/* "Netscape Data Type" */
444&(nid_objs[75]),/* "Netscape Renewal Url" */
445&(nid_objs[73]),/* "Netscape Revocation Url" */
446&(nid_objs[77]),/* "Netscape SSL Server Name" */
447&(nid_objs[11]),/* "X500" */
448&(nid_objs[12]),/* "X509" */
449&(nid_objs[90]),/* "X509v3 Authority Key Identifier" */
450&(nid_objs[87]),/* "X509v3 Basic Constraints" */
451&(nid_objs[103]),/* "X509v3 CRL Distribution Points" */
452&(nid_objs[88]),/* "X509v3 CRL Number" */
453&(nid_objs[89]),/* "X509v3 Certificate Policies" */
454&(nid_objs[86]),/* "X509v3 Issuer Alternative Name" */
455&(nid_objs[83]),/* "X509v3 Key Usage" */
456&(nid_objs[84]),/* "X509v3 Private Key Usage Period" */
457&(nid_objs[85]),/* "X509v3 Subject Alternative Name" */
458&(nid_objs[82]),/* "X509v3 Subject Key Identifier" */
459&(nid_objs[91]),/* "bf-cbc" */
460&(nid_objs[93]),/* "bf-cfb" */
461&(nid_objs[92]),/* "bf-ecb" */
462&(nid_objs[94]),/* "bf-ofb" */
463&(nid_objs[108]),/* "cast5-cbc" */
464&(nid_objs[110]),/* "cast5-cfb" */
465&(nid_objs[109]),/* "cast5-ecb" */
466&(nid_objs[111]),/* "cast5-ofb" */
467&(nid_objs[54]),/* "challengePassword" */
468&(nid_objs[13]),/* "commonName" */
469&(nid_objs[50]),/* "contentType" */
470&(nid_objs[53]),/* "countersignature" */
471&(nid_objs[14]),/* "countryName" */
472&(nid_objs[31]),/* "des-cbc" */
473&(nid_objs[30]),/* "des-cfb" */
474&(nid_objs[29]),/* "des-ecb" */
475&(nid_objs[32]),/* "des-ede" */
476&(nid_objs[43]),/* "des-ede-cbc" */
477&(nid_objs[60]),/* "des-ede-cfb" */
478&(nid_objs[62]),/* "des-ede-ofb" */
479&(nid_objs[33]),/* "des-ede3" */
480&(nid_objs[44]),/* "des-ede3-cbc" */
481&(nid_objs[61]),/* "des-ede3-cfb" */
482&(nid_objs[63]),/* "des-ede3-ofb" */
483&(nid_objs[45]),/* "des-ofb" */
484&(nid_objs[107]),/* "description" */
485&(nid_objs[80]),/* "desx-cbc" */
486&(nid_objs[28]),/* "dhKeyAgreement" */
487&(nid_objs[116]),/* "dsaEncryption" */
488&(nid_objs[67]),/* "dsaEncryption-old" */
489&(nid_objs[66]),/* "dsaWithSHA" */
490&(nid_objs[113]),/* "dsaWithSHA1" */
491&(nid_objs[70]),/* "dsaWithSHA1" */
492&(nid_objs[48]),/* "emailAddress" */
493&(nid_objs[56]),/* "extendedCertificateAttributes" */
494&(nid_objs[99]),/* "givenName" */
495&(nid_objs[34]),/* "idea-cbc" */
496&(nid_objs[35]),/* "idea-cfb" */
497&(nid_objs[36]),/* "idea-ecb" */
498&(nid_objs[46]),/* "idea-ofb" */
499&(nid_objs[101]),/* "initials" */
500&(nid_objs[15]),/* "localityName" */
501&(nid_objs[ 3]),/* "md2" */
502&(nid_objs[ 7]),/* "md2WithRSAEncryption" */
503&(nid_objs[ 4]),/* "md5" */
504&(nid_objs[114]),/* "md5-sha1" */
505&(nid_objs[104]),/* "md5WithRSA" */
506&(nid_objs[ 8]),/* "md5WithRSAEncryption" */
507&(nid_objs[95]),/* "mdc2" */
508&(nid_objs[96]),/* "mdc2withRSA" */
509&(nid_objs[51]),/* "messageDigest" */
510&(nid_objs[17]),/* "organizationName" */
511&(nid_objs[18]),/* "organizationalUnitName" */
512&(nid_objs[ 9]),/* "pbeWithMD2AndDES-CBC" */
513&(nid_objs[112]),/* "pbeWithMD5AndCast5CBC" */
514&(nid_objs[10]),/* "pbeWithMD5AndDES-CBC" */
515&(nid_objs[68]),/* "pbeWithSHA1AndRC2-CBC" */
516&(nid_objs[69]),/* "pbeWithSHA1AndRC4" */
517&(nid_objs[ 2]),/* "pkcs" */
518&(nid_objs[27]),/* "pkcs3" */
519&(nid_objs[20]),/* "pkcs7" */
520&(nid_objs[21]),/* "pkcs7-data" */
521&(nid_objs[25]),/* "pkcs7-digestData" */
522&(nid_objs[26]),/* "pkcs7-encryptedData" */
523&(nid_objs[23]),/* "pkcs7-envelopedData" */
524&(nid_objs[24]),/* "pkcs7-signedAndEnvelopedData" */
525&(nid_objs[22]),/* "pkcs7-signedData" */
526&(nid_objs[47]),/* "pkcs9" */
527&(nid_objs[98]),/* "rc2-40-cbc" */
528&(nid_objs[37]),/* "rc2-cbc" */
529&(nid_objs[39]),/* "rc2-cfb" */
530&(nid_objs[38]),/* "rc2-ecb" */
531&(nid_objs[40]),/* "rc2-ofb" */
532&(nid_objs[ 5]),/* "rc4" */
533&(nid_objs[97]),/* "rc4-40" */
534&(nid_objs[120]),/* "rc5-cbc" */
535&(nid_objs[122]),/* "rc5-cfb" */
536&(nid_objs[121]),/* "rc5-ecb" */
537&(nid_objs[123]),/* "rc5-ofb" */
538&(nid_objs[117]),/* "ripemd160" */
539&(nid_objs[119]),/* "ripemd160WithRSA" */
540&(nid_objs[19]),/* "rsa" */
541&(nid_objs[ 6]),/* "rsaEncryption" */
542&(nid_objs[ 1]),/* "rsadsi" */
543&(nid_objs[105]),/* "serialNumber" */
544&(nid_objs[41]),/* "sha" */
545&(nid_objs[64]),/* "sha1" */
546&(nid_objs[115]),/* "sha1WithRSA" */
547&(nid_objs[65]),/* "sha1WithRSAEncryption" */
548&(nid_objs[42]),/* "shaWithRSAEncryption" */
549&(nid_objs[52]),/* "signingTime" */
550&(nid_objs[16]),/* "stateOrProvinceName" */
551&(nid_objs[100]),/* "surname" */
552&(nid_objs[106]),/* "title" */
553&(nid_objs[ 0]),/* "undefined" */
554&(nid_objs[102]),/* "uniqueIdentifier" */
555&(nid_objs[55]),/* "unstructuredAddress" */
556&(nid_objs[49]),/* "unstructuredName" */
557};
558
559static ASN1_OBJECT *obj_objs[NUM_OBJ]={
560&(nid_objs[11]),/* OBJ_X500 2 5 */
561&(nid_objs[12]),/* OBJ_X509 2 5 4 */
562&(nid_objs[81]),/* OBJ_ld_ce 2 5 29 */
563&(nid_objs[13]),/* OBJ_commonName 2 5 4 3 */
564&(nid_objs[100]),/* OBJ_surname 2 5 4 4 */
565&(nid_objs[105]),/* OBJ_serialNumber 2 5 4 5 */
566&(nid_objs[14]),/* OBJ_countryName 2 5 4 6 */
567&(nid_objs[15]),/* OBJ_localityName 2 5 4 7 */
568&(nid_objs[16]),/* OBJ_stateOrProvinceName 2 5 4 8 */
569&(nid_objs[17]),/* OBJ_organizationName 2 5 4 10 */
570&(nid_objs[18]),/* OBJ_organizationalUnitName 2 5 4 11 */
571&(nid_objs[106]),/* OBJ_title 2 5 4 12 */
572&(nid_objs[107]),/* OBJ_description 2 5 4 13 */
573&(nid_objs[99]),/* OBJ_givenName 2 5 4 42 */
574&(nid_objs[101]),/* OBJ_initials 2 5 4 43 */
575&(nid_objs[102]),/* OBJ_uniqueIdentifier 2 5 4 45 */
576&(nid_objs[82]),/* OBJ_subject_key_identifier 2 5 29 14 */
577&(nid_objs[83]),/* OBJ_key_usage 2 5 29 15 */
578&(nid_objs[84]),/* OBJ_private_key_usage_period 2 5 29 16 */
579&(nid_objs[85]),/* OBJ_subject_alt_name 2 5 29 17 */
580&(nid_objs[86]),/* OBJ_issuer_alt_name 2 5 29 18 */
581&(nid_objs[87]),/* OBJ_basic_constraints 2 5 29 19 */
582&(nid_objs[88]),/* OBJ_crl_number 2 5 29 20 */
583&(nid_objs[103]),/* OBJ_crl_distribution_points 2 5 29 31 */
584&(nid_objs[89]),/* OBJ_certificate_policies 2 5 29 32 */
585&(nid_objs[90]),/* OBJ_authority_key_identifier 2 5 29 35 */
586&(nid_objs[19]),/* OBJ_rsa 2 5 8 1 1 */
587&(nid_objs[96]),/* OBJ_mdc2WithRSA 2 5 8 3 100 */
588&(nid_objs[95]),/* OBJ_mdc2 2 5 8 3 101 */
589&(nid_objs[104]),/* OBJ_md5WithRSA 1 3 14 3 2 3 */
590&(nid_objs[29]),/* OBJ_des_ecb 1 3 14 3 2 6 */
591&(nid_objs[31]),/* OBJ_des_cbc 1 3 14 3 2 7 */
592&(nid_objs[45]),/* OBJ_des_ofb64 1 3 14 3 2 8 */
593&(nid_objs[30]),/* OBJ_des_cfb64 1 3 14 3 2 9 */
594&(nid_objs[67]),/* OBJ_dsa_2 1 3 14 3 2 12 */
595&(nid_objs[66]),/* OBJ_dsaWithSHA 1 3 14 3 2 13 */
596&(nid_objs[42]),/* OBJ_shaWithRSAEncryption 1 3 14 3 2 15 */
597&(nid_objs[32]),/* OBJ_des_ede 1 3 14 3 2 17 */
598&(nid_objs[41]),/* OBJ_sha 1 3 14 3 2 18 */
599&(nid_objs[64]),/* OBJ_sha1 1 3 14 3 2 26 */
600&(nid_objs[70]),/* OBJ_dsaWithSHA1_2 1 3 14 3 2 27 */
601&(nid_objs[115]),/* OBJ_sha1WithRSA 1 3 14 3 2 29 */
602&(nid_objs[117]),/* OBJ_ripemd160 1 3 36 3 2 1 */
603&(nid_objs[ 1]),/* OBJ_rsadsi 1 2 840 113549 */
604&(nid_objs[119]),/* OBJ_ripemd160WithRSA 1 3 36 3 3 1 2 */
605&(nid_objs[ 2]),/* OBJ_pkcs 1 2 840 113549 1 */
606&(nid_objs[116]),/* OBJ_dsa 1 2 840 10040 4 1 */
607&(nid_objs[113]),/* OBJ_dsaWithSHA1 1 2 840 10040 4 3 */
608&(nid_objs[57]),/* OBJ_netscape 2 16 840 1 113730 */
609&(nid_objs[27]),/* OBJ_pkcs3 1 2 840 113549 1 3 */
610&(nid_objs[20]),/* OBJ_pkcs7 1 2 840 113549 1 7 */
611&(nid_objs[47]),/* OBJ_pkcs9 1 2 840 113549 1 9 */
612&(nid_objs[ 3]),/* OBJ_md2 1 2 840 113549 2 2 */
613&(nid_objs[ 4]),/* OBJ_md5 1 2 840 113549 2 5 */
614&(nid_objs[37]),/* OBJ_rc2_cbc 1 2 840 113549 3 2 */
615&(nid_objs[ 5]),/* OBJ_rc4 1 2 840 113549 3 4 */
616&(nid_objs[44]),/* OBJ_des_ede3_cbc 1 2 840 113549 3 7 */
617&(nid_objs[120]),/* OBJ_rc5_cbc 1 2 840 113549 3 8 */
618&(nid_objs[58]),/* OBJ_netscape_cert_extension 2 16 840 1 113730 1 */
619&(nid_objs[59]),/* OBJ_netscape_data_type 2 16 840 1 113730 2 */
620&(nid_objs[108]),/* OBJ_cast5_cbc 1 2 840 113533 7 66 10 */
621&(nid_objs[112]),/* OBJ_pbeWithMD5AndCast5_CBC 1 2 840 113533 7 66 12 */
622&(nid_objs[ 6]),/* OBJ_rsaEncryption 1 2 840 113549 1 1 1 */
623&(nid_objs[ 7]),/* OBJ_md2WithRSAEncryption 1 2 840 113549 1 1 2 */
624&(nid_objs[ 8]),/* OBJ_md5WithRSAEncryption 1 2 840 113549 1 1 4 */
625&(nid_objs[65]),/* OBJ_sha1WithRSAEncryption 1 2 840 113549 1 1 5 */
626&(nid_objs[28]),/* OBJ_dhKeyAgreement 1 2 840 113549 1 3 1 */
627&(nid_objs[ 9]),/* OBJ_pbeWithMD2AndDES_CBC 1 2 840 113549 1 5 1 */
628&(nid_objs[10]),/* OBJ_pbeWithMD5AndDES_CBC 1 2 840 113549 1 5 3 */
629&(nid_objs[68]),/* OBJ_pbeWithSHA1AndRC2_CBC 1 2 840 113549 1 5 11 */
630&(nid_objs[69]),/* OBJ_pbeWithSHA1AndRC4 1 2 840 113549 1 5 12 */
631&(nid_objs[21]),/* OBJ_pkcs7_data 1 2 840 113549 1 7 1 */
632&(nid_objs[22]),/* OBJ_pkcs7_signed 1 2 840 113549 1 7 2 */
633&(nid_objs[23]),/* OBJ_pkcs7_enveloped 1 2 840 113549 1 7 3 */
634&(nid_objs[24]),/* OBJ_pkcs7_signedAndEnveloped 1 2 840 113549 1 7 4 */
635&(nid_objs[25]),/* OBJ_pkcs7_digest 1 2 840 113549 1 7 5 */
636&(nid_objs[26]),/* OBJ_pkcs7_encrypted 1 2 840 113549 1 7 6 */
637&(nid_objs[48]),/* OBJ_pkcs9_emailAddress 1 2 840 113549 1 9 1 */
638&(nid_objs[49]),/* OBJ_pkcs9_unstructuredName 1 2 840 113549 1 9 2 */
639&(nid_objs[50]),/* OBJ_pkcs9_contentType 1 2 840 113549 1 9 3 */
640&(nid_objs[51]),/* OBJ_pkcs9_messageDigest 1 2 840 113549 1 9 4 */
641&(nid_objs[52]),/* OBJ_pkcs9_signingTime 1 2 840 113549 1 9 5 */
642&(nid_objs[53]),/* OBJ_pkcs9_countersignature 1 2 840 113549 1 9 6 */
643&(nid_objs[54]),/* OBJ_pkcs9_challengePassword 1 2 840 113549 1 9 7 */
644&(nid_objs[55]),/* OBJ_pkcs9_unstructuredAddress 1 2 840 113549 1 9 8 */
645&(nid_objs[56]),/* OBJ_pkcs9_extCertAttributes 1 2 840 113549 1 9 9 */
646&(nid_objs[71]),/* OBJ_netscape_cert_type 2 16 840 1 113730 1 1 */
647&(nid_objs[72]),/* OBJ_netscape_base_url 2 16 840 1 113730 1 2 */
648&(nid_objs[73]),/* OBJ_netscape_revocation_url 2 16 840 1 113730 1 3 */
649&(nid_objs[74]),/* OBJ_netscape_ca_revocation_url 2 16 840 1 113730 1 4 */
650&(nid_objs[75]),/* OBJ_netscape_renewal_url 2 16 840 1 113730 1 7 */
651&(nid_objs[76]),/* OBJ_netscape_ca_policy_url 2 16 840 1 113730 1 8 */
652&(nid_objs[77]),/* OBJ_netscape_ssl_server_name 2 16 840 1 113730 1 12 */
653&(nid_objs[78]),/* OBJ_netscape_comment 2 16 840 1 113730 1 13 */
654&(nid_objs[79]),/* OBJ_netscape_cert_sequence 2 16 840 1 113730 2 5 */
655};
656
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3sub obj_cmp 3sub obj_cmp
4 { 4 {
@@ -252,7 +252,7 @@ sub der_it
252 $ret.=pack("C*",$a[0]*40+$a[1]); 252 $ret.=pack("C*",$a[0]*40+$a[1]);
253 shift @a; 253 shift @a;
254 shift @a; 254 shift @a;
255 while ($_=shift(@a)) 255 foreach (@a)
256 { 256 {
257 @r=(); 257 @r=();
258 $t=0; 258 $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 @@
1/* lib/obj/obj_err.c */ 1/* crypto/objects/obj_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "objects.h" 62#include <openssl/objects.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -68,24 +70,24 @@ static ERR_STRING_DATA OBJ_str_functs[]=
68{ERR_PACK(0,OBJ_F_OBJ_NID2LN,0), "OBJ_nid2ln"}, 70{ERR_PACK(0,OBJ_F_OBJ_NID2LN,0), "OBJ_nid2ln"},
69{ERR_PACK(0,OBJ_F_OBJ_NID2OBJ,0), "OBJ_nid2obj"}, 71{ERR_PACK(0,OBJ_F_OBJ_NID2OBJ,0), "OBJ_nid2obj"},
70{ERR_PACK(0,OBJ_F_OBJ_NID2SN,0), "OBJ_nid2sn"}, 72{ERR_PACK(0,OBJ_F_OBJ_NID2SN,0), "OBJ_nid2sn"},
71{0,NULL}, 73{0,NULL}
72 }; 74 };
73 75
74static ERR_STRING_DATA OBJ_str_reasons[]= 76static ERR_STRING_DATA OBJ_str_reasons[]=
75 { 77 {
76{OBJ_R_MALLOC_FAILURE ,"malloc failure"}, 78{OBJ_R_MALLOC_FAILURE ,"malloc failure"},
77{OBJ_R_UNKNOWN_NID ,"unknown nid"}, 79{OBJ_R_UNKNOWN_NID ,"unknown nid"},
78{0,NULL}, 80{0,NULL}
79 }; 81 };
80 82
81#endif 83#endif
82 84
83void ERR_load_OBJ_strings() 85void ERR_load_OBJ_strings(void)
84 { 86 {
85 static int init=1; 87 static int init=1;
86 88
87 if (init); 89 if (init)
88 {; 90 {
89 init=0; 91 init=0;
90#ifndef NO_ERR 92#ifndef NO_ERR
91 ERR_load_strings(ERR_LIB_OBJ,OBJ_str_functs); 93 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "lhash.h" 61#include <openssl/lhash.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "buffer.h" 63#include <openssl/buffer.h>
64 64
65ASN1_OBJECT *OBJ_dup(o) 65ASN1_OBJECT *OBJ_dup(ASN1_OBJECT *o)
66ASN1_OBJECT *o;
67 { 66 {
68 ASN1_OBJECT *r; 67 ASN1_OBJECT *r;
69 int i; 68 int i;
69 char *ln=NULL;
70 70
71 if (o == NULL) return(NULL); 71 if (o == NULL) return(NULL);
72 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC)) 72 if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
73 return(o); 73 return(o);
74 74
75 r=(ASN1_OBJECT *)ASN1_OBJECT_new(); 75 r=ASN1_OBJECT_new();
76 if (r == NULL) 76 if (r == NULL)
77 { 77 {
78 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); 78 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB);
79 return(NULL); 79 return(NULL);
80 } 80 }
81 r->data=(unsigned char *)Malloc(o->length); 81 r->data=Malloc(o->length);
82 if (r->data == NULL) 82 if (r->data == NULL)
83 goto err; 83 goto err;
84 memcpy(r->data,o->data,o->length); 84 memcpy(r->data,o->data,o->length);
@@ -88,35 +88,35 @@ ASN1_OBJECT *o;
88 if (o->ln != NULL) 88 if (o->ln != NULL)
89 { 89 {
90 i=strlen(o->ln)+1; 90 i=strlen(o->ln)+1;
91 r->ln=(char *)Malloc(i); 91 r->ln=ln=Malloc(i);
92 if (r->ln == NULL) goto err; 92 if (r->ln == NULL) goto err;
93 memcpy(r->ln,o->ln,i); 93 memcpy(ln,o->ln,i);
94 } 94 }
95 95
96 if (o->sn != NULL) 96 if (o->sn != NULL)
97 { 97 {
98 char *s;
99
98 i=strlen(o->sn)+1; 100 i=strlen(o->sn)+1;
99 r->sn=(char *)Malloc(i); 101 r->sn=s=Malloc(i);
100 if (r->sn == NULL) goto err; 102 if (r->sn == NULL) goto err;
101 memcpy(r->sn,o->sn,i); 103 memcpy(s,o->sn,i);
102 } 104 }
103 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC| 105 r->flags=o->flags|(ASN1_OBJECT_FLAG_DYNAMIC|
104 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS); 106 ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|ASN1_OBJECT_FLAG_DYNAMIC_DATA);
105 return(r); 107 return(r);
106err: 108err:
107 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE); 109 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
108 if (r != NULL) 110 if (r != NULL)
109 { 111 {
110 if (r->ln != NULL) Free(r->ln); 112 if (ln != NULL) Free(ln);
111 if (r->data != NULL) Free(r->data); 113 if (r->data != NULL) Free(r->data);
112 Free(r); 114 Free(r);
113 } 115 }
114 return(NULL); 116 return(NULL);
115 } 117 }
116 118
117int OBJ_cmp(a,b) 119int OBJ_cmp(ASN1_OBJECT *a, ASN1_OBJECT *b)
118ASN1_OBJECT *a;
119ASN1_OBJECT *b;
120 { 120 {
121 int ret; 121 int ret;
122 122
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 @@
1/* Error codes for the OBJ functions. */
2
3/* Function codes. */
4#define OBJ_F_OBJ_CREATE 100
5#define OBJ_F_OBJ_DUP 101
6#define OBJ_F_OBJ_NID2LN 102
7#define OBJ_F_OBJ_NID2OBJ 103
8#define OBJ_F_OBJ_NID2SN 104
9
10/* Reason codes. */
11#define OBJ_R_MALLOC_FAILURE 100
12#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" {
66#define SN_undef "UNDEF" 66#define SN_undef "UNDEF"
67#define LN_undef "undefined" 67#define LN_undef "undefined"
68#define NID_undef 0 68#define NID_undef 0
69#define OBJ_undef 0L
69 70
70#define SN_Algorithm "Algorithm" 71#define SN_Algorithm "Algorithm"
71#define LN_algorithm "algorithm" 72#define LN_algorithm "algorithm"
@@ -383,13 +384,16 @@ extern "C" {
383#define NID_pbeWithSHA1AndRC2_CBC 68 384#define NID_pbeWithSHA1AndRC2_CBC 68
384#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L 385#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs,5L,11L
385 386
386/* proposed by microsoft to RSA */ 387/* proposed by microsoft to RSA as pbeWithSHA1AndRC4: it is now
387#define LN_pbeWithSHA1AndRC4 "pbeWithSHA1AndRC4" 388 * defined explicitly in PKCS#5 v2.0 as id-PBKDF2 which is something
388#define NID_pbeWithSHA1AndRC4 69 389 * completely different.
389#define OBJ_pbeWithSHA1AndRC4 OBJ_pkcs,5L,12L 390 */
391#define LN_id_pbkdf2 "PBKDF2"
392#define NID_id_pbkdf2 69
393#define OBJ_id_pbkdf2 OBJ_pkcs,5L,12L
390 394
391#define SN_dsaWithSHA1_2 "DSA-SHA1-old" 395#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
392#define LN_dsaWithSHA1_2 "dsaWithSHA1" 396#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
393#define NID_dsaWithSHA1_2 70 397#define NID_dsaWithSHA1_2 70
394/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */ 398/* Got this one from 'sdn706r20.pdf' which is actually an NSA document :-) */
395#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L 399#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
@@ -654,21 +658,280 @@ extern "C" {
654#define LN_rc5_ofb64 "rc5-ofb" 658#define LN_rc5_ofb64 "rc5-ofb"
655#define NID_rc5_ofb64 123 659#define NID_rc5_ofb64 123
656 660
657#include "bio.h" 661#define SN_rle_compression "RLE"
658#include "asn1.h" 662#define LN_rle_compression "run length compression"
663#define NID_rle_compression 124
664#define OBJ_rle_compression 1L,1L,1L,1L,666L.1L
665
666#define SN_zlib_compression "ZLIB"
667#define LN_zlib_compression "zlib compression"
668#define NID_zlib_compression 125
669#define OBJ_zlib_compression 1L,1L,1L,1L,666L.2L
670
671#define SN_ext_key_usage "extendedKeyUsage"
672#define LN_ext_key_usage "X509v3 Extended Key Usage"
673#define NID_ext_key_usage 126
674#define OBJ_ext_key_usage OBJ_ld_ce,37
675
676#define SN_id_pkix "PKIX"
677#define NID_id_pkix 127
678#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L
679
680#define SN_id_kp "id-kp"
681#define NID_id_kp 128
682#define OBJ_id_kp OBJ_id_pkix,3L
683
684/* PKIX extended key usage OIDs */
685
686#define SN_server_auth "serverAuth"
687#define LN_server_auth "TLS Web Server Authentication"
688#define NID_server_auth 129
689#define OBJ_server_auth OBJ_id_kp,1L
690
691#define SN_client_auth "clientAuth"
692#define LN_client_auth "TLS Web Client Authentication"
693#define NID_client_auth 130
694#define OBJ_client_auth OBJ_id_kp,2L
695
696#define SN_code_sign "codeSigning"
697#define LN_code_sign "Code Signing"
698#define NID_code_sign 131
699#define OBJ_code_sign OBJ_id_kp,3L
700
701#define SN_email_protect "emailProtection"
702#define LN_email_protect "E-mail Protection"
703#define NID_email_protect 132
704#define OBJ_email_protect OBJ_id_kp,4L
705
706#define SN_time_stamp "timeStamping"
707#define LN_time_stamp "Time Stamping"
708#define NID_time_stamp 133
709#define OBJ_time_stamp OBJ_id_kp,8L
710
711/* Additional extended key usage OIDs: Microsoft */
712
713#define SN_ms_code_ind "msCodeInd"
714#define LN_ms_code_ind "Microsoft Individual Code Signing"
715#define NID_ms_code_ind 134
716#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
717
718#define SN_ms_code_com "msCodeCom"
719#define LN_ms_code_com "Microsoft Commercial Code Signing"
720#define NID_ms_code_com 135
721#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
722
723#define SN_ms_ctl_sign "msCTLSign"
724#define LN_ms_ctl_sign "Microsoft Trust List Signing"
725#define NID_ms_ctl_sign 136
726#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
727
728#define SN_ms_sgc "msSGC"
729#define LN_ms_sgc "Microsoft Server Gated Crypto"
730#define NID_ms_sgc 137
731#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
732
733#define SN_ms_efs "msEFS"
734#define LN_ms_efs "Microsoft Encrypted File System"
735#define NID_ms_efs 138
736#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
737
738/* Addidional usage: Netscape */
739
740#define SN_ns_sgc "nsSGC"
741#define LN_ns_sgc "Netscape Server Gated Crypto"
742#define NID_ns_sgc 139
743#define OBJ_ns_sgc OBJ_netscape,4L,1L
744
745#define SN_delta_crl "deltaCRL"
746#define LN_delta_crl "X509v3 Delta CRL Indicator"
747#define NID_delta_crl 140
748#define OBJ_delta_crl OBJ_ld_ce,27L
749
750#define SN_crl_reason "CRLReason"
751#define LN_crl_reason "CRL Reason Code"
752#define NID_crl_reason 141
753#define OBJ_crl_reason OBJ_ld_ce,21L
754
755#define SN_invalidity_date "invalidityDate"
756#define LN_invalidity_date "Invalidity Date"
757#define NID_invalidity_date 142
758#define OBJ_invalidity_date OBJ_ld_ce,24L
759
760#define SN_sxnet "SXNetID"
761#define LN_sxnet "Strong Extranet ID"
762#define NID_sxnet 143
763#define OBJ_sxnet 1L,3L,101L,1L,4L,1L
764
765/* PKCS12 and related OBJECT IDENTIFIERS */
766
767#define OBJ_pkcs12 OBJ_pkcs,12L
768#define OBJ_pkcs12_pbeids OBJ_pkcs12, 1
769
770#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
771#define NID_pbe_WithSHA1And128BitRC4 144
772#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids, 1L
773
774#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
775#define NID_pbe_WithSHA1And40BitRC4 145
776#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids, 2L
777
778#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
779#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
780#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 3L
781
782#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
783#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
784#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids, 4L
785
786#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
787#define NID_pbe_WithSHA1And128BitRC2_CBC 148
788#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids, 5L
789
790#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
791#define NID_pbe_WithSHA1And40BitRC2_CBC 149
792#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids, 6L
793
794#define OBJ_pkcs12_Version1 OBJ_pkcs12, 10L
795
796#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1, 1L
797
798#define LN_keyBag "keyBag"
799#define NID_keyBag 150
800#define OBJ_keyBag OBJ_pkcs12_BagIds, 1L
801
802#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"
803#define NID_pkcs8ShroudedKeyBag 151
804#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds, 2L
805
806#define LN_certBag "certBag"
807#define NID_certBag 152
808#define OBJ_certBag OBJ_pkcs12_BagIds, 3L
809
810#define LN_crlBag "crlBag"
811#define NID_crlBag 153
812#define OBJ_crlBag OBJ_pkcs12_BagIds, 4L
813
814#define LN_secretBag "secretBag"
815#define NID_secretBag 154
816#define OBJ_secretBag OBJ_pkcs12_BagIds, 5L
817
818#define LN_safeContentsBag "safeContentsBag"
819#define NID_safeContentsBag 155
820#define OBJ_safeContentsBag OBJ_pkcs12_BagIds, 6L
821
822#define LN_friendlyName "friendlyName"
823#define NID_friendlyName 156
824#define OBJ_friendlyName OBJ_pkcs9, 20L
825
826#define LN_localKeyID "localKeyID"
827#define NID_localKeyID 157
828#define OBJ_localKeyID OBJ_pkcs9, 21L
829
830#define OBJ_certTypes OBJ_pkcs9, 22L
831
832#define LN_x509Certificate "x509Certificate"
833#define NID_x509Certificate 158
834#define OBJ_x509Certificate OBJ_certTypes, 1L
835
836#define LN_sdsiCertificate "sdsiCertificate"
837#define NID_sdsiCertificate 159
838#define OBJ_sdsiCertificate OBJ_certTypes, 2L
839
840#define OBJ_crlTypes OBJ_pkcs9, 23L
841
842#define LN_x509Crl "x509Crl"
843#define NID_x509Crl 160
844#define OBJ_x509Crl OBJ_crlTypes, 1L
845
846/* PKCS#5 v2 OIDs */
847
848#define LN_pbes2 "PBES2"
849#define NID_pbes2 161
850#define OBJ_pbes2 OBJ_pkcs,5L,13L
851
852#define LN_pbmac1 "PBMAC1"
853#define NID_pbmac1 162
854#define OBJ_pbmac1 OBJ_pkcs,5L,14L
855
856#define LN_hmacWithSHA1 "hmacWithSHA1"
857#define NID_hmacWithSHA1 163
858#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L
859
860/* Policy Qualifier Ids */
861
862#define LN_id_qt_cps "Policy Qualifier CPS"
863#define SN_id_qt_cps "id-qt-cps"
864#define NID_id_qt_cps 164
865#define OBJ_id_qt_cps OBJ_id_pkix,2L,1L
866
867#define LN_id_qt_unotice "Policy Qualifier User Notice"
868#define SN_id_qt_unotice "id-qt-unotice"
869#define NID_id_qt_unotice 165
870#define OBJ_id_qt_unotice OBJ_id_pkix,2L,2L
871
872#define SN_rc2_64_cbc "RC2-64-CBC"
873#define LN_rc2_64_cbc "rc2-64-cbc"
874#define NID_rc2_64_cbc 166
875
876#define SN_SMIMECapabilities "SMIME-CAPS"
877#define LN_SMIMECapabilities "S/MIME Capabilities"
878#define NID_SMIMECapabilities 167
879#define OBJ_SMIMECapabilities OBJ_id_pkcs9,15L
880
881#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
882#define NID_pbeWithMD2AndRC2_CBC 168
883#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs,5L,4L
884
885#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
886#define NID_pbeWithMD5AndRC2_CBC 169
887#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs,5L,6L
888
889#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
890#define NID_pbeWithSHA1AndDES_CBC 170
891#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs,5L,10L
892
893#include <openssl/bio.h>
894#include <openssl/asn1.h>
895
896#define OBJ_NAME_TYPE_UNDEF 0x00
897#define OBJ_NAME_TYPE_MD_METH 0x01
898#define OBJ_NAME_TYPE_CIPHER_METH 0x02
899#define OBJ_NAME_TYPE_PKEY_METH 0x03
900#define OBJ_NAME_TYPE_COMP_METH 0x04
901#define OBJ_NAME_TYPE_NUM 0x05
902
903#define OBJ_NAME_ALIAS 0x8000
904
905
906typedef struct obj_name_st
907 {
908 int type;
909 int alias;
910 const char *name;
911 const char *data;
912 } OBJ_NAME;
659 913
660#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c) 914#define OBJ_create_and_add_object(a,b,c) OBJ_create(a,b,c)
661 915
662#ifndef NOPROTO 916
917int OBJ_NAME_init(void);
918int OBJ_NAME_new_index(unsigned long (*hash_func)(),int (*cmp_func)(),
919 void (*free_func)());
920const char *OBJ_NAME_get(const char *name,int type);
921int OBJ_NAME_add(const char *name,int type,const char *data);
922int OBJ_NAME_remove(const char *name,int type);
923void OBJ_NAME_cleanup(int type); /* -1 for everything */
663 924
664ASN1_OBJECT * OBJ_dup(ASN1_OBJECT *o); 925ASN1_OBJECT * OBJ_dup(ASN1_OBJECT *o);
665ASN1_OBJECT * OBJ_nid2obj(int n); 926ASN1_OBJECT * OBJ_nid2obj(int n);
666char * OBJ_nid2ln(int n); 927const char * OBJ_nid2ln(int n);
667char * OBJ_nid2sn(int n); 928const char * OBJ_nid2sn(int n);
668int OBJ_obj2nid(ASN1_OBJECT *o); 929int OBJ_obj2nid(ASN1_OBJECT *o);
930ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name);
931int OBJ_obj2txt(char *buf, int buf_len, ASN1_OBJECT *a, int no_name);
669int OBJ_txt2nid(char *s); 932int OBJ_txt2nid(char *s);
670int OBJ_ln2nid(char *s); 933int OBJ_ln2nid(const char *s);
671int OBJ_sn2nid(char *s); 934int OBJ_sn2nid(const char *s);
672int OBJ_cmp(ASN1_OBJECT *a,ASN1_OBJECT *b); 935int OBJ_cmp(ASN1_OBJECT *a,ASN1_OBJECT *b);
673char * OBJ_bsearch(char *key,char *base,int num,int size,int (*cmp)()); 936char * OBJ_bsearch(char *key,char *base,int num,int size,int (*cmp)());
674 937
@@ -680,30 +943,11 @@ int OBJ_create(char *oid,char *sn,char *ln);
680void OBJ_cleanup(void ); 943void OBJ_cleanup(void );
681int OBJ_create_objects(BIO *in); 944int OBJ_create_objects(BIO *in);
682 945
683#else
684
685ASN1_OBJECT * OBJ_dup();
686ASN1_OBJECT * OBJ_nid2obj();
687char * OBJ_nid2ln();
688char * OBJ_nid2sn();
689int OBJ_obj2nid();
690int OBJ_txt2nid();
691int OBJ_ln2nid();
692int OBJ_sn2nid();
693int OBJ_cmp();
694char * OBJ_bsearch();
695
696void ERR_load_OBJ_strings();
697
698int OBJ_new_nid();
699int OBJ_add_object();
700int OBJ_create();
701void OBJ_cleanup();
702int OBJ_create_objects();
703
704#endif
705
706/* BEGIN ERROR CODES */ 946/* BEGIN ERROR CODES */
947/* The following lines are auto generated by the script mkerr.pl. Any changes
948 * made after this point may be overwritten when the script is next run.
949 */
950
707/* Error codes for the OBJ functions. */ 951/* Error codes for the OBJ functions. */
708 952
709/* Function codes. */ 953/* Function codes. */
@@ -716,7 +960,7 @@ int OBJ_create_objects();
716/* Reason codes. */ 960/* Reason codes. */
717#define OBJ_R_MALLOC_FAILURE 100 961#define OBJ_R_MALLOC_FAILURE 100
718#define OBJ_R_UNKNOWN_NID 101 962#define OBJ_R_UNKNOWN_NID 101
719 963
720#ifdef __cplusplus 964#ifdef __cplusplus
721} 965}
722#endif 966#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 @@
1/* crypto/opensslconf.h */
2/* WARNING: This file is autogenerated by Configure */
3
4/* Generate 80386 code? */
5#undef I386_ONLY
6
7#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
8#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
9#define OPENSSLDIR "/usr/local/ssl"
10#endif
11#endif
12
13#define OPENSSL_UNISTD <unistd.h>
14
15#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
16#define IDEA_INT unsigned int
17#endif
18
19#if defined(HEADER_MD2_H) && !defined(MD2_INT)
20#define MD2_INT unsigned int
21#endif
22
23#if defined(HEADER_RC2_H) && !defined(RC2_INT)
24/* I need to put in a mod for the alpha - eay */
25#define RC2_INT unsigned int
26#endif
27
28#if defined(HEADER_RC4_H) && !defined(RC4_INT)
29/* using int types make the structure larger but make the code faster
30 * on most boxes I have tested - up to %20 faster. */
31#define RC4_INT unsigned int
32#endif
33
34#if defined(HEADER_DES_H) && !defined(DES_LONG)
35/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
36 * %20 speed up (longs are 8 bytes, int's are 4). */
37#ifndef DES_LONG
38#define DES_LONG unsigned long
39#endif
40#endif
41
42#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
43#define CONFIG_HEADER_BN_H
44#undef BN_LLONG
45
46/* Should we define BN_DIV2W here? */
47
48/* Only one for the following should be defined */
49/* The prime number generation stuff may not work when
50 * EIGHT_BIT but I don't care since I've only used this mode
51 * for debuging the bignum libraries */
52#undef SIXTY_FOUR_BIT_LONG
53#undef SIXTY_FOUR_BIT
54#define THIRTY_TWO_BIT
55#undef SIXTEEN_BIT
56#undef EIGHT_BIT
57#endif
58
59#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
60#define CONFIG_HEADER_RC4_LOCL_H
61/* if this is defined data[i] is used instead of *data, this is a %20
62 * speedup on x86 */
63#undef RC4_INDEX
64#endif
65
66#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
67#define CONFIG_HEADER_BF_LOCL_H
68#undef BF_PTR
69#endif /* HEADER_BF_LOCL_H */
70
71#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
72#define CONFIG_HEADER_DES_LOCL_H
73#ifndef DES_DEFAULT_OPTIONS
74/* the following is tweaked from a config script, that is why it is a
75 * protected undef/define */
76#ifndef DES_PTR
77#undef DES_PTR
78#endif
79
80/* This helps C compiler generate the correct code for multiple functional
81 * units. It reduces register dependancies at the expense of 2 more
82 * registers */
83#ifndef DES_RISC1
84#undef DES_RISC1
85#endif
86
87#ifndef DES_RISC2
88#undef DES_RISC2
89#endif
90
91#if defined(DES_RISC1) && defined(DES_RISC2)
92YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
93#endif
94
95/* Unroll the inner loop, this sometimes helps, sometimes hinders.
96 * Very mucy CPU dependant */
97#ifndef DES_UNROLL
98#undef DES_UNROLL
99#endif
100
101/* These default values were supplied by
102 * Peter Gutman <pgut001@cs.auckland.ac.nz>
103 * They are only used if nothing else has been defined */
104#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
105/* Special defines which change the way the code is built depending on the
106 CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
107 even newer MIPS CPU's, but at the moment one size fits all for
108 optimization options. Older Sparc's work better with only UNROLL, but
109 there's no way to tell at compile time what it is you're running on */
110
111#if defined( sun ) /* Newer Sparc's */
112# define DES_PTR
113# define DES_RISC1
114# define DES_UNROLL
115#elif defined( __ultrix ) /* Older MIPS */
116# define DES_PTR
117# define DES_RISC2
118# define DES_UNROLL
119#elif defined( __osf1__ ) /* Alpha */
120# define DES_PTR
121# define DES_RISC2
122#elif defined ( _AIX ) /* RS6000 */
123 /* Unknown */
124#elif defined( __hpux ) /* HP-PA */
125 /* Unknown */
126#elif defined( __aux ) /* 68K */
127 /* Unknown */
128#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */
129# define DES_UNROLL
130#elif defined( __sgi ) /* Newer MIPS */
131# define DES_PTR
132# define DES_RISC2
133# define DES_UNROLL
134#elif defined( i386 ) /* x86 boxes, should be gcc */
135# define DES_PTR
136# define DES_RISC1
137# define DES_UNROLL
138#endif /* Systems-specific speed defines */
139#endif
140
141#endif /* DES_DEFAULT_OPTIONS */
142#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 @@
1#ifndef HEADER_OPENSSLV_H
2#define HEADER_OPENSSLV_H
3
4/* Numeric release version identifier:
5 * MMNNFFRBB: major minor fix final beta/patch
6 * For example:
7 * 0.9.3-dev 0x00903000
8 * 0.9.3beta1 0x00903001
9 * 0.9.3beta2-dev 0x00903002
10 * 0.9.3beta2 0x00903002
11 * 0.9.3 0x00903100
12 * 0.9.3a 0x00903101
13 * 0.9.4 0x00904100
14 * 1.2.3z 0x1020311a
15 * (Prior to 0.9.3-dev a different scheme was used: 0.9.2b is 0x0922.)
16 */
17#define OPENSSL_VERSION_NUMBER 0x00904100L
18#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.4 09 Aug 1999"
19#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
20
21#endif /* HEADER_OPENSSLV_H */
diff --git a/src/lib/libcrypto/pem/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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=pem
19ERRC=pem_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= 21TEST=
22APPS= 22APPS=
23 23
24CTX_SIZE= ctx_size
25
26LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
27LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c $(ERRC).c 25LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c pem_err.c
28 26
29LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o $(ERRC).o 27LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o pem_err.o
30 28
31SRC= $(LIBSRC) 29SRC= $(LIBSRC)
32 30
33EXHEADER= pem.h 31EXHEADER= pem.h pem2.h
34HEADER= $(EXHEADER) 32HEADER= $(EXHEADER)
35 33
36ALL= $(GENERAL) $(SRC) $(HEADER) 34ALL= $(GENERAL) $(SRC) $(HEADER)
@@ -38,36 +36,27 @@ ALL= $(GENERAL) $(SRC) $(HEADER)
38top: 36top:
39 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) 37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
40 38
41all: pem.h lib 39all: lib
42
43pem.h: $(CTX_SIZE)
44 ./$(CTX_SIZE) <pem.org >pem.new
45 if [ -f pem.h ]; then mv -f pem.h pem.old; fi
46 mv -f pem.new pem.h
47
48$(CTX_SIZE): $(CTX_SIZE).o
49 $(CC) $(CFLAGS) -o $(CTX_SIZE) $(CTX_SIZE).o
50 40
51lib: $(LIBOBJ) 41lib: $(LIBOBJ)
52 $(AR) $(LIB) $(LIBOBJ) 42 $(AR) $(LIB) $(LIBOBJ)
53 sh $(TOP)/util/ranlib.sh $(LIB) 43 $(RANLIB) $(LIB)
54 @touch lib 44 @touch lib
55 45
56files: 46files:
57 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
58 48
59links: 49links: $(EXHEADER)
60 /bin/rm -f Makefile 50 @$(TOP)/util/point.sh Makefile.ssl Makefile
61 $(TOP)/util/point.sh Makefile.ssl Makefile ; 51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
62 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
63 $(TOP)/util/mklink.sh ../../test $(TEST) 53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
64 $(TOP)/util/mklink.sh ../../apps $(APPS)
65 54
66install: 55install:
67 @for i in $(EXHEADER) ; \ 56 @for i in $(EXHEADER) ; \
68 do \ 57 do \
69 (cp $$i $(INSTALLTOP)/include/$$i; \ 58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
70 chmod 644 $(INSTALLTOP)/include/$$i ); \ 59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
71 done; 60 done;
72 61
73tags: 62tags:
@@ -79,18 +68,121 @@ lint:
79 lint -DLINT $(INCLUDES) $(SRC)>fluff 68 lint -DLINT $(INCLUDES) $(SRC)>fluff
80 69
81depend: 70depend:
82 $(MAKEDEPEND) $(INCLUDES) $(CTX_SIZE).c $(LIBSRC) 71 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(LIBSRC)
83 72
84dclean: 73dclean:
85 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
86 mv -f Makefile.new $(MAKEFILE) 75 mv -f Makefile.new $(MAKEFILE)
87 76
88clean: 77clean:
89 /bin/rm -f $(CTX_SIZE) *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
90
91errors:
92 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).org # SPECIAL CASE .org
93 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
94 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
95 79
96# DO NOT DELETE THIS LINE -- make depend depends on it. 80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82pem_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
83pem_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
84pem_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
85pem_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
86pem_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
87pem_all.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
88pem_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
89pem_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
90pem_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
91pem_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
92pem_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
93pem_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
94pem_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
95pem_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
96pem_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
97pem_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
98pem_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
99pem_all.o: ../cryptlib.h
100pem_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
101pem_err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
102pem_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
103pem_err.o: ../../include/openssl/des.h ../../include/openssl/dh.h
104pem_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
105pem_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
106pem_err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
107pem_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
108pem_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
109pem_err.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
110pem_err.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
111pem_err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
112pem_err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
113pem_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
114pem_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
115pem_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
116pem_info.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
117pem_info.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
118pem_info.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
119pem_info.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
120pem_info.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
121pem_info.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
122pem_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
123pem_info.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
124pem_info.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
125pem_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
126pem_info.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
127pem_info.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
128pem_info.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
129pem_info.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
130pem_info.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
131pem_info.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
132pem_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
133pem_info.o: ../cryptlib.h
134pem_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
135pem_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
136pem_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
137pem_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
138pem_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
139pem_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
140pem_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
141pem_lib.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
142pem_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
143pem_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
144pem_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
145pem_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
146pem_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
147pem_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
148pem_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
149pem_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
150pem_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
151pem_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
152pem_lib.o: ../cryptlib.h
153pem_seal.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
154pem_seal.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
155pem_seal.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
156pem_seal.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
157pem_seal.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
158pem_seal.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
159pem_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
160pem_seal.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
161pem_seal.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
162pem_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
163pem_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
164pem_seal.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
165pem_seal.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
166pem_seal.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
167pem_seal.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
168pem_seal.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
169pem_seal.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
170pem_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
171pem_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
172pem_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
173pem_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
174pem_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
175pem_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
176pem_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
177pem_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
178pem_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
179pem_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
180pem_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
181pem_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
182pem_sign.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
183pem_sign.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
184pem_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
185pem_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
186pem_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
187pem_sign.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
188pem_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 @@
1/* crypto/pem/ctx_size.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include "evp.h"
62
63int main(argc,argv)
64int argc;
65char *argv[];
66 {
67 int i,j;
68 char buf[256];
69
70 for (;;)
71 {
72 char *str;
73 buf[0]='\0';
74 fgets(buf,256,stdin);
75 if (buf[0] == '\0') break;
76
77 str="#define EVP_ENCODE_CTX_SIZE ";
78 if (strncmp(buf,str,strlen(str)) == 0)
79 {
80 printf("%s %d\n",str,(int)sizeof(EVP_ENCODE_CTX));
81 continue;
82 }
83 str="#define EVP_MD_SIZE ";
84 if (strncmp(buf,str,strlen(str)) == 0)
85 {
86 printf("%s %d\n",str,(int)sizeof(EVP_MD));
87 continue;
88 }
89 str="#define EVP_MD_CTX_SIZE ";
90 if (strncmp(buf,str,strlen(str)) == 0)
91 {
92 printf("%s %d\n",str,(int)sizeof(EVP_MD_CTX));
93 continue;
94 }
95 str="#define EVP_CIPHER_SIZE ";
96 if (strncmp(buf,str,strlen(str)) == 0)
97 {
98 printf("%s %d\n",str,(int)sizeof(EVP_CIPHER));
99 continue;
100 }
101 str="#define EVP_CIPHER_CTX_SIZE ";
102 if (strncmp(buf,str,strlen(str)) == 0)
103 {
104 printf("%s %d\n",str,(int)sizeof(EVP_CIPHER_CTX));
105 continue;
106 }
107
108 str="#define EVP_MAX_MD_SIZE ";
109 if (strncmp(buf,str,strlen(str)) == 0)
110 {
111 i=MD2_DIGEST_LENGTH;
112 j=MD5_DIGEST_LENGTH;
113 if (j > i) i=j;
114 j=SHA_DIGEST_LENGTH;
115 if (j > i) i=j;
116 printf("%s %d\n",str,i);
117 continue;
118 }
119 fputs(buf,stdout);
120 }
121 exit(0);
122 }
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 @@
1/* Error codes for the PEM functions. */
2
3/* Function codes. */
4#define PEM_F_DEF_CALLBACK 100
5#define PEM_F_LOAD_IV 101
6#define PEM_F_PEM_ASN1_READ 102
7#define PEM_F_PEM_ASN1_READ_BIO 103
8#define PEM_F_PEM_ASN1_WRITE 104
9#define PEM_F_PEM_ASN1_WRITE_BIO 105
10#define PEM_F_PEM_DO_HEADER 106
11#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
12#define PEM_F_PEM_READ 108
13#define PEM_F_PEM_READ_BIO 109
14#define PEM_F_PEM_SEALFINAL 110
15#define PEM_F_PEM_SEALINIT 111
16#define PEM_F_PEM_SIGNFINAL 112
17#define PEM_F_PEM_WRITE 113
18#define PEM_F_PEM_WRITE_BIO 114
19#define PEM_F_PEM_X509_INFO_READ 115
20#define PEM_F_PEM_X509_INFO_READ_BIO 116
21#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
22
23/* Reason codes. */
24#define PEM_R_BAD_BASE64_DECODE 100
25#define PEM_R_BAD_DECRYPT 101
26#define PEM_R_BAD_END_LINE 102
27#define PEM_R_BAD_IV_CHARS 103
28#define PEM_R_BAD_PASSWORD_READ 104
29#define PEM_R_NOT_DEK_INFO 105
30#define PEM_R_NOT_ENCRYPTED 106
31#define PEM_R_NOT_PROC_TYPE 107
32#define PEM_R_NO_START_LINE 108
33#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
34#define PEM_R_PUBLIC_KEY_NO_RSA 110
35#define PEM_R_READ_KEY 111
36#define PEM_R_SHORT_HEADER 112
37#define PEM_R_UNSUPPORTED_CIPHER 113
38#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 @@
1/* crypto/pem/pem.org */ 1/* crypto/pem/pem.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,14 +56,6 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify pem.org since pem.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_PEM_H 59#ifndef HEADER_PEM_H
68#define HEADER_PEM_H 60#define HEADER_PEM_H
69 61
@@ -71,8 +63,11 @@
71extern "C" { 63extern "C" {
72#endif 64#endif
73 65
74#include "evp.h" 66#include <openssl/evp.h>
75#include "x509.h" 67#include <openssl/x509.h>
68#include <openssl/pem2.h>
69
70#define PEM_BUFSIZE 1024
76 71
77#define PEM_OBJ_UNDEF 0 72#define PEM_OBJ_UNDEF 0
78#define PEM_OBJ_X509 1 73#define PEM_OBJ_X509 1
@@ -111,45 +106,17 @@ extern "C" {
111#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" 106#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
112#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" 107#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
113#define PEM_STRING_X509_CRL "X509 CRL" 108#define PEM_STRING_X509_CRL "X509 CRL"
114#define PEM_STRING_EVP_PKEY "PRIVATE KEY" 109#define PEM_STRING_EVP_PKEY "ANY PRIVATE KEY"
115#define PEM_STRING_RSA "RSA PRIVATE KEY" 110#define PEM_STRING_RSA "RSA PRIVATE KEY"
116#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY" 111#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
117#define PEM_STRING_DSA "DSA PRIVATE KEY" 112#define PEM_STRING_DSA "DSA PRIVATE KEY"
118#define PEM_STRING_PKCS7 "PKCS7" 113#define PEM_STRING_PKCS7 "PKCS7"
114#define PEM_STRING_PKCS8 "ENCRYPTED PRIVATE KEY"
115#define PEM_STRING_PKCS8INF "PRIVATE KEY"
119#define PEM_STRING_DHPARAMS "DH PARAMETERS" 116#define PEM_STRING_DHPARAMS "DH PARAMETERS"
120#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" 117#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
121#define PEM_STRING_DSAPARAMS "DSA PARAMETERS" 118#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
122 119
123#ifndef HEADER_ENVELOPE_H
124
125#define EVP_ENCODE_CTX_SIZE 96
126#define EVP_MD_SIZE 60
127#define EVP_MD_CTX_SIZE 152
128#define EVP_CIPHER_SIZE 40
129#define EVP_CIPHER_CTX_SIZE 4212
130#define EVP_MAX_MD_SIZE 20
131
132typedef struct evp_encode_ctx_st
133 {
134 char data[EVP_ENCODE_CTX_SIZE];
135 } EVP_ENCODE_CTX;
136
137typedef struct env_md_ctx_st
138 {
139 char data[EVP_MD_CTX_SIZE];
140 } EVP_MD_CTX;
141
142typedef struct evp_cipher_st
143 {
144 char data[EVP_CIPHER_SIZE];
145 } EVP_CIPHER;
146
147typedef struct evp_cipher_ctx_st
148 {
149 char data[EVP_CIPHER_CTX_SIZE];
150 } EVP_CIPHER_CTX;
151#endif
152
153 120
154typedef struct PEM_Encode_Seal_st 121typedef struct PEM_Encode_Seal_st
155 { 122 {
@@ -217,151 +184,322 @@ typedef struct pem_ctx_st
217 unsigned char *data; 184 unsigned char *data;
218 } PEM_CTX; 185 } PEM_CTX;
219 186
187/* These macros make the PEM_read/PEM_write functions easier to maintain and
188 * write. Now they are all implemented with either:
189 * IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
190 */
191
192#ifdef NO_FP_API
193
194#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/
195#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/
196#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/
197
198#else
199
200#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
201type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
202{ \
203return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
204 cb,u)); \
205} \
206
207#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
208int PEM_write_##name(FILE *fp, type *x) \
209{ \
210return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
211 NULL,NULL,0,NULL,NULL)); \
212}
213
214#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
215int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
216 unsigned char *kstr, int klen, pem_password_cb *cb, \
217 void *u) \
218 { \
219 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
220 (char *)x,enc,kstr,klen,cb,u)); \
221 }
222
223#endif
224
225#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
226type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
227{ \
228return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
229 (char **)x,cb,u)); \
230}
231
232#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
233int PEM_write_bio_##name(BIO *bp, type *x) \
234{ \
235return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
236 NULL,NULL,0,NULL,NULL)); \
237}
238
239#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
240int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
241 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
242 { \
243 return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \
244 (char *)x,enc,kstr,klen,cb,u)); \
245 }
246
247#define IMPLEMENT_PEM_write(name, type, str, asn1) \
248 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
249 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
250
251#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
252 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
253 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
254
255#define IMPLEMENT_PEM_read(name, type, str, asn1) \
256 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
257 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
258
259#define IMPLEMENT_PEM_rw(name, type, str, asn1) \
260 IMPLEMENT_PEM_read(name, type, str, asn1) \
261 IMPLEMENT_PEM_write(name, type, str, asn1)
262
263#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
264 IMPLEMENT_PEM_read(name, type, str, asn1) \
265 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
266
267/* These are the same except they are for the declarations */
268
269#if defined(WIN16) || defined(NO_FP_API)
270
271#define DECLARE_PEM_read_fp(name, type) /**/
272#define DECLARE_PEM_write_fp(name, type) /**/
273#define DECLARE_PEM_write_cb_fp(name, type) /**/
274
275#else
276
277#define DECLARE_PEM_read_fp(name, type) \
278 type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u);
279
280#define DECLARE_PEM_write_fp(name, type) \
281 int PEM_write_##name(FILE *fp, type *x);
282
283#define DECLARE_PEM_write_cb_fp(name, type) \
284 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
285 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
286
287#endif
288
289#ifdef HEADER_BIO_H
290#define DECLARE_PEM_read_bio(name, type) \
291 type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u);
292
293#define DECLARE_PEM_write_bio(name, type) \
294 int PEM_write_bio_##name(BIO *bp, type *x);
295
296#define DECLARE_PEM_write_cb_bio(name, type) \
297 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
298 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
299
300#else
301
302#define DECLARE_PEM_read_bio(name, type) /**/
303#define DECLARE_PEM_write_bio(name, type) /**/
304#define DECLARE_PEM_write_cb_bio(name, type) /**/
305
306#endif
307
308#define DECLARE_PEM_write(name, type) \
309 DECLARE_PEM_write_bio(name, type) \
310 DECLARE_PEM_write_fp(name, type)
311
312#define DECLARE_PEM_write_cb(name, type) \
313 DECLARE_PEM_write_cb_bio(name, type) \
314 DECLARE_PEM_write_cb_fp(name, type)
315
316#define DECLARE_PEM_read(name, type) \
317 DECLARE_PEM_read_bio(name, type) \
318 DECLARE_PEM_read_fp(name, type)
319
320#define DECLARE_PEM_rw(name, type) \
321 DECLARE_PEM_read(name, type) \
322 DECLARE_PEM_write(name, type)
323
324#define DECLARE_PEM_rw_cb(name, type) \
325 DECLARE_PEM_read(name, type) \
326 DECLARE_PEM_write_cb(name, type)
327
220#ifdef SSLEAY_MACROS 328#ifdef SSLEAY_MACROS
221 329
222#define PEM_write_SSL_SESSION(fp,x) \ 330#define PEM_write_SSL_SESSION(fp,x) \
223 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \ 331 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
224 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL) 332 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
225#define PEM_write_X509(fp,x) \ 333#define PEM_write_X509(fp,x) \
226 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \ 334 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
227 (char *)x, NULL,NULL,0,NULL) 335 (char *)x, NULL,NULL,0,NULL,NULL)
228#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \ 336#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
229 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \ 337 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
230 NULL,NULL,0,NULL) 338 NULL,NULL,0,NULL,NULL)
231#define PEM_write_X509_CRL(fp,x) \ 339#define PEM_write_X509_CRL(fp,x) \
232 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \ 340 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
233 fp,(char *)x, NULL,NULL,0,NULL) 341 fp,(char *)x, NULL,NULL,0,NULL,NULL)
234#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \ 342#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
235 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\ 343 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
236 (char *)x,enc,kstr,klen,cb) 344 (char *)x,enc,kstr,klen,cb,u)
237#define PEM_write_RSAPublicKey(fp,x) \ 345#define PEM_write_RSAPublicKey(fp,x) \
238 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\ 346 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
239 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL) 347 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
240#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \ 348#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb,u) \
241 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\ 349 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
242 (char *)x,enc,kstr,klen,cb) 350 (char *)x,enc,kstr,klen,cb,u)
243#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \ 351#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
244 PEM_ASN1_write((int (*)())i2d_PrivateKey,\ 352 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
245 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ 353 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
246 bp,(char *)x,enc,kstr,klen,cb) 354 bp,(char *)x,enc,kstr,klen,cb,u)
247#define PEM_write_PKCS7(fp,x) \ 355#define PEM_write_PKCS7(fp,x) \
248 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \ 356 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
249 (char *)x, NULL,NULL,0,NULL) 357 (char *)x, NULL,NULL,0,NULL,NULL)
250#define PEM_write_DHparams(fp,x) \ 358#define PEM_write_DHparams(fp,x) \
251 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\ 359 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
252 (char *)x,NULL,NULL,0,NULL) 360 (char *)x,NULL,NULL,0,NULL,NULL)
253 361
254#define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \ 362#define PEM_write_NETSCAPE_CERT_SEQUENCE(fp,x) \
255 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb) 363 PEM_ASN1_write((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
256#define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \ 364 PEM_STRING_X509,fp, \
257 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb) 365 (char *)x, NULL,NULL,0,NULL,NULL)
258#define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \ 366
259 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb) 367#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
260#define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \ 368 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
261 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb) 369#define PEM_read_X509(fp,x,cb,u) (X509 *)PEM_ASN1_read( \
262#define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ 370 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb,u)
263 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb) 371#define PEM_read_X509_REQ(fp,x,cb,u) (X509_REQ *)PEM_ASN1_read( \
264#define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \ 372 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb,u)
265 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb) 373#define PEM_read_X509_CRL(fp,x,cb,u) (X509_CRL *)PEM_ASN1_read( \
266#define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \ 374 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb,u)
267 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb) 375#define PEM_read_RSAPrivateKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
268#define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \ 376 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb,u)
269 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb) 377#define PEM_read_RSAPublicKey(fp,x,cb,u) (RSA *)PEM_ASN1_read( \
270#define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \ 378 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb,u)
271 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb) 379#define PEM_read_DSAPrivateKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
272#define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \ 380 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb,u)
273 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb) 381#define PEM_read_PrivateKey(fp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read( \
382 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb,u)
383#define PEM_read_PKCS7(fp,x,cb,u) (PKCS7 *)PEM_ASN1_read( \
384 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb,u)
385#define PEM_read_DHparams(fp,x,cb,u) (DH *)PEM_ASN1_read( \
386 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb,u)
387
388#define PEM_read_NETSCAPE_CERT_SEQUENCE(fp,x,cb,u) \
389 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read( \
390 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
391 (char **)x,cb,u)
274 392
275#define PEM_write_bio_SSL_SESSION(bp,x) \ 393#define PEM_write_bio_SSL_SESSION(bp,x) \
276 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \ 394 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
277 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL) 395 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
278#define PEM_write_bio_X509(bp,x) \ 396#define PEM_write_bio_X509(bp,x) \
279 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ 397 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
280 (char *)x, NULL,NULL,0,NULL) 398 (char *)x, NULL,NULL,0,NULL,NULL)
281#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \ 399#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
282 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \ 400 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
283 NULL,NULL,0,NULL) 401 NULL,NULL,0,NULL,NULL)
284#define PEM_write_bio_X509_CRL(bp,x) \ 402#define PEM_write_bio_X509_CRL(bp,x) \
285 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\ 403 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
286 bp,(char *)x, NULL,NULL,0,NULL) 404 bp,(char *)x, NULL,NULL,0,NULL,NULL)
287#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \ 405#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
288 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\ 406 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
289 bp,(char *)x,enc,kstr,klen,cb) 407 bp,(char *)x,enc,kstr,klen,cb,u)
290#define PEM_write_bio_RSAPublicKey(bp,x) \ 408#define PEM_write_bio_RSAPublicKey(bp,x) \
291 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \ 409 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
292 PEM_STRING_RSA_PUBLIC,\ 410 PEM_STRING_RSA_PUBLIC,\
293 bp,(char *)x,NULL,NULL,0,NULL) 411 bp,(char *)x,NULL,NULL,0,NULL,NULL)
294#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \ 412#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb,u) \
295 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\ 413 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
296 bp,(char *)x,enc,kstr,klen,cb) 414 bp,(char *)x,enc,kstr,klen,cb,u)
297#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \ 415#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb,u) \
298 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\ 416 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
299 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\ 417 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
300 bp,(char *)x,enc,kstr,klen,cb) 418 bp,(char *)x,enc,kstr,klen,cb,u)
301#define PEM_write_bio_PKCS7(bp,x) \ 419#define PEM_write_bio_PKCS7(bp,x) \
302 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \ 420 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
303 (char *)x, NULL,NULL,0,NULL) 421 (char *)x, NULL,NULL,0,NULL,NULL)
304#define PEM_write_bio_DHparams(bp,x) \ 422#define PEM_write_bio_DHparams(bp,x) \
305 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\ 423 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
306 bp,(char *)x,NULL,NULL,0,NULL) 424 bp,(char *)x,NULL,NULL,0,NULL,NULL)
307#define PEM_write_bio_DSAparams(bp,x) \ 425#define PEM_write_bio_DSAparams(bp,x) \
308 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \ 426 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
309 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL) 427 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL,NULL)
310 428
311#define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \ 429#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE(bp,x) \
312 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb) 430 PEM_ASN1_write_bio((int (*)())i2d_NETSCAPE_CERT_SEQUENCE, \
313#define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \ 431 PEM_STRING_X509,bp, \
314 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb) 432 (char *)x, NULL,NULL,0,NULL,NULL)
315#define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \ 433
316 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb) 434#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
317#define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \ 435 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
318 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb) 436#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
319#define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ 437 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
320 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb) 438#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
321#define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \ 439 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb,u)
322 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb) 440#define PEM_read_bio_X509_CRL(bp,x,cb,u) (X509_CRL *)PEM_ASN1_read_bio( \
323#define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ 441 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb,u)
324 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb) 442#define PEM_read_bio_RSAPrivateKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
325#define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \ 443 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb,u)
326 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb) 444#define PEM_read_bio_RSAPublicKey(bp,x,cb,u) (RSA *)PEM_ASN1_read_bio( \
327 445 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb,u)
328#define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \ 446#define PEM_read_bio_DSAPrivateKey(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
329 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb) 447 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb,u)
330#define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \ 448#define PEM_read_bio_PrivateKey(bp,x,cb,u) (EVP_PKEY *)PEM_ASN1_read_bio( \
331 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb) 449 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb,u)
332#define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \ 450
333 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb) 451#define PEM_read_bio_PKCS7(bp,x,cb,u) (PKCS7 *)PEM_ASN1_read_bio( \
452 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb,u)
453#define PEM_read_bio_DHparams(bp,x,cb,u) (DH *)PEM_ASN1_read_bio( \
454 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb,u)
455#define PEM_read_bio_DSAparams(bp,x,cb,u) (DSA *)PEM_ASN1_read_bio( \
456 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb,u)
457
458#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE(bp,x,cb,u) \
459 (NETSCAPE_CERT_SEQUENCE *)PEM_ASN1_read_bio( \
460 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,bp,\
461 (char **)x,cb,u)
334 462
335#endif 463#endif
336 464
337#ifndef NOPROTO 465#if 1
466/* "userdata": new with OpenSSL 0.9.4 */
467typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
468#else
469/* OpenSSL 0.9.3, 0.9.3a */
470typedef int pem_password_cb(char *buf, int size, int rwflag);
471#endif
472
338int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); 473int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
339int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, 474int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
340 int (*callback)()); 475 pem_password_cb *callback,void *u);
341 476
342#ifdef HEADER_BIO_H 477#ifdef HEADER_BIO_H
343int PEM_read_bio(BIO *bp, char **name, char **header, 478int PEM_read_bio(BIO *bp, char **name, char **header,
344 unsigned char **data,long *len); 479 unsigned char **data,long *len);
345int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data, 480int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
346 long len); 481 long len);
347char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x, 482char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
348 int (*cb)()); 483 pem_password_cb *cb, void *u);
349int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x, 484int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
350 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); 485 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
351STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)()); 486 pem_password_cb *cb, void *u);
487STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
352int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, 488int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
353 unsigned char *kstr, int klen, int (*cb)()); 489 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
354#endif 490#endif
355 491
356#ifndef WIN16 492#ifndef WIN16
357int PEM_read(FILE *fp, char **name, char **header, 493int PEM_read(FILE *fp, char **name, char **header,
358 unsigned char **data,long *len); 494 unsigned char **data,long *len);
359int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); 495int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
360char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x, 496char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
361 int (*cb)()); 497 pem_password_cb *cb, void *u);
362int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x, 498int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
363 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)()); 499 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
364STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)()); 500 pem_password_cb *callback, void *u);
501STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
502 pem_password_cb *cb, void *u);
365#endif 503#endif
366 504
367int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, 505int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
@@ -380,142 +518,64 @@ int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
380void ERR_load_PEM_strings(void); 518void ERR_load_PEM_strings(void);
381 519
382void PEM_proc_type(char *buf, int type); 520void PEM_proc_type(char *buf, int type);
383void PEM_dek_info(char *buf, char *type, int len, char *str); 521void PEM_dek_info(char *buf, const char *type, int len, char *str);
384 522
385#ifndef SSLEAY_MACROS 523#ifndef SSLEAY_MACROS
386 524
387#ifndef WIN16 525#ifdef VMS
388X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)()); 526#include <openssl/vms_idhacks.h>
389X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)());
390X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)());
391RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)());
392RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)());
393DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)());
394EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)());
395PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)());
396DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)());
397DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)());
398int PEM_write_X509(FILE *fp,X509 *x);
399int PEM_write_X509_REQ(FILE *fp,X509_REQ *x);
400int PEM_write_X509_CRL(FILE *fp,X509_CRL *x);
401int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr,
402 int klen,int (*cb)());
403int PEM_write_RSAPublicKey(FILE *fp,RSA *x);
404int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr,
405 int klen,int (*cb)());
406int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc,
407 unsigned char *kstr,int klen,int (*cb)());
408int PEM_write_PKCS7(FILE *fp,PKCS7 *x);
409int PEM_write_DHparams(FILE *fp,DH *x);
410int PEM_write_DSAparams(FILE *fp,DSA *x);
411#endif 527#endif
412 528
413#ifdef HEADER_BIO_H 529DECLARE_PEM_rw(X509, X509)
414X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)()); 530
415X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)()); 531DECLARE_PEM_rw(X509_REQ, X509_REQ)
416X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)()); 532
417RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)()); 533DECLARE_PEM_rw(X509_CRL, X509_CRL)
418RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)()); 534
419DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)()); 535DECLARE_PEM_rw(PKCS7, PKCS7)
420EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)()); 536
421PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)()); 537DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE)
422DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)()); 538
423DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)()); 539DECLARE_PEM_rw(PKCS8, X509_SIG)
424int PEM_write_bio_X509(BIO *bp,X509 *x); 540
425int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x); 541DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
426int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x); 542
427int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc, 543#ifndef NO_RSA
428 unsigned char *kstr,int klen,int (*cb)()); 544
429int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x); 545DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
430int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc, 546
431 unsigned char *kstr,int klen,int (*cb)()); 547DECLARE_PEM_rw(RSAPublicKey, RSA)
432int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc, 548
433 unsigned char *kstr,int klen,int (*cb)());
434int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x);
435int PEM_write_bio_DHparams(BIO *bp,DH *x);
436int PEM_write_bio_DSAparams(BIO *bp,DSA *x);
437#endif 549#endif
438 550
439#endif /* SSLEAY_MACROS */ 551#ifndef NO_DSA
440 552
553DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
441 554
442#else 555DECLARE_PEM_rw(DSAparams, DSA)
443 556
444int PEM_get_EVP_CIPHER_INFO();
445int PEM_do_header();
446int PEM_read_bio();
447int PEM_write_bio();
448#ifndef WIN16
449int PEM_read();
450int PEM_write();
451STACK * PEM_X509_INFO_read();
452char * PEM_ASN1_read();
453int PEM_ASN1_write();
454#endif 557#endif
455STACK * PEM_X509_INFO_read_bio();
456int PEM_X509_INFO_write_bio();
457char * PEM_ASN1_read_bio();
458int PEM_ASN1_write_bio();
459int PEM_SealInit();
460void PEM_SealUpdate();
461int PEM_SealFinal();
462int PEM_SignFinal();
463 558
464void ERR_load_PEM_strings(); 559#ifndef NO_DH
465 560
466void PEM_proc_type(); 561DECLARE_PEM_rw(DHparams, DH)
467void PEM_dek_info();
468 562
469#ifndef SSLEAY_MACROS
470#ifndef WIN16
471X509 *PEM_read_X509();
472X509_REQ *PEM_read_X509_REQ();
473X509_CRL *PEM_read_X509_CRL();
474RSA *PEM_read_RSAPrivateKey();
475RSA *PEM_read_RSAPublicKey();
476DSA *PEM_read_DSAPrivateKey();
477EVP_PKEY *PEM_read_PrivateKey();
478PKCS7 *PEM_read_PKCS7();
479DH *PEM_read_DHparams();
480DSA *PEM_read_DSAparams();
481int PEM_write_X509();
482int PEM_write_X509_REQ();
483int PEM_write_X509_CRL();
484int PEM_write_RSAPrivateKey();
485int PEM_write_RSAPublicKey();
486int PEM_write_DSAPrivateKey();
487int PEM_write_PrivateKey();
488int PEM_write_PKCS7();
489int PEM_write_DHparams();
490int PEM_write_DSAparams();
491#endif 563#endif
492 564
493X509 *PEM_read_bio_X509(); 565DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
494X509_REQ *PEM_read_bio_X509_REQ();
495X509_CRL *PEM_read_bio_X509_CRL();
496RSA *PEM_read_bio_RSAPrivateKey();
497RSA *PEM_read_bio_RSAPublicKey();
498DSA *PEM_read_bio_DSAPrivateKey();
499EVP_PKEY *PEM_read_bio_PrivateKey();
500PKCS7 *PEM_read_bio_PKCS7();
501DH *PEM_read_bio_DHparams();
502DSA *PEM_read_bio_DSAparams();
503int PEM_write_bio_X509();
504int PEM_write_bio_X509_REQ();
505int PEM_write_bio_X509_CRL();
506int PEM_write_bio_RSAPrivateKey();
507int PEM_write_bio_RSAPublicKey();
508int PEM_write_bio_DSAPrivateKey();
509int PEM_write_bio_PrivateKey();
510int PEM_write_bio_PKCS7();
511int PEM_write_bio_DHparams();
512int PEM_write_bio_DSAparams();
513 566
567int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *,
568 char *, int, pem_password_cb *, void *);
569int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc,
570 char *kstr,int klen, pem_password_cb *cd, void *u);
514#endif /* SSLEAY_MACROS */ 571#endif /* SSLEAY_MACROS */
515 572
516#endif
517 573
518/* BEGIN ERROR CODES */ 574/* BEGIN ERROR CODES */
575/* The following lines are auto generated by the script mkerr.pl. Any changes
576 * made after this point may be overwritten when the script is next run.
577 */
578
519/* Error codes for the PEM functions. */ 579/* Error codes for the PEM functions. */
520 580
521/* Function codes. */ 581/* Function codes. */
@@ -526,6 +586,7 @@ int PEM_write_bio_DSAparams();
526#define PEM_F_PEM_ASN1_WRITE 104 586#define PEM_F_PEM_ASN1_WRITE 104
527#define PEM_F_PEM_ASN1_WRITE_BIO 105 587#define PEM_F_PEM_ASN1_WRITE_BIO 105
528#define PEM_F_PEM_DO_HEADER 106 588#define PEM_F_PEM_DO_HEADER 106
589#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
529#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 590#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
530#define PEM_F_PEM_READ 108 591#define PEM_F_PEM_READ 108
531#define PEM_F_PEM_READ_BIO 109 592#define PEM_F_PEM_READ_BIO 109
@@ -534,6 +595,7 @@ int PEM_write_bio_DSAparams();
534#define PEM_F_PEM_SIGNFINAL 112 595#define PEM_F_PEM_SIGNFINAL 112
535#define PEM_F_PEM_WRITE 113 596#define PEM_F_PEM_WRITE 113
536#define PEM_F_PEM_WRITE_BIO 114 597#define PEM_F_PEM_WRITE_BIO 114
598#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
537#define PEM_F_PEM_X509_INFO_READ 115 599#define PEM_F_PEM_X509_INFO_READ 115
538#define PEM_F_PEM_X509_INFO_READ_BIO 116 600#define PEM_F_PEM_X509_INFO_READ_BIO 116
539#define PEM_F_PEM_X509_INFO_WRITE_BIO 117 601#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
@@ -544,6 +606,7 @@ int PEM_write_bio_DSAparams();
544#define PEM_R_BAD_END_LINE 102 606#define PEM_R_BAD_END_LINE 102
545#define PEM_R_BAD_IV_CHARS 103 607#define PEM_R_BAD_IV_CHARS 103
546#define PEM_R_BAD_PASSWORD_READ 104 608#define PEM_R_BAD_PASSWORD_READ 104
609#define PEM_R_ERROR_CONVERTING_PRIVATE_KEY 115
547#define PEM_R_NOT_DEK_INFO 105 610#define PEM_R_NOT_DEK_INFO 105
548#define PEM_R_NOT_ENCRYPTED 106 611#define PEM_R_NOT_ENCRYPTED 106
549#define PEM_R_NOT_PROC_TYPE 107 612#define PEM_R_NOT_PROC_TYPE 107
@@ -554,7 +617,7 @@ int PEM_write_bio_DSAparams();
554#define PEM_R_SHORT_HEADER 112 617#define PEM_R_SHORT_HEADER 112
555#define PEM_R_UNSUPPORTED_CIPHER 113 618#define PEM_R_UNSUPPORTED_CIPHER 113
556#define PEM_R_UNSUPPORTED_ENCRYPTION 114 619#define PEM_R_UNSUPPORTED_ENCRYPTION 114
557 620
558#ifdef __cplusplus 621#ifdef __cplusplus
559} 622}
560#endif 623#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 @@
1/* crypto/pem/pem.org */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify pem.org since pem.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_PEM_H
68#define HEADER_PEM_H
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74#include "evp.h"
75#include "x509.h"
76
77#define PEM_OBJ_UNDEF 0
78#define PEM_OBJ_X509 1
79#define PEM_OBJ_X509_REQ 2
80#define PEM_OBJ_CRL 3
81#define PEM_OBJ_SSL_SESSION 4
82#define PEM_OBJ_PRIV_KEY 10
83#define PEM_OBJ_PRIV_RSA 11
84#define PEM_OBJ_PRIV_DSA 12
85#define PEM_OBJ_PRIV_DH 13
86#define PEM_OBJ_PUB_RSA 14
87#define PEM_OBJ_PUB_DSA 15
88#define PEM_OBJ_PUB_DH 16
89#define PEM_OBJ_DHPARAMS 17
90#define PEM_OBJ_DSAPARAMS 18
91#define PEM_OBJ_PRIV_RSA_PUBLIC 19
92
93#define PEM_ERROR 30
94#define PEM_DEK_DES_CBC 40
95#define PEM_DEK_IDEA_CBC 45
96#define PEM_DEK_DES_EDE 50
97#define PEM_DEK_DES_ECB 60
98#define PEM_DEK_RSA 70
99#define PEM_DEK_RSA_MD2 80
100#define PEM_DEK_RSA_MD5 90
101
102#define PEM_MD_MD2 NID_md2
103#define PEM_MD_MD5 NID_md5
104#define PEM_MD_SHA NID_sha
105#define PEM_MD_MD2_RSA NID_md2WithRSAEncryption
106#define PEM_MD_MD5_RSA NID_md5WithRSAEncryption
107#define PEM_MD_SHA_RSA NID_sha1WithRSAEncryption
108
109#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
110#define PEM_STRING_X509 "CERTIFICATE"
111#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
112#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
113#define PEM_STRING_X509_CRL "X509 CRL"
114#define PEM_STRING_EVP_PKEY "PRIVATE KEY"
115#define PEM_STRING_RSA "RSA PRIVATE KEY"
116#define PEM_STRING_RSA_PUBLIC "RSA PUBLIC KEY"
117#define PEM_STRING_DSA "DSA PRIVATE KEY"
118#define PEM_STRING_PKCS7 "PKCS7"
119#define PEM_STRING_DHPARAMS "DH PARAMETERS"
120#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
121#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
122
123#ifndef HEADER_ENVELOPE_H
124
125#define EVP_ENCODE_CTX_SIZE 92
126#define EVP_MD_SIZE 48
127#define EVP_MD_CTX_SIZE 152
128#define EVP_CIPHER_SIZE 28
129#define EVP_CIPHER_CTX_SIZE 4212
130#define EVP_MAX_MD_SIZE 20
131
132typedef struct evp_encode_ctx_st
133 {
134 char data[EVP_ENCODE_CTX_SIZE];
135 } EVP_ENCODE_CTX;
136
137typedef struct env_md_ctx_st
138 {
139 char data[EVP_MD_CTX_SIZE];
140 } EVP_MD_CTX;
141
142typedef struct evp_cipher_st
143 {
144 char data[EVP_CIPHER_SIZE];
145 } EVP_CIPHER;
146
147typedef struct evp_cipher_ctx_st
148 {
149 char data[EVP_CIPHER_CTX_SIZE];
150 } EVP_CIPHER_CTX;
151#endif
152
153
154typedef struct PEM_Encode_Seal_st
155 {
156 EVP_ENCODE_CTX encode;
157 EVP_MD_CTX md;
158 EVP_CIPHER_CTX cipher;
159 } PEM_ENCODE_SEAL_CTX;
160
161/* enc_type is one off */
162#define PEM_TYPE_ENCRYPTED 10
163#define PEM_TYPE_MIC_ONLY 20
164#define PEM_TYPE_MIC_CLEAR 30
165#define PEM_TYPE_CLEAR 40
166
167typedef struct pem_recip_st
168 {
169 char *name;
170 X509_NAME *dn;
171
172 int cipher;
173 int key_enc;
174 char iv[8];
175 } PEM_USER;
176
177typedef struct pem_ctx_st
178 {
179 int type; /* what type of object */
180
181 struct {
182 int version;
183 int mode;
184 } proc_type;
185
186 char *domain;
187
188 struct {
189 int cipher;
190 unsigned char iv[8];
191 } DEK_info;
192
193 PEM_USER *originator;
194
195 int num_recipient;
196 PEM_USER **recipient;
197
198#ifdef HEADER_STACK_H
199 STACK *x509_chain; /* certificate chain */
200#else
201 char *x509_chain; /* certificate chain */
202#endif
203 EVP_MD *md; /* signature type */
204
205 int md_enc; /* is the md encrypted or not? */
206 int md_len; /* length of md_data */
207 char *md_data; /* message digest, could be pkey encrypted */
208
209 EVP_CIPHER *dec; /* date encryption cipher */
210 int key_len; /* key length */
211 unsigned char *key; /* key */
212 unsigned char iv[8]; /* the iv */
213
214
215 int data_enc; /* is the data encrypted */
216 int data_len;
217 unsigned char *data;
218 } PEM_CTX;
219
220#ifdef SSLEAY_MACROS
221
222#define PEM_write_SSL_SESSION(fp,x) \
223 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
224 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL)
225#define PEM_write_X509(fp,x) \
226 PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp, \
227 (char *)x, NULL,NULL,0,NULL)
228#define PEM_write_X509_REQ(fp,x) PEM_ASN1_write( \
229 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,(char *)x, \
230 NULL,NULL,0,NULL)
231#define PEM_write_X509_CRL(fp,x) \
232 PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL, \
233 fp,(char *)x, NULL,NULL,0,NULL)
234#define PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb) \
235 PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,\
236 (char *)x,enc,kstr,klen,cb)
237#define PEM_write_RSAPublicKey(fp,x) \
238 PEM_ASN1_write((int (*)())i2d_RSAPublicKey,\
239 PEM_STRING_RSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL)
240#define PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb) \
241 PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,\
242 (char *)x,enc,kstr,klen,cb)
243#define PEM_write_PrivateKey(bp,x,enc,kstr,klen,cb) \
244 PEM_ASN1_write((int (*)())i2d_PrivateKey,\
245 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
246 bp,(char *)x,enc,kstr,klen,cb)
247#define PEM_write_PKCS7(fp,x) \
248 PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp, \
249 (char *)x, NULL,NULL,0,NULL)
250#define PEM_write_DHparams(fp,x) \
251 PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,\
252 (char *)x,NULL,NULL,0,NULL)
253
254#define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \
255 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb)
256#define PEM_read_X509(fp,x,cb) (X509 *)PEM_ASN1_read( \
257 (char *(*)())d2i_X509,PEM_STRING_X509,fp,(char **)x,cb)
258#define PEM_read_X509_REQ(fp,x,cb) (X509_REQ *)PEM_ASN1_read( \
259 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,fp,(char **)x,cb)
260#define PEM_read_X509_CRL(fp,x,cb) (X509_CRL *)PEM_ASN1_read( \
261 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,fp,(char **)x,cb)
262#define PEM_read_RSAPrivateKey(fp,x,cb) (RSA *)PEM_ASN1_read( \
263 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,fp,(char **)x,cb)
264#define PEM_read_RSAPublicKey(fp,x,cb) (RSA *)PEM_ASN1_read( \
265 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb)
266#define PEM_read_DSAPrivateKey(fp,x,cb) (DSA *)PEM_ASN1_read( \
267 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,fp,(char **)x,cb)
268#define PEM_read_PrivateKey(fp,x,cb) (EVP_PKEY *)PEM_ASN1_read( \
269 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,fp,(char **)x,cb)
270#define PEM_read_PKCS7(fp,x,cb) (PKCS7 *)PEM_ASN1_read( \
271 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,fp,(char **)x,cb)
272#define PEM_read_DHparams(fp,x,cb) (DH *)PEM_ASN1_read( \
273 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,fp,(char **)x,cb)
274
275#define PEM_write_bio_SSL_SESSION(bp,x) \
276 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
277 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL)
278#define PEM_write_bio_X509(bp,x) \
279 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
280 (char *)x, NULL,NULL,0,NULL)
281#define PEM_write_bio_X509_REQ(bp,x) PEM_ASN1_write_bio( \
282 (int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,bp,(char *)x, \
283 NULL,NULL,0,NULL)
284#define PEM_write_bio_X509_CRL(bp,x) \
285 PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,\
286 bp,(char *)x, NULL,NULL,0,NULL)
287#define PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb) \
288 PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,\
289 bp,(char *)x,enc,kstr,klen,cb)
290#define PEM_write_bio_RSAPublicKey(bp,x) \
291 PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey, \
292 PEM_STRING_RSA_PUBLIC,\
293 bp,(char *)x,NULL,NULL,0,NULL)
294#define PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) \
295 PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,\
296 bp,(char *)x,enc,kstr,klen,cb)
297#define PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) \
298 PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,\
299 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),\
300 bp,(char *)x,enc,kstr,klen,cb)
301#define PEM_write_bio_PKCS7(bp,x) \
302 PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp, \
303 (char *)x, NULL,NULL,0,NULL)
304#define PEM_write_bio_DHparams(bp,x) \
305 PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,\
306 bp,(char *)x,NULL,NULL,0,NULL)
307#define PEM_write_bio_DSAparams(bp,x) \
308 PEM_ASN1_write_bio((int (*)())i2d_DSAparams, \
309 PEM_STRING_DSAPARAMS,bp,(char *)x,NULL,NULL,0,NULL)
310
311#define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \
312 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb)
313#define PEM_read_bio_X509(bp,x,cb) (X509 *)PEM_ASN1_read_bio( \
314 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb)
315#define PEM_read_bio_X509_REQ(bp,x,cb) (X509_REQ *)PEM_ASN1_read_bio( \
316 (char *(*)())d2i_X509_REQ,PEM_STRING_X509_REQ,bp,(char **)x,cb)
317#define PEM_read_bio_X509_CRL(bp,x,cb) (X509_CRL *)PEM_ASN1_read_bio( \
318 (char *(*)())d2i_X509_CRL,PEM_STRING_X509_CRL,bp,(char **)x,cb)
319#define PEM_read_bio_RSAPrivateKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \
320 (char *(*)())d2i_RSAPrivateKey,PEM_STRING_RSA,bp,(char **)x,cb)
321#define PEM_read_bio_RSAPublicKey(bp,x,cb) (RSA *)PEM_ASN1_read_bio( \
322 (char *(*)())d2i_RSAPublicKey,PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb)
323#define PEM_read_bio_DSAPrivateKey(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \
324 (char *(*)())d2i_DSAPrivateKey,PEM_STRING_DSA,bp,(char **)x,cb)
325#define PEM_read_bio_PrivateKey(bp,x,cb) (EVP_PKEY *)PEM_ASN1_read_bio( \
326 (char *(*)())d2i_PrivateKey,PEM_STRING_EVP_PKEY,bp,(char **)x,cb)
327
328#define PEM_read_bio_PKCS7(bp,x,cb) (PKCS7 *)PEM_ASN1_read_bio( \
329 (char *(*)())d2i_PKCS7,PEM_STRING_PKCS7,bp,(char **)x,cb)
330#define PEM_read_bio_DHparams(bp,x,cb) (DH *)PEM_ASN1_read_bio( \
331 (char *(*)())d2i_DHparams,PEM_STRING_DHPARAMS,bp,(char **)x,cb)
332#define PEM_read_bio_DSAparams(bp,x,cb) (DSA *)PEM_ASN1_read_bio( \
333 (char *(*)())d2i_DSAparams,PEM_STRING_DSAPARAMS,bp,(char **)x,cb)
334
335#endif
336
337#ifndef NOPROTO
338int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher);
339int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len,
340 int (*callback)());
341
342#ifdef HEADER_BIO_H
343int PEM_read_bio(BIO *bp, char **name, char **header,
344 unsigned char **data,long *len);
345int PEM_write_bio(BIO *bp,char *name,char *hdr,unsigned char *data,
346 long len);
347char * PEM_ASN1_read_bio(char *(*d2i)(),char *name,BIO *bp,char **x,
348 int (*cb)());
349int PEM_ASN1_write_bio(int (*i2d)(),char *name,BIO *bp,char *x,
350 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
351STACK * PEM_X509_INFO_read_bio(BIO *bp, STACK *sk, int (*cb)());
352int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
353 unsigned char *kstr, int klen, int (*cb)());
354#endif
355
356#ifndef WIN16
357int PEM_read(FILE *fp, char **name, char **header,
358 unsigned char **data,long *len);
359int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
360char * PEM_ASN1_read(char *(*d2i)(),char *name,FILE *fp,char **x,
361 int (*cb)());
362int PEM_ASN1_write(int (*i2d)(),char *name,FILE *fp,char *x,
363 EVP_CIPHER *enc,unsigned char *kstr,int klen,int (*callback)());
364STACK * PEM_X509_INFO_read(FILE *fp, STACK *sk, int (*cb)());
365#endif
366
367int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type,
368 EVP_MD *md_type, unsigned char **ek, int *ekl,
369 unsigned char *iv, EVP_PKEY **pubk, int npubk);
370void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
371 unsigned char *in, int inl);
372int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig,int *sigl,
373 unsigned char *out, int *outl, EVP_PKEY *priv);
374
375void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type);
376void PEM_SignUpdate(EVP_MD_CTX *ctx,unsigned char *d,unsigned int cnt);
377int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
378 unsigned int *siglen, EVP_PKEY *pkey);
379
380void ERR_load_PEM_strings(void);
381
382void PEM_proc_type(char *buf, int type);
383void PEM_dek_info(char *buf, char *type, int len, char *str);
384
385#ifndef SSLEAY_MACROS
386
387#ifndef WIN16
388X509 *PEM_read_X509(FILE *fp,X509 **x,int (*cb)());
389X509_REQ *PEM_read_X509_REQ(FILE *fp,X509_REQ **x,int (*cb)());
390X509_CRL *PEM_read_X509_CRL(FILE *fp,X509_CRL **x,int (*cb)());
391RSA *PEM_read_RSAPrivateKey(FILE *fp,RSA **x,int (*cb)());
392RSA *PEM_read_RSAPublicKey(FILE *fp,RSA **x,int (*cb)());
393DSA *PEM_read_DSAPrivateKey(FILE *fp,DSA **x,int (*cb)());
394EVP_PKEY *PEM_read_PrivateKey(FILE *fp,EVP_PKEY **x,int (*cb)());
395PKCS7 *PEM_read_PKCS7(FILE *fp,PKCS7 **x,int (*cb)());
396DH *PEM_read_DHparams(FILE *fp,DH **x,int (*cb)());
397DSA *PEM_read_DSAparams(FILE *fp,DSA **x,int (*cb)());
398int PEM_write_X509(FILE *fp,X509 *x);
399int PEM_write_X509_REQ(FILE *fp,X509_REQ *x);
400int PEM_write_X509_CRL(FILE *fp,X509_CRL *x);
401int PEM_write_RSAPrivateKey(FILE *fp,RSA *x,EVP_CIPHER *enc,unsigned char *kstr,
402 int klen,int (*cb)());
403int PEM_write_RSAPublicKey(FILE *fp,RSA *x);
404int PEM_write_DSAPrivateKey(FILE *fp,DSA *x,EVP_CIPHER *enc,unsigned char *kstr,
405 int klen,int (*cb)());
406int PEM_write_PrivateKey(FILE *fp,EVP_PKEY *x,EVP_CIPHER *enc,
407 unsigned char *kstr,int klen,int (*cb)());
408int PEM_write_PKCS7(FILE *fp,PKCS7 *x);
409int PEM_write_DHparams(FILE *fp,DH *x);
410int PEM_write_DSAparams(FILE *fp,DSA *x);
411#endif
412
413#ifdef HEADER_BIO_H
414X509 *PEM_read_bio_X509(BIO *bp,X509 **x,int (*cb)());
415X509_REQ *PEM_read_bio_X509_REQ(BIO *bp,X509_REQ **x,int (*cb)());
416X509_CRL *PEM_read_bio_X509_CRL(BIO *bp,X509_CRL **x,int (*cb)());
417RSA *PEM_read_bio_RSAPrivateKey(BIO *bp,RSA **x,int (*cb)());
418RSA *PEM_read_bio_RSAPublicKey(BIO *bp,RSA **x,int (*cb)());
419DSA *PEM_read_bio_DSAPrivateKey(BIO *bp,DSA **x,int (*cb)());
420EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp,EVP_PKEY **x,int (*cb)());
421PKCS7 *PEM_read_bio_PKCS7(BIO *bp,PKCS7 **x,int (*cb)());
422DH *PEM_read_bio_DHparams(BIO *bp,DH **x,int (*cb)());
423DSA *PEM_read_bio_DSAparams(BIO *bp,DSA **x,int (*cb)());
424int PEM_write_bio_X509(BIO *bp,X509 *x);
425int PEM_write_bio_X509_REQ(BIO *bp,X509_REQ *x);
426int PEM_write_bio_X509_CRL(BIO *bp,X509_CRL *x);
427int PEM_write_bio_RSAPrivateKey(BIO *fp,RSA *x,EVP_CIPHER *enc,
428 unsigned char *kstr,int klen,int (*cb)());
429int PEM_write_bio_RSAPublicKey(BIO *fp,RSA *x);
430int PEM_write_bio_DSAPrivateKey(BIO *fp,DSA *x,EVP_CIPHER *enc,
431 unsigned char *kstr,int klen,int (*cb)());
432int PEM_write_bio_PrivateKey(BIO *fp,EVP_PKEY *x,EVP_CIPHER *enc,
433 unsigned char *kstr,int klen,int (*cb)());
434int PEM_write_bio_PKCS7(BIO *bp,PKCS7 *x);
435int PEM_write_bio_DHparams(BIO *bp,DH *x);
436int PEM_write_bio_DSAparams(BIO *bp,DSA *x);
437#endif
438
439#endif /* SSLEAY_MACROS */
440
441
442#else
443
444int PEM_get_EVP_CIPHER_INFO();
445int PEM_do_header();
446int PEM_read_bio();
447int PEM_write_bio();
448#ifndef WIN16
449int PEM_read();
450int PEM_write();
451STACK * PEM_X509_INFO_read();
452char * PEM_ASN1_read();
453int PEM_ASN1_write();
454#endif
455STACK * PEM_X509_INFO_read_bio();
456int PEM_X509_INFO_write_bio();
457char * PEM_ASN1_read_bio();
458int PEM_ASN1_write_bio();
459int PEM_SealInit();
460void PEM_SealUpdate();
461int PEM_SealFinal();
462int PEM_SignFinal();
463
464void ERR_load_PEM_strings();
465
466void PEM_proc_type();
467void PEM_dek_info();
468
469#ifndef SSLEAY_MACROS
470#ifndef WIN16
471X509 *PEM_read_X509();
472X509_REQ *PEM_read_X509_REQ();
473X509_CRL *PEM_read_X509_CRL();
474RSA *PEM_read_RSAPrivateKey();
475RSA *PEM_read_RSAPublicKey();
476DSA *PEM_read_DSAPrivateKey();
477EVP_PKEY *PEM_read_PrivateKey();
478PKCS7 *PEM_read_PKCS7();
479DH *PEM_read_DHparams();
480DSA *PEM_read_DSAparams();
481int PEM_write_X509();
482int PEM_write_X509_REQ();
483int PEM_write_X509_CRL();
484int PEM_write_RSAPrivateKey();
485int PEM_write_RSAPublicKey();
486int PEM_write_DSAPrivateKey();
487int PEM_write_PrivateKey();
488int PEM_write_PKCS7();
489int PEM_write_DHparams();
490int PEM_write_DSAparams();
491#endif
492
493X509 *PEM_read_bio_X509();
494X509_REQ *PEM_read_bio_X509_REQ();
495X509_CRL *PEM_read_bio_X509_CRL();
496RSA *PEM_read_bio_RSAPrivateKey();
497RSA *PEM_read_bio_RSAPublicKey();
498DSA *PEM_read_bio_DSAPrivateKey();
499EVP_PKEY *PEM_read_bio_PrivateKey();
500PKCS7 *PEM_read_bio_PKCS7();
501DH *PEM_read_bio_DHparams();
502DSA *PEM_read_bio_DSAparams();
503int PEM_write_bio_X509();
504int PEM_write_bio_X509_REQ();
505int PEM_write_bio_X509_CRL();
506int PEM_write_bio_RSAPrivateKey();
507int PEM_write_bio_RSAPublicKey();
508int PEM_write_bio_DSAPrivateKey();
509int PEM_write_bio_PrivateKey();
510int PEM_write_bio_PKCS7();
511int PEM_write_bio_DHparams();
512int PEM_write_bio_DSAparams();
513
514#endif /* SSLEAY_MACROS */
515
516#endif
517
518/* BEGIN ERROR CODES */
519/* Error codes for the PEM functions. */
520
521/* Function codes. */
522#define PEM_F_DEF_CALLBACK 100
523#define PEM_F_LOAD_IV 101
524#define PEM_F_PEM_ASN1_READ 102
525#define PEM_F_PEM_ASN1_READ_BIO 103
526#define PEM_F_PEM_ASN1_WRITE 104
527#define PEM_F_PEM_ASN1_WRITE_BIO 105
528#define PEM_F_PEM_DO_HEADER 106
529#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
530#define PEM_F_PEM_READ 108
531#define PEM_F_PEM_READ_BIO 109
532#define PEM_F_PEM_SEALFINAL 110
533#define PEM_F_PEM_SEALINIT 111
534#define PEM_F_PEM_SIGNFINAL 112
535#define PEM_F_PEM_WRITE 113
536#define PEM_F_PEM_WRITE_BIO 114
537#define PEM_F_PEM_X509_INFO_READ 115
538#define PEM_F_PEM_X509_INFO_READ_BIO 116
539#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
540
541/* Reason codes. */
542#define PEM_R_BAD_BASE64_DECODE 100
543#define PEM_R_BAD_DECRYPT 101
544#define PEM_R_BAD_END_LINE 102
545#define PEM_R_BAD_IV_CHARS 103
546#define PEM_R_BAD_PASSWORD_READ 104
547#define PEM_R_NOT_DEK_INFO 105
548#define PEM_R_NOT_ENCRYPTED 106
549#define PEM_R_NOT_PROC_TYPE 107
550#define PEM_R_NO_START_LINE 108
551#define PEM_R_PROBLEMS_GETTING_PASSWORD 109
552#define PEM_R_PUBLIC_KEY_NO_RSA 110
553#define PEM_R_READ_KEY 111
554#define PEM_R_SHORT_HEADER 112
555#define PEM_R_UNSUPPORTED_CIPHER 113
556#define PEM_R_UNSUPPORTED_ENCRYPTION 114
557
558#ifdef __cplusplus
559}
560#endif
561#endif
562
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 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * licensing@OpenSSL.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55/*
56 * This header only exists to break a circular dependency between pem and err
57 * Ben 30 Jan 1999.
58 */
59
60void ERR_load_PEM_strings(void);
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
index d1cda7aabe..bc473f3cff 100644
--- a/src/lib/libcrypto/pem/pem_all.c
+++ b/src/lib/libcrypto/pem/pem_all.c
@@ -59,430 +59,55 @@
59#include <stdio.h> 59#include <stdio.h>
60#undef SSLEAY_MACROS 60#undef SSLEAY_MACROS
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bio.h" 62#include <openssl/bio.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pkcs7.h" 65#include <openssl/pkcs7.h>
66#include "pem.h" 66#include <openssl/pem.h>
67 67
68#ifndef NO_FP_API 68IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
69/* The X509 functions */
70X509 *PEM_read_X509(fp,x,cb)
71FILE *fp;
72X509 **x;
73int (*cb)();
74 {
75 return((X509 *)PEM_ASN1_read((char *(*)())d2i_X509,
76 PEM_STRING_X509,fp,(char **)x,cb));
77 }
78#endif
79
80X509 *PEM_read_bio_X509(bp,x,cb)
81BIO *bp;
82X509 **x;
83int (*cb)();
84 {
85 return((X509 *)PEM_ASN1_read_bio((char *(*)())d2i_X509,
86 PEM_STRING_X509,bp,(char **)x,cb));
87 }
88
89#ifndef NO_FP_API
90int PEM_write_X509(fp,x)
91FILE *fp;
92X509 *x;
93 {
94 return(PEM_ASN1_write((int (*)())i2d_X509,PEM_STRING_X509,fp,
95 (char *)x, NULL,NULL,0,NULL));
96 }
97#endif
98 69
99int PEM_write_bio_X509(bp,x) 70IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
100BIO *bp;
101X509 *x;
102 {
103 return(PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp,
104 (char *)x, NULL,NULL,0,NULL));
105 }
106 71
107#ifndef NO_FP_API 72IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
108/* The X509_REQ functions */
109X509_REQ *PEM_read_X509_REQ(fp,x,cb)
110FILE *fp;
111X509_REQ **x;
112int (*cb)();
113 {
114 return((X509_REQ *)PEM_ASN1_read((char *(*)())d2i_X509_REQ,
115 PEM_STRING_X509_REQ,fp,(char **)x,cb));
116 }
117#endif
118 73
119X509_REQ *PEM_read_bio_X509_REQ(bp,x,cb) 74IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
120BIO *bp;
121X509_REQ **x;
122int (*cb)();
123 {
124 return((X509_REQ *)PEM_ASN1_read_bio((char *(*)())d2i_X509_REQ,
125 PEM_STRING_X509_REQ,bp,(char **)x,cb));
126 }
127 75
128#ifndef NO_FP_API 76IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
129int PEM_write_X509_REQ(fp,x) 77 PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
130FILE *fp;
131X509_REQ *x;
132 {
133 return(PEM_ASN1_write((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,fp,
134 (char *)x, NULL,NULL,0,NULL));
135 }
136#endif
137 78
138int PEM_write_bio_X509_REQ(bp,x) 79IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
139BIO *bp; 80IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
140X509_REQ *x; 81 PKCS8_PRIV_KEY_INFO)
141 {
142 return(PEM_ASN1_write_bio((int (*)())i2d_X509_REQ,PEM_STRING_X509_REQ,
143 bp,(char *)x, NULL,NULL,0,NULL));
144 }
145
146#ifndef NO_FP_API
147/* The X509_CRL functions */
148X509_CRL *PEM_read_X509_CRL(fp,x,cb)
149FILE *fp;
150X509_CRL **x;
151int (*cb)();
152 {
153 return((X509_CRL *)PEM_ASN1_read((char *(*)())d2i_X509_CRL,
154 PEM_STRING_X509_CRL,fp,(char **)x,cb));
155 }
156#endif
157
158X509_CRL *PEM_read_bio_X509_CRL(bp,x,cb)
159BIO *bp;
160X509_CRL **x;
161int (*cb)();
162 {
163 return((X509_CRL *)PEM_ASN1_read_bio((char *(*)())d2i_X509_CRL,
164 PEM_STRING_X509_CRL,bp,(char **)x,cb));
165 }
166
167#ifndef NO_FP_API
168int PEM_write_X509_CRL(fp,x)
169FILE *fp;
170X509_CRL *x;
171 {
172 return(PEM_ASN1_write((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,fp,
173 (char *)x, NULL,NULL,0,NULL));
174 }
175#endif
176
177int PEM_write_bio_X509_CRL(bp,x)
178BIO *bp;
179X509_CRL *x;
180 {
181 return(PEM_ASN1_write_bio((int (*)())i2d_X509_CRL,PEM_STRING_X509_CRL,
182 bp,(char *)x, NULL,NULL,0,NULL));
183 }
184 82
185#ifndef NO_RSA 83#ifndef NO_RSA
186#ifndef NO_FP_API
187/* The RSAPrivateKey functions */
188RSA *PEM_read_RSAPrivateKey(fp,x,cb)
189FILE *fp;
190RSA **x;
191int (*cb)();
192 {
193 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPrivateKey,
194 PEM_STRING_RSA,fp,(char **)x,cb));
195 }
196
197RSA *PEM_read_RSAPublicKey(fp,x,cb)
198FILE *fp;
199RSA **x;
200int (*cb)();
201 {
202 return((RSA *)PEM_ASN1_read((char *(*)())d2i_RSAPublicKey,
203 PEM_STRING_RSA_PUBLIC,fp,(char **)x,cb));
204 }
205#endif
206 84
207RSA *PEM_read_bio_RSAPrivateKey(bp,x,cb) 85IMPLEMENT_PEM_rw_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
208BIO *bp;
209RSA **x;
210int (*cb)();
211 {
212 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPrivateKey,
213 PEM_STRING_RSA,bp,(char **)x,cb));
214 }
215 86
216RSA *PEM_read_bio_RSAPublicKey(bp,x,cb) 87IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
217BIO *bp;
218RSA **x;
219int (*cb)();
220 {
221 return((RSA *)PEM_ASN1_read_bio((char *(*)())d2i_RSAPublicKey,
222 PEM_STRING_RSA_PUBLIC,bp,(char **)x,cb));
223 }
224 88
225#ifndef NO_FP_API
226int PEM_write_RSAPrivateKey(fp,x,enc,kstr,klen,cb)
227FILE *fp;
228RSA *x;
229EVP_CIPHER *enc;
230unsigned char *kstr;
231int klen;
232int (*cb)();
233 {
234 return(PEM_ASN1_write((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,fp,
235 (char *)x,enc,kstr,klen,cb));
236 }
237
238int PEM_write_RSAPublicKey(fp,x)
239FILE *fp;
240RSA *x;
241 {
242 return(PEM_ASN1_write((int (*)())i2d_RSAPublicKey,
243 PEM_STRING_RSA_PUBLIC,fp,
244 (char *)x,NULL,NULL,0,NULL));
245 }
246#endif 89#endif
247 90
248int PEM_write_bio_RSAPrivateKey(bp,x,enc,kstr,klen,cb)
249BIO *bp;
250RSA *x;
251EVP_CIPHER *enc;
252unsigned char *kstr;
253int klen;
254int (*cb)();
255 {
256 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPrivateKey,PEM_STRING_RSA,
257 bp,(char *)x,enc,kstr,klen,cb));
258 }
259
260int PEM_write_bio_RSAPublicKey(bp,x)
261BIO *bp;
262RSA *x;
263 {
264 return(PEM_ASN1_write_bio((int (*)())i2d_RSAPublicKey,
265 PEM_STRING_RSA_PUBLIC,
266 bp,(char *)x,NULL,NULL,0,NULL));
267 }
268#endif /* !NO_RSA */
269
270#ifndef NO_DSA 91#ifndef NO_DSA
271#ifndef NO_FP_API
272/* The DSAPrivateKey functions */
273DSA *PEM_read_DSAPrivateKey(fp,x,cb)
274FILE *fp;
275DSA **x;
276int (*cb)();
277 {
278 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAPrivateKey,
279 PEM_STRING_DSA,fp,(char **)x,cb));
280 }
281#endif
282
283DSA *PEM_read_bio_DSAPrivateKey(bp,x,cb)
284BIO *bp;
285DSA **x;
286int (*cb)();
287 {
288 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAPrivateKey,
289 PEM_STRING_DSA,bp,(char **)x,cb));
290 }
291
292#ifndef NO_FP_API
293int PEM_write_DSAPrivateKey(fp,x,enc,kstr,klen,cb)
294FILE *fp;
295DSA *x;
296EVP_CIPHER *enc;
297unsigned char *kstr;
298int klen;
299int (*cb)();
300 {
301 return(PEM_ASN1_write((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,fp,
302 (char *)x,enc,kstr,klen,cb));
303 }
304#endif
305 92
306int PEM_write_bio_DSAPrivateKey(bp,x,enc,kstr,klen,cb) 93IMPLEMENT_PEM_rw_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
307BIO *bp;
308DSA *x;
309EVP_CIPHER *enc;
310unsigned char *kstr;
311int klen;
312int (*cb)();
313 {
314 return(PEM_ASN1_write_bio((int (*)())i2d_DSAPrivateKey,PEM_STRING_DSA,
315 bp,(char *)x,enc,kstr,klen,cb));
316 }
317#endif
318
319#ifndef NO_FP_API
320/* The PrivateKey functions */
321EVP_PKEY *PEM_read_PrivateKey(fp,x,cb)
322FILE *fp;
323EVP_PKEY **x;
324int (*cb)();
325 {
326 return((EVP_PKEY *)PEM_ASN1_read((char *(*)())d2i_PrivateKey,
327 PEM_STRING_EVP_PKEY,fp,(char **)x,cb));
328 }
329#endif
330
331EVP_PKEY *PEM_read_bio_PrivateKey(bp,x,cb)
332BIO *bp;
333EVP_PKEY **x;
334int (*cb)();
335 {
336 return((EVP_PKEY *)PEM_ASN1_read_bio((char *(*)())d2i_PrivateKey,
337 PEM_STRING_EVP_PKEY,bp,(char **)x,cb));
338 }
339
340#ifndef NO_FP_API
341int PEM_write_PrivateKey(fp,x,enc,kstr,klen,cb)
342FILE *fp;
343EVP_PKEY *x;
344EVP_CIPHER *enc;
345unsigned char *kstr;
346int klen;
347int (*cb)();
348 {
349 return(PEM_ASN1_write((int (*)())i2d_PrivateKey,
350 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
351 fp,(char *)x,enc,kstr,klen,cb));
352 }
353#endif
354 94
355int PEM_write_bio_PrivateKey(bp,x,enc,kstr,klen,cb) 95IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
356BIO *bp;
357EVP_PKEY *x;
358EVP_CIPHER *enc;
359unsigned char *kstr;
360int klen;
361int (*cb)();
362 {
363 return(PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
364 ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
365 bp,(char *)x,enc,kstr,klen,cb));
366 }
367 96
368#ifndef NO_FP_API
369/* The PKCS7 functions */
370PKCS7 *PEM_read_PKCS7(fp,x,cb)
371FILE *fp;
372PKCS7 **x;
373int (*cb)();
374 {
375 return((PKCS7 *)PEM_ASN1_read((char *(*)())d2i_PKCS7,
376 PEM_STRING_PKCS7,fp,(char **)x,cb));
377 }
378#endif 97#endif
379 98
380PKCS7 *PEM_read_bio_PKCS7(bp,x,cb)
381BIO *bp;
382PKCS7 **x;
383int (*cb)();
384 {
385 return((PKCS7 *)PEM_ASN1_read_bio((char *(*)())d2i_PKCS7,
386 PEM_STRING_PKCS7,bp,(char **)x,cb));
387 }
388
389#ifndef NO_FP_API
390int PEM_write_PKCS7(fp,x)
391FILE *fp;
392PKCS7 *x;
393 {
394 return(PEM_ASN1_write((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,fp,
395 (char *)x, NULL,NULL,0,NULL));
396 }
397#endif
398
399int PEM_write_bio_PKCS7(bp,x)
400BIO *bp;
401PKCS7 *x;
402 {
403 return(PEM_ASN1_write_bio((int (*)())i2d_PKCS7,PEM_STRING_PKCS7,bp,
404 (char *)x, NULL,NULL,0,NULL));
405 }
406
407#ifndef NO_DH 99#ifndef NO_DH
408#ifndef NO_FP_API
409/* The DHparams functions */
410DH *PEM_read_DHparams(fp,x,cb)
411FILE *fp;
412DH **x;
413int (*cb)();
414 {
415 return((DH *)PEM_ASN1_read((char *(*)())d2i_DHparams,
416 PEM_STRING_DHPARAMS,fp,(char **)x,cb));
417 }
418#endif
419 100
420DH *PEM_read_bio_DHparams(bp,x,cb) 101IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
421BIO *bp;
422DH **x;
423int (*cb)();
424 {
425 return((DH *)PEM_ASN1_read_bio((char *(*)())d2i_DHparams,
426 PEM_STRING_DHPARAMS,bp,(char **)x,cb));
427 }
428 102
429#ifndef NO_FP_API
430int PEM_write_DHparams(fp,x)
431FILE *fp;
432DH *x;
433 {
434 return(PEM_ASN1_write((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,fp,
435 (char *)x, NULL,NULL,0,NULL));
436 }
437#endif 103#endif
438 104
439int PEM_write_bio_DHparams(bp,x)
440BIO *bp;
441DH *x;
442 {
443 return(PEM_ASN1_write_bio((int (*)())i2d_DHparams,PEM_STRING_DHPARAMS,
444 bp,(char *)x, NULL,NULL,0,NULL));
445 }
446#endif
447
448#ifndef NO_DSA
449#ifndef NO_FP_API
450/* The DSAparams functions */
451DSA *PEM_read_DSAparams(fp,x,cb)
452FILE *fp;
453DSA **x;
454int (*cb)();
455 {
456 return((DSA *)PEM_ASN1_read((char *(*)())d2i_DSAparams,
457 PEM_STRING_DSAPARAMS,fp,(char **)x,cb));
458 }
459#endif
460
461DSA *PEM_read_bio_DSAparams(bp,x,cb)
462BIO *bp;
463DSA **x;
464int (*cb)();
465 {
466 return((DSA *)PEM_ASN1_read_bio((char *(*)())d2i_DSAparams,
467 PEM_STRING_DSAPARAMS,bp,(char **)x,cb));
468 }
469
470#ifndef NO_FP_API
471int PEM_write_DSAparams(fp,x)
472FILE *fp;
473DSA *x;
474 {
475 return(PEM_ASN1_write((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,fp,
476 (char *)x, NULL,NULL,0,NULL));
477 }
478#endif
479
480int PEM_write_bio_DSAparams(bp,x)
481BIO *bp;
482DSA *x;
483 {
484 return(PEM_ASN1_write_bio((int (*)())i2d_DSAparams,PEM_STRING_DSAPARAMS,
485 bp,(char *)x, NULL,NULL,0,NULL));
486 }
487#endif
488 105
106/* The PrivateKey case is not that straightforward.
107 * IMPLEMENT_PEM_rw_cb(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
108 * does not work, RSA and DSA keys have specific strings.
109 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
110 * appropriate.)
111 */
112IMPLEMENT_PEM_read(PrivateKey, EVP_PKEY, PEM_STRING_EVP_PKEY, PrivateKey)
113IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
index e17fcdb540..fa70f60998 100644
--- a/src/lib/libcrypto/pem/pem_err.c
+++ b/src/lib/libcrypto/pem/pem_err.c
@@ -1,63 +1,65 @@
1/* lib/pem/pem_err.c */ 1/* crypto/pem/pem_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "pem.h" 62#include <openssl/pem.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -70,6 +72,7 @@ static ERR_STRING_DATA PEM_str_functs[]=
70{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"}, 72{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE,0), "PEM_ASN1_write"},
71{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"}, 73{ERR_PACK(0,PEM_F_PEM_ASN1_WRITE_BIO,0), "PEM_ASN1_write_bio"},
72{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"}, 74{ERR_PACK(0,PEM_F_PEM_DO_HEADER,0), "PEM_do_header"},
75{ERR_PACK(0,PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,0), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
73{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"}, 76{ERR_PACK(0,PEM_F_PEM_GET_EVP_CIPHER_INFO,0), "PEM_get_EVP_CIPHER_INFO"},
74{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"}, 77{ERR_PACK(0,PEM_F_PEM_READ,0), "PEM_read"},
75{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"}, 78{ERR_PACK(0,PEM_F_PEM_READ_BIO,0), "PEM_read_bio"},
@@ -78,10 +81,11 @@ static ERR_STRING_DATA PEM_str_functs[]=
78{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"}, 81{ERR_PACK(0,PEM_F_PEM_SIGNFINAL,0), "PEM_SignFinal"},
79{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"}, 82{ERR_PACK(0,PEM_F_PEM_WRITE,0), "PEM_write"},
80{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"}, 83{ERR_PACK(0,PEM_F_PEM_WRITE_BIO,0), "PEM_write_bio"},
84{ERR_PACK(0,PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,0), "PEM_write_bio_PKCS8PrivateKey"},
81{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"}, 85{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ,0), "PEM_X509_INFO_read"},
82{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"}, 86{ERR_PACK(0,PEM_F_PEM_X509_INFO_READ_BIO,0), "PEM_X509_INFO_read_bio"},
83{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"}, 87{ERR_PACK(0,PEM_F_PEM_X509_INFO_WRITE_BIO,0), "PEM_X509_INFO_write_bio"},
84{0,NULL}, 88{0,NULL}
85 }; 89 };
86 90
87static ERR_STRING_DATA PEM_str_reasons[]= 91static ERR_STRING_DATA PEM_str_reasons[]=
@@ -91,6 +95,7 @@ static ERR_STRING_DATA PEM_str_reasons[]=
91{PEM_R_BAD_END_LINE ,"bad end line"}, 95{PEM_R_BAD_END_LINE ,"bad end line"},
92{PEM_R_BAD_IV_CHARS ,"bad iv chars"}, 96{PEM_R_BAD_IV_CHARS ,"bad iv chars"},
93{PEM_R_BAD_PASSWORD_READ ,"bad password read"}, 97{PEM_R_BAD_PASSWORD_READ ,"bad password read"},
98{PEM_R_ERROR_CONVERTING_PRIVATE_KEY ,"error converting private key"},
94{PEM_R_NOT_DEK_INFO ,"not dek info"}, 99{PEM_R_NOT_DEK_INFO ,"not dek info"},
95{PEM_R_NOT_ENCRYPTED ,"not encrypted"}, 100{PEM_R_NOT_ENCRYPTED ,"not encrypted"},
96{PEM_R_NOT_PROC_TYPE ,"not proc type"}, 101{PEM_R_NOT_PROC_TYPE ,"not proc type"},
@@ -101,17 +106,17 @@ static ERR_STRING_DATA PEM_str_reasons[]=
101{PEM_R_SHORT_HEADER ,"short header"}, 106{PEM_R_SHORT_HEADER ,"short header"},
102{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, 107{PEM_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
103{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"}, 108{PEM_R_UNSUPPORTED_ENCRYPTION ,"unsupported encryption"},
104{0,NULL}, 109{0,NULL}
105 }; 110 };
106 111
107#endif 112#endif
108 113
109void ERR_load_PEM_strings() 114void ERR_load_PEM_strings(void)
110 { 115 {
111 static int init=1; 116 static int init=1;
112 117
113 if (init); 118 if (init)
114 {; 119 {
115 init=0; 120 init=0;
116#ifndef NO_ERR 121#ifndef NO_ERR
117 ERR_load_strings(ERR_LIB_PEM,PEM_str_functs); 122 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pem.h" 65#include <openssl/pem.h>
66 66
67#ifndef NO_FP_API 67#ifndef NO_FP_API
68STACK *PEM_X509_INFO_read(fp,sk,cb) 68STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
69FILE *fp;
70STACK *sk;
71int (*cb)();
72 { 69 {
73 BIO *b; 70 BIO *b;
74 STACK *ret; 71 STACK_OF(X509_INFO) *ret;
75 72
76 if ((b=BIO_new(BIO_s_file())) == NULL) 73 if ((b=BIO_new(BIO_s_file())) == NULL)
77 { 74 {
@@ -79,29 +76,26 @@ int (*cb)();
79 return(0); 76 return(0);
80 } 77 }
81 BIO_set_fp(b,fp,BIO_NOCLOSE); 78 BIO_set_fp(b,fp,BIO_NOCLOSE);
82 ret=PEM_X509_INFO_read_bio(b,sk,cb); 79 ret=PEM_X509_INFO_read_bio(b,sk,cb,u);
83 BIO_free(b); 80 BIO_free(b);
84 return(ret); 81 return(ret);
85 } 82 }
86#endif 83#endif
87 84
88STACK *PEM_X509_INFO_read_bio(bp,sk,cb) 85STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
89BIO *bp;
90STACK *sk;
91int (*cb)();
92 { 86 {
93 X509_INFO *xi=NULL; 87 X509_INFO *xi=NULL;
94 char *name=NULL,*header=NULL,**pp; 88 char *name=NULL,*header=NULL,**pp;
95 unsigned char *data=NULL,*p; 89 unsigned char *data=NULL,*p;
96 long len,error=0; 90 long len,error=0;
97 int ok=0; 91 int ok=0;
98 STACK *ret=NULL; 92 STACK_OF(X509_INFO) *ret=NULL;
99 unsigned int i,raw; 93 unsigned int i,raw;
100 char *(*d2i)(); 94 char *(*d2i)();
101 95
102 if (sk == NULL) 96 if (sk == NULL)
103 { 97 {
104 if ((ret=sk_new_null()) == NULL) 98 if ((ret=sk_X509_INFO_new_null()) == NULL)
105 { 99 {
106 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE); 100 PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE);
107 goto err; 101 goto err;
@@ -132,7 +126,7 @@ start:
132 d2i=(char *(*)())d2i_X509; 126 d2i=(char *(*)())d2i_X509;
133 if (xi->x509 != NULL) 127 if (xi->x509 != NULL)
134 { 128 {
135 if (!sk_push(ret,(char *)xi)) goto err; 129 if (!sk_X509_INFO_push(ret,xi)) goto err;
136 if ((xi=X509_INFO_new()) == NULL) goto err; 130 if ((xi=X509_INFO_new()) == NULL) goto err;
137 goto start; 131 goto start;
138 } 132 }
@@ -143,7 +137,7 @@ start:
143 d2i=(char *(*)())d2i_X509_CRL; 137 d2i=(char *(*)())d2i_X509_CRL;
144 if (xi->crl != NULL) 138 if (xi->crl != NULL)
145 { 139 {
146 if (!sk_push(ret,(char *)xi)) goto err; 140 if (!sk_X509_INFO_push(ret,xi)) goto err;
147 if ((xi=X509_INFO_new()) == NULL) goto err; 141 if ((xi=X509_INFO_new()) == NULL) goto err;
148 goto start; 142 goto start;
149 } 143 }
@@ -156,7 +150,7 @@ start:
156 d2i=(char *(*)())d2i_RSAPrivateKey; 150 d2i=(char *(*)())d2i_RSAPrivateKey;
157 if (xi->x_pkey != NULL) 151 if (xi->x_pkey != NULL)
158 { 152 {
159 if (!sk_push(ret,(char *)xi)) goto err; 153 if (!sk_X509_INFO_push(ret,xi)) goto err;
160 if ((xi=X509_INFO_new()) == NULL) goto err; 154 if ((xi=X509_INFO_new()) == NULL) goto err;
161 goto start; 155 goto start;
162 } 156 }
@@ -180,7 +174,7 @@ start:
180 d2i=(char *(*)())d2i_DSAPrivateKey; 174 d2i=(char *(*)())d2i_DSAPrivateKey;
181 if (xi->x_pkey != NULL) 175 if (xi->x_pkey != NULL)
182 { 176 {
183 if (!sk_push(ret,(char *)xi)) goto err; 177 if (!sk_X509_INFO_push(ret,xi)) goto err;
184 if ((xi=X509_INFO_new()) == NULL) goto err; 178 if ((xi=X509_INFO_new()) == NULL) goto err;
185 goto start; 179 goto start;
186 } 180 }
@@ -211,7 +205,7 @@ start:
211 205
212 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) 206 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
213 goto err; 207 goto err;
214 if (!PEM_do_header(&cipher,data,&len,cb)) 208 if (!PEM_do_header(&cipher,data,&len,cb,u))
215 goto err; 209 goto err;
216 p=data; 210 p=data;
217 if (d2i(pp,&p,len) == NULL) 211 if (d2i(pp,&p,len) == NULL)
@@ -246,7 +240,7 @@ start:
246 if ((xi->x509 != NULL) || (xi->crl != NULL) || 240 if ((xi->x509 != NULL) || (xi->crl != NULL) ||
247 (xi->x_pkey != NULL) || (xi->enc_data != NULL)) 241 (xi->x_pkey != NULL) || (xi->enc_data != NULL))
248 { 242 {
249 if (!sk_push(ret,(char *)xi)) goto err; 243 if (!sk_X509_INFO_push(ret,xi)) goto err;
250 xi=NULL; 244 xi=NULL;
251 } 245 }
252 ok=1; 246 ok=1;
@@ -254,12 +248,12 @@ err:
254 if (xi != NULL) X509_INFO_free(xi); 248 if (xi != NULL) X509_INFO_free(xi);
255 if (!ok) 249 if (!ok)
256 { 250 {
257 for (i=0; ((int)i)<sk_num(ret); i++) 251 for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
258 { 252 {
259 xi=(X509_INFO *)sk_value(ret,i); 253 xi=sk_X509_INFO_value(ret,i);
260 X509_INFO_free(xi); 254 X509_INFO_free(xi);
261 } 255 }
262 if (ret != sk) sk_free(ret); 256 if (ret != sk) sk_X509_INFO_free(ret);
263 ret=NULL; 257 ret=NULL;
264 } 258 }
265 259
@@ -271,19 +265,13 @@ err:
271 265
272 266
273/* A TJH addition */ 267/* A TJH addition */
274int PEM_X509_INFO_write_bio(bp,xi,enc,kstr,klen,cb) 268int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
275BIO *bp; 269 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
276X509_INFO *xi;
277EVP_CIPHER *enc;
278unsigned char *kstr;
279int klen;
280int (*cb)();
281 { 270 {
282 EVP_CIPHER_CTX ctx; 271 EVP_CIPHER_CTX ctx;
283 int i,ret=0; 272 int i,ret=0;
284 unsigned char *data=NULL; 273 unsigned char *data=NULL;
285 char *objstr=NULL; 274 const char *objstr=NULL;
286#define PEM_BUFSIZE 1024
287 char buf[PEM_BUFSIZE]; 275 char buf[PEM_BUFSIZE];
288 unsigned char *iv=NULL; 276 unsigned char *iv=NULL;
289 277
@@ -340,7 +328,7 @@ int (*cb)();
340 /* normal optionally encrypted stuff */ 328 /* normal optionally encrypted stuff */
341 if (PEM_write_bio_RSAPrivateKey(bp, 329 if (PEM_write_bio_RSAPrivateKey(bp,
342 xi->x_pkey->dec_pkey->pkey.rsa, 330 xi->x_pkey->dec_pkey->pkey.rsa,
343 enc,kstr,klen,cb)<=0) 331 enc,kstr,klen,cb,u)<=0)
344 goto err; 332 goto err;
345#endif 333#endif
346 } 334 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "rand.h" 64#include <openssl/rand.h>
65#include "x509.h" 65#include <openssl/x509.h>
66#include "pem.h" 66#include <openssl/pem.h>
67#include <openssl/pkcs12.h>
67#ifndef NO_DES 68#ifndef NO_DES
68#include "des.h" 69#include <openssl/des.h>
69#endif 70#endif
70 71
71char *PEM_version="PEM part of SSLeay 0.9.0b 29-Jun-1998"; 72const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT;
72 73
73#define MIN_LENGTH 4 74#define MIN_LENGTH 4
74 75
75/* PEMerr(PEM_F_PEM_WRITE_BIO,ERR_R_MALLOC_FAILURE); 76static int def_callback(char *buf, int num, int w, void *userdata);
76 * PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
77 */
78
79#ifndef NOPROTO
80static int def_callback(char *buf, int num, int w);
81static int load_iv(unsigned char **fromp,unsigned char *to, int num); 77static int load_iv(unsigned char **fromp,unsigned char *to, int num);
82#else
83static int def_callback();
84static int load_iv();
85#endif
86 78
87static int def_callback(buf, num, w) 79static int def_callback(char *buf, int num, int w, void *userdata)
88char *buf;
89int num;
90int w;
91 { 80 {
92#ifdef NO_FP_API 81#ifdef NO_FP_API
93 /* We should not ever call the default callback routine from 82 /* We should not ever call the default callback routine from
@@ -96,7 +85,7 @@ int w;
96 return(-1); 85 return(-1);
97#else 86#else
98 int i,j; 87 int i,j;
99 char *prompt; 88 const char *prompt;
100 89
101 prompt=EVP_get_pw_prompt(); 90 prompt=EVP_get_pw_prompt();
102 if (prompt == NULL) 91 if (prompt == NULL)
@@ -123,11 +112,9 @@ int w;
123#endif 112#endif
124 } 113 }
125 114
126void PEM_proc_type(buf, type) 115void PEM_proc_type(char *buf, int type)
127char *buf;
128int type;
129 { 116 {
130 char *str; 117 const char *str;
131 118
132 if (type == PEM_TYPE_ENCRYPTED) 119 if (type == PEM_TYPE_ENCRYPTED)
133 str="ENCRYPTED"; 120 str="ENCRYPTED";
@@ -143,11 +130,7 @@ int type;
143 strcat(buf,"\n"); 130 strcat(buf,"\n");
144 } 131 }
145 132
146void PEM_dek_info(buf, type, len, str) 133void PEM_dek_info(char *buf, const char *type, int len, char *str)
147char *buf;
148char *type;
149int len;
150char *str;
151 { 134 {
152 static unsigned char map[17]="0123456789ABCDEF"; 135 static unsigned char map[17]="0123456789ABCDEF";
153 long i; 136 long i;
@@ -167,12 +150,8 @@ char *str;
167 } 150 }
168 151
169#ifndef NO_FP_API 152#ifndef NO_FP_API
170char *PEM_ASN1_read(d2i,name,fp, x, cb) 153char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
171char *(*d2i)(); 154 pem_password_cb *cb, void *u)
172char *name;
173FILE *fp;
174char **x;
175int (*cb)();
176 { 155 {
177 BIO *b; 156 BIO *b;
178 char *ret; 157 char *ret;
@@ -183,18 +162,14 @@ int (*cb)();
183 return(0); 162 return(0);
184 } 163 }
185 BIO_set_fp(b,fp,BIO_NOCLOSE); 164 BIO_set_fp(b,fp,BIO_NOCLOSE);
186 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb); 165 ret=PEM_ASN1_read_bio(d2i,name,b,x,cb,u);
187 BIO_free(b); 166 BIO_free(b);
188 return(ret); 167 return(ret);
189 } 168 }
190#endif 169#endif
191 170
192char *PEM_ASN1_read_bio(d2i,name,bp, x, cb) 171char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
193char *(*d2i)(); 172 pem_password_cb *cb, void *u)
194char *name;
195BIO *bp;
196char **x;
197int (*cb)();
198 { 173 {
199 EVP_CIPHER_INFO cipher; 174 EVP_CIPHER_INFO cipher;
200 char *nm=NULL,*header=NULL; 175 char *nm=NULL,*header=NULL;
@@ -210,10 +185,14 @@ int (*cb)();
210 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || 185 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
211 ((strcmp(nm,PEM_STRING_DSA) == 0) && 186 ((strcmp(nm,PEM_STRING_DSA) == 0) &&
212 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) || 187 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
188 ((strcmp(nm,PEM_STRING_PKCS8) == 0) &&
189 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
190 ((strcmp(nm,PEM_STRING_PKCS8INF) == 0) &&
191 (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||
213 ((strcmp(nm,PEM_STRING_X509_OLD) == 0) && 192 ((strcmp(nm,PEM_STRING_X509_OLD) == 0) &&
214 (strcmp(name,PEM_STRING_X509) == 0)) || 193 (strcmp(name,PEM_STRING_X509) == 0)) ||
215 ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) && 194 ((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) &&
216 (strcmp(name,PEM_STRING_X509_REQ) == 0)) 195 (strcmp(name,PEM_STRING_X509_REQ) == 0))
217 ) 196 )
218 break; 197 break;
219 Free(nm); 198 Free(nm);
@@ -221,17 +200,41 @@ int (*cb)();
221 Free(data); 200 Free(data);
222 } 201 }
223 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; 202 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
224 if (!PEM_do_header(&cipher,data,&len,cb)) goto err; 203 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
225 p=data; 204 p=data;
226 if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) 205 if (strcmp(name,PEM_STRING_EVP_PKEY) == 0) {
227 {
228 if (strcmp(nm,PEM_STRING_RSA) == 0) 206 if (strcmp(nm,PEM_STRING_RSA) == 0)
229 ret=d2i(EVP_PKEY_RSA,x,&p,len); 207 ret=d2i(EVP_PKEY_RSA,x,&p,len);
230 else if (strcmp(nm,PEM_STRING_DSA) == 0) 208 else if (strcmp(nm,PEM_STRING_DSA) == 0)
231 ret=d2i(EVP_PKEY_DSA,x,&p,len); 209 ret=d2i(EVP_PKEY_DSA,x,&p,len);
210 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
211 PKCS8_PRIV_KEY_INFO *p8inf;
212 p8inf=d2i_PKCS8_PRIV_KEY_INFO(
213 (PKCS8_PRIV_KEY_INFO **) x, &p, len);
214 ret = (char *)EVP_PKCS82PKEY(p8inf);
215 PKCS8_PRIV_KEY_INFO_free(p8inf);
216 } else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
217 PKCS8_PRIV_KEY_INFO *p8inf;
218 X509_SIG *p8;
219 int klen;
220 char psbuf[PEM_BUFSIZE];
221 p8 = d2i_X509_SIG((X509_SIG **)x, &p, len);
222 if(!p8) goto p8err;
223 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
224 else klen=def_callback(psbuf,PEM_BUFSIZE,0,u);
225 if (klen <= 0) {
226 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
227 PEM_R_BAD_PASSWORD_READ);
228 goto err;
229 }
230 p8inf = M_PKCS8_decrypt(p8, psbuf, klen);
231 X509_SIG_free(p8);
232 if(!p8inf) goto p8err;
233 ret = (char *)EVP_PKCS82PKEY(p8inf);
234 PKCS8_PRIV_KEY_INFO_free(p8inf);
232 } 235 }
233 else 236 } else ret=d2i(x,&p,len);
234 ret=d2i(x,&p,len); 237p8err:
235 if (ret == NULL) 238 if (ret == NULL)
236 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); 239 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
237err: 240err:
@@ -242,15 +245,9 @@ err:
242 } 245 }
243 246
244#ifndef NO_FP_API 247#ifndef NO_FP_API
245int PEM_ASN1_write(i2d,name,fp, x, enc, kstr, klen, callback) 248int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
246int (*i2d)(); 249 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
247char *name; 250 pem_password_cb *callback, void *u)
248FILE *fp;
249char *x;
250EVP_CIPHER *enc;
251unsigned char *kstr;
252int klen;
253int (*callback)();
254 { 251 {
255 BIO *b; 252 BIO *b;
256 int ret; 253 int ret;
@@ -261,27 +258,20 @@ int (*callback)();
261 return(0); 258 return(0);
262 } 259 }
263 BIO_set_fp(b,fp,BIO_NOCLOSE); 260 BIO_set_fp(b,fp,BIO_NOCLOSE);
264 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback); 261 ret=PEM_ASN1_write_bio(i2d,name,b,x,enc,kstr,klen,callback,u);
265 BIO_free(b); 262 BIO_free(b);
266 return(ret); 263 return(ret);
267 } 264 }
268#endif 265#endif
269 266
270int PEM_ASN1_write_bio(i2d,name,bp, x, enc, kstr, klen, callback) 267int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
271int (*i2d)(); 268 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
272char *name; 269 pem_password_cb *callback, void *u)
273BIO *bp;
274char *x;
275EVP_CIPHER *enc;
276unsigned char *kstr;
277int klen;
278int (*callback)();
279 { 270 {
280 EVP_CIPHER_CTX ctx; 271 EVP_CIPHER_CTX ctx;
281 int dsize=0,i,j,ret=0; 272 int dsize=0,i,j,ret=0;
282 unsigned char *p,*data=NULL; 273 unsigned char *p,*data=NULL;
283 char *objstr=NULL; 274 const char *objstr=NULL;
284#define PEM_BUFSIZE 1024
285 char buf[PEM_BUFSIZE]; 275 char buf[PEM_BUFSIZE];
286 unsigned char key[EVP_MAX_KEY_LENGTH]; 276 unsigned char key[EVP_MAX_KEY_LENGTH];
287 unsigned char iv[EVP_MAX_IV_LENGTH]; 277 unsigned char iv[EVP_MAX_IV_LENGTH];
@@ -317,14 +307,18 @@ int (*callback)();
317 if (kstr == NULL) 307 if (kstr == NULL)
318 { 308 {
319 if (callback == NULL) 309 if (callback == NULL)
320 klen=def_callback(buf,PEM_BUFSIZE,1); 310 klen=def_callback(buf,PEM_BUFSIZE,1,u);
321 else 311 else
322 klen=(*callback)(buf,PEM_BUFSIZE,1); 312 klen=(*callback)(buf,PEM_BUFSIZE,1,u);
323 if (klen <= 0) 313 if (klen <= 0)
324 { 314 {
325 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY); 315 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,PEM_R_READ_KEY);
326 goto err; 316 goto err;
327 } 317 }
318#ifdef CHARSET_EBCDIC
319 /* Convert the pass phrase from EBCDIC */
320 ebcdic2ascii(buf, buf, klen);
321#endif
328 kstr=(unsigned char *)buf; 322 kstr=(unsigned char *)buf;
329 } 323 }
330 RAND_seed(data,i);/* put in the RSA key. */ 324 RAND_seed(data,i);/* put in the RSA key. */
@@ -363,11 +357,8 @@ err:
363 return(ret); 357 return(ret);
364 } 358 }
365 359
366int PEM_do_header(cipher, data, plen, callback) 360int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
367EVP_CIPHER_INFO *cipher; 361 pem_password_cb *callback,void *u)
368unsigned char *data;
369long *plen;
370int (*callback)();
371 { 362 {
372 int i,j,o,klen; 363 int i,j,o,klen;
373 long len; 364 long len;
@@ -379,14 +370,19 @@ int (*callback)();
379 370
380 if (cipher->cipher == NULL) return(1); 371 if (cipher->cipher == NULL) return(1);
381 if (callback == NULL) 372 if (callback == NULL)
382 klen=def_callback(buf,PEM_BUFSIZE,0); 373 klen=def_callback(buf,PEM_BUFSIZE,0,u);
383 else 374 else
384 klen=callback(buf,PEM_BUFSIZE,0); 375 klen=callback(buf,PEM_BUFSIZE,0,u);
385 if (klen <= 0) 376 if (klen <= 0)
386 { 377 {
387 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ); 378 PEMerr(PEM_F_PEM_DO_HEADER,PEM_R_BAD_PASSWORD_READ);
388 return(0); 379 return(0);
389 } 380 }
381#ifdef CHARSET_EBCDIC
382 /* Convert the pass phrase from EBCDIC */
383 ebcdic2ascii(buf, buf, klen);
384#endif
385
390 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), 386 EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]),
391 (unsigned char *)buf,klen,1,key,NULL); 387 (unsigned char *)buf,klen,1,key,NULL);
392 388
@@ -407,12 +403,10 @@ int (*callback)();
407 return(1); 403 return(1);
408 } 404 }
409 405
410int PEM_get_EVP_CIPHER_INFO(header,cipher) 406int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher)
411char *header;
412EVP_CIPHER_INFO *cipher;
413 { 407 {
414 int o; 408 int o;
415 EVP_CIPHER *enc=NULL; 409 const EVP_CIPHER *enc=NULL;
416 char *p,c; 410 char *p,c;
417 411
418 cipher->cipher=NULL; 412 cipher->cipher=NULL;
@@ -438,9 +432,15 @@ EVP_CIPHER_INFO *cipher;
438 for (;;) 432 for (;;)
439 { 433 {
440 c= *header; 434 c= *header;
435#ifndef CHARSET_EBCDIC
441 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') || 436 if (!( ((c >= 'A') && (c <= 'Z')) || (c == '-') ||
442 ((c >= '0') && (c <= '9')))) 437 ((c >= '0') && (c <= '9'))))
443 break; 438 break;
439#else
440 if (!( isupper(c) || (c == '-') ||
441 isdigit(c)))
442 break;
443#endif
444 header++; 444 header++;
445 } 445 }
446 *header='\0'; 446 *header='\0';
@@ -459,9 +459,7 @@ EVP_CIPHER_INFO *cipher;
459 return(1); 459 return(1);
460 } 460 }
461 461
462static int load_iv(fromp,to,num) 462static int load_iv(unsigned char **fromp, unsigned char *to, int num)
463unsigned char **fromp,*to;
464int num;
465 { 463 {
466 int v,i; 464 int v,i;
467 unsigned char *from; 465 unsigned char *from;
@@ -491,12 +489,8 @@ int num;
491 } 489 }
492 490
493#ifndef NO_FP_API 491#ifndef NO_FP_API
494int PEM_write(fp, name, header, data,len) 492int PEM_write(FILE *fp, char *name, char *header, unsigned char *data,
495FILE *fp; 493 long len)
496char *name;
497char *header;
498unsigned char *data;
499long len;
500 { 494 {
501 BIO *b; 495 BIO *b;
502 int ret; 496 int ret;
@@ -513,12 +507,8 @@ long len;
513 } 507 }
514#endif 508#endif
515 509
516int PEM_write_bio(bp, name, header, data,len) 510int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
517BIO *bp; 511 long len)
518char *name;
519char *header;
520unsigned char *data;
521long len;
522 { 512 {
523 int nlen,n,i,j,outl; 513 int nlen,n,i,j,outl;
524 unsigned char *buf; 514 unsigned char *buf;
@@ -573,12 +563,8 @@ err:
573 } 563 }
574 564
575#ifndef NO_FP_API 565#ifndef NO_FP_API
576int PEM_read(fp, name, header, data,len) 566int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,
577FILE *fp; 567 long *len)
578char **name;
579char **header;
580unsigned char **data;
581long *len;
582 { 568 {
583 BIO *b; 569 BIO *b;
584 int ret; 570 int ret;
@@ -595,12 +581,8 @@ long *len;
595 } 581 }
596#endif 582#endif
597 583
598int PEM_read_bio(bp, name, header, data, len) 584int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
599BIO *bp; 585 long *len)
600char **name;
601char **header;
602unsigned char **data;
603long *len;
604 { 586 {
605 EVP_ENCODE_CTX ctx; 587 EVP_ENCODE_CTX ctx;
606 int end=0,i,k,bl=0,hl=0,nohead=0; 588 int end=0,i,k,bl=0,hl=0,nohead=0;
@@ -643,7 +625,7 @@ long *len;
643 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); 625 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
644 goto err; 626 goto err;
645 } 627 }
646 strncpy(nameB->data,&(buf[11]),(unsigned int)i-6); 628 memcpy(nameB->data,&(buf[11]),i-6);
647 nameB->data[i-6]='\0'; 629 nameB->data[i-6]='\0';
648 break; 630 break;
649 } 631 }
@@ -668,7 +650,7 @@ long *len;
668 nohead=1; 650 nohead=1;
669 break; 651 break;
670 } 652 }
671 strncpy(&(headerB->data[hl]),buf,(unsigned int)i); 653 memcpy(&(headerB->data[hl]),buf,i);
672 headerB->data[hl+i]='\0'; 654 headerB->data[hl+i]='\0';
673 hl+=i; 655 hl+=i;
674 } 656 }
@@ -696,7 +678,7 @@ long *len;
696 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); 678 PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);
697 goto err; 679 goto err;
698 } 680 }
699 strncpy(&(dataB->data[bl]),buf,(unsigned int)i); 681 memcpy(&(dataB->data[bl]),buf,i);
700 dataB->data[bl+i]='\0'; 682 dataB->data[bl+i]='\0';
701 bl+=i; 683 bl+=i;
702 if (end) 684 if (end)
@@ -721,7 +703,7 @@ long *len;
721 } 703 }
722 i=strlen(nameB->data); 704 i=strlen(nameB->data);
723 if ( (strncmp(buf,"-----END ",9) != 0) || 705 if ( (strncmp(buf,"-----END ",9) != 0) ||
724 (strncmp(nameB->data,&(buf[9]),(unsigned int)i) != 0) || 706 (strncmp(nameB->data,&(buf[9]),i) != 0) ||
725 (strncmp(&(buf[9+i]),"-----\n",6) != 0)) 707 (strncmp(&(buf[9+i]),"-----\n",6) != 0))
726 { 708 {
727 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE); 709 PEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);
@@ -760,3 +742,62 @@ err:
760 BUF_MEM_free(dataB); 742 BUF_MEM_free(dataB);
761 return(0); 743 return(0);
762 } 744 }
745
746/* This function writes a private key in PKCS#8 format: it is a "drop in"
747 * replacement for PEM_write_bio_PrivateKey(). As usual if 'enc' is NULL then
748 * it uses the unencrypted private key form. It uses PKCS#5 v2.0 password based
749 * encryption algorithms.
750 */
751
752int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
753 char *kstr, int klen,
754 pem_password_cb *cb, void *u)
755{
756 X509_SIG *p8;
757 PKCS8_PRIV_KEY_INFO *p8inf;
758 char buf[PEM_BUFSIZE];
759 int ret;
760 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
761 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
762 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
763 return 0;
764 }
765 if(enc) {
766 if(!kstr) {
767 if(!cb) klen = def_callback(buf, PEM_BUFSIZE, 1, u);
768 else klen = cb(buf, PEM_BUFSIZE, 1, u);
769 if(klen <= 0) {
770 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
771 PEM_R_READ_KEY);
772 PKCS8_PRIV_KEY_INFO_free(p8inf);
773 return 0;
774 }
775
776 kstr = buf;
777 }
778 p8 = PKCS8_encrypt(-1, enc, kstr, klen, NULL, 0, 0, p8inf);
779 if(kstr == buf) memset(buf, 0, klen);
780 PKCS8_PRIV_KEY_INFO_free(p8inf);
781 ret = PEM_write_bio_PKCS8(bp, p8);
782 X509_SIG_free(p8);
783 return ret;
784 } else {
785 ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
786 PKCS8_PRIV_KEY_INFO_free(p8inf);
787 return ret;
788 }
789}
790
791int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
792 char *kstr, int klen, pem_password_cb *cb, void *u)
793{
794 BIO *bp;
795 int ret;
796 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
797 PEMerr(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY,ERR_R_BUF_LIB);
798 return(0);
799 }
800 ret = PEM_write_bio_PKCS8PrivateKey(bp, x, enc, kstr, klen, cb, u);
801 BIO_free(bp);
802 return ret;
803}
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index b4b36df453..23f95beb1e 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -56,23 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#include "evp.h" 62#include <openssl/evp.h>
62#include "rand.h" 63#include <openssl/rand.h>
63#include "objects.h" 64#include <openssl/objects.h>
64#include "x509.h" 65#include <openssl/x509.h>
65#include "pem.h" 66#include <openssl/pem.h>
66 67
67int PEM_SealInit(ctx,type,md_type,ek,ekl,iv,pubk,npubk) 68int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
68PEM_ENCODE_SEAL_CTX *ctx; 69 unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk,
69EVP_CIPHER *type; 70 int npubk)
70EVP_MD *md_type;
71unsigned char **ek;
72int *ekl;
73unsigned char *iv;
74EVP_PKEY **pubk;
75int npubk;
76 { 71 {
77 unsigned char key[EVP_MAX_KEY_LENGTH]; 72 unsigned char key[EVP_MAX_KEY_LENGTH];
78 int ret= -1; 73 int ret= -1;
@@ -118,12 +113,8 @@ err:
118 return(ret); 113 return(ret);
119 } 114 }
120 115
121void PEM_SealUpdate(ctx,out,outl,in,inl) 116void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
122PEM_ENCODE_SEAL_CTX *ctx; 117 unsigned char *in, int inl)
123unsigned char *out;
124int *outl;
125unsigned char *in;
126int inl;
127 { 118 {
128 unsigned char buffer[1600]; 119 unsigned char buffer[1600];
129 int i,j; 120 int i,j;
@@ -146,13 +137,8 @@ int inl;
146 } 137 }
147 } 138 }
148 139
149int PEM_SealFinal(ctx,sig,sigl,out,outl,priv) 140int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
150PEM_ENCODE_SEAL_CTX *ctx; 141 unsigned char *out, int *outl, EVP_PKEY *priv)
151unsigned char *sig;
152int *sigl;
153unsigned char *out;
154int *outl;
155EVP_PKEY *priv;
156 { 142 {
157 unsigned char *s=NULL; 143 unsigned char *s=NULL;
158 int ret=0,j; 144 int ret=0,j;
@@ -189,3 +175,4 @@ err:
189 if (s != NULL) Free(s); 175 if (s != NULL) Free(s);
190 return(ret); 176 return(ret);
191 } 177 }
178#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "rand.h" 61#include <openssl/rand.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pem.h" 65#include <openssl/pem.h>
66 66
67void PEM_SignInit(ctx,type) 67void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
68EVP_MD_CTX *ctx;
69EVP_MD *type;
70 { 68 {
71 EVP_DigestInit(ctx,type); 69 EVP_DigestInit(ctx,type);
72 } 70 }
73 71
74void PEM_SignUpdate(ctx,data,count) 72void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
75EVP_MD_CTX *ctx; 73 unsigned int count)
76unsigned char *data;
77unsigned int count;
78 { 74 {
79 EVP_DigestUpdate(ctx,data,count); 75 EVP_DigestUpdate(ctx,data,count);
80 } 76 }
81 77
82int PEM_SignFinal(ctx,sigret,siglen,pkey) 78int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
83EVP_MD_CTX *ctx; 79 EVP_PKEY *pkey)
84unsigned char *sigret;
85unsigned int *siglen;
86EVP_PKEY *pkey;
87 { 80 {
88 unsigned char *m; 81 unsigned char *m;
89 int i,ret=0; 82 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 @@
1#!/usr/local/bin/perl
2
3package alpha;
4use Carp qw(croak cluck);
5
6$label="100";
7
8$n_debug=0;
9$smear_regs=1;
10$reg_alloc=1;
11
12$align="3";
13$com_start="#";
14
15sub main'asm_init_output { @out=(); }
16sub main'asm_get_output { return(@out); }
17sub main'get_labels { return(@labels); }
18sub main'external_label { push(@labels,@_); }
19
20# General registers
21
22%regs=( 'r0', '$0',
23 'r1', '$1',
24 'r2', '$2',
25 'r3', '$3',
26 'r4', '$4',
27 'r5', '$5',
28 'r6', '$6',
29 'r7', '$7',
30 'r8', '$8',
31 'r9', '$22',
32 'r10', '$23',
33 'r11', '$24',
34 'r12', '$25',
35 'r13', '$27',
36 'r14', '$28',
37 'r15', '$21', # argc == 5
38 'r16', '$20', # argc == 4
39 'r17', '$19', # argc == 3
40 'r18', '$18', # argc == 2
41 'r19', '$17', # argc == 1
42 'r20', '$16', # argc == 0
43 'r21', '$9', # save 0
44 'r22', '$10', # save 1
45 'r23', '$11', # save 2
46 'r24', '$12', # save 3
47 'r25', '$13', # save 4
48 'r26', '$14', # save 5
49
50 'a0', '$16',
51 'a1', '$17',
52 'a2', '$18',
53 'a3', '$19',
54 'a4', '$20',
55 'a5', '$21',
56
57 's0', '$9',
58 's1', '$10',
59 's2', '$11',
60 's3', '$12',
61 's4', '$13',
62 's5', '$14',
63 'zero', '$31',
64 'sp', '$30',
65 );
66
67$main'reg_s0="r21";
68$main'reg_s1="r22";
69$main'reg_s2="r23";
70$main'reg_s3="r24";
71$main'reg_s4="r25";
72$main'reg_s5="r26";
73
74@reg=( '$0', '$1' ,'$2' ,'$3' ,'$4' ,'$5' ,'$6' ,'$7' ,'$8',
75 '$22','$23','$24','$25','$20','$21','$27','$28');
76
77
78sub main'sub { &out3("subq",@_); }
79sub main'add { &out3("addq",@_); }
80sub main'mov { &out3("bis",$_[0],$_[0],$_[1]); }
81sub main'or { &out3("bis",@_); }
82sub main'bis { &out3("bis",@_); }
83sub main'br { &out1("br",@_); }
84sub main'ld { &out2("ldq",@_); }
85sub main'st { &out2("stq",@_); }
86sub main'cmpult { &out3("cmpult",@_); }
87sub main'cmplt { &out3("cmplt",@_); }
88sub main'bgt { &out2("bgt",@_); }
89sub main'ble { &out2("ble",@_); }
90sub main'blt { &out2("blt",@_); }
91sub main'mul { &out3("mulq",@_); }
92sub main'muh { &out3("umulh",@_); }
93
94$main'QWS=8;
95
96sub main'asm_add
97 {
98 push(@out,@_);
99 }
100
101sub main'asm_finish
102 {
103 &main'file_end();
104 print &main'asm_get_output();
105 }
106
107sub main'asm_init
108 {
109 ($type,$fn)=@_;
110 $filename=$fn;
111
112 &main'asm_init_output();
113 &main'comment("Don't even think of reading this code");
114 &main'comment("It was automatically generated by $filename");
115 &main'comment("Which is a perl program used to generate the alpha assember.");
116 &main'comment("eric <eay\@cryptsoft.com>");
117 &main'comment("");
118
119 $filename =~ s/\.pl$//;
120 &main'file($filename);
121 }
122
123sub conv
124 {
125 local($r)=@_;
126 local($v);
127
128 return($regs{$r}) if defined($regs{$r});
129 return($r);
130 }
131
132sub main'QWPw
133 {
134 local($off,$reg)=@_;
135
136 return(&main'QWP($off*8,$reg));
137 }
138
139sub main'QWP
140 {
141 local($off,$reg)=@_;
142
143 $ret="$off(".&conv($reg).")";
144 return($ret);
145 }
146
147sub out3
148 {
149 local($name,$p1,$p2,$p3)=@_;
150
151 $p1=&conv($p1);
152 $p2=&conv($p2);
153 $p3=&conv($p3);
154 push(@out,"\t$name\t");
155 $l=length($p1)+1;
156 push(@out,$p1.",");
157 $ll=3-($l+9)/8;
158 $tmp1=sprintf("\t" x $ll);
159 push(@out,$tmp1);
160
161 $l=length($p2)+1;
162 push(@out,$p2.",");
163 $ll=3-($l+9)/8;
164 $tmp1=sprintf("\t" x $ll);
165 push(@out,$tmp1);
166
167 push(@out,&conv($p3)."\n");
168 }
169
170sub out2
171 {
172 local($name,$p1,$p2,$p3)=@_;
173
174 $p1=&conv($p1);
175 $p2=&conv($p2);
176 push(@out,"\t$name\t");
177 $l=length($p1)+1;
178 push(@out,$p1.",");
179 $ll=3-($l+9)/8;
180 $tmp1=sprintf("\t" x $ll);
181 push(@out,$tmp1);
182
183 push(@out,&conv($p2)."\n");
184 }
185
186sub out1
187 {
188 local($name,$p1)=@_;
189
190 $p1=&conv($p1);
191 push(@out,"\t$name\t".$p1."\n");
192 }
193
194sub out0
195 {
196 push(@out,"\t$_[0]\n");
197 }
198
199sub main'file
200 {
201 local($file)=@_;
202
203 local($tmp)=<<"EOF";
204 # DEC Alpha assember
205 # Generated from perl scripts contains in SSLeay
206 .file 1 "$file.s"
207 .set noat
208EOF
209 push(@out,$tmp);
210 }
211
212sub main'function_begin
213 {
214 local($func)=@_;
215
216print STDERR "$func\n";
217 local($tmp)=<<"EOF";
218 .text
219 .align $align
220 .globl $func
221 .ent $func
222${func}:
223${func}..ng:
224 .frame \$30,0,\$26,0
225 .prologue 0
226EOF
227 push(@out,$tmp);
228 $stack=0;
229 }
230
231sub main'function_end
232 {
233 local($func)=@_;
234
235 local($tmp)=<<"EOF";
236 ret \$31,(\$26),1
237 .end $func
238EOF
239 push(@out,$tmp);
240 $stack=0;
241 %label=();
242 }
243
244sub main'function_end_A
245 {
246 local($func)=@_;
247
248 local($tmp)=<<"EOF";
249 ret \$31,(\$26),1
250EOF
251 push(@out,$tmp);
252 }
253
254sub main'function_end_B
255 {
256 local($func)=@_;
257
258 $func=$under.$func;
259
260 push(@out,"\t.end $func\n");
261 $stack=0;
262 %label=();
263 }
264
265sub main'wparam
266 {
267 local($num)=@_;
268
269 if ($num < 6)
270 {
271 $num=20-$num;
272 return("r$num");
273 }
274 else
275 { return(&main'QWP($stack+$num*8,"sp")); }
276 }
277
278sub main'stack_push
279 {
280 local($num)=@_;
281 $stack+=$num*8;
282 &main'sub("sp",$num*8,"sp");
283 }
284
285sub main'stack_pop
286 {
287 local($num)=@_;
288 $stack-=$num*8;
289 &main'add("sp",$num*8,"sp");
290 }
291
292sub main'swtmp
293 {
294 return(&main'QWP(($_[0])*8,"sp"));
295 }
296
297# Should use swtmp, which is above sp. Linix can trash the stack above esp
298#sub main'wtmp
299# {
300# local($num)=@_;
301#
302# return(&main'QWP(-($num+1)*4,"esp","",0));
303# }
304
305sub main'comment
306 {
307 foreach (@_)
308 {
309 if (/^\s*$/)
310 { push(@out,"\n"); }
311 else
312 { push(@out,"\t$com_start $_ $com_end\n"); }
313 }
314 }
315
316sub main'label
317 {
318 if (!defined($label{$_[0]}))
319 {
320 $label{$_[0]}=$label;
321 $label++;
322 }
323 return('$'.$label{$_[0]});
324 }
325
326sub main'set_label
327 {
328 if (!defined($label{$_[0]}))
329 {
330 $label{$_[0]}=$label;
331 $label++;
332 }
333# push(@out,".align $align\n") if ($_[1] != 0);
334 push(@out,'$'."$label{$_[0]}:\n");
335 }
336
337sub main'file_end
338 {
339 }
340
341sub main'data_word
342 {
343 push(@out,"\t.long $_[0]\n");
344 }
345
346@pool_free=();
347@pool_taken=();
348$curr_num=0;
349$max=0;
350
351sub main'init_pool
352 {
353 local($args)=@_;
354 local($i);
355
356 @pool_free=();
357 for ($i=(14+(6-$args)); $i >= 0; $i--)
358 {
359 push(@pool_free,"r$i");
360 }
361 print STDERR "START :register pool:@pool_free\n";
362 $curr_num=$max=0;
363 }
364
365sub main'fin_pool
366 {
367 printf STDERR "END %2d:register pool:@pool_free\n",$max;
368 }
369
370sub main'GR
371 {
372 local($r)=@_;
373 local($i,@n,$_);
374
375 foreach (@pool_free)
376 {
377 if ($r ne $_)
378 { push(@n,$_); }
379 else
380 {
381 $curr_num++;
382 $max=$curr_num if ($curr_num > $max);
383 }
384 }
385 @pool_free=@n;
386print STDERR "GR:@pool_free\n" if $reg_alloc;
387 return(@_);
388 }
389
390sub main'NR
391 {
392 local($num)=@_;
393 local(@ret);
394
395 $num=1 if $num == 0;
396 ($#pool_free >= ($num-1)) || croak "out of registers: want $num, have @pool_free";
397 while ($num > 0)
398 {
399 push(@ret,pop @pool_free);
400 $curr_num++;
401 $max=$curr_num if ($curr_num > $max);
402 $num--
403 }
404 print STDERR "nr @ret\n" if $n_debug;
405print STDERR "NR:@pool_free\n" if $reg_alloc;
406 return(@ret);
407
408 }
409
410sub main'FR
411 {
412 local(@r)=@_;
413 local(@a,$v,$w);
414
415 print STDERR "fr @r\n" if $n_debug;
416# cluck "fr @r";
417 for $w (@pool_free)
418 {
419 foreach $v (@r)
420 {
421 croak "double register free of $v (@pool_free)" if $w eq $v;
422 }
423 }
424 foreach $v (@r)
425 {
426 croak "bad argument to FR" if ($v !~ /^r\d+$/);
427 if ($smear_regs)
428 { unshift(@pool_free,$v); }
429 else { push(@pool_free,$v); }
430 $curr_num--;
431 }
432print STDERR "FR:@pool_free\n" if $reg_alloc;
433 }
4341;
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) 3# void des_ncbc_encrypt(input, output, length, schedule, ivec, enc)
4# des_cblock (*input); 4# 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# require 'x86asm.pl'; 3# require 'x86asm.pl';
4# &asm_init("cpp","des-586.pl"); 4# &asm_init("cpp","des-586.pl");
@@ -15,7 +15,7 @@ sub main'asm_finish
15 15
16sub main'asm_init 16sub main'asm_init
17 { 17 {
18 ($type,$fn)=@_; 18 ($type,$fn,$i386)=@_;
19 $filename=$fn; 19 $filename=$fn;
20 20
21 $cpp=$sol=$aout=$win32=0; 21 $cpp=$sol=$aout=$win32=0;
@@ -29,6 +29,8 @@ sub main'asm_init
29 { $cpp=1; require "x86unix.pl"; } 29 { $cpp=1; require "x86unix.pl"; }
30 elsif ( ($type eq "win32")) 30 elsif ( ($type eq "win32"))
31 { $win32=1; require "x86ms.pl"; } 31 { $win32=1; require "x86ms.pl"; }
32 elsif ( ($type eq "win32n"))
33 { $win32=1; require "x86nasm.pl"; }
32 else 34 else
33 { 35 {
34 print STDERR <<"EOF"; 36 print STDERR <<"EOF";
@@ -38,6 +40,7 @@ Pick one target type from
38 sol - x86 solaris 40 sol - x86 solaris
39 cpp - format so x86unix.cpp can be used 41 cpp - format so x86unix.cpp can be used
40 win32 - Windows 95/Windows NT 42 win32 - Windows 95/Windows NT
43 win32n - Windows 95/Windows NT NASM format
41EOF 44EOF
42 exit(1); 45 exit(1);
43 } 46 }
@@ -75,7 +78,7 @@ sub asm_finish_cpp
75#define TYPE(a,b) .type a,b 78#define TYPE(a,b) .type a,b
76#define SIZE(a,b) .size a,b 79#define SIZE(a,b) .size a,b
77 80
78#if defined(OUT) || defined(BSDI) 81#if defined(OUT) || (defined(BSDI) && !defined(ELF))
79$tmp 82$tmp
80#endif 83#endif
81 84
@@ -84,7 +87,7 @@ $tmp
84#define ALIGN 4 87#define ALIGN 4
85#endif 88#endif
86 89
87#ifdef BSDI 90#if defined(BSDI) && !defined(ELF)
88#define OK 1 91#define OK 1
89#define ALIGN 4 92#define ALIGN 4
90#undef SIZE 93#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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3package x86ms; 3package x86ms;
4 4
@@ -51,6 +51,16 @@ sub main'DWP
51 &get_mem("DWORD",@_); 51 &get_mem("DWORD",@_);
52 } 52 }
53 53
54sub main'BC
55 {
56 return @_;
57 }
58
59sub main'DWC
60 {
61 return @_;
62 }
63
54sub main'stack_push 64sub main'stack_push
55 { 65 {
56 local($num)=@_; 66 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 @@
1#!/usr/local/bin/perl
2
3package x86nasm;
4
5$label="L000";
6
7%lb=( 'eax', 'al',
8 'ebx', 'bl',
9 'ecx', 'cl',
10 'edx', 'dl',
11 'ax', 'al',
12 'bx', 'bl',
13 'cx', 'cl',
14 'dx', 'dl',
15 );
16
17%hb=( 'eax', 'ah',
18 'ebx', 'bh',
19 'ecx', 'ch',
20 'edx', 'dh',
21 'ax', 'ah',
22 'bx', 'bh',
23 'cx', 'ch',
24 'dx', 'dh',
25 );
26
27sub main'asm_init_output { @out=(); }
28sub main'asm_get_output { return(@out); }
29sub main'get_labels { return(@labels); }
30
31sub main'external_label
32{
33 push(@labels,@_);
34 foreach (@_) {
35 push(@out, "extern\t_$_\n");
36 }
37}
38
39sub main'LB
40 {
41 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
42 return($lb{$_[0]});
43 }
44
45sub main'HB
46 {
47 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
48 return($hb{$_[0]});
49 }
50
51sub main'BP
52 {
53 &get_mem("BYTE",@_);
54 }
55
56sub main'DWP
57 {
58 &get_mem("DWORD",@_);
59 }
60
61sub main'BC
62 {
63 return "BYTE @_";
64 }
65
66sub main'DWC
67 {
68 return "DWORD @_";
69 }
70
71sub main'stack_push
72 {
73 my($num)=@_;
74 $stack+=$num*4;
75 &main'sub("esp",$num*4);
76 }
77
78sub main'stack_pop
79 {
80 my($num)=@_;
81 $stack-=$num*4;
82 &main'add("esp",$num*4);
83 }
84
85sub get_mem
86 {
87 my($size,$addr,$reg1,$reg2,$idx)=@_;
88 my($t,$post);
89 my($ret)="[";
90 $addr =~ s/^\s+//;
91 if ($addr =~ /^(.+)\+(.+)$/)
92 {
93 $reg2=&conv($1);
94 $addr="_$2";
95 }
96 elsif ($addr =~ /^[_a-zA-Z]/)
97 {
98 $addr="_$addr";
99 }
100
101 $reg1="$regs{$reg1}" if defined($regs{$reg1});
102 $reg2="$regs{$reg2}" if defined($regs{$reg2});
103 if (($addr ne "") && ($addr ne 0))
104 {
105 if ($addr !~ /^-/)
106 { $ret.="${addr}+"; }
107 else { $post=$addr; }
108 }
109 if ($reg2 ne "")
110 {
111 $t="";
112 $t="*$idx" if ($idx != 0);
113 $reg1="+".$reg1 if ("$reg1$post" ne "");
114 $ret.="$reg2$t$reg1$post]";
115 }
116 else
117 {
118 $ret.="$reg1$post]"
119 }
120 return($ret);
121 }
122
123sub main'mov { &out2("mov",@_); }
124sub main'movb { &out2("mov",@_); }
125sub main'and { &out2("and",@_); }
126sub main'or { &out2("or",@_); }
127sub main'shl { &out2("shl",@_); }
128sub main'shr { &out2("shr",@_); }
129sub main'xor { &out2("xor",@_); }
130sub main'xorb { &out2("xor",@_); }
131sub main'add { &out2("add",@_); }
132sub main'adc { &out2("adc",@_); }
133sub main'sub { &out2("sub",@_); }
134sub main'rotl { &out2("rol",@_); }
135sub main'rotr { &out2("ror",@_); }
136sub main'exch { &out2("xchg",@_); }
137sub main'cmp { &out2("cmp",@_); }
138sub main'lea { &out2("lea",@_); }
139sub main'mul { &out1("mul",@_); }
140sub main'div { &out1("div",@_); }
141sub main'dec { &out1("dec",@_); }
142sub main'inc { &out1("inc",@_); }
143sub main'jmp { &out1("jmp",@_); }
144sub main'jmp_ptr { &out1p("jmp",@_); }
145
146# This is a bit of a kludge: declare all branches as NEAR.
147sub main'je { &out1("je NEAR",@_); }
148sub main'jle { &out1("jle NEAR",@_); }
149sub main'jz { &out1("jz NEAR",@_); }
150sub main'jge { &out1("jge NEAR",@_); }
151sub main'jl { &out1("jl NEAR",@_); }
152sub main'jb { &out1("jb NEAR",@_); }
153sub main'jc { &out1("jc NEAR",@_); }
154sub main'jnc { &out1("jnc NEAR",@_); }
155sub main'jnz { &out1("jnz NEAR",@_); }
156sub main'jne { &out1("jne NEAR",@_); }
157sub main'jno { &out1("jno NEAR",@_); }
158
159sub main'push { &out1("push",@_); $stack+=4; }
160sub main'pop { &out1("pop",@_); $stack-=4; }
161sub main'bswap { &out1("bswap",@_); &using486(); }
162sub main'not { &out1("not",@_); }
163sub main'call { &out1("call",'_'.$_[0]); }
164sub main'ret { &out0("ret"); }
165sub main'nop { &out0("nop"); }
166
167sub out2
168 {
169 my($name,$p1,$p2)=@_;
170 my($l,$t);
171
172 push(@out,"\t$name\t");
173 $t=&conv($p1).",";
174 $l=length($t);
175 push(@out,$t);
176 $l=4-($l+9)/8;
177 push(@out,"\t" x $l);
178 push(@out,&conv($p2));
179 push(@out,"\n");
180 }
181
182sub out0
183 {
184 my($name)=@_;
185
186 push(@out,"\t$name\n");
187 }
188
189sub out1
190 {
191 my($name,$p1)=@_;
192 my($l,$t);
193 push(@out,"\t$name\t".&conv($p1)."\n");
194 }
195
196sub conv
197 {
198 my($p)=@_;
199 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
200 return $p;
201 }
202
203sub using486
204 {
205 return if $using486;
206 $using486++;
207 grep(s/\.386/\.486/,@out);
208 }
209
210sub main'file
211 {
212 push(@out, "segment .text\n");
213 }
214
215sub main'function_begin
216 {
217 my($func,$extra)=@_;
218
219 push(@labels,$func);
220 my($tmp)=<<"EOF";
221global _$func
222_$func:
223 push ebp
224 push ebx
225 push esi
226 push edi
227EOF
228 push(@out,$tmp);
229 $stack=20;
230 }
231
232sub main'function_begin_B
233 {
234 my($func,$extra)=@_;
235 my($tmp)=<<"EOF";
236global _$func
237_$func:
238EOF
239 push(@out,$tmp);
240 $stack=4;
241 }
242
243sub main'function_end
244 {
245 my($func)=@_;
246
247 my($tmp)=<<"EOF";
248 pop edi
249 pop esi
250 pop ebx
251 pop ebp
252 ret
253EOF
254 push(@out,$tmp);
255 $stack=0;
256 %label=();
257 }
258
259sub main'function_end_B
260 {
261 $stack=0;
262 %label=();
263 }
264
265sub main'function_end_A
266 {
267 my($func)=@_;
268
269 my($tmp)=<<"EOF";
270 pop edi
271 pop esi
272 pop ebx
273 pop ebp
274 ret
275EOF
276 push(@out,$tmp);
277 }
278
279sub main'file_end
280 {
281 }
282
283sub main'wparam
284 {
285 my($num)=@_;
286
287 return(&main'DWP($stack+$num*4,"esp","",0));
288 }
289
290sub main'swtmp
291 {
292 return(&main'DWP($_[0]*4,"esp","",0));
293 }
294
295# Should use swtmp, which is above esp. Linix can trash the stack above esp
296#sub main'wtmp
297# {
298# my($num)=@_;
299#
300# return(&main'DWP(-(($num+1)*4),"esp","",0));
301# }
302
303sub main'comment
304 {
305 foreach (@_)
306 {
307 push(@out,"\t; $_\n");
308 }
309 }
310
311sub main'label
312 {
313 if (!defined($label{$_[0]}))
314 {
315 $label{$_[0]}="\$${label}${_[0]}";
316 $label++;
317 }
318 return($label{$_[0]});
319 }
320
321sub main'set_label
322 {
323 if (!defined($label{$_[0]}))
324 {
325 $label{$_[0]}="${label}${_[0]}";
326 $label++;
327 }
328 push(@out,"$label{$_[0]}:\n");
329 }
330
331sub main'data_word
332 {
333 push(@out,"\tDD\t$_[0]\n");
334 }
335
336sub out1p
337 {
338 my($name,$p1)=@_;
339 my($l,$t);
340
341 push(@out,"\t$name\t ".&conv($p1)."\n");
342 }
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2
3# Because the bswapl instruction is not supported for old assembers
4# (it was a new instruction for the 486), I've added .byte xxxx code
5# to put it in.
6# eric 24-Apr-1998
7#
8 2
9package x86unix; 3package x86unix;
10 4
@@ -90,7 +84,12 @@ sub main'DWP
90 $reg2="$regs{$reg2}" if defined($regs{$reg2}); 84 $reg2="$regs{$reg2}" if defined($regs{$reg2});
91 $ret.=$addr if ($addr ne "") && ($addr ne 0); 85 $ret.=$addr if ($addr ne "") && ($addr ne 0);
92 if ($reg2 ne "") 86 if ($reg2 ne "")
93 { $ret.="($reg1,$reg2,$idx)"; } 87 {
88 if($idx ne "")
89 { $ret.="($reg1,$reg2,$idx)"; }
90 else
91 { $ret.="($reg1,$reg2)"; }
92 }
94 else 93 else
95 { $ret.="($reg1)" } 94 { $ret.="($reg1)" }
96 return($ret); 95 return($ret);
@@ -101,6 +100,16 @@ sub main'BP
101 return(&main'DWP(@_)); 100 return(&main'DWP(@_));
102 } 101 }
103 102
103sub main'BC
104 {
105 return @_;
106 }
107
108sub main'DWC
109 {
110 return @_;
111 }
112
104#sub main'BP 113#sub main'BP
105# { 114# {
106# local($addr,$reg1,$reg2,$idx)=@_; 115# local($addr,$reg1,$reg2,$idx)=@_;
@@ -153,12 +162,27 @@ sub main'dec { &out1("decl",@_); }
153sub main'inc { &out1("incl",@_); } 162sub main'inc { &out1("incl",@_); }
154sub main'push { &out1("pushl",@_); $stack+=4; } 163sub main'push { &out1("pushl",@_); $stack+=4; }
155sub main'pop { &out1("popl",@_); $stack-=4; } 164sub main'pop { &out1("popl",@_); $stack-=4; }
156sub main'bswap { &out1("bswapl",@_); }
157sub main'not { &out1("notl",@_); } 165sub main'not { &out1("notl",@_); }
158sub main'call { &out1("call",$under.$_[0]); } 166sub main'call { &out1("call",$under.$_[0]); }
159sub main'ret { &out0("ret"); } 167sub main'ret { &out0("ret"); }
160sub main'nop { &out0("nop"); } 168sub main'nop { &out0("nop"); }
161 169
170# The bswapl instruction is new for the 486. Emulate if i386.
171sub main'bswap
172 {
173 if ($main'i386)
174 {
175 &main'comment("bswapl @_");
176 &main'exch(main'HB(@_),main'LB(@_));
177 &main'rotr(@_,16);
178 &main'exch(main'HB(@_),main'LB(@_));
179 }
180 else
181 {
182 &out1("bswapl",@_);
183 }
184 }
185
162sub out2 186sub out2
163 { 187 {
164 local($name,$p1,$p2)=@_; 188 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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=pkcs7
19ERRC=pkcs7err
20GENERAL=Makefile README 20GENERAL=Makefile README
21TEST= 21TEST=
22APPS= 22APPS=
@@ -39,26 +39,39 @@ test:
39 39
40all: lib 40all: lib
41 41
42testapps: enc dec sign verify
43
44enc: enc.o lib
45 $(CC) $(CFLAGS) -o enc enc.o $(LIB)
46
47dec: dec.o lib
48 $(CC) $(CFLAGS) -o dec dec.o $(LIB)
49
50sign: sign.o lib
51 $(CC) $(CFLAGS) -o sign sign.o $(LIB)
52
53verify: verify.o example.o lib
54 $(CC) $(CFLAGS) -o verify verify.o example.o $(LIB)
55
42lib: $(LIBOBJ) 56lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ) 57 $(AR) $(LIB) $(LIBOBJ)
44 sh $(TOP)/util/ranlib.sh $(LIB) 58 $(RANLIB) $(LIB)
45 @touch lib 59 @touch lib
46 60
47files: 61files:
48 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 62 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
49 63
50links: 64links:
51 /bin/rm -f Makefile 65 @$(TOP)/util/point.sh Makefile.ssl Makefile
52 $(TOP)/util/point.sh Makefile.ssl Makefile ; 66 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
53 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 67 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
54 $(TOP)/util/mklink.sh ../../test $(TEST) 68 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
55 $(TOP)/util/mklink.sh ../../apps $(APPS)
56 69
57install: 70install:
58 @for i in $(EXHEADER) ; \ 71 @for i in $(EXHEADER) ; \
59 do \ 72 do \
60 (cp $$i $(INSTALLTOP)/include/$$i; \ 73 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
61 chmod 644 $(INSTALLTOP)/include/$$i ); \ 74 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
62 done; 75 done;
63 76
64tags: 77tags:
@@ -70,17 +83,63 @@ lint:
70 lint -DLINT $(INCLUDES) $(SRC)>fluff 83 lint -DLINT $(INCLUDES) $(SRC)>fluff
71 84
72depend: 85depend:
73 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 86 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
74 87
75dclean: 88dclean:
76 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 89 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
77 mv -f Makefile.new $(MAKEFILE) 90 mv -f Makefile.new $(MAKEFILE)
78 91
79clean: 92clean:
80 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 93 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
81
82errors:
83 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
84 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
85 94
86# DO NOT DELETE THIS LINE -- make depend depends on it. 95# DO NOT DELETE THIS LINE -- make depend depends on it.
96
97pk7_doit.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
98pk7_doit.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
99pk7_doit.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
100pk7_doit.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
101pk7_doit.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
102pk7_doit.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
103pk7_doit.o: ../../include/openssl/err.h ../../include/openssl/evp.h
104pk7_doit.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
105pk7_doit.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
106pk7_doit.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
107pk7_doit.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
108pk7_doit.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
109pk7_doit.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
110pk7_doit.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
111pk7_doit.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
112pk7_doit.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
113pk7_doit.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
114pk7_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
115pk7_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
116pk7_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
117pk7_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
118pk7_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
119pk7_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
120pk7_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
121pk7_lib.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
122pk7_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
123pk7_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
124pk7_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
125pk7_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
126pk7_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
127pk7_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
128pk7_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
129pk7_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
130pk7_lib.o: ../cryptlib.h
131pkcs7err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
132pkcs7err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
133pkcs7err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
134pkcs7err.o: ../../include/openssl/des.h ../../include/openssl/dh.h
135pkcs7err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
136pkcs7err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
137pkcs7err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
138pkcs7err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
139pkcs7err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
140pkcs7err.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
141pkcs7err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
142pkcs7err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
143pkcs7err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
144pkcs7err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
145pkcs7err.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 @@
1/* crypto/evp/bio_ber.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int ber_write(BIO *h,char *buf,int num);
66static int ber_read(BIO *h,char *buf,int size);
67/*static int ber_puts(BIO *h,char *str); */
68/*static int ber_gets(BIO *h,char *str,int size); */
69static long ber_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int ber_new(BIO *h);
71static int ber_free(BIO *data);
72#define BER_BUF_SIZE (32)
73
74/* This is used to hold the state of the BER objects being read. */
75typedef struct ber_struct
76 {
77 int tag;
78 int class;
79 long length;
80 int inf;
81 int num_left;
82 int depth;
83 } BER_CTX;
84
85typedef struct bio_ber_struct
86 {
87 int tag;
88 int class;
89 long length;
90 int inf;
91
92 /* most of the following are used when doing non-blocking IO */
93 /* reading */
94 long num_left; /* number of bytes still to read/write in block */
95 int depth; /* used with idefinite encoding. */
96 int finished; /* No more read data */
97
98 /* writting */
99 char *w_addr;
100 int w_offset;
101 int w_left;
102
103 int buf_len;
104 int buf_off;
105 unsigned char buf[BER_BUF_SIZE];
106 } BIO_BER_CTX;
107
108static BIO_METHOD methods_ber=
109 {
110 BIO_TYPE_CIPHER,"cipher",
111 ber_write,
112 ber_read,
113 NULL, /* ber_puts, */
114 NULL, /* ber_gets, */
115 ber_ctrl,
116 ber_new,
117 ber_free,
118 };
119
120BIO_METHOD *BIO_f_ber(void)
121 {
122 return(&methods_ber);
123 }
124
125static int ber_new(BIO *bi)
126 {
127 BIO_BER_CTX *ctx;
128
129 ctx=(BIO_BER_CTX *)Malloc(sizeof(BIO_BER_CTX));
130 if (ctx == NULL) return(0);
131
132 memset((char *)ctx,0,sizeof(BIO_BER_CTX));
133
134 bi->init=0;
135 bi->ptr=(char *)ctx;
136 bi->flags=0;
137 return(1);
138 }
139
140static int ber_free(BIO *a)
141 {
142 BIO_BER_CTX *b;
143
144 if (a == NULL) return(0);
145 b=(BIO_BER_CTX *)a->ptr;
146 memset(a->ptr,0,sizeof(BIO_BER_CTX));
147 Free(a->ptr);
148 a->ptr=NULL;
149 a->init=0;
150 a->flags=0;
151 return(1);
152 }
153
154int bio_ber_get_header(BIO *bio, BIO_BER_CTX *ctx)
155 {
156 char buf[64];
157 int i,j,n;
158 int ret;
159 unsigned char *p;
160 unsigned long length
161 int tag;
162 int class;
163 long max;
164
165 BIO_clear_retry_flags(b);
166
167 /* Pack the buffer down if there is a hole at the front */
168 if (ctx->buf_off != 0)
169 {
170 p=ctx->buf;
171 j=ctx->buf_off;
172 n=ctx->buf_len-j;
173 for (i=0; i<n; i++)
174 {
175 p[0]=p[j];
176 p++;
177 }
178 ctx->buf_len-j;
179 ctx->buf_off=0;
180 }
181
182 /* If there is more room, read some more data */
183 i=BER_BUF_SIZE-ctx->buf_len;
184 if (i)
185 {
186 i=BIO_read(bio->next_bio,&(ctx->buf[ctx->buf_len]),i);
187 if (i <= 0)
188 {
189 BIO_copy_next_retry(b);
190 return(i);
191 }
192 else
193 ctx->buf_len+=i;
194 }
195
196 max=ctx->buf_len;
197 p=ctx->buf;
198 ret=ASN1_get_object(&p,&length,&tag,&class,max);
199
200 if (ret & 0x80)
201 {
202 if ((ctx->buf_len < BER_BUF_SIZE) &&
203 (ERR_GET_REASON(ERR_peek_error()) == ASN1_R_TOO_LONG))
204 {
205 ERR_get_error(); /* clear the error */
206 BIO_set_retry_read(b);
207 }
208 return(-1);
209 }
210
211 /* We have no error, we have a header, so make use of it */
212
213 if ((ctx->tag >= 0) && (ctx->tag != tag))
214 {
215 BIOerr(BIO_F_BIO_BER_GET_HEADER,BIO_R_TAG_MISMATCH);
216 sprintf(buf,"tag=%d, got %d",ctx->tag,tag);
217 ERR_add_error_data(1,buf);
218 return(-1);
219 }
220 if (ret & 0x01)
221 if (ret & V_ASN1_CONSTRUCTED)
222 }
223
224static int ber_read(BIO *b, char *out, int outl)
225 {
226 int ret=0,i,n;
227 BIO_BER_CTX *ctx;
228
229 BIO_clear_retry_flags(b);
230
231 if (out == NULL) return(0);
232 ctx=(BIO_BER_CTX *)b->ptr;
233
234 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
235
236 if (ctx->finished) return(0);
237
238again:
239 /* First see if we are half way through reading a block */
240 if (ctx->num_left > 0)
241 {
242 if (ctx->num_left < outl)
243 n=ctx->num_left;
244 else
245 n=outl;
246 i=BIO_read(b->next_bio,out,n);
247 if (i <= 0)
248 {
249 BIO_copy_next_retry(b);
250 return(i);
251 }
252 ctx->num_left-=i;
253 outl-=i;
254 ret+=i;
255 if (ctx->num_left <= 0)
256 {
257 ctx->depth--;
258 if (ctx->depth <= 0)
259 ctx->finished=1;
260 }
261 if (outl <= 0)
262 return(ret);
263 else
264 goto again;
265 }
266 else /* we need to read another BER header */
267 {
268 }
269 }
270
271static int ber_write(BIO *b, char *in, int inl)
272 {
273 int ret=0,n,i;
274 BIO_ENC_CTX *ctx;
275
276 ctx=(BIO_ENC_CTX *)b->ptr;
277 ret=inl;
278
279 BIO_clear_retry_flags(b);
280 n=ctx->buf_len-ctx->buf_off;
281 while (n > 0)
282 {
283 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
284 if (i <= 0)
285 {
286 BIO_copy_next_retry(b);
287 return(i);
288 }
289 ctx->buf_off+=i;
290 n-=i;
291 }
292 /* at this point all pending data has been written */
293
294 if ((in == NULL) || (inl <= 0)) return(0);
295
296 ctx->buf_off=0;
297 while (inl > 0)
298 {
299 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
300 EVP_CipherUpdate(&(ctx->cipher),
301 (unsigned char *)ctx->buf,&ctx->buf_len,
302 (unsigned char *)in,n);
303 inl-=n;
304 in+=n;
305
306 ctx->buf_off=0;
307 n=ctx->buf_len;
308 while (n > 0)
309 {
310 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
311 if (i <= 0)
312 {
313 BIO_copy_next_retry(b);
314 return(i);
315 }
316 n-=i;
317 ctx->buf_off+=i;
318 }
319 ctx->buf_len=0;
320 ctx->buf_off=0;
321 }
322 BIO_copy_next_retry(b);
323 return(ret);
324 }
325
326static long ber_ctrl(BIO *b, int cmd, long num, char *ptr)
327 {
328 BIO *dbio;
329 BIO_ENC_CTX *ctx,*dctx;
330 long ret=1;
331 int i;
332
333 ctx=(BIO_ENC_CTX *)b->ptr;
334
335 switch (cmd)
336 {
337 case BIO_CTRL_RESET:
338 ctx->ok=1;
339 ctx->finished=0;
340 EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL,
341 ctx->cipher.berrypt);
342 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
343 break;
344 case BIO_CTRL_EOF: /* More to read */
345 if (ctx->cont <= 0)
346 ret=1;
347 else
348 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
349 break;
350 case BIO_CTRL_WPENDING:
351 ret=ctx->buf_len-ctx->buf_off;
352 if (ret <= 0)
353 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
354 break;
355 case BIO_CTRL_PENDING: /* More to read in buffer */
356 ret=ctx->buf_len-ctx->buf_off;
357 if (ret <= 0)
358 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
359 break;
360 case BIO_CTRL_FLUSH:
361 /* do a final write */
362again:
363 while (ctx->buf_len != ctx->buf_off)
364 {
365 i=ber_write(b,NULL,0);
366 if (i < 0)
367 {
368 ret=i;
369 break;
370 }
371 }
372
373 if (!ctx->finished)
374 {
375 ctx->finished=1;
376 ctx->buf_off=0;
377 ret=EVP_CipherFinal(&(ctx->cipher),
378 (unsigned char *)ctx->buf,
379 &(ctx->buf_len));
380 ctx->ok=(int)ret;
381 if (ret <= 0) break;
382
383 /* push out the bytes */
384 goto again;
385 }
386
387 /* Finally flush the underlying BIO */
388 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
389 break;
390 case BIO_C_GET_CIPHER_STATUS:
391 ret=(long)ctx->ok;
392 break;
393 case BIO_C_DO_STATE_MACHINE:
394 BIO_clear_retry_flags(b);
395 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
396 BIO_copy_next_retry(b);
397 break;
398
399 case BIO_CTRL_DUP:
400 dbio=(BIO *)ptr;
401 dctx=(BIO_ENC_CTX *)dbio->ptr;
402 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
403 dbio->init=1;
404 break;
405 default:
406 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
407 break;
408 }
409 return(ret);
410 }
411
412/*
413void BIO_set_cipher_ctx(b,c)
414BIO *b;
415EVP_CIPHER_ctx *c;
416 {
417 if (b == NULL) return;
418
419 if ((b->callback != NULL) &&
420 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
421 return;
422
423 b->init=1;
424 ctx=(BIO_ENC_CTX *)b->ptr;
425 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
426
427 if (b->callback != NULL)
428 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
429 }
430*/
431
432void BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *k, unsigned char *i,
433 int e)
434 {
435 BIO_ENC_CTX *ctx;
436
437 if (b == NULL) return;
438
439 if ((b->callback != NULL) &&
440 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
441 return;
442
443 b->init=1;
444 ctx=(BIO_ENC_CTX *)b->ptr;
445 EVP_CipherInit(&(ctx->cipher),c,k,i,e);
446
447 if (b->callback != NULL)
448 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
449 }
450
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 @@
1/* crypto/pkcs7/verify.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#include <stdio.h>
59#include <stdlib.h>
60#include <openssl/bio.h>
61#include <openssl/x509.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64#include <openssl/asn1.h>
65
66int verify_callback(int ok, X509_STORE_CTX *ctx);
67
68BIO *bio_err=NULL;
69
70int main(argc,argv)
71int argc;
72char *argv[];
73 {
74 char *keyfile=NULL;
75 BIO *in;
76 EVP_PKEY *pkey;
77 X509 *x509;
78 PKCS7 *p7;
79 PKCS7_SIGNER_INFO *si;
80 X509_STORE_CTX cert_ctx;
81 X509_STORE *cert_store=NULL;
82 BIO *data,*detached=NULL,*p7bio=NULL;
83 char buf[1024*4];
84 unsigned char *pp;
85 int i,printit=0;
86 STACK_OF(PKCS7_SIGNER_INFO) *sk;
87
88 SSLeay_add_all_algorithms();
89 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
90
91 data=BIO_new(BIO_s_file());
92 pp=NULL;
93 while (argc > 1)
94 {
95 argc--;
96 argv++;
97 if (strcmp(argv[0],"-p") == 0)
98 {
99 printit=1;
100 }
101 else if ((strcmp(argv[0],"-k") == 0) && (argc >= 2)) {
102 keyfile = argv[1];
103 argc-=1;
104 argv+=1;
105 } else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2))
106 {
107 detached=BIO_new(BIO_s_file());
108 if (!BIO_read_filename(detached,argv[1]))
109 goto err;
110 argc-=1;
111 argv+=1;
112 }
113 else break;
114 }
115
116 if (!BIO_read_filename(data,argv[0])) goto err;
117
118 if(!keyfile) {
119 fprintf(stderr, "No private key file specified\n");
120 goto err;
121 }
122
123 if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err;
124 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
125 BIO_reset(in);
126 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
127 BIO_free(in);
128
129 if (pp == NULL)
130 BIO_set_fp(data,stdin,BIO_NOCLOSE);
131
132
133 /* Load the PKCS7 object from a file */
134 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err;
135
136
137
138 /* This stuff is being setup for certificate verification.
139 * When using SSL, it could be replaced with a
140 * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */
141 cert_store=X509_STORE_new();
142 X509_STORE_set_default_paths(cert_store);
143 X509_STORE_load_locations(cert_store,NULL,"../../certs");
144 X509_STORE_set_verify_cb_func(cert_store,verify_callback);
145
146 ERR_clear_error();
147
148 /* We need to process the data */
149 /* We cannot support detached encryption */
150 p7bio=PKCS7_dataDecode(p7,pkey,detached,x509);
151
152 if (p7bio == NULL)
153 {
154 printf("problems decoding\n");
155 goto err;
156 }
157
158 /* We now have to 'read' from p7bio to calculate digests etc. */
159 for (;;)
160 {
161 i=BIO_read(p7bio,buf,sizeof(buf));
162 /* print it? */
163 if (i <= 0) break;
164 fwrite(buf,1, i, stdout);
165 }
166
167 /* We can now verify signatures */
168 sk=PKCS7_get_signer_info(p7);
169 if (sk == NULL)
170 {
171 fprintf(stderr, "there are no signatures on this data\n");
172 }
173 else
174 {
175 /* Ok, first we need to, for each subject entry,
176 * see if we can verify */
177 ERR_clear_error();
178 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sk); i++)
179 {
180 si=sk_PKCS7_SIGNER_INFO_value(sk,i);
181 i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
182 if (i <= 0)
183 goto err;
184 else
185 fprintf(stderr,"Signature verified\n");
186 }
187 }
188 X509_STORE_free(cert_store);
189
190 exit(0);
191err:
192 ERR_load_crypto_strings();
193 ERR_print_errors_fp(stderr);
194 exit(1);
195 }
196
197/* should be X509 * but we can just have them as char *. */
198int verify_callback(int ok, X509_STORE_CTX *ctx)
199 {
200 char buf[256];
201 X509 *err_cert;
202 int err,depth;
203
204 err_cert=X509_STORE_CTX_get_current_cert(ctx);
205 err= X509_STORE_CTX_get_error(ctx);
206 depth= X509_STORE_CTX_get_error_depth(ctx);
207
208 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
209 BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
210 if (!ok)
211 {
212 BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
213 X509_verify_cert_error_string(err));
214 if (depth < 6)
215 {
216 ok=1;
217 X509_STORE_CTX_set_error(ctx,X509_V_OK);
218 }
219 else
220 {
221 ok=0;
222 X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
223 }
224 }
225 switch (ctx->error)
226 {
227 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
228 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
229 BIO_printf(bio_err,"issuer= %s\n",buf);
230 break;
231 case X509_V_ERR_CERT_NOT_YET_VALID:
232 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
233 BIO_printf(bio_err,"notBefore=");
234 ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
235 BIO_printf(bio_err,"\n");
236 break;
237 case X509_V_ERR_CERT_HAS_EXPIRED:
238 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
239 BIO_printf(bio_err,"notAfter=");
240 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
241 BIO_printf(bio_err,"\n");
242 break;
243 }
244 BIO_printf(bio_err,"verify return:%d\n",ok);
245 return(ok);
246 }
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 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ
6/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N
11WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
12oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL
13lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8
145PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA=
15
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include "bio.h" 59#include <openssl/bio.h>
60#include "x509.h" 60#include <openssl/x509.h>
61#include "pem.h" 61#include <openssl/pem.h>
62#include <openssl/err.h>
62 63
63main(argc,argv) 64int main(argc,argv)
64int argc; 65int argc;
65char *argv[]; 66char *argv[];
66 { 67 {
67 X509 *x509; 68 X509 *x509;
68 EVP_PKEY *pkey;
69 PKCS7 *p7; 69 PKCS7 *p7;
70 PKCS7 *p7_data;
71 PKCS7_SIGNER_INFO *si;
72 BIO *in; 70 BIO *in;
73 BIO *data,*p7bio; 71 BIO *data,*p7bio;
74 char buf[1024*4]; 72 char buf[1024*4];
75 int i,j; 73 int i;
76 int nodetach=0; 74 int nodetach=1;
75 char *keyfile = NULL;
76 const EVP_CIPHER *cipher=NULL;
77 STACK_OF(X509) *recips=NULL;
77 78
78 EVP_add_digest(EVP_sha1()); 79 SSLeay_add_all_algorithms();
79 EVP_add_cipher(EVP_des_cbc());
80 80
81 data=BIO_new(BIO_s_file()); 81 data=BIO_new(BIO_s_file());
82again: 82 while(argc > 1)
83 if (argc > 1)
84 { 83 {
85 if (strcmp(argv[1],"-nd") == 0) 84 if (strcmp(argv[1],"-nd") == 0)
86 { 85 {
87 nodetach=1; 86 nodetach=1;
88 argv++; argc--; 87 argv++; argc--;
89 goto again;
90 } 88 }
91 if (!BIO_read_filename(data,argv[1])) 89 else if ((strcmp(argv[1],"-c") == 0) && (argc >= 2)) {
92 goto err; 90 if(!(cipher = EVP_get_cipherbyname(argv[2]))) {
93 } 91 fprintf(stderr, "Unknown cipher %s\n", argv[2]);
94 else 92 goto err;
95 BIO_set_fp(data,stdin,BIO_NOCLOSE); 93 }
94 argc-=2;
95 argv+=2;
96 } else if ((strcmp(argv[1],"-k") == 0) && (argc >= 2)) {
97 keyfile = argv[2];
98 argc-=2;
99 argv+=2;
100 if (!(in=BIO_new_file(keyfile,"r"))) goto err;
101 if (!(x509=PEM_read_bio_X509(in,NULL,NULL))) goto err;
102 if(!recips) recips = sk_X509_new_null();
103 sk_X509_push(recips, x509);
104 BIO_free(in);
105 } else break;
106 }
96 107
97 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err; 108 if(!recips) {
98 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; 109 fprintf(stderr, "No recipients\n");
110 goto err;
111 }
112
113 if (!BIO_read_filename(data,argv[1])) goto err;
114
115 p7=PKCS7_new();
116#if 0
99 BIO_reset(in); 117 BIO_reset(in);
100 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; 118 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
101 BIO_free(in); 119 BIO_free(in);
102
103 p7=PKCS7_new();
104 PKCS7_set_type(p7,NID_pkcs7_signedAndEnveloped); 120 PKCS7_set_type(p7,NID_pkcs7_signedAndEnveloped);
105 121
106 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err; 122 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
107
108 if (!PKCS7_set_cipher(p7,EVP_des_cbc())) goto err;
109 if (PKCS7_add_recipient(p7,x509) == NULL) goto err;
110
111 /* we may want to add more */ 123 /* we may want to add more */
112 PKCS7_add_certificate(p7,x509); 124 PKCS7_add_certificate(p7,x509);
113 125#else
126 PKCS7_set_type(p7,NID_pkcs7_enveloped);
127#endif
128 if(!cipher) cipher = EVP_des_ede3_cbc();
129
130 if (!PKCS7_set_cipher(p7,cipher)) goto err;
131 for(i = 0; i < sk_X509_num(recips); i++) {
132 if (!PKCS7_add_recipient(p7,sk_X509_value(recips, i))) goto err;
133 }
134 sk_X509_pop_free(recips, X509_free);
114 135
115 /* Set the content of the signed to 'data' */ 136 /* Set the content of the signed to 'data' */
116 /* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */ 137 /* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */
@@ -129,7 +150,7 @@ again:
129 } 150 }
130 BIO_flush(p7bio); 151 BIO_flush(p7bio);
131 152
132 if (!PKCS7_dataSign(p7,p7bio)) goto err; 153 if (!PKCS7_dataFinal(p7,p7bio)) goto err;
133 BIO_free(p7bio); 154 BIO_free(p7bio);
134 155
135 PEM_write_PKCS7(stdout,p7); 156 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 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqGSIb3DQEBAQUABEDWak0y/5XZJhQJeCLo
6KECcHXkTEbjzYkYNHIinbiPmRK4QbNfs9z2mA3z/c2ykQ4eAqFR2jyNrUMN/+I5XEiv6MIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEAWg9+KgtCjc77Jdj1Ve4wGgHjVHbbSYEA1ZqKFDoi15vSr9hfpHmC4
11ycZzcRo16JkTfolefiHZzmyjVz94vSN6MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
12oAQI7X4Tk4mcbV6ggASBsHl1mCaJ3RhXWlNPCgCRU53d7M5x6TDZRkvwdtdvW96m1lupT03F
13XtonkBqk7oMkH7kGfs5/REQOPjx0QE2Ixmgt1W3szum82EZwA7pZNppcraK7W/odw/7bYZO+
14II3HPmRklE2N9qiu1LPaPUsnYogkO6SennyeL5tZ382vBweL/8pnG0qsbT1OBb65v+llnsjT
15pa1T/p+fIx/iJJGE6K9fYFokC6gXLQ6ozXRdOu5oBDB8mPCYYvAqKycidM/MrGGUkpEtS4f0
16lS31PwQi5YTim8Ig3/TOwVpPX32i46FTuEIEIMHkD/OvpfwCCzXUHHJnKnKUAUvIsSY3vGBs
178ezpUDfBBBj9LHDy32hZ2tQilkDefP5VM2LLdrWgamYEgfiyITQvn08Ul5lQOQxbFKBheFq5
18otCCN4MR+w5eq12xQu6y+f9z0159ag2ru87D0lLtUtXXtCELbO1nUkT2sJ0k/iDs9TOXr6Cx
19go1XKYho83hlkXYiCteVizdAbgVGNsNRD4wtIdajsorET/LuJECgp11YeL9w1dlDB0HLEZfi
20XCsUphH4jGagba3hDeUSibnjSiJlN0ukfuQurBBbI2UkBAujiEAubKPn7C1FZJRSw6CPPX5t
21KEpmcqT1JNk6LO8Js6/1sCmmBh1VGCy1+EuTI9J1p7Dagf4nQ8cHitoCRpHuKZlFHnZyv7tw
22Rn/KOhHaYP2VzAh40gQIvKMAAWh9oFsEEIMwIoOmLwLH5wf+8QdbDhoECH8HwZt9a12dBAjL
23r4j2zlvtfgQIt7nmEM3wz1EECKlc3EIy1irCBBCAKINcermK3A+jI6ISN2RzBFA3dsh/xwMu
24l61aWMBBZzEz/SF92k6n35KZhCC0d6fIVC/1WMv0fnCwQ8oEDynSre216VEFiYKBaQLJe5o/
25mTAxC7Ht3goXnuc+i1FItOkLrgRI/wyvTICEn2WsNZiMADnGaee2bqPnUopo+VMGexJEtCPk
26l0ZNlDJGquPDkpUwaEtecVZzCNyVPYyyF4J/l8rmGDhDdYUIC8IKBEg/ip/E0BuubBLWVbv+
27HRl4QrnGpyCyeXRXXK603QP3sT1Zbbm1v5pI/loOhVHi724LmtXHSyp5qv9MDcxE1PoX10LY
28gBRtlwwESPeCF8bK5jk4xIQMhK5NMHj1Y1KQWTZ9NGITBL4hjRq2qp4Qk5GIpGgOVPopAuCo
29TIyPikpqBRNtLSPRSsDs6QPUPzWBh6JgxwRQblnDKKUkxUcnJiD4i9QtGa/ZabMn4KxtNOBL
305JSh1nJkaLXCZY070131WWPAByLcd5TiXq8x84pmzV5NNk4tiMpoXhJNsx8e4rskQQlKd6ME
31SCe2eYDHKcKPX3WJbUzhrJSQ92/aWnI2iUY8WQ+kSNyiZ2QUjyuUg9Z66g/0d2STlvPOBHT/
32y5ODP2CwbcWX4QmCbUc9TT66fQRIrRVuwvtOfnUueyGgYhJ3HpAJfVaB/7kap5bj7Fi/azW4
339JDfd1bC/W9h0Kyk7RO2gxvE0hIHc26mZJHTm9MNP5D328MnM2MdBEjKjQBtgrp+lFIii7MP
34nGHFTKUkG4WAIZJCf/CsT+p6/SW0qG71Me/YcSw5STB24j+a+HgMV8RVIeUlkP4z0IWWrSoB
35Gh4d/Z0EUMCVHs/HZ/bWgiyhtHpvuVAzidm8D81p1LJ5BQX5/5f/m+q5+fS/npL27dTEbNqs
36LSB6ij3MZAi7LwHWpTn9zWnDajCMEj9vlaV7mcKtHK5iBEg85agFi1h3MvicqLtoFe5hVv9T
37tG0j6CRkjkixPzivltlrf44KHv14gLM0XJxCGyq7vd3l8QYr3+9at0zNnX/yqTiBnsnE5dUE
38SIgrYuz87M2gi/ER9PcDoTtONH3+CkcqVy03q/Sj8cVWD/b1KgEhqnNOfc8Ak9PctyR/ItcR
398Me5XVn1GJKkQJk4O29fxvgNoAQIrIESvUWGshAEQByXiFoFTDUByjTlgjcy77H1lrH+y3P/
40wAInJjJAut9kCNyGJV0PA4kdPB5USWltuO6t8gk4Pd2YBMl09zqUWkAEUCjFrtZ3mapjcGZI
41uQTASKR5LSjXoWxTT5gae/+64MerF/oCEeO3ehRTpjnPrsiRDo0rWIQTaj9+Nro8Z2xtWstw
42RnfoAHIxV1lEamPwjsceBEi2SD9hiifFeO5ECiVoaE1FdXUXhU+jwYAMx6jHWO9hMkYzS9pM
43Y3IyWR5ybtOjiQgkUdvRJPUPGf5DVVMPnymGX25aDh5PYpIESPbsM9akCpOOVuscywcUswmU
44o7dXvlB48WWCfg/al3BQKAZbn5ZXtWNwpUZkrEdHsrxAVv3rxRcdkT3Z1fzUbIuYkLJN200o
45WgRIJvn6RO8KEj7/HOg2sYuuM8nz1kR0TSgwX7/0y/7JfjBa0JIlP7o75sNJscE8oyoIMzuy
46Dvn6/U9g3BCDXn83A/s+ke60qn9gBFC6NAeLOlXal1YVWYhMQNOqCyUfAjiXBTawaysQb1Mk
47YgeNlF8xuEFcUQWIP+vNG7FJ5JPMaMRL4YEoaQ3sVFhYOERJR1cSb+8xt4QCYtBKQgRIUOmJ
48CHW5o1hXJWJiTkZK2qWFcEMzTINSj5EpYFySr8aVBjkRnI7vxegRT/+XZZXoYedQ3UNsnGI3
49DdkWii5VzX0PNF6C60pfBEiVpausYuX7Wjb3Lfm8cBj7GgN69i6Pm2gxtobVcmpo2nS4D714
50ePyhlX9n8kJ6QAcqWMRj22smDPrHVGNTizfzHBh5zNllK9gESJizILOWI327og3ZWp+qUht5
51kNDJCzMK7Z09UAy+h+vq0VTQuEo3FgLzVdqkJujjSL4Nx97lXg51AovrEn3nd4evydwcjKLX
521wRIo72NaeWuUEQ+rt1SlCsOJ7k1ioJSqhrPOfvwcaFcb4beVet1JWiy4yvowTjLDGbUje2s
53xjrlVt4BJWI/uA6jbQsrxSe89ADZBAi5YAlR4qszeAQIXD3VSBVKbRUECNTtyvw9vvqXBAhb
54IZNn4H4cxgQI+XW7GkfL+ekECCCCg2reMyGDBAh1PYqkg3lw3gQQkNlggEPU+BH8eh7Gm7n7
557AQIjC5EWbkil5cEEKcpuqwTWww/X89KnQAg8TcECJPomqHvrlZFBBiRSuIiHpmN+PaujXpv
56qZV2VhjkB2j09GEECOIdv8AVOJgKBAjlHgIqAD9jZQQIXHbs44+wogcEIGGqTACRJxrhMcMG
57X8drNjksIPt+snxTXUBIkTVpZWoABAh6unXPTyIr8QQgBF8xKoX27MWk7iTNmkSNZggZXa2a
58DWCGHSYLngbSOHIECD9XmO6VsvTgBAjfqB70CEW4WwQIVIBkbCocznUEEHB/zFXy/sR4OYHe
59UfbNPnIEEDWBB/NTCLMGE+o8BfyujcAECFik7GQnnF9VBBAhLXExQeWAofZNc6NtN7qZBCC1
60gVIS3ruTwKltmcrgx3heT3M8ZJhCfWa+6KzchnmKygQQ+1NL5sSzR4m/fdrqxHFyUAQYCT2x
61PamQr3wK3h0lyZER+4H0zPM86AhFBBC3CkmvL2vjflMfujnzPBVpBBge9rMbI5+0q9DLrTiT
625F3AIgXLpD8PQWAECHkHVo6RomV3BAgMbi8E271UeAQIqtS8wnI3XngECG3TWmOMb3/iBEha
63y+mvCS6I3n3JfL8e1B5P4qX9/czJRaERLuKpGNjLiL4A+zxN0LZ0UHd0qfmJjwOTxAx3iJAC
64lGXX4nB9ATYPUT5EU+o1Y4sECN01pP6vWNIdBDAsiE0Ts8/9ltJlqX2B3AoOM4qOt9EaCjXf
65lB+aEmrhtjUwuZ6GqS5Ke7P6XnakTk4ECCLIMatNdootAAAAAAAAAAAAAA==
66-----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 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <openssl/pkcs7.h>
4#include <openssl/asn1_mac.h>
5
6int add_signed_time(PKCS7_SIGNER_INFO *si)
7 {
8 ASN1_UTCTIME *sign_time;
9
10 /* The last parameter is the amount to add/subtract from the current
11 * time (in seconds) */
12 sign_time=X509_gmtime_adj(NULL,0);
13 PKCS7_add_signed_attribute(si,NID_pkcs9_signingTime,
14 V_ASN1_UTCTIME,(char *)sign_time);
15 return(1);
16 }
17
18ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si)
19 {
20 ASN1_TYPE *so;
21
22 so=PKCS7_get_signed_attribute(si,NID_pkcs9_signingTime);
23 if (so->type == V_ASN1_UTCTIME)
24 return so->value.utctime;
25 return NULL;
26 }
27
28static int signed_string_nid= -1;
29
30void add_signed_string(PKCS7_SIGNER_INFO *si, char *str)
31 {
32 ASN1_OCTET_STRING *os;
33
34 /* To a an object of OID 1.2.3.4.5, which is an octet string */
35 if (signed_string_nid == -1)
36 signed_string_nid=
37 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
38 os=ASN1_OCTET_STRING_new();
39 ASN1_OCTET_STRING_set(os,str,strlen(str));
40 /* When we add, we do not free */
41 PKCS7_add_signed_attribute(si,signed_string_nid,
42 V_ASN1_OCTET_STRING,(char *)os);
43 }
44
45int get_signed_string(PKCS7_SIGNER_INFO *si, char *buf, int len)
46 {
47 ASN1_TYPE *so;
48 ASN1_OCTET_STRING *os;
49 int i;
50
51 if (signed_string_nid == -1)
52 signed_string_nid=
53 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
54 /* To retrieve */
55 so=PKCS7_get_signed_attribute(si,signed_string_nid);
56 if (so != NULL)
57 {
58 if (so->type == V_ASN1_OCTET_STRING)
59 {
60 os=so->value.octet_string;
61 i=os->length;
62 if ((i+1) > len)
63 i=len-1;
64 memcpy(buf,os->data,i);
65 return(i);
66 }
67 }
68 return(0);
69 }
70
71static signed_seq2string_nid= -1;
72/* ########################################### */
73int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
74 {
75 /* To add an object of OID 1.9.999, which is a sequence containing
76 * 2 octet strings */
77 unsigned char *p;
78 ASN1_OCTET_STRING *os1,*os2;
79 ASN1_STRING *seq;
80 unsigned char *data;
81 int i,total;
82
83 if (signed_seq2string_nid == -1)
84 signed_seq2string_nid=
85 OBJ_create("1.9.9999","OID_example","Our example OID");
86
87 os1=ASN1_OCTET_STRING_new();
88 os2=ASN1_OCTET_STRING_new();
89 ASN1_OCTET_STRING_set(os1,str1,strlen(str1));
90 ASN1_OCTET_STRING_set(os2,str1,strlen(str1));
91 i =i2d_ASN1_OCTET_STRING(os1,NULL);
92 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
93 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
94
95 data=malloc(total);
96 p=data;
97 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
98 i2d_ASN1_OCTET_STRING(os1,&p);
99 i2d_ASN1_OCTET_STRING(os2,&p);
100
101 seq=ASN1_STRING_new();
102 ASN1_STRING_set(seq,data,total);
103 free(data);
104 ASN1_OCTET_STRING_free(os1);
105 ASN1_OCTET_STRING_free(os2);
106
107 PKCS7_add_signed_attribute(si,signed_seq2string_nid,
108 V_ASN1_SEQUENCE,(char *)seq);
109 return(1);
110 }
111
112/* For this case, I will malloc the return strings */
113int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2)
114 {
115 ASN1_TYPE *so;
116
117 if (signed_seq2string_nid == -1)
118 signed_seq2string_nid=
119 OBJ_create("1.9.9999","OID_example","Our example OID");
120 /* To retrieve */
121 so=PKCS7_get_signed_attribute(si,signed_seq2string_nid);
122 if (so && (so->type == V_ASN1_SEQUENCE))
123 {
124 ASN1_CTX c;
125 ASN1_STRING *s;
126 long length;
127 ASN1_OCTET_STRING *os1,*os2;
128
129 s=so->value.sequence;
130 c.p=ASN1_STRING_data(s);
131 c.max=c.p+ASN1_STRING_length(s);
132 if (!asn1_GetSequence(&c,&length)) goto err;
133 /* Length is the length of the seqence */
134
135 c.q=c.p;
136 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
137 goto err;
138 c.slen-=(c.p-c.q);
139
140 c.q=c.p;
141 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
142 goto err;
143 c.slen-=(c.p-c.q);
144
145 if (!asn1_Finish(&c)) goto err;
146 *str1=malloc(os1->length+1);
147 *str2=malloc(os2->length+1);
148 memcpy(*str1,os1->data,os1->length);
149 memcpy(*str2,os2->data,os2->length);
150 (*str1)[os1->length]='\0';
151 (*str2)[os2->length]='\0';
152 ASN1_OCTET_STRING_free(os1);
153 ASN1_OCTET_STRING_free(os2);
154 return(1);
155 }
156err:
157 return(0);
158 }
159
160
161/* #######################################
162 * THE OTHER WAY TO DO THINGS
163 * #######################################
164 */
165X509_ATTRIBUTE *create_time(void)
166 {
167 ASN1_UTCTIME *sign_time;
168 X509_ATTRIBUTE *ret;
169
170 /* The last parameter is the amount to add/subtract from the current
171 * time (in seconds) */
172 sign_time=X509_gmtime_adj(NULL,0);
173 ret=X509_ATTRIBUTE_create(NID_pkcs9_signingTime,
174 V_ASN1_UTCTIME,(char *)sign_time);
175 return(ret);
176 }
177
178ASN1_UTCTIME *sk_get_time(STACK_OF(X509_ATTRIBUTE) *sk)
179 {
180 ASN1_TYPE *so;
181 PKCS7_SIGNER_INFO si;
182
183 si.auth_attr=sk;
184 so=PKCS7_get_signed_attribute(&si,NID_pkcs9_signingTime);
185 if (so->type == V_ASN1_UTCTIME)
186 return so->value.utctime;
187 return NULL;
188 }
189
190X509_ATTRIBUTE *create_string(char *str)
191 {
192 ASN1_OCTET_STRING *os;
193 X509_ATTRIBUTE *ret;
194
195 /* To a an object of OID 1.2.3.4.5, which is an octet string */
196 if (signed_string_nid == -1)
197 signed_string_nid=
198 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
199 os=ASN1_OCTET_STRING_new();
200 ASN1_OCTET_STRING_set(os,str,strlen(str));
201 /* When we add, we do not free */
202 ret=X509_ATTRIBUTE_create(signed_string_nid,
203 V_ASN1_OCTET_STRING,(char *)os);
204 return(ret);
205 }
206
207int sk_get_string(STACK_OF(X509_ATTRIBUTE) *sk, char *buf, int len)
208 {
209 ASN1_TYPE *so;
210 ASN1_OCTET_STRING *os;
211 int i;
212 PKCS7_SIGNER_INFO si;
213
214 si.auth_attr=sk;
215
216 if (signed_string_nid == -1)
217 signed_string_nid=
218 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
219 /* To retrieve */
220 so=PKCS7_get_signed_attribute(&si,signed_string_nid);
221 if (so != NULL)
222 {
223 if (so->type == V_ASN1_OCTET_STRING)
224 {
225 os=so->value.octet_string;
226 i=os->length;
227 if ((i+1) > len)
228 i=len-1;
229 memcpy(buf,os->data,i);
230 return(i);
231 }
232 }
233 return(0);
234 }
235
236X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
237 {
238 /* To add an object of OID 1.9.999, which is a sequence containing
239 * 2 octet strings */
240 unsigned char *p;
241 ASN1_OCTET_STRING *os1,*os2;
242 ASN1_STRING *seq;
243 X509_ATTRIBUTE *ret;
244 unsigned char *data;
245 int i,total;
246
247 if (signed_seq2string_nid == -1)
248 signed_seq2string_nid=
249 OBJ_create("1.9.9999","OID_example","Our example OID");
250
251 os1=ASN1_OCTET_STRING_new();
252 os2=ASN1_OCTET_STRING_new();
253 ASN1_OCTET_STRING_set(os1,str1,strlen(str1));
254 ASN1_OCTET_STRING_set(os2,str1,strlen(str1));
255 i =i2d_ASN1_OCTET_STRING(os1,NULL);
256 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
257 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
258
259 data=malloc(total);
260 p=data;
261 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
262 i2d_ASN1_OCTET_STRING(os1,&p);
263 i2d_ASN1_OCTET_STRING(os2,&p);
264
265 seq=ASN1_STRING_new();
266 ASN1_STRING_set(seq,data,total);
267 free(data);
268 ASN1_OCTET_STRING_free(os1);
269 ASN1_OCTET_STRING_free(os2);
270
271 ret=X509_ATTRIBUTE_create(signed_seq2string_nid,
272 V_ASN1_SEQUENCE,(char *)seq);
273 return(ret);
274 }
275
276/* For this case, I will malloc the return strings */
277int sk_get_seq2string(STACK_OF(X509_ATTRIBUTE) *sk, char **str1, char **str2)
278 {
279 ASN1_TYPE *so;
280 PKCS7_SIGNER_INFO si;
281
282 if (signed_seq2string_nid == -1)
283 signed_seq2string_nid=
284 OBJ_create("1.9.9999","OID_example","Our example OID");
285
286 si.auth_attr=sk;
287 /* To retrieve */
288 so=PKCS7_get_signed_attribute(&si,signed_seq2string_nid);
289 if (so->type == V_ASN1_SEQUENCE)
290 {
291 ASN1_CTX c;
292 ASN1_STRING *s;
293 long length;
294 ASN1_OCTET_STRING *os1,*os2;
295
296 s=so->value.sequence;
297 c.p=ASN1_STRING_data(s);
298 c.max=c.p+ASN1_STRING_length(s);
299 if (!asn1_GetSequence(&c,&length)) goto err;
300 /* Length is the length of the seqence */
301
302 c.q=c.p;
303 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
304 goto err;
305 c.slen-=(c.p-c.q);
306
307 c.q=c.p;
308 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
309 goto err;
310 c.slen-=(c.p-c.q);
311
312 if (!asn1_Finish(&c)) goto err;
313 *str1=malloc(os1->length+1);
314 *str2=malloc(os2->length+1);
315 memcpy(*str1,os1->data,os1->length);
316 memcpy(*str2,os2->data,os2->length);
317 (*str1)[os1->length]='\0';
318 (*str2)[os2->length]='\0';
319 ASN1_OCTET_STRING_free(os1);
320 ASN1_OCTET_STRING_free(os2);
321 return(1);
322 }
323err:
324 return(0);
325 }
326
327
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 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55int add_signed_time(PKCS7_SIGNER_INFO *si);
56ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si);
57int 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 @@
1issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
2subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
3serial :047D
4
5Certificate:
6 Data:
7 Version: 3 (0x2)
8 Serial Number: 1149 (0x47d)
9 Signature Algorithm: md5withRSAEncryption
10 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
11 Validity
12 Not Before: May 13 05:40:58 1998 GMT
13 Not After : May 12 05:40:58 2000 GMT
14 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
15 Subject Public Key Info:
16 Public Key Algorithm: rsaEncryption
17 Modulus:
18 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
19 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
20 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
21 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
22 e7:e7:0c:4d:0b
23 Exponent: 65537 (0x10001)
24 X509v3 extensions:
25 Netscape Comment:
26 Generated with SSLeay
27 Signature Algorithm: md5withRSAEncryption
28 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
29 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
30 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
31 50:74:ad:92:cb:4e:90:e5:fa:7d
32
33-----BEGIN CERTIFICATE-----
34MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
35MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
36ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
37IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
38NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
39UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
40dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
41aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
429w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
43lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
44hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
45UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
464A3ZItobUHStkstOkOX6fQ==
47-----END CERTIFICATE-----
48
49-----BEGIN RSA PRIVATE KEY-----
50MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
51mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
52fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
53zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
54p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
55bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
56IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
57-----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 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
3mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
4fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
5zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
6p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
7bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
8IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
9-----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 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHAqCAMIIC2QIBATEMMAoGCCqGSIb3DQIFMIAGCSqGSIb3DQEH
3AQAAoIIB7TCCAekwggFSAgEAMA0GCSqGSIb3DQEBBAUAMFsxCzAJBgNVBAYTAkFV
4MRMwEQYDVQQIEwpRdWVlbnNsYW5kMRowGAYDVQQKExFDcnlwdFNvZnQgUHR5IEx0
5ZDEbMBkGA1UEAxMSVGVzdCBDQSAoMTAyNCBiaXQpMB4XDTk3MDYwOTEzNTc0NloX
6DTk4MDYwOTEzNTc0NlowYzELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xh
7bmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMSMwIQYDVQQDExpTZXJ2ZXIg
8dGVzdCBjZXJ0ICg1MTIgYml0KTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQCfs8OE
9J5X/EjFSDxXvRhHErYDmNlsP3YDXYY3g/HJFCTT+VWZFQ0xol2r+qKCl3194/+7X
10ZLg/BMtv/yr+/rntAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAeEzEdgr2nChPcALL
11vY8gl/GIlpoAjPmKD+pLeGZI9s+SEX5u1q8nCrJ6ZzkfrRnqgI5Anmev9+qPZfdU
12bz5zdVSf4sUL9nX9ChXjK9NCJA3UzQHSFqhZErGUwGNkAHYHp2+zAdY6Ho6rmMzt
13g0CDu/sKR4qzm6REsQGS8kgpjz4xgcUwgcICAQEwYDBbMQswCQYDVQQGEwJBVTET
14MBEGA1UECBMKUXVlZW5zbGFuZDEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQx
15GzAZBgNVBAMTElRlc3QgQ0EgKDEwMjQgYml0KQIBADAKBggqhkiG9w0CBTANBgkq
16hkiG9w0BAQQFAARALnrxJiOX9XZf2D+3vL8SKMQmMq55LltomwOLGUru/q1uVXzi
17ARg7FSCegOpA1nunsTURMUGgrPXKK4XmL4IseQAAAAA=
18-----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 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHAqCAMIIFsQIBATELMAkGBSsOAwIaBQAwgAYJKoZIhvcNAQcB
3AACgggQdMIICJTCCAc+gAwIBAgIBIjANBgkqhkiG9w0BAQQFADCBgjELMAkGA1UE
4BhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRow
5GAYDVQQKExFDcnlwdFNvZnQgUHR5IEx0ZDEUMBIGA1UECxMLZGV2ZWxvcG1lbnQx
6GTAXBgNVBAMTEENyeXB0U29mdCBEZXYgQ0EwHhcNOTcwNjEzMTgxMDE3WhcNOTgw
7NjEzMTgxMDE3WjCBiDELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQx
8ETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdFNvZnQgUHR5IEx0ZDEU
9MBIGA1UECxMLSUlTIHRlc3RpbmcxDjAMBgNVBAMTBXRlc3QxMQ8wDQYJKoZIhvcN
10AQkBFgAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAxtWiv59VH42+rotrmFAyDxTc
11J2osFt5uy/zEllx3vvjtwewqQxGUOwf6cjqFOTrnpEdVvwywpEhIQ5364bJqIwID
12AQABoygwJjAkBglghkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0G
13CSqGSIb3DQEBBAUAA0EAMnYkNV2AdpeHPy/qlcdZx6MDGIJgrLhklhcn6Or6KiAP
14t9+nv9XdOGHyMyQr9ufsweuQfAgJ9yjKPZR2/adTjTCCAfAwggGaAgEAMA0GCSqG
15SIb3DQEBBAUAMIGCMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDER
16MA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRQw
17EgYDVQQLEwtkZXZlbG9wbWVudDEZMBcGA1UEAxMQQ3J5cHRTb2Z0IERldiBDQTAe
18Fw05NzAzMjIxMzM0MDRaFw05ODAzMjIxMzM0MDRaMIGCMQswCQYDVQQGEwJBVTET
19MBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoT
20EUNyeXB0U29mdCBQdHkgTHRkMRQwEgYDVQQLEwtkZXZlbG9wbWVudDEZMBcGA1UE
21AxMQQ3J5cHRTb2Z0IERldiBDQTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDgDgKq
22IBuUMAJi4c8juAqEZ8f8FcuDWT+HcScvNztRJy9K8DnbGpiSrzzix4El6N4A7vbl
23crwn/0CZmQJguZpfAgMBAAEwDQYJKoZIhvcNAQEEBQADQQA0UUvxlXXe6wKkVukn
24ZoCyXbjlNsqt2rwbvfZEam6fQP3S7uq+o1Pnj+KDgE33WxWbQAA9h8fY1LWN7X3a
25yTm/MYIBbTCCAWkCAQEwgYgwgYIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVl
26bnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRTb2Z0IFB0
27eSBMdGQxFDASBgNVBAsTC2RldmVsb3BtZW50MRkwFwYDVQQDExBDcnlwdFNvZnQg
28RGV2IENBAgEiMAkGBSsOAwIaBQCgfTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcB
29MCMGCSqGSIb3DQEJBDEWBBSUVhbGkNE+KGqpOK13+FkfOkaoizAcBgkqhkiG9w0B
30CQUxDxcNOTcwNzAxMDE0MzM0WjAeBgkqhkiG9w0BCQ8xETAPMA0GCCqGSIb3DQMC
31AgEoMA0GCSqGSIb3DQEBAQUABECa9Jpo4w/fZOc3Vy78wZFAVF8kvpn7il99Ldsr
32AQ4JiBmcfiSwEBBY6WuKT+/SYtFwZl1oXkTwB5AVCFIC/IFNAAAAAA==
33-----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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "rand.h" 62#include <openssl/rand.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pkcs7.h" 65#include <openssl/pkcs7.h>
66 66
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "rand.h" 61#include <openssl/rand.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/x509.h>
64 64
65BIO *PKCS7_dataInit(p7,bio) 65static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
66PKCS7 *p7; 66 void *value);
67BIO *bio; 67static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid);
68
69BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
68 { 70 {
69 int i,j; 71 int i,j;
70 BIO *out=NULL,*btmp; 72 BIO *out=NULL,*btmp=NULL;
71 X509_ALGOR *xa; 73 X509_ALGOR *xa;
72 EVP_MD *evp_md; 74 const EVP_MD *evp_md;
73 EVP_CIPHER *evp_cipher=NULL; 75 const EVP_CIPHER *evp_cipher=NULL;
74 STACK *md_sk=NULL,*rsk=NULL; 76 STACK_OF(X509_ALGOR) *md_sk=NULL;
77 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
75 X509_ALGOR *xalg=NULL; 78 X509_ALGOR *xalg=NULL;
76 PKCS7_RECIP_INFO *ri=NULL; 79 PKCS7_RECIP_INFO *ri=NULL;
77 EVP_PKEY *pkey; 80 EVP_PKEY *pkey;
@@ -87,13 +90,25 @@ BIO *bio;
87 case NID_pkcs7_signedAndEnveloped: 90 case NID_pkcs7_signedAndEnveloped:
88 rsk=p7->d.signed_and_enveloped->recipientinfo; 91 rsk=p7->d.signed_and_enveloped->recipientinfo;
89 md_sk=p7->d.signed_and_enveloped->md_algs; 92 md_sk=p7->d.signed_and_enveloped->md_algs;
90 evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(p7->d.signed_and_enveloped->enc_data->algorithm->algorithm))); 93 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
94 evp_cipher=p7->d.signed_and_enveloped->enc_data->cipher;
91 if (evp_cipher == NULL) 95 if (evp_cipher == NULL)
92 { 96 {
93 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); 97 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
98 PKCS7_R_CIPHER_NOT_INITIALIZED);
99 goto err;
100 }
101 break;
102 case NID_pkcs7_enveloped:
103 rsk=p7->d.enveloped->recipientinfo;
104 xalg=p7->d.enveloped->enc_data->algorithm;
105 evp_cipher=p7->d.enveloped->enc_data->cipher;
106 if (evp_cipher == NULL)
107 {
108 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
109 PKCS7_R_CIPHER_NOT_INITIALIZED);
94 goto err; 110 goto err;
95 } 111 }
96 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
97 break; 112 break;
98 default: 113 default:
99 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); 114 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
@@ -102,10 +117,14 @@ BIO *bio;
102 117
103 if (md_sk != NULL) 118 if (md_sk != NULL)
104 { 119 {
105 for (i=0; i<sk_num(md_sk); i++) 120 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
106 { 121 {
107 xa=(X509_ALGOR *)sk_value(md_sk,i); 122 xa=sk_X509_ALGOR_value(md_sk,i);
108 if ((btmp=BIO_new(BIO_f_md())) == NULL) goto err; 123 if ((btmp=BIO_new(BIO_f_md())) == NULL)
124 {
125 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
126 goto err;
127 }
109 128
110 j=OBJ_obj2nid(xa->algorithm); 129 j=OBJ_obj2nid(xa->algorithm);
111 evp_md=EVP_get_digestbyname(OBJ_nid2sn(j)); 130 evp_md=EVP_get_digestbyname(OBJ_nid2sn(j));
@@ -120,6 +139,7 @@ BIO *bio;
120 out=btmp; 139 out=btmp;
121 else 140 else
122 BIO_push(out,btmp); 141 BIO_push(out,btmp);
142 btmp=NULL;
123 } 143 }
124 } 144 }
125 145
@@ -130,49 +150,70 @@ BIO *bio;
130 int keylen,ivlen; 150 int keylen,ivlen;
131 int jj,max; 151 int jj,max;
132 unsigned char *tmp; 152 unsigned char *tmp;
153 EVP_CIPHER_CTX *ctx;
133 154
134 if ((btmp=BIO_new(BIO_f_cipher())) == NULL) goto err; 155 if ((btmp=BIO_new(BIO_f_cipher())) == NULL)
156 {
157 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
158 goto err;
159 }
160 BIO_get_cipher_ctx(btmp, &ctx);
135 keylen=EVP_CIPHER_key_length(evp_cipher); 161 keylen=EVP_CIPHER_key_length(evp_cipher);
136 ivlen=EVP_CIPHER_iv_length(evp_cipher); 162 ivlen=EVP_CIPHER_iv_length(evp_cipher);
137
138 if (ivlen > 0)
139 {
140 ASN1_OCTET_STRING *os;
141
142 RAND_bytes(iv,ivlen);
143 os=ASN1_OCTET_STRING_new();
144 ASN1_OCTET_STRING_set(os,iv,ivlen);
145 /* ASN1_TYPE_set(xalg->parameter,V_ASN1_OCTET_STRING,
146 (char *)os);
147 */ }
148 RAND_bytes(key,keylen); 163 RAND_bytes(key,keylen);
164 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
165 if (ivlen > 0) RAND_bytes(iv,ivlen);
166 EVP_CipherInit(ctx, evp_cipher, key, iv, 1);
167
168 if (ivlen > 0) {
169 if (xalg->parameter == NULL)
170 xalg->parameter=ASN1_TYPE_new();
171 if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0)
172 goto err;
173 }
149 174
150 /* Lets do the pub key stuff :-) */ 175 /* Lets do the pub key stuff :-) */
151 max=0; 176 max=0;
152 for (i=0; i<sk_num(rsk); i++) 177 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
153 { 178 {
154 ri=(PKCS7_RECIP_INFO *)sk_value(rsk,i); 179 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
155 if (ri->cert == NULL) abort(); 180 if (ri->cert == NULL)
181 {
182 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO);
183 goto err;
184 }
156 pkey=X509_get_pubkey(ri->cert); 185 pkey=X509_get_pubkey(ri->cert);
157 jj=EVP_PKEY_size(pkey); 186 jj=EVP_PKEY_size(pkey);
187 EVP_PKEY_free(pkey);
158 if (max < jj) max=jj; 188 if (max < jj) max=jj;
159 } 189 }
160 if ((tmp=(unsigned char *)Malloc(max)) == NULL) abort(); 190 if ((tmp=(unsigned char *)Malloc(max)) == NULL)
161 for (i=0; i<sk_num(rsk); i++)
162 { 191 {
163 ri=(PKCS7_RECIP_INFO *)sk_value(rsk,i); 192 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_MALLOC_FAILURE);
193 goto err;
194 }
195 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
196 {
197 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
164 pkey=X509_get_pubkey(ri->cert); 198 pkey=X509_get_pubkey(ri->cert);
165 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey); 199 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
166 if (jj <= 0) abort(); 200 EVP_PKEY_free(pkey);
201 if (jj <= 0)
202 {
203 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB);
204 Free(tmp);
205 goto err;
206 }
167 ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj); 207 ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj);
168 } 208 }
169 209 Free(tmp);
170 BIO_set_cipher(btmp,evp_cipher,key,iv,1); 210 memset(key, 0, keylen);
171 211
172 if (out == NULL) 212 if (out == NULL)
173 out=btmp; 213 out=btmp;
174 else 214 else
175 BIO_push(out,btmp); 215 BIO_push(out,btmp);
216 btmp=NULL;
176 } 217 }
177 218
178 if (bio == NULL) /* ??????????? */ 219 if (bio == NULL) /* ??????????? */
@@ -182,6 +223,11 @@ BIO *bio;
182 else 223 else
183 { 224 {
184 bio=BIO_new(BIO_s_mem()); 225 bio=BIO_new(BIO_s_mem());
226 /* We need to set this so that when we have read all
227 * the data, the encrypt BIO, if present, will read
228 * EOF and encode the last few bytes */
229 BIO_set_mem_eof_return(bio,0);
230
185 if (PKCS7_type_is_signed(p7) && 231 if (PKCS7_type_is_signed(p7) &&
186 PKCS7_type_is_data(p7->d.sign->contents)) 232 PKCS7_type_is_data(p7->d.sign->contents))
187 { 233 {
@@ -195,14 +241,222 @@ BIO *bio;
195 } 241 }
196 } 242 }
197 BIO_push(out,bio); 243 BIO_push(out,bio);
244 bio=NULL;
245 if (0)
246 {
247err:
248 if (out != NULL)
249 BIO_free_all(out);
250 if (btmp != NULL)
251 BIO_free_all(btmp);
252 out=NULL;
253 }
198 return(out); 254 return(out);
255 }
256
257/* int */
258BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
259 {
260 int i,j;
261 BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
262 char *tmp=NULL;
263 X509_ALGOR *xa;
264 ASN1_OCTET_STRING *data_body=NULL;
265 const EVP_MD *evp_md;
266 const EVP_CIPHER *evp_cipher=NULL;
267 EVP_CIPHER_CTX *evp_ctx=NULL;
268 X509_ALGOR *enc_alg=NULL;
269 STACK_OF(X509_ALGOR) *md_sk=NULL;
270 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
271 X509_ALGOR *xalg=NULL;
272 PKCS7_RECIP_INFO *ri=NULL;
273/* EVP_PKEY *pkey; */
274#if 0
275 X509_STORE_CTX s_ctx;
276#endif
277
278 i=OBJ_obj2nid(p7->type);
279 p7->state=PKCS7_S_HEADER;
280
281 switch (i)
282 {
283 case NID_pkcs7_signed:
284 data_body=p7->d.sign->contents->d.data;
285 md_sk=p7->d.sign->md_algs;
286 break;
287 case NID_pkcs7_signedAndEnveloped:
288 rsk=p7->d.signed_and_enveloped->recipientinfo;
289 md_sk=p7->d.signed_and_enveloped->md_algs;
290 data_body=p7->d.signed_and_enveloped->enc_data->enc_data;
291 enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;
292 evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm)));
293 if (evp_cipher == NULL)
294 {
295 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
296 goto err;
297 }
298 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
299 break;
300 case NID_pkcs7_enveloped:
301 rsk=p7->d.enveloped->recipientinfo;
302 enc_alg=p7->d.enveloped->enc_data->algorithm;
303 data_body=p7->d.enveloped->enc_data->enc_data;
304 evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm)));
305 if (evp_cipher == NULL)
306 {
307 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
308 goto err;
309 }
310 xalg=p7->d.enveloped->enc_data->algorithm;
311 break;
312 default:
313 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
314 goto err;
315 }
316
317 /* We will be checking the signature */
318 if (md_sk != NULL)
319 {
320 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
321 {
322 xa=sk_X509_ALGOR_value(md_sk,i);
323 if ((btmp=BIO_new(BIO_f_md())) == NULL)
324 {
325 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
326 goto err;
327 }
328
329 j=OBJ_obj2nid(xa->algorithm);
330 evp_md=EVP_get_digestbyname(OBJ_nid2sn(j));
331 if (evp_md == NULL)
332 {
333 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);
334 goto err;
335 }
336
337 BIO_set_md(btmp,evp_md);
338 if (out == NULL)
339 out=btmp;
340 else
341 BIO_push(out,btmp);
342 btmp=NULL;
343 }
344 }
345
346 if (evp_cipher != NULL)
347 {
348#if 0
349 unsigned char key[EVP_MAX_KEY_LENGTH];
350 unsigned char iv[EVP_MAX_IV_LENGTH];
351 unsigned char *p;
352 int keylen,ivlen;
353 int max;
354 X509_OBJECT ret;
355#endif
356 int jj;
357
358 if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
359 {
360 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
361 goto err;
362 }
363
364 /* It was encrypted, we need to decrypt the secret key
365 * with the private key */
366
367 /* Find the recipientInfo which matches the passed certificate
368 * (if any)
369 */
370
371 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
372 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
373 if(!X509_NAME_cmp(ri->issuer_and_serial->issuer,
374 pcert->cert_info->issuer) &&
375 !ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
376 ri->issuer_and_serial->serial)) break;
377 ri=NULL;
378 }
379 if (ri == NULL) {
380 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
381 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
382 return(NULL);
383 }
384
385 jj=EVP_PKEY_size(pkey);
386 tmp=Malloc(jj+10);
387 if (tmp == NULL)
388 {
389 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);
390 goto err;
391 }
392
393 jj=EVP_PKEY_decrypt((unsigned char *)tmp,
394 ASN1_STRING_data(ri->enc_key),
395 ASN1_STRING_length(ri->enc_key),
396 pkey);
397 if (jj <= 0)
398 {
399 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);
400 goto err;
401 }
402
403 evp_ctx=NULL;
404 BIO_get_cipher_ctx(etmp,&evp_ctx);
405 EVP_CipherInit(evp_ctx,evp_cipher,NULL,NULL,0);
406 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
407 return(NULL);
408
409 if (jj != EVP_CIPHER_CTX_key_length(evp_ctx))
410 {
411 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
412 PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);
413 goto err;
414 }
415 EVP_CipherInit(evp_ctx,NULL,(unsigned char *)tmp,NULL,0);
416
417 memset(tmp,0,jj);
418
419 if (out == NULL)
420 out=etmp;
421 else
422 BIO_push(out,etmp);
423 etmp=NULL;
424 }
425
426#if 1
427 if (p7->detached || (in_bio != NULL))
428 {
429 bio=in_bio;
430 }
431 else
432 {
433 bio=BIO_new(BIO_s_mem());
434 /* We need to set this so that when we have read all
435 * the data, the encrypt BIO, if present, will read
436 * EOF and encode the last few bytes */
437 BIO_set_mem_eof_return(bio,0);
438
439 if (data_body->length > 0)
440 BIO_write(bio,(char *)data_body->data,data_body->length);
441 }
442 BIO_push(out,bio);
443 bio=NULL;
444#endif
445 if (0)
446 {
199err: 447err:
200 return(NULL); 448 if (out != NULL) BIO_free_all(out);
449 if (btmp != NULL) BIO_free_all(btmp);
450 if (etmp != NULL) BIO_free_all(etmp);
451 if (bio != NULL) BIO_free_all(bio);
452 out=NULL;
453 }
454 if (tmp != NULL)
455 Free(tmp);
456 return(out);
201 } 457 }
202 458
203int PKCS7_dataSign(p7,bio) 459int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
204PKCS7 *p7;
205BIO *bio;
206 { 460 {
207 int ret=0; 461 int ret=0;
208 int i,j; 462 int i,j;
@@ -211,7 +465,8 @@ BIO *bio;
211 BUF_MEM *buf=NULL; 465 BUF_MEM *buf=NULL;
212 PKCS7_SIGNER_INFO *si; 466 PKCS7_SIGNER_INFO *si;
213 EVP_MD_CTX *mdc,ctx_tmp; 467 EVP_MD_CTX *mdc,ctx_tmp;
214 STACK *sk,*si_sk=NULL; 468 STACK_OF(X509_ATTRIBUTE) *sk;
469 STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL;
215 unsigned char *p,*pp=NULL; 470 unsigned char *p,*pp=NULL;
216 int x; 471 int x;
217 ASN1_OCTET_STRING *os=NULL; 472 ASN1_OCTET_STRING *os=NULL;
@@ -227,22 +482,35 @@ BIO *bio;
227 os=ASN1_OCTET_STRING_new(); 482 os=ASN1_OCTET_STRING_new();
228 p7->d.signed_and_enveloped->enc_data->enc_data=os; 483 p7->d.signed_and_enveloped->enc_data->enc_data=os;
229 break; 484 break;
485 case NID_pkcs7_enveloped:
486 /* XXXXXXXXXXXXXXXX */
487 os=ASN1_OCTET_STRING_new();
488 p7->d.enveloped->enc_data->enc_data=os;
489 break;
230 case NID_pkcs7_signed: 490 case NID_pkcs7_signed:
231 si_sk=p7->d.sign->signer_info; 491 si_sk=p7->d.sign->signer_info;
232 os=p7->d.sign->contents->d.data; 492 os=p7->d.sign->contents->d.data;
493 /* If detached data then the content is excluded */
494 if(p7->detached) {
495 ASN1_OCTET_STRING_free(os);
496 p7->d.sign->contents->d.data = NULL;
497 }
233 break; 498 break;
234 } 499 }
235 500
236 if (si_sk != NULL) 501 if (si_sk != NULL)
237 { 502 {
238 if ((buf=BUF_MEM_new()) == NULL) goto err; 503 if ((buf=BUF_MEM_new()) == NULL)
239 for (i=0; i<sk_num(si_sk); i++) 504 {
505 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
506 goto err;
507 }
508 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
240 { 509 {
241 si=(PKCS7_SIGNER_INFO *) 510 si=sk_PKCS7_SIGNER_INFO_value(si_sk,i);
242 sk_value(si_sk,i); 511 if (si->pkey == NULL) continue;
243 if (si->pkey == NULL) 512
244 continue; 513 j=OBJ_obj2nid(si->digest_alg->algorithm);
245 j=OBJ_obj2nid(si->digest_enc_alg->algorithm);
246 514
247 btmp=bio; 515 btmp=bio;
248 for (;;) 516 for (;;)
@@ -259,7 +527,7 @@ BIO *bio;
259 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR); 527 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR);
260 goto err; 528 goto err;
261 } 529 }
262 if (EVP_MD_pkey_type(EVP_MD_CTX_type(mdc)) == j) 530 if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == j)
263 break; 531 break;
264 else 532 else
265 btmp=btmp->next_bio; 533 btmp=btmp->next_bio;
@@ -269,75 +537,117 @@ BIO *bio;
269 * signing. */ 537 * signing. */
270 memcpy(&ctx_tmp,mdc,sizeof(ctx_tmp)); 538 memcpy(&ctx_tmp,mdc,sizeof(ctx_tmp));
271 if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey))) 539 if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey)))
540 {
541 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
272 goto err; 542 goto err;
543 }
273 544
274 sk=si->auth_attr; 545 sk=si->auth_attr;
275 if ((sk != NULL) && (sk_num(sk) != 0)) 546
547 /* If there are attributes, we add the digest
548 * attribute and only sign the attributes */
549 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
276 { 550 {
277 x=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE, 551 unsigned char md_data[EVP_MAX_MD_SIZE];
278 V_ASN1_SET,V_ASN1_UNIVERSAL); 552 unsigned int md_len;
279 pp=(unsigned char *)Malloc(i); 553 ASN1_OCTET_STRING *digest;
554 ASN1_UTCTIME *sign_time;
555 const EVP_MD *md_tmp;
556
557 /* Add signing time */
558 sign_time=X509_gmtime_adj(NULL,0);
559 PKCS7_add_signed_attribute(si,
560 NID_pkcs9_signingTime,
561 V_ASN1_UTCTIME,sign_time);
562
563 /* Add digest */
564 md_tmp=EVP_MD_CTX_type(&ctx_tmp);
565 EVP_DigestFinal(&ctx_tmp,md_data,&md_len);
566 digest=ASN1_OCTET_STRING_new();
567 ASN1_OCTET_STRING_set(digest,md_data,md_len);
568 PKCS7_add_signed_attribute(si,
569 NID_pkcs9_messageDigest,
570 V_ASN1_OCTET_STRING,digest);
571
572 /* Now sign the mess */
573 EVP_SignInit(&ctx_tmp,md_tmp);
574 x=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,
575 i2d_X509_ATTRIBUTE,
576 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
577 pp=(unsigned char *)Malloc(x);
280 p=pp; 578 p=pp;
281 i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE, 579 i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,
282 V_ASN1_SET,V_ASN1_UNIVERSAL); 580 i2d_X509_ATTRIBUTE,
581 V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET);
283 EVP_SignUpdate(&ctx_tmp,pp,x); 582 EVP_SignUpdate(&ctx_tmp,pp,x);
284 Free(pp); 583 Free(pp);
584 pp=NULL;
285 } 585 }
286 586
587 if (si->pkey->type == EVP_PKEY_DSA)
588 ctx_tmp.digest=EVP_dss1();
589
287 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data, 590 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data,
288 (unsigned int *)&buf->length,si->pkey)) 591 (unsigned int *)&buf->length,si->pkey))
592 {
593 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_EVP_LIB);
289 goto err; 594 goto err;
595 }
290 if (!ASN1_STRING_set(si->enc_digest, 596 if (!ASN1_STRING_set(si->enc_digest,
291 (unsigned char *)buf->data,buf->length)) 597 (unsigned char *)buf->data,buf->length))
292 goto err;
293 }
294 if (p7->detached)
295 ASN1_OCTET_STRING_set(os,(unsigned char *)"",0);
296 else
297 {
298 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
299 if (btmp == NULL)
300 { 598 {
301 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO); 599 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_ASN1_LIB);
302 goto err; 600 goto err;
303 } 601 }
304 BIO_get_mem_ptr(btmp,&buf_mem);
305 ASN1_OCTET_STRING_set(os,
306 (unsigned char *)buf_mem->data,buf_mem->length);
307 } 602 }
308 if (pp != NULL) Free(pp);
309 pp=NULL;
310 } 603 }
311 604
605 if (!p7->detached)
606 {
607 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
608 if (btmp == NULL)
609 {
610 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
611 goto err;
612 }
613 BIO_get_mem_ptr(btmp,&buf_mem);
614 ASN1_OCTET_STRING_set(os,
615 (unsigned char *)buf_mem->data,buf_mem->length);
616 }
617 if (pp != NULL) Free(pp);
618 pp=NULL;
619
312 ret=1; 620 ret=1;
313err: 621err:
314 if (buf != NULL) BUF_MEM_free(buf); 622 if (buf != NULL) BUF_MEM_free(buf);
315 return(ret); 623 return(ret);
316 } 624 }
317 625
318int PKCS7_dataVerify(cert_store,ctx,bio,p7,si) 626int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
319X509_STORE *cert_store; 627 PKCS7 *p7, PKCS7_SIGNER_INFO *si)
320X509_STORE_CTX *ctx;
321BIO *bio;
322PKCS7 *p7;
323PKCS7_SIGNER_INFO *si;
324 { 628 {
325 PKCS7_SIGNED *s;
326 ASN1_OCTET_STRING *os;
327 EVP_MD_CTX mdc_tmp,*mdc;
328 unsigned char *pp,*p;
329 PKCS7_ISSUER_AND_SERIAL *ias; 629 PKCS7_ISSUER_AND_SERIAL *ias;
330 int ret=0,md_type,i; 630 int ret=0,i;
331 STACK *sk; 631 STACK_OF(X509) *cert;
332 BIO *btmp;
333 X509 *x509; 632 X509 *x509;
334 633
335 if (!PKCS7_type_is_signed(p7)) abort(); 634 if (PKCS7_type_is_signed(p7))
635 {
636 cert=p7->d.sign->cert;
637 }
638 else if (PKCS7_type_is_signedAndEnveloped(p7))
639 {
640 cert=p7->d.signed_and_enveloped->cert;
641 }
642 else
643 {
644 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE);
645 goto err;
646 }
336 /* XXXXXXXXXXXXXXXXXXXXXXX */ 647 /* XXXXXXXXXXXXXXXXXXXXXXX */
337 ias=si->issuer_and_serial; 648 ias=si->issuer_and_serial;
338 s=p7->d.sign;
339 649
340 x509=X509_find_by_issuer_and_serial(s->cert,ias->issuer,ias->serial); 650 x509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial);
341 651
342 /* were we able to find the cert in passed to us */ 652 /* were we able to find the cert in passed to us */
343 if (x509 == NULL) 653 if (x509 == NULL)
@@ -347,12 +657,39 @@ PKCS7_SIGNER_INFO *si;
347 } 657 }
348 658
349 /* Lets verify */ 659 /* Lets verify */
350 X509_STORE_CTX_init(ctx,cert_store,x509,s->cert); 660 X509_STORE_CTX_init(ctx,cert_store,x509,cert);
351 i=X509_verify_cert(ctx); 661 i=X509_verify_cert(ctx);
352 if (i <= 0) goto err; 662 if (i <= 0)
663 {
664 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
665 goto err;
666 }
353 X509_STORE_CTX_cleanup(ctx); 667 X509_STORE_CTX_cleanup(ctx);
354 668
355 /* So we like 'x509', lets check the signature. */ 669 return PKCS7_signatureVerify(bio, p7, si, x509);
670 err:
671 return ret;
672 }
673
674int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
675 X509 *x509)
676 {
677 ASN1_OCTET_STRING *os;
678 EVP_MD_CTX mdc_tmp,*mdc;
679 unsigned char *pp,*p;
680 int ret=0,i;
681 int md_type;
682 STACK_OF(X509_ATTRIBUTE) *sk;
683 BIO *btmp;
684 EVP_PKEY *pkey;
685
686 if (!PKCS7_type_is_signed(p7) &&
687 !PKCS7_type_is_signedAndEnveloped(p7)) {
688 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
689 PKCS7_R_WRONG_PKCS7_TYPE);
690 goto err;
691 }
692
356 md_type=OBJ_obj2nid(si->digest_alg->algorithm); 693 md_type=OBJ_obj2nid(si->digest_alg->algorithm);
357 694
358 btmp=bio; 695 btmp=bio;
@@ -361,13 +698,15 @@ PKCS7_SIGNER_INFO *si;
361 if ((btmp == NULL) || 698 if ((btmp == NULL) ||
362 ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL)) 699 ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))
363 { 700 {
364 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); 701 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
702 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
365 goto err; 703 goto err;
366 } 704 }
367 BIO_get_md_ctx(btmp,&mdc); 705 BIO_get_md_ctx(btmp,&mdc);
368 if (mdc == NULL) 706 if (mdc == NULL)
369 { 707 {
370 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_INTERNAL_ERROR); 708 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
709 PKCS7_R_INTERNAL_ERROR);
371 goto err; 710 goto err;
372 } 711 }
373 if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type) 712 if (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type)
@@ -375,28 +714,68 @@ PKCS7_SIGNER_INFO *si;
375 btmp=btmp->next_bio; 714 btmp=btmp->next_bio;
376 } 715 }
377 716
378 /* mdc is the digest ctx that we want */ 717 /* mdc is the digest ctx that we want, unless there are attributes,
718 * in which case the digest is the signed attributes */
379 memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp)); 719 memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp));
380 720
381 sk=si->auth_attr; 721 sk=si->auth_attr;
382 if ((sk != NULL) && (sk_num(sk) != 0)) 722 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
383 { 723 {
384 i=i2d_ASN1_SET(sk,NULL,i2d_X509_ATTRIBUTE, 724 unsigned char md_dat[EVP_MAX_MD_SIZE];
385 V_ASN1_SET,V_ASN1_UNIVERSAL); 725 unsigned int md_len;
386 pp=(unsigned char *)malloc(i); 726 ASN1_OCTET_STRING *message_digest;
727
728 EVP_DigestFinal(&mdc_tmp,md_dat,&md_len);
729 message_digest=PKCS7_digest_from_attributes(sk);
730 if (!message_digest)
731 {
732 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
733 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
734 goto err;
735 }
736 if ((message_digest->length != (int)md_len) ||
737 (memcmp(message_digest->data,md_dat,md_len)))
738 {
739#if 0
740{
741int ii;
742for (ii=0; ii<message_digest->length; ii++)
743 printf("%02X",message_digest->data[ii]); printf(" sent\n");
744for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
745}
746#endif
747 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
748 PKCS7_R_DIGEST_FAILURE);
749 ret= -1;
750 goto err;
751 }
752
753 EVP_VerifyInit(&mdc_tmp,EVP_get_digestbynid(md_type));
754 /* Note: when forming the encoding of the attributes we
755 * shouldn't reorder them or this will break the signature.
756 * This is done by using the IS_SEQUENCE flag.
757 */
758 i=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,i2d_X509_ATTRIBUTE,
759 V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);
760 pp=Malloc(i);
387 p=pp; 761 p=pp;
388 i2d_ASN1_SET(sk,&p,i2d_X509_ATTRIBUTE, 762 i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,i2d_X509_ATTRIBUTE,
389 V_ASN1_SET,V_ASN1_UNIVERSAL); 763 V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);
390 EVP_VerifyUpdate(&mdc_tmp,pp,i); 764 EVP_VerifyUpdate(&mdc_tmp,pp,i);
391 free(pp); 765
766 Free(pp);
392 } 767 }
393 768
394 os=si->enc_digest; 769 os=si->enc_digest;
395 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, 770 pkey = X509_get_pubkey(x509);
396 X509_get_pubkey(x509)); 771 if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();
772
773 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);
774 EVP_PKEY_free(pkey);
397 if (i <= 0) 775 if (i <= 0)
398 { 776 {
399 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_SIGNATURE_FAILURE); 777 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
778 PKCS7_R_SIGNATURE_FAILURE);
400 ret= -1; 779 ret= -1;
401 goto err; 780 goto err;
402 } 781 }
@@ -406,3 +785,138 @@ err:
406 return(ret); 785 return(ret);
407 } 786 }
408 787
788PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx)
789 {
790 STACK_OF(PKCS7_RECIP_INFO) *rsk;
791 PKCS7_RECIP_INFO *ri;
792 int i;
793
794 i=OBJ_obj2nid(p7->type);
795 if (i != NID_pkcs7_signedAndEnveloped) return(NULL);
796 rsk=p7->d.signed_and_enveloped->recipientinfo;
797 ri=sk_PKCS7_RECIP_INFO_value(rsk,0);
798 if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL);
799 ri=sk_PKCS7_RECIP_INFO_value(rsk,idx);
800 return(ri->issuer_and_serial);
801 }
802
803ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid)
804 {
805 return(get_attribute(si->auth_attr,nid));
806 }
807
808ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
809 {
810 return(get_attribute(si->unauth_attr,nid));
811 }
812
813static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid)
814 {
815 int i;
816 X509_ATTRIBUTE *xa;
817 ASN1_OBJECT *o;
818
819 o=OBJ_nid2obj(nid);
820 if (!o || !sk) return(NULL);
821 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
822 {
823 xa=sk_X509_ATTRIBUTE_value(sk,i);
824 if (OBJ_cmp(xa->object,o) == 0)
825 {
826 if (xa->set && sk_ASN1_TYPE_num(xa->value.set))
827 return(sk_ASN1_TYPE_value(xa->value.set,0));
828 else
829 return(NULL);
830 }
831 }
832 return(NULL);
833 }
834
835ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
836{
837 ASN1_TYPE *astype;
838 if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL;
839 return astype->value.octet_string;
840}
841
842int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
843 STACK_OF(X509_ATTRIBUTE) *sk)
844 {
845 int i;
846
847 if (p7si->auth_attr != NULL)
848 sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
849 p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk);
850 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
851 {
852 if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i,
853 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
854 == NULL)
855 return(0);
856 }
857 return(1);
858 }
859
860int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk)
861 {
862 int i;
863
864 if (p7si->unauth_attr != NULL)
865 sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr,
866 X509_ATTRIBUTE_free);
867 p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk);
868 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
869 {
870 if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i,
871 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
872 == NULL)
873 return(0);
874 }
875 return(1);
876 }
877
878int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
879 void *value)
880 {
881 return(add_attribute(&(p7si->auth_attr),nid,atrtype,value));
882 }
883
884int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
885 void *value)
886 {
887 return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value));
888 }
889
890static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
891 void *value)
892 {
893 X509_ATTRIBUTE *attr=NULL;
894
895 if (*sk == NULL)
896 {
897 *sk = sk_X509_ATTRIBUTE_new(NULL);
898new_attrib:
899 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
900 sk_X509_ATTRIBUTE_push(*sk,attr);
901 }
902 else
903 {
904 int i;
905
906 for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++)
907 {
908 attr=sk_X509_ATTRIBUTE_value(*sk,i);
909 if (OBJ_obj2nid(attr->object) == nid)
910 {
911 X509_ATTRIBUTE_free(attr);
912 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
913 sk_X509_ATTRIBUTE_set(*sk,i,attr);
914 goto end;
915 }
916 }
917 goto new_attrib;
918 }
919end:
920 return(1);
921 }
922
diff --git a/src/lib/libcrypto/pkcs7/pk7_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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "rand.h" 62#include <openssl/rand.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "pkcs7.h" 65#include <openssl/pkcs7.h>
66 66
67PKCS7_in_bio(PKCS7 *p7,BIO *in); 67PKCS7_in_bio(PKCS7 *p7,BIO *in);
68PKCS7_out_bio(PKCS7 *p7,BIO *out); 68PKCS7_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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "objects.h" 61#include <openssl/objects.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64long PKCS7_ctrl(p7,cmd,larg,parg) 64long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
65PKCS7 *p7;
66int cmd;
67long larg;
68char *parg;
69 { 65 {
70 int nid; 66 int nid;
71 long ret; 67 long ret;
@@ -98,14 +94,13 @@ char *parg;
98 94
99 break; 95 break;
100 default: 96 default:
101 abort(); 97 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_UNKNOWN_OPERATION);
98 ret=0;
102 } 99 }
103 return(ret); 100 return(ret);
104 } 101 }
105 102
106int PKCS7_content_new(p7,type) 103int PKCS7_content_new(PKCS7 *p7, int type)
107PKCS7 *p7;
108int type;
109 { 104 {
110 PKCS7 *ret=NULL; 105 PKCS7 *ret=NULL;
111 106
@@ -119,9 +114,7 @@ err:
119 return(0); 114 return(0);
120 } 115 }
121 116
122int PKCS7_set_content(p7,p7_data) 117int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data)
123PKCS7 *p7;
124PKCS7 *p7_data;
125 { 118 {
126 int i; 119 int i;
127 120
@@ -147,9 +140,7 @@ err:
147 return(0); 140 return(0);
148 } 141 }
149 142
150int PKCS7_set_type(p7,type) 143int PKCS7_set_type(PKCS7 *p7, int type)
151PKCS7 *p7;
152int type;
153 { 144 {
154 ASN1_OBJECT *obj; 145 ASN1_OBJECT *obj;
155 146
@@ -172,12 +163,19 @@ int type;
172 case NID_pkcs7_signedAndEnveloped: 163 case NID_pkcs7_signedAndEnveloped:
173 p7->type=obj; 164 p7->type=obj;
174 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new()) 165 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new())
175 == NULL) 166 == NULL) goto err;
176 goto err; 167 ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1);
177 ASN1_INTEGER_set(p7->d.sign->version,1); 168/* p7->d.signed_and_enveloped->enc_data->content_type=
169 OBJ_nid2obj(NID_pkcs7_encrypted);*/
170
178 break; 171 break;
179 case NID_pkcs7_digest:
180 case NID_pkcs7_enveloped: 172 case NID_pkcs7_enveloped:
173 p7->type=obj;
174 if ((p7->d.enveloped=PKCS7_ENVELOPE_new())
175 == NULL) goto err;
176 ASN1_INTEGER_set(p7->d.enveloped->version,0);
177 break;
178 case NID_pkcs7_digest:
181 case NID_pkcs7_encrypted: 179 case NID_pkcs7_encrypted:
182 default: 180 default:
183 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); 181 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
@@ -188,14 +186,12 @@ err:
188 return(0); 186 return(0);
189 } 187 }
190 188
191int PKCS7_add_signer(p7,psi) 189int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
192PKCS7 *p7;
193PKCS7_SIGNER_INFO *psi;
194 { 190 {
195 int i,j,nid; 191 int i,j,nid;
196 X509_ALGOR *alg; 192 X509_ALGOR *alg;
197 STACK *signer_sk; 193 STACK_OF(PKCS7_SIGNER_INFO) *signer_sk;
198 STACK *md_sk; 194 STACK_OF(X509_ALGOR) *md_sk;
199 195
200 i=OBJ_obj2nid(p7->type); 196 i=OBJ_obj2nid(p7->type);
201 switch (i) 197 switch (i)
@@ -217,9 +213,9 @@ PKCS7_SIGNER_INFO *psi;
217 213
218 /* If the digest is not currently listed, add it */ 214 /* If the digest is not currently listed, add it */
219 j=0; 215 j=0;
220 for (i=0; i<sk_num(md_sk); i++) 216 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
221 { 217 {
222 alg=(X509_ALGOR *)sk_value(md_sk,i); 218 alg=sk_X509_ALGOR_value(md_sk,i);
223 if (OBJ_obj2nid(alg->algorithm) == nid) 219 if (OBJ_obj2nid(alg->algorithm) == nid)
224 { 220 {
225 j=1; 221 j=1;
@@ -230,19 +226,17 @@ PKCS7_SIGNER_INFO *psi;
230 { 226 {
231 alg=X509_ALGOR_new(); 227 alg=X509_ALGOR_new();
232 alg->algorithm=OBJ_nid2obj(nid); 228 alg->algorithm=OBJ_nid2obj(nid);
233 sk_push(md_sk,(char *)alg); 229 sk_X509_ALGOR_push(md_sk,alg);
234 } 230 }
235 231
236 sk_push(signer_sk,(char *)psi); 232 sk_PKCS7_SIGNER_INFO_push(signer_sk,psi);
237 return(1); 233 return(1);
238 } 234 }
239 235
240int PKCS7_add_certificate(p7,x509) 236int PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
241PKCS7 *p7;
242X509 *x509;
243 { 237 {
244 int i; 238 int i;
245 STACK **sk; 239 STACK_OF(X509) **sk;
246 240
247 i=OBJ_obj2nid(p7->type); 241 i=OBJ_obj2nid(p7->type);
248 switch (i) 242 switch (i)
@@ -259,18 +253,16 @@ X509 *x509;
259 } 253 }
260 254
261 if (*sk == NULL) 255 if (*sk == NULL)
262 *sk=sk_new_null(); 256 *sk=sk_X509_new_null();
263 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); 257 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
264 sk_push(*sk,(char *)x509); 258 sk_X509_push(*sk,x509);
265 return(1); 259 return(1);
266 } 260 }
267 261
268int PKCS7_add_crl(p7,crl) 262int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
269PKCS7 *p7;
270X509_CRL *crl;
271 { 263 {
272 int i; 264 int i;
273 STACK **sk; 265 STACK_OF(X509_CRL) **sk;
274 266
275 i=OBJ_obj2nid(p7->type); 267 i=OBJ_obj2nid(p7->type);
276 switch (i) 268 switch (i)
@@ -287,18 +279,15 @@ X509_CRL *crl;
287 } 279 }
288 280
289 if (*sk == NULL) 281 if (*sk == NULL)
290 *sk=sk_new_null(); 282 *sk=sk_X509_CRL_new_null();
291 283
292 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL); 284 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL);
293 sk_push(*sk,(char *)crl); 285 sk_X509_CRL_push(*sk,crl);
294 return(1); 286 return(1);
295 } 287 }
296 288
297int PKCS7_SIGNER_INFO_set(p7i,x509,pkey,dgst) 289int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
298PKCS7_SIGNER_INFO *p7i; 290 EVP_MD *dgst)
299X509 *x509;
300EVP_PKEY *pkey;
301EVP_MD *dgst;
302 { 291 {
303 /* We now need to add another PKCS7_SIGNER_INFO entry */ 292 /* We now need to add another PKCS7_SIGNER_INFO entry */
304 ASN1_INTEGER_set(p7i->version,1); 293 ASN1_INTEGER_set(p7i->version,1);
@@ -316,27 +305,32 @@ EVP_MD *dgst;
316 p7i->pkey=pkey; 305 p7i->pkey=pkey;
317 306
318 /* Set the algorithms */ 307 /* Set the algorithms */
319 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst)); 308 if (pkey->type == EVP_PKEY_DSA)
320 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_MD_pkey_type(dgst)); 309 p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1);
310 else
311 p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst));
312
313 if (p7i->digest_alg->parameter != NULL)
314 ASN1_TYPE_free(p7i->digest_alg->parameter);
315 if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL)
316 goto err;
317 p7i->digest_alg->parameter->type=V_ASN1_NULL;
318
319 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type));
321 320
322#if 1
323 if (p7i->digest_enc_alg->parameter != NULL) 321 if (p7i->digest_enc_alg->parameter != NULL)
324 ASN1_TYPE_free(p7i->digest_enc_alg->parameter); 322 ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
325 if ((p7i->digest_enc_alg->parameter=ASN1_TYPE_new()) == NULL) 323 if ((p7i->digest_enc_alg->parameter=ASN1_TYPE_new()) == NULL)
326 goto err; 324 goto err;
327 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL; 325 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
328#endif
329 326
330 return(1); 327 return(1);
331err: 328err:
332 return(0); 329 return(0);
333 } 330 }
334 331
335PKCS7_SIGNER_INFO *PKCS7_add_signature(p7,x509,pkey,dgst) 332PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
336PKCS7 *p7; 333 EVP_MD *dgst)
337X509 *x509;
338EVP_PKEY *pkey;
339EVP_MD *dgst;
340 { 334 {
341 PKCS7_SIGNER_INFO *si; 335 PKCS7_SIGNER_INFO *si;
342 336
@@ -348,20 +342,21 @@ err:
348 return(NULL); 342 return(NULL);
349 } 343 }
350 344
351STACK *PKCS7_get_signer_info(p7) 345STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
352PKCS7 *p7;
353 { 346 {
354 if (PKCS7_type_is_signed(p7)) 347 if (PKCS7_type_is_signed(p7))
355 { 348 {
356 return(p7->d.sign->signer_info); 349 return(p7->d.sign->signer_info);
357 } 350 }
351 else if (PKCS7_type_is_signedAndEnveloped(p7))
352 {
353 return(p7->d.signed_and_enveloped->signer_info);
354 }
358 else 355 else
359 return(NULL); 356 return(NULL);
360 } 357 }
361 358
362PKCS7_RECIP_INFO *PKCS7_add_recipient(p7,x509) 359PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
363PKCS7 *p7;
364X509 *x509;
365 { 360 {
366 PKCS7_RECIP_INFO *ri; 361 PKCS7_RECIP_INFO *ri;
367 362
@@ -373,12 +368,10 @@ err:
373 return(NULL); 368 return(NULL);
374 } 369 }
375 370
376int PKCS7_add_recipient_info(p7,ri) 371int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
377PKCS7 *p7;
378PKCS7_RECIP_INFO *ri;
379 { 372 {
380 int i; 373 int i;
381 STACK *sk; 374 STACK_OF(PKCS7_RECIP_INFO) *sk;
382 375
383 i=OBJ_obj2nid(p7->type); 376 i=OBJ_obj2nid(p7->type);
384 switch (i) 377 switch (i)
@@ -386,18 +379,19 @@ PKCS7_RECIP_INFO *ri;
386 case NID_pkcs7_signedAndEnveloped: 379 case NID_pkcs7_signedAndEnveloped:
387 sk= p7->d.signed_and_enveloped->recipientinfo; 380 sk= p7->d.signed_and_enveloped->recipientinfo;
388 break; 381 break;
382 case NID_pkcs7_enveloped:
383 sk= p7->d.enveloped->recipientinfo;
384 break;
389 default: 385 default:
390 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE); 386 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE);
391 return(0); 387 return(0);
392 } 388 }
393 389
394 sk_push(sk,(char *)ri); 390 sk_PKCS7_RECIP_INFO_push(sk,ri);
395 return(1); 391 return(1);
396 } 392 }
397 393
398int PKCS7_RECIP_INFO_set(p7i,x509) 394int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
399PKCS7_RECIP_INFO *p7i;
400X509 *x509;
401 { 395 {
402 ASN1_INTEGER_set(p7i->version,0); 396 ASN1_INTEGER_set(p7i->version,0);
403 X509_NAME_set(&p7i->issuer_and_serial->issuer, 397 X509_NAME_set(&p7i->issuer_and_serial->issuer,
@@ -407,15 +401,18 @@ X509 *x509;
407 p7i->issuer_and_serial->serial= 401 p7i->issuer_and_serial->serial=
408 ASN1_INTEGER_dup(X509_get_serialNumber(x509)); 402 ASN1_INTEGER_dup(X509_get_serialNumber(x509));
409 403
404 X509_ALGOR_free(p7i->key_enc_algor);
405 p7i->key_enc_algor=(X509_ALGOR *)ASN1_dup(i2d_X509_ALGOR,
406 (char *(*)())d2i_X509_ALGOR,
407 (char *)x509->cert_info->key->algor);
408
410 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); 409 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
411 p7i->cert=x509; 410 p7i->cert=x509;
412 411
413 return(1); 412 return(1);
414 } 413 }
415 414
416X509 *PKCS7_cert_from_signer_info(p7,si) 415X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
417PKCS7 *p7;
418PKCS7_SIGNER_INFO *si;
419 { 416 {
420 if (PKCS7_type_is_signed(p7)) 417 if (PKCS7_type_is_signed(p7))
421 return(X509_find_by_issuer_and_serial(p7->d.sign->cert, 418 return(X509_find_by_issuer_and_serial(p7->d.sign->cert,
@@ -425,9 +422,7 @@ PKCS7_SIGNER_INFO *si;
425 return(NULL); 422 return(NULL);
426 } 423 }
427 424
428int PKCS7_set_cipher(p7,cipher) 425int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
429PKCS7 *p7;
430EVP_CIPHER *cipher;
431 { 426 {
432 int i; 427 int i;
433 PKCS7_ENC_CONTENT *ec; 428 PKCS7_ENC_CONTENT *ec;
@@ -438,12 +433,17 @@ EVP_CIPHER *cipher;
438 case NID_pkcs7_signedAndEnveloped: 433 case NID_pkcs7_signedAndEnveloped:
439 ec=p7->d.signed_and_enveloped->enc_data; 434 ec=p7->d.signed_and_enveloped->enc_data;
440 break; 435 break;
436 case NID_pkcs7_enveloped:
437 ec=p7->d.enveloped->enc_data;
438 break;
441 default: 439 default:
442 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE); 440 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE);
443 return(0); 441 return(0);
444 } 442 }
445 443
446 ec->algorithm->algorithm=OBJ_nid2obj(EVP_CIPHER_nid(cipher)); 444 /* Setup cipher OID */
447 return(ec->algorithm->algorithm != NULL); 445
446 ec->cipher = cipher;
447 return 1;
448 } 448 }
449 449
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 @@
1/* Error codes for the PKCS7 functions. */
2
3/* Function codes. */
4#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
5#define PKCS7_F_PKCS7_ADD_CRL 101
6#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
7#define PKCS7_F_PKCS7_ADD_SIGNER 103
8#define PKCS7_F_PKCS7_CTRL 104
9#define PKCS7_F_PKCS7_DATAINIT 105
10#define PKCS7_F_PKCS7_DATASIGN 106
11#define PKCS7_F_PKCS7_DATAVERIFY 107
12#define PKCS7_F_PKCS7_SET_CIPHER 108
13#define PKCS7_F_PKCS7_SET_CONTENT 109
14#define PKCS7_F_PKCS7_SET_TYPE 110
15
16/* Reason codes. */
17#define PKCS7_R_INTERNAL_ERROR 100
18#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 101
19#define PKCS7_R_SIGNATURE_FAILURE 102
20#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 103
21#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 104
22#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 105
23#define PKCS7_R_UNKNOWN_DIGEST_TYPE 106
24#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 107
25#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 108
26#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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "bio.h" 66#include <openssl/bio.h>
67#include "x509.h" 67#include <openssl/x509.h>
68
69#ifdef VMS
70#include <openssl/vms_idhacks.h>
71#endif
72
73#ifdef WIN32
74/* Under Win32 this is defined in wincrypt.h */
75#undef PKCS7_ISSUER_AND_SERIAL
76#endif
68 77
69/* 78/*
70Encryption_ID DES-CBC 79Encryption_ID DES-CBC
@@ -84,15 +93,18 @@ typedef struct pkcs7_signer_info_st
84 ASN1_INTEGER *version; /* version 1 */ 93 ASN1_INTEGER *version; /* version 1 */
85 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; 94 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
86 X509_ALGOR *digest_alg; 95 X509_ALGOR *digest_alg;
87 STACK /* X509_ATTRIBUTE */ *auth_attr; /* [ 0 ] */ 96 STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */
88 X509_ALGOR *digest_enc_alg; 97 X509_ALGOR *digest_enc_alg;
89 ASN1_OCTET_STRING *enc_digest; 98 ASN1_OCTET_STRING *enc_digest;
90 STACK /* X509_ATTRIBUTE */ *unauth_attr; /* [ 1 ] */ 99 STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */
91 100
92 /* The private key to sign with */ 101 /* The private key to sign with */
93 EVP_PKEY *pkey; 102 EVP_PKEY *pkey;
94 } PKCS7_SIGNER_INFO; 103 } PKCS7_SIGNER_INFO;
95 104
105DECLARE_STACK_OF(PKCS7_SIGNER_INFO)
106DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO)
107
96typedef struct pkcs7_recip_info_st 108typedef struct pkcs7_recip_info_st
97 { 109 {
98 ASN1_INTEGER *version; /* version 0 */ 110 ASN1_INTEGER *version; /* version 0 */
@@ -102,13 +114,16 @@ typedef struct pkcs7_recip_info_st
102 X509 *cert; /* get the pub-key from this */ 114 X509 *cert; /* get the pub-key from this */
103 } PKCS7_RECIP_INFO; 115 } PKCS7_RECIP_INFO;
104 116
117DECLARE_STACK_OF(PKCS7_RECIP_INFO)
118DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO)
119
105typedef struct pkcs7_signed_st 120typedef struct pkcs7_signed_st
106 { 121 {
107 ASN1_INTEGER *version; /* version 1 */ 122 ASN1_INTEGER *version; /* version 1 */
108 STACK /* X509_ALGOR's */ *md_algs; /* md used */ 123 STACK_OF(X509_ALGOR) *md_algs; /* md used */
109 STACK /* X509 */ *cert; /* [ 0 ] */ 124 STACK_OF(X509) *cert; /* [ 0 ] */
110 STACK /* X509_CRL */ *crl; /* [ 1 ] */ 125 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
111 STACK /* PKCS7_SIGNER_INFO */ *signer_info; 126 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
112 127
113 struct pkcs7_st *contents; 128 struct pkcs7_st *contents;
114 } PKCS7_SIGNED; 129 } PKCS7_SIGNED;
@@ -120,25 +135,26 @@ typedef struct pkcs7_enc_content_st
120 ASN1_OBJECT *content_type; 135 ASN1_OBJECT *content_type;
121 X509_ALGOR *algorithm; 136 X509_ALGOR *algorithm;
122 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */ 137 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */
138 const EVP_CIPHER *cipher;
123 } PKCS7_ENC_CONTENT; 139 } PKCS7_ENC_CONTENT;
124 140
125typedef struct pkcs7_enveloped_st 141typedef struct pkcs7_enveloped_st
126 { 142 {
127 ASN1_INTEGER *version; /* version 0 */ 143 ASN1_INTEGER *version; /* version 0 */
128 STACK /* PKCS7_RECIP_INFO */ *recipientinfo; 144 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
129 PKCS7_ENC_CONTENT *enc_data; 145 PKCS7_ENC_CONTENT *enc_data;
130 } PKCS7_ENVELOPE; 146 } PKCS7_ENVELOPE;
131 147
132typedef struct pkcs7_signedandenveloped_st 148typedef struct pkcs7_signedandenveloped_st
133 { 149 {
134 ASN1_INTEGER *version; /* version 1 */ 150 ASN1_INTEGER *version; /* version 1 */
135 STACK /* X509_ALGOR's */ *md_algs; /* md used */ 151 STACK_OF(X509_ALGOR) *md_algs; /* md used */
136 STACK /* X509 */ *cert; /* [ 0 ] */ 152 STACK_OF(X509) *cert; /* [ 0 ] */
137 STACK /* X509_CRL */ *crl; /* [ 1 ] */ 153 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
138 STACK /* PKCS7_SIGNER_INFO */ *signer_info; 154 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
139 155
140 PKCS7_ENC_CONTENT *enc_data; 156 PKCS7_ENC_CONTENT *enc_data;
141 STACK /* PKCS7_RECIP_INFO */ *recipientinfo; 157 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
142 } PKCS7_SIGN_ENVELOPE; 158 } PKCS7_SIGN_ENVELOPE;
143 159
144typedef struct pkcs7_digest_st 160typedef struct pkcs7_digest_st
@@ -199,7 +215,12 @@ typedef struct pkcs7_st
199#define PKCS7_OP_SET_DETACHED_SIGNATURE 1 215#define PKCS7_OP_SET_DETACHED_SIGNATURE 1
200#define PKCS7_OP_GET_DETACHED_SIGNATURE 2 216#define PKCS7_OP_GET_DETACHED_SIGNATURE 2
201 217
218#define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
219#define PKCS7_get_attributes(si) ((si)->unauth_attr)
220
202#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) 221#define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
222#define PKCS7_type_is_signedAndEnveloped(a) \
223 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
203#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) 224#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
204 225
205#define PKCS7_set_detached(p,v) \ 226#define PKCS7_set_detached(p,v) \
@@ -208,14 +229,14 @@ typedef struct pkcs7_st
208 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) 229 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
209 230
210#ifdef SSLEAY_MACROS 231#ifdef SSLEAY_MACROS
211 232#ifndef PKCS7_ISSUER_AND_SERIAL_digest
212#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ 233#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
213 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ 234 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
214 (char *)data,md,len) 235 (char *)data,md,len)
215#endif 236#endif
237#endif
216 238
217 239
218#ifndef NOPROTO
219PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void ); 240PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void );
220void PKCS7_ISSUER_AND_SERIAL_free( 241void PKCS7_ISSUER_AND_SERIAL_free(
221 PKCS7_ISSUER_AND_SERIAL *a); 242 PKCS7_ISSUER_AND_SERIAL *a);
@@ -229,11 +250,11 @@ PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL(
229int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,EVP_MD *type, 250int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,EVP_MD *type,
230 unsigned char *md,unsigned int *len); 251 unsigned char *md,unsigned int *len);
231#ifndef NO_FP_API 252#ifndef NO_FP_API
232PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 *p7); 253PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
233int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7); 254int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
234#endif 255#endif
235PKCS7 *PKCS7_dup(PKCS7 *p7); 256PKCS7 *PKCS7_dup(PKCS7 *p7);
236PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 *p7); 257PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
237int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7); 258int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
238#endif 259#endif
239 260
@@ -314,107 +335,45 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
314int PKCS7_add_certificate(PKCS7 *p7, X509 *x509); 335int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
315int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); 336int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
316int PKCS7_content_new(PKCS7 *p7, int nid); 337int PKCS7_content_new(PKCS7 *p7, int nid);
317int PKCS7_dataSign(PKCS7 *p7, BIO *bio);
318int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, 338int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
319 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); 339 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
340int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
341 X509 *x509);
320 342
321BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); 343BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
322/*int PKCS7_DataFinal(PKCS7 *p7, BIO *bio); */ 344int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
345BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
346
323 347
324PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, 348PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
325 EVP_PKEY *pkey, EVP_MD *dgst); 349 EVP_PKEY *pkey, EVP_MD *dgst);
326X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); 350X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
327STACK *PKCS7_get_signer_info(PKCS7 *p7); 351STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
328 352
329PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); 353PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
330int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); 354int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
331int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); 355int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
332int PKCS7_set_cipher(PKCS7 *p7, EVP_CIPHER *cipher); 356int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
333
334 357
358PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
359ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
360int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,
361 void *data);
362int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
363 void *value);
364ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
365ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
366int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
367 STACK_OF(X509_ATTRIBUTE) *sk);
368int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
335 369
336#else
337 370
338PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new();
339void PKCS7_ISSUER_AND_SERIAL_free();
340int i2d_PKCS7_ISSUER_AND_SERIAL();
341PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL();
342
343#ifndef SSLEAY_MACROS
344int PKCS7_ISSUER_AND_SERIAL_digest();
345#ifndef NO_FP_API
346PKCS7 *d2i_PKCS7_fp();
347int i2d_PKCS7_fp();
348#endif
349PKCS7 *PKCS7_dup();
350PKCS7 *d2i_PKCS7_bio();
351int i2d_PKCS7_bio();
352
353#endif
354
355PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new();
356void PKCS7_SIGNER_INFO_free();
357int i2d_PKCS7_SIGNER_INFO();
358PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO();
359PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new();
360void PKCS7_RECIP_INFO_free();
361int i2d_PKCS7_RECIP_INFO();
362PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO();
363PKCS7_SIGNED *PKCS7_SIGNED_new();
364void PKCS7_SIGNED_free();
365int i2d_PKCS7_SIGNED();
366PKCS7_SIGNED *d2i_PKCS7_SIGNED();
367PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new();
368void PKCS7_ENC_CONTENT_free();
369int i2d_PKCS7_ENC_CONTENT();
370PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT();
371PKCS7_ENVELOPE *PKCS7_ENVELOPE_new();
372void PKCS7_ENVELOPE_free();
373int i2d_PKCS7_ENVELOPE();
374PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE();
375PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new();
376void PKCS7_SIGN_ENVELOPE_free();
377int i2d_PKCS7_SIGN_ENVELOPE();
378PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE();
379PKCS7_DIGEST *PKCS7_DIGEST_new();
380void PKCS7_DIGEST_free();
381int i2d_PKCS7_DIGEST();
382PKCS7_DIGEST *d2i_PKCS7_DIGEST();
383PKCS7_ENCRYPT *PKCS7_ENCRYPT_new();
384void PKCS7_ENCRYPT_free();
385int i2d_PKCS7_ENCRYPT();
386PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT();
387PKCS7 *PKCS7_new();
388void PKCS7_free();
389void PKCS7_content_free();
390int i2d_PKCS7();
391PKCS7 *d2i_PKCS7();
392
393void ERR_load_PKCS7_strings();
394
395long PKCS7_ctrl();
396int PKCS7_set_type();
397int PKCS7_set_content();
398int PKCS7_SIGNER_INFO_set();
399int PKCS7_add_signer();
400int PKCS7_add_certificate();
401int PKCS7_add_crl();
402int PKCS7_content_new();
403int PKCS7_dataSign();
404int PKCS7_dataVerify();
405BIO *PKCS7_dataInit();
406PKCS7_SIGNER_INFO *PKCS7_add_signature();
407X509 *PKCS7_cert_from_signer_info();
408STACK *PKCS7_get_signer_info();
409
410PKCS7_RECIP_INFO *PKCS7_add_recipient();
411int PKCS7_add_recipient_info();
412int PKCS7_RECIP_INFO_set();
413int PKCS7_set_cipher();
414
415#endif
416 371
417/* BEGIN ERROR CODES */ 372/* BEGIN ERROR CODES */
373/* The following lines are auto generated by the script mkerr.pl. Any changes
374 * made after this point may be overwritten when the script is next run.
375 */
376
418/* Error codes for the PKCS7 functions. */ 377/* Error codes for the PKCS7 functions. */
419 378
420/* Function codes. */ 379/* Function codes. */
@@ -423,25 +382,34 @@ int PKCS7_set_cipher();
423#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 382#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
424#define PKCS7_F_PKCS7_ADD_SIGNER 103 383#define PKCS7_F_PKCS7_ADD_SIGNER 103
425#define PKCS7_F_PKCS7_CTRL 104 384#define PKCS7_F_PKCS7_CTRL 104
385#define PKCS7_F_PKCS7_DATADECODE 112
426#define PKCS7_F_PKCS7_DATAINIT 105 386#define PKCS7_F_PKCS7_DATAINIT 105
427#define PKCS7_F_PKCS7_DATASIGN 106 387#define PKCS7_F_PKCS7_DATASIGN 106
428#define PKCS7_F_PKCS7_DATAVERIFY 107 388#define PKCS7_F_PKCS7_DATAVERIFY 107
429#define PKCS7_F_PKCS7_SET_CIPHER 108 389#define PKCS7_F_PKCS7_SET_CIPHER 108
430#define PKCS7_F_PKCS7_SET_CONTENT 109 390#define PKCS7_F_PKCS7_SET_CONTENT 109
431#define PKCS7_F_PKCS7_SET_TYPE 110 391#define PKCS7_F_PKCS7_SET_TYPE 110
392#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
432 393
433/* Reason codes. */ 394/* Reason codes. */
434#define PKCS7_R_INTERNAL_ERROR 100 395#define PKCS7_R_CIPHER_NOT_INITIALIZED 116
435#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 101 396#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100
436#define PKCS7_R_SIGNATURE_FAILURE 102 397#define PKCS7_R_DIGEST_FAILURE 101
437#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 103 398#define PKCS7_R_INTERNAL_ERROR 102
438#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 104 399#define PKCS7_R_MISSING_CERIPEND_INFO 103
439#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 105 400#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
440#define PKCS7_R_UNKNOWN_DIGEST_TYPE 106 401#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
441#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 107 402#define PKCS7_R_SIGNATURE_FAILURE 105
442#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 108 403#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106
443#define PKCS7_R_WRONG_CONTENT_TYPE 109 404#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107
444 405#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108
406#define PKCS7_R_UNKNOWN_DIGEST_TYPE 109
407#define PKCS7_R_UNKNOWN_OPERATION 110
408#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111
409#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112
410#define PKCS7_R_WRONG_CONTENT_TYPE 113
411#define PKCS7_R_WRONG_PKCS7_TYPE 114
412
445#ifdef __cplusplus 413#ifdef __cplusplus
446} 414}
447#endif 415#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 @@
1/* lib/pkcs7/pkcs7_err.c */ 1/* crypto/pkcs7/pkcs7err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "pkcs7.h" 62#include <openssl/pkcs7.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -68,38 +70,47 @@ static ERR_STRING_DATA PKCS7_str_functs[]=
68{ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"}, 70{ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"},
69{ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"}, 71{ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"},
70{ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"}, 72{ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"},
73{ERR_PACK(0,PKCS7_F_PKCS7_DATADECODE,0), "PKCS7_dataDecode"},
71{ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"}, 74{ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"},
72{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_dataSign"}, 75{ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_DATASIGN"},
73{ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"}, 76{ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"},
74{ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"}, 77{ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"},
75{ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"}, 78{ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"},
76{ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"}, 79{ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"},
77{0,NULL}, 80{ERR_PACK(0,PKCS7_F_PKCS7_SIGNATUREVERIFY,0), "PKCS7_signatureVerify"},
81{0,NULL}
78 }; 82 };
79 83
80static ERR_STRING_DATA PKCS7_str_reasons[]= 84static ERR_STRING_DATA PKCS7_str_reasons[]=
81 { 85 {
86{PKCS7_R_CIPHER_NOT_INITIALIZED ,"cipher not initialized"},
87{PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH ,"decrypted key is wrong length"},
88{PKCS7_R_DIGEST_FAILURE ,"digest failure"},
82{PKCS7_R_INTERNAL_ERROR ,"internal error"}, 89{PKCS7_R_INTERNAL_ERROR ,"internal error"},
90{PKCS7_R_MISSING_CERIPEND_INFO ,"missing ceripend info"},
91{PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE,"no recipient matches certificate"},
83{PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"}, 92{PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"},
84{PKCS7_R_SIGNATURE_FAILURE ,"signature failure"}, 93{PKCS7_R_SIGNATURE_FAILURE ,"signature failure"},
85{PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"}, 94{PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"},
86{PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"}, 95{PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"},
87{PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"}, 96{PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"},
88{PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"}, 97{PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"},
98{PKCS7_R_UNKNOWN_OPERATION ,"unknown operation"},
89{PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"}, 99{PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"},
90{PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"}, 100{PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"},
91{PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"}, 101{PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"},
92{0,NULL}, 102{PKCS7_R_WRONG_PKCS7_TYPE ,"wrong pkcs7 type"},
103{0,NULL}
93 }; 104 };
94 105
95#endif 106#endif
96 107
97void ERR_load_PKCS7_strings() 108void ERR_load_PKCS7_strings(void)
98 { 109 {
99 static int init=1; 110 static int init=1;
100 111
101 if (init); 112 if (init)
102 {; 113 {
103 init=0; 114 init=0;
104#ifndef NO_ERR 115#ifndef NO_ERR
105 ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_functs); 116 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include "bio.h" 59#include <openssl/bio.h>
60#include "x509.h" 60#include <openssl/x509.h>
61#include "pem.h" 61#include <openssl/pem.h>
62#include <openssl/err.h>
62 63
63main(argc,argv) 64int main(argc,argv)
64int argc; 65int argc;
65char *argv[]; 66char *argv[];
66 { 67 {
67 X509 *x509; 68 X509 *x509;
68 EVP_PKEY *pkey; 69 EVP_PKEY *pkey;
69 PKCS7 *p7; 70 PKCS7 *p7;
70 PKCS7 *p7_data;
71 PKCS7_SIGNER_INFO *si; 71 PKCS7_SIGNER_INFO *si;
72 BIO *in; 72 BIO *in;
73 BIO *data,*p7bio; 73 BIO *data,*p7bio;
74 char buf[1024*4]; 74 char buf[1024*4];
75 int i,j; 75 int i;
76 int nodetach=0; 76 int nodetach=0;
77 77
78 EVP_add_digest(EVP_md2()); 78 EVP_add_digest(EVP_md2());
@@ -105,7 +105,12 @@ again:
105 p7=PKCS7_new(); 105 p7=PKCS7_new();
106 PKCS7_set_type(p7,NID_pkcs7_signed); 106 PKCS7_set_type(p7,NID_pkcs7_signed);
107 107
108 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err; 108 si=PKCS7_add_signature(p7,x509,pkey,EVP_sha1());
109 if (si == NULL) goto err;
110
111 /* If you do this then you get signing time automatically added */
112 PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, V_ASN1_OBJECT,
113 OBJ_nid2obj(NID_pkcs7_data));
109 114
110 /* we may want to add more */ 115 /* we may want to add more */
111 PKCS7_add_certificate(p7,x509); 116 PKCS7_add_certificate(p7,x509);
@@ -125,7 +130,7 @@ again:
125 BIO_write(p7bio,buf,i); 130 BIO_write(p7bio,buf,i);
126 } 131 }
127 132
128 if (!PKCS7_dataSign(p7,p7bio)) goto err; 133 if (!PKCS7_dataFinal(p7,p7bio)) goto err;
129 BIO_free(p7bio); 134 BIO_free(p7bio);
130 135
131 PEM_write_PKCS7(stdout,p7); 136 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include "asn1.h" 59#include <openssl/bio.h>
60#include "bio.h" 60#include <openssl/asn1.h>
61#include "x509.h" 61#include <openssl/x509.h>
62#include "pem.h" 62#include <openssl/pem.h>
63#include <openssl/err.h>
64#include "example.h"
63 65
64int verify_callback(int ok, X509_STORE_CTX *ctx); 66int verify_callback(int ok, X509_STORE_CTX *ctx);
65 67
66BIO *bio_err=NULL; 68BIO *bio_err=NULL;
69BIO *bio_out=NULL;
67 70
68main(argc,argv) 71int main(argc,argv)
69int argc; 72int argc;
70char *argv[]; 73char *argv[];
71 { 74 {
72 X509 *x509,*x;
73 PKCS7 *p7; 75 PKCS7 *p7;
74 PKCS7_SIGNED *s;
75 PKCS7_SIGNER_INFO *si; 76 PKCS7_SIGNER_INFO *si;
76 PKCS7_ISSUER_AND_SERIAL *ias;
77 X509_STORE_CTX cert_ctx; 77 X509_STORE_CTX cert_ctx;
78 X509_STORE *cert_store=NULL; 78 X509_STORE *cert_store=NULL;
79 X509_LOOKUP *lookup=NULL;
80 BIO *data,*detached=NULL,*p7bio=NULL; 79 BIO *data,*detached=NULL,*p7bio=NULL;
81 char buf[1024*4]; 80 char buf[1024*4];
82 unsigned char *p,*pp; 81 char *pp;
83 int i,j,printit=0; 82 int i,printit=0;
84 STACK *sk; 83 STACK_OF(PKCS7_SIGNER_INFO) *sk;
85 84
86 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); 85 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
86 bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);
87 EVP_add_digest(EVP_md2()); 87 EVP_add_digest(EVP_md2());
88 EVP_add_digest(EVP_md5()); 88 EVP_add_digest(EVP_md5());
89 EVP_add_digest(EVP_sha1()); 89 EVP_add_digest(EVP_sha1());
90 EVP_add_digest(EVP_mdc2()); 90 EVP_add_digest(EVP_mdc2());
91 91
92 data=BIO_new(BIO_s_file()); 92 data=BIO_new(BIO_s_file());
93again: 93
94 pp=NULL; 94 pp=NULL;
95 while (argc > 1) 95 while (argc > 1)
96 { 96 {
@@ -131,10 +131,10 @@ again:
131 X509_STORE_load_locations(cert_store,NULL,"../../certs"); 131 X509_STORE_load_locations(cert_store,NULL,"../../certs");
132 X509_STORE_set_verify_cb_func(cert_store,verify_callback); 132 X509_STORE_set_verify_cb_func(cert_store,verify_callback);
133 133
134 ERR_clear_errors(); 134 ERR_clear_error();
135 135
136 /* We need to process the data */ 136 /* We need to process the data */
137 if (PKCS7_get_detached(p7)) 137 if ((PKCS7_get_detached(p7) || detached))
138 { 138 {
139 if (detached == NULL) 139 if (detached == NULL)
140 { 140 {
@@ -166,12 +166,29 @@ again:
166 } 166 }
167 167
168 /* Ok, first we need to, for each subject entry, see if we can verify */ 168 /* Ok, first we need to, for each subject entry, see if we can verify */
169 for (i=0; i<sk_num(sk); i++) 169 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sk); i++)
170 { 170 {
171 si=(PKCS7_SIGNER_INFO *)sk_value(sk,i); 171 ASN1_UTCTIME *tm;
172 char *str1,*str2;
173
174 si=sk_PKCS7_SIGNER_INFO_value(sk,i);
172 i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si); 175 i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
173 if (i <= 0) 176 if (i <= 0)
174 goto err; 177 goto err;
178 printf("signer info\n");
179 if ((tm=get_signed_time(si)) != NULL)
180 {
181 BIO_printf(bio_out,"Signed time:");
182 ASN1_UTCTIME_print(bio_out,tm);
183 ASN1_UTCTIME_free(tm);
184 BIO_printf(bio_out,"\n");
185 }
186 if (get_signed_seq2string(si,&str1,&str2))
187 {
188 BIO_printf(bio_out,"String 1 is %s\n",str1);
189 BIO_printf(bio_out,"String 2 is %s\n",str2);
190 }
191
175 } 192 }
176 193
177 X509_STORE_free(cert_store); 194 X509_STORE_free(cert_store);
@@ -185,9 +202,7 @@ err:
185 } 202 }
186 203
187/* should be X509 * but we can just have them as char *. */ 204/* should be X509 * but we can just have them as char *. */
188int verify_callback(ok, ctx) 205int verify_callback(int ok, X509_STORE_CTX *ctx)
189int ok;
190X509_STORE_CTX *ctx;
191 { 206 {
192 char buf[256]; 207 char buf[256];
193 X509 *err_cert; 208 X509 *err_cert;
diff --git a/src/lib/libcrypto/rand/Makefile.ssl b/src/lib/libcrypto/rand/Makefile.ssl
index d04f0a9b43..76bfdfeae5 100644
--- a/src/lib/libcrypto/rand/Makefile.ssl
+++ b/src/lib/libcrypto/rand/Makefile.ssl
@@ -7,9 +7,11 @@ TOP= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -20,8 +22,8 @@ TEST= randtest.c
20APPS= 22APPS=
21 23
22LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
23LIBSRC=md_rand.c randfile.c 25LIBSRC=md_rand.c randfile.c rand_lib.c
24LIBOBJ=md_rand.o randfile.o 26LIBOBJ=md_rand.o randfile.o rand_lib.o
25 27
26SRC= $(LIBSRC) 28SRC= $(LIBSRC)
27 29
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,21 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81md_rand.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
82md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
83md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
84md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
85rand_lib.o: ../../include/openssl/rand.h
86randfile.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
87randfile.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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h"
61#include <sys/types.h> 60#include <sys/types.h>
62#include <time.h> 61#include <time.h>
62#include <string.h>
63
64#include "openssl/e_os.h"
65
66#include <openssl/crypto.h>
63 67
64#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND) 68#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
65#ifndef NO_MD5 69#if !defined(NO_SHA) && !defined(NO_SHA1)
66#define USE_MD5_RAND
67#elif !defined(NO_SHA1)
68#define USE_SHA1_RAND 70#define USE_SHA1_RAND
69#elif !defined(NO_MDC2) 71#elif !defined(NO_MD5)
72#define USE_MD5_RAND
73#elif !defined(NO_MDC2) && !defined(NO_DES)
70#define USE_MDC2_RAND 74#define USE_MDC2_RAND
71#elif !defined(NO_MD2) 75#elif !defined(NO_MD2)
72#define USE_MD2_RAND 76#define USE_MD2_RAND
73#else 77#else
74We need a message digest of some type 78#error No message digest algorithm available
75#endif 79#endif
76#endif 80#endif
77 81
@@ -82,60 +86,78 @@ We need a message digest of some type
82 */ 86 */
83 87
84#if defined(USE_MD5_RAND) 88#if defined(USE_MD5_RAND)
85#include "md5.h" 89#include <openssl/md5.h>
86#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH 90#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
87#define MD_CTX MD5_CTX 91#define MD_CTX MD5_CTX
88#define MD_Init(a) MD5_Init(a) 92#define MD_Init(a) MD5_Init(a)
89#define MD_Update(a,b,c) MD5_Update(a,b,c) 93#define MD_Update(a,b,c) MD5_Update(a,b,c)
90#define MD_Final(a,b) MD5_Final(a,b) 94#define MD_Final(a,b) MD5_Final(a,b)
95#define MD(a,b,c) MD5(a,b,c)
91#elif defined(USE_SHA1_RAND) 96#elif defined(USE_SHA1_RAND)
92#include "sha.h" 97#include <openssl/sha.h>
93#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH 98#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
94#define MD_CTX SHA_CTX 99#define MD_CTX SHA_CTX
95#define MD_Init(a) SHA1_Init(a) 100#define MD_Init(a) SHA1_Init(a)
96#define MD_Update(a,b,c) SHA1_Update(a,b,c) 101#define MD_Update(a,b,c) SHA1_Update(a,b,c)
97#define MD_Final(a,b) SHA1_Final(a,b) 102#define MD_Final(a,b) SHA1_Final(a,b)
103#define MD(a,b,c) SHA1(a,b,c)
98#elif defined(USE_MDC2_RAND) 104#elif defined(USE_MDC2_RAND)
99#include "mdc2.h" 105#include <openssl/mdc2.h>
100#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH 106#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
101#define MD_CTX MDC2_CTX 107#define MD_CTX MDC2_CTX
102#define MD_Init(a) MDC2_Init(a) 108#define MD_Init(a) MDC2_Init(a)
103#define MD_Update(a,b,c) MDC2_Update(a,b,c) 109#define MD_Update(a,b,c) MDC2_Update(a,b,c)
104#define MD_Final(a,b) MDC2_Final(a,b) 110#define MD_Final(a,b) MDC2_Final(a,b)
111#define MD(a,b,c) MDC2(a,b,c)
105#elif defined(USE_MD2_RAND) 112#elif defined(USE_MD2_RAND)
106#include "md2.h" 113#include <openssl/md2.h>
107#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH 114#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
108#define MD_CTX MD2_CTX 115#define MD_CTX MD2_CTX
109#define MD_Init(a) MD2_Init(a) 116#define MD_Init(a) MD2_Init(a)
110#define MD_Update(a,b,c) MD2_Update(a,b,c) 117#define MD_Update(a,b,c) MD2_Update(a,b,c)
111#define MD_Final(a,b) MD2_Final(a,b) 118#define MD_Final(a,b) MD2_Final(a,b)
119#define MD(a,b,c) MD2(a,b,c)
112#endif 120#endif
113 121
114#include "rand.h" 122#include <openssl/rand.h>
115 123
116/*#define NORAND 1 */ 124/* #define NORAND 1 */
117/*#define PREDICT 1 */ 125/* #define PREDICT 1 */
118 126
119#define STATE_SIZE 1023 127#define STATE_SIZE 1023
120static int state_num=0,state_index=0; 128static int state_num=0,state_index=0;
121static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH]; 129static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];
122static unsigned char md[MD_DIGEST_LENGTH]; 130static unsigned char md[MD_DIGEST_LENGTH];
123static int md_count=0; 131static long md_count[2]={0,0};
132
133const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT;
134
135static void ssleay_rand_cleanup(void);
136static void ssleay_rand_seed(const void *buf, int num);
137static void ssleay_rand_bytes(unsigned char *buf, int num);
124 138
125char *RAND_version="RAND part of SSLeay 0.9.0b 29-Jun-1998"; 139RAND_METHOD rand_ssleay_meth={
140 ssleay_rand_seed,
141 ssleay_rand_bytes,
142 ssleay_rand_cleanup,
143 };
126 144
127void RAND_cleanup() 145RAND_METHOD *RAND_SSLeay(void)
146 {
147 return(&rand_ssleay_meth);
148 }
149
150static void ssleay_rand_cleanup(void)
128 { 151 {
129 memset(state,0,sizeof(state)); 152 memset(state,0,sizeof(state));
130 state_num=0; 153 state_num=0;
131 state_index=0; 154 state_index=0;
132 memset(md,0,MD_DIGEST_LENGTH); 155 memset(md,0,MD_DIGEST_LENGTH);
133 md_count=0; 156 md_count[0]=0;
157 md_count[1]=0;
134 } 158 }
135 159
136void RAND_seed(buf,num) 160static void ssleay_rand_seed(const void *buf, int num)
137unsigned char *buf;
138int num;
139 { 161 {
140 int i,j,k,st_idx,st_num; 162 int i,j,k,st_idx,st_num;
141 MD_CTX m; 163 MD_CTX m;
@@ -178,9 +200,11 @@ int num;
178 MD_Update(&m,&(state[st_idx]),j); 200 MD_Update(&m,&(state[st_idx]),j);
179 201
180 MD_Update(&m,buf,j); 202 MD_Update(&m,buf,j);
203 MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count));
181 MD_Final(md,&m); 204 MD_Final(md,&m);
205 md_count[1]++;
182 206
183 buf+=j; 207 buf=(const char *)buf + j;
184 208
185 for (k=0; k<j; k++) 209 for (k=0; k<j; k++)
186 { 210 {
@@ -195,9 +219,7 @@ int num;
195 memset((char *)&m,0,sizeof(m)); 219 memset((char *)&m,0,sizeof(m));
196 } 220 }
197 221
198void RAND_bytes(buf,num) 222static void ssleay_rand_bytes(unsigned char *buf, int num)
199unsigned char *buf;
200int num;
201 { 223 {
202 int i,j,k,st_num,st_idx; 224 int i,j,k,st_num,st_idx;
203 MD_CTX m; 225 MD_CTX m;
@@ -221,19 +243,18 @@ int num;
221 243
222 if (init) 244 if (init)
223 { 245 {
224 init=0;
225 CRYPTO_w_unlock(CRYPTO_LOCK_RAND); 246 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
226 /* put in some default random data, we need more than 247 /* put in some default random data, we need more than
227 * just this */ 248 * just this */
228 RAND_seed((unsigned char *)&m,sizeof(m)); 249 RAND_seed(&m,sizeof(m));
229#ifndef MSDOS 250#ifndef MSDOS
230 l=getpid(); 251 l=getpid();
231 RAND_seed((unsigned char *)&l,sizeof(l)); 252 RAND_seed(&l,sizeof(l));
232 l=getuid(); 253 l=getuid();
233 RAND_seed((unsigned char *)&l,sizeof(l)); 254 RAND_seed(&l,sizeof(l));
234#endif 255#endif
235 l=time(NULL); 256 l=time(NULL);
236 RAND_seed((unsigned char *)&l,sizeof(l)); 257 RAND_seed(&l,sizeof(l));
237 258
238/* #ifdef DEVRANDOM */ 259/* #ifdef DEVRANDOM */
239 /* 260 /*
@@ -261,6 +282,7 @@ int num;
261 memset(md,0,MD_DIGEST_LENGTH); 282 memset(md,0,MD_DIGEST_LENGTH);
262#endif 283#endif
263 CRYPTO_w_lock(CRYPTO_LOCK_RAND); 284 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
285 init=0;
264 } 286 }
265 287
266 st_idx=state_index; 288 st_idx=state_index;
@@ -277,6 +299,7 @@ int num;
277 num-=j; 299 num-=j;
278 MD_Init(&m); 300 MD_Init(&m);
279 MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2); 301 MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2);
302 MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count));
280#ifndef PURIFY 303#ifndef PURIFY
281 MD_Update(&m,buf,j); /* purify complains */ 304 MD_Update(&m,buf,j); /* purify complains */
282#endif 305#endif
@@ -300,7 +323,8 @@ int num;
300 } 323 }
301 324
302 MD_Init(&m); 325 MD_Init(&m);
303 MD_Update(&m,(unsigned char *)&md_count,sizeof(md_count)); md_count++; 326 MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count));
327 md_count[0]++;
304 MD_Update(&m,md,MD_DIGEST_LENGTH); 328 MD_Update(&m,md,MD_DIGEST_LENGTH);
305 MD_Final(md,&m); 329 MD_Final(md,&m);
306 memset(&m,0,sizeof(m)); 330 memset(&m,0,sizeof(m));
@@ -308,7 +332,7 @@ int num;
308 332
309#ifdef WINDOWS 333#ifdef WINDOWS
310#include <windows.h> 334#include <windows.h>
311#include <rand.h> 335#include <openssl/rand.h>
312 336
313/***************************************************************************** 337/*****************************************************************************
314 * Initialisation function for the SSL random generator. Takes the contents 338 * Initialisation function for the SSL random generator. Takes the contents
@@ -320,13 +344,13 @@ int num;
320 * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>; 344 * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>;
321 * the original copyright message is: 345 * the original copyright message is:
322 * 346 *
323// (C) Copyright Microsoft Corp. 1993. All rights reserved. 347 * (C) Copyright Microsoft Corp. 1993. All rights reserved.
324// 348 *
325// You have a royalty-free right to use, modify, reproduce and 349 * You have a royalty-free right to use, modify, reproduce and
326// distribute the Sample Files (and/or any modified version) in 350 * distribute the Sample Files (and/or any modified version) in
327// any way you find useful, provided that you agree that 351 * any way you find useful, provided that you agree that
328// Microsoft has no warranty obligations or liability for any 352 * Microsoft has no warranty obligations or liability for any
329// Sample Application Files which are modified. 353 * Sample Application Files which are modified.
330 */ 354 */
331/* 355/*
332 * I have modified the loading of bytes via RAND_seed() mechanism since 356 * I have modified the loading of bytes via RAND_seed() mechanism since
@@ -385,7 +409,7 @@ void RAND_screen(void)
385 GetBitmapBits(hBitmap, size, bmbits); 409 GetBitmapBits(hBitmap, size, bmbits);
386 410
387 /* Get the MD5 of the bitmap */ 411 /* Get the MD5 of the bitmap */
388 MD5(bmbits,size,md); 412 MD(bmbits,size,md);
389 413
390 /* Seed the random generator with the MD5 digest */ 414 /* Seed the random generator with the MD5 digest */
391 RAND_seed(md, MD_DIGEST_LENGTH); 415 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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifndef NOPROTO 66typedef struct rand_meth_st
67 {
68 void (*seed)(const void *buf, int num);
69 void (*bytes)(unsigned char *buf, int num);
70 void (*cleanup)(void);
71 } RAND_METHOD;
72
73void RAND_set_rand_method(RAND_METHOD *meth);
74RAND_METHOD *RAND_get_rand_method(void );
75RAND_METHOD *RAND_SSLeay(void);
67void RAND_cleanup(void ); 76void RAND_cleanup(void );
68void RAND_bytes( unsigned char *buf,int num); 77void RAND_bytes(unsigned char *buf,int num);
69void RAND_seed( unsigned char *buf,int num); 78void RAND_seed(const void *buf,int num);
70int RAND_load_file(char *file,long max_bytes); 79int RAND_load_file(const char *file,long max_bytes);
71int RAND_write_file(char *file); 80int RAND_write_file(const char *file);
72char *RAND_file_name(char *file,int num); 81char *RAND_file_name(char *file,int num);
73#ifdef WINDOWS 82#ifdef WINDOWS
74void RAND_screen(void); 83void RAND_screen(void);
75#endif 84#endif
76#else
77void RAND_cleanup();
78void RAND_bytes();
79void RAND_seed();
80int RAND_load_file();
81int RAND_write_file();
82char *RAND_file_name();
83#ifdef WINDOWS
84void RAND_screen();
85#endif
86#endif
87
88#ifdef __cplusplus 85#ifdef __cplusplus
89} 86}
90#endif 87#endif
diff --git a/src/lib/libcrypto/cryptall.h b/src/lib/libcrypto/rand/rand_lib.c
index 65a46452a8..34c6d5b968 100644
--- a/src/lib/libcrypto/cryptall.h
+++ b/src/lib/libcrypto/rand/rand_lib.c
@@ -1,4 +1,4 @@
1/* crypto/cryptall.h */ 1/* crypto/rand/rand_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,55 +56,43 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef HEADER_CRYPTOALL_H 59#include <stdio.h>
60#define HEADER_CRYPTOALL_H 60#include <sys/types.h>
61#include <time.h>
62#include <openssl/rand.h>
61 63
62#include "buffer.h" 64#ifdef NO_RAND
63#include "stack.h" 65static RAND_METHOD *rand_meth=NULL;
64#include "lhash.h"
65
66#include "err.h"
67
68#ifdef NO_MD2
69#include <md2.h>
70#else
71#include "md2.h"
72#endif
73#ifdef NO_MD5
74#include <md5.h>
75#else 66#else
76#include "md5.h" 67extern RAND_METHOD rand_ssleay_meth;
68static RAND_METHOD *rand_meth= &rand_ssleay_meth;
77#endif 69#endif
78#include "sha.h"
79 70
80#ifdef NO_DES 71void RAND_set_rand_method(RAND_METHOD *meth)
81#include <des.h> 72 {
82#else 73 rand_meth=meth;
83#include "des.h" 74 }
84#endif
85#include "rc2.h"
86#include "rc4.h"
87#include "idea.h"
88 75
89#include "bn.h" 76RAND_METHOD *RAND_get_rand_method(void)
90#include "dh.h" 77 {
91#include "rsa.h" 78 return(rand_meth);
92#include "dsa.h" 79 }
93 80
94#include "rand.h" 81void RAND_cleanup(void)
95#include "conf.h" 82 {
96#include "txt_db.h" 83 if (rand_meth != NULL)
84 rand_meth->cleanup();
85 }
97 86
98#include "err.h" 87void RAND_seed(const void *buf, int num)
99#include "evp.h" 88 {
89 if (rand_meth != NULL)
90 rand_meth->seed(buf,num);
91 }
100 92
101#include "meth.h" 93void RAND_bytes(unsigned char *buf, int num)
102#include "x509.h" 94 {
103#include "pkcs7.h" 95 if (rand_meth != NULL)
104#include "pem.h" 96 rand_meth->bytes(buf,num);
105#include "asn1.h" 97 }
106#include "objects.h"
107 98
108#include "crypto.h"
109
110#endif
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <errno.h>
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include <stdlib.h>
62#include <string.h>
63#include <sys/types.h>
61#include <sys/stat.h> 64#include <sys/stat.h>
62#include <sys/types.h> 65#include <sys/types.h>
63#include "rand.h" 66
67#include "openssl/e_os.h"
68
69#include <openssl/rand.h>
64 70
65#undef BUFSIZE 71#undef BUFSIZE
66#define BUFSIZE 1024 72#define BUFSIZE 1024
@@ -68,9 +74,7 @@
68 74
69/* #define RFILE ".rand" - defined in ../../e_os.h */ 75/* #define RFILE ".rand" - defined in ../../e_os.h */
70 76
71int RAND_load_file(file,bytes) 77int RAND_load_file(const char *file, long bytes)
72char *file;
73long bytes;
74 { 78 {
75 MS_STATIC unsigned char buf[BUFSIZE]; 79 MS_STATIC unsigned char buf[BUFSIZE];
76 struct stat sb; 80 struct stat sb;
@@ -81,12 +85,12 @@ long bytes;
81 85
82 i=stat(file,&sb); 86 i=stat(file,&sb);
83 /* If the state fails, put some crap in anyway */ 87 /* If the state fails, put some crap in anyway */
84 RAND_seed((unsigned char *)&sb,sizeof(sb)); 88 RAND_seed(&sb,sizeof(sb));
85 ret+=sizeof(sb); 89 ret+=sizeof(sb);
86 if (i < 0) return(0); 90 if (i < 0) return(0);
87 if (bytes <= 0) return(ret); 91 if (bytes <= 0) return(ret);
88 92
89 in=fopen(file,"r"); 93 in=fopen(file,"rb");
90 if (in == NULL) goto err; 94 if (in == NULL) goto err;
91 for (;;) 95 for (;;)
92 { 96 {
@@ -105,15 +109,24 @@ err:
105 return(ret); 109 return(ret);
106 } 110 }
107 111
108int RAND_write_file(file) 112int RAND_write_file(const char *file)
109char *file;
110 { 113 {
111 unsigned char buf[BUFSIZE]; 114 unsigned char buf[BUFSIZE];
112 int i,ret=0; 115 int i,ret=0;
113 FILE *out; 116 FILE *out;
114 int n; 117 int n;
115 118
116 out=fopen(file,"w"); 119 /* Under VMS, fopen(file, "wb") will craete a new version of the
120 same file. This is not good, so let's try updating an existing
121 one, and create file only if it doesn't already exist. This
122 should be completely harmless on system that have no file
123 versions. -- Richard Levitte */
124 out=fopen(file,"rb+");
125 if (out == NULL && errno == ENOENT)
126 {
127 errno = 0;
128 out=fopen(file,"wb");
129 }
117 if (out == NULL) goto err; 130 if (out == NULL) goto err;
118 chmod(file,0600); 131 chmod(file,0600);
119 n=RAND_DATA; 132 n=RAND_DATA;
@@ -137,9 +150,7 @@ err:
137 return(ret); 150 return(ret);
138 } 151 }
139 152
140char *RAND_file_name(buf,size) 153char *RAND_file_name(char *buf, int size)
141char *buf;
142int size;
143 { 154 {
144 char *s; 155 char *s;
145 char *ret=NULL; 156 char *ret=NULL;
@@ -158,7 +169,9 @@ int size;
158 if (((int)(strlen(s)+strlen(RFILE)+2)) > size) 169 if (((int)(strlen(s)+strlen(RFILE)+2)) > size)
159 return(RFILE); 170 return(RFILE);
160 strcpy(buf,s); 171 strcpy(buf,s);
172#ifndef VMS
161 strcat(buf,"/"); 173 strcat(buf,"/");
174#endif
162 strcat(buf,RFILE); 175 strcat(buf,RFILE);
163 ret=buf; 176 ret=buf;
164 } 177 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "rand.h" 61#include <openssl/rand.h>
62 62
63/* some FIPS 140-1 random number test */ 63/* some FIPS 140-1 random number test */
64/* some simple tests */ 64/* some simple tests */
@@ -117,7 +117,7 @@ int main()
117 /* test 1 */ 117 /* test 1 */
118 if (!((9654 < n1) && (n1 < 10346))) 118 if (!((9654 < n1) && (n1 < 10346)))
119 { 119 {
120 printf("test 1 failed, X=%ld\n",n1); 120 printf("test 1 failed, X=%lu\n",n1);
121 err++; 121 err++;
122 } 122 }
123 printf("test 1 done\n"); 123 printf("test 1 done\n");
@@ -150,37 +150,37 @@ int main()
150 { 150 {
151 if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) 151 if (!((2267 < runs[i][0]) && (runs[i][0] < 2733)))
152 { 152 {
153 printf("test 3 failed, bit=%d run=%d num=%ld\n", 153 printf("test 3 failed, bit=%d run=%d num=%lu\n",
154 i,1,runs[i][0]); 154 i,1,runs[i][0]);
155 err++; 155 err++;
156 } 156 }
157 if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) 157 if (!((1079 < runs[i][1]) && (runs[i][1] < 1421)))
158 { 158 {
159 printf("test 3 failed, bit=%d run=%d num=%ld\n", 159 printf("test 3 failed, bit=%d run=%d num=%lu\n",
160 i,2,runs[i][1]); 160 i,2,runs[i][1]);
161 err++; 161 err++;
162 } 162 }
163 if (!(( 502 < runs[i][2]) && (runs[i][2] < 748))) 163 if (!(( 502 < runs[i][2]) && (runs[i][2] < 748)))
164 { 164 {
165 printf("test 3 failed, bit=%d run=%d num=%ld\n", 165 printf("test 3 failed, bit=%d run=%d num=%lu\n",
166 i,3,runs[i][2]); 166 i,3,runs[i][2]);
167 err++; 167 err++;
168 } 168 }
169 if (!(( 223 < runs[i][3]) && (runs[i][3] < 402))) 169 if (!(( 223 < runs[i][3]) && (runs[i][3] < 402)))
170 { 170 {
171 printf("test 3 failed, bit=%d run=%d num=%ld\n", 171 printf("test 3 failed, bit=%d run=%d num=%lu\n",
172 i,4,runs[i][3]); 172 i,4,runs[i][3]);
173 err++; 173 err++;
174 } 174 }
175 if (!(( 90 < runs[i][4]) && (runs[i][4] < 223))) 175 if (!(( 90 < runs[i][4]) && (runs[i][4] < 223)))
176 { 176 {
177 printf("test 3 failed, bit=%d run=%d num=%ld\n", 177 printf("test 3 failed, bit=%d run=%d num=%lu\n",
178 i,5,runs[i][4]); 178 i,5,runs[i][4]);
179 err++; 179 err++;
180 } 180 }
181 if (!(( 90 < runs[i][5]) && (runs[i][5] < 223))) 181 if (!(( 90 < runs[i][5]) && (runs[i][5] < 223)))
182 { 182 {
183 printf("test 3 failed, bit=%d run=%d num=%ld\n", 183 printf("test 3 failed, bit=%d run=%d num=%lu\n",
184 i,6,runs[i][5]); 184 i,6,runs[i][5]);
185 err++; 185 err++;
186 } 186 }
@@ -190,13 +190,13 @@ int main()
190 /* test 4 */ 190 /* test 4 */
191 if (runs[0][33] != 0) 191 if (runs[0][33] != 0)
192 { 192 {
193 printf("test 4 failed, bit=%d run=%d num=%ld\n", 193 printf("test 4 failed, bit=%d run=%d num=%lu\n",
194 0,34,runs[0][33]); 194 0,34,runs[0][33]);
195 err++; 195 err++;
196 } 196 }
197 if (runs[1][33] != 0) 197 if (runs[1][33] != 0)
198 { 198 {
199 printf("test 4 failed, bit=%d run=%d num=%ld\n", 199 printf("test 4 failed, bit=%d run=%d num=%lu\n",
200 1,34,runs[1][33]); 200 1,34,runs[1][33]);
201 err++; 201 err++;
202 } 202 }
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 @@
1#!/bin/sh
2
3cwd=`pwd`
4cd /tmp
5
6if [ -s /bin/ranlib ] ; then
7 RL=/bin/ranlib
8else if [ -s /usr/bin/ranlib ] ; then
9 RL=/usr/bin/ranlib
10fi
11fi
12
13if [ "x$RL" != "x" ]
14then
15 case "$1" in
16 /*)
17 $RL "$1"
18 ;;
19 *)
20 $RL "$cwd/$1"
21 ;;
22 esac
23fi
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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,24 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81rc2_cbc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
82rc2_cbc.o: rc2_locl.h
83rc2_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
84rc2_ecb.o: ../../include/openssl/rc2.h rc2_locl.h
85rc2_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
86rc2_skey.o: rc2_locl.h
87rc2cfb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
88rc2cfb64.o: rc2_locl.h
89rc2ofb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
90rc2ofb64.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
15MAKEDEPEND= makedepend 15MAKEDEPEND= makedepend
16MAKEFILE= Makefile.uni 16MAKEFILE= Makefile.uni
17AR= ar r 17AR= ar r
18RANLIB= ranlib
18 19
19IDEA_ENC=rc2_cbc.o 20IDEA_ENC=rc2_cbc.o
20 21
@@ -39,7 +40,7 @@ all: $(LIB) $(TEST) $(APPS)
39 40
40$(LIB): $(LIBOBJ) 41$(LIB): $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ) 42 $(AR) $(LIB) $(LIBOBJ)
42 sh $(TOP)/ranlib.sh $(LIB) 43 $(RANLIB) $(LIB)
43 44
44test: $(TEST) 45test: $(TEST)
45 ./$(TEST) 46 ./$(TEST)
diff --git a/src/lib/libcrypto/rc2/rc2.org b/src/lib/libcrypto/rc2/rc2.h
index 37354cfa62..9571efb755 100644
--- a/src/lib/libcrypto/rc2/rc2.org
+++ b/src/lib/libcrypto/rc2/rc2.h
@@ -1,4 +1,4 @@
1/* crypto/rc2/rc2.org */ 1/* crypto/rc2/rc2.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,14 +56,6 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify rc2.org since rc2.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_RC2_H 59#ifndef HEADER_RC2_H
68#define HEADER_RC2_H 60#define HEADER_RC2_H
69 61
@@ -71,12 +63,14 @@
71extern "C" { 63extern "C" {
72#endif 64#endif
73 65
66#ifdef NO_RC2
67#error RC2 is disabled.
68#endif
69
74#define RC2_ENCRYPT 1 70#define RC2_ENCRYPT 1
75#define RC2_DECRYPT 0 71#define RC2_DECRYPT 0
76 72
77/* I need to put in a mod for the alpha - eay */ 73#include <openssl/opensslconf.h> /* RC2_INT */
78#define RC2_INT unsigned short
79
80#define RC2_BLOCK 8 74#define RC2_BLOCK 8
81#define RC2_KEY_LENGTH 16 75#define RC2_KEY_LENGTH 16
82 76
@@ -85,7 +79,6 @@ typedef struct rc2_key_st
85 RC2_INT data[64]; 79 RC2_INT data[64];
86 } RC2_KEY; 80 } RC2_KEY;
87 81
88#ifndef NOPROTO
89 82
90void RC2_set_key(RC2_KEY *key, int len, unsigned char *data,int bits); 83void RC2_set_key(RC2_KEY *key, int len, unsigned char *data,int bits);
91void RC2_ecb_encrypt(unsigned char *in,unsigned char *out,RC2_KEY *key, 84void RC2_ecb_encrypt(unsigned char *in,unsigned char *out,RC2_KEY *key,
@@ -99,18 +92,6 @@ void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
99void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, 92void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
100 RC2_KEY *schedule, unsigned char *ivec, int *num); 93 RC2_KEY *schedule, unsigned char *ivec, int *num);
101 94
102#else
103
104void RC2_set_key();
105void RC2_ecb_encrypt();
106void RC2_encrypt();
107void RC2_decrypt();
108void RC2_cbc_encrypt();
109void RC2_cfb64_encrypt();
110void RC2_ofb64_encrypt();
111
112#endif
113
114#ifdef __cplusplus 95#ifdef __cplusplus
115} 96}
116#endif 97#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "rc2.h" 59#include <openssl/rc2.h>
60#include "rc2_locl.h" 60#include "rc2_locl.h"
61 61
62void RC2_cbc_encrypt(in, out, length, ks, iv, encrypt) 62void RC2_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
63unsigned char *in; 63 RC2_KEY *ks, unsigned char *iv, int encrypt)
64unsigned char *out;
65long length;
66RC2_KEY *ks;
67unsigned char *iv;
68int encrypt;
69 { 64 {
70 register unsigned long tin0,tin1; 65 register unsigned long tin0,tin1;
71 register unsigned long tout0,tout1,xor0,xor1; 66 register unsigned long tout0,tout1,xor0,xor1;
@@ -138,9 +133,7 @@ int encrypt;
138 tin[0]=tin[1]=0; 133 tin[0]=tin[1]=0;
139 } 134 }
140 135
141void RC2_encrypt(d,key) 136void RC2_encrypt(unsigned long *d, RC2_KEY *key)
142unsigned long *d;
143RC2_KEY *key;
144 { 137 {
145 int i,n; 138 int i,n;
146 register RC2_INT *p0,*p1; 139 register RC2_INT *p0,*p1;
@@ -185,9 +178,7 @@ RC2_KEY *key;
185 d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L); 178 d[1]=(unsigned long)(x2&0xffff)|((unsigned long)(x3&0xffff)<<16L);
186 } 179 }
187 180
188void RC2_decrypt(d,key) 181void RC2_decrypt(unsigned long *d, RC2_KEY *key)
189unsigned long *d;
190RC2_KEY *key;
191 { 182 {
192 int i,n; 183 int i,n;
193 register RC2_INT *p0,*p1; 184 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "rc2.h" 59#include <openssl/rc2.h>
60#include "rc2_locl.h" 60#include "rc2_locl.h"
61#include <openssl/opensslv.h>
61 62
62char *RC2_version="RC2 part of SSLeay 0.9.0b 29-Jun-1998"; 63const char *RC2_version="RC2" OPENSSL_VERSION_PTEXT;
63 64
64/* RC2 as implemented frm a posting from 65/* RC2 as implemented frm a posting from
65 * Newsgroups: sci.crypt 66 * Newsgroups: sci.crypt
@@ -69,11 +70,8 @@ char *RC2_version="RC2 part of SSLeay 0.9.0b 29-Jun-1998";
69 * Date: 11 Feb 1996 06:45:03 GMT 70 * Date: 11 Feb 1996 06:45:03 GMT
70 */ 71 */
71 72
72void RC2_ecb_encrypt(in, out, ks, encrypt) 73void RC2_ecb_encrypt(unsigned char *in, unsigned char *out, RC2_KEY *ks,
73unsigned char *in; 74 int encrypt)
74unsigned char *out;
75RC2_KEY *ks;
76int encrypt;
77 { 75 {
78 unsigned long l,d[2]; 76 unsigned long l,d[2];
79 77
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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "rc2.h" 59#include <openssl/rc2.h>
60#include "rc2_locl.h" 60#include "rc2_locl.h"
61 61
62static unsigned char key_table[256]={ 62static unsigned char key_table[256]={
@@ -90,11 +90,7 @@ static unsigned char key_table[256]={
90 * BSAFE uses the 'retarded' version. What I previously shipped is 90 * BSAFE uses the 'retarded' version. What I previously shipped is
91 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses 91 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses
92 * a version where the bits parameter is the same as len*8 */ 92 * a version where the bits parameter is the same as len*8 */
93void RC2_set_key(key,len,data,bits) 93void RC2_set_key(RC2_KEY *key, int len, unsigned char *data, int bits)
94RC2_KEY *key;
95int len;
96unsigned char *data;
97int bits;
98 { 94 {
99 int i,j; 95 int i,j;
100 unsigned char *k; 96 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "rc2.h" 59#include <openssl/rc2.h>
60#include "rc2_locl.h" 60#include "rc2_locl.h"
61 61
62/* The input and output encrypted as though 64bit cfb mode is being 62/* The input and output encrypted as though 64bit cfb mode is being
@@ -64,14 +64,8 @@
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66 66
67void RC2_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) 67void RC2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
68unsigned char *in; 68 RC2_KEY *schedule, unsigned char *ivec, int *num, int encrypt)
69unsigned char *out;
70long length;
71RC2_KEY *schedule;
72unsigned char *ivec;
73int *num;
74int encrypt;
75 { 69 {
76 register unsigned long v0,v1,t; 70 register unsigned long v0,v1,t;
77 register int n= *num; 71 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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "rc2.h" 59#include <openssl/rc2.h>
60#include "rc2_locl.h" 60#include "rc2_locl.h"
61 61
62/* The input and output encrypted as though 64bit ofb mode is being 62/* The input and output encrypted as though 64bit ofb mode is being
63 * used. The extra state information to record how much of the 63 * used. The extra state information to record how much of the
64 * 64bit block we have used is contained in *num; 64 * 64bit block we have used is contained in *num;
65 */ 65 */
66void RC2_ofb64_encrypt(in, out, length, schedule, ivec, num) 66void RC2_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
67unsigned char *in; 67 RC2_KEY *schedule, unsigned char *ivec, int *num)
68unsigned char *out;
69long length;
70RC2_KEY *schedule;
71unsigned char *ivec;
72int *num;
73 { 68 {
74 register unsigned long v0,v1,t; 69 register unsigned long v0,v1,t;
75 register int n= *num; 70 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 @@
59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ 59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ 60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61 61
62#ifndef MSDOS 62#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
63#define TIMES 63#define TIMES
64#endif 64#endif
65 65
66#include <stdio.h> 66#include <stdio.h>
67#ifndef MSDOS 67
68#include <unistd.h> 68#include <openssl/e_os2.h>
69#else 69#include OPENSSL_UNISTD_IO
70#include <io.h> 70OPENSSL_DECLARE_EXIT
71extern int exit(); 71
72#endif
73#include <signal.h> 72#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX 73#ifndef _IRIX
76#include <time.h> 74#include <time.h>
77#endif 75#endif
@@ -79,48 +77,40 @@ extern int exit();
79#include <sys/types.h> 77#include <sys/types.h>
80#include <sys/times.h> 78#include <sys/times.h>
81#endif 79#endif
82#else /* VMS */ 80
83#include <types.h> 81/* Depending on the VMS version, the tms structure is perhaps defined.
84struct tms { 82 The __TMS macro will show if it was. If it wasn't defined, we should
85 time_t tms_utime; 83 undefine TIMES, since that tells the rest of the program how things
86 time_t tms_stime; 84 should be handled. -- Richard Levitte */
87 time_t tms_uchild; /* I dunno... */ 85#if defined(VMS) && defined(__DECC) && !defined(__TMS)
88 time_t tms_uchildsys; /* so these names are a guess :-) */ 86#undef TIMES
89 }
90#endif 87#endif
88
91#ifndef TIMES 89#ifndef TIMES
92#include <sys/timeb.h> 90#include <sys/timeb.h>
93#endif 91#endif
94 92
95#ifdef sun 93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
96#include <limits.h> 95#include <limits.h>
97#include <sys/param.h> 96#include <sys/param.h>
98#endif 97#endif
99 98
100#include "rc2.h" 99#include <openssl/rc2.h>
101 100
102/* The following if from times(3) man page. It may need to be changed */ 101/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ 102#ifndef HZ
104#ifndef CLK_TCK 103#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0 104#define HZ 100.0
109#endif 105#endif
110#else /* CLK_TCK */ 106#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK) 107#define HZ ((double)CLK_TCK)
112#endif 108#endif
113#endif
114 109
115#define BUFSIZE ((long)1024) 110#define BUFSIZE ((long)1024)
116long run=0; 111long run=0;
117 112
118#ifndef NOPROTO
119double Time_F(int s); 113double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM 114#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX) 115#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void 116#define SIGRETTYPE void
@@ -128,14 +118,8 @@ double Time_F();
128#define SIGRETTYPE int 118#define SIGRETTYPE int
129#endif 119#endif
130 120
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig); 121SIGRETTYPE sig_done(int sig);
133#else 122SIGRETTYPE sig_done(int sig)
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 { 123 {
140 signal(SIGALRM,sig_done); 124 signal(SIGALRM,sig_done);
141 run=0; 125 run=0;
@@ -148,8 +132,7 @@ int sig;
148#define START 0 132#define START 0
149#define STOP 1 133#define STOP 1
150 134
151double Time_F(s) 135double Time_F(int s)
152int s;
153 { 136 {
154 double ret; 137 double ret;
155#ifdef TIMES 138#ifdef TIMES
@@ -185,9 +168,7 @@ int s;
185#endif 168#endif
186 } 169 }
187 170
188int main(argc,argv) 171int main(int argc, char **argv)
189int argc;
190char **argv;
191 { 172 {
192 long count; 173 long count;
193 static unsigned char buf[BUFSIZE]; 174 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 @@
62#include <stdio.h> 62#include <stdio.h>
63#include <string.h> 63#include <string.h>
64#include <stdlib.h> 64#include <stdlib.h>
65#include "rc2.h" 65
66#ifdef NO_RC2
67int main(int argc, char *argv[])
68{
69 printf("No RC2 support\n");
70 return(0);
71}
72#else
73#include <openssl/rc2.h>
66 74
67unsigned char RC2key[4][16]={ 75unsigned char RC2key[4][16]={
68 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 76 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -125,19 +133,11 @@ static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
125 }; 133 };
126 134
127 135
128#ifndef NOPROTO
129/*static int cfb64_test(unsigned char *cfb_cipher);*/ 136/*static int cfb64_test(unsigned char *cfb_cipher);*/
130static char *pt(unsigned char *p); 137static char *pt(unsigned char *p);
131#else
132/*static int cfb64_test(); */
133static char *pt();
134#endif 138#endif
135 139
136#endif 140int main(int argc, char *argv[])
137
138int main(argc,argv)
139int argc;
140char *argv[];
141 { 141 {
142 int i,n,err=0; 142 int i,n,err=0;
143 RC2_KEY key; 143 RC2_KEY key;
@@ -208,8 +208,7 @@ char *argv[];
208 } 208 }
209 209
210#ifdef undef 210#ifdef undef
211static int cfb64_test(cfb_cipher) 211static int cfb64_test(unsigned char *cfb_cipher)
212unsigned char *cfb_cipher;
213 { 212 {
214 IDEA_KEY_SCHEDULE eks,dks; 213 IDEA_KEY_SCHEDULE eks,dks;
215 int err=0,i,n; 214 int err=0,i,n;
@@ -247,8 +246,7 @@ unsigned char *cfb_cipher;
247 return(err); 246 return(err);
248 } 247 }
249 248
250static char *pt(p) 249static char *pt(unsigned char *p)
251unsigned char *p;
252 { 250 {
253 static char bufs[10][20]; 251 static char bufs[10][20];
254 static int bnum=0; 252 static int bnum=0;
@@ -268,3 +266,4 @@ unsigned char *p;
268 } 266 }
269 267
270#endif 268#endif
269#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 @@
1#include <stdio.h>
2
3unsigned char ebits_to_num[256]={
4 0xbd,0x56,0xea,0xf2,0xa2,0xf1,0xac,0x2a,
5 0xb0,0x93,0xd1,0x9c,0x1b,0x33,0xfd,0xd0,
6 0x30,0x04,0xb6,0xdc,0x7d,0xdf,0x32,0x4b,
7 0xf7,0xcb,0x45,0x9b,0x31,0xbb,0x21,0x5a,
8 0x41,0x9f,0xe1,0xd9,0x4a,0x4d,0x9e,0xda,
9 0xa0,0x68,0x2c,0xc3,0x27,0x5f,0x80,0x36,
10 0x3e,0xee,0xfb,0x95,0x1a,0xfe,0xce,0xa8,
11 0x34,0xa9,0x13,0xf0,0xa6,0x3f,0xd8,0x0c,
12 0x78,0x24,0xaf,0x23,0x52,0xc1,0x67,0x17,
13 0xf5,0x66,0x90,0xe7,0xe8,0x07,0xb8,0x60,
14 0x48,0xe6,0x1e,0x53,0xf3,0x92,0xa4,0x72,
15 0x8c,0x08,0x15,0x6e,0x86,0x00,0x84,0xfa,
16 0xf4,0x7f,0x8a,0x42,0x19,0xf6,0xdb,0xcd,
17 0x14,0x8d,0x50,0x12,0xba,0x3c,0x06,0x4e,
18 0xec,0xb3,0x35,0x11,0xa1,0x88,0x8e,0x2b,
19 0x94,0x99,0xb7,0x71,0x74,0xd3,0xe4,0xbf,
20 0x3a,0xde,0x96,0x0e,0xbc,0x0a,0xed,0x77,
21 0xfc,0x37,0x6b,0x03,0x79,0x89,0x62,0xc6,
22 0xd7,0xc0,0xd2,0x7c,0x6a,0x8b,0x22,0xa3,
23 0x5b,0x05,0x5d,0x02,0x75,0xd5,0x61,0xe3,
24 0x18,0x8f,0x55,0x51,0xad,0x1f,0x0b,0x5e,
25 0x85,0xe5,0xc2,0x57,0x63,0xca,0x3d,0x6c,
26 0xb4,0xc5,0xcc,0x70,0xb2,0x91,0x59,0x0d,
27 0x47,0x20,0xc8,0x4f,0x58,0xe0,0x01,0xe2,
28 0x16,0x38,0xc4,0x6f,0x3b,0x0f,0x65,0x46,
29 0xbe,0x7e,0x2d,0x7b,0x82,0xf9,0x40,0xb5,
30 0x1d,0x73,0xf8,0xeb,0x26,0xc7,0x87,0x97,
31 0x25,0x54,0xb1,0x28,0xaa,0x98,0x9d,0xa5,
32 0x64,0x6d,0x7a,0xd4,0x10,0x81,0x44,0xef,
33 0x49,0xd6,0xae,0x2e,0xdd,0x76,0x5c,0x2f,
34 0xa7,0x1c,0xc9,0x09,0x69,0x9a,0x83,0xcf,
35 0x29,0x39,0xb9,0xe9,0x4c,0xff,0x43,0xab,
36 };
37
38unsigned char num_to_ebits[256]={
39 0x5d,0xbe,0x9b,0x8b,0x11,0x99,0x6e,0x4d,
40 0x59,0xf3,0x85,0xa6,0x3f,0xb7,0x83,0xc5,
41 0xe4,0x73,0x6b,0x3a,0x68,0x5a,0xc0,0x47,
42 0xa0,0x64,0x34,0x0c,0xf1,0xd0,0x52,0xa5,
43 0xb9,0x1e,0x96,0x43,0x41,0xd8,0xd4,0x2c,
44 0xdb,0xf8,0x07,0x77,0x2a,0xca,0xeb,0xef,
45 0x10,0x1c,0x16,0x0d,0x38,0x72,0x2f,0x89,
46 0xc1,0xf9,0x80,0xc4,0x6d,0xae,0x30,0x3d,
47 0xce,0x20,0x63,0xfe,0xe6,0x1a,0xc7,0xb8,
48 0x50,0xe8,0x24,0x17,0xfc,0x25,0x6f,0xbb,
49 0x6a,0xa3,0x44,0x53,0xd9,0xa2,0x01,0xab,
50 0xbc,0xb6,0x1f,0x98,0xee,0x9a,0xa7,0x2d,
51 0x4f,0x9e,0x8e,0xac,0xe0,0xc6,0x49,0x46,
52 0x29,0xf4,0x94,0x8a,0xaf,0xe1,0x5b,0xc3,
53 0xb3,0x7b,0x57,0xd1,0x7c,0x9c,0xed,0x87,
54 0x40,0x8c,0xe2,0xcb,0x93,0x14,0xc9,0x61,
55 0x2e,0xe5,0xcc,0xf6,0x5e,0xa8,0x5c,0xd6,
56 0x75,0x8d,0x62,0x95,0x58,0x69,0x76,0xa1,
57 0x4a,0xb5,0x55,0x09,0x78,0x33,0x82,0xd7,
58 0xdd,0x79,0xf5,0x1b,0x0b,0xde,0x26,0x21,
59 0x28,0x74,0x04,0x97,0x56,0xdf,0x3c,0xf0,
60 0x37,0x39,0xdc,0xff,0x06,0xa4,0xea,0x42,
61 0x08,0xda,0xb4,0x71,0xb0,0xcf,0x12,0x7a,
62 0x4e,0xfa,0x6c,0x1d,0x84,0x00,0xc8,0x7f,
63 0x91,0x45,0xaa,0x2b,0xc2,0xb1,0x8f,0xd5,
64 0xba,0xf2,0xad,0x19,0xb2,0x67,0x36,0xf7,
65 0x0f,0x0a,0x92,0x7d,0xe3,0x9d,0xe9,0x90,
66 0x3e,0x23,0x27,0x66,0x13,0xec,0x81,0x15,
67 0xbd,0x22,0xbf,0x9f,0x7e,0xa9,0x51,0x4b,
68 0x4c,0xfb,0x02,0xd3,0x70,0x86,0x31,0xe7,
69 0x3b,0x05,0x03,0x54,0x60,0x48,0x65,0x18,
70 0xd2,0xcd,0x5f,0x32,0x88,0x0e,0x35,0xfd,
71 };
72
73main()
74 {
75 int i,j;
76
77 for (i=0; i<256; i++)
78 {
79 for (j=0; j<256; j++)
80 if (ebits_to_num[j] == i)
81 {
82 printf("0x%02x,",j);
83 break;
84 }
85 }
86 }
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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -44,7 +46,7 @@ all: lib
44 46
45lib: $(LIBOBJ) 47lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ) 48 $(AR) $(LIB) $(LIBOBJ)
47 sh $(TOP)/util/ranlib.sh $(LIB) 49 $(RANLIB) $(LIB)
48 @touch lib 50 @touch lib
49 51
50# elf 52# elf
@@ -63,26 +65,25 @@ asm/rx86-out.o: asm/rx86unix.cpp
63 65
64# bsdi 66# bsdi
65asm/rx86bsdi.o: asm/rx86unix.cpp 67asm/rx86bsdi.o: asm/rx86unix.cpp
66 $(CPP) -DBSDI asm/rx86unix.cpp | as -o asm/rx86bsdi.o 68 $(CPP) -DBSDI asm/rx86unix.cpp | sed 's/ :/:/' | as -o asm/rx86bsdi.o
67 69
68asm/rx86unix.cpp: 70asm/rx86unix.cpp: asm/rc4-586.pl
69 (cd asm; perl rc4-586.pl cpp >rx86unix.cpp) 71 (cd asm; $(PERL) rc4-586.pl cpp >rx86unix.cpp)
70 72
71files: 73files:
72 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 74 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
73 75
74links: 76links:
75 /bin/rm -f Makefile 77 @$(TOP)/util/point.sh Makefile.ssl Makefile
76 $(TOP)/util/point.sh Makefile.ssl Makefile ; 78 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
77 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 79 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
78 $(TOP)/util/mklink.sh ../../test $(TEST) 80 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
79 $(TOP)/util/mklink.sh ../../apps $(APPS)
80 81
81install: 82install:
82 @for i in $(EXHEADER) ; \ 83 @for i in $(EXHEADER) ; \
83 do \ 84 do \
84 (cp $$i $(INSTALLTOP)/include/$$i; \ 85 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
85 chmod 644 $(INSTALLTOP)/include/$$i ); \ 86 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
86 done; 87 done;
87 88
88tags: 89tags:
@@ -94,15 +95,19 @@ lint:
94 lint -DLINT $(INCLUDES) $(SRC)>fluff 95 lint -DLINT $(INCLUDES) $(SRC)>fluff
95 96
96depend: 97depend:
97 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 98 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
98 99
99dclean: 100dclean:
100 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 101 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
101 mv -f Makefile.new $(MAKEFILE) 102 mv -f Makefile.new $(MAKEFILE)
102 103
103clean: 104clean:
104 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o 105 rm -f asm/rx86unix.cpp *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o
105
106errors:
107 106
108# DO NOT DELETE THIS LINE -- make depend depends on it. 107# DO NOT DELETE THIS LINE -- make depend depends on it.
108
109rc4_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc4.h
110rc4_enc.o: rc4_locl.h
111rc4_skey.o: ../../include/openssl/opensslconf.h
112rc4_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/rc4.h
113rc4_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
19MAKEDEPEND= makedepend 19MAKEDEPEND= makedepend
20MAKEFILE= Makefile.uni 20MAKEFILE= Makefile.uni
21AR= ar r 21AR= ar r
22RANLIB= ranlib
22 23
23RC4_ENC=rc4_enc.o 24RC4_ENC=rc4_enc.o
24# or use 25# or use
@@ -48,7 +49,7 @@ all: $(LIB) $(TEST) $(APPS)
48 49
49$(LIB): $(LIBOBJ) 50$(LIB): $(LIBOBJ)
50 $(AR) $(LIB) $(LIBOBJ) 51 $(AR) $(LIB) $(LIBOBJ)
51 sh $(TOP)/ranlib.sh $(LIB) 52 $(RANLIB) $(LIB)
52 53
53# elf 54# elf
54asm/rx86-elf.o: asm/rx86unix.cpp 55asm/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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# define for pentium pro friendly version 3# define for pentium pro friendly version
4 4
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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define RC4 _RC4
13
14#endif
15
16#ifdef OUT
17#define OK 1
18#define ALIGN 4
19#endif
20
21#ifdef BSDI
22#define OK 1
23#define ALIGN 4
24#undef SIZE
25#undef TYPE
26#define SIZE(a,b)
27#define TYPE(a,b)
28#endif
29
30#if defined(ELF) || defined(SOL)
31#define OK 1
32#define ALIGN 16
33#endif
34
35#ifndef OK
36You need to define one of
37ELF - elf systems - linux-elf, NetBSD and DG-UX
38OUT - a.out systems - linux-a.out and FreeBSD
39SOL - solaris systems, which are elf with strange comment lines
40BSDI - a.out with a very primative version of as.
41#endif
42
43/* Let the Assembler begin :-) */
44 /* Don't even think of reading this code */
45 /* It was automatically generated by rc4-586.pl */
46 /* Which is a perl program used to generate the x86 assember for */
47 /* any of elf, a.out, BSDI,Win32, or Solaris */
48 /* eric <eay@cryptsoft.com> */
49
50 .file "rc4-586.s"
51 .version "01.01"
52gcc2_compiled.:
53.text
54 .align ALIGN
55.globl RC4
56 TYPE(RC4,@function)
57RC4:
58
59 pushl %ebp
60 pushl %ebx
61 movl 12(%esp), %ebp
62 movl 16(%esp), %ebx
63 pushl %esi
64 pushl %edi
65 movl (%ebp), %ecx
66 movl 4(%ebp), %edx
67 movl 28(%esp), %esi
68 incl %ecx
69 subl $12, %esp
70 addl $8, %ebp
71 andl $255, %ecx
72 leal -8(%ebx,%esi,), %ebx
73 movl 44(%esp), %edi
74 movl %ebx, 8(%esp)
75 movl (%ebp,%ecx,4), %eax
76 cmpl %esi, %ebx
77 jl .L000end
78.L001start:
79 addl $8, %esi
80 /* Round 0 */
81 addl %eax, %edx
82 andl $255, %edx
83 incl %ecx
84 movl (%ebp,%edx,4), %ebx
85 movl %ebx, -4(%ebp,%ecx,4)
86 addl %eax, %ebx
87 andl $255, %ecx
88 andl $255, %ebx
89 movl %eax, (%ebp,%edx,4)
90 nop
91 movl (%ebp,%ebx,4), %ebx
92 movl (%ebp,%ecx,4), %eax
93 movb %bl, (%esp)
94 /* Round 1 */
95 addl %eax, %edx
96 andl $255, %edx
97 incl %ecx
98 movl (%ebp,%edx,4), %ebx
99 movl %ebx, -4(%ebp,%ecx,4)
100 addl %eax, %ebx
101 andl $255, %ecx
102 andl $255, %ebx
103 movl %eax, (%ebp,%edx,4)
104 nop
105 movl (%ebp,%ebx,4), %ebx
106 movl (%ebp,%ecx,4), %eax
107 movb %bl, 1(%esp)
108 /* Round 2 */
109 addl %eax, %edx
110 andl $255, %edx
111 incl %ecx
112 movl (%ebp,%edx,4), %ebx
113 movl %ebx, -4(%ebp,%ecx,4)
114 addl %eax, %ebx
115 andl $255, %ecx
116 andl $255, %ebx
117 movl %eax, (%ebp,%edx,4)
118 nop
119 movl (%ebp,%ebx,4), %ebx
120 movl (%ebp,%ecx,4), %eax
121 movb %bl, 2(%esp)
122 /* Round 3 */
123 addl %eax, %edx
124 andl $255, %edx
125 incl %ecx
126 movl (%ebp,%edx,4), %ebx
127 movl %ebx, -4(%ebp,%ecx,4)
128 addl %eax, %ebx
129 andl $255, %ecx
130 andl $255, %ebx
131 movl %eax, (%ebp,%edx,4)
132 nop
133 movl (%ebp,%ebx,4), %ebx
134 movl (%ebp,%ecx,4), %eax
135 movb %bl, 3(%esp)
136 /* Round 4 */
137 addl %eax, %edx
138 andl $255, %edx
139 incl %ecx
140 movl (%ebp,%edx,4), %ebx
141 movl %ebx, -4(%ebp,%ecx,4)
142 addl %eax, %ebx
143 andl $255, %ecx
144 andl $255, %ebx
145 movl %eax, (%ebp,%edx,4)
146 nop
147 movl (%ebp,%ebx,4), %ebx
148 movl (%ebp,%ecx,4), %eax
149 movb %bl, 4(%esp)
150 /* Round 5 */
151 addl %eax, %edx
152 andl $255, %edx
153 incl %ecx
154 movl (%ebp,%edx,4), %ebx
155 movl %ebx, -4(%ebp,%ecx,4)
156 addl %eax, %ebx
157 andl $255, %ecx
158 andl $255, %ebx
159 movl %eax, (%ebp,%edx,4)
160 nop
161 movl (%ebp,%ebx,4), %ebx
162 movl (%ebp,%ecx,4), %eax
163 movb %bl, 5(%esp)
164 /* Round 6 */
165 addl %eax, %edx
166 andl $255, %edx
167 incl %ecx
168 movl (%ebp,%edx,4), %ebx
169 movl %ebx, -4(%ebp,%ecx,4)
170 addl %eax, %ebx
171 andl $255, %ecx
172 andl $255, %ebx
173 movl %eax, (%ebp,%edx,4)
174 nop
175 movl (%ebp,%ebx,4), %ebx
176 movl (%ebp,%ecx,4), %eax
177 movb %bl, 6(%esp)
178 /* Round 7 */
179 addl %eax, %edx
180 andl $255, %edx
181 incl %ecx
182 movl (%ebp,%edx,4), %ebx
183 movl %ebx, -4(%ebp,%ecx,4)
184 addl %eax, %ebx
185 andl $255, %ecx
186 andl $255, %ebx
187 movl %eax, (%ebp,%edx,4)
188 nop
189 movl (%ebp,%ebx,4), %ebx
190 addl $8, %edi
191 movb %bl, 7(%esp)
192 /* apply the cipher text */
193 movl (%esp), %eax
194 movl -8(%esi), %ebx
195 xorl %ebx, %eax
196 movl -4(%esi), %ebx
197 movl %eax, -8(%edi)
198 movl 4(%esp), %eax
199 xorl %ebx, %eax
200 movl 8(%esp), %ebx
201 movl %eax, -4(%edi)
202 movl (%ebp,%ecx,4), %eax
203 cmpl %ebx, %esi
204 jle .L001start
205.L000end:
206 /* Round 0 */
207 addl $8, %ebx
208 incl %esi
209 cmpl %esi, %ebx
210 jl .L002finished
211 movl %ebx, 8(%esp)
212 addl %eax, %edx
213 andl $255, %edx
214 incl %ecx
215 movl (%ebp,%edx,4), %ebx
216 movl %ebx, -4(%ebp,%ecx,4)
217 addl %eax, %ebx
218 andl $255, %ecx
219 andl $255, %ebx
220 movl %eax, (%ebp,%edx,4)
221 nop
222 movl (%ebp,%ebx,4), %ebx
223 movl (%ebp,%ecx,4), %eax
224 movb -1(%esi), %bh
225 xorb %bh, %bl
226 movb %bl, (%edi)
227 /* Round 1 */
228 movl 8(%esp), %ebx
229 cmpl %esi, %ebx
230 jle .L002finished
231 incl %esi
232 addl %eax, %edx
233 andl $255, %edx
234 incl %ecx
235 movl (%ebp,%edx,4), %ebx
236 movl %ebx, -4(%ebp,%ecx,4)
237 addl %eax, %ebx
238 andl $255, %ecx
239 andl $255, %ebx
240 movl %eax, (%ebp,%edx,4)
241 nop
242 movl (%ebp,%ebx,4), %ebx
243 movl (%ebp,%ecx,4), %eax
244 movb -1(%esi), %bh
245 xorb %bh, %bl
246 movb %bl, 1(%edi)
247 /* Round 2 */
248 movl 8(%esp), %ebx
249 cmpl %esi, %ebx
250 jle .L002finished
251 incl %esi
252 addl %eax, %edx
253 andl $255, %edx
254 incl %ecx
255 movl (%ebp,%edx,4), %ebx
256 movl %ebx, -4(%ebp,%ecx,4)
257 addl %eax, %ebx
258 andl $255, %ecx
259 andl $255, %ebx
260 movl %eax, (%ebp,%edx,4)
261 nop
262 movl (%ebp,%ebx,4), %ebx
263 movl (%ebp,%ecx,4), %eax
264 movb -1(%esi), %bh
265 xorb %bh, %bl
266 movb %bl, 2(%edi)
267 /* Round 3 */
268 movl 8(%esp), %ebx
269 cmpl %esi, %ebx
270 jle .L002finished
271 incl %esi
272 addl %eax, %edx
273 andl $255, %edx
274 incl %ecx
275 movl (%ebp,%edx,4), %ebx
276 movl %ebx, -4(%ebp,%ecx,4)
277 addl %eax, %ebx
278 andl $255, %ecx
279 andl $255, %ebx
280 movl %eax, (%ebp,%edx,4)
281 nop
282 movl (%ebp,%ebx,4), %ebx
283 movl (%ebp,%ecx,4), %eax
284 movb -1(%esi), %bh
285 xorb %bh, %bl
286 movb %bl, 3(%edi)
287 /* Round 4 */
288 movl 8(%esp), %ebx
289 cmpl %esi, %ebx
290 jle .L002finished
291 incl %esi
292 addl %eax, %edx
293 andl $255, %edx
294 incl %ecx
295 movl (%ebp,%edx,4), %ebx
296 movl %ebx, -4(%ebp,%ecx,4)
297 addl %eax, %ebx
298 andl $255, %ecx
299 andl $255, %ebx
300 movl %eax, (%ebp,%edx,4)
301 nop
302 movl (%ebp,%ebx,4), %ebx
303 movl (%ebp,%ecx,4), %eax
304 movb -1(%esi), %bh
305 xorb %bh, %bl
306 movb %bl, 4(%edi)
307 /* Round 5 */
308 movl 8(%esp), %ebx
309 cmpl %esi, %ebx
310 jle .L002finished
311 incl %esi
312 addl %eax, %edx
313 andl $255, %edx
314 incl %ecx
315 movl (%ebp,%edx,4), %ebx
316 movl %ebx, -4(%ebp,%ecx,4)
317 addl %eax, %ebx
318 andl $255, %ecx
319 andl $255, %ebx
320 movl %eax, (%ebp,%edx,4)
321 nop
322 movl (%ebp,%ebx,4), %ebx
323 movl (%ebp,%ecx,4), %eax
324 movb -1(%esi), %bh
325 xorb %bh, %bl
326 movb %bl, 5(%edi)
327 /* Round 6 */
328 movl 8(%esp), %ebx
329 cmpl %esi, %ebx
330 jle .L002finished
331 incl %esi
332 addl %eax, %edx
333 andl $255, %edx
334 incl %ecx
335 movl (%ebp,%edx,4), %ebx
336 movl %ebx, -4(%ebp,%ecx,4)
337 addl %eax, %ebx
338 andl $255, %ecx
339 andl $255, %ebx
340 movl %eax, (%ebp,%edx,4)
341 nop
342 movl (%ebp,%ebx,4), %ebx
343 movb -1(%esi), %bh
344 xorb %bh, %bl
345 movb %bl, 6(%edi)
346.L002finished:
347 decl %ecx
348 addl $12, %esp
349 movl %edx, -4(%ebp)
350 movb %cl, -8(%ebp)
351 popl %edi
352 popl %esi
353 popl %ebx
354 popl %ebp
355 ret
356.RC4_end:
357 SIZE(RC4,.RC4_end-RC4)
358.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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include "rc4.h" 62#include <openssl/rc4.h>
63 63
64char *usage[]={ 64char *usage[]={
65"usage: rc4 args\n", 65"usage: rc4 args\n",
@@ -70,9 +70,7 @@ char *usage[]={
70NULL 70NULL
71}; 71};
72 72
73int main(argc, argv) 73int main(int argc, char *argv[])
74int argc;
75char *argv[];
76 { 74 {
77 FILE *in=NULL,*out=NULL; 75 FILE *in=NULL,*out=NULL;
78 char *infile=NULL,*outfile=NULL,*keystr=NULL; 76 char *infile=NULL,*outfile=NULL,*keystr=NULL;
diff --git a/src/lib/libcrypto/rc4/rc4.org b/src/lib/libcrypto/rc4/rc4.h
index c558651af8..7418c2a9a2 100644
--- a/src/lib/libcrypto/rc4/rc4.org
+++ b/src/lib/libcrypto/rc4/rc4.h
@@ -1,4 +1,4 @@
1/* crypto/rc4/rc4.org */ 1/* crypto/rc4/rc4.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,14 +56,6 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60 *
61 * Always modify rc4.org since rc4.h is automatically generated from
62 * it during SSLeay configuration.
63 *
64 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
65 */
66
67#ifndef HEADER_RC4_H 59#ifndef HEADER_RC4_H
68#define HEADER_RC4_H 60#define HEADER_RC4_H
69 61
@@ -71,9 +63,11 @@
71extern "C" { 63extern "C" {
72#endif 64#endif
73 65
74/* using int types make the structure larger but make the code faster 66#ifdef NO_RC4
75 * on most boxes I have tested - up to %20 faster. */ 67#error RC4 is disabled.
76#define RC4_INT unsigned int 68#endif
69
70#include <openssl/opensslconf.h> /* RC4_INT */
77 71
78typedef struct rc4_key_st 72typedef struct rc4_key_st
79 { 73 {
@@ -81,21 +75,12 @@ typedef struct rc4_key_st
81 RC4_INT data[256]; 75 RC4_INT data[256];
82 } RC4_KEY; 76 } RC4_KEY;
83 77
84#ifndef NOPROTO
85 78
86char *RC4_options(void); 79const char *RC4_options(void);
87void RC4_set_key(RC4_KEY *key, int len, unsigned char *data); 80void RC4_set_key(RC4_KEY *key, int len, unsigned char *data);
88void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata, 81void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata,
89 unsigned char *outdata); 82 unsigned char *outdata);
90 83
91#else
92
93char *RC4_options();
94void RC4_set_key();
95void RC4();
96
97#endif
98
99#ifdef __cplusplus 84#ifdef __cplusplus
100} 85}
101#endif 86#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 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "rc4.h" 59#include <openssl/rc4.h>
60#include "rc4_locl.h" 60#include "rc4_locl.h"
61 61
62/* RC4 as implemented from a posting from 62/* RC4 as implemented from a posting from
@@ -67,11 +67,8 @@
67 * Date: Wed, 14 Sep 1994 06:35:31 GMT 67 * Date: Wed, 14 Sep 1994 06:35:31 GMT
68 */ 68 */
69 69
70void RC4(key, len, indata, outdata) 70void RC4(RC4_KEY *key, unsigned long len, unsigned char *indata,
71RC4_KEY *key; 71 unsigned char *outdata)
72unsigned long len;
73unsigned char *indata;
74unsigned char *outdata;
75 { 72 {
76 register RC4_INT *d; 73 register RC4_INT *d;
77 register RC4_INT x,y,tx,ty; 74 register RC4_INT x,y,tx,ty;
@@ -95,7 +92,6 @@ unsigned char *outdata;
95#define RC4_LOOP(a,b,i) LOOP(a[i],b[i]) 92#define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
96#endif 93#endif
97 94
98 i= -(int)len;
99 i=(int)(len>>3L); 95 i=(int)(len>>3L);
100 if (i) 96 if (i)
101 { 97 {
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 @@
1#ifndef HEADER_RC4_LOCL_H
2#define HEADER_RC4_LOCL_H
3#include <openssl/opensslconf.h>
4#endif
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c
index 0be5fde67b..c67a445f1f 100644
--- a/src/lib/libcrypto/rc4/rc4_skey.c
+++ b/src/lib/libcrypto/rc4/rc4_skey.c
@@ -56,12 +56,13 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include "rc4.h" 59#include <openssl/rc4.h>
60#include "rc4_locl.h" 60#include "rc4_locl.h"
61#include <openssl/opensslv.h>
61 62
62char *RC4_version="RC4 part of SSLeay 0.9.0b 29-Jun-1998"; 63const char *RC4_version="RC4" OPENSSL_VERSION_PTEXT;
63 64
64char *RC4_options() 65const char *RC4_options(void)
65 { 66 {
66#ifdef RC4_INDEX 67#ifdef RC4_INDEX
67 if (sizeof(RC4_INT) == 1) 68 if (sizeof(RC4_INT) == 1)
@@ -84,10 +85,7 @@ char *RC4_options()
84 * Date: Wed, 14 Sep 1994 06:35:31 GMT 85 * Date: Wed, 14 Sep 1994 06:35:31 GMT
85 */ 86 */
86 87
87void RC4_set_key(key, len, data) 88void RC4_set_key(RC4_KEY *key, int len, register unsigned char *data)
88RC4_KEY *key;
89int len;
90register unsigned char *data;
91 { 89 {
92 register RC4_INT tmp; 90 register RC4_INT tmp;
93 register int id1,id2; 91 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)
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <stdlib.h> 34#include <stdlib.h>
35#include "rc4.h" 35#include <openssl/rc4.h>
36 36
37void main(int argc,char *argv[]) 37void main(int argc,char *argv[])
38 { 38 {
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 @@
59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ 59/* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ 60/* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
61 61
62#ifndef MSDOS 62#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
63#define TIMES 63#define TIMES
64#endif 64#endif
65 65
66#include <stdio.h> 66#include <stdio.h>
67#ifndef MSDOS 67
68#include <unistd.h> 68#include <openssl/e_os2.h>
69#else 69#include OPENSSL_UNISTD_IO
70#include <io.h> 70OPENSSL_DECLARE_EXIT
71extern int exit(); 71
72#endif
73#include <signal.h> 72#include <signal.h>
74#ifndef VMS
75#ifndef _IRIX 73#ifndef _IRIX
76#include <time.h> 74#include <time.h>
77#endif 75#endif
@@ -79,34 +77,31 @@ extern int exit();
79#include <sys/types.h> 77#include <sys/types.h>
80#include <sys/times.h> 78#include <sys/times.h>
81#endif 79#endif
82#else /* VMS */ 80
83#include <types.h> 81/* Depending on the VMS version, the tms structure is perhaps defined.
84struct tms { 82 The __TMS macro will show if it was. If it wasn't defined, we should
85 time_t tms_utime; 83 undefine TIMES, since that tells the rest of the program how things
86 time_t tms_stime; 84 should be handled. -- Richard Levitte */
87 time_t tms_uchild; /* I dunno... */ 85#if defined(VMS) && defined(__DECC) && !defined(__TMS)
88 time_t tms_uchildsys; /* so these names are a guess :-) */ 86#undef TIMES
89 }
90#endif 87#endif
88
91#ifndef TIMES 89#ifndef TIMES
92#include <sys/timeb.h> 90#include <sys/timeb.h>
93#endif 91#endif
94 92
95#ifdef sun 93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
96#include <limits.h> 95#include <limits.h>
97#include <sys/param.h> 96#include <sys/param.h>
98#endif 97#endif
99 98
100#include "rc4.h" 99#include <openssl/rc4.h>
101 100
102/* The following if from times(3) man page. It may need to be changed */ 101/* The following if from times(3) man page. It may need to be changed */
103#ifndef HZ 102#ifndef HZ
104#ifndef CLK_TCK 103#ifndef CLK_TCK
105#ifndef VMS
106#define HZ 100.0
107#else /* VMS */
108#define HZ 100.0 104#define HZ 100.0
109#endif
110#else /* CLK_TCK */ 105#else /* CLK_TCK */
111#define HZ ((double)CLK_TCK) 106#define HZ ((double)CLK_TCK)
112#endif 107#endif
@@ -115,12 +110,7 @@ struct tms {
115#define BUFSIZE ((long)1024) 110#define BUFSIZE ((long)1024)
116long run=0; 111long run=0;
117 112
118#ifndef NOPROTO
119double Time_F(int s); 113double Time_F(int s);
120#else
121double Time_F();
122#endif
123
124#ifdef SIGALRM 114#ifdef SIGALRM
125#if defined(__STDC__) || defined(sgi) || defined(_AIX) 115#if defined(__STDC__) || defined(sgi) || defined(_AIX)
126#define SIGRETTYPE void 116#define SIGRETTYPE void
@@ -128,14 +118,8 @@ double Time_F();
128#define SIGRETTYPE int 118#define SIGRETTYPE int
129#endif 119#endif
130 120
131#ifndef NOPROTO
132SIGRETTYPE sig_done(int sig); 121SIGRETTYPE sig_done(int sig);
133#else 122SIGRETTYPE sig_done(int sig)
134SIGRETTYPE sig_done();
135#endif
136
137SIGRETTYPE sig_done(sig)
138int sig;
139 { 123 {
140 signal(SIGALRM,sig_done); 124 signal(SIGALRM,sig_done);
141 run=0; 125 run=0;
@@ -148,8 +132,7 @@ int sig;
148#define START 0 132#define START 0
149#define STOP 1 133#define STOP 1
150 134
151double Time_F(s) 135double Time_F(int s)
152int s;
153 { 136 {
154 double ret; 137 double ret;
155#ifdef TIMES 138#ifdef TIMES
@@ -185,9 +168,7 @@ int s;
185#endif 168#endif
186 } 169 }
187 170
188int main(argc,argv) 171int main(int argc, char **argv)
189int argc;
190char **argv;
191 { 172 {
192 long count; 173 long count;
193 static unsigned char buf[BUFSIZE]; 174 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include "rc4.h" 62
63#ifdef NO_RC4
64int main(int argc, char *argv[])
65{
66 printf("No RC4 support\n");
67 return(0);
68}
69#else
70#include <openssl/rc4.h>
63 71
64unsigned char keys[7][30]={ 72unsigned char keys[7][30]={
65 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}, 73 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
@@ -101,9 +109,7 @@ unsigned char output[7][30]={
101 {0}, 109 {0},
102 }; 110 };
103 111
104int main(argc,argv) 112int main(int argc, char *argv[])
105int argc;
106char *argv[];
107 { 113 {
108 int i,err=0; 114 int i,err=0;
109 int j; 115 int j;
@@ -192,4 +198,4 @@ char *argv[];
192 exit(err); 198 exit(err);
193 return(0); 199 return(0);
194 } 200 }
195 201#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
8CPP= $(CC) -E 8CPP= $(CC) -E
9INCLUDES= 9INCLUDES=
10CFLAG=-g 10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
11INSTALLTOP=/usr/local/ssl 13INSTALLTOP=/usr/local/ssl
12MAKE= make -f Makefile.ssl 14MAKE= make -f Makefile.ssl
13MAKEDEPEND= makedepend -f Makefile.ssl 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
14MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
15AR= ar r 17AR= ar r
16 18
@@ -42,7 +44,7 @@ all: lib
42 44
43lib: $(LIBOBJ) 45lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ) 46 $(AR) $(LIB) $(LIBOBJ)
45 sh $(TOP)/util/ranlib.sh $(LIB) 47 $(RANLIB) $(LIB)
46 @touch lib 48 @touch lib
47 49
48# elf 50# elf
@@ -61,27 +63,25 @@ asm/r586-out.o: asm/r586unix.cpp
61 63
62# bsdi 64# bsdi
63asm/r586bsdi.o: asm/r586unix.cpp 65asm/r586bsdi.o: asm/r586unix.cpp
64 $(CPP) -DBSDI asm/r586unix.cpp | as -o asm/r586bsdi.o 66 $(CPP) -DBSDI asm/r586unix.cpp | sed 's/ :/:/' | as -o asm/r586bsdi.o
65 67
66asm/r586unix.cpp: 68asm/r586unix.cpp:
67 (cd asm; perl rc5-586.pl cpp >r586unix.cpp) 69 (cd asm; $(PERL) rc5-586.pl cpp >r586unix.cpp)
68 70
69files: 71files:
70 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 72 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
71 73
72links: 74links:
73 /bin/rm -f Makefile 75 @$(TOP)/util/point.sh Makefile.ssl Makefile
74 $(TOP)/util/point.sh Makefile.ssl Makefile ; 76 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
75 $(TOP)/util/point.sh ../../doc/rc5.doc rc5.doc ; 77 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
76 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 78 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
77 $(TOP)/util/mklink.sh ../../test $(TEST)
78 $(TOP)/util/mklink.sh ../../apps $(APPS)
79 79
80install: 80install:
81 @for i in $(EXHEADER) ; \ 81 @for i in $(EXHEADER) ; \
82 do \ 82 do \
83 (cp $$i $(INSTALLTOP)/include/$$i; \ 83 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
84 chmod 644 $(INSTALLTOP)/include/$$i ); \ 84 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
85 done; 85 done;
86 86
87tags: 87tags:
@@ -93,15 +93,20 @@ lint:
93 lint -DLINT $(INCLUDES) $(SRC)>fluff 93 lint -DLINT $(INCLUDES) $(SRC)>fluff
94 94
95depend: 95depend:
96 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 96 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
97 97
98dclean: 98dclean:
99 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 99 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
100 mv -f Makefile.new $(MAKEFILE) 100 mv -f Makefile.new $(MAKEFILE)
101 101
102clean: 102clean:
103 /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 103 rm -f asm/r586unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
104
105errors:
106 104
107# DO NOT DELETE THIS LINE -- make depend depends on it. 105# DO NOT DELETE THIS LINE -- make depend depends on it.
106
107rc5_ecb.o: ../../include/openssl/opensslv.h ../../include/openssl/rc5.h
108rc5_ecb.o: rc5_locl.h
109rc5_enc.o: ../../include/openssl/rc5.h rc5_locl.h
110rc5_skey.o: ../../include/openssl/rc5.h rc5_locl.h
111rc5cfb64.o: ../../include/openssl/rc5.h rc5_locl.h
112rc5ofb64.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
15MAKEDEPEND= makedepend 15MAKEDEPEND= makedepend
16MAKEFILE= Makefile.uni 16MAKEFILE= Makefile.uni
17AR= ar r 17AR= ar r
18RANLIB= ranlib
18 19
19IDEA_ENC=rc2_cbc.o 20IDEA_ENC=rc2_cbc.o
20 21
@@ -39,7 +40,7 @@ all: $(LIB) $(TEST) $(APPS)
39 40
40$(LIB): $(LIBOBJ) 41$(LIB): $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ) 42 $(AR) $(LIB) $(LIBOBJ)
42 sh $(TOP)/ranlib.sh $(LIB) 43 $(RANLIB) $(LIB)
43 44
44test: $(TEST) 45test: $(TEST)
45 ./$(TEST) 46 ./$(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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define RC5_32_encrypt _RC5_32_encrypt
13#define RC5_32_decrypt _RC5_32_decrypt
14#define RC5_32_cbc_encrypt _RC5_32_cbc_encrypt
15
16#endif
17
18#ifdef OUT
19#define OK 1
20#define ALIGN 4
21#endif
22
23#ifdef BSDI
24#define OK 1
25#define ALIGN 4
26#undef SIZE
27#undef TYPE
28#define SIZE(a,b)
29#define TYPE(a,b)
30#endif
31
32#if defined(ELF) || defined(SOL)
33#define OK 1
34#define ALIGN 16
35#endif
36
37#ifndef OK
38You need to define one of
39ELF - elf systems - linux-elf, NetBSD and DG-UX
40OUT - a.out systems - linux-a.out and FreeBSD
41SOL - solaris systems, which are elf with strange comment lines
42BSDI - a.out with a very primative version of as.
43#endif
44
45/* Let the Assembler begin :-) */
46 /* Don't even think of reading this code */
47 /* It was automatically generated by rc5-586.pl */
48 /* Which is a perl program used to generate the x86 assember for */
49 /* any of elf, a.out, BSDI,Win32, or Solaris */
50 /* eric <eay@cryptsoft.com> */
51
52 .file "rc5-586.s"
53 .version "01.01"
54gcc2_compiled.:
55.text
56 .align ALIGN
57.globl RC5_32_encrypt
58 TYPE(RC5_32_encrypt,@function)
59RC5_32_encrypt:
60
61 pushl %ebp
62 pushl %esi
63 pushl %edi
64 movl 16(%esp), %edx
65 movl 20(%esp), %ebp
66 /* Load the 2 words */
67 movl (%edx), %edi
68 movl 4(%edx), %esi
69 pushl %ebx
70 movl (%ebp), %ebx
71 addl 4(%ebp), %edi
72 addl 8(%ebp), %esi
73 xorl %esi, %edi
74 movl 12(%ebp), %eax
75 movl %esi, %ecx
76 roll %cl, %edi
77 addl %eax, %edi
78 xorl %edi, %esi
79 movl 16(%ebp), %eax
80 movl %edi, %ecx
81 roll %cl, %esi
82 addl %eax, %esi
83 xorl %esi, %edi
84 movl 20(%ebp), %eax
85 movl %esi, %ecx
86 roll %cl, %edi
87 addl %eax, %edi
88 xorl %edi, %esi
89 movl 24(%ebp), %eax
90 movl %edi, %ecx
91 roll %cl, %esi
92 addl %eax, %esi
93 xorl %esi, %edi
94 movl 28(%ebp), %eax
95 movl %esi, %ecx
96 roll %cl, %edi
97 addl %eax, %edi
98 xorl %edi, %esi
99 movl 32(%ebp), %eax
100 movl %edi, %ecx
101 roll %cl, %esi
102 addl %eax, %esi
103 xorl %esi, %edi
104 movl 36(%ebp), %eax
105 movl %esi, %ecx
106 roll %cl, %edi
107 addl %eax, %edi
108 xorl %edi, %esi
109 movl 40(%ebp), %eax
110 movl %edi, %ecx
111 roll %cl, %esi
112 addl %eax, %esi
113 xorl %esi, %edi
114 movl 44(%ebp), %eax
115 movl %esi, %ecx
116 roll %cl, %edi
117 addl %eax, %edi
118 xorl %edi, %esi
119 movl 48(%ebp), %eax
120 movl %edi, %ecx
121 roll %cl, %esi
122 addl %eax, %esi
123 xorl %esi, %edi
124 movl 52(%ebp), %eax
125 movl %esi, %ecx
126 roll %cl, %edi
127 addl %eax, %edi
128 xorl %edi, %esi
129 movl 56(%ebp), %eax
130 movl %edi, %ecx
131 roll %cl, %esi
132 addl %eax, %esi
133 xorl %esi, %edi
134 movl 60(%ebp), %eax
135 movl %esi, %ecx
136 roll %cl, %edi
137 addl %eax, %edi
138 xorl %edi, %esi
139 movl 64(%ebp), %eax
140 movl %edi, %ecx
141 roll %cl, %esi
142 addl %eax, %esi
143 xorl %esi, %edi
144 movl 68(%ebp), %eax
145 movl %esi, %ecx
146 roll %cl, %edi
147 addl %eax, %edi
148 xorl %edi, %esi
149 movl 72(%ebp), %eax
150 movl %edi, %ecx
151 roll %cl, %esi
152 addl %eax, %esi
153 cmpl $8, %ebx
154 je .L000rc5_exit
155 xorl %esi, %edi
156 movl 76(%ebp), %eax
157 movl %esi, %ecx
158 roll %cl, %edi
159 addl %eax, %edi
160 xorl %edi, %esi
161 movl 80(%ebp), %eax
162 movl %edi, %ecx
163 roll %cl, %esi
164 addl %eax, %esi
165 xorl %esi, %edi
166 movl 84(%ebp), %eax
167 movl %esi, %ecx
168 roll %cl, %edi
169 addl %eax, %edi
170 xorl %edi, %esi
171 movl 88(%ebp), %eax
172 movl %edi, %ecx
173 roll %cl, %esi
174 addl %eax, %esi
175 xorl %esi, %edi
176 movl 92(%ebp), %eax
177 movl %esi, %ecx
178 roll %cl, %edi
179 addl %eax, %edi
180 xorl %edi, %esi
181 movl 96(%ebp), %eax
182 movl %edi, %ecx
183 roll %cl, %esi
184 addl %eax, %esi
185 xorl %esi, %edi
186 movl 100(%ebp), %eax
187 movl %esi, %ecx
188 roll %cl, %edi
189 addl %eax, %edi
190 xorl %edi, %esi
191 movl 104(%ebp), %eax
192 movl %edi, %ecx
193 roll %cl, %esi
194 addl %eax, %esi
195 cmpl $12, %ebx
196 je .L000rc5_exit
197 xorl %esi, %edi
198 movl 108(%ebp), %eax
199 movl %esi, %ecx
200 roll %cl, %edi
201 addl %eax, %edi
202 xorl %edi, %esi
203 movl 112(%ebp), %eax
204 movl %edi, %ecx
205 roll %cl, %esi
206 addl %eax, %esi
207 xorl %esi, %edi
208 movl 116(%ebp), %eax
209 movl %esi, %ecx
210 roll %cl, %edi
211 addl %eax, %edi
212 xorl %edi, %esi
213 movl 120(%ebp), %eax
214 movl %edi, %ecx
215 roll %cl, %esi
216 addl %eax, %esi
217 xorl %esi, %edi
218 movl 124(%ebp), %eax
219 movl %esi, %ecx
220 roll %cl, %edi
221 addl %eax, %edi
222 xorl %edi, %esi
223 movl 128(%ebp), %eax
224 movl %edi, %ecx
225 roll %cl, %esi
226 addl %eax, %esi
227 xorl %esi, %edi
228 movl 132(%ebp), %eax
229 movl %esi, %ecx
230 roll %cl, %edi
231 addl %eax, %edi
232 xorl %edi, %esi
233 movl 136(%ebp), %eax
234 movl %edi, %ecx
235 roll %cl, %esi
236 addl %eax, %esi
237.L000rc5_exit:
238 movl %edi, (%edx)
239 movl %esi, 4(%edx)
240 popl %ebx
241 popl %edi
242 popl %esi
243 popl %ebp
244 ret
245.RC5_32_encrypt_end:
246 SIZE(RC5_32_encrypt,.RC5_32_encrypt_end-RC5_32_encrypt)
247.ident "desasm.pl"
248.text
249 .align ALIGN
250.globl RC5_32_decrypt
251 TYPE(RC5_32_decrypt,@function)
252RC5_32_decrypt:
253
254 pushl %ebp
255 pushl %esi
256 pushl %edi
257 movl 16(%esp), %edx
258 movl 20(%esp), %ebp
259 /* Load the 2 words */
260 movl (%edx), %edi
261 movl 4(%edx), %esi
262 pushl %ebx
263 movl (%ebp), %ebx
264 cmpl $12, %ebx
265 je .L001rc5_dec_12
266 cmpl $8, %ebx
267 je .L002rc5_dec_8
268 movl 136(%ebp), %eax
269 subl %eax, %esi
270 movl %edi, %ecx
271 rorl %cl, %esi
272 xorl %edi, %esi
273 movl 132(%ebp), %eax
274 subl %eax, %edi
275 movl %esi, %ecx
276 rorl %cl, %edi
277 xorl %esi, %edi
278 movl 128(%ebp), %eax
279 subl %eax, %esi
280 movl %edi, %ecx
281 rorl %cl, %esi
282 xorl %edi, %esi
283 movl 124(%ebp), %eax
284 subl %eax, %edi
285 movl %esi, %ecx
286 rorl %cl, %edi
287 xorl %esi, %edi
288 movl 120(%ebp), %eax
289 subl %eax, %esi
290 movl %edi, %ecx
291 rorl %cl, %esi
292 xorl %edi, %esi
293 movl 116(%ebp), %eax
294 subl %eax, %edi
295 movl %esi, %ecx
296 rorl %cl, %edi
297 xorl %esi, %edi
298 movl 112(%ebp), %eax
299 subl %eax, %esi
300 movl %edi, %ecx
301 rorl %cl, %esi
302 xorl %edi, %esi
303 movl 108(%ebp), %eax
304 subl %eax, %edi
305 movl %esi, %ecx
306 rorl %cl, %edi
307 xorl %esi, %edi
308.L001rc5_dec_12:
309 movl 104(%ebp), %eax
310 subl %eax, %esi
311 movl %edi, %ecx
312 rorl %cl, %esi
313 xorl %edi, %esi
314 movl 100(%ebp), %eax
315 subl %eax, %edi
316 movl %esi, %ecx
317 rorl %cl, %edi
318 xorl %esi, %edi
319 movl 96(%ebp), %eax
320 subl %eax, %esi
321 movl %edi, %ecx
322 rorl %cl, %esi
323 xorl %edi, %esi
324 movl 92(%ebp), %eax
325 subl %eax, %edi
326 movl %esi, %ecx
327 rorl %cl, %edi
328 xorl %esi, %edi
329 movl 88(%ebp), %eax
330 subl %eax, %esi
331 movl %edi, %ecx
332 rorl %cl, %esi
333 xorl %edi, %esi
334 movl 84(%ebp), %eax
335 subl %eax, %edi
336 movl %esi, %ecx
337 rorl %cl, %edi
338 xorl %esi, %edi
339 movl 80(%ebp), %eax
340 subl %eax, %esi
341 movl %edi, %ecx
342 rorl %cl, %esi
343 xorl %edi, %esi
344 movl 76(%ebp), %eax
345 subl %eax, %edi
346 movl %esi, %ecx
347 rorl %cl, %edi
348 xorl %esi, %edi
349.L002rc5_dec_8:
350 movl 72(%ebp), %eax
351 subl %eax, %esi
352 movl %edi, %ecx
353 rorl %cl, %esi
354 xorl %edi, %esi
355 movl 68(%ebp), %eax
356 subl %eax, %edi
357 movl %esi, %ecx
358 rorl %cl, %edi
359 xorl %esi, %edi
360 movl 64(%ebp), %eax
361 subl %eax, %esi
362 movl %edi, %ecx
363 rorl %cl, %esi
364 xorl %edi, %esi
365 movl 60(%ebp), %eax
366 subl %eax, %edi
367 movl %esi, %ecx
368 rorl %cl, %edi
369 xorl %esi, %edi
370 movl 56(%ebp), %eax
371 subl %eax, %esi
372 movl %edi, %ecx
373 rorl %cl, %esi
374 xorl %edi, %esi
375 movl 52(%ebp), %eax
376 subl %eax, %edi
377 movl %esi, %ecx
378 rorl %cl, %edi
379 xorl %esi, %edi
380 movl 48(%ebp), %eax
381 subl %eax, %esi
382 movl %edi, %ecx
383 rorl %cl, %esi
384 xorl %edi, %esi
385 movl 44(%ebp), %eax
386 subl %eax, %edi
387 movl %esi, %ecx
388 rorl %cl, %edi
389 xorl %esi, %edi
390 movl 40(%ebp), %eax
391 subl %eax, %esi
392 movl %edi, %ecx
393 rorl %cl, %esi
394 xorl %edi, %esi
395 movl 36(%ebp), %eax
396 subl %eax, %edi
397 movl %esi, %ecx
398 rorl %cl, %edi
399 xorl %esi, %edi
400 movl 32(%ebp), %eax
401 subl %eax, %esi
402 movl %edi, %ecx
403 rorl %cl, %esi
404 xorl %edi, %esi
405 movl 28(%ebp), %eax
406 subl %eax, %edi
407 movl %esi, %ecx
408 rorl %cl, %edi
409 xorl %esi, %edi
410 movl 24(%ebp), %eax
411 subl %eax, %esi
412 movl %edi, %ecx
413 rorl %cl, %esi
414 xorl %edi, %esi
415 movl 20(%ebp), %eax
416 subl %eax, %edi
417 movl %esi, %ecx
418 rorl %cl, %edi
419 xorl %esi, %edi
420 movl 16(%ebp), %eax
421 subl %eax, %esi
422 movl %edi, %ecx
423 rorl %cl, %esi
424 xorl %edi, %esi
425 movl 12(%ebp), %eax
426 subl %eax, %edi
427 movl %esi, %ecx
428 rorl %cl, %edi
429 xorl %esi, %edi
430 subl 8(%ebp), %esi
431 subl 4(%ebp), %edi
432.L003rc5_exit:
433 movl %edi, (%edx)
434 movl %esi, 4(%edx)
435 popl %ebx
436 popl %edi
437 popl %esi
438 popl %ebp
439 ret
440.RC5_32_decrypt_end:
441 SIZE(RC5_32_decrypt,.RC5_32_decrypt_end-RC5_32_decrypt)
442.ident "desasm.pl"
443.text
444 .align ALIGN
445.globl RC5_32_cbc_encrypt
446 TYPE(RC5_32_cbc_encrypt,@function)
447RC5_32_cbc_encrypt:
448
449 pushl %ebp
450 pushl %ebx
451 pushl %esi
452 pushl %edi
453 movl 28(%esp), %ebp
454 /* getting iv ptr from parameter 4 */
455 movl 36(%esp), %ebx
456 movl (%ebx), %esi
457 movl 4(%ebx), %edi
458 pushl %edi
459 pushl %esi
460 pushl %edi
461 pushl %esi
462 movl %esp, %ebx
463 movl 36(%esp), %esi
464 movl 40(%esp), %edi
465 /* getting encrypt flag from parameter 5 */
466 movl 56(%esp), %ecx
467 /* get and push parameter 3 */
468 movl 48(%esp), %eax
469 pushl %eax
470 pushl %ebx
471 cmpl $0, %ecx
472 jz .L004decrypt
473 andl $4294967288, %ebp
474 movl 8(%esp), %eax
475 movl 12(%esp), %ebx
476 jz .L005encrypt_finish
477.L006encrypt_loop:
478 movl (%esi), %ecx
479 movl 4(%esi), %edx
480 xorl %ecx, %eax
481 xorl %edx, %ebx
482 movl %eax, 8(%esp)
483 movl %ebx, 12(%esp)
484 call RC5_32_encrypt
485 movl 8(%esp), %eax
486 movl 12(%esp), %ebx
487 movl %eax, (%edi)
488 movl %ebx, 4(%edi)
489 addl $8, %esi
490 addl $8, %edi
491 subl $8, %ebp
492 jnz .L006encrypt_loop
493.L005encrypt_finish:
494 movl 52(%esp), %ebp
495 andl $7, %ebp
496 jz .L007finish
497 xorl %ecx, %ecx
498 xorl %edx, %edx
499 movl .L008cbc_enc_jmp_table(,%ebp,4),%ebp
500 jmp *%ebp
501.L009ej7:
502 movb 6(%esi), %dh
503 sall $8, %edx
504.L010ej6:
505 movb 5(%esi), %dh
506.L011ej5:
507 movb 4(%esi), %dl
508.L012ej4:
509 movl (%esi), %ecx
510 jmp .L013ejend
511.L014ej3:
512 movb 2(%esi), %ch
513 sall $8, %ecx
514.L015ej2:
515 movb 1(%esi), %ch
516.L016ej1:
517 movb (%esi), %cl
518.L013ejend:
519 xorl %ecx, %eax
520 xorl %edx, %ebx
521 movl %eax, 8(%esp)
522 movl %ebx, 12(%esp)
523 call RC5_32_encrypt
524 movl 8(%esp), %eax
525 movl 12(%esp), %ebx
526 movl %eax, (%edi)
527 movl %ebx, 4(%edi)
528 jmp .L007finish
529.align ALIGN
530.L004decrypt:
531 andl $4294967288, %ebp
532 movl 16(%esp), %eax
533 movl 20(%esp), %ebx
534 jz .L017decrypt_finish
535.L018decrypt_loop:
536 movl (%esi), %eax
537 movl 4(%esi), %ebx
538 movl %eax, 8(%esp)
539 movl %ebx, 12(%esp)
540 call RC5_32_decrypt
541 movl 8(%esp), %eax
542 movl 12(%esp), %ebx
543 movl 16(%esp), %ecx
544 movl 20(%esp), %edx
545 xorl %eax, %ecx
546 xorl %ebx, %edx
547 movl (%esi), %eax
548 movl 4(%esi), %ebx
549 movl %ecx, (%edi)
550 movl %edx, 4(%edi)
551 movl %eax, 16(%esp)
552 movl %ebx, 20(%esp)
553 addl $8, %esi
554 addl $8, %edi
555 subl $8, %ebp
556 jnz .L018decrypt_loop
557.L017decrypt_finish:
558 movl 52(%esp), %ebp
559 andl $7, %ebp
560 jz .L007finish
561 movl (%esi), %eax
562 movl 4(%esi), %ebx
563 movl %eax, 8(%esp)
564 movl %ebx, 12(%esp)
565 call RC5_32_decrypt
566 movl 8(%esp), %eax
567 movl 12(%esp), %ebx
568 movl 16(%esp), %ecx
569 movl 20(%esp), %edx
570 xorl %eax, %ecx
571 xorl %ebx, %edx
572 movl (%esi), %eax
573 movl 4(%esi), %ebx
574.L019dj7:
575 rorl $16, %edx
576 movb %dl, 6(%edi)
577 shrl $16, %edx
578.L020dj6:
579 movb %dh, 5(%edi)
580.L021dj5:
581 movb %dl, 4(%edi)
582.L022dj4:
583 movl %ecx, (%edi)
584 jmp .L023djend
585.L024dj3:
586 rorl $16, %ecx
587 movb %cl, 2(%edi)
588 sall $16, %ecx
589.L025dj2:
590 movb %ch, 1(%esi)
591.L026dj1:
592 movb %cl, (%esi)
593.L023djend:
594 jmp .L007finish
595.align ALIGN
596.L007finish:
597 movl 60(%esp), %ecx
598 addl $24, %esp
599 movl %eax, (%ecx)
600 movl %ebx, 4(%ecx)
601 popl %edi
602 popl %esi
603 popl %ebx
604 popl %ebp
605 ret
606.align ALIGN
607.L008cbc_enc_jmp_table:
608 .long 0
609 .long .L016ej1
610 .long .L015ej2
611 .long .L014ej3
612 .long .L012ej4
613 .long .L011ej5
614 .long .L010ej6
615 .long .L009ej7
616.align ALIGN
617.L027cbc_dec_jmp_table:
618 .long 0
619 .long .L026dj1
620 .long .L025dj2
621 .long .L024dj3
622 .long .L022dj4
623 .long .L021dj5
624 .long .L020dj6
625 .long .L019dj7
626.RC5_32_cbc_encrypt_end:
627 SIZE(RC5_32_cbc_encrypt,.RC5_32_cbc_encrypt_end-RC5_32_cbc_encrypt)
628.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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3push(@INC,"perlasm","../../perlasm"); 3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl"; 4require "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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifdef NO_RC5
67#error RC5 is disabled.
68#endif
69
66#define RC5_ENCRYPT 1 70#define RC5_ENCRYPT 1
67#define RC5_DECRYPT 0 71#define RC5_DECRYPT 0
68 72
@@ -88,7 +92,6 @@ typedef struct rc5_key_st
88 RC5_32_INT data[2*(RC5_16_ROUNDS+1)]; 92 RC5_32_INT data[2*(RC5_16_ROUNDS+1)];
89 } RC5_32_KEY; 93 } RC5_32_KEY;
90 94
91#ifndef NOPROTO
92 95
93void RC5_32_set_key(RC5_32_KEY *key, int len, unsigned char *data, 96void RC5_32_set_key(RC5_32_KEY *key, int len, unsigned char *data,
94 int rounds); 97 int rounds);
@@ -103,18 +106,6 @@ void RC5_32_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
103void RC5_32_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, 106void RC5_32_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
104 RC5_32_KEY *schedule, unsigned char *ivec, int *num); 107 RC5_32_KEY *schedule, unsigned char *ivec, int *num);
105 108
106#else
107
108void RC5_32_set_key();
109void RC5_32_ecb_encrypt();
110void RC5_32_encrypt();
111void RC5_32_decrypt();
112void RC5_32_cbc_encrypt();
113void RC5_32_cfb64_encrypt();
114void RC5_32_ofb64_encrypt();
115
116#endif
117
118#ifdef __cplusplus 109#ifdef __cplusplus
119} 110}
120#endif 111#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
8CPP= $(CC) -E 8CPP= $(CC) -E
9INCLUDES= 9INCLUDES=
10CFLAG=-g 10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
11INSTALLTOP=/usr/local/ssl 13INSTALLTOP=/usr/local/ssl
12MAKE= make -f Makefile.ssl 14MAKE= make -f Makefile.ssl
13MAKEDEPEND= makedepend -f Makefile.ssl 15MAKEDEPEND= $(TOP)/util/domd $(TOP)
14MAKEFILE= Makefile.ssl 16MAKEFILE= Makefile.ssl
15AR= ar r 17AR= ar r
16 18
@@ -40,7 +42,7 @@ all: lib
40 42
41lib: $(LIBOBJ) 43lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ) 44 $(AR) $(LIB) $(LIBOBJ)
43 sh $(TOP)/util/ranlib.sh $(LIB) 45 $(RANLIB) $(LIB)
44 @touch lib 46 @touch lib
45 47
46# elf 48# elf
@@ -59,26 +61,25 @@ asm/rm86-out.o: asm/rm86unix.cpp
59 61
60# bsdi 62# bsdi
61asm/rm86bsdi.o: asm/rm86unix.cpp 63asm/rm86bsdi.o: asm/rm86unix.cpp
62 $(CPP) -DBSDI asm/rm86unix.cpp | as -o asm/rm86bsdi.o 64 $(CPP) -DBSDI asm/rm86unix.cpp | sed 's/ :/:/' | as -o asm/rm86bsdi.o
63 65
64asm/rm86unix.cpp: 66asm/rm86unix.cpp: asm/rmd-586.pl
65 (cd asm; perl rmd-586.pl cpp >rm86unix.cpp) 67 (cd asm; $(PERL) rmd-586.pl cpp >rm86unix.cpp)
66 68
67files: 69files:
68 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 70 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
69 71
70links: 72links:
71 /bin/rm -f Makefile 73 @$(TOP)/util/point.sh Makefile.ssl Makefile
72 $(TOP)/util/point.sh Makefile.ssl Makefile ; 74 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
73 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 75 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
74 $(TOP)/util/mklink.sh ../../test $(TEST) 76 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
75 $(TOP)/util/mklink.sh ../../apps $(APPS)
76 77
77install: 78install:
78 @for i in $(EXHEADER) ; \ 79 @for i in $(EXHEADER) ; \
79 do \ 80 do \
80 (cp $$i $(INSTALLTOP)/include/$$i; \ 81 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
81 chmod 644 $(INSTALLTOP)/include/$$i ); \ 82 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
82 done; 83 done;
83 84
84tags: 85tags:
@@ -90,15 +91,17 @@ lint:
90 lint -DLINT $(INCLUDES) $(SRC)>fluff 91 lint -DLINT $(INCLUDES) $(SRC)>fluff
91 92
92depend: 93depend:
93 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 94 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
94 95
95dclean: 96dclean:
96 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 97 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
97 mv -f Makefile.new $(MAKEFILE) 98 mv -f Makefile.new $(MAKEFILE)
98 99
99clean: 100clean:
100 /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 101 rm -f asm/rm86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
101
102errors:
103 102
104# DO NOT DELETE THIS LINE -- make depend depends on it. 103# DO NOT DELETE THIS LINE -- make depend depends on it.
104
105rmd_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ripemd.h
106rmd_dgst.o: rmd_locl.h rmdconst.h
107rmd_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)
43 43
44$(LIB): $(LIBOBJ) 44$(LIB): $(LIBOBJ)
45 $(AR) $(LIB) $(LIBOBJ) 45 $(AR) $(LIB) $(LIBOBJ)
46 sh $(TOP)/ranlib.sh $(LIB) 46 $(RANLIB) $(LIB)
47 47
48# elf 48# elf
49asm/mx86-elf.o: asm/mx86unix.cpp 49asm/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)
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <stdlib.h> 34#include <stdlib.h>
35#include "ripemd.h" 35#include <openssl/ripemd.h>
36 36
37extern "C" { 37extern "C" {
38void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num); 38void 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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define ripemd160_block_x86 _ripemd160_block_x86
13
14#endif
15
16#ifdef OUT
17#define OK 1
18#define ALIGN 4
19#endif
20
21#ifdef BSDI
22#define OK 1
23#define ALIGN 4
24#undef SIZE
25#undef TYPE
26#define SIZE(a,b)
27#define TYPE(a,b)
28#endif
29
30#if defined(ELF) || defined(SOL)
31#define OK 1
32#define ALIGN 16
33#endif
34
35#ifndef OK
36You need to define one of
37ELF - elf systems - linux-elf, NetBSD and DG-UX
38OUT - a.out systems - linux-a.out and FreeBSD
39SOL - solaris systems, which are elf with strange comment lines
40BSDI - a.out with a very primative version of as.
41#endif
42
43/* Let the Assembler begin :-) */
44 /* Don't even think of reading this code */
45 /* It was automatically generated by rmd-586.pl */
46 /* Which is a perl program used to generate the x86 assember for */
47 /* any of elf, a.out, BSDI,Win32, or Solaris */
48 /* eric <eay@cryptsoft.com> */
49
50 .file "rmd-586.s"
51 .version "01.01"
52gcc2_compiled.:
53.text
54 .align ALIGN
55.globl ripemd160_block_x86
56 TYPE(ripemd160_block_x86,@function)
57ripemd160_block_x86:
58 pushl %esi
59 movl 16(%esp), %ecx
60 pushl %edi
61 movl 16(%esp), %esi
62 pushl %ebp
63 addl %esi, %ecx
64 pushl %ebx
65 subl $64, %ecx
66 subl $88, %esp
67 movl %ecx, (%esp)
68 movl 108(%esp), %edi
69.L000start:
70
71 movl (%esi), %eax
72 movl 4(%esi), %ebx
73 movl %eax, 4(%esp)
74 movl %ebx, 8(%esp)
75 movl 8(%esi), %eax
76 movl 12(%esi), %ebx
77 movl %eax, 12(%esp)
78 movl %ebx, 16(%esp)
79 movl 16(%esi), %eax
80 movl 20(%esi), %ebx
81 movl %eax, 20(%esp)
82 movl %ebx, 24(%esp)
83 movl 24(%esi), %eax
84 movl 28(%esi), %ebx
85 movl %eax, 28(%esp)
86 movl %ebx, 32(%esp)
87 movl 32(%esi), %eax
88 movl 36(%esi), %ebx
89 movl %eax, 36(%esp)
90 movl %ebx, 40(%esp)
91 movl 40(%esi), %eax
92 movl 44(%esi), %ebx
93 movl %eax, 44(%esp)
94 movl %ebx, 48(%esp)
95 movl 48(%esi), %eax
96 movl 52(%esi), %ebx
97 movl %eax, 52(%esp)
98 movl %ebx, 56(%esp)
99 movl 56(%esi), %eax
100 movl 60(%esi), %ebx
101 movl %eax, 60(%esp)
102 movl %ebx, 64(%esp)
103 addl $64, %esi
104 movl (%edi), %eax
105 movl %esi, 112(%esp)
106 movl 4(%edi), %ebx
107 movl 8(%edi), %ecx
108 movl 12(%edi), %edx
109 movl 16(%edi), %ebp
110 /* 0 */
111 movl %ecx, %esi
112 xorl %edx, %esi
113 movl 4(%esp), %edi
114 xorl %ebx, %esi
115 addl %edi, %eax
116 roll $10, %ecx
117 addl %esi, %eax
118 movl %ebx, %esi
119 roll $11, %eax
120 addl %ebp, %eax
121 /* 1 */
122 xorl %ecx, %esi
123 movl 8(%esp), %edi
124 xorl %eax, %esi
125 addl %esi, %ebp
126 movl %eax, %esi
127 roll $10, %ebx
128 addl %edi, %ebp
129 xorl %ebx, %esi
130 roll $14, %ebp
131 addl %edx, %ebp
132 /* 2 */
133 movl 12(%esp), %edi
134 xorl %ebp, %esi
135 addl %edi, %edx
136 roll $10, %eax
137 addl %esi, %edx
138 movl %ebp, %esi
139 roll $15, %edx
140 addl %ecx, %edx
141 /* 3 */
142 xorl %eax, %esi
143 movl 16(%esp), %edi
144 xorl %edx, %esi
145 addl %esi, %ecx
146 movl %edx, %esi
147 roll $10, %ebp
148 addl %edi, %ecx
149 xorl %ebp, %esi
150 roll $12, %ecx
151 addl %ebx, %ecx
152 /* 4 */
153 movl 20(%esp), %edi
154 xorl %ecx, %esi
155 addl %edi, %ebx
156 roll $10, %edx
157 addl %esi, %ebx
158 movl %ecx, %esi
159 roll $5, %ebx
160 addl %eax, %ebx
161 /* 5 */
162 xorl %edx, %esi
163 movl 24(%esp), %edi
164 xorl %ebx, %esi
165 addl %esi, %eax
166 movl %ebx, %esi
167 roll $10, %ecx
168 addl %edi, %eax
169 xorl %ecx, %esi
170 roll $8, %eax
171 addl %ebp, %eax
172 /* 6 */
173 movl 28(%esp), %edi
174 xorl %eax, %esi
175 addl %edi, %ebp
176 roll $10, %ebx
177 addl %esi, %ebp
178 movl %eax, %esi
179 roll $7, %ebp
180 addl %edx, %ebp
181 /* 7 */
182 xorl %ebx, %esi
183 movl 32(%esp), %edi
184 xorl %ebp, %esi
185 addl %esi, %edx
186 movl %ebp, %esi
187 roll $10, %eax
188 addl %edi, %edx
189 xorl %eax, %esi
190 roll $9, %edx
191 addl %ecx, %edx
192 /* 8 */
193 movl 36(%esp), %edi
194 xorl %edx, %esi
195 addl %edi, %ecx
196 roll $10, %ebp
197 addl %esi, %ecx
198 movl %edx, %esi
199 roll $11, %ecx
200 addl %ebx, %ecx
201 /* 9 */
202 xorl %ebp, %esi
203 movl 40(%esp), %edi
204 xorl %ecx, %esi
205 addl %esi, %ebx
206 movl %ecx, %esi
207 roll $10, %edx
208 addl %edi, %ebx
209 xorl %edx, %esi
210 roll $13, %ebx
211 addl %eax, %ebx
212 /* 10 */
213 movl 44(%esp), %edi
214 xorl %ebx, %esi
215 addl %edi, %eax
216 roll $10, %ecx
217 addl %esi, %eax
218 movl %ebx, %esi
219 roll $14, %eax
220 addl %ebp, %eax
221 /* 11 */
222 xorl %ecx, %esi
223 movl 48(%esp), %edi
224 xorl %eax, %esi
225 addl %esi, %ebp
226 movl %eax, %esi
227 roll $10, %ebx
228 addl %edi, %ebp
229 xorl %ebx, %esi
230 roll $15, %ebp
231 addl %edx, %ebp
232 /* 12 */
233 movl 52(%esp), %edi
234 xorl %ebp, %esi
235 addl %edi, %edx
236 roll $10, %eax
237 addl %esi, %edx
238 movl %ebp, %esi
239 roll $6, %edx
240 addl %ecx, %edx
241 /* 13 */
242 xorl %eax, %esi
243 movl 56(%esp), %edi
244 xorl %edx, %esi
245 addl %esi, %ecx
246 movl %edx, %esi
247 roll $10, %ebp
248 addl %edi, %ecx
249 xorl %ebp, %esi
250 roll $7, %ecx
251 addl %ebx, %ecx
252 /* 14 */
253 movl 60(%esp), %edi
254 xorl %ecx, %esi
255 addl %edi, %ebx
256 roll $10, %edx
257 addl %esi, %ebx
258 movl %ecx, %esi
259 roll $9, %ebx
260 addl %eax, %ebx
261 /* 15 */
262 xorl %edx, %esi
263 movl 64(%esp), %edi
264 xorl %ebx, %esi
265 addl %esi, %eax
266 movl $-1, %esi
267 roll $10, %ecx
268 addl %edi, %eax
269 movl 32(%esp), %edi
270 roll $8, %eax
271 addl %ebp, %eax
272 /* 16 */
273 addl %edi, %ebp
274 movl %ebx, %edi
275 subl %eax, %esi
276 andl %eax, %edi
277 andl %ecx, %esi
278 orl %esi, %edi
279 movl 20(%esp), %esi
280 roll $10, %ebx
281 leal 1518500249(%ebp,%edi,1),%ebp
282 movl $-1, %edi
283 roll $7, %ebp
284 addl %edx, %ebp
285 /* 17 */
286 addl %esi, %edx
287 movl %eax, %esi
288 subl %ebp, %edi
289 andl %ebp, %esi
290 andl %ebx, %edi
291 orl %edi, %esi
292 movl 56(%esp), %edi
293 roll $10, %eax
294 leal 1518500249(%edx,%esi,1),%edx
295 movl $-1, %esi
296 roll $6, %edx
297 addl %ecx, %edx
298 /* 18 */
299 addl %edi, %ecx
300 movl %ebp, %edi
301 subl %edx, %esi
302 andl %edx, %edi
303 andl %eax, %esi
304 orl %esi, %edi
305 movl 8(%esp), %esi
306 roll $10, %ebp
307 leal 1518500249(%ecx,%edi,1),%ecx
308 movl $-1, %edi
309 roll $8, %ecx
310 addl %ebx, %ecx
311 /* 19 */
312 addl %esi, %ebx
313 movl %edx, %esi
314 subl %ecx, %edi
315 andl %ecx, %esi
316 andl %ebp, %edi
317 orl %edi, %esi
318 movl 44(%esp), %edi
319 roll $10, %edx
320 leal 1518500249(%ebx,%esi,1),%ebx
321 movl $-1, %esi
322 roll $13, %ebx
323 addl %eax, %ebx
324 /* 20 */
325 addl %edi, %eax
326 movl %ecx, %edi
327 subl %ebx, %esi
328 andl %ebx, %edi
329 andl %edx, %esi
330 orl %esi, %edi
331 movl 28(%esp), %esi
332 roll $10, %ecx
333 leal 1518500249(%eax,%edi,1),%eax
334 movl $-1, %edi
335 roll $11, %eax
336 addl %ebp, %eax
337 /* 21 */
338 addl %esi, %ebp
339 movl %ebx, %esi
340 subl %eax, %edi
341 andl %eax, %esi
342 andl %ecx, %edi
343 orl %edi, %esi
344 movl 64(%esp), %edi
345 roll $10, %ebx
346 leal 1518500249(%ebp,%esi,1),%ebp
347 movl $-1, %esi
348 roll $9, %ebp
349 addl %edx, %ebp
350 /* 22 */
351 addl %edi, %edx
352 movl %eax, %edi
353 subl %ebp, %esi
354 andl %ebp, %edi
355 andl %ebx, %esi
356 orl %esi, %edi
357 movl 16(%esp), %esi
358 roll $10, %eax
359 leal 1518500249(%edx,%edi,1),%edx
360 movl $-1, %edi
361 roll $7, %edx
362 addl %ecx, %edx
363 /* 23 */
364 addl %esi, %ecx
365 movl %ebp, %esi
366 subl %edx, %edi
367 andl %edx, %esi
368 andl %eax, %edi
369 orl %edi, %esi
370 movl 52(%esp), %edi
371 roll $10, %ebp
372 leal 1518500249(%ecx,%esi,1),%ecx
373 movl $-1, %esi
374 roll $15, %ecx
375 addl %ebx, %ecx
376 /* 24 */
377 addl %edi, %ebx
378 movl %edx, %edi
379 subl %ecx, %esi
380 andl %ecx, %edi
381 andl %ebp, %esi
382 orl %esi, %edi
383 movl 4(%esp), %esi
384 roll $10, %edx
385 leal 1518500249(%ebx,%edi,1),%ebx
386 movl $-1, %edi
387 roll $7, %ebx
388 addl %eax, %ebx
389 /* 25 */
390 addl %esi, %eax
391 movl %ecx, %esi
392 subl %ebx, %edi
393 andl %ebx, %esi
394 andl %edx, %edi
395 orl %edi, %esi
396 movl 40(%esp), %edi
397 roll $10, %ecx
398 leal 1518500249(%eax,%esi,1),%eax
399 movl $-1, %esi
400 roll $12, %eax
401 addl %ebp, %eax
402 /* 26 */
403 addl %edi, %ebp
404 movl %ebx, %edi
405 subl %eax, %esi
406 andl %eax, %edi
407 andl %ecx, %esi
408 orl %esi, %edi
409 movl 24(%esp), %esi
410 roll $10, %ebx
411 leal 1518500249(%ebp,%edi,1),%ebp
412 movl $-1, %edi
413 roll $15, %ebp
414 addl %edx, %ebp
415 /* 27 */
416 addl %esi, %edx
417 movl %eax, %esi
418 subl %ebp, %edi
419 andl %ebp, %esi
420 andl %ebx, %edi
421 orl %edi, %esi
422 movl 12(%esp), %edi
423 roll $10, %eax
424 leal 1518500249(%edx,%esi,1),%edx
425 movl $-1, %esi
426 roll $9, %edx
427 addl %ecx, %edx
428 /* 28 */
429 addl %edi, %ecx
430 movl %ebp, %edi
431 subl %edx, %esi
432 andl %edx, %edi
433 andl %eax, %esi
434 orl %esi, %edi
435 movl 60(%esp), %esi
436 roll $10, %ebp
437 leal 1518500249(%ecx,%edi,1),%ecx
438 movl $-1, %edi
439 roll $11, %ecx
440 addl %ebx, %ecx
441 /* 29 */
442 addl %esi, %ebx
443 movl %edx, %esi
444 subl %ecx, %edi
445 andl %ecx, %esi
446 andl %ebp, %edi
447 orl %edi, %esi
448 movl 48(%esp), %edi
449 roll $10, %edx
450 leal 1518500249(%ebx,%esi,1),%ebx
451 movl $-1, %esi
452 roll $7, %ebx
453 addl %eax, %ebx
454 /* 30 */
455 addl %edi, %eax
456 movl %ecx, %edi
457 subl %ebx, %esi
458 andl %ebx, %edi
459 andl %edx, %esi
460 orl %esi, %edi
461 movl 36(%esp), %esi
462 roll $10, %ecx
463 leal 1518500249(%eax,%edi,1),%eax
464 movl $-1, %edi
465 roll $13, %eax
466 addl %ebp, %eax
467 /* 31 */
468 addl %esi, %ebp
469 movl %ebx, %esi
470 subl %eax, %edi
471 andl %eax, %esi
472 andl %ecx, %edi
473 orl %edi, %esi
474 movl $-1, %edi
475 roll $10, %ebx
476 leal 1518500249(%ebp,%esi,1),%ebp
477 subl %eax, %edi
478 roll $12, %ebp
479 addl %edx, %ebp
480 /* 32 */
481 movl 16(%esp), %esi
482 orl %ebp, %edi
483 addl %esi, %edx
484 xorl %ebx, %edi
485 movl $-1, %esi
486 roll $10, %eax
487 leal 1859775393(%edx,%edi,1),%edx
488 subl %ebp, %esi
489 roll $11, %edx
490 addl %ecx, %edx
491 /* 33 */
492 movl 44(%esp), %edi
493 orl %edx, %esi
494 addl %edi, %ecx
495 xorl %eax, %esi
496 movl $-1, %edi
497 roll $10, %ebp
498 leal 1859775393(%ecx,%esi,1),%ecx
499 subl %edx, %edi
500 roll $13, %ecx
501 addl %ebx, %ecx
502 /* 34 */
503 movl 60(%esp), %esi
504 orl %ecx, %edi
505 addl %esi, %ebx
506 xorl %ebp, %edi
507 movl $-1, %esi
508 roll $10, %edx
509 leal 1859775393(%ebx,%edi,1),%ebx
510 subl %ecx, %esi
511 roll $6, %ebx
512 addl %eax, %ebx
513 /* 35 */
514 movl 20(%esp), %edi
515 orl %ebx, %esi
516 addl %edi, %eax
517 xorl %edx, %esi
518 movl $-1, %edi
519 roll $10, %ecx
520 leal 1859775393(%eax,%esi,1),%eax
521 subl %ebx, %edi
522 roll $7, %eax
523 addl %ebp, %eax
524 /* 36 */
525 movl 40(%esp), %esi
526 orl %eax, %edi
527 addl %esi, %ebp
528 xorl %ecx, %edi
529 movl $-1, %esi
530 roll $10, %ebx
531 leal 1859775393(%ebp,%edi,1),%ebp
532 subl %eax, %esi
533 roll $14, %ebp
534 addl %edx, %ebp
535 /* 37 */
536 movl 64(%esp), %edi
537 orl %ebp, %esi
538 addl %edi, %edx
539 xorl %ebx, %esi
540 movl $-1, %edi
541 roll $10, %eax
542 leal 1859775393(%edx,%esi,1),%edx
543 subl %ebp, %edi
544 roll $9, %edx
545 addl %ecx, %edx
546 /* 38 */
547 movl 36(%esp), %esi
548 orl %edx, %edi
549 addl %esi, %ecx
550 xorl %eax, %edi
551 movl $-1, %esi
552 roll $10, %ebp
553 leal 1859775393(%ecx,%edi,1),%ecx
554 subl %edx, %esi
555 roll $13, %ecx
556 addl %ebx, %ecx
557 /* 39 */
558 movl 8(%esp), %edi
559 orl %ecx, %esi
560 addl %edi, %ebx
561 xorl %ebp, %esi
562 movl $-1, %edi
563 roll $10, %edx
564 leal 1859775393(%ebx,%esi,1),%ebx
565 subl %ecx, %edi
566 roll $15, %ebx
567 addl %eax, %ebx
568 /* 40 */
569 movl 12(%esp), %esi
570 orl %ebx, %edi
571 addl %esi, %eax
572 xorl %edx, %edi
573 movl $-1, %esi
574 roll $10, %ecx
575 leal 1859775393(%eax,%edi,1),%eax
576 subl %ebx, %esi
577 roll $14, %eax
578 addl %ebp, %eax
579 /* 41 */
580 movl 32(%esp), %edi
581 orl %eax, %esi
582 addl %edi, %ebp
583 xorl %ecx, %esi
584 movl $-1, %edi
585 roll $10, %ebx
586 leal 1859775393(%ebp,%esi,1),%ebp
587 subl %eax, %edi
588 roll $8, %ebp
589 addl %edx, %ebp
590 /* 42 */
591 movl 4(%esp), %esi
592 orl %ebp, %edi
593 addl %esi, %edx
594 xorl %ebx, %edi
595 movl $-1, %esi
596 roll $10, %eax
597 leal 1859775393(%edx,%edi,1),%edx
598 subl %ebp, %esi
599 roll $13, %edx
600 addl %ecx, %edx
601 /* 43 */
602 movl 28(%esp), %edi
603 orl %edx, %esi
604 addl %edi, %ecx
605 xorl %eax, %esi
606 movl $-1, %edi
607 roll $10, %ebp
608 leal 1859775393(%ecx,%esi,1),%ecx
609 subl %edx, %edi
610 roll $6, %ecx
611 addl %ebx, %ecx
612 /* 44 */
613 movl 56(%esp), %esi
614 orl %ecx, %edi
615 addl %esi, %ebx
616 xorl %ebp, %edi
617 movl $-1, %esi
618 roll $10, %edx
619 leal 1859775393(%ebx,%edi,1),%ebx
620 subl %ecx, %esi
621 roll $5, %ebx
622 addl %eax, %ebx
623 /* 45 */
624 movl 48(%esp), %edi
625 orl %ebx, %esi
626 addl %edi, %eax
627 xorl %edx, %esi
628 movl $-1, %edi
629 roll $10, %ecx
630 leal 1859775393(%eax,%esi,1),%eax
631 subl %ebx, %edi
632 roll $12, %eax
633 addl %ebp, %eax
634 /* 46 */
635 movl 24(%esp), %esi
636 orl %eax, %edi
637 addl %esi, %ebp
638 xorl %ecx, %edi
639 movl $-1, %esi
640 roll $10, %ebx
641 leal 1859775393(%ebp,%edi,1),%ebp
642 subl %eax, %esi
643 roll $7, %ebp
644 addl %edx, %ebp
645 /* 47 */
646 movl 52(%esp), %edi
647 orl %ebp, %esi
648 addl %edi, %edx
649 xorl %ebx, %esi
650 movl $-1, %edi
651 roll $10, %eax
652 leal 1859775393(%edx,%esi,1),%edx
653 movl %eax, %esi
654 roll $5, %edx
655 addl %ecx, %edx
656 /* 48 */
657 subl %eax, %edi
658 andl %edx, %esi
659 andl %ebp, %edi
660 orl %esi, %edi
661 movl 8(%esp), %esi
662 roll $10, %ebp
663 leal 2400959708(%ecx,%edi,),%ecx
664 movl $-1, %edi
665 addl %esi, %ecx
666 movl %ebp, %esi
667 roll $11, %ecx
668 addl %ebx, %ecx
669 /* 49 */
670 subl %ebp, %edi
671 andl %ecx, %esi
672 andl %edx, %edi
673 orl %esi, %edi
674 movl 40(%esp), %esi
675 roll $10, %edx
676 leal 2400959708(%ebx,%edi,),%ebx
677 movl $-1, %edi
678 addl %esi, %ebx
679 movl %edx, %esi
680 roll $12, %ebx
681 addl %eax, %ebx
682 /* 50 */
683 subl %edx, %edi
684 andl %ebx, %esi
685 andl %ecx, %edi
686 orl %esi, %edi
687 movl 48(%esp), %esi
688 roll $10, %ecx
689 leal 2400959708(%eax,%edi,),%eax
690 movl $-1, %edi
691 addl %esi, %eax
692 movl %ecx, %esi
693 roll $14, %eax
694 addl %ebp, %eax
695 /* 51 */
696 subl %ecx, %edi
697 andl %eax, %esi
698 andl %ebx, %edi
699 orl %esi, %edi
700 movl 44(%esp), %esi
701 roll $10, %ebx
702 leal 2400959708(%ebp,%edi,),%ebp
703 movl $-1, %edi
704 addl %esi, %ebp
705 movl %ebx, %esi
706 roll $15, %ebp
707 addl %edx, %ebp
708 /* 52 */
709 subl %ebx, %edi
710 andl %ebp, %esi
711 andl %eax, %edi
712 orl %esi, %edi
713 movl 4(%esp), %esi
714 roll $10, %eax
715 leal 2400959708(%edx,%edi,),%edx
716 movl $-1, %edi
717 addl %esi, %edx
718 movl %eax, %esi
719 roll $14, %edx
720 addl %ecx, %edx
721 /* 53 */
722 subl %eax, %edi
723 andl %edx, %esi
724 andl %ebp, %edi
725 orl %esi, %edi
726 movl 36(%esp), %esi
727 roll $10, %ebp
728 leal 2400959708(%ecx,%edi,),%ecx
729 movl $-1, %edi
730 addl %esi, %ecx
731 movl %ebp, %esi
732 roll $15, %ecx
733 addl %ebx, %ecx
734 /* 54 */
735 subl %ebp, %edi
736 andl %ecx, %esi
737 andl %edx, %edi
738 orl %esi, %edi
739 movl 52(%esp), %esi
740 roll $10, %edx
741 leal 2400959708(%ebx,%edi,),%ebx
742 movl $-1, %edi
743 addl %esi, %ebx
744 movl %edx, %esi
745 roll $9, %ebx
746 addl %eax, %ebx
747 /* 55 */
748 subl %edx, %edi
749 andl %ebx, %esi
750 andl %ecx, %edi
751 orl %esi, %edi
752 movl 20(%esp), %esi
753 roll $10, %ecx
754 leal 2400959708(%eax,%edi,),%eax
755 movl $-1, %edi
756 addl %esi, %eax
757 movl %ecx, %esi
758 roll $8, %eax
759 addl %ebp, %eax
760 /* 56 */
761 subl %ecx, %edi
762 andl %eax, %esi
763 andl %ebx, %edi
764 orl %esi, %edi
765 movl 56(%esp), %esi
766 roll $10, %ebx
767 leal 2400959708(%ebp,%edi,),%ebp
768 movl $-1, %edi
769 addl %esi, %ebp
770 movl %ebx, %esi
771 roll $9, %ebp
772 addl %edx, %ebp
773 /* 57 */
774 subl %ebx, %edi
775 andl %ebp, %esi
776 andl %eax, %edi
777 orl %esi, %edi
778 movl 16(%esp), %esi
779 roll $10, %eax
780 leal 2400959708(%edx,%edi,),%edx
781 movl $-1, %edi
782 addl %esi, %edx
783 movl %eax, %esi
784 roll $14, %edx
785 addl %ecx, %edx
786 /* 58 */
787 subl %eax, %edi
788 andl %edx, %esi
789 andl %ebp, %edi
790 orl %esi, %edi
791 movl 32(%esp), %esi
792 roll $10, %ebp
793 leal 2400959708(%ecx,%edi,),%ecx
794 movl $-1, %edi
795 addl %esi, %ecx
796 movl %ebp, %esi
797 roll $5, %ecx
798 addl %ebx, %ecx
799 /* 59 */
800 subl %ebp, %edi
801 andl %ecx, %esi
802 andl %edx, %edi
803 orl %esi, %edi
804 movl 64(%esp), %esi
805 roll $10, %edx
806 leal 2400959708(%ebx,%edi,),%ebx
807 movl $-1, %edi
808 addl %esi, %ebx
809 movl %edx, %esi
810 roll $6, %ebx
811 addl %eax, %ebx
812 /* 60 */
813 subl %edx, %edi
814 andl %ebx, %esi
815 andl %ecx, %edi
816 orl %esi, %edi
817 movl 60(%esp), %esi
818 roll $10, %ecx
819 leal 2400959708(%eax,%edi,),%eax
820 movl $-1, %edi
821 addl %esi, %eax
822 movl %ecx, %esi
823 roll $8, %eax
824 addl %ebp, %eax
825 /* 61 */
826 subl %ecx, %edi
827 andl %eax, %esi
828 andl %ebx, %edi
829 orl %esi, %edi
830 movl 24(%esp), %esi
831 roll $10, %ebx
832 leal 2400959708(%ebp,%edi,),%ebp
833 movl $-1, %edi
834 addl %esi, %ebp
835 movl %ebx, %esi
836 roll $6, %ebp
837 addl %edx, %ebp
838 /* 62 */
839 subl %ebx, %edi
840 andl %ebp, %esi
841 andl %eax, %edi
842 orl %esi, %edi
843 movl 28(%esp), %esi
844 roll $10, %eax
845 leal 2400959708(%edx,%edi,),%edx
846 movl $-1, %edi
847 addl %esi, %edx
848 movl %eax, %esi
849 roll $5, %edx
850 addl %ecx, %edx
851 /* 63 */
852 subl %eax, %edi
853 andl %edx, %esi
854 andl %ebp, %edi
855 orl %esi, %edi
856 movl 12(%esp), %esi
857 roll $10, %ebp
858 leal 2400959708(%ecx,%edi,),%ecx
859 movl $-1, %edi
860 addl %esi, %ecx
861 subl %ebp, %edi
862 roll $12, %ecx
863 addl %ebx, %ecx
864 /* 64 */
865 movl 20(%esp), %esi
866 orl %edx, %edi
867 addl %esi, %ebx
868 xorl %ecx, %edi
869 movl $-1, %esi
870 roll $10, %edx
871 leal 2840853838(%ebx,%edi,1),%ebx
872 subl %edx, %esi
873 roll $9, %ebx
874 addl %eax, %ebx
875 /* 65 */
876 movl 4(%esp), %edi
877 orl %ecx, %esi
878 addl %edi, %eax
879 xorl %ebx, %esi
880 movl $-1, %edi
881 roll $10, %ecx
882 leal 2840853838(%eax,%esi,1),%eax
883 subl %ecx, %edi
884 roll $15, %eax
885 addl %ebp, %eax
886 /* 66 */
887 movl 24(%esp), %esi
888 orl %ebx, %edi
889 addl %esi, %ebp
890 xorl %eax, %edi
891 movl $-1, %esi
892 roll $10, %ebx
893 leal 2840853838(%ebp,%edi,1),%ebp
894 subl %ebx, %esi
895 roll $5, %ebp
896 addl %edx, %ebp
897 /* 67 */
898 movl 40(%esp), %edi
899 orl %eax, %esi
900 addl %edi, %edx
901 xorl %ebp, %esi
902 movl $-1, %edi
903 roll $10, %eax
904 leal 2840853838(%edx,%esi,1),%edx
905 subl %eax, %edi
906 roll $11, %edx
907 addl %ecx, %edx
908 /* 68 */
909 movl 32(%esp), %esi
910 orl %ebp, %edi
911 addl %esi, %ecx
912 xorl %edx, %edi
913 movl $-1, %esi
914 roll $10, %ebp
915 leal 2840853838(%ecx,%edi,1),%ecx
916 subl %ebp, %esi
917 roll $6, %ecx
918 addl %ebx, %ecx
919 /* 69 */
920 movl 52(%esp), %edi
921 orl %edx, %esi
922 addl %edi, %ebx
923 xorl %ecx, %esi
924 movl $-1, %edi
925 roll $10, %edx
926 leal 2840853838(%ebx,%esi,1),%ebx
927 subl %edx, %edi
928 roll $8, %ebx
929 addl %eax, %ebx
930 /* 70 */
931 movl 12(%esp), %esi
932 orl %ecx, %edi
933 addl %esi, %eax
934 xorl %ebx, %edi
935 movl $-1, %esi
936 roll $10, %ecx
937 leal 2840853838(%eax,%edi,1),%eax
938 subl %ecx, %esi
939 roll $13, %eax
940 addl %ebp, %eax
941 /* 71 */
942 movl 44(%esp), %edi
943 orl %ebx, %esi
944 addl %edi, %ebp
945 xorl %eax, %esi
946 movl $-1, %edi
947 roll $10, %ebx
948 leal 2840853838(%ebp,%esi,1),%ebp
949 subl %ebx, %edi
950 roll $12, %ebp
951 addl %edx, %ebp
952 /* 72 */
953 movl 60(%esp), %esi
954 orl %eax, %edi
955 addl %esi, %edx
956 xorl %ebp, %edi
957 movl $-1, %esi
958 roll $10, %eax
959 leal 2840853838(%edx,%edi,1),%edx
960 subl %eax, %esi
961 roll $5, %edx
962 addl %ecx, %edx
963 /* 73 */
964 movl 8(%esp), %edi
965 orl %ebp, %esi
966 addl %edi, %ecx
967 xorl %edx, %esi
968 movl $-1, %edi
969 roll $10, %ebp
970 leal 2840853838(%ecx,%esi,1),%ecx
971 subl %ebp, %edi
972 roll $12, %ecx
973 addl %ebx, %ecx
974 /* 74 */
975 movl 16(%esp), %esi
976 orl %edx, %edi
977 addl %esi, %ebx
978 xorl %ecx, %edi
979 movl $-1, %esi
980 roll $10, %edx
981 leal 2840853838(%ebx,%edi,1),%ebx
982 subl %edx, %esi
983 roll $13, %ebx
984 addl %eax, %ebx
985 /* 75 */
986 movl 36(%esp), %edi
987 orl %ecx, %esi
988 addl %edi, %eax
989 xorl %ebx, %esi
990 movl $-1, %edi
991 roll $10, %ecx
992 leal 2840853838(%eax,%esi,1),%eax
993 subl %ecx, %edi
994 roll $14, %eax
995 addl %ebp, %eax
996 /* 76 */
997 movl 48(%esp), %esi
998 orl %ebx, %edi
999 addl %esi, %ebp
1000 xorl %eax, %edi
1001 movl $-1, %esi
1002 roll $10, %ebx
1003 leal 2840853838(%ebp,%edi,1),%ebp
1004 subl %ebx, %esi
1005 roll $11, %ebp
1006 addl %edx, %ebp
1007 /* 77 */
1008 movl 28(%esp), %edi
1009 orl %eax, %esi
1010 addl %edi, %edx
1011 xorl %ebp, %esi
1012 movl $-1, %edi
1013 roll $10, %eax
1014 leal 2840853838(%edx,%esi,1),%edx
1015 subl %eax, %edi
1016 roll $8, %edx
1017 addl %ecx, %edx
1018 /* 78 */
1019 movl 64(%esp), %esi
1020 orl %ebp, %edi
1021 addl %esi, %ecx
1022 xorl %edx, %edi
1023 movl $-1, %esi
1024 roll $10, %ebp
1025 leal 2840853838(%ecx,%edi,1),%ecx
1026 subl %ebp, %esi
1027 roll $5, %ecx
1028 addl %ebx, %ecx
1029 /* 79 */
1030 movl 56(%esp), %edi
1031 orl %edx, %esi
1032 addl %edi, %ebx
1033 xorl %ecx, %esi
1034 movl 108(%esp), %edi
1035 roll $10, %edx
1036 leal 2840853838(%ebx,%esi,1),%ebx
1037 movl %eax, 68(%esp)
1038 roll $6, %ebx
1039 addl %eax, %ebx
1040 movl (%edi), %eax
1041 movl %ebx, 72(%esp)
1042 movl %ecx, 76(%esp)
1043 movl 4(%edi), %ebx
1044 movl %edx, 80(%esp)
1045 movl 8(%edi), %ecx
1046 movl %ebp, 84(%esp)
1047 movl 12(%edi), %edx
1048 movl 16(%edi), %ebp
1049 /* 80 */
1050 movl $-1, %edi
1051 subl %edx, %edi
1052 movl 24(%esp), %esi
1053 orl %ecx, %edi
1054 addl %esi, %eax
1055 xorl %ebx, %edi
1056 movl $-1, %esi
1057 roll $10, %ecx
1058 leal 1352829926(%eax,%edi,1),%eax
1059 subl %ecx, %esi
1060 roll $8, %eax
1061 addl %ebp, %eax
1062 /* 81 */
1063 movl 60(%esp), %edi
1064 orl %ebx, %esi
1065 addl %edi, %ebp
1066 xorl %eax, %esi
1067 movl $-1, %edi
1068 roll $10, %ebx
1069 leal 1352829926(%ebp,%esi,1),%ebp
1070 subl %ebx, %edi
1071 roll $9, %ebp
1072 addl %edx, %ebp
1073 /* 82 */
1074 movl 32(%esp), %esi
1075 orl %eax, %edi
1076 addl %esi, %edx
1077 xorl %ebp, %edi
1078 movl $-1, %esi
1079 roll $10, %eax
1080 leal 1352829926(%edx,%edi,1),%edx
1081 subl %eax, %esi
1082 roll $9, %edx
1083 addl %ecx, %edx
1084 /* 83 */
1085 movl 4(%esp), %edi
1086 orl %ebp, %esi
1087 addl %edi, %ecx
1088 xorl %edx, %esi
1089 movl $-1, %edi
1090 roll $10, %ebp
1091 leal 1352829926(%ecx,%esi,1),%ecx
1092 subl %ebp, %edi
1093 roll $11, %ecx
1094 addl %ebx, %ecx
1095 /* 84 */
1096 movl 40(%esp), %esi
1097 orl %edx, %edi
1098 addl %esi, %ebx
1099 xorl %ecx, %edi
1100 movl $-1, %esi
1101 roll $10, %edx
1102 leal 1352829926(%ebx,%edi,1),%ebx
1103 subl %edx, %esi
1104 roll $13, %ebx
1105 addl %eax, %ebx
1106 /* 85 */
1107 movl 12(%esp), %edi
1108 orl %ecx, %esi
1109 addl %edi, %eax
1110 xorl %ebx, %esi
1111 movl $-1, %edi
1112 roll $10, %ecx
1113 leal 1352829926(%eax,%esi,1),%eax
1114 subl %ecx, %edi
1115 roll $15, %eax
1116 addl %ebp, %eax
1117 /* 86 */
1118 movl 48(%esp), %esi
1119 orl %ebx, %edi
1120 addl %esi, %ebp
1121 xorl %eax, %edi
1122 movl $-1, %esi
1123 roll $10, %ebx
1124 leal 1352829926(%ebp,%edi,1),%ebp
1125 subl %ebx, %esi
1126 roll $15, %ebp
1127 addl %edx, %ebp
1128 /* 87 */
1129 movl 20(%esp), %edi
1130 orl %eax, %esi
1131 addl %edi, %edx
1132 xorl %ebp, %esi
1133 movl $-1, %edi
1134 roll $10, %eax
1135 leal 1352829926(%edx,%esi,1),%edx
1136 subl %eax, %edi
1137 roll $5, %edx
1138 addl %ecx, %edx
1139 /* 88 */
1140 movl 56(%esp), %esi
1141 orl %ebp, %edi
1142 addl %esi, %ecx
1143 xorl %edx, %edi
1144 movl $-1, %esi
1145 roll $10, %ebp
1146 leal 1352829926(%ecx,%edi,1),%ecx
1147 subl %ebp, %esi
1148 roll $7, %ecx
1149 addl %ebx, %ecx
1150 /* 89 */
1151 movl 28(%esp), %edi
1152 orl %edx, %esi
1153 addl %edi, %ebx
1154 xorl %ecx, %esi
1155 movl $-1, %edi
1156 roll $10, %edx
1157 leal 1352829926(%ebx,%esi,1),%ebx
1158 subl %edx, %edi
1159 roll $7, %ebx
1160 addl %eax, %ebx
1161 /* 90 */
1162 movl 64(%esp), %esi
1163 orl %ecx, %edi
1164 addl %esi, %eax
1165 xorl %ebx, %edi
1166 movl $-1, %esi
1167 roll $10, %ecx
1168 leal 1352829926(%eax,%edi,1),%eax
1169 subl %ecx, %esi
1170 roll $8, %eax
1171 addl %ebp, %eax
1172 /* 91 */
1173 movl 36(%esp), %edi
1174 orl %ebx, %esi
1175 addl %edi, %ebp
1176 xorl %eax, %esi
1177 movl $-1, %edi
1178 roll $10, %ebx
1179 leal 1352829926(%ebp,%esi,1),%ebp
1180 subl %ebx, %edi
1181 roll $11, %ebp
1182 addl %edx, %ebp
1183 /* 92 */
1184 movl 8(%esp), %esi
1185 orl %eax, %edi
1186 addl %esi, %edx
1187 xorl %ebp, %edi
1188 movl $-1, %esi
1189 roll $10, %eax
1190 leal 1352829926(%edx,%edi,1),%edx
1191 subl %eax, %esi
1192 roll $14, %edx
1193 addl %ecx, %edx
1194 /* 93 */
1195 movl 44(%esp), %edi
1196 orl %ebp, %esi
1197 addl %edi, %ecx
1198 xorl %edx, %esi
1199 movl $-1, %edi
1200 roll $10, %ebp
1201 leal 1352829926(%ecx,%esi,1),%ecx
1202 subl %ebp, %edi
1203 roll $14, %ecx
1204 addl %ebx, %ecx
1205 /* 94 */
1206 movl 16(%esp), %esi
1207 orl %edx, %edi
1208 addl %esi, %ebx
1209 xorl %ecx, %edi
1210 movl $-1, %esi
1211 roll $10, %edx
1212 leal 1352829926(%ebx,%edi,1),%ebx
1213 subl %edx, %esi
1214 roll $12, %ebx
1215 addl %eax, %ebx
1216 /* 95 */
1217 movl 52(%esp), %edi
1218 orl %ecx, %esi
1219 addl %edi, %eax
1220 xorl %ebx, %esi
1221 movl $-1, %edi
1222 roll $10, %ecx
1223 leal 1352829926(%eax,%esi,1),%eax
1224 movl %ecx, %esi
1225 roll $6, %eax
1226 addl %ebp, %eax
1227 /* 96 */
1228 subl %ecx, %edi
1229 andl %eax, %esi
1230 andl %ebx, %edi
1231 orl %esi, %edi
1232 movl 28(%esp), %esi
1233 roll $10, %ebx
1234 leal 1548603684(%ebp,%edi,),%ebp
1235 movl $-1, %edi
1236 addl %esi, %ebp
1237 movl %ebx, %esi
1238 roll $9, %ebp
1239 addl %edx, %ebp
1240 /* 97 */
1241 subl %ebx, %edi
1242 andl %ebp, %esi
1243 andl %eax, %edi
1244 orl %esi, %edi
1245 movl 48(%esp), %esi
1246 roll $10, %eax
1247 leal 1548603684(%edx,%edi,),%edx
1248 movl $-1, %edi
1249 addl %esi, %edx
1250 movl %eax, %esi
1251 roll $13, %edx
1252 addl %ecx, %edx
1253 /* 98 */
1254 subl %eax, %edi
1255 andl %edx, %esi
1256 andl %ebp, %edi
1257 orl %esi, %edi
1258 movl 16(%esp), %esi
1259 roll $10, %ebp
1260 leal 1548603684(%ecx,%edi,),%ecx
1261 movl $-1, %edi
1262 addl %esi, %ecx
1263 movl %ebp, %esi
1264 roll $15, %ecx
1265 addl %ebx, %ecx
1266 /* 99 */
1267 subl %ebp, %edi
1268 andl %ecx, %esi
1269 andl %edx, %edi
1270 orl %esi, %edi
1271 movl 32(%esp), %esi
1272 roll $10, %edx
1273 leal 1548603684(%ebx,%edi,),%ebx
1274 movl $-1, %edi
1275 addl %esi, %ebx
1276 movl %edx, %esi
1277 roll $7, %ebx
1278 addl %eax, %ebx
1279 /* 100 */
1280 subl %edx, %edi
1281 andl %ebx, %esi
1282 andl %ecx, %edi
1283 orl %esi, %edi
1284 movl 4(%esp), %esi
1285 roll $10, %ecx
1286 leal 1548603684(%eax,%edi,),%eax
1287 movl $-1, %edi
1288 addl %esi, %eax
1289 movl %ecx, %esi
1290 roll $12, %eax
1291 addl %ebp, %eax
1292 /* 101 */
1293 subl %ecx, %edi
1294 andl %eax, %esi
1295 andl %ebx, %edi
1296 orl %esi, %edi
1297 movl 56(%esp), %esi
1298 roll $10, %ebx
1299 leal 1548603684(%ebp,%edi,),%ebp
1300 movl $-1, %edi
1301 addl %esi, %ebp
1302 movl %ebx, %esi
1303 roll $8, %ebp
1304 addl %edx, %ebp
1305 /* 102 */
1306 subl %ebx, %edi
1307 andl %ebp, %esi
1308 andl %eax, %edi
1309 orl %esi, %edi
1310 movl 24(%esp), %esi
1311 roll $10, %eax
1312 leal 1548603684(%edx,%edi,),%edx
1313 movl $-1, %edi
1314 addl %esi, %edx
1315 movl %eax, %esi
1316 roll $9, %edx
1317 addl %ecx, %edx
1318 /* 103 */
1319 subl %eax, %edi
1320 andl %edx, %esi
1321 andl %ebp, %edi
1322 orl %esi, %edi
1323 movl 44(%esp), %esi
1324 roll $10, %ebp
1325 leal 1548603684(%ecx,%edi,),%ecx
1326 movl $-1, %edi
1327 addl %esi, %ecx
1328 movl %ebp, %esi
1329 roll $11, %ecx
1330 addl %ebx, %ecx
1331 /* 104 */
1332 subl %ebp, %edi
1333 andl %ecx, %esi
1334 andl %edx, %edi
1335 orl %esi, %edi
1336 movl 60(%esp), %esi
1337 roll $10, %edx
1338 leal 1548603684(%ebx,%edi,),%ebx
1339 movl $-1, %edi
1340 addl %esi, %ebx
1341 movl %edx, %esi
1342 roll $7, %ebx
1343 addl %eax, %ebx
1344 /* 105 */
1345 subl %edx, %edi
1346 andl %ebx, %esi
1347 andl %ecx, %edi
1348 orl %esi, %edi
1349 movl 64(%esp), %esi
1350 roll $10, %ecx
1351 leal 1548603684(%eax,%edi,),%eax
1352 movl $-1, %edi
1353 addl %esi, %eax
1354 movl %ecx, %esi
1355 roll $7, %eax
1356 addl %ebp, %eax
1357 /* 106 */
1358 subl %ecx, %edi
1359 andl %eax, %esi
1360 andl %ebx, %edi
1361 orl %esi, %edi
1362 movl 36(%esp), %esi
1363 roll $10, %ebx
1364 leal 1548603684(%ebp,%edi,),%ebp
1365 movl $-1, %edi
1366 addl %esi, %ebp
1367 movl %ebx, %esi
1368 roll $12, %ebp
1369 addl %edx, %ebp
1370 /* 107 */
1371 subl %ebx, %edi
1372 andl %ebp, %esi
1373 andl %eax, %edi
1374 orl %esi, %edi
1375 movl 52(%esp), %esi
1376 roll $10, %eax
1377 leal 1548603684(%edx,%edi,),%edx
1378 movl $-1, %edi
1379 addl %esi, %edx
1380 movl %eax, %esi
1381 roll $7, %edx
1382 addl %ecx, %edx
1383 /* 108 */
1384 subl %eax, %edi
1385 andl %edx, %esi
1386 andl %ebp, %edi
1387 orl %esi, %edi
1388 movl 20(%esp), %esi
1389 roll $10, %ebp
1390 leal 1548603684(%ecx,%edi,),%ecx
1391 movl $-1, %edi
1392 addl %esi, %ecx
1393 movl %ebp, %esi
1394 roll $6, %ecx
1395 addl %ebx, %ecx
1396 /* 109 */
1397 subl %ebp, %edi
1398 andl %ecx, %esi
1399 andl %edx, %edi
1400 orl %esi, %edi
1401 movl 40(%esp), %esi
1402 roll $10, %edx
1403 leal 1548603684(%ebx,%edi,),%ebx
1404 movl $-1, %edi
1405 addl %esi, %ebx
1406 movl %edx, %esi
1407 roll $15, %ebx
1408 addl %eax, %ebx
1409 /* 110 */
1410 subl %edx, %edi
1411 andl %ebx, %esi
1412 andl %ecx, %edi
1413 orl %esi, %edi
1414 movl 8(%esp), %esi
1415 roll $10, %ecx
1416 leal 1548603684(%eax,%edi,),%eax
1417 movl $-1, %edi
1418 addl %esi, %eax
1419 movl %ecx, %esi
1420 roll $13, %eax
1421 addl %ebp, %eax
1422 /* 111 */
1423 subl %ecx, %edi
1424 andl %eax, %esi
1425 andl %ebx, %edi
1426 orl %esi, %edi
1427 movl 12(%esp), %esi
1428 roll $10, %ebx
1429 leal 1548603684(%ebp,%edi,),%ebp
1430 movl $-1, %edi
1431 addl %esi, %ebp
1432 subl %eax, %edi
1433 roll $11, %ebp
1434 addl %edx, %ebp
1435 /* 112 */
1436 movl 64(%esp), %esi
1437 orl %ebp, %edi
1438 addl %esi, %edx
1439 xorl %ebx, %edi
1440 movl $-1, %esi
1441 roll $10, %eax
1442 leal 1836072691(%edx,%edi,1),%edx
1443 subl %ebp, %esi
1444 roll $9, %edx
1445 addl %ecx, %edx
1446 /* 113 */
1447 movl 24(%esp), %edi
1448 orl %edx, %esi
1449 addl %edi, %ecx
1450 xorl %eax, %esi
1451 movl $-1, %edi
1452 roll $10, %ebp
1453 leal 1836072691(%ecx,%esi,1),%ecx
1454 subl %edx, %edi
1455 roll $7, %ecx
1456 addl %ebx, %ecx
1457 /* 114 */
1458 movl 8(%esp), %esi
1459 orl %ecx, %edi
1460 addl %esi, %ebx
1461 xorl %ebp, %edi
1462 movl $-1, %esi
1463 roll $10, %edx
1464 leal 1836072691(%ebx,%edi,1),%ebx
1465 subl %ecx, %esi
1466 roll $15, %ebx
1467 addl %eax, %ebx
1468 /* 115 */
1469 movl 16(%esp), %edi
1470 orl %ebx, %esi
1471 addl %edi, %eax
1472 xorl %edx, %esi
1473 movl $-1, %edi
1474 roll $10, %ecx
1475 leal 1836072691(%eax,%esi,1),%eax
1476 subl %ebx, %edi
1477 roll $11, %eax
1478 addl %ebp, %eax
1479 /* 116 */
1480 movl 32(%esp), %esi
1481 orl %eax, %edi
1482 addl %esi, %ebp
1483 xorl %ecx, %edi
1484 movl $-1, %esi
1485 roll $10, %ebx
1486 leal 1836072691(%ebp,%edi,1),%ebp
1487 subl %eax, %esi
1488 roll $8, %ebp
1489 addl %edx, %ebp
1490 /* 117 */
1491 movl 60(%esp), %edi
1492 orl %ebp, %esi
1493 addl %edi, %edx
1494 xorl %ebx, %esi
1495 movl $-1, %edi
1496 roll $10, %eax
1497 leal 1836072691(%edx,%esi,1),%edx
1498 subl %ebp, %edi
1499 roll $6, %edx
1500 addl %ecx, %edx
1501 /* 118 */
1502 movl 28(%esp), %esi
1503 orl %edx, %edi
1504 addl %esi, %ecx
1505 xorl %eax, %edi
1506 movl $-1, %esi
1507 roll $10, %ebp
1508 leal 1836072691(%ecx,%edi,1),%ecx
1509 subl %edx, %esi
1510 roll $6, %ecx
1511 addl %ebx, %ecx
1512 /* 119 */
1513 movl 40(%esp), %edi
1514 orl %ecx, %esi
1515 addl %edi, %ebx
1516 xorl %ebp, %esi
1517 movl $-1, %edi
1518 roll $10, %edx
1519 leal 1836072691(%ebx,%esi,1),%ebx
1520 subl %ecx, %edi
1521 roll $14, %ebx
1522 addl %eax, %ebx
1523 /* 120 */
1524 movl 48(%esp), %esi
1525 orl %ebx, %edi
1526 addl %esi, %eax
1527 xorl %edx, %edi
1528 movl $-1, %esi
1529 roll $10, %ecx
1530 leal 1836072691(%eax,%edi,1),%eax
1531 subl %ebx, %esi
1532 roll $12, %eax
1533 addl %ebp, %eax
1534 /* 121 */
1535 movl 36(%esp), %edi
1536 orl %eax, %esi
1537 addl %edi, %ebp
1538 xorl %ecx, %esi
1539 movl $-1, %edi
1540 roll $10, %ebx
1541 leal 1836072691(%ebp,%esi,1),%ebp
1542 subl %eax, %edi
1543 roll $13, %ebp
1544 addl %edx, %ebp
1545 /* 122 */
1546 movl 52(%esp), %esi
1547 orl %ebp, %edi
1548 addl %esi, %edx
1549 xorl %ebx, %edi
1550 movl $-1, %esi
1551 roll $10, %eax
1552 leal 1836072691(%edx,%edi,1),%edx
1553 subl %ebp, %esi
1554 roll $5, %edx
1555 addl %ecx, %edx
1556 /* 123 */
1557 movl 12(%esp), %edi
1558 orl %edx, %esi
1559 addl %edi, %ecx
1560 xorl %eax, %esi
1561 movl $-1, %edi
1562 roll $10, %ebp
1563 leal 1836072691(%ecx,%esi,1),%ecx
1564 subl %edx, %edi
1565 roll $14, %ecx
1566 addl %ebx, %ecx
1567 /* 124 */
1568 movl 44(%esp), %esi
1569 orl %ecx, %edi
1570 addl %esi, %ebx
1571 xorl %ebp, %edi
1572 movl $-1, %esi
1573 roll $10, %edx
1574 leal 1836072691(%ebx,%edi,1),%ebx
1575 subl %ecx, %esi
1576 roll $13, %ebx
1577 addl %eax, %ebx
1578 /* 125 */
1579 movl 4(%esp), %edi
1580 orl %ebx, %esi
1581 addl %edi, %eax
1582 xorl %edx, %esi
1583 movl $-1, %edi
1584 roll $10, %ecx
1585 leal 1836072691(%eax,%esi,1),%eax
1586 subl %ebx, %edi
1587 roll $13, %eax
1588 addl %ebp, %eax
1589 /* 126 */
1590 movl 20(%esp), %esi
1591 orl %eax, %edi
1592 addl %esi, %ebp
1593 xorl %ecx, %edi
1594 movl $-1, %esi
1595 roll $10, %ebx
1596 leal 1836072691(%ebp,%edi,1),%ebp
1597 subl %eax, %esi
1598 roll $7, %ebp
1599 addl %edx, %ebp
1600 /* 127 */
1601 movl 56(%esp), %edi
1602 orl %ebp, %esi
1603 addl %edi, %edx
1604 xorl %ebx, %esi
1605 movl 36(%esp), %edi
1606 roll $10, %eax
1607 leal 1836072691(%edx,%esi,1),%edx
1608 movl $-1, %esi
1609 roll $5, %edx
1610 addl %ecx, %edx
1611 /* 128 */
1612 addl %edi, %ecx
1613 movl %ebp, %edi
1614 subl %edx, %esi
1615 andl %edx, %edi
1616 andl %eax, %esi
1617 orl %esi, %edi
1618 movl 28(%esp), %esi
1619 roll $10, %ebp
1620 leal 2053994217(%ecx,%edi,1),%ecx
1621 movl $-1, %edi
1622 roll $15, %ecx
1623 addl %ebx, %ecx
1624 /* 129 */
1625 addl %esi, %ebx
1626 movl %edx, %esi
1627 subl %ecx, %edi
1628 andl %ecx, %esi
1629 andl %ebp, %edi
1630 orl %edi, %esi
1631 movl 20(%esp), %edi
1632 roll $10, %edx
1633 leal 2053994217(%ebx,%esi,1),%ebx
1634 movl $-1, %esi
1635 roll $5, %ebx
1636 addl %eax, %ebx
1637 /* 130 */
1638 addl %edi, %eax
1639 movl %ecx, %edi
1640 subl %ebx, %esi
1641 andl %ebx, %edi
1642 andl %edx, %esi
1643 orl %esi, %edi
1644 movl 8(%esp), %esi
1645 roll $10, %ecx
1646 leal 2053994217(%eax,%edi,1),%eax
1647 movl $-1, %edi
1648 roll $8, %eax
1649 addl %ebp, %eax
1650 /* 131 */
1651 addl %esi, %ebp
1652 movl %ebx, %esi
1653 subl %eax, %edi
1654 andl %eax, %esi
1655 andl %ecx, %edi
1656 orl %edi, %esi
1657 movl 16(%esp), %edi
1658 roll $10, %ebx
1659 leal 2053994217(%ebp,%esi,1),%ebp
1660 movl $-1, %esi
1661 roll $11, %ebp
1662 addl %edx, %ebp
1663 /* 132 */
1664 addl %edi, %edx
1665 movl %eax, %edi
1666 subl %ebp, %esi
1667 andl %ebp, %edi
1668 andl %ebx, %esi
1669 orl %esi, %edi
1670 movl 48(%esp), %esi
1671 roll $10, %eax
1672 leal 2053994217(%edx,%edi,1),%edx
1673 movl $-1, %edi
1674 roll $14, %edx
1675 addl %ecx, %edx
1676 /* 133 */
1677 addl %esi, %ecx
1678 movl %ebp, %esi
1679 subl %edx, %edi
1680 andl %edx, %esi
1681 andl %eax, %edi
1682 orl %edi, %esi
1683 movl 64(%esp), %edi
1684 roll $10, %ebp
1685 leal 2053994217(%ecx,%esi,1),%ecx
1686 movl $-1, %esi
1687 roll $14, %ecx
1688 addl %ebx, %ecx
1689 /* 134 */
1690 addl %edi, %ebx
1691 movl %edx, %edi
1692 subl %ecx, %esi
1693 andl %ecx, %edi
1694 andl %ebp, %esi
1695 orl %esi, %edi
1696 movl 4(%esp), %esi
1697 roll $10, %edx
1698 leal 2053994217(%ebx,%edi,1),%ebx
1699 movl $-1, %edi
1700 roll $6, %ebx
1701 addl %eax, %ebx
1702 /* 135 */
1703 addl %esi, %eax
1704 movl %ecx, %esi
1705 subl %ebx, %edi
1706 andl %ebx, %esi
1707 andl %edx, %edi
1708 orl %edi, %esi
1709 movl 24(%esp), %edi
1710 roll $10, %ecx
1711 leal 2053994217(%eax,%esi,1),%eax
1712 movl $-1, %esi
1713 roll $14, %eax
1714 addl %ebp, %eax
1715 /* 136 */
1716 addl %edi, %ebp
1717 movl %ebx, %edi
1718 subl %eax, %esi
1719 andl %eax, %edi
1720 andl %ecx, %esi
1721 orl %esi, %edi
1722 movl 52(%esp), %esi
1723 roll $10, %ebx
1724 leal 2053994217(%ebp,%edi,1),%ebp
1725 movl $-1, %edi
1726 roll $6, %ebp
1727 addl %edx, %ebp
1728 /* 137 */
1729 addl %esi, %edx
1730 movl %eax, %esi
1731 subl %ebp, %edi
1732 andl %ebp, %esi
1733 andl %ebx, %edi
1734 orl %edi, %esi
1735 movl 12(%esp), %edi
1736 roll $10, %eax
1737 leal 2053994217(%edx,%esi,1),%edx
1738 movl $-1, %esi
1739 roll $9, %edx
1740 addl %ecx, %edx
1741 /* 138 */
1742 addl %edi, %ecx
1743 movl %ebp, %edi
1744 subl %edx, %esi
1745 andl %edx, %edi
1746 andl %eax, %esi
1747 orl %esi, %edi
1748 movl 56(%esp), %esi
1749 roll $10, %ebp
1750 leal 2053994217(%ecx,%edi,1),%ecx
1751 movl $-1, %edi
1752 roll $12, %ecx
1753 addl %ebx, %ecx
1754 /* 139 */
1755 addl %esi, %ebx
1756 movl %edx, %esi
1757 subl %ecx, %edi
1758 andl %ecx, %esi
1759 andl %ebp, %edi
1760 orl %edi, %esi
1761 movl 40(%esp), %edi
1762 roll $10, %edx
1763 leal 2053994217(%ebx,%esi,1),%ebx
1764 movl $-1, %esi
1765 roll $9, %ebx
1766 addl %eax, %ebx
1767 /* 140 */
1768 addl %edi, %eax
1769 movl %ecx, %edi
1770 subl %ebx, %esi
1771 andl %ebx, %edi
1772 andl %edx, %esi
1773 orl %esi, %edi
1774 movl 32(%esp), %esi
1775 roll $10, %ecx
1776 leal 2053994217(%eax,%edi,1),%eax
1777 movl $-1, %edi
1778 roll $12, %eax
1779 addl %ebp, %eax
1780 /* 141 */
1781 addl %esi, %ebp
1782 movl %ebx, %esi
1783 subl %eax, %edi
1784 andl %eax, %esi
1785 andl %ecx, %edi
1786 orl %edi, %esi
1787 movl 44(%esp), %edi
1788 roll $10, %ebx
1789 leal 2053994217(%ebp,%esi,1),%ebp
1790 movl $-1, %esi
1791 roll $5, %ebp
1792 addl %edx, %ebp
1793 /* 142 */
1794 addl %edi, %edx
1795 movl %eax, %edi
1796 subl %ebp, %esi
1797 andl %ebp, %edi
1798 andl %ebx, %esi
1799 orl %esi, %edi
1800 movl 60(%esp), %esi
1801 roll $10, %eax
1802 leal 2053994217(%edx,%edi,1),%edx
1803 movl $-1, %edi
1804 roll $15, %edx
1805 addl %ecx, %edx
1806 /* 143 */
1807 addl %esi, %ecx
1808 movl %ebp, %esi
1809 subl %edx, %edi
1810 andl %edx, %esi
1811 andl %eax, %edi
1812 orl %esi, %edi
1813 movl %edx, %esi
1814 roll $10, %ebp
1815 leal 2053994217(%ecx,%edi,1),%ecx
1816 xorl %ebp, %esi
1817 roll $8, %ecx
1818 addl %ebx, %ecx
1819 /* 144 */
1820 movl 52(%esp), %edi
1821 xorl %ecx, %esi
1822 addl %edi, %ebx
1823 roll $10, %edx
1824 addl %esi, %ebx
1825 movl %ecx, %esi
1826 roll $8, %ebx
1827 addl %eax, %ebx
1828 /* 145 */
1829 xorl %edx, %esi
1830 movl 64(%esp), %edi
1831 xorl %ebx, %esi
1832 addl %esi, %eax
1833 movl %ebx, %esi
1834 roll $10, %ecx
1835 addl %edi, %eax
1836 xorl %ecx, %esi
1837 roll $5, %eax
1838 addl %ebp, %eax
1839 /* 146 */
1840 movl 44(%esp), %edi
1841 xorl %eax, %esi
1842 addl %edi, %ebp
1843 roll $10, %ebx
1844 addl %esi, %ebp
1845 movl %eax, %esi
1846 roll $12, %ebp
1847 addl %edx, %ebp
1848 /* 147 */
1849 xorl %ebx, %esi
1850 movl 20(%esp), %edi
1851 xorl %ebp, %esi
1852 addl %esi, %edx
1853 movl %ebp, %esi
1854 roll $10, %eax
1855 addl %edi, %edx
1856 xorl %eax, %esi
1857 roll $9, %edx
1858 addl %ecx, %edx
1859 /* 148 */
1860 movl 8(%esp), %edi
1861 xorl %edx, %esi
1862 addl %edi, %ecx
1863 roll $10, %ebp
1864 addl %esi, %ecx
1865 movl %edx, %esi
1866 roll $12, %ecx
1867 addl %ebx, %ecx
1868 /* 149 */
1869 xorl %ebp, %esi
1870 movl 24(%esp), %edi
1871 xorl %ecx, %esi
1872 addl %esi, %ebx
1873 movl %ecx, %esi
1874 roll $10, %edx
1875 addl %edi, %ebx
1876 xorl %edx, %esi
1877 roll $5, %ebx
1878 addl %eax, %ebx
1879 /* 150 */
1880 movl 36(%esp), %edi
1881 xorl %ebx, %esi
1882 addl %edi, %eax
1883 roll $10, %ecx
1884 addl %esi, %eax
1885 movl %ebx, %esi
1886 roll $14, %eax
1887 addl %ebp, %eax
1888 /* 151 */
1889 xorl %ecx, %esi
1890 movl 32(%esp), %edi
1891 xorl %eax, %esi
1892 addl %esi, %ebp
1893 movl %eax, %esi
1894 roll $10, %ebx
1895 addl %edi, %ebp
1896 xorl %ebx, %esi
1897 roll $6, %ebp
1898 addl %edx, %ebp
1899 /* 152 */
1900 movl 28(%esp), %edi
1901 xorl %ebp, %esi
1902 addl %edi, %edx
1903 roll $10, %eax
1904 addl %esi, %edx
1905 movl %ebp, %esi
1906 roll $8, %edx
1907 addl %ecx, %edx
1908 /* 153 */
1909 xorl %eax, %esi
1910 movl 12(%esp), %edi
1911 xorl %edx, %esi
1912 addl %esi, %ecx
1913 movl %edx, %esi
1914 roll $10, %ebp
1915 addl %edi, %ecx
1916 xorl %ebp, %esi
1917 roll $13, %ecx
1918 addl %ebx, %ecx
1919 /* 154 */
1920 movl 56(%esp), %edi
1921 xorl %ecx, %esi
1922 addl %edi, %ebx
1923 roll $10, %edx
1924 addl %esi, %ebx
1925 movl %ecx, %esi
1926 roll $6, %ebx
1927 addl %eax, %ebx
1928 /* 155 */
1929 xorl %edx, %esi
1930 movl 60(%esp), %edi
1931 xorl %ebx, %esi
1932 addl %esi, %eax
1933 movl %ebx, %esi
1934 roll $10, %ecx
1935 addl %edi, %eax
1936 xorl %ecx, %esi
1937 roll $5, %eax
1938 addl %ebp, %eax
1939 /* 156 */
1940 movl 4(%esp), %edi
1941 xorl %eax, %esi
1942 addl %edi, %ebp
1943 roll $10, %ebx
1944 addl %esi, %ebp
1945 movl %eax, %esi
1946 roll $15, %ebp
1947 addl %edx, %ebp
1948 /* 157 */
1949 xorl %ebx, %esi
1950 movl 16(%esp), %edi
1951 xorl %ebp, %esi
1952 addl %esi, %edx
1953 movl %ebp, %esi
1954 roll $10, %eax
1955 addl %edi, %edx
1956 xorl %eax, %esi
1957 roll $13, %edx
1958 addl %ecx, %edx
1959 /* 158 */
1960 movl 40(%esp), %edi
1961 xorl %edx, %esi
1962 addl %edi, %ecx
1963 roll $10, %ebp
1964 addl %esi, %ecx
1965 movl %edx, %esi
1966 roll $11, %ecx
1967 addl %ebx, %ecx
1968 /* 159 */
1969 xorl %ebp, %esi
1970 movl 48(%esp), %edi
1971 xorl %ecx, %esi
1972 addl %esi, %ebx
1973 roll $10, %edx
1974 addl %edi, %ebx
1975 movl 108(%esp), %edi
1976 roll $11, %ebx
1977 addl %eax, %ebx
1978 movl 4(%edi), %esi
1979 addl %esi, %edx
1980 movl 76(%esp), %esi
1981 addl %esi, %edx
1982 movl 8(%edi), %esi
1983 addl %esi, %ebp
1984 movl 80(%esp), %esi
1985 addl %esi, %ebp
1986 movl 12(%edi), %esi
1987 addl %esi, %eax
1988 movl 84(%esp), %esi
1989 addl %esi, %eax
1990 movl 16(%edi), %esi
1991 addl %esi, %ebx
1992 movl 68(%esp), %esi
1993 addl %esi, %ebx
1994 movl (%edi), %esi
1995 addl %esi, %ecx
1996 movl 72(%esp), %esi
1997 addl %esi, %ecx
1998 movl %edx, (%edi)
1999 movl %ebp, 4(%edi)
2000 movl %eax, 8(%edi)
2001 movl %ebx, 12(%edi)
2002 movl %ecx, 16(%edi)
2003 movl (%esp), %edi
2004 movl 112(%esp), %esi
2005 cmpl %esi, %edi
2006 movl 108(%esp), %edi
2007 jge .L000start
2008 addl $88, %esp
2009 popl %ebx
2010 popl %ebp
2011 popl %edi
2012 popl %esi
2013 ret
2014.ripemd160_block_x86_end:
2015 SIZE(ripemd160_block_x86,.ripemd160_block_x86_end-ripemd160_block_x86)
2016.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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# Normal is the 3# Normal is the
4# ripemd160_block_x86(MD5_CTX *c, ULONG *X); 4# ripemd160_block_x86(MD5_CTX *c, ULONG *X);
@@ -530,7 +530,7 @@ sub ripemd160_block
530 # &mov($tmp2, &wparam(0)); # Moved into last round 530 # &mov($tmp2, &wparam(0)); # Moved into last round
531 531
532 &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B 532 &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B
533 &add($D, $tmp1); 533 &add($D, $tmp1);
534 &mov($tmp1, &swtmp(1+18)); # $c 534 &mov($tmp1, &swtmp(1+18)); # $c
535 &add($D, $tmp1); 535 &add($D, $tmp1);
536 536
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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#ifdef NO_RIPEMD
67#error RIPEMD is disabled.
68#endif
69
66#define RIPEMD160_CBLOCK 64 70#define RIPEMD160_CBLOCK 64
67#define RIPEMD160_LBLOCK 16 71#define RIPEMD160_LBLOCK 16
68#define RIPEMD160_BLOCK 16 72#define RIPEMD160_BLOCK 16
@@ -78,20 +82,11 @@ typedef struct RIPEMD160state_st
78 int num; 82 int num;
79 } RIPEMD160_CTX; 83 } RIPEMD160_CTX;
80 84
81#ifndef NOPROTO
82void RIPEMD160_Init(RIPEMD160_CTX *c); 85void RIPEMD160_Init(RIPEMD160_CTX *c);
83void RIPEMD160_Update(RIPEMD160_CTX *c, unsigned char *data, unsigned long len); 86void RIPEMD160_Update(RIPEMD160_CTX *c, unsigned char *data, unsigned long len);
84void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); 87void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
85unsigned char *RIPEMD160(unsigned char *d, unsigned long n, unsigned char *md); 88unsigned char *RIPEMD160(unsigned char *d, unsigned long n, unsigned char *md);
86void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b); 89void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b);
87#else
88void RIPEMD160_Init();
89void RIPEMD160_Update();
90void RIPEMD160_Final();
91unsigned char *RIPEMD160();
92void RIPEMD160_Transform();
93#endif
94
95#ifdef __cplusplus 90#ifdef __cplusplus
96} 91}
97#endif 92#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "ripemd.h" 61#include <openssl/ripemd.h>
62 62
63#define BUFSIZE 1024*16 63#define BUFSIZE 1024*16
64 64
65#ifndef NOPROTO
66void do_fp(FILE *f); 65void do_fp(FILE *f);
67void pt(unsigned char *md); 66void pt(unsigned char *md);
67#ifndef _OSD_POSIX
68int read(int, void *, unsigned int); 68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif 69#endif
74 70
75int main(argc, argv) 71int main(int argc, char **argv)
76int argc;
77char **argv;
78 { 72 {
79 int i,err=0; 73 int i,err=0;
80 FILE *IN; 74 FILE *IN;
@@ -102,8 +96,7 @@ char **argv;
102 exit(err); 96 exit(err);
103 } 97 }
104 98
105void do_fp(f) 99void do_fp(FILE *f)
106FILE *f;
107 { 100 {
108 RIPEMD160_CTX c; 101 RIPEMD160_CTX c;
109 unsigned char md[RIPEMD160_DIGEST_LENGTH]; 102 unsigned char md[RIPEMD160_DIGEST_LENGTH];
@@ -123,8 +116,7 @@ FILE *f;
123 pt(md); 116 pt(md);
124 } 117 }
125 118
126void pt(md) 119void pt(unsigned char *md)
127unsigned char *md;
128 { 120 {
129 int i; 121 int i;
130 122
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "rmd_locl.h" 60#include "rmd_locl.h"
61#include <openssl/opensslv.h>
61 62
62char *RMD160_version="RIPEMD160 part of SSLeay 0.9.0b 29-Jun-1998"; 63char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
63 64
64#ifndef NOPROTO
65# ifdef RMD160_ASM 65# ifdef RMD160_ASM
66 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num); 66 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num);
67# define ripemd160_block ripemd160_block_x86 67# define ripemd160_block ripemd160_block_x86
68# else 68# else
69 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num); 69 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num);
70# endif 70# endif
71#else 71void RIPEMD160_Init(RIPEMD160_CTX *c)
72# ifdef RMD160_ASM
73 void ripemd160_block_x86();
74# define ripemd160_block ripemd160_block_x86
75# else
76 static void ripemd160_block();
77# endif
78#endif
79
80void RIPEMD160_Init(c)
81RIPEMD160_CTX *c;
82 { 72 {
83 c->A=RIPEMD160_A; 73 c->A=RIPEMD160_A;
84 c->B=RIPEMD160_B; 74 c->B=RIPEMD160_B;
@@ -90,10 +80,8 @@ RIPEMD160_CTX *c;
90 c->num=0; 80 c->num=0;
91 } 81 }
92 82
93void RIPEMD160_Update(c, data, len) 83void RIPEMD160_Update(RIPEMD160_CTX *c, register unsigned char *data,
94RIPEMD160_CTX *c; 84 unsigned long len)
95register unsigned char *data;
96unsigned long len;
97 { 85 {
98 register ULONG *p; 86 register ULONG *p;
99 int sw,sc; 87 int sw,sc;
@@ -221,9 +209,7 @@ unsigned long len;
221 } 209 }
222 } 210 }
223 211
224void RIPEMD160_Transform(c,b) 212void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b)
225RIPEMD160_CTX *c;
226unsigned char *b;
227 { 213 {
228 ULONG p[16]; 214 ULONG p[16];
229#if !defined(L_ENDIAN) 215#if !defined(L_ENDIAN)
@@ -260,10 +246,7 @@ unsigned char *b;
260 246
261#ifndef RMD160_ASM 247#ifndef RMD160_ASM
262 248
263void ripemd160_block(ctx, X, num) 249void ripemd160_block(RIPEMD160_CTX *ctx, register ULONG *X, int num)
264RIPEMD160_CTX *ctx;
265register ULONG *X;
266int num;
267 { 250 {
268 register ULONG A,B,C,D,E; 251 register ULONG A,B,C,D,E;
269 ULONG a,b,c,d,e; 252 ULONG a,b,c,d,e;
@@ -460,9 +443,7 @@ int num;
460 } 443 }
461#endif 444#endif
462 445
463void RIPEMD160_Final(md, c) 446void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c)
464unsigned char *md;
465RIPEMD160_CTX *c;
466 { 447 {
467 register int i,j; 448 register int i,j;
468 register ULONG l; 449 register ULONG l;
@@ -518,8 +499,7 @@ RIPEMD160_CTX *c;
518 } 499 }
519 500
520#ifdef undef 501#ifdef undef
521int printit(l) 502int printit(unsigned long *l)
522unsigned long *l;
523 { 503 {
524 int i,ii; 504 int i,ii;
525 505
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 @@
58 58
59#include <stdlib.h> 59#include <stdlib.h>
60#include <string.h> 60#include <string.h>
61#include "ripemd.h" 61#include <openssl/ripemd.h>
62 62
63#define ULONG unsigned long 63#define ULONG unsigned long
64#define UCHAR unsigned char 64#define UCHAR unsigned char
65#define UINT unsigned int 65#define UINT unsigned int
66 66
67#ifdef NOCONST
68#define const
69#endif
70
71#undef c2nl 67#undef c2nl
72#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ 68#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
73 l|=(((unsigned long)(*((c)++)))<<16), \ 69 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include "rmd_locl.h" 60#include "rmd_locl.h"
61 61
62unsigned char *RIPEMD160(d, n, md) 62unsigned char *RIPEMD160(unsigned char *d, unsigned long n,
63unsigned char *d; 63 unsigned char *md)
64unsigned long n;
65unsigned char *md;
66 { 64 {
67 RIPEMD160_CTX c; 65 RIPEMD160_CTX c;
68 static unsigned char m[RIPEMD160_DIGEST_LENGTH]; 66 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include "ripemd.h" 62
63#ifdef NO_RIPEMD
64int main(int argc, char *argv[])
65{
66 printf("No ripemd support\n");
67 return(0);
68}
69#else
70#include <openssl/ripemd.h>
71
72#ifdef CHARSET_EBCDIC
73#include <openssl/ebcdic.h>
74#endif
63 75
64char *test[]={ 76char *test[]={
65 "", 77 "",
@@ -84,15 +96,8 @@ char *ret[]={
84 "9b752e45573d4b39f4dbd3323cab82bf63326bfb", 96 "9b752e45573d4b39f4dbd3323cab82bf63326bfb",
85 }; 97 };
86 98
87#ifndef NOPROTO
88static char *pt(unsigned char *md); 99static char *pt(unsigned char *md);
89#else 100int main(int argc, char *argv[])
90static char *pt();
91#endif
92
93int main(argc,argv)
94int argc;
95char *argv[];
96 { 101 {
97 int i,err=0; 102 int i,err=0;
98 unsigned char **P,**R; 103 unsigned char **P,**R;
@@ -103,6 +108,9 @@ char *argv[];
103 i=1; 108 i=1;
104 while (*P != NULL) 109 while (*P != NULL)
105 { 110 {
111#ifdef CHARSET_EBCDIC
112 ebcdic2ascii((char *)*P, (char *)*P, strlen((char *)*P));
113#endif
106 p=pt(RIPEMD160(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL)); 114 p=pt(RIPEMD160(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
107 if (strcmp(p,(char *)*R) != 0) 115 if (strcmp(p,(char *)*R) != 0)
108 { 116 {
@@ -120,8 +128,7 @@ char *argv[];
120 return(0); 128 return(0);
121 } 129 }
122 130
123static char *pt(md) 131static char *pt(unsigned char *md)
124unsigned char *md;
125 { 132 {
126 int i; 133 int i;
127 static char buf[80]; 134 static char buf[80];
@@ -130,4 +137,4 @@ unsigned char *md;
130 sprintf(&(buf[i*2]),"%02x",md[i]); 137 sprintf(&(buf[i*2]),"%02x",md[i]);
131 return(buf); 138 return(buf);
132 } 139 }
133 140#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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=rsa
19ERRC=rsa_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= 21TEST=rsa_oaep_test.c
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c $(ERRC).c \ 25LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \
26 rsa_pk1.c rsa_ssl.c rsa_none.c 26 rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c
27LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o $(ERRC).o \ 27LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \
28 rsa_pk1.o rsa_ssl.o rsa_none.o 28 rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o
29 29
30SRC= $(LIBSRC) 30SRC= $(LIBSRC)
31 31
@@ -41,24 +41,23 @@ all: lib
41 41
42lib: $(LIBOBJ) 42lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ) 43 $(AR) $(LIB) $(LIBOBJ)
44 sh $(TOP)/util/ranlib.sh $(LIB) 44 $(RANLIB) $(LIB)
45 @touch lib 45 @touch lib
46 46
47files: 47files:
48 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 48 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
49 49
50links: 50links:
51 /bin/rm -f Makefile 51 @$(TOP)/util/point.sh Makefile.ssl Makefile
52 $(TOP)/util/point.sh Makefile.ssl Makefile ; 52 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
53 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 53 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
54 $(TOP)/util/mklink.sh ../../test $(TEST) 54 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
55 $(TOP)/util/mklink.sh ../../apps $(APPS)
56 55
57install: 56install:
58 @for i in $(EXHEADER) ; \ 57 @for i in $(EXHEADER) ; \
59 do \ 58 do \
60 (cp $$i $(INSTALLTOP)/include/$$i; \ 59 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
61 chmod 644 $(INSTALLTOP)/include/$$i ); \ 60 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
62 done; 61 done;
63 62
64tags: 63tags:
@@ -70,17 +69,104 @@ lint:
70 lint -DLINT $(INCLUDES) $(SRC)>fluff 69 lint -DLINT $(INCLUDES) $(SRC)>fluff
71 70
72depend: 71depend:
73 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 72 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
74 73
75dclean: 74dclean:
76 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 75 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
77 mv -f Makefile.new $(MAKEFILE) 76 mv -f Makefile.new $(MAKEFILE)
78 77
79clean: 78clean:
80 /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 79 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
81
82errors:
83 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
84 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
85 80
86# DO NOT DELETE THIS LINE -- make depend depends on it. 81# DO NOT DELETE THIS LINE -- make depend depends on it.
82
83rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
84rsa_chk.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
85rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
86rsa_chk.o: ../../include/openssl/stack.h
87rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
88rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
89rsa_eay.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
90rsa_eay.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
91rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
92rsa_eay.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h
93rsa_eay.o: ../cryptlib.h
94rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
95rsa_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
96rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
97rsa_err.o: ../../include/openssl/stack.h
98rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
99rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
100rsa_gen.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
101rsa_gen.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
102rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/rsa.h
103rsa_gen.o: ../../include/openssl/stack.h ../cryptlib.h
104rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
105rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
106rsa_lib.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
107rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
108rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
109rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h
110rsa_lib.o: ../cryptlib.h
111rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
112rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
113rsa_none.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
114rsa_none.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
115rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
116rsa_none.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h
117rsa_none.o: ../cryptlib.h
118rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
119rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
120rsa_oaep.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
121rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
122rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
123rsa_oaep.o: ../../include/openssl/rsa.h ../../include/openssl/sha.h
124rsa_oaep.o: ../../include/openssl/stack.h ../cryptlib.h
125rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
126rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
127rsa_pk1.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
128rsa_pk1.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
129rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
130rsa_pk1.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h
131rsa_pk1.o: ../cryptlib.h
132rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
133rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
134rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
135rsa_saos.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
136rsa_saos.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
137rsa_saos.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
138rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h
139rsa_saos.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
140rsa_saos.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
141rsa_saos.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
142rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
143rsa_saos.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
144rsa_saos.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
145rsa_saos.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
146rsa_saos.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
147rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
148rsa_saos.o: ../cryptlib.h
149rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
150rsa_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
151rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
152rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
153rsa_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
154rsa_sign.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
155rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
156rsa_sign.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
157rsa_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
158rsa_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
159rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
160rsa_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
161rsa_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
162rsa_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
163rsa_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
164rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
165rsa_sign.o: ../cryptlib.h
166rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
167rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
168rsa_ssl.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
169rsa_ssl.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
170rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h
171rsa_ssl.o: ../../include/openssl/rsa.h ../../include/openssl/stack.h
172rsa_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 @@
1/* Error codes for the RSA functions. */
2
3/* Function codes. */
4#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 100
5#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 101
6#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 102
7#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 103
8#define RSA_F_RSA_GENERATE_KEY 104
9#define RSA_F_RSA_NEW_METHOD 105
10#define RSA_F_RSA_PADDING_ADD_NONE 106
11#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 107
12#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 108
13#define RSA_F_RSA_PADDING_ADD_SSLV23 109
14#define RSA_F_RSA_PADDING_CHECK_NONE 110
15#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 111
16#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 112
17#define RSA_F_RSA_PADDING_CHECK_SSLV23 113
18#define RSA_F_RSA_PRINT 114
19#define RSA_F_RSA_PRINT_FP 115
20#define RSA_F_RSA_SIGN 116
21#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 117
22#define RSA_F_RSA_VERIFY 118
23#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 119
24
25/* Reason codes. */
26#define RSA_R_ALGORITHM_MISMATCH 100
27#define RSA_R_BAD_E_VALUE 101
28#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
29#define RSA_R_BAD_PAD_BYTE_COUNT 103
30#define RSA_R_BAD_SIGNATURE 104
31#define RSA_R_BAD_ZERO_BYTE 105
32#define RSA_R_BLOCK_TYPE_IS_NOT_01 106
33#define RSA_R_BLOCK_TYPE_IS_NOT_02 107
34#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
35#define RSA_R_DATA_TOO_LARGE 109
36#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
37#define RSA_R_DATA_TOO_SMALL 111
38#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
39#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
40#define RSA_R_PADDING_CHECK_FAILED 114
41#define RSA_R_SSLV3_ROLLBACK_ATTACK 115
42#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
43#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
44#define RSA_R_UNKNOWN_PADDING_TYPE 118
45#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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "bn.h" 66#include <openssl/bn.h>
67#include "crypto.h" 67#include <openssl/crypto.h>
68
69#ifdef NO_RSA
70#error RSA is disabled.
71#endif
72
73typedef struct rsa_st RSA;
68 74
69typedef struct rsa_meth_st 75typedef struct rsa_meth_st
70 { 76 {
71 char *name; 77 const char *name;
72 int (*rsa_pub_enc)(); 78 int (*rsa_pub_enc)(int flen,unsigned char *from,unsigned char *to,
73 int (*rsa_pub_dec)(); 79 RSA *rsa,int padding);
74 int (*rsa_priv_enc)(); 80 int (*rsa_pub_dec)(int flen,unsigned char *from,unsigned char *to,
75 int (*rsa_priv_dec)(); 81 RSA *rsa,int padding);
76 int (*rsa_mod_exp)(); /* Can be null */ 82 int (*rsa_priv_enc)(int flen,unsigned char *from,unsigned char *to,
77 int (*bn_mod_exp)(); /* Can be null */ 83 RSA *rsa,int padding);
78 int (*init)(/* RSA * */); /* called at new */ 84 int (*rsa_priv_dec)(int flen,unsigned char *from,unsigned char *to,
79 int (*finish)(/* RSA * */); /* called at free */ 85 RSA *rsa,int padding);
80 86 int (*rsa_mod_exp)(BIGNUM *r0,BIGNUM *I,RSA *rsa); /* Can be null */
87 int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
88 const BIGNUM *m, BN_CTX *ctx,
89 BN_MONT_CTX *m_ctx); /* Can be null */
90 int (*init)(RSA *rsa); /* called at new */
91 int (*finish)(RSA *rsa); /* called at free */
81 int flags; /* RSA_METHOD_FLAG_* things */ 92 int flags; /* RSA_METHOD_FLAG_* things */
82 char *app_data; /* may be needed! */ 93 char *app_data; /* may be needed! */
83 } RSA_METHOD; 94 } RSA_METHOD;
84 95
85typedef struct rsa_st 96struct rsa_st
86 { 97 {
87 /* The first parameter is used to pickup errors where 98 /* The first parameter is used to pickup errors where
88 * this is passed instead of aEVP_PKEY, it is set to 0 */ 99 * this is passed instead of aEVP_PKEY, it is set to 0 */
@@ -97,41 +108,52 @@ typedef struct rsa_st
97 BIGNUM *dmp1; 108 BIGNUM *dmp1;
98 BIGNUM *dmq1; 109 BIGNUM *dmq1;
99 BIGNUM *iqmp; 110 BIGNUM *iqmp;
100 /* be carefull using this if the RSA structure is shared */ 111 /* be careful using this if the RSA structure is shared */
101 CRYPTO_EX_DATA ex_data; 112 CRYPTO_EX_DATA ex_data;
102 int references; 113 int references;
103 int flags; 114 int flags;
104 115
105 /* Normally used to cached montgomery values */ 116 /* Used to cache montgomery values */
106 char *method_mod_n; 117 BN_MONT_CTX *_method_mod_n;
107 char *method_mod_p; 118 BN_MONT_CTX *_method_mod_p;
108 char *method_mod_q; 119 BN_MONT_CTX *_method_mod_q;
109 120
121 /* all BIGNUM values are actually in the following data, if it is not
122 * NULL */
123 char *bignum_data;
110 BN_BLINDING *blinding; 124 BN_BLINDING *blinding;
111 } RSA; 125 };
112 126
113#define RSA_3 0x3L 127#define RSA_3 0x3L
114#define RSA_F4 0x10001L 128#define RSA_F4 0x10001L
115 129
116#define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */ 130#define RSA_METHOD_FLAG_NO_CHECK 0x01 /* don't check pub/private match */
131
117#define RSA_FLAG_CACHE_PUBLIC 0x02 132#define RSA_FLAG_CACHE_PUBLIC 0x02
118#define RSA_FLAG_CACHE_PRIVATE 0x04 133#define RSA_FLAG_CACHE_PRIVATE 0x04
119#define RSA_FLAG_BLINDING 0x08 134#define RSA_FLAG_BLINDING 0x08
120#define RSA_FLAG_THREAD_SAFE 0x10 135#define RSA_FLAG_THREAD_SAFE 0x10
136/* This flag means the private key operations will be handled by rsa_mod_exp
137 * and that they do not depend on the private key components being present:
138 * for example a key stored in external hardware. Without this flag bn_mod_exp
139 * gets called when private key components are absent.
140 */
141#define RSA_FLAG_EXT_PKEY 0x20
121 142
122#define RSA_PKCS1_PADDING 1 143#define RSA_PKCS1_PADDING 1
123#define RSA_SSLV23_PADDING 2 144#define RSA_SSLV23_PADDING 2
124#define RSA_NO_PADDING 3 145#define RSA_NO_PADDING 3
146#define RSA_PKCS1_OAEP_PADDING 4
125 147
126#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg) 148#define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,(char *)arg)
127#define RSA_get_app_data(s) RSA_get_ex_data(s,0) 149#define RSA_get_app_data(s) RSA_get_ex_data(s,0)
128 150
129#ifndef NOPROTO
130RSA * RSA_new(void); 151RSA * RSA_new(void);
131RSA * RSA_new_method(RSA_METHOD *method); 152RSA * RSA_new_method(RSA_METHOD *method);
132int RSA_size(RSA *); 153int RSA_size(RSA *);
133RSA * RSA_generate_key(int bits, unsigned long e,void 154RSA * RSA_generate_key(int bits, unsigned long e,void
134 (*callback)(int,int,char *),char *cb_arg); 155 (*callback)(int,int,void *),void *cb_arg);
156int RSA_check_key(RSA *);
135 /* next 4 return -1 on error */ 157 /* next 4 return -1 on error */
136int RSA_public_encrypt(int flen, unsigned char *from, 158int RSA_public_encrypt(int flen, unsigned char *from,
137 unsigned char *to, RSA *rsa,int padding); 159 unsigned char *to, RSA *rsa,int padding);
@@ -146,6 +168,12 @@ void RSA_free (RSA *r);
146int RSA_flags(RSA *r); 168int RSA_flags(RSA *r);
147 169
148void RSA_set_default_method(RSA_METHOD *meth); 170void RSA_set_default_method(RSA_METHOD *meth);
171RSA_METHOD *RSA_get_default_method(void);
172RSA_METHOD *RSA_get_method(RSA *rsa);
173RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth);
174
175/* This function needs the memory locking malloc callbacks to be installed */
176int RSA_memory_lock(RSA *r);
149 177
150/* If you have RSAref compiled in. */ 178/* If you have RSAref compiled in. */
151RSA_METHOD *RSA_PKCS1_RSAref(void); 179RSA_METHOD *RSA_PKCS1_RSAref(void);
@@ -193,107 +221,63 @@ void RSA_blinding_off(RSA *rsa);
193int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, 221int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,
194 unsigned char *f,int fl); 222 unsigned char *f,int fl);
195int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen, 223int RSA_padding_check_PKCS1_type_1(unsigned char *to,int tlen,
196 unsigned char *f,int fl); 224 unsigned char *f,int fl,int rsa_len);
197int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen, 225int RSA_padding_add_PKCS1_type_2(unsigned char *to,int tlen,
198 unsigned char *f,int fl); 226 unsigned char *f,int fl);
199int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen, 227int RSA_padding_check_PKCS1_type_2(unsigned char *to,int tlen,
200 unsigned char *f,int fl); 228 unsigned char *f,int fl,int rsa_len);
229int RSA_padding_add_PKCS1_OAEP(unsigned char *to,int tlen,
230 unsigned char *f,int fl,unsigned char *p,
231 int pl);
232int RSA_padding_check_PKCS1_OAEP(unsigned char *to,int tlen,
233 unsigned char *f,int fl,int rsa_len,
234 unsigned char *p,int pl);
201int RSA_padding_add_SSLv23(unsigned char *to,int tlen, 235int RSA_padding_add_SSLv23(unsigned char *to,int tlen,
202 unsigned char *f,int fl); 236 unsigned char *f,int fl);
203int RSA_padding_check_SSLv23(unsigned char *to,int tlen, 237int RSA_padding_check_SSLv23(unsigned char *to,int tlen,
204 unsigned char *f,int fl); 238 unsigned char *f,int fl,int rsa_len);
205int RSA_padding_add_none(unsigned char *to,int tlen, 239int RSA_padding_add_none(unsigned char *to,int tlen,
206 unsigned char *f,int fl); 240 unsigned char *f,int fl);
207int RSA_padding_check_none(unsigned char *to,int tlen, 241int RSA_padding_check_none(unsigned char *to,int tlen,
208 unsigned char *f,int fl); 242 unsigned char *f,int fl,int rsa_len);
209 243
210int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(), 244int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
211 int (*dup_func)(), void (*free_func)()); 245 int (*dup_func)(), void (*free_func)());
212int RSA_set_ex_data(RSA *r,int idx,char *arg); 246int RSA_set_ex_data(RSA *r,int idx,char *arg);
213char *RSA_get_ex_data(RSA *r, int idx); 247char *RSA_get_ex_data(RSA *r, int idx);
214 248
215#else
216
217RSA * RSA_new();
218RSA * RSA_new_method();
219int RSA_size();
220RSA * RSA_generate_key();
221int RSA_public_encrypt();
222int RSA_private_encrypt();
223int RSA_public_decrypt();
224int RSA_private_decrypt();
225void RSA_free ();
226
227int RSA_flags();
228
229void RSA_set_default_method();
230
231/* RSA_METHOD *RSA_PKCS1_RSAref(); */
232RSA_METHOD *RSA_PKCS1_SSLeay();
233
234void ERR_load_RSA_strings();
235
236RSA * d2i_RSAPublicKey();
237int i2d_RSAPublicKey();
238RSA * d2i_RSAPrivateKey();
239int i2d_RSAPrivateKey();
240#ifndef NO_FP_API
241int RSA_print_fp();
242#endif
243
244int RSA_print();
245
246int i2d_Netscape_RSA();
247RSA *d2i_Netscape_RSA();
248RSA *d2i_Netscape_RSA_2();
249
250int RSA_sign();
251int RSA_verify();
252
253int RSA_sign_ASN1_OCTET_STRING();
254int RSA_verify_ASN1_OCTET_STRING();
255int RSA_blinding_on();
256void RSA_blinding_off();
257
258int RSA_padding_add_PKCS1_type_1();
259int RSA_padding_check_PKCS1_type_1();
260int RSA_padding_add_PKCS1_type_2();
261int RSA_padding_check_PKCS1_type_2();
262int RSA_padding_add_SSLv23();
263int RSA_padding_check_SSLv23();
264int RSA_padding_add_none();
265int RSA_padding_check_none();
266
267int RSA_get_ex_new_index();
268int RSA_set_ex_data();
269char *RSA_get_ex_data();
270
271#endif
272
273/* BEGIN ERROR CODES */ 249/* BEGIN ERROR CODES */
250/* The following lines are auto generated by the script mkerr.pl. Any changes
251 * made after this point may be overwritten when the script is next run.
252 */
253
274/* Error codes for the RSA functions. */ 254/* Error codes for the RSA functions. */
275 255
276/* Function codes. */ 256/* Function codes. */
277#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 100 257#define RSA_F_MEMORY_LOCK 100
278#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 101 258#define RSA_F_RSA_CHECK_KEY 123
279#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 102 259#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101
280#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 103 260#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102
281#define RSA_F_RSA_GENERATE_KEY 104 261#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103
282#define RSA_F_RSA_NEW_METHOD 105 262#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104
283#define RSA_F_RSA_PADDING_ADD_NONE 106 263#define RSA_F_RSA_GENERATE_KEY 105
284#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 107 264#define RSA_F_RSA_NEW_METHOD 106
285#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 108 265#define RSA_F_RSA_PADDING_ADD_NONE 107
286#define RSA_F_RSA_PADDING_ADD_SSLV23 109 266#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
287#define RSA_F_RSA_PADDING_CHECK_NONE 110 267#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1 108
288#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 111 268#define RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2 109
289#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 112 269#define RSA_F_RSA_PADDING_ADD_SSLV23 110
290#define RSA_F_RSA_PADDING_CHECK_SSLV23 113 270#define RSA_F_RSA_PADDING_CHECK_NONE 111
291#define RSA_F_RSA_PRINT 114 271#define RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP 122
292#define RSA_F_RSA_PRINT_FP 115 272#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1 112
293#define RSA_F_RSA_SIGN 116 273#define RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2 113
294#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 117 274#define RSA_F_RSA_PADDING_CHECK_SSLV23 114
295#define RSA_F_RSA_VERIFY 118 275#define RSA_F_RSA_PRINT 115
296#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 119 276#define RSA_F_RSA_PRINT_FP 116
277#define RSA_F_RSA_SIGN 117
278#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
279#define RSA_F_RSA_VERIFY 119
280#define RSA_F_RSA_VERIFY_ASN1_OCTET_STRING 120
297 281
298/* Reason codes. */ 282/* Reason codes. */
299#define RSA_R_ALGORITHM_MISMATCH 100 283#define RSA_R_ALGORITHM_MISMATCH 100
@@ -301,22 +285,31 @@ char *RSA_get_ex_data();
301#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102 285#define RSA_R_BAD_FIXED_HEADER_DECRYPT 102
302#define RSA_R_BAD_PAD_BYTE_COUNT 103 286#define RSA_R_BAD_PAD_BYTE_COUNT 103
303#define RSA_R_BAD_SIGNATURE 104 287#define RSA_R_BAD_SIGNATURE 104
304#define RSA_R_BAD_ZERO_BYTE 105
305#define RSA_R_BLOCK_TYPE_IS_NOT_01 106 288#define RSA_R_BLOCK_TYPE_IS_NOT_01 106
306#define RSA_R_BLOCK_TYPE_IS_NOT_02 107 289#define RSA_R_BLOCK_TYPE_IS_NOT_02 107
307#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108 290#define RSA_R_DATA_GREATER_THAN_MOD_LEN 108
308#define RSA_R_DATA_TOO_LARGE 109 291#define RSA_R_DATA_TOO_LARGE 109
309#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110 292#define RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 110
310#define RSA_R_DATA_TOO_SMALL 111 293#define RSA_R_DATA_TOO_SMALL 111
294#define RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE 122
295#define RSA_R_D_E_NOT_CONGRUENT_TO_1 123
311#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112 296#define RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY 112
297#define RSA_R_DMP1_NOT_CONGRUENT_TO_D 124
298#define RSA_R_DMQ1_NOT_CONGRUENT_TO_D 125
299#define RSA_R_IQMP_NOT_INVERSE_OF_Q 126
300#define RSA_R_KEY_SIZE_TOO_SMALL 120
312#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 301#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
302#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
303#define RSA_R_OAEP_DECODING_ERROR 121
313#define RSA_R_PADDING_CHECK_FAILED 114 304#define RSA_R_PADDING_CHECK_FAILED 114
305#define RSA_R_P_NOT_PRIME 128
306#define RSA_R_Q_NOT_PRIME 129
314#define RSA_R_SSLV3_ROLLBACK_ATTACK 115 307#define RSA_R_SSLV3_ROLLBACK_ATTACK 115
315#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116 308#define RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 116
316#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117 309#define RSA_R_UNKNOWN_ALGORITHM_TYPE 117
317#define RSA_R_UNKNOWN_PADDING_TYPE 118 310#define RSA_R_UNKNOWN_PADDING_TYPE 118
318#define RSA_R_WRONG_SIGNATURE_LENGTH 119 311#define RSA_R_WRONG_SIGNATURE_LENGTH 119
319 312
320#ifdef __cplusplus 313#ifdef __cplusplus
321} 314}
322#endif 315#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 @@
1/* crypto/rsa/rsa_chk.c -*- Mode: C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 */
50
51#include <openssl/bn.h>
52#include <openssl/err.h>
53#include <openssl/rsa.h>
54
55
56int RSA_check_key(RSA *key)
57 {
58 BIGNUM *i, *j, *k, *l, *m;
59 BN_CTX *ctx;
60 int r;
61 int ret=1;
62
63 i = BN_new();
64 j = BN_new();
65 k = BN_new();
66 l = BN_new();
67 m = BN_new();
68 ctx = BN_CTX_new();
69 if (i == NULL || j == NULL || k == NULL || l == NULL ||
70 m == NULL || ctx == NULL)
71 {
72 ret = -1;
73 RSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE);
74 goto err;
75 }
76
77 /* p prime? */
78 r = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL);
79 if (r != 1)
80 {
81 ret = r;
82 if (r != 0)
83 goto err;
84 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME);
85 }
86
87 /* q prime? */
88 r = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL);
89 if (r != 1)
90 {
91 ret = r;
92 if (r != 0)
93 goto err;
94 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME);
95 }
96
97 /* n = p*q? */
98 r = BN_mul(i, key->p, key->q, ctx);
99 if (!r) { ret = -1; goto err; }
100
101 if (BN_cmp(i, key->n) != 0)
102 {
103 ret = 0;
104 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q);
105 }
106
107 /* d*e = 1 mod lcm(p-1,q-1)? */
108
109 r = BN_sub(i, key->p, BN_value_one());
110 if (!r) { ret = -1; goto err; }
111 r = BN_sub(j, key->q, BN_value_one());
112 if (!r) { ret = -1; goto err; }
113
114 /* now compute k = lcm(i,j) */
115 r = BN_mul(l, i, j, ctx);
116 if (!r) { ret = -1; goto err; }
117 r = BN_gcd(m, i, j, ctx);
118 if (!r) { ret = -1; goto err; }
119 r = BN_div(k, NULL, l, m, ctx); /* remainder is 0 */
120 if (!r) { ret = -1; goto err; }
121
122 r = BN_mod_mul(i, key->d, key->e, k, ctx);
123 if (!r) { ret = -1; goto err; }
124
125 if (!BN_is_one(i))
126 {
127 ret = 0;
128 RSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1);
129 }
130
131 if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL)
132 {
133 /* dmp1 = d mod (p-1)? */
134 r = BN_sub(i, key->p, BN_value_one());
135 if (!r) { ret = -1; goto err; }
136
137 r = BN_mod(j, key->d, i, ctx);
138 if (!r) { ret = -1; goto err; }
139
140 if (BN_cmp(j, key->dmp1) != 0)
141 {
142 ret = 0;
143 RSAerr(RSA_F_RSA_CHECK_KEY,
144 RSA_R_DMP1_NOT_CONGRUENT_TO_D);
145 }
146
147 /* dmq1 = d mod (q-1)? */
148 r = BN_sub(i, key->q, BN_value_one());
149 if (!r) { ret = -1; goto err; }
150
151 r = BN_mod(j, key->d, i, ctx);
152 if (!r) { ret = -1; goto err; }
153
154 if (BN_cmp(j, key->dmq1) != 0)
155 {
156 ret = 0;
157 RSAerr(RSA_F_RSA_CHECK_KEY,
158 RSA_R_DMQ1_NOT_CONGRUENT_TO_D);
159 }
160
161 /* iqmp = q^-1 mod p? */
162 if(!BN_mod_inverse(i, key->q, key->p, ctx))
163 {
164 ret = -1;
165 goto err;
166 }
167
168 if (BN_cmp(i, key->iqmp) != 0)
169 {
170 ret = 0;
171 RSAerr(RSA_F_RSA_CHECK_KEY,
172 RSA_R_IQMP_NOT_INVERSE_OF_Q);
173 }
174 }
175
176 err:
177 if (i != NULL) BN_free(i);
178 if (j != NULL) BN_free(j);
179 if (k != NULL) BN_free(k);
180 if (l != NULL) BN_free(l);
181 if (m != NULL) BN_free(m);
182 if (ctx != NULL) BN_CTX_free(ctx);
183 return (ret);
184 }
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index 42a77f11cd..776324860c 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -68,11 +68,10 @@
68 68
69#include <stdio.h> 69#include <stdio.h>
70#include "cryptlib.h" 70#include "cryptlib.h"
71#include "bn.h" 71#include <openssl/bn.h>
72#include "rsa.h" 72#include <openssl/rsa.h>
73#include "rand.h" 73#include <openssl/rand.h>
74 74
75#ifndef NOPROTO
76static int RSA_eay_public_encrypt(int flen, unsigned char *from, 75static int RSA_eay_public_encrypt(int flen, unsigned char *from,
77 unsigned char *to, RSA *rsa,int padding); 76 unsigned char *to, RSA *rsa,int padding);
78static int RSA_eay_private_encrypt(int flen, unsigned char *from, 77static 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,
84static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa); 83static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa);
85static int RSA_eay_init(RSA *rsa); 84static int RSA_eay_init(RSA *rsa);
86static int RSA_eay_finish(RSA *rsa); 85static int RSA_eay_finish(RSA *rsa);
87#else
88static int RSA_eay_public_encrypt();
89static int RSA_eay_private_encrypt();
90static int RSA_eay_public_decrypt();
91static int RSA_eay_private_decrypt();
92static int RSA_eay_mod_exp();
93static int RSA_eay_init();
94static int RSA_eay_finish();
95#endif
96
97static RSA_METHOD rsa_pkcs1_eay_meth={ 86static RSA_METHOD rsa_pkcs1_eay_meth={
98 "Eric Young's PKCS#1 RSA", 87 "Eric Young's PKCS#1 RSA",
99 RSA_eay_public_encrypt, 88 RSA_eay_public_encrypt,
@@ -108,31 +97,75 @@ static RSA_METHOD rsa_pkcs1_eay_meth={
108 NULL, 97 NULL,
109 }; 98 };
110 99
111RSA_METHOD *RSA_PKCS1_SSLeay() 100RSA_METHOD *RSA_PKCS1_SSLeay(void)
112 { 101 {
113 return(&rsa_pkcs1_eay_meth); 102 return(&rsa_pkcs1_eay_meth);
114 } 103 }
115 104
116static int RSA_eay_public_encrypt(flen, from, to, rsa, padding) 105static int RSA_eay_public_encrypt(int flen, unsigned char *from,
117int flen; 106 unsigned char *to, RSA *rsa, int padding)
118unsigned char *from;
119unsigned char *to;
120RSA *rsa;
121int padding;
122 { 107 {
123 BIGNUM *f=NULL,*ret=NULL; 108 BIGNUM f,ret;
124 int i,j,k,num=0,r= -1; 109 int i,j,k,num=0,r= -1;
125 unsigned char *buf=NULL; 110 unsigned char *buf=NULL;
126 BN_CTX *ctx=NULL; 111 BN_CTX *ctx=NULL;
127 112
128 /* Body of this routine removed for OpenBSD - will return 113 BN_init(&f);
129 * when the RSA patent expires 114 BN_init(&ret);
130 */ 115 if ((ctx=BN_CTX_new()) == NULL) goto err;
116 num=BN_num_bytes(rsa->n);
117 if ((buf=(unsigned char *)Malloc(num)) == NULL)
118 {
119 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
120 goto err;
121 }
122
123 switch (padding)
124 {
125 case RSA_PKCS1_PADDING:
126 i=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);
127 break;
128#ifndef NO_SHA
129 case RSA_PKCS1_OAEP_PADDING:
130 i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);
131 break;
132#endif
133 case RSA_SSLV23_PADDING:
134 i=RSA_padding_add_SSLv23(buf,num,from,flen);
135 break;
136 case RSA_NO_PADDING:
137 i=RSA_padding_add_none(buf,num,from,flen);
138 break;
139 default:
140 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
141 goto err;
142 }
143 if (i <= 0) goto err;
144
145 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
146
147 if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
148 {
149 if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)
150 if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))
151 goto err;
152 }
153
154 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
155 rsa->_method_mod_n)) goto err;
131 156
157 /* put in leading 0 bytes if the number is less than the
158 * length of the modulus */
159 j=BN_num_bytes(&ret);
160 i=BN_bn2bin(&ret,&(to[num-j]));
161 for (k=0; k<(num-i); k++)
162 to[k]=0;
163
164 r=num;
132err: 165err:
133 if (ctx != NULL) BN_CTX_free(ctx); 166 if (ctx != NULL) BN_CTX_free(ctx);
134 if (f != NULL) BN_free(f); 167 BN_clear_free(&f);
135 if (ret != NULL) BN_free(ret); 168 BN_clear_free(&ret);
136 if (buf != NULL) 169 if (buf != NULL)
137 { 170 {
138 memset(buf,0,num); 171 memset(buf,0,num);
@@ -141,14 +174,10 @@ err:
141 return(r); 174 return(r);
142 } 175 }
143 176
144static int RSA_eay_private_encrypt(flen, from, to, rsa, padding) 177static int RSA_eay_private_encrypt(int flen, unsigned char *from,
145int flen; 178 unsigned char *to, RSA *rsa, int padding)
146unsigned char *from;
147unsigned char *to;
148RSA *rsa;
149int padding;
150 { 179 {
151 BIGNUM *f=NULL,*ret=NULL; 180 BIGNUM f,ret;
152 int i,j,k,num=0,r= -1; 181 int i,j,k,num=0,r= -1;
153 unsigned char *buf=NULL; 182 unsigned char *buf=NULL;
154 BN_CTX *ctx=NULL; 183 BN_CTX *ctx=NULL;
@@ -159,8 +188,8 @@ int padding;
159 188
160err: 189err:
161 if (ctx != NULL) BN_CTX_free(ctx); 190 if (ctx != NULL) BN_CTX_free(ctx);
162 if (ret != NULL) BN_free(ret); 191 BN_clear_free(&ret);
163 if (f != NULL) BN_free(f); 192 BN_clear_free(&f);
164 if (buf != NULL) 193 if (buf != NULL)
165 { 194 {
166 memset(buf,0,num); 195 memset(buf,0,num);
@@ -169,14 +198,10 @@ err:
169 return(r); 198 return(r);
170 } 199 }
171 200
172static int RSA_eay_private_decrypt(flen, from, to, rsa,padding) 201static int RSA_eay_private_decrypt(int flen, unsigned char *from,
173int flen; 202 unsigned char *to, RSA *rsa, int padding)
174unsigned char *from;
175unsigned char *to;
176RSA *rsa;
177int padding;
178 { 203 {
179 BIGNUM *f=NULL,*ret=NULL; 204 BIGNUM f,ret;
180 int j,num=0,r= -1; 205 int j,num=0,r= -1;
181 unsigned char *p; 206 unsigned char *p;
182 unsigned char *buf=NULL; 207 unsigned char *buf=NULL;
@@ -188,8 +213,8 @@ int padding;
188 213
189err: 214err:
190 if (ctx != NULL) BN_CTX_free(ctx); 215 if (ctx != NULL) BN_CTX_free(ctx);
191 if (f != NULL) BN_free(f); 216 BN_clear_free(&f);
192 if (ret != NULL) BN_free(ret); 217 BN_clear_free(&ret);
193 if (buf != NULL) 218 if (buf != NULL)
194 { 219 {
195 memset(buf,0,num); 220 memset(buf,0,num);
@@ -198,28 +223,23 @@ err:
198 return(r); 223 return(r);
199 } 224 }
200 225
201static int RSA_eay_public_decrypt(flen, from, to, rsa, padding) 226static int RSA_eay_public_decrypt(int flen, unsigned char *from,
202int flen; 227 unsigned char *to, RSA *rsa, int padding)
203unsigned char *from;
204unsigned char *to;
205RSA *rsa;
206int padding;
207 { 228 {
208 BIGNUM *f=NULL,*ret=NULL; 229 BIGNUM f,ret;
209 int i,num=0,r= -1; 230 int i,num=0,r= -1;
210 unsigned char *p; 231 unsigned char *p;
211 unsigned char *buf=NULL; 232 unsigned char *buf=NULL;
212 BN_CTX *ctx=NULL; 233 BN_CTX *ctx=NULL;
213 234
214
215 /* Body of this routine removed for OpenBSD - will return 235 /* Body of this routine removed for OpenBSD - will return
216 * when the RSA patent expires 236 * when the RSA patent expires
217 */ 237 */
218 238
219err: 239err:
220 if (ctx != NULL) BN_CTX_free(ctx); 240 if (ctx != NULL) BN_CTX_free(ctx);
221 if (f != NULL) BN_free(f); 241 BN_clear_free(&f);
222 if (ret != NULL) BN_free(ret); 242 BN_clear_free(&ret);
223 if (buf != NULL) 243 if (buf != NULL)
224 { 244 {
225 memset(buf,0,num); 245 memset(buf,0,num);
@@ -228,46 +248,40 @@ err:
228 return(r); 248 return(r);
229 } 249 }
230 250
231static int RSA_eay_mod_exp(r0, I, rsa) 251static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
232BIGNUM *r0;
233BIGNUM *I;
234RSA *rsa;
235 { 252 {
236 BIGNUM *r1=NULL,*m1=NULL; 253 BIGNUM r1,m1;
237 int ret=0; 254 int ret=0;
238 BN_CTX *ctx; 255 BN_CTX *ctx;
239 256
240 if ((ctx=BN_CTX_new()) == NULL) goto err; 257 if ((ctx=BN_CTX_new()) == NULL) goto err;
241 m1=BN_new(); 258 BN_init(&m1);
242 r1=BN_new(); 259 BN_init(&r1);
243 if ((m1 == NULL) || (r1 == NULL)) goto err;
244 260
245 /* Body of this routine removed for OpenBSD - will return 261 /* Body of this routine removed for OpenBSD - will return
246 * when the RSA patent expires 262 * when the RSA patent expires
247 */ 263 */
248err: 264err:
249 if (m1 != NULL) BN_free(m1); 265 BN_clear_free(&m1);
250 if (r1 != NULL) BN_free(r1); 266 BN_clear_free(&r1);
251 BN_CTX_free(ctx); 267 BN_CTX_free(ctx);
252 return(ret); 268 return(ret);
253 } 269 }
254 270
255static int RSA_eay_init(rsa) 271static int RSA_eay_init(RSA *rsa)
256RSA *rsa;
257 { 272 {
258 rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE; 273 rsa->flags|=RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE;
259 return(1); 274 return(1);
260 } 275 }
261 276
262static int RSA_eay_finish(rsa) 277static int RSA_eay_finish(RSA *rsa)
263RSA *rsa;
264 { 278 {
265 if (rsa->method_mod_n != NULL) 279 if (rsa->_method_mod_n != NULL)
266 BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_n); 280 BN_MONT_CTX_free(rsa->_method_mod_n);
267 if (rsa->method_mod_p != NULL) 281 if (rsa->_method_mod_p != NULL)
268 BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_p); 282 BN_MONT_CTX_free(rsa->_method_mod_p);
269 if (rsa->method_mod_q != NULL) 283 if (rsa->_method_mod_q != NULL)
270 BN_MONT_CTX_free((BN_MONT_CTX *)rsa->method_mod_q); 284 BN_MONT_CTX_free(rsa->_method_mod_q);
271 return(1); 285 return(1);
272 } 286 }
273 287
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 @@
1/* lib/rsa/rsa_err.c */ 1/* crypto/rsa/rsa_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "rsa.h" 62#include <openssl/rsa.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
64static ERR_STRING_DATA RSA_str_functs[]= 66static ERR_STRING_DATA RSA_str_functs[]=
65 { 67 {
68{ERR_PACK(0,RSA_F_MEMORY_LOCK,0), "MEMORY_LOCK"},
69{ERR_PACK(0,RSA_F_RSA_CHECK_KEY,0), "RSA_check_key"},
66{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"}, 70{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_DECRYPT,0), "RSA_EAY_PRIVATE_DECRYPT"},
67{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"}, 71{ERR_PACK(0,RSA_F_RSA_EAY_PRIVATE_ENCRYPT,0), "RSA_EAY_PRIVATE_ENCRYPT"},
68{ERR_PACK(0,RSA_F_RSA_EAY_PUBLIC_DECRYPT,0), "RSA_EAY_PUBLIC_DECRYPT"}, 72{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[]=
70{ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"}, 74{ERR_PACK(0,RSA_F_RSA_GENERATE_KEY,0), "RSA_generate_key"},
71{ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"}, 75{ERR_PACK(0,RSA_F_RSA_NEW_METHOD,0), "RSA_new_method"},
72{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"}, 76{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_NONE,0), "RSA_padding_add_none"},
77{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,0), "RSA_padding_add_PKCS1_OAEP"},
73{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"}, 78{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,0), "RSA_padding_add_PKCS1_type_1"},
74{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"}, 79{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_2,0), "RSA_padding_add_PKCS1_type_2"},
75{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"}, 80{ERR_PACK(0,RSA_F_RSA_PADDING_ADD_SSLV23,0), "RSA_padding_add_SSLv23"},
76{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"}, 81{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_NONE,0), "RSA_padding_check_none"},
82{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,0), "RSA_padding_check_PKCS1_OAEP"},
77{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"}, 83{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,0), "RSA_padding_check_PKCS1_type_1"},
78{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"}, 84{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,0), "RSA_padding_check_PKCS1_type_2"},
79{ERR_PACK(0,RSA_F_RSA_PADDING_CHECK_SSLV23,0), "RSA_padding_check_SSLv23"}, 85{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[]=
83{ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"}, 89{ERR_PACK(0,RSA_F_RSA_SIGN_ASN1_OCTET_STRING,0), "RSA_sign_ASN1_OCTET_STRING"},
84{ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"}, 90{ERR_PACK(0,RSA_F_RSA_VERIFY,0), "RSA_verify"},
85{ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"}, 91{ERR_PACK(0,RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,0), "RSA_verify_ASN1_OCTET_STRING"},
86{0,NULL}, 92{0,NULL}
87 }; 93 };
88 94
89static ERR_STRING_DATA RSA_str_reasons[]= 95static ERR_STRING_DATA RSA_str_reasons[]=
@@ -93,32 +99,41 @@ static ERR_STRING_DATA RSA_str_reasons[]=
93{RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"}, 99{RSA_R_BAD_FIXED_HEADER_DECRYPT ,"bad fixed header decrypt"},
94{RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"}, 100{RSA_R_BAD_PAD_BYTE_COUNT ,"bad pad byte count"},
95{RSA_R_BAD_SIGNATURE ,"bad signature"}, 101{RSA_R_BAD_SIGNATURE ,"bad signature"},
96{RSA_R_BAD_ZERO_BYTE ,"bad zero byte"},
97{RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"}, 102{RSA_R_BLOCK_TYPE_IS_NOT_01 ,"block type is not 01"},
98{RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"}, 103{RSA_R_BLOCK_TYPE_IS_NOT_02 ,"block type is not 02"},
99{RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"}, 104{RSA_R_DATA_GREATER_THAN_MOD_LEN ,"data greater than mod len"},
100{RSA_R_DATA_TOO_LARGE ,"data too large"}, 105{RSA_R_DATA_TOO_LARGE ,"data too large"},
101{RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, 106{RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"},
102{RSA_R_DATA_TOO_SMALL ,"data too small"}, 107{RSA_R_DATA_TOO_SMALL ,"data too small"},
108{RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE ,"data too small for key size"},
109{RSA_R_D_E_NOT_CONGRUENT_TO_1 ,"d e not congruent to 1"},
103{RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"}, 110{RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY ,"digest too big for rsa key"},
111{RSA_R_DMP1_NOT_CONGRUENT_TO_D ,"dmp1 not congruent to d"},
112{RSA_R_DMQ1_NOT_CONGRUENT_TO_D ,"dmq1 not congruent to d"},
113{RSA_R_IQMP_NOT_INVERSE_OF_Q ,"iqmp not inverse of q"},
114{RSA_R_KEY_SIZE_TOO_SMALL ,"key size too small"},
104{RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"}, 115{RSA_R_NULL_BEFORE_BLOCK_MISSING ,"null before block missing"},
116{RSA_R_N_DOES_NOT_EQUAL_P_Q ,"n does not equal p q"},
117{RSA_R_OAEP_DECODING_ERROR ,"oaep decoding error"},
105{RSA_R_PADDING_CHECK_FAILED ,"padding check failed"}, 118{RSA_R_PADDING_CHECK_FAILED ,"padding check failed"},
119{RSA_R_P_NOT_PRIME ,"p not prime"},
120{RSA_R_Q_NOT_PRIME ,"q not prime"},
106{RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"}, 121{RSA_R_SSLV3_ROLLBACK_ATTACK ,"sslv3 rollback attack"},
107{RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, 122{RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"},
108{RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"}, 123{RSA_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
109{RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"}, 124{RSA_R_UNKNOWN_PADDING_TYPE ,"unknown padding type"},
110{RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"}, 125{RSA_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
111{0,NULL}, 126{0,NULL}
112 }; 127 };
113 128
114#endif 129#endif
115 130
116void ERR_load_RSA_strings() 131void ERR_load_RSA_strings(void)
117 { 132 {
118 static int init=1; 133 static int init=1;
119 134
120 if (init); 135 if (init)
121 {; 136 {
122 init=0; 137 init=0;
123#ifndef NO_ERR 138#ifndef NO_ERR
124 ERR_load_strings(ERR_LIB_RSA,RSA_str_functs); 139 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "bn.h" 62#include <openssl/bn.h>
63#include "rsa.h" 63#include <openssl/rsa.h>
64 64
65RSA *RSA_generate_key(bits, e_value, callback,cb_arg) 65RSA *RSA_generate_key(int bits, unsigned long e_value,
66int bits; 66 void (*callback)(int,int,void *), void *cb_arg)
67unsigned long e_value;
68void (*callback)(P_I_I_P);
69char *cb_arg;
70 { 67 {
71 RSA *rsa=NULL; 68 RSA *rsa=NULL;
72 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp; 69 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;
73 int bitsp,bitsq,ok= -1,n=0; 70 int bitsp,bitsq,ok= -1,n=0,i;
74 BN_CTX *ctx=NULL,*ctx2=NULL; 71 BN_CTX *ctx=NULL,*ctx2=NULL;
75 72
76 ctx=BN_CTX_new(); 73 ctx=BN_CTX_new();
@@ -81,6 +78,7 @@ char *cb_arg;
81 /* Body of this routine removed for OpenBSD - will return 78 /* Body of this routine removed for OpenBSD - will return
82 * when the RSA patent expires 79 * when the RSA patent expires
83 */ 80 */
81
84err: 82err:
85 if (ok == -1) 83 if (ok == -1)
86 { 84 {
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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "crypto.h" 60#include <openssl/crypto.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "lhash.h" 62#include <openssl/lhash.h>
63#include "bn.h" 63#include <openssl/bn.h>
64#include "rsa.h" 64#include <openssl/rsa.h>
65 65
66char *RSA_version="RSA part of SSLeay 0.9.0b 29-Jun-1998"; 66const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT;
67 67
68static RSA_METHOD *default_RSA_meth=NULL; 68static RSA_METHOD *default_RSA_meth=NULL;
69static int rsa_meth_num=0; 69static int rsa_meth_num=0;
70static STACK *rsa_meth=NULL; 70static STACK *rsa_meth=NULL;
71 71
72RSA *RSA_new() 72RSA *RSA_new(void)
73 { 73 {
74 return(RSA_new_method(NULL)); 74 return(RSA_new_method(NULL));
75 } 75 }
76 76
77void RSA_set_default_method(meth) 77void RSA_set_default_method(RSA_METHOD *meth)
78RSA_METHOD *meth;
79 { 78 {
80 default_RSA_meth=meth; 79 default_RSA_meth=meth;
81 } 80 }
82 81
83RSA *RSA_new_method(meth) 82RSA_METHOD *RSA_get_default_method(void)
84RSA_METHOD *meth; 83{
84 return default_RSA_meth;
85}
86
87RSA_METHOD *RSA_get_method(RSA *rsa)
88{
89 return rsa->meth;
90}
91
92RSA_METHOD *RSA_set_method(RSA *rsa, RSA_METHOD *meth)
93{
94 RSA_METHOD *mtmp;
95 mtmp = rsa->meth;
96 if (mtmp->finish) mtmp->finish(rsa);
97 rsa->meth = meth;
98 if (meth->init) meth->init(rsa);
99 return mtmp;
100}
101
102RSA *RSA_new_method(RSA_METHOD *meth)
85 { 103 {
86 RSA *ret; 104 RSA *ret;
87 105
@@ -116,22 +134,23 @@ RSA_METHOD *meth;
116 ret->dmq1=NULL; 134 ret->dmq1=NULL;
117 ret->iqmp=NULL; 135 ret->iqmp=NULL;
118 ret->references=1; 136 ret->references=1;
119 ret->method_mod_n=NULL; 137 ret->_method_mod_n=NULL;
120 ret->method_mod_p=NULL; 138 ret->_method_mod_p=NULL;
121 ret->method_mod_q=NULL; 139 ret->_method_mod_q=NULL;
122 ret->blinding=NULL; 140 ret->blinding=NULL;
141 ret->bignum_data=NULL;
123 ret->flags=ret->meth->flags; 142 ret->flags=ret->meth->flags;
124 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 143 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
125 { 144 {
126 Free(ret); 145 Free(ret);
127 ret=NULL; 146 ret=NULL;
128 } 147 }
129 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data); 148 else
149 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data);
130 return(ret); 150 return(ret);
131 } 151 }
132 152
133void RSA_free(r) 153void RSA_free(RSA *r)
134RSA *r;
135 { 154 {
136 int i; 155 int i;
137 156
@@ -164,90 +183,63 @@ RSA *r;
164 if (r->dmq1 != NULL) BN_clear_free(r->dmq1); 183 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
165 if (r->iqmp != NULL) BN_clear_free(r->iqmp); 184 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
166 if (r->blinding != NULL) BN_BLINDING_free(r->blinding); 185 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
186 if (r->bignum_data != NULL) Free_locked(r->bignum_data);
167 Free(r); 187 Free(r);
168 } 188 }
169 189
170int RSA_get_ex_new_index(argl,argp,new_func,dup_func,free_func) 190int RSA_get_ex_new_index(long argl, char *argp, int (*new_func)(),
171long argl; 191 int (*dup_func)(), void (*free_func)())
172char *argp;
173int (*new_func)();
174int (*dup_func)();
175void (*free_func)();
176 { 192 {
177 rsa_meth_num++; 193 rsa_meth_num++;
178 return(CRYPTO_get_ex_new_index(rsa_meth_num-1, 194 return(CRYPTO_get_ex_new_index(rsa_meth_num-1,
179 &rsa_meth,argl,argp,new_func,dup_func,free_func)); 195 &rsa_meth,argl,argp,new_func,dup_func,free_func));
180 } 196 }
181 197
182int RSA_set_ex_data(r,idx,arg) 198int RSA_set_ex_data(RSA *r, int idx, char *arg)
183RSA *r;
184int idx;
185char *arg;
186 { 199 {
187 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); 200 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
188 } 201 }
189 202
190char *RSA_get_ex_data(r,idx) 203char *RSA_get_ex_data(RSA *r, int idx)
191RSA *r;
192int idx;
193 { 204 {
194 return(CRYPTO_get_ex_data(&r->ex_data,idx)); 205 return(CRYPTO_get_ex_data(&r->ex_data,idx));
195 } 206 }
196 207
197int RSA_size(r) 208int RSA_size(RSA *r)
198RSA *r;
199 { 209 {
200 return(BN_num_bytes(r->n)); 210 return(BN_num_bytes(r->n));
201 } 211 }
202 212
203int RSA_public_encrypt(flen, from, to, rsa, padding) 213int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to,
204int flen; 214 RSA *rsa, int padding)
205unsigned char *from;
206unsigned char *to;
207RSA *rsa;
208int padding;
209 { 215 {
210 return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding)); 216 return(rsa->meth->rsa_pub_enc(flen, from, to, rsa, padding));
211 } 217 }
212 218
213int RSA_private_encrypt(flen, from, to, rsa, padding) 219int RSA_private_encrypt(int flen, unsigned char *from, unsigned char *to,
214int flen; 220 RSA *rsa, int padding)
215unsigned char *from;
216unsigned char *to;
217RSA *rsa;
218int padding;
219 { 221 {
220 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding)); 222 return(rsa->meth->rsa_priv_enc(flen, from, to, rsa, padding));
221 } 223 }
222 224
223int RSA_private_decrypt(flen, from, to, rsa, padding) 225int RSA_private_decrypt(int flen, unsigned char *from, unsigned char *to,
224int flen; 226 RSA *rsa, int padding)
225unsigned char *from;
226unsigned char *to;
227RSA *rsa;
228int padding;
229 { 227 {
230 return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding)); 228 return(rsa->meth->rsa_priv_dec(flen, from, to, rsa, padding));
231 } 229 }
232 230
233int RSA_public_decrypt(flen, from, to, rsa, padding) 231int RSA_public_decrypt(int flen, unsigned char *from, unsigned char *to,
234int flen; 232 RSA *rsa, int padding)
235unsigned char *from;
236unsigned char *to;
237RSA *rsa;
238int padding;
239 { 233 {
240 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding)); 234 return(rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));
241 } 235 }
242 236
243int RSA_flags(r) 237int RSA_flags(RSA *r)
244RSA *r;
245 { 238 {
246 return((r == NULL)?0:r->meth->flags); 239 return((r == NULL)?0:r->meth->flags);
247 } 240 }
248 241
249void RSA_blinding_off(rsa) 242void RSA_blinding_off(RSA *rsa)
250RSA *rsa;
251 { 243 {
252 if (rsa->blinding != NULL) 244 if (rsa->blinding != NULL)
253 { 245 {
@@ -257,9 +249,7 @@ RSA *rsa;
257 rsa->flags&= ~RSA_FLAG_BLINDING; 249 rsa->flags&= ~RSA_FLAG_BLINDING;
258 } 250 }
259 251
260int RSA_blinding_on(rsa,p_ctx) 252int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
261RSA *rsa;
262BN_CTX *p_ctx;
263 { 253 {
264 BIGNUM *A,*Ai; 254 BIGNUM *A,*Ai;
265 BN_CTX *ctx; 255 BN_CTX *ctx;
@@ -275,13 +265,13 @@ BN_CTX *p_ctx;
275 if (rsa->blinding != NULL) 265 if (rsa->blinding != NULL)
276 BN_BLINDING_free(rsa->blinding); 266 BN_BLINDING_free(rsa->blinding);
277 267
278 A=ctx->bn[0]; 268 A= &(ctx->bn[0]);
279 ctx->tos++; 269 ctx->tos++;
280 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err; 270 if (!BN_rand(A,BN_num_bits(rsa->n)-1,1,0)) goto err;
281 if ((Ai=BN_mod_inverse(A,rsa->n,ctx)) == NULL) goto err; 271 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
282 272
283 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx, 273 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
284 (char *)rsa->method_mod_n)) goto err; 274 goto err;
285 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); 275 rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n);
286 ctx->tos--; 276 ctx->tos--;
287 rsa->flags|=RSA_FLAG_BLINDING; 277 rsa->flags|=RSA_FLAG_BLINDING;
@@ -292,3 +282,48 @@ err:
292 return(ret); 282 return(ret);
293 } 283 }
294 284
285int RSA_memory_lock(RSA *r)
286 {
287 int i,j,k,off;
288 char *p;
289 BIGNUM *bn,**t[6],*b;
290 BN_ULONG *ul;
291
292 if (r->d == NULL) return(1);
293 t[0]= &r->d;
294 t[1]= &r->p;
295 t[2]= &r->q;
296 t[3]= &r->dmp1;
297 t[4]= &r->dmq1;
298 t[5]= &r->iqmp;
299 k=sizeof(BIGNUM)*6;
300 off=k/sizeof(BN_ULONG)+1;
301 j=1;
302 for (i=0; i<6; i++)
303 j+= (*t[i])->top;
304 if ((p=Malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
305 {
306 RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
307 return(0);
308 }
309 bn=(BIGNUM *)p;
310 ul=(BN_ULONG *)&(p[off]);
311 for (i=0; i<6; i++)
312 {
313 b= *(t[i]);
314 *(t[i])= &(bn[i]);
315 memcpy((char *)&(bn[i]),(char *)b,sizeof(BIGNUM));
316 bn[i].flags=BN_FLG_STATIC_DATA;
317 bn[i].d=ul;
318 memcpy((char *)ul,b->d,sizeof(BN_ULONG)*b->top);
319 ul+=b->top;
320 BN_clear_free(b);
321 }
322
323 /* I should fix this so it can still be done */
324 r->flags&= ~(RSA_FLAG_CACHE_PRIVATE|RSA_FLAG_CACHE_PUBLIC);
325
326 r->bignum_data=p;
327 return(1);
328 }
329
diff --git a/src/lib/libcrypto/rsa/rsa_none.c b/src/lib/libcrypto/rsa/rsa_none.c
index f0dd943657..f22fce5016 100644
--- a/src/lib/libcrypto/rsa/rsa_none.c
+++ b/src/lib/libcrypto/rsa/rsa_none.c
@@ -58,52 +58,41 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "rsa.h" 62#include <openssl/rsa.h>
63#include "rand.h" 63#include <openssl/rand.h>
64 64
65int RSA_padding_add_none(to,tlen,from,flen) 65int RSA_padding_add_none(unsigned char *to, int tlen, unsigned char *from,
66unsigned char *to; 66 int flen)
67int tlen;
68unsigned char *from;
69int flen;
70 { 67 {
71 if (flen >= tlen) 68 if (flen > tlen)
72 { 69 {
73 RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); 70 RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
74 return(0); 71 return(0);
75 } 72 }
73
74 if (flen < tlen)
75 {
76 RSAerr(RSA_F_RSA_PADDING_ADD_NONE,RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
77 return(0);
78 }
76 79
77 *(to++)=0;
78 memcpy(to,from,(unsigned int)flen); 80 memcpy(to,from,(unsigned int)flen);
79 return(1); 81 return(1);
80 } 82 }
81 83
82int RSA_padding_check_none(to,tlen,from,flen) 84int RSA_padding_check_none(unsigned char *to, int tlen, unsigned char *from,
83unsigned char *to; 85 int flen, int num)
84int tlen;
85unsigned char *from;
86int flen;
87 { 86 {
88 int j;
89 87
90 from++; 88 if (flen > tlen)
91 if (flen+1 > tlen)
92 { 89 {
93 RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE); 90 RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_DATA_TOO_LARGE);
94 return(-1); 91 return(-1);
95 } 92 }
96 if (*(from++) != 0)
97 {
98 RSAerr(RSA_F_RSA_PADDING_CHECK_NONE,RSA_R_BAD_ZERO_BYTE);
99 return(-1);
100 }
101 93
102 /* scan over padding data */ 94 memset(to,0,tlen-flen);
103 j=flen-1; /* one for type and one for the prepended 0. */ 95 memcpy(to+tlen-flen,from,flen);
104 memset(to,0,tlen-j); 96 return(tlen);
105 to+=(tlen-j);
106 memcpy(to,from,j);
107 return(j);
108 } 97 }
109 98
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 @@
1/* crypto/rsa/rsa_oaep.c */
2/* Written by Ulf Moeller. This software is distributed on an "AS IS"
3 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. */
4
5/* EME_OAEP as defined in RFC 2437 (PKCS #1 v2.0) */
6
7#if !defined(NO_SHA) && !defined(NO_SHA1)
8#include <stdio.h>
9#include "cryptlib.h"
10#include <openssl/bn.h>
11#include <openssl/rsa.h>
12#include <openssl/sha.h>
13#include <openssl/rand.h>
14
15int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen);
16
17int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
18 unsigned char *from, int flen, unsigned char *param, int plen)
19 {
20 int i, emlen = tlen - 1;
21 unsigned char *db, *seed;
22 unsigned char *dbmask, seedmask[SHA_DIGEST_LENGTH];
23
24 if (flen > emlen - 2 * SHA_DIGEST_LENGTH - 1)
25 {
26 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP,
27 RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
28 return (0);
29 }
30
31 if (emlen < 2 * SHA_DIGEST_LENGTH + 1)
32 {
33 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_KEY_SIZE_TOO_SMALL);
34 return (0);
35 }
36
37 dbmask = Malloc(emlen - SHA_DIGEST_LENGTH);
38 if (dbmask == NULL)
39 {
40 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
41 return (0);
42 }
43
44 to[0] = 0;
45 seed = to + 1;
46 db = to + SHA_DIGEST_LENGTH + 1;
47
48 SHA1(param, plen, db);
49 memset(db + SHA_DIGEST_LENGTH, 0,
50 emlen - flen - 2 * SHA_DIGEST_LENGTH - 1);
51 db[emlen - flen - SHA_DIGEST_LENGTH - 1] = 0x01;
52 memcpy(db + emlen - flen - SHA_DIGEST_LENGTH, from, (unsigned int) flen);
53 RAND_bytes(seed, SHA_DIGEST_LENGTH);
54#ifdef PKCS_TESTVECT
55 memcpy(seed,
56 "\xaa\xfd\x12\xf6\x59\xca\xe6\x34\x89\xb4\x79\xe5\x07\x6d\xde\xc2\xf0\x6c\xb5\x8f",
57 20);
58#endif
59
60 MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH);
61 for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)
62 db[i] ^= dbmask[i];
63
64 MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH);
65 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
66 seed[i] ^= seedmask[i];
67
68 Free(dbmask);
69 return (1);
70 }
71
72int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
73 unsigned char *from, int flen, int num, unsigned char *param,
74 int plen)
75 {
76 int i, dblen, mlen = -1;
77 unsigned char *maskeddb;
78 int lzero;
79 unsigned char *db, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH];
80
81 if (--num < 2 * SHA_DIGEST_LENGTH + 1)
82 {
83 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
84 return (-1);
85 }
86
87 dblen = num - SHA_DIGEST_LENGTH;
88 db = Malloc(dblen);
89 if (db == NULL)
90 {
91 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
92 return (-1);
93 }
94
95 lzero = num - flen;
96 maskeddb = from - lzero + SHA_DIGEST_LENGTH;
97
98 MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen);
99 for (i = lzero; i < SHA_DIGEST_LENGTH; i++)
100 seed[i] ^= from[i - lzero];
101
102 MGF1(db, dblen, seed, SHA_DIGEST_LENGTH);
103 for (i = 0; i < dblen; i++)
104 db[i] ^= maskeddb[i];
105
106 SHA1(param, plen, phash);
107
108 if (memcmp(db, phash, SHA_DIGEST_LENGTH) != 0)
109 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
110 else
111 {
112 for (i = SHA_DIGEST_LENGTH; i < dblen; i++)
113 if (db[i] != 0x00)
114 break;
115 if (db[i] != 0x01 || i++ >= dblen)
116 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP,
117 RSA_R_OAEP_DECODING_ERROR);
118 else
119 {
120 mlen = dblen - i;
121 if (tlen < mlen)
122 {
123 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE);
124 mlen = -1;
125 }
126 else
127 memcpy(to, db + i, mlen);
128 }
129 }
130 Free(db);
131 return (mlen);
132 }
133
134int MGF1(unsigned char *mask, long len, unsigned char *seed, long seedlen)
135 {
136 long i, outlen = 0;
137 unsigned char cnt[4];
138 SHA_CTX c;
139 unsigned char md[SHA_DIGEST_LENGTH];
140
141 for (i = 0; outlen < len; i++)
142 {
143 cnt[0] = (i >> 24) & 255, cnt[1] = (i >> 16) & 255,
144 cnt[2] = (i >> 8) & 255, cnt[3] = i & 255;
145 SHA1_Init(&c);
146 SHA1_Update(&c, seed, seedlen);
147 SHA1_Update(&c, cnt, 4);
148 if (outlen + SHA_DIGEST_LENGTH <= len)
149 {
150 SHA1_Final(mask + outlen, &c);
151 outlen += SHA_DIGEST_LENGTH;
152 }
153 else
154 {
155 SHA1_Final(md, &c);
156 memcpy(mask + outlen, md, len - outlen);
157 outlen = len;
158 }
159 }
160 return (0);
161 }
162#endif
diff --git a/src/lib/libcrypto/rsa/rsa_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 @@
1/* test vectors from p1ovect1.txt */
2
3#include <stdio.h>
4#include <string.h>
5
6#include "openssl/e_os.h"
7
8#include <openssl/crypto.h>
9#include <openssl/err.h>
10#ifdef NO_RSA
11int main(int argc, char *argv[])
12{
13 printf("No RSA support\n");
14 return(0);
15}
16#else
17#include <openssl/rsa.h>
18
19#define SetKey \
20 key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
21 key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
22 key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
23 key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
24 key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
25 key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
26 key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
27 key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
28 memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
29 return (sizeof(ctext_ex) - 1);
30
31static int key1(RSA *key, unsigned char *c)
32 {
33 static unsigned char n[] =
34"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
35"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
36"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
37"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
38"\xF5";
39
40 static unsigned char e[] = "\x11";
41
42 static unsigned char d[] =
43"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
44"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
45"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
46"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
47
48 static unsigned char p[] =
49"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
50"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
51"\x0D";
52
53 static unsigned char q[] =
54"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
55"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
56"\x89";
57
58 static unsigned char dmp1[] =
59"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
60"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
61
62 static unsigned char dmq1[] =
63"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
64"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
65"\x51";
66
67 static unsigned char iqmp[] =
68"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
69"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
70
71 static unsigned char ctext_ex[] =
72"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
73"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
74"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
75"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
76
77 SetKey;
78 }
79
80static int key2(RSA *key, unsigned char *c)
81 {
82 static unsigned char n[] =
83"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
84"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
85"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
86"\x34\x77\xCF";
87
88 static unsigned char e[] = "\x3";
89
90 static unsigned char d[] =
91"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
92"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
93"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
94"\xE5\xEB";
95
96 static unsigned char p[] =
97"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
98"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
99
100 static unsigned char q[] =
101"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
102"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
103
104 static unsigned char dmp1[] =
105"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
106"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
107
108 static unsigned char dmq1[] =
109"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
110"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
111
112 static unsigned char iqmp[] =
113"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
114"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
115
116 static unsigned char ctext_ex[] =
117"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
118"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
119"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
120"\x62\x51";
121
122 SetKey;
123 }
124
125static int key3(RSA *key, unsigned char *c)
126 {
127 static unsigned char n[] =
128"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
129"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
130"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
131"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
132"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
133"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
134"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
135"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
136"\xCB";
137
138 static unsigned char e[] = "\x11";
139
140 static unsigned char d[] =
141"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
142"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
143"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
144"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
145"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
146"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
147"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
148"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
149"\xC1";
150
151 static unsigned char p[] =
152"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
153"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
154"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
155"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
156"\x99";
157
158 static unsigned char q[] =
159"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
160"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
161"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
162"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
163"\x03";
164
165 static unsigned char dmp1[] =
166"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
167"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
168"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
169"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
170
171 static unsigned char dmq1[] =
172"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
173"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
174"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
175"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
176
177 static unsigned char iqmp[] =
178"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
179"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
180"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
181"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
182"\xF7";
183
184 static unsigned char ctext_ex[] =
185"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
186"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
187"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
188"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
189"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
190"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
191"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
192"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
193
194 SetKey;
195 }
196
197static int pad_unknown(void)
198{
199 unsigned long l;
200 while ((l = ERR_get_error()) != 0)
201 if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
202 return(1);
203 return(0);
204}
205
206int main()
207 {
208 int err=0;
209 int v;
210 RSA *key;
211 unsigned char ptext[256];
212 unsigned char ctext[256];
213 static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
214 unsigned char ctext_ex[256];
215 int plen;
216 int clen = 0;
217 int num;
218
219 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
220
221 plen = sizeof(ptext_ex) - 1;
222
223 for (v = 0; v < 3; v++)
224 {
225 key = RSA_new();
226 switch (v) {
227 case 0:
228 clen = key1(key, ctext_ex);
229 break;
230 case 1:
231 clen = key2(key, ctext_ex);
232 break;
233 case 2:
234 clen = key3(key, ctext_ex);
235 break;
236 }
237
238 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
239 RSA_PKCS1_PADDING);
240 if (num != clen)
241 {
242 printf("PKCS#1 v1.5 encryption failed!\n");
243 err=1;
244 goto oaep;
245 }
246
247 num = RSA_private_decrypt(num, ctext, ptext, key,
248 RSA_PKCS1_PADDING);
249 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
250 {
251 printf("PKCS#1 v1.5 decryption failed!\n");
252 err=1;
253 }
254 else
255 printf("PKCS #1 v1.5 encryption/decryption ok\n");
256
257 oaep:
258 ERR_clear_error();
259 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
260 RSA_PKCS1_OAEP_PADDING);
261 if (num == -1 && pad_unknown())
262 {
263 printf("No OAEP support\n");
264 goto next;
265 }
266 if (num != clen)
267 {
268 printf("OAEP encryption failed!\n");
269 err=1;
270 goto next;
271 }
272
273 num = RSA_private_decrypt(num, ctext, ptext, key,
274 RSA_PKCS1_OAEP_PADDING);
275 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
276 {
277 printf("OAEP decryption (encrypted data) failed!\n");
278 err=1;
279 }
280 else if (memcmp(ctext, ctext_ex, num) == 0)
281 {
282 printf("OAEP test vector %d passed!\n", v);
283 goto next;
284 }
285
286 /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT).
287 Try decrypting ctext_ex */
288
289 num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
290 RSA_PKCS1_OAEP_PADDING);
291
292 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
293 {
294 printf("OAEP decryption (test vector data) failed!\n");
295 err=1;
296 }
297 else
298 printf("OAEP encryption/decryption ok\n");
299 next:
300 RSA_free(key);
301 }
302
303 ERR_remove_state(0);
304
305 CRYPTO_mem_leaks_fp(stdout);
306
307 return err;
308 }
309#endif
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c
index 2791291b94..f0ae51f234 100644
--- a/src/lib/libcrypto/rsa/rsa_pk1.c
+++ b/src/lib/libcrypto/rsa/rsa_pk1.c
@@ -58,27 +58,12 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "rsa.h" 62#include <openssl/rsa.h>
63#include "rand.h" 63#include <openssl/rand.h>
64
65#ifndef NOPROTO
66int RSA_padding_add_PKCS1_type_1();
67int RSA_padding_check_PKCS1_type_1();
68int RSA_padding_add_PKCS1_type_2();
69int RSA_padding_check_PKCS1_type_2();
70int RSA_padding_add_SSLv23();
71int RSA_padding_check_SSLv23();
72int RSA_padding_add_none();
73int RSA_padding_check_none();
74 64
75#endif 65int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
76 66 unsigned char *from, int flen)
77int RSA_padding_add_PKCS1_type_1(to,tlen,from,flen)
78unsigned char *to;
79int tlen;
80unsigned char *from;
81int flen;
82 { 67 {
83 int j; 68 int j;
84 unsigned char *p; 69 unsigned char *p;
@@ -103,17 +88,14 @@ int flen;
103 return(1); 88 return(1);
104 } 89 }
105 90
106int RSA_padding_check_PKCS1_type_1(to,tlen,from,flen) 91int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
107unsigned char *to; 92 unsigned char *from, int flen, int num)
108int tlen;
109unsigned char *from;
110int flen;
111 { 93 {
112 int i,j; 94 int i,j;
113 unsigned char *p; 95 unsigned char *p;
114 96
115 p=from; 97 p=from;
116 if (*(p++) != 01) 98 if ((num != (flen+1)) || (*(p++) != 01))
117 { 99 {
118 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01); 100 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,RSA_R_BLOCK_TYPE_IS_NOT_01);
119 return(-1); 101 return(-1);
@@ -153,11 +135,8 @@ int flen;
153 return(j); 135 return(j);
154 } 136 }
155 137
156int RSA_padding_add_PKCS1_type_2(to,tlen,from,flen) 138int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
157unsigned char *to; 139 unsigned char *from, int flen)
158int tlen;
159unsigned char *from;
160int flen;
161 { 140 {
162 int i,j; 141 int i,j;
163 unsigned char *p; 142 unsigned char *p;
@@ -192,21 +171,21 @@ int flen;
192 return(1); 171 return(1);
193 } 172 }
194 173
195int RSA_padding_check_PKCS1_type_2(to,tlen,from,flen) 174int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
196unsigned char *to; 175 unsigned char *from, int flen, int num)
197int tlen;
198unsigned char *from;
199int flen;
200 { 176 {
201 int i,j; 177 int i,j;
202 unsigned char *p; 178 unsigned char *p;
203 179
204 p=from; 180 p=from;
205 if (*(p++) != 02) 181 if ((num != (flen+1)) || (*(p++) != 02))
206 { 182 {
207 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02); 183 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,RSA_R_BLOCK_TYPE_IS_NOT_02);
208 return(-1); 184 return(-1);
209 } 185 }
186#ifdef PKCS1_CHECK
187 return(num-11);
188#endif
210 189
211 /* scan over padding data */ 190 /* scan over padding data */
212 j=flen-1; /* one for type. */ 191 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "rsa.h" 62#include <openssl/rsa.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66int RSA_sign_ASN1_OCTET_STRING(type,m,m_len,sigret,siglen,rsa) 66int RSA_sign_ASN1_OCTET_STRING(int type, unsigned char *m, unsigned int m_len,
67int type; 67 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
68unsigned char *m;
69unsigned int m_len;
70unsigned char *sigret;
71unsigned int *siglen;
72RSA *rsa;
73 { 68 {
74 ASN1_OCTET_STRING sig; 69 ASN1_OCTET_STRING sig;
75 int i,j,ret=1; 70 int i,j,ret=1;
@@ -105,13 +100,9 @@ RSA *rsa;
105 return(ret); 100 return(ret);
106 } 101 }
107 102
108int RSA_verify_ASN1_OCTET_STRING(dtype, m, m_len, sigbuf, siglen, rsa) 103int RSA_verify_ASN1_OCTET_STRING(int dtype, unsigned char *m,
109int dtype; 104 unsigned int m_len, unsigned char *sigbuf, unsigned int siglen,
110unsigned char *m; 105 RSA *rsa)
111unsigned int m_len;
112unsigned char *sigbuf;
113unsigned int siglen;
114RSA *rsa;
115 { 106 {
116 int i,ret=0; 107 int i,ret=0;
117 unsigned char *p,*s; 108 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "rsa.h" 62#include <openssl/rsa.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66int RSA_sign(type,m,m_len,sigret,siglen,rsa) 66int RSA_sign(int type, unsigned char *m, unsigned int m_len,
67int type; 67 unsigned char *sigret, unsigned int *siglen, RSA *rsa)
68unsigned char *m;
69unsigned int m_len;
70unsigned char *sigret;
71unsigned int *siglen;
72RSA *rsa;
73 { 68 {
74 X509_SIG sig; 69 X509_SIG sig;
75 ASN1_TYPE parameter; 70 ASN1_TYPE parameter;
@@ -124,13 +119,8 @@ RSA *rsa;
124 return(ret); 119 return(ret);
125 } 120 }
126 121
127int RSA_verify(dtype, m, m_len, sigbuf, siglen, rsa) 122int RSA_verify(int dtype, unsigned char *m, unsigned int m_len,
128int dtype; 123 unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
129unsigned char *m;
130unsigned int m_len;
131unsigned char *sigbuf;
132unsigned int siglen;
133RSA *rsa;
134 { 124 {
135 int i,ret=0,sigtype; 125 int i,ret=0,sigtype;
136 unsigned char *p,*s; 126 unsigned char *p,*s;
@@ -154,9 +144,11 @@ RSA *rsa;
154 144
155 p=s; 145 p=s;
156 sig=d2i_X509_SIG(NULL,&p,(long)i); 146 sig=d2i_X509_SIG(NULL,&p,(long)i);
147
157 if (sig == NULL) goto err; 148 if (sig == NULL) goto err;
158 sigtype=OBJ_obj2nid(sig->algor->algorithm); 149 sigtype=OBJ_obj2nid(sig->algor->algorithm);
159 150
151
160#ifdef RSA_DEBUG 152#ifdef RSA_DEBUG
161 /* put a backward compatability flag in EAY */ 153 /* put a backward compatability flag in EAY */
162 fprintf(stderr,"in(%s) expect(%s)\n",OBJ_nid2ln(sigtype), 154 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "rsa.h" 62#include <openssl/rsa.h>
63#include "rand.h" 63#include <openssl/rand.h>
64 64
65int RSA_padding_add_SSLv23(to,tlen,from,flen) 65int RSA_padding_add_SSLv23(unsigned char *to, int tlen, unsigned char *from,
66unsigned char *to; 66 int flen)
67int tlen;
68unsigned char *from;
69int flen;
70 { 67 {
71 int i,j; 68 int i,j;
72 unsigned char *p; 69 unsigned char *p;
@@ -103,11 +100,8 @@ int flen;
103 return(1); 100 return(1);
104 } 101 }
105 102
106int RSA_padding_check_SSLv23(to,tlen,from,flen) 103int RSA_padding_check_SSLv23(unsigned char *to, int tlen, unsigned char *from,
107unsigned char *to; 104 int flen, int num)
108int tlen;
109unsigned char *from;
110int flen;
111 { 105 {
112 int i,j,k; 106 int i,j,k;
113 unsigned char *p; 107 unsigned char *p;
@@ -118,7 +112,7 @@ int flen;
118 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL); 112 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_DATA_TOO_SMALL);
119 return(-1); 113 return(-1);
120 } 114 }
121 if (*(p++) != 02) 115 if ((num != (flen+1)) || (*(p++) != 02))
122 { 116 {
123 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02); 117 RSAerr(RSA_F_RSA_PADDING_CHECK_SSLV23,RSA_R_BLOCK_TYPE_IS_NOT_02);
124 return(-1); 118 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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -39,7 +41,7 @@ all: lib
39 41
40lib: $(LIBOBJ) 42lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ) 43 $(AR) $(LIB) $(LIBOBJ)
42 sh $(TOP)/util/ranlib.sh $(LIB) 44 $(RANLIB) $(LIB)
43 @touch lib 45 @touch lib
44 46
45# elf 47# elf
@@ -58,26 +60,25 @@ asm/sx86-out.o: asm/sx86unix.cpp
58 60
59# bsdi 61# bsdi
60asm/sx86bsdi.o: asm/sx86unix.cpp 62asm/sx86bsdi.o: asm/sx86unix.cpp
61 $(CPP) -DBSDI asm/sx86unix.cpp | as -o asm/sx86bsdi.o 63 $(CPP) -DBSDI asm/sx86unix.cpp | sed 's/ :/:/' | as -o asm/sx86bsdi.o
62 64
63asm/sx86unix.cpp: 65asm/sx86unix.cpp:
64 (cd asm; perl sha1-586.pl cpp >sx86unix.cpp) 66 (cd asm; $(PERL) sha1-586.pl cpp $(PROCESSOR) >sx86unix.cpp)
65 67
66files: 68files:
67 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 69 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
68 70
69links: 71links:
70 /bin/rm -f Makefile 72 @$(TOP)/util/point.sh Makefile.ssl Makefile
71 $(TOP)/util/point.sh Makefile.ssl Makefile ; 73 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
72 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 74 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
73 $(TOP)/util/mklink.sh ../../test $(TEST) 75 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
74 $(TOP)/util/mklink.sh ../../apps $(APPS)
75 76
76install: 77install:
77 @for i in $(EXHEADER) ; \ 78 @for i in $(EXHEADER) ; \
78 do \ 79 do \
79 (cp $$i $(INSTALLTOP)/include/$$i; \ 80 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
80 chmod 644 $(INSTALLTOP)/include/$$i ); \ 81 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
81 done; 82 done;
82 83
83tags: 84tags:
@@ -89,15 +90,22 @@ lint:
89 lint -DLINT $(INCLUDES) $(SRC)>fluff 90 lint -DLINT $(INCLUDES) $(SRC)>fluff
90 91
91depend: 92depend:
92 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 93 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
93 94
94dclean: 95dclean:
95 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 96 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
96 mv -f Makefile.new $(MAKEFILE) 97 mv -f Makefile.new $(MAKEFILE)
97 98
98clean: 99clean:
99 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o 100 rm -f asm/sx86unix.cpp *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o
100
101errors:
102 101
103# DO NOT DELETE THIS LINE -- make depend depends on it. 102# DO NOT DELETE THIS LINE -- make depend depends on it.
103
104sha1_one.o: ../../include/openssl/sha.h
105sha1dgst.o: ../../include/openssl/opensslconf.h
106sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
107sha1dgst.o: sha_locl.h
108sha_dgst.o: ../../include/openssl/opensslconf.h
109sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
110sha_dgst.o: sha_locl.h
111sha_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)
49 49
50$(LIB): $(LIBOBJ) 50$(LIB): $(LIBOBJ)
51 $(AR) $(LIB) $(LIBOBJ) 51 $(AR) $(LIB) $(LIBOBJ)
52 sh $(TOP)/ranlib.sh $(LIB) 52 $(RANLIB) $(LIB)
53 53
54# elf 54# elf
55asm/sx86-elf.o: asm/sx86unix.cpp 55asm/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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3$normal=0; 3$normal=0;
4 4
5push(@INC,"perlasm","../../perlasm"); 5push(@INC,"perlasm","../../perlasm");
6require "x86asm.pl"; 6require "x86asm.pl";
7 7
8&asm_init($ARGV[0],"sha1-586.pl"); 8&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386");
9 9
10$A="eax"; 10$A="eax";
11$B="ebx"; 11$B="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 @@
1/* Run the C pre-processor over this file with one of the following defined
2 * ELF - elf object files,
3 * OUT - a.out object files,
4 * BSDI - BSDI style a.out object files
5 * SOL - Solaris style elf
6 */
7
8#define TYPE(a,b) .type a,b
9#define SIZE(a,b) .size a,b
10
11#if defined(OUT) || defined(BSDI)
12#define sha1_block_x86 _sha1_block_x86
13
14#endif
15
16#ifdef OUT
17#define OK 1
18#define ALIGN 4
19#endif
20
21#ifdef BSDI
22#define OK 1
23#define ALIGN 4
24#undef SIZE
25#undef TYPE
26#define SIZE(a,b)
27#define TYPE(a,b)
28#endif
29
30#if defined(ELF) || defined(SOL)
31#define OK 1
32#define ALIGN 16
33#endif
34
35#ifndef OK
36You need to define one of
37ELF - elf systems - linux-elf, NetBSD and DG-UX
38OUT - a.out systems - linux-a.out and FreeBSD
39SOL - solaris systems, which are elf with strange comment lines
40BSDI - a.out with a very primative version of as.
41#endif
42
43/* Let the Assembler begin :-) */
44 /* Don't even think of reading this code */
45 /* It was automatically generated by sha1-586.pl */
46 /* Which is a perl program used to generate the x86 assember for */
47 /* any of elf, a.out, BSDI,Win32, or Solaris */
48 /* eric <eay@cryptsoft.com> */
49
50 .file "sha1-586.s"
51 .version "01.01"
52gcc2_compiled.:
53.text
54 .align ALIGN
55.globl sha1_block_x86
56 TYPE(sha1_block_x86,@function)
57sha1_block_x86:
58 pushl %esi
59 pushl %ebp
60 movl 20(%esp), %eax
61 movl 16(%esp), %esi
62 addl %esi, %eax
63 movl 12(%esp), %ebp
64 pushl %ebx
65 subl $64, %eax
66 pushl %edi
67 movl 4(%ebp), %ebx
68 subl $72, %esp
69 movl 12(%ebp), %edx
70 movl 16(%ebp), %edi
71 movl 8(%ebp), %ecx
72 movl %eax, 68(%esp)
73 /* First we need to setup the X array */
74 movl (%esi), %eax
75.L000start:
76 /* First, load the words onto the stack in network byte order */
77.byte 15
78.byte 200 /* bswapl %eax */
79 movl %eax, (%esp)
80 movl 4(%esi), %eax
81.byte 15
82.byte 200 /* bswapl %eax */
83 movl %eax, 4(%esp)
84 movl 8(%esi), %eax
85.byte 15
86.byte 200 /* bswapl %eax */
87 movl %eax, 8(%esp)
88 movl 12(%esi), %eax
89.byte 15
90.byte 200 /* bswapl %eax */
91 movl %eax, 12(%esp)
92 movl 16(%esi), %eax
93.byte 15
94.byte 200 /* bswapl %eax */
95 movl %eax, 16(%esp)
96 movl 20(%esi), %eax
97.byte 15
98.byte 200 /* bswapl %eax */
99 movl %eax, 20(%esp)
100 movl 24(%esi), %eax
101.byte 15
102.byte 200 /* bswapl %eax */
103 movl %eax, 24(%esp)
104 movl 28(%esi), %eax
105.byte 15
106.byte 200 /* bswapl %eax */
107 movl %eax, 28(%esp)
108 movl 32(%esi), %eax
109.byte 15
110.byte 200 /* bswapl %eax */
111 movl %eax, 32(%esp)
112 movl 36(%esi), %eax
113.byte 15
114.byte 200 /* bswapl %eax */
115 movl %eax, 36(%esp)
116 movl 40(%esi), %eax
117.byte 15
118.byte 200 /* bswapl %eax */
119 movl %eax, 40(%esp)
120 movl 44(%esi), %eax
121.byte 15
122.byte 200 /* bswapl %eax */
123 movl %eax, 44(%esp)
124 movl 48(%esi), %eax
125.byte 15
126.byte 200 /* bswapl %eax */
127 movl %eax, 48(%esp)
128 movl 52(%esi), %eax
129.byte 15
130.byte 200 /* bswapl %eax */
131 movl %eax, 52(%esp)
132 movl 56(%esi), %eax
133.byte 15
134.byte 200 /* bswapl %eax */
135 movl %eax, 56(%esp)
136 movl 60(%esi), %eax
137.byte 15
138.byte 200 /* bswapl %eax */
139 movl %eax, 60(%esp)
140 /* We now have the X array on the stack */
141 /* starting at sp-4 */
142 movl %esi, 64(%esp)
143
144 /* Start processing */
145 movl (%ebp), %eax
146 /* 00_15 0 */
147 movl %ecx, %esi
148 movl %eax, %ebp
149 xorl %edx, %esi
150 roll $5, %ebp
151 andl %ebx, %esi
152 addl %edi, %ebp
153.byte 209
154.byte 203 /* rorl $1 %ebx */
155 movl (%esp), %edi
156.byte 209
157.byte 203 /* rorl $1 %ebx */
158 xorl %edx, %esi
159 leal 1518500249(%ebp,%edi,1),%ebp
160 movl %ebx, %edi
161 addl %ebp, %esi
162 xorl %ecx, %edi
163 movl %esi, %ebp
164 andl %eax, %edi
165 roll $5, %ebp
166 addl %edx, %ebp
167 movl 4(%esp), %edx
168.byte 209
169.byte 200 /* rorl $1 %eax */
170 xorl %ecx, %edi
171.byte 209
172.byte 200 /* rorl $1 %eax */
173 leal 1518500249(%ebp,%edx,1),%ebp
174 addl %ebp, %edi
175 /* 00_15 2 */
176 movl %eax, %edx
177 movl %edi, %ebp
178 xorl %ebx, %edx
179 roll $5, %ebp
180 andl %esi, %edx
181 addl %ecx, %ebp
182.byte 209
183.byte 206 /* rorl $1 %esi */
184 movl 8(%esp), %ecx
185.byte 209
186.byte 206 /* rorl $1 %esi */
187 xorl %ebx, %edx
188 leal 1518500249(%ebp,%ecx,1),%ebp
189 movl %esi, %ecx
190 addl %ebp, %edx
191 xorl %eax, %ecx
192 movl %edx, %ebp
193 andl %edi, %ecx
194 roll $5, %ebp
195 addl %ebx, %ebp
196 movl 12(%esp), %ebx
197.byte 209
198.byte 207 /* rorl $1 %edi */
199 xorl %eax, %ecx
200.byte 209
201.byte 207 /* rorl $1 %edi */
202 leal 1518500249(%ebp,%ebx,1),%ebp
203 addl %ebp, %ecx
204 /* 00_15 4 */
205 movl %edi, %ebx
206 movl %ecx, %ebp
207 xorl %esi, %ebx
208 roll $5, %ebp
209 andl %edx, %ebx
210 addl %eax, %ebp
211.byte 209
212.byte 202 /* rorl $1 %edx */
213 movl 16(%esp), %eax
214.byte 209
215.byte 202 /* rorl $1 %edx */
216 xorl %esi, %ebx
217 leal 1518500249(%ebp,%eax,1),%ebp
218 movl %edx, %eax
219 addl %ebp, %ebx
220 xorl %edi, %eax
221 movl %ebx, %ebp
222 andl %ecx, %eax
223 roll $5, %ebp
224 addl %esi, %ebp
225 movl 20(%esp), %esi
226.byte 209
227.byte 201 /* rorl $1 %ecx */
228 xorl %edi, %eax
229.byte 209
230.byte 201 /* rorl $1 %ecx */
231 leal 1518500249(%ebp,%esi,1),%ebp
232 addl %ebp, %eax
233 /* 00_15 6 */
234 movl %ecx, %esi
235 movl %eax, %ebp
236 xorl %edx, %esi
237 roll $5, %ebp
238 andl %ebx, %esi
239 addl %edi, %ebp
240.byte 209
241.byte 203 /* rorl $1 %ebx */
242 movl 24(%esp), %edi
243.byte 209
244.byte 203 /* rorl $1 %ebx */
245 xorl %edx, %esi
246 leal 1518500249(%ebp,%edi,1),%ebp
247 movl %ebx, %edi
248 addl %ebp, %esi
249 xorl %ecx, %edi
250 movl %esi, %ebp
251 andl %eax, %edi
252 roll $5, %ebp
253 addl %edx, %ebp
254 movl 28(%esp), %edx
255.byte 209
256.byte 200 /* rorl $1 %eax */
257 xorl %ecx, %edi
258.byte 209
259.byte 200 /* rorl $1 %eax */
260 leal 1518500249(%ebp,%edx,1),%ebp
261 addl %ebp, %edi
262 /* 00_15 8 */
263 movl %eax, %edx
264 movl %edi, %ebp
265 xorl %ebx, %edx
266 roll $5, %ebp
267 andl %esi, %edx
268 addl %ecx, %ebp
269.byte 209
270.byte 206 /* rorl $1 %esi */
271 movl 32(%esp), %ecx
272.byte 209
273.byte 206 /* rorl $1 %esi */
274 xorl %ebx, %edx
275 leal 1518500249(%ebp,%ecx,1),%ebp
276 movl %esi, %ecx
277 addl %ebp, %edx
278 xorl %eax, %ecx
279 movl %edx, %ebp
280 andl %edi, %ecx
281 roll $5, %ebp
282 addl %ebx, %ebp
283 movl 36(%esp), %ebx
284.byte 209
285.byte 207 /* rorl $1 %edi */
286 xorl %eax, %ecx
287.byte 209
288.byte 207 /* rorl $1 %edi */
289 leal 1518500249(%ebp,%ebx,1),%ebp
290 addl %ebp, %ecx
291 /* 00_15 10 */
292 movl %edi, %ebx
293 movl %ecx, %ebp
294 xorl %esi, %ebx
295 roll $5, %ebp
296 andl %edx, %ebx
297 addl %eax, %ebp
298.byte 209
299.byte 202 /* rorl $1 %edx */
300 movl 40(%esp), %eax
301.byte 209
302.byte 202 /* rorl $1 %edx */
303 xorl %esi, %ebx
304 leal 1518500249(%ebp,%eax,1),%ebp
305 movl %edx, %eax
306 addl %ebp, %ebx
307 xorl %edi, %eax
308 movl %ebx, %ebp
309 andl %ecx, %eax
310 roll $5, %ebp
311 addl %esi, %ebp
312 movl 44(%esp), %esi
313.byte 209
314.byte 201 /* rorl $1 %ecx */
315 xorl %edi, %eax
316.byte 209
317.byte 201 /* rorl $1 %ecx */
318 leal 1518500249(%ebp,%esi,1),%ebp
319 addl %ebp, %eax
320 /* 00_15 12 */
321 movl %ecx, %esi
322 movl %eax, %ebp
323 xorl %edx, %esi
324 roll $5, %ebp
325 andl %ebx, %esi
326 addl %edi, %ebp
327.byte 209
328.byte 203 /* rorl $1 %ebx */
329 movl 48(%esp), %edi
330.byte 209
331.byte 203 /* rorl $1 %ebx */
332 xorl %edx, %esi
333 leal 1518500249(%ebp,%edi,1),%ebp
334 movl %ebx, %edi
335 addl %ebp, %esi
336 xorl %ecx, %edi
337 movl %esi, %ebp
338 andl %eax, %edi
339 roll $5, %ebp
340 addl %edx, %ebp
341 movl 52(%esp), %edx
342.byte 209
343.byte 200 /* rorl $1 %eax */
344 xorl %ecx, %edi
345.byte 209
346.byte 200 /* rorl $1 %eax */
347 leal 1518500249(%ebp,%edx,1),%ebp
348 addl %ebp, %edi
349 /* 00_15 14 */
350 movl %eax, %edx
351 movl %edi, %ebp
352 xorl %ebx, %edx
353 roll $5, %ebp
354 andl %esi, %edx
355 addl %ecx, %ebp
356.byte 209
357.byte 206 /* rorl $1 %esi */
358 movl 56(%esp), %ecx
359.byte 209
360.byte 206 /* rorl $1 %esi */
361 xorl %ebx, %edx
362 leal 1518500249(%ebp,%ecx,1),%ebp
363 movl %esi, %ecx
364 addl %ebp, %edx
365 xorl %eax, %ecx
366 movl %edx, %ebp
367 andl %edi, %ecx
368 roll $5, %ebp
369 addl %ebx, %ebp
370 movl 60(%esp), %ebx
371.byte 209
372.byte 207 /* rorl $1 %edi */
373 xorl %eax, %ecx
374.byte 209
375.byte 207 /* rorl $1 %edi */
376 leal 1518500249(%ebp,%ebx,1),%ebp
377 addl %ebp, %ecx
378 /* 16_19 16 */
379 nop
380 movl (%esp), %ebp
381 movl 8(%esp), %ebx
382 xorl %ebp, %ebx
383 movl 32(%esp), %ebp
384 xorl %ebp, %ebx
385 movl 52(%esp), %ebp
386 xorl %ebp, %ebx
387 movl %edi, %ebp
388.byte 209
389.byte 195 /* roll $1 %ebx */
390 xorl %esi, %ebp
391 movl %ebx, (%esp)
392 andl %edx, %ebp
393 leal 1518500249(%ebx,%eax,1),%ebx
394 xorl %esi, %ebp
395 movl %ecx, %eax
396 addl %ebp, %ebx
397 roll $5, %eax
398.byte 209
399.byte 202 /* rorl $1 %edx */
400 addl %eax, %ebx
401 movl 4(%esp), %eax
402 movl 12(%esp), %ebp
403 xorl %ebp, %eax
404 movl 36(%esp), %ebp
405 xorl %ebp, %eax
406 movl 56(%esp), %ebp
407.byte 209
408.byte 202 /* rorl $1 %edx */
409 xorl %ebp, %eax
410.byte 209
411.byte 192 /* roll $1 %eax */
412 movl %edx, %ebp
413 xorl %edi, %ebp
414 movl %eax, 4(%esp)
415 andl %ecx, %ebp
416 leal 1518500249(%eax,%esi,1),%eax
417 xorl %edi, %ebp
418 movl %ebx, %esi
419 roll $5, %esi
420.byte 209
421.byte 201 /* rorl $1 %ecx */
422 addl %esi, %eax
423.byte 209
424.byte 201 /* rorl $1 %ecx */
425 addl %ebp, %eax
426 /* 16_19 18 */
427 movl 8(%esp), %ebp
428 movl 16(%esp), %esi
429 xorl %ebp, %esi
430 movl 40(%esp), %ebp
431 xorl %ebp, %esi
432 movl 60(%esp), %ebp
433 xorl %ebp, %esi
434 movl %ecx, %ebp
435.byte 209
436.byte 198 /* roll $1 %esi */
437 xorl %edx, %ebp
438 movl %esi, 8(%esp)
439 andl %ebx, %ebp
440 leal 1518500249(%esi,%edi,1),%esi
441 xorl %edx, %ebp
442 movl %eax, %edi
443 addl %ebp, %esi
444 roll $5, %edi
445.byte 209
446.byte 203 /* rorl $1 %ebx */
447 addl %edi, %esi
448 movl 12(%esp), %edi
449 movl 20(%esp), %ebp
450 xorl %ebp, %edi
451 movl 44(%esp), %ebp
452 xorl %ebp, %edi
453 movl (%esp), %ebp
454.byte 209
455.byte 203 /* rorl $1 %ebx */
456 xorl %ebp, %edi
457.byte 209
458.byte 199 /* roll $1 %edi */
459 movl %ebx, %ebp
460 xorl %ecx, %ebp
461 movl %edi, 12(%esp)
462 andl %eax, %ebp
463 leal 1518500249(%edi,%edx,1),%edi
464 xorl %ecx, %ebp
465 movl %esi, %edx
466 roll $5, %edx
467.byte 209
468.byte 200 /* rorl $1 %eax */
469 addl %edx, %edi
470.byte 209
471.byte 200 /* rorl $1 %eax */
472 addl %ebp, %edi
473 /* 20_39 20 */
474 movl 16(%esp), %edx
475 movl 24(%esp), %ebp
476 xorl %ebp, %edx
477 movl 48(%esp), %ebp
478 xorl %ebp, %edx
479 movl 4(%esp), %ebp
480 xorl %ebp, %edx
481 movl %esi, %ebp
482.byte 209
483.byte 194 /* roll $1 %edx */
484 xorl %eax, %ebp
485 movl %edx, 16(%esp)
486 xorl %ebx, %ebp
487 leal 1859775393(%edx,%ecx,1),%edx
488 movl %edi, %ecx
489 roll $5, %ecx
490.byte 209
491.byte 206 /* rorl $1 %esi */
492 addl %ebp, %ecx
493.byte 209
494.byte 206 /* rorl $1 %esi */
495 addl %ecx, %edx
496 /* 20_39 21 */
497 movl 20(%esp), %ecx
498 movl 28(%esp), %ebp
499 xorl %ebp, %ecx
500 movl 52(%esp), %ebp
501 xorl %ebp, %ecx
502 movl 8(%esp), %ebp
503 xorl %ebp, %ecx
504 movl %edi, %ebp
505.byte 209
506.byte 193 /* roll $1 %ecx */
507 xorl %esi, %ebp
508 movl %ecx, 20(%esp)
509 xorl %eax, %ebp
510 leal 1859775393(%ecx,%ebx,1),%ecx
511 movl %edx, %ebx
512 roll $5, %ebx
513.byte 209
514.byte 207 /* rorl $1 %edi */
515 addl %ebp, %ebx
516.byte 209
517.byte 207 /* rorl $1 %edi */
518 addl %ebx, %ecx
519 /* 20_39 22 */
520 movl 24(%esp), %ebx
521 movl 32(%esp), %ebp
522 xorl %ebp, %ebx
523 movl 56(%esp), %ebp
524 xorl %ebp, %ebx
525 movl 12(%esp), %ebp
526 xorl %ebp, %ebx
527 movl %edx, %ebp
528.byte 209
529.byte 195 /* roll $1 %ebx */
530 xorl %edi, %ebp
531 movl %ebx, 24(%esp)
532 xorl %esi, %ebp
533 leal 1859775393(%ebx,%eax,1),%ebx
534 movl %ecx, %eax
535 roll $5, %eax
536.byte 209
537.byte 202 /* rorl $1 %edx */
538 addl %ebp, %eax
539.byte 209
540.byte 202 /* rorl $1 %edx */
541 addl %eax, %ebx
542 /* 20_39 23 */
543 movl 28(%esp), %eax
544 movl 36(%esp), %ebp
545 xorl %ebp, %eax
546 movl 60(%esp), %ebp
547 xorl %ebp, %eax
548 movl 16(%esp), %ebp
549 xorl %ebp, %eax
550 movl %ecx, %ebp
551.byte 209
552.byte 192 /* roll $1 %eax */
553 xorl %edx, %ebp
554 movl %eax, 28(%esp)
555 xorl %edi, %ebp
556 leal 1859775393(%eax,%esi,1),%eax
557 movl %ebx, %esi
558 roll $5, %esi
559.byte 209
560.byte 201 /* rorl $1 %ecx */
561 addl %ebp, %esi
562.byte 209
563.byte 201 /* rorl $1 %ecx */
564 addl %esi, %eax
565 /* 20_39 24 */
566 movl 32(%esp), %esi
567 movl 40(%esp), %ebp
568 xorl %ebp, %esi
569 movl (%esp), %ebp
570 xorl %ebp, %esi
571 movl 20(%esp), %ebp
572 xorl %ebp, %esi
573 movl %ebx, %ebp
574.byte 209
575.byte 198 /* roll $1 %esi */
576 xorl %ecx, %ebp
577 movl %esi, 32(%esp)
578 xorl %edx, %ebp
579 leal 1859775393(%esi,%edi,1),%esi
580 movl %eax, %edi
581 roll $5, %edi
582.byte 209
583.byte 203 /* rorl $1 %ebx */
584 addl %ebp, %edi
585.byte 209
586.byte 203 /* rorl $1 %ebx */
587 addl %edi, %esi
588 /* 20_39 25 */
589 movl 36(%esp), %edi
590 movl 44(%esp), %ebp
591 xorl %ebp, %edi
592 movl 4(%esp), %ebp
593 xorl %ebp, %edi
594 movl 24(%esp), %ebp
595 xorl %ebp, %edi
596 movl %eax, %ebp
597.byte 209
598.byte 199 /* roll $1 %edi */
599 xorl %ebx, %ebp
600 movl %edi, 36(%esp)
601 xorl %ecx, %ebp
602 leal 1859775393(%edi,%edx,1),%edi
603 movl %esi, %edx
604 roll $5, %edx
605.byte 209
606.byte 200 /* rorl $1 %eax */
607 addl %ebp, %edx
608.byte 209
609.byte 200 /* rorl $1 %eax */
610 addl %edx, %edi
611 /* 20_39 26 */
612 movl 40(%esp), %edx
613 movl 48(%esp), %ebp
614 xorl %ebp, %edx
615 movl 8(%esp), %ebp
616 xorl %ebp, %edx
617 movl 28(%esp), %ebp
618 xorl %ebp, %edx
619 movl %esi, %ebp
620.byte 209
621.byte 194 /* roll $1 %edx */
622 xorl %eax, %ebp
623 movl %edx, 40(%esp)
624 xorl %ebx, %ebp
625 leal 1859775393(%edx,%ecx,1),%edx
626 movl %edi, %ecx
627 roll $5, %ecx
628.byte 209
629.byte 206 /* rorl $1 %esi */
630 addl %ebp, %ecx
631.byte 209
632.byte 206 /* rorl $1 %esi */
633 addl %ecx, %edx
634 /* 20_39 27 */
635 movl 44(%esp), %ecx
636 movl 52(%esp), %ebp
637 xorl %ebp, %ecx
638 movl 12(%esp), %ebp
639 xorl %ebp, %ecx
640 movl 32(%esp), %ebp
641 xorl %ebp, %ecx
642 movl %edi, %ebp
643.byte 209
644.byte 193 /* roll $1 %ecx */
645 xorl %esi, %ebp
646 movl %ecx, 44(%esp)
647 xorl %eax, %ebp
648 leal 1859775393(%ecx,%ebx,1),%ecx
649 movl %edx, %ebx
650 roll $5, %ebx
651.byte 209
652.byte 207 /* rorl $1 %edi */
653 addl %ebp, %ebx
654.byte 209
655.byte 207 /* rorl $1 %edi */
656 addl %ebx, %ecx
657 /* 20_39 28 */
658 movl 48(%esp), %ebx
659 movl 56(%esp), %ebp
660 xorl %ebp, %ebx
661 movl 16(%esp), %ebp
662 xorl %ebp, %ebx
663 movl 36(%esp), %ebp
664 xorl %ebp, %ebx
665 movl %edx, %ebp
666.byte 209
667.byte 195 /* roll $1 %ebx */
668 xorl %edi, %ebp
669 movl %ebx, 48(%esp)
670 xorl %esi, %ebp
671 leal 1859775393(%ebx,%eax,1),%ebx
672 movl %ecx, %eax
673 roll $5, %eax
674.byte 209
675.byte 202 /* rorl $1 %edx */
676 addl %ebp, %eax
677.byte 209
678.byte 202 /* rorl $1 %edx */
679 addl %eax, %ebx
680 /* 20_39 29 */
681 movl 52(%esp), %eax
682 movl 60(%esp), %ebp
683 xorl %ebp, %eax
684 movl 20(%esp), %ebp
685 xorl %ebp, %eax
686 movl 40(%esp), %ebp
687 xorl %ebp, %eax
688 movl %ecx, %ebp
689.byte 209
690.byte 192 /* roll $1 %eax */
691 xorl %edx, %ebp
692 movl %eax, 52(%esp)
693 xorl %edi, %ebp
694 leal 1859775393(%eax,%esi,1),%eax
695 movl %ebx, %esi
696 roll $5, %esi
697.byte 209
698.byte 201 /* rorl $1 %ecx */
699 addl %ebp, %esi
700.byte 209
701.byte 201 /* rorl $1 %ecx */
702 addl %esi, %eax
703 /* 20_39 30 */
704 movl 56(%esp), %esi
705 movl (%esp), %ebp
706 xorl %ebp, %esi
707 movl 24(%esp), %ebp
708 xorl %ebp, %esi
709 movl 44(%esp), %ebp
710 xorl %ebp, %esi
711 movl %ebx, %ebp
712.byte 209
713.byte 198 /* roll $1 %esi */
714 xorl %ecx, %ebp
715 movl %esi, 56(%esp)
716 xorl %edx, %ebp
717 leal 1859775393(%esi,%edi,1),%esi
718 movl %eax, %edi
719 roll $5, %edi
720.byte 209
721.byte 203 /* rorl $1 %ebx */
722 addl %ebp, %edi
723.byte 209
724.byte 203 /* rorl $1 %ebx */
725 addl %edi, %esi
726 /* 20_39 31 */
727 movl 60(%esp), %edi
728 movl 4(%esp), %ebp
729 xorl %ebp, %edi
730 movl 28(%esp), %ebp
731 xorl %ebp, %edi
732 movl 48(%esp), %ebp
733 xorl %ebp, %edi
734 movl %eax, %ebp
735.byte 209
736.byte 199 /* roll $1 %edi */
737 xorl %ebx, %ebp
738 movl %edi, 60(%esp)
739 xorl %ecx, %ebp
740 leal 1859775393(%edi,%edx,1),%edi
741 movl %esi, %edx
742 roll $5, %edx
743.byte 209
744.byte 200 /* rorl $1 %eax */
745 addl %ebp, %edx
746.byte 209
747.byte 200 /* rorl $1 %eax */
748 addl %edx, %edi
749 /* 20_39 32 */
750 movl (%esp), %edx
751 movl 8(%esp), %ebp
752 xorl %ebp, %edx
753 movl 32(%esp), %ebp
754 xorl %ebp, %edx
755 movl 52(%esp), %ebp
756 xorl %ebp, %edx
757 movl %esi, %ebp
758.byte 209
759.byte 194 /* roll $1 %edx */
760 xorl %eax, %ebp
761 movl %edx, (%esp)
762 xorl %ebx, %ebp
763 leal 1859775393(%edx,%ecx,1),%edx
764 movl %edi, %ecx
765 roll $5, %ecx
766.byte 209
767.byte 206 /* rorl $1 %esi */
768 addl %ebp, %ecx
769.byte 209
770.byte 206 /* rorl $1 %esi */
771 addl %ecx, %edx
772 /* 20_39 33 */
773 movl 4(%esp), %ecx
774 movl 12(%esp), %ebp
775 xorl %ebp, %ecx
776 movl 36(%esp), %ebp
777 xorl %ebp, %ecx
778 movl 56(%esp), %ebp
779 xorl %ebp, %ecx
780 movl %edi, %ebp
781.byte 209
782.byte 193 /* roll $1 %ecx */
783 xorl %esi, %ebp
784 movl %ecx, 4(%esp)
785 xorl %eax, %ebp
786 leal 1859775393(%ecx,%ebx,1),%ecx
787 movl %edx, %ebx
788 roll $5, %ebx
789.byte 209
790.byte 207 /* rorl $1 %edi */
791 addl %ebp, %ebx
792.byte 209
793.byte 207 /* rorl $1 %edi */
794 addl %ebx, %ecx
795 /* 20_39 34 */
796 movl 8(%esp), %ebx
797 movl 16(%esp), %ebp
798 xorl %ebp, %ebx
799 movl 40(%esp), %ebp
800 xorl %ebp, %ebx
801 movl 60(%esp), %ebp
802 xorl %ebp, %ebx
803 movl %edx, %ebp
804.byte 209
805.byte 195 /* roll $1 %ebx */
806 xorl %edi, %ebp
807 movl %ebx, 8(%esp)
808 xorl %esi, %ebp
809 leal 1859775393(%ebx,%eax,1),%ebx
810 movl %ecx, %eax
811 roll $5, %eax
812.byte 209
813.byte 202 /* rorl $1 %edx */
814 addl %ebp, %eax
815.byte 209
816.byte 202 /* rorl $1 %edx */
817 addl %eax, %ebx
818 /* 20_39 35 */
819 movl 12(%esp), %eax
820 movl 20(%esp), %ebp
821 xorl %ebp, %eax
822 movl 44(%esp), %ebp
823 xorl %ebp, %eax
824 movl (%esp), %ebp
825 xorl %ebp, %eax
826 movl %ecx, %ebp
827.byte 209
828.byte 192 /* roll $1 %eax */
829 xorl %edx, %ebp
830 movl %eax, 12(%esp)
831 xorl %edi, %ebp
832 leal 1859775393(%eax,%esi,1),%eax
833 movl %ebx, %esi
834 roll $5, %esi
835.byte 209
836.byte 201 /* rorl $1 %ecx */
837 addl %ebp, %esi
838.byte 209
839.byte 201 /* rorl $1 %ecx */
840 addl %esi, %eax
841 /* 20_39 36 */
842 movl 16(%esp), %esi
843 movl 24(%esp), %ebp
844 xorl %ebp, %esi
845 movl 48(%esp), %ebp
846 xorl %ebp, %esi
847 movl 4(%esp), %ebp
848 xorl %ebp, %esi
849 movl %ebx, %ebp
850.byte 209
851.byte 198 /* roll $1 %esi */
852 xorl %ecx, %ebp
853 movl %esi, 16(%esp)
854 xorl %edx, %ebp
855 leal 1859775393(%esi,%edi,1),%esi
856 movl %eax, %edi
857 roll $5, %edi
858.byte 209
859.byte 203 /* rorl $1 %ebx */
860 addl %ebp, %edi
861.byte 209
862.byte 203 /* rorl $1 %ebx */
863 addl %edi, %esi
864 /* 20_39 37 */
865 movl 20(%esp), %edi
866 movl 28(%esp), %ebp
867 xorl %ebp, %edi
868 movl 52(%esp), %ebp
869 xorl %ebp, %edi
870 movl 8(%esp), %ebp
871 xorl %ebp, %edi
872 movl %eax, %ebp
873.byte 209
874.byte 199 /* roll $1 %edi */
875 xorl %ebx, %ebp
876 movl %edi, 20(%esp)
877 xorl %ecx, %ebp
878 leal 1859775393(%edi,%edx,1),%edi
879 movl %esi, %edx
880 roll $5, %edx
881.byte 209
882.byte 200 /* rorl $1 %eax */
883 addl %ebp, %edx
884.byte 209
885.byte 200 /* rorl $1 %eax */
886 addl %edx, %edi
887 /* 20_39 38 */
888 movl 24(%esp), %edx
889 movl 32(%esp), %ebp
890 xorl %ebp, %edx
891 movl 56(%esp), %ebp
892 xorl %ebp, %edx
893 movl 12(%esp), %ebp
894 xorl %ebp, %edx
895 movl %esi, %ebp
896.byte 209
897.byte 194 /* roll $1 %edx */
898 xorl %eax, %ebp
899 movl %edx, 24(%esp)
900 xorl %ebx, %ebp
901 leal 1859775393(%edx,%ecx,1),%edx
902 movl %edi, %ecx
903 roll $5, %ecx
904.byte 209
905.byte 206 /* rorl $1 %esi */
906 addl %ebp, %ecx
907.byte 209
908.byte 206 /* rorl $1 %esi */
909 addl %ecx, %edx
910 /* 20_39 39 */
911 movl 28(%esp), %ecx
912 movl 36(%esp), %ebp
913 xorl %ebp, %ecx
914 movl 60(%esp), %ebp
915 xorl %ebp, %ecx
916 movl 16(%esp), %ebp
917 xorl %ebp, %ecx
918 movl %edi, %ebp
919.byte 209
920.byte 193 /* roll $1 %ecx */
921 xorl %esi, %ebp
922 movl %ecx, 28(%esp)
923 xorl %eax, %ebp
924 leal 1859775393(%ecx,%ebx,1),%ecx
925 movl %edx, %ebx
926 roll $5, %ebx
927.byte 209
928.byte 207 /* rorl $1 %edi */
929 addl %ebp, %ebx
930.byte 209
931.byte 207 /* rorl $1 %edi */
932 addl %ebx, %ecx
933 /* 40_59 40 */
934 movl 32(%esp), %ebx
935 movl 40(%esp), %ebp
936 xorl %ebp, %ebx
937 movl (%esp), %ebp
938 xorl %ebp, %ebx
939 movl 20(%esp), %ebp
940 xorl %ebp, %ebx
941 movl %edx, %ebp
942.byte 209
943.byte 195 /* roll $1 %ebx */
944 orl %edi, %ebp
945 movl %ebx, 32(%esp)
946 andl %esi, %ebp
947 leal 2400959708(%ebx,%eax,1),%ebx
948 movl %edx, %eax
949.byte 209
950.byte 202 /* rorl $1 %edx */
951 andl %edi, %eax
952 orl %eax, %ebp
953 movl %ecx, %eax
954 roll $5, %eax
955 addl %eax, %ebp
956 movl 36(%esp), %eax
957 addl %ebp, %ebx
958 movl 44(%esp), %ebp
959 xorl %ebp, %eax
960 movl 4(%esp), %ebp
961 xorl %ebp, %eax
962 movl 24(%esp), %ebp
963.byte 209
964.byte 202 /* rorl $1 %edx */
965 xorl %ebp, %eax
966.byte 209
967.byte 192 /* roll $1 %eax */
968 movl %ecx, %ebp
969 movl %eax, 36(%esp)
970 orl %edx, %ebp
971 leal 2400959708(%eax,%esi,1),%eax
972 movl %ecx, %esi
973 andl %edi, %ebp
974 andl %edx, %esi
975 orl %esi, %ebp
976 movl %ebx, %esi
977 roll $5, %esi
978.byte 209
979.byte 201 /* rorl $1 %ecx */
980 addl %esi, %ebp
981.byte 209
982.byte 201 /* rorl $1 %ecx */
983 addl %ebp, %eax
984 /* 40_59 41 */
985 /* 40_59 42 */
986 movl 40(%esp), %esi
987 movl 48(%esp), %ebp
988 xorl %ebp, %esi
989 movl 8(%esp), %ebp
990 xorl %ebp, %esi
991 movl 28(%esp), %ebp
992 xorl %ebp, %esi
993 movl %ebx, %ebp
994.byte 209
995.byte 198 /* roll $1 %esi */
996 orl %ecx, %ebp
997 movl %esi, 40(%esp)
998 andl %edx, %ebp
999 leal 2400959708(%esi,%edi,1),%esi
1000 movl %ebx, %edi
1001.byte 209
1002.byte 203 /* rorl $1 %ebx */
1003 andl %ecx, %edi
1004 orl %edi, %ebp
1005 movl %eax, %edi
1006 roll $5, %edi
1007 addl %edi, %ebp
1008 movl 44(%esp), %edi
1009 addl %ebp, %esi
1010 movl 52(%esp), %ebp
1011 xorl %ebp, %edi
1012 movl 12(%esp), %ebp
1013 xorl %ebp, %edi
1014 movl 32(%esp), %ebp
1015.byte 209
1016.byte 203 /* rorl $1 %ebx */
1017 xorl %ebp, %edi
1018.byte 209
1019.byte 199 /* roll $1 %edi */
1020 movl %eax, %ebp
1021 movl %edi, 44(%esp)
1022 orl %ebx, %ebp
1023 leal 2400959708(%edi,%edx,1),%edi
1024 movl %eax, %edx
1025 andl %ecx, %ebp
1026 andl %ebx, %edx
1027 orl %edx, %ebp
1028 movl %esi, %edx
1029 roll $5, %edx
1030.byte 209
1031.byte 200 /* rorl $1 %eax */
1032 addl %edx, %ebp
1033.byte 209
1034.byte 200 /* rorl $1 %eax */
1035 addl %ebp, %edi
1036 /* 40_59 43 */
1037 /* 40_59 44 */
1038 movl 48(%esp), %edx
1039 movl 56(%esp), %ebp
1040 xorl %ebp, %edx
1041 movl 16(%esp), %ebp
1042 xorl %ebp, %edx
1043 movl 36(%esp), %ebp
1044 xorl %ebp, %edx
1045 movl %esi, %ebp
1046.byte 209
1047.byte 194 /* roll $1 %edx */
1048 orl %eax, %ebp
1049 movl %edx, 48(%esp)
1050 andl %ebx, %ebp
1051 leal 2400959708(%edx,%ecx,1),%edx
1052 movl %esi, %ecx
1053.byte 209
1054.byte 206 /* rorl $1 %esi */
1055 andl %eax, %ecx
1056 orl %ecx, %ebp
1057 movl %edi, %ecx
1058 roll $5, %ecx
1059 addl %ecx, %ebp
1060 movl 52(%esp), %ecx
1061 addl %ebp, %edx
1062 movl 60(%esp), %ebp
1063 xorl %ebp, %ecx
1064 movl 20(%esp), %ebp
1065 xorl %ebp, %ecx
1066 movl 40(%esp), %ebp
1067.byte 209
1068.byte 206 /* rorl $1 %esi */
1069 xorl %ebp, %ecx
1070.byte 209
1071.byte 193 /* roll $1 %ecx */
1072 movl %edi, %ebp
1073 movl %ecx, 52(%esp)
1074 orl %esi, %ebp
1075 leal 2400959708(%ecx,%ebx,1),%ecx
1076 movl %edi, %ebx
1077 andl %eax, %ebp
1078 andl %esi, %ebx
1079 orl %ebx, %ebp
1080 movl %edx, %ebx
1081 roll $5, %ebx
1082.byte 209
1083.byte 207 /* rorl $1 %edi */
1084 addl %ebx, %ebp
1085.byte 209
1086.byte 207 /* rorl $1 %edi */
1087 addl %ebp, %ecx
1088 /* 40_59 45 */
1089 /* 40_59 46 */
1090 movl 56(%esp), %ebx
1091 movl (%esp), %ebp
1092 xorl %ebp, %ebx
1093 movl 24(%esp), %ebp
1094 xorl %ebp, %ebx
1095 movl 44(%esp), %ebp
1096 xorl %ebp, %ebx
1097 movl %edx, %ebp
1098.byte 209
1099.byte 195 /* roll $1 %ebx */
1100 orl %edi, %ebp
1101 movl %ebx, 56(%esp)
1102 andl %esi, %ebp
1103 leal 2400959708(%ebx,%eax,1),%ebx
1104 movl %edx, %eax
1105.byte 209
1106.byte 202 /* rorl $1 %edx */
1107 andl %edi, %eax
1108 orl %eax, %ebp
1109 movl %ecx, %eax
1110 roll $5, %eax
1111 addl %eax, %ebp
1112 movl 60(%esp), %eax
1113 addl %ebp, %ebx
1114 movl 4(%esp), %ebp
1115 xorl %ebp, %eax
1116 movl 28(%esp), %ebp
1117 xorl %ebp, %eax
1118 movl 48(%esp), %ebp
1119.byte 209
1120.byte 202 /* rorl $1 %edx */
1121 xorl %ebp, %eax
1122.byte 209
1123.byte 192 /* roll $1 %eax */
1124 movl %ecx, %ebp
1125 movl %eax, 60(%esp)
1126 orl %edx, %ebp
1127 leal 2400959708(%eax,%esi,1),%eax
1128 movl %ecx, %esi
1129 andl %edi, %ebp
1130 andl %edx, %esi
1131 orl %esi, %ebp
1132 movl %ebx, %esi
1133 roll $5, %esi
1134.byte 209
1135.byte 201 /* rorl $1 %ecx */
1136 addl %esi, %ebp
1137.byte 209
1138.byte 201 /* rorl $1 %ecx */
1139 addl %ebp, %eax
1140 /* 40_59 47 */
1141 /* 40_59 48 */
1142 movl (%esp), %esi
1143 movl 8(%esp), %ebp
1144 xorl %ebp, %esi
1145 movl 32(%esp), %ebp
1146 xorl %ebp, %esi
1147 movl 52(%esp), %ebp
1148 xorl %ebp, %esi
1149 movl %ebx, %ebp
1150.byte 209
1151.byte 198 /* roll $1 %esi */
1152 orl %ecx, %ebp
1153 movl %esi, (%esp)
1154 andl %edx, %ebp
1155 leal 2400959708(%esi,%edi,1),%esi
1156 movl %ebx, %edi
1157.byte 209
1158.byte 203 /* rorl $1 %ebx */
1159 andl %ecx, %edi
1160 orl %edi, %ebp
1161 movl %eax, %edi
1162 roll $5, %edi
1163 addl %edi, %ebp
1164 movl 4(%esp), %edi
1165 addl %ebp, %esi
1166 movl 12(%esp), %ebp
1167 xorl %ebp, %edi
1168 movl 36(%esp), %ebp
1169 xorl %ebp, %edi
1170 movl 56(%esp), %ebp
1171.byte 209
1172.byte 203 /* rorl $1 %ebx */
1173 xorl %ebp, %edi
1174.byte 209
1175.byte 199 /* roll $1 %edi */
1176 movl %eax, %ebp
1177 movl %edi, 4(%esp)
1178 orl %ebx, %ebp
1179 leal 2400959708(%edi,%edx,1),%edi
1180 movl %eax, %edx
1181 andl %ecx, %ebp
1182 andl %ebx, %edx
1183 orl %edx, %ebp
1184 movl %esi, %edx
1185 roll $5, %edx
1186.byte 209
1187.byte 200 /* rorl $1 %eax */
1188 addl %edx, %ebp
1189.byte 209
1190.byte 200 /* rorl $1 %eax */
1191 addl %ebp, %edi
1192 /* 40_59 49 */
1193 /* 40_59 50 */
1194 movl 8(%esp), %edx
1195 movl 16(%esp), %ebp
1196 xorl %ebp, %edx
1197 movl 40(%esp), %ebp
1198 xorl %ebp, %edx
1199 movl 60(%esp), %ebp
1200 xorl %ebp, %edx
1201 movl %esi, %ebp
1202.byte 209
1203.byte 194 /* roll $1 %edx */
1204 orl %eax, %ebp
1205 movl %edx, 8(%esp)
1206 andl %ebx, %ebp
1207 leal 2400959708(%edx,%ecx,1),%edx
1208 movl %esi, %ecx
1209.byte 209
1210.byte 206 /* rorl $1 %esi */
1211 andl %eax, %ecx
1212 orl %ecx, %ebp
1213 movl %edi, %ecx
1214 roll $5, %ecx
1215 addl %ecx, %ebp
1216 movl 12(%esp), %ecx
1217 addl %ebp, %edx
1218 movl 20(%esp), %ebp
1219 xorl %ebp, %ecx
1220 movl 44(%esp), %ebp
1221 xorl %ebp, %ecx
1222 movl (%esp), %ebp
1223.byte 209
1224.byte 206 /* rorl $1 %esi */
1225 xorl %ebp, %ecx
1226.byte 209
1227.byte 193 /* roll $1 %ecx */
1228 movl %edi, %ebp
1229 movl %ecx, 12(%esp)
1230 orl %esi, %ebp
1231 leal 2400959708(%ecx,%ebx,1),%ecx
1232 movl %edi, %ebx
1233 andl %eax, %ebp
1234 andl %esi, %ebx
1235 orl %ebx, %ebp
1236 movl %edx, %ebx
1237 roll $5, %ebx
1238.byte 209
1239.byte 207 /* rorl $1 %edi */
1240 addl %ebx, %ebp
1241.byte 209
1242.byte 207 /* rorl $1 %edi */
1243 addl %ebp, %ecx
1244 /* 40_59 51 */
1245 /* 40_59 52 */
1246 movl 16(%esp), %ebx
1247 movl 24(%esp), %ebp
1248 xorl %ebp, %ebx
1249 movl 48(%esp), %ebp
1250 xorl %ebp, %ebx
1251 movl 4(%esp), %ebp
1252 xorl %ebp, %ebx
1253 movl %edx, %ebp
1254.byte 209
1255.byte 195 /* roll $1 %ebx */
1256 orl %edi, %ebp
1257 movl %ebx, 16(%esp)
1258 andl %esi, %ebp
1259 leal 2400959708(%ebx,%eax,1),%ebx
1260 movl %edx, %eax
1261.byte 209
1262.byte 202 /* rorl $1 %edx */
1263 andl %edi, %eax
1264 orl %eax, %ebp
1265 movl %ecx, %eax
1266 roll $5, %eax
1267 addl %eax, %ebp
1268 movl 20(%esp), %eax
1269 addl %ebp, %ebx
1270 movl 28(%esp), %ebp
1271 xorl %ebp, %eax
1272 movl 52(%esp), %ebp
1273 xorl %ebp, %eax
1274 movl 8(%esp), %ebp
1275.byte 209
1276.byte 202 /* rorl $1 %edx */
1277 xorl %ebp, %eax
1278.byte 209
1279.byte 192 /* roll $1 %eax */
1280 movl %ecx, %ebp
1281 movl %eax, 20(%esp)
1282 orl %edx, %ebp
1283 leal 2400959708(%eax,%esi,1),%eax
1284 movl %ecx, %esi
1285 andl %edi, %ebp
1286 andl %edx, %esi
1287 orl %esi, %ebp
1288 movl %ebx, %esi
1289 roll $5, %esi
1290.byte 209
1291.byte 201 /* rorl $1 %ecx */
1292 addl %esi, %ebp
1293.byte 209
1294.byte 201 /* rorl $1 %ecx */
1295 addl %ebp, %eax
1296 /* 40_59 53 */
1297 /* 40_59 54 */
1298 movl 24(%esp), %esi
1299 movl 32(%esp), %ebp
1300 xorl %ebp, %esi
1301 movl 56(%esp), %ebp
1302 xorl %ebp, %esi
1303 movl 12(%esp), %ebp
1304 xorl %ebp, %esi
1305 movl %ebx, %ebp
1306.byte 209
1307.byte 198 /* roll $1 %esi */
1308 orl %ecx, %ebp
1309 movl %esi, 24(%esp)
1310 andl %edx, %ebp
1311 leal 2400959708(%esi,%edi,1),%esi
1312 movl %ebx, %edi
1313.byte 209
1314.byte 203 /* rorl $1 %ebx */
1315 andl %ecx, %edi
1316 orl %edi, %ebp
1317 movl %eax, %edi
1318 roll $5, %edi
1319 addl %edi, %ebp
1320 movl 28(%esp), %edi
1321 addl %ebp, %esi
1322 movl 36(%esp), %ebp
1323 xorl %ebp, %edi
1324 movl 60(%esp), %ebp
1325 xorl %ebp, %edi
1326 movl 16(%esp), %ebp
1327.byte 209
1328.byte 203 /* rorl $1 %ebx */
1329 xorl %ebp, %edi
1330.byte 209
1331.byte 199 /* roll $1 %edi */
1332 movl %eax, %ebp
1333 movl %edi, 28(%esp)
1334 orl %ebx, %ebp
1335 leal 2400959708(%edi,%edx,1),%edi
1336 movl %eax, %edx
1337 andl %ecx, %ebp
1338 andl %ebx, %edx
1339 orl %edx, %ebp
1340 movl %esi, %edx
1341 roll $5, %edx
1342.byte 209
1343.byte 200 /* rorl $1 %eax */
1344 addl %edx, %ebp
1345.byte 209
1346.byte 200 /* rorl $1 %eax */
1347 addl %ebp, %edi
1348 /* 40_59 55 */
1349 /* 40_59 56 */
1350 movl 32(%esp), %edx
1351 movl 40(%esp), %ebp
1352 xorl %ebp, %edx
1353 movl (%esp), %ebp
1354 xorl %ebp, %edx
1355 movl 20(%esp), %ebp
1356 xorl %ebp, %edx
1357 movl %esi, %ebp
1358.byte 209
1359.byte 194 /* roll $1 %edx */
1360 orl %eax, %ebp
1361 movl %edx, 32(%esp)
1362 andl %ebx, %ebp
1363 leal 2400959708(%edx,%ecx,1),%edx
1364 movl %esi, %ecx
1365.byte 209
1366.byte 206 /* rorl $1 %esi */
1367 andl %eax, %ecx
1368 orl %ecx, %ebp
1369 movl %edi, %ecx
1370 roll $5, %ecx
1371 addl %ecx, %ebp
1372 movl 36(%esp), %ecx
1373 addl %ebp, %edx
1374 movl 44(%esp), %ebp
1375 xorl %ebp, %ecx
1376 movl 4(%esp), %ebp
1377 xorl %ebp, %ecx
1378 movl 24(%esp), %ebp
1379.byte 209
1380.byte 206 /* rorl $1 %esi */
1381 xorl %ebp, %ecx
1382.byte 209
1383.byte 193 /* roll $1 %ecx */
1384 movl %edi, %ebp
1385 movl %ecx, 36(%esp)
1386 orl %esi, %ebp
1387 leal 2400959708(%ecx,%ebx,1),%ecx
1388 movl %edi, %ebx
1389 andl %eax, %ebp
1390 andl %esi, %ebx
1391 orl %ebx, %ebp
1392 movl %edx, %ebx
1393 roll $5, %ebx
1394.byte 209
1395.byte 207 /* rorl $1 %edi */
1396 addl %ebx, %ebp
1397.byte 209
1398.byte 207 /* rorl $1 %edi */
1399 addl %ebp, %ecx
1400 /* 40_59 57 */
1401 /* 40_59 58 */
1402 movl 40(%esp), %ebx
1403 movl 48(%esp), %ebp
1404 xorl %ebp, %ebx
1405 movl 8(%esp), %ebp
1406 xorl %ebp, %ebx
1407 movl 28(%esp), %ebp
1408 xorl %ebp, %ebx
1409 movl %edx, %ebp
1410.byte 209
1411.byte 195 /* roll $1 %ebx */
1412 orl %edi, %ebp
1413 movl %ebx, 40(%esp)
1414 andl %esi, %ebp
1415 leal 2400959708(%ebx,%eax,1),%ebx
1416 movl %edx, %eax
1417.byte 209
1418.byte 202 /* rorl $1 %edx */
1419 andl %edi, %eax
1420 orl %eax, %ebp
1421 movl %ecx, %eax
1422 roll $5, %eax
1423 addl %eax, %ebp
1424 movl 44(%esp), %eax
1425 addl %ebp, %ebx
1426 movl 52(%esp), %ebp
1427 xorl %ebp, %eax
1428 movl 12(%esp), %ebp
1429 xorl %ebp, %eax
1430 movl 32(%esp), %ebp
1431.byte 209
1432.byte 202 /* rorl $1 %edx */
1433 xorl %ebp, %eax
1434.byte 209
1435.byte 192 /* roll $1 %eax */
1436 movl %ecx, %ebp
1437 movl %eax, 44(%esp)
1438 orl %edx, %ebp
1439 leal 2400959708(%eax,%esi,1),%eax
1440 movl %ecx, %esi
1441 andl %edi, %ebp
1442 andl %edx, %esi
1443 orl %esi, %ebp
1444 movl %ebx, %esi
1445 roll $5, %esi
1446.byte 209
1447.byte 201 /* rorl $1 %ecx */
1448 addl %esi, %ebp
1449.byte 209
1450.byte 201 /* rorl $1 %ecx */
1451 addl %ebp, %eax
1452 /* 40_59 59 */
1453 /* 20_39 60 */
1454 movl 48(%esp), %esi
1455 movl 56(%esp), %ebp
1456 xorl %ebp, %esi
1457 movl 16(%esp), %ebp
1458 xorl %ebp, %esi
1459 movl 36(%esp), %ebp
1460 xorl %ebp, %esi
1461 movl %ebx, %ebp
1462.byte 209
1463.byte 198 /* roll $1 %esi */
1464 xorl %ecx, %ebp
1465 movl %esi, 48(%esp)
1466 xorl %edx, %ebp
1467 leal 3395469782(%esi,%edi,1),%esi
1468 movl %eax, %edi
1469 roll $5, %edi
1470.byte 209
1471.byte 203 /* rorl $1 %ebx */
1472 addl %ebp, %edi
1473.byte 209
1474.byte 203 /* rorl $1 %ebx */
1475 addl %edi, %esi
1476 /* 20_39 61 */
1477 movl 52(%esp), %edi
1478 movl 60(%esp), %ebp
1479 xorl %ebp, %edi
1480 movl 20(%esp), %ebp
1481 xorl %ebp, %edi
1482 movl 40(%esp), %ebp
1483 xorl %ebp, %edi
1484 movl %eax, %ebp
1485.byte 209
1486.byte 199 /* roll $1 %edi */
1487 xorl %ebx, %ebp
1488 movl %edi, 52(%esp)
1489 xorl %ecx, %ebp
1490 leal 3395469782(%edi,%edx,1),%edi
1491 movl %esi, %edx
1492 roll $5, %edx
1493.byte 209
1494.byte 200 /* rorl $1 %eax */
1495 addl %ebp, %edx
1496.byte 209
1497.byte 200 /* rorl $1 %eax */
1498 addl %edx, %edi
1499 /* 20_39 62 */
1500 movl 56(%esp), %edx
1501 movl (%esp), %ebp
1502 xorl %ebp, %edx
1503 movl 24(%esp), %ebp
1504 xorl %ebp, %edx
1505 movl 44(%esp), %ebp
1506 xorl %ebp, %edx
1507 movl %esi, %ebp
1508.byte 209
1509.byte 194 /* roll $1 %edx */
1510 xorl %eax, %ebp
1511 movl %edx, 56(%esp)
1512 xorl %ebx, %ebp
1513 leal 3395469782(%edx,%ecx,1),%edx
1514 movl %edi, %ecx
1515 roll $5, %ecx
1516.byte 209
1517.byte 206 /* rorl $1 %esi */
1518 addl %ebp, %ecx
1519.byte 209
1520.byte 206 /* rorl $1 %esi */
1521 addl %ecx, %edx
1522 /* 20_39 63 */
1523 movl 60(%esp), %ecx
1524 movl 4(%esp), %ebp
1525 xorl %ebp, %ecx
1526 movl 28(%esp), %ebp
1527 xorl %ebp, %ecx
1528 movl 48(%esp), %ebp
1529 xorl %ebp, %ecx
1530 movl %edi, %ebp
1531.byte 209
1532.byte 193 /* roll $1 %ecx */
1533 xorl %esi, %ebp
1534 movl %ecx, 60(%esp)
1535 xorl %eax, %ebp
1536 leal 3395469782(%ecx,%ebx,1),%ecx
1537 movl %edx, %ebx
1538 roll $5, %ebx
1539.byte 209
1540.byte 207 /* rorl $1 %edi */
1541 addl %ebp, %ebx
1542.byte 209
1543.byte 207 /* rorl $1 %edi */
1544 addl %ebx, %ecx
1545 /* 20_39 64 */
1546 movl (%esp), %ebx
1547 movl 8(%esp), %ebp
1548 xorl %ebp, %ebx
1549 movl 32(%esp), %ebp
1550 xorl %ebp, %ebx
1551 movl 52(%esp), %ebp
1552 xorl %ebp, %ebx
1553 movl %edx, %ebp
1554.byte 209
1555.byte 195 /* roll $1 %ebx */
1556 xorl %edi, %ebp
1557 movl %ebx, (%esp)
1558 xorl %esi, %ebp
1559 leal 3395469782(%ebx,%eax,1),%ebx
1560 movl %ecx, %eax
1561 roll $5, %eax
1562.byte 209
1563.byte 202 /* rorl $1 %edx */
1564 addl %ebp, %eax
1565.byte 209
1566.byte 202 /* rorl $1 %edx */
1567 addl %eax, %ebx
1568 /* 20_39 65 */
1569 movl 4(%esp), %eax
1570 movl 12(%esp), %ebp
1571 xorl %ebp, %eax
1572 movl 36(%esp), %ebp
1573 xorl %ebp, %eax
1574 movl 56(%esp), %ebp
1575 xorl %ebp, %eax
1576 movl %ecx, %ebp
1577.byte 209
1578.byte 192 /* roll $1 %eax */
1579 xorl %edx, %ebp
1580 movl %eax, 4(%esp)
1581 xorl %edi, %ebp
1582 leal 3395469782(%eax,%esi,1),%eax
1583 movl %ebx, %esi
1584 roll $5, %esi
1585.byte 209
1586.byte 201 /* rorl $1 %ecx */
1587 addl %ebp, %esi
1588.byte 209
1589.byte 201 /* rorl $1 %ecx */
1590 addl %esi, %eax
1591 /* 20_39 66 */
1592 movl 8(%esp), %esi
1593 movl 16(%esp), %ebp
1594 xorl %ebp, %esi
1595 movl 40(%esp), %ebp
1596 xorl %ebp, %esi
1597 movl 60(%esp), %ebp
1598 xorl %ebp, %esi
1599 movl %ebx, %ebp
1600.byte 209
1601.byte 198 /* roll $1 %esi */
1602 xorl %ecx, %ebp
1603 movl %esi, 8(%esp)
1604 xorl %edx, %ebp
1605 leal 3395469782(%esi,%edi,1),%esi
1606 movl %eax, %edi
1607 roll $5, %edi
1608.byte 209
1609.byte 203 /* rorl $1 %ebx */
1610 addl %ebp, %edi
1611.byte 209
1612.byte 203 /* rorl $1 %ebx */
1613 addl %edi, %esi
1614 /* 20_39 67 */
1615 movl 12(%esp), %edi
1616 movl 20(%esp), %ebp
1617 xorl %ebp, %edi
1618 movl 44(%esp), %ebp
1619 xorl %ebp, %edi
1620 movl (%esp), %ebp
1621 xorl %ebp, %edi
1622 movl %eax, %ebp
1623.byte 209
1624.byte 199 /* roll $1 %edi */
1625 xorl %ebx, %ebp
1626 movl %edi, 12(%esp)
1627 xorl %ecx, %ebp
1628 leal 3395469782(%edi,%edx,1),%edi
1629 movl %esi, %edx
1630 roll $5, %edx
1631.byte 209
1632.byte 200 /* rorl $1 %eax */
1633 addl %ebp, %edx
1634.byte 209
1635.byte 200 /* rorl $1 %eax */
1636 addl %edx, %edi
1637 /* 20_39 68 */
1638 movl 16(%esp), %edx
1639 movl 24(%esp), %ebp
1640 xorl %ebp, %edx
1641 movl 48(%esp), %ebp
1642 xorl %ebp, %edx
1643 movl 4(%esp), %ebp
1644 xorl %ebp, %edx
1645 movl %esi, %ebp
1646.byte 209
1647.byte 194 /* roll $1 %edx */
1648 xorl %eax, %ebp
1649 movl %edx, 16(%esp)
1650 xorl %ebx, %ebp
1651 leal 3395469782(%edx,%ecx,1),%edx
1652 movl %edi, %ecx
1653 roll $5, %ecx
1654.byte 209
1655.byte 206 /* rorl $1 %esi */
1656 addl %ebp, %ecx
1657.byte 209
1658.byte 206 /* rorl $1 %esi */
1659 addl %ecx, %edx
1660 /* 20_39 69 */
1661 movl 20(%esp), %ecx
1662 movl 28(%esp), %ebp
1663 xorl %ebp, %ecx
1664 movl 52(%esp), %ebp
1665 xorl %ebp, %ecx
1666 movl 8(%esp), %ebp
1667 xorl %ebp, %ecx
1668 movl %edi, %ebp
1669.byte 209
1670.byte 193 /* roll $1 %ecx */
1671 xorl %esi, %ebp
1672 movl %ecx, 20(%esp)
1673 xorl %eax, %ebp
1674 leal 3395469782(%ecx,%ebx,1),%ecx
1675 movl %edx, %ebx
1676 roll $5, %ebx
1677.byte 209
1678.byte 207 /* rorl $1 %edi */
1679 addl %ebp, %ebx
1680.byte 209
1681.byte 207 /* rorl $1 %edi */
1682 addl %ebx, %ecx
1683 /* 20_39 70 */
1684 movl 24(%esp), %ebx
1685 movl 32(%esp), %ebp
1686 xorl %ebp, %ebx
1687 movl 56(%esp), %ebp
1688 xorl %ebp, %ebx
1689 movl 12(%esp), %ebp
1690 xorl %ebp, %ebx
1691 movl %edx, %ebp
1692.byte 209
1693.byte 195 /* roll $1 %ebx */
1694 xorl %edi, %ebp
1695 movl %ebx, 24(%esp)
1696 xorl %esi, %ebp
1697 leal 3395469782(%ebx,%eax,1),%ebx
1698 movl %ecx, %eax
1699 roll $5, %eax
1700.byte 209
1701.byte 202 /* rorl $1 %edx */
1702 addl %ebp, %eax
1703.byte 209
1704.byte 202 /* rorl $1 %edx */
1705 addl %eax, %ebx
1706 /* 20_39 71 */
1707 movl 28(%esp), %eax
1708 movl 36(%esp), %ebp
1709 xorl %ebp, %eax
1710 movl 60(%esp), %ebp
1711 xorl %ebp, %eax
1712 movl 16(%esp), %ebp
1713 xorl %ebp, %eax
1714 movl %ecx, %ebp
1715.byte 209
1716.byte 192 /* roll $1 %eax */
1717 xorl %edx, %ebp
1718 movl %eax, 28(%esp)
1719 xorl %edi, %ebp
1720 leal 3395469782(%eax,%esi,1),%eax
1721 movl %ebx, %esi
1722 roll $5, %esi
1723.byte 209
1724.byte 201 /* rorl $1 %ecx */
1725 addl %ebp, %esi
1726.byte 209
1727.byte 201 /* rorl $1 %ecx */
1728 addl %esi, %eax
1729 /* 20_39 72 */
1730 movl 32(%esp), %esi
1731 movl 40(%esp), %ebp
1732 xorl %ebp, %esi
1733 movl (%esp), %ebp
1734 xorl %ebp, %esi
1735 movl 20(%esp), %ebp
1736 xorl %ebp, %esi
1737 movl %ebx, %ebp
1738.byte 209
1739.byte 198 /* roll $1 %esi */
1740 xorl %ecx, %ebp
1741 movl %esi, 32(%esp)
1742 xorl %edx, %ebp
1743 leal 3395469782(%esi,%edi,1),%esi
1744 movl %eax, %edi
1745 roll $5, %edi
1746.byte 209
1747.byte 203 /* rorl $1 %ebx */
1748 addl %ebp, %edi
1749.byte 209
1750.byte 203 /* rorl $1 %ebx */
1751 addl %edi, %esi
1752 /* 20_39 73 */
1753 movl 36(%esp), %edi
1754 movl 44(%esp), %ebp
1755 xorl %ebp, %edi
1756 movl 4(%esp), %ebp
1757 xorl %ebp, %edi
1758 movl 24(%esp), %ebp
1759 xorl %ebp, %edi
1760 movl %eax, %ebp
1761.byte 209
1762.byte 199 /* roll $1 %edi */
1763 xorl %ebx, %ebp
1764 movl %edi, 36(%esp)
1765 xorl %ecx, %ebp
1766 leal 3395469782(%edi,%edx,1),%edi
1767 movl %esi, %edx
1768 roll $5, %edx
1769.byte 209
1770.byte 200 /* rorl $1 %eax */
1771 addl %ebp, %edx
1772.byte 209
1773.byte 200 /* rorl $1 %eax */
1774 addl %edx, %edi
1775 /* 20_39 74 */
1776 movl 40(%esp), %edx
1777 movl 48(%esp), %ebp
1778 xorl %ebp, %edx
1779 movl 8(%esp), %ebp
1780 xorl %ebp, %edx
1781 movl 28(%esp), %ebp
1782 xorl %ebp, %edx
1783 movl %esi, %ebp
1784.byte 209
1785.byte 194 /* roll $1 %edx */
1786 xorl %eax, %ebp
1787 movl %edx, 40(%esp)
1788 xorl %ebx, %ebp
1789 leal 3395469782(%edx,%ecx,1),%edx
1790 movl %edi, %ecx
1791 roll $5, %ecx
1792.byte 209
1793.byte 206 /* rorl $1 %esi */
1794 addl %ebp, %ecx
1795.byte 209
1796.byte 206 /* rorl $1 %esi */
1797 addl %ecx, %edx
1798 /* 20_39 75 */
1799 movl 44(%esp), %ecx
1800 movl 52(%esp), %ebp
1801 xorl %ebp, %ecx
1802 movl 12(%esp), %ebp
1803 xorl %ebp, %ecx
1804 movl 32(%esp), %ebp
1805 xorl %ebp, %ecx
1806 movl %edi, %ebp
1807.byte 209
1808.byte 193 /* roll $1 %ecx */
1809 xorl %esi, %ebp
1810 movl %ecx, 44(%esp)
1811 xorl %eax, %ebp
1812 leal 3395469782(%ecx,%ebx,1),%ecx
1813 movl %edx, %ebx
1814 roll $5, %ebx
1815.byte 209
1816.byte 207 /* rorl $1 %edi */
1817 addl %ebp, %ebx
1818.byte 209
1819.byte 207 /* rorl $1 %edi */
1820 addl %ebx, %ecx
1821 /* 20_39 76 */
1822 movl 48(%esp), %ebx
1823 movl 56(%esp), %ebp
1824 xorl %ebp, %ebx
1825 movl 16(%esp), %ebp
1826 xorl %ebp, %ebx
1827 movl 36(%esp), %ebp
1828 xorl %ebp, %ebx
1829 movl %edx, %ebp
1830.byte 209
1831.byte 195 /* roll $1 %ebx */
1832 xorl %edi, %ebp
1833 movl %ebx, 48(%esp)
1834 xorl %esi, %ebp
1835 leal 3395469782(%ebx,%eax,1),%ebx
1836 movl %ecx, %eax
1837 roll $5, %eax
1838.byte 209
1839.byte 202 /* rorl $1 %edx */
1840 addl %ebp, %eax
1841.byte 209
1842.byte 202 /* rorl $1 %edx */
1843 addl %eax, %ebx
1844 /* 20_39 77 */
1845 movl 52(%esp), %eax
1846 movl 60(%esp), %ebp
1847 xorl %ebp, %eax
1848 movl 20(%esp), %ebp
1849 xorl %ebp, %eax
1850 movl 40(%esp), %ebp
1851 xorl %ebp, %eax
1852 movl %ecx, %ebp
1853.byte 209
1854.byte 192 /* roll $1 %eax */
1855 xorl %edx, %ebp
1856 movl %eax, 52(%esp)
1857 xorl %edi, %ebp
1858 leal 3395469782(%eax,%esi,1),%eax
1859 movl %ebx, %esi
1860 roll $5, %esi
1861.byte 209
1862.byte 201 /* rorl $1 %ecx */
1863 addl %ebp, %esi
1864.byte 209
1865.byte 201 /* rorl $1 %ecx */
1866 addl %esi, %eax
1867 /* 20_39 78 */
1868 movl 56(%esp), %esi
1869 movl (%esp), %ebp
1870 xorl %ebp, %esi
1871 movl 24(%esp), %ebp
1872 xorl %ebp, %esi
1873 movl 44(%esp), %ebp
1874 xorl %ebp, %esi
1875 movl %ebx, %ebp
1876.byte 209
1877.byte 198 /* roll $1 %esi */
1878 xorl %ecx, %ebp
1879 movl %esi, 56(%esp)
1880 xorl %edx, %ebp
1881 leal 3395469782(%esi,%edi,1),%esi
1882 movl %eax, %edi
1883 roll $5, %edi
1884.byte 209
1885.byte 203 /* rorl $1 %ebx */
1886 addl %ebp, %edi
1887.byte 209
1888.byte 203 /* rorl $1 %ebx */
1889 addl %edi, %esi
1890 /* 20_39 79 */
1891 movl 60(%esp), %edi
1892 movl 4(%esp), %ebp
1893 xorl %ebp, %edi
1894 movl 28(%esp), %ebp
1895 xorl %ebp, %edi
1896 movl 48(%esp), %ebp
1897 xorl %ebp, %edi
1898 movl %eax, %ebp
1899.byte 209
1900.byte 199 /* roll $1 %edi */
1901 xorl %ebx, %ebp
1902 movl %edi, 60(%esp)
1903 xorl %ecx, %ebp
1904 leal 3395469782(%edi,%edx,1),%edi
1905 movl %esi, %edx
1906 roll $5, %edx
1907 addl %ebp, %edx
1908 movl 92(%esp), %ebp
1909.byte 209
1910.byte 200 /* rorl $1 %eax */
1911 addl %edx, %edi
1912.byte 209
1913.byte 200 /* rorl $1 %eax */
1914 /* End processing */
1915
1916 movl 12(%ebp), %edx
1917 addl %ebx, %edx
1918 movl 4(%ebp), %ebx
1919 addl %esi, %ebx
1920 movl %eax, %esi
1921 movl (%ebp), %eax
1922 movl %edx, 12(%ebp)
1923 addl %edi, %eax
1924 movl 16(%ebp), %edi
1925 addl %ecx, %edi
1926 movl 8(%ebp), %ecx
1927 addl %esi, %ecx
1928 movl %eax, (%ebp)
1929 movl 64(%esp), %esi
1930 movl %ecx, 8(%ebp)
1931 addl $64, %esi
1932 movl 68(%esp), %eax
1933 movl %edi, 16(%ebp)
1934 cmpl %esi, %eax
1935 movl %ebx, 4(%ebp)
1936 jl .L001end
1937 movl (%esi), %eax
1938 jmp .L000start
1939.L001end:
1940 addl $72, %esp
1941 popl %edi
1942 popl %ebx
1943 popl %ebp
1944 popl %esi
1945 ret
1946.sha1_block_x86_end:
1947 SIZE(sha1_block_x86,.sha1_block_x86_end-sha1_block_x86)
1948.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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "sha.h" 61#include <openssl/sha.h>
62 62
63#define BUFSIZE 1024*16 63#define BUFSIZE 1024*16
64 64
65#ifndef NOPROTO
66void do_fp(FILE *f); 65void do_fp(FILE *f);
67void pt(unsigned char *md); 66void pt(unsigned char *md);
68int read(int, void *, unsigned int); 67int read(int, void *, unsigned int);
69#else 68int main(int argc, char **argv)
70void do_fp();
71void pt();
72int read();
73#endif
74
75int main(argc, argv)
76int argc;
77char **argv;
78 { 69 {
79 int i,err=0; 70 int i,err=0;
80 FILE *IN; 71 FILE *IN;
@@ -102,8 +93,7 @@ char **argv;
102 exit(err); 93 exit(err);
103 } 94 }
104 95
105void do_fp(f) 96void do_fp(FILE *f)
106FILE *f;
107 { 97 {
108 SHA_CTX c; 98 SHA_CTX c;
109 unsigned char md[SHA_DIGEST_LENGTH]; 99 unsigned char md[SHA_DIGEST_LENGTH];
@@ -123,8 +113,7 @@ FILE *f;
123 pt(md); 113 pt(md);
124 } 114 }
125 115
126void pt(md) 116void pt(unsigned char *md)
127unsigned char *md;
128 { 117 {
129 int i; 118 int i;
130 119
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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#define SHA_CBLOCK 64 66#ifdef NO_SHA
67#error SHA is disabled.
68#endif
69
70/*
71 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
72 * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
73 * ! SHA_LONG_LOG2 has to be defined along. !
74 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 */
76
77#if defined(WIN16) || defined(__LP32__)
78#define SHA_LONG unsigned long
79#elif defined(_CRAY) || defined(__ILP64__)
80#define SHA_LONG unsigned long
81#define SHA_LONG_LOG2 3
82#else
83#define SHA_LONG unsigned int
84#endif
85
67#define SHA_LBLOCK 16 86#define SHA_LBLOCK 16
68#define SHA_BLOCK 16 87#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a
69#define SHA_LAST_BLOCK 56 88 * contiguous array of 32 bit
70#define SHA_LENGTH_BLOCK 8 89 * wide big-endian values. */
90#define SHA_LAST_BLOCK (SHA_CBLOCK-8)
71#define SHA_DIGEST_LENGTH 20 91#define SHA_DIGEST_LENGTH 20
72 92
73typedef struct SHAstate_st 93typedef struct SHAstate_st
74 { 94 {
75 unsigned long h0,h1,h2,h3,h4; 95 SHA_LONG h0,h1,h2,h3,h4;
76 unsigned long Nl,Nh; 96 SHA_LONG Nl,Nh;
77 unsigned long data[SHA_LBLOCK]; 97 SHA_LONG data[SHA_LBLOCK];
78 int num; 98 int num;
79 } SHA_CTX; 99 } SHA_CTX;
80 100
81#ifndef NOPROTO 101#ifndef NO_SHA0
82void SHA_Init(SHA_CTX *c); 102void SHA_Init(SHA_CTX *c);
83void SHA_Update(SHA_CTX *c, unsigned char *data, unsigned long len); 103void SHA_Update(SHA_CTX *c, const unsigned char *data, unsigned long len);
84void SHA_Final(unsigned char *md, SHA_CTX *c); 104void SHA_Final(unsigned char *md, SHA_CTX *c);
85unsigned char *SHA(unsigned char *d, unsigned long n,unsigned char *md); 105unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md);
86void SHA_Transform(SHA_CTX *c, unsigned char *data); 106void SHA_Transform(SHA_CTX *c, unsigned char *data);
107#endif
108#ifndef NO_SHA1
87void SHA1_Init(SHA_CTX *c); 109void SHA1_Init(SHA_CTX *c);
88void SHA1_Update(SHA_CTX *c, unsigned char *data, unsigned long len); 110void SHA1_Update(SHA_CTX *c, const unsigned char *data, unsigned long len);
89void SHA1_Final(unsigned char *md, SHA_CTX *c); 111void SHA1_Final(unsigned char *md, SHA_CTX *c);
90unsigned char *SHA1(unsigned char *d, unsigned long n,unsigned char *md); 112unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md);
91void SHA1_Transform(SHA_CTX *c, unsigned char *data); 113void SHA1_Transform(SHA_CTX *c, unsigned char *data);
92#else
93void SHA_Init();
94void SHA_Update();
95void SHA_Final();
96unsigned char *SHA();
97void SHA_Transform();
98void SHA1_Init();
99void SHA1_Update();
100void SHA1_Final();
101unsigned char *SHA1();
102void SHA1_Transform();
103#endif 114#endif
104
105#ifdef __cplusplus 115#ifdef __cplusplus
106} 116}
107#endif 117#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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include "sha.h" 61#include <openssl/sha.h>
62 62
63#define BUFSIZE 1024*16 63#define BUFSIZE 1024*16
64 64
65#ifndef NOPROTO
66void do_fp(FILE *f); 65void do_fp(FILE *f);
67void pt(unsigned char *md); 66void pt(unsigned char *md);
67#ifndef _OSD_POSIX
68int read(int, void *, unsigned int); 68int read(int, void *, unsigned int);
69#else
70void do_fp();
71void pt();
72int read();
73#endif 69#endif
74 70
75int main(argc, argv) 71int main(int argc, char **argv)
76int argc;
77char **argv;
78 { 72 {
79 int i,err=0; 73 int i,err=0;
80 FILE *IN; 74 FILE *IN;
@@ -102,8 +96,7 @@ char **argv;
102 exit(err); 96 exit(err);
103 } 97 }
104 98
105void do_fp(f) 99void do_fp(FILE *f)
106FILE *f;
107 { 100 {
108 SHA_CTX c; 101 SHA_CTX c;
109 unsigned char md[SHA_DIGEST_LENGTH]; 102 unsigned char md[SHA_DIGEST_LENGTH];
@@ -123,8 +116,7 @@ FILE *f;
123 pt(md); 116 pt(md);
124 } 117 }
125 118
126void pt(md) 119void pt(unsigned char *md)
127unsigned char *md;
128 { 120 {
129 int i; 121 int i;
130 122
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "sha.h" 61#include <openssl/sha.h>
62 62
63unsigned char *SHA1(d, n, md) 63#ifndef NO_SHA1
64unsigned char *d; 64unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md)
65unsigned long n;
66unsigned char *md;
67 { 65 {
68 SHA_CTX c; 66 SHA_CTX c;
69 static unsigned char m[SHA_DIGEST_LENGTH]; 67 static unsigned char m[SHA_DIGEST_LENGTH];
@@ -75,3 +73,4 @@ unsigned char *md;
75 memset(&c,0,sizeof(c)); 73 memset(&c,0,sizeof(c));
76 return(md); 74 return(md);
77 } 75 }
76#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 @@
60#include <string.h> 60#include <string.h>
61#undef SHA_0 61#undef SHA_0
62#define SHA_1 62#define SHA_1
63#include "sha.h" 63#include <openssl/sha.h>
64#include "sha_locl.h" 64#include "sha_locl.h"
65#include <openssl/opensslv.h>
65 66
66char *SHA1_version="SHA1 part of SSLeay 0.9.0b 29-Jun-1998"; 67#ifndef NO_SHA1
68char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
67 69
68/* Implemented from SHA-1 document - The Secure Hash Algorithm 70/* Implemented from SHA-1 document - The Secure Hash Algorithm
69 */ 71 */
70 72
71#define INIT_DATA_h0 (unsigned long)0x67452301L 73#define INIT_DATA_h0 0x67452301UL
72#define INIT_DATA_h1 (unsigned long)0xefcdab89L 74#define INIT_DATA_h1 0xefcdab89UL
73#define INIT_DATA_h2 (unsigned long)0x98badcfeL 75#define INIT_DATA_h2 0x98badcfeUL
74#define INIT_DATA_h3 (unsigned long)0x10325476L 76#define INIT_DATA_h3 0x10325476UL
75#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L 77#define INIT_DATA_h4 0xc3d2e1f0UL
76 78
77#define K_00_19 0x5a827999L 79#define K_00_19 0x5a827999UL
78#define K_20_39 0x6ed9eba1L 80#define K_20_39 0x6ed9eba1UL
79#define K_40_59 0x8f1bbcdcL 81#define K_40_59 0x8f1bbcdcUL
80#define K_60_79 0xca62c1d6L 82#define K_60_79 0xca62c1d6UL
81 83
82#ifndef NOPROTO 84#ifdef SHA1_ASM
83# ifdef SHA1_ASM 85 void sha1_block_x86(SHA_CTX *c, register SHA_LONG *p, int num);
84 void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int num); 86# define sha1_block(c,p,n) sha1_block_x86((c),(p),(n)*SHA_CBLOCK)
85# define sha1_block sha1_block_x86
86# else
87 void sha1_block(SHA_CTX *c, register unsigned long *p, int num);
88# endif
89#else 87#else
90# ifdef SHA1_ASM 88 static void sha1_block(SHA_CTX *c, register SHA_LONG *p, int num);
91 void sha1_block_x86();
92# define sha1_block sha1_block_x86
93# else
94 void sha1_block();
95# endif
96#endif 89#endif
97 90
98 91#if !defined(B_ENDIAN) && defined(SHA1_ASM)
99#if defined(L_ENDIAN) && defined(SHA1_ASM)
100# define M_c2nl c2l 92# define M_c2nl c2l
101# define M_p_c2nl p_c2l 93# define M_p_c2nl p_c2l
102# define M_c2nl_p c2l_p 94# define M_c2nl_p c2l_p
@@ -110,8 +102,7 @@ char *SHA1_version="SHA1 part of SSLeay 0.9.0b 29-Jun-1998";
110# define M_nl2c nl2c 102# define M_nl2c nl2c
111#endif 103#endif
112 104
113void SHA1_Init(c) 105void SHA1_Init(SHA_CTX *c)
114SHA_CTX *c;
115 { 106 {
116 c->h0=INIT_DATA_h0; 107 c->h0=INIT_DATA_h0;
117 c->h1=INIT_DATA_h1; 108 c->h1=INIT_DATA_h1;
@@ -123,14 +114,12 @@ SHA_CTX *c;
123 c->num=0; 114 c->num=0;
124 } 115 }
125 116
126void SHA1_Update(c, data, len) 117void SHA1_Update(SHA_CTX *c, register const unsigned char *data,
127SHA_CTX *c; 118 unsigned long len)
128register unsigned char *data;
129unsigned long len;
130 { 119 {
131 register ULONG *p; 120 register SHA_LONG *p;
132 int ew,ec,sw,sc; 121 int ew,ec,sw,sc;
133 ULONG l; 122 SHA_LONG l;
134 123
135 if (len == 0) return; 124 if (len == 0) return;
136 125
@@ -158,7 +147,7 @@ unsigned long len;
158 } 147 }
159 len-=(SHA_CBLOCK-c->num); 148 len-=(SHA_CBLOCK-c->num);
160 149
161 sha1_block(c,p,64); 150 sha1_block(c,p,1);
162 c->num=0; 151 c->num=0;
163 /* drop through and do the rest */ 152 /* drop through and do the rest */
164 } 153 }
@@ -195,15 +184,15 @@ unsigned long len;
195 * copies it to a local array. I should be able to do this for 184 * copies it to a local array. I should be able to do this for
196 * the C version as well.... 185 * the C version as well....
197 */ 186 */
198#if 1 187#if SHA_LONG_LOG2==2
199#if defined(B_ENDIAN) || defined(SHA1_ASM) 188#if defined(B_ENDIAN) || defined(SHA1_ASM)
200 if ((((unsigned int)data)%sizeof(ULONG)) == 0) 189 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
201 { 190 {
202 sw=len/SHA_CBLOCK; 191 sw=len/SHA_CBLOCK;
203 if (sw) 192 if (sw)
204 { 193 {
194 sha1_block(c,(SHA_LONG *)data,sw);
205 sw*=SHA_CBLOCK; 195 sw*=SHA_CBLOCK;
206 sha1_block(c,(ULONG *)data,sw);
207 data+=sw; 196 data+=sw;
208 len-=sw; 197 len-=sw;
209 } 198 }
@@ -215,35 +204,61 @@ unsigned long len;
215 p=c->data; 204 p=c->data;
216 while (len >= SHA_CBLOCK) 205 while (len >= SHA_CBLOCK)
217 { 206 {
218#if defined(B_ENDIAN) || defined(L_ENDIAN) 207#if SHA_LONG_LOG2==2
219 if (p != (unsigned long *)data) 208#if defined(B_ENDIAN) || defined(SHA1_ASM)
209#define SHA_NO_TAIL_CODE
210 /*
211 * Basically we get here only when data happens
212 * to be unaligned.
213 */
214 if (p != (SHA_LONG *)data)
220 memcpy(p,data,SHA_CBLOCK); 215 memcpy(p,data,SHA_CBLOCK);
221 data+=SHA_CBLOCK; 216 data+=SHA_CBLOCK;
222# ifdef L_ENDIAN 217 sha1_block(c,p=c->data,1);
223# ifndef SHA1_ASM /* Will not happen */ 218 len-=SHA_CBLOCK;
224 for (sw=(SHA_LBLOCK/4); sw; sw--) 219#elif defined(L_ENDIAN)
220#define BE_COPY(dst,src,i) { \
221 l = ((SHA_LONG *)src)[i]; \
222 Endian_Reverse32(l); \
223 dst[i] = l; \
224 }
225 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
225 { 226 {
226 Endian_Reverse32(p[0]); 227 for (sw=(SHA_LBLOCK/4); sw; sw--)
227 Endian_Reverse32(p[1]); 228 {
228 Endian_Reverse32(p[2]); 229 BE_COPY(p,data,0);
229 Endian_Reverse32(p[3]); 230 BE_COPY(p,data,1);
230 p+=4; 231 BE_COPY(p,data,2);
232 BE_COPY(p,data,3);
233 p+=4;
234 data += 4*sizeof(SHA_LONG);
235 }
236 sha1_block(c,p=c->data,1);
237 len-=SHA_CBLOCK;
238 continue;
231 } 239 }
240#endif
241#endif
242#ifndef SHA_NO_TAIL_CODE
243 /*
244 * In addition to "sizeof(SHA_LONG)!= 4" case the
245 * following code covers unaligned access cases on
246 * little-endian machines.
247 * <appro@fy.chalmers.se>
248 */
232 p=c->data; 249 p=c->data;
233# endif 250 for (sw=(SHA_LBLOCK/4); sw; sw--)
234# endif
235#else
236 for (sw=(SHA_BLOCK/4); sw; sw--)
237 { 251 {
238 M_c2nl(data,l); *(p++)=l; 252 M_c2nl(data,l); p[0]=l;
239 M_c2nl(data,l); *(p++)=l; 253 M_c2nl(data,l); p[1]=l;
240 M_c2nl(data,l); *(p++)=l; 254 M_c2nl(data,l); p[2]=l;
241 M_c2nl(data,l); *(p++)=l; 255 M_c2nl(data,l); p[3]=l;
256 p+=4;
242 } 257 }
243 p=c->data; 258 p=c->data;
244#endif 259 sha1_block(c,p,1);
245 sha1_block(c,p,64);
246 len-=SHA_CBLOCK; 260 len-=SHA_CBLOCK;
261#endif
247 } 262 }
248 ec=(int)len; 263 ec=(int)len;
249 c->num=ec; 264 c->num=ec;
@@ -256,52 +271,61 @@ unsigned long len;
256 p[sw]=l; 271 p[sw]=l;
257 } 272 }
258 273
259void SHA1_Transform(c,b) 274void SHA1_Transform(SHA_CTX *c, unsigned char *b)
260SHA_CTX *c;
261unsigned char *b;
262 { 275 {
263 ULONG p[16]; 276 SHA_LONG p[SHA_LBLOCK];
264#ifndef B_ENDIAN
265 ULONG *q;
266 int i;
267#endif
268 277
269#if defined(B_ENDIAN) || defined(L_ENDIAN) 278#if SHA_LONG_LOG2==2
270 memcpy(p,b,64); 279#if defined(B_ENDIAN) || defined(SHA1_ASM)
271#ifdef L_ENDIAN 280 memcpy(p,b,SHA_CBLOCK);
272 q=p; 281 sha1_block(c,p,1);
273 for (i=(SHA_LBLOCK/4); i; i--) 282 return;
283#elif defined(L_ENDIAN)
284 if (((unsigned long)b%sizeof(SHA_LONG)) == 0)
274 { 285 {
275 Endian_Reverse32(q[0]); 286 SHA_LONG *q;
276 Endian_Reverse32(q[1]); 287 int i;
277 Endian_Reverse32(q[2]); 288
278 Endian_Reverse32(q[3]); 289 q=p;
279 q+=4; 290 for (i=(SHA_LBLOCK/4); i; i--)
291 {
292 unsigned long l;
293 BE_COPY(q,b,0); /* BE_COPY was defined above */
294 BE_COPY(q,b,1);
295 BE_COPY(q,b,2);
296 BE_COPY(q,b,3);
297 q+=4;
298 b+=4*sizeof(SHA_LONG);
299 }
300 sha1_block(c,p,1);
301 return;
280 } 302 }
281#endif 303#endif
282#else 304#endif
283 q=p; 305#ifndef SHA_NO_TAIL_CODE /* defined above, see comment */
284 for (i=(SHA_LBLOCK/4); i; i--)
285 { 306 {
286 ULONG l; 307 SHA_LONG *q;
287 c2nl(b,l); *(q++)=l; 308 int i;
288 c2nl(b,l); *(q++)=l; 309
289 c2nl(b,l); *(q++)=l; 310 q=p;
290 c2nl(b,l); *(q++)=l; 311 for (i=(SHA_LBLOCK/4); i; i--)
291 } 312 {
313 SHA_LONG l;
314 c2nl(b,l); *(q++)=l;
315 c2nl(b,l); *(q++)=l;
316 c2nl(b,l); *(q++)=l;
317 c2nl(b,l); *(q++)=l;
318 }
319 sha1_block(c,p,1);
320 }
292#endif 321#endif
293 sha1_block(c,p,64);
294 } 322 }
295 323
296#ifndef SHA1_ASM 324#ifndef SHA1_ASM
297 325static void sha1_block(SHA_CTX *c, register SHA_LONG *W, int num)
298void sha1_block(c, W, num)
299SHA_CTX *c;
300register unsigned long *W;
301int num;
302 { 326 {
303 register ULONG A,B,C,D,E,T; 327 register SHA_LONG A,B,C,D,E,T;
304 ULONG X[16]; 328 SHA_LONG X[SHA_LBLOCK];
305 329
306 A=c->h0; 330 A=c->h0;
307 B=c->h1; 331 B=c->h1;
@@ -401,8 +425,7 @@ int num;
401 c->h3=(c->h3+B)&0xffffffffL; 425 c->h3=(c->h3+B)&0xffffffffL;
402 c->h4=(c->h4+C)&0xffffffffL; 426 c->h4=(c->h4+C)&0xffffffffL;
403 427
404 num-=64; 428 if (--num <= 0) break;
405 if (num <= 0) break;
406 429
407 A=c->h0; 430 A=c->h0;
408 B=c->h1; 431 B=c->h1;
@@ -410,18 +433,21 @@ int num;
410 D=c->h3; 433 D=c->h3;
411 E=c->h4; 434 E=c->h4;
412 435
413 W+=16; 436 W+=SHA_LBLOCK; /* Note! This can happen only when sizeof(SHA_LONG)
437 * is 4. Whenever it's not the actual case this
438 * function is never called with num larger than 1
439 * and we never advance down here.
440 * <appro@fy.chalmers.se>
441 */
414 } 442 }
415 } 443 }
416#endif 444#endif
417 445
418void SHA1_Final(md, c) 446void SHA1_Final(unsigned char *md, SHA_CTX *c)
419unsigned char *md;
420SHA_CTX *c;
421 { 447 {
422 register int i,j; 448 register int i,j;
423 register ULONG l; 449 register SHA_LONG l;
424 register ULONG *p; 450 register SHA_LONG *p;
425 static unsigned char end[4]={0x80,0x00,0x00,0x00}; 451 static unsigned char end[4]={0x80,0x00,0x00,0x00};
426 unsigned char *cp=end; 452 unsigned char *cp=end;
427 453
@@ -441,18 +467,20 @@ SHA_CTX *c;
441 { 467 {
442 for (; i<SHA_LBLOCK; i++) 468 for (; i<SHA_LBLOCK; i++)
443 p[i]=0; 469 p[i]=0;
444 sha1_block(c,p,64); 470 sha1_block(c,p,1);
445 i=0; 471 i=0;
446 } 472 }
447 for (; i<(SHA_LBLOCK-2); i++) 473 for (; i<(SHA_LBLOCK-2); i++)
448 p[i]=0; 474 p[i]=0;
449 p[SHA_LBLOCK-2]=c->Nh; 475 p[SHA_LBLOCK-2]=c->Nh;
450 p[SHA_LBLOCK-1]=c->Nl; 476 p[SHA_LBLOCK-1]=c->Nl;
451#if defined(L_ENDIAN) && defined(SHA1_ASM) 477#if SHA_LONG_LOG2==2
478#if !defined(B_ENDIAN) && defined(SHA1_ASM)
452 Endian_Reverse32(p[SHA_LBLOCK-2]); 479 Endian_Reverse32(p[SHA_LBLOCK-2]);
453 Endian_Reverse32(p[SHA_LBLOCK-1]); 480 Endian_Reverse32(p[SHA_LBLOCK-1]);
454#endif 481#endif
455 sha1_block(c,p,64); 482#endif
483 sha1_block(c,p,1);
456 cp=md; 484 cp=md;
457 l=c->h0; nl2c(l,cp); 485 l=c->h0; nl2c(l,cp);
458 l=c->h1; nl2c(l,cp); 486 l=c->h1; nl2c(l,cp);
@@ -460,9 +488,11 @@ SHA_CTX *c;
460 l=c->h3; nl2c(l,cp); 488 l=c->h3; nl2c(l,cp);
461 l=c->h4; nl2c(l,cp); 489 l=c->h4; nl2c(l,cp);
462 490
463 /* clear stuff, sha1_block may be leaving some stuff on the stack
464 * but I'm not worried :-) */
465 c->num=0; 491 c->num=0;
466/* memset((char *)&c,0,sizeof(c));*/ 492 /* sha_block may be leaving some stuff on the stack
493 * but I'm not worried :-)
494 memset((void *)c,0,sizeof(SHA_CTX));
495 */
467 } 496 }
497#endif
468 498
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)
32 32
33#include <stdio.h> 33#include <stdio.h>
34#include <stdlib.h> 34#include <stdlib.h>
35#include "sha.h" 35#include <openssl/sha.h>
36 36
37extern "C" { 37extern "C" {
38void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num); 38void 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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include "sha.h" 62
63#ifdef NO_SHA
64int main(int argc, char *argv[])
65{
66 printf("No SHA support\n");
67 return(0);
68}
69#else
70#include <openssl/sha.h>
71
72#ifdef CHARSET_EBCDIC
73#include <openssl/ebcdic.h>
74#endif
63 75
64#undef SHA_0 /* FIPS 180 */ 76#undef SHA_0 /* FIPS 180 */
65#define SHA_1 /* FIPS 180-1 */ 77#define SHA_1 /* FIPS 180-1 */
@@ -87,15 +99,8 @@ char *bigret=
87 "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; 99 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
88#endif 100#endif
89 101
90#ifndef NOPROTO
91static char *pt(unsigned char *md); 102static char *pt(unsigned char *md);
92#else 103int main(int argc, char *argv[])
93static char *pt();
94#endif
95
96int main(argc,argv)
97int argc;
98char *argv[];
99 { 104 {
100 int i,err=0; 105 int i,err=0;
101 unsigned char **P,**R; 106 unsigned char **P,**R;
@@ -104,6 +109,11 @@ char *argv[];
104 SHA_CTX c; 109 SHA_CTX c;
105 unsigned char md[SHA_DIGEST_LENGTH]; 110 unsigned char md[SHA_DIGEST_LENGTH];
106 111
112#ifdef CHARSET_EBCDIC
113 ebcdic2ascii(test[0], test[0], strlen(test[0]));
114 ebcdic2ascii(test[1], test[1], strlen(test[1]));
115#endif
116
107 P=(unsigned char **)test; 117 P=(unsigned char **)test;
108 R=(unsigned char **)ret; 118 R=(unsigned char **)ret;
109 i=1; 119 i=1;
@@ -124,6 +134,9 @@ char *argv[];
124 } 134 }
125 135
126 memset(buf,'a',1000); 136 memset(buf,'a',1000);
137#ifdef CHARSET_EBCDIC
138 ebcdic2ascii(buf, buf, 1000);
139#endif /*CHARSET_EBCDIC*/
127 SHA1_Init(&c); 140 SHA1_Init(&c);
128 for (i=0; i<1000; i++) 141 for (i=0; i<1000; i++)
129 SHA1_Update(&c,buf,1000); 142 SHA1_Update(&c,buf,1000);
@@ -143,8 +156,7 @@ char *argv[];
143 return(0); 156 return(0);
144 } 157 }
145 158
146static char *pt(md) 159static char *pt(unsigned char *md)
147unsigned char *md;
148 { 160 {
149 int i; 161 int i;
150 static char buf[80]; 162 static char buf[80];
@@ -153,3 +165,4 @@ unsigned char *md;
153 sprintf(&(buf[i*2]),"%02x",md[i]); 165 sprintf(&(buf[i*2]),"%02x",md[i]);
154 return(buf); 166 return(buf);
155 } 167 }
168#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 @@
60#include <string.h> 60#include <string.h>
61#define SHA_0 61#define SHA_0
62#undef SHA_1 62#undef SHA_1
63#include "sha.h" 63#include <openssl/sha.h>
64#include "sha_locl.h" 64#include "sha_locl.h"
65#include <openssl/opensslv.h>
65 66
66char *SHA_version="SHA part of SSLeay 0.9.0b 29-Jun-1998"; 67#ifndef NO_SHA0
68char *SHA_version="SHA" OPENSSL_VERSION_PTEXT;
67 69
68/* Implemented from SHA-0 document - The Secure Hash Algorithm 70/* Implemented from SHA-0 document - The Secure Hash Algorithm
69 */ 71 */
70 72
71#define INIT_DATA_h0 (unsigned long)0x67452301L 73#define INIT_DATA_h0 0x67452301UL
72#define INIT_DATA_h1 (unsigned long)0xefcdab89L 74#define INIT_DATA_h1 0xefcdab89UL
73#define INIT_DATA_h2 (unsigned long)0x98badcfeL 75#define INIT_DATA_h2 0x98badcfeUL
74#define INIT_DATA_h3 (unsigned long)0x10325476L 76#define INIT_DATA_h3 0x10325476UL
75#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L 77#define INIT_DATA_h4 0xc3d2e1f0UL
76 78
77#define K_00_19 0x5a827999L 79#define K_00_19 0x5a827999UL
78#define K_20_39 0x6ed9eba1L 80#define K_20_39 0x6ed9eba1UL
79#define K_40_59 0x8f1bbcdcL 81#define K_40_59 0x8f1bbcdcUL
80#define K_60_79 0xca62c1d6L 82#define K_60_79 0xca62c1d6UL
81 83
82#ifndef NOPROTO 84static void sha_block(SHA_CTX *c, register SHA_LONG *p, int num);
83 void sha_block(SHA_CTX *c, register unsigned long *p, int num); 85
86#if !defined(B_ENDIAN) && defined(SHA_ASM)
87# define M_c2nl c2l
88# define M_p_c2nl p_c2l
89# define M_c2nl_p c2l_p
90# define M_p_c2nl_p p_c2l_p
91# define M_nl2c l2c
84#else 92#else
85 void sha_block(); 93# define M_c2nl c2nl
94# define M_p_c2nl p_c2nl
95# define M_c2nl_p c2nl_p
96# define M_p_c2nl_p p_c2nl_p
97# define M_nl2c nl2c
86#endif 98#endif
87 99
88#define M_c2nl c2nl 100void SHA_Init(SHA_CTX *c)
89#define M_p_c2nl p_c2nl
90#define M_c2nl_p c2nl_p
91#define M_p_c2nl_p p_c2nl_p
92#define M_nl2c nl2c
93
94void SHA_Init(c)
95SHA_CTX *c;
96 { 101 {
97 c->h0=INIT_DATA_h0; 102 c->h0=INIT_DATA_h0;
98 c->h1=INIT_DATA_h1; 103 c->h1=INIT_DATA_h1;
@@ -104,14 +109,12 @@ SHA_CTX *c;
104 c->num=0; 109 c->num=0;
105 } 110 }
106 111
107void SHA_Update(c, data, len) 112void SHA_Update(SHA_CTX *c, register const unsigned char *data,
108SHA_CTX *c; 113 unsigned long len)
109register unsigned char *data;
110unsigned long len;
111 { 114 {
112 register ULONG *p; 115 register SHA_LONG *p;
113 int ew,ec,sw,sc; 116 int ew,ec,sw,sc;
114 ULONG l; 117 SHA_LONG l;
115 118
116 if (len == 0) return; 119 if (len == 0) return;
117 120
@@ -139,7 +142,7 @@ unsigned long len;
139 } 142 }
140 len-=(SHA_CBLOCK-c->num); 143 len-=(SHA_CBLOCK-c->num);
141 144
142 sha_block(c,p,64); 145 sha_block(c,p,1);
143 c->num=0; 146 c->num=0;
144 /* drop through and do the rest */ 147 /* drop through and do the rest */
145 } 148 }
@@ -176,15 +179,15 @@ unsigned long len;
176 * copies it to a local array. I should be able to do this for 179 * copies it to a local array. I should be able to do this for
177 * the C version as well.... 180 * the C version as well....
178 */ 181 */
179#if 1 182#if SHA_LONG_LOG2==2
180#if defined(B_ENDIAN) || defined(SHA_ASM) 183#if defined(B_ENDIAN) || defined(SHA_ASM)
181 if ((((unsigned int)data)%sizeof(ULONG)) == 0) 184 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
182 { 185 {
183 sw=len/SHA_CBLOCK; 186 sw=len/SHA_CBLOCK;
184 if (sw) 187 if (sw)
185 { 188 {
189 sha_block(c,(SHA_LONG *)data,sw);
186 sw*=SHA_CBLOCK; 190 sw*=SHA_CBLOCK;
187 sha_block(c,(ULONG *)data,sw);
188 data+=sw; 191 data+=sw;
189 len-=sw; 192 len-=sw;
190 } 193 }
@@ -196,35 +199,61 @@ unsigned long len;
196 p=c->data; 199 p=c->data;
197 while (len >= SHA_CBLOCK) 200 while (len >= SHA_CBLOCK)
198 { 201 {
199#if defined(B_ENDIAN) || defined(L_ENDIAN) 202#if SHA_LONG_LOG2==2
200 if (p != (unsigned long *)data) 203#if defined(B_ENDIAN) || defined(SHA_ASM)
204#define SHA_NO_TAIL_CODE
205 /*
206 * Basically we get here only when data happens
207 * to be unaligned.
208 */
209 if (p != (SHA_LONG *)data)
201 memcpy(p,data,SHA_CBLOCK); 210 memcpy(p,data,SHA_CBLOCK);
202 data+=SHA_CBLOCK; 211 data+=SHA_CBLOCK;
203# ifdef L_ENDIAN 212 sha_block(c,p=c->data,1);
204# ifndef SHA_ASM /* Will not happen */ 213 len-=SHA_CBLOCK;
205 for (sw=(SHA_LBLOCK/4); sw; sw--) 214#elif defined(L_ENDIAN)
215#define BE_COPY(dst,src,i) { \
216 l = ((SHA_LONG *)src)[i]; \
217 Endian_Reverse32(l); \
218 dst[i] = l; \
219 }
220 if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
206 { 221 {
207 Endian_Reverse32(p[0]); 222 for (sw=(SHA_LBLOCK/4); sw; sw--)
208 Endian_Reverse32(p[1]); 223 {
209 Endian_Reverse32(p[2]); 224 BE_COPY(p,data,0);
210 Endian_Reverse32(p[3]); 225 BE_COPY(p,data,1);
211 p+=4; 226 BE_COPY(p,data,2);
227 BE_COPY(p,data,3);
228 p+=4;
229 data += 4*sizeof(SHA_LONG);
230 }
231 sha_block(c,p=c->data,1);
232 len-=SHA_CBLOCK;
233 continue;
212 } 234 }
235#endif
236#endif
237#ifndef SHA_NO_TAIL_CODE
238 /*
239 * In addition to "sizeof(SHA_LONG)!= 4" case the
240 * following code covers unaligned access cases on
241 * little-endian machines.
242 * <appro@fy.chalmers.se>
243 */
213 p=c->data; 244 p=c->data;
214# endif 245 for (sw=(SHA_LBLOCK/4); sw; sw--)
215# endif
216#else
217 for (sw=(SHA_BLOCK/4); sw; sw--)
218 { 246 {
219 M_c2nl(data,l); *(p++)=l; 247 M_c2nl(data,l); p[0]=l;
220 M_c2nl(data,l); *(p++)=l; 248 M_c2nl(data,l); p[1]=l;
221 M_c2nl(data,l); *(p++)=l; 249 M_c2nl(data,l); p[2]=l;
222 M_c2nl(data,l); *(p++)=l; 250 M_c2nl(data,l); p[3]=l;
251 p+=4;
223 } 252 }
224 p=c->data; 253 p=c->data;
225#endif 254 sha_block(c,p,1);
226 sha_block(c,p,64);
227 len-=SHA_CBLOCK; 255 len-=SHA_CBLOCK;
256#endif
228 } 257 }
229 ec=(int)len; 258 ec=(int)len;
230 c->num=ec; 259 c->num=ec;
@@ -237,50 +266,61 @@ unsigned long len;
237 p[sw]=l; 266 p[sw]=l;
238 } 267 }
239 268
240void SHA_Transform(c,b) 269void SHA_Transform(SHA_CTX *c, unsigned char *b)
241SHA_CTX *c;
242unsigned char *b;
243 { 270 {
244 ULONG p[16]; 271 SHA_LONG p[SHA_LBLOCK];
245#if !defined(B_ENDIAN)
246 ULONG *q;
247 int i;
248#endif
249 272
250#if defined(B_ENDIAN) || defined(L_ENDIAN) 273#if SHA_LONG_LOG2==2
251 memcpy(p,b,64); 274#if defined(B_ENDIAN) || defined(SHA_ASM)
252#ifdef L_ENDIAN 275 memcpy(p,b,SHA_CBLOCK);
253 q=p; 276 sha_block(c,p,1);
254 for (i=(SHA_LBLOCK/4); i; i--) 277 return;
278#elif defined(L_ENDIAN)
279 if (((unsigned long)b%sizeof(SHA_LONG)) == 0)
255 { 280 {
256 Endian_Reverse32(q[0]); 281 SHA_LONG *q;
257 Endian_Reverse32(q[1]); 282 int i;
258 Endian_Reverse32(q[2]); 283
259 Endian_Reverse32(q[3]); 284 q=p;
260 q+=4; 285 for (i=(SHA_LBLOCK/4); i; i--)
286 {
287 unsigned long l;
288 BE_COPY(q,b,0); /* BE_COPY was defined above */
289 BE_COPY(q,b,1);
290 BE_COPY(q,b,2);
291 BE_COPY(q,b,3);
292 q+=4;
293 b+=4*sizeof(SHA_LONG);
294 }
295 sha_block(c,p,1);
296 return;
261 } 297 }
262#endif 298#endif
263#else 299#endif
264 q=p; 300#ifndef SHA_NO_TAIL_CODE /* defined above, see comment */
265 for (i=(SHA_LBLOCK/4); i; i--)
266 { 301 {
267 ULONG l; 302 SHA_LONG *q;
268 c2nl(b,l); *(q++)=l; 303 int i;
269 c2nl(b,l); *(q++)=l; 304
270 c2nl(b,l); *(q++)=l; 305 q=p;
271 c2nl(b,l); *(q++)=l; 306 for (i=(SHA_LBLOCK/4); i; i--)
272 } 307 {
308 SHA_LONG l;
309 c2nl(b,l); *(q++)=l;
310 c2nl(b,l); *(q++)=l;
311 c2nl(b,l); *(q++)=l;
312 c2nl(b,l); *(q++)=l;
313 }
314 sha_block(c,p,1);
315 }
273#endif 316#endif
274 sha_block(c,p,64);
275 } 317 }
276 318
277void sha_block(c, W, num) 319#ifndef SHA_ASM
278SHA_CTX *c; 320static void sha_block(SHA_CTX *c, register SHA_LONG *W, int num)
279register unsigned long *W;
280int num;
281 { 321 {
282 register ULONG A,B,C,D,E,T; 322 register SHA_LONG A,B,C,D,E,T;
283 ULONG X[16]; 323 SHA_LONG X[SHA_LBLOCK];
284 324
285 A=c->h0; 325 A=c->h0;
286 B=c->h1; 326 B=c->h1;
@@ -380,8 +420,7 @@ int num;
380 c->h3=(c->h3+B)&0xffffffffL; 420 c->h3=(c->h3+B)&0xffffffffL;
381 c->h4=(c->h4+C)&0xffffffffL; 421 c->h4=(c->h4+C)&0xffffffffL;
382 422
383 num-=64; 423 if (--num <= 0) break;
384 if (num <= 0) break;
385 424
386 A=c->h0; 425 A=c->h0;
387 B=c->h1; 426 B=c->h1;
@@ -389,17 +428,21 @@ int num;
389 D=c->h3; 428 D=c->h3;
390 E=c->h4; 429 E=c->h4;
391 430
392 W+=16; 431 W+=SHA_LBLOCK; /* Note! This can happen only when sizeof(SHA_LONG)
432 * is 4. Whenever it's not the actual case this
433 * function is never called with num larger than 1
434 * and we never advance down here.
435 * <appro@fy.chalmers.se>
436 */
393 } 437 }
394 } 438 }
439#endif
395 440
396void SHA_Final(md, c) 441void SHA_Final(unsigned char *md, SHA_CTX *c)
397unsigned char *md;
398SHA_CTX *c;
399 { 442 {
400 register int i,j; 443 register int i,j;
401 register ULONG l; 444 register SHA_LONG l;
402 register ULONG *p; 445 register SHA_LONG *p;
403 static unsigned char end[4]={0x80,0x00,0x00,0x00}; 446 static unsigned char end[4]={0x80,0x00,0x00,0x00};
404 unsigned char *cp=end; 447 unsigned char *cp=end;
405 448
@@ -419,14 +462,20 @@ SHA_CTX *c;
419 { 462 {
420 for (; i<SHA_LBLOCK; i++) 463 for (; i<SHA_LBLOCK; i++)
421 p[i]=0; 464 p[i]=0;
422 sha_block(c,p,64); 465 sha_block(c,p,1);
423 i=0; 466 i=0;
424 } 467 }
425 for (; i<(SHA_LBLOCK-2); i++) 468 for (; i<(SHA_LBLOCK-2); i++)
426 p[i]=0; 469 p[i]=0;
427 p[SHA_LBLOCK-2]=c->Nh; 470 p[SHA_LBLOCK-2]=c->Nh;
428 p[SHA_LBLOCK-1]=c->Nl; 471 p[SHA_LBLOCK-1]=c->Nl;
429 sha_block(c,p,64); 472#if SHA_LONG_LOG2==2
473#if !defined(B_ENDIAN) && defined(SHA_ASM)
474 Endian_Reverse32(p[SHA_LBLOCK-2]);
475 Endian_Reverse32(p[SHA_LBLOCK-1]);
476#endif
477#endif
478 sha_block(c,p,1);
430 cp=md; 479 cp=md;
431 l=c->h0; nl2c(l,cp); 480 l=c->h0; nl2c(l,cp);
432 l=c->h1; nl2c(l,cp); 481 l=c->h1; nl2c(l,cp);
@@ -434,9 +483,10 @@ SHA_CTX *c;
434 l=c->h3; nl2c(l,cp); 483 l=c->h3; nl2c(l,cp);
435 l=c->h4; nl2c(l,cp); 484 l=c->h4; nl2c(l,cp);
436 485
437 /* clear stuff, sha_block may be leaving some stuff on the stack
438 * but I'm not worried :-) */
439 c->num=0; 486 c->num=0;
440/* memset((char *)&c,0,sizeof(c));*/ 487 /* sha_block may be leaving some stuff on the stack
488 * but I'm not worried :-)
489 memset((void *)c,0,sizeof(SHA_CTX));
490 */
441 } 491 }
442 492#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 @@
59#include <stdlib.h> 59#include <stdlib.h>
60#include <string.h> 60#include <string.h>
61 61
62#include <openssl/opensslconf.h>
63
62#ifdef undef 64#ifdef undef
63/* one or the other needs to be defined */ 65/* one or the other needs to be defined */
64#ifndef SHA_1 /* FIPE 180-1 */ 66#ifndef SHA_1 /* FIPE 180-1 */
@@ -66,14 +68,6 @@
66#endif 68#endif
67#endif 69#endif
68 70
69#define ULONG unsigned long
70#define UCHAR unsigned char
71#define UINT unsigned int
72
73#ifdef NOCONST
74#define const
75#endif
76
77#undef c2nl 71#undef c2nl
78#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ 72#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
79 l|=(((unsigned long)(*((c)++)))<<16), \ 73 l|=(((unsigned long)(*((c)++)))<<16), \
@@ -166,30 +160,79 @@
166 *((c)++)=(unsigned char)(((l)>>16)&0xff), \ 160 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
167 *((c)++)=(unsigned char)(((l)>>24)&0xff)) 161 *((c)++)=(unsigned char)(((l)>>24)&0xff))
168 162
163#ifndef SHA_LONG_LOG2
164#define SHA_LONG_LOG2 2 /* default to 32 bits */
165#endif
166
169#undef ROTATE 167#undef ROTATE
168#undef Endian_Reverse32
170#if defined(WIN32) 169#if defined(WIN32)
171#define ROTATE(a,n) _lrotl(a,n) 170#define ROTATE(a,n) _lrotl(a,n)
172#else 171#elif defined(__GNUC__) && !defined(PEDANTIC)
173#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) 172/* some inline assembler templates by <appro@fy.chalmers.se> */
173#if defined(__i386) && !defined(NO_ASM)
174#define ROTATE(a,n) ({ register unsigned int ret; \
175 asm ("roll %1,%0" \
176 : "=r"(ret) \
177 : "I"(n), "0"(a) \
178 : "cc"); \
179 ret; \
180 })
181#ifndef I386_ONLY
182#define Endian_Reverse32(a) \
183 { register unsigned int ltmp=(a); \
184 asm ("bswapl %0" \
185 : "=r"(ltmp) : "0"(ltmp)); \
186 (a)=ltmp; \
187 }
188#endif
189#elif defined(__powerpc)
190#define ROTATE(a,n) ({ register unsigned int ret; \
191 asm ("rlwinm %0,%1,%2,0,31" \
192 : "=r"(ret) \
193 : "r"(a), "I"(n)); \
194 ret; \
195 })
196/* Endian_Reverse32 is not needed for PowerPC */
197#endif
174#endif 198#endif
175 199
176/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ 200/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
177#if defined(WIN32) 201#ifdef ROTATE
202#ifndef Endian_Reverse32
178/* 5 instructions with rotate instruction, else 9 */ 203/* 5 instructions with rotate instruction, else 9 */
179#define Endian_Reverse32(a) \ 204#define Endian_Reverse32(a) \
180 { \ 205 { \
181 unsigned long l=(a); \ 206 unsigned long t=(a); \
182 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ 207 (a)=((ROTATE(t,8)&0x00FF00FF)|(ROTATE((t&0x00FF00FF),24))); \
183 } 208 }
209#endif
184#else 210#else
211#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
212#ifndef Endian_Reverse32
185/* 6 instructions with rotate instruction, else 8 */ 213/* 6 instructions with rotate instruction, else 8 */
186#define Endian_Reverse32(a) \ 214#define Endian_Reverse32(a) \
187 { \ 215 { \
188 unsigned long l=(a); \ 216 unsigned long t=(a); \
189 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ 217 t=(((t>>8)&0x00FF00FF)|((t&0x00FF00FF)<<8)); \
190 (a)=ROTATE(l,16L); \ 218 (a)=ROTATE(t,16); \
191 } 219 }
192#endif 220#endif
221/*
222 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
223 * It's rewritten as above for two reasons:
224 * - RISCs aren't good at long constants and have to explicitely
225 * compose 'em with several (well, usually 2) instructions in a
226 * register before performing the actual operation and (as you
227 * already realized:-) having same constant should inspire the
228 * compiler to permanently allocate the only register for it;
229 * - most modern CPUs have two ALUs, but usually only one has
230 * circuitry for shifts:-( this minor tweak inspires compiler
231 * to schedule shift instructions in a better way...
232 *
233 * <appro@fy.chalmers.se>
234 */
235#endif
193 236
194/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be 237/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
195 * simplified to the code in F_00_19. Wei attributes these optimisations 238 * simplified to the code in F_00_19. Wei attributes these optimisations
@@ -203,13 +246,12 @@
203#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) 246#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
204#define F_60_79(b,c,d) F_20_39(b,c,d) 247#define F_60_79(b,c,d) F_20_39(b,c,d)
205 248
206#ifdef SHA_0
207#undef Xupdate 249#undef Xupdate
250#ifdef SHA_0
208#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\ 251#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\
209 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]); 252 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);
210#endif 253#endif
211#ifdef SHA_1 254#ifdef SHA_1
212#undef Xupdate
213#define Xupdate(a,i,ia,ib,ic,id) (a)=\ 255#define Xupdate(a,i,ia,ib,ic,id) (a)=\
214 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\ 256 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\
215 X[(i)&0x0f]=(a)=ROTATE((a),1); 257 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "sha.h" 61#include <openssl/sha.h>
62 62
63unsigned char *SHA(d, n, md) 63#ifndef NO_SHA0
64unsigned char *d; 64unsigned char *SHA(const unsigned char *d, unsigned long n, unsigned char *md)
65unsigned long n;
66unsigned char *md;
67 { 65 {
68 SHA_CTX c; 66 SHA_CTX c;
69 static unsigned char m[SHA_DIGEST_LENGTH]; 67 static unsigned char m[SHA_DIGEST_LENGTH];
@@ -75,3 +73,4 @@ unsigned char *md;
75 memset(&c,0,sizeof(c)); 73 memset(&c,0,sizeof(c));
76 return(md); 74 return(md);
77 } 75 }
76#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 @@
1/* crypto/sha/sha_sgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60#include <string.h>
61
62#ifdef undef
63/* one or the other needs to be defined */
64#ifndef SHA_1 /* FIPE 180-1 */
65#define SHA_0 /* FIPS 180 */
66#endif
67#endif
68
69#define ULONG unsigned long
70#define UCHAR unsigned char
71#define UINT unsigned int
72
73#ifdef NOCONST
74#define const
75#endif
76
77#undef c2nl
78#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
79 l|=(((unsigned long)(*((c)++)))<<16), \
80 l|=(((unsigned long)(*((c)++)))<< 8), \
81 l|=(((unsigned long)(*((c)++))) ))
82
83#undef p_c2nl
84#define p_c2nl(c,l,n) { \
85 switch (n) { \
86 case 0: l =((unsigned long)(*((c)++)))<<24; \
87 case 1: l|=((unsigned long)(*((c)++)))<<16; \
88 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
89 case 3: l|=((unsigned long)(*((c)++))); \
90 } \
91 }
92
93#undef c2nl_p
94/* NOTE the pointer is not incremented at the end of this */
95#define c2nl_p(c,l,n) { \
96 l=0; \
97 (c)+=n; \
98 switch (n) { \
99 case 3: l =((unsigned long)(*(--(c))))<< 8; \
100 case 2: l|=((unsigned long)(*(--(c))))<<16; \
101 case 1: l|=((unsigned long)(*(--(c))))<<24; \
102 } \
103 }
104
105#undef p_c2nl_p
106#define p_c2nl_p(c,l,sc,len) { \
107 switch (sc) \
108 { \
109 case 0: l =((unsigned long)(*((c)++)))<<24; \
110 if (--len == 0) break; \
111 case 1: l|=((unsigned long)(*((c)++)))<<16; \
112 if (--len == 0) break; \
113 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
114 } \
115 }
116
117#undef nl2c
118#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
119 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
120 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
121 *((c)++)=(unsigned char)(((l) )&0xff))
122
123#undef c2l
124#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
125 l|=(((unsigned long)(*((c)++)))<< 8), \
126 l|=(((unsigned long)(*((c)++)))<<16), \
127 l|=(((unsigned long)(*((c)++)))<<24))
128
129#undef p_c2l
130#define p_c2l(c,l,n) { \
131 switch (n) { \
132 case 0: l =((unsigned long)(*((c)++))); \
133 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
134 case 2: l|=((unsigned long)(*((c)++)))<<16; \
135 case 3: l|=((unsigned long)(*((c)++)))<<24; \
136 } \
137 }
138
139#undef c2l_p
140/* NOTE the pointer is not incremented at the end of this */
141#define c2l_p(c,l,n) { \
142 l=0; \
143 (c)+=n; \
144 switch (n) { \
145 case 3: l =((unsigned long)(*(--(c))))<<16; \
146 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
147 case 1: l|=((unsigned long)(*(--(c)))); \
148 } \
149 }
150
151#undef p_c2l_p
152#define p_c2l_p(c,l,sc,len) { \
153 switch (sc) \
154 { \
155 case 0: l =((unsigned long)(*((c)++))); \
156 if (--len == 0) break; \
157 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
158 if (--len == 0) break; \
159 case 2: l|=((unsigned long)(*((c)++)))<<16; \
160 } \
161 }
162
163#undef l2c
164#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
165 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
166 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
167 *((c)++)=(unsigned char)(((l)>>24)&0xff))
168
169#undef ROTATE
170#if defined(WIN32)
171#define ROTATE(a,n) _lrotl(a,n)
172#else
173#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
174#endif
175
176/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
177#if defined(WIN32)
178/* 5 instructions with rotate instruction, else 9 */
179#define Endian_Reverse32(a) \
180 { \
181 unsigned long l=(a); \
182 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \
183 }
184#else
185/* 6 instructions with rotate instruction, else 8 */
186#define Endian_Reverse32(a) \
187 { \
188 unsigned long l=(a); \
189 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \
190 (a)=ROTATE(l,16L); \
191 }
192#endif
193
194/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
195 * simplified to the code in F_00_19. Wei attributes these optimisations
196 * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel.
197 * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z)))
198 * I've just become aware of another tweak to be made, again from Wei Dai,
199 * in F_40_59, (x&a)|(y&a) -> (x|y)&a
200 */
201#define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d))
202#define F_20_39(b,c,d) ((b) ^ (c) ^ (d))
203#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
204#define F_60_79(b,c,d) F_20_39(b,c,d)
205
206#ifdef SHA_0
207#undef Xupdate
208#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\
209 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);
210#endif
211#ifdef SHA_1
212#undef Xupdate
213#define Xupdate(a,i,ia,ib,ic,id) (a)=\
214 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\
215 X[(i)&0x0f]=(a)=ROTATE((a),1);
216#endif
217
218#define BODY_00_15(i,a,b,c,d,e,f,xa) \
219 (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
220 (b)=ROTATE((b),30);
221
222#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \
223 Xupdate(f,i,xa,xb,xc,xd); \
224 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
225 (b)=ROTATE((b),30);
226
227#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \
228 Xupdate(f,i,xa,xb,xc,xd); \
229 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
230 (b)=ROTATE((b),30);
231
232#define BODY_32_39(i,a,b,c,d,e,f,xa) \
233 Xupdate(f,i,xa,xa,xa,xa); \
234 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
235 (b)=ROTATE((b),30);
236
237#define BODY_40_59(i,a,b,c,d,e,f,xa) \
238 Xupdate(f,i,xa,xa,xa,xa); \
239 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
240 (b)=ROTATE((b),30);
241
242#define BODY_60_79(i,a,b,c,d,e,f,xa) \
243 Xupdate(f,i,xa,xa,xa,xa); \
244 (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
245 (b)=ROTATE((b),30);
246
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 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include "sha.h" 62
63#ifdef NO_SHA
64int main(int argc, char *argv[])
65{
66 printf("No SHA support\n");
67 return(0);
68}
69#else
70#include <openssl/sha.h>
71
72#ifdef CHARSET_EBCDIC
73#include <openssl/ebcdic.h>
74#endif
63 75
64#define SHA_0 /* FIPS 180 */ 76#define SHA_0 /* FIPS 180 */
65#undef SHA_1 /* FIPS 180-1 */ 77#undef SHA_1 /* FIPS 180-1 */
@@ -87,15 +99,8 @@ char *bigret=
87 "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; 99 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
88#endif 100#endif
89 101
90#ifndef NOPROTO
91static char *pt(unsigned char *md); 102static char *pt(unsigned char *md);
92#else 103int main(int argc, char *argv[])
93static char *pt();
94#endif
95
96int main(argc,argv)
97int argc;
98char *argv[];
99 { 104 {
100 int i,err=0; 105 int i,err=0;
101 unsigned char **P,**R; 106 unsigned char **P,**R;
@@ -104,6 +109,11 @@ char *argv[];
104 SHA_CTX c; 109 SHA_CTX c;
105 unsigned char md[SHA_DIGEST_LENGTH]; 110 unsigned char md[SHA_DIGEST_LENGTH];
106 111
112#ifdef CHARSET_EBCDIC
113 ebcdic2ascii(test[0], test[0], strlen(test[0]));
114 ebcdic2ascii(test[1], test[1], strlen(test[1]));
115#endif
116
107 P=(unsigned char **)test; 117 P=(unsigned char **)test;
108 R=(unsigned char **)ret; 118 R=(unsigned char **)ret;
109 i=1; 119 i=1;
@@ -124,6 +134,9 @@ char *argv[];
124 } 134 }
125 135
126 memset(buf,'a',1000); 136 memset(buf,'a',1000);
137#ifdef CHARSET_EBCDIC
138 ebcdic2ascii(buf, buf, 1000);
139#endif /*CHARSET_EBCDIC*/
127 SHA_Init(&c); 140 SHA_Init(&c);
128 for (i=0; i<1000; i++) 141 for (i=0; i<1000; i++)
129 SHA_Update(&c,buf,1000); 142 SHA_Update(&c,buf,1000);
@@ -143,8 +156,7 @@ char *argv[];
143 return(0); 156 return(0);
144 } 157 }
145 158
146static char *pt(md) 159static char *pt(unsigned char *md)
147unsigned char *md;
148 { 160 {
149 int i; 161 int i;
150 static char buf[80]; 162 static char buf[80];
@@ -153,3 +165,4 @@ unsigned char *md;
153 sprintf(&(buf[i*2]),"%02x",md[i]); 165 sprintf(&(buf[i*2]),"%02x",md[i]);
154 return(buf); 166 return(buf);
155 } 167 }
168#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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -25,7 +27,7 @@ LIBOBJ=stack.o
25 27
26SRC= $(LIBSRC) 28SRC= $(LIBSRC)
27 29
28EXHEADER= stack.h 30EXHEADER= stack.h safestack.h
29HEADER= $(EXHEADER) 31HEADER= $(EXHEADER)
30 32
31ALL= $(GENERAL) $(SRC) $(HEADER) 33ALL= $(GENERAL) $(SRC) $(HEADER)
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,19 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81stack.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82stack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83stack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84stack.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
85stack.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 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_SAFESTACK_H
56#define HEADER_SAFESTACK_H
57
58#include <openssl/stack.h>
59
60#define STACK_OF(type) STACK_##type
61
62#define DECLARE_STACK_OF(type) \
63typedef struct stack_st_##type \
64 { \
65 STACK stack; \
66 } STACK_OF(type); \
67STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)); \
68STACK_OF(type) *sk_##type##_new_null(void); \
69void sk_##type##_free(STACK_OF(type) *sk); \
70int sk_##type##_num(const STACK_OF(type) *sk); \
71type *sk_##type##_value(const STACK_OF(type) *sk,int n); \
72type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v); \
73void sk_##type##_zero(STACK_OF(type) *sk); \
74int sk_##type##_push(STACK_OF(type) *sk,type *v); \
75int sk_##type##_unshift(STACK_OF(type) *sk,type *v); \
76int sk_##type##_find(STACK_OF(type) *sk,type *v); \
77type *sk_##type##_delete(STACK_OF(type) *sk,int n); \
78void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v); \
79int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n); \
80int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \
81 int (*cmp)(type **,type **)))(type **,type **); \
82STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk); \
83void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)); \
84type *sk_##type##_shift(STACK_OF(type) *sk); \
85type *sk_##type##_pop(STACK_OF(type) *sk); \
86void sk_##type##_sort(STACK_OF(type) *sk);
87
88#define IMPLEMENT_STACK_OF(type) \
89STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)) \
90 { return (STACK_OF(type) *)sk_new(cmp); } \
91STACK_OF(type) *sk_##type##_new_null() \
92 { return (STACK_OF(type) *)sk_new_null(); } \
93void sk_##type##_free(STACK_OF(type) *sk) \
94 { sk_free((STACK *)sk); } \
95int sk_##type##_num(const STACK_OF(type) *sk) \
96 { return M_sk_num((const STACK *)sk); } \
97type *sk_##type##_value(const STACK_OF(type) *sk,int n) \
98 { return (type *)sk_value((STACK *)sk,n); } \
99type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v) \
100 { return (type *)(sk_set((STACK *)sk,n,(char *)v)); } \
101void sk_##type##_zero(STACK_OF(type) *sk) \
102 { sk_zero((STACK *)sk); } \
103int sk_##type##_push(STACK_OF(type) *sk,type *v) \
104 { return sk_push((STACK *)sk,(char *)v); } \
105int sk_##type##_unshift(STACK_OF(type) *sk,type *v) \
106 { return sk_unshift((STACK *)sk,(char *)v); } \
107int sk_##type##_find(STACK_OF(type) *sk,type *v) \
108 { return sk_find((STACK *)sk,(char *)v); } \
109type *sk_##type##_delete(STACK_OF(type) *sk,int n) \
110 { return (type *)sk_delete((STACK *)sk,n); } \
111void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v) \
112 { sk_delete_ptr((STACK *)sk,(char *)v); } \
113int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n) \
114 { return sk_insert((STACK *)sk,(char *)v,n); } \
115int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \
116 int (*cmp)(type **,type **)))(type **,type **) \
117 { return (int (*)(type **,type **))sk_set_cmp_func((STACK *)sk,cmp); } \
118STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk) \
119 { return (STACK_OF(type) *)sk_dup((STACK *)sk); } \
120void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)) \
121 { sk_pop_free((STACK *)sk,func); } \
122type *sk_##type##_shift(STACK_OF(type) *sk) \
123 { return (type *)sk_shift((STACK *)sk); } \
124type *sk_##type##_pop(STACK_OF(type) *sk) \
125 { return (type *)sk_pop((STACK *)sk); } \
126void sk_##type##_sort(STACK_OF(type) *sk) \
127 { sk_sort((STACK *)sk); }
128
129#endif /* ndef HEADER_SAFESTACK_H */
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c
index 610ccbb756..8b96713884 100644
--- a/src/lib/libcrypto/stack/stack.c
+++ b/src/lib/libcrypto/stack/stack.c
@@ -67,32 +67,28 @@
67 */ 67 */
68#include <stdio.h> 68#include <stdio.h>
69#include "cryptlib.h" 69#include "cryptlib.h"
70#include "stack.h" 70#include <openssl/stack.h>
71 71
72#undef MIN_NODES 72#undef MIN_NODES
73#define MIN_NODES 4 73#define MIN_NODES 4
74 74
75char *STACK_version="STACK part of SSLeay 0.9.0b 29-Jun-1998"; 75const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT;
76 76
77#ifndef NOPROTO
78#define FP_ICC (int (*)(const void *,const void *)) 77#define FP_ICC (int (*)(const void *,const void *))
79#else
80#define FP_ICC
81#endif
82
83#include <errno.h> 78#include <errno.h>
84 79
85void sk_set_cmp_func(sk,c) 80int (*sk_set_cmp_func(STACK *sk, int (*c)()))(void)
86STACK *sk;
87int (*c)();
88 { 81 {
82 int (*old)()=sk->comp;
83
89 if (sk->comp != c) 84 if (sk->comp != c)
90 sk->sorted=0; 85 sk->sorted=0;
91 sk->comp=c; 86 sk->comp=c;
87
88 return old;
92 } 89 }
93 90
94STACK *sk_dup(sk) 91STACK *sk_dup(STACK *sk)
95STACK *sk;
96 { 92 {
97 STACK *ret; 93 STACK *ret;
98 char **s; 94 char **s;
@@ -113,8 +109,7 @@ err:
113 return(NULL); 109 return(NULL);
114 } 110 }
115 111
116STACK *sk_new(c) 112STACK *sk_new(int (*c)())
117int (*c)();
118 { 113 {
119 STACK *ret; 114 STACK *ret;
120 int i; 115 int i;
@@ -136,13 +131,11 @@ err0:
136 return(NULL); 131 return(NULL);
137 } 132 }
138 133
139int sk_insert(st,data,loc) 134int sk_insert(STACK *st, char *data, int loc)
140STACK *st;
141char *data;
142int loc;
143 { 135 {
144 char **s; 136 char **s;
145 137
138 if(st == NULL) return 0;
146 if (st->num_alloc <= st->num+1) 139 if (st->num_alloc <= st->num+1)
147 { 140 {
148 s=(char **)Realloc((char *)st->data, 141 s=(char **)Realloc((char *)st->data,
@@ -161,7 +154,7 @@ int loc;
161 154
162 f=(char **)st->data; 155 f=(char **)st->data;
163 t=(char **)&(st->data[1]); 156 t=(char **)&(st->data[1]);
164 for (i=st->num; i>loc; i--) 157 for (i=st->num; i>=loc; i--)
165 t[i]=f[i]; 158 t[i]=f[i];
166 159
167#ifdef undef /* no memmove on sunos :-( */ 160#ifdef undef /* no memmove on sunos :-( */
@@ -176,9 +169,7 @@ int loc;
176 return(st->num); 169 return(st->num);
177 } 170 }
178 171
179char *sk_delete_ptr(st,p) 172char *sk_delete_ptr(STACK *st, char *p)
180STACK *st;
181char *p;
182 { 173 {
183 int i; 174 int i;
184 175
@@ -188,14 +179,13 @@ char *p;
188 return(NULL); 179 return(NULL);
189 } 180 }
190 181
191char *sk_delete(st,loc) 182char *sk_delete(STACK *st, int loc)
192STACK *st;
193int loc;
194 { 183 {
195 char *ret; 184 char *ret;
196 int i,j; 185 int i,j;
197 186
198 if ((st->num == 0) || (loc < 0) || (loc >= st->num)) return(NULL); 187 if ((st == NULL) || (st->num == 0) || (loc < 0)
188 || (loc >= st->num)) return(NULL);
199 189
200 ret=st->data[loc]; 190 ret=st->data[loc];
201 if (loc != st->num-1) 191 if (loc != st->num-1)
@@ -213,13 +203,12 @@ int loc;
213 return(ret); 203 return(ret);
214 } 204 }
215 205
216int sk_find(st,data) 206int sk_find(STACK *st, char *data)
217STACK *st;
218char *data;
219 { 207 {
220 char **r; 208 char **r;
221 int i; 209 int i;
222 int (*comp_func)(); 210 int (*comp_func)();
211 if(st == NULL) return -1;
223 212
224 if (st->comp == NULL) 213 if (st->comp == NULL)
225 { 214 {
@@ -228,13 +217,9 @@ char *data;
228 return(i); 217 return(i);
229 return(-1); 218 return(-1);
230 } 219 }
231 comp_func=(int (*)())st->comp; 220 sk_sort(st);
232 if (!st->sorted)
233 {
234 qsort((char *)st->data,st->num,sizeof(char *),FP_ICC comp_func);
235 st->sorted=1;
236 }
237 if (data == NULL) return(-1); 221 if (data == NULL) return(-1);
222 comp_func=(int (*)())st->comp;
238 r=(char **)bsearch(&data,(char *)st->data, 223 r=(char **)bsearch(&data,(char *)st->data,
239 st->num,sizeof(char *),FP_ICC comp_func); 224 st->num,sizeof(char *),FP_ICC comp_func);
240 if (r == NULL) return(-1); 225 if (r == NULL) return(-1);
@@ -245,38 +230,31 @@ char *data;
245 return(i); 230 return(i);
246 } 231 }
247 232
248int sk_push(st,data) 233int sk_push(STACK *st, char *data)
249STACK *st;
250char *data;
251 { 234 {
252 return(sk_insert(st,data,st->num)); 235 return(sk_insert(st,data,st->num));
253 } 236 }
254 237
255int sk_unshift(st,data) 238int sk_unshift(STACK *st, char *data)
256STACK *st;
257char *data;
258 { 239 {
259 return(sk_insert(st,data,0)); 240 return(sk_insert(st,data,0));
260 } 241 }
261 242
262char *sk_shift(st) 243char *sk_shift(STACK *st)
263STACK *st;
264 { 244 {
265 if (st == NULL) return(NULL); 245 if (st == NULL) return(NULL);
266 if (st->num <= 0) return(NULL); 246 if (st->num <= 0) return(NULL);
267 return(sk_delete(st,0)); 247 return(sk_delete(st,0));
268 } 248 }
269 249
270char *sk_pop(st) 250char *sk_pop(STACK *st)
271STACK *st;
272 { 251 {
273 if (st == NULL) return(NULL); 252 if (st == NULL) return(NULL);
274 if (st->num <= 0) return(NULL); 253 if (st->num <= 0) return(NULL);
275 return(sk_delete(st,st->num-1)); 254 return(sk_delete(st,st->num-1));
276 } 255 }
277 256
278void sk_zero(st) 257void sk_zero(STACK *st)
279STACK *st;
280 { 258 {
281 if (st == NULL) return; 259 if (st == NULL) return;
282 if (st->num <= 0) return; 260 if (st->num <= 0) return;
@@ -284,9 +262,7 @@ STACK *st;
284 st->num=0; 262 st->num=0;
285 } 263 }
286 264
287void sk_pop_free(st,func) 265void sk_pop_free(STACK *st, void (*func)())
288STACK *st;
289void (*func)();
290 { 266 {
291 int i; 267 int i;
292 268
@@ -297,11 +273,39 @@ void (*func)();
297 sk_free(st); 273 sk_free(st);
298 } 274 }
299 275
300void sk_free(st) 276void sk_free(STACK *st)
301STACK *st;
302 { 277 {
303 if (st == NULL) return; 278 if (st == NULL) return;
304 if (st->data != NULL) Free((char *)st->data); 279 if (st->data != NULL) Free((char *)st->data);
305 Free((char *)st); 280 Free((char *)st);
306 } 281 }
307 282
283int sk_num(STACK *st)
284{
285 if(st == NULL) return -1;
286 return st->num;
287}
288
289char *sk_value(STACK *st, int i)
290{
291 if(st == NULL) return NULL;
292 return st->data[i];
293}
294
295char *sk_set(STACK *st, int i, char *value)
296{
297 if(st == NULL) return NULL;
298 return (st->data[i] = value);
299}
300
301void sk_sort(STACK *st)
302 {
303 if (!st->sorted)
304 {
305 int (*comp_func)();
306
307 comp_func=(int (*)())st->comp;
308 qsort(st->data,st->num,sizeof(char *),FP_ICC comp_func);
309 st->sorted=1;
310 }
311 }
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h
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
73 int (*comp)(); 73 int (*comp)();
74 } STACK; 74 } STACK;
75 75
76#define sk_num(sk) ((sk)->num)
77#define sk_value(sk,n) ((sk)->data[n])
78 76
79#define sk_new_null() sk_new(NULL) 77#define sk_new_null() sk_new(NULL)
80#ifndef NOPROTO 78
79#define M_sk_num(sk) ((sk)->num)
80#define M_sk_value(sk,n) ((sk)->data[n])
81
82int sk_num(STACK *);
83char *sk_value(STACK *, int);
84
85char *sk_set(STACK *, int, char *);
81 86
82STACK *sk_new(int (*cmp)()); 87STACK *sk_new(int (*cmp)());
83void sk_free(STACK *); 88void sk_free(STACK *);
@@ -91,27 +96,9 @@ int sk_unshift(STACK *st,char *data);
91char *sk_shift(STACK *st); 96char *sk_shift(STACK *st);
92char *sk_pop(STACK *st); 97char *sk_pop(STACK *st);
93void sk_zero(STACK *st); 98void sk_zero(STACK *st);
94void sk_set_cmp_func(STACK *sk, int (*c)()); 99int (*sk_set_cmp_func(STACK *sk, int (*c)()))();
95STACK *sk_dup(STACK *st); 100STACK *sk_dup(STACK *st);
96 101void sk_sort(STACK *st);
97#else
98
99STACK *sk_new();
100void sk_free();
101void sk_pop_free();
102int sk_insert();
103char *sk_delete();
104char *sk_delete_ptr();
105int sk_find();
106int sk_push();
107int sk_unshift();
108char *sk_shift();
109char *sk_pop();
110void sk_zero();
111void sk_set_cmp_func();
112STACK *sk_dup();
113
114#endif
115 102
116#ifdef __cplusplus 103#ifdef __cplusplus
117} 104}
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 @@
74#include <ulocks.h> 74#include <ulocks.h>
75#include <sys/prctl.h> 75#include <sys/prctl.h>
76#endif 76#endif
77#include "lhash.h" 77#include <openssl/lhash.h>
78#include "crypto.h" 78#include <openssl/crypto.h>
79#include "buffer.h" 79#include <openssl/buffer.h>
80#include "../e_os.h" 80#include "../e_os.h"
81#include "x509.h" 81#include <openssl/x509.h>
82#include "ssl.h" 82#include <openssl/ssl.h>
83#include "err.h" 83#include <openssl/err.h>
84 84
85#ifdef NO_FP_API 85#ifdef NO_FP_API
86#define APPS_WIN16 86#define APPS_WIN16
@@ -92,7 +92,6 @@
92 92
93#define MAX_THREAD_NUMBER 100 93#define MAX_THREAD_NUMBER 100
94 94
95#ifndef NOPROTO
96int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, 95int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
97 int error,char *arg); 96 int error,char *arg);
98void thread_setup(void); 97void thread_setup(void);
@@ -108,23 +107,6 @@ unsigned long irix_thread_id(void );
108unsigned long solaris_thread_id(void ); 107unsigned long solaris_thread_id(void );
109unsigned long pthreads_thread_id(void ); 108unsigned long pthreads_thread_id(void );
110 109
111#else
112int MS_CALLBACK verify_callback();
113void thread_setup();
114void thread_cleanup();
115void do_threads();
116
117void irix_locking_callback();
118void solaris_locking_callback();
119void win32_locking_callback();
120void pthreads_locking_callback();
121
122unsigned long irix_thread_id();
123unsigned long solaris_thread_id();
124unsigned long pthreads_thread_id();
125
126#endif
127
128BIO *bio_err=NULL; 110BIO *bio_err=NULL;
129BIO *bio_stdout=NULL; 111BIO *bio_stdout=NULL;
130 112
@@ -139,15 +121,8 @@ int number_of_loops=10;
139int reconnect=0; 121int reconnect=0;
140int cache_stats=0; 122int cache_stats=0;
141 123
142#ifndef NOPROTO
143int doit(char *ctx[4]); 124int doit(char *ctx[4]);
144#else 125static void print_stats(FILE *fp, SSL_CTX *ctx)
145int doit();
146#endif
147
148static void print_stats(fp,ctx)
149FILE *fp;
150SSL_CTX *ctx;
151{ 126{
152 fprintf(fp,"%4ld items in the session cache\n", 127 fprintf(fp,"%4ld items in the session cache\n",
153 SSL_CTX_sess_number(ctx)); 128 SSL_CTX_sess_number(ctx));
@@ -164,7 +139,7 @@ SSL_CTX *ctx;
164 fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx)); 139 fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx));
165 } 140 }
166 141
167static void sv_usage() 142static void sv_usage(void)
168 { 143 {
169 fprintf(stderr,"usage: ssltest [args ...]\n"); 144 fprintf(stderr,"usage: ssltest [args ...]\n");
170 fprintf(stderr,"\n"); 145 fprintf(stderr,"\n");
@@ -182,9 +157,7 @@ static void sv_usage()
182 fprintf(stderr," -ssl3 - just SSLv3n\n"); 157 fprintf(stderr," -ssl3 - just SSLv3n\n");
183 } 158 }
184 159
185int main(argc, argv) 160int main(int argc, char *argv[])
186int argc;
187char *argv[];
188 { 161 {
189 char *CApath=NULL,*CAfile=NULL; 162 char *CApath=NULL,*CAfile=NULL;
190 int badop=0; 163 int badop=0;
@@ -358,8 +331,7 @@ end:
358#define C_DONE 1 331#define C_DONE 1
359#define S_DONE 2 332#define S_DONE 2
360 333
361int ndoit(ssl_ctx) 334int ndoit(SSL_CTX *ssl_ctx[2])
362SSL_CTX *ssl_ctx[2];
363 { 335 {
364 int i; 336 int i;
365 int ret; 337 int ret;
@@ -405,8 +377,7 @@ SSL_CTX *ssl_ctx[2];
405 return(0); 377 return(0);
406 } 378 }
407 379
408int doit(ctx) 380int doit(char *ctx[4])
409char *ctx[4];
410 { 381 {
411 SSL_CTX *s_ctx,*c_ctx; 382 SSL_CTX *s_ctx,*c_ctx;
412 static char cbuf[200],sbuf[200]; 383 static char cbuf[200],sbuf[200];
@@ -681,13 +652,8 @@ err:
681 return(0); 652 return(0);
682 } 653 }
683 654
684int MS_CALLBACK verify_callback(ok, xs, xi, depth, error, arg) 655int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth,
685int ok; 656 int error, char *arg)
686X509 *xs;
687X509 *xi;
688int depth;
689int error;
690char *arg;
691 { 657 {
692 char buf[256]; 658 char buf[256];
693 659
@@ -708,7 +674,7 @@ char *arg;
708 674
709static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; 675static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
710 676
711void thread_setup() 677void thread_setup(void)
712 { 678 {
713 int i; 679 int i;
714 680
@@ -721,7 +687,7 @@ void thread_setup()
721 /* id callback defined */ 687 /* id callback defined */
722 } 688 }
723 689
724void thread_cleanup() 690void thread_cleanup(void)
725 { 691 {
726 int i; 692 int i;
727 693
@@ -730,11 +696,7 @@ void thread_cleanup()
730 CloseHandle(lock_cs[i]); 696 CloseHandle(lock_cs[i]);
731 } 697 }
732 698
733void win32_locking_callback(mode,type,file,line) 699void win32_locking_callback(int mode, int type, char *file, int line)
734int mode;
735int type;
736char *file;
737int line;
738 { 700 {
739 if (mode & CRYPTO_LOCK) 701 if (mode & CRYPTO_LOCK)
740 { 702 {
@@ -746,8 +708,7 @@ int line;
746 } 708 }
747 } 709 }
748 710
749void do_threads(s_ctx,c_ctx) 711void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
750SSL_CTX *s_ctx,*c_ctx;
751 { 712 {
752 double ret; 713 double ret;
753 SSL_CTX *ssl_ctx[2]; 714 SSL_CTX *ssl_ctx[2];
@@ -806,7 +767,7 @@ static mutex_t lock_cs[CRYPTO_NUM_LOCKS];
806/*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */ 767/*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */
807static long lock_count[CRYPTO_NUM_LOCKS]; 768static long lock_count[CRYPTO_NUM_LOCKS];
808 769
809void thread_setup() 770void thread_setup(void)
810 { 771 {
811 int i; 772 int i;
812 773
@@ -821,7 +782,7 @@ void thread_setup()
821 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); 782 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
822 } 783 }
823 784
824void thread_cleanup() 785void thread_cleanup(void)
825 { 786 {
826 int i; 787 int i;
827 788
@@ -836,11 +797,7 @@ fprintf(stderr,"cleanup\n");
836fprintf(stderr,"done cleanup\n"); 797fprintf(stderr,"done cleanup\n");
837 } 798 }
838 799
839void solaris_locking_callback(mode,type,file,line) 800void solaris_locking_callback(int mode, int type, char *file, int line)
840int mode;
841int type;
842char *file;
843int line;
844 { 801 {
845#ifdef undef 802#ifdef undef
846fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", 803fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
@@ -872,8 +829,7 @@ if (CRYPTO_LOCK_SSL_CERT == type)
872 } 829 }
873 } 830 }
874 831
875void do_threads(s_ctx,c_ctx) 832void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
876SSL_CTX *s_ctx,*c_ctx;
877 { 833 {
878 SSL_CTX *ssl_ctx[2]; 834 SSL_CTX *ssl_ctx[2];
879 thread_t thread_ctx[MAX_THREAD_NUMBER]; 835 thread_t thread_ctx[MAX_THREAD_NUMBER];
@@ -902,7 +858,7 @@ SSL_CTX *s_ctx,*c_ctx;
902 s_ctx->references,c_ctx->references); 858 s_ctx->references,c_ctx->references);
903 } 859 }
904 860
905unsigned long solaris_thread_id() 861unsigned long solaris_thread_id(void)
906 { 862 {
907 unsigned long ret; 863 unsigned long ret;
908 864
@@ -917,7 +873,7 @@ unsigned long solaris_thread_id()
917static usptr_t *arena; 873static usptr_t *arena;
918static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; 874static usema_t *lock_cs[CRYPTO_NUM_LOCKS];
919 875
920void thread_setup() 876void thread_setup(void)
921 { 877 {
922 int i; 878 int i;
923 char filename[20]; 879 char filename[20];
@@ -941,7 +897,7 @@ void thread_setup()
941 CRYPTO_set_locking_callback((void (*)())irix_locking_callback); 897 CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
942 } 898 }
943 899
944void thread_cleanup() 900void thread_cleanup(void)
945 { 901 {
946 int i; 902 int i;
947 903
@@ -956,11 +912,7 @@ void thread_cleanup()
956 } 912 }
957 } 913 }
958 914
959void irix_locking_callback(mode,type,file,line) 915void irix_locking_callback(int mode, int type, char *file, int line)
960int mode;
961int type;
962char *file;
963int line;
964 { 916 {
965 if (mode & CRYPTO_LOCK) 917 if (mode & CRYPTO_LOCK)
966 { 918 {
@@ -974,8 +926,7 @@ int line;
974 } 926 }
975 } 927 }
976 928
977void do_threads(s_ctx,c_ctx) 929void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
978SSL_CTX *s_ctx,*c_ctx;
979 { 930 {
980 SSL_CTX *ssl_ctx[2]; 931 SSL_CTX *ssl_ctx[2];
981 int thread_ctx[MAX_THREAD_NUMBER]; 932 int thread_ctx[MAX_THREAD_NUMBER];
@@ -1000,7 +951,7 @@ SSL_CTX *s_ctx,*c_ctx;
1000 s_ctx->references,c_ctx->references); 951 s_ctx->references,c_ctx->references);
1001 } 952 }
1002 953
1003unsigned long irix_thread_id() 954unsigned long irix_thread_id(void)
1004 { 955 {
1005 unsigned long ret; 956 unsigned long ret;
1006 957
@@ -1014,7 +965,7 @@ unsigned long irix_thread_id()
1014static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 965static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
1015static long lock_count[CRYPTO_NUM_LOCKS]; 966static long lock_count[CRYPTO_NUM_LOCKS];
1016 967
1017void thread_setup() 968void thread_setup(void)
1018 { 969 {
1019 int i; 970 int i;
1020 971
@@ -1028,7 +979,7 @@ void thread_setup()
1028 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); 979 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
1029 } 980 }
1030 981
1031void thread_cleanup() 982void thread_cleanup(void)
1032 { 983 {
1033 int i; 984 int i;
1034 985
@@ -1043,11 +994,8 @@ void thread_cleanup()
1043 fprintf(stderr,"done cleanup\n"); 994 fprintf(stderr,"done cleanup\n");
1044 } 995 }
1045 996
1046void pthreads_locking_callback(mode,type,file,line) 997void pthreads_locking_callback(int mode, int type, char *file,
1047int mode; 998 int line)
1048int type;
1049char *file;
1050int line;
1051 { 999 {
1052#ifdef undef 1000#ifdef undef
1053 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", 1001 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
@@ -1072,8 +1020,7 @@ int line;
1072 } 1020 }
1073 } 1021 }
1074 1022
1075void do_threads(s_ctx,c_ctx) 1023void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
1076SSL_CTX *s_ctx,*c_ctx;
1077 { 1024 {
1078 SSL_CTX *ssl_ctx[2]; 1025 SSL_CTX *ssl_ctx[2];
1079 pthread_t thread_ctx[MAX_THREAD_NUMBER]; 1026 pthread_t thread_ctx[MAX_THREAD_NUMBER];
@@ -1101,7 +1048,7 @@ SSL_CTX *s_ctx,*c_ctx;
1101 s_ctx->references,c_ctx->references); 1048 s_ctx->references,c_ctx->references);
1102 } 1049 }
1103 1050
1104unsigned long pthreads_thread_id() 1051unsigned long pthreads_thread_id(void)
1105 { 1052 {
1106 unsigned long ret; 1053 unsigned long ret;
1107 1054
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 @@
74#include <ulocks.h> 74#include <ulocks.h>
75#include <sys/prctl.h> 75#include <sys/prctl.h>
76#endif 76#endif
77#include "lhash.h" 77#include <openssl/lhash.h>
78#include "crypto.h" 78#include <openssl/crypto.h>
79#include "buffer.h" 79#include <openssl/buffer.h>
80#include "e_os.h" 80#include <openssl/e_os.h>
81#include "x509.h" 81#include <openssl/x509.h>
82#include "ssl.h" 82#include <openssl/ssl.h>
83#include "err.h" 83#include <openssl/err.h>
84 84
85#ifndef NOPROTO
86int CRYPTO_thread_setup(void); 85int CRYPTO_thread_setup(void);
87void CRYPTO_thread_cleanup(void); 86void CRYPTO_thread_cleanup(void);
88 87
@@ -95,21 +94,6 @@ static unsigned long irix_thread_id(void );
95static unsigned long solaris_thread_id(void ); 94static unsigned long solaris_thread_id(void );
96static unsigned long pthreads_thread_id(void ); 95static unsigned long pthreads_thread_id(void );
97 96
98#else
99int CRYPOTO_thread_setup();
100void CRYPTO_cleanup();
101
102static void irix_locking_callback();
103static void solaris_locking_callback();
104static void win32_locking_callback();
105static void pthreads_locking_callback();
106
107static unsigned long irix_thread_id();
108static unsigned long solaris_thread_id();
109static unsigned long pthreads_thread_id();
110
111#endif
112
113/* usage: 97/* usage:
114 * CRYPTO_thread_setup(); 98 * CRYPTO_thread_setup();
115 * applicaion code 99 * applicaion code
@@ -122,7 +106,7 @@ static unsigned long pthreads_thread_id();
122 106
123static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; 107static HANDLE lock_cs[CRYPTO_NUM_LOCKS];
124 108
125int CRYPTO_thread_setup() 109int CRYPTO_thread_setup(void)
126 { 110 {
127 int i; 111 int i;
128 112
@@ -136,7 +120,7 @@ int CRYPTO_thread_setup()
136 return(1); 120 return(1);
137 } 121 }
138 122
139static void CRYPTO_thread_cleanup() 123static void CRYPTO_thread_cleanup(void)
140 { 124 {
141 int i; 125 int i;
142 126
@@ -145,11 +129,7 @@ static void CRYPTO_thread_cleanup()
145 CloseHandle(lock_cs[i]); 129 CloseHandle(lock_cs[i]);
146 } 130 }
147 131
148void win32_locking_callback(mode,type,file,line) 132void win32_locking_callback(int mode, int type, char *file, int line)
149int mode;
150int type;
151char *file;
152int line;
153 { 133 {
154 if (mode & CRYPTO_LOCK) 134 if (mode & CRYPTO_LOCK)
155 { 135 {
@@ -174,7 +154,7 @@ static long lock_count[CRYPTO_NUM_LOCKS];
174static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; 154static rwlock_t lock_cs[CRYPTO_NUM_LOCKS];
175#endif 155#endif
176 156
177void CRYPTO_thread_setup() 157void CRYPTO_thread_setup(void)
178 { 158 {
179 int i; 159 int i;
180 160
@@ -192,7 +172,7 @@ void CRYPTO_thread_setup()
192 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); 172 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
193 } 173 }
194 174
195void CRYPTO_thread_cleanup() 175void CRYPTO_thread_cleanup(void)
196 { 176 {
197 int i; 177 int i;
198 178
@@ -207,11 +187,7 @@ void CRYPTO_thread_cleanup()
207 } 187 }
208 } 188 }
209 189
210void solaris_locking_callback(mode,type,file,line) 190void solaris_locking_callback(int mode, int type, char *file, int line)
211int mode;
212int type;
213char *file;
214int line;
215 { 191 {
216#if 0 192#if 0
217 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", 193 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
@@ -248,7 +224,7 @@ int line;
248 } 224 }
249 } 225 }
250 226
251unsigned long solaris_thread_id() 227unsigned long solaris_thread_id(void)
252 { 228 {
253 unsigned long ret; 229 unsigned long ret;
254 230
@@ -263,7 +239,7 @@ unsigned long solaris_thread_id()
263static usptr_t *arena; 239static usptr_t *arena;
264static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; 240static usema_t *lock_cs[CRYPTO_NUM_LOCKS];
265 241
266void CRYPTO_thread_setup() 242void CRYPTO_thread_setup(void)
267 { 243 {
268 int i; 244 int i;
269 char filename[20]; 245 char filename[20];
@@ -287,7 +263,7 @@ void CRYPTO_thread_setup()
287 CRYPTO_set_locking_callback((void (*)())irix_locking_callback); 263 CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
288 } 264 }
289 265
290void CRYPTO_thread_cleanup() 266void CRYPTO_thread_cleanup(void)
291 { 267 {
292 int i; 268 int i;
293 269
@@ -302,11 +278,7 @@ void CRYPTO_thread_cleanup()
302 } 278 }
303 } 279 }
304 280
305void irix_locking_callback(mode,type,file,line) 281void irix_locking_callback(int mode, int type, char *file, int line)
306int mode;
307int type;
308char *file;
309int line;
310 { 282 {
311 if (mode & CRYPTO_LOCK) 283 if (mode & CRYPTO_LOCK)
312 { 284 {
@@ -318,7 +290,7 @@ int line;
318 } 290 }
319 } 291 }
320 292
321unsigned long irix_thread_id() 293unsigned long irix_thread_id(void)
322 { 294 {
323 unsigned long ret; 295 unsigned long ret;
324 296
@@ -333,7 +305,7 @@ unsigned long irix_thread_id()
333static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; 305static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS];
334static long lock_count[CRYPTO_NUM_LOCKS]; 306static long lock_count[CRYPTO_NUM_LOCKS];
335 307
336void CRYPTO_thread_setup() 308void CRYPTO_thread_setup(void)
337 { 309 {
338 int i; 310 int i;
339 311
@@ -347,7 +319,7 @@ void CRYPTO_thread_setup()
347 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); 319 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
348 } 320 }
349 321
350void thread_cleanup() 322void thread_cleanup(void)
351 { 323 {
352 int i; 324 int i;
353 325
@@ -358,11 +330,8 @@ void thread_cleanup()
358 } 330 }
359 } 331 }
360 332
361void pthreads_locking_callback(mode,type,file,line) 333void pthreads_locking_callback(int mode, int type, char *file,
362int mode; 334 int line)
363int type;
364char *file;
365int line;
366 { 335 {
367#if 0 336#if 0
368 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", 337 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
@@ -387,7 +356,7 @@ int line;
387 } 356 }
388 } 357 }
389 358
390unsigned long pthreads_thread_id() 359unsigned long pthreads_thread_id(void)
391 { 360 {
392 unsigned long ret; 361 unsigned long ret;
393 362
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 @@
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include <stdlib.h> 59#include <stdlib.h>
60#include "cryptlib.h"
61#include <openssl/tmdiff.h>
62
63#ifdef TIMEB
64#undef WIN32
65#undef TIMES
66#endif
60 67
61#ifndef MSDOS 68#ifndef MSDOS
62# ifndef WIN32 69# ifndef WIN32
63# define TIMES 70# if !defined(VMS) || defined(__DECC)
71# define TIMES
72# endif
64# endif 73# endif
65#endif 74#endif
66 75
67#ifndef VMS 76#ifndef _IRIX
68# ifndef _IRIX 77# include <time.h>
69# include <time.h> 78#endif
70# endif 79#ifdef TIMES
71# ifdef TIMES 80# include <sys/types.h>
72# include <sys/types.h> 81# include <sys/times.h>
73# include <sys/times.h> 82#endif
74# endif 83
75#else /* VMS */ 84/* Depending on the VMS version, the tms structure is perhaps defined.
76# include <types.h> 85 The __TMS macro will show if it was. If it wasn't defined, we should
77 struct tms { 86 undefine TIMES, since that tells the rest of the program how things
78 time_t tms_utime; 87 should be handled. -- Richard Levitte */
79 time_t tms_stime; 88#if defined(VMS) && defined(__DECC) && !defined(__TMS)
80 time_t tms_uchild; /* I dunno... */ 89#undef TIMES
81 time_t tms_uchildsys; /* so these names are a guess :-) */ 90#endif
82 } 91
83#endif /* VMS */ 92#if defined(sun) || defined(__ultrix)
84 93#define _POSIX_SOURCE
85#ifdef sun
86#include <limits.h> 94#include <limits.h>
87#include <sys/param.h> 95#include <sys/param.h>
88#endif 96#endif
@@ -99,11 +107,7 @@
99#ifndef HZ 107#ifndef HZ
100# ifndef CLK_TCK 108# ifndef CLK_TCK
101# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ 109# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
102# ifndef VMS 110# define HZ 100.0
103# define HZ 100.0
104# else /* VMS */
105# define HZ 100.0
106# endif
107# else /* _BSD_CLK_TCK_ */ 111# else /* _BSD_CLK_TCK_ */
108# define HZ ((double)_BSD_CLK_TCK_) 112# define HZ ((double)_BSD_CLK_TCK_)
109# endif 113# endif
@@ -126,11 +130,11 @@ typedef struct ms_tm
126#endif 130#endif
127 } MS_TM; 131 } MS_TM;
128 132
129char *ms_time_init() 133char *ms_time_new(void)
130 { 134 {
131 MS_TM *ret; 135 MS_TM *ret;
132 136
133 ret=malloc(sizeof(MS_TM)); 137 ret=(MS_TM *)Malloc(sizeof(MS_TM));
134 if (ret == NULL) 138 if (ret == NULL)
135 return(NULL); 139 return(NULL);
136 memset(ret,0,sizeof(MS_TM)); 140 memset(ret,0,sizeof(MS_TM));
@@ -140,34 +144,31 @@ char *ms_time_init()
140 return((char *)ret); 144 return((char *)ret);
141 } 145 }
142 146
143void ms_time_final(a) 147void ms_time_free(char *a)
144char *a;
145 { 148 {
146 if (a != NULL) 149 if (a != NULL)
147 free(a); 150 Free(a);
148 } 151 }
149 152
150void ms_time_get(a) 153void ms_time_get(char *a)
151char *a;
152 { 154 {
153 MS_TM *tm=(MS_TM *)a; 155 MS_TM *tm=(MS_TM *)a;
154 FILETIME tmpa,tmpb,tmpc; 156#ifdef WIN32
157 FILETIME tmpa,tmpb,tmpc;
158#endif
155 159
156#ifdef TIMES 160#ifdef TIMES
157 printf("AAA\n");
158 times(&tm->ms_tms); 161 times(&tm->ms_tms);
159#else 162#else
160# ifdef WIN32 163# ifdef WIN32
161 GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32)); 164 GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32));
162# else 165# else
163 printf("CCC\n"); 166 ftime(&tm->ms_timeb);
164 ftime(tm->ms_timeb);
165# endif 167# endif
166#endif 168#endif
167 } 169 }
168 170
169double ms_time_diff(ap,bp) 171double ms_time_diff(char *ap, char *bp)
170char *ap,*bp;
171 { 172 {
172 MS_TM *a=(MS_TM *)ap; 173 MS_TM *a=(MS_TM *)ap;
173 MS_TM *b=(MS_TM *)bp; 174 MS_TM *b=(MS_TM *)bp;
@@ -177,19 +178,30 @@ char *ap,*bp;
177 ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ; 178 ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
178#else 179#else
179# ifdef WIN32 180# ifdef WIN32
180 ret =(double)(b->ms_win32.dwHighDateTime&0x000fffff)*10+ 181 {
181 b->ms_win32.dwLowDateTime/1e7; 182#ifdef __GNUC__
182 ret-=(double)(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; 183 signed long long la,lb;
184#else
185 signed _int64 la,lb;
186#endif
187 la=a->ms_win32.dwHighDateTime;
188 lb=b->ms_win32.dwHighDateTime;
189 la<<=32;
190 lb<<=32;
191 la+=a->ms_win32.dwLowDateTime;
192 lb+=b->ms_win32.dwLowDateTime;
193 ret=((double)(lb-la))/1e7;
194 }
183# else 195# else
184 ret= (double)(b->time-a->time)+ 196 ret= (double)(b->ms_timeb.time-a->ms_timeb.time)+
185 ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0; 197 (((double)b->ms_timeb.millitm)-
198 ((double)a->ms_timeb.millitm))/1000.0;
186# endif 199# endif
187#endif 200#endif
188 return((ret < 0.0000001)?0.0000001:ret); 201 return((ret < 0.0000001)?0.0000001:ret);
189 } 202 }
190 203
191int ms_time_cmp(ap,bp) 204int ms_time_cmp(char *ap, char *bp)
192char *ap,*bp;
193 { 205 {
194 MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp; 206 MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp;
195 double d; 207 double d;
@@ -202,8 +214,8 @@ char *ap,*bp;
202 d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7; 214 d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7;
203 d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7; 215 d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7;
204# else 216# else
205 d= (double)(b->time-a->time)+ 217 d= (double)(b->ms_timeb.time-a->ms_timeb.time)+
206 ((double)((unsigned long)b->mullitm-(unsigned long)))/1000.0; 218 (((double)b->ms_timeb.millitm)-(double)a->ms_timeb.millitm)/1000.0;
207# endif 219# endif
208#endif 220#endif
209 if (d == 0.0) 221 if (d == 0.0)
diff --git a/src/lib/libcrypto/evp/pk_lib.c b/src/lib/libcrypto/tmdiff.h
index 08f9fabbae..41a8a1e0e0 100644
--- a/src/lib/libcrypto/evp/pk_lib.c
+++ b/src/lib/libcrypto/tmdiff.h
@@ -1,4 +1,4 @@
1/* crypto/evp/pk_lib.c */ 1/* crypto/tmdiff.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -56,27 +56,26 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <stdio.h> 59/* Header for dynamic hash table routines
60#include "cryptlib.h" 60 * Author - Eric Young
61#include "evp.h" 61 */
62#include "objects.h"
63
64static LHASH *pk_md=NULL;
65 62
66static LHASH *pk_md=NULL; 63#ifndef HEADER_TMDIFF_H
64#define HEADER_TMDIFF_H
67 65
68int EVP_add_pkey_md(oid,pkm,md) 66#ifdef __cplusplus
69int oid; 67extern "C" {
70EVP_PKEY_METHOD *pkm; 68#endif
71EVP_MD *md;
72 {
73 }
74 69
75EVP_add_pkey(pkm) 70char *ms_time_new(void );
76EVP_PKEY_METHOD *pkm; 71void ms_time_free(char *a);
77 { 72void ms_time_get(char *a);
78 } 73double ms_time_diff(char *start,char *end);
74int ms_time_cmp(char *ap,char *bp);
79 75
80EVP_PKEY_METHOD:q 76#ifdef __cplusplus
77}
78#endif
81 79
80#endif
82 81
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= ../..
7CC= cc 7CC= cc
8INCLUDES= 8INCLUDES=
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
@@ -37,24 +39,23 @@ all: lib
37 39
38lib: $(LIBOBJ) 40lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ) 41 $(AR) $(LIB) $(LIBOBJ)
40 sh $(TOP)/util/ranlib.sh $(LIB) 42 $(RANLIB) $(LIB)
41 @touch lib 43 @touch lib
42 44
43files: 45files:
44 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
45 47
46links: 48links:
47 /bin/rm -f Makefile 49 @$(TOP)/util/point.sh Makefile.ssl Makefile
48 $(TOP)/util/point.sh Makefile.ssl Makefile ; 50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 $(TOP)/util/mklink.sh ../../test $(TEST) 52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51 $(TOP)/util/mklink.sh ../../apps $(APPS)
52 53
53install: 54install:
54 @for i in $(EXHEADER) ; \ 55 @for i in $(EXHEADER) ; \
55 do \ 56 do \
56 (cp $$i $(INSTALLTOP)/include/$$i; \ 57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALLTOP)/include/$$i ); \ 58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done; 59 done;
59 60
60tags: 61tags:
@@ -66,15 +67,20 @@ lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
67 68
68depend: 69depend:
69 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
70 71
71dclean: 72dclean:
72 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE) 74 mv -f Makefile.new $(MAKEFILE)
74 75
75clean: 76clean:
76 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78errors:
79 78
80# DO NOT DELETE THIS LINE -- make depend depends on it. 79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81txt_db.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82txt_db.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83txt_db.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84txt_db.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
85txt_db.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
86txt_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 @@
60#include <stdlib.h> 60#include <stdlib.h>
61#include <string.h> 61#include <string.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "buffer.h" 63#include <openssl/buffer.h>
64#include "txt_db.h" 64#include <openssl/txt_db.h>
65 65
66#undef BUFSIZE 66#undef BUFSIZE
67#define BUFSIZE 512 67#define BUFSIZE 512
68 68
69char *TXT_DB_version="TXT_DB part of SSLeay 0.9.0b 29-Jun-1998"; 69const char *TXT_DB_version="TXT_DB" OPENSSL_VERSION_PTEXT;
70 70
71TXT_DB *TXT_DB_read(in,num) 71TXT_DB *TXT_DB_read(BIO *in, int num)
72BIO *in;
73int num;
74 { 72 {
75 TXT_DB *ret=NULL; 73 TXT_DB *ret=NULL;
76 int er=1; 74 int er=1;
@@ -158,7 +156,7 @@ int num;
158 if ((n != num) || (*f != '\0')) 156 if ((n != num) || (*f != '\0'))
159 { 157 {
160#if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */ 158#if !defined(NO_STDIO) && !defined(WIN16) /* temporaty fix :-( */
161 fprintf(stderr,"wrong number of fields on line %ld\n",ln); 159 fprintf(stderr,"wrong number of fields on line %ld (looking for field %d, got %d, '%s' left)\n",ln,num,n,f);
162#endif 160#endif
163 er=2; 161 er=2;
164 goto err; 162 goto err;
@@ -191,10 +189,7 @@ err:
191 return(ret); 189 return(ret);
192 } 190 }
193 191
194char **TXT_DB_get_by_index(db,idx,value) 192char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value)
195TXT_DB *db;
196int idx;
197char **value;
198 { 193 {
199 char **ret; 194 char **ret;
200 LHASH *lh; 195 LHASH *lh;
@@ -215,12 +210,8 @@ char **value;
215 return(ret); 210 return(ret);
216 } 211 }
217 212
218int TXT_DB_create_index(db,field,qual,hash,cmp) 213int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(),
219TXT_DB *db; 214 unsigned long (*hash)(), int (*cmp)())
220int field;
221int (*qual)();
222unsigned long (*hash)();
223int (*cmp)();
224 { 215 {
225 LHASH *idx; 216 LHASH *idx;
226 char *r; 217 char *r;
@@ -256,9 +247,7 @@ int (*cmp)();
256 return(1); 247 return(1);
257 } 248 }
258 249
259long TXT_DB_write(out,db) 250long TXT_DB_write(BIO *out, TXT_DB *db)
260BIO *out;
261TXT_DB *db;
262 { 251 {
263 long i,j,n,nn,l,tot=0; 252 long i,j,n,nn,l,tot=0;
264 char *p,**pp,*f; 253 char *p,**pp,*f;
@@ -306,9 +295,7 @@ err:
306 return(ret); 295 return(ret);
307 } 296 }
308 297
309int TXT_DB_insert(db,row) 298int TXT_DB_insert(TXT_DB *db, char **row)
310TXT_DB *db;
311char **row;
312 { 299 {
313 int i; 300 int i;
314 char **r; 301 char **r;
@@ -350,12 +337,14 @@ err:
350 return(0); 337 return(0);
351 } 338 }
352 339
353void TXT_DB_free(db) 340void TXT_DB_free(TXT_DB *db)
354TXT_DB *db;
355 { 341 {
356 int i,n; 342 int i,n;
357 char **p,*max; 343 char **p,*max;
358 344
345 if(db == NULL)
346 return;
347
359 if (db->index != NULL) 348 if (db->index != NULL)
360 { 349 {
361 for (i=db->num_fields-1; i>=0; i--) 350 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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "stack.h" 66#include <openssl/stack.h>
67#include "lhash.h" 67#include <openssl/lhash.h>
68 68
69#define DB_ERROR_OK 0 69#define DB_ERROR_OK 0
70#define DB_ERROR_MALLOC 1 70#define DB_ERROR_MALLOC 1
@@ -85,7 +85,6 @@ typedef struct txt_db_st
85 char **arg_row; 85 char **arg_row;
86 } TXT_DB; 86 } TXT_DB;
87 87
88#ifndef NOPROTO
89#ifdef HEADER_BIO_H 88#ifdef HEADER_BIO_H
90TXT_DB *TXT_DB_read(BIO *in, int num); 89TXT_DB *TXT_DB_read(BIO *in, int num);
91long TXT_DB_write(BIO *out, TXT_DB *db); 90long TXT_DB_write(BIO *out, TXT_DB *db);
@@ -99,17 +98,6 @@ void TXT_DB_free(TXT_DB *db);
99char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value); 98char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value);
100int TXT_DB_insert(TXT_DB *db,char **value); 99int TXT_DB_insert(TXT_DB *db,char **value);
101 100
102#else
103
104TXT_DB *TXT_DB_read();
105long TXT_DB_write();
106int TXT_DB_create_index();
107void TXT_DB_free();
108char **TXT_DB_get_by_index();
109int TXT_DB_insert();
110
111#endif
112
113#ifdef __cplusplus 101#ifdef __cplusplus
114} 102}
115#endif 103#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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# This adds a copyright message to a souce code file. 3# This adds a copyright message to a souce code file.
4# It also gets the file name correct. 4# 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# This is just a quick script to scan for cases where the 'error' 3# This is just a quick script to scan for cases where the 'error'
4# function name in a XXXerr() macro is wrong. 4# function name in a XXXerr() macro is wrong.
@@ -40,5 +40,6 @@ foreach $file (@ARGV)
40 # print "$func:$1\n"; 40 # print "$func:$1\n";
41 } 41 }
42 } 42 }
43 close(IN);
43 } 44 }
44 45
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 @@
1#!/usr/local/bin/perl -w
2# Clean the dependency list in a makefile of standard includes...
3# Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
4
5use strict;
6
7while(<STDIN>) {
8 print;
9 last if /^# DO NOT DELETE THIS LINE/;
10}
11
12my %files;
13
14while(<STDIN>) {
15 my ($file,$deps)=/^(.*): (.*)$/;
16 next if !defined $deps;
17 my @deps=split ' ',$deps;
18 @deps=grep(!/^\/usr\/include/,@deps);
19 @deps=grep(!/^\/usr\/lib\/gcc-lib/,@deps);
20 push @{$files{$file}},@deps;
21}
22
23my $file;
24foreach $file (sort keys %files) {
25 my $len=0;
26 my $dep;
27 foreach $dep (sort @{$files{$file}}) {
28 $len=0 if $len+length($dep)+1 >= 80;
29 if($len == 0) {
30 print "\n$file:";
31 $len=length($file)+1;
32 }
33 print " $dep";
34 $len+=length($dep)+1;
35 }
36}
37
38print "\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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3while (<>) 3while (<>)
4 { 4 {
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 @@
5 5
6PATH=util:../util:$PATH 6PATH=util:../util:$PATH
7 7
8# perl util/mk1mf.pl VC-MSDOS no-sock >ms/msdos.mak 8# perl util/mk1mf.pl no-sock VC-MSDOS >ms/msdos.mak
9# perl util/mk1mf.pl VC-W31-32 >ms/w31.mak 9# perl util/mk1mf.pl VC-W31-32 >ms/w31.mak
10perl util/mk1mf.pl VC-WIN16 dll >ms/w31dll.mak 10perl util/mk1mf.pl dll VC-WIN16 >ms/w31dll.mak
11# perl util/mk1mf.pl VC-WIN32 >ms/nt.mak 11# perl util/mk1mf.pl VC-WIN32 >ms/nt.mak
12perl util/mk1mf.pl VC-WIN32 dll >ms/ntdll.mak 12perl util/mk1mf.pl dll VC-WIN32 >ms/ntdll.mak
13perl util/mk1mf.pl Mingw32 >ms/mingw32.mak
14perl util/mk1mf.pl Mingw32-files >ms/mingw32f.mak
13 15
14perl util/mkdef.pl 16 libeay > ms/libeay16.def 16perl util/mkdef.pl 16 libeay > ms/libeay16.def
15perl util/mkdef.pl 32 libeay > ms/libeay32.def 17perl 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 @@
1#!/bin/sh
2# Do a makedepend, only leave out the standard headers
3# Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
4
5TOP=$1
6shift
7
8cp Makefile.ssl Makefile.save
9makedepend -f Makefile.ssl $@
10$TOP/util/clean-depend.pl < Makefile.ssl > Makefile.new
11mv 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# tack error codes onto the end of a file 3# tack error codes onto the end of a file
4# 4#
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# used to generate the file MINFO for use by util/mk1mf.pl 3# used to generate the file MINFO for use by util/mk1mf.pl
4# It is basically a list of all variables from the passed makefile 4# 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
580X509_NAME_print 586 580X509_NAME_print 586
581X509_NAME_set 587 581X509_NAME_set 587
582X509_OBJECT_free_contents 588 582X509_OBJECT_free_contents 588
583X509_OBJECT_retrive_by_subject 589 583X509_OBJECT_retrieve_by_subject 589
584X509_OBJECT_up_ref_count 590 584X509_OBJECT_up_ref_count 590
585X509_PKEY_free 591 585X509_PKEY_free 591
586X509_PKEY_new 592 586X509_PKEY_new 592
@@ -695,12 +695,12 @@ a2i_ASN1_INTEGER 700
695a2i_ASN1_STRING 701 695a2i_ASN1_STRING 701
696asn1_Finish 702 696asn1_Finish 702
697asn1_GetSequence 703 697asn1_GetSequence 703
698bn_div64 704 698bn_div_words 704
699bn_expand2 705 699bn_expand2 705
700bn_mul_add_words 706 700bn_mul_add_words 706
701bn_mul_words 707 701bn_mul_words 707
702bn_qadd 708 702BN_uadd 708
703bn_qsub 709 703BN_usub 709
704bn_sqr_words 710 704bn_sqr_words 710
705crypt 711 705crypt 711
706d2i_ASN1_BIT_STRING 712 706d2i_ASN1_BIT_STRING 712
@@ -1063,3 +1063,784 @@ EVP_rc5_32_12_16_cfb 1088
1063EVP_rc5_32_12_16_ecb 1089 1063EVP_rc5_32_12_16_ecb 1089
1064EVP_rc5_32_12_16_ofb 1090 1064EVP_rc5_32_12_16_ofb 1090
1065asn1_add_error 1091 1065asn1_add_error 1091
1066d2i_ASN1_BMPSTRING 1092
1067i2d_ASN1_BMPSTRING 1093
1068BIO_f_ber 1094
1069BN_init 1095
1070COMP_CTX_new 1096
1071COMP_CTX_free 1097
1072COMP_CTX_compress_block 1098
1073COMP_CTX_expand_block 1099
1074X509_STORE_CTX_get_ex_new_index 1100
1075OBJ_NAME_add 1101
1076BIO_socket_nbio 1102
1077EVP_rc2_64_cbc 1103
1078OBJ_NAME_cleanup 1104
1079OBJ_NAME_get 1105
1080OBJ_NAME_init 1106
1081OBJ_NAME_new_index 1107
1082OBJ_NAME_remove 1108
1083BN_MONT_CTX_copy 1109
1084BIO_new_socks4a_connect 1110
1085BIO_s_socks4a_connect 1111
1086PROXY_set_connect_mode 1112
1087RAND_SSLeay 1113
1088RAND_set_rand_method 1114
1089RSA_memory_lock 1115
1090bn_sub_words 1116
1091bn_mul_normal 1117
1092bn_mul_comba8 1118
1093bn_mul_comba4 1119
1094bn_sqr_normal 1120
1095bn_sqr_comba8 1121
1096bn_sqr_comba4 1122
1097bn_cmp_words 1123
1098bn_mul_recursive 1124
1099bn_mul_part_recursive 1125
1100bn_sqr_recursive 1126
1101bn_mul_low_normal 1127
1102BN_RECP_CTX_init 1128
1103BN_RECP_CTX_new 1129
1104BN_RECP_CTX_free 1130
1105BN_RECP_CTX_set 1131
1106BN_mod_mul_reciprocal 1132
1107BN_mod_exp_recp 1133
1108BN_div_recp 1134
1109BN_CTX_init 1135
1110BN_MONT_CTX_init 1136
1111RAND_get_rand_method 1137
1112PKCS7_add_attribute 1138
1113PKCS7_add_signed_attribute 1139
1114PKCS7_digest_from_attributes 1140
1115PKCS7_get_attribute 1141
1116PKCS7_get_issuer_and_serial 1142
1117PKCS7_get_signed_attribute 1143
1118COMP_compress_block 1144
1119COMP_expand_block 1145
1120COMP_rle 1146
1121COMP_zlib 1147
1122ms_time_diff 1148
1123ms_time_new 1149
1124ms_time_free 1150
1125ms_time_cmp 1151
1126ms_time_get 1152
1127PKCS7_set_attributes 1153
1128PKCS7_set_signed_attributes 1154
1129X509_ATTRIBUTE_create 1155
1130X509_ATTRIBUTE_dup 1156
1131ASN1_GENERALIZEDTIME_check 1157
1132ASN1_GENERALIZEDTIME_print 1158
1133ASN1_GENERALIZEDTIME_set 1159
1134ASN1_GENERALIZEDTIME_set_string 1160
1135ASN1_TIME_print 1161
1136BASIC_CONSTRAINTS_free 1162
1137BASIC_CONSTRAINTS_new 1163
1138ERR_load_X509V3_strings 1164
1139NETSCAPE_CERT_SEQUENCE_free 1165
1140NETSCAPE_CERT_SEQUENCE_new 1166
1141OBJ_txt2obj 1167
1142PEM_read_NETSCAPE_CERT_SEQUENCE 1168
1143PEM_read_bio_NETSCAPE_CERT_SEQUENCE 1169
1144PEM_write_NETSCAPE_CERT_SEQUENCE 1170
1145PEM_write_bio_NETSCAPE_CERT_SEQUENCE 1171
1146X509V3_EXT_add 1172
1147X509V3_EXT_add_alias 1173
1148X509V3_EXT_add_conf 1174
1149X509V3_EXT_cleanup 1175
1150X509V3_EXT_conf 1176
1151X509V3_EXT_conf_nid 1177
1152X509V3_EXT_get 1178
1153X509V3_EXT_get_nid 1179
1154X509V3_EXT_print 1180
1155X509V3_EXT_print_fp 1181
1156X509V3_add_standard_extensions 1182
1157X509V3_add_value 1183
1158X509V3_add_value_bool 1184
1159X509V3_add_value_int 1185
1160X509V3_conf_free 1186
1161X509V3_get_value_bool 1187
1162X509V3_get_value_int 1188
1163X509V3_parse_list 1189
1164d2i_ASN1_GENERALIZEDTIME 1190
1165d2i_ASN1_TIME 1191
1166d2i_BASIC_CONSTRAINTS 1192
1167d2i_NETSCAPE_CERT_SEQUENCE 1193
1168d2i_ext_ku 1194
1169ext_ku_free 1195
1170ext_ku_new 1196
1171i2d_ASN1_GENERALIZEDTIME 1197
1172i2d_ASN1_TIME 1198
1173i2d_BASIC_CONSTRAINTS 1199
1174i2d_NETSCAPE_CERT_SEQUENCE 1200
1175i2d_ext_ku 1201
1176EVP_MD_CTX_copy 1202
1177i2d_ASN1_ENUMERATED 1203
1178d2i_ASN1_ENUMERATED 1204
1179ASN1_ENUMERATED_set 1205
1180ASN1_ENUMERATED_get 1206
1181BN_to_ASN1_ENUMERATED 1207
1182ASN1_ENUMERATED_to_BN 1208
1183i2a_ASN1_ENUMERATED 1209
1184a2i_ASN1_ENUMERATED 1210
1185i2d_GENERAL_NAME 1211
1186d2i_GENERAL_NAME 1212
1187GENERAL_NAME_new 1213
1188GENERAL_NAME_free 1214
1189GENERAL_NAMES_new 1215
1190GENERAL_NAMES_free 1216
1191d2i_GENERAL_NAMES 1217
1192i2d_GENERAL_NAMES 1218
1193i2v_GENERAL_NAMES 1219
1194i2s_ASN1_OCTET_STRING 1220
1195s2i_ASN1_OCTET_STRING 1221
1196X509V3_EXT_check_conf 1222
1197hex_to_string 1223
1198string_to_hex 1224
1199des_ede3_cbcm_encrypt 1225
1200RSA_padding_add_PKCS1_OAEP 1226
1201RSA_padding_check_PKCS1_OAEP 1227
1202X509_CRL_print_fp 1228
1203X509_CRL_print 1229
1204i2v_GENERAL_NAME 1230
1205v2i_GENERAL_NAME 1231
1206i2d_PKEY_USAGE_PERIOD 1232
1207d2i_PKEY_USAGE_PERIOD 1233
1208PKEY_USAGE_PERIOD_new 1234
1209PKEY_USAGE_PERIOD_free 1235
1210v2i_GENERAL_NAMES 1236
1211i2s_ASN1_INTEGER 1237
1212X509V3_EXT_d2i 1238
1213name_cmp 1239
1214str_dup 1240
1215i2s_ASN1_ENUMERATED 1241
1216i2s_ASN1_ENUMERATED_TABLE 1242
1217BIO_s_log 1243
1218BIO_f_reliable 1244
1219PKCS7_dataFinal 1245
1220PKCS7_dataDecode 1246
1221X509V3_EXT_CRL_add_conf 1247
1222BN_set_params 1248
1223BN_get_params 1249
1224BIO_get_ex_num 1250
1225BIO_set_ex_free_func 1251
1226EVP_ripemd160 1252
1227ASN1_TIME_set 1253
1228i2d_AUTHORITY_KEYID 1254
1229d2i_AUTHORITY_KEYID 1255
1230AUTHORITY_KEYID_new 1256
1231AUTHORITY_KEYID_free 1257
1232ASN1_seq_unpack 1258
1233ASN1_seq_pack 1259
1234ASN1_unpack_string 1260
1235ASN1_pack_string 1261
1236PKCS12_pack_safebag 1262
1237PKCS12_MAKE_KEYBAG 1263
1238PKCS8_encrypt 1264
1239PKCS12_MAKE_SHKEYBAG 1265
1240PKCS12_pack_p7data 1266
1241PKCS12_pack_p7encdata 1267
1242PKCS12_add_localkeyid 1268
1243PKCS12_add_friendlyname_asc 1269
1244PKCS12_add_friendlyname_uni 1270
1245PKCS12_get_friendlyname 1271
1246PKCS12_pbe_crypt 1272
1247PKCS12_decrypt_d2i 1273
1248PKCS12_i2d_encrypt 1274
1249PKCS12_init 1275
1250PKCS12_key_gen_asc 1276
1251PKCS12_key_gen_uni 1277
1252PKCS12_gen_mac 1278
1253PKCS12_verify_mac 1279
1254PKCS12_set_mac 1280
1255PKCS12_setup_mac 1281
1256asc2uni 1282
1257uni2asc 1283
1258i2d_PKCS12_BAGS 1284
1259PKCS12_BAGS_new 1285
1260d2i_PKCS12_BAGS 1286
1261PKCS12_BAGS_free 1287
1262i2d_PKCS12 1288
1263d2i_PKCS12 1289
1264PKCS12_new 1290
1265PKCS12_free 1291
1266i2d_PKCS12_MAC_DATA 1292
1267PKCS12_MAC_DATA_new 1293
1268d2i_PKCS12_MAC_DATA 1294
1269PKCS12_MAC_DATA_free 1295
1270i2d_PKCS12_SAFEBAG 1296
1271PKCS12_SAFEBAG_new 1297
1272d2i_PKCS12_SAFEBAG 1298
1273PKCS12_SAFEBAG_free 1299
1274ERR_load_PKCS12_strings 1300
1275PKCS12_PBE_add 1301
1276PKCS8_add_keyusage 1302
1277PKCS12_get_attr_gen 1303
1278PKCS12_parse 1304
1279PKCS12_create 1305
1280i2d_PKCS12_bio 1306
1281i2d_PKCS12_fp 1307
1282d2i_PKCS12_bio 1308
1283d2i_PKCS12_fp 1309
1284i2d_PBEPARAM 1310
1285PBEPARAM_new 1311
1286d2i_PBEPARAM 1312
1287PBEPARAM_free 1313
1288i2d_PKCS8_PRIV_KEY_INFO 1314
1289PKCS8_PRIV_KEY_INFO_new 1315
1290d2i_PKCS8_PRIV_KEY_INFO 1316
1291PKCS8_PRIV_KEY_INFO_free 1317
1292EVP_PKCS82PKEY 1318
1293EVP_PKEY2PKCS8 1319
1294PKCS8_set_broken 1320
1295EVP_PBE_ALGOR_CipherInit 1321
1296EVP_PBE_alg_add 1322
1297PKCS5_pbe_set 1323
1298EVP_PBE_cleanup 1324
1299i2d_SXNET 1325
1300d2i_SXNET 1326
1301SXNET_new 1327
1302SXNET_free 1328
1303i2d_SXNETID 1329
1304d2i_SXNETID 1330
1305SXNETID_new 1331
1306SXNETID_free 1332
1307DSA_SIG_new 1333
1308DSA_SIG_free 1334
1309DSA_do_sign 1335
1310DSA_do_verify 1336
1311d2i_DSA_SIG 1337
1312i2d_DSA_SIG 1338
1313
1314i2d_ASN1_VISIBLESTRING 1339
1315d2i_ASN1_VISIBLESTRING 1340
1316i2d_ASN1_UTF8STRING 1341
1317d2i_ASN1_UTF8STRING 1342
1318i2d_DIRECTORYSTRING 1343
1319d2i_DIRECTORYSTRING 1344
1320i2d_DISPLAYTEXT 1345
1321d2i_DISPLAYTEXT 1346
1322sk_X509_NAME_new 1347
1323sk_X509_NAME_new_null 1348
1324sk_X509_NAME_free 1349
1325sk_X509_NAME_num 1350
1326sk_X509_NAME_value 1351
1327sk_X509_NAME_set 1352
1328sk_X509_NAME_zero 1353
1329sk_X509_NAME_push 1354
1330sk_X509_NAME_pop 1355
1331sk_X509_NAME_find 1356
1332sk_X509_NAME_delete 1357
1333sk_X509_NAME_delete_ptr 1358
1334sk_X509_NAME_set_cmp_func 1359
1335sk_X509_NAME_dup 1360
1336sk_X509_NAME_pop_free 1361
1337sk_X509_NAME_shift 1362
1338sk_X509_new 1363
1339sk_X509_new_null 1364
1340sk_X509_free 1365
1341sk_X509_num 1366
1342sk_X509_value 1367
1343sk_X509_set 1368
1344sk_X509_zero 1369
1345sk_X509_push 1370
1346sk_X509_pop 1371
1347sk_X509_find 1372
1348sk_X509_delete 1373
1349sk_X509_delete_ptr 1374
1350sk_X509_set_cmp_func 1375
1351sk_X509_dup 1376
1352sk_X509_pop_free 1377
1353sk_X509_shift 1378
1354d2i_ASN1_SET_OF_X509 1379
1355i2d_ASN1_SET_OF_X509 1380
1356sk_X509_ATTRIBUTE_new 1381
1357sk_X509_ATTRIBUTE_new_null 1382
1358sk_X509_ATTRIBUTE_free 1383
1359sk_X509_ATTRIBUTE_num 1384
1360sk_X509_ATTRIBUTE_value 1385
1361sk_X509_ATTRIBUTE_set 1386
1362sk_X509_ATTRIBUTE_zero 1387
1363sk_X509_ATTRIBUTE_push 1388
1364sk_X509_ATTRIBUTE_pop 1389
1365sk_X509_ATTRIBUTE_find 1390
1366sk_X509_ATTRIBUTE_delete 1391
1367sk_X509_ATTRIBUTE_delete_ptr 1392
1368sk_X509_ATTRIBUTE_set_cmp_func 1393
1369sk_X509_ATTRIBUTE_dup 1394
1370sk_X509_ATTRIBUTE_pop_free 1395
1371sk_X509_ATTRIBUTE_shift 1396
1372i2d_PBKDF2PARAM 1397
1373PBKDF2PARAM_new 1398
1374d2i_PBKDF2PARAM 1399
1375PBKDF2PARAM_free 1400
1376i2d_PBE2PARAM 1401
1377PBE2PARAM_new 1402
1378d2i_PBE2PARAM 1403
1379PBE2PARAM_free 1404
1380sk_GENERAL_NAME_new 1405
1381sk_GENERAL_NAME_new_null 1406
1382sk_GENERAL_NAME_free 1407
1383sk_GENERAL_NAME_num 1408
1384sk_GENERAL_NAME_value 1409
1385sk_GENERAL_NAME_set 1410
1386sk_GENERAL_NAME_zero 1411
1387sk_GENERAL_NAME_push 1412
1388sk_GENERAL_NAME_pop 1413
1389sk_GENERAL_NAME_find 1414
1390sk_GENERAL_NAME_delete 1415
1391sk_GENERAL_NAME_delete_ptr 1416
1392sk_GENERAL_NAME_set_cmp_func 1417
1393sk_GENERAL_NAME_dup 1418
1394sk_GENERAL_NAME_pop_free 1419
1395sk_GENERAL_NAME_shift 1420
1396d2i_ASN1_SET_OF_GENERAL_NAME 1421
1397i2d_ASN1_SET_OF_GENERAL_NAME 1422
1398sk_SXNETID_new 1423
1399sk_SXNETID_new_null 1424
1400sk_SXNETID_free 1425
1401sk_SXNETID_num 1426
1402sk_SXNETID_value 1427
1403sk_SXNETID_set 1428
1404sk_SXNETID_zero 1429
1405sk_SXNETID_push 1430
1406sk_SXNETID_pop 1431
1407sk_SXNETID_find 1432
1408sk_SXNETID_delete 1433
1409sk_SXNETID_delete_ptr 1434
1410sk_SXNETID_set_cmp_func 1435
1411sk_SXNETID_dup 1436
1412sk_SXNETID_pop_free 1437
1413sk_SXNETID_shift 1438
1414d2i_ASN1_SET_OF_SXNETID 1439
1415i2d_ASN1_SET_OF_SXNETID 1440
1416sk_POLICYQUALINFO_new 1441
1417sk_POLICYQUALINFO_new_null 1442
1418sk_POLICYQUALINFO_free 1443
1419sk_POLICYQUALINFO_num 1444
1420sk_POLICYQUALINFO_value 1445
1421sk_POLICYQUALINFO_set 1446
1422sk_POLICYQUALINFO_zero 1447
1423sk_POLICYQUALINFO_push 1448
1424sk_POLICYQUALINFO_pop 1449
1425sk_POLICYQUALINFO_find 1450
1426sk_POLICYQUALINFO_delete 1451
1427sk_POLICYQUALINFO_delete_ptr 1452
1428sk_POLICYQUALINFO_set_cmp_func 1453
1429sk_POLICYQUALINFO_dup 1454
1430sk_POLICYQUALINFO_pop_free 1455
1431sk_POLICYQUALINFO_shift 1456
1432d2i_ASN1_SET_OF_POLICYQUALINFO 1457
1433i2d_ASN1_SET_OF_POLICYQUALINFO 1458
1434sk_POLICYINFO_new 1459
1435sk_POLICYINFO_new_null 1460
1436sk_POLICYINFO_free 1461
1437sk_POLICYINFO_num 1462
1438sk_POLICYINFO_value 1463
1439sk_POLICYINFO_set 1464
1440sk_POLICYINFO_zero 1465
1441sk_POLICYINFO_push 1466
1442sk_POLICYINFO_pop 1467
1443sk_POLICYINFO_find 1468
1444sk_POLICYINFO_delete 1469
1445sk_POLICYINFO_delete_ptr 1470
1446sk_POLICYINFO_set_cmp_func 1471
1447sk_POLICYINFO_dup 1472
1448sk_POLICYINFO_pop_free 1473
1449sk_POLICYINFO_shift 1474
1450d2i_ASN1_SET_OF_POLICYINFO 1475
1451i2d_ASN1_SET_OF_POLICYINFO 1476
1452SXNET_add_id_asc 1477
1453SXNET_add_id_ulong 1478
1454SXNET_add_id_INTEGER 1479
1455SXNET_get_id_asc 1480
1456SXNET_get_id_ulong 1481
1457SXNET_get_id_INTEGER 1482
1458X509V3_set_conf_lhash 1483
1459i2d_CERTIFICATEPOLICIES 1484
1460CERTIFICATEPOLICIES_new 1485
1461CERTIFICATEPOLICIES_free 1486
1462d2i_CERTIFICATEPOLICIES 1487
1463i2d_POLICYINFO 1488
1464POLICYINFO_new 1489
1465d2i_POLICYINFO 1490
1466POLICYINFO_free 1491
1467i2d_POLICYQUALINFO 1492
1468POLICYQUALINFO_new 1493
1469d2i_POLICYQUALINFO 1494
1470POLICYQUALINFO_free 1495
1471i2d_USERNOTICE 1496
1472USERNOTICE_new 1497
1473d2i_USERNOTICE 1498
1474USERNOTICE_free 1499
1475i2d_NOTICEREF 1500
1476NOTICEREF_new 1501
1477d2i_NOTICEREF 1502
1478NOTICEREF_free 1503
1479X509V3_get_string 1504
1480X509V3_get_section 1505
1481X509V3_string_free 1506
1482X509V3_section_free 1507
1483X509V3_set_ctx 1508
1484s2i_ASN1_INTEGER 1509
1485CRYPTO_set_locked_mem_functions 1510
1486CRYPTO_get_locked_mem_functions 1511
1487CRYPTO_malloc_locked 1512
1488CRYPTO_free_locked 1513
1489BN_mod_exp2_mont 1514
1490ERR_get_error_line_data 1515
1491ERR_peek_error_line_data 1516
1492PKCS12_PBE_keyivgen 1517
1493X509_ALGOR_dup 1518
1494sk_DIST_POINT_new 1519
1495sk_DIST_POINT_new_null 1520
1496sk_DIST_POINT_free 1521
1497sk_DIST_POINT_num 1522
1498sk_DIST_POINT_value 1523
1499sk_DIST_POINT_set 1524
1500sk_DIST_POINT_zero 1525
1501sk_DIST_POINT_push 1526
1502sk_DIST_POINT_pop 1527
1503sk_DIST_POINT_find 1528
1504sk_DIST_POINT_delete 1529
1505sk_DIST_POINT_delete_ptr 1530
1506sk_DIST_POINT_set_cmp_func 1531
1507sk_DIST_POINT_dup 1532
1508sk_DIST_POINT_pop_free 1533
1509sk_DIST_POINT_shift 1534
1510d2i_ASN1_SET_OF_DIST_POINT 1535
1511i2d_ASN1_SET_OF_DIST_POINT 1536
1512i2d_CRL_DIST_POINTS 1537
1513CRL_DIST_POINTS_new 1538
1514CRL_DIST_POINTS_free 1539
1515d2i_CRL_DIST_POINTS 1540
1516i2d_DIST_POINT 1541
1517DIST_POINT_new 1542
1518d2i_DIST_POINT 1543
1519DIST_POINT_free 1544
1520i2d_DIST_POINT_NAME 1545
1521DIST_POINT_NAME_new 1546
1522DIST_POINT_NAME_free 1547
1523d2i_DIST_POINT_NAME 1548
1524X509V3_add_value_uchar 1549
1525sk_X509_INFO_new 1550
1526sk_X509_EXTENSION_new 1551
1527sk_X509_NAME_ENTRY_unshift 1552
1528sk_ASN1_TYPE_value 1553
1529sk_X509_EXTENSION_find 1554
1530d2i_ASN1_SET_OF_X509_ATTRIBUTE 1555
1531sk_ASN1_TYPE_pop 1556
1532sk_X509_EXTENSION_set_cmp_func 1557
1533sk_ASN1_TYPE_new_null 1558
1534sk_X509_NAME_ENTRY_delete 1559
1535i2d_ASN1_SET_OF_ASN1_TYPE 1560
1536sk_X509_NAME_ENTRY_dup 1561
1537sk_X509_unshift 1562
1538sk_X509_NAME_unshift 1563
1539sk_ASN1_TYPE_num 1564
1540sk_X509_EXTENSION_new_null 1565
1541sk_X509_INFO_value 1566
1542d2i_ASN1_SET_OF_X509_EXTENSION 1567
1543sk_X509_INFO_delete_ptr 1568
1544sk_X509_NAME_ENTRY_new 1569
1545sk_DIST_POINT_insert 1570
1546sk_ASN1_TYPE_set_cmp_func 1571
1547sk_X509_EXTENSION_value 1572
1548sk_DIST_POINT_unshift 1573
1549d2i_ASN1_SET_OF_X509_NAME_ENTRY 1574
1550sk_X509_INFO_pop 1575
1551sk_X509_EXTENSION_pop 1576
1552sk_X509_NAME_ENTRY_shift 1577
1553sk_X509_INFO_num 1578
1554sk_X509_EXTENSION_num 1579
1555sk_X509_INFO_pop_free 1580
1556sk_POLICYQUALINFO_unshift 1581
1557sk_POLICYINFO_unshift 1582
1558sk_X509_NAME_ENTRY_new_null 1583
1559sk_X509_NAME_ENTRY_pop 1584
1560sk_X509_ATTRIBUTE_unshift 1585
1561sk_X509_NAME_ENTRY_num 1586
1562sk_GENERAL_NAME_unshift 1587
1563sk_X509_INFO_free 1588
1564d2i_ASN1_SET_OF_ASN1_TYPE 1589
1565sk_X509_INFO_insert 1590
1566sk_X509_NAME_ENTRY_value 1591
1567sk_POLICYQUALINFO_insert 1592
1568sk_ASN1_TYPE_set 1593
1569sk_X509_EXTENSION_delete_ptr 1594
1570sk_X509_INFO_unshift 1595
1571sk_ASN1_TYPE_unshift 1596
1572sk_ASN1_TYPE_free 1597
1573sk_ASN1_TYPE_delete_ptr 1598
1574sk_ASN1_TYPE_pop_free 1599
1575sk_X509_EXTENSION_unshift 1600
1576sk_X509_EXTENSION_pop_free 1601
1577sk_X509_NAME_ENTRY_set_cmp_func 1602
1578sk_ASN1_TYPE_insert 1603
1579sk_X509_NAME_ENTRY_free 1604
1580sk_SXNETID_insert 1605
1581sk_X509_NAME_insert 1606
1582sk_X509_insert 1607
1583sk_X509_INFO_delete 1608
1584sk_X509_INFO_set_cmp_func 1609
1585sk_X509_ATTRIBUTE_insert 1610
1586sk_X509_INFO_zero 1611
1587sk_X509_INFO_set 1612
1588sk_X509_EXTENSION_set 1613
1589sk_X509_EXTENSION_free 1614
1590i2d_ASN1_SET_OF_X509_ATTRIBUTE 1615
1591sk_SXNETID_unshift 1616
1592sk_X509_INFO_push 1617
1593sk_X509_EXTENSION_insert 1618
1594sk_X509_INFO_new_null 1619
1595sk_ASN1_TYPE_dup 1620
1596sk_X509_INFO_find 1621
1597sk_POLICYINFO_insert 1622
1598sk_ASN1_TYPE_zero 1623
1599i2d_ASN1_SET_OF_X509_EXTENSION 1624
1600sk_X509_NAME_ENTRY_set 1625
1601sk_ASN1_TYPE_push 1626
1602sk_X509_NAME_ENTRY_insert 1627
1603sk_ASN1_TYPE_new 1628
1604sk_GENERAL_NAME_insert 1629
1605sk_ASN1_TYPE_shift 1630
1606sk_ASN1_TYPE_delete 1631
1607sk_X509_NAME_ENTRY_pop_free 1632
1608i2d_ASN1_SET_OF_X509_NAME_ENTRY 1633
1609sk_X509_NAME_ENTRY_zero 1634
1610sk_ASN1_TYPE_find 1635
1611sk_X509_NAME_ENTRY_delete_ptr 1636
1612sk_X509_NAME_ENTRY_push 1637
1613sk_X509_EXTENSION_zero 1638
1614sk_X509_INFO_shift 1639
1615sk_X509_INFO_dup 1640
1616sk_X509_EXTENSION_dup 1641
1617sk_X509_EXTENSION_delete 1642
1618sk_X509_EXTENSION_shift 1643
1619sk_X509_EXTENSION_push 1644
1620sk_X509_NAME_ENTRY_find 1645
1621X509V3_EXT_i2d 1646
1622X509V3_EXT_val_prn 1647
1623X509V3_EXT_add_list 1648
1624EVP_CIPHER_type 1649
1625EVP_PBE_CipherInit 1650
1626X509V3_add_value_bool_nf 1651
1627d2i_ASN1_UINTEGER 1652
1628sk_value 1653
1629sk_num 1654
1630sk_set 1655
1631sk_X509_REVOKED_set_cmp_func 1656
1632sk_X509_REVOKED_unshift 1657
1633sk_X509_REVOKED_dup 1658
1634sk_X509_REVOKED_free 1659
1635sk_X509_REVOKED_new 1660
1636i2d_ASN1_SET_OF_X509_REVOKED 1661
1637sk_X509_REVOKED_shift 1662
1638sk_X509_REVOKED_delete_ptr 1663
1639sk_X509_REVOKED_pop_free 1664
1640sk_X509_REVOKED_insert 1665
1641sk_X509_REVOKED_zero 1666
1642sk_X509_REVOKED_pop 1667
1643sk_X509_REVOKED_value 1668
1644sk_X509_REVOKED_num 1669
1645sk_X509_REVOKED_push 1670
1646sk_sort 1671
1647sk_X509_REVOKED_find 1672
1648sk_X509_REVOKED_delete 1673
1649d2i_ASN1_SET_OF_X509_REVOKED 1674
1650sk_X509_REVOKED_new_null 1675
1651sk_X509_REVOKED_set 1676
1652sk_X509_ALGOR_new 1677
1653sk_X509_CRL_set_cmp_func 1678
1654sk_X509_CRL_set 1679
1655sk_X509_ALGOR_unshift 1680
1656sk_X509_CRL_free 1681
1657i2d_ASN1_SET_OF_X509_ALGOR 1682
1658sk_X509_ALGOR_pop 1683
1659sk_X509_CRL_unshift 1684
1660i2d_ASN1_SET_OF_X509_CRL 1685
1661sk_X509_ALGOR_num 1686
1662sk_X509_CRL_insert 1687
1663sk_X509_CRL_pop_free 1688
1664sk_X509_CRL_delete_ptr 1689
1665sk_X509_ALGOR_insert 1690
1666sk_X509_CRL_dup 1691
1667sk_X509_CRL_zero 1692
1668sk_X509_CRL_new 1693
1669sk_X509_CRL_push 1694
1670sk_X509_ALGOR_new_null 1695
1671d2i_ASN1_SET_OF_X509_ALGOR 1696
1672sk_X509_CRL_shift 1697
1673sk_X509_CRL_find 1698
1674sk_X509_CRL_delete 1699
1675sk_X509_ALGOR_free 1700
1676sk_X509_ALGOR_delete 1701
1677d2i_ASN1_SET_OF_X509_CRL 1702
1678sk_X509_ALGOR_delete_ptr 1703
1679sk_X509_CRL_pop 1704
1680sk_X509_ALGOR_set 1705
1681sk_X509_CRL_num 1706
1682sk_X509_CRL_value 1707
1683sk_X509_ALGOR_shift 1708
1684sk_X509_ALGOR_zero 1709
1685sk_X509_CRL_new_null 1710
1686sk_X509_ALGOR_push 1711
1687sk_X509_ALGOR_value 1712
1688sk_X509_ALGOR_find 1713
1689sk_X509_ALGOR_set_cmp_func 1714
1690sk_X509_ALGOR_dup 1715
1691sk_X509_ALGOR_pop_free 1716
1692sk_PKCS7_SIGNER_INFO_new 1717
1693sk_PKCS7_SIGNER_INFO_zero 1718
1694sk_PKCS7_SIGNER_INFO_unshift 1719
1695sk_PKCS7_RECIP_INFO_dup 1720
1696sk_PKCS7_SIGNER_INFO_insert 1721
1697sk_PKCS7_SIGNER_INFO_push 1722
1698i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO 1723
1699sk_PKCS7_RECIP_INFO_new 1724
1700sk_X509_LOOKUP_new_null 1725
1701sk_PKCS7_SIGNER_INFO_find 1726
1702sk_PKCS7_SIGNER_INFO_set_cmp_func 1727
1703sk_X509_LOOKUP_zero 1728
1704sk_PKCS7_RECIP_INFO_shift 1729
1705sk_PKCS7_RECIP_INFO_new_null 1730
1706sk_PKCS7_SIGNER_INFO_shift 1731
1707sk_PKCS7_SIGNER_INFO_pop 1732
1708sk_PKCS7_SIGNER_INFO_pop_free 1733
1709sk_X509_LOOKUP_push 1734
1710sk_X509_LOOKUP_dup 1735
1711sk_PKCS7_SIGNER_INFO_num 1736
1712sk_X509_LOOKUP_find 1737
1713i2d_ASN1_SET_OF_PKCS7_RECIP_INFO 1738
1714sk_X509_LOOKUP_new 1739
1715sk_PKCS7_SIGNER_INFO_delete 1740
1716sk_PKCS7_RECIP_INFO_set_cmp_func 1741
1717sk_PKCS7_SIGNER_INFO_delete_ptr 1742
1718sk_PKCS7_RECIP_INFO_pop 1743
1719sk_X509_LOOKUP_insert 1744
1720sk_PKCS7_RECIP_INFO_value 1745
1721sk_PKCS7_RECIP_INFO_num 1746
1722sk_PKCS7_SIGNER_INFO_value 1747
1723d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO 1748
1724sk_X509_LOOKUP_pop 1749
1725sk_X509_LOOKUP_num 1750
1726sk_X509_LOOKUP_delete 1751
1727sk_PKCS7_RECIP_INFO_free 1752
1728d2i_ASN1_SET_OF_PKCS7_RECIP_INFO 1753
1729sk_PKCS7_SIGNER_INFO_set 1754
1730sk_X509_LOOKUP_pop_free 1755
1731sk_X509_LOOKUP_shift 1756
1732sk_X509_LOOKUP_unshift 1757
1733sk_PKCS7_SIGNER_INFO_new_null 1758
1734sk_PKCS7_RECIP_INFO_delete_ptr 1759
1735sk_PKCS7_RECIP_INFO_pop_free 1760
1736sk_PKCS7_RECIP_INFO_insert 1761
1737sk_PKCS7_SIGNER_INFO_free 1762
1738sk_PKCS7_RECIP_INFO_set 1763
1739sk_PKCS7_RECIP_INFO_zero 1764
1740sk_X509_LOOKUP_value 1765
1741sk_PKCS7_RECIP_INFO_push 1766
1742sk_PKCS7_RECIP_INFO_unshift 1767
1743sk_X509_LOOKUP_set_cmp_func 1768
1744sk_X509_LOOKUP_free 1769
1745sk_PKCS7_SIGNER_INFO_dup 1770
1746sk_X509_LOOKUP_delete_ptr 1771
1747sk_X509_LOOKUP_set 1772
1748sk_PKCS7_RECIP_INFO_find 1773
1749sk_PKCS7_RECIP_INFO_delete 1774
1750PKCS5_PBE_add 1775
1751PEM_write_bio_PKCS8 1776
1752i2d_PKCS8_fp 1777
1753PEM_read_bio_PKCS8_PRIV_KEY_INFO 1778
1754d2i_PKCS8_bio 1779
1755d2i_PKCS8_PRIV_KEY_INFO_fp 1780
1756PEM_write_bio_PKCS8_PRIV_KEY_INFO 1781
1757PEM_read_PKCS8 1782
1758d2i_PKCS8_PRIV_KEY_INFO_bio 1783
1759d2i_PKCS8_fp 1784
1760PEM_write_PKCS8 1785
1761PEM_read_PKCS8_PRIV_KEY_INFO 1786
1762PEM_read_bio_PKCS8 1787
1763PEM_write_PKCS8_PRIV_KEY_INFO 1788
1764PKCS5_PBE_keyivgen 1789
1765i2d_PKCS8_bio 1790
1766i2d_PKCS8_PRIV_KEY_INFO_fp 1791
1767i2d_PKCS8_PRIV_KEY_INFO_bio 1792
1768BIO_s_bio 1793
1769PKCS5_pbe2_set 1794
1770PKCS5_PBKDF2_HMAC_SHA1 1795
1771PKCS5_v2_PBE_keyivgen 1796
1772PEM_write_bio_PKCS8PrivateKey 1797
1773PEM_write_PKCS8PrivateKey 1798
1774BIO_ctrl_get_read_request 1799
1775BIO_ctrl_pending 1800
1776BIO_ctrl_wpending 1801
1777BIO_new_bio_pair 1802
1778BIO_ctrl_get_write_guarantee 1803
1779CRYPTO_num_locks 1804
1780CONF_load_bio 1805
1781CONF_load_fp 1806
1782sk_CONF_VALUE_delete 1807
1783sk_CONF_VALUE_pop 1808
1784sk_CONF_VALUE_num 1809
1785sk_CONF_VALUE_pop_free 1810
1786sk_CONF_VALUE_free 1811
1787sk_CONF_VALUE_shift 1812
1788sk_CONF_VALUE_unshift 1813
1789sk_CONF_VALUE_value 1814
1790sk_CONF_VALUE_set 1815
1791sk_CONF_VALUE_zero 1816
1792sk_CONF_VALUE_push 1817
1793sk_CONF_VALUE_delete_ptr 1818
1794sk_CONF_VALUE_find 1819
1795sk_CONF_VALUE_set_cmp_func 1820
1796sk_CONF_VALUE_new_null 1821
1797sk_CONF_VALUE_dup 1822
1798sk_CONF_VALUE_insert 1823
1799sk_CONF_VALUE_new 1824
1800sk_ASN1_OBJECT_find 1825
1801sk_ASN1_OBJECT_pop_free 1826
1802sk_ASN1_OBJECT_dup 1827
1803sk_ASN1_OBJECT_delete_ptr 1828
1804sk_ASN1_OBJECT_new 1829
1805sk_ASN1_OBJECT_unshift 1830
1806sk_ASN1_OBJECT_delete 1831
1807sk_ASN1_OBJECT_shift 1832
1808sk_ASN1_OBJECT_pop 1833
1809sk_ASN1_OBJECT_num 1834
1810sk_ASN1_OBJECT_value 1835
1811sk_ASN1_OBJECT_new_null 1836
1812i2d_ASN1_SET_OF_ASN1_OBJECT 1837
1813sk_ASN1_OBJECT_free 1838
1814sk_ASN1_OBJECT_set 1839
1815sk_ASN1_OBJECT_set_cmp_func 1840
1816sk_ASN1_OBJECT_zero 1841
1817sk_ASN1_OBJECT_insert 1842
1818sk_ASN1_OBJECT_push 1843
1819d2i_ASN1_SET_OF_ASN1_OBJECT 1844
1820PKCS7_signatureVerify 1845
1821RSA_set_method 1846
1822RSA_get_method 1847
1823RSA_get_default_method 1848
1824sk_CONF_VALUE_sort 1849
1825sk_X509_REVOKED_sort 1850
1826sk_X509_ATTRIBUTE_sort 1851
1827sk_X509_INFO_sort 1852
1828sk_POLICYINFO_sort 1853
1829sk_GENERAL_NAME_sort 1854
1830sk_X509_sort 1855
1831sk_X509_NAME_sort 1856
1832sk_ASN1_TYPE_sort 1857
1833sk_X509_ALGOR_sort 1858
1834sk_PKCS7_RECIP_INFO_sort 1859
1835sk_X509_NAME_ENTRY_sort 1860
1836sk_X509_EXTENSION_sort 1861
1837sk_SXNETID_sort 1862
1838sk_ASN1_OBJECT_sort 1863
1839sk_PKCS7_SIGNER_INFO_sort 1864
1840sk_X509_LOOKUP_sort 1865
1841sk_POLICYQUALINFO_sort 1866
1842sk_X509_CRL_sort 1867
1843sk_DIST_POINT_sort 1868
1844RSA_check_key 1869
1845OBJ_obj2txt 1870
1846DSA_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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# A bit of an evil hack but it post processes the file ../MINFO which 2# A bit of an evil hack but it post processes the file ../MINFO which
3# is generated by `make files` in the top directory. 3# is generated by `make files` in the top directory.
4# This script outputs one mega makefile that has no shell stuff or any 4# This script outputs one mega makefile that has no shell stuff or any
@@ -6,82 +6,59 @@
6# 6#
7 7
8$INSTALLTOP="/usr/local/ssl"; 8$INSTALLTOP="/usr/local/ssl";
9$OPTIONS="";
10$ssl_version="";
11
12open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n";
13while(<IN>) {
14 $ssl_version=$1 if (/^VERSION=(.*)$/);
15 $OPTIONS=$1 if (/^OPTIONS=(.*)$/);
16 $INSTALLTOP=$1 if (/^INSTALLTOP=(.*$)/);
17}
18close(IN);
9 19
10$ssl_version="0.8.2"; 20die "Makefile.ssl is not the toplevel Makefile!\n" if $ssl_version eq "";
11 21
12$infile="MINFO"; 22$infile="MINFO";
13 23
14%ops=( 24%ops=(
15 "VC-WIN32", "Microsoft Visual C++ 4.[01] - Windows NT [34].x", 25 "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X",
26 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
16 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286", 27 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
17 "VC-WIN16", "Alias for VC-W31-32", 28 "VC-WIN16", "Alias for VC-W31-32",
18 "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+", 29 "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+",
19 "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS", 30 "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS",
20 "BC-NT", "Borland C++ 4.5 - Windows NT - PROBABLY NOT WORKING", 31 "Mingw32", "GNU C++ - Windows NT or 9x",
32 "Mingw32-files", "Create files with DOS copy ...",
33 "BC-NT", "Borland C++ 4.5 - Windows NT",
21 "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING", 34 "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
22 "BC-MSDOS","Borland C++ 4.5 - MSDOS", 35 "BC-MSDOS","Borland C++ 4.5 - MSDOS",
23 "linux-elf","Linux elf", 36 "linux-elf","Linux elf",
37 "ultrix-mips","DEC mips ultrix",
24 "FreeBSD","FreeBSD distribution", 38 "FreeBSD","FreeBSD distribution",
25 "default","cc under unix", 39 "default","cc under unix",
26 ); 40 );
27 41
28$type=""; 42$platform="";
29foreach (@ARGV) 43foreach (@ARGV)
30 { 44 {
31 if (/^no-rc2$/) { $no_rc2=1; } 45 if (!&read_options && !defined($ops{$_}))
32 elsif (/^no-rc4$/) { $no_rc4=1; }
33 elsif (/^no-rc5$/) { $no_rc5=1; }
34 elsif (/^no-idea$/) { $no_idea=1; }
35 elsif (/^no-des$/) { $no_des=1; }
36 elsif (/^no-bf$/) { $no_bf=1; }
37 elsif (/^no-cast$/) { $no_cast=1; }
38 elsif (/^no-md2$/) { $no_md2=1; }
39 elsif (/^no-md5$/) { $no_md5=1; }
40 elsif (/^no-sha$/) { $no_sha=1; }
41 elsif (/^no-sha1$/) { $no_sha1=1; }
42 elsif (/^no-rmd160$/) { $no_rmd160=1; }
43 elsif (/^no-mdc2$/) { $no_mdc2=1; }
44 elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; }
45 elsif (/^no-rsa$/) { $no_rsa=1; }
46 elsif (/^no-dsa$/) { $no_dsa=1; }
47 elsif (/^no-dh$/) { $no_dh=1; }
48 elsif (/^no-asm$/) { $no_asm=1; }
49 elsif (/^no-ssl2$/) { $no_ssl2=1; }
50 elsif (/^no-ssl3$/) { $no_ssl3=1; }
51 elsif (/^no-err$/) { $no_err=1; }
52 elsif (/^no-sock$/) { $no_sock=1; }
53
54 elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1;
55 $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1;
56 $no_ssl2=$no_err=1; }
57
58 elsif (/^rsaref$/) { $rsaref=1; }
59 elsif (/^gcc$/) { $gcc=1; }
60 elsif (/^debug$/) { $debug=1; }
61 elsif (/^shlib$/) { $shlib=1; }
62 elsif (/^dll$/) { $shlib=1; }
63 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
64 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
65 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
66 { $c_flags.="$_ "; }
67 else
68 { 46 {
69 if (!defined($ops{$_})) 47 print STDERR "unknown option - $_\n";
70 { 48 print STDERR "usage: perl mk1mf.pl [options] [system]\n";
71 print STDERR "unknown option - $_\n"; 49 print STDERR "\nwhere [system] can be one of the following\n";
72 print STDERR "usage: perl mk1mf.pl [system] [options]\n"; 50 foreach $i (sort keys %ops)
73 print STDERR "\nwhere [system] can be one of the following\n"; 51 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
74 foreach $i (sort keys %ops) 52 print STDERR <<"EOF";
75 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
76 print STDERR <<"EOF";
77and [options] can be one of 53and [options] can be one of
78 no-md2 no-md5 no-sha no-sha1 no-mdc2 no-rmd160 - Skip this digest 54 no-md2 no-md5 no-sha no-mdc2 no-ripemd - Skip this digest
79 no-rc2 no-rc4 no-idea no-des no-bf no-cast - Skip this symetric cipher 55 no-rc2 no-rc4 no-idea no-des no-bf no-cast - Skip this symetric cipher
80 no-rc5 56 no-rc5
81 no-rsa no-dsa no-dh - Skip this public key cipher 57 no-rsa no-dsa no-dh - Skip this public key cipher
82 no-ssl2 no-ssl3 - Skip this version of SSL 58 no-ssl2 no-ssl3 - Skip this version of SSL
83 just-ssl - remove all non-ssl keys/digest 59 just-ssl - remove all non-ssl keys/digest
84 no-asm - No x86 asm 60 no-asm - No x86 asm
61 nasm - Use NASM for x86 asm
85 no-socks - No socket code 62 no-socks - No socket code
86 no-err - No error strings 63 no-err - No error strings
87 dll/shlib - Build shared libraries (MS) 64 dll/shlib - Build shared libraries (MS)
@@ -96,15 +73,18 @@ TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
96-<ex_cc_flags> - extra 'cc' flags, 73-<ex_cc_flags> - extra 'cc' flags,
97 added (MS), or replace (unix) 74 added (MS), or replace (unix)
98EOF 75EOF
99 exit(1); 76 exit(1);
100 }
101 $type=$_;
102 } 77 }
78 $platform=$_;
79 }
80foreach (split / /, $OPTIONS)
81 {
82 print STDERR "unknown option - $_\n" if !&read_options;
103 } 83 }
104 84
105$no_mdc2=1 if ($no_des); 85$no_mdc2=1 if ($no_des);
106 86
107$no_ssl3=1 if ($no_md5 || $no_sha1); 87$no_ssl3=1 if ($no_md5 || $no_sha);
108$no_ssl3=1 if ($no_rsa && $no_dh); 88$no_ssl3=1 if ($no_rsa && $no_dh);
109 89
110$no_ssl2=1 if ($no_md5 || $no_rsa); 90$no_ssl2=1 if ($no_md5 || $no_rsa);
@@ -114,6 +94,7 @@ $out_def="out";
114$inc_def="outinc"; 94$inc_def="outinc";
115$tmp_def="tmp"; 95$tmp_def="tmp";
116 96
97$mkdir="mkdir";
117 98
118($ssl,$crypto)=("ssl","crypto"); 99($ssl,$crypto)=("ssl","crypto");
119$RSAglue="RSAglue"; 100$RSAglue="RSAglue";
@@ -125,62 +106,79 @@ $bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
125 106
126# $bin_dir.=$o causes a core dump on my sparc :-( 107# $bin_dir.=$o causes a core dump on my sparc :-(
127 108
109$NT=0;
110
128push(@INC,"util/pl","pl"); 111push(@INC,"util/pl","pl");
129if ($type eq "VC-MSDOS") 112if ($platform eq "VC-MSDOS")
130 { 113 {
131 $asmbits=16; 114 $asmbits=16;
132 $msdos=1; 115 $msdos=1;
133 require 'VC-16.pl'; 116 require 'VC-16.pl';
134 } 117 }
135elsif ($type eq "VC-W31-16") 118elsif ($platform eq "VC-W31-16")
136 { 119 {
137 $asmbits=16; 120 $asmbits=16;
138 $msdos=1; $win16=1; 121 $msdos=1; $win16=1;
139 require 'VC-16.pl'; 122 require 'VC-16.pl';
140 } 123 }
141elsif (($type eq "VC-W31-32") || ($type eq "VC-WIN16")) 124elsif (($platform eq "VC-W31-32") || ($platform eq "VC-WIN16"))
142 { 125 {
143 $asmbits=32; 126 $asmbits=32;
144 $msdos=1; $win16=1; 127 $msdos=1; $win16=1;
145 require 'VC-16.pl'; 128 require 'VC-16.pl';
146 } 129 }
147elsif (($type eq "VC-WIN32") || ($type eq "VC-NT")) 130elsif (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
148 { 131 {
132 $NT = 1 if $platform eq "VC-NT";
149 require 'VC-32.pl'; 133 require 'VC-32.pl';
150 } 134 }
151elsif ($type eq "BC-NT") 135elsif ($platform eq "Mingw32")
136 {
137 require 'Mingw32.pl';
138 }
139elsif ($platform eq "Mingw32-files")
140 {
141 require 'Mingw32f.pl';
142 }
143elsif ($platform eq "BC-NT")
152 { 144 {
153 $bc=1; 145 $bc=1;
154 require 'BC-32.pl'; 146 require 'BC-32.pl';
155 } 147 }
156elsif ($type eq "BC-W31") 148elsif ($platform eq "BC-W31")
157 { 149 {
158 $bc=1; 150 $bc=1;
159 $msdos=1; $w16=1; 151 $msdos=1; $w16=1;
160 require 'BC-16.pl'; 152 require 'BC-16.pl';
161 } 153 }
162elsif ($type eq "BC-Q16") 154elsif ($platform eq "BC-Q16")
163 { 155 {
164 $msdos=1; $w16=1; $shlib=0; $qw=1; 156 $msdos=1; $w16=1; $shlib=0; $qw=1;
165 require 'BC-16.pl'; 157 require 'BC-16.pl';
166 } 158 }
167elsif ($type eq "BC-MSDOS") 159elsif ($platform eq "BC-MSDOS")
168 { 160 {
169 $asmbits=16; 161 $asmbits=16;
170 $msdos=1; 162 $msdos=1;
171 require 'BC-16.pl'; 163 require 'BC-16.pl';
172 } 164 }
173elsif ($type eq "FreeBSD") 165elsif ($platform eq "FreeBSD")
174 { 166 {
175 require 'unix.pl'; 167 require 'unix.pl';
176 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer'; 168 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
177 } 169 }
178elsif ($type eq "linux-elf") 170elsif ($platform eq "linux-elf")
179 { 171 {
180 require "unix.pl"; 172 require "unix.pl";
181 require "linux.pl"; 173 require "linux.pl";
182 $unix=1; 174 $unix=1;
183 } 175 }
176elsif ($platform eq "ultrix-mips")
177 {
178 require "unix.pl";
179 require "ultrix.pl";
180 $unix=1;
181 }
184else 182else
185 { 183 {
186 require "unix.pl"; 184 require "unix.pl";
@@ -203,9 +201,9 @@ $cflags.=" -DNO_MD2" if $no_md2;
203$cflags.=" -DNO_MD5" if $no_md5; 201$cflags.=" -DNO_MD5" if $no_md5;
204$cflags.=" -DNO_SHA" if $no_sha; 202$cflags.=" -DNO_SHA" if $no_sha;
205$cflags.=" -DNO_SHA1" if $no_sha1; 203$cflags.=" -DNO_SHA1" if $no_sha1;
206$cflags.=" -DNO_RMD160" if $no_rmd160; 204$cflags.=" -DNO_RIPEMD" if $no_rmd160;
207$cflags.=" -DNO_MDC2" if $no_mdc2; 205$cflags.=" -DNO_MDC2" if $no_mdc2;
208$cflags.=" -DNO_BLOWFISH" if $no_bf; 206$cflags.=" -DNO_BF" if $no_bf;
209$cflags.=" -DNO_CAST" if $no_cast; 207$cflags.=" -DNO_CAST" if $no_cast;
210$cflags.=" -DNO_DES" if $no_des; 208$cflags.=" -DNO_DES" if $no_des;
211$cflags.=" -DNO_RSA" if $no_rsa; 209$cflags.=" -DNO_RSA" if $no_rsa;
@@ -223,14 +221,9 @@ else { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
223 221
224$ex_libs="$l_flags$ex_libs" if ($l_flags ne ""); 222$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
225 223
226if ($ranlib ne "")
227 {
228 $ranlib="\$(SRC_D)$o$ranlib";
229 }
230
231if ($msdos) 224if ($msdos)
232 { 225 {
233 $banner ="\t\@echo Make sure you have run 'perl Configure $type' in the\n"; 226 $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
234 $banner.="\t\@echo top level directory, if you don't have perl, you will\n"; 227 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
235 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n"; 228 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
236 $banner.="\t\@echo documentation for details.\n"; 229 $banner.="\t\@echo documentation for details.\n";
@@ -242,8 +235,8 @@ $link="$bin_dir$link" if ($link !~ /^\$/);
242$INSTALLTOP =~ s|/|$o|g; 235$INSTALLTOP =~ s|/|$o|g;
243 236
244$defs= <<"EOF"; 237$defs= <<"EOF";
245# This makefile has been automatically generated from the SSLeay distribution. 238# This makefile has been automatically generated from the OpenSSL distribution.
246# This single makefile will build the complete SSLeay distribution and 239# This single makefile will build the complete OpenSSL distribution and
247# by default leave the 'intertesting' output files in .${o}out and the stuff 240# by default leave the 'intertesting' output files in .${o}out and the stuff
248# that needs deleting in .${o}tmp. 241# that needs deleting in .${o}tmp.
249# The file was generated by running 'make makefile.one', which 242# The file was generated by running 'make makefile.one', which
@@ -258,6 +251,7 @@ $defs= <<"EOF";
258INSTALLTOP=$INSTALLTOP 251INSTALLTOP=$INSTALLTOP
259 252
260# Set your compiler options 253# Set your compiler options
254PLATFORM=$platform
261CC=$bin_dir${cc} 255CC=$bin_dir${cc}
262CFLAG=$cflags 256CFLAG=$cflags
263APP_CFLAG=$app_cflag 257APP_CFLAG=$app_cflag
@@ -269,18 +263,16 @@ SHLIB_EX_OBJ=$shlib_ex_obj
269# be added 263# be added
270EX_LIBS=$ex_libs 264EX_LIBS=$ex_libs
271 265
272# The SSLeay directory 266# The OpenSSL directory
273SRC_D=$src_dir 267SRC_D=$src_dir
274 268
275LINK=$link 269LINK=$link
276LFLAGS=$lflags 270LFLAGS=$lflags
277 271
278BN_MULW_OBJ=$bn_mulw_obj 272BN_ASM_OBJ=$bn_asm_obj
279BN_MULW_SRC=$bn_mulw_src 273BN_ASM_SRC=$bn_asm_src
280DES_ENC_OBJ=$des_enc_obj 274DES_ENC_OBJ=$des_enc_obj
281DES_ENC_SRC=$des_enc_src 275DES_ENC_SRC=$des_enc_src
282DES_CRYPT_OBJ=$des_crypt_obj
283DES_CRYPT_SRC=$des_crypt_src
284BF_ENC_OBJ=$bf_enc_obj 276BF_ENC_OBJ=$bf_enc_obj
285BF_ENC_SRC=$bf_enc_src 277BF_ENC_SRC=$bf_enc_src
286CAST_ENC_OBJ=$cast_enc_obj 278CAST_ENC_OBJ=$cast_enc_obj
@@ -302,11 +294,12 @@ OUT_D=$out_dir
302TMP_D=$tmp_dir 294TMP_D=$tmp_dir
303# The output directory for the header files 295# The output directory for the header files
304INC_D=$inc_dir 296INC_D=$inc_dir
297INCO_D=$inc_dir${o}openssl
305 298
306CP=$cp 299CP=$cp
307RM=$rm 300RM=$rm
308RANLIB=$ranlib 301RANLIB=$ranlib
309MKDIR=mkdir 302MKDIR=$mkdir
310MKLIB=$bin_dir$mklib 303MKLIB=$bin_dir$mklib
311MLFLAGS=$mlflags 304MLFLAGS=$mlflags
312ASM=$bin_dir$asm 305ASM=$bin_dir$asm
@@ -315,7 +308,7 @@ ASM=$bin_dir$asm
315# You should not need to touch anything below this point 308# You should not need to touch anything below this point
316###################################################### 309######################################################
317 310
318E_EXE=ssleay 311E_EXE=openssl
319SSL=$ssl 312SSL=$ssl
320CRYPTO=$crypto 313CRYPTO=$crypto
321RSAGLUE=$RSAglue 314RSAGLUE=$RSAglue
@@ -323,6 +316,9 @@ RSAGLUE=$RSAglue
323# BIN_D - Binary output directory 316# BIN_D - Binary output directory
324# TEST_D - Binary test file output directory 317# TEST_D - Binary test file output directory
325# LIB_D - library output directory 318# LIB_D - library output directory
319# Note: if you change these point to different directories then uncomment out
320# the lines around the 'NB' comment below.
321#
326BIN_D=\$(OUT_D) 322BIN_D=\$(OUT_D)
327TEST_D=\$(OUT_D) 323TEST_D=\$(OUT_D)
328LIB_D=\$(OUT_D) 324LIB_D=\$(OUT_D)
@@ -337,8 +333,8 @@ O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
337O_RSAGLUE= \$(LIB_D)$o$plib\$(RSAGLUE)$libp 333O_RSAGLUE= \$(LIB_D)$o$plib\$(RSAGLUE)$libp
338SO_SSL= $plib\$(SSL)$so_shlibp 334SO_SSL= $plib\$(SSL)$so_shlibp
339SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp 335SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
340L_SSL= \$(LIB_D)$o\$(SSL)$libp 336L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
341L_CRYPTO= \$(LIB_D)$o\$(CRYPTO)$libp 337L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
342 338
343L_LIBS= \$(L_SSL) \$(L_CRYPTO) 339L_LIBS= \$(L_SSL) \$(L_CRYPTO)
344#L_LIBS= \$(O_SSL) \$(O_RSAGLUE) -lrsaref \$(O_CRYPTO) 340#L_LIBS= \$(O_SSL) \$(O_RSAGLUE) -lrsaref \$(O_CRYPTO)
@@ -357,23 +353,26 @@ LIBS_DEP=\$(O_CRYPTO) \$(O_RSAGLUE) \$(O_SSL)
357EOF 353EOF
358 354
359$rules=<<"EOF"; 355$rules=<<"EOF";
360all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INC_D) headers lib exe 356all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers lib exe
361 357
362banner: 358banner:
363$banner 359$banner
364 360
365\$(TMP_D): 361\$(TMP_D):
366 \$(MKDIR) \$(TMP_D) 362 \$(MKDIR) \$(TMP_D)
367 363# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
368\$(BIN_D): 364#\$(BIN_D):
369 \$(MKDIR) \$(BIN_D) 365# \$(MKDIR) \$(BIN_D)
370 366#
371\$(TEST_D): 367#\$(TEST_D):
372 \$(MKDIR) \$(TEST_D) 368# \$(MKDIR) \$(TEST_D)
373 369
374\$(LIB_D): 370\$(LIB_D):
375 \$(MKDIR) \$(LIB_D) 371 \$(MKDIR) \$(LIB_D)
376 372
373\$(INCO_D): \$(INC_D)
374 \$(MKDIR) \$(INCO_D)
375
377\$(INC_D): 376\$(INC_D):
378 \$(MKDIR) \$(INC_D) 377 \$(MKDIR) \$(INC_D)
379 378
@@ -387,8 +386,9 @@ install:
387 \$(MKDIR) \$(INSTALLTOP) 386 \$(MKDIR) \$(INSTALLTOP)
388 \$(MKDIR) \$(INSTALLTOP)${o}bin 387 \$(MKDIR) \$(INSTALLTOP)${o}bin
389 \$(MKDIR) \$(INSTALLTOP)${o}include 388 \$(MKDIR) \$(INSTALLTOP)${o}include
389 \$(MKDIR) \$(INSTALLTOP)${o}include${o}openssl
390 \$(MKDIR) \$(INSTALLTOP)${o}lib 390 \$(MKDIR) \$(INSTALLTOP)${o}lib
391 \$(CP) \$(INC_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include 391 \$(CP) \$(INCO_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include${o}openssl
392 \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin 392 \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
393 \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib 393 \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
394 \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib 394 \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
@@ -401,6 +401,42 @@ vclean:
401 \$(RM) \$(OUT_D)$o*.* 401 \$(RM) \$(OUT_D)$o*.*
402 402
403EOF 403EOF
404
405my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
406$platform_cpp_symbol =~ s/-/_/g;
407if (open(IN,"crypto/buildinf.h"))
408 {
409 # Remove entry for this platform in existing file buildinf.h.
410
411 my $old_buildinf_h = "";
412 while (<IN>)
413 {
414 if (/^\#ifdef $platform_cpp_symbol$/)
415 {
416 while (<IN>) { last if (/^\#endif/); }
417 }
418 else
419 {
420 $old_buildinf_h .= $_;
421 }
422 }
423 close(IN);
424
425 open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
426 print OUT $old_buildinf_h;
427 close(OUT);
428 }
429
430open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
431printf OUT <<EOF;
432#ifdef $platform_cpp_symbol
433 /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
434 #define CFLAGS "$cc $cflags"
435 #define PLATFORM "$platform"
436EOF
437printf OUT " #define DATE \"%s\"\n", scalar gmtime();
438printf OUT "#endif\n";
439close(OUT);
404 440
405############################################# 441#############################################
406# We parse in input file and 'store' info for later printing. 442# We parse in input file and 'store' info for later printing.
@@ -468,8 +504,8 @@ chop($h); $header=$h;
468$defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h"); 504$defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
469$rules.=&do_copy_rule("\$(INCL_D)",$header,".h"); 505$rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
470 506
471$defs.=&do_defs("EXHEADER",$exheader,"\$(INC_D)",".h"); 507$defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)",".h");
472$rules.=&do_copy_rule("\$(INC_D)",$exheader,".h"); 508$rules.=&do_copy_rule("\$(INCO_D)",$exheader,".h");
473 509
474$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj); 510$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
475$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)"); 511$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
@@ -496,10 +532,10 @@ foreach (values %lib_nam)
496 next; 532 next;
497 } 533 }
498 534
499 if (($bn_mulw_obj ne "") && ($_ eq "CRYPTO")) 535 if (($bn_asm_obj ne "") && ($_ eq "CRYPTO"))
500 { 536 {
501 $lib_obj =~ s/\s\S*\/bn_mulw\S*/ \$(BN_MULW_OBJ)/; 537 $lib_obj =~ s/\s\S*\/bn_asm\S*/ \$(BN_ASM_OBJ)/;
502 $rules.=&do_asm_rule($bn_mulw_obj,$bn_mulw_src); 538 $rules.=&do_asm_rule($bn_asm_obj,$bn_asm_src);
503 } 539 }
504 if (($des_enc_obj ne "") && ($_ eq "CRYPTO")) 540 if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
505 { 541 {
@@ -615,6 +651,7 @@ sub var_add
615 651
616 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2; 652 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
617 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5; 653 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
654 @a=grep(!/(rmd)|(ripemd)/,@a) if $no_rmd160;
618 655
619 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa; 656 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
620 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa; 657 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
@@ -631,7 +668,7 @@ sub var_add
631 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1; 668 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
632 @a=grep(!/_mdc2$/,@a) if $no_mdc2; 669 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
633 670
634 @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa; 671 @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
635 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa; 672 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
636 @a=grep(!/^gendsa$/,@a) if $no_sha1; 673 @a=grep(!/^gendsa$/,@a) if $no_sha1;
637 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh; 674 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
@@ -677,7 +714,7 @@ sub do_defs
677 if (($_ =~ /bss_file/) && ($postfix eq ".h")) 714 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
678 { $pf=".c"; } 715 { $pf=".c"; }
679 else { $pf=$postfix; } 716 else { $pf=$postfix; }
680 if ($_ =~ /BN_MULW/) { $t="$_ "; } 717 if ($_ =~ /BN_ASM/) { $t="$_ "; }
681 elsif ($_ =~ /DES_ENC/) { $t="$_ "; } 718 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
682 elsif ($_ =~ /BF_ENC/) { $t="$_ "; } 719 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
683 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; } 720 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
@@ -704,23 +741,6 @@ sub bname
704 return($ret); 741 return($ret);
705 } 742 }
706 743
707# do a rule for each file that says 'copy' to new direcory on change
708sub do_copy_rule
709 {
710 local($to,$files,$p)=@_;
711 local($ret,$_,$n,$pp);
712
713 $files =~ s/\//$o/g if $o ne '/';
714 foreach (split(/\s+/,$files))
715 {
716 $n=&bname($_);
717 if ($n =~ /bss_file/)
718 { $pp=".c"; }
719 else { $pp=$p; }
720 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
721 }
722 return($ret);
723 }
724 744
725############################################################## 745##############################################################
726# do a rule for each file that says 'compile' to new direcory 746# do a rule for each file that says 'compile' to new direcory
@@ -746,8 +766,7 @@ sub cc_compile_target
746 local($target,$source,$ex_flags)=@_; 766 local($target,$source,$ex_flags)=@_;
747 local($ret); 767 local($ret);
748 768
749 # EAY EAY 769 $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
750 $ex_flags.=' -DCFLAGS="\"$(CC) $(CFLAG)\""' if ($source =~ /cversion/);
751 $target =~ s/\//$o/g if $o ne "/"; 770 $target =~ s/\//$o/g if $o ne "/";
752 $source =~ s/\//$o/g if $o ne "/"; 771 $source =~ s/\//$o/g if $o ne "/";
753 $ret ="$target: \$(SRC_D)$o$source\n\t"; 772 $ret ="$target: \$(SRC_D)$o$source\n\t";
@@ -791,3 +810,64 @@ sub do_shlib_rule
791 return($ret); 810 return($ret);
792 } 811 }
793 812
813# do a rule for each file that says 'copy' to new direcory on change
814sub do_copy_rule
815 {
816 local($to,$files,$p)=@_;
817 local($ret,$_,$n,$pp);
818
819 $files =~ s/\//$o/g if $o ne '/';
820 foreach (split(/\s+/,$files))
821 {
822 $n=&bname($_);
823 if ($n =~ /bss_file/)
824 { $pp=".c"; }
825 else { $pp=$p; }
826 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
827 }
828 return($ret);
829 }
830
831sub read_options
832 {
833 if (/^no-rc2$/) { $no_rc2=1; }
834 elsif (/^no-rc4$/) { $no_rc4=1; }
835 elsif (/^no-rc5$/) { $no_rc5=1; }
836 elsif (/^no-idea$/) { $no_idea=1; }
837 elsif (/^no-des$/) { $no_des=1; }
838 elsif (/^no-bf$/) { $no_bf=1; }
839 elsif (/^no-cast$/) { $no_cast=1; }
840 elsif (/^no-md2$/) { $no_md2=1; }
841 elsif (/^no-md5$/) { $no_md5=1; }
842 elsif (/^no-sha$/) { $no_sha=1; }
843 elsif (/^no-sha1$/) { $no_sha1=1; }
844 elsif (/^no-ripemd$/) { $no_ripemd=1; }
845 elsif (/^no-mdc2$/) { $no_mdc2=1; }
846 elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; }
847 elsif (/^no-rsa$/) { $no_rsa=1; }
848 elsif (/^no-dsa$/) { $no_dsa=1; }
849 elsif (/^no-dh$/) { $no_dh=1; }
850 elsif (/^no-hmac$/) { $no_hmac=1; }
851 elsif (/^no-asm$/) { $no_asm=1; }
852 elsif (/^nasm$/) { $nasm=1; }
853 elsif (/^no-ssl2$/) { $no_ssl2=1; }
854 elsif (/^no-ssl3$/) { $no_ssl3=1; }
855 elsif (/^no-err$/) { $no_err=1; }
856 elsif (/^no-sock$/) { $no_sock=1; }
857
858 elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1;
859 $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1;
860 $no_ssl2=$no_err=$no_rmd160=$no_rc5=1; }
861
862 elsif (/^rsaref$/) { $rsaref=1; }
863 elsif (/^gcc$/) { $gcc=1; }
864 elsif (/^debug$/) { $debug=1; }
865 elsif (/^shlib$/) { $shlib=1; }
866 elsif (/^dll$/) { $shlib=1; }
867 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
868 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
869 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
870 { $c_flags.="$_ "; }
871 else { return(0); }
872 return(1);
873 }
diff --git a/src/lib/libcrypto/util/mkdef.pl b/src/lib/libcrypto/util/mkdef.pl
index 8124f11292..80384af325 100644
--- a/src/lib/libcrypto/util/mkdef.pl
+++ b/src/lib/libcrypto/util/mkdef.pl
@@ -1,52 +1,96 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl -w
2# 2#
3# generate a .def file 3# generate a .def file
4# 4#
5# It does this by parsing the header files and looking for the 5# It does this by parsing the header files and looking for the
6# non-prototyped functions. 6# prototyped functions: it then prunes the output.
7# 7#
8 8
9$crypto_num="util/libeay.num"; 9$crypto_num="util/libeay.num";
10$ssl_num= "util/ssleay.num"; 10$ssl_num= "util/ssleay.num";
11 11
12$NT=1; 12my $do_update = 0;
13foreach (@ARGV) 13my $do_crypto = 0;
14my $do_ssl = 0;
15$rsaref = 0;
16
17$W32=1;
18$NT=0;
19# Set this to make typesafe STACK definitions appear in DEF
20$safe_stack_def = 1;
21
22$options="";
23open(IN,"<Makefile.ssl") || die "unable to open Makefile.ssl!\n";
24while(<IN>) {
25 $options=$1 if (/^OPTIONS=(.*)$/);
26}
27close(IN);
28
29foreach (@ARGV, split(/ /, $options))
14 { 30 {
15 $NT=1 if $_ eq "32"; 31 $W32=1 if $_ eq "32";
16 $NT=0 if $_ eq "16"; 32 $W32=0 if $_ eq "16";
33 if($_ eq "NT") {
34 $W32 = 1;
35 $NT = 1;
36 }
17 $do_ssl=1 if $_ eq "ssleay"; 37 $do_ssl=1 if $_ eq "ssleay";
38 $do_ssl=1 if $_ eq "ssl";
18 $do_crypto=1 if $_ eq "libeay"; 39 $do_crypto=1 if $_ eq "libeay";
40 $do_crypto=1 if $_ eq "crypto";
41 $do_update=1 if $_ eq "update";
42 $rsaref=1 if $_ eq "rsaref";
43
44 if (/^no-rc2$/) { $no_rc2=1; }
45 elsif (/^no-rc4$/) { $no_rc4=1; }
46 elsif (/^no-rc5$/) { $no_rc5=1; }
47 elsif (/^no-idea$/) { $no_idea=1; }
48 elsif (/^no-des$/) { $no_des=1; }
49 elsif (/^no-bf$/) { $no_bf=1; }
50 elsif (/^no-cast$/) { $no_cast=1; }
51 elsif (/^no-md2$/) { $no_md2=1; }
52 elsif (/^no-md5$/) { $no_md5=1; }
53 elsif (/^no-sha$/) { $no_sha=1; }
54 elsif (/^no-ripemd$/) { $no_ripemd=1; }
55 elsif (/^no-mdc2$/) { $no_mdc2=1; }
56 elsif (/^no-rsa$/) { $no_rsa=1; }
57 elsif (/^no-dsa$/) { $no_dsa=1; }
58 elsif (/^no-dh$/) { $no_dh=1; }
59 elsif (/^no-hmac$/) { $no_hmac=1; }
19 } 60 }
20 61
21if (!$do_ssl && !$do_crypto) 62if (!$do_ssl && !$do_crypto)
22 { 63 {
23 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 ]\n"; 64 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT ] [rsaref]\n";
24 exit(1); 65 exit(1);
25 } 66 }
26 67
27%ssl_list=&load_numbers($ssl_num); 68%ssl_list=&load_numbers($ssl_num);
69$max_ssl = $max_num;
28%crypto_list=&load_numbers($crypto_num); 70%crypto_list=&load_numbers($crypto_num);
71$max_crypto = $max_num;
29 72
30$ssl="ssl/ssl.h"; 73$ssl="ssl/ssl.h";
31 74
32$crypto ="crypto/crypto.h"; 75$crypto ="crypto/crypto.h";
33$crypto.=" crypto/des/des.h"; 76$crypto.=" crypto/des/des.h" unless $no_des;
34$crypto.=" crypto/idea/idea.h"; 77$crypto.=" crypto/idea/idea.h" unless $no_idea;
35$crypto.=" crypto/rc4/rc4.h"; 78$crypto.=" crypto/rc4/rc4.h" unless $no_rc4;
36$crypto.=" crypto/rc5/rc5.h"; 79$crypto.=" crypto/rc5/rc5.h" unless $no_rc5;
37$crypto.=" crypto/rc2/rc2.h"; 80$crypto.=" crypto/rc2/rc2.h" unless $no_rc2;
38$crypto.=" crypto/bf/blowfish.h"; 81$crypto.=" crypto/bf/blowfish.h" unless $no_bf;
39$crypto.=" crypto/cast/cast.h"; 82$crypto.=" crypto/cast/cast.h" unless $no_cast;
40$crypto.=" crypto/md2/md2.h"; 83$crypto.=" crypto/md2/md2.h" unless $no_md2;
41$crypto.=" crypto/md5/md5.h"; 84$crypto.=" crypto/md5/md5.h" unless $no_md5;
42$crypto.=" crypto/mdc2/mdc2.h"; 85$crypto.=" crypto/mdc2/mdc2.h" unless $no_mdc2;
43$crypto.=" crypto/sha/sha.h"; 86$crypto.=" crypto/sha/sha.h" unless $no_sha;
44$crypto.=" crypto/ripemd/ripemd.h"; 87$crypto.=" crypto/ripemd/ripemd.h" unless $no_ripemd;
45 88
46$crypto.=" crypto/bn/bn.h"; 89$crypto.=" crypto/bn/bn.h";
47$crypto.=" crypto/rsa/rsa.h"; 90$crypto.=" crypto/rsa/rsa.h" unless $no_rsa;
48$crypto.=" crypto/dsa/dsa.h"; 91$crypto.=" crypto/dsa/dsa.h" unless $no_dsa;
49$crypto.=" crypto/dh/dh.h"; 92$crypto.=" crypto/dh/dh.h" unless $no_dh;
93$crypto.=" crypto/hmac/hmac.h" unless $no_hmac;
50 94
51$crypto.=" crypto/stack/stack.h"; 95$crypto.=" crypto/stack/stack.h";
52$crypto.=" crypto/buffer/buffer.h"; 96$crypto.=" crypto/buffer/buffer.h";
@@ -63,182 +107,255 @@ $crypto.=" crypto/asn1/asn1.h";
63$crypto.=" crypto/asn1/asn1_mac.h"; 107$crypto.=" crypto/asn1/asn1_mac.h";
64$crypto.=" crypto/err/err.h"; 108$crypto.=" crypto/err/err.h";
65$crypto.=" crypto/pkcs7/pkcs7.h"; 109$crypto.=" crypto/pkcs7/pkcs7.h";
110$crypto.=" crypto/pkcs12/pkcs12.h";
66$crypto.=" crypto/x509/x509.h"; 111$crypto.=" crypto/x509/x509.h";
67$crypto.=" crypto/x509/x509_vfy.h"; 112$crypto.=" crypto/x509/x509_vfy.h";
113$crypto.=" crypto/x509v3/x509v3.h";
68$crypto.=" crypto/rand/rand.h"; 114$crypto.=" crypto/rand/rand.h";
69$crypto.=" crypto/hmac/hmac.h"; 115$crypto.=" crypto/comp/comp.h";
116$crypto.=" crypto/tmdiff.h";
117
118@ssl_func = &do_defs("SSLEAY", $ssl);
119@crypto_func = &do_defs("LIBEAY", $crypto);
120
121
122if ($do_update) {
123
124if ($do_ssl == 1) {
125 open(OUT, ">>$ssl_num");
126 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl, @ssl_func);
127 close OUT;
128}
70 129
71$match{'NOPROTO'}=1; 130if($do_crypto == 1) {
72$match2{'PERL5'}=1; 131 open(OUT, ">>$crypto_num");
132 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto, @crypto_func);
133 close OUT;
134}
73 135
74&print_def_file(*STDOUT,"SSLEAY",*ssl_list,&do_defs("SSLEAY",$ssl)) 136} else {
75 if $do_ssl == 1; 137
138 &print_def_file(*STDOUT,"SSLEAY",*ssl_list,@ssl_func)
139 if $do_ssl == 1;
140
141 &print_def_file(*STDOUT,"LIBEAY",*crypto_list,@crypto_func)
142 if $do_crypto == 1;
143
144}
76 145
77&print_def_file(*STDOUT,"LIBEAY",*crypto_list,&do_defs("LIBEAY",$crypto))
78 if $do_crypto == 1;
79 146
80sub do_defs 147sub do_defs
81 { 148{
82 local($name,$files)=@_; 149 my($name,$files)=@_;
83 local(@ret); 150 my @ret;
151 my %funcs;
84 152
85 $off=-1;
86 foreach $file (split(/\s+/,$files)) 153 foreach $file (split(/\s+/,$files))
87 { 154 {
88# print STDERR "reading $file\n";
89 open(IN,"<$file") || die "unable to open $file:$!\n"; 155 open(IN,"<$file") || die "unable to open $file:$!\n";
90 $depth=0; 156
91 $pr=-1; 157 my $line = "", $def= "";
92 @np=""; 158 my %tag = (
93 $/=undef; 159 FreeBSD => 0,
94 $a=<IN>; 160 NOPROTO => 0,
95 while (($i=index($a,"/*")) >= 0) 161 WIN16 => 0,
96 { 162 PERL5 => 0,
97 $j=index($a,"*/"); 163 _WINDLL => 0,
98 break unless ($j >= 0); 164 NO_FP_API => 0,
99 $a=substr($a,0,$i).substr($a,$j+2); 165 CONST_STRICT => 0,
100 # print "$i $j\n"; 166 TRUE => 1,
167 );
168 while(<IN>) {
169 last if (/BEGIN ERROR CODES/);
170 if ($line ne '') {
171 $_ = $line . $_;
172 $line = '';
101 } 173 }
102 foreach (split("\n",$a)) 174
103 { 175 if (/\\$/) {
104 if (/^\#\s*ifndef (.*)/) 176 $line = $_;
105 { 177 next;
178 }
179
180 $cpp = 1 if /^#.*ifdef.*cplusplus/;
181 if ($cpp) {
182 $cpp = 0 if /^#.*endif/;
183 next;
184 }
185
186 s/\/\*.*?\*\///gs; # ignore comments
187 s/{[^{}]*}//gs; # ignore {} blocks
188 if (/^\#\s*ifndef (.*)/) {
106 push(@tag,$1); 189 push(@tag,$1);
107 $tag{$1}=-1; 190 $tag{$1}=-1;
108 next; 191 next;
109 } 192 } elsif (/^\#\s*if !defined\(([^\)]+)\)/) {
110 elsif (/^\#\s*if !defined\(([^\)]+)\)/)
111 {
112 push(@tag,$1); 193 push(@tag,$1);
113 $tag{$1}=-1; 194 $tag{$1}=-1;
114 next; 195 next;
115 } 196 } elsif (/^\#\s*ifdef (.*)/) {
116 elsif (/^\#\s*ifdef (.*)/)
117 {
118 push(@tag,$1); 197 push(@tag,$1);
119 $tag{$1}=1; 198 $tag{$1}=1;
120 next; 199 next;
121 } 200 } elsif (/^\#\s*if defined(.*)/) {
122 elsif (/^\#\s*if defined(.*)/)
123 {
124 push(@tag,$1); 201 push(@tag,$1);
125 $tag{$1}=1; 202 $tag{$1}=1;
126 next; 203 next;
127 } 204 } elsif (/^\#\s*endif/) {
128 elsif (/^\#\s*endif/)
129 {
130 $tag{$tag[$#tag]}=0; 205 $tag{$tag[$#tag]}=0;
131 pop(@tag); 206 pop(@tag);
132 next; 207 next;
133 } 208 } elsif (/^\#\s*else/) {
134 elsif (/^\#\s*else/) 209 my $t=$tag[$#tag];
135 {
136 $t=$tag[$#tag];
137 $tag{$t}= -$tag{$t}; 210 $tag{$t}= -$tag{$t};
138 next; 211 next;
212 } elsif (/^\#\s*if\s+1/) {
213 # Dummy tag
214 push(@tag,"TRUE");
215 $tag{"TRUE"}=1;
216 next;
217 } elsif (/^\#/) {
218 next;
219 }
220 if ($safe_stack_def &&
221 /^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
222 $funcs{"sk_${1}_new"} = 1;
223 $funcs{"sk_${1}_new_null"} = 1;
224 $funcs{"sk_${1}_free"} = 1;
225 $funcs{"sk_${1}_num"} = 1;
226 $funcs{"sk_${1}_value"} = 1;
227 $funcs{"sk_${1}_set"} = 1;
228 $funcs{"sk_${1}_zero"} = 1;
229 $funcs{"sk_${1}_push"} = 1;
230 $funcs{"sk_${1}_unshift"} = 1;
231 $funcs{"sk_${1}_find"} = 1;
232 $funcs{"sk_${1}_delete"} = 1;
233 $funcs{"sk_${1}_delete_ptr"} = 1;
234 $funcs{"sk_${1}_insert"} = 1;
235 $funcs{"sk_${1}_set_cmp_func"} = 1;
236 $funcs{"sk_${1}_dup"} = 1;
237 $funcs{"sk_${1}_pop_free"} = 1;
238 $funcs{"sk_${1}_shift"} = 1;
239 $funcs{"sk_${1}_pop"} = 1;
240 $funcs{"sk_${1}_sort"} = 1;
241 } elsif ($safe_stack_def &&
242 /^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
243 $funcs{"d2i_ASN1_SET_OF_${1}"} = 1;
244 $funcs{"i2d_ASN1_SET_OF_${1}"} = 1;
245 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
246 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) {
247 if($W32) {
248 $funcs{"PEM_read_${1}"} = 1;
249 $funcs{"PEM_write_${1}"} = 1;
139 } 250 }
140#printf STDERR "$_\n%2d %2d %2d %2d %2d $NT\n", 251 $funcs{"PEM_read_bio_${1}"} = 1;
141#$tag{'NOPROTO'},$tag{'FreeBSD'},$tag{'WIN16'},$tag{'PERL5'},$tag{'NO_FP_API'}; 252 $funcs{"PEM_write_bio_${1}"} = 1;
142 253 } elsif (
143 $t=undef;
144 if (/^extern .*;$/)
145 { $t=&do_extern($name,$_); }
146 elsif ( ($tag{'NOPROTO'} == 1) &&
147 ($tag{'FreeBSD'} != 1) && 254 ($tag{'FreeBSD'} != 1) &&
148 (($NT && ($tag{'WIN16'} != 1)) || 255 ($tag{'CONST_STRICT'} != 1) &&
149 (!$NT && ($tag{'WIN16'} != -1))) && 256 (($W32 && ($tag{'WIN16'} != 1)) ||
257 (!$W32 && ($tag{'WIN16'} != -1))) &&
150 ($tag{'PERL5'} != 1) && 258 ($tag{'PERL5'} != 1) &&
151# ($tag{'_WINDLL'} != -1) && 259# ($tag{'_WINDLL'} != -1) &&
152 ((!$NT && $tag{'_WINDLL'} != -1) || 260 ((!$W32 && $tag{'_WINDLL'} != -1) ||
153 ($NT && $tag{'_WINDLL'} != 1)) && 261 ($W32 && $tag{'_WINDLL'} != 1)) &&
154 ((($tag{'NO_FP_API'} != 1) && $NT) || 262 ((($tag{'NO_FP_API'} != 1) && $W32) ||
155 (($tag{'NO_FP_API'} != -1) && !$NT))) 263 (($tag{'NO_FP_API'} != -1) && !$W32)))
156 { $t=&do_line($name,$_); }
157 else
158 { $t=undef; }
159 if (($t ne undef) && (!$done{$name,$t}))
160 { 264 {
161 $done{$name,$t}++; 265 if (/{|\/\*/) { # }
162 push(@ret,$t); 266 $line = $_;
163#printf STDERR "one:$t\n" if $t =~ /BIO_/; 267 } else {
268 $def .= $_;
269 }
164 } 270 }
165 } 271 }
166 close(IN); 272 close(IN);
273
274 foreach (split /;/, $def) {
275 s/^[\n\s]*//g;
276 s/[\n\s]*$//g;
277 next if(/typedef\W/);
278 next if(/EVP_bf/ and $no_bf);
279 next if(/EVP_cast/ and $no_cast);
280 next if(/EVP_des/ and $no_des);
281 next if(/EVP_dss/ and $no_dsa);
282 next if(/EVP_idea/ and $no_idea);
283 next if(/EVP_md2/ and $no_md2);
284 next if(/EVP_md5/ and $no_md5);
285 next if(/EVP_rc2/ and $no_rc2);
286 next if(/EVP_rc4/ and $no_rc4);
287 next if(/EVP_rc5/ and $no_rc5);
288 next if(/EVP_ripemd/ and $no_ripemd);
289 next if(/EVP_sha/ and $no_sha);
290 if (/\(\*(\w*)\([^\)]+/) {
291 $funcs{$1} = 1;
292 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s) {
293 # K&R C
294 next;
295 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
296 while (not /\(\)$/s) {
297 s/[^\(\)]*\)$/\)/s;
298 s/\([^\(\)]*\)\)$/\)/s;
299 }
300 s/\(void\)//;
301 /(\w+)\W*\(\)/s;
302 $funcs{$1} = 1;
303 } elsif (/\(/ and not (/=/)) {
304 print STDERR "File $file: cannot parse: $_;\n";
305 }
167 } 306 }
168 return(@ret);
169 } 307 }
170 308
171sub do_line 309 # Prune the returned functions
172 { 310
173 local($file,$_)=@_; 311 delete $funcs{"SSL_add_dir_cert_subjects_to_stack"};
174 local($n); 312 delete $funcs{"des_crypt"};
175 313 delete $funcs{"RSA_PKCS1_RSAref"} unless $rsaref;
176 return(undef) if /^$/; 314
177 return(undef) if /^\s/; 315 if($W32) {
178#printf STDERR "two:$_\n" if $_ =~ /BIO_/; 316 delete $funcs{"BIO_s_file_internal"};
179 if (/(CRYPTO_get_locking_callback)/) 317 delete $funcs{"BIO_new_file_internal"};
180 { return($1); } 318 delete $funcs{"BIO_new_fp_internal"};
181 elsif (/(CRYPTO_get_id_callback)/) 319 } else {
182 { return($1); } 320 if(exists $funcs{"ERR_load_CRYPTO_strings"}) {
183 elsif (/(CRYPTO_get_add_lock_callback)/) 321 delete $funcs{"ERR_load_CRYPTO_strings"};
184 { return($1); } 322 $funcs{"ERR_load_CRYPTOlib_strings"} = 1;
185 elsif (/(SSL_CTX_get_verify_callback)/)
186 { return($1); }
187 elsif (/(SSL_get_info_callback)/)
188 { return($1); }
189 elsif ((!$NT) && /(ERR_load_CRYPTO_strings)/)
190 { return("ERR_load_CRYPTOlib_strings"); }
191 elsif (!$NT && /BIO_s_file/)
192 { return(undef); }
193 elsif (!$NT && /BIO_new_file/)
194 { return(undef); }
195 elsif (!$NT && /BIO_new_fp/)
196 { return(undef); }
197 elsif ($NT && /BIO_s_file_internal/)
198 { return(undef); }
199 elsif ($NT && /BIO_new_file_internal/)
200 { return(undef); }
201 elsif ($NT && /BIO_new_fp_internal/)
202 { return(undef); }
203 else
204 {
205 /\s\**(\S+)\s*\(/;
206 return($1);
207 } 323 }
324 delete $funcs{"BIO_s_file"};
325 delete $funcs{"BIO_new_file"};
326 delete $funcs{"BIO_new_fp"};
327 }
328 if (!$NT) {
329 delete $funcs{"BIO_s_log"};
208 } 330 }
209 331
210sub do_extern 332 push @ret, keys %funcs;
211 {
212 local($file,$_)=@_;
213 local($n);
214 333
215 /\s\**(\S+);$/; 334 return(@ret);
216 return($1); 335}
217 }
218 336
219sub print_def_file 337sub print_def_file
220 { 338{
221 local(*OUT,$name,*nums,@functions)=@_; 339 (*OUT,my $name,*nums,@functions)=@_;
222 local($n)=1; 340 my $n =1;
223 341
224 if ($NT) 342 if ($W32)
225 { $name.="32"; } 343 { $name.="32"; }
226 else 344 else
227 { $name.="16"; } 345 { $name.="16"; }
228 346
229 print OUT <<"EOF"; 347 print OUT <<"EOF";
230; 348;
231; Definition file for the DDL version of the $name library from SSLeay 349; Definition file for the DLL version of the $name library from OpenSSL
232; 350;
233 351
234LIBRARY $name 352LIBRARY $name
235 353
236DESCRIPTION 'SSLeay $name - eay\@cryptsoft.com' 354DESCRIPTION 'OpenSSL $name - http://www.openssl.org/'
237 355
238EOF 356EOF
239 357
240 if (!$NT) 358 if (!$W32) {
241 {
242 print <<"EOF"; 359 print <<"EOF";
243CODE PRELOAD MOVEABLE 360CODE PRELOAD MOVEABLE
244DATA PRELOAD MOVEABLE SINGLE 361DATA PRELOAD MOVEABLE SINGLE
@@ -249,7 +366,7 @@ HEAPSIZE 4096
249STACKSIZE 8192 366STACKSIZE 8192
250 367
251EOF 368EOF
252 } 369 }
253 370
254 print "EXPORTS\n"; 371 print "EXPORTS\n";
255 372
@@ -258,35 +375,52 @@ EOF
258 (@r)=grep(!/^SSLeay/,@functions); 375 (@r)=grep(!/^SSLeay/,@functions);
259 @functions=((sort @e),(sort @r)); 376 @functions=((sort @e),(sort @r));
260 377
261 foreach $func (@functions) 378 foreach $func (@functions) {
262 { 379 if (!defined($nums{$func})) {
263 if (!defined($nums{$func})) 380 printf STDERR "$func does not have a number assigned\n"
264 { 381 if(!$do_update);
265 printf STDERR "$func does not have a number assigned\n"; 382 } else {
266 }
267 else
268 {
269 $n=$nums{$func}; 383 $n=$nums{$func};
270 printf OUT " %s%-35s@%d\n",($NT)?"":"_",$func,$n; 384 printf OUT " %s%-40s@%d\n",($W32)?"":"_",$func,$n;
271 }
272 } 385 }
273 printf OUT "\n";
274 } 386 }
387 printf OUT "\n";
388}
275 389
276sub load_numbers 390sub load_numbers
277 { 391{
278 local($name)=@_; 392 my($name)=@_;
279 local($j,@a,%ret); 393 my(@a,%ret);
394
395 $max_num = 0;
280 396
281 open(IN,"<$name") || die "unable to open $name:$!\n"; 397 open(IN,"<$name") || die "unable to open $name:$!\n";
282 while (<IN>) 398 while (<IN>) {
283 {
284 chop; 399 chop;
285 s/#.*$//; 400 s/#.*$//;
286 next if /^\s*$/; 401 next if /^\s*$/;
287 @a=split; 402 @a=split;
288 $ret{$a[0]}=$a[1]; 403 $ret{$a[0]}=$a[1];
289 } 404 $max_num = $a[1] if $a[1] > $max_num;
405 }
290 close(IN); 406 close(IN);
291 return(%ret); 407 return(%ret);
408}
409
410sub update_numbers
411{
412 (*OUT,$name,*nums,my $start_num, my @functions)=@_;
413 my $new_funcs = 0;
414 print STDERR "Updating $name\n";
415 foreach $func (@functions) {
416 if (!exists $nums{$func}) {
417 $new_funcs++;
418 printf OUT "%s%-40s%d\n","",$func, ++$start_num;
419 }
420 }
421 if($new_funcs) {
422 print STDERR "$new_funcs New Functions added\n";
423 } else {
424 print STDERR "No New Functions Added\n";
292 } 425 }
426}
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 @@
1#!/usr/local/bin/perl
2
3# mkdir-p.pl
4
5# On some systems, the -p option to mkdir (= also create any missing parent
6# directories) is not available.
7
8my $arg;
9
10foreach $arg (@ARGV) {
11 &do_mkdir_p($arg);
12}
13
14
15sub do_mkdir_p {
16 local($dir) = @_;
17
18 $dir =~ s|/*\Z(?!\n)||s;
19
20 if (-d $dir) {
21 return;
22 }
23
24 if ($dir =~ m|[^/]/|s) {
25 local($parent) = $dir;
26 $parent =~ s|[^/]*\Z(?!\n)||s;
27
28 do_mkdir_p($parent);
29 }
30
31 mkdir($dir, 0777) || die "Cannot create directory $dir: $!\n";
32 print "created directory `$dir'\n";
33}
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 @@
1#!/usr/local/bin/perl -w
2
3my $config = "crypto/err/openssl.ec";
4my $debug = 0;
5my $rebuild = 0;
6my $static = 1;
7my $recurse = 0;
8my $reindex = 0;
9my $dowrite = 0;
10
11
12while (@ARGV) {
13 my $arg = $ARGV[0];
14 if($arg eq "-conf") {
15 shift @ARGV;
16 $config = shift @ARGV;
17 } elsif($arg eq "-debug") {
18 $debug = 1;
19 shift @ARGV;
20 } elsif($arg eq "-rebuild") {
21 $rebuild = 1;
22 shift @ARGV;
23 } elsif($arg eq "-recurse") {
24 $recurse = 1;
25 shift @ARGV;
26 } elsif($arg eq "-reindex") {
27 $reindex = 1;
28 shift @ARGV;
29 } elsif($arg eq "-nostatic") {
30 $static = 0;
31 shift @ARGV;
32 } elsif($arg eq "-write") {
33 $dowrite = 1;
34 shift @ARGV;
35 } else {
36 last;
37 }
38}
39
40if($recurse) {
41 @source = (<crypto/*.c>, <crypto/*/*.c>, ,<rsaref/*.c>, <ssl/*.c>);
42} else {
43 @source = @ARGV;
44}
45
46# Read in the config file
47
48open(IN, "<$config") || die "Can't open config file $config";
49
50# Parse config file
51
52while(<IN>)
53{
54 if(/^L\s+(\S+)\s+(\S+)\s+(\S+)/) {
55 $hinc{$1} = $2;
56 $cskip{$3} = $1;
57 if($3 ne "NONE") {
58 $csrc{$1} = $3;
59 $fmax{$1} = 99;
60 $rmax{$1} = 99;
61 $fnew{$1} = 0;
62 $rnew{$1} = 0;
63 }
64 } elsif (/^F\s+(\S+)/) {
65 # Add extra function with $1
66 } elsif (/^R\s+(\S+)\s+(\S+)/) {
67 $rextra{$1} = $2;
68 $rcodes{$1} = $2;
69 }
70}
71
72close IN;
73
74# Scan each header file in turn and make a list of error codes
75# and function names
76
77while (($lib, $hdr) = each %hinc)
78{
79 next if($hdr eq "NONE");
80 print STDERR "Scanning header file $hdr\n" if $debug;
81 open(IN, "<$hdr") || die "Can't open Header file $hdr\n";
82 my $line = "", $def= "";
83 while(<IN>) {
84 last if(/BEGIN\s+ERROR\s+CODES/);
85 if ($line ne '') {
86 $_ = $line . $_;
87 $line = '';
88 }
89
90 if (/\\$/) {
91 $line = $_;
92 next;
93 }
94
95 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
96 if ($cpp) {
97 $cpp = 0 if /^#.*endif/;
98 next;
99 }
100
101 next if (/^#/); # skip preprocessor directives
102
103 s/\/\*.*?\*\///gs; # ignore comments
104 s/{[^{}]*}//gs; # ignore {} blocks
105
106 if (/{|\/\*/) { # Add a } so editor works...
107 $line = $_;
108 } else {
109 $def .= $_;
110 }
111 }
112
113 foreach (split /;/, $def) {
114 s/^[\n\s]*//g;
115 s/[\n\s]*$//g;
116 next if(/typedef\W/);
117 if (/\(\*(\w*)\([^\)]+/) {
118 my $name = $1;
119 $name =~ tr/[a-z]/[A-Z]/;
120 $ftrans{$name} = $1;
121 } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){
122 # K&R C
123 next ;
124 } elsif (/\w+\W+\w+\W*\(.*\)$/s) {
125 while (not /\(\)$/s) {
126 s/[^\(\)]*\)$/\)/s;
127 s/\([^\(\)]*\)\)$/\)/s;
128 }
129 s/\(void\)//;
130 /(\w+)\W*\(\)/s;
131 my $name = $1;
132 $name =~ tr/[a-z]/[A-Z]/;
133 $ftrans{$name} = $1;
134 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
135 print STDERR "Header $hdr: cannot parse: $_;\n";
136 }
137 }
138
139 next if $reindex;
140
141 # Scan function and reason codes and store them: keep a note of the
142 # maximum code used.
143
144 while(<IN>) {
145 if(/^#define\s+(\S+)\s+(\S+)/) {
146 $name = $1;
147 $code = $2;
148 unless($name =~ /^${lib}_([RF])_(\w+)$/) {
149 print STDERR "Invalid error code $name\n";
150 next;
151 }
152 if($1 eq "R") {
153 $rcodes{$name} = $code;
154 if(!(exists $rextra{$name}) &&
155 ($code > $rmax{$lib}) ) {
156 $rmax{$lib} = $code;
157 }
158 } else {
159 if($code > $fmax{$lib}) {
160 $fmax{$lib} = $code;
161 }
162 $fcodes{$name} = $code;
163 }
164 }
165 }
166 close IN;
167}
168
169# Scan each C source file and look for function and reason codes
170# This is done by looking for strings that "look like" function or
171# reason codes: basically anything consisting of all upper case and
172# numerics which has _F_ or _R_ in it and which has the name of an
173# error library at the start. This seems to work fine except for the
174# oddly named structure BIO_F_CTX which needs to be ignored.
175# If a code doesn't exist in list compiled from headers then mark it
176# with the value "X" as a place holder to give it a value later.
177# Store all function and reason codes found in %ufcodes and %urcodes
178# so all those unreferenced can be printed out.
179
180
181foreach $file (@source) {
182 # Don't parse the error source file.
183 next if exists $cskip{$file};
184 open(IN, "<$file") || die "Can't open source file $file\n";
185 while(<IN>) {
186 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
187 next unless exists $csrc{$2};
188 next if($1 eq "BIO_F_BUFFER_CTX");
189 $ufcodes{$1} = 1;
190 if(!exists $fcodes{$1}) {
191 $fcodes{$1} = "X";
192 $fnew{$2}++;
193 }
194 $notrans{$1} = 1 unless exists $ftrans{$3};
195 }
196 if(/(([A-Z0-9]+)_R_[A-Z0-9_]+)/) {
197 next unless exists $csrc{$2};
198 $urcodes{$1} = 1;
199 if(!exists $rcodes{$1}) {
200 $rcodes{$1} = "X";
201 $rnew{$2}++;
202 }
203 }
204 }
205 close IN;
206}
207
208# Now process each library in turn.
209
210foreach $lib (keys %csrc)
211{
212 my $hfile = $hinc{$lib};
213 my $cfile = $csrc{$lib};
214 if(!$fnew{$lib} && !$rnew{$lib}) {
215 print STDERR "$lib:\t\tNo new error codes\n";
216 next unless $rebuild;
217 } else {
218 print STDERR "$lib:\t\t$fnew{$lib} New Functions,";
219 print STDERR " $rnew{$lib} New Reasons.\n";
220 next unless $dowrite;
221 }
222
223 # If we get here then we have some new error codes so we
224 # need to rebuild the header file and C file.
225
226 # Make a sorted list of error and reason codes for later use.
227
228 my @function = sort grep(/^${lib}_/,keys %fcodes);
229 my @reasons = sort grep(/^${lib}_/,keys %rcodes);
230
231 # Rewrite the header file
232
233 open(IN, "<$hfile") || die "Can't Open Header File $hfile\n";
234
235 # Copy across the old file
236 while(<IN>) {
237 push @out, $_;
238 last if (/BEGIN ERROR CODES/);
239 }
240 close IN;
241
242 open (OUT, ">$hfile") || die "Can't Open File $hfile for writing\n";
243
244 print OUT @out;
245 undef @out;
246 print OUT <<"EOF";
247/* The following lines are auto generated by the script mkerr.pl. Any changes
248 * made after this point may be overwritten when the script is next run.
249 */
250
251/* Error codes for the $lib functions. */
252
253/* Function codes. */
254EOF
255
256 foreach $i (@function) {
257 $z=6-int(length($i)/8);
258 if($fcodes{$i} eq "X") {
259 $fcodes{$i} = ++$fmax{$lib};
260 print STDERR "New Function code $i\n" if $debug;
261 }
262 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
263 }
264
265 print OUT "\n/* Reason codes. */\n";
266
267 foreach $i (@reasons) {
268 $z=6-int(length($i)/8);
269 if($rcodes{$i} eq "X") {
270 $rcodes{$i} = ++$rmax{$lib};
271 print STDERR "New Reason code $i\n" if $debug;
272 }
273 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
274 }
275 print OUT <<"EOF";
276
277#ifdef __cplusplus
278}
279#endif
280#endif
281
282EOF
283 close OUT;
284
285 # Rewrite the C source file containing the error details.
286
287 my $hincf;
288 if($static) {
289 $hfile =~ /([^\/]+)$/;
290 $hincf = "<openssl/$1>";
291 } else {
292 $hincf = "\"$hfile\"";
293 }
294
295
296 open (OUT,">$cfile") || die "Can't open $cfile for writing";
297
298 print OUT <<"EOF";
299/* $cfile */
300/* ====================================================================
301 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
302 *
303 * Redistribution and use in source and binary forms, with or without
304 * modification, are permitted provided that the following conditions
305 * are met:
306 *
307 * 1. Redistributions of source code must retain the above copyright
308 * notice, this list of conditions and the following disclaimer.
309 *
310 * 2. Redistributions in binary form must reproduce the above copyright
311 * notice, this list of conditions and the following disclaimer in
312 * the documentation and/or other materials provided with the
313 * distribution.
314 *
315 * 3. All advertising materials mentioning features or use of this
316 * software must display the following acknowledgment:
317 * "This product includes software developed by the OpenSSL Project
318 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
319 *
320 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
321 * endorse or promote products derived from this software without
322 * prior written permission. For written permission, please contact
323 * openssl-core\@OpenSSL.org.
324 *
325 * 5. Products derived from this software may not be called "OpenSSL"
326 * nor may "OpenSSL" appear in their names without prior written
327 * permission of the OpenSSL Project.
328 *
329 * 6. Redistributions of any form whatsoever must retain the following
330 * acknowledgment:
331 * "This product includes software developed by the OpenSSL Project
332 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
333 *
334 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
335 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
336 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
337 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
338 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
339 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
340 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
341 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
342 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
343 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
344 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
345 * OF THE POSSIBILITY OF SUCH DAMAGE.
346 * ====================================================================
347 *
348 * This product includes cryptographic software written by Eric Young
349 * (eay\@cryptsoft.com). This product includes software written by Tim
350 * Hudson (tjh\@cryptsoft.com).
351 *
352 */
353
354/* NOTE: this file was auto generated by the mkerr.pl script: any changes
355 * made to it will be overwritten when the script next updates this file.
356 */
357
358#include <stdio.h>
359#include <openssl/err.h>
360#include $hincf
361
362/* BEGIN ERROR CODES */
363#ifndef NO_ERR
364static ERR_STRING_DATA ${lib}_str_functs[]=
365 {
366EOF
367 # Add each function code: if a function name is found then use it.
368 foreach $i (@function) {
369 my $fn;
370 $i =~ /^${lib}_F_(\S+)$/;
371 $fn = $1;
372 if(exists $ftrans{$fn}) {
373 $fn = $ftrans{$fn};
374 }
375 print OUT "{ERR_PACK(0,$i,0),\t\"$fn\"},\n";
376 }
377 print OUT <<"EOF";
378{0,NULL}
379 };
380
381static ERR_STRING_DATA ${lib}_str_reasons[]=
382 {
383EOF
384 # Add each reason code.
385 foreach $i (@reasons) {
386 my $rn;
387 my $nspc = 0;
388 $i =~ /^${lib}_R_(\S+)$/;
389 $rn = $1;
390 $rn =~ tr/_[A-Z]/ [a-z]/;
391 $nspc = 40 - length($i) unless length($i) > 40;
392 $nspc = " " x $nspc;
393 print OUT "{${i}${nspc},\"$rn\"},\n";
394 }
395if($static) {
396 print OUT <<"EOF";
397{0,NULL}
398 };
399
400#endif
401
402void ERR_load_${lib}_strings(void)
403 {
404 static int init=1;
405
406 if (init)
407 {
408 init=0;
409#ifndef NO_ERR
410 ERR_load_strings(ERR_LIB_${lib},${lib}_str_functs);
411 ERR_load_strings(ERR_LIB_${lib},${lib}_str_reasons);
412#endif
413
414 }
415 }
416EOF
417} else {
418 print OUT <<"EOF";
419{0,NULL}
420 };
421
422#endif
423
424#ifdef ${lib}_LIB_NAME
425static ERR_STRING_DATA ${lib}_lib_name[]=
426 {
427{0 ,${lib}_LIB_NAME},
428{0,NULL}
429 };
430#endif
431
432
433int ${lib}_lib_error_code=0;
434
435void ERR_load_${lib}_strings(void)
436 {
437 static int init=1;
438
439 if (${lib}_lib_error_code == 0)
440 ${lib}_lib_error_code=ERR_get_next_error_library();
441
442 if (init)
443 {
444 init=0;
445#ifndef NO_ERR
446 ERR_load_strings(${lib}_lib_error_code,${lib}_str_functs);
447 ERR_load_strings(${lib}_lib_error_code,${lib}_str_reasons);
448#endif
449
450#ifdef ${lib}_LIB_NAME
451 ${lib}_lib_name->error = ERR_PACK(${lib}_lib_error_code,0,0);
452 ERR_load_strings(0,${lib}_lib_name);
453#endif;
454 }
455 }
456
457void ERR_${lib}_error(int function, int reason, char *file, int line)
458 {
459 if (${lib}_lib_error_code == 0)
460 ${lib}_lib_error_code=ERR_get_next_error_library();
461 ERR_PUT_error(${lib}_lib_error_code,function,reason,file,line);
462 }
463EOF
464
465}
466
467 close OUT;
468
469}
470
471if($debug && defined(%notrans)) {
472 print STDERR "The following function codes were not translated:\n";
473 foreach(sort keys %notrans)
474 {
475 print STDERR "$_\n";
476 }
477}
478
479# Make a list of unreferenced function and reason codes
480
481foreach (keys %fcodes) {
482 push (@funref, $_) unless exists $ufcodes{$_};
483}
484
485foreach (keys %rcodes) {
486 push (@runref, $_) unless exists $urcodes{$_};
487}
488
489if($debug && defined(@funref) ) {
490 print STDERR "The following function codes were not referenced:\n";
491 foreach(sort @funref)
492 {
493 print STDERR "$_\n";
494 }
495}
496
497if($debug && defined(@runref) ) {
498 print STDERR "The following reason codes were not referenced:\n";
499 foreach(sort @runref)
500 {
501 print STDERR "$_\n";
502 }
503}
diff --git a/src/lib/libcrypto/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 @@
1#!/usr/local/bin/perl
2#
3# This is a hacked version of files.pl for systems that can't do a 'make files'.
4# Do a perl util/mkminfo.pl >MINFO to build MINFO
5# Written by Steve Henson 1999.
6
7# List of directories to process
8
9my @dirs = (
10".",
11"crypto",
12"crypto/md2",
13"crypto/md5",
14"crypto/sha",
15"crypto/mdc2",
16"crypto/hmac",
17"crypto/ripemd",
18"crypto/des",
19"crypto/rc2",
20"crypto/rc4",
21"crypto/rc5",
22"crypto/idea",
23"crypto/bf",
24"crypto/cast",
25"crypto/bn",
26"crypto/rsa",
27"crypto/dsa",
28"crypto/dh",
29"crypto/buffer",
30"crypto/bio",
31"crypto/stack",
32"crypto/lhash",
33"crypto/rand",
34"crypto/err",
35"crypto/objects",
36"crypto/evp",
37"crypto/asn1",
38"crypto/pem",
39"crypto/x509",
40"crypto/x509v3",
41"crypto/conf",
42"crypto/txt_db",
43"crypto/pkcs7",
44"crypto/pkcs12",
45"crypto/comp",
46"ssl",
47"rsaref",
48"apps",
49"test",
50"tools"
51);
52
53foreach (@dirs) {
54 &files_dir ($_, "Makefile.ssl");
55}
56
57exit(0);
58
59sub files_dir
60{
61my ($dir, $makefile) = @_;
62
63my %sym;
64
65open (IN, "$dir/$makefile") || die "Can't open $dir/$makefile";
66
67my $s="";
68
69while (<IN>)
70 {
71 chop;
72 s/#.*//;
73 if (/^(\S+)\s*=\s*(.*)$/)
74 {
75 $o="";
76 ($s,$b)=($1,$2);
77 for (;;)
78 {
79 if ($b =~ /\\$/)
80 {
81 chop($b);
82 $o.=$b." ";
83 $b=<IN>;
84 chop($b);
85 }
86 else
87 {
88 $o.=$b." ";
89 last;
90 }
91 }
92 $o =~ s/^\s+//;
93 $o =~ s/\s+$//;
94 $o =~ s/\s+/ /g;
95
96 $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
97 $sym{$s}=$o;
98 }
99 }
100
101print "RELATIVE_DIRECTORY=$dir\n";
102
103foreach (sort keys %sym)
104 {
105 print "$_=$sym{$_}\n";
106 }
107print "RELATIVE_DIRECTORY=\n";
108
109close (IN);
110}
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 @@
1#!/usr/local/bin/perl
2
3# mklink.pl
4
5# The first command line argument is a non-empty relative path
6# specifying the "from" directory.
7# Each other argument is a file name not containing / and
8# names a file in the current directory.
9#
10# For each of these files, we create in the "from" directory a link
11# of the same name pointing to the local file.
12#
13# We assume that the directory structure is a tree, i.e. that it does
14# not contain symbolic links and that the parent of / is never referenced.
15# Apart from this, this script should be able to handle even the most
16# pathological cases.
17
18my $from = shift;
19my @files = @ARGV;
20
21my @from_path = split(/\//, $from);
22my $pwd = `pwd`;
23chop($pwd);
24my @pwd_path = split(/\//, $pwd);
25
26my @to_path = ();
27
28my $dirname;
29foreach $dirname (@from_path) {
30
31 # In this loop, @to_path always is a relative path from
32 # @pwd_path (interpreted is an absolute path) to the original pwd.
33
34 # At the end, @from_path (as a relative path from the original pwd)
35 # designates the same directory as the absolute path @pwd_path,
36 # which means that @to_path then is a path from there to the original pwd.
37
38 next if ($dirname eq "" || $dirname eq ".");
39
40 if ($dirname eq "..") {
41 @to_path = (pop(@pwd_path), @to_path);
42 } else {
43 @to_path = ("..", @to_path);
44 push(@pwd_path, $dirname);
45 }
46}
47
48my $to = join('/', @to_path);
49
50my $file;
51foreach $file (@files) {
52# print "ln -s $to/$file $from/$file\n";
53 symlink("$to/$file", "$from/$file");
54 print $file . " => $from/$file\n";
55}
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 @@
1#!/bin/sh
2#
3# A bit of an ugly shell script used to actually 'link' files.
4# Used by 'make links'
5#
6
7PATH=$PATH:.:util:../util:../../util
8export PATH
9
10from=$1
11shift
12
13here=`pwd`
14tmp=`dirname $from`
15while [ "$tmp"x != "x" -a "$tmp"x != ".x" ]
16do
17 t=`basename $here`
18 here=`dirname $here`
19 to="/$t$to"
20 tmp=`dirname $tmp`
21done
22to=..$to
23
24#echo from=$from
25#echo to =$to
26#exit 1
27
28if [ "$*"x != "x" ]; then
29 for i in $*
30 do
31 /bin/rm -f $from/$i
32 point.sh $to/$i $from/$i
33 done
34fi
35exit 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# modify the '#!/usr/local/bin/perl' 3# modify the '#!/usr/local/bin/perl'
4# line in all scripts that rely on perl. 4# line in all scripts that rely on perl.
@@ -17,7 +17,12 @@ sub wanted
17 @a=<IN>; 17 @a=<IN>;
18 close(IN); 18 close(IN);
19 19
20 $a[0]="#!$ARGV[0]/perl\n"; 20 if (-d $ARGV[0]) {
21 $a[0]="#!$ARGV[0]/perl\n";
22 }
23 else {
24 $a[0]="#!$ARGV[0]\n";
25 }
21 26
22 # Playing it safe... 27 # Playing it safe...
23 $new="$_.new"; 28 $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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries 2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3# 3#
4 4
@@ -66,18 +66,18 @@ $asm='bcc -c -B -Tml';
66$afile='/o'; 66$afile='/o';
67if ($no_asm) 67if ($no_asm)
68 { 68 {
69 $bn_mulw_obj=''; 69 $bn_asm_obj='';
70 $bn_mulw_src=''; 70 $bn_asm_src='';
71 } 71 }
72elsif ($asmbits == 32) 72elsif ($asmbits == 32)
73 { 73 {
74 $bn_mulw_obj='crypto\bn\asm\x86w32.obj'; 74 $bn_asm_obj='crypto\bn\asm\x86w32.obj';
75 $bn_mulw_src='crypto\bn\asm\x86w32.asm'; 75 $bn_asm_src='crypto\bn\asm\x86w32.asm';
76 } 76 }
77else 77else
78 { 78 {
79 $bn_mulw_obj='crypto\bn\asm\x86w16.obj'; 79 $bn_asm_obj='crypto\bn\asm\x86w16.obj';
80 $bn_mulw_src='crypto\bn\asm\x86w16.asm'; 80 $bn_asm_src='crypto\bn\asm\x86w16.asm';
81 } 81 }
82 82
83sub do_lib_rule 83sub 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries 2# Borland C++ builder 3 and 4 -- Janez Jere <jj@void.si>
3# 3#
4 4
5$ssl= "ssleay32";
6$crypto="libeay32";
7$RSAref="RSAref32";
8
5$o='\\'; 9$o='\\';
6$cp='copy'; 10$cp='copy';
7$rm='del'; 11$rm='del';
8 12
9# C compiler stuff 13# C compiler stuff
10$cc='bcc32'; 14$cc='bcc32';
11 15$lflags="-ap -Tpe -x -Gn ";
16$mlflags='';
17
18$out_def="out32";
19$tmp_def="tmp32";
20$inc_def="inc32";
21#enable max error messages, disable most common warnings
22$cflags="-DWIN32_LEAN_AND_MEAN -j255 -w-aus -w-par -w-inl -c -tWC -tWM -DWINDOWS -DWIN32 -DL_ENDIAN ";
12if ($debug) 23if ($debug)
13 { $op="-v "; } 24{
14else { $op="-O "; } 25 $cflags.="-Od -y -v -vi- -D_DEBUG";
15 26 $mlflags.=' ';
16$cflags="-d $op -DL_ENDIAN "; 27}
17# I add the stack opt
18$base_lflags="-c";
19$lflags="$base_lflags";
20
21$cflags.=" -DWINDOWS -DWIN32";
22$app_cflag="-WC";
23$lib_cflag="-WC";
24$lflags.=" -Tpe";
25
26if ($shlib)
27 {
28 $mlflags="$base_lflags -Tpe"; # stack if defined in .def file
29 $libs="libw ldllcew";
30 }
31else 28else
32 { $mlflags=''; } 29{
30 $cflags.="-O2 -ff -fp";
31}
33 32
34$obj='.obj'; 33$obj='.obj';
35$ofile="-o"; 34$ofile="-o";
36 35
37# EXE linking stuff 36# EXE linking stuff
38$link="tlink32"; 37$link="ilink32";
39$efile=""; 38$efile="";
40$exep='.exe'; 39$exep='.exe';
41$ex_libs="CW32.LIB IMPORT32.LIB"; 40if ($no_sock)
42$ex_libs.=$no_sock?"":" wsock32.lib"; 41 { $ex_libs=""; }
43$shlib_ex_obj="" if $shlib; 42else { $ex_libs="cw32mt.lib import32.lib"; }
44$app_ex_obj="C0X32.OBJ";
45 43
46# static library stuff 44# static library stuff
47$mklib='tlib'; 45$mklib='tlib /P64';
48$ranlib=''; 46$ranlib='';
49$plib=""; 47$plib="";
50$libp=".lib"; 48$libp=".lib";
51$shlibp=($shlib)?".dll":".lib"; 49$shlibp=($shlib)?".dll":".lib";
52$lfile=''; 50$lfile='';
53 51
54$asm='ml /Cp /c /Cx'; 52$shlib_ex_obj="";
53$app_ex_obj="c0x32.obj";
54
55$asm='n_o_T_a_s_m';
56$asm.=" /Zi" if $debug;
55$afile='/Fo'; 57$afile='/Fo';
56if ($noasm) 58
59$bn_mulw_obj='';
60$bn_mulw_src='';
61$des_enc_obj='';
62$des_enc_src='';
63$bf_enc_obj='';
64$bf_enc_src='';
65
66if (!$no_asm)
57 { 67 {
58 $bn_mulw_obj=''; 68 $bn_mulw_obj='crypto\bn\asm\bn-win32.obj';
59 $bn_mulw_src=''; 69 $bn_mulw_src='crypto\bn\asm\bn-win32.asm';
70 $des_enc_obj='crypto\des\asm\d-win32.obj crypto\des\asm\y-win32.obj';
71 $des_enc_src='crypto\des\asm\d-win32.asm crypto\des\asm\y-win32.asm';
72 $bf_enc_obj='crypto\bf\asm\b-win32.obj';
73 $bf_enc_src='crypto\bf\asm\b-win32.asm';
74 $cast_enc_obj='crypto\cast\asm\c-win32.obj';
75 $cast_enc_src='crypto\cast\asm\c-win32.asm';
76 $rc4_enc_obj='crypto\rc4\asm\r4-win32.obj';
77 $rc4_enc_src='crypto\rc4\asm\r4-win32.asm';
78 $rc5_enc_obj='crypto\rc5\asm\r5-win32.obj';
79 $rc5_enc_src='crypto\rc5\asm\r5-win32.asm';
80 $md5_asm_obj='crypto\md5\asm\m5-win32.obj';
81 $md5_asm_src='crypto\md5\asm\m5-win32.asm';
82 $sha1_asm_obj='crypto\sha\asm\s1-win32.obj';
83 $sha1_asm_src='crypto\sha\asm\s1-win32.asm';
84 $rmd160_asm_obj='crypto\ripemd\asm\rm-win32.obj';
85 $rmd160_asm_src='crypto\ripemd\asm\rm-win32.asm';
86 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
60 } 87 }
61else 88
89if ($shlib)
62 { 90 {
63 $bn_mulw_obj='crypto\bn\asm\x86b32.obj'; 91 $mlflags.=" $lflags /dll";
64 $bn_mulw_src='crypto\bn\asm\x86m32.asm'; 92# $cflags =~ s| /MD| /MT|;
93 $lib_cflag=" /GD -D_WINDLL -D_DLL";
94 $out_def="out32dll";
95 $tmp_def="tmp32dll";
65 } 96 }
66 97
67sub do_lib_rule 98sub do_lib_rule
68 { 99 {
69 local($target,$name,$shlib)=@_; 100 local($objs,$target,$name,$shlib)=@_;
70 local($ret,$Name); 101 local($ret,$Name);
71 102
72 $taget =~ s/\//$o/g if $o ne '/'; 103 $taget =~ s/\//$o/g if $o ne '/';
73 ($Name=$name) =~ tr/a-z/A-Z/; 104 ($Name=$name) =~ tr/a-z/A-Z/;
74 105
75 $ret.="$target: \$(${Name}OBJ)\n"; 106# $target="\$(LIB_D)$o$target";
76 $ret.="\t\$(RM) \$(O_$Name)\n"; 107 $ret.="$target: $objs\n";
77
78 # Due to a pathetic line length limit, I unwrap the args.
79 local($lib_names)="";
80 local($dll_names)="";
81 foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"}))
82 {
83 $lib_names.=" +$_ &\n";
84 $dll_names.=" $_\n";
85 }
86
87 if (!$shlib) 108 if (!$shlib)
88 { 109 {
89 $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n"; 110 # $ret.="\t\$(RM) \$(O_$Name)\n";
111 $ret.="\techo LIB $<\n";
112 $ret.="\t\$(MKLIB) $lfile$target \$(addprefix +, $objs)\n";
90 } 113 }
91 else 114 else
92 { 115 {
93 # $(SHLIB_EX_OBJ) 116 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
94 local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':""; 117 $ex.=' wsock32.lib gdi32.lib';
95 $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n"; 118 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
96 $ret.=$dll_names;
97 $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n";
98 ($out_lib=$target) =~ s/O_/L_/;
99 $ret.="\timplib /nowep $out_lib $target\n\n";
100 } 119 }
101 $ret.="\n"; 120 $ret.="\n";
102 return($ret); 121 return($ret);
@@ -105,30 +124,12 @@ sub do_lib_rule
105sub do_link_rule 124sub do_link_rule
106 { 125 {
107 local($target,$files,$dep_libs,$libs)=@_; 126 local($target,$files,$dep_libs,$libs)=@_;
108 local($ret,$f,$_,@f); 127 local($ret,$_);
109 128
110 $file =~ s/\//$o/g if $o ne '/'; 129 $file =~ s/\//$o/g if $o ne '/';
111 $n=&bname($targer); 130 $n=&bname($targer);
112 $ret.="$target: $files $dep_libs\n"; 131 $ret.="$target: $files $dep_libs\n";
113 $ret.=" \$(LINK) @&&|"; 132 $ret.="\t\$(LINK) \$(LFLAGS) $files \$(APP_EX_OBJ), $target,, $libs\n\n";
114
115 # Due to a pathetic line length limit, I have to unwrap the args.
116 $r=" \$(LFLAGS) ";
117 if ($files =~ /\(([^)]*)\)$/)
118 {
119 @a=('$(APP_EX_OBJ)');
120 push(@a,sort split(/\s+/,$Vars{$1}));
121 foreach $_ (@a)
122 {
123 $ret.="\n $r $_ +";
124 $r="";
125 }
126 chop($ret);
127 $ret.="\n";
128 }
129 else
130 { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; }
131 $ret.=" $target\n\n $libs\n\n|\n\n";
132 return($ret); 133 return($ret);
133 } 134 }
134 135
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 @@
1#!/usr/local/bin/perl
2#
3# Mingw32.pl -- Mingw32 with GNU cp (Mingw32f.pl uses DOS tools)
4#
5
6$o='/';
7$cp='cp';
8$rm='rem'; # use 'rm -f' if using GNU file utilities
9$mkdir='gmkdir';
10
11# gcc wouldn't accept backslashes in paths
12#$o='\\';
13#$cp='copy';
14#$rm='del';
15
16# C compiler stuff
17
18$cc='gcc';
19if ($debug)
20 { $cflags="-g2 -ggdb"; }
21else
22 { $cflags="-DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall"; }
23
24$obj='.o';
25$ofile='-o ';
26
27# EXE linking stuff
28$link='${CC}';
29$lflags='${CFLAGS}';
30$efile='-o ';
31$exep='';
32$ex_libs="-lwsock32 -lgdi32";
33
34# static library stuff
35$mklib='ar r';
36$mlflags='';
37$ranlib='ranlib';
38$plib='lib';
39$libp=".a";
40$shlibp=".a";
41$lfile='';
42
43$asm='as';
44$afile='-o ';
45$bn_asm_obj="";
46$bn_asm_src="";
47$des_enc_obj="";
48$des_enc_src="";
49$bf_enc_obj="";
50$bf_enc_src="";
51
52sub do_lib_rule
53 {
54 local($obj,$target,$name,$shlib)=@_;
55 local($ret,$_,$Name);
56
57 $target =~ s/\//$o/g if $o ne '/';
58 $target="$target";
59 ($Name=$name) =~ tr/a-z/A-Z/;
60
61 $ret.="$target: \$(${Name}OBJ)\n";
62 $ret.="\t\$(RM) $target\n";
63 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
64 $ret.="\t\$(RANLIB) $target\n\n";
65 }
66
67sub do_link_rule
68 {
69 local($target,$files,$dep_libs,$libs)=@_;
70 local($ret,$_);
71
72 $file =~ s/\//$o/g if $o ne '/';
73 $n=&bname($target);
74 $ret.="$target: $files $dep_libs\n";
75 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
76 return($ret);
77 }
781;
79
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 @@
1#!/usr/local/bin/perl
2#
3# Mingw32f.pl -- copy files; Mingw32.pl is needed to do the compiling.
4#
5
6$o='\\';
7$cp='copy';
8$rm='del';
9
10# C compiler stuff
11
12$cc='gcc';
13if ($debug)
14 { $cflags="-g2 -ggdb"; }
15else
16 { $cflags="-O3 -fomit-frame-pointer"; }
17
18$obj='.o';
19$ofile='-o ';
20
21# EXE linking stuff
22$link='${CC}';
23$lflags='${CFLAGS}';
24$efile='-o ';
25$exep='';
26$ex_libs="-lwsock32 -lgdi32";
27
28# static library stuff
29$mklib='ar r';
30$mlflags='';
31$ranlib='ranlib';
32$plib='lib';
33$libp=".a";
34$shlibp=".a";
35$lfile='';
36
37$asm='as';
38$afile='-o ';
39$bn_asm_obj="";
40$bn_asm_src="";
41$des_enc_obj="";
42$des_enc_src="";
43$bf_enc_obj="";
44$bf_enc_src="";
45
46sub do_lib_rule
47 {
48 local($obj,$target,$name,$shlib)=@_;
49 local($ret,$_,$Name);
50
51 $target =~ s/\//$o/g if $o ne '/';
52 $target="$target";
53 ($Name=$name) =~ tr/a-z/A-Z/;
54
55 $ret.="$target: \$(${Name}OBJ)\n";
56 $ret.="\t\$(RM) $target\n";
57 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
58 $ret.="\t\$(RANLIB) $target\n\n";
59 }
60
61sub do_link_rule
62 {
63 local($target,$files,$dep_libs,$libs)=@_;
64 local($ret,$_);
65
66 $file =~ s/\//$o/g if $o ne '/';
67 $n=&bname($target);
68 $ret.="$target: $files $dep_libs\n";
69 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
70 return($ret);
71 }
721;
73
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries 2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3# 3#
4 4
@@ -84,8 +84,8 @@ $lfile='';
84$asm='ml /Cp /c /Cx'; 84$asm='ml /Cp /c /Cx';
85$afile='/Fo'; 85$afile='/Fo';
86 86
87$bn_mulw_obj=''; 87$bn_asm_obj='';
88$bn_mulw_src=''; 88$bn_asm_src='';
89$des_enc_obj=''; 89$des_enc_obj='';
90$des_enc_src=''; 90$des_enc_src='';
91$bf_enc_obj=''; 91$bf_enc_obj='';
@@ -95,13 +95,13 @@ if (!$no_asm)
95 { 95 {
96 if ($asmbits == 32) 96 if ($asmbits == 32)
97 { 97 {
98 $bn_mulw_obj='crypto\bn\asm\x86w32.obj'; 98 $bn_asm_obj='crypto\bn\asm\x86w32.obj';
99 $bn_mulw_src='crypto\bn\asm\x86w32.asm'; 99 $bn_asm_src='crypto\bn\asm\x86w32.asm';
100 } 100 }
101 else 101 else
102 { 102 {
103 $bn_mulw_obj='crypto\bn\asm\x86w16.obj'; 103 $bn_asm_obj='crypto\bn\asm\x86w16.obj';
104 $bn_mulw_src='crypto\bn\asm\x86w16.asm'; 104 $bn_asm_src='crypto\bn\asm\x86w16.asm';
105 } 105 }
106 } 106 }
107 107
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries 2# VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries
3# 3#
4 4
@@ -7,7 +7,7 @@ $crypto="libeay32";
7$RSAref="RSAref32"; 7$RSAref="RSAref32";
8 8
9$o='\\'; 9$o='\\';
10$cp='copy'; 10$cp='copy nul+'; # Timestamps get stuffed otherwise
11$rm='del'; 11$rm='del';
12 12
13# C compiler stuff 13# C compiler stuff
@@ -22,10 +22,11 @@ $inc_def="inc32";
22 22
23if ($debug) 23if ($debug)
24 { 24 {
25 $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWINDOWS -DWIN32 -D_DEBUG -DL_ENDIAN"; 25 $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWINDOWS -DWIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG";
26 $lflags.=" /debug"; 26 $lflags.=" /debug";
27 $mlflags.=' /debug'; 27 $mlflags.=' /debug';
28 } 28 }
29$cflags .= " -DWINNT" if $NT == 1;
29 30
30$obj='.obj'; 31$obj='.obj';
31$ofile="/Fo"; 32$ofile="/Fo";
@@ -48,13 +49,17 @@ $lfile='/out:';
48 49
49$shlib_ex_obj=""; 50$shlib_ex_obj="";
50$app_ex_obj="setargv.obj"; 51$app_ex_obj="setargv.obj";
51 52if ($nasm) {
52$asm='ml /Cp /coff /c /Cx'; 53 $asm='nasmw -f win32';
53$asm.=" /Zi" if $debug; 54 $afile='-o ';
54$afile='/Fo'; 55} else {
55 56 $asm='ml /Cp /coff /c /Cx';
56$bn_mulw_obj=''; 57 $asm.=" /Zi" if $debug;
57$bn_mulw_src=''; 58 $afile='/Fo';
59}
60
61$bn_asm_obj='';
62$bn_asm_src='';
58$des_enc_obj=''; 63$des_enc_obj='';
59$des_enc_src=''; 64$des_enc_src='';
60$bf_enc_obj=''; 65$bf_enc_obj='';
@@ -62,8 +67,8 @@ $bf_enc_src='';
62 67
63if (!$no_asm) 68if (!$no_asm)
64 { 69 {
65 $bn_mulw_obj='crypto\bn\asm\bn-win32.obj'; 70 $bn_asm_obj='crypto\bn\asm\bn-win32.obj';
66 $bn_mulw_src='crypto\bn\asm\bn-win32.asm'; 71 $bn_asm_src='crypto\bn\asm\bn-win32.asm';
67 $des_enc_obj='crypto\des\asm\d-win32.obj crypto\des\asm\y-win32.obj'; 72 $des_enc_obj='crypto\des\asm\d-win32.obj crypto\des\asm\y-win32.obj';
68 $des_enc_src='crypto\des\asm\d-win32.asm crypto\des\asm\y-win32.asm'; 73 $des_enc_src='crypto\des\asm\d-win32.asm crypto\des\asm\y-win32.asm';
69 $bf_enc_obj='crypto\bf\asm\b-win32.obj'; 74 $bf_enc_obj='crypto\bf\asm\b-win32.obj';
@@ -92,6 +97,8 @@ if ($shlib)
92 $tmp_def="tmp32dll"; 97 $tmp_def="tmp32dll";
93 } 98 }
94 99
100$cflags.=" /Fd$out_def";
101
95sub do_lib_rule 102sub do_lib_rule
96 { 103 {
97 local($objs,$target,$name,$shlib)=@_; 104 local($objs,$target,$name,$shlib)=@_;
@@ -110,7 +117,7 @@ sub do_lib_rule
110 else 117 else
111 { 118 {
112 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':''; 119 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
113 $ex.=' wsock32.lib gdi32.lib'; 120 $ex.=' wsock32.lib gdi32.lib advapi32.lib';
114 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n"; 121 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
115 } 122 }
116 $ret.="\n"; 123 $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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# linux.pl - the standard unix makefile stuff. 3# linux.pl - the standard unix makefile stuff.
4# 4#
@@ -17,8 +17,8 @@ else
17 17
18if (!$no_asm) 18if (!$no_asm)
19 { 19 {
20 $bn_mulw_obj='$(OBJ_D)/bn86-elf.o'; 20 $bn_asm_obj='$(OBJ_D)/bn86-elf.o';
21 $bn_mulw_src='crypto/bn/asm/bn86unix.cpp'; 21 $bn_asm_src='crypto/bn/asm/bn86unix.cpp';
22 $des_enc_obj='$(OBJ_D)/dx86-elf.o $(OBJ_D)/yx86-elf.o'; 22 $des_enc_obj='$(OBJ_D)/dx86-elf.o $(OBJ_D)/yx86-elf.o';
23 $des_enc_src='crypto/des/asm/dx86unix.cpp crypto/des/asm/yx86unix.cpp'; 23 $des_enc_src='crypto/des/asm/dx86unix.cpp crypto/des/asm/yx86unix.cpp';
24 $bf_enc_obj='$(OBJ_D)/bx86-elf.o'; 24 $bf_enc_obj='$(OBJ_D)/bx86-elf.o';
@@ -27,8 +27,12 @@ if (!$no_asm)
27 $cast_enc_src='crypto/cast/asm/cx86unix.cpp'; 27 $cast_enc_src='crypto/cast/asm/cx86unix.cpp';
28 $rc4_enc_obj='$(OBJ_D)/rx86-elf.o'; 28 $rc4_enc_obj='$(OBJ_D)/rx86-elf.o';
29 $rc4_enc_src='crypto/rc4/asm/rx86unix.cpp'; 29 $rc4_enc_src='crypto/rc4/asm/rx86unix.cpp';
30 $rc5_enc_obj='$(OBJ_D)/r586-elf.o';
31 $rc5_enc_src='crypto/rc5/asm/r586unix.cpp';
30 $md5_asm_obj='$(OBJ_D)/mx86-elf.o'; 32 $md5_asm_obj='$(OBJ_D)/mx86-elf.o';
31 $md5_asm_src='crypto/md5/asm/mx86unix.cpp'; 33 $md5_asm_src='crypto/md5/asm/mx86unix.cpp';
34 $rmd160_asm_obj='$(OBJ_D)/rm86-elf.o';
35 $rmd160_asm_src='crypto/ripemd/asm/rm86unix.cpp';
32 $sha1_asm_obj='$(OBJ_D)/sx86-elf.o'; 36 $sha1_asm_obj='$(OBJ_D)/sx86-elf.o';
33 $sha1_asm_src='crypto/sha/asm/sx86unix.cpp'; 37 $sha1_asm_src='crypto/sha/asm/sx86unix.cpp';
34 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM"; 38 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM";
@@ -51,9 +55,9 @@ sub do_shlib_rule
51 $target =~ s/\//$o/g if $o ne '/'; 55 $target =~ s/\//$o/g if $o ne '/';
52 ($Name=$name) =~ tr/a-z/A-Z/; 56 ($Name=$name) =~ tr/a-z/A-Z/;
53 57
54 $ret.="\$(LIB_D)$o$target: \$(${Name}OBJ)\n"; 58 $ret.="$target: \$(${Name}OBJ)\n";
55 $ret.="\t\$(RM) \$(LIB_D)$o$target\n"; 59 $ret.="\t\$(RM) target\n";
56 $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o \$(LIB_D)$o$target \$(${Name}OBJ)\n"; 60 $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o $target \$(${Name}OBJ)\n";
57 ($t=$target) =~ s/(^.*)\/[^\/]*$/$1/; 61 ($t=$target) =~ s/(^.*)\/[^\/]*$/$1/;
58 if ($so_name ne "") 62 if ($so_name ne "")
59 { 63 {
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 @@
1#!/usr/local/bin/perl
2#
3# linux.pl - the standard unix makefile stuff.
4#
5
6$o='/';
7$cp='/bin/cp';
8$rm='/bin/rm -f';
9
10# C compiler stuff
11
12$cc='cc';
13if ($debug)
14 { $cflags="-g -DREF_CHECK -DCRYPTO_MDEBUG"; }
15else
16 { $cflags="-O2"; }
17
18$cflags.=" -std1 -DL_ENDIAN";
19
20if (!$no_asm)
21 {
22 $bn_asm_obj='$(OBJ_D)/mips1.o';
23 $bn_asm_src='crypto/bn/asm/mips1.s';
24 }
25
26sub do_link_rule
27 {
28 local($target,$files,$dep_libs,$libs)=@_;
29 local($ret,$_);
30
31 $file =~ s/\//$o/g if $o ne '/';
32 $n=&bname($target);
33 $ret.="$target: $files $dep_libs\n";
34 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
35 return($ret);
36 }
37
381;
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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# unix.pl - the standard unix makefile stuff. 3# unix.pl - the standard unix makefile stuff.
4# 4#
@@ -38,7 +38,7 @@ $ex_libs="";
38# static library stuff 38# static library stuff
39$mklib='ar r'; 39$mklib='ar r';
40$mlflags=''; 40$mlflags='';
41$ranlib='util/ranlib.sh'; 41$ranlib=&which("ranlib") or $ranlib="true";
42$plib='lib'; 42$plib='lib';
43$libp=".a"; 43$libp=".a";
44$shlibp=".a"; 44$shlibp=".a";
@@ -46,8 +46,8 @@ $lfile='';
46 46
47$asm='as'; 47$asm='as';
48$afile='-o '; 48$afile='-o ';
49$bn_mulw_obj=""; 49$bn_asm_obj="";
50$bn_mulw_src=""; 50$bn_asm_src="";
51$des_enc_obj=""; 51$des_enc_obj="";
52$des_enc_src=""; 52$des_enc_src="";
53$bf_enc_obj=""; 53$bf_enc_obj="";
@@ -59,7 +59,7 @@ sub do_lib_rule
59 local($ret,$_,$Name); 59 local($ret,$_,$Name);
60 60
61 $target =~ s/\//$o/g if $o ne '/'; 61 $target =~ s/\//$o/g if $o ne '/';
62 $target="\$(LIB_D)$o$target"; 62 $target="$target";
63 ($Name=$name) =~ tr/a-z/A-Z/; 63 ($Name=$name) =~ tr/a-z/A-Z/;
64 64
65 $ret.="$target: \$(${Name}OBJ)\n"; 65 $ret.="$target: \$(${Name}OBJ)\n";
@@ -80,4 +80,17 @@ sub do_link_rule
80 return($ret); 80 return($ret);
81 } 81 }
82 82
83sub which
84 {
85 my ($name)=@_;
86 my $path;
87 foreach $path (split /:/, $ENV{PATH})
88 {
89 if (-x "$path/$name")
90 {
91 return "$path/$name";
92 }
93 }
94 }
95
831; 961;
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 @@
1#!/bin/sh 1#!/bin/sh
2 2
3/bin/rm -f $2 3rm -f $2
4ln -s $1 $2 4ln -s $1 $2
5echo "$2 => $1"
6
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 @@
1#!/bin/sh
2
3cwd=`pwd`
4cd /tmp
5
6if [ -s /bin/ranlib ] ; then
7 RL=/bin/ranlib
8else if [ -s /usr/bin/ranlib ] ; then
9 RL=/usr/bin/ranlib
10fi
11fi
12
13if [ "x$RL" != "x" ]
14then
15 case "$1" in
16 /*)
17 $RL "$1"
18 ;;
19 *)
20 $RL "$cwd/$1"
21 ;;
22 esac
23fi
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
21 /bin/rm -f *.old 21 /bin/rm -f *.old
22 /bin/mv Makefile.uni Makefile 22 /bin/mv Makefile.uni Makefile
23 23
24 cp $cwd/util/ranlib.sh .
25 chmod +x ranlib.sh
26
27 if [ -d asm ]; then 24 if [ -d asm ]; then
28 mkdir asm/perlasm 25 mkdir asm/perlasm
29 cp $cwd/crypto/perlasm/*.pl asm/perlasm 26 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2# 2#
3# This file takes as input, the files that have been output from 3# This file takes as input, the files that have been output from
4# ssleay speed. 4# 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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# we make up an array of 3# we make up an array of
4# $file{function_name}=filename; 4# $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 @@
1#!/usr/bin/perl
2
3$#ARGV == 0 || die "usage: ssldir.pl /new/path\n";
4@files=('crypto/cryptlib.h',
5 'Makefile.ssl',
6 'tools/c_rehash',
7 'util/mk1mf.pl',
8 );
9
10%cryptlib=(
11 '\sX509_CERT_AREA\s',"#define X509_CERT_AREA\t\t".'"%s"',
12 '\sX509_CERT_DIR\s', "#define X509_CERT_DIR\t\t".'"%s/certs"',
13 '\sX509_CERT_FILE\s', "#define X509_CERT_FILE\t\t".'"%s/cert.pem"',
14 '\sX509_PRIVATE_DIR\s',"#define X509_PRIVATE_DIR\t".'"%s/private"',
15 );
16
17%Makefile_ssl=(
18 '^INSTALLTOP=','INSTALLTOP=%s',
19 );
20
21%c_rehash=(
22 '^DIR=', 'DIR=%s',
23 );
24
25%mk1mf=(
26 '^$INSTALLTOP=','$INSTALLTOP="%s";',
27 );
28
29&dofile("crypto/cryptlib.h",$ARGV[0],%cryptlib);
30&dofile("Makefile.ssl",$ARGV[0],%Makefile_ssl);
31&dofile("tools/c_rehash",$ARGV[0],%c_rehash);
32&dofile("util/mk1mf.pl",$ARGV[0],%mk1mf);
33
34sub dofile
35 {
36 ($f,$p,%m)=@_;
37
38 open(IN,"<$f") || die "unable to open $f:$!\n";
39 @a=<IN>;
40 close(IN);
41 foreach $k (keys %m)
42 {
43 grep(/$k/ && ($_=sprintf($m{$k}."\n",$p)),@a);
44 }
45 ($ff=$f) =~ s/\..*$//;
46 open(OUT,">$ff.new") || die "unable to open $f:$!\n";
47 print OUT @a;
48 close(OUT);
49 rename($f,"$ff.old") || die "unable to rename $f\n";
50 rename("$ff.new",$f) || die "unable to rename $ff.new\n";
51 }
52
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
154TLSv1_client_method 172 154TLSv1_client_method 172
155BIO_new_buffer_ssl_connect 173 155BIO_new_buffer_ssl_connect 173
156BIO_new_ssl_connect 174 156BIO_new_ssl_connect 174
157SSL_get_ex_data_X509_STORE_CTX_idx 175
158SSL_CTX_set_tmp_dh_callback 176
159SSL_CTX_set_tmp_rsa_callback 177
160SSL_CTX_set_timeout 178
161SSL_CTX_get_timeout 179
162SSL_CTX_get_cert_store 180
163SSL_CTX_set_cert_store 181
164SSL_want 182
165SSL_library_init 183
166SSL_COMP_add_compression_method 184
167SSL_add_file_cert_subjects_to_stack 185
168SSL_set_tmp_rsa_callback 186
169SSL_set_tmp_dh_callback 187
170SSL_add_dir_cert_subjects_to_stack 188
171SSL_set_session_id_context 189
172sk_SSL_CIPHER_new 190
173sk_SSL_CIPHER_new_null 191
174sk_SSL_CIPHER_free 192
175sk_SSL_CIPHER_num 193
176sk_SSL_CIPHER_value 194
177sk_SSL_CIPHER_set 195
178sk_SSL_CIPHER_zero 196
179sk_SSL_CIPHER_push 197
180sk_SSL_CIPHER_pop 198
181sk_SSL_CIPHER_find 199
182sk_SSL_CIPHER_delete 200
183sk_SSL_CIPHER_delete_ptr 201
184sk_SSL_CIPHER_set_cmp_func 202
185sk_SSL_CIPHER_dup 203
186sk_SSL_CIPHER_pop_free 204
187sk_SSL_CIPHER_shift 205
188sk_SSL_COMP_new 206
189sk_SSL_COMP_new_null 207
190sk_SSL_COMP_free 208
191sk_SSL_COMP_num 209
192sk_SSL_COMP_value 210
193sk_SSL_COMP_set 211
194sk_SSL_COMP_zero 212
195sk_SSL_COMP_push 213
196sk_SSL_COMP_pop 214
197sk_SSL_COMP_find 215
198sk_SSL_COMP_delete 216
199sk_SSL_COMP_delete_ptr 217
200sk_SSL_COMP_set_cmp_func 218
201sk_SSL_COMP_dup 219
202sk_SSL_COMP_pop_free 220
203sk_SSL_COMP_shift 221
204SSL_CTX_use_certificate_chain_file 222
205sk_SSL_COMP_insert 223
206sk_SSL_CIPHER_insert 224
207SSL_CTX_set_verify_depth 225
208SSL_set_verify_depth 226
209sk_SSL_CIPHER_unshift 227
210SSL_CTX_get_verify_depth 228
211SSL_get_verify_depth 229
212sk_SSL_COMP_unshift 230
213SSL_CTX_set_session_id_context 231
214SSL_CTX_set_cert_verify_callback 232
215sk_SSL_COMP_sort 233
216sk_SSL_CIPHER_sort 234
217SSL_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 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3$num=1; 3$num=1;
4$width=40; 4$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 @@
1#!/usr/bin/perl
2#
3# Up the version numbers in the files.
4#
5
6@files=(
7 "crypto/crypto.h",
8 "crypto/des/ecb_enc.c",
9 "crypto/idea/i_ecb.c",
10 "crypto/lhash/lhash.c",
11 "crypto/conf/conf.c",
12 "crypto/md2/md2_dgst.c",
13 "crypto/md5/md5_dgst.c",
14 "crypto/ripemd/rmd_dgst.c",
15 "crypto/pem/pem_lib.c",
16 "crypto/bn/bn_lib.c",
17 "crypto/dh/dh_lib.c",
18 "crypto/rc2/rc2_ecb.c",
19 "crypto/rc4/rc4_skey.c",
20 "crypto/rc5/rc5_ecb.c",
21 "crypto/bf/bf_ecb.c",
22 "crypto/cast/c_ecb.c",
23 "crypto/rsa/rsa_lib.c",
24 "crypto/dsa/dsa_lib.c",
25 "crypto/sha/sha1dgst.c",
26 "crypto/sha/sha_dgst.c",
27 "crypto/asn1/asn1_lib.c",
28 "crypto/x509/x509_vfy.c",
29 "crypto/evp/evp_enc.c",
30 "crypto/rand/md_rand.c",
31 "crypto/stack/stack.c",
32 "crypto/txt_db/txt_db.c",
33 "crypto/cversion.c",
34 "ssl/ssl_lib.c",
35 "ssl/s2_lib.c",
36 "ssl/s3_lib.c",
37 "ssl/t1_lib.c",
38 "README",
39 );
40
41@month=('Jan','Feb','Mar','Apr','May','Jun',
42 'Jul','Aug','Sep','Oct','Nov','Dec');
43@a=localtime(time());
44$time=sprintf("%02d-%s-%04d",$a[3],$month[$a[4]],$a[5]+1900);
45
46$ver=$ARGV[0];
47($ver ne "") || die "no version number specified\n";
48($a,$b,$c,$d)=unpack('axaxac',$ver);
49$d=defined($d)?$d-96:0;
50$xver=sprintf("%x%x%x%x",$a,$b,$c,$d);
51
52foreach $file (@files)
53 {
54 open(IN,"<$file") || die "unable to open $file:$!\n";
55 open(OUT,">$file.new") || die "unable to open $file.new:$!\n";
56 $found=0;
57
58 print STDERR "$file:";
59
60 while (<IN>)
61 {
62 if ((s/SSLeay \d\.\d.\d[^"]*(\"|\s)/SSLeay $ver $time\1/) ||
63 s/^(\#define\s+SSLEAY_VERSION_NUMBER\s+0x)[0-9a-zA-Z]+(.*)$/$1$xver$2/)
64 {
65 print STDERR " Done";
66 $found++;
67 print OUT;
68 while (<IN>) { print OUT; }
69 last;
70 }
71 print OUT;
72 }
73 print STDERR "\n";
74 close(IN);
75 close(OUT);
76 (!$found) && die "unable to update the version number in $file\n";
77 rename($file,"$file.old") || die "unable to rename $file:$!\n";
78 rename("$file.new",$file) || die "unable to rename $file.new:$!\n";
79 }
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 @@
2 2
3echo Generating x86 assember 3echo Generating x86 assember
4echo Bignum 4echo Bignum
5(cd crypto/bn/asm; perl bn-586.pl cpp > bn86unix.cpp) 5(cd crypto/bn/asm; perl x86.pl cpp > bn86unix.cpp)
6(cd crypto/bn/asm; perl bn-586.pl win32 > bn-win32.asm) 6(cd crypto/bn/asm; perl x86.pl win32 > bn-win32.asm)
7 7
8echo DES 8echo DES
9(cd crypto/des/asm; perl des-586.pl cpp > dx86unix.cpp) 9(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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=x509
19ERRC=x509_err
20GENERAL=Makefile README 20GENERAL=Makefile README
21TEST= 21TEST=
22APPS= 22APPS=
@@ -24,18 +24,16 @@ APPS=
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \ 25LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \
26 x509_obj.c x509_req.c x509_vfy.c \ 26 x509_obj.c x509_req.c x509_vfy.c \
27 x509_set.c x509rset.c $(ERRC).c \ 27 x509_set.c x509rset.c x509_err.c \
28 x509name.c x509_v3.c x509_ext.c x509pack.c \ 28 x509name.c x509_v3.c x509_ext.c \
29 x509type.c x509_lu.c x_all.c x509_txt.c \ 29 x509type.c x509_lu.c x_all.c x509_txt.c \
30 by_file.c by_dir.c \ 30 by_file.c by_dir.c
31 v3_net.c v3_x509.c
32LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \ 31LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \
33 x509_obj.o x509_req.o x509_vfy.o \ 32 x509_obj.o x509_req.o x509_vfy.o \
34 x509_set.o x509rset.o $(ERRC).o \ 33 x509_set.o x509rset.o x509_err.o \
35 x509name.o x509_v3.o x509_ext.o x509pack.o \ 34 x509name.o x509_v3.o x509_ext.o \
36 x509type.o x509_lu.o x_all.o x509_txt.o \ 35 x509type.o x509_lu.o x_all.o x509_txt.o \
37 by_file.o by_dir.o \ 36 by_file.o by_dir.o
38 v3_net.o v3_x509.o
39 37
40SRC= $(LIBSRC) 38SRC= $(LIBSRC)
41 39
@@ -51,24 +49,23 @@ all: lib
51 49
52lib: $(LIBOBJ) 50lib: $(LIBOBJ)
53 $(AR) $(LIB) $(LIBOBJ) 51 $(AR) $(LIB) $(LIBOBJ)
54 sh $(TOP)/util/ranlib.sh $(LIB) 52 $(RANLIB) $(LIB)
55 @touch lib 53 @touch lib
56 54
57files: 55files:
58 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 56 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
59 57
60links: 58links:
61 /bin/rm -f Makefile 59 @$(TOP)/util/point.sh Makefile.ssl Makefile
62 $(TOP)/util/point.sh Makefile.ssl Makefile ; 60 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
63 $(TOP)/util/mklink.sh ../../include $(EXHEADER) 61 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
64 $(TOP)/util/mklink.sh ../../test $(TEST) 62 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
65 $(TOP)/util/mklink.sh ../../apps $(APPS)
66 63
67install: 64install:
68 @for i in $(EXHEADER) ; \ 65 @for i in $(EXHEADER) ; \
69 do \ 66 do \
70 (cp $$i $(INSTALLTOP)/include/$$i; \ 67 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
71 chmod 644 $(INSTALLTOP)/include/$$i ); \ 68 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
72 done; 69 done;
73 70
74tags: 71tags:
@@ -80,17 +77,340 @@ lint:
80 lint -DLINT $(INCLUDES) $(SRC)>fluff 77 lint -DLINT $(INCLUDES) $(SRC)>fluff
81 78
82depend: 79depend:
83 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 80 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
84 81
85dclean: 82dclean:
86 perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new 83 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
87 mv -f Makefile.new $(MAKEFILE) 84 mv -f Makefile.new $(MAKEFILE)
88 85
89clean: 86clean:
90 /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff 87 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
91
92errors:
93 perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h
94 perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c
95 88
96# DO NOT DELETE THIS LINE -- make depend depends on it. 89# DO NOT DELETE THIS LINE -- make depend depends on it.
90
91by_dir.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
92by_dir.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
93by_dir.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
94by_dir.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
95by_dir.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
96by_dir.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
97by_dir.o: ../../include/openssl/err.h ../../include/openssl/evp.h
98by_dir.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
99by_dir.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
100by_dir.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
101by_dir.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
102by_dir.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
103by_dir.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
104by_dir.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
105by_dir.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
106by_dir.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
107by_dir.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
108by_file.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
109by_file.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
110by_file.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
111by_file.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
112by_file.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
113by_file.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
114by_file.o: ../../include/openssl/err.h ../../include/openssl/evp.h
115by_file.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
116by_file.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
117by_file.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
118by_file.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
119by_file.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
120by_file.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
121by_file.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
122by_file.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
123by_file.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
124by_file.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
125by_file.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
126x509_cmp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
127x509_cmp.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
128x509_cmp.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
129x509_cmp.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
130x509_cmp.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
131x509_cmp.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
132x509_cmp.o: ../../include/openssl/err.h ../../include/openssl/evp.h
133x509_cmp.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
134x509_cmp.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
135x509_cmp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
136x509_cmp.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
137x509_cmp.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
138x509_cmp.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
139x509_cmp.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
140x509_cmp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
141x509_cmp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
142x509_cmp.o: ../cryptlib.h
143x509_d2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
144x509_d2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
145x509_d2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
146x509_d2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
147x509_d2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
148x509_d2.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
149x509_d2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
150x509_d2.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
151x509_d2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
152x509_d2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
153x509_d2.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
154x509_d2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
155x509_d2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
156x509_d2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
157x509_d2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
158x509_d2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
159x509_d2.o: ../cryptlib.h
160x509_def.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
161x509_def.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
162x509_def.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
163x509_def.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
164x509_def.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
165x509_def.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
166x509_def.o: ../../include/openssl/err.h ../../include/openssl/evp.h
167x509_def.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
168x509_def.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
169x509_def.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
170x509_def.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
171x509_def.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
172x509_def.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
173x509_def.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
174x509_def.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
175x509_def.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
176x509_def.o: ../cryptlib.h
177x509_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
178x509_err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
179x509_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
180x509_err.o: ../../include/openssl/des.h ../../include/openssl/dh.h
181x509_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
182x509_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
183x509_err.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
184x509_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
185x509_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
186x509_err.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
187x509_err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
188x509_err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
189x509_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
190x509_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
191x509_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
192x509_ext.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
193x509_ext.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
194x509_ext.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
195x509_ext.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
196x509_ext.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
197x509_ext.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
198x509_ext.o: ../../include/openssl/err.h ../../include/openssl/evp.h
199x509_ext.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
200x509_ext.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
201x509_ext.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
202x509_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
203x509_ext.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
204x509_ext.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
205x509_ext.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
206x509_ext.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
207x509_ext.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
208x509_ext.o: ../cryptlib.h
209x509_lu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
210x509_lu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
211x509_lu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
212x509_lu.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
213x509_lu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
214x509_lu.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
215x509_lu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
216x509_lu.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
217x509_lu.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
218x509_lu.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
219x509_lu.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
220x509_lu.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
221x509_lu.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
222x509_lu.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
223x509_lu.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
224x509_lu.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
225x509_lu.o: ../../include/openssl/x509_vfy.h ../cryptlib.h
226x509_obj.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
227x509_obj.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
228x509_obj.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
229x509_obj.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
230x509_obj.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
231x509_obj.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
232x509_obj.o: ../../include/openssl/err.h ../../include/openssl/evp.h
233x509_obj.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
234x509_obj.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
235x509_obj.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
236x509_obj.o: ../../include/openssl/opensslconf.h
237x509_obj.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
238x509_obj.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
239x509_obj.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
240x509_obj.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
241x509_obj.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
242x509_obj.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
243x509_obj.o: ../cryptlib.h
244x509_r2x.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
245x509_r2x.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
246x509_r2x.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
247x509_r2x.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
248x509_r2x.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
249x509_r2x.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
250x509_r2x.o: ../../include/openssl/err.h ../../include/openssl/evp.h
251x509_r2x.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
252x509_r2x.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
253x509_r2x.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
254x509_r2x.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
255x509_r2x.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
256x509_r2x.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
257x509_r2x.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
258x509_r2x.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
259x509_r2x.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
260x509_r2x.o: ../cryptlib.h
261x509_req.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
262x509_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
263x509_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
264x509_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
265x509_req.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
266x509_req.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
267x509_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
268x509_req.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
269x509_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
270x509_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
271x509_req.o: ../../include/openssl/opensslv.h ../../include/openssl/pem.h
272x509_req.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
273x509_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
274x509_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
275x509_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
276x509_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
277x509_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
278x509_req.o: ../cryptlib.h
279x509_set.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
280x509_set.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
281x509_set.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
282x509_set.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
283x509_set.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
284x509_set.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
285x509_set.o: ../../include/openssl/err.h ../../include/openssl/evp.h
286x509_set.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
287x509_set.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
288x509_set.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
289x509_set.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
290x509_set.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
291x509_set.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
292x509_set.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
293x509_set.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
294x509_set.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
295x509_set.o: ../cryptlib.h
296x509_txt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
297x509_txt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
298x509_txt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
299x509_txt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
300x509_txt.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
301x509_txt.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
302x509_txt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
303x509_txt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
304x509_txt.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
305x509_txt.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
306x509_txt.o: ../../include/openssl/opensslconf.h
307x509_txt.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
308x509_txt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
309x509_txt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
310x509_txt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
311x509_txt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
312x509_txt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
313x509_txt.o: ../cryptlib.h
314x509_v3.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
315x509_v3.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
316x509_v3.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
317x509_v3.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
318x509_v3.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
319x509_v3.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
320x509_v3.o: ../../include/openssl/err.h ../../include/openssl/evp.h
321x509_v3.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
322x509_v3.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
323x509_v3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
324x509_v3.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
325x509_v3.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
326x509_v3.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
327x509_v3.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
328x509_v3.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
329x509_v3.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
330x509_v3.o: ../cryptlib.h
331x509_vfy.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
332x509_vfy.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
333x509_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
334x509_vfy.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
335x509_vfy.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
336x509_vfy.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
337x509_vfy.o: ../../include/openssl/err.h ../../include/openssl/evp.h
338x509_vfy.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
339x509_vfy.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
340x509_vfy.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
341x509_vfy.o: ../../include/openssl/opensslconf.h
342x509_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
343x509_vfy.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
344x509_vfy.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
345x509_vfy.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
346x509_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
347x509_vfy.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
348x509_vfy.o: ../cryptlib.h
349x509name.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
350x509name.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
351x509name.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
352x509name.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
353x509name.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
354x509name.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
355x509name.o: ../../include/openssl/err.h ../../include/openssl/evp.h
356x509name.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
357x509name.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
358x509name.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
359x509name.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
360x509name.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
361x509name.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
362x509name.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
363x509name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
364x509name.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
365x509name.o: ../cryptlib.h
366x509rset.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
367x509rset.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
368x509rset.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
369x509rset.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
370x509rset.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
371x509rset.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
372x509rset.o: ../../include/openssl/err.h ../../include/openssl/evp.h
373x509rset.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
374x509rset.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
375x509rset.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
376x509rset.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
377x509rset.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
378x509rset.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
379x509rset.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
380x509rset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
381x509rset.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
382x509rset.o: ../cryptlib.h
383x509type.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
384x509type.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
385x509type.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
386x509type.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
387x509type.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
388x509type.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
389x509type.o: ../../include/openssl/err.h ../../include/openssl/evp.h
390x509type.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
391x509type.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
392x509type.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
393x509type.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
394x509type.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
395x509type.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
396x509type.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
397x509type.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
398x509type.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
399x509type.o: ../cryptlib.h
400x_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
401x_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
402x_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
403x_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
404x_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
405x_all.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
406x_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
407x_all.o: ../../include/openssl/idea.h ../../include/openssl/md2.h
408x_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
409x_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
410x_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
411x_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
412x_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
413x_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
414x_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
415x_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
416x_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 @@
1
2PKCS7
3 STACK of X509_ATTRIBUTES
4 ASN1_OBJECT
5 STACK of ASN1_TYPE
6
7So it is
8
9p7.xa[].obj
10p7.xa[].data[]
11
12get_obj_by_nid(STACK , nid)
13get_num_by_nid(STACK , nid)
14get_data_by_nid(STACK , nid, index)
15
16X509_ATTRIBUTE *X509_ATTRIBUTE_new(void );
17void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
18
19X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **ex,
20 int nid, STACK *value);
21
22X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **ex,
23 int nid, STACK *value);
24
25int X509_ATTRIBUTE_set_object(X509_ATTRIBUTE *ex,ASN1_OBJECT *obj);
26int X509_ATTRIBUTE_add_data(X509_ATTRIBUTE *ex, int index,
27 ASN1_TYPE *value);
28
29ASN1_OBJECT * X509_ATTRIBUTE_get_object(X509_ATTRIBUTE *ex);
30int X509_ATTRIBUTE_get_num(X509_ATTRIBUTE *ne);
31ASN1_TYPE * X509_ATTRIBUTE_get_data(X509_ATTRIBUTE *ne,int index);
32
33ASN1_TYPE * X509_ATTRIBUTE_get_data_by_NID(X509_ATTRIBUTE *ne,
34 ASN1_OBJECT *obj);
35
36X509_ATTRUBUTE *PKCS7_get_s_att_by_NID(PKCS7 *p7,int nid);
37X509_ATTRUBUTE *PKCS7_get_u_att_by_NID(PKCS7 *p7,int nid);
38
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 @@
63#include <sys/stat.h> 63#include <sys/stat.h>
64 64
65#include "cryptlib.h" 65#include "cryptlib.h"
66#include "lhash.h" 66#include <openssl/lhash.h>
67#include "x509.h" 67#include <openssl/x509.h>
68#include "pem.h"
69 68
70typedef struct lookup_dir_st 69typedef struct lookup_dir_st
71 { 70 {
@@ -76,21 +75,13 @@ typedef struct lookup_dir_st
76 int num_dirs_alloced; 75 int num_dirs_alloced;
77 } BY_DIR; 76 } BY_DIR;
78 77
79#ifndef NOPROTO 78static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
80static int dir_ctrl(X509_LOOKUP *ctx,int cmd,char *argp,long argl,char **ret); 79 char **ret);
81static int new_dir(X509_LOOKUP *lu); 80static int new_dir(X509_LOOKUP *lu);
82static void free_dir(X509_LOOKUP *lu); 81static void free_dir(X509_LOOKUP *lu);
83static int add_cert_dir(BY_DIR *ctx,char *dir,int type); 82static int add_cert_dir(BY_DIR *ctx,const char *dir,int type);
84static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name, 83static int get_cert_by_subject(X509_LOOKUP *xl,int type,X509_NAME *name,
85 X509_OBJECT *ret); 84 X509_OBJECT *ret);
86#else
87static int dir_ctrl();
88static int new_dir();
89static void free_dir();
90static int add_cert_dir();
91static int get_cert_by_subject();
92#endif
93
94X509_LOOKUP_METHOD x509_dir_lookup= 85X509_LOOKUP_METHOD x509_dir_lookup=
95 { 86 {
96 "Load certs from files in a directory", 87 "Load certs from files in a directory",
@@ -105,17 +96,13 @@ X509_LOOKUP_METHOD x509_dir_lookup=
105 NULL, /* get_by_alias */ 96 NULL, /* get_by_alias */
106 }; 97 };
107 98
108X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir() 99X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void)
109 { 100 {
110 return(&x509_dir_lookup); 101 return(&x509_dir_lookup);
111 } 102 }
112 103
113static int dir_ctrl(ctx,cmd,argp,argl,retp) 104static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
114X509_LOOKUP *ctx; 105 char **retp)
115int cmd;
116long argl;
117char *argp;
118char **retp;
119 { 106 {
120 int ret=0; 107 int ret=0;
121 BY_DIR *ld; 108 BY_DIR *ld;
@@ -147,8 +134,7 @@ char **retp;
147 return(ret); 134 return(ret);
148 } 135 }
149 136
150static int new_dir(lu) 137static int new_dir(X509_LOOKUP *lu)
151X509_LOOKUP *lu;
152 { 138 {
153 BY_DIR *a; 139 BY_DIR *a;
154 140
@@ -167,8 +153,7 @@ X509_LOOKUP *lu;
167 return(1); 153 return(1);
168 } 154 }
169 155
170static void free_dir(lu) 156static void free_dir(X509_LOOKUP *lu)
171X509_LOOKUP *lu;
172 { 157 {
173 BY_DIR *a; 158 BY_DIR *a;
174 int i; 159 int i;
@@ -182,17 +167,18 @@ X509_LOOKUP *lu;
182 Free(a); 167 Free(a);
183 } 168 }
184 169
185static int add_cert_dir(ctx,dir, type) 170static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
186BY_DIR *ctx;
187char *dir;
188int type;
189 { 171 {
190 int j,len; 172 int j,len;
191 int *ip; 173 int *ip;
192 char *s,*ss,*p; 174 const char *s,*ss,*p;
193 char **pp; 175 char **pp;
194 176
195 if (dir == NULL) return(0); 177 if (dir == NULL || !*dir)
178 {
179 X509err(X509_F_ADD_CERT_DIR,X509_R_INVALID_DIRECTORY);
180 return 0;
181 }
196 182
197 s=dir; 183 s=dir;
198 p=s; 184 p=s;
@@ -243,11 +229,8 @@ int type;
243 return(1); 229 return(1);
244 } 230 }
245 231
246static int get_cert_by_subject(xl,type,name,ret) 232static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
247X509_LOOKUP *xl; 233 X509_OBJECT *ret)
248int type;
249X509_NAME *name;
250X509_OBJECT *ret;
251 { 234 {
252 BY_DIR *ctx; 235 BY_DIR *ctx;
253 union { 236 union {
@@ -266,7 +249,7 @@ X509_OBJECT *ret;
266 BUF_MEM *b=NULL; 249 BUF_MEM *b=NULL;
267 struct stat st; 250 struct stat st;
268 X509_OBJECT stmp,*tmp; 251 X509_OBJECT stmp,*tmp;
269 char *postfix=""; 252 const char *postfix="";
270 253
271 if (name == NULL) return(0); 254 if (name == NULL) return(0);
272 255
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 @@
63#include <sys/stat.h> 63#include <sys/stat.h>
64 64
65#include "cryptlib.h" 65#include "cryptlib.h"
66#include "lhash.h" 66#include <openssl/lhash.h>
67#include "buffer.h" 67#include <openssl/buffer.h>
68#include "x509.h" 68#include <openssl/x509.h>
69#include "pem.h" 69#include <openssl/pem.h>
70 70
71#ifndef NO_STDIO 71#ifndef NO_STDIO
72 72
73#ifndef NOPROTO 73static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
74static int by_file_ctrl(X509_LOOKUP *ctx,int cmd,char *argc, 74 long argl, char **ret);
75 long argl,char **ret);
76#else
77static int by_file_ctrl();
78#endif
79
80X509_LOOKUP_METHOD x509_file_lookup= 75X509_LOOKUP_METHOD x509_file_lookup=
81 { 76 {
82 "Load file into cache", 77 "Load file into cache",
@@ -91,17 +86,13 @@ X509_LOOKUP_METHOD x509_file_lookup=
91 NULL, /* get_by_alias */ 86 NULL, /* get_by_alias */
92 }; 87 };
93 88
94X509_LOOKUP_METHOD *X509_LOOKUP_file() 89X509_LOOKUP_METHOD *X509_LOOKUP_file(void)
95 { 90 {
96 return(&x509_file_lookup); 91 return(&x509_file_lookup);
97 } 92 }
98 93
99static int by_file_ctrl(ctx,cmd,argp,argl,ret) 94static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
100X509_LOOKUP *ctx; 95 char **ret)
101int cmd;
102char *argp;
103long argl;
104char **ret;
105 { 96 {
106 int ok=0,ok2=0; 97 int ok=0,ok2=0;
107 char *file; 98 char *file;
@@ -138,10 +129,7 @@ char **ret;
138 return((ok && ok2)?ok:0); 129 return((ok && ok2)?ok:0);
139 } 130 }
140 131
141int X509_load_cert_file(ctx,file,type) 132int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
142X509_LOOKUP *ctx;
143char *file;
144int type;
145 { 133 {
146 int ret=0; 134 int ret=0;
147 BIO *in=NULL; 135 BIO *in=NULL;
@@ -161,7 +149,7 @@ int type;
161 { 149 {
162 for (;;) 150 for (;;)
163 { 151 {
164 x=PEM_read_bio_X509(in,NULL,NULL); 152 x=PEM_read_bio_X509(in,NULL,NULL,NULL);
165 if (x == NULL) 153 if (x == NULL)
166 { 154 {
167 if ((ERR_GET_REASON(ERR_peek_error()) == 155 if ((ERR_GET_REASON(ERR_peek_error()) ==
@@ -208,10 +196,7 @@ err:
208 return(ret); 196 return(ret);
209 } 197 }
210 198
211int X509_load_crl_file(ctx,file,type) 199int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
212X509_LOOKUP *ctx;
213char *file;
214int type;
215 { 200 {
216 int ret=0; 201 int ret=0;
217 BIO *in=NULL; 202 BIO *in=NULL;
@@ -231,7 +216,7 @@ int type;
231 { 216 {
232 for (;;) 217 for (;;)
233 { 218 {
234 x=PEM_read_bio_X509_CRL(in,NULL,NULL); 219 x=PEM_read_bio_X509_CRL(in,NULL,NULL,NULL);
235 if (x == NULL) 220 if (x == NULL)
236 { 221 {
237 if ((ERR_GET_REASON(ERR_peek_error()) == 222 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 @@
1/* crypto/x509/v3_net.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "stack.h"
61#include "cryptlib.h"
62#include "asn1.h"
63#include "objects.h"
64#include "x509.h"
65
66#define NETSCAPE_X509_EXT_NUM 8
67
68static X509_EXTENSION_METHOD netscape_x509_ext[NETSCAPE_X509_EXT_NUM]={
69{NID_netscape_ca_policy_url, V_ASN1_IA5STRING,X509_EXT_PACK_STRING},
70{NID_netscape_ssl_server_name, V_ASN1_IA5STRING,X509_EXT_PACK_STRING},
71{NID_netscape_revocation_url, V_ASN1_IA5STRING,X509_EXT_PACK_STRING},
72{NID_netscape_base_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING},
73{NID_netscape_cert_type,V_ASN1_BIT_STRING,X509_EXT_PACK_STRING},
74{NID_netscape_ca_revocation_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING},
75{NID_netscape_renewal_url,V_ASN1_IA5STRING,X509_EXT_PACK_STRING},
76{NID_netscape_comment,V_ASN1_IA5STRING,X509_EXT_PACK_STRING},
77 };
78
79int X509v3_add_netscape_extensions()
80 {
81 int i;
82
83 for (i=0; i<NETSCAPE_X509_EXT_NUM; i++)
84 if (!X509v3_add_extension(&(netscape_x509_ext[i])))
85 return(0);
86 return(1);
87 }
diff --git a/src/lib/libcrypto/x509/v3_x509.c b/src/lib/libcrypto/x509/v3_x509.c
deleted file mode 100644
index f685aa4c71..0000000000
--- a/src/lib/libcrypto/x509/v3_x509.c
+++ /dev/null
@@ -1,253 +0,0 @@
1/* crypto/x509/v3_x509.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "stack.h"
62#include "cryptlib.h"
63#include "bio.h"
64#include "asn1.h"
65#include "objects.h"
66#include "x509.h"
67
68#if 0
69static int i2a_key_usage(BIO *bp, X509 *x);
70static int a2i_key_usage(X509 *x, char *str, int len);
71#endif
72
73int X509v3_get_key_usage(X509 *x);
74int X509v3_set_key_usage(X509 *x,unsigned int use);
75int i2a_X509v3_key_usage(BIO *bp, unsigned int use);
76unsigned int a2i_X509v3_key_usage(char *p);
77
78#define STD_X509_EXT_NUM 9
79
80#if 0
81static X509_OBJECTS std_x509_ext[STD_X509_EXT_NUM]={
82{NID_subject_key_identifier, NULL,NULL},
83{NID_key_usage, a2i_key_usage,i2a_key_usage}, /**/
84{NID_private_key_usage_period, NULL,NULL},
85{NID_subject_alt_name, NULL,NULL},
86{NID_issuer_alt_name, NULL,NULL},
87{NID_basic_constraints, NULL,NULL},
88{NID_crl_number, NULL,NULL},
89{NID_certificate_policies, NULL,NULL},
90{NID_authority_key_identifier, NULL,NULL},
91 };
92#endif
93
94int X509v3_add_standard_extensions()
95 {
96
97#if 0
98 for (i=0; i<STD_X509_EXT_NUM; i++)
99 if (!X509v3_add_extension(&(std_x509_ext[i])))
100 return(0);
101#endif
102 return(1);
103 }
104
105int X509v3_get_key_usage(x)
106X509 *x;
107 {
108 X509_EXTENSION *ext;
109 ASN1_STRING *st;
110 char *p;
111 int i;
112
113 i=X509_get_ext_by_NID(x,NID_key_usage,-1);
114 if (i < 0) return(X509v3_KU_UNDEF);
115 ext=X509_get_ext(x,i);
116 st=X509v3_unpack_string(NULL,V_ASN1_BIT_STRING,
117 X509_EXTENSION_get_data(X509_get_ext(x,i)));
118
119 p=(char *)ASN1_STRING_data(st);
120 if (ASN1_STRING_length(st) == 1)
121 i=p[0];
122 else if (ASN1_STRING_length(st) == 2)
123 i=p[0]|(p[1]<<8);
124 else
125 i=0;
126 return(i);
127 }
128
129static struct
130 {
131 char *name;
132 unsigned int value;
133 } key_usage_data[] ={
134 {"digitalSignature", X509v3_KU_DIGITAL_SIGNATURE},
135 {"nonRepudiation", X509v3_KU_NON_REPUDIATION},
136 {"keyEncipherment", X509v3_KU_KEY_ENCIPHERMENT},
137 {"dataEncipherment", X509v3_KU_DATA_ENCIPHERMENT},
138 {"keyAgreement", X509v3_KU_KEY_AGREEMENT},
139 {"keyCertSign", X509v3_KU_KEY_CERT_SIGN},
140 {"cRLSign", X509v3_KU_CRL_SIGN},
141 {"encipherOnly", X509v3_KU_ENCIPHER_ONLY},
142 {"decipherOnly", X509v3_KU_DECIPHER_ONLY},
143 {NULL,0},
144 };
145
146#if 0
147static int a2i_key_usage(x,str,len)
148X509 *x;
149char *str;
150int len;
151 {
152 return(X509v3_set_key_usage(x,a2i_X509v3_key_usage(str)));
153 }
154
155static int i2a_key_usage(bp,x)
156BIO *bp;
157X509 *x;
158 {
159 return(i2a_X509v3_key_usage(bp,X509v3_get_key_usage(x)));
160 }
161#endif
162
163int i2a_X509v3_key_usage(bp,use)
164BIO *bp;
165unsigned int use;
166 {
167 int i=0,first=1;
168
169 for (;;)
170 {
171 if (use | key_usage_data[i].value)
172 {
173 BIO_printf(bp,"%s%s",((first)?"":" "),
174 key_usage_data[i].name);
175 first=0;
176 }
177 }
178 return(1);
179 }
180
181unsigned int a2i_X509v3_key_usage(p)
182char *p;
183 {
184 unsigned int ret=0;
185 char *q,*s;
186 int i,n;
187
188 q=p;
189 for (;;)
190 {
191 while ((*q != '\0') && isalnum(*q))
192 q++;
193 if (*q == '\0') break;
194 s=q++;
195 while (isalnum(*q))
196 q++;
197 n=q-s;
198 i=0;
199 for (;;)
200 {
201 if (strncmp(key_usage_data[i].name,s,n) == 0)
202 {
203 ret|=key_usage_data[i].value;
204 break;
205 }
206 i++;
207 if (key_usage_data[i].name == NULL)
208 return(X509v3_KU_UNDEF);
209 }
210 }
211 return(ret);
212 }
213
214int X509v3_set_key_usage(x,use)
215X509 *x;
216unsigned int use;
217 {
218 ASN1_OCTET_STRING *os;
219 X509_EXTENSION *ext;
220 int i;
221 unsigned char data[4];
222
223 i=X509_get_ext_by_NID(x,NID_key_usage,-1);
224 if (i < 0)
225 {
226 i=X509_get_ext_count(x)+1;
227 if ((ext=X509_EXTENSION_new()) == NULL) return(0);
228 if (!X509_add_ext(x,ext,i))
229 {
230 X509_EXTENSION_free(ext);
231 return(0);
232 }
233 }
234 else
235 ext=X509_get_ext(x,i);
236
237 /* fill in 'ext' */
238 os=X509_EXTENSION_get_data(ext);
239
240 i=0;
241 if (use > 0)
242 {
243 i=1;
244 data[0]=use&0xff;
245 }
246 if (use > 0xff)
247 {
248 i=2;
249 data[1]=(use>>8)&0xff;
250 }
251 return((X509v3_pack_string(&os,V_ASN1_BIT_STRING,data,i) == NULL)?0:1);
252 }
253
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 @@
1X509_verify()
2X509_sign()
3
4X509_get_version()
5X509_get_serialNumber()
6X509_get_issuer()
7X509_get_subject()
8X509_get_notBefore()
9X509_get_notAfter()
10X509_get_pubkey()
11
12X509_set_version()
13X509_set_serialNumber()
14X509_set_issuer()
15X509_set_subject()
16X509_set_notBefore()
17X509_set_notAfter()
18X509_set_pubkey()
19
20X509_get_extensions()
21X509_set_extensions()
22
23X509_EXTENSIONS_clear()
24X509_EXTENSIONS_retrieve()
25X509_EXTENSIONS_add()
26X509_EXTENSIONS_delete()
27
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 @@
1/* Error codes for the X509 functions. */
2
3/* Function codes. */
4#define X509_F_ADD_CERT_DIR 100
5#define X509_F_BY_FILE_CTRL 101
6#define X509_F_DIR_CTRL 102
7#define X509_F_GET_CERT_BY_SUBJECT 103
8#define X509_F_X509V3_ADD_EXT 104
9#define X509_F_X509V3_ADD_EXTENSION 105
10#define X509_F_X509V3_PACK_STRING 106
11#define X509_F_X509V3_UNPACK_STRING 107
12#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
13#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
14#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
15#define X509_F_X509_LOAD_CERT_FILE 111
16#define X509_F_X509_LOAD_CRL_FILE 112
17#define X509_F_X509_NAME_ADD_ENTRY 113
18#define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114
19#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
20#define X509_F_X509_NAME_ONELINE 116
21#define X509_F_X509_NAME_PRINT 117
22#define X509_F_X509_PRINT_FP 118
23#define X509_F_X509_PUBKEY_GET 119
24#define X509_F_X509_PUBKEY_SET 120
25#define X509_F_X509_REQ_PRINT 121
26#define X509_F_X509_REQ_PRINT_FP 122
27#define X509_F_X509_REQ_TO_X509 123
28#define X509_F_X509_STORE_ADD_CERT 124
29#define X509_F_X509_STORE_ADD_CRL 125
30#define X509_F_X509_TO_X509_REQ 126
31#define X509_F_X509_VERIFY_CERT 127
32
33/* Reason codes. */
34#define X509_R_BAD_X509_FILETYPE 100
35#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
36#define X509_R_ERR_ASN1_LIB 102
37#define X509_R_LOADING_CERT_DIR 103
38#define X509_R_LOADING_DEFAULTS 104
39#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105
40#define X509_R_SHOULD_RETRY 106
41#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107
42#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
43#define X509_R_UNKNOWN_NID 109
44#define X509_R_UNKNOWN_STRING_TYPE 110
45#define X509_R_UNSUPPORTED_ALGORITHM 111
46#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 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include "stack.h" 66#ifdef VMS
67#include "asn1.h" 67#undef X509_REVOKED_get_ext_by_critical
68#define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
69#endif
70
71#include <openssl/stack.h>
72#include <openssl/asn1.h>
73#include <openssl/safestack.h>
68 74
69#ifndef NO_RSA 75#ifndef NO_RSA
70#include "rsa.h" 76#include <openssl/rsa.h>
71#else
72#define RSA long
73#endif 77#endif
74 78
75#ifndef NO_DSA 79#ifndef NO_DSA
76#include "dsa.h" 80#include <openssl/dsa.h>
77#else
78#define DSA long
79#endif 81#endif
80 82
81#ifndef NO_DH 83#ifndef NO_DH
82#include "dh.h" 84#include <openssl/dh.h>
83#else
84#define DH long
85#endif 85#endif
86 86
87#include "evp.h" 87#include <openssl/evp.h>
88
89
90#ifdef WIN32
91/* Under Win32 this is defined in wincrypt.h */
92#undef X509_NAME
93#endif
88 94
89#define X509_FILETYPE_PEM 1 95#define X509_FILETYPE_PEM 1
90#define X509_FILETYPE_ASN1 2 96#define X509_FILETYPE_ASN1 2
@@ -114,6 +120,9 @@ typedef struct X509_algor_st
114 ASN1_TYPE *parameter; 120 ASN1_TYPE *parameter;
115 } X509_ALGOR; 121 } X509_ALGOR;
116 122
123DECLARE_STACK_OF(X509_ALGOR)
124DECLARE_ASN1_SET_OF(X509_ALGOR)
125
117typedef struct X509_val_st 126typedef struct X509_val_st
118 { 127 {
119 ASN1_UTCTIME *notBefore; 128 ASN1_UTCTIME *notBefore;
@@ -124,7 +133,7 @@ typedef struct X509_pubkey_st
124 { 133 {
125 X509_ALGOR *algor; 134 X509_ALGOR *algor;
126 ASN1_BIT_STRING *public_key; 135 ASN1_BIT_STRING *public_key;
127 struct evp_pkey_st /* EVP_PKEY*/ *pkey; 136 EVP_PKEY *pkey;
128 } X509_PUBKEY; 137 } X509_PUBKEY;
129 138
130typedef struct X509_sig_st 139typedef struct X509_sig_st
@@ -141,10 +150,13 @@ typedef struct X509_name_entry_st
141 int size; /* temp variable */ 150 int size; /* temp variable */
142 } X509_NAME_ENTRY; 151 } X509_NAME_ENTRY;
143 152
153DECLARE_STACK_OF(X509_NAME_ENTRY)
154DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)
155
144/* we always keep X509_NAMEs in 2 forms. */ 156/* we always keep X509_NAMEs in 2 forms. */
145typedef struct X509_name_st 157typedef struct X509_name_st
146 { 158 {
147 STACK *entries; /* of X509_NAME_ENTRY */ 159 STACK_OF(X509_NAME_ENTRY) *entries;
148 int modified; /* true if 'bytes' needs to be built */ 160 int modified; /* true if 'bytes' needs to be built */
149#ifdef HEADER_BUFFER_H 161#ifdef HEADER_BUFFER_H
150 BUF_MEM *bytes; 162 BUF_MEM *bytes;
@@ -154,6 +166,8 @@ typedef struct X509_name_st
154 unsigned long hash; /* Keep the hash around for lookups */ 166 unsigned long hash; /* Keep the hash around for lookups */
155 } X509_NAME; 167 } X509_NAME;
156 168
169DECLARE_STACK_OF(X509_NAME)
170
157#define X509_EX_V_NETSCAPE_HACK 0x8000 171#define X509_EX_V_NETSCAPE_HACK 0x8000
158#define X509_EX_V_INIT 0x0001 172#define X509_EX_V_INIT 0x0001
159typedef struct X509_extension_st 173typedef struct X509_extension_st
@@ -167,23 +181,23 @@ typedef struct X509_extension_st
167 void (*ex_free)(); /* clear argp stuff */ 181 void (*ex_free)(); /* clear argp stuff */
168 } X509_EXTENSION; 182 } X509_EXTENSION;
169 183
170/* #if 1 */ 184DECLARE_STACK_OF(X509_EXTENSION)
171typedef struct x509_extension_method_st 185DECLARE_ASN1_SET_OF(X509_EXTENSION)
186
187/* a sequence of these are used */
188typedef struct x509_attributes_st
172 { 189 {
173 int nid; 190 ASN1_OBJECT *object;
174 int data_type; 191 int set; /* 1 for a set, 0 for a single item (which is wrong) */
175 int pack_type; 192 union {
176 void (*ex_clear)(); 193 char *ptr;
177 int (*ex_get_bool)(); 194/* 1 */ STACK_OF(ASN1_TYPE) *set;
178 int (*ex_set_bool)(); 195/* 0 */ ASN1_TYPE *single;
179 int (*ex_get_str)(); 196 } value;
180 int (*ex_set_str)(); 197 } X509_ATTRIBUTE;
181 char *(*ex_get_struct)(); 198
182 int (*ex_set_struct)(); 199DECLARE_STACK_OF(X509_ATTRIBUTE)
183 int (*a2i)(); 200DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)
184 int (*i2a)();
185 } X509_EXTENSION_METHOD;
186/* #endif */
187 201
188typedef struct X509_req_info_st 202typedef struct X509_req_info_st
189 { 203 {
@@ -191,7 +205,7 @@ typedef struct X509_req_info_st
191 X509_NAME *subject; 205 X509_NAME *subject;
192 X509_PUBKEY *pubkey; 206 X509_PUBKEY *pubkey;
193 /* d=2 hl=2 l= 0 cons: cont: 00 */ 207 /* d=2 hl=2 l= 0 cons: cont: 00 */
194 STACK /* X509_ATTRIBUTE */ *attributes; /* [ 0 ] */ 208 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
195 int req_kludge; 209 int req_kludge;
196 } X509_REQ_INFO; 210 } X509_REQ_INFO;
197 211
@@ -214,7 +228,7 @@ typedef struct x509_cinf_st
214 X509_PUBKEY *key; 228 X509_PUBKEY *key;
215 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */ 229 ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */
216 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */ 230 ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */
217 STACK /* X509_EXTENSION */ *extensions; /* [ 3 ] optional in v3 */ 231 STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */
218 } X509_CINF; 232 } X509_CINF;
219 233
220typedef struct x509_st 234typedef struct x509_st
@@ -227,14 +241,20 @@ typedef struct x509_st
227 char *name; 241 char *name;
228 } X509; 242 } X509;
229 243
244DECLARE_STACK_OF(X509)
245DECLARE_ASN1_SET_OF(X509)
246
230typedef struct X509_revoked_st 247typedef struct X509_revoked_st
231 { 248 {
232 ASN1_INTEGER *serialNumber; 249 ASN1_INTEGER *serialNumber;
233 ASN1_UTCTIME *revocationDate; 250 ASN1_UTCTIME *revocationDate;
234 STACK /* optional X509_EXTENSION */ *extensions; 251 STACK_OF(X509_EXTENSION) /* optional */ *extensions;
235 int sequence; /* load sequence */ 252 int sequence; /* load sequence */
236 } X509_REVOKED; 253 } X509_REVOKED;
237 254
255DECLARE_STACK_OF(X509_REVOKED)
256DECLARE_ASN1_SET_OF(X509_REVOKED)
257
238typedef struct X509_crl_info_st 258typedef struct X509_crl_info_st
239 { 259 {
240 ASN1_INTEGER *version; 260 ASN1_INTEGER *version;
@@ -242,8 +262,8 @@ typedef struct X509_crl_info_st
242 X509_NAME *issuer; 262 X509_NAME *issuer;
243 ASN1_UTCTIME *lastUpdate; 263 ASN1_UTCTIME *lastUpdate;
244 ASN1_UTCTIME *nextUpdate; 264 ASN1_UTCTIME *nextUpdate;
245 STACK /* X509_REVOKED */ *revoked; 265 STACK_OF(X509_REVOKED) *revoked;
246 STACK /* [0] X509_EXTENSION */ *extensions; 266 STACK_OF(X509_EXTENSION) /* [0] */ *extensions;
247 } X509_CRL_INFO; 267 } X509_CRL_INFO;
248 268
249typedef struct X509_crl_st 269typedef struct X509_crl_st
@@ -255,17 +275,8 @@ typedef struct X509_crl_st
255 int references; 275 int references;
256 } X509_CRL; 276 } X509_CRL;
257 277
258/* a sequence of these are used */ 278DECLARE_STACK_OF(X509_CRL)
259typedef struct x509_attributes_st 279DECLARE_ASN1_SET_OF(X509_CRL)
260 {
261 ASN1_OBJECT *object;
262 int set; /* 1 for a set, 0 for a single item (which is wrong) */
263 union {
264 char *ptr;
265/* 1 */ STACK /* ASN1_TYPE */ *set;
266/* 0 */ ASN1_TYPE *single;
267 } value;
268 } X509_ATTRIBUTE;
269 280
270typedef struct private_key_st 281typedef struct private_key_st
271 { 282 {
@@ -301,6 +312,8 @@ typedef struct X509_info_st
301 312
302 int references; 313 int references;
303 } X509_INFO; 314 } X509_INFO;
315
316DECLARE_STACK_OF(X509_INFO)
304#endif 317#endif
305 318
306/* The next 2 structures and their 8 routines were sent to me by 319/* The next 2 structures and their 8 routines were sent to me by
@@ -320,17 +333,55 @@ typedef struct Netscape_spki_st
320 ASN1_BIT_STRING *signature; 333 ASN1_BIT_STRING *signature;
321 } NETSCAPE_SPKI; 334 } NETSCAPE_SPKI;
322 335
323#ifndef HEADER_BN_H 336/* Netscape certificate sequence structure */
324#define BIGNUM char 337typedef struct Netscape_certificate_sequence
325#endif 338 {
339 ASN1_OBJECT *type;
340 STACK_OF(X509) *certs;
341 } NETSCAPE_CERT_SEQUENCE;
326 342
327typedef struct CBCParameter_st 343typedef struct CBCParameter_st
328 { 344 {
329 unsigned char iv[8]; 345 unsigned char iv[8];
330 } CBC_PARAM; 346 } CBC_PARAM;
331 347
332#include "x509_vfy.h" 348/* Password based encryption structure */
333#include "pkcs7.h" 349
350typedef struct PBEPARAM_st {
351ASN1_OCTET_STRING *salt;
352ASN1_INTEGER *iter;
353} PBEPARAM;
354
355/* Password based encryption V2 structures */
356
357typedef struct PBE2PARAM_st {
358X509_ALGOR *keyfunc;
359X509_ALGOR *encryption;
360} PBE2PARAM;
361
362typedef struct PBKDF2PARAM_st {
363ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */
364ASN1_INTEGER *iter;
365ASN1_INTEGER *keylength;
366X509_ALGOR *prf;
367} PBKDF2PARAM;
368
369
370/* PKCS#8 private key info structure */
371
372typedef struct pkcs8_priv_key_info_st
373 {
374 int broken; /* Flag for various broken formats */
375#define PKCS8_OK 0
376#define PKCS8_NO_OCTET 1
377 ASN1_INTEGER *version;
378 X509_ALGOR *pkeyalg;
379 ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */
380 STACK_OF(X509_ATTRIBUTE) *attributes;
381 } PKCS8_PRIV_KEY_INFO;
382
383#include <openssl/x509_vfy.h>
384#include <openssl/pkcs7.h>
334 385
335#ifdef SSLEAY_MACROS 386#ifdef SSLEAY_MACROS
336#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\ 387#define X509_verify(a,r) ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,\
@@ -355,6 +406,9 @@ typedef struct CBCParameter_st
355 406
356#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \ 407#define X509_dup(x509) (X509 *)ASN1_dup((int (*)())i2d_X509, \
357 (char *(*)())d2i_X509,(char *)x509) 408 (char *(*)())d2i_X509,(char *)x509)
409#define X509_ATTRIBUTE_dup(xa) (X509_ATTRIBUTE *)ASN1_dup(\
410 (int (*)())i2d_X509_ATTRIBUTE, \
411 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa)
358#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \ 412#define X509_EXTENSION_dup(ex) (X509_EXTENSION *)ASN1_dup( \
359 (int (*)())i2d_X509_EXTENSION, \ 413 (int (*)())i2d_X509_EXTENSION, \
360 (char *(*)())d2i_X509_EXTENSION,(char *)ex) 414 (char *(*)())d2i_X509_EXTENSION,(char *)ex)
@@ -442,6 +496,9 @@ typedef struct CBCParameter_st
442#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \ 496#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
443 (unsigned char *)dsa) 497 (unsigned char *)dsa)
444 498
499#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
500 (char *(*)())d2i_X509_ALGOR,(char *)xn)
501
445#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \ 502#define X509_NAME_dup(xn) (X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, \
446 (char *(*)())d2i_X509_NAME,(char *)xn) 503 (char *(*)())d2i_X509_NAME,(char *)xn)
447#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \ 504#define X509_NAME_ENTRY_dup(ne) (X509_NAME_ENTRY *)ASN1_dup( \
@@ -453,10 +510,12 @@ typedef struct CBCParameter_st
453 ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len) 510 ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)
454#define X509_NAME_digest(data,type,md,len) \ 511#define X509_NAME_digest(data,type,md,len) \
455 ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len) 512 ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)
513#ifndef PKCS7_ISSUER_AND_SERIAL_digest
456#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ 514#define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \
457 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ 515 ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\
458 (char *)data,md,len) 516 (char *)data,md,len)
459#endif 517#endif
518#endif
460 519
461#define X509_EXT_PACK_UNKNOWN 1 520#define X509_EXT_PACK_UNKNOWN 1
462#define X509_EXT_PACK_STRING 2 521#define X509_EXT_PACK_STRING 2
@@ -472,25 +531,31 @@ typedef struct CBCParameter_st
472#define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) 531#define X509_name_cmp(a,b) X509_NAME_cmp((a),(b))
473#define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm)) 532#define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm))
474 533
534#define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version)
535#define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate)
536#define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate)
537#define X509_CRL_get_issuer(x) ((x)->crl->issuer)
538#define X509_CRL_get_REVOKED(x) ((x)->crl->revoked)
539
475/* This one is only used so that a binary form can output, as in 540/* This one is only used so that a binary form can output, as in
476 * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */ 541 * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */
477#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key) 542#define X509_get_X509_PUBKEY(x) ((x)->cert_info->key)
478 543
479#ifndef NOPROTO 544
545const char *X509_verify_cert_error_string(long n);
480 546
481#ifndef SSLEAY_MACROS 547#ifndef SSLEAY_MACROS
482#ifdef HEADER_ENVELOPE_H 548#ifdef HEADER_ENVELOPE_H
483int X509_verify(X509 *a, EVP_PKEY *r); 549int X509_verify(X509 *a, EVP_PKEY *r);
484char *X509_verify_cert_error_string(long n);
485 550
486int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); 551int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r);
487int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); 552int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r);
488int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); 553int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r);
489 554
490int X509_sign(X509 *x, EVP_PKEY *pkey, EVP_MD *md); 555int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
491int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, EVP_MD *md); 556int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md);
492int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, EVP_MD *md); 557int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md);
493int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, EVP_MD *md); 558int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md);
494 559
495int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len); 560int X509_digest(X509 *data,EVP_MD *type,unsigned char *md,unsigned int *len);
496int X509_NAME_digest(X509_NAME *data,EVP_MD *type, 561int X509_NAME_digest(X509_NAME *data,EVP_MD *type,
@@ -498,55 +563,77 @@ int X509_NAME_digest(X509_NAME *data,EVP_MD *type,
498#endif 563#endif
499 564
500#ifndef NO_FP_API 565#ifndef NO_FP_API
501X509 *d2i_X509_fp(FILE *fp, X509 *x509); 566X509 *d2i_X509_fp(FILE *fp, X509 **x509);
502int i2d_X509_fp(FILE *fp,X509 *x509); 567int i2d_X509_fp(FILE *fp,X509 *x509);
503X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL *crl); 568X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl);
504int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl); 569int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl);
505X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ *req); 570X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req);
506int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req); 571int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req);
507RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA *rsa); 572#ifndef NO_RSA
573RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa);
508int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa); 574int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa);
509DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA *dsa); 575RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa);
510int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
511RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA *rsa);
512int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa); 576int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa);
513#endif 577#endif
578#ifndef NO_DSA
579DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
580int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
581X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
582int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
583PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
584 PKCS8_PRIV_KEY_INFO **p8inf);
585int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
586#endif
587#endif
514 588
515#ifdef HEADER_BIO_H 589#ifdef HEADER_BIO_H
516X509 *d2i_X509_bio(BIO *bp,X509 *x509); 590X509 *d2i_X509_bio(BIO *bp,X509 **x509);
517int i2d_X509_bio(BIO *bp,X509 *x509); 591int i2d_X509_bio(BIO *bp,X509 *x509);
518X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL *crl); 592X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl);
519int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl); 593int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl);
520X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ *req); 594X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req);
521int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req); 595int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req);
522RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA *rsa); 596#ifndef NO_RSA
597RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa);
523int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa); 598int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa);
524DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA *dsa); 599RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa);
525int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
526RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA *rsa);
527int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa); 600int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa);
528#endif 601#endif
602#ifndef NO_DSA
603DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
604int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
605#endif
606X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
607int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
608PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
609 PKCS8_PRIV_KEY_INFO **p8inf);
610int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
611#endif
529 612
530X509 *X509_dup(X509 *x509); 613X509 *X509_dup(X509 *x509);
614X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa);
531X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); 615X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
532X509_CRL *X509_CRL_dup(X509_CRL *crl); 616X509_CRL *X509_CRL_dup(X509_CRL *crl);
533X509_REQ *X509_REQ_dup(X509_REQ *req); 617X509_REQ *X509_REQ_dup(X509_REQ *req);
618X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
534X509_NAME *X509_NAME_dup(X509_NAME *xn); 619X509_NAME *X509_NAME_dup(X509_NAME *xn);
535X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); 620X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
621#ifndef NO_RSA
536RSA *RSAPublicKey_dup(RSA *rsa); 622RSA *RSAPublicKey_dup(RSA *rsa);
537RSA *RSAPrivateKey_dup(RSA *rsa); 623RSA *RSAPrivateKey_dup(RSA *rsa);
624#endif
538 625
539#endif /* !SSLEAY_MACROS */ 626#endif /* !SSLEAY_MACROS */
540 627
541int X509_cmp_current_time(ASN1_UTCTIME *s); 628int X509_cmp_current_time(ASN1_UTCTIME *s);
542ASN1_UTCTIME * X509_gmtime_adj(ASN1_UTCTIME *s, long adj); 629ASN1_UTCTIME * X509_gmtime_adj(ASN1_UTCTIME *s, long adj);
543 630
544char * X509_get_default_cert_area(void ); 631const char * X509_get_default_cert_area(void );
545char * X509_get_default_cert_dir(void ); 632const char * X509_get_default_cert_dir(void );
546char * X509_get_default_cert_file(void ); 633const char * X509_get_default_cert_file(void );
547char * X509_get_default_cert_dir_env(void ); 634const char * X509_get_default_cert_dir_env(void );
548char * X509_get_default_cert_file_env(void ); 635const char * X509_get_default_cert_file_env(void );
549char * X509_get_default_private_dir(void ); 636const char * X509_get_default_private_dir(void );
550 637
551X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md); 638X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md);
552X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey); 639X509 * 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,
571 long length); 658 long length);
572int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); 659int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey);
573EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); 660EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
574int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK *chain); 661int X509_get_pubkey_parameters(EVP_PKEY *pkey,
662 STACK_OF(X509) *chain);
575 663
576 664
577X509_SIG * X509_SIG_new(void ); 665X509_SIG * X509_SIG_new(void );
@@ -595,6 +683,8 @@ void X509_ATTRIBUTE_free(X509_ATTRIBUTE *a);
595int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp); 683int i2d_X509_ATTRIBUTE(X509_ATTRIBUTE *a,unsigned char **pp);
596X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp, 684X509_ATTRIBUTE *d2i_X509_ATTRIBUTE(X509_ATTRIBUTE **a,unsigned char **pp,
597 long length); 685 long length);
686X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
687
598 688
599X509_EXTENSION *X509_EXTENSION_new(void ); 689X509_EXTENSION *X509_EXTENSION_new(void );
600void X509_EXTENSION_free(X509_EXTENSION *a); 690void X509_EXTENSION_free(X509_EXTENSION *a);
@@ -658,6 +748,12 @@ int i2d_NETSCAPE_SPKAC(NETSCAPE_SPKAC *a,unsigned char **pp);
658NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp, 748NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC(NETSCAPE_SPKAC **a,unsigned char **pp,
659 long length); 749 long length);
660 750
751
752int i2d_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE *a, unsigned char **pp);
753NETSCAPE_CERT_SEQUENCE *NETSCAPE_CERT_SEQUENCE_new(void);
754NETSCAPE_CERT_SEQUENCE *d2i_NETSCAPE_CERT_SEQUENCE(NETSCAPE_CERT_SEQUENCE **a, unsigned char **pp, long length);
755void NETSCAPE_CERT_SEQUENCE_free(NETSCAPE_CERT_SEQUENCE *a);
756
661#ifdef HEADER_ENVELOPE_H 757#ifdef HEADER_ENVELOPE_H
662X509_INFO * X509_INFO_new(void); 758X509_INFO * X509_INFO_new(void);
663void X509_INFO_free(X509_INFO *a); 759void X509_INFO_free(X509_INFO *a);
@@ -671,7 +767,7 @@ int ASN1_digest(int (*i2d)(),EVP_MD *type,char *data,
671 767
672int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2, 768int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
673 ASN1_BIT_STRING *signature, 769 ASN1_BIT_STRING *signature,
674 char *data,EVP_PKEY *pkey, EVP_MD *type); 770 char *data,EVP_PKEY *pkey, const EVP_MD *type);
675#endif 771#endif
676 772
677int X509_set_version(X509 *x,long version); 773int X509_set_version(X509 *x,long version);
@@ -709,12 +805,14 @@ unsigned long X509_NAME_hash(X509_NAME *x);
709int X509_CRL_cmp(X509_CRL *a,X509_CRL *b); 805int X509_CRL_cmp(X509_CRL *a,X509_CRL *b);
710#ifndef NO_FP_API 806#ifndef NO_FP_API
711int X509_print_fp(FILE *bp,X509 *x); 807int X509_print_fp(FILE *bp,X509 *x);
808int X509_CRL_print_fp(FILE *bp,X509_CRL *x);
712int X509_REQ_print_fp(FILE *bp,X509_REQ *req); 809int X509_REQ_print_fp(FILE *bp,X509_REQ *req);
713#endif 810#endif
714 811
715#ifdef HEADER_BIO_H 812#ifdef HEADER_BIO_H
716int X509_NAME_print(BIO *bp, X509_NAME *name, int obase); 813int X509_NAME_print(BIO *bp, X509_NAME *name, int obase);
717int X509_print(BIO *bp,X509 *x); 814int X509_print(BIO *bp,X509 *x);
815int X509_CRL_print(BIO *bp,X509_CRL *x);
718int X509_REQ_print(BIO *bp,X509_REQ *req); 816int X509_REQ_print(BIO *bp,X509_REQ *req);
719#endif 817#endif
720 818
@@ -745,18 +843,17 @@ int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
745ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne); 843ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
746ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne); 844ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
747 845
748int X509v3_get_ext_count(STACK *x); 846int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x);
749int X509v3_get_ext_by_NID(STACK *x, int nid, int lastpos); 847int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x,
750int X509v3_get_ext_by_OBJ(STACK *x,ASN1_OBJECT *obj,int lastpos); 848 int nid, int lastpos);
751int X509v3_get_ext_by_critical(STACK *x, int crit, int lastpos); 849int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x,
752X509_EXTENSION *X509v3_get_ext(STACK *x, int loc); 850 ASN1_OBJECT *obj,int lastpos);
753X509_EXTENSION *X509v3_delete_ext(STACK *x, int loc); 851int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x,
754STACK * X509v3_add_ext(STACK **x, X509_EXTENSION *ex, int loc); 852 int crit, int lastpos);
755 853X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc);
756int X509v3_data_type_by_OBJ(ASN1_OBJECT *obj); 854X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc);
757int X509v3_data_type_by_NID(int nid); 855STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
758int X509v3_pack_type_by_OBJ(ASN1_OBJECT *obj); 856 X509_EXTENSION *ex, int loc);
759int X509v3_pack_type_by_NID(int nid);
760 857
761int X509_get_ext_count(X509 *x); 858int X509_get_ext_count(X509 *x);
762int X509_get_ext_by_NID(X509 *x, int nid, int lastpos); 859int X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
@@ -793,311 +890,49 @@ int X509_EXTENSION_set_data(X509_EXTENSION *ex,
793ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex); 890ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex);
794ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); 891ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne);
795int X509_EXTENSION_get_critical(X509_EXTENSION *ex); 892int X509_EXTENSION_get_critical(X509_EXTENSION *ex);
796ASN1_OCTET_STRING *X509v3_pack_string(ASN1_OCTET_STRING **ex,int type,
797 unsigned char *bytes, int len);
798ASN1_STRING * X509v3_unpack_string(ASN1_STRING **ex,int type,
799 ASN1_OCTET_STRING *os);
800 893
801int X509_verify_cert(X509_STORE_CTX *ctx); 894int X509_verify_cert(X509_STORE_CTX *ctx);
802 895
803/* lookup a cert from a X509 STACK */ 896/* lookup a cert from a X509 STACK */
804X509 *X509_find_by_issuer_and_serial(STACK *sk,X509_NAME *name, 897X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name,
805 ASN1_INTEGER *serial); 898 ASN1_INTEGER *serial);
806X509 *X509_find_by_subject(STACK *sk,X509_NAME *name); 899X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name);
807 900
808#else 901int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp);
809 902PBEPARAM *PBEPARAM_new(void);
810#ifndef SSLEAY_MACROS 903PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length);
811#ifdef HEADER_ENVELOPE_H 904void PBEPARAM_free(PBEPARAM *a);
812int X509_verify(); 905X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, int saltlen);
813int X509_REQ_verify(); 906X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
814int X509_CRL_verify(); 907 unsigned char *salt, int saltlen);
815int NETSCAPE_SPKI_verify(); 908
816 909int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp);
817int X509_sign(); 910PBKDF2PARAM *PBKDF2PARAM_new(void);
818int X509_REQ_sign(); 911PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, long length);
819int X509_CRL_sign(); 912void PBKDF2PARAM_free(PBKDF2PARAM *a);
820int NETSCAPE_SPKI_sign(); 913
821 914int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp);
822int X509_digest(); 915PBE2PARAM *PBE2PARAM_new(void);
823int X509_NAME_digest(); 916PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length);
824#endif 917void PBE2PARAM_free(PBE2PARAM *a);
825 918
826#ifndef NO_FP_API 919/* PKCS#8 utilities */
827X509 *d2i_X509_fp(); 920
828int i2d_X509_fp(); 921int i2d_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO *a, unsigned char **pp);
829X509_CRL *d2i_X509_CRL_fp(); 922PKCS8_PRIV_KEY_INFO *PKCS8_PRIV_KEY_INFO_new(void);
830int i2d_X509_CRL_fp(); 923PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,
831X509_REQ *d2i_X509_REQ_fp(); 924 unsigned char **pp, long length);
832int i2d_X509_REQ_fp(); 925void PKCS8_PRIV_KEY_INFO_free(PKCS8_PRIV_KEY_INFO *a);
833RSA *d2i_RSAPrivateKey_fp(); 926
834int i2d_RSAPrivateKey_fp(); 927EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8);
835DSA *d2i_DSAPrivateKey_fp(); 928PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey);
836int i2d_DSAPrivateKey_fp(); 929PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken);
837RSA *d2i_RSAPublicKey_fp();
838int i2d_RSAPublicKey_fp();
839#endif
840
841X509 *d2i_X509_bio();
842int i2d_X509_bio();
843X509_CRL *d2i_X509_CRL_bio();
844int i2d_X509_CRL_bio();
845X509_REQ *d2i_X509_REQ_bio();
846int i2d_X509_REQ_bio();
847RSA *d2i_RSAPrivateKey_bio();
848int i2d_RSAPrivateKey_bio();
849DSA *d2i_DSAPrivateKey_bio();
850int i2d_DSAPrivateKey_bio();
851RSA *d2i_RSAPublicKey_bio();
852int i2d_RSAPublicKey_bio();
853
854X509 *X509_dup();
855X509_EXTENSION *X509_EXTENSION_dup();
856X509_CRL *X509_CRL_dup();
857X509_REQ *X509_REQ_dup();
858X509_NAME *X509_NAME_dup();
859X509_NAME_ENTRY *X509_NAME_ENTRY_dup();
860RSA *RSAPublicKey_dup();
861RSA *RSAPrivateKey_dup();
862
863#endif /* !SSLEAY_MACROS */
864
865int X509_cmp_current_time();
866ASN1_UTCTIME * X509_gmtime_adj();
867
868char * X509_get_default_cert_area();
869char * X509_get_default_cert_dir();
870char * X509_get_default_cert_file();
871char * X509_get_default_cert_dir_env();
872char * X509_get_default_cert_file_env();
873char * X509_get_default_private_dir();
874
875X509_REQ * X509_to_X509_REQ();
876X509 * X509_REQ_to_X509();
877void ERR_load_X509_strings();
878
879X509_ALGOR * X509_ALGOR_new();
880void X509_ALGOR_free();
881int i2d_X509_ALGOR();
882X509_ALGOR * d2i_X509_ALGOR();
883
884X509_VAL * X509_VAL_new();
885void X509_VAL_free();
886int i2d_X509_VAL();
887X509_VAL * d2i_X509_VAL();
888
889X509_PUBKEY * X509_PUBKEY_new();
890void X509_PUBKEY_free();
891int i2d_X509_PUBKEY();
892X509_PUBKEY * d2i_X509_PUBKEY();
893int X509_PUBKEY_set();
894EVP_PKEY * X509_PUBKEY_get();
895int X509_get_pubkey_parameters();
896
897X509_SIG * X509_SIG_new();
898void X509_SIG_free();
899int i2d_X509_SIG();
900X509_SIG * d2i_X509_SIG();
901
902X509_REQ_INFO *X509_REQ_INFO_new();
903void X509_REQ_INFO_free();
904int i2d_X509_REQ_INFO();
905X509_REQ_INFO *d2i_X509_REQ_INFO();
906
907X509_REQ * X509_REQ_new();
908void X509_REQ_free();
909int i2d_X509_REQ();
910X509_REQ * d2i_X509_REQ();
911
912X509_ATTRIBUTE *X509_ATTRIBUTE_new();
913void X509_ATTRIBUTE_free();
914int i2d_X509_ATTRIBUTE();
915X509_ATTRIBUTE *d2i_X509_ATTRIBUTE();
916
917X509_EXTENSION *X509_EXTENSION_new();
918void X509_EXTENSION_free();
919int i2d_X509_EXTENSION();
920X509_EXTENSION *d2i_X509_EXTENSION();
921
922X509_NAME_ENTRY *X509_NAME_ENTRY_new();
923void X509_NAME_ENTRY_free();
924int i2d_X509_NAME_ENTRY();
925X509_NAME_ENTRY *d2i_X509_NAME_ENTRY();
926
927X509_NAME * X509_NAME_new();
928void X509_NAME_free();
929int i2d_X509_NAME();
930X509_NAME * d2i_X509_NAME();
931int X509_NAME_set();
932
933
934X509_CINF * X509_CINF_new();
935void X509_CINF_free();
936int i2d_X509_CINF();
937X509_CINF * d2i_X509_CINF();
938
939X509 * X509_new();
940void X509_free();
941int i2d_X509();
942X509 * d2i_X509();
943
944X509_REVOKED * X509_REVOKED_new();
945void X509_REVOKED_free();
946int i2d_X509_REVOKED();
947X509_REVOKED * d2i_X509_REVOKED();
948
949X509_CRL_INFO *X509_CRL_INFO_new();
950void X509_CRL_INFO_free();
951int i2d_X509_CRL_INFO();
952X509_CRL_INFO *d2i_X509_CRL_INFO();
953
954X509_CRL * X509_CRL_new();
955void X509_CRL_free();
956int i2d_X509_CRL();
957X509_CRL * d2i_X509_CRL();
958
959X509_PKEY * X509_PKEY_new();
960void X509_PKEY_free();
961int i2d_X509_PKEY();
962X509_PKEY * d2i_X509_PKEY();
963
964NETSCAPE_SPKI * NETSCAPE_SPKI_new();
965void NETSCAPE_SPKI_free();
966int i2d_NETSCAPE_SPKI();
967NETSCAPE_SPKI * d2i_NETSCAPE_SPKI();
968
969NETSCAPE_SPKAC *NETSCAPE_SPKAC_new();
970void NETSCAPE_SPKAC_free();
971int i2d_NETSCAPE_SPKAC();
972NETSCAPE_SPKAC *d2i_NETSCAPE_SPKAC();
973
974#ifdef HEADER_ENVELOPE_H
975X509_INFO * X509_INFO_new();
976void X509_INFO_free();
977#endif
978
979char * X509_NAME_oneline();
980
981int ASN1_verify();
982int ASN1_digest();
983int ASN1_sign();
984
985int X509_set_version();
986int X509_set_serialNumber();
987ASN1_INTEGER * X509_get_serialNumber();
988int X509_set_issuer_name();
989X509_NAME * X509_get_issuer_name();
990int X509_set_subject_name();
991X509_NAME * X509_get_subject_name();
992int X509_set_notBefore();
993int X509_set_notAfter();
994int X509_set_pubkey();
995EVP_PKEY * X509_get_pubkey();
996int X509_certificate_type();
997
998int X509_REQ_set_version();
999int X509_REQ_set_subject_name();
1000int X509_REQ_set_pubkey();
1001EVP_PKEY * X509_REQ_get_pubkey();
1002
1003int X509_check_private_key();
1004
1005int X509_issuer_and_serial_cmp();
1006unsigned long X509_issuer_and_serial_hash();
1007
1008int X509_issuer_name_cmp();
1009unsigned long X509_issuer_name_hash();
1010
1011int X509_subject_name_cmp();
1012unsigned long X509_subject_name_hash();
1013
1014int X509_NAME_cmp ();
1015unsigned long X509_NAME_hash();
1016
1017int X509_CRL_cmp();
1018#ifndef NO_FP_API
1019int X509_print_fp();
1020int X509_REQ_print_fp();
1021#endif
1022
1023int X509_NAME_print();
1024int X509_print();
1025int X509_REQ_print();
1026
1027int X509_NAME_entry_count();
1028int X509_NAME_get_text_by_NID();
1029int X509_NAME_get_text_by_OBJ();
1030
1031int X509_NAME_get_index_by_NID();
1032int X509_NAME_get_index_by_OBJ();
1033X509_NAME_ENTRY *X509_NAME_get_entry();
1034X509_NAME_ENTRY *X509_NAME_delete_entry();
1035int X509_NAME_add_entry();
1036X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID();
1037X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ();
1038int X509_NAME_ENTRY_set_object();
1039int X509_NAME_ENTRY_set_data();
1040ASN1_OBJECT * X509_NAME_ENTRY_get_object();
1041ASN1_STRING * X509_NAME_ENTRY_get_data();
1042
1043int X509v3_get_ext_count();
1044int X509v3_get_ext_by_NID();
1045int X509v3_get_ext_by_OBJ();
1046int X509v3_get_ext_by_critical();
1047X509_EXTENSION *X509v3_get_ext();
1048X509_EXTENSION *X509v3_delete_ext();
1049STACK * X509v3_add_ext();
1050
1051int X509v3_data_type_by_OBJ();
1052int X509v3_data_type_by_NID();
1053int X509v3_pack_type_by_OBJ();
1054int X509v3_pack_type_by_NID();
1055
1056int X509_get_ext_count();
1057int X509_get_ext_by_NID();
1058int X509_get_ext_by_OBJ();
1059int X509_get_ext_by_critical();
1060X509_EXTENSION *X509_get_ext();
1061X509_EXTENSION *X509_delete_ext();
1062int X509_add_ext();
1063
1064int X509_CRL_get_ext_count();
1065int X509_CRL_get_ext_by_NID();
1066int X509_CRL_get_ext_by_OBJ();
1067int X509_CRL_get_ext_by_critical();
1068X509_EXTENSION *X509_CRL_get_ext();
1069X509_EXTENSION *X509_CRL_delete_ext();
1070int X509_CRL_add_ext();
1071
1072int X509_REVOKED_get_ext_count();
1073int X509_REVOKED_get_ext_by_NID();
1074int X509_REVOKED_get_ext_by_OBJ();
1075int X509_REVOKED_get_ext_by_critical();
1076X509_EXTENSION *X509_REVOKED_get_ext();
1077X509_EXTENSION *X509_REVOKED_delete_ext();
1078int X509_REVOKED_add_ext();
1079
1080X509_EXTENSION *X509_EXTENSION_create_by_NID();
1081X509_EXTENSION *X509_EXTENSION_create_by_OBJ();
1082int X509_EXTENSION_set_object();
1083int X509_EXTENSION_set_critical();
1084int X509_EXTENSION_set_data();
1085ASN1_OBJECT * X509_EXTENSION_get_object();
1086ASN1_OCTET_STRING *X509_EXTENSION_get_data();
1087int X509_EXTENSION_get_critical();
1088ASN1_OCTET_STRING *X509v3_pack_string();
1089ASN1_STRING * X509v3_unpack_string();
1090
1091int X509_verify_cert();
1092char * X509_verify_cert_error_string();
1093
1094/* lookup a cert from a X509 STACK */
1095X509 *X509_find_by_issuer_and_serial();
1096X509 *X509_find_by_subject();
1097
1098#endif
1099 930
1100/* BEGIN ERROR CODES */ 931/* BEGIN ERROR CODES */
932/* The following lines are auto generated by the script mkerr.pl. Any changes
933 * made after this point may be overwritten when the script is next run.
934 */
935
1101/* Error codes for the X509 functions. */ 936/* Error codes for the X509 functions. */
1102 937
1103/* Function codes. */ 938/* Function codes. */
@@ -1106,9 +941,7 @@ X509 *X509_find_by_subject();
1106#define X509_F_DIR_CTRL 102 941#define X509_F_DIR_CTRL 102
1107#define X509_F_GET_CERT_BY_SUBJECT 103 942#define X509_F_GET_CERT_BY_SUBJECT 103
1108#define X509_F_X509V3_ADD_EXT 104 943#define X509_F_X509V3_ADD_EXT 104
1109#define X509_F_X509V3_ADD_EXTENSION 105 944#define X509_F_X509_CHECK_PRIVATE_KEY 128
1110#define X509_F_X509V3_PACK_STRING 106
1111#define X509_F_X509V3_UNPACK_STRING 107
1112#define X509_F_X509_EXTENSION_CREATE_BY_NID 108 945#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
1113#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 946#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
1114#define X509_F_X509_GET_PUBKEY_PARAMETERS 110 947#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
@@ -1132,19 +965,23 @@ X509 *X509_find_by_subject();
1132 965
1133/* Reason codes. */ 966/* Reason codes. */
1134#define X509_R_BAD_X509_FILETYPE 100 967#define X509_R_BAD_X509_FILETYPE 100
968#define X509_R_CANT_CHECK_DH_KEY 114
1135#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 969#define X509_R_CERT_ALREADY_IN_HASH_TABLE 101
1136#define X509_R_ERR_ASN1_LIB 102 970#define X509_R_ERR_ASN1_LIB 102
971#define X509_R_INVALID_DIRECTORY 113
972#define X509_R_KEY_TYPE_MISMATCH 115
973#define X509_R_KEY_VALUES_MISMATCH 116
1137#define X509_R_LOADING_CERT_DIR 103 974#define X509_R_LOADING_CERT_DIR 103
1138#define X509_R_LOADING_DEFAULTS 104 975#define X509_R_LOADING_DEFAULTS 104
1139#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 976#define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105
1140#define X509_R_SHOULD_RETRY 106 977#define X509_R_SHOULD_RETRY 106
1141#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 978#define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107
1142#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 979#define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108
980#define X509_R_UNKNOWN_KEY_TYPE 117
1143#define X509_R_UNKNOWN_NID 109 981#define X509_R_UNKNOWN_NID 109
1144#define X509_R_UNKNOWN_STRING_TYPE 110
1145#define X509_R_UNSUPPORTED_ALGORITHM 111 982#define X509_R_UNSUPPORTED_ALGORITHM 111
1146#define X509_R_WRONG_LOOKUP_TYPE 112 983#define X509_R_WRONG_LOOKUP_TYPE 112
1147 984
1148#ifdef __cplusplus 985#ifdef __cplusplus
1149} 986}
1150#endif 987#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 @@
60#include <sys/types.h> 60#include <sys/types.h>
61#include <sys/stat.h> 61#include <sys/stat.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "asn1.h" 63#include <openssl/asn1.h>
64#include "objects.h" 64#include <openssl/objects.h>
65#include "x509.h" 65#include <openssl/x509.h>
66 66
67int X509_issuer_and_serial_cmp(a,b) 67int X509_issuer_and_serial_cmp(X509 *a, X509 *b)
68X509 *a;
69X509 *b;
70 { 68 {
71 int i; 69 int i;
72 X509_CINF *ai,*bi; 70 X509_CINF *ai,*bi;
@@ -79,8 +77,7 @@ X509 *b;
79 } 77 }
80 78
81#ifndef NO_MD5 79#ifndef NO_MD5
82unsigned long X509_issuer_and_serial_hash(a) 80unsigned long X509_issuer_and_serial_hash(X509 *a)
83X509 *a;
84 { 81 {
85 unsigned long ret=0; 82 unsigned long ret=0;
86 MD5_CTX ctx; 83 MD5_CTX ctx;
@@ -101,70 +98,59 @@ X509 *a;
101 } 98 }
102#endif 99#endif
103 100
104int X509_issuer_name_cmp(a, b) 101int X509_issuer_name_cmp(X509 *a, X509 *b)
105X509 *a;
106X509 *b;
107 { 102 {
108 return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer)); 103 return(X509_NAME_cmp(a->cert_info->issuer,b->cert_info->issuer));
109 } 104 }
110 105
111int X509_subject_name_cmp(a, b) 106int X509_subject_name_cmp(X509 *a, X509 *b)
112X509 *a;
113X509 *b;
114 { 107 {
115 return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject)); 108 return(X509_NAME_cmp(a->cert_info->subject,b->cert_info->subject));
116 } 109 }
117 110
118int X509_CRL_cmp(a, b) 111int X509_CRL_cmp(X509_CRL *a, X509_CRL *b)
119X509_CRL *a;
120X509_CRL *b;
121 { 112 {
122 return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer)); 113 return(X509_NAME_cmp(a->crl->issuer,b->crl->issuer));
123 } 114 }
124 115
125X509_NAME *X509_get_issuer_name(a) 116X509_NAME *X509_get_issuer_name(X509 *a)
126X509 *a;
127 { 117 {
128 return(a->cert_info->issuer); 118 return(a->cert_info->issuer);
129 } 119 }
130 120
131unsigned long X509_issuer_name_hash(x) 121unsigned long X509_issuer_name_hash(X509 *x)
132X509 *x;
133 { 122 {
134 return(X509_NAME_hash(x->cert_info->issuer)); 123 return(X509_NAME_hash(x->cert_info->issuer));
135 } 124 }
136 125
137X509_NAME *X509_get_subject_name(a) 126X509_NAME *X509_get_subject_name(X509 *a)
138X509 *a;
139 { 127 {
140 return(a->cert_info->subject); 128 return(a->cert_info->subject);
141 } 129 }
142 130
143ASN1_INTEGER *X509_get_serialNumber(a) 131ASN1_INTEGER *X509_get_serialNumber(X509 *a)
144X509 *a;
145 { 132 {
146 return(a->cert_info->serialNumber); 133 return(a->cert_info->serialNumber);
147 } 134 }
148 135
149unsigned long X509_subject_name_hash(x) 136unsigned long X509_subject_name_hash(X509 *x)
150X509 *x;
151 { 137 {
152 return(X509_NAME_hash(x->cert_info->subject)); 138 return(X509_NAME_hash(x->cert_info->subject));
153 } 139 }
154 140
155int X509_NAME_cmp(a, b) 141int X509_NAME_cmp(X509_NAME *a, X509_NAME *b)
156X509_NAME *a;
157X509_NAME *b;
158 { 142 {
159 int i,j; 143 int i,j;
160 X509_NAME_ENTRY *na,*nb; 144 X509_NAME_ENTRY *na,*nb;
161 145
162 if (sk_num(a->entries) != sk_num(b->entries)) 146 if (sk_X509_NAME_ENTRY_num(a->entries)
163 return(sk_num(a->entries)-sk_num(b->entries)); 147 != sk_X509_NAME_ENTRY_num(b->entries))
164 for (i=sk_num(a->entries)-1; i>=0; i--) 148 return sk_X509_NAME_ENTRY_num(a->entries)
149 -sk_X509_NAME_ENTRY_num(b->entries);
150 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
165 { 151 {
166 na=(X509_NAME_ENTRY *)sk_value(a->entries,i); 152 na=sk_X509_NAME_ENTRY_value(a->entries,i);
167 nb=(X509_NAME_ENTRY *)sk_value(b->entries,i); 153 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
168 j=na->value->length-nb->value->length; 154 j=na->value->length-nb->value->length;
169 if (j) return(j); 155 if (j) return(j);
170 j=memcmp(na->value->data,nb->value->data, 156 j=memcmp(na->value->data,nb->value->data,
@@ -177,10 +163,10 @@ X509_NAME *b;
177 /* We will check the object types after checking the values 163 /* We will check the object types after checking the values
178 * since the values will more often be different than the object 164 * since the values will more often be different than the object
179 * types. */ 165 * types. */
180 for (i=sk_num(a->entries)-1; i>=0; i--) 166 for (i=sk_X509_NAME_ENTRY_num(a->entries)-1; i>=0; i--)
181 { 167 {
182 na=(X509_NAME_ENTRY *)sk_value(a->entries,i); 168 na=sk_X509_NAME_ENTRY_value(a->entries,i);
183 nb=(X509_NAME_ENTRY *)sk_value(b->entries,i); 169 nb=sk_X509_NAME_ENTRY_value(b->entries,i);
184 j=OBJ_cmp(na->object,nb->object); 170 j=OBJ_cmp(na->object,nb->object);
185 if (j) return(j); 171 if (j) return(j);
186 } 172 }
@@ -190,8 +176,7 @@ X509_NAME *b;
190#ifndef NO_MD5 176#ifndef NO_MD5
191/* I now DER encode the name and hash it. Since I cache the DER encoding, 177/* I now DER encode the name and hash it. Since I cache the DER encoding,
192 * this is reasonably effiecent. */ 178 * this is reasonably effiecent. */
193unsigned long X509_NAME_hash(x) 179unsigned long X509_NAME_hash(X509_NAME *x)
194X509_NAME *x;
195 { 180 {
196 unsigned long ret=0; 181 unsigned long ret=0;
197 unsigned char md[16]; 182 unsigned char md[16];
@@ -217,10 +202,8 @@ X509_NAME *x;
217#endif 202#endif
218 203
219/* Search a stack of X509 for a match */ 204/* Search a stack of X509 for a match */
220X509 *X509_find_by_issuer_and_serial(sk,name,serial) 205X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name,
221STACK *sk; 206 ASN1_INTEGER *serial)
222X509_NAME *name;
223ASN1_INTEGER *serial;
224 { 207 {
225 int i; 208 int i;
226 X509_CINF cinf; 209 X509_CINF cinf;
@@ -230,28 +213,81 @@ ASN1_INTEGER *serial;
230 cinf.serialNumber=serial; 213 cinf.serialNumber=serial;
231 cinf.issuer=name; 214 cinf.issuer=name;
232 215
233 for (i=0; i<sk_num(sk); i++) 216 for (i=0; i<sk_X509_num(sk); i++)
234 { 217 {
235 x509=(X509 *)sk_value(sk,i); 218 x509=sk_X509_value(sk,i);
236 if (X509_issuer_and_serial_cmp(x509,&x) == 0) 219 if (X509_issuer_and_serial_cmp(x509,&x) == 0)
237 return(x509); 220 return(x509);
238 } 221 }
239 return(NULL); 222 return(NULL);
240 } 223 }
241 224
242X509 *X509_find_by_subject(sk,name) 225X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name)
243STACK *sk;
244X509_NAME *name;
245 { 226 {
246 X509 *x509; 227 X509 *x509;
247 int i; 228 int i;
248 229
249 for (i=0; i<sk_num(sk); i++) 230 for (i=0; i<sk_X509_num(sk); i++)
250 { 231 {
251 x509=(X509 *)sk_value(sk,i); 232 x509=sk_X509_value(sk,i);
252 if (X509_NAME_cmp(X509_get_subject_name(x509),name) == 0) 233 if (X509_NAME_cmp(X509_get_subject_name(x509),name) == 0)
253 return(x509); 234 return(x509);
254 } 235 }
255 return(NULL); 236 return(NULL);
256 } 237 }
257 238
239EVP_PKEY *X509_get_pubkey(X509 *x)
240 {
241 if ((x == NULL) || (x->cert_info == NULL))
242 return(NULL);
243 return(X509_PUBKEY_get(x->cert_info->key));
244 }
245
246int X509_check_private_key(X509 *x, EVP_PKEY *k)
247 {
248 EVP_PKEY *xk=NULL;
249 int ok=0;
250
251 xk=X509_get_pubkey(x);
252 if (xk->type != k->type)
253 {
254 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);
255 goto err;
256 }
257 switch (k->type)
258 {
259#ifndef NO_RSA
260 case EVP_PKEY_RSA:
261 if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0
262 || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)
263 {
264 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
265 goto err;
266 }
267 break;
268#endif
269#ifndef NO_DSA
270 case EVP_PKEY_DSA:
271 if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)
272 {
273 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
274 goto err;
275 }
276 break;
277#endif
278#ifndef NO_DH
279 case EVP_PKEY_DH:
280 /* No idea */
281 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);
282 goto err;
283#endif
284 default:
285 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);
286 goto err;
287 }
288
289 ok=1;
290err:
291 EVP_PKEY_free(xk);
292 return(ok);
293 }
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c
index 01e22f4cb4..3e7ec5b432 100644
--- a/src/lib/libcrypto/x509/x509_d2.c
+++ b/src/lib/libcrypto/x509/x509_d2.c
@@ -60,12 +60,11 @@
60#include <sys/types.h> 60#include <sys/types.h>
61#include <sys/stat.h> 61#include <sys/stat.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "crypto.h" 63#include <openssl/crypto.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66#ifndef NO_STDIO 66#ifndef NO_STDIO
67int X509_STORE_set_default_paths(ctx) 67int X509_STORE_set_default_paths(X509_STORE *ctx)
68X509_STORE *ctx;
69 { 68 {
70 X509_LOOKUP *lookup; 69 X509_LOOKUP *lookup;
71 70
@@ -83,10 +82,8 @@ X509_STORE *ctx;
83 return(1); 82 return(1);
84 } 83 }
85 84
86int X509_STORE_load_locations(ctx,file,path) 85int X509_STORE_load_locations(X509_STORE *ctx, const char *file,
87X509_STORE *ctx; 86 const char *path)
88char *file;
89char *path;
90 { 87 {
91 X509_LOOKUP *lookup; 88 X509_LOOKUP *lookup;
92 89
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 @@
60#include <sys/types.h> 60#include <sys/types.h>
61#include <sys/stat.h> 61#include <sys/stat.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "crypto.h" 63#include <openssl/crypto.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66char *X509_get_default_private_dir() 66const char *X509_get_default_private_dir(void)
67 { return(X509_PRIVATE_DIR); } 67 { return(X509_PRIVATE_DIR); }
68 68
69char *X509_get_default_cert_area() 69const char *X509_get_default_cert_area(void)
70 { return(X509_CERT_AREA); } 70 { return(X509_CERT_AREA); }
71 71
72char *X509_get_default_cert_dir() 72const char *X509_get_default_cert_dir(void)
73 { return(X509_CERT_DIR); } 73 { return(X509_CERT_DIR); }
74 74
75char *X509_get_default_cert_file() 75const char *X509_get_default_cert_file(void)
76 { return(X509_CERT_FILE); } 76 { return(X509_CERT_FILE); }
77 77
78char *X509_get_default_cert_dir_env() 78const char *X509_get_default_cert_dir_env(void)
79 { return(X509_CERT_DIR_EVP); } 79 { return(X509_CERT_DIR_EVP); }
80 80
81char *X509_get_default_cert_file_env() 81const char *X509_get_default_cert_file_env(void)
82 { return(X509_CERT_FILE_EVP); } 82 { return(X509_CERT_FILE_EVP); }
83 83
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 @@
1/* lib/x509/x509_err.c */ 1/* crypto/x509/x509_err.c */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) 2/* ====================================================================
3 * All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
25 * are met: 7 * are met:
26 * 1. Redistributions of source code must retain the copyright 8 *
27 * notice, this list of conditions and the following disclaimer. 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
28 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 14 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 15 * distribution.
32 * must display the following acknowledgement: 16 *
33 * "This product includes cryptographic software written by 17 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 18 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 19 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 21 *
38 * the apps directory (application code) you must include an acknowledgement: 22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 23 * endorse or promote products derived from this software without
40 * 24 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 25 * openssl-core@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 35 *
52 * 36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
57 */ 54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
58#include <stdio.h> 60#include <stdio.h>
59#include "err.h" 61#include <openssl/err.h>
60#include "x509.h" 62#include <openssl/x509.h>
61 63
62/* BEGIN ERROR CODES */ 64/* BEGIN ERROR CODES */
63#ifndef NO_ERR 65#ifndef NO_ERR
@@ -68,14 +70,12 @@ static ERR_STRING_DATA X509_str_functs[]=
68{ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"}, 70{ERR_PACK(0,X509_F_DIR_CTRL,0), "DIR_CTRL"},
69{ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"}, 71{ERR_PACK(0,X509_F_GET_CERT_BY_SUBJECT,0), "GET_CERT_BY_SUBJECT"},
70{ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"}, 72{ERR_PACK(0,X509_F_X509V3_ADD_EXT,0), "X509v3_add_ext"},
71{ERR_PACK(0,X509_F_X509V3_ADD_EXTENSION,0), "X509V3_ADD_EXTENSION"}, 73{ERR_PACK(0,X509_F_X509_CHECK_PRIVATE_KEY,0), "X509_check_private_key"},
72{ERR_PACK(0,X509_F_X509V3_PACK_STRING,0), "X509v3_pack_string"},
73{ERR_PACK(0,X509_F_X509V3_UNPACK_STRING,0), "X509v3_unpack_string"},
74{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"}, 74{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_NID,0), "X509_EXTENSION_create_by_NID"},
75{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"}, 75{ERR_PACK(0,X509_F_X509_EXTENSION_CREATE_BY_OBJ,0), "X509_EXTENSION_create_by_OBJ"},
76{ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"}, 76{ERR_PACK(0,X509_F_X509_GET_PUBKEY_PARAMETERS,0), "X509_get_pubkey_parameters"},
77{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_LOAD_CERT_FILE"}, 77{ERR_PACK(0,X509_F_X509_LOAD_CERT_FILE,0), "X509_load_cert_file"},
78{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_LOAD_CRL_FILE"}, 78{ERR_PACK(0,X509_F_X509_LOAD_CRL_FILE,0), "X509_load_crl_file"},
79{ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"}, 79{ERR_PACK(0,X509_F_X509_NAME_ADD_ENTRY,0), "X509_NAME_add_entry"},
80{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"}, 80{ERR_PACK(0,X509_F_X509_NAME_ENTRY_CREATE_BY_NID,0), "X509_NAME_ENTRY_create_by_NID"},
81{ERR_PACK(0,X509_F_X509_NAME_ENTRY_SET_OBJECT,0), "X509_NAME_ENTRY_set_object"}, 81{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[]=
87{ERR_PACK(0,X509_F_X509_REQ_PRINT,0), "X509_REQ_print"}, 87{ERR_PACK(0,X509_F_X509_REQ_PRINT,0), "X509_REQ_print"},
88{ERR_PACK(0,X509_F_X509_REQ_PRINT_FP,0), "X509_REQ_print_fp"}, 88{ERR_PACK(0,X509_F_X509_REQ_PRINT_FP,0), "X509_REQ_print_fp"},
89{ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"}, 89{ERR_PACK(0,X509_F_X509_REQ_TO_X509,0), "X509_REQ_to_X509"},
90{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_ADD_CERT"}, 90{ERR_PACK(0,X509_F_X509_STORE_ADD_CERT,0), "X509_STORE_add_cert"},
91{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_ADD_CRL"}, 91{ERR_PACK(0,X509_F_X509_STORE_ADD_CRL,0), "X509_STORE_add_crl"},
92{ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"}, 92{ERR_PACK(0,X509_F_X509_TO_X509_REQ,0), "X509_to_X509_REQ"},
93{ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"}, 93{ERR_PACK(0,X509_F_X509_VERIFY_CERT,0), "X509_verify_cert"},
94{0,NULL}, 94{0,NULL}
95 }; 95 };
96 96
97static ERR_STRING_DATA X509_str_reasons[]= 97static ERR_STRING_DATA X509_str_reasons[]=
98 { 98 {
99{X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"}, 99{X509_R_BAD_X509_FILETYPE ,"bad x509 filetype"},
100{X509_R_CANT_CHECK_DH_KEY ,"cant check dh key"},
100{X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"}, 101{X509_R_CERT_ALREADY_IN_HASH_TABLE ,"cert already in hash table"},
101{X509_R_ERR_ASN1_LIB ,"err asn1 lib"}, 102{X509_R_ERR_ASN1_LIB ,"err asn1 lib"},
103{X509_R_INVALID_DIRECTORY ,"invalid directory"},
104{X509_R_KEY_TYPE_MISMATCH ,"key type mismatch"},
105{X509_R_KEY_VALUES_MISMATCH ,"key values mismatch"},
102{X509_R_LOADING_CERT_DIR ,"loading cert dir"}, 106{X509_R_LOADING_CERT_DIR ,"loading cert dir"},
103{X509_R_LOADING_DEFAULTS ,"loading defaults"}, 107{X509_R_LOADING_DEFAULTS ,"loading defaults"},
104{X509_R_NO_CERT_SET_FOR_US_TO_VERIFY ,"no cert set for us to verify"}, 108{X509_R_NO_CERT_SET_FOR_US_TO_VERIFY ,"no cert set for us to verify"},
105{X509_R_SHOULD_RETRY ,"should retry"}, 109{X509_R_SHOULD_RETRY ,"should retry"},
106{X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN,"unable to find parameters in chain"}, 110{X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN,"unable to find parameters in chain"},
107{X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"}, 111{X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY ,"unable to get certs public key"},
112{X509_R_UNKNOWN_KEY_TYPE ,"unknown key type"},
108{X509_R_UNKNOWN_NID ,"unknown nid"}, 113{X509_R_UNKNOWN_NID ,"unknown nid"},
109{X509_R_UNKNOWN_STRING_TYPE ,"unknown string type"},
110{X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"}, 114{X509_R_UNSUPPORTED_ALGORITHM ,"unsupported algorithm"},
111{X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"}, 115{X509_R_WRONG_LOOKUP_TYPE ,"wrong lookup type"},
112{0,NULL}, 116{0,NULL}
113 }; 117 };
114 118
115#endif 119#endif
116 120
117void ERR_load_X509_strings() 121void ERR_load_X509_strings(void)
118 { 122 {
119 static int init=1; 123 static int init=1;
120 124
121 if (init); 125 if (init)
122 {; 126 {
123 init=0; 127 init=0;
124#ifndef NO_ERR 128#ifndef NO_ERR
125 ERR_load_strings(ERR_LIB_X509,X509_str_functs); 129 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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "stack.h" 60#include <openssl/stack.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "asn1.h" 62#include <openssl/asn1.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "evp.h" 64#include <openssl/evp.h>
65#include "x509.h" 65#include <openssl/x509.h>
66 66
67int X509_CRL_get_ext_count(x) 67int X509_CRL_get_ext_count(X509_CRL *x)
68X509_CRL *x;
69 { 68 {
70 return(X509v3_get_ext_count(x->crl->extensions)); 69 return(X509v3_get_ext_count(x->crl->extensions));
71 } 70 }
72 71
73int X509_CRL_get_ext_by_NID(x,nid,lastpos) 72int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos)
74X509_CRL *x;
75int nid;
76int lastpos;
77 { 73 {
78 return(X509v3_get_ext_by_NID(x->crl->extensions,nid,lastpos)); 74 return(X509v3_get_ext_by_NID(x->crl->extensions,nid,lastpos));
79 } 75 }
80 76
81int X509_CRL_get_ext_by_OBJ(x,obj,lastpos) 77int X509_CRL_get_ext_by_OBJ(X509_CRL *x, ASN1_OBJECT *obj, int lastpos)
82X509_CRL *x;
83ASN1_OBJECT *obj;
84int lastpos;
85 { 78 {
86 return(X509v3_get_ext_by_OBJ(x->crl->extensions,obj,lastpos)); 79 return(X509v3_get_ext_by_OBJ(x->crl->extensions,obj,lastpos));
87 } 80 }
88 81
89int X509_CRL_get_ext_by_critical(x,crit,lastpos) 82int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos)
90X509_CRL *x;
91int crit;
92int lastpos;
93 { 83 {
94 return(X509v3_get_ext_by_critical(x->crl->extensions,crit,lastpos)); 84 return(X509v3_get_ext_by_critical(x->crl->extensions,crit,lastpos));
95 } 85 }
96 86
97X509_EXTENSION *X509_CRL_get_ext(x,loc) 87X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc)
98X509_CRL *x;
99int loc;
100 { 88 {
101 return(X509v3_get_ext(x->crl->extensions,loc)); 89 return(X509v3_get_ext(x->crl->extensions,loc));
102 } 90 }
103 91
104X509_EXTENSION *X509_CRL_delete_ext(x,loc) 92X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc)
105X509_CRL *x;
106int loc;
107 { 93 {
108 return(X509v3_delete_ext(x->crl->extensions,loc)); 94 return(X509v3_delete_ext(x->crl->extensions,loc));
109 } 95 }
110 96
111int X509_CRL_add_ext(x,ex,loc) 97int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc)
112X509_CRL *x;
113X509_EXTENSION *ex;
114int loc;
115 { 98 {
116 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL); 99 return(X509v3_add_ext(&(x->crl->extensions),ex,loc) != NULL);
117 } 100 }
118 101
119int X509_get_ext_count(x) 102int X509_get_ext_count(X509 *x)
120X509 *x;
121 { 103 {
122 return(X509v3_get_ext_count(x->cert_info->extensions)); 104 return(X509v3_get_ext_count(x->cert_info->extensions));
123 } 105 }
124 106
125int X509_get_ext_by_NID(x,nid,lastpos) 107int X509_get_ext_by_NID(X509 *x, int nid, int lastpos)
126X509 *x;
127int nid;
128int lastpos;
129 { 108 {
130 return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos)); 109 return(X509v3_get_ext_by_NID(x->cert_info->extensions,nid,lastpos));
131 } 110 }
132 111
133int X509_get_ext_by_OBJ(x,obj,lastpos) 112int X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos)
134X509 *x;
135ASN1_OBJECT *obj;
136int lastpos;
137 { 113 {
138 return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos)); 114 return(X509v3_get_ext_by_OBJ(x->cert_info->extensions,obj,lastpos));
139 } 115 }
140 116
141int X509_get_ext_by_critical(x,crit,lastpos) 117int X509_get_ext_by_critical(X509 *x, int crit, int lastpos)
142X509 *x;
143int crit;
144int lastpos;
145 { 118 {
146 return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos)); 119 return(X509v3_get_ext_by_critical(x->cert_info->extensions,crit,lastpos));
147 } 120 }
148 121
149X509_EXTENSION *X509_get_ext(x,loc) 122X509_EXTENSION *X509_get_ext(X509 *x, int loc)
150X509 *x;
151int loc;
152 { 123 {
153 return(X509v3_get_ext(x->cert_info->extensions,loc)); 124 return(X509v3_get_ext(x->cert_info->extensions,loc));
154 } 125 }
155 126
156X509_EXTENSION *X509_delete_ext(x,loc) 127X509_EXTENSION *X509_delete_ext(X509 *x, int loc)
157X509 *x;
158int loc;
159 { 128 {
160 return(X509v3_delete_ext(x->cert_info->extensions,loc)); 129 return(X509v3_delete_ext(x->cert_info->extensions,loc));
161 } 130 }
162 131
163int X509_add_ext(x,ex,loc) 132int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
164X509 *x;
165X509_EXTENSION *ex;
166int loc;
167 { 133 {
168 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL); 134 return(X509v3_add_ext(&(x->cert_info->extensions),ex,loc) != NULL);
169 } 135 }
170 136
171int X509_REVOKED_get_ext_count(x) 137int X509_REVOKED_get_ext_count(X509_REVOKED *x)
172X509_REVOKED *x;
173 { 138 {
174 return(X509v3_get_ext_count(x->extensions)); 139 return(X509v3_get_ext_count(x->extensions));
175 } 140 }
176 141
177int X509_REVOKED_get_ext_by_NID(x,nid,lastpos) 142int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos)
178X509_REVOKED *x;
179int nid;
180int lastpos;
181 { 143 {
182 return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos)); 144 return(X509v3_get_ext_by_NID(x->extensions,nid,lastpos));
183 } 145 }
184 146
185int X509_REVOKED_get_ext_by_OBJ(x,obj,lastpos) 147int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x, ASN1_OBJECT *obj,
186X509_REVOKED *x; 148 int lastpos)
187ASN1_OBJECT *obj;
188int lastpos;
189 { 149 {
190 return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos)); 150 return(X509v3_get_ext_by_OBJ(x->extensions,obj,lastpos));
191 } 151 }
192 152
193int X509_REVOKED_get_ext_by_critical(x,crit,lastpos) 153int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos)
194X509_REVOKED *x;
195int crit;
196int lastpos;
197 { 154 {
198 return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos)); 155 return(X509v3_get_ext_by_critical(x->extensions,crit,lastpos));
199 } 156 }
200 157
201X509_EXTENSION *X509_REVOKED_get_ext(x,loc) 158X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc)
202X509_REVOKED *x;
203int loc;
204 { 159 {
205 return(X509v3_get_ext(x->extensions,loc)); 160 return(X509v3_get_ext(x->extensions,loc));
206 } 161 }
207 162
208X509_EXTENSION *X509_REVOKED_delete_ext(x,loc) 163X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc)
209X509_REVOKED *x;
210int loc;
211 { 164 {
212 return(X509v3_delete_ext(x->extensions,loc)); 165 return(X509v3_delete_ext(x->extensions,loc));
213 } 166 }
214 167
215int X509_REVOKED_add_ext(x,ex,loc) 168int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc)
216X509_REVOKED *x;
217X509_EXTENSION *ex;
218int loc;
219 { 169 {
220 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL); 170 return(X509v3_add_ext(&(x->extensions),ex,loc) != NULL);
221 } 171 }
222 172
173IMPLEMENT_STACK_OF(X509_EXTENSION)
174IMPLEMENT_ASN1_SET_OF(X509_EXTENSION)
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c
index 2c7e10a46e..18bfecb11e 100644
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ b/src/lib/libcrypto/x509/x509_lu.c
@@ -58,14 +58,13 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "lhash.h" 61#include <openssl/lhash.h>
62#include "x509.h" 62#include <openssl/x509.h>
63 63
64static STACK *x509_store_meth=NULL; 64static STACK *x509_store_meth=NULL;
65static STACK *x509_store_ctx_meth=NULL; 65static STACK *x509_store_ctx_meth=NULL;
66 66
67X509_LOOKUP *X509_LOOKUP_new(method) 67X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method)
68X509_LOOKUP_METHOD *method;
69 { 68 {
70 X509_LOOKUP *ret; 69 X509_LOOKUP *ret;
71 70
@@ -85,8 +84,7 @@ X509_LOOKUP_METHOD *method;
85 return(ret); 84 return(ret);
86 } 85 }
87 86
88void X509_LOOKUP_free(ctx) 87void X509_LOOKUP_free(X509_LOOKUP *ctx)
89X509_LOOKUP *ctx;
90 { 88 {
91 if (ctx == NULL) return; 89 if (ctx == NULL) return;
92 if ( (ctx->method != NULL) && 90 if ( (ctx->method != NULL) &&
@@ -95,8 +93,7 @@ X509_LOOKUP *ctx;
95 Free(ctx); 93 Free(ctx);
96 } 94 }
97 95
98int X509_LOOKUP_init(ctx) 96int X509_LOOKUP_init(X509_LOOKUP *ctx)
99X509_LOOKUP *ctx;
100 { 97 {
101 if (ctx->method == NULL) return(0); 98 if (ctx->method == NULL) return(0);
102 if (ctx->method->init != NULL) 99 if (ctx->method->init != NULL)
@@ -105,22 +102,17 @@ X509_LOOKUP *ctx;
105 return(1); 102 return(1);
106 } 103 }
107 104
108int X509_LOOKUP_shutdown(ctx) 105int X509_LOOKUP_shutdown(X509_LOOKUP *ctx)
109X509_LOOKUP *ctx;
110 { 106 {
111 if (ctx->method == NULL) return(0); 107 if (ctx->method == NULL) return(0);
112 if (ctx->method->init != NULL) 108 if (ctx->method->shutdown != NULL)
113 return(ctx->method->shutdown(ctx)); 109 return(ctx->method->shutdown(ctx));
114 else 110 else
115 return(1); 111 return(1);
116 } 112 }
117 113
118int X509_LOOKUP_ctrl(ctx,cmd,argc,argl,ret) 114int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
119X509_LOOKUP *ctx; 115 char **ret)
120int cmd;
121char *argc;
122long argl;
123char **ret;
124 { 116 {
125 if (ctx->method == NULL) return(-1); 117 if (ctx->method == NULL) return(-1);
126 if (ctx->method->ctrl != NULL) 118 if (ctx->method->ctrl != NULL)
@@ -129,11 +121,8 @@ char **ret;
129 return(1); 121 return(1);
130 } 122 }
131 123
132int X509_LOOKUP_by_subject(ctx,type,name,ret) 124int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,
133X509_LOOKUP *ctx; 125 X509_OBJECT *ret)
134int type;
135X509_NAME *name;
136X509_OBJECT *ret;
137 { 126 {
138 if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL)) 127 if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL))
139 return(X509_LU_FAIL); 128 return(X509_LU_FAIL);
@@ -141,12 +130,8 @@ X509_OBJECT *ret;
141 return(ctx->method->get_by_subject(ctx,type,name,ret)); 130 return(ctx->method->get_by_subject(ctx,type,name,ret));
142 } 131 }
143 132
144int X509_LOOKUP_by_issuer_serial(ctx,type,name,serial,ret) 133int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name,
145X509_LOOKUP *ctx; 134 ASN1_INTEGER *serial, X509_OBJECT *ret)
146int type;
147X509_NAME *name;
148ASN1_INTEGER *serial;
149X509_OBJECT *ret;
150 { 135 {
151 if ((ctx->method == NULL) || 136 if ((ctx->method == NULL) ||
152 (ctx->method->get_by_issuer_serial == NULL)) 137 (ctx->method->get_by_issuer_serial == NULL))
@@ -154,32 +139,23 @@ X509_OBJECT *ret;
154 return(ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret)); 139 return(ctx->method->get_by_issuer_serial(ctx,type,name,serial,ret));
155 } 140 }
156 141
157int X509_LOOKUP_by_fingerprint(ctx,type,bytes,len,ret) 142int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type,
158X509_LOOKUP *ctx; 143 unsigned char *bytes, int len, X509_OBJECT *ret)
159int type;
160unsigned char *bytes;
161int len;
162X509_OBJECT *ret;
163 { 144 {
164 if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL)) 145 if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL))
165 return(X509_LU_FAIL); 146 return(X509_LU_FAIL);
166 return(ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret)); 147 return(ctx->method->get_by_fingerprint(ctx,type,bytes,len,ret));
167 } 148 }
168 149
169int X509_LOOKUP_by_alias(ctx,type,str,len,ret) 150int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len,
170X509_LOOKUP *ctx; 151 X509_OBJECT *ret)
171int type;
172char *str;
173int len;
174X509_OBJECT *ret;
175 { 152 {
176 if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL)) 153 if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL))
177 return(X509_LU_FAIL); 154 return(X509_LU_FAIL);
178 return(ctx->method->get_by_alias(ctx,str,len,ret)); 155 return(ctx->method->get_by_alias(ctx,type,str,len,ret));
179 } 156 }
180 157
181static unsigned long x509_object_hash(a) 158static unsigned long x509_object_hash(X509_OBJECT *a)
182X509_OBJECT *a;
183 { 159 {
184 unsigned long h; 160 unsigned long h;
185 161
@@ -197,8 +173,7 @@ X509_OBJECT *a;
197 return(h); 173 return(h);
198 } 174 }
199 175
200static int x509_object_cmp(a,b) 176static int x509_object_cmp(X509_OBJECT *a, X509_OBJECT *b)
201X509_OBJECT *a,*b;
202 { 177 {
203 int ret; 178 int ret;
204 179
@@ -218,7 +193,7 @@ X509_OBJECT *a,*b;
218 return(ret); 193 return(ret);
219 } 194 }
220 195
221X509_STORE *X509_STORE_new() 196X509_STORE *X509_STORE_new(void)
222 { 197 {
223 X509_STORE *ret; 198 X509_STORE *ret;
224 199
@@ -226,16 +201,16 @@ X509_STORE *X509_STORE_new()
226 return(NULL); 201 return(NULL);
227 ret->certs=lh_new(x509_object_hash,x509_object_cmp); 202 ret->certs=lh_new(x509_object_hash,x509_object_cmp);
228 ret->cache=1; 203 ret->cache=1;
229 ret->get_cert_methods=sk_new_null(); 204 ret->get_cert_methods=sk_X509_LOOKUP_new_null();
230 ret->verify=NULL; 205 ret->verify=NULL;
231 ret->verify_cb=NULL; 206 ret->verify_cb=NULL;
232 memset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA)); 207 memset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA));
233 ret->references=1; 208 ret->references=1;
209 ret->depth=0;
234 return(ret); 210 return(ret);
235 } 211 }
236 212
237static void cleanup(a) 213static void cleanup(X509_OBJECT *a)
238X509_OBJECT *a;
239 { 214 {
240 if (a->type == X509_LU_X509) 215 if (a->type == X509_LU_X509)
241 { 216 {
@@ -251,21 +226,23 @@ X509_OBJECT *a;
251 Free(a); 226 Free(a);
252 } 227 }
253 228
254void X509_STORE_free(vfy) 229void X509_STORE_free(X509_STORE *vfy)
255X509_STORE *vfy;
256 { 230 {
257 int i; 231 int i;
258 STACK *sk; 232 STACK_OF(X509_LOOKUP) *sk;
259 X509_LOOKUP *lu; 233 X509_LOOKUP *lu;
260 234
235 if(vfy == NULL)
236 return;
237
261 sk=vfy->get_cert_methods; 238 sk=vfy->get_cert_methods;
262 for (i=0; i<sk_num(sk); i++) 239 for (i=0; i<sk_X509_LOOKUP_num(sk); i++)
263 { 240 {
264 lu=(X509_LOOKUP *)sk_value(sk,i); 241 lu=sk_X509_LOOKUP_value(sk,i);
265 X509_LOOKUP_shutdown(lu); 242 X509_LOOKUP_shutdown(lu);
266 X509_LOOKUP_free(lu); 243 X509_LOOKUP_free(lu);
267 } 244 }
268 sk_free(sk); 245 sk_X509_LOOKUP_free(sk);
269 246
270 CRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data); 247 CRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data);
271 lh_doall(vfy->certs,cleanup); 248 lh_doall(vfy->certs,cleanup);
@@ -273,18 +250,16 @@ X509_STORE *vfy;
273 Free(vfy); 250 Free(vfy);
274 } 251 }
275 252
276X509_LOOKUP *X509_STORE_add_lookup(v,m) 253X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m)
277X509_STORE *v;
278X509_LOOKUP_METHOD *m;
279 { 254 {
280 int i; 255 int i;
281 STACK *sk; 256 STACK_OF(X509_LOOKUP) *sk;
282 X509_LOOKUP *lu; 257 X509_LOOKUP *lu;
283 258
284 sk=v->get_cert_methods; 259 sk=v->get_cert_methods;
285 for (i=0; i<sk_num(sk); i++) 260 for (i=0; i<sk_X509_LOOKUP_num(sk); i++)
286 { 261 {
287 lu=(X509_LOOKUP *)sk_value(sk,i); 262 lu=sk_X509_LOOKUP_value(sk,i);
288 if (m == lu->method) 263 if (m == lu->method)
289 { 264 {
290 return(lu); 265 return(lu);
@@ -297,7 +272,7 @@ X509_LOOKUP_METHOD *m;
297 else 272 else
298 { 273 {
299 lu->store_ctx=v; 274 lu->store_ctx=v;
300 if (sk_push(v->get_cert_methods,(char *)lu)) 275 if (sk_X509_LOOKUP_push(v->get_cert_methods,lu))
301 return(lu); 276 return(lu);
302 else 277 else
303 { 278 {
@@ -307,24 +282,21 @@ X509_LOOKUP_METHOD *m;
307 } 282 }
308 } 283 }
309 284
310int X509_STORE_get_by_subject(vs,type,name,ret) 285int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
311X509_STORE_CTX *vs; 286 X509_OBJECT *ret)
312int type;
313X509_NAME *name;
314X509_OBJECT *ret;
315 { 287 {
316 X509_STORE *ctx=vs->ctx; 288 X509_STORE *ctx=vs->ctx;
317 X509_LOOKUP *lu; 289 X509_LOOKUP *lu;
318 X509_OBJECT stmp,*tmp; 290 X509_OBJECT stmp,*tmp;
319 int i,j; 291 int i,j;
320 292
321 tmp=X509_OBJECT_retrive_by_subject(ctx->certs,type,name); 293 tmp=X509_OBJECT_retrieve_by_subject(ctx->certs,type,name);
322 294
323 if (tmp == NULL) 295 if (tmp == NULL)
324 { 296 {
325 for (i=vs->current_method; i<sk_num(ctx->get_cert_methods); i++) 297 for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++)
326 { 298 {
327 lu=(X509_LOOKUP *)sk_value(ctx->get_cert_methods,i); 299 lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i);
328 j=X509_LOOKUP_by_subject(lu,type,name,&stmp); 300 j=X509_LOOKUP_by_subject(lu,type,name,&stmp);
329 if (j < 0) 301 if (j < 0)
330 { 302 {
@@ -353,8 +325,7 @@ X509_OBJECT *ret;
353 return(1); 325 return(1);
354 } 326 }
355 327
356void X509_OBJECT_up_ref_count(a) 328void X509_OBJECT_up_ref_count(X509_OBJECT *a)
357X509_OBJECT *a;
358 { 329 {
359 switch (a->type) 330 switch (a->type)
360 { 331 {
@@ -367,8 +338,7 @@ X509_OBJECT *a;
367 } 338 }
368 } 339 }
369 340
370void X509_OBJECT_free_contents(a) 341void X509_OBJECT_free_contents(X509_OBJECT *a)
371X509_OBJECT *a;
372 { 342 {
373 switch (a->type) 343 switch (a->type)
374 { 344 {
@@ -381,10 +351,8 @@ X509_OBJECT *a;
381 } 351 }
382 } 352 }
383 353
384X509_OBJECT *X509_OBJECT_retrive_by_subject(h,type,name) 354X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h, int type,
385LHASH *h; 355 X509_NAME *name)
386int type;
387X509_NAME *name;
388 { 356 {
389 X509_OBJECT stmp,*tmp; 357 X509_OBJECT stmp,*tmp;
390 X509 x509_s; 358 X509 x509_s;
@@ -413,11 +381,8 @@ X509_NAME *name;
413 return(tmp); 381 return(tmp);
414 } 382 }
415 383
416void X509_STORE_CTX_init(ctx,store,x509,chain) 384void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
417X509_STORE_CTX *ctx; 385 STACK_OF(X509) *chain)
418X509_STORE *store;
419X509 *x509;
420STACK *chain;
421 { 386 {
422 ctx->ctx=store; 387 ctx->ctx=store;
423 ctx->current_method=0; 388 ctx->current_method=0;
@@ -426,21 +391,21 @@ STACK *chain;
426 ctx->last_untrusted=0; 391 ctx->last_untrusted=0;
427 ctx->valid=0; 392 ctx->valid=0;
428 ctx->chain=NULL; 393 ctx->chain=NULL;
429 ctx->depth=10; 394 ctx->depth=9;
430 ctx->error=0; 395 ctx->error=0;
431 ctx->current_cert=NULL; 396 ctx->current_cert=NULL;
432 memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA)); 397 memset(&(ctx->ex_data),0,sizeof(CRYPTO_EX_DATA));
433 } 398 }
434 399
435void X509_STORE_CTX_cleanup(ctx) 400void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
436X509_STORE_CTX *ctx;
437 { 401 {
438 if (ctx->chain != NULL) 402 if (ctx->chain != NULL)
439 { 403 {
440 sk_pop_free(ctx->chain,X509_free); 404 sk_X509_pop_free(ctx->chain,X509_free);
441 ctx->chain=NULL; 405 ctx->chain=NULL;
442 } 406 }
443 CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data)); 407 CRYPTO_free_ex_data(x509_store_ctx_meth,(char *)ctx,&(ctx->ex_data));
444 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA)); 408 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA));
445 } 409 }
446 410
411IMPLEMENT_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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "lhash.h" 61#include <openssl/lhash.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/x509.h>
64#include "buffer.h" 64#include <openssl/buffer.h>
65 65
66char *X509_NAME_oneline(a,buf,len) 66char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
67X509_NAME *a;
68char *buf;
69int len;
70 { 67 {
71 X509_NAME_ENTRY *ne; 68 X509_NAME_ENTRY *ne;
72 unsigned int i; 69int i;
73 int n,lold,l,l1,l2,num,j,type; 70 int n,lold,l,l1,l2,num,j,type;
74 char *s,*p; 71 const char *s;
72 char *p;
75 unsigned char *q; 73 unsigned char *q;
76 BUF_MEM *b=NULL; 74 BUF_MEM *b=NULL;
77 static char hex[17]="0123456789ABCDEF"; 75 static char hex[17]="0123456789ABCDEF";
78 int gs_doit[4]; 76 int gs_doit[4];
79 char tmp_buf[80]; 77 char tmp_buf[80];
78#ifdef CHARSET_EBCDIC
79 char ebcdic_buf[1024];
80#endif
80 81
81 if (a == NULL) return("NO X509_NAME");
82 if (buf == NULL) 82 if (buf == NULL)
83 { 83 {
84 if ((b=BUF_MEM_new()) == NULL) goto err; 84 if ((b=BUF_MEM_new()) == NULL) goto err;
@@ -86,12 +86,22 @@ int len;
86 b->data[0]='\0'; 86 b->data[0]='\0';
87 len=200; 87 len=200;
88 } 88 }
89 if (a == NULL)
90 {
91 if(b)
92 {
93 buf=b->data;
94 Free(b);
95 }
96 strncpy(buf,"NO X509_NAME",len);
97 return buf;
98 }
89 99
90 len--; /* space for '\0' */ 100 len--; /* space for '\0' */
91 l=0; 101 l=0;
92 for (i=0; (int)i<sk_num(a->entries); i++) 102 for (i=0; i<sk_X509_NAME_ENTRY_num(a->entries); i++)
93 { 103 {
94 ne=(X509_NAME_ENTRY *)sk_value(a->entries,i); 104 ne=sk_X509_NAME_ENTRY_value(a->entries,i);
95 n=OBJ_obj2nid(ne->object); 105 n=OBJ_obj2nid(ne->object);
96 if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL)) 106 if ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL))
97 { 107 {
@@ -103,6 +113,19 @@ int len;
103 type=ne->value->type; 113 type=ne->value->type;
104 num=ne->value->length; 114 num=ne->value->length;
105 q=ne->value->data; 115 q=ne->value->data;
116#ifdef CHARSET_EBCDIC
117 if (type == V_ASN1_GENERALSTRING ||
118 type == V_ASN1_VISIBLESTRING ||
119 type == V_ASN1_PRINTABLESTRING ||
120 type == V_ASN1_TELETEXSTRING ||
121 type == V_ASN1_VISIBLESTRING ||
122 type == V_ASN1_IA5STRING) {
123 ascii2ebcdic(ebcdic_buf, q,
124 (num > sizeof ebcdic_buf)
125 ? sizeof ebcdic_buf : num);
126 q=ebcdic_buf;
127 }
128#endif
106 129
107 if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0)) 130 if ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0))
108 { 131 {
@@ -125,7 +148,12 @@ int len;
125 { 148 {
126 if (!gs_doit[j&3]) continue; 149 if (!gs_doit[j&3]) continue;
127 l2++; 150 l2++;
151#ifndef CHARSET_EBCDIC
128 if ((q[j] < ' ') || (q[j] > '~')) l2+=3; 152 if ((q[j] < ' ') || (q[j] > '~')) l2+=3;
153#else
154 if ((os_toascii[q[j]] < os_toascii[' ']) ||
155 (os_toascii[q[j]] > os_toascii['~'])) l2+=3;
156#endif
129 } 157 }
130 158
131 lold=l; 159 lold=l;
@@ -145,11 +173,14 @@ int len;
145 memcpy(p,s,(unsigned int)l1); p+=l1; 173 memcpy(p,s,(unsigned int)l1); p+=l1;
146 *(p++)='='; 174 *(p++)='=';
147 175
176#ifndef CHARSET_EBCDIC /* q was assigned above already. */
148 q=ne->value->data; 177 q=ne->value->data;
178#endif
149 179
150 for (j=0; j<num; j++) 180 for (j=0; j<num; j++)
151 { 181 {
152 if (!gs_doit[j&3]) continue; 182 if (!gs_doit[j&3]) continue;
183#ifndef CHARSET_EBCDIC
153 n=q[j]; 184 n=q[j];
154 if ((n < ' ') || (n > '~')) 185 if ((n < ' ') || (n > '~'))
155 { 186 {
@@ -160,13 +191,26 @@ int len;
160 } 191 }
161 else 192 else
162 *(p++)=n; 193 *(p++)=n;
194#else
195 n=os_toascii[q[j]];
196 if ((n < os_toascii[' ']) ||
197 (n > os_toascii['~']))
198 {
199 *(p++)='\\';
200 *(p++)='x';
201 *(p++)=hex[(n>>4)&0x0f];
202 *(p++)=hex[n&0x0f];
203 }
204 else
205 *(p++)=q[j];
206#endif
163 } 207 }
164 *p='\0'; 208 *p='\0';
165 } 209 }
166 if (b != NULL) 210 if (b != NULL)
167 { 211 {
168 p=b->data; 212 p=b->data;
169 Free((char *)b); 213 Free(b);
170 } 214 }
171 else 215 else
172 p=buf; 216 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "asn1.h" 63#include <openssl/asn1.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "objects.h" 65#include <openssl/objects.h>
66#include "buffer.h" 66#include <openssl/buffer.h>
67#include "pem.h"
68 67
69X509 *X509_REQ_to_X509(r,days,pkey) 68X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
70X509_REQ *r;
71int days;
72EVP_PKEY *pkey;
73 { 69 {
74 X509 *ret=NULL; 70 X509 *ret=NULL;
75 int er=1;
76 X509_REQ_INFO *ri=NULL;
77 X509_CINF *xi=NULL; 71 X509_CINF *xi=NULL;
78 X509_NAME *xn; 72 X509_NAME *xn;
79 73
@@ -84,13 +78,9 @@ EVP_PKEY *pkey;
84 } 78 }
85 79
86 /* duplicate the request */ 80 /* duplicate the request */
87 ri=(X509_REQ_INFO *)ASN1_dup(i2d_X509_REQ_INFO,
88 (char *(*)())d2i_X509_REQ_INFO,(char *)r->req_info);
89 if (ri == NULL) goto err;
90
91 xi=ret->cert_info; 81 xi=ret->cert_info;
92 82
93 if (sk_num(ri->attributes) != 0) 83 if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0)
94 { 84 {
95 if ((xi->version=ASN1_INTEGER_new()) == NULL) goto err; 85 if ((xi->version=ASN1_INTEGER_new()) == NULL) goto err;
96 if (!ASN1_INTEGER_set(xi->version,2)) goto err; 86 if (!ASN1_INTEGER_set(xi->version,2)) goto err;
@@ -109,13 +99,11 @@ EVP_PKEY *pkey;
109 99
110 if (!X509_sign(ret,pkey,EVP_md5())) 100 if (!X509_sign(ret,pkey,EVP_md5()))
111 goto err; 101 goto err;
112 er=0; 102 if (0)
113err:
114 if (er)
115 { 103 {
104err:
116 X509_free(ret); 105 X509_free(ret);
117 X509_REQ_INFO_free(ri); 106 ret=NULL;
118 return(NULL);
119 } 107 }
120 return(ret); 108 return(ret);
121 } 109 }
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "bn.h" 61#include <openssl/bn.h>
62#include "evp.h" 62#include <openssl/evp.h>
63#include "asn1.h" 63#include <openssl/asn1.h>
64#include "x509.h" 64#include <openssl/x509.h>
65#include "objects.h" 65#include <openssl/objects.h>
66#include "buffer.h" 66#include <openssl/buffer.h>
67#include "pem.h" 67#include <openssl/pem.h>
68 68
69X509_REQ *X509_to_X509_REQ(x,pkey,md) 69X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, EVP_MD *md)
70X509 *x;
71EVP_PKEY *pkey;
72EVP_MD *md;
73 { 70 {
74 X509_REQ *ret; 71 X509_REQ *ret;
75 X509_REQ_INFO *ri; 72 X509_REQ_INFO *ri;
76 int i; 73 int i;
74 EVP_PKEY *pktmp;
77 75
78 ret=X509_REQ_new(); 76 ret=X509_REQ_new();
79 if (ret == NULL) 77 if (ret == NULL)
@@ -92,7 +90,9 @@ EVP_MD *md;
92 if (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x))) 90 if (!X509_REQ_set_subject_name(ret,X509_get_subject_name(x)))
93 goto err; 91 goto err;
94 92
95 i=X509_REQ_set_pubkey(ret,X509_get_pubkey(x)); 93 pktmp = X509_get_pubkey(x);
94 i=X509_REQ_set_pubkey(ret,pktmp);
95 EVP_PKEY_free(pktmp);
96 if (!i) goto err; 96 if (!i) goto err;
97 97
98 if (pkey != NULL) 98 if (pkey != NULL)
@@ -106,8 +106,7 @@ err:
106 return(NULL); 106 return(NULL);
107 } 107 }
108 108
109EVP_PKEY *X509_REQ_get_pubkey(req) 109EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)
110X509_REQ *req;
111 { 110 {
112 if ((req == NULL) || (req->req_info == NULL)) 111 if ((req == NULL) || (req->req_info == NULL))
113 return(NULL); 112 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66int X509_set_version(x,version) 66int X509_set_version(X509 *x, long version)
67X509 *x;
68long version;
69 { 67 {
70 if (x == NULL) return(0); 68 if (x == NULL) return(0);
71 if (x->cert_info->version == NULL) 69 if (x->cert_info->version == NULL)
@@ -76,9 +74,7 @@ long version;
76 return(ASN1_INTEGER_set(x->cert_info->version,version)); 74 return(ASN1_INTEGER_set(x->cert_info->version,version));
77 } 75 }
78 76
79int X509_set_serialNumber(x,serial) 77int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial)
80X509 *x;
81ASN1_INTEGER *serial;
82 { 78 {
83 ASN1_INTEGER *in; 79 ASN1_INTEGER *in;
84 80
@@ -96,25 +92,19 @@ ASN1_INTEGER *serial;
96 return(in != NULL); 92 return(in != NULL);
97 } 93 }
98 94
99int X509_set_issuer_name(x,name) 95int X509_set_issuer_name(X509 *x, X509_NAME *name)
100X509 *x;
101X509_NAME *name;
102 { 96 {
103 if ((x == NULL) || (x->cert_info == NULL)) return(0); 97 if ((x == NULL) || (x->cert_info == NULL)) return(0);
104 return(X509_NAME_set(&x->cert_info->issuer,name)); 98 return(X509_NAME_set(&x->cert_info->issuer,name));
105 } 99 }
106 100
107int X509_set_subject_name(x,name) 101int X509_set_subject_name(X509 *x, X509_NAME *name)
108X509 *x;
109X509_NAME *name;
110 { 102 {
111 if ((x == NULL) || (x->cert_info == NULL)) return(0); 103 if ((x == NULL) || (x->cert_info == NULL)) return(0);
112 return(X509_NAME_set(&x->cert_info->subject,name)); 104 return(X509_NAME_set(&x->cert_info->subject,name));
113 } 105 }
114 106
115int X509_set_notBefore(x,tm) 107int X509_set_notBefore(X509 *x, ASN1_UTCTIME *tm)
116X509 *x;
117ASN1_UTCTIME *tm;
118 { 108 {
119 ASN1_UTCTIME *in; 109 ASN1_UTCTIME *in;
120 110
@@ -132,9 +122,7 @@ ASN1_UTCTIME *tm;
132 return(in != NULL); 122 return(in != NULL);
133 } 123 }
134 124
135int X509_set_notAfter(x,tm) 125int X509_set_notAfter(X509 *x, ASN1_UTCTIME *tm)
136X509 *x;
137ASN1_UTCTIME *tm;
138 { 126 {
139 ASN1_UTCTIME *in; 127 ASN1_UTCTIME *in;
140 128
@@ -152,9 +140,7 @@ ASN1_UTCTIME *tm;
152 return(in != NULL); 140 return(in != NULL);
153 } 141 }
154 142
155int X509_set_pubkey(x,pkey) 143int X509_set_pubkey(X509 *x, EVP_PKEY *pkey)
156X509 *x;
157EVP_PKEY *pkey;
158 { 144 {
159 if ((x == NULL) || (x->cert_info == NULL)) return(0); 145 if ((x == NULL) || (x->cert_info == NULL)) return(0);
160 return(X509_PUBKEY_set(&(x->cert_info->key),pkey)); 146 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 @@
62#include <sys/types.h> 62#include <sys/types.h>
63 63
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "lhash.h" 65#include <openssl/lhash.h>
66#include "buffer.h" 66#include <openssl/buffer.h>
67#include "evp.h" 67#include <openssl/evp.h>
68#include "asn1.h" 68#include <openssl/asn1.h>
69#include "x509.h" 69#include <openssl/x509.h>
70#include "objects.h" 70#include <openssl/objects.h>
71#include "pem.h"
72 71
73char *X509_verify_cert_error_string(n) 72const char *X509_verify_cert_error_string(long n)
74long n;
75 { 73 {
76 static char buf[100]; 74 static char buf[100];
77 75
@@ -121,6 +119,8 @@ long n;
121 return("unable to verify the first certificate"); 119 return("unable to verify the first certificate");
122 case X509_V_ERR_CERT_CHAIN_TOO_LONG: 120 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
123 return("certificate chain too long"); 121 return("certificate chain too long");
122 case X509_V_ERR_CERT_REVOKED:
123 return("certificate revoked");
124 case X509_V_ERR_APPLICATION_VERIFICATION: 124 case X509_V_ERR_APPLICATION_VERIFICATION:
125 return("application verification failure"); 125 return("application verification failure");
126 default: 126 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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "stack.h" 60#include <openssl/stack.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "asn1.h" 62#include <openssl/asn1.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "evp.h" 64#include <openssl/evp.h>
65#include "x509.h" 65#include <openssl/x509.h>
66 66
67#ifndef NOPROTO 67int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x)
68static X509_EXTENSION_METHOD *find_by_nid(int nid);
69static int xem_cmp(X509_EXTENSION_METHOD **a, X509_EXTENSION_METHOD **b);
70#else
71static X509_EXTENSION_METHOD *find_by_nid();
72static int xem_cmp();
73#endif
74
75static STACK *extensions=NULL;
76
77int X509v3_get_ext_count(x)
78STACK *x;
79 { 68 {
80 if (x == NULL) return(0); 69 if (x == NULL) return(0);
81 return(sk_num(x)); 70 return(sk_X509_EXTENSION_num(x));
82 } 71 }
83 72
84int X509v3_get_ext_by_NID(x,nid,lastpos) 73int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid,
85STACK *x; 74 int lastpos)
86int nid;
87int lastpos;
88 { 75 {
89 ASN1_OBJECT *obj; 76 ASN1_OBJECT *obj;
90 77
@@ -93,10 +80,8 @@ int lastpos;
93 return(X509v3_get_ext_by_OBJ(x,obj,lastpos)); 80 return(X509v3_get_ext_by_OBJ(x,obj,lastpos));
94 } 81 }
95 82
96int X509v3_get_ext_by_OBJ(sk,obj,lastpos) 83int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj,
97STACK *sk; 84 int lastpos)
98ASN1_OBJECT *obj;
99int lastpos;
100 { 85 {
101 int n; 86 int n;
102 X509_EXTENSION *ex; 87 X509_EXTENSION *ex;
@@ -105,20 +90,18 @@ int lastpos;
105 lastpos++; 90 lastpos++;
106 if (lastpos < 0) 91 if (lastpos < 0)
107 lastpos=0; 92 lastpos=0;
108 n=sk_num(sk); 93 n=sk_X509_EXTENSION_num(sk);
109 for ( ; lastpos < n; lastpos++) 94 for ( ; lastpos < n; lastpos++)
110 { 95 {
111 ex=(X509_EXTENSION *)sk_value(sk,lastpos); 96 ex=sk_X509_EXTENSION_value(sk,lastpos);
112 if (OBJ_cmp(ex->object,obj) == 0) 97 if (OBJ_cmp(ex->object,obj) == 0)
113 return(lastpos); 98 return(lastpos);
114 } 99 }
115 return(-1); 100 return(-1);
116 } 101 }
117 102
118int X509v3_get_ext_by_critical(sk,crit,lastpos) 103int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit,
119STACK *sk; 104 int lastpos)
120int crit;
121int lastpos;
122 { 105 {
123 int n; 106 int n;
124 X509_EXTENSION *ex; 107 X509_EXTENSION *ex;
@@ -127,10 +110,10 @@ int lastpos;
127 lastpos++; 110 lastpos++;
128 if (lastpos < 0) 111 if (lastpos < 0)
129 lastpos=0; 112 lastpos=0;
130 n=sk_num(sk); 113 n=sk_X509_EXTENSION_num(sk);
131 for ( ; lastpos < n; lastpos++) 114 for ( ; lastpos < n; lastpos++)
132 { 115 {
133 ex=(X509_EXTENSION *)sk_value(sk,lastpos); 116 ex=sk_X509_EXTENSION_value(sk,lastpos);
134 if ( (ex->critical && crit) || 117 if ( (ex->critical && crit) ||
135 (!ex->critical && !crit)) 118 (!ex->critical && !crit))
136 return(lastpos); 119 return(lastpos);
@@ -138,52 +121,46 @@ int lastpos;
138 return(-1); 121 return(-1);
139 } 122 }
140 123
141X509_EXTENSION *X509v3_get_ext(x,loc) 124X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc)
142STACK *x;
143int loc;
144 { 125 {
145 if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0)) 126 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
146 return(NULL); 127 return NULL;
147 else 128 else
148 return((X509_EXTENSION *)sk_value(x,loc)); 129 return sk_X509_EXTENSION_value(x,loc);
149 } 130 }
150 131
151X509_EXTENSION *X509v3_delete_ext(x,loc) 132X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc)
152STACK *x;
153int loc;
154 { 133 {
155 X509_EXTENSION *ret; 134 X509_EXTENSION *ret;
156 135
157 if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0)) 136 if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0)
158 return(NULL); 137 return(NULL);
159 ret=(X509_EXTENSION *)sk_delete(x,loc); 138 ret=sk_X509_EXTENSION_delete(x,loc);
160 return(ret); 139 return(ret);
161 } 140 }
162 141
163STACK *X509v3_add_ext(x,ex,loc) 142STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
164STACK **x; 143 X509_EXTENSION *ex, int loc)
165X509_EXTENSION *ex;
166int loc;
167 { 144 {
168 X509_EXTENSION *new_ex=NULL; 145 X509_EXTENSION *new_ex=NULL;
169 int n; 146 int n;
170 STACK *sk=NULL; 147 STACK_OF(X509_EXTENSION) *sk=NULL;
171 148
172 if ((x != NULL) && (*x == NULL)) 149 if ((x != NULL) && (*x == NULL))
173 { 150 {
174 if ((sk=sk_new_null()) == NULL) 151 if ((sk=sk_X509_EXTENSION_new_null()) == NULL)
175 goto err; 152 goto err;
176 } 153 }
177 else 154 else
178 sk= *x; 155 sk= *x;
179 156
180 n=sk_num(sk); 157 n=sk_X509_EXTENSION_num(sk);
181 if (loc > n) loc=n; 158 if (loc > n) loc=n;
182 else if (loc < 0) loc=n; 159 else if (loc < 0) loc=n;
183 160
184 if ((new_ex=X509_EXTENSION_dup(ex)) == NULL) 161 if ((new_ex=X509_EXTENSION_dup(ex)) == NULL)
185 goto err2; 162 goto err2;
186 if (!sk_insert(sk,(char *)new_ex,loc)) 163 if (!sk_X509_EXTENSION_insert(sk,new_ex,loc))
187 goto err; 164 goto err;
188 if ((x != NULL) && (*x == NULL)) 165 if ((x != NULL) && (*x == NULL))
189 *x=sk; 166 *x=sk;
@@ -192,15 +169,12 @@ err:
192 X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE); 169 X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE);
193err2: 170err2:
194 if (new_ex != NULL) X509_EXTENSION_free(new_ex); 171 if (new_ex != NULL) X509_EXTENSION_free(new_ex);
195 if (sk != NULL) sk_free(sk); 172 if (sk != NULL) sk_X509_EXTENSION_free(sk);
196 return(NULL); 173 return(NULL);
197 } 174 }
198 175
199X509_EXTENSION *X509_EXTENSION_create_by_NID(ex,nid,crit,data) 176X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,
200X509_EXTENSION **ex; 177 int crit, ASN1_OCTET_STRING *data)
201int nid;
202int crit;
203ASN1_OCTET_STRING *data;
204 { 178 {
205 ASN1_OBJECT *obj; 179 ASN1_OBJECT *obj;
206 X509_EXTENSION *ret; 180 X509_EXTENSION *ret;
@@ -216,11 +190,8 @@ ASN1_OCTET_STRING *data;
216 return(ret); 190 return(ret);
217 } 191 }
218 192
219X509_EXTENSION *X509_EXTENSION_create_by_OBJ(ex,obj,crit,data) 193X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex,
220X509_EXTENSION **ex; 194 ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data)
221ASN1_OBJECT *obj;
222int crit;
223ASN1_OCTET_STRING *data;
224 { 195 {
225 X509_EXTENSION *ret; 196 X509_EXTENSION *ret;
226 197
@@ -250,9 +221,7 @@ err:
250 return(NULL); 221 return(NULL);
251 } 222 }
252 223
253int X509_EXTENSION_set_object(ex,obj) 224int X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj)
254X509_EXTENSION *ex;
255ASN1_OBJECT *obj;
256 { 225 {
257 if ((ex == NULL) || (obj == NULL)) 226 if ((ex == NULL) || (obj == NULL))
258 return(0); 227 return(0);
@@ -261,18 +230,14 @@ ASN1_OBJECT *obj;
261 return(1); 230 return(1);
262 } 231 }
263 232
264int X509_EXTENSION_set_critical(ex,crit) 233int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit)
265X509_EXTENSION *ex;
266int crit;
267 { 234 {
268 if (ex == NULL) return(0); 235 if (ex == NULL) return(0);
269 ex->critical=(crit)?0xFF:0; 236 ex->critical=(crit)?0xFF:0;
270 return(1); 237 return(1);
271 } 238 }
272 239
273int X509_EXTENSION_set_data(ex,data) 240int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data)
274X509_EXTENSION *ex;
275ASN1_OCTET_STRING *data;
276 { 241 {
277 int i; 242 int i;
278 243
@@ -282,128 +247,20 @@ ASN1_OCTET_STRING *data;
282 return(1); 247 return(1);
283 } 248 }
284 249
285ASN1_OBJECT *X509_EXTENSION_get_object(ex) 250ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex)
286X509_EXTENSION *ex;
287 { 251 {
288 if (ex == NULL) return(NULL); 252 if (ex == NULL) return(NULL);
289 return(ex->object); 253 return(ex->object);
290 } 254 }
291 255
292ASN1_OCTET_STRING *X509_EXTENSION_get_data(ex) 256ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex)
293X509_EXTENSION *ex;
294 { 257 {
295 if (ex == NULL) return(NULL); 258 if (ex == NULL) return(NULL);
296 return(ex->value); 259 return(ex->value);
297 } 260 }
298 261
299int X509_EXTENSION_get_critical(ex) 262int X509_EXTENSION_get_critical(X509_EXTENSION *ex)
300X509_EXTENSION *ex;
301 { 263 {
302 if (ex == NULL) return(0); 264 if (ex == NULL) return(0);
303 return(ex->critical); 265 return(ex->critical);
304 } 266 }
305
306int X509v3_data_type_by_OBJ(obj)
307ASN1_OBJECT *obj;
308 {
309 int nid;
310
311 nid=OBJ_obj2nid(obj);
312 if (nid == V_ASN1_UNDEF) return(V_ASN1_UNDEF);
313 return(X509v3_data_type_by_NID(nid));
314 }
315
316int X509v3_data_type_by_NID(nid)
317int nid;
318 {
319 X509_EXTENSION_METHOD *x;
320
321 x=find_by_nid(nid);
322 if (x == NULL)
323 return(V_ASN1_UNDEF);
324 else
325 return(x->data_type);
326 }
327
328int X509v3_pack_type_by_OBJ(obj)
329ASN1_OBJECT *obj;
330 {
331 int nid;
332
333 nid=OBJ_obj2nid(obj);
334 if (nid == NID_undef) return(X509_EXT_PACK_UNKNOWN);
335 return(X509v3_pack_type_by_NID(nid));
336 }
337
338int X509v3_pack_type_by_NID(nid)
339int nid;
340 {
341 X509_EXTENSION_METHOD *x;
342
343 x=find_by_nid(nid);
344 if (x == NULL)
345 return(X509_EXT_PACK_UNKNOWN);
346 else
347 return(x->pack_type);
348 }
349
350static X509_EXTENSION_METHOD *find_by_nid(nid)
351int nid;
352 {
353 X509_EXTENSION_METHOD x;
354 int i;
355
356 x.nid=nid;
357 if (extensions == NULL) return(NULL);
358 i=sk_find(extensions,(char *)&x);
359 if (i < 0)
360 return(NULL);
361 else
362 return((X509_EXTENSION_METHOD *)sk_value(extensions,i));
363 }
364
365static int xem_cmp(a,b)
366X509_EXTENSION_METHOD **a,**b;
367 {
368 return((*a)->nid-(*b)->nid);
369 }
370
371void X509v3_cleanup_extensions()
372 {
373 int i;
374
375 if (extensions != NULL)
376 {
377 for (i=0; i<sk_num(extensions); i++)
378 Free(sk_value(extensions,i));
379 sk_free(extensions);
380 extensions=NULL;
381 }
382 }
383
384int X509v3_add_extension(x)
385X509_EXTENSION_METHOD *x;
386 {
387 X509_EXTENSION_METHOD *newx;
388
389 if (extensions == NULL)
390 {
391 extensions=sk_new(xem_cmp);
392 if (extensions == NULL) goto err;
393 }
394 newx=(X509_EXTENSION_METHOD *)Malloc(sizeof(X509_EXTENSION_METHOD));
395 if (newx == NULL) goto err;
396 newx->nid=x->nid;
397 newx->data_type=x->data_type;
398 newx->pack_type=x->pack_type;
399 if (!sk_push(extensions,(char *)newx))
400 {
401 Free(newx);
402 goto err;
403 }
404 return(1);
405err:
406 X509err(X509_F_X509V3_ADD_EXTENSION,ERR_R_MALLOC_FAILURE);
407 return(0);
408 }
409
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 @@
62#include <sys/types.h> 62#include <sys/types.h>
63#include <sys/stat.h> 63#include <sys/stat.h>
64 64
65#include "crypto.h" 65#include <openssl/crypto.h>
66#include "cryptlib.h" 66#include "cryptlib.h"
67#include "lhash.h" 67#include <openssl/lhash.h>
68#include "buffer.h" 68#include <openssl/buffer.h>
69#include "evp.h" 69#include <openssl/evp.h>
70#include "asn1.h" 70#include <openssl/asn1.h>
71#include "x509.h" 71#include <openssl/x509.h>
72#include "objects.h" 72#include <openssl/objects.h>
73#include "pem.h" 73
74
75#ifndef NOPROTO
76static int null_callback(int ok,X509_STORE_CTX *e); 74static int null_callback(int ok,X509_STORE_CTX *e);
77static int internal_verify(X509_STORE_CTX *ctx); 75static int internal_verify(X509_STORE_CTX *ctx);
78#else 76const char *X509_version="X.509" OPENSSL_VERSION_PTEXT;
79static int null_callback();
80static int internal_verify();
81#endif
82 77
83char *X509_version="X509 part of SSLeay 0.9.0b 29-Jun-1998";
84static STACK *x509_store_ctx_method=NULL; 78static STACK *x509_store_ctx_method=NULL;
85static int x509_store_ctx_num=0; 79static int x509_store_ctx_num=0;
86#if 0 80#if 0
@@ -88,23 +82,19 @@ static int x509_store_num=1;
88static STACK *x509_store_method=NULL; 82static STACK *x509_store_method=NULL;
89#endif 83#endif
90 84
91static int null_callback(ok,e) 85static int null_callback(int ok, X509_STORE_CTX *e)
92int ok;
93X509_STORE_CTX *e;
94 { 86 {
95 return(ok); 87 return(ok);
96 } 88 }
97 89
98#if 0 90#if 0
99static int x509_subject_cmp(a,b) 91static int x509_subject_cmp(X509 **a, X509 **b)
100X509 **a,**b;
101 { 92 {
102 return(X509_subject_name_cmp(*a,*b)); 93 return(X509_subject_name_cmp(*a,*b));
103 } 94 }
104#endif 95#endif
105 96
106int X509_verify_cert(ctx) 97int X509_verify_cert(X509_STORE_CTX *ctx)
107X509_STORE_CTX *ctx;
108 { 98 {
109 X509 *x,*xtmp,*chain_ss=NULL; 99 X509 *x,*xtmp,*chain_ss=NULL;
110 X509_NAME *xn; 100 X509_NAME *xn;
@@ -112,7 +102,7 @@ X509_STORE_CTX *ctx;
112 int depth,i,ok=0; 102 int depth,i,ok=0;
113 int num; 103 int num;
114 int (*cb)(); 104 int (*cb)();
115 STACK *sktmp=NULL; 105 STACK_OF(X509) *sktmp=NULL;
116 106
117 if (ctx->cert == NULL) 107 if (ctx->cert == NULL)
118 { 108 {
@@ -127,8 +117,8 @@ X509_STORE_CTX *ctx;
127 * present and that the first entry is in place */ 117 * present and that the first entry is in place */
128 if (ctx->chain == NULL) 118 if (ctx->chain == NULL)
129 { 119 {
130 if ( ((ctx->chain=sk_new_null()) == NULL) || 120 if ( ((ctx->chain=sk_X509_new_null()) == NULL) ||
131 (!sk_push(ctx->chain,(char *)ctx->cert))) 121 (!sk_X509_push(ctx->chain,ctx->cert)))
132 { 122 {
133 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); 123 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
134 goto end; 124 goto end;
@@ -138,21 +128,26 @@ X509_STORE_CTX *ctx;
138 } 128 }
139 129
140 /* We use a temporary so we can chop and hack at it */ 130 /* We use a temporary so we can chop and hack at it */
141 if ((ctx->untrusted != NULL) && (sktmp=sk_dup(ctx->untrusted)) == NULL) 131 if (ctx->untrusted != NULL
132 && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
142 { 133 {
143 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); 134 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
144 goto end; 135 goto end;
145 } 136 }
146 137
147 num=sk_num(ctx->chain); 138 num=sk_X509_num(ctx->chain);
148 x=(X509 *)sk_value(ctx->chain,num-1); 139 x=sk_X509_value(ctx->chain,num-1);
149 depth=ctx->depth; 140 depth=ctx->depth;
150 141
151 142
152 for (;;) 143 for (;;)
153 { 144 {
154 /* If we have enough, we break */ 145 /* If we have enough, we break */
155 if (depth <= num) break; 146 if (depth < num) break; /* FIXME: If this happens, we should take
147 * note of it and, if appropriate, use the
148 * X509_V_ERR_CERT_CHAIN_TOO_LONG error
149 * code later.
150 */
156 151
157 /* If we are self signed, we break */ 152 /* If we are self signed, we break */
158 xn=X509_get_issuer_name(x); 153 xn=X509_get_issuer_name(x);
@@ -165,13 +160,13 @@ X509_STORE_CTX *ctx;
165 xtmp=X509_find_by_subject(sktmp,xn); 160 xtmp=X509_find_by_subject(sktmp,xn);
166 if (xtmp != NULL) 161 if (xtmp != NULL)
167 { 162 {
168 if (!sk_push(ctx->chain,(char *)xtmp)) 163 if (!sk_X509_push(ctx->chain,xtmp))
169 { 164 {
170 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); 165 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
171 goto end; 166 goto end;
172 } 167 }
173 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509); 168 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
174 sk_delete_ptr(sktmp,(char *)xtmp); 169 sk_X509_delete_ptr(sktmp,xtmp);
175 ctx->last_untrusted++; 170 ctx->last_untrusted++;
176 x=xtmp; 171 x=xtmp;
177 num++; 172 num++;
@@ -187,13 +182,13 @@ X509_STORE_CTX *ctx;
187 * certificates. We now need to add at least one trusted one, 182 * certificates. We now need to add at least one trusted one,
188 * if possible, otherwise we complain. */ 183 * if possible, otherwise we complain. */
189 184
190 i=sk_num(ctx->chain); 185 i=sk_X509_num(ctx->chain);
191 x=(X509 *)sk_value(ctx->chain,i-1); 186 x=sk_X509_value(ctx->chain,i-1);
192 if (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x)) 187 if (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x))
193 == 0) 188 == 0)
194 { 189 {
195 /* we have a self signed certificate */ 190 /* we have a self signed certificate */
196 if (sk_num(ctx->chain) == 1) 191 if (sk_X509_num(ctx->chain) == 1)
197 { 192 {
198 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT; 193 ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
199 ctx->current_cert=x; 194 ctx->current_cert=x;
@@ -204,10 +199,10 @@ X509_STORE_CTX *ctx;
204 else 199 else
205 { 200 {
206 /* worry more about this one elsewhere */ 201 /* worry more about this one elsewhere */
207 chain_ss=(X509 *)sk_pop(ctx->chain); 202 chain_ss=sk_X509_pop(ctx->chain);
208 ctx->last_untrusted--; 203 ctx->last_untrusted--;
209 num--; 204 num--;
210 x=(X509 *)sk_value(ctx->chain,num-1); 205 x=sk_X509_value(ctx->chain,num-1);
211 } 206 }
212 } 207 }
213 208
@@ -215,7 +210,7 @@ X509_STORE_CTX *ctx;
215 for (;;) 210 for (;;)
216 { 211 {
217 /* If we have enough, we break */ 212 /* If we have enough, we break */
218 if (depth <= num) break; 213 if (depth < num) break;
219 214
220 /* If we are self signed, we break */ 215 /* If we are self signed, we break */
221 xn=X509_get_issuer_name(x); 216 xn=X509_get_issuer_name(x);
@@ -240,7 +235,7 @@ X509_STORE_CTX *ctx;
240 break; 235 break;
241 } 236 }
242 x=obj.data.x509; 237 x=obj.data.x509;
243 if (!sk_push(ctx->chain,(char *)obj.data.x509)) 238 if (!sk_X509_push(ctx->chain,obj.data.x509))
244 { 239 {
245 X509_OBJECT_free_contents(&obj); 240 X509_OBJECT_free_contents(&obj);
246 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE); 241 X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
@@ -264,7 +259,7 @@ X509_STORE_CTX *ctx;
264 else 259 else
265 { 260 {
266 261
267 sk_push(ctx->chain,(char *)chain_ss); 262 sk_X509_push(ctx->chain,chain_ss);
268 num++; 263 num++;
269 ctx->last_untrusted=num; 264 ctx->last_untrusted=num;
270 ctx->current_cert=chain_ss; 265 ctx->current_cert=chain_ss;
@@ -285,14 +280,17 @@ X509_STORE_CTX *ctx;
285 ok=ctx->ctx->verify(ctx); 280 ok=ctx->ctx->verify(ctx);
286 else 281 else
287 ok=internal_verify(ctx); 282 ok=internal_verify(ctx);
283 if (0)
284 {
288end: 285end:
289 if (sktmp != NULL) sk_free(sktmp); 286 X509_get_pubkey_parameters(NULL,ctx->chain);
287 }
288 if (sktmp != NULL) sk_X509_free(sktmp);
290 if (chain_ss != NULL) X509_free(chain_ss); 289 if (chain_ss != NULL) X509_free(chain_ss);
291 return(ok); 290 return(ok);
292 } 291 }
293 292
294static int internal_verify(ctx) 293static int internal_verify(X509_STORE_CTX *ctx)
295X509_STORE_CTX *ctx;
296 { 294 {
297 int i,ok=0,n; 295 int i,ok=0,n;
298 X509 *xs,*xi; 296 X509 *xs,*xi;
@@ -302,10 +300,10 @@ X509_STORE_CTX *ctx;
302 cb=ctx->ctx->verify_cb; 300 cb=ctx->ctx->verify_cb;
303 if (cb == NULL) cb=null_callback; 301 if (cb == NULL) cb=null_callback;
304 302
305 n=sk_num(ctx->chain); 303 n=sk_X509_num(ctx->chain);
306 ctx->error_depth=n-1; 304 ctx->error_depth=n-1;
307 n--; 305 n--;
308 xi=(X509 *)sk_value(ctx->chain,n); 306 xi=sk_X509_value(ctx->chain,n);
309 if (X509_NAME_cmp(X509_get_subject_name(xi), 307 if (X509_NAME_cmp(X509_get_subject_name(xi),
310 X509_get_issuer_name(xi)) == 0) 308 X509_get_issuer_name(xi)) == 0)
311 xs=xi; 309 xs=xi;
@@ -322,7 +320,7 @@ X509_STORE_CTX *ctx;
322 { 320 {
323 n--; 321 n--;
324 ctx->error_depth=n; 322 ctx->error_depth=n;
325 xs=(X509 *)sk_value(ctx->chain,n); 323 xs=sk_X509_value(ctx->chain,n);
326 } 324 }
327 } 325 }
328 326
@@ -341,11 +339,13 @@ X509_STORE_CTX *ctx;
341 } 339 }
342 if (X509_verify(xs,pkey) <= 0) 340 if (X509_verify(xs,pkey) <= 0)
343 { 341 {
342 EVP_PKEY_free(pkey);
344 ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE; 343 ctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;
345 ctx->current_cert=xs; 344 ctx->current_cert=xs;
346 ok=(*cb)(0,ctx); 345 ok=(*cb)(0,ctx);
347 if (!ok) goto end; 346 if (!ok) goto end;
348 } 347 }
348 EVP_PKEY_free(pkey);
349 pkey=NULL; 349 pkey=NULL;
350 350
351 i=X509_cmp_current_time(X509_get_notBefore(xs)); 351 i=X509_cmp_current_time(X509_get_notBefore(xs));
@@ -394,7 +394,7 @@ X509_STORE_CTX *ctx;
394 if (n >= 0) 394 if (n >= 0)
395 { 395 {
396 xi=xs; 396 xi=xs;
397 xs=(X509 *)sk_value(ctx->chain,n); 397 xs=sk_X509_value(ctx->chain,n);
398 } 398 }
399 } 399 }
400 ok=1; 400 ok=1;
@@ -402,8 +402,7 @@ end:
402 return(ok); 402 return(ok);
403 } 403 }
404 404
405int X509_cmp_current_time(ctm) 405int X509_cmp_current_time(ASN1_UTCTIME *ctm)
406ASN1_UTCTIME *ctm;
407 { 406 {
408 char *str; 407 char *str;
409 ASN1_UTCTIME atm; 408 ASN1_UTCTIME atm;
@@ -434,7 +433,7 @@ ASN1_UTCTIME *ctm;
434 offset=((str[1]-'0')*10+(str[2]-'0'))*60; 433 offset=((str[1]-'0')*10+(str[2]-'0'))*60;
435 offset+=(str[3]-'0')*10+(str[4]-'0'); 434 offset+=(str[3]-'0')*10+(str[4]-'0');
436 if (*str == '-') 435 if (*str == '-')
437 offset=-offset; 436 offset= -offset;
438 } 437 }
439 atm.type=V_ASN1_UTCTIME; 438 atm.type=V_ASN1_UTCTIME;
440 atm.length=sizeof(buff2); 439 atm.length=sizeof(buff2);
@@ -443,9 +442,9 @@ ASN1_UTCTIME *ctm;
443 X509_gmtime_adj(&atm,-offset); 442 X509_gmtime_adj(&atm,-offset);
444 443
445 i=(buff1[0]-'0')*10+(buff1[1]-'0'); 444 i=(buff1[0]-'0')*10+(buff1[1]-'0');
446 if (i < 70) i+=100; 445 if (i < 50) i+=100; /* cf. RFC 2459 */
447 j=(buff2[0]-'0')*10+(buff2[1]-'0'); 446 j=(buff2[0]-'0')*10+(buff2[1]-'0');
448 if (j < 70) j+=100; 447 if (j < 50) j+=100;
449 448
450 if (i < j) return (-1); 449 if (i < j) return (-1);
451 if (i > j) return (1); 450 if (i > j) return (1);
@@ -456,9 +455,7 @@ ASN1_UTCTIME *ctm;
456 return(i); 455 return(i);
457 } 456 }
458 457
459ASN1_UTCTIME *X509_gmtime_adj(s, adj) 458ASN1_UTCTIME *X509_gmtime_adj(ASN1_UTCTIME *s, long adj)
460ASN1_UTCTIME *s;
461long adj;
462 { 459 {
463 time_t t; 460 time_t t;
464 461
@@ -467,18 +464,16 @@ long adj;
467 return(ASN1_UTCTIME_set(s,t)); 464 return(ASN1_UTCTIME_set(s,t));
468 } 465 }
469 466
470int X509_get_pubkey_parameters(pkey,chain) 467int X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain)
471EVP_PKEY *pkey;
472STACK *chain;
473 { 468 {
474 EVP_PKEY *ktmp=NULL,*ktmp2; 469 EVP_PKEY *ktmp=NULL,*ktmp2;
475 int i,j; 470 int i,j;
476 471
477 if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return(1); 472 if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) return(1);
478 473
479 for (i=0; i<sk_num(chain); i++) 474 for (i=0; i<sk_X509_num(chain); i++)
480 { 475 {
481 ktmp=X509_get_pubkey((X509 *)sk_value(chain,i)); 476 ktmp=X509_get_pubkey(sk_X509_value(chain,i));
482 if (ktmp == NULL) 477 if (ktmp == NULL)
483 { 478 {
484 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY); 479 X509err(X509_F_X509_GET_PUBKEY_PARAMETERS,X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY);
@@ -488,6 +483,7 @@ STACK *chain;
488 break; 483 break;
489 else 484 else
490 { 485 {
486 EVP_PKEY_free(ktmp);
491 ktmp=NULL; 487 ktmp=NULL;
492 } 488 }
493 } 489 }
@@ -500,63 +496,17 @@ STACK *chain;
500 /* first, populate the other certs */ 496 /* first, populate the other certs */
501 for (j=i-1; j >= 0; j--) 497 for (j=i-1; j >= 0; j--)
502 { 498 {
503 ktmp2=X509_get_pubkey((X509 *)sk_value(chain,j)); 499 ktmp2=X509_get_pubkey(sk_X509_value(chain,j));
504 EVP_PKEY_copy_parameters(ktmp2,ktmp); 500 EVP_PKEY_copy_parameters(ktmp2,ktmp);
501 EVP_PKEY_free(ktmp2);
505 } 502 }
506 503
507 if (pkey != NULL) 504 if (pkey != NULL) EVP_PKEY_copy_parameters(pkey,ktmp);
508 EVP_PKEY_copy_parameters(pkey,ktmp); 505 EVP_PKEY_free(ktmp);
509 return(1); 506 return(1);
510 } 507 }
511 508
512EVP_PKEY *X509_get_pubkey(x) 509int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
513X509 *x;
514 {
515 if ((x == NULL) || (x->cert_info == NULL))
516 return(NULL);
517 return(X509_PUBKEY_get(x->cert_info->key));
518 }
519
520int X509_check_private_key(x,k)
521X509 *x;
522EVP_PKEY *k;
523 {
524 EVP_PKEY *xk=NULL;
525 int ok=0;
526
527 xk=X509_get_pubkey(x);
528 if (xk->type != k->type) goto err;
529 switch (k->type)
530 {
531#ifndef NO_RSA
532 case EVP_PKEY_RSA:
533 if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0) goto err;
534 if (BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0) goto err;
535 break;
536#endif
537#ifndef NO_DSA
538 case EVP_PKEY_DSA:
539 if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)
540 goto err;
541 break;
542#endif
543#ifndef NO_DH
544 case EVP_PKEY_DH:
545 /* No idea */
546 goto err;
547#endif
548 default:
549 goto err;
550 }
551
552 ok=1;
553err:
554 return(ok);
555 }
556
557int X509_STORE_add_cert(ctx,x)
558X509_STORE *ctx;
559X509 *x;
560 { 510 {
561 X509_OBJECT *obj,*r; 511 X509_OBJECT *obj,*r;
562 int ret=1; 512 int ret=1;
@@ -591,9 +541,7 @@ X509 *x;
591 return(ret); 541 return(ret);
592 } 542 }
593 543
594int X509_STORE_add_crl(ctx,x) 544int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
595X509_STORE *ctx;
596X509_CRL *x;
597 { 545 {
598 X509_OBJECT *obj,*r; 546 X509_OBJECT *obj,*r;
599 int ret=1; 547 int ret=1;
@@ -628,12 +576,8 @@ X509_CRL *x;
628 return(ret); 576 return(ret);
629 } 577 }
630 578
631int X509_STORE_CTX_get_ex_new_index(argl,argp,new_func,dup_func,free_func) 579int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(),
632long argl; 580 int (*dup_func)(), void (*free_func)())
633char *argp;
634int (*new_func)();
635int (*dup_func)();
636void (*free_func)();
637 { 581 {
638 x509_store_ctx_num++; 582 x509_store_ctx_num++;
639 return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1, 583 return(CRYPTO_get_ex_new_index(x509_store_ctx_num-1,
@@ -641,64 +585,55 @@ void (*free_func)();
641 argl,argp,new_func,dup_func,free_func)); 585 argl,argp,new_func,dup_func,free_func));
642 } 586 }
643 587
644int X509_STORE_CTX_set_ex_data(ctx,idx,data) 588int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data)
645X509_STORE_CTX *ctx;
646int idx;
647char *data;
648 { 589 {
649 return(CRYPTO_set_ex_data(&ctx->ex_data,idx,data)); 590 return(CRYPTO_set_ex_data(&ctx->ex_data,idx,data));
650 } 591 }
651 592
652char *X509_STORE_CTX_get_ex_data(ctx,idx) 593void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx)
653X509_STORE_CTX *ctx;
654int idx;
655 { 594 {
656 return(CRYPTO_get_ex_data(&ctx->ex_data,idx)); 595 return(CRYPTO_get_ex_data(&ctx->ex_data,idx));
657 } 596 }
658 597
659int X509_STORE_CTX_get_error(ctx) 598int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx)
660X509_STORE_CTX *ctx;
661 { 599 {
662 return(ctx->error); 600 return(ctx->error);
663 } 601 }
664 602
665void X509_STORE_CTX_set_error(ctx,err) 603void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err)
666X509_STORE_CTX *ctx;
667int err;
668 { 604 {
669 ctx->error=err; 605 ctx->error=err;
670 } 606 }
671 607
672int X509_STORE_CTX_get_error_depth(ctx) 608int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx)
673X509_STORE_CTX *ctx;
674 { 609 {
675 return(ctx->error_depth); 610 return(ctx->error_depth);
676 } 611 }
677 612
678X509 *X509_STORE_CTX_get_current_cert(ctx) 613X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx)
679X509_STORE_CTX *ctx;
680 { 614 {
681 return(ctx->current_cert); 615 return(ctx->current_cert);
682 } 616 }
683 617
684STACK *X509_STORE_CTX_get_chain(ctx) 618STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx)
685X509_STORE_CTX *ctx;
686 { 619 {
687 return(ctx->chain); 620 return(ctx->chain);
688 } 621 }
689 622
690void X509_STORE_CTX_set_cert(ctx,x) 623void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)
691X509_STORE_CTX *ctx;
692X509 *x;
693 { 624 {
694 ctx->cert=x; 625 ctx->cert=x;
695 } 626 }
696 627
697void X509_STORE_CTX_set_chain(ctx,sk) 628void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
698X509_STORE_CTX *ctx;
699STACK *sk;
700 { 629 {
701 ctx->untrusted=sk; 630 ctx->untrusted=sk;
702 } 631 }
703 632
633IMPLEMENT_STACK_OF(X509)
634IMPLEMENT_ASN1_SET_OF(X509)
635
636IMPLEMENT_STACK_OF(X509_NAME)
704 637
638IMPLEMENT_STACK_OF(X509_ATTRIBUTE)
639IMPLEMENT_ASN1_SET_OF(X509_ATTRIBUTE)
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h
index dfc060f899..ecfd4cf9ed 100644
--- a/src/lib/libcrypto/x509/x509_vfy.h
+++ b/src/lib/libcrypto/x509/x509_vfy.h
@@ -56,6 +56,12 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef HEADER_X509_H
60#include <openssl/x509.h>
61/* openssl/x509.h ends up #include-ing this file at about the only
62 * appropriate moment. */
63#endif
64
59#ifndef HEADER_X509_VFY_H 65#ifndef HEADER_X509_VFY_H
60#define HEADER_X509_VFY_H 66#define HEADER_X509_VFY_H
61 67
@@ -63,8 +69,8 @@
63extern "C" { 69extern "C" {
64#endif 70#endif
65 71
66#include "bio.h" 72#include <openssl/bio.h>
67#include "crypto.h" 73#include <openssl/crypto.h>
68 74
69/* Outer object */ 75/* Outer object */
70typedef struct x509_hash_dir_st 76typedef struct x509_hash_dir_st
@@ -119,21 +125,33 @@ typedef struct x509_object_st
119 } data; 125 } data;
120 } X509_OBJECT; 126 } X509_OBJECT;
121 127
128typedef struct x509_lookup_st X509_LOOKUP;
129
130DECLARE_STACK_OF(X509_LOOKUP)
131
122/* This is a static that defines the function interface */ 132/* This is a static that defines the function interface */
123typedef struct x509_lookup_method_st 133typedef struct x509_lookup_method_st
124 { 134 {
125 char *name; 135 const char *name;
126 int (*new_item)(); 136 int (*new_item)(X509_LOOKUP *ctx);
127 void (*free)(); 137 void (*free)(X509_LOOKUP *ctx);
128 int (*init)(/* meth, char ** */); 138 int (*init)(X509_LOOKUP *ctx);
129 int (*shutdown)( /* meth, char ** */); 139 int (*shutdown)(X509_LOOKUP *ctx);
130 int (*ctrl)( /* meth, char **, int cmd, char *argp, int argi */); 140 int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl,
131 int (*get_by_subject)(/* meth, char **, XNAME *, X509 **ret */); 141 char **ret);
132 int (*get_by_issuer_serial)(); 142 int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name,
133 int (*get_by_fingerprint)(); 143 X509_OBJECT *ret);
134 int (*get_by_alias)(); 144 int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name,
145 ASN1_INTEGER *serial,X509_OBJECT *ret);
146 int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type,
147 unsigned char *bytes,int len,
148 X509_OBJECT *ret);
149 int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len,
150 X509_OBJECT *ret);
135 } X509_LOOKUP_METHOD; 151 } X509_LOOKUP_METHOD;
136 152
153typedef struct x509_store_state_st X509_STORE_CTX;
154
137/* This is used to hold everything. It is used for all certificate 155/* This is used to hold everything. It is used for all certificate
138 * validation. Once we have a certificate chain, the 'verify' 156 * validation. Once we have a certificate chain, the 'verify'
139 * function is then called to actually check the cert chain. */ 157 * function is then called to actually check the cert chain. */
@@ -148,13 +166,13 @@ typedef struct x509_store_st
148#endif 166#endif
149 167
150 /* These are external lookup methods */ 168 /* These are external lookup methods */
151 STACK *get_cert_methods;/* X509_LOOKUP */ 169 STACK_OF(X509_LOOKUP) *get_cert_methods;
152 int (*verify)(); /* called to verify a certificate */ 170 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
153 int (*verify_cb)(); /* error callback */ 171 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
154 172
155 CRYPTO_EX_DATA ex_data; 173 CRYPTO_EX_DATA ex_data;
156 int references; 174 int references;
157 int depth; /* how deep to look */ 175 int depth; /* how deep to look (still unused -- X509_STORE_CTX's depth is used) */
158 } X509_STORE; 176 } X509_STORE;
159 177
160#define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d)) 178#define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d))
@@ -163,7 +181,7 @@ typedef struct x509_store_st
163#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func)) 181#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func))
164 182
165/* This is the functions plus an instance of the local variables. */ 183/* This is the functions plus an instance of the local variables. */
166typedef struct x509_lookup_st 184struct x509_lookup_st
167 { 185 {
168 int init; /* have we been started */ 186 int init; /* have we been started */
169 int skip; /* don't use us. */ 187 int skip; /* don't use us. */
@@ -171,25 +189,25 @@ typedef struct x509_lookup_st
171 char *method_data; /* method data */ 189 char *method_data; /* method data */
172 190
173 X509_STORE *store_ctx; /* who owns us */ 191 X509_STORE *store_ctx; /* who owns us */
174 } X509_LOOKUP; 192 };
175 193
176/* This is a temporary used when processing cert chains. Since the 194/* This is a temporary used when processing cert chains. Since the
177 * gathering of the cert chain can take some time (and have to be 195 * gathering of the cert chain can take some time (and have to be
178 * 'retried', this needs to be kept and passed around. */ 196 * 'retried', this needs to be kept and passed around. */
179typedef struct x509_store_state_st 197struct x509_store_state_st /* X509_STORE_CTX */
180 { 198 {
181 X509_STORE *ctx; 199 X509_STORE *ctx;
182 int current_method; /* used when looking up certs */ 200 int current_method; /* used when looking up certs */
183 201
184 /* The following are set by the caller */ 202 /* The following are set by the caller */
185 X509 *cert; /* The cert to check */ 203 X509 *cert; /* The cert to check */
186 STACK *untrusted; /* chain of X509s - untrusted - passed in */ 204 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */
187 205
188 /* The following is built up */ 206 /* The following is built up */
189 int depth; /* how far to go looking up certs */ 207 int depth; /* how far to go looking up certs */
190 int valid; /* if 0, rebuild chain */ 208 int valid; /* if 0, rebuild chain */
191 int last_untrusted; /* index of last untrusted cert */ 209 int last_untrusted; /* index of last untrusted cert */
192 STACK *chain; /* chain of X509s - built up and trusted */ 210 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */
193 211
194 /* When something goes wrong, this is why */ 212 /* When something goes wrong, this is why */
195 int error_depth; 213 int error_depth;
@@ -197,7 +215,9 @@ typedef struct x509_store_state_st
197 X509 *current_cert; 215 X509 *current_cert;
198 216
199 CRYPTO_EX_DATA ex_data; 217 CRYPTO_EX_DATA ex_data;
200 } X509_STORE_CTX; 218 };
219
220#define X509_STORE_CTX_set_depth(ctx,d) ((ctx)->depth=(d))
201 221
202#define X509_STORE_CTX_set_app_data(ctx,data) \ 222#define X509_STORE_CTX_set_app_data(ctx,data) \
203 X509_STORE_CTX_set_ex_data(ctx,0,data) 223 X509_STORE_CTX_set_ex_data(ctx,0,data)
@@ -207,11 +227,9 @@ typedef struct x509_store_state_st
207#define X509_L_FILE_LOAD 1 227#define X509_L_FILE_LOAD 1
208#define X509_L_ADD_DIR 2 228#define X509_L_ADD_DIR 2
209 229
210X509_LOOKUP_METHOD *X509_LOOKUP_file();
211#define X509_LOOKUP_load_file(x,name,type) \ 230#define X509_LOOKUP_load_file(x,name,type) \
212 X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) 231 X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL)
213 232
214X509_LOOKUP_METHOD *X509_LOOKUP_dir();
215#define X509_LOOKUP_add_dir(x,name,type) \ 233#define X509_LOOKUP_add_dir(x,name,type) \
216 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) 234 X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL)
217 235
@@ -243,9 +261,23 @@ X509_LOOKUP_METHOD *X509_LOOKUP_dir();
243/* The application is not happy */ 261/* The application is not happy */
244#define X509_V_ERR_APPLICATION_VERIFICATION 50 262#define X509_V_ERR_APPLICATION_VERIFICATION 50
245 263
246#ifndef NOPROTO 264 /* These functions are being redefined in another directory,
265 and clash when the linker is case-insensitive, so let's
266 hide them a little, by giving them an extra 'o' at the
267 beginning of the name... */
268#ifdef VMS
269#undef X509v3_cleanup_extensions
270#define X509v3_cleanup_extensions oX509v3_cleanup_extensions
271#undef X509v3_add_extension
272#define X509v3_add_extension oX509v3_add_extension
273#undef X509v3_add_netscape_extensions
274#define X509v3_add_netscape_extensions oX509v3_add_netscape_extensions
275#undef X509v3_add_standard_extensions
276#define X509v3_add_standard_extensions oX509v3_add_standard_extensions
277#endif
278
247#ifdef HEADER_LHASH_H 279#ifdef HEADER_LHASH_H
248X509_OBJECT *X509_OBJECT_retrive_by_subject(LHASH *h,int type,X509_NAME *name); 280X509_OBJECT *X509_OBJECT_retrieve_by_subject(LHASH *h,int type,X509_NAME *name);
249#endif 281#endif
250void X509_OBJECT_up_ref_count(X509_OBJECT *a); 282void X509_OBJECT_up_ref_count(X509_OBJECT *a);
251void X509_OBJECT_free_contents(X509_OBJECT *a); 283void X509_OBJECT_free_contents(X509_OBJECT *a);
@@ -253,7 +285,7 @@ X509_STORE *X509_STORE_new(void );
253void X509_STORE_free(X509_STORE *v); 285void X509_STORE_free(X509_STORE *v);
254 286
255void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, 287void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store,
256 X509 *x509, STACK *chain); 288 X509 *x509, STACK_OF(X509) *chain);
257void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); 289void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx);
258 290
259X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); 291X509_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);
267int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name, 299int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name,
268 X509_OBJECT *ret); 300 X509_OBJECT *ret);
269 301
270int X509_LOOKUP_ctrl(X509_LOOKUP *ctx,int cmd,char *argc,long argl,char **ret); 302int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,
303 long argl, char **ret);
271 304
272#ifndef NO_STDIO 305#ifndef NO_STDIO
273int X509_load_cert_file(X509_LOOKUP *ctx, char *file, int type); 306int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type);
274int X509_load_crl_file(X509_LOOKUP *ctx, char *file, int type); 307int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type);
275#endif 308#endif
276 309
277void X509v3_cleanup_extensions(void );
278int X509v3_add_extension(X509_EXTENSION_METHOD *x);
279int X509v3_add_netscape_extensions(void );
280int X509v3_add_standard_extensions(void );
281 310
282X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); 311X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method);
283void X509_LOOKUP_free(X509_LOOKUP *ctx); 312void X509_LOOKUP_free(X509_LOOKUP *ctx);
@@ -294,82 +323,21 @@ int X509_LOOKUP_shutdown(X509_LOOKUP *ctx);
294 323
295#ifndef NO_STDIO 324#ifndef NO_STDIO
296int X509_STORE_load_locations (X509_STORE *ctx, 325int X509_STORE_load_locations (X509_STORE *ctx,
297 char *file, char *dir); 326 const char *file, const char *dir);
298int X509_STORE_set_default_paths(X509_STORE *ctx); 327int X509_STORE_set_default_paths(X509_STORE *ctx);
299#endif 328#endif
300 329
301int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(), 330int X509_STORE_CTX_get_ex_new_index(long argl, char *argp, int (*new_func)(),
302 int (*dup_func)(), void (*free_func)()); 331 int (*dup_func)(), void (*free_func)());
303int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,char *data); 332int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data);
304char * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx); 333void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx);
305int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); 334int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx);
306void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s); 335void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s);
307int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); 336int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx);
308X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); 337X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx);
309STACK * X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); 338STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
310void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x); 339void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
311void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK /* X509 */ *sk); 340void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);
312
313#else
314
315#ifdef HEADER_LHASH_H
316X509_OBJECT *X509_OBJECT_retrive_by_subject();
317#endif
318void X509_OBJECT_up_ref_count();
319void X509_OBJECT_free_contents();
320X509_STORE *X509_STORE_new();
321void X509_STORE_free();
322
323void X509_STORE_CTX_init();
324void X509_STORE_CTX_cleanup();
325
326X509_LOOKUP *X509_STORE_add_lookup();
327
328X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir();
329X509_LOOKUP_METHOD *X509_LOOKUP_file();
330
331int X509_STORE_add_cert();
332int X509_STORE_add_crl();
333
334int X509_STORE_get_by_subject();
335
336int X509_LOOKUP_ctrl();
337
338#ifndef NO_STDIO
339int X509_load_cert_file();
340int X509_load_crl_file();
341#endif
342
343void X509v3_cleanup_extensions();
344int X509v3_add_extension();
345int X509v3_add_netscape_extensions();
346int X509v3_add_standard_extensions();
347
348X509_LOOKUP *X509_LOOKUP_new();
349void X509_LOOKUP_free();
350int X509_LOOKUP_init();
351int X509_LOOKUP_by_subject();
352int X509_LOOKUP_by_issuer_serial();
353int X509_LOOKUP_by_fingerprint();
354int X509_LOOKUP_by_alias();
355int X509_LOOKUP_shutdown();
356
357#ifndef NO_STDIO
358int X509_STORE_load_locations ();
359int X509_STORE_set_default_paths();
360#endif
361
362int X509_STORE_CTX_set_ex_data();
363char * X509_STORE_CTX_get_ex_data();
364int X509_STORE_CTX_get_error();
365void X509_STORE_CTX_set_error();
366int X509_STORE_CTX_get_error_depth();
367X509 * X509_STORE_CTX_get_current_cert();
368STACK * X509_STORE_CTX_get_chain();
369void X509_STORE_CTX_set_cert();
370void X509_STORE_CTX_set_chain();
371
372#endif
373 341
374#ifdef __cplusplus 342#ifdef __cplusplus
375} 343}
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 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "stack.h" 60#include <openssl/stack.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "asn1.h" 62#include <openssl/asn1.h>
63#include "objects.h" 63#include <openssl/objects.h>
64#include "evp.h" 64#include <openssl/evp.h>
65#include "x509.h" 65#include <openssl/x509.h>
66 66
67int X509_NAME_get_text_by_NID(name,nid,buf,len) 67int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len)
68X509_NAME *name;
69int nid;
70char *buf;
71int len;
72 { 68 {
73 ASN1_OBJECT *obj; 69 ASN1_OBJECT *obj;
74 70
@@ -77,11 +73,8 @@ int len;
77 return(X509_NAME_get_text_by_OBJ(name,obj,buf,len)); 73 return(X509_NAME_get_text_by_OBJ(name,obj,buf,len));
78 } 74 }
79 75
80int X509_NAME_get_text_by_OBJ(name,obj,buf,len) 76int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf,
81X509_NAME *name; 77 int len)
82ASN1_OBJECT *obj;
83char *buf;
84int len;
85 { 78 {
86 int i; 79 int i;
87 ASN1_STRING *data; 80 ASN1_STRING *data;
@@ -96,17 +89,13 @@ int len;
96 return(i); 89 return(i);
97 } 90 }
98 91
99int X509_NAME_entry_count(name) 92int X509_NAME_entry_count(X509_NAME *name)
100X509_NAME *name;
101 { 93 {
102 if (name == NULL) return(0); 94 if (name == NULL) return(0);
103 return(sk_num(name->entries)); 95 return(sk_X509_NAME_ENTRY_num(name->entries));
104 } 96 }
105 97
106int X509_NAME_get_index_by_NID(name,nid,lastpos) 98int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)
107X509_NAME *name;
108int nid;
109int lastpos;
110 { 99 {
111 ASN1_OBJECT *obj; 100 ASN1_OBJECT *obj;
112 101
@@ -116,61 +105,57 @@ int lastpos;
116 } 105 }
117 106
118/* NOTE: you should be passsing -1, not 0 as lastpos */ 107/* NOTE: you should be passsing -1, not 0 as lastpos */
119int X509_NAME_get_index_by_OBJ(name,obj,lastpos) 108int X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj,
120X509_NAME *name; 109 int lastpos)
121ASN1_OBJECT *obj;
122int lastpos;
123 { 110 {
124 int n; 111 int n;
125 X509_NAME_ENTRY *ne; 112 X509_NAME_ENTRY *ne;
126 STACK *sk; 113 STACK_OF(X509_NAME_ENTRY) *sk;
127 114
128 if (name == NULL) return(-1); 115 if (name == NULL) return(-1);
129 if (lastpos < 0) 116 if (lastpos < 0)
130 lastpos= -1; 117 lastpos= -1;
131 sk=name->entries; 118 sk=name->entries;
132 n=sk_num(sk); 119 n=sk_X509_NAME_ENTRY_num(sk);
133 for (lastpos++; lastpos < n; lastpos++) 120 for (lastpos++; lastpos < n; lastpos++)
134 { 121 {
135 ne=(X509_NAME_ENTRY *)sk_value(sk,lastpos); 122 ne=sk_X509_NAME_ENTRY_value(sk,lastpos);
136 if (OBJ_cmp(ne->object,obj) == 0) 123 if (OBJ_cmp(ne->object,obj) == 0)
137 return(lastpos); 124 return(lastpos);
138 } 125 }
139 return(-1); 126 return(-1);
140 } 127 }
141 128
142X509_NAME_ENTRY *X509_NAME_get_entry(name,loc) 129X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)
143X509_NAME *name;
144int loc;
145 { 130 {
146 if ( (name == NULL) || (sk_num(name->entries) <= loc) || (loc < 0)) 131 if(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
132 || loc < 0)
147 return(NULL); 133 return(NULL);
148 else 134 else
149 return((X509_NAME_ENTRY *)sk_value(name->entries,loc)); 135 return(sk_X509_NAME_ENTRY_value(name->entries,loc));
150 } 136 }
151 137
152X509_NAME_ENTRY *X509_NAME_delete_entry(name,loc) 138X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc)
153X509_NAME *name;
154int loc;
155 { 139 {
156 X509_NAME_ENTRY *ret; 140 X509_NAME_ENTRY *ret;
157 int i,j,n,set_prev,set_next; 141 int i,n,set_prev,set_next;
158 STACK *sk; 142 STACK_OF(X509_NAME_ENTRY) *sk;
159 143
160 if ((name == NULL) || (sk_num(name->entries) <= loc) || (loc < 0)) 144 if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc
145 || loc < 0)
161 return(NULL); 146 return(NULL);
162 sk=name->entries; 147 sk=name->entries;
163 ret=(X509_NAME_ENTRY *)sk_delete(sk,loc); 148 ret=sk_X509_NAME_ENTRY_delete(sk,loc);
164 n=sk_num(sk); 149 n=sk_X509_NAME_ENTRY_num(sk);
165 name->modified=1; 150 name->modified=1;
166 if (loc == n) return(ret); 151 if (loc == n) return(ret);
167 152
168 /* else we need to fixup the set field */ 153 /* else we need to fixup the set field */
169 if (loc != 0) 154 if (loc != 0)
170 set_prev=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set; 155 set_prev=(sk_X509_NAME_ENTRY_value(sk,loc-1))->set;
171 else 156 else
172 set_prev=ret->set-1; 157 set_prev=ret->set-1;
173 set_next=((X509_NAME_ENTRY *)sk_value(sk,loc))->set; 158 set_next=sk_X509_NAME_ENTRY_value(sk,loc)->set;
174 159
175 /* set_prev is the previous set 160 /* set_prev is the previous set
176 * set is the current set 161 * set is the current set
@@ -181,29 +166,23 @@ int loc;
181 * so basically only if prev and next differ by 2, then 166 * so basically only if prev and next differ by 2, then
182 * re-number down by 1 */ 167 * re-number down by 1 */
183 if (set_prev+1 < set_next) 168 if (set_prev+1 < set_next)
184 {
185 j=set_next-set_prev-1;
186 for (i=loc; i<n; i++) 169 for (i=loc; i<n; i++)
187 ((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set-=j; 170 sk_X509_NAME_ENTRY_value(sk,i)->set--;
188 }
189 return(ret); 171 return(ret);
190 } 172 }
191 173
192/* if set is -1, append to previous set, 0 'a new one', and 1, 174/* if set is -1, append to previous set, 0 'a new one', and 1,
193 * prepend to the guy we are about to stomp on. */ 175 * prepend to the guy we are about to stomp on. */
194int X509_NAME_add_entry(name,ne,loc,set) 176int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc,
195X509_NAME *name; 177 int set)
196X509_NAME_ENTRY *ne;
197int loc;
198int set;
199 { 178 {
200 X509_NAME_ENTRY *new_name=NULL; 179 X509_NAME_ENTRY *new_name=NULL;
201 int n,i,inc; 180 int n,i,inc;
202 STACK *sk; 181 STACK_OF(X509_NAME_ENTRY) *sk;
203 182
204 if (name == NULL) return(0); 183 if (name == NULL) return(0);
205 sk=name->entries; 184 sk=name->entries;
206 n=sk_num(sk); 185 n=sk_X509_NAME_ENTRY_num(sk);
207 if (loc > n) loc=n; 186 if (loc > n) loc=n;
208 else if (loc < 0) loc=n; 187 else if (loc < 0) loc=n;
209 188
@@ -218,7 +197,7 @@ int set;
218 } 197 }
219 else 198 else
220 { 199 {
221 set=((X509_NAME_ENTRY *)sk_value(sk,loc-1))->set; 200 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set;
222 inc=0; 201 inc=0;
223 } 202 }
224 } 203 }
@@ -227,43 +206,38 @@ int set;
227 if (loc >= n) 206 if (loc >= n)
228 { 207 {
229 if (loc != 0) 208 if (loc != 0)
230 set=((X509_NAME_ENTRY *) 209 set=sk_X509_NAME_ENTRY_value(sk,loc-1)->set+1;
231 sk_value(sk,loc-1))->set+1;
232 else 210 else
233 set=0; 211 set=0;
234 } 212 }
235 else 213 else
236 set=((X509_NAME_ENTRY *)sk_value(sk,loc))->set; 214 set=sk_X509_NAME_ENTRY_value(sk,loc)->set;
237 inc=(set == 0)?1:0; 215 inc=(set == 0)?1:0;
238 } 216 }
239 217
240 if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL) 218 if ((new_name=X509_NAME_ENTRY_dup(ne)) == NULL)
241 goto err; 219 goto err;
242 new_name->set=set; 220 new_name->set=set;
243 if (!sk_insert(sk,(char *)new_name,loc)) 221 if (!sk_X509_NAME_ENTRY_insert(sk,new_name,loc))
244 { 222 {
245 X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE); 223 X509err(X509_F_X509_NAME_ADD_ENTRY,ERR_R_MALLOC_FAILURE);
246 goto err; 224 goto err;
247 } 225 }
248 if (inc) 226 if (inc)
249 { 227 {
250 n=sk_num(sk); 228 n=sk_X509_NAME_ENTRY_num(sk);
251 for (i=loc+1; i<n; i++) 229 for (i=loc+1; i<n; i++)
252 ((X509_NAME_ENTRY *)sk_value(sk,i-1))->set+=1; 230 sk_X509_NAME_ENTRY_value(sk,i-1)->set+=1;
253 } 231 }
254 return(1); 232 return(1);
255err: 233err:
256 if (new_name != NULL) 234 if (new_name != NULL)
257 X509_NAME_ENTRY_free(ne); 235 X509_NAME_ENTRY_free(new_name);
258 return(0); 236 return(0);
259 } 237 }
260 238
261X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(ne,nid,type,bytes,len) 239X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid,
262X509_NAME_ENTRY **ne; 240 int type, unsigned char *bytes, int len)
263int nid;
264int type;
265unsigned char *bytes;
266int len;
267 { 241 {
268 ASN1_OBJECT *obj; 242 ASN1_OBJECT *obj;
269 243
@@ -276,12 +250,8 @@ int len;
276 return(X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len)); 250 return(X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len));
277 } 251 }
278 252
279X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(ne,obj,type,bytes,len) 253X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne,
280X509_NAME_ENTRY **ne; 254 ASN1_OBJECT *obj, int type, unsigned char *bytes, int len)
281ASN1_OBJECT *obj;
282int type;
283unsigned char *bytes;
284int len;
285 { 255 {
286 X509_NAME_ENTRY *ret; 256 X509_NAME_ENTRY *ret;
287 257
@@ -306,9 +276,7 @@ err:
306 return(NULL); 276 return(NULL);
307 } 277 }
308 278
309int X509_NAME_ENTRY_set_object(ne,obj) 279int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj)
310X509_NAME_ENTRY *ne;
311ASN1_OBJECT *obj;
312 { 280 {
313 if ((ne == NULL) || (obj == NULL)) 281 if ((ne == NULL) || (obj == NULL))
314 { 282 {
@@ -320,11 +288,8 @@ ASN1_OBJECT *obj;
320 return((ne->object == NULL)?0:1); 288 return((ne->object == NULL)?0:1);
321 } 289 }
322 290
323int X509_NAME_ENTRY_set_data(ne,type,bytes,len) 291int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type,
324X509_NAME_ENTRY *ne; 292 unsigned char *bytes, int len)
325int type;
326unsigned char *bytes;
327int len;
328 { 293 {
329 int i; 294 int i;
330 295
@@ -342,15 +307,13 @@ int len;
342 return(1); 307 return(1);
343 } 308 }
344 309
345ASN1_OBJECT *X509_NAME_ENTRY_get_object(ne) 310ASN1_OBJECT *X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne)
346X509_NAME_ENTRY *ne;
347 { 311 {
348 if (ne == NULL) return(NULL); 312 if (ne == NULL) return(NULL);
349 return(ne->object); 313 return(ne->object);
350 } 314 }
351 315
352ASN1_STRING *X509_NAME_ENTRY_get_data(ne) 316ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)
353X509_NAME_ENTRY *ne;
354 { 317 {
355 if (ne == NULL) return(NULL); 318 if (ne == NULL) return(NULL);
356 return(ne->value); 319 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 @@
1/* crypto/x509/x509pack.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "stack.h"
61#include "cryptlib.h"
62#include "asn1.h"
63#include "objects.h"
64#include "evp.h"
65#include "x509.h"
66
67ASN1_OCTET_STRING *X509v3_pack_string(ex,type,bytes,len)
68ASN1_OCTET_STRING **ex;
69int type;
70unsigned char *bytes;
71int len;
72 {
73 ASN1_OCTET_STRING *os;
74 ASN1_STRING str;
75 unsigned char *p;
76 int i;
77
78 if ((ex == NULL) || (*ex == NULL))
79 os=ASN1_OCTET_STRING_new();
80 else
81 os= *ex;
82
83 if (len < 0) len=strlen((char *)bytes);
84 str.length=len;
85 str.type=type;
86 str.data=bytes;
87
88 /* str now holds the data, we just have to copy it into ->value */
89
90 switch (type)
91 {
92 case V_ASN1_BIT_STRING:
93 i=i2d_ASN1_BIT_STRING((ASN1_BIT_STRING *)&str,NULL);
94 if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i))
95 goto err;
96 p=(unsigned char *)os->data;
97 i2d_ASN1_BIT_STRING((ASN1_BIT_STRING *)&str,&p);
98 break;
99 case V_ASN1_OCTET_STRING:
100 i=i2d_ASN1_OCTET_STRING((ASN1_OCTET_STRING *)&str,NULL);
101 if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i))
102 goto err;
103 p=(unsigned char *)os->data;
104 i2d_ASN1_OCTET_STRING((ASN1_OCTET_STRING *)&str,&p);
105 break;
106 case V_ASN1_IA5STRING:
107 case V_ASN1_PRINTABLESTRING:
108 case V_ASN1_T61STRING:
109 i=i2d_ASN1_bytes(&str,NULL,type,V_ASN1_UNIVERSAL);
110 if (!ASN1_STRING_set((ASN1_STRING *)os,NULL,i))
111 goto err;
112 p=(unsigned char *)os->data;
113 i=i2d_ASN1_bytes(&str,&p,type,V_ASN1_UNIVERSAL);
114 break;
115 default:
116 X509err(X509_F_X509V3_PACK_STRING,X509_R_UNKNOWN_STRING_TYPE);
117 goto err;
118 }
119 os->length=i;
120
121 if ((ex != NULL) && (os != *ex))
122 *ex=os;
123 return(os);
124err:
125 return(NULL);
126 }
127
128ASN1_STRING *X509v3_unpack_string(ex,type,os)
129ASN1_STRING **ex;
130int type;
131ASN1_OCTET_STRING *os;
132 {
133 unsigned char *p;
134 ASN1_STRING *ret=NULL;
135
136 p=os->data;
137 switch (type)
138 {
139 case V_ASN1_BIT_STRING:
140 ret=(ASN1_STRING *)d2i_ASN1_BIT_STRING(
141 (ASN1_BIT_STRING **)ex,&p,os->length);
142 break;
143 case V_ASN1_OCTET_STRING:
144 ret=(ASN1_STRING *)d2i_ASN1_OCTET_STRING(
145 (ASN1_BIT_STRING **)ex,&p,os->length);
146 break;
147 case V_ASN1_IA5STRING:
148 case V_ASN1_PRINTABLESTRING:
149 case V_ASN1_T61STRING:
150 ret=(ASN1_STRING *)d2i_ASN1_PRINTABLE(ex,&p,os->length);
151 break;
152 default:
153 X509err(X509_F_X509V3_UNPACK_STRING,X509_R_UNKNOWN_STRING_TYPE);
154 }
155 return(ret);
156 }
157
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1.h" 61#include <openssl/asn1.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "evp.h" 63#include <openssl/evp.h>
64#include "x509.h" 64#include <openssl/x509.h>
65 65
66int X509_REQ_set_version(x,version) 66int X509_REQ_set_version(X509_REQ *x, long version)
67X509_REQ *x;
68long version;
69 { 67 {
70 if (x == NULL) return(0); 68 if (x == NULL) return(0);
71 return(ASN1_INTEGER_set(x->req_info->version,version)); 69 return(ASN1_INTEGER_set(x->req_info->version,version));
72 } 70 }
73 71
74int X509_REQ_set_subject_name(x,name) 72int X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name)
75X509_REQ *x;
76X509_NAME *name;
77 { 73 {
78 if ((x == NULL) || (x->req_info == NULL)) return(0); 74 if ((x == NULL) || (x->req_info == NULL)) return(0);
79 return(X509_NAME_set(&x->req_info->subject,name)); 75 return(X509_NAME_set(&x->req_info->subject,name));
80 } 76 }
81 77
82int X509_REQ_set_pubkey(x,pkey) 78int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey)
83X509_REQ *x;
84EVP_PKEY *pkey;
85 { 79 {
86 if ((x == NULL) || (x->req_info == NULL)) return(0); 80 if ((x == NULL) || (x->req_info == NULL)) return(0);
87 return(X509_PUBKEY_set(&x->req_info->pubkey,pkey)); 81 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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "evp.h" 61#include <openssl/evp.h>
62#include "objects.h" 62#include <openssl/objects.h>
63#include "x509.h" 63#include <openssl/x509.h>
64 64
65int X509_certificate_type(x,pkey) 65int X509_certificate_type(X509 *x, EVP_PKEY *pkey)
66X509 *x;
67EVP_PKEY *pkey;
68 { 66 {
69 EVP_PKEY *pk; 67 EVP_PKEY *pk;
70 int ret=0,i; 68 int ret=0,i;
@@ -108,8 +106,9 @@ EVP_PKEY *pkey;
108 break; 106 break;
109 } 107 }
110 108
111 if (EVP_PKEY_size(pkey) <= 512) 109 if (EVP_PKEY_size(pk) <= 512)
112 ret|=EVP_PKT_EXP; 110 ret|=EVP_PKT_EXP;
111 if(pkey==NULL) EVP_PKEY_free(pk);
113 return(ret); 112 return(ret);
114 } 113 }
115 114
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 @@
1The 'new' system.
2
3The X509_EXTENSION_METHOD includes extensions and attributes and/or names.
4Basically everthing that can be added to an X509 with an OID identifying it.
5
6It operates via 2 methods per object id.
7int a2i_XXX(X509 *x,char *str,int len);
8int i2a_XXX(BIO *bp,X509 *x);
9
10The a2i_XXX function will add the object with a value converted from the
11string into the X509. Len can be -1 in which case the length is calculated
12via strlen(str). Applications can always use direct knowledge to load and
13unload the relevent objects themselves.
14
15i2a_XXX will print to the passed BIO, a text representation of the
16relevet object. Use a memory BIO if you want it printed to a buffer :-).
17
18X509_add_by_NID(X509 *x,int nid,char *str,int len);
19X509_add_by_OBJ(X509 *x,ASN1_OBJECT *obj,char *str,int len);
20
21X509_print_by_name(BIO *bp,X509 *x);
22X509_print_by_NID(BIO *bp,X509 *x);
23X509_print_by_OBJ(BIO *bp,X509 *x);
24
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 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#undef SSLEAY_MACROS 60#undef SSLEAY_MACROS
61#include "stack.h" 61#include <openssl/stack.h>
62#include "cryptlib.h" 62#include "cryptlib.h"
63#include "buffer.h" 63#include <openssl/buffer.h>
64#include "asn1.h" 64#include <openssl/asn1.h>
65#include "evp.h" 65#include <openssl/evp.h>
66#include "x509.h" 66#include <openssl/x509.h>
67 67
68int X509_verify(a,r) 68int X509_verify(X509 *a, EVP_PKEY *r)
69X509 *a;
70EVP_PKEY *r;
71 { 69 {
72 return(ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg, 70 return(ASN1_verify((int (*)())i2d_X509_CINF,a->sig_alg,
73 a->signature,(char *)a->cert_info,r)); 71 a->signature,(char *)a->cert_info,r));
74 } 72 }
75 73
76int X509_REQ_verify(a,r) 74int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r)
77X509_REQ *a;
78EVP_PKEY *r;
79 { 75 {
80 return( ASN1_verify((int (*)())i2d_X509_REQ_INFO, 76 return( ASN1_verify((int (*)())i2d_X509_REQ_INFO,
81 a->sig_alg,a->signature,(char *)a->req_info,r)); 77 a->sig_alg,a->signature,(char *)a->req_info,r));
82 } 78 }
83 79
84int X509_CRL_verify(a,r) 80int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r)
85X509_CRL *a;
86EVP_PKEY *r;
87 { 81 {
88 return(ASN1_verify((int (*)())i2d_X509_CRL_INFO, 82 return(ASN1_verify((int (*)())i2d_X509_CRL_INFO,
89 a->sig_alg, a->signature,(char *)a->crl,r)); 83 a->sig_alg, a->signature,(char *)a->crl,r));
90 } 84 }
91 85
92int NETSCAPE_SPKI_verify(a,r) 86int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r)
93NETSCAPE_SPKI *a;
94EVP_PKEY *r;
95 { 87 {
96 return(ASN1_verify((int (*)())i2d_NETSCAPE_SPKAC, 88 return(ASN1_verify((int (*)())i2d_NETSCAPE_SPKAC,
97 a->sig_algor,a->signature, (char *)a->spkac,r)); 89 a->sig_algor,a->signature, (char *)a->spkac,r));
98 } 90 }
99 91
100int X509_sign(x,pkey,md) 92int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
101X509 *x;
102EVP_PKEY *pkey;
103EVP_MD *md;
104 { 93 {
105 return(ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature, 94 return(ASN1_sign((int (*)())i2d_X509_CINF, x->cert_info->signature,
106 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md)); 95 x->sig_alg, x->signature, (char *)x->cert_info,pkey,md));
107 } 96 }
108 97
109int X509_REQ_sign(x,pkey,md) 98int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md)
110X509_REQ *x;
111EVP_PKEY *pkey;
112EVP_MD *md;
113 { 99 {
114 return(ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL, 100 return(ASN1_sign((int (*)())i2d_X509_REQ_INFO,x->sig_alg, NULL,
115 x->signature, (char *)x->req_info,pkey,md)); 101 x->signature, (char *)x->req_info,pkey,md));
116 } 102 }
117 103
118int X509_CRL_sign(x,pkey,md) 104int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md)
119X509_CRL *x;
120EVP_PKEY *pkey;
121EVP_MD *md;
122 { 105 {
123 return(ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg, 106 return(ASN1_sign((int (*)())i2d_X509_CRL_INFO,x->crl->sig_alg,
124 x->sig_alg, x->signature, (char *)x->crl,pkey,md)); 107 x->sig_alg, x->signature, (char *)x->crl,pkey,md));
125 } 108 }
126 109
127int NETSCAPE_SPKI_sign(x,pkey,md) 110int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md)
128NETSCAPE_SPKI *x;
129EVP_PKEY *pkey;
130EVP_MD *md;
131 { 111 {
132 return(ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL, 112 return(ASN1_sign((int (*)())i2d_NETSCAPE_SPKAC, x->sig_algor,NULL,
133 x->signature, (char *)x->spkac,pkey,md)); 113 x->signature, (char *)x->spkac,pkey,md));
134 } 114 }
135 115
136X509 *X509_dup(x509) 116X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa)
137X509 *x509; 117 {
118 return((X509_ATTRIBUTE *)ASN1_dup((int (*)())i2d_X509_ATTRIBUTE,
119 (char *(*)())d2i_X509_ATTRIBUTE,(char *)xa));
120 }
121
122X509 *X509_dup(X509 *x509)
138 { 123 {
139 return((X509 *)ASN1_dup((int (*)())i2d_X509, 124 return((X509 *)ASN1_dup((int (*)())i2d_X509,
140 (char *(*)())d2i_X509,(char *)x509)); 125 (char *(*)())d2i_X509,(char *)x509));
141 } 126 }
142 127
143X509_EXTENSION *X509_EXTENSION_dup(ex) 128X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex)
144X509_EXTENSION *ex;
145 { 129 {
146 return((X509_EXTENSION *)ASN1_dup( 130 return((X509_EXTENSION *)ASN1_dup(
147 (int (*)())i2d_X509_EXTENSION, 131 (int (*)())i2d_X509_EXTENSION,
@@ -149,237 +133,184 @@ X509_EXTENSION *ex;
149 } 133 }
150 134
151#ifndef NO_FP_API 135#ifndef NO_FP_API
152X509 *d2i_X509_fp(fp,x509) 136X509 *d2i_X509_fp(FILE *fp, X509 **x509)
153FILE *fp;
154X509 *x509;
155 { 137 {
156 return((X509 *)ASN1_d2i_fp((char *(*)())X509_new, 138 return((X509 *)ASN1_d2i_fp((char *(*)())X509_new,
157 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509))); 139 (char *(*)())d2i_X509, (fp),(unsigned char **)(x509)));
158 } 140 }
159 141
160int i2d_X509_fp(fp,x509) 142int i2d_X509_fp(FILE *fp, X509 *x509)
161FILE *fp;
162X509 *x509;
163 { 143 {
164 return(ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509)); 144 return(ASN1_i2d_fp(i2d_X509,fp,(unsigned char *)x509));
165 } 145 }
166#endif 146#endif
167 147
168X509 *d2i_X509_bio(bp,x509) 148X509 *d2i_X509_bio(BIO *bp, X509 **x509)
169BIO *bp;
170X509 *x509;
171 { 149 {
172 return((X509 *)ASN1_d2i_bio((char *(*)())X509_new, 150 return((X509 *)ASN1_d2i_bio((char *(*)())X509_new,
173 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509))); 151 (char *(*)())d2i_X509, (bp),(unsigned char **)(x509)));
174 } 152 }
175 153
176int i2d_X509_bio(bp,x509) 154int i2d_X509_bio(BIO *bp, X509 *x509)
177BIO *bp;
178X509 *x509;
179 { 155 {
180 return(ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509)); 156 return(ASN1_i2d_bio(i2d_X509,bp,(unsigned char *)x509));
181 } 157 }
182 158
183X509_CRL *X509_CRL_dup(crl) 159X509_CRL *X509_CRL_dup(X509_CRL *crl)
184X509_CRL *crl;
185 { 160 {
186 return((X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL, 161 return((X509_CRL *)ASN1_dup((int (*)())i2d_X509_CRL,
187 (char *(*)())d2i_X509_CRL,(char *)crl)); 162 (char *(*)())d2i_X509_CRL,(char *)crl));
188 } 163 }
189 164
190#ifndef NO_FP_API 165#ifndef NO_FP_API
191X509_CRL *d2i_X509_CRL_fp(fp,crl) 166X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl)
192FILE *fp;
193X509_CRL *crl;
194 { 167 {
195 return((X509_CRL *)ASN1_d2i_fp((char *(*)()) 168 return((X509_CRL *)ASN1_d2i_fp((char *(*)())
196 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp), 169 X509_CRL_new,(char *(*)())d2i_X509_CRL, (fp),
197 (unsigned char **)(crl))); 170 (unsigned char **)(crl)));
198 } 171 }
199 172
200int i2d_X509_CRL_fp(fp,crl) 173int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl)
201FILE *fp;
202X509_CRL *crl;
203 { 174 {
204 return(ASN1_i2d_fp(i2d_X509_CRL,fp,(unsigned char *)crl)); 175 return(ASN1_i2d_fp(i2d_X509_CRL,fp,(unsigned char *)crl));
205 } 176 }
206#endif 177#endif
207 178
208X509_CRL *d2i_X509_CRL_bio(bp,crl) 179X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl)
209BIO *bp;
210X509_CRL *crl;
211 { 180 {
212 return((X509_CRL *)ASN1_d2i_bio((char *(*)()) 181 return((X509_CRL *)ASN1_d2i_bio((char *(*)())
213 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp), 182 X509_CRL_new,(char *(*)())d2i_X509_CRL, (bp),
214 (unsigned char **)(crl))); 183 (unsigned char **)(crl)));
215 } 184 }
216 185
217int i2d_X509_CRL_bio(bp,crl) 186int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl)
218BIO *bp;
219X509_CRL *crl;
220 { 187 {
221 return(ASN1_i2d_bio(i2d_X509_CRL,bp,(unsigned char *)crl)); 188 return(ASN1_i2d_bio(i2d_X509_CRL,bp,(unsigned char *)crl));
222 } 189 }
223 190
224PKCS7 *PKCS7_dup(p7) 191PKCS7 *PKCS7_dup(PKCS7 *p7)
225PKCS7 *p7;
226 { 192 {
227 return((PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7, 193 return((PKCS7 *)ASN1_dup((int (*)())i2d_PKCS7,
228 (char *(*)())d2i_PKCS7,(char *)p7)); 194 (char *(*)())d2i_PKCS7,(char *)p7));
229 } 195 }
230 196
231#ifndef NO_FP_API 197#ifndef NO_FP_API
232PKCS7 *d2i_PKCS7_fp(fp,p7) 198PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7)
233FILE *fp;
234PKCS7 *p7;
235 { 199 {
236 return((PKCS7 *)ASN1_d2i_fp((char *(*)()) 200 return((PKCS7 *)ASN1_d2i_fp((char *(*)())
237 PKCS7_new,(char *(*)())d2i_PKCS7, (fp), 201 PKCS7_new,(char *(*)())d2i_PKCS7, (fp),
238 (unsigned char **)(p7))); 202 (unsigned char **)(p7)));
239 } 203 }
240 204
241int i2d_PKCS7_fp(fp,p7) 205int i2d_PKCS7_fp(FILE *fp, PKCS7 *p7)
242FILE *fp;
243PKCS7 *p7;
244 { 206 {
245 return(ASN1_i2d_fp(i2d_PKCS7,fp,(unsigned char *)p7)); 207 return(ASN1_i2d_fp(i2d_PKCS7,fp,(unsigned char *)p7));
246 } 208 }
247#endif 209#endif
248 210
249PKCS7 *d2i_PKCS7_bio(bp,p7) 211PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7)
250BIO *bp;
251PKCS7 *p7;
252 { 212 {
253 return((PKCS7 *)ASN1_d2i_bio((char *(*)()) 213 return((PKCS7 *)ASN1_d2i_bio((char *(*)())
254 PKCS7_new,(char *(*)())d2i_PKCS7, (bp), 214 PKCS7_new,(char *(*)())d2i_PKCS7, (bp),
255 (unsigned char **)(p7))); 215 (unsigned char **)(p7)));
256 } 216 }
257 217
258int i2d_PKCS7_bio(bp,p7) 218int i2d_PKCS7_bio(BIO *bp, PKCS7 *p7)
259BIO *bp;
260PKCS7 *p7;
261 { 219 {
262 return(ASN1_i2d_bio(i2d_PKCS7,bp,(unsigned char *)p7)); 220 return(ASN1_i2d_bio(i2d_PKCS7,bp,(unsigned char *)p7));
263 } 221 }
264 222
265X509_REQ *X509_REQ_dup(req) 223X509_REQ *X509_REQ_dup(X509_REQ *req)
266X509_REQ *req;
267 { 224 {
268 return((X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ, 225 return((X509_REQ *)ASN1_dup((int (*)())i2d_X509_REQ,
269 (char *(*)())d2i_X509_REQ,(char *)req)); 226 (char *(*)())d2i_X509_REQ,(char *)req));
270 } 227 }
271 228
272#ifndef NO_FP_API 229#ifndef NO_FP_API
273X509_REQ *d2i_X509_REQ_fp(fp,req) 230X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req)
274FILE *fp;
275X509_REQ *req;
276 { 231 {
277 return((X509_REQ *)ASN1_d2i_fp((char *(*)()) 232 return((X509_REQ *)ASN1_d2i_fp((char *(*)())
278 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp), 233 X509_REQ_new, (char *(*)())d2i_X509_REQ, (fp),
279 (unsigned char **)(req))); 234 (unsigned char **)(req)));
280 } 235 }
281 236
282int i2d_X509_REQ_fp(fp,req) 237int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req)
283FILE *fp;
284X509_REQ *req;
285 { 238 {
286 return(ASN1_i2d_fp(i2d_X509_REQ,fp,(unsigned char *)req)); 239 return(ASN1_i2d_fp(i2d_X509_REQ,fp,(unsigned char *)req));
287 } 240 }
288#endif 241#endif
289 242
290X509_REQ *d2i_X509_REQ_bio(bp,req) 243X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req)
291BIO *bp;
292X509_REQ *req;
293 { 244 {
294 return((X509_REQ *)ASN1_d2i_bio((char *(*)()) 245 return((X509_REQ *)ASN1_d2i_bio((char *(*)())
295 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp), 246 X509_REQ_new, (char *(*)())d2i_X509_REQ, (bp),
296 (unsigned char **)(req))); 247 (unsigned char **)(req)));
297 } 248 }
298 249
299int i2d_X509_REQ_bio(bp,req) 250int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req)
300BIO *bp;
301X509_REQ *req;
302 { 251 {
303 return(ASN1_i2d_bio(i2d_X509_REQ,bp,(unsigned char *)req)); 252 return(ASN1_i2d_bio(i2d_X509_REQ,bp,(unsigned char *)req));
304 } 253 }
305 254
306#ifndef NO_RSA 255#ifndef NO_RSA
307RSA *RSAPublicKey_dup(rsa) 256RSA *RSAPublicKey_dup(RSA *rsa)
308RSA *rsa;
309 { 257 {
310 return((RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey, 258 return((RSA *)ASN1_dup((int (*)())i2d_RSAPublicKey,
311 (char *(*)())d2i_RSAPublicKey,(char *)rsa)); 259 (char *(*)())d2i_RSAPublicKey,(char *)rsa));
312 } 260 }
313 261
314RSA *RSAPrivateKey_dup(rsa) 262RSA *RSAPrivateKey_dup(RSA *rsa)
315RSA *rsa;
316 { 263 {
317 return((RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey, 264 return((RSA *)ASN1_dup((int (*)())i2d_RSAPrivateKey,
318 (char *(*)())d2i_RSAPrivateKey,(char *)rsa)); 265 (char *(*)())d2i_RSAPrivateKey,(char *)rsa));
319 } 266 }
320 267
321#ifndef NO_FP_API 268#ifndef NO_FP_API
322RSA *d2i_RSAPrivateKey_fp(fp,rsa) 269RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa)
323FILE *fp;
324RSA *rsa;
325 { 270 {
326 return((RSA *)ASN1_d2i_fp((char *(*)()) 271 return((RSA *)ASN1_d2i_fp((char *(*)())
327 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp), 272 RSA_new,(char *(*)())d2i_RSAPrivateKey, (fp),
328 (unsigned char **)(rsa))); 273 (unsigned char **)(rsa)));
329 } 274 }
330 275
331int i2d_RSAPrivateKey_fp(fp,rsa) 276int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa)
332FILE *fp;
333RSA *rsa;
334 { 277 {
335 return(ASN1_i2d_fp(i2d_RSAPrivateKey,fp,(unsigned char *)rsa)); 278 return(ASN1_i2d_fp(i2d_RSAPrivateKey,fp,(unsigned char *)rsa));
336 } 279 }
337 280
338RSA *d2i_RSAPublicKey_fp(fp,rsa) 281RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa)
339FILE *fp;
340RSA *rsa;
341 { 282 {
342 return((RSA *)ASN1_d2i_fp((char *(*)()) 283 return((RSA *)ASN1_d2i_fp((char *(*)())
343 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp), 284 RSA_new,(char *(*)())d2i_RSAPublicKey, (fp),
344 (unsigned char **)(rsa))); 285 (unsigned char **)(rsa)));
345 } 286 }
346 287
347int i2d_RSAPublicKey_fp(fp,rsa) 288int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
348FILE *fp;
349RSA *rsa;
350 { 289 {
351 return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa)); 290 return(ASN1_i2d_fp(i2d_RSAPublicKey,fp,(unsigned char *)rsa));
352 } 291 }
353#endif 292#endif
354 293
355RSA *d2i_RSAPrivateKey_bio(bp,rsa) 294RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa)
356BIO *bp;
357RSA *rsa;
358 { 295 {
359 return((RSA *)ASN1_d2i_bio((char *(*)()) 296 return((RSA *)ASN1_d2i_bio((char *(*)())
360 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp), 297 RSA_new,(char *(*)())d2i_RSAPrivateKey, (bp),
361 (unsigned char **)(rsa))); 298 (unsigned char **)(rsa)));
362 } 299 }
363 300
364int i2d_RSAPrivateKey_bio(bp,rsa) 301int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa)
365BIO *bp;
366RSA *rsa;
367 { 302 {
368 return(ASN1_i2d_bio(i2d_RSAPrivateKey,bp,(unsigned char *)rsa)); 303 return(ASN1_i2d_bio(i2d_RSAPrivateKey,bp,(unsigned char *)rsa));
369 } 304 }
370 305
371RSA *d2i_RSAPublicKey_bio(bp,rsa) 306RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa)
372BIO *bp;
373RSA *rsa;
374 { 307 {
375 return((RSA *)ASN1_d2i_bio((char *(*)()) 308 return((RSA *)ASN1_d2i_bio((char *(*)())
376 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp), 309 RSA_new,(char *(*)())d2i_RSAPublicKey, (bp),
377 (unsigned char **)(rsa))); 310 (unsigned char **)(rsa)));
378 } 311 }
379 312
380int i2d_RSAPublicKey_bio(bp,rsa) 313int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
381BIO *bp;
382RSA *rsa;
383 { 314 {
384 return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa)); 315 return(ASN1_i2d_bio(i2d_RSAPublicKey,bp,(unsigned char *)rsa));
385 } 316 }
@@ -387,79 +318,120 @@ RSA *rsa;
387 318
388#ifndef NO_DSA 319#ifndef NO_DSA
389#ifndef NO_FP_API 320#ifndef NO_FP_API
390DSA *d2i_DSAPrivateKey_fp(fp,dsa) 321DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa)
391FILE *fp;
392DSA *dsa;
393 { 322 {
394 return((DSA *)ASN1_d2i_fp((char *(*)()) 323 return((DSA *)ASN1_d2i_fp((char *(*)())
395 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp), 324 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp),
396 (unsigned char **)(dsa))); 325 (unsigned char **)(dsa)));
397 } 326 }
398 327
399int i2d_DSAPrivateKey_fp(fp,dsa) 328int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
400FILE *fp;
401DSA *dsa;
402 { 329 {
403 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa)); 330 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
404 } 331 }
405#endif 332#endif
406 333
407DSA *d2i_DSAPrivateKey_bio(bp,dsa) 334DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa)
408BIO *bp;
409DSA *dsa;
410 { 335 {
411 return((DSA *)ASN1_d2i_bio((char *(*)()) 336 return((DSA *)ASN1_d2i_bio((char *(*)())
412 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp), 337 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp),
413 (unsigned char **)(dsa))); 338 (unsigned char **)(dsa)));
414 } 339 }
415 340
416int i2d_DSAPrivateKey_bio(bp,dsa) 341int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa)
417BIO *bp;
418DSA *dsa;
419 { 342 {
420 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa)); 343 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
421 } 344 }
422#endif 345#endif
423 346
424X509_NAME *X509_NAME_dup(xn) 347X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn)
425X509_NAME *xn; 348 {
349 return((X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,
350 (char *(*)())d2i_X509_ALGOR,(char *)xn));
351 }
352
353X509_NAME *X509_NAME_dup(X509_NAME *xn)
426 { 354 {
427 return((X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME, 355 return((X509_NAME *)ASN1_dup((int (*)())i2d_X509_NAME,
428 (char *(*)())d2i_X509_NAME,(char *)xn)); 356 (char *(*)())d2i_X509_NAME,(char *)xn));
429 } 357 }
430 358
431X509_NAME_ENTRY *X509_NAME_ENTRY_dup(ne) 359X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne)
432X509_NAME_ENTRY *ne;
433 { 360 {
434 return((X509_NAME_ENTRY *)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY, 361 return((X509_NAME_ENTRY *)ASN1_dup((int (*)())i2d_X509_NAME_ENTRY,
435 (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne)); 362 (char *(*)())d2i_X509_NAME_ENTRY,(char *)ne));
436 } 363 }
437 364
438int X509_digest(data,type,md,len) 365int X509_digest(X509 *data, EVP_MD *type, unsigned char *md,
439X509 *data; 366 unsigned int *len)
440EVP_MD *type;
441unsigned char *md;
442unsigned int *len;
443 { 367 {
444 return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)); 368 return(ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len));
445 } 369 }
446 370
447int X509_NAME_digest(data,type,md,len) 371int X509_NAME_digest(X509_NAME *data, EVP_MD *type, unsigned char *md,
448X509_NAME *data; 372 unsigned int *len)
449EVP_MD *type;
450unsigned char *md;
451unsigned int *len;
452 { 373 {
453 return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len)); 374 return(ASN1_digest((int (*)())i2d_X509_NAME,type,(char *)data,md,len));
454 } 375 }
455 376
456int PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) 377int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, EVP_MD *type,
457PKCS7_ISSUER_AND_SERIAL *data; 378 unsigned char *md, unsigned int *len)
458EVP_MD *type;
459unsigned char *md;
460unsigned int *len;
461 { 379 {
462 return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type, 380 return(ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,
463 (char *)data,md,len)); 381 (char *)data,md,len));
464 } 382 }
465 383
384
385#ifndef NO_FP_API
386X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8)
387 {
388 return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new,
389 (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8)));
390 }
391
392int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8)
393 {
394 return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8));
395 }
396#endif
397
398X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8)
399 {
400 return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new,
401 (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8)));
402 }
403
404int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8)
405 {
406 return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8));
407 }
408
409#ifndef NO_FP_API
410PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
411 PKCS8_PRIV_KEY_INFO **p8inf)
412 {
413 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp(
414 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
415 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp),
416 (unsigned char **)(p8inf)));
417 }
418
419int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
420 {
421 return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf));
422 }
423#endif
424
425PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
426 PKCS8_PRIV_KEY_INFO **p8inf)
427 {
428 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio(
429 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
430 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp),
431 (unsigned char **)(p8inf)));
432 }
433
434int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
435 {
436 return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf));
437 }
diff --git a/src/lib/libcrypto/x509v3/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 @@
1#
2# SSLeay/crypto/x509v3/Makefile
3#
4
5DIR= x509v3
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPEND= $(TOP)/util/domd $(TOP)
15MAKEFILE= Makefile.ssl
16AR= ar r
17
18CFLAGS= $(INCLUDES) $(CFLAG)
19
20GENERAL=Makefile README
21TEST=
22APPS=
23
24LIB=$(TOP)/libcrypto.a
25LIBSRC= v3_bcons.c v3_bitst.c v3_conf.c v3_extku.c v3_ia5.c \
26v3_lib.c v3_prn.c v3_utl.c v3err.c v3_genn.c v3_alt.c v3_skey.c v3_akey.c \
27v3_pku.c v3_int.c v3_enum.c v3_sxnet.c v3_cpols.c v3_crld.c
28LIBOBJ= v3_bcons.o v3_bitst.o v3_conf.o v3_extku.o v3_ia5.o v3_lib.o \
29v3_prn.o v3_utl.o v3err.o v3_genn.o v3_alt.o v3_skey.o v3_akey.o v3_pku.o \
30v3_int.o v3_enum.o v3_sxnet.o v3_cpols.o v3_crld.o
31
32SRC= $(LIBSRC)
33
34EXHEADER= x509v3.h
35HEADER= $(EXHEADER)
36
37ALL= $(GENERAL) $(SRC) $(HEADER)
38
39top:
40 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
41
42all: lib
43
44lib: $(LIBOBJ)
45 $(AR) $(LIB) $(LIBOBJ)
46 $(RANLIB) $(LIB)
47 @touch lib
48
49files:
50 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
51
52links:
53 @$(TOP)/util/point.sh Makefile.ssl Makefile
54 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
55 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
56 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
57
58install:
59 @for i in $(EXHEADER) ; \
60 do \
61 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
62 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
63 done;
64
65tags:
66 ctags $(SRC)
67
68tests:
69
70lint:
71 lint -DLINT $(INCLUDES) $(SRC)>fluff
72
73depend:
74 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
75
76dclean:
77 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
78 mv -f Makefile.new $(MAKEFILE)
79
80clean:
81 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
82
83# DO NOT DELETE THIS LINE -- make depend depends on it.
84
85v3_akey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
86v3_akey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
87v3_akey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
88v3_akey.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
89v3_akey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
90v3_akey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
91v3_akey.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
92v3_akey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
93v3_akey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
94v3_akey.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
95v3_akey.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
96v3_akey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
97v3_akey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
98v3_akey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
99v3_akey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
100v3_akey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
101v3_akey.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
102v3_akey.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
103v3_akey.o: ../cryptlib.h
104v3_alt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
105v3_alt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
106v3_alt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
107v3_alt.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
108v3_alt.o: ../../include/openssl/des.h ../../include/openssl/dh.h
109v3_alt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
110v3_alt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
111v3_alt.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
112v3_alt.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
113v3_alt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
114v3_alt.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
115v3_alt.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
116v3_alt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
117v3_alt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
118v3_alt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
119v3_alt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
120v3_alt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
121v3_alt.o: ../../include/openssl/x509v3.h ../cryptlib.h
122v3_bcons.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
123v3_bcons.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
124v3_bcons.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
125v3_bcons.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
126v3_bcons.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
127v3_bcons.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
128v3_bcons.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
129v3_bcons.o: ../../include/openssl/err.h ../../include/openssl/evp.h
130v3_bcons.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
131v3_bcons.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
132v3_bcons.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
133v3_bcons.o: ../../include/openssl/opensslconf.h
134v3_bcons.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
135v3_bcons.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
136v3_bcons.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
137v3_bcons.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
138v3_bcons.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
139v3_bcons.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
140v3_bcons.o: ../../include/openssl/x509v3.h ../cryptlib.h
141v3_bitst.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
142v3_bitst.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
143v3_bitst.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
144v3_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
145v3_bitst.o: ../../include/openssl/des.h ../../include/openssl/dh.h
146v3_bitst.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
147v3_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
148v3_bitst.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
149v3_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
150v3_bitst.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
151v3_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
152v3_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
153v3_bitst.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
154v3_bitst.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
155v3_bitst.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
156v3_bitst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
157v3_bitst.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
158v3_bitst.o: ../../include/openssl/x509v3.h ../cryptlib.h
159v3_conf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
160v3_conf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
161v3_conf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
162v3_conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
163v3_conf.o: ../../include/openssl/des.h ../../include/openssl/dh.h
164v3_conf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
165v3_conf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
166v3_conf.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
167v3_conf.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
168v3_conf.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
169v3_conf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
170v3_conf.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
171v3_conf.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
172v3_conf.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
173v3_conf.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
174v3_conf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
175v3_conf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
176v3_conf.o: ../../include/openssl/x509v3.h ../cryptlib.h
177v3_cpols.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
178v3_cpols.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
179v3_cpols.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
180v3_cpols.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
181v3_cpols.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
182v3_cpols.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
183v3_cpols.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
184v3_cpols.o: ../../include/openssl/err.h ../../include/openssl/evp.h
185v3_cpols.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
186v3_cpols.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
187v3_cpols.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
188v3_cpols.o: ../../include/openssl/opensslconf.h
189v3_cpols.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
190v3_cpols.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
191v3_cpols.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
192v3_cpols.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
193v3_cpols.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
194v3_cpols.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
195v3_cpols.o: ../../include/openssl/x509v3.h ../cryptlib.h
196v3_crld.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
197v3_crld.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
198v3_crld.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
199v3_crld.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
200v3_crld.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
201v3_crld.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
202v3_crld.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
203v3_crld.o: ../../include/openssl/err.h ../../include/openssl/evp.h
204v3_crld.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
205v3_crld.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
206v3_crld.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
207v3_crld.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
208v3_crld.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
209v3_crld.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
210v3_crld.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
211v3_crld.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
212v3_crld.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
213v3_crld.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
214v3_crld.o: ../cryptlib.h
215v3_enum.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
216v3_enum.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
217v3_enum.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
218v3_enum.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
219v3_enum.o: ../../include/openssl/des.h ../../include/openssl/dh.h
220v3_enum.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
221v3_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
222v3_enum.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
223v3_enum.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
224v3_enum.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
225v3_enum.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
226v3_enum.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
227v3_enum.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
228v3_enum.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
229v3_enum.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
230v3_enum.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
231v3_enum.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
232v3_enum.o: ../../include/openssl/x509v3.h ../cryptlib.h
233v3_extku.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
234v3_extku.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
235v3_extku.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
236v3_extku.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
237v3_extku.o: ../../include/openssl/des.h ../../include/openssl/dh.h
238v3_extku.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
239v3_extku.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
240v3_extku.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
241v3_extku.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
242v3_extku.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
243v3_extku.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
244v3_extku.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
245v3_extku.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
246v3_extku.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
247v3_extku.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
248v3_extku.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
249v3_extku.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
250v3_extku.o: ../../include/openssl/x509v3.h ../cryptlib.h
251v3_genn.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
252v3_genn.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
253v3_genn.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
254v3_genn.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
255v3_genn.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
256v3_genn.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
257v3_genn.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
258v3_genn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
259v3_genn.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
260v3_genn.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
261v3_genn.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
262v3_genn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
263v3_genn.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
264v3_genn.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
265v3_genn.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
266v3_genn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
267v3_genn.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
268v3_genn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
269v3_genn.o: ../cryptlib.h
270v3_ia5.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
271v3_ia5.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
272v3_ia5.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
273v3_ia5.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
274v3_ia5.o: ../../include/openssl/des.h ../../include/openssl/dh.h
275v3_ia5.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
276v3_ia5.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
277v3_ia5.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
278v3_ia5.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
279v3_ia5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
280v3_ia5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
281v3_ia5.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
282v3_ia5.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
283v3_ia5.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
284v3_ia5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
285v3_ia5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
286v3_ia5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
287v3_ia5.o: ../../include/openssl/x509v3.h ../cryptlib.h
288v3_int.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
289v3_int.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
290v3_int.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
291v3_int.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
292v3_int.o: ../../include/openssl/des.h ../../include/openssl/dh.h
293v3_int.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
294v3_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
295v3_int.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
296v3_int.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
297v3_int.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
298v3_int.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
299v3_int.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
300v3_int.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
301v3_int.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
302v3_int.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
303v3_int.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
304v3_int.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
305v3_int.o: ../../include/openssl/x509v3.h ../cryptlib.h
306v3_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
307v3_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
308v3_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
309v3_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
310v3_lib.o: ../../include/openssl/des.h ../../include/openssl/dh.h
311v3_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
312v3_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
313v3_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
314v3_lib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
315v3_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
316v3_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
317v3_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
318v3_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
319v3_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
320v3_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
321v3_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
322v3_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
323v3_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h
324v3_pku.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
325v3_pku.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
326v3_pku.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
327v3_pku.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
328v3_pku.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
329v3_pku.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
330v3_pku.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
331v3_pku.o: ../../include/openssl/err.h ../../include/openssl/evp.h
332v3_pku.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
333v3_pku.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
334v3_pku.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
335v3_pku.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
336v3_pku.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
337v3_pku.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
338v3_pku.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
339v3_pku.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
340v3_pku.o: ../../include/openssl/stack.h ../../include/openssl/x509.h
341v3_pku.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
342v3_pku.o: ../cryptlib.h
343v3_prn.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
344v3_prn.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
345v3_prn.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
346v3_prn.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
347v3_prn.o: ../../include/openssl/des.h ../../include/openssl/dh.h
348v3_prn.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
349v3_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
350v3_prn.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
351v3_prn.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
352v3_prn.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
353v3_prn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
354v3_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
355v3_prn.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
356v3_prn.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
357v3_prn.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
358v3_prn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
359v3_prn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
360v3_prn.o: ../../include/openssl/x509v3.h ../cryptlib.h
361v3_skey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
362v3_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
363v3_skey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
364v3_skey.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
365v3_skey.o: ../../include/openssl/des.h ../../include/openssl/dh.h
366v3_skey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
367v3_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
368v3_skey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
369v3_skey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
370v3_skey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
371v3_skey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
372v3_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
373v3_skey.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
374v3_skey.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
375v3_skey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
376v3_skey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
377v3_skey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
378v3_skey.o: ../../include/openssl/x509v3.h ../cryptlib.h
379v3_sxnet.o: ../../include/openssl/asn1.h ../../include/openssl/asn1_mac.h
380v3_sxnet.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
381v3_sxnet.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
382v3_sxnet.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
383v3_sxnet.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
384v3_sxnet.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
385v3_sxnet.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
386v3_sxnet.o: ../../include/openssl/err.h ../../include/openssl/evp.h
387v3_sxnet.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
388v3_sxnet.o: ../../include/openssl/md2.h ../../include/openssl/md5.h
389v3_sxnet.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h
390v3_sxnet.o: ../../include/openssl/opensslconf.h
391v3_sxnet.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
392v3_sxnet.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
393v3_sxnet.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
394v3_sxnet.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
395v3_sxnet.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
396v3_sxnet.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
397v3_sxnet.o: ../../include/openssl/x509v3.h ../cryptlib.h
398v3_utl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
399v3_utl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
400v3_utl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
401v3_utl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
402v3_utl.o: ../../include/openssl/des.h ../../include/openssl/dh.h
403v3_utl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os.h
404v3_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
405v3_utl.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
406v3_utl.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
407v3_utl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
408v3_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
409v3_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
410v3_utl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
411v3_utl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
412v3_utl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
413v3_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
414v3_utl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
415v3_utl.o: ../../include/openssl/x509v3.h ../cryptlib.h
416v3err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
417v3err.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
418v3err.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
419v3err.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
420v3err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
421v3err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
422v3err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
423v3err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
424v3err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
425v3err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
426v3err.o: ../../include/openssl/opensslv.h ../../include/openssl/pkcs7.h
427v3err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
428v3err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
429v3err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
430v3err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
431v3err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
432v3err.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 @@
1WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
2
3This is ***VERY*** new experimental code and is likely to change
4considerably or vanish altogether.
diff --git a/src/lib/libcrypto/x509v3/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 @@
1AuthorityKeyIdentifier
2 {
3 keyIdentifier [0] OCTET_STRING OPTIONAL
4 authorityCertIssuer [1] GeneralNames OPTIONAL
5 authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL
6 }
7
8SubjectKeyIdentifier OCTET_STRING
9
10KeyUsage
11 {
12 BIT_STRING
13 digitalSignature 0
14 nonRepudiation 1
15 keyEncipherment 2
16 dataEncipherment 3
17 keyAgreement 4
18 keyCertSign 5
19 cRLSign 6
20 encipherOnly 7
21 decipherOnly 8
22 }
23
24extKeyUsage
25 {
26 SEQUENCE of OBJECT_IDENTIFIER
27 }
28
29privateKeyUsagePeriod
30 {
31 notBefore [0] GeneralizedTime OPTIONAL
32 notAfter [1] GeneralizedTime OPTIONAL
33 }
34
35certificatePoliciesSyntax
36 SEQUENCE of PoliciesInformation
37
38PoliciesInformation XXX
39policyMappings XXX
40supportedAlgorithms XXX
41
42subjectAltName
43 GeneralNames sequence of GeneralName
44
45GeneralName
46 {
47 otherName [0] INSTANCE OF OTHER-NAME
48 rfc882Name [1] IA5String
49 dNSName [2] IA5String
50 x400Address [3] ORAddress
51 directoryName [4] Name
52 ediPartyName [5]
53 {
54 nameAssigner [0] DirectoryString OPTIONAL
55 partyName [1] DirectoryString
56 }
57 uniformResourceIdentifier [6] IA5String
58 iPAddress [7] OCTET_STRING
59 registeredID [8] OBJECT_IDENTIFIER
60 }
61
62issuerAltName
63 GeneralNames sequence of GeneralName
64
65subjectDirectoryAttribute SEQUENCE of Attribute
66
67basicConstraints
68 {
69 cA BOOLEAN default FALSE
70 pathLenConstraint INTEGER OPTIONAL
71 }
72
73nameConstraints
74 {
75 permittedSubtrees [0] sequence of GeneralSubtree OPTIONAL
76 excludedSubtrees [1] sequence of GeneralSubtree OPTIONAL
77 }
78
79GeneralSubtree
80 {
81 base GeneralName
82 minimum [0] BaseDistance DEFAULT 0
83 maximum [1] BaseDistance OPTIONAL
84 }
85
86PolicyConstraints
87 {
88 requiredExplicitPolicy [0] SkipCerts OPTIONAL
89 inhibitPolicyMapping [1] SkipCerts OPTIONAL
90 }
91SkipCerts == INTEGER
92
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 @@
1int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size)
2int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a)
3int i2d_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp)
4ASN1_INTEGER * d2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,long length)
5
6
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 @@
1/* v3_akey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
67 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist);
68static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
70
71X509V3_EXT_METHOD v3_akey_id = {
72NID_authority_key_identifier, X509V3_EXT_MULTILINE,
73(X509V3_EXT_NEW)AUTHORITY_KEYID_new,
74(X509V3_EXT_FREE)AUTHORITY_KEYID_free,
75(X509V3_EXT_D2I)d2i_AUTHORITY_KEYID,
76(X509V3_EXT_I2D)i2d_AUTHORITY_KEYID,
77NULL, NULL,
78(X509V3_EXT_I2V)i2v_AUTHORITY_KEYID,
79(X509V3_EXT_V2I)v2i_AUTHORITY_KEYID,
80NULL,NULL,
81NULL
82};
83
84
85int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *a, unsigned char **pp)
86{
87 M_ASN1_I2D_vars(a);
88
89 M_ASN1_I2D_len_IMP_opt (a->keyid, i2d_ASN1_OCTET_STRING);
90 M_ASN1_I2D_len_IMP_opt (a->issuer, i2d_GENERAL_NAMES);
91 M_ASN1_I2D_len_IMP_opt (a->serial, i2d_ASN1_INTEGER);
92
93 M_ASN1_I2D_seq_total();
94
95 M_ASN1_I2D_put_IMP_opt (a->keyid, i2d_ASN1_OCTET_STRING, 0);
96 M_ASN1_I2D_put_IMP_opt (a->issuer, i2d_GENERAL_NAMES, 1);
97 M_ASN1_I2D_put_IMP_opt (a->serial, i2d_ASN1_INTEGER, 2);
98
99 M_ASN1_I2D_finish();
100}
101
102AUTHORITY_KEYID *AUTHORITY_KEYID_new(void)
103{
104 AUTHORITY_KEYID *ret=NULL;
105 ASN1_CTX c;
106 M_ASN1_New_Malloc(ret, AUTHORITY_KEYID);
107 ret->keyid = NULL;
108 ret->issuer = NULL;
109 ret->serial = NULL;
110 return (ret);
111 M_ASN1_New_Error(ASN1_F_AUTHORITY_KEYID_NEW);
112}
113
114AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp,
115 long length)
116{
117 M_ASN1_D2I_vars(a,AUTHORITY_KEYID *,AUTHORITY_KEYID_new);
118 M_ASN1_D2I_Init();
119 M_ASN1_D2I_start_sequence();
120 M_ASN1_D2I_get_IMP_opt (ret->keyid, d2i_ASN1_OCTET_STRING, 0,
121 V_ASN1_OCTET_STRING);
122 M_ASN1_D2I_get_IMP_opt (ret->issuer, d2i_GENERAL_NAMES, 1,
123 V_ASN1_SEQUENCE);
124 M_ASN1_D2I_get_IMP_opt (ret->serial, d2i_ASN1_INTEGER, 2,
125 V_ASN1_INTEGER);
126 M_ASN1_D2I_Finish(a, AUTHORITY_KEYID_free, ASN1_F_D2I_AUTHORITY_KEYID);
127}
128
129void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a)
130{
131 if (a == NULL) return;
132 ASN1_OCTET_STRING_free(a->keyid);
133 sk_GENERAL_NAME_pop_free(a->issuer, GENERAL_NAME_free);
134 ASN1_INTEGER_free (a->serial);
135 Free ((char *)a);
136}
137
138static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
139 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist)
140{
141 char *tmp;
142 if(akeyid->keyid) {
143 tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length);
144 X509V3_add_value("keyid", tmp, &extlist);
145 Free(tmp);
146 }
147 if(akeyid->issuer)
148 extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
149 if(akeyid->serial) {
150 tmp = hex_to_string(akeyid->serial->data,
151 akeyid->serial->length);
152 X509V3_add_value("serial", tmp, &extlist);
153 Free(tmp);
154 }
155 return extlist;
156}
157
158/* Currently two options:
159 * keyid: use the issuers subject keyid, the value 'always' means its is
160 * an error if the issuer certificate doesn't have a key id.
161 * issuer: use the issuers cert issuer and serial number. The default is
162 * to only use this if keyid is not present. With the option 'always'
163 * this is always included.
164 */
165
166static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
167 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
168{
169char keyid=0, issuer=0;
170int i;
171CONF_VALUE *cnf;
172ASN1_OCTET_STRING *ikeyid = NULL;
173X509_NAME *isname = NULL;
174STACK_OF(GENERAL_NAME) * gens = NULL;
175GENERAL_NAME *gen = NULL;
176ASN1_INTEGER *serial = NULL;
177X509_EXTENSION *ext;
178X509 *cert;
179AUTHORITY_KEYID *akeyid;
180for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
181 cnf = sk_CONF_VALUE_value(values, i);
182 if(!strcmp(cnf->name, "keyid")) {
183 keyid = 1;
184 if(cnf->value && !strcmp(cnf->value, "always")) keyid = 2;
185 } else if(!strcmp(cnf->name, "issuer")) {
186 issuer = 1;
187 if(cnf->value && !strcmp(cnf->value, "always")) issuer = 2;
188 } else {
189 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION);
190 ERR_add_error_data(2, "name=", cnf->name);
191 return NULL;
192 }
193}
194
195
196
197if(!ctx || !ctx->issuer_cert) {
198 if(ctx && (ctx->flags==CTX_TEST)) return AUTHORITY_KEYID_new();
199 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE);
200 return NULL;
201}
202
203cert = ctx->issuer_cert;
204
205if(keyid) {
206 i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
207 if((i >= 0) && (ext = X509_get_ext(cert, i)))
208 ikeyid = X509V3_EXT_d2i(ext);
209 if(keyid==2 && !ikeyid) {
210 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
211 return NULL;
212 }
213}
214
215if((issuer && !ikeyid) || (issuer == 2)) {
216 isname = X509_NAME_dup(X509_get_issuer_name(cert));
217 serial = ASN1_INTEGER_dup(X509_get_serialNumber(cert));
218 if(!isname || !serial) {
219 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
220 goto err;
221 }
222}
223
224if(!(akeyid = AUTHORITY_KEYID_new())) goto err;
225
226if(isname) {
227 if(!(gens = sk_GENERAL_NAME_new(NULL)) || !(gen = GENERAL_NAME_new())
228 || !sk_GENERAL_NAME_push(gens, gen)) {
229 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE);
230 goto err;
231 }
232 gen->type = GEN_DIRNAME;
233 gen->d.dirn = isname;
234}
235
236akeyid->issuer = gens;
237akeyid->serial = serial;
238akeyid->keyid = ikeyid;
239
240return akeyid;
241
242err:
243X509_NAME_free(isname);
244ASN1_INTEGER_free(serial);
245ASN1_OCTET_STRING_free(ikeyid);
246return NULL;
247
248}
249
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c
new file mode 100644
index 0000000000..b5e1f8af96
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_alt.c
@@ -0,0 +1,402 @@
1/* v3_alt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
65static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens);
67static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens);
68X509V3_EXT_METHOD v3_alt[] = {
69{ NID_subject_alt_name, 0,
70(X509V3_EXT_NEW)GENERAL_NAMES_new,
71(X509V3_EXT_FREE)GENERAL_NAMES_free,
72(X509V3_EXT_D2I)d2i_GENERAL_NAMES,
73(X509V3_EXT_I2D)i2d_GENERAL_NAMES,
74NULL, NULL,
75(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
76(X509V3_EXT_V2I)v2i_subject_alt,
77NULL, NULL, NULL},
78{ NID_issuer_alt_name, 0,
79(X509V3_EXT_NEW)GENERAL_NAMES_new,
80(X509V3_EXT_FREE)GENERAL_NAMES_free,
81(X509V3_EXT_D2I)d2i_GENERAL_NAMES,
82(X509V3_EXT_I2D)i2d_GENERAL_NAMES,
83NULL, NULL,
84(X509V3_EXT_I2V)i2v_GENERAL_NAMES,
85(X509V3_EXT_V2I)v2i_issuer_alt,
86NULL, NULL, NULL},
87EXT_END
88};
89
90STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
91 STACK_OF(GENERAL_NAME) *gens, STACK_OF(CONF_VALUE) *ret)
92{
93 int i;
94 GENERAL_NAME *gen;
95 for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
96 gen = sk_GENERAL_NAME_value(gens, i);
97 ret = i2v_GENERAL_NAME(method, gen, ret);
98 }
99 if(!ret) return sk_CONF_VALUE_new_null();
100 return ret;
101}
102
103STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
104 GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret)
105{
106 char oline[256];
107 unsigned char *p;
108 switch (gen->type)
109 {
110 case GEN_OTHERNAME:
111 X509V3_add_value("othername","<unsupported>", &ret);
112 break;
113
114 case GEN_X400:
115 X509V3_add_value("X400Name","<unsupported>", &ret);
116 break;
117
118 case GEN_EDIPARTY:
119 X509V3_add_value("EdiPartyName","<unsupported>", &ret);
120 break;
121
122 case GEN_EMAIL:
123 X509V3_add_value_uchar("email",gen->d.ia5->data, &ret);
124 break;
125
126 case GEN_DNS:
127 X509V3_add_value_uchar("DNS",gen->d.ia5->data, &ret);
128 break;
129
130 case GEN_URI:
131 X509V3_add_value_uchar("URI",gen->d.ia5->data, &ret);
132 break;
133
134 case GEN_DIRNAME:
135 X509_NAME_oneline(gen->d.dirn, oline, 256);
136 X509V3_add_value("DirName",oline, &ret);
137 break;
138
139 case GEN_IPADD:
140 p = gen->d.ip->data;
141 /* BUG: doesn't support IPV6 */
142 if(gen->d.ip->length != 4) {
143 X509V3_add_value("IP Address","<invalid>", &ret);
144 break;
145 }
146 sprintf(oline, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
147 X509V3_add_value("IP Address",oline, &ret);
148 break;
149
150 case GEN_RID:
151 i2t_ASN1_OBJECT(oline, 256, gen->d.rid);
152 X509V3_add_value("Registered ID",oline, &ret);
153 break;
154 }
155 return ret;
156}
157
158static STACK_OF(GENERAL_NAME) *v2i_issuer_alt(X509V3_EXT_METHOD *method,
159 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
160{
161 STACK_OF(GENERAL_NAME) *gens = NULL;
162 CONF_VALUE *cnf;
163 int i;
164 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
165 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
166 return NULL;
167 }
168 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
169 cnf = sk_CONF_VALUE_value(nval, i);
170 if(!name_cmp(cnf->name, "issuer") && cnf->value &&
171 !strcmp(cnf->value, "copy")) {
172 if(!copy_issuer(ctx, gens)) goto err;
173 } else {
174 GENERAL_NAME *gen;
175 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
176 goto err;
177 sk_GENERAL_NAME_push(gens, gen);
178 }
179 }
180 return gens;
181 err:
182 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
183 return NULL;
184}
185
186/* Append subject altname of issuer to issuer alt name of subject */
187
188static int copy_issuer(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
189{
190 STACK_OF(GENERAL_NAME) *ialt;
191 GENERAL_NAME *gen;
192 X509_EXTENSION *ext;
193 int i;
194 if(ctx && (ctx->flags == CTX_TEST)) return 1;
195 if(!ctx || !ctx->issuer_cert) {
196 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_NO_ISSUER_DETAILS);
197 goto err;
198 }
199 i = X509_get_ext_by_NID(ctx->issuer_cert, NID_subject_alt_name, -1);
200 if(i < 0) return 1;
201 if(!(ext = X509_get_ext(ctx->issuer_cert, i)) ||
202 !(ialt = X509V3_EXT_d2i(ext)) ) {
203 X509V3err(X509V3_F_COPY_ISSUER,X509V3_R_ISSUER_DECODE_ERROR);
204 goto err;
205 }
206
207 for(i = 0; i < sk_GENERAL_NAME_num(ialt); i++) {
208 gen = sk_GENERAL_NAME_value(ialt, i);
209 if(!sk_GENERAL_NAME_push(gens, gen)) {
210 X509V3err(X509V3_F_COPY_ISSUER,ERR_R_MALLOC_FAILURE);
211 goto err;
212 }
213 }
214 sk_GENERAL_NAME_free(ialt);
215
216 return 1;
217
218 err:
219 return 0;
220
221}
222
223static STACK_OF(GENERAL_NAME) *v2i_subject_alt(X509V3_EXT_METHOD *method,
224 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
225{
226 STACK_OF(GENERAL_NAME) *gens = NULL;
227 CONF_VALUE *cnf;
228 int i;
229 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
230 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
231 return NULL;
232 }
233 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
234 cnf = sk_CONF_VALUE_value(nval, i);
235 if(!name_cmp(cnf->name, "email") && cnf->value &&
236 !strcmp(cnf->value, "copy")) {
237 if(!copy_email(ctx, gens)) goto err;
238 } else {
239 GENERAL_NAME *gen;
240 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf)))
241 goto err;
242 sk_GENERAL_NAME_push(gens, gen);
243 }
244 }
245 return gens;
246 err:
247 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
248 return NULL;
249}
250
251/* Copy any email addresses in a certificate or request to
252 * GENERAL_NAMES
253 */
254
255static int copy_email(X509V3_CTX *ctx, STACK_OF(GENERAL_NAME) *gens)
256{
257 X509_NAME *nm;
258 ASN1_IA5STRING *email = NULL;
259 X509_NAME_ENTRY *ne;
260 GENERAL_NAME *gen = NULL;
261 int i;
262 if(ctx->flags == CTX_TEST) return 1;
263 if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
264 X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS);
265 goto err;
266 }
267 /* Find the subject name */
268 if(ctx->subject_cert) nm = X509_get_subject_name(ctx->subject_cert);
269 else nm = X509_REQ_get_subject_name(ctx->subject_req);
270
271 /* Now add any email address(es) to STACK */
272 i = -1;
273 while((i = X509_NAME_get_index_by_NID(nm,
274 NID_pkcs9_emailAddress, i)) > 0) {
275 ne = X509_NAME_get_entry(nm, i);
276 email = ASN1_IA5STRING_dup(X509_NAME_ENTRY_get_data(ne));
277 if(!email || !(gen = GENERAL_NAME_new())) {
278 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
279 goto err;
280 }
281 gen->d.ia5 = email;
282 email = NULL;
283 gen->type = GEN_EMAIL;
284 if(!sk_GENERAL_NAME_push(gens, gen)) {
285 X509V3err(X509V3_F_COPY_EMAIL,ERR_R_MALLOC_FAILURE);
286 goto err;
287 }
288 gen = NULL;
289 }
290
291
292 return 1;
293
294 err:
295 GENERAL_NAME_free(gen);
296 ASN1_IA5STRING_free(email);
297 return 0;
298
299}
300
301STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
302 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
303{
304 GENERAL_NAME *gen;
305 STACK_OF(GENERAL_NAME) *gens = NULL;
306 CONF_VALUE *cnf;
307 int i;
308 if(!(gens = sk_GENERAL_NAME_new(NULL))) {
309 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
310 return NULL;
311 }
312 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
313 cnf = sk_CONF_VALUE_value(nval, i);
314 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
315 sk_GENERAL_NAME_push(gens, gen);
316 }
317 return gens;
318 err:
319 sk_GENERAL_NAME_pop_free(gens, GENERAL_NAME_free);
320 return NULL;
321}
322
323GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
324 CONF_VALUE *cnf)
325{
326char is_string = 0;
327int type;
328GENERAL_NAME *gen = NULL;
329
330char *name, *value;
331
332name = cnf->name;
333value = cnf->value;
334
335if(!value) {
336 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE);
337 return NULL;
338}
339
340if(!(gen = GENERAL_NAME_new())) {
341 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
342 return NULL;
343}
344
345if(!name_cmp(name, "email")) {
346 is_string = 1;
347 type = GEN_EMAIL;
348} else if(!name_cmp(name, "URI")) {
349 is_string = 1;
350 type = GEN_URI;
351} else if(!name_cmp(name, "DNS")) {
352 is_string = 1;
353 type = GEN_DNS;
354} else if(!name_cmp(name, "RID")) {
355 ASN1_OBJECT *obj;
356 if(!(obj = OBJ_txt2obj(value,0))) {
357 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT);
358 ERR_add_error_data(2, "value=", value);
359 goto err;
360 }
361 gen->d.rid = obj;
362 type = GEN_RID;
363} else if(!name_cmp(name, "IP")) {
364 int i1,i2,i3,i4;
365 unsigned char ip[4];
366 if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) ||
367 (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) ||
368 (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) {
369 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS);
370 ERR_add_error_data(2, "value=", value);
371 goto err;
372 }
373 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4;
374 if(!(gen->d.ip = ASN1_OCTET_STRING_new()) ||
375 !ASN1_STRING_set(gen->d.ip, ip, 4)) {
376 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
377 goto err;
378 }
379 type = GEN_IPADD;
380} else {
381 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION);
382 ERR_add_error_data(2, "name=", name);
383 goto err;
384}
385
386if(is_string) {
387 if(!(gen->d.ia5 = ASN1_IA5STRING_new()) ||
388 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
389 strlen(value))) {
390 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
391 goto err;
392 }
393}
394
395gen->type = type;
396
397return gen;
398
399err:
400GENERAL_NAME_free(gen);
401return NULL;
402}
diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c
new file mode 100644
index 0000000000..de2f855c35
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_bcons.c
@@ -0,0 +1,164 @@
1/* v3_bcons.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist);
68static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
69
70X509V3_EXT_METHOD v3_bcons = {
71NID_basic_constraints, 0,
72(X509V3_EXT_NEW)BASIC_CONSTRAINTS_new,
73(X509V3_EXT_FREE)BASIC_CONSTRAINTS_free,
74(X509V3_EXT_D2I)d2i_BASIC_CONSTRAINTS,
75(X509V3_EXT_I2D)i2d_BASIC_CONSTRAINTS,
76NULL, NULL,
77(X509V3_EXT_I2V)i2v_BASIC_CONSTRAINTS,
78(X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS,
79NULL,NULL,
80NULL
81};
82
83
84int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp)
85{
86 M_ASN1_I2D_vars(a);
87 if(a->ca) M_ASN1_I2D_len (a->ca, i2d_ASN1_BOOLEAN);
88 M_ASN1_I2D_len (a->pathlen, i2d_ASN1_INTEGER);
89
90 M_ASN1_I2D_seq_total();
91
92 if (a->ca) M_ASN1_I2D_put (a->ca, i2d_ASN1_BOOLEAN);
93 M_ASN1_I2D_put (a->pathlen, i2d_ASN1_INTEGER);
94 M_ASN1_I2D_finish();
95}
96
97BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void)
98{
99 BASIC_CONSTRAINTS *ret=NULL;
100 ASN1_CTX c;
101 M_ASN1_New_Malloc(ret, BASIC_CONSTRAINTS);
102 ret->ca = 0;
103 ret->pathlen = NULL;
104 return (ret);
105 M_ASN1_New_Error(ASN1_F_BASIC_CONSTRAINTS_NEW);
106}
107
108BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a,
109 unsigned char **pp, long length)
110{
111 M_ASN1_D2I_vars(a,BASIC_CONSTRAINTS *,BASIC_CONSTRAINTS_new);
112 M_ASN1_D2I_Init();
113 M_ASN1_D2I_start_sequence();
114 if((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) ==
115 (V_ASN1_UNIVERSAL|V_ASN1_BOOLEAN) ) {
116 M_ASN1_D2I_get_int (ret->ca, d2i_ASN1_BOOLEAN);
117 }
118 M_ASN1_D2I_get_opt (ret->pathlen, d2i_ASN1_INTEGER, V_ASN1_INTEGER);
119 M_ASN1_D2I_Finish(a, BASIC_CONSTRAINTS_free, ASN1_F_D2I_BASIC_CONSTRAINTS);
120}
121
122void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a)
123{
124 if (a == NULL) return;
125 ASN1_INTEGER_free (a->pathlen);
126 Free ((char *)a);
127}
128
129static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
130 BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist)
131{
132 X509V3_add_value_bool("CA", bcons->ca, &extlist);
133 X509V3_add_value_int("pathlen", bcons->pathlen, &extlist);
134 return extlist;
135}
136
137static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method,
138 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
139{
140 BASIC_CONSTRAINTS *bcons=NULL;
141 CONF_VALUE *val;
142 int i;
143 if(!(bcons = BASIC_CONSTRAINTS_new())) {
144 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE);
145 return NULL;
146 }
147 for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
148 val = sk_CONF_VALUE_value(values, i);
149 if(!strcmp(val->name, "CA")) {
150 if(!X509V3_get_value_bool(val, &bcons->ca)) goto err;
151 } else if(!strcmp(val->name, "pathlen")) {
152 if(!X509V3_get_value_int(val, &bcons->pathlen)) goto err;
153 } else {
154 X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME);
155 X509V3_conf_err(val);
156 goto err;
157 }
158 }
159 return bcons;
160 err:
161 BASIC_CONSTRAINTS_free(bcons);
162 return NULL;
163}
164
diff --git a/src/lib/libcrypto/x509v3/v3_bitst.c b/src/lib/libcrypto/x509v3/v3_bitst.c
new file mode 100644
index 0000000000..9828ba15b3
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_bitst.c
@@ -0,0 +1,147 @@
1/* v3_bitst.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/x509v3.h>
63
64static ASN1_BIT_STRING *asn1_bit_string_new(void);
65static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
66 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
67static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
68 ASN1_BIT_STRING *bits,
69 STACK_OF(CONF_VALUE) *extlist);
70static BIT_STRING_BITNAME ns_cert_type_table[] = {
71{0, "SSL Client", "client"},
72{1, "SSL Server", "server"},
73{2, "S/MIME", "email"},
74{3, "Object Signing", "objsign"},
75{4, "Unused", "reserved"},
76{5, "SSL CA", "sslCA"},
77{6, "S/MIME CA", "emailCA"},
78{7, "Object Signing CA", "objCA"},
79{-1, NULL, NULL}
80};
81
82static BIT_STRING_BITNAME key_usage_type_table[] = {
83{0, "Digital Signature", "digitalSignature"},
84{1, "Non Repudiation", "nonRepudiation"},
85{2, "Key Encipherment", "keyEncipherment"},
86{3, "Data Encipherment", "dataEncipherment"},
87{4, "Key Agreement", "keyAgreement"},
88{5, "Certificate Sign", "keyCertSign"},
89{6, "CRL Sign", "cRLSign"},
90{7, "Encipher Only", "encipherOnly"},
91{8, "Decipher Only", "decipherOnly"},
92{-1, NULL, NULL}
93};
94
95
96
97X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
98X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table);
99
100static ASN1_BIT_STRING *asn1_bit_string_new(void)
101{
102 return ASN1_BIT_STRING_new();
103}
104
105static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
106 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret)
107{
108 BIT_STRING_BITNAME *bnam;
109 for(bnam =method->usr_data; bnam->lname; bnam++) {
110 if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum))
111 X509V3_add_value(bnam->lname, NULL, &ret);
112 }
113 return ret;
114}
115
116static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
117 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
118{
119 CONF_VALUE *val;
120 ASN1_BIT_STRING *bs;
121 int i;
122 BIT_STRING_BITNAME *bnam;
123 if(!(bs = ASN1_BIT_STRING_new())) {
124 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE);
125 return NULL;
126 }
127 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
128 val = sk_CONF_VALUE_value(nval, i);
129 for(bnam = method->usr_data; bnam->lname; bnam++) {
130 if(!strcmp(bnam->sname, val->name) ||
131 !strcmp(bnam->lname, val->name) ) {
132 ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1);
133 break;
134 }
135 }
136 if(!bnam->lname) {
137 X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,
138 X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT);
139 X509V3_conf_err(val);
140 ASN1_BIT_STRING_free(bs);
141 return NULL;
142 }
143 }
144 return bs;
145}
146
147
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
new file mode 100644
index 0000000000..f19bb3ad84
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_conf.c
@@ -0,0 +1,366 @@
1/* v3_conf.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* extension creation utilities */
59
60
61
62#include <stdio.h>
63#include <ctype.h>
64#include "cryptlib.h"
65#include <openssl/conf.h>
66#include <openssl/x509.h>
67#include <openssl/x509v3.h>
68
69static int v3_check_critical(char **value);
70static int v3_check_generic(char **value);
71static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value);
72static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type);
73static char *conf_lhash_get_string(void *db, char *section, char *value);
74static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section);
75static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
76 int crit, void *ext_struc);
77/* LHASH *conf: Config file */
78/* char *name: Name */
79/* char *value: Value */
80X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
81 char *value)
82{
83 int crit;
84 int ext_type;
85 X509_EXTENSION *ret;
86 crit = v3_check_critical(&value);
87 if((ext_type = v3_check_generic(&value)))
88 return v3_generic_extension(name, value, crit, ext_type);
89 ret = do_ext_conf(conf, ctx, OBJ_sn2nid(name), crit, value);
90 if(!ret) {
91 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_ERROR_IN_EXTENSION);
92 ERR_add_error_data(4,"name=", name, ", value=", value);
93 }
94 return ret;
95}
96
97/* LHASH *conf: Config file */
98/* char *value: Value */
99X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
100 char *value)
101{
102 int crit;
103 int ext_type;
104 crit = v3_check_critical(&value);
105 if((ext_type = v3_check_generic(&value)))
106 return v3_generic_extension(OBJ_nid2sn(ext_nid),
107 value, crit, ext_type);
108 return do_ext_conf(conf, ctx, ext_nid, crit, value);
109}
110
111/* LHASH *conf: Config file */
112/* char *value: Value */
113static X509_EXTENSION *do_ext_conf(LHASH *conf, X509V3_CTX *ctx, int ext_nid,
114 int crit, char *value)
115{
116 X509V3_EXT_METHOD *method;
117 X509_EXTENSION *ext;
118 STACK_OF(CONF_VALUE) *nval;
119 void *ext_struc;
120 if(ext_nid == NID_undef) {
121 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION_NAME);
122 return NULL;
123 }
124 if(!(method = X509V3_EXT_get_nid(ext_nid))) {
125 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION);
126 return NULL;
127 }
128 /* Now get internal extension representation based on type */
129 if(method->v2i) {
130 if(*value == '@') nval = CONF_get_section(conf, value + 1);
131 else nval = X509V3_parse_list(value);
132 if(!nval) {
133 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_INVALID_EXTENSION_STRING);
134 ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value);
135 return NULL;
136 }
137 ext_struc = method->v2i(method, ctx, nval);
138 if(*value != '@') sk_CONF_VALUE_pop_free(nval,
139 X509V3_conf_free);
140 if(!ext_struc) return NULL;
141 } else if(method->s2i) {
142 if(!(ext_struc = method->s2i(method, ctx, value))) return NULL;
143 } else if(method->r2i) {
144 if(!ctx->db) {
145 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_NO_CONFIG_DATABASE);
146 return NULL;
147 }
148 if(!(ext_struc = method->r2i(method, ctx, value))) return NULL;
149 } else {
150 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
151 ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid));
152 return NULL;
153 }
154
155 ext = do_ext_i2d(method, ext_nid, crit, ext_struc);
156 method->ext_free(ext_struc);
157 return ext;
158
159}
160
161static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
162 int crit, void *ext_struc)
163{
164 unsigned char *ext_der, *p;
165 int ext_len;
166 ASN1_OCTET_STRING *ext_oct;
167 X509_EXTENSION *ext;
168 /* Convert internal representation to DER */
169 ext_len = method->i2d(ext_struc, NULL);
170 if(!(ext_der = Malloc(ext_len))) goto merr;
171 p = ext_der;
172 method->i2d(ext_struc, &p);
173 if(!(ext_oct = ASN1_OCTET_STRING_new())) goto merr;
174 ext_oct->data = ext_der;
175 ext_oct->length = ext_len;
176
177 ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);
178 if(!ext) goto merr;
179 ASN1_OCTET_STRING_free(ext_oct);
180
181 return ext;
182
183 merr:
184 X509V3err(X509V3_F_DO_EXT_I2D,ERR_R_MALLOC_FAILURE);
185 return NULL;
186
187}
188
189/* Given an internal structure, nid and critical flag create an extension */
190
191X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc)
192{
193 X509V3_EXT_METHOD *method;
194 if(!(method = X509V3_EXT_get_nid(ext_nid))) {
195 X509V3err(X509V3_F_X509V3_EXT_I2D,X509V3_R_UNKNOWN_EXTENSION);
196 return NULL;
197 }
198 return do_ext_i2d(method, ext_nid, crit, ext_struc);
199}
200
201/* Check the extension string for critical flag */
202static int v3_check_critical(char **value)
203{
204 char *p = *value;
205 if((strlen(p) < 9) || strncmp(p, "critical,", 9)) return 0;
206 p+=9;
207 while(isspace((unsigned char)*p)) p++;
208 *value = p;
209 return 1;
210}
211
212/* Check extension string for generic extension and return the type */
213static int v3_check_generic(char **value)
214{
215 char *p = *value;
216 if((strlen(p) < 4) || strncmp(p, "DER:,", 4)) return 0;
217 p+=4;
218 while(isspace((unsigned char)*p)) p++;
219 *value = p;
220 return 1;
221}
222
223/* Create a generic extension: for now just handle RAW type */
224static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
225 int crit, int type)
226{
227unsigned char *ext_der=NULL;
228long ext_len;
229ASN1_OBJECT *obj=NULL;
230ASN1_OCTET_STRING *oct=NULL;
231X509_EXTENSION *extension=NULL;
232if(!(obj = OBJ_txt2obj(ext, 0))) {
233 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_NAME_ERROR);
234 ERR_add_error_data(2, "name=", ext);
235 goto err;
236}
237
238if(!(ext_der = string_to_hex(value, &ext_len))) {
239 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR);
240 ERR_add_error_data(2, "value=", value);
241 goto err;
242}
243
244if(!(oct = ASN1_OCTET_STRING_new())) {
245 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,ERR_R_MALLOC_FAILURE);
246 goto err;
247}
248
249oct->data = ext_der;
250oct->length = ext_len;
251ext_der = NULL;
252
253extension = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct);
254
255err:
256ASN1_OBJECT_free(obj);
257ASN1_OCTET_STRING_free(oct);
258if(ext_der) Free(ext_der);
259return extension;
260}
261
262
263/* This is the main function: add a bunch of extensions based on a config file
264 * section
265 */
266
267int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
268 X509 *cert)
269{
270 X509_EXTENSION *ext;
271 STACK_OF(CONF_VALUE) *nval;
272 CONF_VALUE *val;
273 int i;
274 if(!(nval = CONF_get_section(conf, section))) return 0;
275 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
276 val = sk_CONF_VALUE_value(nval, i);
277 if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value)))
278 return 0;
279 if(cert) X509_add_ext(cert, ext, -1);
280 X509_EXTENSION_free(ext);
281 }
282 return 1;
283}
284
285/* Same as above but for a CRL */
286
287int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
288 X509_CRL *crl)
289{
290 X509_EXTENSION *ext;
291 STACK_OF(CONF_VALUE) *nval;
292 CONF_VALUE *val;
293 int i;
294 if(!(nval = CONF_get_section(conf, section))) return 0;
295 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
296 val = sk_CONF_VALUE_value(nval, i);
297 if(!(ext = X509V3_EXT_conf(conf, ctx, val->name, val->value)))
298 return 0;
299 if(crl) X509_CRL_add_ext(crl, ext, -1);
300 X509_EXTENSION_free(ext);
301 }
302 return 1;
303}
304
305/* Config database functions */
306
307char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
308{
309 if(ctx->db_meth->get_string)
310 return ctx->db_meth->get_string(ctx->db, name, section);
311 return NULL;
312}
313
314STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section)
315{
316 if(ctx->db_meth->get_section)
317 return ctx->db_meth->get_section(ctx->db, section);
318 return NULL;
319}
320
321void X509V3_string_free(X509V3_CTX *ctx, char *str)
322{
323 if(!str) return;
324 if(ctx->db_meth->free_string)
325 ctx->db_meth->free_string(ctx->db, str);
326}
327
328void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section)
329{
330 if(!section) return;
331 if(ctx->db_meth->free_section)
332 ctx->db_meth->free_section(ctx->db, section);
333}
334
335static char *conf_lhash_get_string(void *db, char *section, char *value)
336{
337 return CONF_get_string(db, section, value);
338}
339
340static STACK_OF(CONF_VALUE) *conf_lhash_get_section(void *db, char *section)
341{
342 return CONF_get_section(db, section);
343}
344
345static X509V3_CONF_METHOD conf_lhash_method = {
346conf_lhash_get_string,
347conf_lhash_get_section,
348NULL,
349NULL
350};
351
352void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash)
353{
354 ctx->db_meth = &conf_lhash_method;
355 ctx->db = lhash;
356}
357
358void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subj, X509_REQ *req,
359 X509_CRL *crl, int flags)
360{
361 ctx->issuer_cert = issuer;
362 ctx->subject_cert = subj;
363 ctx->crl = crl;
364 ctx->subject_req = req;
365 ctx->flags = flags;
366}
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
new file mode 100644
index 0000000000..b4d4883545
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_cpols.c
@@ -0,0 +1,655 @@
1/* v3_cpols.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66/* Certificate policies extension support: this one is a bit complex... */
67
68static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent);
69static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *value);
70static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals, int indent);
71static void print_notice(BIO *out, USERNOTICE *notice, int indent);
72static POLICYINFO *policy_section(X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *polstrs, int ia5org);
74static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
75 STACK_OF(CONF_VALUE) *unot, int ia5org);
76static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos);
77
78X509V3_EXT_METHOD v3_cpols = {
79NID_certificate_policies, 0,
80(X509V3_EXT_NEW)CERTIFICATEPOLICIES_new,
81(X509V3_EXT_FREE)CERTIFICATEPOLICIES_free,
82(X509V3_EXT_D2I)d2i_CERTIFICATEPOLICIES,
83(X509V3_EXT_I2D)i2d_CERTIFICATEPOLICIES,
84NULL, NULL,
85NULL, NULL,
86(X509V3_EXT_I2R)i2r_certpol,
87(X509V3_EXT_R2I)r2i_certpol,
88NULL
89};
90
91
92static STACK_OF(POLICYINFO) *r2i_certpol(X509V3_EXT_METHOD *method,
93 X509V3_CTX *ctx, char *value)
94{
95 STACK_OF(POLICYINFO) *pols = NULL;
96 char *pstr;
97 POLICYINFO *pol;
98 ASN1_OBJECT *pobj;
99 STACK_OF(CONF_VALUE) *vals;
100 CONF_VALUE *cnf;
101 int i, ia5org;
102 pols = sk_POLICYINFO_new_null();
103 vals = X509V3_parse_list(value);
104 ia5org = 0;
105 for(i = 0; i < sk_CONF_VALUE_num(vals); i++) {
106 cnf = sk_CONF_VALUE_value(vals, i);
107 if(cnf->value || !cnf->name ) {
108 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_POLICY_IDENTIFIER);
109 X509V3_conf_err(cnf);
110 goto err;
111 }
112 pstr = cnf->name;
113 if(!strcmp(pstr,"ia5org")) {
114 ia5org = 1;
115 continue;
116 } else if(*pstr == '@') {
117 STACK_OF(CONF_VALUE) *polsect;
118 polsect = X509V3_get_section(ctx, pstr + 1);
119 if(!polsect) {
120 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_SECTION);
121
122 X509V3_conf_err(cnf);
123 goto err;
124 }
125 pol = policy_section(ctx, polsect, ia5org);
126 X509V3_section_free(ctx, polsect);
127 if(!pol) goto err;
128 } else {
129 if(!(pobj = OBJ_txt2obj(cnf->name, 0))) {
130 X509V3err(X509V3_F_R2I_CERTPOL,X509V3_R_INVALID_OBJECT_IDENTIFIER);
131 X509V3_conf_err(cnf);
132 goto err;
133 }
134 pol = POLICYINFO_new();
135 pol->policyid = pobj;
136 }
137 sk_POLICYINFO_push(pols, pol);
138 }
139 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
140 return pols;
141 err:
142 sk_POLICYINFO_pop_free(pols, POLICYINFO_free);
143 return NULL;
144}
145
146static POLICYINFO *policy_section(X509V3_CTX *ctx,
147 STACK_OF(CONF_VALUE) *polstrs, int ia5org)
148{
149 int i;
150 CONF_VALUE *cnf;
151 POLICYINFO *pol;
152 POLICYQUALINFO *qual;
153 if(!(pol = POLICYINFO_new())) goto merr;
154 for(i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
155 cnf = sk_CONF_VALUE_value(polstrs, i);
156 if(!strcmp(cnf->name, "policyIdentifier")) {
157 ASN1_OBJECT *pobj;
158 if(!(pobj = OBJ_txt2obj(cnf->value, 0))) {
159 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OBJECT_IDENTIFIER);
160 X509V3_conf_err(cnf);
161 goto err;
162 }
163 pol->policyid = pobj;
164
165 } else if(!name_cmp(cnf->name, "CPS")) {
166 if(!pol->qualifiers) pol->qualifiers =
167 sk_POLICYQUALINFO_new_null();
168 if(!(qual = POLICYQUALINFO_new())) goto merr;
169 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
170 goto merr;
171 qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
172 qual->d.cpsuri = ASN1_IA5STRING_new();
173 if(!ASN1_STRING_set(qual->d.cpsuri, cnf->value,
174 strlen(cnf->value))) goto merr;
175 } else if(!name_cmp(cnf->name, "userNotice")) {
176 STACK_OF(CONF_VALUE) *unot;
177 if(*cnf->value != '@') {
178 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_EXPECTED_A_SECTION_NAME);
179 X509V3_conf_err(cnf);
180 goto err;
181 }
182 unot = X509V3_get_section(ctx, cnf->value + 1);
183 if(!unot) {
184 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_SECTION);
185
186 X509V3_conf_err(cnf);
187 goto err;
188 }
189 qual = notice_section(ctx, unot, ia5org);
190 X509V3_section_free(ctx, unot);
191 if(!qual) goto err;
192 if(!sk_POLICYQUALINFO_push(pol->qualifiers, qual))
193 goto merr;
194 } else {
195 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_INVALID_OPTION);
196
197 X509V3_conf_err(cnf);
198 goto err;
199 }
200 }
201 if(!pol->policyid) {
202 X509V3err(X509V3_F_POLICY_SECTION,X509V3_R_NO_POLICY_IDENTIFIER);
203 goto err;
204 }
205
206 return pol;
207
208 merr:
209 X509V3err(X509V3_F_POLICY_SECTION,ERR_R_MALLOC_FAILURE);
210
211 err:
212 POLICYINFO_free(pol);
213 return NULL;
214
215
216}
217
218static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
219 STACK_OF(CONF_VALUE) *unot, int ia5org)
220{
221 int i;
222 CONF_VALUE *cnf;
223 USERNOTICE *not;
224 POLICYQUALINFO *qual;
225 if(!(qual = POLICYQUALINFO_new())) goto merr;
226 qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
227 if(!(not = USERNOTICE_new())) goto merr;
228 qual->d.usernotice = not;
229 for(i = 0; i < sk_CONF_VALUE_num(unot); i++) {
230 cnf = sk_CONF_VALUE_value(unot, i);
231 if(!strcmp(cnf->name, "explicitText")) {
232 not->exptext = ASN1_VISIBLESTRING_new();
233 if(!ASN1_STRING_set(not->exptext, cnf->value,
234 strlen(cnf->value))) goto merr;
235 } else if(!strcmp(cnf->name, "organization")) {
236 NOTICEREF *nref;
237 if(!not->noticeref) {
238 if(!(nref = NOTICEREF_new())) goto merr;
239 not->noticeref = nref;
240 } else nref = not->noticeref;
241 if(ia5org) nref->organization = ASN1_IA5STRING_new();
242 else nref->organization = ASN1_VISIBLESTRING_new();
243 if(!ASN1_STRING_set(nref->organization, cnf->value,
244 strlen(cnf->value))) goto merr;
245 } else if(!strcmp(cnf->name, "noticeNumbers")) {
246 NOTICEREF *nref;
247 STACK_OF(CONF_VALUE) *nos;
248 if(!not->noticeref) {
249 if(!(nref = NOTICEREF_new())) goto merr;
250 not->noticeref = nref;
251 } else nref = not->noticeref;
252 nos = X509V3_parse_list(cnf->value);
253 if(!nos || !sk_CONF_VALUE_num(nos)) {
254 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_NUMBERS);
255 X509V3_conf_err(cnf);
256 goto err;
257 }
258 nref->noticenos = nref_nos(nos);
259 sk_CONF_VALUE_pop_free(nos, X509V3_conf_free);
260 if(!nref->noticenos) goto err;
261 } else {
262 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_INVALID_OPTION);
263
264 X509V3_conf_err(cnf);
265 goto err;
266 }
267 }
268
269 if(not->noticeref &&
270 (!not->noticeref->noticenos || !not->noticeref->organization)) {
271 X509V3err(X509V3_F_NOTICE_SECTION,X509V3_R_NEED_ORGANIZATION_AND_NUMBERS);
272 goto err;
273 }
274
275 return qual;
276
277 merr:
278 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
279
280 err:
281 POLICYQUALINFO_free(qual);
282 return NULL;
283}
284
285static STACK *nref_nos(STACK_OF(CONF_VALUE) *nos)
286{
287 STACK *nnums;
288 CONF_VALUE *cnf;
289 ASN1_INTEGER *aint;
290 int i;
291 if(!(nnums = sk_new_null())) goto merr;
292 for(i = 0; i < sk_CONF_VALUE_num(nos); i++) {
293 cnf = sk_CONF_VALUE_value(nos, i);
294 if(!(aint = s2i_ASN1_INTEGER(NULL, cnf->name))) {
295 X509V3err(X509V3_F_NREF_NOS,X509V3_R_INVALID_NUMBER);
296 goto err;
297 }
298 if(!sk_push(nnums, (char *)aint)) goto merr;
299 }
300 return nnums;
301
302 merr:
303 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
304
305 err:
306 sk_pop_free(nnums, ASN1_STRING_free);
307 return NULL;
308}
309
310
311static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol,
312 BIO *out, int indent)
313{
314 int i;
315 POLICYINFO *pinfo;
316 /* First print out the policy OIDs */
317 for(i = 0; i < sk_POLICYINFO_num(pol); i++) {
318 pinfo = sk_POLICYINFO_value(pol, i);
319 BIO_printf(out, "%*sPolicy: ", indent, "");
320 i2a_ASN1_OBJECT(out, pinfo->policyid);
321 BIO_puts(out, "\n");
322 if(pinfo->qualifiers)
323 print_qualifiers(out, pinfo->qualifiers, indent + 2);
324 }
325 return 1;
326}
327
328
329int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp)
330{
331
332return i2d_ASN1_SET_OF_POLICYINFO(a, pp, i2d_POLICYINFO, V_ASN1_SEQUENCE,
333 V_ASN1_UNIVERSAL, IS_SEQUENCE);}
334
335STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void)
336{
337 return sk_POLICYINFO_new_null();
338}
339
340void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a)
341{
342 sk_POLICYINFO_pop_free(a, POLICYINFO_free);
343}
344
345STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a,
346 unsigned char **pp,long length)
347{
348return d2i_ASN1_SET_OF_POLICYINFO(a, pp, length, d2i_POLICYINFO,
349 POLICYINFO_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
350
351}
352
353IMPLEMENT_STACK_OF(POLICYINFO)
354IMPLEMENT_ASN1_SET_OF(POLICYINFO)
355
356int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp)
357{
358 M_ASN1_I2D_vars(a);
359
360 M_ASN1_I2D_len (a->policyid, i2d_ASN1_OBJECT);
361 M_ASN1_I2D_len_SEQUENCE_type(POLICYQUALINFO, a->qualifiers,
362 i2d_POLICYQUALINFO);
363
364 M_ASN1_I2D_seq_total();
365
366 M_ASN1_I2D_put (a->policyid, i2d_ASN1_OBJECT);
367 M_ASN1_I2D_put_SEQUENCE_type(POLICYQUALINFO, a->qualifiers,
368 i2d_POLICYQUALINFO);
369
370 M_ASN1_I2D_finish();
371}
372
373POLICYINFO *POLICYINFO_new(void)
374{
375 POLICYINFO *ret=NULL;
376 ASN1_CTX c;
377 M_ASN1_New_Malloc(ret, POLICYINFO);
378 ret->policyid = NULL;
379 ret->qualifiers = NULL;
380 return (ret);
381 M_ASN1_New_Error(ASN1_F_POLICYINFO_NEW);
382}
383
384POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp,long length)
385{
386 M_ASN1_D2I_vars(a,POLICYINFO *,POLICYINFO_new);
387 M_ASN1_D2I_Init();
388 M_ASN1_D2I_start_sequence();
389 M_ASN1_D2I_get(ret->policyid, d2i_ASN1_OBJECT);
390 if(!M_ASN1_D2I_end_sequence()) {
391 M_ASN1_D2I_get_seq_type (POLICYQUALINFO, ret->qualifiers,
392 d2i_POLICYQUALINFO, POLICYQUALINFO_free);
393 }
394 M_ASN1_D2I_Finish(a, POLICYINFO_free, ASN1_F_D2I_POLICYINFO);
395}
396
397void POLICYINFO_free(POLICYINFO *a)
398{
399 if (a == NULL) return;
400 ASN1_OBJECT_free(a->policyid);
401 sk_POLICYQUALINFO_pop_free(a->qualifiers, POLICYQUALINFO_free);
402 Free (a);
403}
404
405static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
406 int indent)
407{
408 POLICYQUALINFO *qualinfo;
409 int i;
410 for(i = 0; i < sk_POLICYQUALINFO_num(quals); i++) {
411 qualinfo = sk_POLICYQUALINFO_value(quals, i);
412 switch(OBJ_obj2nid(qualinfo->pqualid))
413 {
414 case NID_id_qt_cps:
415 BIO_printf(out, "%*sCPS: %s\n", indent, "",
416 qualinfo->d.cpsuri->data);
417 break;
418
419 case NID_id_qt_unotice:
420 BIO_printf(out, "%*sUser Notice:\n", indent, "");
421 print_notice(out, qualinfo->d.usernotice, indent + 2);
422 break;
423
424 default:
425 BIO_printf(out, "%*sUnknown Qualifier: ",
426 indent + 2, "");
427
428 i2a_ASN1_OBJECT(out, qualinfo->pqualid);
429 BIO_puts(out, "\n");
430 break;
431 }
432 }
433}
434
435static void print_notice(BIO *out, USERNOTICE *notice, int indent)
436{
437 int i;
438 if(notice->noticeref) {
439 NOTICEREF *ref;
440 ref = notice->noticeref;
441 BIO_printf(out, "%*sOrganization: %s\n", indent, "",
442 ref->organization->data);
443 BIO_printf(out, "%*sNumber%s: ", indent, "",
444 (sk_num(ref->noticenos) > 1) ? "s" : "");
445 for(i = 0; i < sk_num(ref->noticenos); i++) {
446 ASN1_INTEGER *num;
447 char *tmp;
448 num = (ASN1_INTEGER *)sk_value(ref->noticenos, i);
449 if(i) BIO_puts(out, ", ");
450 tmp = i2s_ASN1_INTEGER(NULL, num);
451 BIO_puts(out, tmp);
452 Free(tmp);
453 }
454 BIO_puts(out, "\n");
455 }
456 if(notice->exptext)
457 BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
458 notice->exptext->data);
459}
460
461
462
463int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp)
464{
465 M_ASN1_I2D_vars(a);
466
467 M_ASN1_I2D_len (a->pqualid, i2d_ASN1_OBJECT);
468 switch(OBJ_obj2nid(a->pqualid)) {
469 case NID_id_qt_cps:
470 M_ASN1_I2D_len(a->d.cpsuri, i2d_ASN1_IA5STRING);
471 break;
472
473 case NID_id_qt_unotice:
474 M_ASN1_I2D_len(a->d.usernotice, i2d_USERNOTICE);
475 break;
476
477 default:
478 M_ASN1_I2D_len(a->d.other, i2d_ASN1_TYPE);
479 break;
480 }
481
482 M_ASN1_I2D_seq_total();
483
484 M_ASN1_I2D_put (a->pqualid, i2d_ASN1_OBJECT);
485 switch(OBJ_obj2nid(a->pqualid)) {
486 case NID_id_qt_cps:
487 M_ASN1_I2D_put(a->d.cpsuri, i2d_ASN1_IA5STRING);
488 break;
489
490 case NID_id_qt_unotice:
491 M_ASN1_I2D_put(a->d.usernotice, i2d_USERNOTICE);
492 break;
493
494 default:
495 M_ASN1_I2D_put(a->d.other, i2d_ASN1_TYPE);
496 break;
497 }
498
499 M_ASN1_I2D_finish();
500}
501
502POLICYQUALINFO *POLICYQUALINFO_new(void)
503{
504 POLICYQUALINFO *ret=NULL;
505 ASN1_CTX c;
506 M_ASN1_New_Malloc(ret, POLICYQUALINFO);
507 ret->pqualid = NULL;
508 ret->d.other = NULL;
509 return (ret);
510 M_ASN1_New_Error(ASN1_F_POLICYQUALINFO_NEW);
511}
512
513POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp,
514 long length)
515{
516 M_ASN1_D2I_vars(a,POLICYQUALINFO *,POLICYQUALINFO_new);
517 M_ASN1_D2I_Init();
518 M_ASN1_D2I_start_sequence();
519 M_ASN1_D2I_get (ret->pqualid, d2i_ASN1_OBJECT);
520 switch(OBJ_obj2nid(ret->pqualid)) {
521 case NID_id_qt_cps:
522 M_ASN1_D2I_get(ret->d.cpsuri, d2i_ASN1_IA5STRING);
523 break;
524
525 case NID_id_qt_unotice:
526 M_ASN1_D2I_get(ret->d.usernotice, d2i_USERNOTICE);
527 break;
528
529 default:
530 M_ASN1_D2I_get(ret->d.other, d2i_ASN1_TYPE);
531 break;
532 }
533 M_ASN1_D2I_Finish(a, POLICYQUALINFO_free, ASN1_F_D2I_POLICYQUALINFO);
534}
535
536void POLICYQUALINFO_free(POLICYQUALINFO *a)
537{
538 if (a == NULL) return;
539 switch(OBJ_obj2nid(a->pqualid)) {
540 case NID_id_qt_cps:
541 ASN1_IA5STRING_free(a->d.cpsuri);
542 break;
543
544 case NID_id_qt_unotice:
545 USERNOTICE_free(a->d.usernotice);
546 break;
547
548 default:
549 ASN1_TYPE_free(a->d.other);
550 break;
551 }
552
553 ASN1_OBJECT_free(a->pqualid);
554 Free (a);
555}
556
557int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp)
558{
559 M_ASN1_I2D_vars(a);
560
561 M_ASN1_I2D_len (a->noticeref, i2d_NOTICEREF);
562 M_ASN1_I2D_len (a->exptext, i2d_DISPLAYTEXT);
563
564 M_ASN1_I2D_seq_total();
565
566 M_ASN1_I2D_put (a->noticeref, i2d_NOTICEREF);
567 M_ASN1_I2D_put (a->exptext, i2d_DISPLAYTEXT);
568
569 M_ASN1_I2D_finish();
570}
571
572USERNOTICE *USERNOTICE_new(void)
573{
574 USERNOTICE *ret=NULL;
575 ASN1_CTX c;
576 M_ASN1_New_Malloc(ret, USERNOTICE);
577 ret->noticeref = NULL;
578 ret->exptext = NULL;
579 return (ret);
580 M_ASN1_New_Error(ASN1_F_USERNOTICE_NEW);
581}
582
583USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp,long length)
584{
585 M_ASN1_D2I_vars(a,USERNOTICE *,USERNOTICE_new);
586 M_ASN1_D2I_Init();
587 M_ASN1_D2I_start_sequence();
588 M_ASN1_D2I_get_opt(ret->noticeref, d2i_NOTICEREF, V_ASN1_SEQUENCE);
589 if (!M_ASN1_D2I_end_sequence()) {
590 M_ASN1_D2I_get(ret->exptext, d2i_DISPLAYTEXT);
591 }
592 M_ASN1_D2I_Finish(a, USERNOTICE_free, ASN1_F_D2I_USERNOTICE);
593}
594
595void USERNOTICE_free(USERNOTICE *a)
596{
597 if (a == NULL) return;
598 NOTICEREF_free(a->noticeref);
599 DISPLAYTEXT_free(a->exptext);
600 Free (a);
601}
602
603int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp)
604{
605 M_ASN1_I2D_vars(a);
606
607 M_ASN1_I2D_len (a->organization, i2d_DISPLAYTEXT);
608 M_ASN1_I2D_len_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER);
609
610 M_ASN1_I2D_seq_total();
611
612 M_ASN1_I2D_put (a->organization, i2d_DISPLAYTEXT);
613 M_ASN1_I2D_put_SEQUENCE(a->noticenos, i2d_ASN1_INTEGER);
614
615 M_ASN1_I2D_finish();
616}
617
618NOTICEREF *NOTICEREF_new(void)
619{
620 NOTICEREF *ret=NULL;
621 ASN1_CTX c;
622 M_ASN1_New_Malloc(ret, NOTICEREF);
623 ret->organization = NULL;
624 ret->noticenos = NULL;
625 return (ret);
626 M_ASN1_New_Error(ASN1_F_NOTICEREF_NEW);
627}
628
629NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp,long length)
630{
631 M_ASN1_D2I_vars(a,NOTICEREF *,NOTICEREF_new);
632 M_ASN1_D2I_Init();
633 M_ASN1_D2I_start_sequence();
634 /* This is to cope with some broken encodings that use IA5STRING for
635 * the organization field
636 */
637 M_ASN1_D2I_get_opt(ret->organization, d2i_ASN1_IA5STRING,
638 V_ASN1_IA5STRING);
639 if(!ret->organization) {
640 M_ASN1_D2I_get(ret->organization, d2i_DISPLAYTEXT);
641 }
642 M_ASN1_D2I_get_seq(ret->noticenos, d2i_ASN1_INTEGER, ASN1_STRING_free);
643 M_ASN1_D2I_Finish(a, NOTICEREF_free, ASN1_F_D2I_NOTICEREF);
644}
645
646void NOTICEREF_free(NOTICEREF *a)
647{
648 if (a == NULL) return;
649 DISPLAYTEXT_free(a->organization);
650 sk_pop_free(a->noticenos, ASN1_STRING_free);
651 Free (a);
652}
653
654IMPLEMENT_STACK_OF(POLICYQUALINFO)
655IMPLEMENT_ASN1_SET_OF(POLICYQUALINFO)
diff --git a/src/lib/libcrypto/x509v3/v3_crld.c b/src/lib/libcrypto/x509v3/v3_crld.c
new file mode 100644
index 0000000000..897ffb63e4
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_crld.c
@@ -0,0 +1,283 @@
1/* v3_crld.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
67 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *extlist);
68static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
70
71X509V3_EXT_METHOD v3_crld = {
72NID_crl_distribution_points, X509V3_EXT_MULTILINE,
73(X509V3_EXT_NEW)CRL_DIST_POINTS_new,
74(X509V3_EXT_FREE)CRL_DIST_POINTS_free,
75(X509V3_EXT_D2I)d2i_CRL_DIST_POINTS,
76(X509V3_EXT_I2D)i2d_CRL_DIST_POINTS,
77NULL, NULL,
78(X509V3_EXT_I2V)i2v_crld,
79(X509V3_EXT_V2I)v2i_crld,
80NULL, NULL, NULL
81};
82
83static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
84 STACK_OF(DIST_POINT) *crld, STACK_OF(CONF_VALUE) *exts)
85{
86 DIST_POINT *point;
87 int i;
88 for(i = 0; i < sk_DIST_POINT_num(crld); i++) {
89 point = sk_DIST_POINT_value(crld, i);
90 if(point->distpoint->fullname) {
91 exts = i2v_GENERAL_NAMES(NULL,
92 point->distpoint->fullname, exts);
93 }
94 if(point->reasons)
95 X509V3_add_value("reasons","<UNSUPPORTED>", &exts);
96 if(point->CRLissuer)
97 X509V3_add_value("CRLissuer","<UNSUPPORTED>", &exts);
98 if(point->distpoint->relativename)
99 X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts);
100 }
101 return exts;
102}
103
104static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
105 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
106{
107 STACK_OF(DIST_POINT) *crld = NULL;
108 STACK_OF(GENERAL_NAME) *gens = NULL;
109 GENERAL_NAME *gen = NULL;
110 CONF_VALUE *cnf;
111 int i;
112 if(!(crld = sk_DIST_POINT_new(NULL))) goto merr;
113 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
114 DIST_POINT *point;
115 cnf = sk_CONF_VALUE_value(nval, i);
116 if(!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) goto err;
117 if(!(gens = GENERAL_NAMES_new())) goto merr;
118 if(!sk_GENERAL_NAME_push(gens, gen)) goto merr;
119 gen = NULL;
120 if(!(point = DIST_POINT_new())) goto merr;
121 if(!sk_DIST_POINT_push(crld, point)) {
122 DIST_POINT_free(point);
123 goto merr;
124 }
125 if(!(point->distpoint = DIST_POINT_NAME_new())) goto merr;
126 point->distpoint->fullname = gens;
127 gens = NULL;
128 }
129 return crld;
130
131 merr:
132 X509V3err(X509V3_F_V2I_CRLD,ERR_R_MALLOC_FAILURE);
133 err:
134 GENERAL_NAME_free(gen);
135 GENERAL_NAMES_free(gens);
136 sk_DIST_POINT_pop_free(crld, DIST_POINT_free);
137 return NULL;
138}
139
140int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp)
141{
142
143return i2d_ASN1_SET_OF_DIST_POINT(a, pp, i2d_DIST_POINT, V_ASN1_SEQUENCE,
144 V_ASN1_UNIVERSAL, IS_SEQUENCE);}
145
146STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void)
147{
148 return sk_DIST_POINT_new_null();
149}
150
151void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a)
152{
153 sk_DIST_POINT_pop_free(a, DIST_POINT_free);
154}
155
156STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a,
157 unsigned char **pp,long length)
158{
159return d2i_ASN1_SET_OF_DIST_POINT(a, pp, length, d2i_DIST_POINT,
160 DIST_POINT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
161
162}
163
164IMPLEMENT_STACK_OF(DIST_POINT)
165IMPLEMENT_ASN1_SET_OF(DIST_POINT)
166
167int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp)
168{
169 int v = 0;
170 M_ASN1_I2D_vars(a);
171 /* NB: underlying type is a CHOICE so need EXPLICIT tagging */
172 M_ASN1_I2D_len_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v);
173 M_ASN1_I2D_len_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING);
174 M_ASN1_I2D_len_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES);
175
176 M_ASN1_I2D_seq_total();
177
178 M_ASN1_I2D_put_EXP_opt (a->distpoint, i2d_DIST_POINT_NAME, 0, v);
179 M_ASN1_I2D_put_IMP_opt (a->reasons, i2d_ASN1_BIT_STRING, 1);
180 M_ASN1_I2D_put_IMP_opt (a->CRLissuer, i2d_GENERAL_NAMES, 2);
181
182 M_ASN1_I2D_finish();
183}
184
185DIST_POINT *DIST_POINT_new(void)
186{
187 DIST_POINT *ret=NULL;
188 ASN1_CTX c;
189 M_ASN1_New_Malloc(ret, DIST_POINT);
190 ret->distpoint = NULL;
191 ret->reasons = NULL;
192 ret->CRLissuer = NULL;
193 return (ret);
194 M_ASN1_New_Error(ASN1_F_DIST_POINT_NEW);
195}
196
197DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length)
198{
199 M_ASN1_D2I_vars(a,DIST_POINT *,DIST_POINT_new);
200 M_ASN1_D2I_Init();
201 M_ASN1_D2I_start_sequence();
202 M_ASN1_D2I_get_EXP_opt (ret->distpoint, d2i_DIST_POINT_NAME, 0);
203 M_ASN1_D2I_get_IMP_opt (ret->reasons, d2i_ASN1_BIT_STRING, 1,
204 V_ASN1_BIT_STRING);
205 M_ASN1_D2I_get_IMP_opt (ret->CRLissuer, d2i_GENERAL_NAMES, 2,
206 V_ASN1_SEQUENCE);
207 M_ASN1_D2I_Finish(a, DIST_POINT_free, ASN1_F_D2I_DIST_POINT);
208}
209
210void DIST_POINT_free(DIST_POINT *a)
211{
212 if (a == NULL) return;
213 DIST_POINT_NAME_free(a->distpoint);
214 ASN1_BIT_STRING_free(a->reasons);
215 sk_GENERAL_NAME_pop_free(a->CRLissuer, GENERAL_NAME_free);
216 Free ((char *)a);
217}
218
219int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp)
220{
221 int v = 0;
222 M_ASN1_I2D_vars(a);
223
224 if(a->fullname) {
225 M_ASN1_I2D_len_IMP_opt (a->fullname, i2d_GENERAL_NAMES);
226 } else {
227 M_ASN1_I2D_len_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
228 }
229
230 /* Don't want a SEQUENCE so... */
231 if(pp == NULL) return ret;
232 p = *pp;
233
234 if(a->fullname) {
235 M_ASN1_I2D_put_IMP_opt (a->fullname, i2d_GENERAL_NAMES, 0);
236 } else {
237 M_ASN1_I2D_put_EXP_opt (a->relativename, i2d_X509_NAME, 1, v);
238 }
239 M_ASN1_I2D_finish();
240}
241
242DIST_POINT_NAME *DIST_POINT_NAME_new(void)
243{
244 DIST_POINT_NAME *ret=NULL;
245 ASN1_CTX c;
246 M_ASN1_New_Malloc(ret, DIST_POINT_NAME);
247 ret->fullname = NULL;
248 ret->relativename = NULL;
249 return (ret);
250 M_ASN1_New_Error(ASN1_F_DIST_POINT_NAME_NEW);
251}
252
253void DIST_POINT_NAME_free(DIST_POINT_NAME *a)
254{
255 if (a == NULL) return;
256 X509_NAME_free(a->relativename);
257 sk_GENERAL_NAME_pop_free(a->fullname, GENERAL_NAME_free);
258 Free ((char *)a);
259}
260
261DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
262 long length)
263{
264 unsigned char _tmp, tag;
265 M_ASN1_D2I_vars(a,DIST_POINT_NAME *,DIST_POINT_NAME_new);
266 M_ASN1_D2I_Init();
267 c.slen = length;
268
269 _tmp = M_ASN1_next;
270 tag = _tmp & ~V_ASN1_CONSTRUCTED;
271
272 if(tag == (0|V_ASN1_CONTEXT_SPECIFIC)) {
273 M_ASN1_D2I_get_imp(ret->fullname, d2i_GENERAL_NAMES,
274 V_ASN1_SEQUENCE);
275 } else if (tag == (1|V_ASN1_CONTEXT_SPECIFIC)) {
276 M_ASN1_D2I_get_EXP_opt (ret->relativename, d2i_X509_NAME, 1);
277 } else {
278 c.error = ASN1_R_BAD_TAG;
279 goto err;
280 }
281
282 M_ASN1_D2I_Finish(a, DIST_POINT_NAME_free, ASN1_F_D2I_DIST_POINT_NAME);
283}
diff --git a/src/lib/libcrypto/x509v3/v3_enum.c b/src/lib/libcrypto/x509v3/v3_enum.c
new file mode 100644
index 0000000000..db423548ff
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_enum.c
@@ -0,0 +1,103 @@
1/* v3_enum.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63static ASN1_ENUMERATED *asn1_enumerated_new(void);
64
65static ENUMERATED_NAMES crl_reasons[] = {
66{0, "Unspecified", "unspecified"},
67{1, "Key Compromise", "keyCompromise"},
68{2, "CA Compromise", "CACompromise"},
69{3, "Affiliation Changed", "affiliationChanged"},
70{4, "Superseded", "superseded"},
71{5, "Cessation Of Operation", "cessationOfOperation"},
72{6, "Certificate Hold", "certificateHold"},
73{8, "Remove From CRL", "removeFromCRL"},
74{-1, NULL, NULL}
75};
76
77X509V3_EXT_METHOD v3_crl_reason = {
78NID_crl_reason, 0,
79(X509V3_EXT_NEW)asn1_enumerated_new,
80(X509V3_EXT_FREE)ASN1_STRING_free,
81(X509V3_EXT_D2I)d2i_ASN1_ENUMERATED,
82(X509V3_EXT_I2D)i2d_ASN1_ENUMERATED,
83(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
84(X509V3_EXT_S2I)NULL,
85NULL, NULL, NULL, NULL, crl_reasons};
86
87
88static ASN1_ENUMERATED *asn1_enumerated_new(void)
89{
90 return ASN1_ENUMERATED_new();
91}
92
93char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method,
94 ASN1_ENUMERATED *e)
95{
96 ENUMERATED_NAMES *enam;
97 long strval;
98 strval = ASN1_ENUMERATED_get(e);
99 for(enam = method->usr_data; enam->lname; enam++) {
100 if(strval == enam->bitnum) return BUF_strdup(enam->lname);
101 }
102 return i2s_ASN1_ENUMERATED(method, e);
103}
diff --git a/src/lib/libcrypto/x509v3/v3_extku.c b/src/lib/libcrypto/x509v3/v3_extku.c
new file mode 100644
index 0000000000..e039d21cbf
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_extku.c
@@ -0,0 +1,150 @@
1/* v3_extku.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static STACK_OF(ASN1_OBJECT) *v2i_ext_ku(X509V3_EXT_METHOD *method,
67 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
68static STACK_OF(CONF_VALUE) *i2v_ext_ku(X509V3_EXT_METHOD *method,
69 STACK_OF(ASN1_OBJECT) *eku, STACK_OF(CONF_VALUE) *extlist);
70X509V3_EXT_METHOD v3_ext_ku = {
71NID_ext_key_usage, 0,
72(X509V3_EXT_NEW)ext_ku_new,
73(X509V3_EXT_FREE)ext_ku_free,
74(X509V3_EXT_D2I)d2i_ext_ku,
75(X509V3_EXT_I2D)i2d_ext_ku,
76NULL, NULL,
77(X509V3_EXT_I2V)i2v_ext_ku,
78(X509V3_EXT_V2I)v2i_ext_ku,
79NULL,NULL,
80NULL
81};
82
83STACK_OF(ASN1_OBJECT) *ext_ku_new(void)
84{
85 return sk_ASN1_OBJECT_new_null();
86}
87
88void ext_ku_free(STACK_OF(ASN1_OBJECT) *eku)
89{
90 sk_ASN1_OBJECT_pop_free(eku, ASN1_OBJECT_free);
91 return;
92}
93
94int i2d_ext_ku(STACK_OF(ASN1_OBJECT) *a, unsigned char **pp)
95{
96 return i2d_ASN1_SET_OF_ASN1_OBJECT(a, pp, i2d_ASN1_OBJECT,
97 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
98}
99
100STACK_OF(ASN1_OBJECT) *d2i_ext_ku(STACK_OF(ASN1_OBJECT) **a,
101 unsigned char **pp, long length)
102{
103 return d2i_ASN1_SET_OF_ASN1_OBJECT(a, pp, length, d2i_ASN1_OBJECT,
104 ASN1_OBJECT_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
105}
106
107
108
109static STACK_OF(CONF_VALUE) *i2v_ext_ku(X509V3_EXT_METHOD *method,
110 STACK_OF(ASN1_OBJECT) *eku, STACK_OF(CONF_VALUE) *ext_list)
111{
112int i;
113ASN1_OBJECT *obj;
114char obj_tmp[80];
115for(i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
116 obj = sk_ASN1_OBJECT_value(eku, i);
117 i2t_ASN1_OBJECT(obj_tmp, 80, obj);
118 X509V3_add_value(NULL, obj_tmp, &ext_list);
119}
120return ext_list;
121}
122
123static STACK_OF(ASN1_OBJECT) *v2i_ext_ku(X509V3_EXT_METHOD *method,
124 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
125{
126STACK_OF(ASN1_OBJECT) *extku;
127char *extval;
128ASN1_OBJECT *objtmp;
129CONF_VALUE *val;
130int i;
131
132if(!(extku = sk_ASN1_OBJECT_new(NULL))) {
133 X509V3err(X509V3_F_V2I_EXT_KU,ERR_R_MALLOC_FAILURE);
134 return NULL;
135}
136
137for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
138 val = sk_CONF_VALUE_value(nval, i);
139 if(val->value) extval = val->value;
140 else extval = val->name;
141 if(!(objtmp = OBJ_txt2obj(extval, 0))) {
142 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
143 X509V3err(X509V3_F_V2I_EXT_KU,X509V3_R_INVALID_OBJECT_IDENTIFIER);
144 X509V3_conf_err(val);
145 return NULL;
146 }
147 sk_ASN1_OBJECT_push(extku, objtmp);
148}
149return extku;
150}
diff --git a/src/lib/libcrypto/x509v3/v3_genn.c b/src/lib/libcrypto/x509v3/v3_genn.c
new file mode 100644
index 0000000000..af716232f8
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_genn.c
@@ -0,0 +1,237 @@
1/* v3_genn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp)
68{
69 unsigned char *p;
70 int ret;
71
72 ret = 0;
73
74 /* Save the location of initial TAG */
75 if(pp) p = *pp;
76 else p = NULL;
77
78 /* GEN_DNAME needs special treatment because of EXPLICIT tag */
79
80 if(a->type == GEN_DIRNAME) {
81 int v = 0;
82 M_ASN1_I2D_len_EXP_opt(a->d.dirn, i2d_X509_NAME, 4, v);
83 if(!p) return ret;
84 M_ASN1_I2D_put_EXP_opt(a->d.dirn, i2d_X509_NAME, 4, v);
85 *pp = p;
86 return ret;
87 }
88
89 switch(a->type) {
90
91 case GEN_OTHERNAME:
92 case GEN_X400:
93 case GEN_EDIPARTY:
94 ret = i2d_ASN1_TYPE(a->d.other, pp);
95 break;
96
97 case GEN_EMAIL:
98 case GEN_DNS:
99 case GEN_URI:
100 ret = i2d_ASN1_IA5STRING(a->d.ia5, pp);
101 break;
102
103 case GEN_IPADD:
104 ret = i2d_ASN1_OCTET_STRING(a->d.ip, pp);
105 break;
106
107 case GEN_RID:
108 ret = i2d_ASN1_OBJECT(a->d.rid, pp);
109 break;
110 }
111 /* Replace TAG with IMPLICIT value */
112 if(p) *p = (*p & V_ASN1_CONSTRUCTED) | a->type;
113 return ret;
114}
115
116GENERAL_NAME *GENERAL_NAME_new()
117{
118 GENERAL_NAME *ret=NULL;
119 ASN1_CTX c;
120 M_ASN1_New_Malloc(ret, GENERAL_NAME);
121 ret->type = -1;
122 ret->d.ptr = NULL;
123 return (ret);
124 M_ASN1_New_Error(ASN1_F_GENERAL_NAME_NEW);
125}
126
127GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp,
128 long length)
129{
130 unsigned char _tmp;
131 M_ASN1_D2I_vars(a,GENERAL_NAME *,GENERAL_NAME_new);
132 M_ASN1_D2I_Init();
133 c.slen = length;
134
135 _tmp = M_ASN1_next;
136 ret->type = _tmp & ~V_ASN1_CONSTRUCTED;
137
138 switch(ret->type) {
139 /* Just put these in a "blob" for now */
140 case GEN_OTHERNAME:
141 case GEN_X400:
142 case GEN_EDIPARTY:
143 M_ASN1_D2I_get_imp(ret->d.other, d2i_ASN1_TYPE,V_ASN1_SEQUENCE);
144 break;
145
146 case GEN_EMAIL:
147 case GEN_DNS:
148 case GEN_URI:
149 M_ASN1_D2I_get_imp(ret->d.ia5, d2i_ASN1_IA5STRING,
150 V_ASN1_IA5STRING);
151 break;
152
153 case GEN_DIRNAME:
154 M_ASN1_D2I_get_EXP_opt(ret->d.dirn, d2i_X509_NAME, 4);
155 break;
156
157 case GEN_IPADD:
158 M_ASN1_D2I_get_imp(ret->d.ip, d2i_ASN1_OCTET_STRING,
159 V_ASN1_OCTET_STRING);
160 break;
161
162 case GEN_RID:
163 M_ASN1_D2I_get_imp(ret->d.rid, d2i_ASN1_OBJECT,V_ASN1_OBJECT);
164 break;
165
166 default:
167 c.error = ASN1_R_BAD_TAG;
168 goto err;
169 }
170
171 c.slen = 0;
172 M_ASN1_D2I_Finish(a, GENERAL_NAME_free, ASN1_F_D2I_GENERAL_NAME);
173}
174
175void GENERAL_NAME_free(GENERAL_NAME *a)
176{
177 if (a == NULL) return;
178 switch(a->type) {
179 case GEN_OTHERNAME:
180 case GEN_X400:
181 case GEN_EDIPARTY:
182 ASN1_TYPE_free(a->d.other);
183 break;
184
185 case GEN_EMAIL:
186 case GEN_DNS:
187 case GEN_URI:
188
189 ASN1_IA5STRING_free(a->d.ia5);
190 break;
191
192 case GEN_DIRNAME:
193 X509_NAME_free(a->d.dirn);
194 break;
195
196 case GEN_IPADD:
197 ASN1_OCTET_STRING_free(a->d.ip);
198 break;
199
200 case GEN_RID:
201 ASN1_OBJECT_free(a->d.rid);
202 break;
203
204 }
205 Free ((char *)a);
206}
207
208/* Now the GeneralNames versions: a SEQUENCE OF GeneralName These are needed as
209 * an explicit functions.
210 */
211
212STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new()
213{
214 return sk_GENERAL_NAME_new(NULL);
215}
216
217void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a)
218{
219 sk_GENERAL_NAME_pop_free(a, GENERAL_NAME_free);
220}
221
222STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a,
223 unsigned char **pp, long length)
224{
225return d2i_ASN1_SET_OF_GENERAL_NAME(a, pp, length, d2i_GENERAL_NAME,
226 GENERAL_NAME_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
227}
228
229int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp)
230{
231return i2d_ASN1_SET_OF_GENERAL_NAME(a, pp, i2d_GENERAL_NAME, V_ASN1_SEQUENCE,
232 V_ASN1_UNIVERSAL, IS_SEQUENCE);
233}
234
235IMPLEMENT_STACK_OF(GENERAL_NAME)
236IMPLEMENT_ASN1_SET_OF(GENERAL_NAME)
237
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
new file mode 100644
index 0000000000..3446c5cd6a
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_ia5.c
@@ -0,0 +1,116 @@
1/* v3_ia5.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509v3.h>
65
66static ASN1_IA5STRING *ia5string_new(void);
67static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5);
68static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
69X509V3_EXT_METHOD v3_ns_ia5_list[] = {
70EXT_IA5STRING(NID_netscape_base_url),
71EXT_IA5STRING(NID_netscape_revocation_url),
72EXT_IA5STRING(NID_netscape_ca_revocation_url),
73EXT_IA5STRING(NID_netscape_renewal_url),
74EXT_IA5STRING(NID_netscape_ca_policy_url),
75EXT_IA5STRING(NID_netscape_ssl_server_name),
76EXT_IA5STRING(NID_netscape_comment),
77EXT_END
78};
79
80
81static ASN1_IA5STRING *ia5string_new(void)
82{
83 return ASN1_IA5STRING_new();
84}
85
86static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
87 ASN1_IA5STRING *ia5)
88{
89 char *tmp;
90 if(!ia5 || !ia5->length) return NULL;
91 tmp = Malloc(ia5->length + 1);
92 memcpy(tmp, ia5->data, ia5->length);
93 tmp[ia5->length] = 0;
94 return tmp;
95}
96
97static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
98 X509V3_CTX *ctx, char *str)
99{
100 ASN1_IA5STRING *ia5;
101 if(!str) {
102 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,X509V3_R_INVALID_NULL_ARGUMENT);
103 return NULL;
104 }
105 if(!(ia5 = ASN1_IA5STRING_new())) goto err;
106 if(!ASN1_STRING_set((ASN1_STRING *)ia5, (unsigned char*)str,
107 strlen(str))) {
108 ASN1_IA5STRING_free(ia5);
109 goto err;
110 }
111 return ia5;
112 err:
113 X509V3err(X509V3_F_S2I_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
114 return NULL;
115}
116
diff --git a/src/lib/libcrypto/x509v3/v3_int.c b/src/lib/libcrypto/x509v3/v3_int.c
new file mode 100644
index 0000000000..637dd5e128
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_int.c
@@ -0,0 +1,79 @@
1/* v3_int.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/x509v3.h>
62
63static ASN1_INTEGER *asn1_integer_new(void);
64
65X509V3_EXT_METHOD v3_crl_num = {
66NID_crl_number, 0,
67(X509V3_EXT_NEW)asn1_integer_new,
68(X509V3_EXT_FREE)ASN1_STRING_free,
69(X509V3_EXT_D2I)d2i_ASN1_INTEGER,
70(X509V3_EXT_I2D)i2d_ASN1_INTEGER,
71(X509V3_EXT_I2S)i2s_ASN1_INTEGER,
72(X509V3_EXT_S2I)NULL,
73NULL, NULL, NULL, NULL, NULL};
74
75
76static ASN1_INTEGER *asn1_integer_new(void)
77{
78 return ASN1_INTEGER_new();
79}
diff --git a/src/lib/libcrypto/x509v3/v3_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 @@
1/* crypto/x509v3/v3_ku.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <ctype.h>
61#include "stack.h"
62#include "cryptlib.h"
63#include "bio.h"
64#include "asn1.h"
65#include "objects.h"
66#include "x509.h"
67
68X509_EXTENSION_METHOD X509v3_key_usage_method=
69 {
70 NID_key_usage,
71 ku_clear,
72 ex_get_bool,
73 ex_set_bool,
74 NULL,
75 NULL,
76 NULL,
77 NULL,
78 ku_a2i,
79 ku_i2a,
80 };
81
82static void ku_clear(a)
83X509_EXTENSION *a;
84 {
85 }
86
87static int ku_expand(a)
88X509_EXTENSION *a;
89 {
90 ASN1_BIT_STRING *bs;
91
92 if (a->argp == NULL)
93 {
94 bs=X509v3_unpack_string(NULL,V_ASN1_BIT_STRING,value);
95 if (bs == NULL) return(0);
96 a->argp=(char *)bs;
97 a->ex_free=ASN1_STRING_free;
98 }
99 return(1);
100 }
101
102static int ku_get_bool(a,num)
103X509_EXTENSION *a;
104int num;
105 {
106 int ret;
107 ASN1_BIT_STRING *bs;
108
109 if ((a->argp == NULL) && !ku_expand(a))
110 return(-1);
111 bs=(ASN1_BIT_STRING *)a->argp;
112 ret=ASN1_BIT_STRING_get_bit(bs,num);
113 return(ret);
114 }
115
116static int ku_set_bool(a,num,value)
117X509_EXTENSION *a;
118int num;
119int value;
120 {
121 ASN1_BIT_STRING *a;
122
123 if ((a->argp == NULL) && !ku_expand(a))
124 return(0);
125 bs=(ASN1_BIT_STRING *)a->argp;
126 ret=ASN1_BIT_STRING_set_bit(bs,num,value);
127 }
128
129static int ku_a2i(bio,a,buf,len)
130BIO *bio;
131X509_EXTENSION *a;
132char *buf;
133int len;
134 {
135 get token
136 }
137
138static char ku_names[X509v3_N_KU_NUM]={
139 X509v3_S_KU_digitalSignature,
140 X509v3_S_KU_nonRepudiation,
141 X509v3_S_KU_keyEncipherment,
142 X509v3_S_KU_dataEncipherment,
143 X509v3_S_KU_keyAgreement,
144 X509v3_S_KU_keyCertSign,
145 X509v3_S_KU_cRLSign,
146 X509v3_S_KU_encipherOnly,
147 X509v3_S_KU_decipherOnly,
148 };
149
150static int ku_i2a(bio,a);
151BIO *bio;
152X509_EXTENSION *a;
153 {
154 int i,first=1;
155 char *c;
156
157 for (i=0; i<X509v3_N_KU_NUM; i++)
158 {
159 if (ku_get_bool(a,i) > 0)
160 {
161 BIO_printf(bio,"%s%s",((first)?"":" "),ku_names[i]);
162 first=0;
163 }
164 }
165 }
166
167/***********************/
168
169int X509v3_get_key_usage(x,ret)
170STACK *x;
171unsigned long *ret;
172 {
173 X509_EXTENSION *ext;
174 ASN1_STRING *st;
175 char *p;
176 int i;
177
178 i=X509_get_ext_by_NID(x,NID_key_usage,-1);
179 if (i < 0) return(X509v3_KU_UNDEF);
180 ext=X509_get_ext(x,i);
181 st=X509v3_unpack_string(NULL,V_ASN1_BIT_STRING,
182 X509_EXTENSION_get_data(X509_get_ext(x,i)));
183
184 p=ASN1_STRING_data(st);
185 if (ASN1_STRING_length(st) == 1)
186 i=p[0];
187 else if (ASN1_STRING_length(st) == 2)
188 i=p[0]|(p[1]<<8);
189 else
190 i=0;
191 return(i);
192 }
193
194static struct
195 {
196 char *name;
197 unsigned int value;
198 } key_usage_data[] ={
199 {"digitalSignature", X509v3_KU_DIGITAL_SIGNATURE},
200 {"nonRepudiation", X509v3_KU_NON_REPUDIATION},
201 {"keyEncipherment", X509v3_KU_KEY_ENCIPHERMENT},
202 {"dataEncipherment", X509v3_KU_DATA_ENCIPHERMENT},
203 {"keyAgreement", X509v3_KU_KEY_AGREEMENT},
204 {"keyCertSign", X509v3_KU_KEY_CERT_SIGN},
205 {"cRLSign", X509v3_KU_CRL_SIGN},
206 {"encipherOnly", X509v3_KU_ENCIPHER_ONLY},
207 {"decipherOnly", X509v3_KU_DECIPHER_ONLY},
208 {NULL,0},
209 };
210
211#if 0
212static int a2i_key_usage(x,str,len)
213X509 *x;
214char *str;
215int len;
216 {
217 return(X509v3_set_key_usage(x,a2i_X509v3_key_usage(str)));
218 }
219
220static int i2a_key_usage(bp,x)
221BIO *bp;
222X509 *x;
223 {
224 return(i2a_X509v3_key_usage(bp,X509v3_get_key_usage(x)));
225 }
226#endif
227
228int i2a_X509v3_key_usage(bp,use)
229BIO *bp;
230unsigned int use;
231 {
232 int i=0,first=1;
233
234 for (;;)
235 {
236 if (use | key_usage_data[i].value)
237 {
238 BIO_printf(bp,"%s%s",((first)?"":" "),
239 key_usage_data[i].name);
240 first=0;
241 }
242 }
243 return(1);
244 }
245
246unsigned int a2i_X509v3_key_usage(p)
247char *p;
248 {
249 unsigned int ret=0;
250 char *q,*s;
251 int i,n;
252
253 q=p;
254 for (;;)
255 {
256 while ((*q != '\0') && isalnum(*q))
257 q++;
258 if (*q == '\0') break;
259 s=q++;
260 while (isalnum(*q))
261 q++;
262 n=q-s;
263 i=0;
264 for (;;)
265 {
266 if (strncmp(key_usage_data[i].name,s,n) == 0)
267 {
268 ret|=key_usage_data[i].value;
269 break;
270 }
271 i++;
272 if (key_usage_data[i].name == NULL)
273 return(X509v3_KU_UNDEF);
274 }
275 }
276 return(ret);
277 }
278
279int X509v3_set_key_usage(x,use)
280X509 *x;
281unsigned int use;
282 {
283 ASN1_OCTET_STRING *os;
284 X509_EXTENSION *ext;
285 int i;
286 unsigned char data[4];
287
288 i=X509_get_ext_by_NID(x,NID_key_usage,-1);
289 if (i < 0)
290 {
291 i=X509_get_ext_count(x)+1;
292 if ((ext=X509_EXTENSION_new()) == NULL) return(0);
293 if (!X509_add_ext(x,ext,i))
294 {
295 X509_EXTENSION_free(ext);
296 return(0);
297 }
298 }
299 else
300 ext=X509_get_ext(x,i);
301
302 /* fill in 'ext' */
303 os=X509_EXTENSION_get_data(ext);
304
305 i=0;
306 if (use > 0)
307 {
308 i=1;
309 data[0]=use&0xff;
310 }
311 if (use > 0xff)
312 {
313 i=2;
314 data[1]=(use>>8)&0xff;
315 }
316 return((X509v3_pack_string(&os,V_ASN1_BIT_STRING,data,i) == NULL)?0:1);
317 }
318
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 @@
1/* v3_lib.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/x509v3.h>
64
65static STACK *ext_list = NULL;
66
67static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b);
68static void ext_list_free(X509V3_EXT_METHOD *ext);
69
70int X509V3_EXT_add(X509V3_EXT_METHOD *ext)
71{
72 if(!ext_list && !(ext_list = sk_new(ext_cmp))) {
73 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
74 return 0;
75 }
76 if(!sk_push(ext_list, (char *)ext)) {
77 X509V3err(X509V3_F_X509V3_EXT_ADD,ERR_R_MALLOC_FAILURE);
78 return 0;
79 }
80 return 1;
81}
82
83static int ext_cmp(X509V3_EXT_METHOD **a, X509V3_EXT_METHOD **b)
84{
85 return ((*a)->ext_nid - (*b)->ext_nid);
86}
87
88X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid)
89{
90 X509V3_EXT_METHOD tmp;
91 int idx;
92 tmp.ext_nid = nid;
93 if(!ext_list || (tmp.ext_nid < 0) ) return NULL;
94 idx = sk_find(ext_list, (char *)&tmp);
95 if(idx == -1) return NULL;
96 return (X509V3_EXT_METHOD *)sk_value(ext_list, idx);
97}
98
99X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext)
100{
101 int nid;
102 if((nid = OBJ_obj2nid(ext->object)) == NID_undef) return NULL;
103 return X509V3_EXT_get_nid(nid);
104}
105
106
107int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist)
108{
109 for(;extlist->ext_nid!=-1;extlist++)
110 if(!X509V3_EXT_add(extlist)) return 0;
111 return 1;
112}
113
114int X509V3_EXT_add_alias(int nid_to, int nid_from)
115{
116 X509V3_EXT_METHOD *ext, *tmpext;
117 if(!(ext = X509V3_EXT_get_nid(nid_from))) {
118 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
119 return 0;
120 }
121 if(!(tmpext = (X509V3_EXT_METHOD *)Malloc(sizeof(X509V3_EXT_METHOD)))) {
122 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE);
123 return 0;
124 }
125 *tmpext = *ext;
126 tmpext->ext_nid = nid_to;
127 tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
128 return 1;
129}
130
131void X509V3_EXT_cleanup(void)
132{
133 sk_pop_free(ext_list, ext_list_free);
134 ext_list = NULL;
135}
136
137static void ext_list_free(X509V3_EXT_METHOD *ext)
138{
139 if(ext->ext_flags & X509V3_EXT_DYNAMIC) Free(ext);
140}
141
142extern X509V3_EXT_METHOD v3_bcons, v3_nscert, v3_key_usage, v3_ext_ku;
143extern X509V3_EXT_METHOD v3_pkey_usage_period, v3_sxnet;
144extern X509V3_EXT_METHOD v3_ns_ia5_list[], v3_alt[], v3_skey_id, v3_akey_id;
145
146extern X509V3_EXT_METHOD v3_crl_num, v3_crl_reason, v3_cpols, v3_crld;
147
148int X509V3_add_standard_extensions(void)
149{
150 X509V3_EXT_add_list(v3_ns_ia5_list);
151 X509V3_EXT_add_list(v3_alt);
152 X509V3_EXT_add(&v3_bcons);
153 X509V3_EXT_add(&v3_nscert);
154 X509V3_EXT_add(&v3_key_usage);
155 X509V3_EXT_add(&v3_ext_ku);
156 X509V3_EXT_add(&v3_skey_id);
157 X509V3_EXT_add(&v3_akey_id);
158 X509V3_EXT_add(&v3_pkey_usage_period);
159 X509V3_EXT_add(&v3_crl_num);
160 X509V3_EXT_add(&v3_sxnet);
161 X509V3_EXT_add(&v3_crl_reason);
162 X509V3_EXT_add(&v3_cpols);
163 X509V3_EXT_add(&v3_crld);
164 return 1;
165}
166
167/* Return an extension internal structure */
168
169void *X509V3_EXT_d2i(X509_EXTENSION *ext)
170{
171 X509V3_EXT_METHOD *method;
172 unsigned char *p;
173 if(!(method = X509V3_EXT_get(ext)) || !method->d2i) return NULL;
174 p = ext->value->data;
175 return method->d2i(NULL, &p, ext->value->length);
176}
177
diff --git a/src/lib/libcrypto/x509v3/v3_pku.c b/src/lib/libcrypto/x509v3/v3_pku.c
new file mode 100644
index 0000000000..c13e7d8f45
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_pku.c
@@ -0,0 +1,151 @@
1/* v3_pku.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1.h>
62#include <openssl/asn1_mac.h>
63#include <openssl/x509v3.h>
64
65static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, PKEY_USAGE_PERIOD *usage, BIO *out, int indent);
66/*
67static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
68*/
69X509V3_EXT_METHOD v3_pkey_usage_period = {
70NID_private_key_usage_period, 0,
71(X509V3_EXT_NEW)PKEY_USAGE_PERIOD_new,
72(X509V3_EXT_FREE)PKEY_USAGE_PERIOD_free,
73(X509V3_EXT_D2I)d2i_PKEY_USAGE_PERIOD,
74(X509V3_EXT_I2D)i2d_PKEY_USAGE_PERIOD,
75NULL, NULL, NULL, NULL,
76(X509V3_EXT_I2R)i2r_PKEY_USAGE_PERIOD, NULL,
77NULL
78};
79
80int i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **pp)
81{
82 M_ASN1_I2D_vars(a);
83
84 M_ASN1_I2D_len_IMP_opt (a->notBefore, i2d_ASN1_GENERALIZEDTIME);
85 M_ASN1_I2D_len_IMP_opt (a->notAfter, i2d_ASN1_GENERALIZEDTIME);
86
87 M_ASN1_I2D_seq_total();
88
89 M_ASN1_I2D_put_IMP_opt (a->notBefore, i2d_ASN1_GENERALIZEDTIME, 0);
90 M_ASN1_I2D_put_IMP_opt (a->notAfter, i2d_ASN1_GENERALIZEDTIME, 1);
91
92 M_ASN1_I2D_finish();
93}
94
95PKEY_USAGE_PERIOD *PKEY_USAGE_PERIOD_new(void)
96{
97 PKEY_USAGE_PERIOD *ret=NULL;
98 ASN1_CTX c;
99 M_ASN1_New_Malloc(ret, PKEY_USAGE_PERIOD);
100 ret->notBefore = NULL;
101 ret->notAfter = NULL;
102 return (ret);
103 M_ASN1_New_Error(ASN1_F_PKEY_USAGE_PERIOD_NEW);
104}
105
106PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a,
107 unsigned char **pp, long length)
108{
109 M_ASN1_D2I_vars(a,PKEY_USAGE_PERIOD *,PKEY_USAGE_PERIOD_new);
110 M_ASN1_D2I_Init();
111 M_ASN1_D2I_start_sequence();
112 M_ASN1_D2I_get_IMP_opt (ret->notBefore, d2i_ASN1_GENERALIZEDTIME, 0,
113 V_ASN1_GENERALIZEDTIME);
114 M_ASN1_D2I_get_IMP_opt (ret->notAfter, d2i_ASN1_GENERALIZEDTIME, 1,
115 V_ASN1_GENERALIZEDTIME);
116 M_ASN1_D2I_Finish(a, PKEY_USAGE_PERIOD_free, ASN1_F_D2I_PKEY_USAGE_PERIOD);
117}
118
119void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a)
120{
121 if (a == NULL) return;
122 ASN1_GENERALIZEDTIME_free(a->notBefore);
123 ASN1_GENERALIZEDTIME_free(a->notAfter);
124 Free ((char *)a);
125}
126
127static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method,
128 PKEY_USAGE_PERIOD *usage, BIO *out, int indent)
129{
130 BIO_printf(out, "%*s", indent, "");
131 if(usage->notBefore) {
132 BIO_write(out, "Not Before: ", 12);
133 ASN1_GENERALIZEDTIME_print(out, usage->notBefore);
134 if(usage->notAfter) BIO_write(out, ", ", 2);
135 }
136 if(usage->notAfter) {
137 BIO_write(out, "Not After: ", 11);
138 ASN1_GENERALIZEDTIME_print(out, usage->notAfter);
139 }
140 return 1;
141}
142
143/*
144static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(method, ctx, values)
145X509V3_EXT_METHOD *method;
146X509V3_CTX *ctx;
147STACK_OF(CONF_VALUE) *values;
148{
149return NULL;
150}
151*/
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c
new file mode 100644
index 0000000000..dc20c6bdba
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_prn.c
@@ -0,0 +1,135 @@
1/* v3_prn.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/conf.h>
63#include <openssl/x509v3.h>
64
65/* Extension printing routines */
66
67/* Print out a name+value stack */
68
69void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml)
70{
71 int i;
72 CONF_VALUE *nval;
73 if(!val) return;
74 if(!ml || !sk_CONF_VALUE_num(val)) {
75 BIO_printf(out, "%*s", indent, "");
76 if(!sk_CONF_VALUE_num(val)) BIO_puts(out, "<EMPTY>\n");
77 }
78 for(i = 0; i < sk_CONF_VALUE_num(val); i++) {
79 if(ml) BIO_printf(out, "%*s", indent, "");
80 else if(i > 0) BIO_printf(out, ", ");
81 nval = sk_CONF_VALUE_value(val, i);
82 if(!nval->name) BIO_puts(out, nval->value);
83 else if(!nval->value) BIO_puts(out, nval->name);
84 else BIO_printf(out, "%s:%s", nval->name, nval->value);
85 if(ml) BIO_puts(out, "\n");
86 }
87}
88
89/* Main routine: print out a general extension */
90
91int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent)
92{
93 char *ext_str = NULL, *value = NULL;
94 unsigned char *p;
95 X509V3_EXT_METHOD *method;
96 STACK_OF(CONF_VALUE) *nval = NULL;
97 int ok = 1;
98 if(!(method = X509V3_EXT_get(ext))) return 0;
99 p = ext->value->data;
100 if(!(ext_str = method->d2i(NULL, &p, ext->value->length))) return 0;
101 if(method->i2s) {
102 if(!(value = method->i2s(method, ext_str))) {
103 ok = 0;
104 goto err;
105 }
106 BIO_printf(out, "%*s%s", indent, "", value);
107 } else if(method->i2v) {
108 if(!(nval = method->i2v(method, ext_str, NULL))) {
109 ok = 0;
110 goto err;
111 }
112 X509V3_EXT_val_prn(out, nval, indent,
113 method->ext_flags & X509V3_EXT_MULTILINE);
114 } else if(method->i2r) {
115 if(!method->i2r(method, ext_str, out, indent)) ok = 0;
116 } else ok = 0;
117
118 err:
119 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
120 if(value) Free(value);
121 method->ext_free(ext_str);
122 return ok;
123}
124
125#ifndef NO_FP_API
126int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent)
127{
128 BIO *bio_tmp;
129 int ret;
130 if(!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) return 0;
131 ret = X509V3_EXT_print(bio_tmp, ext, flag, indent);
132 BIO_free(bio_tmp);
133 return ret;
134}
135#endif
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c
new file mode 100644
index 0000000000..fb3e36014d
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_skey.c
@@ -0,0 +1,156 @@
1/* v3_skey.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/x509v3.h>
63
64static ASN1_OCTET_STRING *octet_string_new(void);
65static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
66X509V3_EXT_METHOD v3_skey_id = {
67NID_subject_key_identifier, 0,
68(X509V3_EXT_NEW)octet_string_new,
69(X509V3_EXT_FREE)ASN1_STRING_free,
70(X509V3_EXT_D2I)d2i_ASN1_OCTET_STRING,
71(X509V3_EXT_I2D)i2d_ASN1_OCTET_STRING,
72(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING,
73(X509V3_EXT_S2I)s2i_skey_id,
74NULL, NULL, NULL, NULL, NULL};
75
76
77static ASN1_OCTET_STRING *octet_string_new(void)
78{
79 return ASN1_OCTET_STRING_new();
80}
81
82char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
83 ASN1_OCTET_STRING *oct)
84{
85 return hex_to_string(oct->data, oct->length);
86}
87
88ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
89 X509V3_CTX *ctx, char *str)
90{
91 ASN1_OCTET_STRING *oct;
92 long length;
93
94 if(!(oct = ASN1_OCTET_STRING_new())) {
95 X509V3err(X509V3_F_S2I_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
96 return NULL;
97 }
98
99 if(!(oct->data = string_to_hex(str, &length))) {
100 ASN1_OCTET_STRING_free(oct);
101 return NULL;
102 }
103
104 oct->length = length;
105
106 return oct;
107
108}
109
110static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
111 X509V3_CTX *ctx, char *str)
112{
113 ASN1_OCTET_STRING *oct;
114 ASN1_BIT_STRING *pk;
115 unsigned char pkey_dig[EVP_MAX_MD_SIZE];
116 EVP_MD_CTX md;
117 unsigned int diglen;
118
119 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str);
120
121 if(!(oct = ASN1_OCTET_STRING_new())) {
122 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
123 return NULL;
124 }
125
126 if(ctx && (ctx->flags == CTX_TEST)) return oct;
127
128 if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
129 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
130 goto err;
131 }
132
133 if(ctx->subject_req)
134 pk = ctx->subject_req->req_info->pubkey->public_key;
135 else pk = ctx->subject_cert->cert_info->key->public_key;
136
137 if(!pk) {
138 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
139 goto err;
140 }
141
142 EVP_DigestInit(&md, EVP_sha1());
143 EVP_DigestUpdate(&md, pk->data, pk->length);
144 EVP_DigestFinal(&md, pkey_dig, &diglen);
145
146 if(!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
147 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
148 goto err;
149 }
150
151 return oct;
152
153 err:
154 ASN1_OCTET_STRING_free(oct);
155 return NULL;
156}
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
new file mode 100644
index 0000000000..0687bb4e3d
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_sxnet.c
@@ -0,0 +1,340 @@
1/* v3_sxnet.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/conf.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/x509v3.h>
65
66/* Support for Thawte strong extranet extension */
67
68#define SXNET_TEST
69
70static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent);
71#ifdef SXNET_TEST
72static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *nval);
74#endif
75X509V3_EXT_METHOD v3_sxnet = {
76NID_sxnet, X509V3_EXT_MULTILINE,
77(X509V3_EXT_NEW)SXNET_new,
78(X509V3_EXT_FREE)SXNET_free,
79(X509V3_EXT_D2I)d2i_SXNET,
80(X509V3_EXT_I2D)i2d_SXNET,
81NULL, NULL,
82NULL,
83#ifdef SXNET_TEST
84(X509V3_EXT_V2I)sxnet_v2i,
85#else
86NULL,
87#endif
88(X509V3_EXT_I2R)sxnet_i2r,
89NULL,
90NULL
91};
92
93
94int i2d_SXNET(SXNET *a, unsigned char **pp)
95{
96 M_ASN1_I2D_vars(a);
97
98 M_ASN1_I2D_len (a->version, i2d_ASN1_INTEGER);
99 M_ASN1_I2D_len_SEQUENCE_type (SXNETID, a->ids, i2d_SXNETID);
100
101 M_ASN1_I2D_seq_total();
102
103 M_ASN1_I2D_put (a->version, i2d_ASN1_INTEGER);
104 M_ASN1_I2D_put_SEQUENCE_type (SXNETID, a->ids, i2d_SXNETID);
105
106 M_ASN1_I2D_finish();
107}
108
109SXNET *SXNET_new(void)
110{
111 SXNET *ret=NULL;
112 ASN1_CTX c;
113 M_ASN1_New_Malloc(ret, SXNET);
114 M_ASN1_New(ret->version,ASN1_INTEGER_new);
115 M_ASN1_New(ret->ids,sk_SXNETID_new_null);
116 return (ret);
117 M_ASN1_New_Error(ASN1_F_SXNET_NEW);
118}
119
120SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length)
121{
122 M_ASN1_D2I_vars(a,SXNET *,SXNET_new);
123 M_ASN1_D2I_Init();
124 M_ASN1_D2I_start_sequence();
125 M_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);
126 M_ASN1_D2I_get_seq_type (SXNETID, ret->ids, d2i_SXNETID, SXNETID_free);
127 M_ASN1_D2I_Finish(a, SXNET_free, ASN1_F_D2I_SXNET);
128}
129
130void SXNET_free(SXNET *a)
131{
132 if (a == NULL) return;
133 ASN1_INTEGER_free(a->version);
134 sk_SXNETID_pop_free(a->ids, SXNETID_free);
135 Free (a);
136}
137
138int i2d_SXNETID(SXNETID *a, unsigned char **pp)
139{
140 M_ASN1_I2D_vars(a);
141
142 M_ASN1_I2D_len (a->zone, i2d_ASN1_INTEGER);
143 M_ASN1_I2D_len (a->user, i2d_ASN1_OCTET_STRING);
144
145 M_ASN1_I2D_seq_total();
146
147 M_ASN1_I2D_put (a->zone, i2d_ASN1_INTEGER);
148 M_ASN1_I2D_put (a->user, i2d_ASN1_OCTET_STRING);
149
150 M_ASN1_I2D_finish();
151}
152
153SXNETID *SXNETID_new(void)
154{
155 SXNETID *ret=NULL;
156 ASN1_CTX c;
157 M_ASN1_New_Malloc(ret, SXNETID);
158 ret->zone = NULL;
159 M_ASN1_New(ret->user,ASN1_OCTET_STRING_new);
160 return (ret);
161 M_ASN1_New_Error(ASN1_F_SXNETID_NEW);
162}
163
164SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length)
165{
166 M_ASN1_D2I_vars(a,SXNETID *,SXNETID_new);
167 M_ASN1_D2I_Init();
168 M_ASN1_D2I_start_sequence();
169 M_ASN1_D2I_get(ret->zone, d2i_ASN1_INTEGER);
170 M_ASN1_D2I_get(ret->user, d2i_ASN1_OCTET_STRING);
171 M_ASN1_D2I_Finish(a, SXNETID_free, ASN1_F_D2I_SXNETID);
172}
173
174void SXNETID_free(SXNETID *a)
175{
176 if (a == NULL) return;
177 ASN1_INTEGER_free(a->zone);
178 ASN1_OCTET_STRING_free(a->user);
179 Free (a);
180}
181
182static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
183 int indent)
184{
185 long v;
186 char *tmp;
187 SXNETID *id;
188 int i;
189 v = ASN1_INTEGER_get(sx->version);
190 BIO_printf(out, "%*sVersion: %d (0x%X)", indent, "", v + 1, v);
191 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
192 id = sk_SXNETID_value(sx->ids, i);
193 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
194 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
195 Free(tmp);
196 ASN1_OCTET_STRING_print(out, id->user);
197 }
198 return 1;
199}
200
201#ifdef SXNET_TEST
202
203/* NBB: this is used for testing only. It should *not* be used for anything
204 * else because it will just take static IDs from the configuration file and
205 * they should really be separate values for each user.
206 */
207
208
209static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
210 STACK_OF(CONF_VALUE) *nval)
211{
212 CONF_VALUE *cnf;
213 SXNET *sx = NULL;
214 int i;
215 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
216 cnf = sk_CONF_VALUE_value(nval, i);
217 if(!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1))
218 return NULL;
219 }
220 return sx;
221}
222
223
224#endif
225
226/* Strong Extranet utility functions */
227
228/* Add an id given the zone as an ASCII number */
229
230int SXNET_add_id_asc(SXNET **psx, char *zone, char *user,
231 int userlen)
232{
233 ASN1_INTEGER *izone = NULL;
234 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
235 X509V3err(X509V3_F_SXNET_ADD_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
236 return 0;
237 }
238 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
239}
240
241/* Add an id given the zone as an unsigned long */
242
243int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
244 int userlen)
245{
246 ASN1_INTEGER *izone = NULL;
247 if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
248 X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
249 ASN1_INTEGER_free(izone);
250 return 0;
251 }
252 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
253
254}
255
256/* Add an id given the zone as an ASN1_INTEGER.
257 * Note this version uses the passed integer and doesn't make a copy so don't
258 * free it up afterwards.
259 */
260
261int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
262 int userlen)
263{
264 SXNET *sx = NULL;
265 SXNETID *id = NULL;
266 if(!psx || !zone || !user) {
267 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT);
268 return 0;
269 }
270 if(userlen == -1) userlen = strlen(user);
271 if(userlen > 64) {
272 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG);
273 return 0;
274 }
275 if(!*psx) {
276 if(!(sx = SXNET_new())) goto err;
277 if(!ASN1_INTEGER_set(sx->version, 0)) goto err;
278 *psx = sx;
279 } else sx = *psx;
280 if(SXNET_get_id_INTEGER(sx, zone)) {
281 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID);
282 return 0;
283 }
284
285 if(!(id = SXNETID_new())) goto err;
286 if(userlen == -1) userlen = strlen(user);
287
288 if(!ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err;
289 if(!sk_SXNETID_push(sx->ids, id)) goto err;
290 id->zone = zone;
291 return 1;
292
293 err:
294 X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE);
295 SXNETID_free(id);
296 SXNET_free(sx);
297 *psx = NULL;
298 return 0;
299}
300
301ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone)
302{
303 ASN1_INTEGER *izone = NULL;
304 ASN1_OCTET_STRING *oct;
305 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
306 X509V3err(X509V3_F_SXNET_GET_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
307 return NULL;
308 }
309 oct = SXNET_get_id_INTEGER(sx, izone);
310 ASN1_INTEGER_free(izone);
311 return oct;
312}
313
314ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
315{
316 ASN1_INTEGER *izone = NULL;
317 ASN1_OCTET_STRING *oct;
318 if(!(izone = ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
319 X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE);
320 ASN1_INTEGER_free(izone);
321 return NULL;
322 }
323 oct = SXNET_get_id_INTEGER(sx, izone);
324 ASN1_INTEGER_free(izone);
325 return oct;
326}
327
328ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone)
329{
330 SXNETID *id;
331 int i;
332 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
333 id = sk_SXNETID_value(sx->ids, i);
334 if(!ASN1_INTEGER_cmp(id->zone, zone)) return id->user;
335 }
336 return NULL;
337}
338
339IMPLEMENT_STACK_OF(SXNETID)
340IMPLEMENT_ASN1_SET_OF(SXNETID)
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
new file mode 100644
index 0000000000..40f71c71b4
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_utl.c
@@ -0,0 +1,418 @@
1/* v3_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* X509 v3 extension utilities */
59
60
61#include <stdio.h>
62#include <ctype.h>
63#include "cryptlib.h"
64#include <openssl/conf.h>
65#include <openssl/x509v3.h>
66
67static char *strip_spaces(char *name);
68
69/* Add a CONF_VALUE name value pair to stack */
70
71int X509V3_add_value(const char *name, const char *value,
72 STACK_OF(CONF_VALUE) **extlist)
73{
74 CONF_VALUE *vtmp = NULL;
75 char *tname = NULL, *tvalue = NULL;
76 if(name && !(tname = BUF_strdup(name))) goto err;
77 if(value && !(tvalue = BUF_strdup(value))) goto err;;
78 if(!(vtmp = (CONF_VALUE *)Malloc(sizeof(CONF_VALUE)))) goto err;
79 if(!*extlist && !(*extlist = sk_CONF_VALUE_new(NULL))) goto err;
80 vtmp->section = NULL;
81 vtmp->name = tname;
82 vtmp->value = tvalue;
83 if(!sk_CONF_VALUE_push(*extlist, vtmp)) goto err;
84 return 1;
85 err:
86 X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE);
87 if(vtmp) Free(vtmp);
88 if(tname) Free(tname);
89 if(tvalue) Free(tvalue);
90 return 0;
91}
92
93int X509V3_add_value_uchar(const char *name, const unsigned char *value,
94 STACK_OF(CONF_VALUE) **extlist)
95 {
96 return X509V3_add_value(name,(const char *)value,extlist);
97 }
98
99/* Free function for STACK_OF(CONF_VALUE) */
100
101void X509V3_conf_free(CONF_VALUE *conf)
102{
103 if(!conf) return;
104 if(conf->name) Free(conf->name);
105 if(conf->value) Free(conf->value);
106 if(conf->section) Free(conf->section);
107 Free((char *)conf);
108}
109
110int X509V3_add_value_bool(const char *name, int asn1_bool,
111 STACK_OF(CONF_VALUE) **extlist)
112{
113 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
114 return X509V3_add_value(name, "FALSE", extlist);
115}
116
117int X509V3_add_value_bool_nf(char *name, int asn1_bool,
118 STACK_OF(CONF_VALUE) **extlist)
119{
120 if(asn1_bool) return X509V3_add_value(name, "TRUE", extlist);
121 return 1;
122}
123
124
125char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *a)
126{
127 BIGNUM *bntmp = NULL;
128 char *strtmp = NULL;
129 if(!a) return NULL;
130 if(!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) ||
131 !(strtmp = BN_bn2dec(bntmp)) )
132 X509V3err(X509V3_F_I2S_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
133 BN_free(bntmp);
134 return strtmp;
135}
136
137char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *method, ASN1_INTEGER *a)
138{
139 BIGNUM *bntmp = NULL;
140 char *strtmp = NULL;
141 if(!a) return NULL;
142 if(!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||
143 !(strtmp = BN_bn2dec(bntmp)) )
144 X509V3err(X509V3_F_I2S_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
145 BN_free(bntmp);
146 return strtmp;
147}
148
149ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
150{
151 BIGNUM *bn = NULL;
152 ASN1_INTEGER *aint;
153 bn = BN_new();
154 if(!value) {
155 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE);
156 return 0;
157 }
158 if(!BN_dec2bn(&bn, value)) {
159 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR);
160 return 0;
161 }
162
163 if(!(aint = BN_to_ASN1_INTEGER(bn, NULL))) {
164 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_TO_ASN1_INTEGER_ERROR);
165 return 0;
166 }
167 BN_free(bn);
168 return aint;
169}
170
171int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
172 STACK_OF(CONF_VALUE) **extlist)
173{
174 char *strtmp;
175 int ret;
176 if(!aint) return 1;
177 if(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0;
178 ret = X509V3_add_value(name, strtmp, extlist);
179 Free(strtmp);
180 return ret;
181}
182
183int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool)
184{
185 char *btmp;
186 if(!(btmp = value->value)) goto err;
187 if(!strcmp(btmp, "TRUE") || !strcmp(btmp, "true")
188 || !strcmp(btmp, "Y") || !strcmp(btmp, "y")
189 || !strcmp(btmp, "YES") || !strcmp(btmp, "yes")) {
190 *asn1_bool = 0xff;
191 return 1;
192 } else if(!strcmp(btmp, "FALSE") || !strcmp(btmp, "false")
193 || !strcmp(btmp, "N") || !strcmp(btmp, "n")
194 || !strcmp(btmp, "NO") || !strcmp(btmp, "no")) {
195 *asn1_bool = 0;
196 return 1;
197 }
198 err:
199 X509V3err(X509V3_F_X509V3_GET_VALUE_BOOL,X509V3_R_INVALID_BOOLEAN_STRING);
200 X509V3_conf_err(value);
201 return 0;
202}
203
204int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint)
205{
206 ASN1_INTEGER *itmp;
207 if(!(itmp = s2i_ASN1_INTEGER(NULL, value->value))) {
208 X509V3_conf_err(value);
209 return 0;
210 }
211 *aint = itmp;
212 return 1;
213}
214
215#define HDR_NAME 1
216#define HDR_VALUE 2
217
218/*#define DEBUG*/
219
220STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line)
221{
222 char *p, *q, c;
223 char *ntmp, *vtmp;
224 STACK_OF(CONF_VALUE) *values = NULL;
225 char *linebuf;
226 int state;
227 /* We are going to modify the line so copy it first */
228 linebuf = BUF_strdup(line);
229 state = HDR_NAME;
230 ntmp = NULL;
231 /* Go through all characters */
232 for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) {
233
234 switch(state) {
235 case HDR_NAME:
236 if(c == ':') {
237 state = HDR_VALUE;
238 *p = 0;
239 ntmp = strip_spaces(q);
240 if(!ntmp) {
241 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
242 goto err;
243 }
244 q = p + 1;
245 } else if(c == ',') {
246 *p = 0;
247 ntmp = strip_spaces(q);
248 q = p + 1;
249#ifdef DEBUG
250 printf("%s\n", ntmp);
251#endif
252 if(!ntmp) {
253 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
254 goto err;
255 }
256 X509V3_add_value(ntmp, NULL, &values);
257 }
258 break ;
259
260 case HDR_VALUE:
261 if(c == ',') {
262 state = HDR_NAME;
263 *p = 0;
264 vtmp = strip_spaces(q);
265#ifdef DEBUG
266 printf("%s\n", ntmp);
267#endif
268 if(!vtmp) {
269 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
270 goto err;
271 }
272 X509V3_add_value(ntmp, vtmp, &values);
273 ntmp = NULL;
274 q = p + 1;
275 }
276
277 }
278 }
279
280 if(state == HDR_VALUE) {
281 vtmp = strip_spaces(q);
282#ifdef DEBUG
283 printf("%s=%s\n", ntmp, vtmp);
284#endif
285 if(!vtmp) {
286 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_VALUE);
287 goto err;
288 }
289 X509V3_add_value(ntmp, vtmp, &values);
290 } else {
291 ntmp = strip_spaces(q);
292#ifdef DEBUG
293 printf("%s\n", ntmp);
294#endif
295 if(!ntmp) {
296 X509V3err(X509V3_F_X509V3_PARSE_LIST, X509V3_R_INVALID_NULL_NAME);
297 goto err;
298 }
299 X509V3_add_value(ntmp, NULL, &values);
300 }
301Free(linebuf);
302return values;
303
304err:
305Free(linebuf);
306sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
307return NULL;
308
309}
310
311/* Delete leading and trailing spaces from a string */
312static char *strip_spaces(char *name)
313{
314 char *p, *q;
315 /* Skip over leading spaces */
316 p = name;
317 while(*p && isspace((unsigned char)*p)) p++;
318 if(!*p) return NULL;
319 q = p + strlen(p) - 1;
320 while((q != p) && isspace((unsigned char)*q)) q--;
321 if(p != q) q[1] = 0;
322 if(!*p) return NULL;
323 return p;
324}
325
326/* hex string utilities */
327
328/* Given a buffer of length 'len' return a Malloc'ed string with its
329 * hex representation
330 */
331
332char *hex_to_string(unsigned char *buffer, long len)
333{
334 char *tmp, *q;
335 unsigned char *p;
336 int i;
337 static char hexdig[] = "0123456789ABCDEF";
338 if(!buffer || !len) return NULL;
339 if(!(tmp = Malloc(len * 3 + 1))) {
340 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
341 return NULL;
342 }
343 q = tmp;
344 for(i = 0, p = buffer; i < len; i++,p++) {
345 *q++ = hexdig[(*p >> 4) & 0xf];
346 *q++ = hexdig[*p & 0xf];
347 *q++ = ':';
348 }
349 q[-1] = 0;
350 return tmp;
351}
352
353/* Give a string of hex digits convert to
354 * a buffer
355 */
356
357unsigned char *string_to_hex(char *str, long *len)
358{
359 unsigned char *hexbuf, *q;
360 unsigned char ch, cl, *p;
361 if(!str) {
362 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_INVALID_NULL_ARGUMENT);
363 return NULL;
364 }
365 if(!(hexbuf = Malloc(strlen(str) >> 1))) goto err;
366 for(p = (unsigned char *)str, q = hexbuf; *p;) {
367 ch = *p++;
368 if(ch == ':') continue;
369 cl = *p++;
370 if(!cl) {
371 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ODD_NUMBER_OF_DIGITS);
372 Free(hexbuf);
373 return NULL;
374 }
375 if(isupper(ch)) ch = tolower(ch);
376 if(isupper(cl)) cl = tolower(cl);
377
378 if((ch >= '0') && (ch <= '9')) ch -= '0';
379 else if ((ch >= 'a') && (ch <= 'f')) ch -= 'a' - 10;
380 else goto badhex;
381
382 if((cl >= '0') && (cl <= '9')) cl -= '0';
383 else if ((cl >= 'a') && (cl <= 'f')) cl -= 'a' - 10;
384 else goto badhex;
385
386 *q++ = (ch << 4) | cl;
387 }
388
389 if(len) *len = q - hexbuf;
390
391 return hexbuf;
392
393 err:
394 if(hexbuf) Free(hexbuf);
395 X509V3err(X509V3_F_STRING_TO_HEX,ERR_R_MALLOC_FAILURE);
396 return NULL;
397
398 badhex:
399 Free(hexbuf);
400 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ILLEGAL_HEX_DIGIT);
401 return NULL;
402
403}
404
405/* V2I name comparison function: returns zero if 'name' matches
406 * cmp or cmp.*
407 */
408
409int name_cmp(const char *name, const char *cmp)
410{
411 int len, ret;
412 char c;
413 len = strlen(cmp);
414 if((ret = strncmp(name, cmp, len))) return ret;
415 c = name[len];
416 if(!c || (c=='.')) return 0;
417 return 1;
418}
diff --git a/src/lib/libcrypto/x509v3/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 @@
1/* v3conf.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68/* Test application to add extensions from a config file */
69
70int main(int argc, char **argv)
71{
72 LHASH *conf;
73 X509 *cert;
74 FILE *inf;
75 char *conf_file;
76 int i;
77 int count;
78 X509_EXTENSION *ext;
79 X509V3_add_standard_extensions();
80 ERR_load_crypto_strings();
81 if(!argv[1]) {
82 fprintf(stderr, "Usage: v3conf cert.pem [file.cnf]\n");
83 exit(1);
84 }
85 conf_file = argv[2];
86 if(!conf_file) conf_file = "test.cnf";
87 conf = CONF_load(NULL, "test.cnf", NULL);
88 if(!conf) {
89 fprintf(stderr, "Error opening Config file %s\n", conf_file);
90 ERR_print_errors_fp(stderr);
91 exit(1);
92 }
93
94 inf = fopen(argv[1], "r");
95 if(!inf) {
96 fprintf(stderr, "Can't open certificate file %s\n", argv[1]);
97 exit(1);
98 }
99 cert = PEM_read_X509(inf, NULL, NULL);
100 if(!cert) {
101 fprintf(stderr, "Error reading certificate file %s\n", argv[1]);
102 exit(1);
103 }
104 fclose(inf);
105
106 sk_pop_free(cert->cert_info->extensions, X509_EXTENSION_free);
107 cert->cert_info->extensions = NULL;
108
109 if(!X509V3_EXT_add_conf(conf, NULL, "test_section", cert)) {
110 fprintf(stderr, "Error adding extensions\n");
111 ERR_print_errors_fp(stderr);
112 exit(1);
113 }
114
115 count = X509_get_ext_count(cert);
116 printf("%d extensions\n", count);
117 for(i = 0; i < count; i++) {
118 ext = X509_get_ext(cert, i);
119 printf("%s", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
120 if(ext->critical) printf(",critical:\n");
121 else printf(":\n");
122 X509V3_EXT_print_fp(stdout, ext, 0);
123 printf("\n");
124
125 }
126 return 0;
127}
128
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 @@
1/* crypto/x509v3/v3err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file.
58 */
59
60#include <stdio.h>
61#include <openssl/err.h>
62#include <openssl/x509v3.h>
63
64/* BEGIN ERROR CODES */
65#ifndef NO_ERR
66static ERR_STRING_DATA X509V3_str_functs[]=
67 {
68{ERR_PACK(0,X509V3_F_COPY_EMAIL,0), "COPY_EMAIL"},
69{ERR_PACK(0,X509V3_F_COPY_ISSUER,0), "COPY_ISSUER"},
70{ERR_PACK(0,X509V3_F_DO_EXT_CONF,0), "DO_EXT_CONF"},
71{ERR_PACK(0,X509V3_F_DO_EXT_I2D,0), "DO_EXT_I2D"},
72{ERR_PACK(0,X509V3_F_HEX_TO_STRING,0), "hex_to_string"},
73{ERR_PACK(0,X509V3_F_I2S_ASN1_ENUMERATED,0), "i2s_ASN1_ENUMERATED"},
74{ERR_PACK(0,X509V3_F_I2S_ASN1_INTEGER,0), "i2s_ASN1_INTEGER"},
75{ERR_PACK(0,X509V3_F_NOTICE_SECTION,0), "NOTICE_SECTION"},
76{ERR_PACK(0,X509V3_F_NREF_NOS,0), "NREF_NOS"},
77{ERR_PACK(0,X509V3_F_POLICY_SECTION,0), "POLICY_SECTION"},
78{ERR_PACK(0,X509V3_F_R2I_CERTPOL,0), "R2I_CERTPOL"},
79{ERR_PACK(0,X509V3_F_S2I_ASN1_IA5STRING,0), "S2I_ASN1_IA5STRING"},
80{ERR_PACK(0,X509V3_F_S2I_ASN1_INTEGER,0), "s2i_ASN1_INTEGER"},
81{ERR_PACK(0,X509V3_F_S2I_ASN1_OCTET_STRING,0), "s2i_ASN1_OCTET_STRING"},
82{ERR_PACK(0,X509V3_F_S2I_ASN1_SKEY_ID,0), "S2I_ASN1_SKEY_ID"},
83{ERR_PACK(0,X509V3_F_S2I_S2I_SKEY_ID,0), "S2I_S2I_SKEY_ID"},
84{ERR_PACK(0,X509V3_F_STRING_TO_HEX,0), "string_to_hex"},
85{ERR_PACK(0,X509V3_F_SXNET_ADD_ASC,0), "SXNET_ADD_ASC"},
86{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_INTEGER,0), "SXNET_add_id_INTEGER"},
87{ERR_PACK(0,X509V3_F_SXNET_ADD_ID_ULONG,0), "SXNET_add_id_ulong"},
88{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ASC,0), "SXNET_get_id_asc"},
89{ERR_PACK(0,X509V3_F_SXNET_GET_ID_ULONG,0), "SXNET_get_id_ulong"},
90{ERR_PACK(0,X509V3_F_V2I_ASN1_BIT_STRING,0), "V2I_ASN1_BIT_STRING"},
91{ERR_PACK(0,X509V3_F_V2I_AUTHORITY_KEYID,0), "V2I_AUTHORITY_KEYID"},
92{ERR_PACK(0,X509V3_F_V2I_BASIC_CONSTRAINTS,0), "V2I_BASIC_CONSTRAINTS"},
93{ERR_PACK(0,X509V3_F_V2I_CRLD,0), "V2I_CRLD"},
94{ERR_PACK(0,X509V3_F_V2I_EXT_KU,0), "V2I_EXT_KU"},
95{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAME,0), "v2i_GENERAL_NAME"},
96{ERR_PACK(0,X509V3_F_V2I_GENERAL_NAMES,0), "v2i_GENERAL_NAMES"},
97{ERR_PACK(0,X509V3_F_V3_GENERIC_EXTENSION,0), "V3_GENERIC_EXTENSION"},
98{ERR_PACK(0,X509V3_F_X509V3_ADD_VALUE,0), "X509V3_add_value"},
99{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD,0), "X509V3_EXT_add"},
100{ERR_PACK(0,X509V3_F_X509V3_EXT_ADD_ALIAS,0), "X509V3_EXT_add_alias"},
101{ERR_PACK(0,X509V3_F_X509V3_EXT_CONF,0), "X509V3_EXT_conf"},
102{ERR_PACK(0,X509V3_F_X509V3_EXT_I2D,0), "X509V3_EXT_i2d"},
103{ERR_PACK(0,X509V3_F_X509V3_GET_VALUE_BOOL,0), "X509V3_get_value_bool"},
104{ERR_PACK(0,X509V3_F_X509V3_PARSE_LIST,0), "X509V3_parse_list"},
105{0,NULL}
106 };
107
108static ERR_STRING_DATA X509V3_str_reasons[]=
109 {
110{X509V3_R_BAD_IP_ADDRESS ,"bad ip address"},
111{X509V3_R_BAD_OBJECT ,"bad object"},
112{X509V3_R_BN_DEC2BN_ERROR ,"bn dec2bn error"},
113{X509V3_R_BN_TO_ASN1_INTEGER_ERROR ,"bn to asn1 integer error"},
114{X509V3_R_DUPLICATE_ZONE_ID ,"duplicate zone id"},
115{X509V3_R_ERROR_CONVERTING_ZONE ,"error converting zone"},
116{X509V3_R_ERROR_IN_EXTENSION ,"error in extension"},
117{X509V3_R_EXPECTED_A_SECTION_NAME ,"expected a section name"},
118{X509V3_R_EXTENSION_NAME_ERROR ,"extension name error"},
119{X509V3_R_EXTENSION_NOT_FOUND ,"extension not found"},
120{X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED,"extension setting not supported"},
121{X509V3_R_EXTENSION_VALUE_ERROR ,"extension value error"},
122{X509V3_R_ILLEGAL_HEX_DIGIT ,"illegal hex digit"},
123{X509V3_R_INVALID_BOOLEAN_STRING ,"invalid boolean string"},
124{X509V3_R_INVALID_EXTENSION_STRING ,"invalid extension string"},
125{X509V3_R_INVALID_NAME ,"invalid name"},
126{X509V3_R_INVALID_NULL_ARGUMENT ,"invalid null argument"},
127{X509V3_R_INVALID_NULL_NAME ,"invalid null name"},
128{X509V3_R_INVALID_NULL_VALUE ,"invalid null value"},
129{X509V3_R_INVALID_NUMBER ,"invalid number"},
130{X509V3_R_INVALID_NUMBERS ,"invalid numbers"},
131{X509V3_R_INVALID_OBJECT_IDENTIFIER ,"invalid object identifier"},
132{X509V3_R_INVALID_OPTION ,"invalid option"},
133{X509V3_R_INVALID_POLICY_IDENTIFIER ,"invalid policy identifier"},
134{X509V3_R_INVALID_SECTION ,"invalid section"},
135{X509V3_R_ISSUER_DECODE_ERROR ,"issuer decode error"},
136{X509V3_R_MISSING_VALUE ,"missing value"},
137{X509V3_R_NEED_ORGANIZATION_AND_NUMBERS ,"need organization and numbers"},
138{X509V3_R_NO_CONFIG_DATABASE ,"no config database"},
139{X509V3_R_NO_ISSUER_CERTIFICATE ,"no issuer certificate"},
140{X509V3_R_NO_ISSUER_DETAILS ,"no issuer details"},
141{X509V3_R_NO_POLICY_IDENTIFIER ,"no policy identifier"},
142{X509V3_R_NO_PUBLIC_KEY ,"no public key"},
143{X509V3_R_NO_SUBJECT_DETAILS ,"no subject details"},
144{X509V3_R_ODD_NUMBER_OF_DIGITS ,"odd number of digits"},
145{X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS ,"unable to get issuer details"},
146{X509V3_R_UNABLE_TO_GET_ISSUER_KEYID ,"unable to get issuer keyid"},
147{X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT ,"unknown bit string argument"},
148{X509V3_R_UNKNOWN_EXTENSION ,"unknown extension"},
149{X509V3_R_UNKNOWN_EXTENSION_NAME ,"unknown extension name"},
150{X509V3_R_UNKNOWN_OPTION ,"unknown option"},
151{X509V3_R_UNSUPPORTED_OPTION ,"unsupported option"},
152{X509V3_R_USER_TOO_LONG ,"user too long"},
153{0,NULL}
154 };
155
156#endif
157
158void ERR_load_X509V3_strings(void)
159 {
160 static int init=1;
161
162 if (init)
163 {
164 init=0;
165#ifndef NO_ERR
166 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_functs);
167 ERR_load_strings(ERR_LIB_X509V3,X509V3_str_reasons);
168#endif
169
170 }
171 }
diff --git a/src/lib/libcrypto/x509v3/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 @@
1/* v3prin.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/asn1.h>
64#include <openssl/asn1_mac.h>
65#include <openssl/conf.h>
66#include <openssl/x509.h>
67#include <openssl/x509v3.h>
68
69int main(int argc, char **argv)
70{
71 X509 *cert;
72 FILE *inf;
73 int i, count;
74 X509_EXTENSION *ext;
75 X509V3_add_standard_extensions();
76 ERR_load_crypto_strings();
77 if(!argv[1]) {
78 fprintf(stderr, "Usage v3prin cert.pem\n");
79 exit(1);
80 }
81 if(!(inf = fopen(argv[1], "r"))) {
82 fprintf(stderr, "Can't open %s\n", argv[1]);
83 exit(1);
84 }
85 if(!(cert = PEM_read_X509(inf, NULL, NULL))) {
86 fprintf(stderr, "Can't read certificate %s\n", argv[1]);
87 ERR_print_errors_fp(stderr);
88 exit(1);
89 }
90 fclose(inf);
91 count = X509_get_ext_count(cert);
92 printf("%d extensions\n", count);
93 for(i = 0; i < count; i++) {
94 ext = X509_get_ext(cert, i);
95 printf("%s\n", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
96 if(!X509V3_EXT_print_fp(stdout, ext, 0, 0)) ERR_print_errors_fp(stderr);
97 printf("\n");
98
99 }
100 return 0;
101}
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 @@
1/* crypto/x509v3/x509v3.h */ 1/* x509v3.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * All rights reserved. 3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 7 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
25 * are met: 10 * are met:
26 * 1. Redistributions of source code must retain the copyright 11 *
27 * notice, this list of conditions and the following disclaimer. 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
28 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in
30 * documentation and/or other materials provided with the distribution. 17 * the documentation and/or other materials provided with the
31 * 3. All advertising materials mentioning features or use of this software 18 * distribution.
32 * must display the following acknowledgement: 19 *
33 * "This product includes cryptographic software written by 20 * 3. All advertising materials mentioning features or use of this
34 * Eric Young (eay@cryptsoft.com)" 21 * software must display the following acknowledgment:
35 * The word 'cryptographic' can be left out if the rouines from the library 22 * "This product includes software developed by the OpenSSL Project
36 * being used are not cryptographic related :-). 23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
37 * 4. If you include any Windows specific code (or a derivative thereof) from 24 *
38 * the apps directory (application code) you must include an acknowledgement: 25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 26 * endorse or promote products derived from this software without
40 * 27 * prior written permission. For written permission, please contact
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 28 * licensing@OpenSSL.org.
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29 *
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30 * 5. Products derived from this software may not be called "OpenSSL"
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 31 * nor may "OpenSSL" appear in their names without prior written
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32 * permission of the OpenSSL Project.
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33 *
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * 6. Redistributions of any form whatsoever must retain the following
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * acknowledgment:
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * "This product includes software developed by the OpenSSL Project
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
51 * SUCH DAMAGE. 38 *
52 * 39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
53 * The licence and distribution terms for any publically available version or 40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * derivative of this code cannot be changed. i.e. this code cannot simply be 41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55 * copied and put under another distribution licence 42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
56 * [including the GNU Public Licence.] 43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */ 57 */
58#define X509v3_N_KU_digitalSignature 0 58#ifndef HEADER_X509V3_H
59#define X509v3_N_KU_nonRepudiation 1 59#define HEADER_X509V3_H
60#define X509v3_N_KU_keyEncipherment 2 60
61#define X509v3_N_KU_dataEncipherment 3 61#ifdef __cplusplus
62#define X509v3_N_KU_keyAgreement 4 62extern "C" {
63#define X509v3_N_KU_keyCertSign 5 63#endif
64#define X509v3_N_KU_cRLSign 6 64
65#define X509v3_N_KU_encipherOnly 7 65#include <openssl/bio.h>
66#define X509v3_N_KU_decipherOnly 8 66#include <openssl/x509.h>
67#define X509v3_N_KU_NUM 9 67#include <openssl/conf.h>
68#define X509v3_S_KU_digitalSignature "digitalSignature" 68
69#define X509v3_S_KU_nonRepudiation "nonRepudiation" 69/* Forward reference */
70#define X509v3_S_KU_keyEncipherment "keyEncipherment" 70struct v3_ext_method;
71#define X509v3_S_KU_dataEncipherment "dataEncipherment" 71struct v3_ext_ctx;
72#define X509v3_S_KU_keyAgreement "keyAgreement" 72
73#define X509v3_S_KU_keyCertSign "keyCertSign" 73/* Useful typedefs */
74#define X509v3_S_KU_cRLSign "cRLSign" 74
75#define X509v3_S_KU_encipherOnly "encipherOnly" 75typedef void * (*X509V3_EXT_NEW)(void);
76#define X509v3_S_KU_decipherOnly "decipherOnly" 76typedef void (*X509V3_EXT_FREE)(void *);
77 77typedef void * (*X509V3_EXT_D2I)(void *, unsigned char ** , long);
78 78typedef int (*X509V3_EXT_I2D)(void *, unsigned char **);
79void X509_ex_clear(X509_EXTENSION *a); 79typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist);
80int X509_ex_get_bool(X509_EXTENSION *a,int num); 80typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values);
81int X509_ex_set_bool(X509_EXTENSION *a,int num,int value); 81typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext);
82int X509_ex_get_str(X509_EXTENSION *a,int index,char **p,int *len); 82typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
83int X509_ex_set_str(X509_EXTENSION *a,int oid,int index,char *p,int len); 83typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent);
84char *X509_ex_get_struct(X509_EXTENSION *a,int oid,int index,char **p); 84typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
85int X509_ex_set_struct(X509_EXTENSION *a,int index,char *p); 85
86int a2i_X509_EXTENSION(BIO *bp,X509_EXTENSION *a,char *buf,int len); 86/* V3 extension structure */
87int i2a_X509_EXTENSION(BIO *bp,X509_EXTENSION *a); 87
88struct v3_ext_method {
89int ext_nid;
90int ext_flags;
91X509V3_EXT_NEW ext_new;
92X509V3_EXT_FREE ext_free;
93X509V3_EXT_D2I d2i;
94X509V3_EXT_I2D i2d;
95
96/* The following pair is used for string extensions */
97X509V3_EXT_I2S i2s;
98X509V3_EXT_S2I s2i;
99
100/* The following pair is used for multi-valued extensions */
101X509V3_EXT_I2V i2v;
102X509V3_EXT_V2I v2i;
103
104/* The following are used for raw extensions */
105X509V3_EXT_I2R i2r;
106X509V3_EXT_R2I r2i;
107
108void *usr_data; /* Any extension specific data */
109};
110
111typedef struct X509V3_CONF_METHOD_st {
112char * (*get_string)(void *db, char *section, char *value);
113STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
114void (*free_string)(void *db, char * string);
115void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
116} X509V3_CONF_METHOD;
117
118/* Context specific info */
119struct v3_ext_ctx {
120#define CTX_TEST 0x1
121int flags;
122X509 *issuer_cert;
123X509 *subject_cert;
124X509_REQ *subject_req;
125X509_CRL *crl;
126X509V3_CONF_METHOD *db_meth;
127void *db;
128/* Maybe more here */
129};
130
131typedef struct v3_ext_method X509V3_EXT_METHOD;
132typedef struct v3_ext_ctx X509V3_CTX;
133
134/* ext_flags values */
135#define X509V3_EXT_DYNAMIC 0x1
136#define X509V3_EXT_CTX_DEP 0x2
137#define X509V3_EXT_MULTILINE 0x4
138
139typedef struct BIT_STRING_BITNAME_st {
140int bitnum;
141const char *lname;
142const char *sname;
143} BIT_STRING_BITNAME;
144
145typedef BIT_STRING_BITNAME ENUMERATED_NAMES;
146
147typedef struct BASIC_CONSTRAINTS_st {
148int ca;
149ASN1_INTEGER *pathlen;
150} BASIC_CONSTRAINTS;
151
152
153typedef struct PKEY_USAGE_PERIOD_st {
154ASN1_GENERALIZEDTIME *notBefore;
155ASN1_GENERALIZEDTIME *notAfter;
156} PKEY_USAGE_PERIOD;
157
158typedef struct GENERAL_NAME_st {
159
160#define GEN_OTHERNAME (0|V_ASN1_CONTEXT_SPECIFIC)
161#define GEN_EMAIL (1|V_ASN1_CONTEXT_SPECIFIC)
162#define GEN_DNS (2|V_ASN1_CONTEXT_SPECIFIC)
163#define GEN_X400 (3|V_ASN1_CONTEXT_SPECIFIC)
164#define GEN_DIRNAME (4|V_ASN1_CONTEXT_SPECIFIC)
165#define GEN_EDIPARTY (5|V_ASN1_CONTEXT_SPECIFIC)
166#define GEN_URI (6|V_ASN1_CONTEXT_SPECIFIC)
167#define GEN_IPADD (7|V_ASN1_CONTEXT_SPECIFIC)
168#define GEN_RID (8|V_ASN1_CONTEXT_SPECIFIC)
169
170int type;
171union {
172 char *ptr;
173 ASN1_IA5STRING *ia5;/* rfc822Name, dNSName, uniformResourceIdentifier */
174 ASN1_OCTET_STRING *ip; /* iPAddress */
175 X509_NAME *dirn; /* dirn */
176 ASN1_OBJECT *rid; /* registeredID */
177 ASN1_TYPE *other; /* otherName, ediPartyName, x400Address */
178} d;
179} GENERAL_NAME;
180
181DECLARE_STACK_OF(GENERAL_NAME)
182DECLARE_ASN1_SET_OF(GENERAL_NAME)
183
184typedef struct DIST_POINT_NAME_st {
185/* NB: this is a CHOICE type and only one of these should be set */
186STACK_OF(GENERAL_NAME) *fullname;
187X509_NAME *relativename;
188} DIST_POINT_NAME;
189
190typedef struct DIST_POINT_st {
191DIST_POINT_NAME *distpoint;
192ASN1_BIT_STRING *reasons;
193STACK_OF(GENERAL_NAME) *CRLissuer;
194} DIST_POINT;
195
196DECLARE_STACK_OF(DIST_POINT)
197DECLARE_ASN1_SET_OF(DIST_POINT)
198
199typedef struct AUTHORITY_KEYID_st {
200ASN1_OCTET_STRING *keyid;
201STACK_OF(GENERAL_NAME) *issuer;
202ASN1_INTEGER *serial;
203} AUTHORITY_KEYID;
204
205/* Strong extranet structures */
206
207typedef struct SXNET_ID_st {
208 ASN1_INTEGER *zone;
209 ASN1_OCTET_STRING *user;
210} SXNETID;
211
212DECLARE_STACK_OF(SXNETID)
213DECLARE_ASN1_SET_OF(SXNETID)
214
215typedef struct SXNET_st {
216 ASN1_INTEGER *version;
217 STACK_OF(SXNETID) *ids;
218} SXNET;
219
220typedef struct NOTICEREF_st {
221 ASN1_STRING *organization;
222 STACK *noticenos;
223} NOTICEREF;
224
225typedef struct USERNOTICE_st {
226 NOTICEREF *noticeref;
227 ASN1_STRING *exptext;
228} USERNOTICE;
229
230typedef struct POLICYQUALINFO_st {
231 ASN1_OBJECT *pqualid;
232 union {
233 ASN1_IA5STRING *cpsuri;
234 USERNOTICE *usernotice;
235 ASN1_TYPE *other;
236 } d;
237} POLICYQUALINFO;
238
239DECLARE_STACK_OF(POLICYQUALINFO)
240DECLARE_ASN1_SET_OF(POLICYQUALINFO)
241
242typedef struct POLICYINFO_st {
243 ASN1_OBJECT *policyid;
244 STACK_OF(POLICYQUALINFO) *qualifiers;
245} POLICYINFO;
246
247DECLARE_STACK_OF(POLICYINFO)
248DECLARE_ASN1_SET_OF(POLICYINFO)
249
250#define X509V3_conf_err(val) ERR_add_error_data(6, "section:", val->section, \
251",name:", val->name, ",value:", val->value);
252
253#define X509V3_set_ctx_test(ctx) \
254 X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, CTX_TEST)
255#define X509V3_set_ctx_nodb(ctx) ctx->db = NULL;
256
257#define EXT_BITSTRING(nid, table) { nid, 0, \
258 (X509V3_EXT_NEW)asn1_bit_string_new, \
259 (X509V3_EXT_FREE)ASN1_STRING_free, \
260 (X509V3_EXT_D2I)d2i_ASN1_BIT_STRING, \
261 (X509V3_EXT_I2D)i2d_ASN1_BIT_STRING, \
262 NULL, NULL, \
263 (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \
264 (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \
265 NULL, NULL, \
266 (char *)table}
267
268#define EXT_IA5STRING(nid) { nid, 0, \
269 (X509V3_EXT_NEW)ia5string_new, \
270 (X509V3_EXT_FREE)ASN1_STRING_free, \
271 (X509V3_EXT_D2I)d2i_ASN1_IA5STRING, \
272 (X509V3_EXT_I2D)i2d_ASN1_IA5STRING, \
273 (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \
274 (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \
275 NULL, NULL, NULL, NULL, \
276 NULL}
277
278#define EXT_END { -1, 0, NULL, NULL, NULL, NULL, NULL, NULL, \
279 NULL, NULL, NULL, NULL, \
280 NULL}
281
282void ERR_load_X509V3_strings(void);
283int i2d_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS *a, unsigned char **pp);
284BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **a, unsigned char **pp, long length);
285BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void);
286void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *a);
287
288int i2d_GENERAL_NAME(GENERAL_NAME *a, unsigned char **pp);
289GENERAL_NAME *d2i_GENERAL_NAME(GENERAL_NAME **a, unsigned char **pp, long length);
290GENERAL_NAME *GENERAL_NAME_new(void);
291void GENERAL_NAME_free(GENERAL_NAME *a);
292STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret);
293
294int i2d_SXNET(SXNET *a, unsigned char **pp);
295SXNET *d2i_SXNET(SXNET **a, unsigned char **pp, long length);
296SXNET *SXNET_new(void);
297void SXNET_free(SXNET *a);
298
299int i2d_SXNETID(SXNETID *a, unsigned char **pp);
300SXNETID *d2i_SXNETID(SXNETID **a, unsigned char **pp, long length);
301SXNETID *SXNETID_new(void);
302void SXNETID_free(SXNETID *a);
303
304int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen);
305int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen);
306int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, char *user, int userlen);
307
308ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone);
309ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone);
310ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone);
311
312int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *a, unsigned char **pp);
313AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **a, unsigned char **pp, long length);
314AUTHORITY_KEYID *AUTHORITY_KEYID_new(void);
315void AUTHORITY_KEYID_free(AUTHORITY_KEYID *a);
316
317int i2d_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD *a, unsigned char **pp);
318PKEY_USAGE_PERIOD *d2i_PKEY_USAGE_PERIOD(PKEY_USAGE_PERIOD **a, unsigned char **pp, long length);
319PKEY_USAGE_PERIOD *PKEY_USAGE_PERIOD_new(void);
320void PKEY_USAGE_PERIOD_free(PKEY_USAGE_PERIOD *a);
321
322STACK_OF(GENERAL_NAME) *GENERAL_NAMES_new(void);
323void GENERAL_NAMES_free(STACK_OF(GENERAL_NAME) *a);
324STACK_OF(GENERAL_NAME) *d2i_GENERAL_NAMES(STACK_OF(GENERAL_NAME) **a, unsigned char **pp, long length);
325int i2d_GENERAL_NAMES(STACK_OF(GENERAL_NAME) *a, unsigned char **pp);
326STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method,
327 STACK_OF(GENERAL_NAME) *gen, STACK_OF(CONF_VALUE) *extlist);
328STACK_OF(GENERAL_NAME) *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
329 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
330
331char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
332ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
333
334int i2d_ext_ku(STACK_OF(ASN1_OBJECT) *a, unsigned char **pp);
335STACK_OF(ASN1_OBJECT) *d2i_ext_ku(STACK_OF(ASN1_OBJECT) **a,
336 unsigned char **pp, long length);
337void ext_ku_free(STACK_OF(ASN1_OBJECT) *a);
338STACK_OF(ASN1_OBJECT) *ext_ku_new(void);
339
340int i2d_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) *a, unsigned char **pp);
341STACK_OF(POLICYINFO) *CERTIFICATEPOLICIES_new(void);
342void CERTIFICATEPOLICIES_free(STACK_OF(POLICYINFO) *a);
343STACK_OF(POLICYINFO) *d2i_CERTIFICATEPOLICIES(STACK_OF(POLICYINFO) **a, unsigned char **pp, long length);
344
345int i2d_POLICYINFO(POLICYINFO *a, unsigned char **pp);
346POLICYINFO *POLICYINFO_new(void);
347POLICYINFO *d2i_POLICYINFO(POLICYINFO **a, unsigned char **pp, long length);
348void POLICYINFO_free(POLICYINFO *a);
349
350int i2d_POLICYQUALINFO(POLICYQUALINFO *a, unsigned char **pp);
351POLICYQUALINFO *POLICYQUALINFO_new(void);
352POLICYQUALINFO *d2i_POLICYQUALINFO(POLICYQUALINFO **a, unsigned char **pp,
353 long length);
354void POLICYQUALINFO_free(POLICYQUALINFO *a);
355
356int i2d_USERNOTICE(USERNOTICE *a, unsigned char **pp);
357USERNOTICE *USERNOTICE_new(void);
358USERNOTICE *d2i_USERNOTICE(USERNOTICE **a, unsigned char **pp, long length);
359void USERNOTICE_free(USERNOTICE *a);
360
361int i2d_NOTICEREF(NOTICEREF *a, unsigned char **pp);
362NOTICEREF *NOTICEREF_new(void);
363NOTICEREF *d2i_NOTICEREF(NOTICEREF **a, unsigned char **pp, long length);
364void NOTICEREF_free(NOTICEREF *a);
365
366int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT) *a, unsigned char **pp);
367STACK_OF(DIST_POINT) *CRL_DIST_POINTS_new(void);
368void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT) *a);
369STACK_OF(DIST_POINT) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT) **a,
370 unsigned char **pp,long length);
371
372int i2d_DIST_POINT(DIST_POINT *a, unsigned char **pp);
373DIST_POINT *DIST_POINT_new(void);
374DIST_POINT *d2i_DIST_POINT(DIST_POINT **a, unsigned char **pp, long length);
375void DIST_POINT_free(DIST_POINT *a);
376
377int i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **pp);
378DIST_POINT_NAME *DIST_POINT_NAME_new(void);
379void DIST_POINT_NAME_free(DIST_POINT_NAME *a);
380DIST_POINT_NAME *d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, unsigned char **pp,
381 long length);
382
383#ifdef HEADER_CONF_H
384GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf);
385void X509V3_conf_free(CONF_VALUE *val);
386X509_EXTENSION *X509V3_EXT_conf_nid(LHASH *conf, X509V3_CTX *ctx, int ext_nid, char *value);
387X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name, char *value);
388int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509 *cert);
389int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section, X509_CRL *crl);
390int X509V3_add_value_bool_nf(char *name, int asn1_bool,
391 STACK_OF(CONF_VALUE) **extlist);
392int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
393int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
394void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
395#endif
396
397char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
398STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
399void X509V3_string_free(X509V3_CTX *ctx, char *str);
400void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
401void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
402 X509_REQ *req, X509_CRL *crl, int flags);
403
404int X509V3_add_value(const char *name, const char *value,
405 STACK_OF(CONF_VALUE) **extlist);
406int X509V3_add_value_uchar(const char *name, const unsigned char *value,
407 STACK_OF(CONF_VALUE) **extlist);
408int X509V3_add_value_bool(const char *name, int asn1_bool,
409 STACK_OF(CONF_VALUE) **extlist);
410int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
411 STACK_OF(CONF_VALUE) **extlist);
412char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
413ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
414char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
415char * i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
416int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
417int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist);
418int X509V3_EXT_add_alias(int nid_to, int nid_from);
419void X509V3_EXT_cleanup(void);
420
421X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext);
422X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid);
423int X509V3_add_standard_extensions(void);
424STACK_OF(CONF_VALUE) *X509V3_parse_list(char *line);
425void *X509V3_EXT_d2i(X509_EXTENSION *ext);
426X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
427
428char *hex_to_string(unsigned char *buffer, long len);
429unsigned char *string_to_hex(char *str, long *len);
430int name_cmp(const char *name, const char *cmp);
431
432void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent,
433 int ml);
434int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
435int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
436
437/* BEGIN ERROR CODES */
438/* The following lines are auto generated by the script mkerr.pl. Any changes
439 * made after this point may be overwritten when the script is next run.
440 */
441
442/* Error codes for the X509V3 functions. */
443
444/* Function codes. */
445#define X509V3_F_COPY_EMAIL 122
446#define X509V3_F_COPY_ISSUER 123
447#define X509V3_F_DO_EXT_CONF 124
448#define X509V3_F_DO_EXT_I2D 135
449#define X509V3_F_HEX_TO_STRING 111
450#define X509V3_F_I2S_ASN1_ENUMERATED 121
451#define X509V3_F_I2S_ASN1_INTEGER 120
452#define X509V3_F_NOTICE_SECTION 132
453#define X509V3_F_NREF_NOS 133
454#define X509V3_F_POLICY_SECTION 131
455#define X509V3_F_R2I_CERTPOL 130
456#define X509V3_F_S2I_ASN1_IA5STRING 100
457#define X509V3_F_S2I_ASN1_INTEGER 108
458#define X509V3_F_S2I_ASN1_OCTET_STRING 112
459#define X509V3_F_S2I_ASN1_SKEY_ID 114
460#define X509V3_F_S2I_S2I_SKEY_ID 115
461#define X509V3_F_STRING_TO_HEX 113
462#define X509V3_F_SXNET_ADD_ASC 125
463#define X509V3_F_SXNET_ADD_ID_INTEGER 126
464#define X509V3_F_SXNET_ADD_ID_ULONG 127
465#define X509V3_F_SXNET_GET_ID_ASC 128
466#define X509V3_F_SXNET_GET_ID_ULONG 129
467#define X509V3_F_V2I_ASN1_BIT_STRING 101
468#define X509V3_F_V2I_AUTHORITY_KEYID 119
469#define X509V3_F_V2I_BASIC_CONSTRAINTS 102
470#define X509V3_F_V2I_CRLD 134
471#define X509V3_F_V2I_EXT_KU 103
472#define X509V3_F_V2I_GENERAL_NAME 117
473#define X509V3_F_V2I_GENERAL_NAMES 118
474#define X509V3_F_V3_GENERIC_EXTENSION 116
475#define X509V3_F_X509V3_ADD_VALUE 105
476#define X509V3_F_X509V3_EXT_ADD 104
477#define X509V3_F_X509V3_EXT_ADD_ALIAS 106
478#define X509V3_F_X509V3_EXT_CONF 107
479#define X509V3_F_X509V3_EXT_I2D 136
480#define X509V3_F_X509V3_GET_VALUE_BOOL 110
481#define X509V3_F_X509V3_PARSE_LIST 109
482
483/* Reason codes. */
484#define X509V3_R_BAD_IP_ADDRESS 118
485#define X509V3_R_BAD_OBJECT 119
486#define X509V3_R_BN_DEC2BN_ERROR 100
487#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101
488#define X509V3_R_DUPLICATE_ZONE_ID 133
489#define X509V3_R_ERROR_CONVERTING_ZONE 131
490#define X509V3_R_ERROR_IN_EXTENSION 128
491#define X509V3_R_EXPECTED_A_SECTION_NAME 137
492#define X509V3_R_EXTENSION_NAME_ERROR 115
493#define X509V3_R_EXTENSION_NOT_FOUND 102
494#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103
495#define X509V3_R_EXTENSION_VALUE_ERROR 116
496#define X509V3_R_ILLEGAL_HEX_DIGIT 113
497#define X509V3_R_INVALID_BOOLEAN_STRING 104
498#define X509V3_R_INVALID_EXTENSION_STRING 105
499#define X509V3_R_INVALID_NAME 106
500#define X509V3_R_INVALID_NULL_ARGUMENT 107
501#define X509V3_R_INVALID_NULL_NAME 108
502#define X509V3_R_INVALID_NULL_VALUE 109
503#define X509V3_R_INVALID_NUMBER 140
504#define X509V3_R_INVALID_NUMBERS 141
505#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110
506#define X509V3_R_INVALID_OPTION 138
507#define X509V3_R_INVALID_POLICY_IDENTIFIER 134
508#define X509V3_R_INVALID_SECTION 135
509#define X509V3_R_ISSUER_DECODE_ERROR 126
510#define X509V3_R_MISSING_VALUE 124
511#define X509V3_R_NEED_ORGANIZATION_AND_NUMBERS 142
512#define X509V3_R_NO_CONFIG_DATABASE 136
513#define X509V3_R_NO_ISSUER_CERTIFICATE 121
514#define X509V3_R_NO_ISSUER_DETAILS 127
515#define X509V3_R_NO_POLICY_IDENTIFIER 139
516#define X509V3_R_NO_PUBLIC_KEY 114
517#define X509V3_R_NO_SUBJECT_DETAILS 125
518#define X509V3_R_ODD_NUMBER_OF_DIGITS 112
519#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122
520#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123
521#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111
522#define X509V3_R_UNKNOWN_EXTENSION 129
523#define X509V3_R_UNKNOWN_EXTENSION_NAME 130
524#define X509V3_R_UNKNOWN_OPTION 120
525#define X509V3_R_UNSUPPORTED_OPTION 117
526#define X509V3_R_USER_TOO_LONG 132
527
528#ifdef __cplusplus
529}
530#endif
531#endif
532